ReactOS  r76032
ke.h File Reference
#include "intrin_i.h"
#include <pshpack1.h>
#include <poppack.h>
Include dependency graph for ke.h:

Go to the source code of this file.

Classes

struct  _KIDT_INIT
 
struct  _KI_INTERRUPT_DISPATCH_ENTRY
 

Macros

#define X86_EFLAGS_TF   0x00000100 /* Trap flag */
 
#define X86_EFLAGS_IF   0x00000200 /* Interrupt Enable flag */
 
#define X86_EFLAGS_IOPL   0x00003000 /* I/O Privilege Level bits */
 
#define X86_EFLAGS_NT   0x00004000 /* Nested Task flag */
 
#define X86_EFLAGS_RF   0x00010000 /* Resume flag */
 
#define X86_EFLAGS_VM   0x00020000 /* Virtual Mode */
 
#define X86_EFLAGS_ID   0x00200000 /* CPUID detection flag */
 
#define X86_CR0_PE   0x00000001 /* enable Protected Mode */
 
#define X86_CR0_NE   0x00000020 /* enable native FPU error reporting */
 
#define X86_CR0_TS   0x00000008 /* enable exception on FPU instruction for task switch */
 
#define X86_CR0_EM   0x00000004 /* enable FPU emulation (disable FPU) */
 
#define X86_CR0_MP   0x00000002 /* enable FPU monitoring */
 
#define X86_CR0_WP   0x00010000 /* enable Write Protect (copy on write) */
 
#define X86_CR0_PG   0x80000000 /* enable Paging */
 
#define X86_CR4_PAE   0x00000020 /* enable physical address extensions */
 
#define X86_CR4_PGE   0x00000080 /* enable global pages */
 
#define X86_CR4_OSFXSR   0x00000200 /* enable FXSAVE/FXRSTOR instructions */
 
#define X86_CR4_OSXMMEXCPT   0x00000400 /* enable #XF exception */
 
#define X86_FEATURE_VME   0x00000002 /* Virtual 8086 Extensions are present */
 
#define X86_FEATURE_TSC   0x00000010 /* time stamp counters are present */
 
#define X86_FEATURE_PAE   0x00000040 /* physical address extension is present */
 
#define X86_FEATURE_CX8   0x00000100 /* CMPXCHG8B instruction present */
 
#define X86_FEATURE_SYSCALL   0x00000800 /* SYSCALL/SYSRET support present */
 
#define X86_FEATURE_PGE   0x00002000 /* Page Global Enable */
 
#define X86_FEATURE_MMX   0x00800000 /* MMX extension present */
 
#define X86_FEATURE_FXSR   0x01000000 /* FXSAVE/FXRSTOR instructions present */
 
#define X86_FEATURE_SSE   0x02000000 /* SSE extension present */
 
#define X86_FEATURE_SSE2   0x04000000 /* SSE2 extension present */
 
#define X86_FEATURE_HT   0x10000000 /* Hyper-Threading present */
 
#define X86_EXT_FEATURE_SSE3   0x00000001 /* SSE3 extension present */
 
#define X86_EXT_FEATURE_3DNOW   0x40000000 /* 3DNOW! extension present */
 
#define FRAME_EDITED   0xFFF8
 
#define X86_MSR_GSBASE   0xC0000101
 
#define X86_MSR_KERNEL_GSBASE   0xC0000102
 
#define X86_MSR_EFER   0xC0000080
 
#define X86_MSR_STAR   0xC0000081
 
#define X86_MSR_LSTAR   0xC0000082
 
#define X86_MSR_CSTAR   0xC0000083
 
#define X86_MSR_SFMASK   0xC0000084
 
#define EFER_SCE   0x01
 
#define EFER_LME   0x10
 
#define EFER_LMA   0x40
 
#define EFER_NXE   0x80
 
#define EFER_SVME   0x100
 
#define EFER_FFXSR   0x400
 
#define AMD64_TSS   9
 
#define APIC_EOI_REGISTER   0xFFFFFFFFFFFE00B0ULL
 
#define KD_BREAKPOINT_TYPE   UCHAR
 
#define KD_BREAKPOINT_SIZE   sizeof(UCHAR)
 
#define KD_BREAKPOINT_VALUE   0xCC
 
#define KeGetContextPc(Context)   ((Context)->Rip)
 
#define KeSetContextPc(Context, ProgramCounter)   ((Context)->Rip = (ProgramCounter))
 
#define KeGetTrapFramePc(TrapFrame)   ((TrapFrame)->Rip)
 
#define KiGetLinkedTrapFrame(x)   (PKTRAP_FRAME)((x)->TrapFrame)
 
#define KeGetContextReturnRegister(Context)   ((Context)->Rax)
 
#define KeSetContextReturnRegister(Context, ReturnValue)   ((Context)->Rax = (ReturnValue))
 
#define KeGetTrapFrame(Thread)
 
#define KeGetContextSwitches(Prcb)   (Prcb->KeContextSwitches)
 
#define KiGetSecondLevelDCacheSize()   ((PKIPCR)KeGetPcr())->SecondLevelCacheSize
 
#define KeGetExceptionFrame(Thread)
 
#define KeGetTrapFrameInterruptState(TrapFrame)   BooleanFlagOn((TrapFrame)->EFlags, EFLAGS_INTERRUPT_MASK)
 
#define Ki386PerfEnd()
 
#define KeArchInitThreadWithContext(Thread, SystemRoutine, StartRoutine, StartContext, Context)   Ke386InitThreadWithContext(Thread,SystemRoutine,StartRoutine,StartContext,Context)
 

Typedefs

typedef struct _KIDT_INIT KIDT_INIT
 
typedef struct _KIDT_INITPKIDT_INIT
 
typedef struct
_KI_INTERRUPT_DISPATCH_ENTRY 
KI_INTERRUPT_DISPATCH_ENTRY
 
typedef struct
_KI_INTERRUPT_DISPATCH_ENTRY
PKI_INTERRUPT_DISPATCH_ENTRY
 

