[NTOSKRNL]
[reactos.git] / reactos / ntoskrnl / include / internal / amd64 / ke.h
index fc54171..7fec19a 100644 (file)
@@ -109,6 +109,19 @@ extern ULONG KeI386CpuStep;
     (PKTRAP_FRAME)((ULONG_PTR)((Thread)->InitialStack) - \
                    sizeof(KTRAP_FRAME))
 
+//
+// Macro to get context switches from the PRCB
+// All architectures but x86 have it in the PRCB's KeContextSwitches
+//
+#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))
@@ -139,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)
@@ -157,6 +163,62 @@ 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,
+               IN PKTRAP_FRAME TrapFrame)
+{
+    DbgPrint("KiEndInterrupt is unimplemented\n");
+}
+
+#define Ki386PerfEnd(x)
+
 struct _KPCR;
 
 VOID
@@ -252,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 */