- Fix incorrect comment, spotted by Timo.
[reactos.git] / reactos / ntoskrnl / ke / i386 / irqobj.c
index 8445e94..f3d841c 100644 (file)
@@ -3,7 +3,7 @@
  * LICENSE:         GPL - See COPYING in the top level directory
  * FILE:            ntoskrnl/ke/i386/irq.c
  * PURPOSE:         Manages the Kernel's IRQ support for external drivers,
- *                  for the purpopses of connecting, disconnecting and setting
+ *                  for the purposes of connecting, disconnecting and setting
  *                  up ISRs for drivers. The backend behind the Io* Interrupt
  *                  routines.
  * PROGRAMMERS:     Alex Ionescu (alex.ionescu@reactos.org)
@@ -19,7 +19,7 @@
 
 ULONG KiISRTimeout = 55;
 USHORT KiISROverflow = 30000;
-extern ULONG KiChainedDispatch2ndLvl;
+extern ULONG NTAPI KiChainedDispatch2ndLvl(VOID);
 
 /* PRIVATE FUNCTIONS *********************************************************/
 
@@ -30,10 +30,21 @@ KiGetVectorDispatch(IN ULONG Vector,
 {
     PKINTERRUPT_ROUTINE Handler;
     ULONG Current;
+    UCHAR Type;
+    UCHAR Entry;
+
+    /* Check if this is a primary or 2nd-level dispatch */
+    Type = HalSystemVectorDispatchEntry(Vector,
+                                        &Dispatch->FlatDispatch,
+                                        &Dispatch->NoDispatch);
+    ASSERT(Type == 0);
+
+    /* Get the IDT entry for this vector */
+    Entry = HalVectorToIDTEntry(Vector);
 
     /* Setup the unhandled dispatch */
     Dispatch->NoDispatch = (PVOID)(((ULONG_PTR)&KiStartUnexpectedRange) +
-                                   (Vector - PRIMARY_VECTOR_BASE) *
+                                   (Entry - PRIMARY_VECTOR_BASE) *
                                    KiUnexpectedEntrySize);
 
     /* Setup the handlers */
@@ -43,9 +54,9 @@ KiGetVectorDispatch(IN ULONG Vector,
     Dispatch->FlatDispatch = NULL;
 
     /* Get the current handler */
-    Current = ((((PKIPCR)KeGetPcr())->IDT[Vector].ExtendedOffset << 16)
+    Current = ((((PKIPCR)KeGetPcr())->IDT[Entry].ExtendedOffset << 16)
                & 0xFFFF0000) |
-              (((PKIPCR)KeGetPcr())->IDT[Vector].Offset & 0xFFFF);
+              (((PKIPCR)KeGetPcr())->IDT[Entry].Offset & 0xFFFF);
 
     /* Set the interrupt */
     Dispatch->Interrupt = CONTAINING_RECORD(Current,
@@ -89,6 +100,7 @@ KiConnectVectorToInterrupt(IN PKINTERRUPT Interrupt,
     DISPATCH_INFO Dispatch;
     PKINTERRUPT_ROUTINE Handler;
     PULONG Patch = &Interrupt->DispatchCode[0];
+    UCHAR Entry;
 
     /* Get vector data */
     KiGetVectorDispatch(Interrupt->Vector, &Dispatch);
@@ -123,10 +135,13 @@ KiConnectVectorToInterrupt(IN PKINTERRUPT Interrupt,
         Handler = (PVOID)&Interrupt->DispatchCode;
     }
 
+    /* Get the IDT entry for this vector */
+    Entry = HalVectorToIDTEntry(Interrupt->Vector);
+
     /* Set the pointer in the IDT */
-    ((PKIPCR)KeGetPcr())->IDT[Interrupt->Vector].ExtendedOffset =
+    ((PKIPCR)KeGetPcr())->IDT[Entry].ExtendedOffset =
         (USHORT)(((ULONG_PTR)Handler >> 16) & 0xFFFF);
-    ((PKIPCR)KeGetPcr())->IDT[Interrupt->Vector].Offset =
+    ((PKIPCR)KeGetPcr())->IDT[Entry].Offset =
         (USHORT)PtrToUlong(Handler);
 }
 
@@ -178,8 +193,8 @@ KeInitializeInterrupt(IN PKINTERRUPT Interrupt,
     Interrupt->ShareVector = ShareVector;
     Interrupt->Number = ProcessorNumber;
     Interrupt->FloatingSave = FloatingSave;
-    Interrupt->TickCount = (ULONG)-1;
-    Interrupt->DispatchCount = (ULONG)-1;
+    Interrupt->TickCount = MAXULONG;
+    Interrupt->DispatchCount = MAXULONG;
 
     /* Loop the template in memory */
     for (i = 0; i < KINTERRUPT_DISPATCH_CODES; i++)
@@ -265,13 +280,17 @@ KeConnectInterrupt(IN PKINTERRUPT Interrupt)
                 (Dispatch.Interrupt->Mode == Interrupt->Mode))
         {
             /* The vector is shared and the interrupts are compatible */
-            while (TRUE); // FIXME: NOT YET SUPPORTED/TESTED
             Interrupt->Connected = Connected = TRUE;
-            ASSERT(Irql <= SYNCH_LEVEL);
+
+            /* FIXME */
+            // ASSERT(Irql <= SYNCH_LEVEL);
 
             /* Check if this is the first chain */
             if (Dispatch.Type != ChainConnect)
             {
+                /* This is not supported */
+                ASSERT(Dispatch.Interrupt->Mode != Latched);
+
                 /* Setup the chainned handler */
                 KiConnectVectorToInterrupt(Dispatch.Interrupt, ChainConnect);
             }