Functions

FORCEINLINE BOOLEAN KeDisableInterrupts (VOID)
 
FORCEINLINE VOID KeRestoreInterrupts (BOOLEAN WereEnabled)
 
FORCEINLINE VOID KeInvalidateTlbEntry (IN PVOID Address)
 
FORCEINLINE VOID KeFlushProcessTb (VOID)
 
FORCEINLINE VOID KeSweepICache (IN PVOID BaseAddress, IN SIZE_T FlushSize)
 
FORCEINLINE VOID KiRundownThread (IN PKTHREAD Thread)
 
FORCEINLINE VOID KeRegisterInterruptHandler (IN ULONG Vector, IN PVOID Handler)
 
FORCEINLINE PVOID KeQueryInterruptHandler (IN ULONG Vector)
 
VOID FORCEINLINE KiSendEOI (VOID)
 
VOID FORCEINLINE KiEndInterrupt (IN KIRQL Irql, IN PKTRAP_FRAME TrapFrame)
 
BOOLEAN FORCEINLINE KiUserTrap (IN PKTRAP_FRAME TrapFrame)
 
VOID KiSwitchToBootStack (IN ULONG_PTR InitialStack)
 
VOID KiDivideErrorFault (VOID)
 
VOID KiDebugTrapOrFault (VOID)
 
VOID KiNmiInterrupt (VOID)
 
VOID KiBreakpointTrap (VOID)
 
VOID KiOverflowTrap (VOID)
 
VOID KiBoundFault (VOID)
 
VOID KiInvalidOpcodeFault (VOID)
 
VOID KiNpxNotAvailableFault (VOID)
 
VOID KiDoubleFaultAbort (VOID)
 
VOID KiNpxSegmentOverrunAbort (VOID)
 
VOID KiInvalidTssFault (VOID)
 
VOID KiSegmentNotPresentFault (VOID)
 
VOID KiStackFault (VOID)
 
VOID KiGeneralProtectionFault (VOID)
 
VOID KiPageFault (VOID)
 
VOID KiFloatingErrorFault (VOID)
 
VOID KiAlignmentFault (VOID)
 
VOID KiMcheckAbort (VOID)
 
VOID KiXmmException (VOID)
 
VOID KiApcInterrupt (VOID)
 
VOID KiRaiseAssertion (VOID)
 
VOID KiDebugServiceTrap (VOID)
 
VOID KiDpcInterrupt (VOID)
 
VOID KiIpiInterrupt (VOID)
 
VOID KiGdtPrepareForApplicationProcessorInit (ULONG Id)
 
VOID Ki386InitializeLdt (VOID)
 
VOID Ki386SetProcessorFeatures (VOID)
 
VOID KiGetCacheInformation (VOID)
 
VOID KiSetProcessorType (VOID)
 
ULONG KiGetFeatureBits (VOID)
 
VOID KiInitializeCpuFeatures (VOID)
 
ULONG KeAllocateGdtSelector (ULONG Desc[2])
 
VOID KeFreeGdtSelector (ULONG Entry)
 
VOID NtEarlyInitVdm (VOID)
 
VOID KeApplicationProcessorInitDispatcher (VOID)
 
VOID KeCreateApplicationProcessorIdleThread (ULONG Id)
 
VOID Ke386InitThreadWithContext (PKTHREAD Thread, PKSYSTEM_ROUTINE SystemRoutine, PKSTART_ROUTINE StartRoutine, PVOID StartContext, PCONTEXT Context)
 
NTHALAPI NTSTATUS NTAPI HalAllocateAdapterChannel (IN PADAPTER_OBJECT AdapterObject, IN PWAIT_CONTEXT_BLOCK Wcb, IN ULONG NumberOfMapRegisters, IN PDRIVER_CONTROL ExecutionRoutine)
 

Variables

ULONG KeI386NpxPresent
 
ULONG KeI386XMMIPresent
 
ULONG KeI386FxsrPresent
 
ULONG KeI386CpuType
 
ULONG KeI386CpuStep
 
NTKERNELAPI volatile KSYSTEM_TIME KeTickCount
 

Macro Definition Documentation

#define AMD64_TSS   9

Definition at line 57 of file ke.h.

Referenced by KiInitializeTss().

#define APIC_EOI_REGISTER   0xFFFFFFFFFFFE00B0ULL

Definition at line 59 of file ke.h.

Referenced by KiSendEOI().

#define EFER_FFXSR   0x400

Definition at line 55 of file ke.h.

#define EFER_LMA   0x40

Definition at line 52 of file ke.h.

#define EFER_LME   0x10

Definition at line 51 of file ke.h.

#define EFER_NXE   0x80

Definition at line 53 of file ke.h.

Referenced by MiInitializePageTable().

#define EFER_SCE   0x01

Definition at line 50 of file ke.h.

#define EFER_SVME   0x100

Definition at line 54 of file ke.h.

#define FRAME_EDITED   0xFFF8
#define KD_BREAKPOINT_TYPE   UCHAR

Definition at line 93 of file ke.h.

Referenced by handle_gdb_c(), KdpAddBreakpoint(), and KdSetOwedBreakpoints().

#define KD_BREAKPOINT_VALUE   0xCC

Definition at line 95 of file ke.h.

Referenced by handle_gdb_c().

#define KeArchInitThreadWithContext (   Thread,
  SystemRoutine,
  StartRoutine,
  StartContext,
  Context 
)    Ke386InitThreadWithContext(Thread,SystemRoutine,StartRoutine,StartContext,Context)

Definition at line 339 of file ke.h.

#define KeGetContextPc (   Context)    ((Context)->Rip)

Definition at line 100 of file ke.h.

Referenced by KdpEnterDebuggerException(), KdpSetCommonState(), KdpStub(), KdpTrap(), and PspCreateThread().

#define KeGetContextReturnRegister (   Context)    ((Context)->Rax)

Definition at line 112 of file ke.h.

Referenced by PspCreateThread().

#define KeGetContextSwitches (   Prcb)    (Prcb->KeContextSwitches)

