1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
|
title "Software Interrupts"
;++
;
; Copyright (c) 1992-1993 Microsoft Corporation
; Copyright (c) 1993 Wyse Technology
;
; Module Name:
;
; wyswint.asm
;
; Abstract:
;
; This module implements the software interrupt handlers
; for x86 machines
;
; Author:
;
; John Vert (jvert) 2-Jan-1992
;
; Environment:
;
; Kernel mode only.
;
; Revision History:
; John Fuller (o-johnf) 31-Aug-1993 mods to support Wyse Lazy IRQLs
;
;--
.386p
.xlist
include hal386.inc
include callconv.inc ; calling convention macros
include i386\ix8259.inc
include i386\kimacro.inc
include i386\wy7000mp.inc
.list
EXTRNP _KiDeliverApc,3,IMPORT
EXTRNP _KiDispatchInterrupt,0,IMPORT
EXTRNP Kei386EoiHelper,0,IMPORT
EXTRNP _HalEndSystemInterrupt,2
extrn SWInterruptHandlerTable:dword
extrn SWInterruptLookUpTable:byte
ifdef IRQL_METRICS
extrn HalApcSoftwareIntCount:dword
extrn HalDpcSoftwareIntCount:dword
endif
_TEXT$02 SEGMENT DWORD PUBLIC 'CODE'
ASSUME DS:FLAT, ES:FLAT, SS:FLAT, FS:NOTHING, GS:NOTHING
page ,132
subttl "Request Software Interrupt"
;++
;
; VOID
; FASTCALL
; HalRequestSoftwareInterrupt (
; IN KIRQL RequestIrql
; )
;
; Routine Description:
;
; This routine is used to request a software interrupt to the
; system. Also, this routine checks to see if any software
; interrupt should be generated.
; The following condition will cause software interrupt to
; be simulated:
; any software interrupt which has higher priority than
; current IRQL's is pending.
;
; NOTE: This routine simulates software interrupt as long as
; any pending SW interrupt level is higher than the current
; IRQL, even when interrupts are disabled.
;
; ASSUMPTIONS:
; 1. This routine is only called for IRQL's 1-4.
; 2. No bits above bit 4 can be set in PcIRR.
; 3. All hardware interrups are above IRQL 4.
;
; Arguments:
;
; (cl) = RequestIrql - Supplies the request IRQL value
;
; Return Value:
;
; None.
;
;--
cPublicFastCall HalRequestSoftwareInterrupt ,1
cPublicFpo 0, 1
mov eax,1
shl eax, cl ; convert to mask
pushfd ; save interrupt mode
cli ; disable interrupt
or PCR[PcIRR], eax ; set the request bit
mov eax, PCR[PcIRR] ; get SW interrupt request register
and eax, 3 ; mask off pending HW interrupts
jz short KsiExit ; exit is none for now
mov al, SWInterruptLookUpTable[eax] ; get the highest pending
; software interrupt level
cmp al, PCR[PcIrql] ; Is highest SW int level > irql?
jbe KsiExit ; No, jmp ksiexit
call SWInterruptHandlerTable[eax*4] ; yes, simulate interrupt
; to the appropriate handler
@@: popfd ; restore original interrupt mode
fstRET HalRequestSoftwareInterrupt
KsiExit:
cmp cl, PCR[PcHal.pchHwIrql]; compare with Hardware Irql
jbe @B ; jump if hardware already above us
mov PCR[PcHal.pchHwIrql], cl; ensure KeLowerIrql checks PcIRR
popfd ; restore original interrupt mode
fstRET HalRequestSoftwareInterrupt
fstENDP HalRequestSoftwareInterrupt
page ,132
subttl "Clear Software Interrupt"
;++
;
; VOID
; HalClearSoftwareInterrupt (
; IN KIRQL RequestIrql
; )
;
; Routine Description:
;
; This routine is used to clear a possible pending software interrupt.
; Support for this function is optional, and allows the kernel to
; reduce the number of spurious software interrupts it receives/
;
; Arguments:
;
; (cl) = RequestIrql - Supplies the request IRQL value
;
; Return Value:
;
; None.
;
;--
cPublicFastCall HalClearSoftwareInterrupt ,1
cPublicFpo 0, 0
mov eax,1
shl eax, cl ; convert to mask
not eax
and PCR[PcIRR], eax ; clear pending irr bit
fstRET HalClearSoftwareInterrupt
fstENDP HalClearSoftwareInterrupt
page ,132
subttl "Dispatch Interrupt"
;++
;
; VOID
; HalpDispatchInterrupt(
; VOID
; );
;
; Routine Description:
;
; This routine is the interrupt handler for a software interrupt generated
; at DISPATCH_LEVEL. Its function is to save the machine state, raise
; Irql to DISPATCH_LEVEL, dismiss the interrupt, and call the DPC
; delivery routine.
;
; Arguments:
;
; None
; Interrupt is disabled
;
; Return Value:
;
; None.
;
;--
ENTER_DR_ASSIST hdpi_a, hdpi_t
align dword
public _HalpDispatchInterrupt
_HalpDispatchInterrupt proc
ifdef IRQL_METRICS
lock inc HalDpcSoftwareIntCount
endif
;
; Create IRET frame on stack
;
pop eax
pushfd
push cs
push eax
;
; Save machine state on trap frame
;
ENTER_INTERRUPT hdpi_a, hdpi_t
.FPO ( FPO_LOCALS+1, 0, 0, 0, 0, FPO_TRAPFRAME )
public _HalpDispatchInterrupt2ndEntry
_HalpDispatchInterrupt2ndEntry:
; Save previous IRQL and set new priority level
push PCR[PcIrql] ; save previous IRQL
mov byte ptr PCR[PcIrql], DISPATCH_LEVEL; set new irql
btr dword ptr PCR[PcIRR], DISPATCH_LEVEL; clear the pending bit in IRR
;
; Now it is safe to enable interrupt to allow higher priority interrupt
; to come in.
;
sti
;
; Go do Dispatch Interrupt processing
;
stdCall _KiDispatchInterrupt
;
; Do interrupt exit processing
;
SOFT_INTERRUPT_EXIT ; will do an iret
_HalpDispatchInterrupt endp
page ,132
subttl "APC Interrupt"
;++
;
; HalpApcInterrupt(
; VOID
; );
;
; Routine Description:
;
; This routine is entered as the result of a software interrupt generated
; at APC_LEVEL. Its function is to save the machine state, raise Irql to
; APC_LEVEL, dismiss the interrupt, and call the APC delivery routine.
;
; Arguments:
;
; None
; Interrupt is Disabled
;
; Return Value:
;
; None.
;
;--
ENTER_DR_ASSIST hapc_a, hapc_t
align dword
public _HalpApcInterrupt
_HalpApcInterrupt proc
ifdef IRQL_METRICS
lock inc HalApcSoftwareIntCount
endif
;
; Create IRET frame on stack
;
pop eax
pushfd
push cs
push eax
;
; Save machine state in trap frame
;
ENTER_INTERRUPT hapc_a, hapc_t
.FPO ( FPO_LOCALS+1, 0, 0, 0, 0, FPO_TRAPFRAME )
public _HalpApcInterrupt2ndEntry
_HalpApcInterrupt2ndEntry:
;
; Save previous IRQL and set new priority level
;
push PCR[PcIrql] ; save previous Irql
mov byte ptr PCR[PcIrql], APC_LEVEL ; set new Irql
btr dword ptr PCR[PcIRR], APC_LEVEL ; dismiss pending APC
;
; Now it is safe to enable interrupt to allow higher priority interrupt
; to come in.
;
sti
;
; call the APC delivery routine.
;
mov eax, [ebp]+TsSegCs ; get interrupted code's CS
and eax, MODE_MASK ; extract the mode
test dword ptr [ebp]+TsEFlags, EFLAGS_V86_MASK
jz short @f
or eax, MODE_MASK ; If v86 frame, then set user_mode
@@:
;
; call APC deliver routine
; Previous mode
; Null exception frame
; Trap frame
stdCall _KiDeliverApc, <eax, 0,ebp>
;
;
; Do interrupt exit processing
;
SOFT_INTERRUPT_EXIT ; will do an iret
_HalpApcInterrupt endp
_TEXT$02 ends
end
|