[NTOSKRNL]
[reactos.git] / reactos / ntoskrnl / include / internal / amd64 / ke.h
index 001c402..7fec19a 100644 (file)
@@ -116,6 +116,12 @@ extern ULONG KeI386CpuStep;
 #define KeGetContextSwitches(Prcb)  \
     (Prcb->KeContextSwitches)
 
+//
+// Macro to get the second level cache size field name which differs between
+// CISC and RISC architectures, as the former has unified I/D cache
+//
+#define KiGetSecondLevelDCacheSize() ((PKIPCR)KeGetPcr())->SecondLevelCacheSize
+
 #define KeGetExceptionFrame(Thread) \
     (PKEXCEPTION_FRAME)((ULONG_PTR)KeGetTrapFrame(Thread) - \
                         sizeof(KEXCEPTION_FRAME))
@@ -146,13 +152,6 @@ KeFlushProcessTb(VOID)
     __writecr3(__readcr3());
 }
 
-FORCEINLINE
-PRKTHREAD
-KeGetCurrentThread(VOID)
-{
-    return (PRKTHREAD)__readgsqword(FIELD_OFFSET(KIPCR, Prcb.CurrentThread));
-}
-
 FORCEINLINE
 VOID
 KiRundownThread(IN PKTHREAD Thread)
@@ -164,6 +163,52 @@ KiRundownThread(IN PKTHREAD Thread)
 #endif
 }
 
+/* Registers an interrupt handler with an IDT vector */
+FORCEINLINE
+VOID
+KeRegisterInterruptHandler(IN ULONG Vector,
+                           IN PVOID Handler)
+{                           
+    UCHAR Entry;
+    PKIDTENTRY64 Idt;
+
+    /* Get the entry from the HAL */
+    Entry = HalVectorToIDTEntry(Vector);
+
+    /* Now set the data */
+    Idt = &KeGetPcr()->IdtBase[Entry];
+    Idt->OffsetLow = (ULONG_PTR)Handler & 0xffff;
+    Idt->OffsetMiddle = ((ULONG_PTR)Handler >> 16) & 0xffff;
+    Idt->OffsetHigh = (ULONG_PTR)Handler >> 32;
+    Idt->Selector = KGDT64_R0_CODE;
+    Idt->IstIndex = 0;
+    Idt->Type = 0x0e;
+    Idt->Dpl = 0;
+    Idt->Present = 1;
+    Idt->Reserved0 = 0;
+    Idt->Reserved1 = 0;
+}
+
+/* Returns the registered interrupt handler for a given IDT vector */
+FORCEINLINE
+PVOID
+KeQueryInterruptHandler(IN ULONG Vector)
+{
+    UCHAR Entry;
+    PKIDTENTRY64 Idt;
+
+    /* Get the entry from the HAL */
+    Entry = HalVectorToIDTEntry(Vector);
+
+    /* Get the IDT entry */
+    Idt = &KeGetPcr()->IdtBase[Entry];
+
+    /* Return the address */
+    return (PVOID)((ULONG64)Idt->OffsetHigh << 32 | 
+                   (ULONG64)Idt->OffsetMiddle << 16 | 
+                   (ULONG64)Idt->OffsetLow);
+}
+
 VOID
 FORCEINLINE
 KiEndInterrupt(IN KIRQL Irql,
@@ -269,7 +314,14 @@ KiThreadStartup(PKSYSTEM_ROUTINE SystemRoutine,
                 KTRAP_FRAME TrapFrame);
 #endif
 
-#endif
+#endif /* __ASM__ */
+
+#undef KeGetCurrentThread
+#define _KeGetCurrentThread KeGetCurrentThread
+
+// HACK
+extern NTKERNELAPI volatile KSYSTEM_TIME KeTickCount;
+
 #endif /* __NTOSKRNL_INCLUDE_INTERNAL_AMD64_KE_H */
 
 /* EOF */