Definition at line 129 of file ke.h.

Referenced by QSI_DEF().

#define KeGetExceptionFrame (   Thread)
Value:
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
uint32_t ULONG_PTR
Definition: typedefs.h:63
struct _KEXCEPTION_FRAME * PKEXCEPTION_FRAME
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
#define KeGetTrapFrame(Thread)
Definition: ke.h:121

Definition at line 138 of file ke.h.

Referenced by PspUserThreadStartup().

#define KeGetTrapFrame (   Thread)
Value:
(PKTRAP_FRAME)((ULONG_PTR)((Thread)->InitialStack) - \
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
uint32_t ULONG_PTR
Definition: typedefs.h:63
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
struct _KTRAP_FRAME * PKTRAP_FRAME

Definition at line 121 of file ke.h.

Referenced by Ke386SetIOPL(), KiSwapContextExit(), KiTrap0EHandler(), PspGetOrSetContextKernelRoutine(), PspUserThreadStartup(), and RtlWalkFrameChain().

#define KeGetTrapFrameInterruptState (   TrapFrame)    BooleanFlagOn((TrapFrame)->EFlags, EFLAGS_INTERRUPT_MASK)

Definition at line 146 of file ke.h.

Referenced by KdpQueryPerformanceCounter().

#define KeGetTrapFramePc (   TrapFrame)    ((TrapFrame)->Rip)

Definition at line 106 of file ke.h.

Referenced by KeBugCheckWithTf(), and KiParseProfileList().

#define KeSetContextPc (   Context,
  ProgramCounter 
)    ((Context)->Rip = (ProgramCounter))

Definition at line 103 of file ke.h.

Referenced by KdpEnterDebuggerException(), KdpStub(), and KdpTrap().

#define KeSetContextReturnRegister (   Context,
  ReturnValue 
)    ((Context)->Rax = (ReturnValue))

Definition at line 115 of file ke.h.

Referenced by KdpEnterDebuggerException(), and KdpTrap().

#define Ki386PerfEnd ( )

Definition at line 287 of file ke.h.

#define KiGetLinkedTrapFrame (   x)    (PKTRAP_FRAME)((x)->TrapFrame)

Definition at line 109 of file ke.h.

Referenced by KiSystemService(), NtContinue(), and NtRaiseException().

#define KiGetSecondLevelDCacheSize ( )    ((PKIPCR)KeGetPcr())->SecondLevelCacheSize

Definition at line 136 of file ke.h.

#define X86_CR0_EM   0x00000004 /* enable FPU emulation (disable FPU) */

Definition at line 15 of file ke.h.

#define X86_CR0_MP   0x00000002 /* enable FPU monitoring */

Definition at line 16 of file ke.h.

#define X86_CR0_NE   0x00000020 /* enable native FPU error reporting */

Definition at line 13 of file ke.h.

#define X86_CR0_PE   0x00000001 /* enable Protected Mode */

Definition at line 12 of file ke.h.

#define X86_CR0_PG   0x80000000 /* enable Paging */

Definition at line 18 of file ke.h.

#define X86_CR0_TS   0x00000008 /* enable exception on FPU instruction for task switch */

Definition at line 14 of file ke.h.

#define X86_CR0_WP   0x00010000 /* enable Write Protect (copy on write) */

Definition at line 17 of file ke.h.

#define X86_CR4_OSFXSR   0x00000200 /* enable FXSAVE/FXRSTOR instructions */

Definition at line 22 of file ke.h.

#define X86_CR4_OSXMMEXCPT   0x00000400 /* enable #XF exception */

Definition at line 23 of file ke.h.

#define X86_CR4_PAE   0x00000020 /* enable physical address extensions */

Definition at line 20 of file ke.h.

#define X86_CR4_PGE   0x00000080 /* enable global pages */

Definition at line 21 of file ke.h.

#define X86_EFLAGS_ID   0x00200000 /* CPUID detection flag */

Definition at line 10 of file ke.h.

#define X86_EFLAGS_IF   0x00000200 /* Interrupt Enable flag */

Definition at line 5 of file ke.h.

#define X86_EFLAGS_IOPL   0x00003000 /* I/O Privilege Level bits */

Definition at line 6 of file ke.h.

#define X86_EFLAGS_NT   0x00004000 /* Nested Task flag */

Definition at line 7 of file ke.h.

#define X86_EFLAGS_RF   0x00010000 /* Resume flag */

Definition at line 8 of file ke.h.

#define X86_EFLAGS_TF   0x00000100 /* Trap flag */

Definition at line 4 of file ke.h.

#define X86_EFLAGS_VM   0x00020000 /* Virtual Mode */

Definition at line 9 of file ke.h.

#define X86_EXT_FEATURE_3DNOW   0x40000000 /* 3DNOW! extension present */

Definition at line 38 of file ke.h.

#define X86_EXT_FEATURE_SSE3   0x00000001 /* SSE3 extension present */

Definition at line 37 of file ke.h.

#define X86_FEATURE_CX8   0x00000100 /* CMPXCHG8B instruction present */

Definition at line 28 of file ke.h.

#define X86_FEATURE_FXSR   0x01000000 /* FXSAVE/FXRSTOR instructions present */

Definition at line 32 of file ke.h.

#define X86_FEATURE_HT   0x10000000 /* Hyper-Threading present */

Definition at line 35 of file ke.h.

#define X86_FEATURE_MMX   0x00800000 /* MMX extension present */

Definition at line 31 of file ke.h.

#define X86_FEATURE_PAE   0x00000040 /* physical address extension is present */

Definition at line 27 of file ke.h.

#define X86_FEATURE_PGE   0x00002000 /* Page Global Enable */

Definition at line 30 of file ke.h.

#define X86_FEATURE_SSE   0x02000000 /* SSE extension present */

Definition at line 33 of file ke.h.

#define X86_FEATURE_SSE2   0x04000000 /* SSE2 extension present */

Definition at line 34 of file ke.h.

#define X86_FEATURE_SYSCALL   0x00000800 /* SYSCALL/SYSRET support present */

