00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
#include "ki.h"
00030
00031
00032
VOID
00033 KeInitializeInterrupt (
00034 IN
PKINTERRUPT Interrupt,
00035 IN PKSERVICE_ROUTINE ServiceRoutine,
00036 IN PVOID ServiceContext,
00037 IN PKSPIN_LOCK SpinLock OPTIONAL,
00038 IN ULONG Vector,
00039 IN KIRQL Irql,
00040 IN KIRQL SynchronizeIrql,
00041 IN KINTERRUPT_MODE InterruptMode,
00042 IN BOOLEAN ShareVector,
00043 IN CCHAR ProcessorNumber,
00044 IN BOOLEAN FloatingSave
00045 )
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098 {
00099
00100
00101
00102
00103 Interrupt->Type =
InterruptObject;
00104 Interrupt->Size =
sizeof(
KINTERRUPT);
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 Interrupt->ServiceRoutine = ServiceRoutine;
00115 Interrupt->ServiceContext = ServiceContext;
00116
00117 Interrupt->SpinLock = 0;
00118
if (ARGUMENT_PRESENT(SpinLock)) {
00119 Interrupt->ActualLock = SpinLock;
00120 }
else {
00121 Interrupt->ActualLock = &Interrupt->SpinLock;
00122 }
00123
00124 Interrupt->Vector = Vector;
00125 Interrupt->Irql = Irql;
00126 Interrupt->SynchronizeIrql = SynchronizeIrql;
00127 Interrupt->Mode = InterruptMode;
00128 Interrupt->ShareVector = ShareVector;
00129 Interrupt->Number = ProcessorNumber;
00130 Interrupt->FloatingSave = FloatingSave;
00131
00132
00133
00134
00135
00136 Interrupt->Connected =
FALSE;
00137
return;
00138 }
00139
00140 BOOLEAN
00141 KeConnectInterrupt (
00142 IN
PKINTERRUPT Interrupt
00143 )
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168 {
00169
00170 BOOLEAN Connected;
00171
PKINTERRUPT Interruptx;
00172 KIRQL Irql;
00173
CHAR Number;
00174 KIRQL OldIrql;
00175 KIRQL PreviousIrql;
00176 ULONG Vector;
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189 Connected =
FALSE;
00190 Irql = Interrupt->Irql;
00191 Number = Interrupt->Number;
00192 Vector = Interrupt->Vector;
00193
if (
00194 (Vector < MAXIMUM_VECTOR) &&
00195 (Irql <=
HIGH_LEVEL) &&
00196 (Number <
KeNumberProcessors) &&
00197 (
00198 (Vector >
HIGH_LEVEL) ||
00199 ((PCR->ReservedVectors & (1 << Vector)) == 0)
00200 )
00201 ) {
00202
00203
00204
00205
00206
00207
00208
KeSetSystemAffinityThread((KAFFINITY)(1 << Number));
00209
00210
00211
00212
00213
00214
KiLockDispatcherDatabase(&OldIrql);
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
if (Interrupt->Connected ==
FALSE) {
00229
if (PCR->InterruptRoutine[Vector] ==
00230 (PKINTERRUPT_ROUTINE)(&KxUnexpectedInterrupt.DispatchCode)) {
00231 Connected =
TRUE;
00232 Interrupt->Connected =
TRUE;
00233
if (Interrupt->FloatingSave) {
00234 Interrupt->DispatchAddress =
KiFloatingDispatch;
00235
00236 }
else {
00237
if (Interrupt->Irql == Interrupt->SynchronizeIrql) {
00238
#if defined(NT_UP)
00239
Interrupt->DispatchAddress =
00240 (PKINTERRUPT_ROUTINE)Interrupt->ServiceRoutine;
00241
#else
00242
Interrupt->DispatchAddress =
00243 (PKINTERRUPT_ROUTINE)
KiInterruptDispatchSame;
00244
#endif
00245
00246 }
else {
00247 Interrupt->DispatchAddress =
00248 (PKINTERRUPT_ROUTINE)
KiInterruptDispatchRaise;
00249 }
00250 }
00251
00252
00253
00254
00255
00256
00257
00258 Interrupt->DispatchCode[0] =
00259 *(PULONG)(Interrupt->DispatchAddress);
00260 Interrupt->DispatchCode[1] =
00261 *(((PULONG)(Interrupt->DispatchAddress))+1);
00262 PCR->InterruptRoutine[Vector] =
00263 (PKINTERRUPT_ROUTINE)Interrupt->DispatchCode;
00264
00265
HalEnableSystemInterrupt(Vector, Irql, Interrupt->Mode);
00266
00267 }
else if (Interrupt->ShareVector) {
00268 Interruptx = CONTAINING_RECORD(PCR->InterruptRoutine[Vector],
00269
KINTERRUPT,
00270 DispatchCode[0]);
00271
if (Interruptx->
ShareVector &&
00272 Interrupt->Mode == Interruptx->
Mode) {
00273 Connected =
TRUE;
00274 Interrupt->Connected =
TRUE;
00275
KeRaiseIrql((KIRQL)(
max(Irql,
SYNCH_LEVEL)), &PreviousIrql);
00276
if (Interruptx->
DispatchAddress !=
00277 (PKINTERRUPT_ROUTINE)
KiChainedDispatch) {
00278 InitializeListHead(&Interruptx->
InterruptListEntry);
00279 Interruptx->
DispatchAddress =
00280 (PKINTERRUPT_ROUTINE)
KiChainedDispatch;
00281 Interruptx->
DispatchCode[0] =
00282 *(PULONG)
KiChainedDispatch;
00283 Interruptx->
DispatchCode[1] =
00284 *(((PULONG)
KiChainedDispatch)+1);
00285 }
00286
00287 InsertTailList(&Interruptx->
InterruptListEntry,
00288 &Interrupt->InterruptListEntry);
00289
KeLowerIrql(PreviousIrql);
00290 }
00291 }
00292 }
00293
00294
00295
00296
00297
00298
KiUnlockDispatcherDatabase(OldIrql);
00299
00300
00301
00302
00303
00304
KeRevertToUserAffinityThread();
00305 }
00306
00307
00308
00309
00310
00311
return Connected;
00312 }
00313
00314 BOOLEAN
00315 KeDisconnectInterrupt (
00316 IN
PKINTERRUPT Interrupt
00317 )
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340 {
00341
00342 BOOLEAN Connected;
00343
PKINTERRUPT Interruptx;
00344
PKINTERRUPT Interrupty;
00345 KIRQL Irql;
00346 KIRQL OldIrql;
00347 KIRQL PreviousIrql;
00348 ULONG Vector;
00349
00350
00351
00352
00353
00354
KeSetSystemAffinityThread((KAFFINITY)(1 << Interrupt->Number));
00355
00356
00357
00358
00359
00360
KiLockDispatcherDatabase(&OldIrql);
00361
00362
00363
00364
00365
00366
00367 Connected = Interrupt->Connected;
00368
if (Connected !=
FALSE) {
00369 Irql = Interrupt->Irql;
00370 Vector = Interrupt->Vector;
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381 Interruptx = CONTAINING_RECORD(PCR->InterruptRoutine[Vector],
00382
KINTERRUPT,
00383 DispatchCode[0]);
00384
00385
if (Interruptx->
DispatchAddress ==
00386 (PKINTERRUPT_ROUTINE)
KiChainedDispatch) {
00387
KeRaiseIrql((KIRQL)(
max(Irql,
SYNCH_LEVEL)), &PreviousIrql);
00388
if (Interrupt == Interruptx) {
00389 Interruptx = CONTAINING_RECORD(Interruptx->
InterruptListEntry.Flink,
00390
KINTERRUPT, InterruptListEntry);
00391 Interruptx->
DispatchAddress =
00392 (PKINTERRUPT_ROUTINE)
KiChainedDispatch;
00393 Interruptx->
DispatchCode[0] = *(PULONG)
KiChainedDispatch;
00394 Interruptx->
DispatchCode[1] = *(((PULONG)
KiChainedDispatch)+1);
00395 PCR->InterruptRoutine[Vector] =
00396 (PKINTERRUPT_ROUTINE)Interruptx->
DispatchCode;
00397
00398 }
00399
00400 RemoveEntryList(&Interrupt->InterruptListEntry);
00401 Interrupty = CONTAINING_RECORD(Interruptx->
InterruptListEntry.Flink,
00402
KINTERRUPT,
00403 InterruptListEntry);
00404
00405
if (Interruptx == Interrupty) {
00406
if (Interrupt->FloatingSave) {
00407 Interrupt->DispatchAddress =
KiFloatingDispatch;
00408
00409 }
else {
00410
if (Interrupt->Irql == Interrupt->SynchronizeIrql) {
00411
#if defined(NT_UP)
00412
Interrupt->DispatchAddress =
00413 (PKINTERRUPT_ROUTINE)Interrupt->ServiceRoutine;
00414
#else
00415
Interrupt->DispatchAddress =
00416 (PKINTERRUPT_ROUTINE)
KiInterruptDispatchSame;
00417
#endif
00418
00419 }
else {
00420 Interrupt->DispatchAddress =
00421 (PKINTERRUPT_ROUTINE)
KiInterruptDispatchRaise;
00422 }
00423 }
00424
00425
00426
00427
00428
00429
00430 Interrupty->
DispatchCode[0] =
00431 *(PULONG)(Interrupty->
DispatchAddress);
00432 Interrupty->
DispatchCode[1] =
00433 *(((PULONG)(Interrupty->
DispatchAddress))+1);
00434 PCR->InterruptRoutine[Vector] =
00435 (PKINTERRUPT_ROUTINE)Interrupty->
DispatchCode;
00436
00437 }
00438
00439
KeLowerIrql(PreviousIrql);
00440
00441 }
else {
00442
HalDisableSystemInterrupt(Vector, Irql);
00443 PCR->InterruptRoutine[Vector] =
00444 (PKINTERRUPT_ROUTINE)(&KxUnexpectedInterrupt.DispatchCode);
00445 }
00446
#ifdef NOTDEF
00447
KeSweepIcache(
TRUE);
00448
#endif
00449
Interrupt->Connected =
FALSE;
00450 }
00451
00452
00453
00454
00455
00456
KiUnlockDispatcherDatabase(OldIrql);
00457
00458
00459
00460
00461
00462
KeRevertToUserAffinityThread();
00463
00464
00465
00466
00467
00468
return Connected;
00469 }