ReactOS 0.4.16-dev-112-g52265ae
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_FPU   0x00000001 /* x87 FPU is present */
 
#define X86_FEATURE_VME   0x00000002 /* Virtual 8086 Extensions are present */
 
#define X86_FEATURE_DBG   0x00000004 /* Debugging extensions are present */
 
#define X86_FEATURE_PSE   0x00000008 /* Page Size Extension is 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_MTTR   0x00001000 /* Memory type range registers are present */
 
#define X86_FEATURE_PGE   0x00002000 /* Page Global Enable */
 
#define X86_FEATURE_CMOV   0x00008000 /* "Conditional move" instruction supported */
 
#define X86_FEATURE_PAT   0x00010000 /* Page Attribute Table is supported */
 
#define X86_FEATURE_DS   0x00200000 /* Debug Store is present */
 
#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_FEATURE_SSE3   0x00000001 /* SSE3 is supported */
 
#define X86_FEATURE_MONITOR   0x00000008 /* SSE3 Monitor instructions supported */
 
#define X86_FEATURE_VMX   0x00000020 /* Virtual Machine eXtensions are available */
 
#define X86_FEATURE_SSSE3   0x00000200 /* Supplemental SSE3 are available */
 
#define X86_FEATURE_FMA3   0x00001000 /* Fused multiple-add supported */
 
#define X86_FEATURE_CX16   0x00002000 /* CMPXCHG16B instruction are available */
 
#define X86_FEATURE_PCID   0x00020000 /* Process Context IDentifiers are supported */
 
#define X86_FEATURE_SSE41   0x00080000 /* SSE 4.1 is supported */
 
#define X86_FEATURE_SSE42   0x00100000 /* SSE 4.2 is supported */
 
#define X86_FEATURE_POPCNT   0x00800000 /* POPCNT instruction is available */
 
#define X86_FEATURE_XSAVE   0x04000000 /* XSAVE family are available */
 
#define X86_FEATURE_NX   0x00100000 /* NX support 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   0x0001
 
#define EFER_LME   0x0100
 
#define EFER_LMA   0x0400
 
#define EFER_NXE   0x0800
 
#define EFER_SVME   0x1000
 
#define EFER_FFXSR   0x4000
 
#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 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 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_ENTRYPKI_INTERRUPT_DISPATCH_ENTRY
 

Functions

FORCEINLINE ULONG_PTR KeGetContextPc (PCONTEXT Context)
 
FORCEINLINE VOID KeSetContextPc (PCONTEXT Context, ULONG_PTR ProgramCounter)
 
FORCEINLINE ULONG_PTR KeGetContextReturnRegister (PCONTEXT Context)
 
FORCEINLINE VOID KeSetContextReturnRegister (PCONTEXT Context, ULONG_PTR ReturnValue)
 
FORCEINLINE ULONG_PTR KeGetContextStackRegister (PCONTEXT Context)
 
FORCEINLINE ULONG_PTR KeGetContextFrameRegister (PCONTEXT Context)
 
FORCEINLINE VOID KeSetContextFrameRegister (PCONTEXT Context, ULONG_PTR Frame)
 
FORCEINLINE ULONG_PTR KeGetTrapFramePc (PKTRAP_FRAME TrapFrame)
 
FORCEINLINE PKTRAP_FRAME KiGetLinkedTrapFrame (PKTRAP_FRAME TrapFrame)
 
FORCEINLINE ULONG_PTR KeGetTrapFrameStackRegister (PKTRAP_FRAME TrapFrame)
 
FORCEINLINE ULONG_PTR KeGetTrapFrameFrameRegister (PKTRAP_FRAME TrapFrame)
 
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)
 
FORCEINLINE VOID KiSendEOI (VOID)
 
FORCEINLINE VOID KiEndInterrupt (IN KIRQL Irql, IN PKTRAP_FRAME TrapFrame)
 
FORCEINLINE BOOLEAN KiUserTrap (IN PKTRAP_FRAME TrapFrame)
 
FORCEINLINE VOID Ki386PerfEnd (VOID)
 
DECLSPEC_NORETURN 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)
 
ULONG64 KiGetFeatureBits (VOID)
 Evaluates the KeFeatureFlag bits for the current CPU.
 
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)
 
FORCEINLINE PULONG_PTR KiGetUserModeStackAddress (void)
 
VOID KiSetTrapContext (_Out_ PKTRAP_FRAME TrapFrame, _In_ PCONTEXT Context, _In_ KPROCESSOR_MODE RequestorMode)
 
DECLSPEC_NORETURN VOID KiUserCallbackExit (_In_ PKTRAP_FRAME TrapFrame)
 
DECLSPEC_NORETURN VOID KiExceptionExit (_In_ PKTRAP_FRAME TrapFrame, _In_ PKEXCEPTION_FRAME ExceptionFrame)
 
BOOLEAN KiProcessorFreezeHandler (_In_ PKTRAP_FRAME TrapFrame, _In_ PKEXCEPTION_FRAME ExceptionFrame)
 

Variables

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

Macro Definition Documentation

◆ AMD64_TSS

#define AMD64_TSS   9

Definition at line 85 of file ke.h.

◆ APIC_EOI_REGISTER

#define APIC_EOI_REGISTER   0xFFFFFFFFFFFE00B0ULL

Definition at line 87 of file ke.h.

◆ EFER_FFXSR

#define EFER_FFXSR   0x4000

Definition at line 83 of file ke.h.

◆ EFER_LMA

#define EFER_LMA   0x0400

Definition at line 80 of file ke.h.

◆ EFER_LME

#define EFER_LME   0x0100

Definition at line 79 of file ke.h.

◆ EFER_NXE

#define EFER_NXE   0x0800

Definition at line 81 of file ke.h.

◆ EFER_SCE

#define EFER_SCE   0x0001

Definition at line 78 of file ke.h.

◆ EFER_SVME

#define EFER_SVME   0x1000

Definition at line 82 of file ke.h.

◆ FRAME_EDITED

#define FRAME_EDITED   0xFFF8

Definition at line 68 of file ke.h.

◆ KD_BREAKPOINT_SIZE

#define KD_BREAKPOINT_SIZE   sizeof(UCHAR)

Definition at line 122 of file ke.h.

◆ KD_BREAKPOINT_TYPE

#define KD_BREAKPOINT_TYPE   UCHAR

Definition at line 121 of file ke.h.

◆ KD_BREAKPOINT_VALUE

#define KD_BREAKPOINT_VALUE   0xCC

Definition at line 123 of file ke.h.

◆ KeArchInitThreadWithContext

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

Definition at line 437 of file ke.h.

◆ KeGetContextSwitches

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

Definition at line 216 of file ke.h.

◆ KeGetExceptionFrame

#define KeGetExceptionFrame (   Thread)
Value:
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
struct _KEXCEPTION_FRAME * PKEXCEPTION_FRAME
#define KeGetTrapFrame(Thread)
Definition: ke.h:208
uint32_t ULONG_PTR
Definition: typedefs.h:65

Definition at line 225 of file ke.h.

◆ KeGetTrapFrame

#define KeGetTrapFrame (   Thread)
Value:
((PKTRAP_FRAME)((ULONG_PTR)((Thread)->InitialStack) - \
sizeof(KTRAP_FRAME)))
struct _KTRAP_FRAME * PKTRAP_FRAME

Definition at line 208 of file ke.h.

◆ KeGetTrapFrameInterruptState

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

Definition at line 233 of file ke.h.