Definition at line 29 of file ke.h.

#define X86_FEATURE_TSC   0x00000010 /* time stamp counters are present */

Definition at line 26 of file ke.h.

#define X86_FEATURE_VME   0x00000002 /* Virtual 8086 Extensions are present */

Definition at line 25 of file ke.h.

#define X86_MSR_CSTAR   0xC0000083

Definition at line 47 of file ke.h.

Referenced by KiRestoreProcessorControlState(), and KiSaveProcessorControlState().

#define X86_MSR_EFER   0xC0000080

Definition at line 44 of file ke.h.

Referenced by MiInitializePageTable().

#define X86_MSR_GSBASE   0xC0000101

Definition at line 42 of file ke.h.

Referenced by KiRestoreProcessorControlState(), and KiSaveProcessorControlState().

#define X86_MSR_KERNEL_GSBASE   0xC0000102

Definition at line 43 of file ke.h.

Referenced by KiRestoreProcessorControlState(), and KiSaveProcessorControlState().

#define X86_MSR_LSTAR   0xC0000082

Definition at line 46 of file ke.h.

Referenced by KiRestoreProcessorControlState(), and KiSaveProcessorControlState().

#define X86_MSR_SFMASK   0xC0000084

Definition at line 48 of file ke.h.

Referenced by KiRestoreProcessorControlState(), and KiSaveProcessorControlState().

#define X86_MSR_STAR   0xC0000081

Definition at line 45 of file ke.h.

Referenced by KiRestoreProcessorControlState(), and KiSaveProcessorControlState().

Typedef Documentation

Function Documentation

NTHALAPI NTSTATUS NTAPI HalAllocateAdapterChannel ( IN PADAPTER_OBJECT  AdapterObject,
IN PWAIT_CONTEXT_BLOCK  Wcb,
IN ULONG  NumberOfMapRegisters,
IN PDRIVER_CONTROL  ExecutionRoutine 
)

Definition at line 88 of file dma.c.

Referenced by HalGetScatterGatherList(), and IoAllocateAdapterChannel().

92 {
94  while (TRUE);
95  return STATUS_SUCCESS;
96 }
#define TRUE
Definition: types.h:120
return STATUS_SUCCESS
Definition: btrfs.c:2664
#define UNIMPLEMENTED
Definition: debug.h:114
VOID Ke386InitThreadWithContext ( PKTHREAD  Thread,
PKSYSTEM_ROUTINE  SystemRoutine,
PKSTART_ROUTINE  StartRoutine,
PVOID  StartContext,
PCONTEXT  Context 
)
ULONG KeAllocateGdtSelector ( ULONG  Desc[2])
VOID KeApplicationProcessorInitDispatcher ( VOID  )
VOID KeCreateApplicationProcessorIdleThread ( ULONG  Id)
FORCEINLINE BOOLEAN KeDisableInterrupts ( VOID  )

Definition at line 152 of file ke.h.

Referenced by _ExiDisableInterruptsAndAcquireSpinlock(), KdPollBreakIn(), KeFreezeExecution(), KeRemoveQueueDpc(), and Ki386EnableGlobalPage().

153 {
155 
156  /* Get EFLAGS and check if the interrupt bit is set */
157  Flags = __readeflags();
158 
159  /* Disable interrupts */
160  _disable();
161  return (Flags & EFLAGS_INTERRUPT_MASK) ? TRUE : FALSE;
162 }
#define TRUE
Definition: types.h:120
uint32_t ULONG_PTR
Definition: typedefs.h:63
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
__INTRIN_INLINE uintptr_t __readeflags(void)
Definition: intrin_x86.h:1456
#define FALSE
Definition: types.h:117
void __cdecl _disable(void)
Definition: intrin_arm.h:365
#define EFLAGS_INTERRUPT_MASK
Definition: ketypes.h:126
FORCEINLINE VOID KeFlushProcessTb ( VOID  )

Definition at line 185 of file ke.h.

Referenced by MiMapPageInHyperSpace(), MiMapPagesInZeroSpace(), MiReserveAlignedSystemPtes(), and MiUnmapLockedPagesInUserSpace().

186 {
187  /* Flush the TLB by resetting CR3 */
189 }
__INTRIN_INLINE unsigned long __readcr3(void)
Definition: intrin_x86.h:1601
__INTRIN_INLINE void __writecr3(unsigned int Data)
Definition: intrin_x86.h:1572
VOID KeFreeGdtSelector ( ULONG  Entry)
FORCEINLINE VOID KeInvalidateTlbEntry ( IN PVOID  Address)

Definition at line 177 of file ke.h.

Referenced by KdpPhysMap(), MiDbgTranslatePhysicalAddress(), MiDbgUnTranslatePhysicalAddress(), MiFlushTlb(), MiProtectVirtualMemory(), and MmCreateVirtualMappingUnsafe().

178 {
179  /* Invalidate the TLB entry for this address */
180  __invlpg(Address);
181 }
PVOID ULONG Address
Definition: oprghdlr.h:14
__INTRIN_INLINE void __invlpg(void *Address)
Definition: intrin_x86.h:1758
FORCEINLINE PVOID KeQueryInterruptHandler ( IN ULONG  Vector)

Definition at line 244 of file ke.h.

Referenced by HalpSwitchToRealModeTrapHandlers(), KeConnectInterrupt(), and KiGetVectorDispatch().

