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