◆ KiGetSecondLevelDCacheSize

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

Definition at line 223 of file ke.h.

◆ X86_CR0_EM

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

Definition at line 19 of file ke.h.

◆ X86_CR0_MP

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

Definition at line 20 of file ke.h.

◆ X86_CR0_NE

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

Definition at line 17 of file ke.h.

◆ X86_CR0_PE

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

Definition at line 16 of file ke.h.

◆ X86_CR0_PG

#define X86_CR0_PG   0x80000000 /* enable Paging */

Definition at line 22 of file ke.h.

◆ X86_CR0_TS

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

Definition at line 18 of file ke.h.

◆ X86_CR0_WP

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

Definition at line 21 of file ke.h.

◆ X86_CR4_OSFXSR

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

Definition at line 26 of file ke.h.

◆ X86_CR4_OSXMMEXCPT

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

Definition at line 27 of file ke.h.

◆ X86_CR4_PAE

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

Definition at line 24 of file ke.h.

◆ X86_CR4_PGE

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

Definition at line 25 of file ke.h.

◆ X86_EFLAGS_ID

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

Definition at line 14 of file ke.h.

◆ X86_EFLAGS_IF

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

Definition at line 9 of file ke.h.

◆ X86_EFLAGS_IOPL

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

Definition at line 10 of file ke.h.

◆ X86_EFLAGS_NT

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

Definition at line 11 of file ke.h.

◆ X86_EFLAGS_RF

#define X86_EFLAGS_RF   0x00010000 /* Resume flag */

Definition at line 12 of file ke.h.

◆ X86_EFLAGS_TF

#define X86_EFLAGS_TF   0x00000100 /* Trap flag */

Definition at line 8 of file ke.h.

◆ X86_EFLAGS_VM

#define X86_EFLAGS_VM   0x00020000 /* Virtual Mode */

Definition at line 13 of file ke.h.

◆ X86_EXT_FEATURE_3DNOW

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

Definition at line 66 of file ke.h.

◆ X86_EXT_FEATURE_SSE3

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

Definition at line 65 of file ke.h.

◆ X86_FEATURE_CMOV

#define X86_FEATURE_CMOV   0x00008000 /* "Conditional move" instruction supported */

Definition at line 40 of file ke.h.

◆ X86_FEATURE_CX16

#define X86_FEATURE_CX16   0x00002000 /* CMPXCHG16B instruction are available */

Definition at line 55 of file ke.h.

◆ X86_FEATURE_CX8

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

Definition at line 36 of file ke.h.

◆ X86_FEATURE_DBG

#define X86_FEATURE_DBG   0x00000004 /* Debugging extensions are present */

Definition at line 32 of file ke.h.

◆ X86_FEATURE_DS

#define X86_FEATURE_DS   0x00200000 /* Debug Store is present */

Definition at line 42 of file ke.h.

◆ X86_FEATURE_FMA3

#define X86_FEATURE_FMA3   0x00001000 /* Fused multiple-add supported */

Definition at line 54 of file ke.h.

◆ X86_FEATURE_FPU

#define X86_FEATURE_FPU   0x00000001 /* x87 FPU is present */

Definition at line 30 of file ke.h.

◆ X86_FEATURE_FXSR

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

Definition at line 44 of file ke.h.

◆ X86_FEATURE_HT

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

Definition at line 47 of file ke.h.

◆ X86_FEATURE_MMX

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

Definition at line 43 of file ke.h.

◆ X86_FEATURE_MONITOR

#define X86_FEATURE_MONITOR   0x00000008 /* SSE3 Monitor instructions supported */

Definition at line 51 of file ke.h.

◆ X86_FEATURE_MTTR

#define X86_FEATURE_MTTR   0x00001000 /* Memory type range registers are present */

Definition at line 38 of file ke.h.

◆ X86_FEATURE_NX

#define X86_FEATURE_NX   0x00100000 /* NX support present */

Definition at line 63 of file ke.h.

◆ X86_FEATURE_PAE

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

Definition at line 35 of file ke.h.

◆ X86_FEATURE_PAT

#define X86_FEATURE_PAT   0x00010000 /* Page Attribute Table is supported */

Definition at line 41 of file ke.h.

◆ X86_FEATURE_PCID

#define X86_FEATURE_PCID   0x00020000 /* Process Context IDentifiers are supported */

Definition at line 56 of file ke.h.

◆ X86_FEATURE_PGE

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

Definition at line 39 of file ke.h.

◆ X86_FEATURE_POPCNT

#define X86_FEATURE_POPCNT   0x00800000 /* POPCNT instruction is available */

Definition at line 59 of file ke.h.

◆ X86_FEATURE_PSE

#define X86_FEATURE_PSE   0x00000008 /* Page Size Extension is present */

Definition at line 33 of file ke.h.

◆ X86_FEATURE_SSE

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

Definition at line 45 of file ke.h.

◆ X86_FEATURE_SSE2

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

Definition at line 46 of file ke.h.

◆ X86_FEATURE_SSE3

#define X86_FEATURE_SSE3   0x00000001 /* SSE3 is supported */

Definition at line 50 of file ke.h.

◆ X86_FEATURE_SSE41

#define X86_FEATURE_SSE41   0x00080000 /* SSE 4.1 is supported */

Definition at line 57 of file ke.h.

◆ X86_FEATURE_SSE42

#define X86_FEATURE_SSE42   0x00100000 /* SSE 4.2 is supported */

Definition at line 58 of file ke.h.

◆ X86_FEATURE_SSSE3

#define X86_FEATURE_SSSE3   0x00000200 /* Supplemental SSE3 are available */

Definition at line 53 of file ke.h.

◆ X86_FEATURE_SYSCALL

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

Definition at line 37 of file ke.h.

◆ X86_FEATURE_TSC

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

Definition at line 34 of file ke.h.

◆ X86_FEATURE_VME

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

Definition at line 31 of file ke.h.

◆ X86_FEATURE_VMX

#define X86_FEATURE_VMX   0x00000020 /* Virtual Machine eXtensions are available */

Definition at line 52 of file ke.h.

◆ X86_FEATURE_XSAVE

#define X86_FEATURE_XSAVE   0x04000000 /* XSAVE family are available */

Definition at line 60 of file ke.h.

◆ X86_MSR_CSTAR

#define X86_MSR_CSTAR   0xC0000083

Definition at line 75 of file ke.h.

◆ X86_MSR_EFER

#define X86_MSR_EFER   0xC0000080

Definition at line 72 of file ke.h.

◆ X86_MSR_GSBASE

#define X86_MSR_GSBASE   0xC0000101

Definition at line 70 of file ke.h.

◆ X86_MSR_KERNEL_GSBASE

#define X86_MSR_KERNEL_GSBASE   0xC0000102

Definition at line 71 of file ke.h.

◆ X86_MSR_LSTAR

#define X86_MSR_LSTAR   0xC0000082

Definition at line 74 of file ke.h.

◆ X86_MSR_SFMASK

#define X86_MSR_SFMASK   0xC0000084

Definition at line 76 of file ke.h.

◆ X86_MSR_STAR

#define X86_MSR_STAR   0xC0000081

Definition at line 73 of file ke.h.

Typedef Documentation

◆ KI_INTERRUPT_DISPATCH_ENTRY

◆ KIDT_INIT

◆ PKI_INTERRUPT_DISPATCH_ENTRY

◆ PKIDT_INIT

Function Documentation

◆ HalAllocateAdapterChannel()

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.