245 {
246  UCHAR Entry;
247  PKIDTENTRY64 Idt;
248 
249  /* Get the entry from the HAL */
250  Entry = HalVectorToIDTEntry(Vector);
251 
252  /* Get the IDT entry */
253  Idt = &KeGetPcr()->IdtBase[Entry];
254 
255  /* Return the address */
256  return (PVOID)((ULONG64)Idt->OffsetHigh << 32 |
257  (ULONG64)Idt->OffsetMiddle << 16 |
258  (ULONG64)Idt->OffsetLow);
259 }
DWORD *typedef PVOID
Definition: winlogon.h:52
struct _Entry Entry
Definition: kefuncs.h:640
union _KIDTENTRY64 * IdtBase
Definition: ke.h:296
uint64_t ULONG64
Definition: typedefs.h:65
USHORT OffsetLow
Definition: ketypes.h:466
USHORT OffsetMiddle
Definition: ketypes.h:473
unsigned char UCHAR
Definition: xmlstorage.h:181
FORCEINLINE PKPCR KeGetPcr(VOID)
Definition: ke.h:318
ULONG OffsetHigh
Definition: ketypes.h:474
#define HalVectorToIDTEntry
Definition: halfuncs.h:50
FORCEINLINE VOID KeRegisterInterruptHandler ( IN ULONG  Vector,
IN PVOID  Handler 
)

Definition at line 218 of file ke.h.

Referenced by ApicInitializeLocalApic(), HalpEnableInterruptHandler(), HalpInitializePICs(), HalpInitializeTsc(), HalpRestoreTrapHandlers(), HalpSwitchToRealModeTrapHandlers(), KeConnectInterrupt(), and KiConnectVectorToInterrupt().

220 {
221  UCHAR Entry;
222  PKIDTENTRY64 Idt;
223 
224  /* Get the entry from the HAL */
225  Entry = HalVectorToIDTEntry(Vector);
226 
227  /* Now set the data */
228  Idt = &KeGetPcr()->IdtBase[Entry];
229  Idt->OffsetLow = (ULONG_PTR)Handler & 0xffff;
230  Idt->OffsetMiddle = ((ULONG_PTR)Handler >> 16) & 0xffff;
231  Idt->OffsetHigh = (ULONG_PTR)Handler >> 32;
232  Idt->Selector = KGDT64_R0_CODE;
233  Idt->IstIndex = 0;
234  Idt->Type = 0x0e;
235  Idt->Dpl = 0;
236  Idt->Present = 1;
237  Idt->Reserved0 = 0;
238  Idt->Reserved1 = 0;
239 }
struct _Entry Entry
Definition: kefuncs.h:640
union _KIDTENTRY64 * IdtBase
Definition: ke.h:296
USHORT Selector
Definition: ketypes.h:467
USHORT OffsetLow
Definition: ketypes.h:466
USHORT Reserved0
Definition: ketypes.h:469
USHORT Type
Definition: ketypes.h:470
USHORT Present
Definition: ketypes.h:472
USHORT OffsetMiddle
Definition: ketypes.h:473
#define KGDT64_R0_CODE
Definition: ketypes.h:72
USHORT IstIndex
Definition: ketypes.h:468
unsigned char UCHAR
Definition: xmlstorage.h:181
USHORT Dpl
Definition: ketypes.h:471
ULONG Reserved1
Definition: ketypes.h:475
ACPI_PHYSICAL_ADDRESS ACPI_SIZE BOOLEAN Warn BOOLEAN Physical UINT32 ACPI_TABLE_HEADER *OutTableHeader ACPI_TABLE_HEADER **OutTable ACPI_HANDLE UINT32 ACPI_WALK_CALLBACK ACPI_WALK_CALLBACK void void **ReturnValue UINT32 ACPI_BUFFER *RetPathPtr ACPI_OBJECT_HANDLER Handler
Definition: acpixf.h:658
FORCEINLINE PKPCR KeGetPcr(VOID)
Definition: ke.h:318
#define ULONG_PTR
Definition: config.h:101
ULONG OffsetHigh
Definition: ketypes.h:474
#define HalVectorToIDTEntry
Definition: halfuncs.h:50
FORCEINLINE VOID KeRestoreInterrupts ( BOOLEAN  WereEnabled)

Definition at line 167 of file ke.h.

Referenced by _ExiReleaseSpinLockAndRestoreInterrupts(), and Ki386EnableGlobalPage().

168 {
169  if (WereEnabled) _enable();
170 }
void __cdecl _enable(void)
Definition: intrin_arm.h:373
FORCEINLINE VOID KeSweepICache ( IN PVOID  BaseAddress,
IN SIZE_T  FlushSize 
)

Definition at line 193 of file ke.h.

Referenced by KdpCopyMemoryChunks(), and NtFlushInstructionCache().

195 {
196  //
197  // Always sweep the whole cache
198  //
200  UNREFERENCED_PARAMETER(FlushSize);
201  __wbinvd();
202 }
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:315
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
PPC_QUAL void __wbinvd(void)
Definition: intrin_ppc.h:759
VOID Ki386InitializeLdt ( VOID  )
VOID Ki386SetProcessorFeatures ( VOID  )
VOID KiAlignmentFault ( VOID  )
VOID KiApcInterrupt ( VOID  )

Definition at line 228 of file trapc.c.

Referenced by KiInitializePcr().

229 {
231  KEXCEPTION_FRAME ExceptionFrame;
232  PKTRAP_FRAME TrapFrame = KeGetCurrentThread()->TrapFrame;
233 
234  DPRINT1("[APC TRAP]\n");
235  while (TRUE);
236 
237  //
238  // Isolate previous mode
239  //
240  PreviousMode = KiGetPreviousMode(TrapFrame);
241 
242  //
243  // FIXME-USER: Handle APC interrupt while in user-mode
244  //
245  if (PreviousMode == UserMode) ASSERT(FALSE);
246 
247  //
248  // Disable interrupts
249  //
250  _disable();
251 
252  //
253  // Clear APC interrupt
254  //
256 
257  //
258  // Re-enable interrupts
259  //
260  _enable();
261 
262  //
263  // Deliver APCs
264  //
265  KiDeliverApc(PreviousMode, &ExceptionFrame, TrapFrame);
266 }
#define TRUE
Definition: types.h:120
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
void __cdecl _enable(void)
Definition: intrin_arm.h:373
#define FALSE
Definition: types.h:117
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
#define KiGetPreviousMode(tf)
Definition: ke.h:180
#define DPRINT1
Definition: precomp.h:8
VOID FASTCALL HalClearSoftwareInterrupt(IN KIRQL Irql)
Definition: pic.c:282
void __cdecl _disable(void)
Definition: intrin_arm.h:365
#define KeGetCurrentThread
Definition: hal.h:44
VOID NTAPI KiDeliverApc(IN KPROCESSOR_MODE DeliveryMode, IN PKEXCEPTION_FRAME ExceptionFrame, IN PKTRAP_FRAME TrapFrame)
Definition: apc.c:302
#define APC_LEVEL
Definition: env_spec_w32.h:695
VOID KiBoundFault ( VOID  )
VOID KiBreakpointTrap ( VOID  )
VOID KiDebugServiceTrap ( VOID  )
VOID KiDebugTrapOrFault ( VOID  )
VOID KiDivideErrorFault ( VOID  )
VOID KiDoubleFaultAbort ( VOID  )
VOID KiDpcInterrupt ( VOID  )
VOID FORCEINLINE KiEndInterrupt ( IN KIRQL  Irql,
IN PKTRAP_FRAME  TrapFrame 
)

Definition at line 271 of file ke.h.

273 {
274  /* Make sure this is from the clock handler */
275  ASSERT(TrapFrame->ErrorCode == 0xc10c4);
276  //KeLowerIrql(Irql);
277 }
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
VOID KiFloatingErrorFault ( VOID  )
VOID KiGdtPrepareForApplicationProcessorInit ( ULONG  Id)
VOID KiGeneralProtectionFault ( VOID  )
VOID KiGetCacheInformation ( VOID  )

Definition at line 224 of file cpu.c.

Referenced by KiSystemStartupBootStack().

225 {
226  PKIPCR Pcr = (PKIPCR)KeGetPcr();
227  ULONG Vendor;
228  ULONG CacheRequests = 0, i;
229  ULONG CurrentRegister;
230  UCHAR RegisterByte;
231  BOOLEAN FirstPass = TRUE;
232  CPU_INFO CpuInfo;
233 
234  /* Set default L2 size */
235  Pcr->SecondLevelCacheSize = 0;
236 
237  /* Get the Vendor ID and make sure we support CPUID */
238  Vendor = KiGetCpuVendor();
239  if (!Vendor) return;
240 
241  /* Check the Vendor ID */
242  switch (Vendor)
243  {
244  /* Handle Intel case */
245  case CPU_INTEL:
246 
247  /*Check if we support CPUID 2 */
248  KiCpuId(&CpuInfo, 0);
249  if (CpuInfo.Eax >= 2)
250  {
251  /* We need to loop for the number of times CPUID will tell us to */
252  do
253  {
254  /* Do the CPUID call */
255  KiCpuId(&CpuInfo, 2);
256 
257  /* Check if it was the first call */
258  if (FirstPass)
259  {
260  /*
261  * The number of times to loop is the first byte. Read
262  * it and then destroy it so we don't get confused.
263  */
264  CacheRequests = CpuInfo.Eax & 0xFF;
265  CpuInfo.Eax &= 0xFFFFFF00;
266 
267  /* Don't go over this again */
268  FirstPass = FALSE;
269  }
270 
271  /* Loop all 4 registers */
272  for (i = 0; i < 4; i++)
273  {
274  /* Get the current register */
275  CurrentRegister = CpuInfo.AsUINT32[i];
276 
277  /*
278  * If the upper bit is set, then this register should
279  * be skipped.
280  */
281  if (CurrentRegister & 0x80000000) continue;
282 
283  /* Keep looping for every byte inside this register */
284  while (CurrentRegister)
285  {
286  /* Read a byte, skip a byte. */
287  RegisterByte = (UCHAR)(CurrentRegister & 0xFF);
288  CurrentRegister >>= 8;
289  if (!RegisterByte) continue;
290 
291  /*
292  * Valid values are from 0x40 (0 bytes) to 0x49
293  * (32MB), or from 0x80 to 0x89 (same size but
294  * 8-way associative.
295  */
296  if (((RegisterByte > 0x40) &&
297  (RegisterByte <= 0x49)) ||
298  ((RegisterByte > 0x80) &&
299  (RegisterByte <= 0x89)))
300  {
301  /* Mask out only the first nibble */
302  RegisterByte &= 0x0F;
303 
304  /* Set the L2 Cache Size */
305  Pcr->SecondLevelCacheSize = 0x10000 <<
306  RegisterByte;
307  }
308  }
309  }
310  } while (--CacheRequests);
311  }
312  break;
313 
314  case CPU_AMD:
315 
316  /* Check if we support CPUID 0x80000006 */
317  KiCpuId(&CpuInfo, 0x80000000);
318  if (CpuInfo.Eax >= 6)
319  {
320  /* Get 2nd level cache and tlb size */
321  KiCpuId(&CpuInfo, 0x80000006);
322 
323  /* Set the L2 Cache Size */
324  Pcr->SecondLevelCacheSize = (CpuInfo.Ecx & 0xFFFF0000) >> 6;
325  }
326  break;
327  }
328 }
#define TRUE
Definition: types.h:120
struct _KIPCR * PKIPCR
#define KeGetPcr()
Definition: ke.h:25
ULONG NTAPI KiGetCpuVendor(VOID)
Definition: cpu.c:95
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define FALSE
Definition: types.h:117
ULONG SecondLevelCacheSize
Definition: ketypes.h:881
ULONG Eax
Definition: ketypes.h:296
unsigned char BOOLEAN
ULONG Ecx
Definition: ketypes.h:298
unsigned char UCHAR
Definition: xmlstorage.h:181
UINT32 AsUINT32[4]
Definition: ketypes.h:293
unsigned int ULONG
Definition: retypes.h:1
ULONG KiGetFeatureBits ( VOID  )

Definition at line 135 of file cpu.c.