92{
94 while (TRUE);
95 return STATUS_SUCCESS;
96}
#define UNIMPLEMENTED
Definition: debug.h:118
#define TRUE
Definition: types.h:120
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by HalBuildScatterGatherList(), and IoAllocateAdapterChannel().

◆ Ke386InitThreadWithContext()

VOID Ke386InitThreadWithContext ( PKTHREAD  Thread,
PKSYSTEM_ROUTINE  SystemRoutine,
PKSTART_ROUTINE  StartRoutine,
PVOID  StartContext,
PCONTEXT  Context 
)

◆ KeAllocateGdtSelector()

ULONG KeAllocateGdtSelector ( ULONG  Desc[2])

◆ KeApplicationProcessorInitDispatcher()

VOID KeApplicationProcessorInitDispatcher ( VOID  )

◆ KeCreateApplicationProcessorIdleThread()

VOID KeCreateApplicationProcessorIdleThread ( ULONG  Id)

◆ KeDisableInterrupts()

FORCEINLINE BOOLEAN KeDisableInterrupts ( VOID  )

Definition at line 239 of file ke.h.

240{
242
243 /* Get EFLAGS and check if the interrupt bit is set */
245
246 /* Disable interrupts */
247 _disable();
248 return (Flags & EFLAGS_INTERRUPT_MASK) ? TRUE : FALSE;
249}
#define EFLAGS_INTERRUPT_MASK
Definition: SystemCall.c:11
#define FALSE
Definition: types.h:117
void __cdecl _disable(void)
Definition: intrin_arm.h:365
__INTRIN_INLINE uintptr_t __readeflags(void)
Definition: intrin_x86.h:1674
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170

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

◆ KeFlushProcessTb()

FORCEINLINE VOID KeFlushProcessTb ( VOID  )

Definition at line 272 of file ke.h.

273{
274 /* Flush the TLB by resetting CR3 */
276}
__INTRIN_INLINE unsigned long __readcr3(void)
Definition: intrin_x86.h:1818
__INTRIN_INLINE void __writecr3(unsigned int Data)
Definition: intrin_x86.h:1794

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

◆ KeFreeGdtSelector()

VOID KeFreeGdtSelector ( ULONG  Entry)

◆ KeGetContextFrameRegister()

FORCEINLINE ULONG_PTR KeGetContextFrameRegister ( PCONTEXT  Context)

Definition at line 165 of file ke.h.

166{
167 return Context->Rbp;
168}

Referenced by KdbpCmdBackTrace().

◆ KeGetContextPc()

FORCEINLINE ULONG_PTR KeGetContextPc ( PCONTEXT  Context)

Definition at line 130 of file ke.h.

131{
132 return Context->Rip;
133}

◆ KeGetContextReturnRegister()

FORCEINLINE ULONG_PTR KeGetContextReturnRegister ( PCONTEXT  Context)

Definition at line 144 of file ke.h.

145{
146 return Context->Rax;
147}

◆ KeGetContextStackRegister()

FORCEINLINE ULONG_PTR KeGetContextStackRegister ( PCONTEXT  Context)

Definition at line 158 of file ke.h.

159{
160 return Context->Rsp;
161}

◆ KeGetTrapFrameFrameRegister()

FORCEINLINE ULONG_PTR KeGetTrapFrameFrameRegister ( PKTRAP_FRAME  TrapFrame)

Definition at line 200 of file ke.h.

201{
202 return TrapFrame->Rbp;
203}
UINT64 Rbp
Definition: ketypes.h:457

Referenced by KdbpCmdThread().

◆ KeGetTrapFramePc()

FORCEINLINE ULONG_PTR KeGetTrapFramePc ( PKTRAP_FRAME  TrapFrame)

Definition at line 179 of file ke.h.

180{
181 return TrapFrame->Rip;
182}
UINT64 Rip
Definition: ketypes.h:464

◆ KeGetTrapFrameStackRegister()

FORCEINLINE ULONG_PTR KeGetTrapFrameStackRegister ( PKTRAP_FRAME  TrapFrame)

Definition at line 193 of file ke.h.

194{
195 return TrapFrame->Rsp;
196}
UINT64 Rsp
Definition: ketypes.h:471

Referenced by KdbpCmdThread().

◆ KeInvalidateTlbEntry()

FORCEINLINE VOID KeInvalidateTlbEntry ( IN PVOID  Address)

Definition at line 264 of file ke.h.

265{
266 /* Invalidate the TLB entry for this address */
268}
__INTRIN_INLINE void __invlpg(void *Address)
Definition: intrin_x86.h:1968
static WCHAR Address[46]
Definition: ping.c:68

Referenced by _Success_(), FreeWsleIndex(), KdpPhysMap(), KiI386PentiumLockErrataFixup(), MiDbgTranslatePhysicalAddress(), MiDbgUnTranslatePhysicalAddress(), MiProtectVirtualMemory(), MmSetDirtyBit(), MmSetPageProtect(), and TrimWsList().

◆ KeQueryInterruptHandler()

FORCEINLINE PVOID KeQueryInterruptHandler ( IN ULONG  Vector)

Definition at line 327 of file ke.h.

328{
329 UCHAR Entry;
330 PKIDTENTRY64 Idt;
331
332 /* Get the entry from the HAL */
334
335 /* Get the IDT entry */
336 Idt = &KeGetPcr()->IdtBase[Entry];
337
338 /* Return the address */
339 return (PVOID)((ULONG64)Idt->OffsetHigh << 32 |
340 (ULONG64)Idt->OffsetMiddle << 16 |
341 (ULONG64)Idt->OffsetLow);
342}
unsigned __int64 ULONG64
Definition: imports.h:198
#define HalVectorToIDTEntry
Definition: halfuncs.h:51
#define KeGetPcr()
Definition: ketypes.h:81
base of all file and directory entries
Definition: entries.h:83
ULONG OffsetHigh
Definition: ketypes.h:559
USHORT OffsetMiddle
Definition: ketypes.h:558
USHORT OffsetLow
Definition: ketypes.h:551
unsigned char UCHAR
Definition: xmlstorage.h:181

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

◆ KeRegisterInterruptHandler()

FORCEINLINE VOID KeRegisterInterruptHandler ( IN ULONG  Vector,
IN PVOID  Handler 
)

Definition at line 301 of file ke.h.

303{
304 UCHAR Entry;
305 PKIDTENTRY64 Idt;
306
307 /* Get the entry from the HAL */
309
310 /* Now set the data */
311 Idt = &KeGetPcr()->IdtBase[Entry];
312 Idt->OffsetLow = (ULONG_PTR)Handler & 0xffff;
313 Idt->OffsetMiddle = ((ULONG_PTR)Handler >> 16) & 0xffff;
314 Idt->OffsetHigh = (ULONG_PTR)Handler >> 32;
316 Idt->IstIndex = 0;
317 Idt->Type = 0x0e;
318 Idt->Dpl = 0;
319 Idt->Present = 1;
320 Idt->Reserved0 = 0;
321 Idt->Reserved1 = 0;
322}
ACPI_PHYSICAL_ADDRESS ACPI_SIZE BOOLEAN Warn UINT32 *TableIdx 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:672
#define ULONG_PTR
Definition: config.h:101
#define KGDT64_R0_CODE
Definition: ketypes.h:133
USHORT Reserved0
Definition: ketypes.h:554
USHORT IstIndex
Definition: ketypes.h:553
ULONG Reserved1
Definition: ketypes.h:560
USHORT Dpl
Definition: ketypes.h:556
USHORT Present
Definition: ketypes.h:557
USHORT Selector
Definition: ketypes.h:552
USHORT Type
Definition: ketypes.h:555

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