136 {
137  PKPRCB Prcb = KeGetCurrentPrcb();
138  ULONG Vendor;
139  ULONG FeatureBits = KF_WORKING_PTE;
140  CPU_INFO CpuInfo;
141 
142  /* Get the Vendor ID */
143  Vendor = KiGetCpuVendor();
144 
145  /* Make sure we got a valid vendor ID at least. */
146  if (!Vendor) return FeatureBits;
147 
148  /* Get the CPUID Info. */
149  KiCpuId(&CpuInfo, 1);
150 
151  /* Set the initial APIC ID */
152  Prcb->InitialApicId = (UCHAR)(CpuInfo.Ebx >> 24);
153 
154  /* Convert all CPUID Feature bits into our format */
155  if (CpuInfo.Edx & 0x00000002) FeatureBits |= KF_V86_VIS | KF_CR4;
156  if (CpuInfo.Edx & 0x00000008) FeatureBits |= KF_LARGE_PAGE | KF_CR4;
157  if (CpuInfo.Edx & 0x00000010) FeatureBits |= KF_RDTSC;
158  if (CpuInfo.Edx & 0x00000100) FeatureBits |= KF_CMPXCHG8B;
159  if (CpuInfo.Edx & 0x00000800) FeatureBits |= KF_FAST_SYSCALL;
160  if (CpuInfo.Edx & 0x00001000) FeatureBits |= KF_MTRR;
161  if (CpuInfo.Edx & 0x00002000) FeatureBits |= KF_GLOBAL_PAGE | KF_CR4;
162  if (CpuInfo.Edx & 0x00008000) FeatureBits |= KF_CMOV;
163  if (CpuInfo.Edx & 0x00010000) FeatureBits |= KF_PAT;
164  if (CpuInfo.Edx & 0x00200000) FeatureBits |= KF_DTS;
165  if (CpuInfo.Edx & 0x00800000) FeatureBits |= KF_MMX;
166  if (CpuInfo.Edx & 0x01000000) FeatureBits |= KF_FXSR;
167  if (CpuInfo.Edx & 0x02000000) FeatureBits |= KF_XMMI;
168  if (CpuInfo.Edx & 0x04000000) FeatureBits |= KF_XMMI64;
169 
170  if (CpuInfo.Ecx & 0x00000001) FeatureBits |= KF_SSE3;
171  //if (CpuInfo.Ecx & 0x00000008) FeatureBits |= KF_MONITOR;
172  //if (CpuInfo.Ecx & 0x00000200) FeatureBits |= KF_SSE3SUP;
173  if (CpuInfo.Ecx & 0x00002000) FeatureBits |= KF_CMPXCHG16B;
174  //if (CpuInfo.Ecx & 0x00080000) FeatureBits |= KF_SSE41;
175  //if (CpuInfo.Ecx & 0x00800000) FeatureBits |= KF_POPCNT;
176  if (CpuInfo.Ecx & 0x04000000) FeatureBits |= KF_XSTATE;
177 
178  /* Check if the CPU has hyper-threading */
179  if (CpuInfo.Ecx & 0x10000000)
180  {
181  /* Set the number of logical CPUs */
182  Prcb->LogicalProcessorsPerPhysicalProcessor = (UCHAR)(CpuInfo.Ebx >> 16);
184  {
185  /* We're on dual-core */
187  }
188  }
189  else
190  {
191  /* We only have a single CPU */
193  }
194 
195  /* Check extended cpuid features */
196  KiCpuId(&CpuInfo, 0x80000000);
197  if ((CpuInfo.Eax & 0xffffff00) == 0x80000000)
198  {
199  /* Check if CPUID 0x80000001 is supported */
200  if (CpuInfo.Eax >= 0x80000001)
201  {
202  /* Check which extended features are available. */
203  KiCpuId(&CpuInfo, 0x80000001);
204 
205  /* Check if NX-bit is supported */
206  if (CpuInfo.Edx & 0x00100000) FeatureBits |= KF_NX_BIT;
207 
208  /* Now handle each features for each CPU Vendor */
209  switch (Vendor)
210  {
211  case CPU_AMD:
212  if (CpuInfo.Edx & 0x80000000) FeatureBits |= KF_3DNOW;
213  break;
214  }
215  }
216  }
217 
218  /* Return the Feature Bits */
219  return FeatureBits;
220 }
#define TRUE
Definition: types.h:120
UCHAR LogicalProcessorsPerPhysicalProcessor
Definition: ketypes.h:703
#define KF_CMPXCHG8B
Definition: ketypes.h:150
#define KF_RDTSC
Definition: ketypes.h:144
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1054
#define KF_MMX
Definition: ketypes.h:151
#define KF_NX_BIT
Definition: ketypes.h:165
ULONG NTAPI KiGetCpuVendor(VOID)
Definition: cpu.c:95
#define KF_LARGE_PAGE
Definition: ketypes.h:148
#define KF_PAT
Definition: ketypes.h:153
#define KF_XMMI
Definition: ketypes.h:156
ULONG Eax
Definition: ketypes.h:296
#define KF_CR4
Definition: ketypes.h:145
ULONG Ebx
Definition: ketypes.h:297
#define KF_MTRR
Definition: ketypes.h:149
ULONG Ecx
Definition: ketypes.h:298
#define KF_WORKING_PTE
Definition: ketypes.h:152
#define KF_FAST_SYSCALL
Definition: ketypes.h:155
#define KF_V86_VIS
Definition: ketypes.h:143
#define KF_FXSR
Definition: ketypes.h:154
#define KF_3DNOW
Definition: ketypes.h:157
unsigned char UCHAR
Definition: xmlstorage.h:181
#define KF_XMMI64
Definition: ketypes.h:159
#define KF_CMPXCHG16B
Definition: ketypes.h:163
#define KF_SSE3
Definition: ketypes.h:162
unsigned int ULONG
Definition: retypes.h:1
#define KF_DTS
Definition: ketypes.h:160
#define KF_XSTATE
Definition: ketypes.h:164
#define KF_GLOBAL_PAGE
Definition: ketypes.h:147
ULONG Edx
Definition: ketypes.h:299
BOOLEAN KiSMTProcessorsPresent
Definition: cpu.c:34
#define KF_CMOV
Definition: ketypes.h:146
ULONG InitialApicId
Definition: ketypes.h:617
VOID KiInitializeCpuFeatures ( VOID  )
VOID KiInvalidOpcodeFault ( VOID  )
VOID KiInvalidTssFault ( VOID  )
VOID KiIpiInterrupt ( VOID  )
VOID KiMcheckAbort ( VOID  )
VOID KiNmiInterrupt ( VOID  )
VOID KiNpxNotAvailableFault ( VOID  )
VOID KiNpxSegmentOverrunAbort ( VOID  )
VOID KiOverflowTrap ( VOID  )
VOID KiPageFault ( VOID  )
VOID KiRaiseAssertion ( VOID  )
FORCEINLINE VOID KiRundownThread ( IN PKTHREAD  Thread)

Definition at line 206 of file ke.h.

Referenced by KeTerminateThread().

207 {
208 #ifndef CONFIG_SMP
209  DbgPrint("KiRundownThread is unimplemented\n");
210 #else
211  /* Nothing to do */
212 #endif
213 }
#define DbgPrint
Definition: loader.c:26
VOID KiSegmentNotPresentFault ( VOID  )
VOID FORCEINLINE KiSendEOI ( VOID  )

Definition at line 263 of file ke.h.

Referenced by KiDpcInterruptHandler().

264 {
265  /* Write 0 to the apic EOI register */
266  *((volatile ULONG*)APIC_EOI_REGISTER) = 0;
267 }
#define APIC_EOI_REGISTER
Definition: ke.h:59
unsigned int ULONG
Definition: retypes.h:1
VOID KiSetProcessorType ( VOID  )

Definition at line 55 of file cpu.c.

56 {
57  ULONG64 EFlags;
58  CPU_INFO CpuInfo;
59  ULONG Stepping, Type;
60 
61  /* Start by assuming no CPUID data */
62  KeGetCurrentPrcb()->CpuID = 0;
63 
64  /* Save EFlags */
65  EFlags = __readeflags();
66 
67  /* Do CPUID 1 now */
68  KiCpuId(&CpuInfo, 1);
69 
70  /*
71  * Get the Stepping and Type. The stepping contains both the
72  * Model and the Step, while the Type contains the returned Type.
73  * We ignore the family.
74  *
75  * For the stepping, we convert this: zzzzzzxy into this: x0y
76  */
77  Stepping = CpuInfo.Eax & 0xF0;
78  Stepping <<= 4;
79  Stepping += (CpuInfo.Eax & 0xFF);
80  Stepping &= 0xF0F;
81  Type = CpuInfo.Eax & 0xF00;
82  Type >>= 8;
83 
84  /* Save them in the PRCB */
85  KeGetCurrentPrcb()->CpuID = TRUE;
86  KeGetCurrentPrcb()->CpuType = (UCHAR)Type;
87  KeGetCurrentPrcb()->CpuStep = (USHORT)Stepping;
88 
89  /* Restore EFLAGS */
90  __writeeflags(EFlags);
91 }
#define TRUE
Definition: types.h:120
Type
Definition: Type.h:6
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1054
__INTRIN_INLINE uintptr_t __readeflags(void)
Definition: intrin_x86.h:1456
uint64_t ULONG64
Definition: typedefs.h:65
ULONG Eax
Definition: ketypes.h:296
unsigned char UCHAR
Definition: xmlstorage.h:181
__INTRIN_INLINE void __writeeflags(uintptr_t Value)
Definition: intrin_x86.h:1451
unsigned short USHORT
Definition: pedump.c:61
unsigned int ULONG
Definition: retypes.h:1
VOID KiStackFault ( VOID  )
VOID KiSwitchToBootStack ( IN ULONG_PTR  InitialStack)

Definition at line 796 of file ke.h.

Referenced by KiSystemStartup().

797 {
799 
800  /* We have to switch to a new stack before continuing kernel initialization */
801 #ifdef __GNUC__
802  __asm__
803  (
804  "movl %0, %%esp\n\t"
805  "subl %1, %%esp\n\t"
806  "pushl %2\n\t"
807  "jmp _KiSystemStartupBootStack@0"
808  :
809  : "c"(InitialStack),
811  "i"(CR0_EM | CR0_TS | CR0_MP),
813  : "%esp"
814  );
815 #elif defined(_MSC_VER)
816  __asm
817  {
818  mov esp, InitialStack
820  push (CR0_EM | CR0_TS | CR0_MP)
822  }
823 #else
824 #error Unknown Compiler
825 #endif
826 }
#define CR0_MP
Definition: asm.h:246
#define NPX_FRAME_LENGTH
Definition: asm.h:244
#define CR0_TS
Definition: asm.h:248
#define KTRAP_FRAME_LENGTH
Definition: asm.h:126
#define KTRAP_FRAME_ALIGN
Definition: asm.h:125
__asm__("\t.globl GetPhys\n""GetPhys:\t\n""mflr 0\n\t""stwu 0,-16(1)\n\t""mfmsr 5\n\t""andi. 6,5,0xffef\n\t""mtmsr 6\n\t""isync\n\t""sync\n\t""lwz 3,0(3)\n\t""mtmsr 5\n\t""isync\n\t""sync\n\t""lwz 0,0(1)\n\t""addi 1,1,16\n\t""mtlr 0\n\t""blr")
VOID NTAPI INIT_FUNCTION KiSystemStartupBootStack(VOID)
Definition: krnlinit.c:55
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
static void push(stack_node_t *op)
Definition: rpn.c:87
#define CR0_EM
Definition: asm.h:247
jmp_buf jmp
Definition: mach.c:36
VOID KiXmmException ( VOID  )
VOID NtEarlyInitVdm ( VOID  )

Variable Documentation

ULONG KeI386CpuStep

Definition at line 29 of file cpu.c.

Referenced by KiInitializeKernel(), and KiInitializeKernelMachineDependent().

ULONG KeI386CpuType

Definition at line 28 of file cpu.c.

Referenced by KiInitializeKernel(), and KiInitializeKernelMachineDependent().

ULONG KeI386XMMIPresent