◆ KeRestoreInterrupts()

FORCEINLINE VOID KeRestoreInterrupts ( BOOLEAN  WereEnabled)

Definition at line 254 of file ke.h.

255{
256 if (WereEnabled) _enable();
257}
void __cdecl _enable(void)
Definition: intrin_arm.h:373

Referenced by _ExiReleaseSpinLockAndRestoreInterrupts(), KdPollBreakIn(), KeThawExecution(), and Ki386EnableGlobalPage().

◆ KeSetContextFrameRegister()

FORCEINLINE VOID KeSetContextFrameRegister ( PCONTEXT  Context,
ULONG_PTR  Frame 
)

Definition at line 172 of file ke.h.

173{
174 Context->Rbp = Frame;
175}

Referenced by KdbpCmdBackTrace().

◆ KeSetContextPc()

FORCEINLINE VOID KeSetContextPc ( PCONTEXT  Context,
ULONG_PTR  ProgramCounter 
)

Definition at line 137 of file ke.h.

138{
139 Context->Rip = ProgramCounter;
140}

◆ KeSetContextReturnRegister()

FORCEINLINE VOID KeSetContextReturnRegister ( PCONTEXT  Context,
ULONG_PTR  ReturnValue 
)

Definition at line 151 of file ke.h.

152{
153 Context->Rax = ReturnValue;
154}
UINT32 void void ** ReturnValue
Definition: acevents.h:216

◆ KeSweepICache()

FORCEINLINE VOID KeSweepICache ( IN PVOID  BaseAddress,
IN SIZE_T  FlushSize 
)

Definition at line 280 of file ke.h.

282{
283 //
284 // Always sweep the whole cache
285 //
287 UNREFERENCED_PARAMETER(FlushSize);
288 __wbinvd();
289}
PPC_QUAL void __wbinvd(void)
Definition: intrin_ppc.h:759
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317

Referenced by KdpCopyMemoryChunks(), and NtFlushInstructionCache().

◆ Ki386InitializeLdt()

VOID Ki386InitializeLdt ( VOID  )

◆ Ki386PerfEnd()

FORCEINLINE VOID Ki386PerfEnd ( VOID  )

Definition at line 375 of file ke.h.

376{
379 DbgPrint("Boot took %I64u cycles!\n", BootCyclesEnd - BootCycles);
380 DbgPrint("Interrupts: %u System Calls: %u Context Switches: %u\n",
381 KeGetCurrentPrcb()->InterruptCount,
382 KeGetCurrentPrcb()->KeSystemCalls,
384}
#define DbgPrint
Definition: hal.h:12
PPC_QUAL unsigned long long __rdtsc(void)
Definition: intrin_ppc.h:688
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1161
#define KeGetContextSwitches(Prcb)
Definition: ke.h:216
ULONGLONG BootCyclesEnd
Definition: ke.h:152
ULONGLONG BootCycles
Definition: kiinit.c:37
uint64_t ULONGLONG
Definition: typedefs.h:67

◆ Ki386SetProcessorFeatures()

VOID Ki386SetProcessorFeatures ( VOID  )

◆ KiAlignmentFault()

VOID KiAlignmentFault ( VOID  )

◆ KiApcInterrupt()

VOID KiApcInterrupt ( VOID  )

Definition at line 229 of file trapc.c.

230{
232 KEXCEPTION_FRAME ExceptionFrame;
233 PKTRAP_FRAME TrapFrame = KeGetCurrentThread()->TrapFrame;
234
235 DPRINT1("[APC TRAP]\n");
236 while (TRUE);
237
238 //
239 // Isolate previous mode
240 //
241 PreviousMode = KiGetPreviousMode(TrapFrame);
242
243 //
244 // FIXME-USER: Handle APC interrupt while in user-mode
245 //
247
248 //
249 // Disable interrupts
250 //
251 _disable();
252
253 //
254 // Clear APC interrupt
255 //
257
258 //
259 // Re-enable interrupts
260 //
261 _enable();
262
263 //
264 // Deliver APCs
265 //
266 KiDeliverApc(PreviousMode, &ExceptionFrame, TrapFrame);
267}
#define DPRINT1
Definition: precomp.h:8
#define APC_LEVEL
Definition: env_spec_w32.h:695
VOID FASTCALL HalClearSoftwareInterrupt(IN KIRQL Irql)
Definition: pic.c:282
#define KeGetCurrentThread
Definition: hal.h:55
#define ASSERT(a)
Definition: mode.c:44
#define UserMode
Definition: asm.h:35
#define KiGetPreviousMode(tf)
Definition: ke.h:180
VOID NTAPI KiDeliverApc(IN KPROCESSOR_MODE DeliveryMode, IN PKEXCEPTION_FRAME ExceptionFrame, IN PKTRAP_FRAME TrapFrame)
Definition: apc.c:302
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103

Referenced by KiInitializePcr().

◆ KiBoundFault()

VOID KiBoundFault ( VOID  )

◆ KiBreakpointTrap()

VOID KiBreakpointTrap ( VOID  )

◆ KiDebugServiceTrap()

VOID KiDebugServiceTrap ( VOID  )

◆ KiDebugTrapOrFault()

VOID KiDebugTrapOrFault ( VOID  )

◆ KiDivideErrorFault()

VOID KiDivideErrorFault ( VOID  )

◆ KiDoubleFaultAbort()

VOID KiDoubleFaultAbort ( VOID  )

◆ KiDpcInterrupt()

VOID KiDpcInterrupt ( VOID  )

◆ KiEndInterrupt()

FORCEINLINE VOID KiEndInterrupt ( IN KIRQL  Irql,
IN PKTRAP_FRAME  TrapFrame 
)

Definition at line 354 of file ke.h.

356{
357 /* Make sure this is from the clock handler */
358 ASSERT(TrapFrame->ErrorCode == 0xc10c4);
359 //KeLowerIrql(Irql);
360}

◆ KiExceptionExit()

DECLSPEC_NORETURN VOID KiExceptionExit ( _In_ PKTRAP_FRAME  TrapFrame,
_In_ PKEXCEPTION_FRAME  ExceptionFrame 
)

Definition at line 685 of file ke.h.

688{
689 KiServiceExit2(TrapFrame);
690}
#define KiServiceExit2
Definition: ke.h:5

Referenced by NtContinue(), and NtRaiseException().

◆ KiFloatingErrorFault()

VOID KiFloatingErrorFault ( VOID  )

◆ KiGdtPrepareForApplicationProcessorInit()

VOID KiGdtPrepareForApplicationProcessorInit ( ULONG  Id)

◆ KiGeneralProtectionFault()

VOID KiGeneralProtectionFault ( VOID  )

◆ KiGetCacheInformation()

VOID KiGetCacheInformation ( VOID  )

Definition at line 418 of file cpu.c.

419{
420 PKIPCR Pcr = (PKIPCR)KeGetPcr();
421 ULONG Vendor;
422 ULONG CacheRequests = 0, i;
423 ULONG CurrentRegister;
424 UCHAR RegisterByte;
425 BOOLEAN FirstPass = TRUE;
426 CPU_INFO CpuInfo;
427
428 /* Set default L2 size */
429 Pcr->SecondLevelCacheSize = 0;
430
431 /* Get the Vendor ID and make sure we support CPUID */
432 Vendor = KiGetCpuVendor();
433 if (!Vendor) return;
434
435 /* Check the Vendor ID */
436 switch (Vendor)
437 {
438 /* Handle Intel case */
439 case CPU_INTEL:
440
441 /*Check if we support CPUID 2 */
442 KiCpuId(&CpuInfo, 0);
443 if (CpuInfo.Eax >= 2)
444 {
445 /* We need to loop for the number of times CPUID will tell us to */
446 do
447 {
448 /* Do the CPUID call */
449 KiCpuId(&CpuInfo, 2);
450
451 /* Check if it was the first call */
452 if (FirstPass)
453 {
454 /*
455 * The number of times to loop is the first byte. Read
456 * it and then destroy it so we don't get confused.
457 */
458 CacheRequests = CpuInfo.Eax & 0xFF;
459 CpuInfo.Eax &= 0xFFFFFF00;
460
461 /* Don't go over this again */
462 FirstPass = FALSE;
463 }
464
465 /* Loop all 4 registers */
466 for (i = 0; i < 4; i++)
467 {
468 /* Get the current register */
469 CurrentRegister = CpuInfo.AsUINT32[i];
470
471 /*
472 * If the upper bit is set, then this register should
473 * be skipped.
474 */
475 if (CurrentRegister & 0x80000000) continue;
476
477 /* Keep looping for every byte inside this register */
478 while (CurrentRegister)
479 {
480 /* Read a byte, skip a byte. */
481 RegisterByte = (UCHAR)(CurrentRegister & 0xFF);
482 CurrentRegister >>= 8;
483 if (!RegisterByte) continue;
484
485 /*
486 * Valid values are from 0x40 (0 bytes) to 0x49
487 * (32MB), or from 0x80 to 0x89 (same size but
488 * 8-way associative.
489 */
490 if (((RegisterByte > 0x40) &&
491 (RegisterByte <= 0x49)) ||
492 ((RegisterByte > 0x80) &&
493 (RegisterByte <= 0x89)))
494 {
495 /* Mask out only the first nibble */
496 RegisterByte &= 0x0F;
497
498 /* Set the L2 Cache Size */
499 Pcr->SecondLevelCacheSize = 0x10000 <<
500 RegisterByte;
501 }
502 }
503 }
504 } while (--CacheRequests);
505 }
506 break;
507
508 case CPU_AMD:
509
510 /* Check if we support CPUID 0x80000006 */
511 KiCpuId(&CpuInfo, 0x80000000);
512 if (CpuInfo.Eax >= 6)
513 {
514 /* Get 2nd level cache and tlb size */
515 KiCpuId(&CpuInfo, 0x80000006);
516
517 /* Set the L2 Cache Size */
518 Pcr->SecondLevelCacheSize = (CpuInfo.Ecx & 0xFFFF0000) >> 6;
519 }
520 break;
521 }
522}
unsigned char BOOLEAN
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
struct _KIPCR * PKIPCR
@ CPU_INTEL
Definition: ketypes.h:106
@ CPU_AMD
Definition: ketypes.h:105
ULONG NTAPI KiGetCpuVendor(VOID)
Definition: cpu.c:59
ULONG SecondLevelCacheSize
Definition: ketypes.h:968
uint32_t ULONG
Definition: typedefs.h:59
ULONG Eax
Definition: ketypes.h:381
UINT32 AsUINT32[4]
Definition: ketypes.h:378
ULONG Ecx
Definition: ketypes.h:383

Referenced by KiInitializeKernel(), and KiSystemStartupBootStack().

◆ KiGetFeatureBits()

ULONG64 KiGetFeatureBits ( VOID  )

Evaluates the KeFeatureFlag bits for the current CPU.

Returns
The feature flags for this CPU.
See also
https://www.geoffchappell.com/studies/windows/km/ntoskrnl/structs/kprcb/featurebits.htm
Todo:
  • KF_VIRT_FIRMWARE_ENABLED 0x08000000 (see notes from Geoff Chappell)
  • KF_FPU_LEAKAGE 0x0000020000000000ULL
  • KF_CAT 0x0000100000000000ULL
  • KF_CET_SS 0x0000400000000000ULL

Definition at line 165 of file cpu.c.

166{
167 PKPRCB Prcb = KeGetCurrentPrcb();
168 ULONG Vendor;
169 ULONG64 FeatureBits = 0;
172 CPUID_EXTENDED_FUNCTION_REGS extendedFunction;
173
174 /* Get the Vendor ID */
175 Vendor = Prcb->CpuVendor;
176
177 /* Make sure we got a valid vendor ID at least. */
178 if (Vendor == CPU_UNKNOWN) return FeatureBits;
179
180 /* Get signature CPUID for the maximum function */
182
183 /* Get the CPUID Info. */
185
186 /* Set the initial APIC ID */
187 Prcb->InitialApicId = (UCHAR)VersionInfo.Ebx.Bits.InitialLocalApicId;
188
189 /* Convert all CPUID Feature bits into our format */
190 if (VersionInfo.Edx.Bits.VME) FeatureBits |= KF_CR4;
191 if (VersionInfo.Edx.Bits.PSE) FeatureBits |= KF_LARGE_PAGE | KF_CR4;
192 if (VersionInfo.Edx.Bits.TSC) FeatureBits |= KF_RDTSC;
193 if (VersionInfo.Edx.Bits.CX8) FeatureBits |= KF_CMPXCHG8B;
194 if (VersionInfo.Edx.Bits.SEP) FeatureBits |= KF_FAST_SYSCALL;
195 if (VersionInfo.Edx.Bits.MTRR) FeatureBits |= KF_MTRR;
196 if (VersionInfo.Edx.Bits.PGE) FeatureBits |= KF_GLOBAL_PAGE | KF_CR4;
197 if (VersionInfo.Edx.Bits.CMOV) FeatureBits |= KF_CMOV;
198 if (VersionInfo.Edx.Bits.PAT) FeatureBits |= KF_PAT;
199 if (VersionInfo.Edx.Bits.DS) FeatureBits |= KF_DTS;
200 if (VersionInfo.Edx.Bits.MMX) FeatureBits |= KF_MMX;
201 if (VersionInfo.Edx.Bits.FXSR) FeatureBits |= KF_FXSR;
202 if (VersionInfo.Edx.Bits.SSE) FeatureBits |= KF_XMMI;
203 if (VersionInfo.Edx.Bits.SSE2) FeatureBits |= KF_XMMI64;
204
205 if (VersionInfo.Ecx.Bits.SSE3) FeatureBits |= KF_SSE3;
206 if (VersionInfo.Ecx.Bits.SSSE3) FeatureBits |= KF_SSSE3;
207 if (VersionInfo.Ecx.Bits.CMPXCHG16B) FeatureBits |= KF_CMPXCHG16B;
208 if (VersionInfo.Ecx.Bits.SSE4_1) FeatureBits |= KF_SSE4_1;
209 if (VersionInfo.Ecx.Bits.XSAVE) FeatureBits |= KF_XSTATE;
210 if (VersionInfo.Ecx.Bits.RDRAND) FeatureBits |= KF_RDRAND;
211
212 /* Check if the CPU has hyper-threading */
213 if (VersionInfo.Edx.Bits.HTT)
214 {
215 /* Set the number of logical CPUs */
217 VersionInfo.Ebx.Bits.MaximumAddressableIdsForLogicalProcessors;
219 {
220 /* We're on dual-core */
222 }
223 }
224 else
225 {
226 /* We only have a single CPU */
228 }
229
230 /* Check if CPUID_THERMAL_POWER_MANAGEMENT (0x06) is supported */
232 {
233 /* Read CPUID_THERMAL_POWER_MANAGEMENT */
236
237 if (PowerInfo.Undoc.Ecx.ACNT2) FeatureBits |= KF_ACNT2;
238 }
239
240 /* Check if CPUID_STRUCTURED_EXTENDED_FEATURE_FLAGS (0x07) is supported */
242 {
243 /* Read CPUID_STRUCTURED_EXTENDED_FEATURE_FLAGS */
245 __cpuidex(ExtFlags.AsInt32,
248
249 if (ExtFlags.Ebx.Bits.SMEP) FeatureBits |= KF_SMEP;
250 if (ExtFlags.Ebx.Bits.FSGSBASE) FeatureBits |= KF_RDWRFSGSBASE;
251 if (ExtFlags.Ebx.Bits.SMAP) FeatureBits |= KF_SMAP;
252 }
253
254 /* Check if CPUID_EXTENDED_STATE (0x0D) is supported */
255 if (signature.MaxLeaf >= CPUID_EXTENDED_STATE)
256 {
257 /* Read CPUID_EXTENDED_STATE */
259 __cpuidex(ExtStateSub.AsInt32,
262
263 if (ExtStateSub.Eax.Bits.XSAVEOPT) FeatureBits |= KF_XSAVEOPT;
264 if (ExtStateSub.Eax.Bits.XSAVES) FeatureBits |= KF_XSAVES;
265 }
266
267 /* Check extended cpuid features */
268 __cpuid(extendedFunction.AsInt32, CPUID_EXTENDED_FUNCTION);
269 if ((extendedFunction.MaxLeaf & 0xffffff00) == 0x80000000)
270 {
271 /* Check if CPUID_EXTENDED_CPU_SIG (0x80000001) is supported */
272 if (extendedFunction.MaxLeaf >= CPUID_EXTENDED_CPU_SIG)
273 {
274 /* Read CPUID_EXTENDED_CPU_SIG */
277
278 /* Check if NX-bit is supported */
279 if (ExtSig.Intel.Edx.Bits.NX) FeatureBits |= KF_NX_BIT;
280 if (ExtSig.Intel.Edx.Bits.Page1GB) FeatureBits |= KF_HUGEPAGE;
281 if (ExtSig.Intel.Edx.Bits.RDTSCP) FeatureBits |= KF_RDTSCP;
282
283 /* AMD specific */
284 if (Vendor == CPU_AMD)
285 {
286 if (ExtSig.Amd.Edx.Bits.ThreeDNow) FeatureBits |= KF_3DNOW;
287 }
288 }
289 }
290
291 /* Vendor specific */
292 if (Vendor == CPU_INTEL)
293 {
294 FeatureBits |= KF_GENUINE_INTEL;
295
296 /* Check for models that support LBR */
297 if (VersionInfo.Eax.Bits.FamilyId == 6)
298 {
299 if ((VersionInfo.Eax.Bits.Model == 15) ||
300 (VersionInfo.Eax.Bits.Model == 22) ||
301 (VersionInfo.Eax.Bits.Model == 23) ||
302 (VersionInfo.Eax.Bits.Model == 26))
303 {
304 FeatureBits |= KF_BRANCH;
305 }
306 }
307
308 /* Check if VMX is available */
309 if (VersionInfo.Ecx.Bits.VMX)
310 {
311 /* Read PROCBASED ctls and check if secondary are allowed */
314 if (ProcBasedCtls.Bits.Allowed1.ActivateSecondaryControls)
315 {
316 /* Read secondary controls and check if EPT is allowed */
319 if (ProcBasedCtls2.Bits.Allowed1.EPT)
320 FeatureBits |= KF_SLAT;
321 }
322 }
323 }
324 else if (Vendor == CPU_AMD)
325 {
326 FeatureBits |= KF_AUTHENTICAMD;
327 FeatureBits |= KF_BRANCH;
328
329 /* Check extended cpuid features */
330 if ((extendedFunction.MaxLeaf & 0xffffff00) == 0x80000000)
331 {
332 /* Check if CPUID_AMD_SVM_FEATURES (0x8000000A) is supported */
333 if (extendedFunction.MaxLeaf >= CPUID_AMD_SVM_FEATURES)
334 {
335 /* Read CPUID_AMD_SVM_FEATURES and check if Nested Paging is available */
336 CPUID_AMD_SVM_FEATURES_REGS SvmFeatures;
338 if (SvmFeatures.Edx.Bits.NP) FeatureBits |= KF_SLAT;
339 }
340 }
341 }
342
343 /* Return the Feature Bits */
344 return FeatureBits;
345}
#define MSR_IA32_VMX_PROCBASED_CTLS
#define MSR_IA32_VMX_PROCBASED_CTLS2
#define CPUID_AMD_SVM_FEATURES
Definition: Cpuid.h:146
#define CPUID_EXTENDED_FUNCTION
Definition: Cpuid.h:3745
#define CPUID_STRUCTURED_EXTENDED_FEATURE_FLAGS
Definition: Cpuid.h:1301
#define CPUID_SIGNATURE
Definition: Cpuid.h:45
#define CPUID_VERSION_INFO
Definition: Cpuid.h:81
#define CPUID_EXTENDED_STATE
Definition: Cpuid.h:1918
#define CPUID_THERMAL_POWER_MANAGEMENT
Definition: Cpuid.h:1114
#define CPUID_EXTENDED_STATE_SUB_LEAF
Definition: Cpuid.h:2033
#define CPUID_STRUCTURED_EXTENDED_FEATURE_FLAGS_SUB_LEAF_INFO
Definition: Cpuid.h:1306
#define CPUID_EXTENDED_CPU_SIG
Definition: Cpuid.h:3768
OSVERSIONINFOW VersionInfo
Definition: wkssvc.c:40
PPC_QUAL void __cpuid(int CPUInfo[], const int InfoType)
Definition: intrin_ppc.h:682
PPC_QUAL unsigned long long __readmsr()
Definition: intrin_ppc.h:741
__INTRIN_INLINE void __cpuidex(int CPUInfo[4], int InfoType, int ECXValue)
Definition: intrin_x86.h:1649
if(dx< 0)
Definition: linetemp.h:194
#define KF_SMEP
Definition: ketypes.h:31
#define KF_SSSE3
Definition: ketypes.h:72
#define KF_MTRR
Definition: ketypes.h:37
#define KF_HUGEPAGE
Definition: ketypes.h:67
#define KF_XSTATE
Definition: ketypes.h:55
#define KF_DTS
Definition: ketypes.h:40
#define KF_CMPXCHG16B
Definition: ketypes.h:52
#define KF_CR4
Definition: ketypes.h:33
#define KF_AUTHENTICAMD
Definition: ketypes.h:53
#define KF_XMMI64
Definition: ketypes.h:48
#define KF_CMOV
Definition: ketypes.h:34
#define KF_ACNT2
Definition: ketypes.h:54
#define KF_SSE4_1
Definition: ketypes.h:73
#define KF_RDWRFSGSBASE
Definition: ketypes.h:60
#define KF_CMPXCHG8B
Definition: ketypes.h:38
#define KF_RDTSC
Definition: ketypes.h:32
#define KF_FAST_SYSCALL
Definition: ketypes.h:43
#define KF_3DNOW
Definition: ketypes.h:45
#define KF_NX_BIT
Definition: ketypes.h:61
#define KF_FXSR
Definition: ketypes.h:42
#define KF_RDRAND
Definition: ketypes.h:64
@ CPU_UNKNOWN
Definition: ketypes.h:104
#define KF_XSAVES
Definition: ketypes.h:68
#define KF_LARGE_PAGE
Definition: ketypes.h:36
#define KF_BRANCH
Definition: ketypes.h:49
#define KF_GENUINE_INTEL
Definition: ketypes.h:56
#define KF_XMMI
Definition: ketypes.h:44
#define KF_MMX
Definition: ketypes.h:39
#define KF_XSAVEOPT
Definition: ketypes.h:47
#define KF_SSE3
Definition: ketypes.h:51
#define KF_SLAT
Definition: ketypes.h:58
#define KF_PAT
Definition: ketypes.h:41
#define KF_RDTSCP
Definition: ketypes.h:66
#define KF_GLOBAL_PAGE
Definition: ketypes.h:35
#define KF_SMAP
Definition: ketypes.h:65
BOOLEAN KiSMTProcessorsPresent
Definition: cpu.c:30
UCHAR CpuVendor
Definition: ketypes.h:684
UCHAR LogicalProcessorsPerPhysicalProcessor
Definition: ketypes.h:759
ULONG InitialApicId
Definition: ketypes.h:701
struct CPUID_AMD_SVM_FEATURES_EDX::@3724 Bits
CPUID_AMD_SVM_FEATURES_EDX Edx
Definition: Cpuid.h:206
struct CPUID_EXTENDED_CPU_SIG_REGS::@3722 Amd
struct CPUID_EXTENDED_CPU_SIG_REGS::@3721 Intel
CPUID_EXTENDED_STATE_SUB_LEAF_EAX Eax
Definition: Cpuid.h:107
struct CPUID_EXTENDED_STATE_SUB_LEAF_EAX::@3819 Bits
struct CPUID_STRUCTURED_EXTENDED_FEATURE_FLAGS_EBX::@3809 Bits
CPUID_STRUCTURED_EXTENDED_FEATURE_FLAGS_EBX Ebx
Definition: Cpuid.h:80
struct CPUID_THERMAL_POWER_MANAGEMENT_REGS::@3712 Undoc
struct MSR_IA32_VMX_PROCBASED_CTLS2_REGISTER::@3856 Bits
struct MSR_IA32_VMX_PROCBASED_CTLS_REGISTER::@3855 Bits

Referenced by KiInitializeCpu(), and KiVerifyCpuFeatures().

◆ KiGetLinkedTrapFrame()

FORCEINLINE PKTRAP_FRAME KiGetLinkedTrapFrame ( PKTRAP_FRAME  TrapFrame)

Definition at line 186 of file ke.h.

187{
188 return (PKTRAP_FRAME)TrapFrame->TrapFrame;
189}
UINT64 TrapFrame
Definition: ketypes.h:453

◆ KiGetUserModeStackAddress()

FORCEINLINE PULONG_PTR KiGetUserModeStackAddress ( void  )

Definition at line 466 of file ke.h.

467{
468 return &PsGetCurrentThread()->Tcb.TrapFrame->Rsp;
469}
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81

Referenced by KeUserModeCallback().

◆ KiInitializeCpuFeatures()

VOID KiInitializeCpuFeatures ( VOID  )

◆ KiInvalidOpcodeFault()

VOID KiInvalidOpcodeFault ( VOID  )

◆ KiInvalidTssFault()

VOID KiInvalidTssFault ( VOID  )

◆ KiIpiInterrupt()

VOID KiIpiInterrupt ( VOID  )

◆ KiMcheckAbort()

VOID KiMcheckAbort ( VOID  )

◆ KiNmiInterrupt()

VOID KiNmiInterrupt ( VOID  )

◆ KiNpxNotAvailableFault()

VOID KiNpxNotAvailableFault ( VOID  )

◆ KiNpxSegmentOverrunAbort()

VOID KiNpxSegmentOverrunAbort ( VOID  )

◆ KiOverflowTrap()

VOID KiOverflowTrap ( VOID  )

◆ KiPageFault()

VOID KiPageFault ( VOID  )

◆ KiProcessorFreezeHandler()

BOOLEAN KiProcessorFreezeHandler ( _In_ PKTRAP_FRAME  TrapFrame,
_In_ PKEXCEPTION_FRAME  ExceptionFrame 
)

Definition at line 21 of file freeze.c.

24{
25 PKPRCB CurrentPrcb = KeGetCurrentPrcb();
26
27 /* Make sure this is a freeze request */
28 if (CurrentPrcb->IpiFrozen != IPI_FROZEN_STATE_TARGET_FREEZE)
29 {
30 /* Not a freeze request, return FALSE to signal it is unhandled */
31 return FALSE;
32 }
33
34 /* We are frozen now */
36
37 /* Save the processor state */
38 KiSaveProcessorState(TrapFrame, ExceptionFrame);
39
40 /* Wait for the freeze owner to release us */
41 while (CurrentPrcb->IpiFrozen != IPI_FROZEN_STATE_THAW)
42 {
43 /* Check for Kd processor switch */
44 if (CurrentPrcb->IpiFrozen & IPI_FROZEN_FLAG_ACTIVE)
45 {
46 KCONTINUE_STATUS ContinueStatus;
47
48 /* Enter the debugger */
49 ContinueStatus = KdReportProcessorChange();
50
51 /* Set the state back to frozen */
53
54 /* If the status is ContinueSuccess, we need to release the freeze owner */
55 if (ContinueStatus == ContinueSuccess)
56 {
57 /* Release the freeze owner */
59 }
60 }
61
64 }
65
66 /* Restore the processor state */
67 KiRestoreProcessorState(TrapFrame, ExceptionFrame);
68
69 /* We are running again now */
71
72 /* Return TRUE to signal that we handled the freeze */
73 return TRUE;
74}
PKPRCB KiFreezeOwner
Definition: freeze.c:16
KCONTINUE_STATUS NTAPI KdReportProcessorChange(VOID)
Definition: kdapi.c:1810
#define IPI_FROZEN_STATE_TARGET_FREEZE
Definition: ketypes.h:315
#define IPI_FROZEN_FLAG_ACTIVE
Definition: ketypes.h:316
#define IPI_FROZEN_STATE_RUNNING
Definition: ketypes.h:311
#define IPI_FROZEN_STATE_THAW
Definition: ketypes.h:313
#define IPI_FROZEN_STATE_FROZEN
Definition: ketypes.h:312
enum _KCONTINUE_STATUS KCONTINUE_STATUS
@ ContinueSuccess
Definition: ketypes.h:450
VOID NTAPI KiSaveProcessorState(_In_ PKTRAP_FRAME TrapFrame, _In_ PKEXCEPTION_FRAME ExceptionFrame)
Definition: cpu.c:617
VOID NTAPI KiRestoreProcessorState(_Out_ PKTRAP_FRAME TrapFrame, _Out_ PKEXCEPTION_FRAME ExceptionFrame)
Definition: cpu.c:633
#define YieldProcessor
Definition: ke.h:48
FORCEINLINE VOID KeMemoryBarrier(VOID)
Definition: ke.h:58
ULONG IpiFrozen
Definition: ketypes.h:755

Referenced by KiNmiInterruptHandler().

◆ KiRaiseAssertion()

VOID KiRaiseAssertion ( VOID  )

◆ KiRundownThread()

FORCEINLINE VOID KiRundownThread ( IN PKTHREAD  Thread)

Definition at line 293 of file ke.h.

294{
295 /* Nothing to do */
296}

Referenced by KeTerminateThread().

◆ KiSegmentNotPresentFault()

VOID KiSegmentNotPresentFault ( VOID  )

◆ KiSendEOI()

FORCEINLINE VOID KiSendEOI ( VOID  )

Definition at line 346 of file ke.h.

347{
348 /* Write 0 to the apic EOI register */
349 *((volatile ULONG*)APIC_EOI_REGISTER) = 0;
350}
#define APIC_EOI_REGISTER
Definition: ke.h:87

Referenced by _Requires_lock_not_held_().

◆ KiSetProcessorType()

VOID KiSetProcessorType ( VOID  )

Definition at line 99 of file cpu.c.

100{
101 CPU_INFO CpuInfo;
102 CPU_SIGNATURE CpuSignature;
103 BOOLEAN ExtendModel;
104 ULONG Stepping, Type, Vendor;
105
106 /* This initializes Prcb->CpuVendor */
107 Vendor = KiGetCpuVendor();
108
109 /* Do CPUID 1 now */
110 KiCpuId(&CpuInfo, 1);
111
112 /*
113 * Get the Stepping and Type. The stepping contains both the
114 * Model and the Step, while the Type contains the returned Family.
115 *
116 * For the stepping, we convert this: zzzzzzxy into this: x0y
117 */
118 CpuSignature.AsULONG = CpuInfo.Eax;
119 Stepping = CpuSignature.Model;
120 ExtendModel = (CpuSignature.Family == 15);
121#if ( (NTDDI_VERSION >= NTDDI_WINXPSP2) && (NTDDI_VERSION < NTDDI_WS03) ) || (NTDDI_VERSION >= NTDDI_WS03SP1)
122 if (CpuSignature.Family == 6)
123 {
124 ExtendModel |= (Vendor == CPU_INTEL);
125#if (NTDDI_VERSION >= NTDDI_WIN8)
126 ExtendModel |= (Vendor == CPU_CENTAUR);
127#endif
128 }
129#endif
130 if (ExtendModel)
131 {
132 /* Add ExtendedModel to distinguish from non-extended values. */
133 Stepping |= (CpuSignature.ExtendedModel << 4);
134 }
135 Stepping = (Stepping << 8) | CpuSignature.Step;
136 Type = CpuSignature.Family;
137 if (CpuSignature.Family == 15)
138 {
139 /* Add ExtendedFamily to distinguish from non-extended values.
140 * It must not be larger than 0xF0 to avoid overflow. */
141 Type += min(CpuSignature.ExtendedFamily, 0xF0);
142 }
143
144 /* Save them in the PRCB */
145 KeGetCurrentPrcb()->CpuID = TRUE;
146 KeGetCurrentPrcb()->CpuType = (UCHAR)Type;
147 KeGetCurrentPrcb()->CpuStep = (USHORT)Stepping;
148}
Type
Definition: Type.h:7
#define min(a, b)
Definition: monoChain.cc:55
@ CPU_CENTAUR
Definition: ketypes.h:95
unsigned short USHORT
Definition: pedump.c:61
ULONG ExtendedFamily
Definition: cpu.c:49
ULONG Model
Definition: cpu.c:45
ULONG Family
Definition: cpu.c:46
ULONG AsULONG
Definition: cpu.c:52
ULONG Step
Definition: cpu.c:44
ULONG ExtendedModel
Definition: cpu.c:48

Referenced by KiInitializeCpu(), and KiVerifyCpuFeatures().

◆ KiSetTrapContext()

VOID KiSetTrapContext ( _Out_ PKTRAP_FRAME  TrapFrame,
_In_ PCONTEXT  Context,
_In_ KPROCESSOR_MODE  RequestorMode 
)

Referenced by _IRQL_requires_().

◆ KiStackFault()

VOID KiStackFault ( VOID  )

◆ KiSwitchToBootStack()

DECLSPEC_NORETURN VOID KiSwitchToBootStack ( IN ULONG_PTR  InitialStack)

Definition at line 889 of file ke.h.

890{
892
893 /* We have to switch to a new stack before continuing kernel initialization */
894#ifdef __GNUC__
895 __asm__
896 (
897 "movl %0, %%esp\n\t"
898 "subl %1, %%esp\n\t"
899 "pushl %2\n\t"
900 "jmp _KiSystemStartupBootStack@0"
901 :
902 : "c"(InitialStack),
904 "i"(CR0_EM | CR0_TS | CR0_MP),
906 : "%esp"
907 );
908#elif defined(_MSC_VER)
909 __asm
910 {
911 mov esp, InitialStack
915 }
916#else
917#error Unknown Compiler
918#endif
919
921}
#define CODE_SEG(...)
DECLSPEC_NORETURN VOID NTAPI KiSystemStartupBootStack(VOID)
Definition: krnlinit.c:142
#define CR0_MP
Definition: asm.h:246
#define CR0_EM
Definition: asm.h:247
#define KTRAP_FRAME_LENGTH
Definition: asm.h:126
#define KTRAP_FRAME_ALIGN
Definition: asm.h:125
#define CR0_TS
Definition: asm.h:248
#define NPX_FRAME_LENGTH
Definition: asm.h:247
#define UNREACHABLE
#define DECLSPEC_NORETURN
Definition: ntbasedef.h:176
__asm__(".p2align 4, 0x90\n" ".seh_proc __seh2_global_filter_func\n" "__seh2_global_filter_func:\n" "\tsub %rbp, %rax\n" "\tpush %rbp\n" "\t.seh_pushreg %rbp\n" "\tsub $32, %rsp\n" "\t.seh_stackalloc 32\n" "\t.seh_endprologue\n" "\tsub %rax, %rdx\n" "\tmov %rdx, %rbp\n" "\tjmp *%r8\n" "__seh2_global_filter_func_exit:\n" "\t.p2align 4\n" "\tadd $32, %rsp\n" "\tpop %rbp\n" "\tret\n" "\t.seh_endproc")
static void push(calc_node_t *op)
Definition: rpn_ieee.c:113
#define NTAPI
Definition: typedefs.h:36

Referenced by KiSystemStartup().

◆ KiUserCallbackExit()

DECLSPEC_NORETURN VOID KiUserCallbackExit ( _In_ PKTRAP_FRAME  TrapFrame)

Referenced by KiUserModeCallout().

◆ KiUserTrap()

◆ KiXmmException()

VOID KiXmmException ( VOID  )

◆ NtEarlyInitVdm()

VOID NtEarlyInitVdm ( VOID  )

Variable Documentation

◆ KeI386CpuStep

ULONG KeI386CpuStep
extern

Definition at line 25 of file cpu.c.

Referenced by KiInitializeKernel(), and KiInitializeKernelMachineDependent().

◆ KeI386CpuType

ULONG KeI386CpuType
extern

Definition at line 24 of file cpu.c.

Referenced by KiInitializeKernel(), and KiInitializeKernelMachineDependent().

◆ KeI386FxsrPresent

◆ KeI386NpxPresent

ULONG KeI386NpxPresent
extern

Definition at line 27 of file cpu.c.

Referenced by CmpInitializeMachineDependentConfiguration().

◆ KeI386XMMIPresent

ULONG KeI386XMMIPresent
extern

Definition at line 32 of file cpu.c.

Referenced by KiInitializeKernel().

◆ KeTickCount