ReactOS 0.4.16-dev-747-gbc52d5f
ke.h File Reference
#include "intrin_i.h"
#include "trap_x.h"
Include dependency graph for ke.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

union  _KTRAP_EXIT_SKIP_BITS
 
struct  _KV86_FRAME
 
struct  _KV8086_STACK_FRAME
 
struct  _LARGE_IDENTITY_MAP
 
struct  _FLOATING_SAVE_CONTEXT
 

Macros

#define DR_MASK(x)   (1 << (x))
 
#define DR_REG_MASK   0x4F
 
#define KD_BREAKPOINT_TYPE   UCHAR
 
#define KD_BREAKPOINT_SIZE   sizeof(UCHAR)
 
#define KD_BREAKPOINT_VALUE   0xCC
 
#define X86_FEATURE_SSE3   0x00000001
 
#define X86_FEATURE_SSSE3   0x00000200
 
#define X86_FEATURE_SSE4_1   0x00080000
 
#define X86_FEATURE_SSE4_2   0x00100000
 
#define X86_FEATURE_XSAVE   0x04000000
 
#define X86_FEATURE_RDRAND   0x40000000
 
#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_APIC   0x00000200 /* APIC is 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_NX   0x00100000 /* NX support present */
 
#define KeGetTrapFrame(Thread)
 
#define KeGetExceptionFrame(Thread)    NULL
 
#define KeGetContextSwitches(Prcb)    CONTAINING_RECORD(Prcb, KIPCR, PrcbData)->ContextSwitches
 
#define KiGetSecondLevelDCacheSize()   ((PKIPCR)KeGetPcr())->SecondLevelCacheSize
 
#define KeGetTrapFrameInterruptState(TrapFrame)    BooleanFlagOn((TrapFrame)->EFlags, EFLAGS_INTERRUPT_MASK)
 
#define KTE_SKIP_PM_BIT   (((KTRAP_EXIT_SKIP_BITS) { { .SkipPreviousMode = TRUE } }).Bits)
 
#define KTE_SKIP_SEG_BIT   (((KTRAP_EXIT_SKIP_BITS) { { .SkipSegments = TRUE } }).Bits)
 
#define KTE_SKIP_VOL_BIT   (((KTRAP_EXIT_SKIP_BITS) { { .SkipVolatiles = TRUE } }).Bits)
 
#define PFX_FLAG_ES   0x00000100
 
#define PFX_FLAG_CS   0x00000200
 
#define PFX_FLAG_SS   0x00000400
 
#define PFX_FLAG_DS   0x00000800
 
#define PFX_FLAG_FS   0x00001000
 
#define PFX_FLAG_GS   0x00002000
 
#define PFX_FLAG_OPER32   0x00004000
 
#define PFX_FLAG_ADDR32   0x00008000
 
#define PFX_FLAG_LOCK   0x00010000
 
#define PFX_FLAG_REPNE   0x00020000
 
#define PFX_FLAG_REP   0x00040000
 
#define KiVdmSetVdmEFlags(x)   InterlockedOr((PLONG)KiNtVdmState, (x));
 
#define KiVdmClearVdmEFlags(x)   InterlockedAnd((PLONG)KiNtVdmState, ~(x))
 
#define KiCallVdmHandler(x)   KiVdmOpcode##x(TrapFrame, Flags)
 
#define KiCallVdmPrefixHandler(x)   KiVdmOpcodePrefix(TrapFrame, Flags | x)
 
#define KiVdmUnhandledOpcode(x)
 

Typedefs

typedef union _KTRAP_EXIT_SKIP_BITS KTRAP_EXIT_SKIP_BITS
 
typedef union _KTRAP_EXIT_SKIP_BITSPKTRAP_EXIT_SKIP_BITS
 
typedef struct _KV86_FRAME KV86_FRAME
 
typedef struct _KV86_FRAMEPKV86_FRAME
 
typedef struct _KV8086_STACK_FRAME KV8086_STACK_FRAME
 
typedef struct _KV8086_STACK_FRAMEPKV8086_STACK_FRAME
 
typedef struct _LARGE_IDENTITY_MAP LARGE_IDENTITY_MAP
 
typedef struct _LARGE_IDENTITY_MAPPLARGE_IDENTITY_MAP
 
typedef struct _FLOATING_SAVE_CONTEXT FLOATING_SAVE_CONTEXT
 
typedef struct _FLOATING_SAVE_CONTEXTPFLOATING_SAVE_CONTEXT
 

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 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)
 
 C_ASSERT (NPX_FRAME_LENGTH==sizeof(FX_SAVE_AREA))
 
FORCEINLINE BOOLEAN KeDisableInterrupts (VOID)
 
FORCEINLINE VOID KeRestoreInterrupts (BOOLEAN WereEnabled)
 
FORCEINLINE VOID KeRegisterInterruptHandler (IN ULONG Vector, IN PVOID Handler)
 
FORCEINLINE PVOID KeQueryInterruptHandler (IN ULONG Vector)
 
FORCEINLINE VOID KeInvalidateTlbEntry (IN PVOID Address)
 
FORCEINLINE VOID KeFlushProcessTb (VOID)
 
FORCEINLINE VOID KeSweepICache (IN PVOID BaseAddress, IN SIZE_T FlushSize)
 
FORCEINLINE PRKTHREAD KeGetCurrentThread (VOID)
 
FORCEINLINE VOID KiRundownThread (IN PKTHREAD Thread)
 
VOID NTAPI KiInitializePcr (IN ULONG ProcessorNumber, IN PKIPCR Pcr, IN PKIDTENTRY Idt, IN PKGDTENTRY Gdt, IN PKTSS Tss, IN PKTHREAD IdleThread, IN PVOID DpcStack)
 
FORCEINLINE VOID Ke386SetGdtEntryBase (PKGDTENTRY GdtEntry, PVOID BaseAddress)
 
FORCEINLINE VOID KiSetTebBase (PKPCR Pcr, PNT_TIB TebAddress)
 
VOID FASTCALL Ki386InitializeTss (IN PKTSS Tss, IN PKIDTENTRY Idt, IN PKGDTENTRY Gdt)
 
VOID NTAPI KiSetCR0Bits (VOID)
 
VOID NTAPI KiGetCacheInformation (VOID)
 
BOOLEAN NTAPI KiIsNpxPresent (VOID)
 
BOOLEAN NTAPI KiIsNpxErrataPresent (VOID)
 
VOID NTAPI KiSetProcessorType (VOID)
 
ULONG64 NTAPI KiGetFeatureBits (VOID)
 Evaluates the KeFeatureFlag bits for the current CPU.
 
VOID NTAPI KiThreadStartup (VOID)
 
NTSTATUS NTAPI Ke386GetGdtEntryThread (IN PKTHREAD Thread, IN ULONG Offset, IN PKGDTENTRY Descriptor)
 
VOID NTAPI KiFlushNPXState (IN FLOATING_SAVE_AREA *SaveArea)
 
VOID NTAPI Ki386AdjustEsp0 (IN PKTRAP_FRAME TrapFrame)
 
VOID NTAPI Ki386SetupAndExitToV86Mode (OUT PTEB VdmTeb)
 
VOID NTAPI KeI386VdmInitialize (VOID)
 
ULONG_PTR NTAPI Ki386EnableGlobalPage (IN ULONG_PTR Context)
 
ULONG_PTR NTAPI Ki386EnableTargetLargePage (IN ULONG_PTR Context)
 
BOOLEAN NTAPI Ki386CreateIdentityMap (IN PLARGE_IDENTITY_MAP IdentityMap, IN PVOID StartPtr, IN ULONG Length)
 
VOID NTAPI Ki386FreeIdentityMap (IN PLARGE_IDENTITY_MAP IdentityMap)
 
VOID NTAPI Ki386EnableCurrentLargePage (IN ULONG_PTR StartAddress, IN ULONG Cr3)
 
VOID NTAPI KiI386PentiumLockErrataFixup (VOID)
 
VOID NTAPI KiInitializePAT (VOID)
 
VOID NTAPI KiInitializeMTRR (IN BOOLEAN FinalCpu)
 
VOID NTAPI KiAmdK6InitializeMTRR (VOID)
 
VOID NTAPI KiRestoreFastSyscallReturnState (VOID)
 
ULONG_PTR NTAPI Ki386EnableDE (IN ULONG_PTR Context)
 
ULONG_PTR NTAPI Ki386EnableFxsr (IN ULONG_PTR Context)
 
ULONG_PTR NTAPI Ki386EnableXMMIExceptions (IN ULONG_PTR Context)
 
BOOLEAN NTAPI VdmDispatchBop (IN PKTRAP_FRAME TrapFrame)
 
BOOLEAN NTAPI VdmDispatchPageFault (_In_ PKTRAP_FRAME TrapFrame)
 
BOOLEAN FASTCALL KiVdmOpcodePrefix (IN PKTRAP_FRAME TrapFrame, IN ULONG Flags)
 
BOOLEAN FASTCALL Ki386HandleOpcodeV86 (IN PKTRAP_FRAME TrapFrame)
 
DECLSPEC_NORETURN VOID FASTCALL KiEoiHelper (IN PKTRAP_FRAME TrapFrame)
 
VOID FASTCALL Ki386BiosCallReturnAddress (IN PKTRAP_FRAME TrapFrame)
 
ULONG_PTR FASTCALL KiExitV86Mode (IN PKTRAP_FRAME TrapFrame)
 
DECLSPEC_NORETURN VOID NTAPI KiDispatchExceptionFromTrapFrame (IN NTSTATUS Code, IN ULONG Flags, IN ULONG_PTR Address, IN ULONG ParameterCount, IN ULONG_PTR Parameter1, IN ULONG_PTR Parameter2, IN ULONG_PTR Parameter3, IN PKTRAP_FRAME TrapFrame)
 
NTSTATUS NTAPI KiConvertToGuiThread (VOID)
 
DECLSPEC_NORETURN VOID FASTCALL KiServiceExit (IN PKTRAP_FRAME TrapFrame, IN NTSTATUS Status)
 
DECLSPEC_NORETURN VOID FASTCALL KiServiceExit2 (IN PKTRAP_FRAME TrapFrame)
 
FORCEINLINE DECLSPEC_NORETURN VOID KiExceptionExit (_In_ PKTRAP_FRAME TrapFrame, _In_ PKEXCEPTION_FRAME ExceptionFrame)
 
VOID __cdecl KiTrap02 (VOID)
 
VOID __cdecl KiTrap08 (VOID)
 
VOID __cdecl KiTrap13 (VOID)
 
VOID __cdecl KiFastCallEntry (VOID)
 
VOID NTAPI ExpInterlockedPopEntrySListFault (VOID)
 
VOID NTAPI ExpInterlockedPopEntrySListResume (VOID)
 
VOID __cdecl CopyParams (VOID)
 
VOID __cdecl ReadBatch (VOID)
 
FORCEINLINE PFX_SAVE_AREA KiGetThreadNpxArea (IN PKTHREAD Thread)
 
FORCEINLINE ULONG Ke386SanitizeSeg (IN ULONG Cs, IN KPROCESSOR_MODE Mode)
 
FORCEINLINE ULONG Ke386SanitizeFlags (IN ULONG Eflags, IN KPROCESSOR_MODE Mode)
 
FORCEINLINE PVOID Ke386SanitizeDr (IN PVOID DrAddress, IN KPROCESSOR_MODE Mode)
 
FORCEINLINE DECLSPEC_NORETURN VOID KiDispatchException0Args (IN NTSTATUS Code, IN ULONG_PTR Address, IN PKTRAP_FRAME TrapFrame)
 
FORCEINLINE DECLSPEC_NORETURN VOID KiDispatchException1Args (IN NTSTATUS Code, IN ULONG_PTR Address, IN ULONG P1, IN PKTRAP_FRAME TrapFrame)
 
FORCEINLINE DECLSPEC_NORETURN VOID KiDispatchException2Args (IN NTSTATUS Code, IN ULONG_PTR Address, IN ULONG P1, IN ULONG P2, IN PKTRAP_FRAME TrapFrame)
 
NTSTATUS NTAPI KiSystemCallTrampoline (_In_ PVOID Handler, _In_ PVOID Arguments, _In_ ULONG StackBytes)
 
FORCEINLINE VOID KiCheckForApcDelivery (IN PKTRAP_FRAME TrapFrame)
 
FORCEINLINE DECLSPEC_NORETURN VOID KiSwitchToBootStack (IN ULONG_PTR InitialStack)
 
FORCEINLINE DECLSPEC_NORETURN VOID KiIret (VOID)
 
FORCEINLINE VOID KiEndInterrupt (IN KIRQL Irql, IN PKTRAP_FRAME TrapFrame)
 
FORCEINLINE VOID Ki386PerfEnd (VOID)
 
FORCEINLINE PULONG KiGetUserModeStackAddress (void)
 

Variables

PVOID Ki386IopmSaveArea
 
ULONG KeI386EFlagsAndMaskV86
 
ULONG KeI386EFlagsOrMaskV86
 
BOOLEAN KeI386VirtualIntExtensions
 
KIDTENTRY KiIdt [MAXIMUM_IDTVECTOR+1]
 
KDESCRIPTOR KiIdtDescriptor
 
BOOLEAN KiI386PentiumLockErrataPresent
 
ULONG KeI386NpxPresent
 
ULONG KeI386XMMIPresent
 
ULONG KeI386FxsrPresent
 
ULONG KiMXCsrMask
 
ULONG KeI386CpuType
 
ULONG KeI386CpuStep
 
ULONG KiFastSystemCallDisable
 
UCHAR KiDebugRegisterTrapOffsets [9]
 
UCHAR KiDebugRegisterContextOffsets [9]
 
CHAR KiSystemCallExitBranch []
 
CHAR KiSystemCallExit []
 
CHAR KiSystemCallExit2 []
 

Macro Definition Documentation

◆ DR_MASK

#define DR_MASK (   x)    (1 << (x))

Definition at line 15 of file ke.h.

◆ DR_REG_MASK

#define DR_REG_MASK   0x4F

Definition at line 16 of file ke.h.

◆ KD_BREAKPOINT_SIZE

#define KD_BREAKPOINT_SIZE   sizeof(UCHAR)

Definition at line 22 of file ke.h.

◆ KD_BREAKPOINT_TYPE

#define KD_BREAKPOINT_TYPE   UCHAR

Definition at line 21 of file ke.h.

◆ KD_BREAKPOINT_VALUE

#define KD_BREAKPOINT_VALUE   0xCC

Definition at line 23 of file ke.h.

◆ KeGetContextSwitches

#define KeGetContextSwitches (   Prcb)     CONTAINING_RECORD(Prcb, KIPCR, PrcbData)->ContextSwitches

Definition at line 148 of file ke.h.

◆ KeGetExceptionFrame

#define KeGetExceptionFrame (   Thread)     NULL

Definition at line 141 of file ke.h.

◆ KeGetTrapFrame

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

Definition at line 136 of file ke.h.

◆ KeGetTrapFrameInterruptState

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

Definition at line 161 of file ke.h.

◆ KiCallVdmHandler

#define KiCallVdmHandler (   x)    KiVdmOpcode##x(TrapFrame, Flags)

Definition at line 223 of file ke.h.

◆ KiCallVdmPrefixHandler

#define KiCallVdmPrefixHandler (   x)    KiVdmOpcodePrefix(TrapFrame, Flags | x)

Definition at line 224 of file ke.h.

◆ KiGetSecondLevelDCacheSize

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

Definition at line 155 of file ke.h.

◆ KiVdmClearVdmEFlags

#define KiVdmClearVdmEFlags (   x)    InterlockedAnd((PLONG)KiNtVdmState, ~(x))

Definition at line 222 of file ke.h.

◆ KiVdmSetVdmEFlags

#define KiVdmSetVdmEFlags (   x)    InterlockedOr((PLONG)KiNtVdmState, (x));

Definition at line 221 of file ke.h.

◆ KiVdmUnhandledOpcode

#define KiVdmUnhandledOpcode (   x)
Value:
BOOLEAN \
FASTCALL \
KiVdmOpcode##x(IN PKTRAP_FRAME TrapFrame, \
{ \
/* Not yet handled */ \
UNIMPLEMENTED_DBGBREAK(); \
return FALSE; \
}
#define FALSE
Definition: types.h:117
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170

Definition at line 225 of file ke.h.

◆ KTE_SKIP_PM_BIT

#define KTE_SKIP_PM_BIT   (((KTRAP_EXIT_SKIP_BITS) { { .SkipPreviousMode = TRUE } }).Bits)

Definition at line 167 of file ke.h.

◆ KTE_SKIP_SEG_BIT

#define KTE_SKIP_SEG_BIT   (((KTRAP_EXIT_SKIP_BITS) { { .SkipSegments = TRUE } }).Bits)

Definition at line 168 of file ke.h.

◆ KTE_SKIP_VOL_BIT

#define KTE_SKIP_VOL_BIT   (((KTRAP_EXIT_SKIP_BITS) { { .SkipVolatiles = TRUE } }).Bits)

Definition at line 169 of file ke.h.

◆ PFX_FLAG_ADDR32

#define PFX_FLAG_ADDR32   0x00008000

Definition at line 194 of file ke.h.

◆ PFX_FLAG_CS

#define PFX_FLAG_CS   0x00000200

Definition at line 188 of file ke.h.

◆ PFX_FLAG_DS

#define PFX_FLAG_DS   0x00000800

Definition at line 190 of file ke.h.

◆ PFX_FLAG_ES

#define PFX_FLAG_ES   0x00000100

Definition at line 187 of file ke.h.

◆ PFX_FLAG_FS

#define PFX_FLAG_FS   0x00001000

Definition at line 191 of file ke.h.

◆ PFX_FLAG_GS

#define PFX_FLAG_GS   0x00002000

Definition at line 192 of file ke.h.

◆ PFX_FLAG_LOCK

#define PFX_FLAG_LOCK   0x00010000

Definition at line 195 of file ke.h.

◆ PFX_FLAG_OPER32

#define PFX_FLAG_OPER32   0x00004000

Definition at line 193 of file ke.h.

◆ PFX_FLAG_REP

#define PFX_FLAG_REP   0x00040000

Definition at line 197 of file ke.h.

◆ PFX_FLAG_REPNE

#define PFX_FLAG_REPNE   0x00020000

Definition at line 196 of file ke.h.

◆ PFX_FLAG_SS

#define PFX_FLAG_SS   0x00000400

Definition at line 189 of file ke.h.

◆ X86_FEATURE_APIC

#define X86_FEATURE_APIC   0x00000200 /* APIC is present */

Definition at line 41 of file ke.h.

◆ X86_FEATURE_CMOV

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

Definition at line 45 of file ke.h.

◆ X86_FEATURE_CX8

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

Definition at line 40 of file ke.h.

◆ X86_FEATURE_DBG

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

Definition at line 36 of file ke.h.

◆ X86_FEATURE_DS

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

Definition at line 47 of file ke.h.

◆ X86_FEATURE_FPU

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

Definition at line 34 of file ke.h.

◆ X86_FEATURE_FXSR

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

Definition at line 49 of file ke.h.

◆ X86_FEATURE_HT

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

Definition at line 52 of file ke.h.

◆ X86_FEATURE_MMX

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

Definition at line 48 of file ke.h.

◆ X86_FEATURE_MTTR

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

Definition at line 43 of file ke.h.

◆ X86_FEATURE_NX

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

Definition at line 55 of file ke.h.

◆ X86_FEATURE_PAE

#define X86_FEATURE_PAE   0x00000040 /* Physical Address Extension is present */

Definition at line 39 of file ke.h.

◆ X86_FEATURE_PAT

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

Definition at line 46 of file ke.h.

◆ X86_FEATURE_PGE

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

Definition at line 44 of file ke.h.

◆ X86_FEATURE_PSE

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

Definition at line 37 of file ke.h.

◆ X86_FEATURE_RDRAND

#define X86_FEATURE_RDRAND   0x40000000

Definition at line 31 of file ke.h.

◆ X86_FEATURE_SSE

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

Definition at line 50 of file ke.h.

◆ X86_FEATURE_SSE2

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

Definition at line 51 of file ke.h.

◆ X86_FEATURE_SSE3

#define X86_FEATURE_SSE3   0x00000001

Definition at line 26 of file ke.h.

◆ X86_FEATURE_SSE4_1

#define X86_FEATURE_SSE4_1   0x00080000

Definition at line 28 of file ke.h.

◆ X86_FEATURE_SSE4_2

#define X86_FEATURE_SSE4_2   0x00100000

Definition at line 29 of file ke.h.

◆ X86_FEATURE_SSSE3

#define X86_FEATURE_SSSE3   0x00000200

Definition at line 27 of file ke.h.

◆ X86_FEATURE_SYSCALL

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

Definition at line 42 of file ke.h.

◆ X86_FEATURE_TSC

#define X86_FEATURE_TSC   0x00000010 /* Time Stamp Counters are present */

Definition at line 38 of file ke.h.

◆ X86_FEATURE_VME

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

Definition at line 35 of file ke.h.

◆ X86_FEATURE_XSAVE

#define X86_FEATURE_XSAVE   0x04000000

Definition at line 30 of file ke.h.

Typedef Documentation

◆ FLOATING_SAVE_CONTEXT

◆ KTRAP_EXIT_SKIP_BITS

◆ KV8086_STACK_FRAME

◆ KV86_FRAME

◆ LARGE_IDENTITY_MAP

◆ PFLOATING_SAVE_CONTEXT

◆ PKTRAP_EXIT_SKIP_BITS

◆ PKV8086_STACK_FRAME

◆ PKV86_FRAME

◆ PLARGE_IDENTITY_MAP

Function Documentation

◆ C_ASSERT()

◆ CopyParams()

VOID __cdecl CopyParams ( VOID  )

Referenced by KiTrap0EHandler().

◆ ExpInterlockedPopEntrySListFault()

VOID NTAPI ExpInterlockedPopEntrySListFault ( VOID  )

◆ ExpInterlockedPopEntrySListResume()

VOID NTAPI ExpInterlockedPopEntrySListResume ( VOID  )

Referenced by KiCheckForSListFault().

◆ Ke386GetGdtEntryThread()

NTSTATUS NTAPI Ke386GetGdtEntryThread ( IN PKTHREAD  Thread,
IN ULONG  Offset,
IN PKGDTENTRY  Descriptor 
)

Definition at line 26 of file ldt.c.

29{
30 /* Make sure the offset isn't outside the allowed range */
31 if (Offset >= (KGDT_NUMBER * sizeof(KGDTENTRY)))
32 {
33 /* It is, fail */
35 }
36
37 /* Check if this is the LDT selector */
38 if (Offset == KGDT_LDT)
39 {
40 /* Get it from the thread's process */
42 &Thread->Process->LdtDescriptor,
43 sizeof(KGDTENTRY));
44 }
45 else
46 {
47 /* Get the descriptor entry from the GDT */
49 (PVOID)(((ULONG_PTR)KeGetPcr()->GDT) + Offset),
50 sizeof(KGDTENTRY));
51
52 /* Check if this is the TEB selector */
53 if (Offset == KGDT_R3_TEB)
54 {
55 /*
56 * Make sure we set the correct base for this thread. This is per
57 * process and is set in the GDT on context switch, so it might not
58 * be correct for the thread specified.
59 */
60 Descriptor->BaseLow =
61 (USHORT)((ULONG_PTR)(Thread->Teb) & 0xFFFF);
62 Descriptor->HighWord.Bytes.BaseMid =
63 (UCHAR)((ULONG_PTR)(Thread->Teb) >> 16);
64 Descriptor->HighWord.Bytes.BaseHi =
65 (UCHAR)((ULONG_PTR)(Thread->Teb) >> 24);
66 }
67 }
68
69 /* Success */
70 return STATUS_SUCCESS;
71}
#define KGDT_R3_TEB
Definition: ketypes.h:129
#define KeGetPcr()
Definition: ketypes.h:81
#define KGDT_NUMBER
Definition: ketypes.h:138
#define KGDT_LDT
Definition: ketypes.h:131
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
unsigned short USHORT
Definition: pedump.c:61
#define STATUS_SUCCESS
Definition: shellext.h:65
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
_Must_inspect_result_ _In_ WDFIORESLIST _In_ PIO_RESOURCE_DESCRIPTOR Descriptor
Definition: wdfresource.h:342
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by PspQueryDescriptorThread().

◆ Ke386SanitizeDr()

FORCEINLINE PVOID Ke386SanitizeDr ( IN PVOID  DrAddress,
IN KPROCESSOR_MODE  Mode 
)

Definition at line 786 of file ke.h.

788{
789 //
790 // Check if we're in kernel-mode, and return the address directly if so.
791 // Otherwise, make sure it's not inside the kernel-mode address space.
792 // If it is, then clear the address.
793 //
794 return ((Mode == KernelMode) ? DrAddress :
795 (DrAddress <= MM_HIGHEST_USER_ADDRESS) ? DrAddress : 0);
796}
#define MM_HIGHEST_USER_ADDRESS
Definition: armddk.h:17
_In_ ULONG Mode
Definition: hubbusif.h:303
#define KernelMode
Definition: asm.h:38

◆ Ke386SanitizeFlags()

FORCEINLINE ULONG Ke386SanitizeFlags ( IN ULONG  Eflags,
IN KPROCESSOR_MODE  Mode 
)

Definition at line 769 of file ke.h.

771{
772 //
773 // Check if we're in kernel-mode, and sanitize EFLAGS if so.
774 // Otherwise, also force interrupt mask on.
775 //
776 return ((Mode == KernelMode) ?
779}
#define EFLAGS_INTERRUPT_MASK
Definition: SystemCall.c:11
#define EFLAGS_USER_SANITIZE
Definition: ketypes.h:202

Referenced by KeContextToTrapFrame(), and KiInitializeUserApc().

◆ Ke386SanitizeSeg()

FORCEINLINE ULONG Ke386SanitizeSeg ( IN ULONG  Cs,
IN KPROCESSOR_MODE  Mode 
)

Definition at line 752 of file ke.h.

754{
755 //
756 // Check if we're in kernel-mode, and force CPL 0 if so.
757 // Otherwise, force CPL 3.
758 //
759 return ((Mode == KernelMode) ?
760 (Cs & (0xFFFF & ~RPL_MASK)) :
761 (RPL_MASK | (Cs & 0xFFFF)));
762}
#define RPL_MASK
Definition: ketypes.h:119

Referenced by KeContextToTrapFrame(), KiDispatchException(), and KiInitializeUserApc().

◆ Ke386SetGdtEntryBase()

FORCEINLINE VOID Ke386SetGdtEntryBase ( PKGDTENTRY  GdtEntry,
PVOID  BaseAddress 
)

Definition at line 419 of file ke.h.

420{
421 GdtEntry->BaseLow = (USHORT)((ULONG_PTR)BaseAddress & 0xFFFF);
422 GdtEntry->HighWord.Bytes.BaseMid = (UCHAR)((ULONG_PTR)BaseAddress >> 16);
423 GdtEntry->HighWord.Bytes.BaseHi = (UCHAR)((ULONG_PTR)BaseAddress >> 24);
424}
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
USHORT BaseLow
Definition: ketypes.h:390
union _KGDTENTRY::@2459 HighWord
struct _KGDTENTRY::@2459::@2460 Bytes

Referenced by KiSetTebBase().

◆ KeDisableInterrupts()

FORCEINLINE BOOLEAN KeDisableInterrupts ( VOID  )

Definition at line 284 of file ke.h.

285{
286 ULONG Flags;
287 BOOLEAN Return;
288
289 /* Get EFLAGS and check if the interrupt bit is set */
291 Return = (Flags & EFLAGS_INTERRUPT_MASK) ? TRUE: FALSE;
292
293 /* Disable interrupts */
294 _disable();
295 return Return;
296}
unsigned char BOOLEAN
#define TRUE
Definition: types.h:120
void __cdecl _disable(void)
Definition: intrin_arm.h:365
__INTRIN_INLINE uintptr_t __readeflags(void)
Definition: intrin_x86.h:1688

◆ KeFlushProcessTb()

FORCEINLINE VOID KeFlushProcessTb ( VOID  )

Definition at line 366 of file ke.h.

367{
368 /* Flush the TLB by resetting CR3 */
370}
__INTRIN_INLINE unsigned long __readcr3(void)
Definition: intrin_x86.h:1832
__INTRIN_INLINE void __writecr3(unsigned int Data)
Definition: intrin_x86.h:1808

◆ KeGetContextFrameRegister()

FORCEINLINE ULONG_PTR KeGetContextFrameRegister ( PCONTEXT  Context)

Definition at line 90 of file ke.h.

91{
92 return Context->Ebp;
93}

◆ KeGetContextPc()

FORCEINLINE ULONG_PTR KeGetContextPc ( PCONTEXT  Context)

Definition at line 62 of file ke.h.

63{
64 return Context->Eip;
65}

◆ KeGetContextReturnRegister()

FORCEINLINE ULONG_PTR KeGetContextReturnRegister ( PCONTEXT  Context)

Definition at line 76 of file ke.h.

77{
78 return Context->Eax;
79}

◆ KeGetCurrentThread()

FORCEINLINE PRKTHREAD KeGetCurrentThread ( VOID  )

Definition at line 387 of file ke.h.

388{
389 /* Return the current thread */
390 return ((PKIPCR)KeGetPcr())->PrcbData.CurrentThread;
391}

◆ KeGetTrapFrameFrameRegister()

FORCEINLINE ULONG_PTR KeGetTrapFrameFrameRegister ( PKTRAP_FRAME  TrapFrame)

Definition at line 128 of file ke.h.

129{
130 return TrapFrame->Ebp;
131}
ULONG Ebp
Definition: ketypes.h:319

◆ KeGetTrapFramePc()

FORCEINLINE ULONG_PTR KeGetTrapFramePc ( PKTRAP_FRAME  TrapFrame)

Definition at line 104 of file ke.h.

105{
106 return TrapFrame->Eip;
107}
ULONG Eip
Definition: ketypes.h:321

◆ KeGetTrapFrameStackRegister()

FORCEINLINE ULONG_PTR KeGetTrapFrameStackRegister ( PKTRAP_FRAME  TrapFrame)

Definition at line 119 of file ke.h.

120{
121 if (TrapFrame->PreviousPreviousMode == KernelMode)
122 return TrapFrame->TempEsp;
123 return TrapFrame->HardwareEsp;
124}
ULONG TempEsp
Definition: ketypes.h:300
ULONG PreviousPreviousMode
Definition: ketypes.h:313
ULONG HardwareEsp
Definition: ketypes.h:324

◆ KeI386VdmInitialize()

VOID NTAPI KeI386VdmInitialize ( VOID  )

Definition at line 42 of file vdmmain.c.

43{
48 UCHAR KeyValueInfo[sizeof(KEY_VALUE_BASIC_INFORMATION) + 30];
50
51 /* Make sure that there is a WOW key */
53 L"\\Registry\\Machine\\System\\CurrentControlSet\\"
54 L"Control\\Wow");
56 &Name,
58 NULL,
59 NULL);
61 if (!NT_SUCCESS(Status)) return;
62
63 /* Check if VME is enabled */
64 RtlInitUnicodeString(&Name, L"DisableVme");
65 Status = ZwQueryValueKey(RegHandle,
66 &Name,
68 &KeyValueInfo,
69 sizeof(KeyValueInfo),
71 if (!NT_SUCCESS(Status))
72 {
73 /* Not present, so check if the CPU supports VME */
74 if (KeGetPcr()->Prcb->FeatureBits & KF_V86_VIS)
75 {
76 /* Enable them. FIXME: Use IPI */
79 }
80 }
81
82 /* Close the key */
84}
_In_ PVOID _In_ ULONG _Out_ PVOID _In_ ULONG _Inout_ PULONG ReturnLength
struct NameRec_ * Name
Definition: cdprocs.h:460
LONG NTSTATUS
Definition: precomp.h:26
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
Status
Definition: gdiplustypes.h:25
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define KF_V86_VIS
Definition: ketypes.h:30
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
struct _KEY_VALUE_BASIC_INFORMATION KEY_VALUE_BASIC_INFORMATION
@ KeyValueBasicInformation
Definition: nt_native.h:1180
#define KEY_READ
Definition: nt_native.h:1023
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
BOOLEAN KeI386VirtualIntExtensions
Definition: v86vdm.c:24
#define L(x)
Definition: ntvdm.h:50
VOID NTAPI Ki386VdmEnablePentiumExtentions(IN BOOLEAN Enable)
Definition: vdmmain.c:23
_In_opt_ PETWENABLECALLBACK _In_opt_ PVOID _Out_ PREGHANDLE RegHandle
Definition: wmifuncs.h:78

Referenced by Phase1InitializationDiscard().

◆ KeInvalidateTlbEntry()

FORCEINLINE VOID KeInvalidateTlbEntry ( IN PVOID  Address)

Definition at line 358 of file ke.h.

359{
360 /* Invalidate the TLB entry for this address */
362}
__INTRIN_INLINE void __invlpg(void *Address)
Definition: intrin_x86.h:1982
static WCHAR Address[46]
Definition: ping.c:68

◆ KeQueryInterruptHandler()

FORCEINLINE PVOID KeQueryInterruptHandler ( IN ULONG  Vector)

Definition at line 336 of file ke.h.

337{
338 PKIPCR Pcr = (PKIPCR)KeGetPcr();
339 UCHAR Entry;
340
341 //
342 // Get the entry from the HAL
343 //
345
346 //
347 // Read the entry from the IDT
348 //
349 return (PVOID)(((Pcr->IDT[Entry].ExtendedOffset << 16) & 0xFFFF0000) |
350 (Pcr->IDT[Entry].Offset & 0xFFFF));
351}
struct _KIPCR * PKIPCR
#define HalVectorToIDTEntry
Definition: halfuncs.h:51
base of all file and directory entries
Definition: entries.h:83
USHORT Offset
Definition: ketypes.h:440
USHORT ExtendedOffset
Definition: ketypes.h:443
PKIDTENTRY IDT
Definition: ketypes.h:818

◆ KeRegisterInterruptHandler()

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

Definition at line 311 of file ke.h.

313{
314 UCHAR Entry;
316 PKIPCR Pcr = (PKIPCR)KeGetPcr();
317
318 //
319 // Get the entry from the HAL
320 //
323
324 //
325 // Now set the data
326 //
327 Pcr->IDT[Entry].ExtendedOffset = (USHORT)(Address >> 16);
328 Pcr->IDT[Entry].Offset = (USHORT)Address;
329}
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 PtrToUlong(u)
Definition: config.h:107

◆ KeRestoreInterrupts()

FORCEINLINE VOID KeRestoreInterrupts ( BOOLEAN  WereEnabled)

Definition at line 301 of file ke.h.

302{
303 if (WereEnabled) _enable();
304}
void __cdecl _enable(void)
Definition: intrin_arm.h:373

◆ KeSetContextFrameRegister()

FORCEINLINE VOID KeSetContextFrameRegister ( PCONTEXT  Context,
ULONG_PTR  Frame 
)

Definition at line 97 of file ke.h.

98{
99 Context->Ebp = Frame;
100}

◆ KeSetContextPc()

FORCEINLINE VOID KeSetContextPc ( PCONTEXT  Context,
ULONG_PTR  ProgramCounter 
)

Definition at line 69 of file ke.h.

70{
71 Context->Eip = ProgramCounter;
72}

◆ KeSetContextReturnRegister()

FORCEINLINE VOID KeSetContextReturnRegister ( PCONTEXT  Context,
ULONG_PTR  ReturnValue 
)

Definition at line 83 of file ke.h.

84{
85 Context->Eax = ReturnValue;
86}
UINT32 void void ** ReturnValue
Definition: acevents.h:216

◆ KeSweepICache()

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

Definition at line 374 of file ke.h.

376{
377 //
378 // Always sweep the whole cache
379 //
381 UNREFERENCED_PARAMETER(FlushSize);
382 __wbinvd();
383}
PPC_QUAL void __wbinvd(void)
Definition: intrin_ppc.h:759
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:325

◆ Ki386AdjustEsp0()

VOID NTAPI Ki386AdjustEsp0 ( IN PKTRAP_FRAME  TrapFrame)

Definition at line 280 of file exp.c.

281{
284 ULONG EFlags;
285
286 /* Get the current thread's stack */
288 Stack = (ULONG_PTR)Thread->InitialStack;
289
290 /* Check if we are in V8086 mode */
291 if (!(TrapFrame->EFlags & EFLAGS_V86_MASK))
292 {
293 /* Bias the stack for the V86 segments */
294 Stack -= sizeof(KTRAP_FRAME) -
296 }
297
298 /* Bias the stack for the FPU area */
299 Stack -= sizeof(FX_SAVE_AREA);
300
301 /* Disable interrupts */
302 EFlags = __readeflags();
303 _disable();
304
305 /* Set new ESP0 value in the TSS */
306 KeGetPcr()->TSS->Esp0 = Stack;
307
308 /* Restore old interrupt state */
309 __writeeflags(EFlags);
310}
#define ULONG_PTR
Definition: config.h:101
#define KeGetCurrentThread
Definition: hal.h:55
__INTRIN_INLINE void __writeeflags(uintptr_t Value)
Definition: intrin_x86.h:1683
if(dx< 0)
Definition: linetemp.h:194
struct _KTRAP_FRAME KTRAP_FRAME
#define EFLAGS_V86_MASK
Definition: ketypes.h:197
struct _FX_SAVE_AREA FX_SAVE_AREA
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
Definition: wdfrequest.h:639

Referenced by KeContextToTrapFrame(), KiVdmOpcodeIRET(), KiVdmOpcodePOPF(), and VdmSwapContext().

◆ Ki386BiosCallReturnAddress()

VOID FASTCALL Ki386BiosCallReturnAddress ( IN PKTRAP_FRAME  TrapFrame)

Referenced by KiEnterV86Mode(), and KiTrap0DHandler().

◆ Ki386CreateIdentityMap()

BOOLEAN NTAPI Ki386CreateIdentityMap ( IN PLARGE_IDENTITY_MAP  IdentityMap,
IN PVOID  StartPtr,
IN ULONG  Length 
)

Referenced by KiInitMachineDependent().

◆ Ki386EnableCurrentLargePage()

VOID NTAPI Ki386EnableCurrentLargePage ( IN ULONG_PTR  StartAddress,
IN ULONG  Cr3 
)

◆ Ki386EnableDE()

ULONG_PTR NTAPI Ki386EnableDE ( IN ULONG_PTR  Context)

Definition at line 1073 of file cpu.c.

1074{
1075 /* Enable DE */
1077 return 0;
1078}
__INTRIN_INLINE unsigned long __readcr4(void)
Definition: intrin_x86.h:1839
__INTRIN_INLINE void __writecr4(unsigned int Data)
Definition: intrin_x86.h:1813
#define CR4_DE
Definition: ketypes.h:152

Referenced by KiInitMachineDependent().

◆ Ki386EnableFxsr()

ULONG_PTR NTAPI Ki386EnableFxsr ( IN ULONG_PTR  Context)

Definition at line 1083 of file cpu.c.

1084{
1085 /* Enable FXSR */
1087 return 0;
1088}
#define CR4_FXSR
Definition: ketypes.h:157

Referenced by KiInitMachineDependent().

◆ Ki386EnableGlobalPage()

ULONG_PTR NTAPI Ki386EnableGlobalPage ( IN ULONG_PTR  Context)

Definition at line 23 of file patpge.c.

24{
25 //PLONG Count;
26#if defined(_GLOBAL_PAGES_ARE_AWESOME_)
27 ULONG Cr4;
28#endif
30
31 /* Disable interrupts */
33
34 /* Spin until other processors are ready */
35 //Count = (PLONG)Context;
36 //InterlockedDecrement(Count);
37 //while (*Count) YieldProcessor();
38
39#if defined(_GLOBAL_PAGES_ARE_AWESOME_)
40
41 /* Get CR4 and ensure global pages are disabled */
42 Cr4 = __readcr4();
43 ASSERT(!(Cr4 & CR4_PGE));
44
45 /* Reset CR3 to flush the TLB */
47
48 /* Now enable PGE */
49 __writecr4(Cr4 | CR4_PGE);
50
51#endif
52
53 /* Restore interrupts and return */
55 return 0;
56}
#define ASSERT(a)
Definition: mode.c:44
#define CR4_PGE
Definition: ketypes.h:156
_In_ ULONGLONG _In_ ULONGLONG _In_ BOOLEAN Enable
Definition: ntddpcm.h:142
FORCEINLINE BOOLEAN KeDisableInterrupts(VOID)
Definition: ke.h:239
FORCEINLINE VOID KeRestoreInterrupts(BOOLEAN WereEnabled)
Definition: ke.h:254

Referenced by KiInitMachineDependent().

◆ Ki386EnableTargetLargePage()

ULONG_PTR NTAPI Ki386EnableTargetLargePage ( IN ULONG_PTR  Context)

Definition at line 70 of file patpge.c.

71{
73
74 /* Call helper function with the start address and temporary page table pointer */
75 Ki386EnableCurrentLargePage(IdentityMap->StartAddress, IdentityMap->Cr3);
76
77 return 0;
78}
struct _LARGE_IDENTITY_MAP * PLARGE_IDENTITY_MAP
VOID NTAPI Ki386EnableCurrentLargePage(IN ULONG_PTR StartAddress, IN ULONG Cr3)
ULONG_PTR StartAddress
Definition: ke.h:265

Referenced by KiInitMachineDependent().

◆ Ki386EnableXMMIExceptions()

ULONG_PTR NTAPI Ki386EnableXMMIExceptions ( IN ULONG_PTR  Context)

Definition at line 1093 of file cpu.c.

1094{
1095 PKIDTENTRY IdtEntry;
1096
1097 /* Get the IDT Entry for Interrupt 0x13 */
1098 IdtEntry = &((PKIPCR)KeGetPcr())->IDT[0x13];
1099
1100 /* Set it up */
1101 IdtEntry->Selector = KGDT_R0_CODE;
1102 IdtEntry->Offset = ((ULONG_PTR)KiTrap13 & 0xFFFF);
1103 IdtEntry->ExtendedOffset = ((ULONG_PTR)KiTrap13 >> 16) & 0xFFFF;
1104 ((PKIDT_ACCESS)&IdtEntry->Access)->Dpl = 0;
1105 ((PKIDT_ACCESS)&IdtEntry->Access)->Present = 1;
1106 ((PKIDT_ACCESS)&IdtEntry->Access)->SegmentType = I386_INTERRUPT_GATE;
1107
1108 /* Enable XMMI exceptions */
1110 return 0;
1111}
#define CR4_XMMEXCPT
Definition: ketypes.h:158
#define I386_INTERRUPT_GATE
Definition: ketypes.h:113
struct _KIDT_ACCESS * PKIDT_ACCESS
#define KGDT_R0_CODE
Definition: ketypes.h:123
VOID __cdecl KiTrap13(VOID)
USHORT Selector
Definition: ketypes.h:441
USHORT Access
Definition: ketypes.h:442

Referenced by KiInitMachineDependent().

◆ Ki386FreeIdentityMap()

VOID NTAPI Ki386FreeIdentityMap ( IN PLARGE_IDENTITY_MAP  IdentityMap)

Referenced by KiInitMachineDependent().

◆ Ki386HandleOpcodeV86()

BOOLEAN FASTCALL Ki386HandleOpcodeV86 ( IN PKTRAP_FRAME  TrapFrame)

Definition at line 456 of file v86vdm.c.

457{
458 /* Clean up */
459 TrapFrame->Eip &= 0xFFFF;
460 TrapFrame->HardwareEsp &= 0xFFFF;
461
462 /* We start with only 1 byte per instruction */
463 return KiVdmHandleOpcode(TrapFrame, 1);
464}
BOOLEAN FASTCALL KiVdmHandleOpcode(IN PKTRAP_FRAME TrapFrame, IN ULONG Flags)
Definition: v86vdm.c:379

Referenced by KiTrap0DHandler().

◆ Ki386InitializeTss()

VOID FASTCALL Ki386InitializeTss ( IN PKTSS  Tss,
IN PKIDTENTRY  Idt,
IN PKGDTENTRY  Gdt 
)

Definition at line 827 of file cpu.c.

830{
831 PKGDTENTRY TssEntry, TaskGateEntry;
832
833 /* Initialize the boot TSS. */
834 TssEntry = &Gdt[KGDT_TSS / sizeof(KGDTENTRY)];
835 TssEntry->HighWord.Bits.Type = I386_TSS;
836 TssEntry->HighWord.Bits.Pres = 1;
837 TssEntry->HighWord.Bits.Dpl = 0;
838 KiInitializeTSS2(Tss, TssEntry);
839 KiInitializeTSS(Tss);
840
841 /* Load the task register */
842 Ke386SetTr(KGDT_TSS);
843
844 /* Setup the Task Gate for Double Fault Traps */
845 TaskGateEntry = (PKGDTENTRY)&Idt[8];
846 TaskGateEntry->HighWord.Bits.Type = I386_TASK_GATE;
847 TaskGateEntry->HighWord.Bits.Pres = 1;
848 TaskGateEntry->HighWord.Bits.Dpl = 0;
849 ((PKIDTENTRY)TaskGateEntry)->Selector = KGDT_DF_TSS;
850
851 /* Initialize the TSS used for handling double faults. */
852 Tss = (PKTSS)KiDoubleFaultTSS;
853 KiInitializeTSS(Tss);
854 Tss->CR3 = __readcr3();
855 Tss->Esp0 = KiDoubleFaultStack;
856 Tss->Esp = KiDoubleFaultStack;
857 Tss->Eip = PtrToUlong(KiTrap08);
858 Tss->Cs = KGDT_R0_CODE;
859 Tss->Fs = KGDT_R0_PCR;
860 Tss->Ss = Ke386GetSs();
861 Tss->Es = KGDT_R3_DATA | RPL_MASK;
862 Tss->Ds = KGDT_R3_DATA | RPL_MASK;
863
864 /* Setup the Double Trap TSS entry in the GDT */
865 TssEntry = &Gdt[KGDT_DF_TSS / sizeof(KGDTENTRY)];
866 TssEntry->HighWord.Bits.Type = I386_TSS;
867 TssEntry->HighWord.Bits.Pres = 1;
868 TssEntry->HighWord.Bits.Dpl = 0;
869 TssEntry->BaseLow = (USHORT)((ULONG_PTR)Tss & 0xFFFF);
870 TssEntry->HighWord.Bytes.BaseMid = (UCHAR)((ULONG_PTR)Tss >> 16);
871 TssEntry->HighWord.Bytes.BaseHi = (UCHAR)((ULONG_PTR)Tss >> 24);
872 TssEntry->LimitLow = KTSS_IO_MAPS;
873
874 /* Now setup the NMI Task Gate */
875 TaskGateEntry = (PKGDTENTRY)&Idt[2];
876 TaskGateEntry->HighWord.Bits.Type = I386_TASK_GATE;
877 TaskGateEntry->HighWord.Bits.Pres = 1;
878 TaskGateEntry->HighWord.Bits.Dpl = 0;
879 ((PKIDTENTRY)TaskGateEntry)->Selector = KGDT_NMI_TSS;
880
881 /* Initialize the actual TSS */
882 Tss = (PKTSS)KiNMITSS;
883 KiInitializeTSS(Tss);
884 Tss->CR3 = __readcr3();
885 Tss->Esp0 = KiDoubleFaultStack;
886 Tss->Esp = KiDoubleFaultStack;
887 Tss->Eip = PtrToUlong(KiTrap02);
888 Tss->Cs = KGDT_R0_CODE;
889 Tss->Fs = KGDT_R0_PCR;
890 Tss->Ss = Ke386GetSs();
891 Tss->Es = KGDT_R3_DATA | RPL_MASK;
892 Tss->Ds = KGDT_R3_DATA | RPL_MASK;
893
894 /* And its associated TSS Entry */
895 TssEntry = &Gdt[KGDT_NMI_TSS / sizeof(KGDTENTRY)];
896 TssEntry->HighWord.Bits.Type = I386_TSS;
897 TssEntry->HighWord.Bits.Pres = 1;
898 TssEntry->HighWord.Bits.Dpl = 0;
899 TssEntry->BaseLow = (USHORT)((ULONG_PTR)Tss & 0xFFFF);
900 TssEntry->HighWord.Bytes.BaseMid = (UCHAR)((ULONG_PTR)Tss >> 16);
901 TssEntry->HighWord.Bytes.BaseHi = (UCHAR)((ULONG_PTR)Tss >> 24);
902 TssEntry->LimitLow = KTSS_IO_MAPS;
903}
#define PKIDTENTRY
Definition: ketypes.h:574
#define I386_TASK_GATE
Definition: ketypes.h:109
#define I386_TSS
Definition: ketypes.h:110
#define PKTSS
Definition: ketypes.h:1019
#define PKGDTENTRY
Definition: ketypes.h:532
#define KGDTENTRY
Definition: ketypes.h:531
#define KTSS_IO_MAPS
Definition: asm.h:84
#define KGDT_R3_DATA
Definition: ketypes.h:126
#define KGDT_NMI_TSS
Definition: ketypes.h:133
#define KGDT_TSS
Definition: ketypes.h:127
#define KGDT_R0_PCR
Definition: ketypes.h:128
#define KGDT_DF_TSS
Definition: ketypes.h:132
VOID __cdecl KiTrap02(VOID)
VOID __cdecl KiTrap08(VOID)
ULONG_PTR KiDoubleFaultStack
Definition: kiinit.c:22
UCHAR KiDoubleFaultTSS[KTSS_IO_MAPS]
Definition: cpu.c:20
VOID NTAPI KiInitializeTSS(IN PKTSS Tss)
Definition: cpu.c:811
VOID NTAPI KiInitializeTSS2(IN PKTSS Tss, IN PKGDTENTRY TssEntry OPTIONAL)
Definition: cpu.c:773
UCHAR KiNMITSS[KTSS_IO_MAPS]
Definition: cpu.c:23
struct _KGDTENTRY::@2459::@2461 Bits
USHORT LimitLow
Definition: ketypes.h:389

Referenced by KiSystemStartup().

◆ Ki386PerfEnd()

FORCEINLINE VOID Ki386PerfEnd ( VOID  )

Definition at line 977 of file ke.h.

978{
981 DbgPrint("Boot took %I64u cycles!\n", BootCyclesEnd - BootCycles);
982 DbgPrint("Interrupts: %u System Calls: %u Context Switches: %u\n",
983 KeGetCurrentPrcb()->InterruptCount,
984 KeGetCurrentPrcb()->KeSystemCalls,
986}
#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:1182
#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

◆ Ki386SetupAndExitToV86Mode()

VOID NTAPI Ki386SetupAndExitToV86Mode ( OUT PTEB  VdmTeb)

Referenced by Ke386CallBios().

◆ KiAmdK6InitializeMTRR()

VOID NTAPI KiAmdK6InitializeMTRR ( VOID  )

Definition at line 31 of file mtrr.c.

32{
33 /* FIXME: Support this */
34 DPRINT("AMD MTRR support detected but not yet taken advantage of\n");
35}
#define DPRINT
Definition: sndvol32.h:73

Referenced by KiInitMachineDependent().

◆ KiCheckForApcDelivery()

FORCEINLINE VOID KiCheckForApcDelivery ( IN PKTRAP_FRAME  TrapFrame)

Definition at line 858 of file ke.h.

859{
862
863 /* Check for V8086 or user-mode trap */
864 if ((TrapFrame->EFlags & EFLAGS_V86_MASK) || (KiUserTrap(TrapFrame)))
865 {
866 /* Get the thread */
868 while (TRUE)
869 {
870 /* Turn off the alerted state for kernel mode */
871 Thread->Alerted[KernelMode] = FALSE;
872
873 /* Are there pending user APCs? */
874 if (!Thread->ApcState.UserApcPending) break;
875
876 /* Raise to APC level and enable interrupts */
878 _enable();
879
880 /* Deliver APCs */
881 KiDeliverApc(UserMode, NULL, TrapFrame);
882
883 /* Restore IRQL and disable interrupts once again */
885 _disable();
886 }
887 }
888}
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define APC_LEVEL
Definition: env_spec_w32.h:695
VOID FASTCALL KfLowerIrql(IN KIRQL NewIrql)
Definition: pic.c:232
KIRQL FASTCALL KfRaiseIrql(IN KIRQL NewIrql)
Definition: pic.c:187
#define UserMode
Definition: asm.h:39
FORCEINLINE BOOLEAN KiUserTrap(IN PKTRAP_FRAME TrapFrame)
Definition: ke.h:367
VOID NTAPI KiDeliverApc(IN KPROCESSOR_MODE DeliveryMode, IN PKEXCEPTION_FRAME ExceptionFrame, IN PKTRAP_FRAME TrapFrame)
Definition: apc.c:302
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778

Referenced by KiCommonExit().

◆ KiConvertToGuiThread()

NTSTATUS NTAPI KiConvertToGuiThread ( VOID  )

Referenced by KiSystemServiceHandler().

◆ KiDispatchException0Args()

FORCEINLINE DECLSPEC_NORETURN VOID KiDispatchException0Args ( IN NTSTATUS  Code,
IN ULONG_PTR  Address,
IN PKTRAP_FRAME  TrapFrame 
)

Definition at line 804 of file ke.h.

807{
808 /* Helper for exceptions with no arguments */
809 KiDispatchExceptionFromTrapFrame(Code, 0, Address, 0, 0, 0, 0, TrapFrame);
810}
DECLSPEC_NORETURN VOID NTAPI KiDispatchExceptionFromTrapFrame(IN NTSTATUS Code, IN ULONG Flags, IN ULONG_PTR Address, IN ULONG ParameterCount, IN ULONG_PTR Parameter1, IN ULONG_PTR Parameter2, IN ULONG_PTR Parameter3, IN PKTRAP_FRAME TrapFrame)
Definition: exp.c:1055
_In_ UCHAR _In_ UCHAR _In_ ULONG Code
Definition: wdfdevice.h:1701

Referenced by KiRaiseAssertionHandler(), KiTrap00Handler(), KiTrap01Handler(), KiTrap04Handler(), KiTrap05Handler(), KiTrap06Handler(), and KiTrap0DHandler().

◆ KiDispatchException1Args()

FORCEINLINE DECLSPEC_NORETURN VOID KiDispatchException1Args ( IN NTSTATUS  Code,
IN ULONG_PTR  Address,
IN ULONG  P1,
IN PKTRAP_FRAME  TrapFrame 
)

Definition at line 818 of file ke.h.

822{
823 /* Helper for exceptions with no arguments */
824 KiDispatchExceptionFromTrapFrame(Code, 0, Address, 1, P1, 0, 0, TrapFrame);
825}

Referenced by KiNpxHandler(), and KiTrap13Handler().

◆ KiDispatchException2Args()

FORCEINLINE DECLSPEC_NORETURN VOID KiDispatchException2Args ( IN NTSTATUS  Code,
IN ULONG_PTR  Address,
IN ULONG  P1,
IN ULONG  P2,
IN PKTRAP_FRAME  TrapFrame 
)

Definition at line 833 of file ke.h.

838{
839 /* Helper for exceptions with no arguments */
840 KiDispatchExceptionFromTrapFrame(Code, 0, Address, 2, P1, P2, 0, TrapFrame);
841}

Referenced by KiNpxHandler(), KiTrap0DHandler(), and KiTrap0EHandler().

◆ KiDispatchExceptionFromTrapFrame()

DECLSPEC_NORETURN VOID NTAPI KiDispatchExceptionFromTrapFrame ( IN NTSTATUS  Code,
IN ULONG  Flags,
IN ULONG_PTR  Address,
IN ULONG  ParameterCount,
IN ULONG_PTR  Parameter1,
IN ULONG_PTR  Parameter2,
IN ULONG_PTR  Parameter3,
IN PKTRAP_FRAME  TrapFrame 
)

Definition at line 1055 of file exp.c.

1063{
1064 EXCEPTION_RECORD ExceptionRecord;
1065
1066 /* Build the exception record */
1067 ExceptionRecord.ExceptionCode = Code;
1068 ExceptionRecord.ExceptionFlags = Flags;
1069 ExceptionRecord.ExceptionRecord = NULL;
1070 ExceptionRecord.ExceptionAddress = (PVOID)Address;
1071 ExceptionRecord.NumberParameters = ParameterCount;
1072 if (ParameterCount)
1073 {
1074 /* Copy extra parameters */
1075 ExceptionRecord.ExceptionInformation[0] = Parameter1;
1076 ExceptionRecord.ExceptionInformation[1] = Parameter2;
1077 ExceptionRecord.ExceptionInformation[2] = Parameter3;
1078 }
1079
1080 /* Now go dispatch the exception */
1081 KiDispatchException(&ExceptionRecord,
1082 NULL,
1083 TrapFrame,
1084 TrapFrame->EFlags & EFLAGS_V86_MASK ?
1085 -1 : KiUserTrap(TrapFrame),
1086 TRUE);
1087
1088 /* Return from this trap */
1089 KiEoiHelper(TrapFrame);
1090}
#define Code
Definition: deflate.h:80
VOID NTAPI KiDispatchException(IN PEXCEPTION_RECORD ExceptionRecord, IN PKEXCEPTION_FRAME ExceptionFrame, IN PKTRAP_FRAME TrapFrame, IN KPROCESSOR_MODE PreviousMode, IN BOOLEAN FirstChance)
Definition: exp.c:795
DECLSPEC_NORETURN VOID FASTCALL KiEoiHelper(IN PKTRAP_FRAME TrapFrame)
Definition: traphdlr.c:126
struct _EXCEPTION_RECORD * ExceptionRecord
Definition: compat.h:210
DWORD ExceptionCode
Definition: compat.h:208
DWORD NumberParameters
Definition: compat.h:212
DWORD ExceptionFlags
Definition: compat.h:209
ULONG_PTR ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS]
Definition: compat.h:213
PVOID ExceptionAddress
Definition: compat.h:211
void * PVOID
Definition: typedefs.h:50

Referenced by KiDebugHandler(), KiDispatchException0Args(), KiDispatchException1Args(), KiDispatchException2Args(), KiRaiseSecurityCheckFailureHandler(), and KiTrap0EHandler().

◆ KiEndInterrupt()

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

Definition at line 961 of file ke.h.

963{
964 /* Disable interrupts and end the interrupt */
965 _disable();
966 HalEndSystemInterrupt(Irql, TrapFrame);
967
968 /* Exit the interrupt */
969 KiEoiHelper(TrapFrame);
970}
_Out_ PKIRQL Irql
Definition: csq.h:179
VOID NTAPI HalEndSystemInterrupt(IN KIRQL OldIrql, IN PKTRAP_FRAME TrapFrame)
Definition: pic.c:335

◆ KiEoiHelper()

DECLSPEC_NORETURN VOID FASTCALL KiEoiHelper ( IN PKTRAP_FRAME  TrapFrame)

Definition at line 126 of file traphdlr.c.

127{
128 /* Common trap exit code */
129 KiCommonExit(TrapFrame, TRUE);
130
131 /* Check if this was a V8086 trap */
132 if (TrapFrame->EFlags & EFLAGS_V86_MASK) KiTrapReturnNoSegments(TrapFrame);
133
134 /* Check for user mode exit */
135 if (KiUserTrap(TrapFrame)) KiTrapReturn(TrapFrame);
136
137 /* Check for edited frame */
138 if (KiIsFrameEdited(TrapFrame)) KiEditedTrapReturn(TrapFrame);
139
140 /* Check if we have single stepping enabled */
141 if (TrapFrame->EFlags & EFLAGS_TF) KiTrapReturnNoSegments(TrapFrame);
142
143 /* Exit the trap to kernel mode */
145}
#define EFLAGS_TF
Definition: SystemCall.c:10
DECLSPEC_NORETURN VOID FASTCALL KiTrapReturnNoSegmentsRet8(IN PKTRAP_FRAME TrapFrame)
DECLSPEC_NORETURN VOID FASTCALL KiTrapReturn(IN PKTRAP_FRAME TrapFrame)
DECLSPEC_NORETURN VOID FASTCALL KiEditedTrapReturn(IN PKTRAP_FRAME TrapFrame)
DECLSPEC_NORETURN VOID FASTCALL KiTrapReturnNoSegments(IN PKTRAP_FRAME TrapFrame)
FORCEINLINE BOOLEAN KiIsFrameEdited(IN PKTRAP_FRAME TrapFrame)
Definition: traphdlr.c:87
FORCEINLINE VOID KiCommonExit(IN PKTRAP_FRAME TrapFrame, BOOLEAN SkipPreviousMode)
Definition: traphdlr.c:96

Referenced by _HalpApcInterruptHandler(), HalpApcInterruptHandler(), HalpClockInterruptHandler(), HalpClockIpiHandler(), HalpDispatchInterrupt2ndEntry(), HalpDispatchInterruptHandler(), HalpTrap0DHandler(), KiDispatchExceptionFromTrapFrame(), KiEndInterrupt(), KiEnterV86Mode(), KiExitInterrupt(), KiExitV86Trap(), KiGetTickCountHandler(), KiNpxHandler(), KiTrap01Handler(), KiTrap07Handler(), KiTrap0EHandler(), and KiTrap10Handler().

◆ KiExceptionExit()

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

Definition at line 693 of file ke.h.

696{
697 KiServiceExit2(TrapFrame);
698}
#define KiServiceExit2
Definition: ke.h:5

Referenced by NtContinue(), and NtRaiseException().

◆ KiExitV86Mode()

ULONG_PTR FASTCALL KiExitV86Mode ( IN PKTRAP_FRAME  TrapFrame)

Definition at line 468 of file v86vdm.c.

469{
470 PKPCR Pcr = KeGetPcr();
471 ULONG_PTR StackFrameUnaligned;
472 PKV8086_STACK_FRAME StackFrame;
474 PKV86_FRAME V86Frame;
475 PFX_SAVE_AREA NpxFrame;
476
477 /* Get the stack frame back */
478 StackFrameUnaligned = TrapFrame->Esi;
479 StackFrame = (PKV8086_STACK_FRAME)(ROUND_UP(StackFrameUnaligned - 4, 16) + 4);
480 V86Frame = &StackFrame->V86Frame;
481 NpxFrame = &StackFrame->NpxArea;
482 ASSERT((ULONG_PTR)NpxFrame % 16 == 0);
483
484 /* Copy the FPU frame back */
487
488 /* Set initial stack back */
489 Thread->InitialStack = (PVOID)((ULONG_PTR)V86Frame->ThreadStack + sizeof(FX_SAVE_AREA));
490
491 /* Set ESP0 back in the KTSS */
492 Pcr->TSS->Esp0 = (ULONG_PTR)Thread->InitialStack;
493 Pcr->TSS->Esp0 -= sizeof(KTRAP_FRAME) - FIELD_OFFSET(KTRAP_FRAME, V86Es);
494 Pcr->TSS->Esp0 -= NPX_FRAME_LENGTH;
495
496 /* Restore TEB addresses */
497 Thread->Teb = V86Frame->ThreadTeb;
498 KiSetTebBase(KeGetPcr(), V86Frame->ThreadTeb);
499
500 /* Enable interrupts and return a pointer to the trap frame */
501 _enable();
502 return StackFrameUnaligned;
503}
#define ROUND_UP(n, align)
Definition: eventvwr.h:34
#define NPX_FRAME_LENGTH
Definition: asm.h:247
FORCEINLINE VOID KiSetTebBase(PKPCR Pcr, PNT_TIB TebAddress)
Definition: ke.h:428
FORCEINLINE PFX_SAVE_AREA KiGetThreadNpxArea(IN PKTHREAD Thread)
Definition: ke.h:741
struct _KV8086_STACK_FRAME * PKV8086_STACK_FRAME
Definition: ke.h:294
struct _KTSS * TSS
Definition: ke.h:55
KV86_FRAME V86Frame
Definition: ke.h:255
FX_SAVE_AREA NpxArea
Definition: ke.h:254
PVOID ThreadTeb
Definition: ke.h:244
PVOID ThreadStack
Definition: ke.h:243

◆ KiFastCallEntry()

VOID __cdecl KiFastCallEntry ( VOID  )

◆ KiFlushNPXState()

VOID NTAPI KiFlushNPXState ( IN FLOATING_SAVE_AREA SaveArea)

◆ KiGetCacheInformation()

VOID NTAPI KiGetCacheInformation ( VOID  )

Definition at line 419 of file cpu.c.

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

◆ KiGetFeatureBits()

ULONG64 NTAPI 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.SSE4_2) FeatureBits |= KF_SSE4_2;
210 if (VersionInfo.Ecx.Bits.XSAVE) FeatureBits |= KF_XSTATE;
211 if (VersionInfo.Ecx.Bits.RDRAND) FeatureBits |= KF_RDRAND;
212
213 /* Check if the CPU has hyper-threading */
214 if (VersionInfo.Edx.Bits.HTT)
215 {
216 /* Set the number of logical CPUs */
218 VersionInfo.Ebx.Bits.MaximumAddressableIdsForLogicalProcessors;
220 {
221 /* We're on dual-core */
223 }
224 }
225 else
226 {
227 /* We only have a single CPU */
229 }
230
231 /* Check if CPUID_THERMAL_POWER_MANAGEMENT (0x06) is supported */
233 {
234 /* Read CPUID_THERMAL_POWER_MANAGEMENT */
237
238 if (PowerInfo.Undoc.Ecx.ACNT2) FeatureBits |= KF_ACNT2;
239 }
240
241 /* Check if CPUID_STRUCTURED_EXTENDED_FEATURE_FLAGS (0x07) is supported */
243 {
244 /* Read CPUID_STRUCTURED_EXTENDED_FEATURE_FLAGS */
246 __cpuidex(ExtFlags.AsInt32,
249
250 if (ExtFlags.Ebx.Bits.SMEP) FeatureBits |= KF_SMEP;
251 if (ExtFlags.Ebx.Bits.FSGSBASE) FeatureBits |= KF_RDWRFSGSBASE;
252 if (ExtFlags.Ebx.Bits.SMAP) FeatureBits |= KF_SMAP;
253 }
254
255 /* Check if CPUID_EXTENDED_STATE (0x0D) is supported */
256 if (signature.MaxLeaf >= CPUID_EXTENDED_STATE)
257 {
258 /* Read CPUID_EXTENDED_STATE */
260 __cpuidex(ExtStateSub.AsInt32,
263
264 if (ExtStateSub.Eax.Bits.XSAVEOPT) FeatureBits |= KF_XSAVEOPT;
265 if (ExtStateSub.Eax.Bits.XSAVES) FeatureBits |= KF_XSAVES;
266 }
267
268 /* Check extended cpuid features */
269 __cpuid(extendedFunction.AsInt32, CPUID_EXTENDED_FUNCTION);
270 if ((extendedFunction.MaxLeaf & 0xffffff00) == 0x80000000)
271 {
272 /* Check if CPUID_EXTENDED_CPU_SIG (0x80000001) is supported */
273 if (extendedFunction.MaxLeaf >= CPUID_EXTENDED_CPU_SIG)
274 {
275 /* Read CPUID_EXTENDED_CPU_SIG */
278
279 /* Check if NX-bit is supported */
280 if (ExtSig.Intel.Edx.Bits.NX) FeatureBits |= KF_NX_BIT;
281 if (ExtSig.Intel.Edx.Bits.Page1GB) FeatureBits |= KF_HUGEPAGE;
282 if (ExtSig.Intel.Edx.Bits.RDTSCP) FeatureBits |= KF_RDTSCP;
283
284 /* AMD specific */
285 if (Vendor == CPU_AMD)
286 {
287 if (ExtSig.Amd.Edx.Bits.ThreeDNow) FeatureBits |= KF_3DNOW;
288 }
289 }
290 }
291
292 /* Vendor specific */
293 if (Vendor == CPU_INTEL)
294 {
295 FeatureBits |= KF_GENUINE_INTEL;
296
297 /* Check for models that support LBR */
298 if (VersionInfo.Eax.Bits.FamilyId == 6)
299 {
300 if ((VersionInfo.Eax.Bits.Model == 15) ||
301 (VersionInfo.Eax.Bits.Model == 22) ||
302 (VersionInfo.Eax.Bits.Model == 23) ||
303 (VersionInfo.Eax.Bits.Model == 26))
304 {
305 FeatureBits |= KF_BRANCH;
306 }
307 }
308
309 /* Check if VMX is available */
310 if (VersionInfo.Ecx.Bits.VMX)
311 {
312 /* Read PROCBASED ctls and check if secondary are allowed */
315 if (ProcBasedCtls.Bits.Allowed1.ActivateSecondaryControls)
316 {
317 /* Read secondary controls and check if EPT is allowed */
320 if (ProcBasedCtls2.Bits.Allowed1.EPT)
321 FeatureBits |= KF_SLAT;
322 }
323 }
324 }
325 else if (Vendor == CPU_AMD)
326 {
327 FeatureBits |= KF_AUTHENTICAMD;
328 FeatureBits |= KF_BRANCH;
329
330 /* Check extended cpuid features */
331 if ((extendedFunction.MaxLeaf & 0xffffff00) == 0x80000000)
332 {
333 /* Check if CPUID_AMD_SVM_FEATURES (0x8000000A) is supported */
334 if (extendedFunction.MaxLeaf >= CPUID_AMD_SVM_FEATURES)
335 {
336 /* Read CPUID_AMD_SVM_FEATURES and check if Nested Paging is available */
337 CPUID_AMD_SVM_FEATURES_REGS SvmFeatures;
339 if (SvmFeatures.Edx.Bits.NP) FeatureBits |= KF_SLAT;
340 }
341 }
342 }
343
344 /* Return the Feature Bits */
345 return FeatureBits;
346}
#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:1662
unsigned __int64 ULONG64
Definition: imports.h:198
#define KF_SSE4_2
Definition: ketypes.h:74
#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:93
#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:693
UCHAR LogicalProcessorsPerPhysicalProcessor
Definition: ketypes.h:759
ULONG InitialApicId
Definition: ketypes.h:710
struct CPUID_AMD_SVM_FEATURES_EDX::@3740 Bits
CPUID_AMD_SVM_FEATURES_EDX Edx
Definition: Cpuid.h:206
struct CPUID_EXTENDED_CPU_SIG_REGS::@3737 Intel
struct CPUID_EXTENDED_CPU_SIG_REGS::@3738 Amd
struct CPUID_EXTENDED_STATE_SUB_LEAF_EAX::@3835 Bits
CPUID_EXTENDED_STATE_SUB_LEAF_EAX Eax
Definition: Cpuid.h:107
struct CPUID_STRUCTURED_EXTENDED_FEATURE_FLAGS_EBX::@3825 Bits
CPUID_STRUCTURED_EXTENDED_FEATURE_FLAGS_EBX Ebx
Definition: Cpuid.h:80
struct CPUID_THERMAL_POWER_MANAGEMENT_REGS::@3728 Undoc
struct MSR_IA32_VMX_PROCBASED_CTLS2_REGISTER::@3872 Bits
struct MSR_IA32_VMX_PROCBASED_CTLS_REGISTER::@3871 Bits

◆ KiGetLinkedTrapFrame()

FORCEINLINE PKTRAP_FRAME KiGetLinkedTrapFrame ( PKTRAP_FRAME  TrapFrame)

Definition at line 111 of file ke.h.

112{
113 return (PKTRAP_FRAME)TrapFrame->Edx;
114}
ULONG Edx
Definition: ketypes.h:310

◆ KiGetThreadNpxArea()

◆ KiGetUserModeStackAddress()

FORCEINLINE PULONG KiGetUserModeStackAddress ( void  )

Definition at line 990 of file ke.h.

991{
992 return &(KeGetCurrentThread()->TrapFrame->HardwareEsp);
993}

◆ KiI386PentiumLockErrataFixup()

VOID NTAPI KiI386PentiumLockErrataFixup ( VOID  )

Definition at line 1116 of file cpu.c.

1117{
1118 KDESCRIPTOR IdtDescriptor = {0, 0, 0};
1119 PKIDTENTRY NewIdt, NewIdt2;
1120 PMMPTE PointerPte;
1121
1122 /* Allocate memory for a new IDT */
1123 NewIdt = ExAllocatePool(NonPagedPool, 2 * PAGE_SIZE);
1124
1125 /* Put everything after the first 7 entries on a new page */
1126 NewIdt2 = (PVOID)((ULONG_PTR)NewIdt + PAGE_SIZE - (7 * sizeof(KIDTENTRY)));
1127
1128 /* Disable interrupts */
1129 _disable();
1130
1131 /* Get the current IDT and copy it */
1132 __sidt(&IdtDescriptor.Limit);
1133 RtlCopyMemory(NewIdt2,
1134 (PVOID)IdtDescriptor.Base,
1135 IdtDescriptor.Limit + 1);
1136 IdtDescriptor.Base = (ULONG)NewIdt2;
1137
1138 /* Set the new IDT */
1139 __lidt(&IdtDescriptor.Limit);
1140 ((PKIPCR)KeGetPcr())->IDT = NewIdt2;
1141
1142 /* Restore interrupts */
1143 _enable();
1144
1145 /* Set the first 7 entries as read-only to produce a fault */
1146 PointerPte = MiAddressToPte(NewIdt);
1147 ASSERT(PointerPte->u.Hard.Write == 1);
1148 PointerPte->u.Hard.Write = 0;
1149 KeInvalidateTlbEntry(NewIdt);
1150}
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define NonPagedPool
Definition: env_spec_w32.h:307
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
__INTRIN_INLINE void __lidt(void *Source)
Definition: intrin_x86.h:2041
__INTRIN_INLINE void __sidt(void *Destination)
Definition: intrin_x86.h:2046
#define MiAddressToPte(x)
Definition: mmx86.c:19
#define KIDTENTRY
Definition: ketypes.h:573
FORCEINLINE VOID KeInvalidateTlbEntry(IN PVOID Address)
Definition: ke.h:264
PVOID Base
Definition: ketypes.h:580
USHORT Limit
Definition: ketypes.h:579
ULONG64 Write
Definition: mmtypes.h:170
union _MMPTE::@2342 u
MMPTE_HARDWARE Hard
Definition: mmtypes.h:217

Referenced by KiInitMachineDependent().

◆ KiInitializeMTRR()

VOID NTAPI KiInitializeMTRR ( IN BOOLEAN  FinalCpu)

Definition at line 22 of file mtrr.c.

23{
24 /* FIXME: Support this */
25 DPRINT("MTRR support detected but not yet taken advantage of\n");
26}

Referenced by KiInitMachineDependent().

◆ KiInitializePAT()

VOID NTAPI KiInitializePAT ( VOID  )

Definition at line 61 of file patpge.c.

62{
63 /* FIXME: Support this */
64 DPRINT("PAT support detected but not yet taken advantage of\n");
65}

Referenced by KiInitMachineDependent().

◆ KiInitializePcr()

VOID NTAPI KiInitializePcr ( IN ULONG  ProcessorNumber,
IN PKIPCR  Pcr,
IN PKIDTENTRY  Idt,
IN PKGDTENTRY  Gdt,
IN PKTSS  Tss,
IN PKTHREAD  IdleThread,
IN PVOID  DpcStack 
)

Definition at line 284 of file kiinit.c.

291{
292 /* Setup the TIB */
293 Pcr->NtTib.ExceptionList = EXCEPTION_CHAIN_END;
294 Pcr->NtTib.StackBase = 0;
295 Pcr->NtTib.StackLimit = 0;
296 Pcr->NtTib.Self = NULL;
297
298 /* Set the Current Thread */
299 Pcr->PrcbData.CurrentThread = IdleThread;
300
301 /* Set pointers to ourselves */
302 Pcr->SelfPcr = (PKPCR)Pcr;
303 Pcr->Prcb = &Pcr->PrcbData;
304
305 /* Set the PCR Version */
306 Pcr->MajorVersion = PCR_MAJOR_VERSION;
307 Pcr->MinorVersion = PCR_MINOR_VERSION;
308
309 /* Set the PCRB Version */
310 Pcr->PrcbData.MajorVersion = PRCB_MAJOR_VERSION;
311 Pcr->PrcbData.MinorVersion = PRCB_MINOR_VERSION;
312
313 /* Set the Build Type */
314 Pcr->PrcbData.BuildType = 0;
315#ifndef CONFIG_SMP
316 Pcr->PrcbData.BuildType |= PRCB_BUILD_UNIPROCESSOR;
317#endif
318#if DBG
319 Pcr->PrcbData.BuildType |= PRCB_BUILD_DEBUG;
320#endif
321
322 /* Set the Processor Number and current Processor Mask */
323 Pcr->PrcbData.Number = (UCHAR)ProcessorNumber;
324 Pcr->PrcbData.SetMember = 1 << ProcessorNumber;
325
326 /* Set the PRCB for this Processor */
327 KiProcessorBlock[ProcessorNumber] = Pcr->Prcb;
328
329 /* Start us out at PASSIVE_LEVEL */
330 Pcr->Irql = PASSIVE_LEVEL;
331
332 /* Set the GDI, IDT, TSS and DPC Stack */
333 Pcr->GDT = (PVOID)Gdt;
334 Pcr->IDT = Idt;
335 Pcr->TSS = Tss;
336 Pcr->TssCopy = Tss;
337 Pcr->PrcbData.DpcStack = DpcStack;
338
339 /* Setup the processor set */
340 Pcr->PrcbData.MultiThreadProcessorSet = Pcr->PrcbData.SetMember;
341}
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define PRCB_MINOR_VERSION
Definition: ketypes.h:325
#define PRCB_MAJOR_VERSION
Definition: ketypes.h:326
#define PRCB_BUILD_UNIPROCESSOR
Definition: ketypes.h:328
#define PRCB_BUILD_DEBUG
Definition: ketypes.h:327
#define EXCEPTION_CHAIN_END
Definition: rtltypes.h:63
PKPRCB KiProcessorBlock[]
Definition: krnlinit.c:31
#define PCR_MINOR_VERSION
Definition: ke.h:290
struct _KPCR * PKPCR
#define PCR_MAJOR_VERSION
Definition: ke.h:291

Referenced by KeStartAllProcessors().

◆ KiIret()

Definition at line 937 of file ke.h.

938{
939#if defined(__GNUC__)
940 __asm__ __volatile__
941 (
942 "iret"
943 );
944#elif defined(_MSC_VER)
945 __asm
946 {
947 iretd
948 }
949#else
950#error Unsupported compiler
951#endif
953}
#define UNREACHABLE
__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")

◆ KiIsNpxErrataPresent()

BOOLEAN NTAPI KiIsNpxErrataPresent ( VOID  )

Definition at line 1187 of file cpu.c.

1188{
1189 static double Value1 = 4195835.0, Value2 = 3145727.0;
1190 INT ErrataPresent;
1191 ULONG Cr0;
1192
1193 /* Interrupts have to be disabled here. */
1195
1196 /* Read CR0 and remove FPU flags */
1197 Cr0 = __readcr0();
1198 __writecr0(Cr0 & ~(CR0_MP | CR0_TS | CR0_EM));
1199
1200 /* Initialize FPU state */
1201 Ke386FnInit();
1202
1203 /* Multiply the magic values and divide, we should get the result back */
1204#ifdef __GNUC__
1205 __asm__ __volatile__
1206 (
1207 "fldl %1\n\t"
1208 "fdivl %2\n\t"
1209 "fmull %2\n\t"
1210 "fldl %1\n\t"
1211 "fsubp\n\t"
1212 "fistpl %0\n\t"
1213 : "=m" (ErrataPresent)
1214 : "m" (Value1),
1215 "m" (Value2)
1216 );
1217#else
1218 __asm
1219 {
1220 fld Value1
1221 fdiv Value2
1222 fmul Value2
1223 fld Value1
1224 fsubp st(1), st(0)
1225 fistp ErrataPresent
1226 };
1227#endif
1228
1229 /* Restore CR0 */
1230 __writecr0(Cr0);
1231
1232 /* Return if there's an errata */
1233 return ErrataPresent != 0;
1234}
__INTRIN_INLINE unsigned long __readcr0(void)
Definition: intrin_x86.h:1818
__INTRIN_INLINE void __writecr0(unsigned int Data)
Definition: intrin_x86.h:1803
#define CR0_MP
Definition: ketypes.h:135
#define CR0_EM
Definition: ketypes.h:136
#define CR0_TS
Definition: ketypes.h:137
int32_t INT
Definition: typedefs.h:58

Referenced by KiVerifyCpuFeatures().

◆ KiIsNpxPresent()

BOOLEAN NTAPI KiIsNpxPresent ( VOID  )

◆ KiRestoreFastSyscallReturnState()

VOID NTAPI KiRestoreFastSyscallReturnState ( VOID  )

Definition at line 1039 of file cpu.c.

1040{
1041 /* Check if the CPU Supports fast system call */
1043 {
1044 /* Check if it has been disabled */
1046 {
1047 /* Disable fast system call */
1048 KeFeatureBits &= ~KF_FAST_SYSCALL;
1050 DPRINT1("Support for SYSENTER disabled.\n");
1051 }
1052 else
1053 {
1054 /* Do an IPI to enable it */
1056
1057 /* It's enabled, so use the proper exit stub */
1059 DPRINT("Support for SYSENTER detected.\n");
1060 }
1061 }
1062 else
1063 {
1064 /* Use the IRET handler */
1066 DPRINT1("No support for SYSENTER detected.\n");
1067 }
1068}
#define DPRINT1
Definition: precomp.h:8
ULONG64 KeFeatureBits
Definition: krnlinit.c:22
ULONG_PTR NTAPI KeIpiGenericCall(_In_ PKIPI_BROADCAST_WORKER Function, _In_ ULONG_PTR Argument)
Definition: ipi.c:44
ULONG KiFastSystemCallDisable
Definition: cpu.c:28
ULONG_PTR NTAPI KiLoadFastSyscallMachineSpecificRegisters(IN ULONG_PTR Context)
Definition: cpu.c:1025
DECLSPEC_NORETURN VOID FASTCALL KiSystemCallTrapReturn(IN PKTRAP_FRAME TrapFrame)
DECLSPEC_NORETURN VOID FASTCALL KiSystemCallSysExitReturn(IN PKTRAP_FRAME TrapFrame)
PFAST_SYSTEM_CALL_EXIT KiFastCallExitHandler
Definition: traphdlr.c:56

Referenced by KiInitMachineDependent().

◆ KiRundownThread()

FORCEINLINE VOID KiRundownThread ( IN PKTHREAD  Thread)

Definition at line 395 of file ke.h.

396{
397 /* Check if this is the NPX Thread */
398 if (KeGetCurrentPrcb()->NpxThread == Thread)
399 {
400 /* Clear it */
401 KeGetCurrentPrcb()->NpxThread = NULL;
402 Ke386FnInit();
403 }
404}

◆ KiServiceExit()

DECLSPEC_NORETURN VOID FASTCALL KiServiceExit ( IN PKTRAP_FRAME  TrapFrame,
IN NTSTATUS  Status 
)

Definition at line 150 of file traphdlr.c.

152{
153 ASSERT((TrapFrame->EFlags & EFLAGS_V86_MASK) == 0);
154 ASSERT(!KiIsFrameEdited(TrapFrame));
155
156 /* Copy the status into EAX */
157 TrapFrame->Eax = Status;
158
159 /* Common trap exit code */
160 KiCommonExit(TrapFrame, FALSE);
161
162 /* Restore previous mode */
163 KeGetCurrentThread()->PreviousMode = (CCHAR)TrapFrame->PreviousPreviousMode;
164
165 /* Check for user mode exit */
166 if (KiUserTrap(TrapFrame))
167 {
168 /* Check if we were single stepping */
169 if (TrapFrame->EFlags & EFLAGS_TF)
170 {
171 /* Must use the IRET handler */
172 KiSystemCallTrapReturn(TrapFrame);
173 }
174 else
175 {
176 /* We can use the sysexit handler */
177 KiFastCallExitHandler(TrapFrame);
179 }
180 }
181
182 /* Exit to kernel mode */
183 KiSystemCallReturn(TrapFrame);
184}
DECLSPEC_NORETURN VOID FASTCALL KiSystemCallReturn(IN PKTRAP_FRAME TrapFrame)
PFAST_SYSTEM_CALL_EXIT KiFastCallExitHandler
Definition: traphdlr.c:56
char CCHAR
Definition: typedefs.h:51

Referenced by KiCallbackReturnHandler(), KiSystemServiceHandler(), and KiUserModeCallout().

◆ KiServiceExit2()

DECLSPEC_NORETURN VOID FASTCALL KiServiceExit2 ( IN PKTRAP_FRAME  TrapFrame)

Definition at line 189 of file traphdlr.c.

190{
191 /* Common trap exit code */
192 KiCommonExit(TrapFrame, FALSE);
193
194 /* Restore previous mode */
195 KeGetCurrentThread()->PreviousMode = (CCHAR)TrapFrame->PreviousPreviousMode;
196
197 /* Check if this was a V8086 trap */
198 if (TrapFrame->EFlags & EFLAGS_V86_MASK) KiTrapReturnNoSegments(TrapFrame);
199
200 /* Check for user mode exit */
201 if (KiUserTrap(TrapFrame)) KiTrapReturn(TrapFrame);
202
203 /* Check for edited frame */
204 if (KiIsFrameEdited(TrapFrame)) KiEditedTrapReturn(TrapFrame);
205
206 /* Check if we have single stepping enabled */
207 if (TrapFrame->EFlags & EFLAGS_TF) KiTrapReturnNoSegments(TrapFrame);
208
209 /* Exit the trap to kernel mode */
211}

◆ KiSetCR0Bits()

VOID NTAPI KiSetCR0Bits ( VOID  )

Definition at line 756 of file cpu.c.

757{
758 ULONG Cr0;
759
760 /* Save current CR0 */
761 Cr0 = __readcr0();
762
763 /* If this is a 486, enable Write-Protection */
764 if (KeGetCurrentPrcb()->CpuType > 3) Cr0 |= CR0_WP;
765
766 /* Set new Cr0 */
767 __writecr0(Cr0);
768}
#define CR0_WP
Definition: ketypes.h:140

Referenced by KiInitMachineDependent().

◆ KiSetProcessorType()

VOID NTAPI 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
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

◆ KiSetTebBase()

FORCEINLINE VOID KiSetTebBase ( PKPCR  Pcr,
PNT_TIB  TebAddress 
)

Definition at line 428 of file ke.h.

429{
430 Pcr->NtTib.Self = TebAddress;
431 Ke386SetGdtEntryBase(&Pcr->GDT[KGDT_R3_TEB / sizeof(KGDTENTRY)], TebAddress);
432}
FORCEINLINE VOID Ke386SetGdtEntryBase(PKGDTENTRY GdtEntry, PVOID BaseAddress)
Definition: ke.h:419
NT_TIB NtTib
Definition: ke.h:297
PUSHORT GDT
Definition: ke.h:54
struct _NT_TIB * Self
Definition: compat.h:720

Referenced by KiEnterV86Mode(), KiExitV86Mode(), and KiSwapContextExit().

◆ KiSwitchToBootStack()

FORCEINLINE DECLSPEC_NORETURN VOID KiSwitchToBootStack ( IN ULONG_PTR  InitialStack)

Definition at line 897 of file ke.h.

898{
900
901 /* We have to switch to a new stack before continuing kernel initialization */
902#ifdef __GNUC__
903 __asm__
904 (
905 "movl %0, %%esp\n\t"
906 "subl %1, %%esp\n\t"
907 "pushl %2\n\t"
908 "jmp _KiSystemStartupBootStack@0"
909 :
910 : "c"(InitialStack),
912 "i"(CR0_EM | CR0_TS | CR0_MP),
914 : "%esp"
915 );
916#elif defined(_MSC_VER)
917 __asm
918 {
919 mov esp, InitialStack
923 }
924#else
925#error Unknown Compiler
926#endif
927
929}
#define CODE_SEG(...)
DECLSPEC_NORETURN VOID NTAPI KiSystemStartupBootStack(VOID)
Definition: krnlinit.c:142
#define KTRAP_FRAME_LENGTH
Definition: asm.h:316
#define KTRAP_FRAME_ALIGN
Definition: asm.h:317
#define DECLSPEC_NORETURN
Definition: ntbasedef.h:176
static void push(calc_node_t *op)
Definition: rpn_ieee.c:113
#define NTAPI
Definition: typedefs.h:36

Referenced by KiSystemStartup().

◆ KiSystemCallTrampoline()

NTSTATUS NTAPI KiSystemCallTrampoline ( _In_ PVOID  Handler,
_In_ PVOID  Arguments,
_In_ ULONG  StackBytes 
)

Referenced by KiSystemServiceHandler().

◆ KiThreadStartup()

VOID NTAPI KiThreadStartup ( VOID  )

Definition at line 63 of file thrdini.c.

64{
65 PKTRAP_FRAME TrapFrame;
66 PKSTART_FRAME StartFrame;
67 PKUINIT_FRAME InitFrame;
68
69 /* Get the start and trap frames */
70 InitFrame = KeGetCurrentThread()->KernelStack;
71 StartFrame = &InitFrame->StartFrame;
72 TrapFrame = &InitFrame->TrapFrame;
73
74 /* Lower to APC level */
76
77 /* Call the system routine */
78 StartFrame->SystemRoutine(StartFrame->StartRoutine, StartFrame->StartContext);
79
80 /* If we returned, we better be a user thread */
81 if (!StartFrame->UserThread)
82 {
83 KeBugCheck(NO_USER_MODE_CONTEXT);
84 }
85
86 /* Exit to user-mode */
87 KiServiceExit2(TrapFrame);
88}
DECLSPEC_NORETURN VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1434
PKSYSTEM_ROUTINE SystemRoutine
Definition: thrdini.c:24
PVOID StartContext
Definition: thrdini.c:26
PKSTART_ROUTINE StartRoutine
Definition: thrdini.c:25
BOOLEAN UserThread
Definition: thrdini.c:27
KTRAP_FRAME TrapFrame
Definition: thrdini.c:25
KSTART_FRAME StartFrame
Definition: thrdini.c:23

Referenced by KiInitializeContextThread().

◆ KiTrap02()

VOID __cdecl KiTrap02 ( VOID  )

Referenced by Ki386InitializeTss().

◆ KiTrap08()

VOID __cdecl KiTrap08 ( VOID  )

Referenced by Ki386InitializeTss().

◆ KiTrap13()

VOID __cdecl KiTrap13 ( VOID  )

◆ KiVdmOpcodePrefix()

BOOLEAN FASTCALL KiVdmOpcodePrefix ( IN PKTRAP_FRAME  TrapFrame,
IN ULONG  Flags 
)

Definition at line 442 of file v86vdm.c.

444{
445 /* Increase instruction size */
446 Flags++;
447
448 /* Handle the next opcode */
449 return KiVdmHandleOpcode(TrapFrame, Flags);
450}

◆ ReadBatch()

VOID __cdecl ReadBatch ( VOID  )

Referenced by KiTrap0EHandler().

◆ VdmDispatchBop()

BOOLEAN NTAPI VdmDispatchBop ( IN PKTRAP_FRAME  TrapFrame)

Definition at line 313 of file vdmexec.c.

314{
315 PUCHAR Eip;
316 PVDM_TIB VdmTib;
317
318 /* Check if this is from V86 mode */
319 if (TrapFrame->EFlags & EFLAGS_V86_MASK)
320 {
321 /* Calculate flat EIP */
322 Eip = (PUCHAR)((TrapFrame->Eip & 0xFFFF) +
323 ((TrapFrame->SegCs & 0xFFFF) << 4));
324
325 /* Check if this is a BOP */
326 if (*(PUSHORT)Eip == 0xC4C4)
327 {
328 /* Check sure its the DOS Bop */
329 if (Eip[2] == 0x50)
330 {
331 /* FIXME: No VDM Support */
332 ASSERT(FALSE);
333 }
334
335 /* Increase the number of BOP operations */
336 VdmBopCount++;
337
338 /* Get the TIB */
339 VdmTib = NtCurrentTeb()->Vdm;
340
341 /* Fill out a VDM Event */
342 VdmTib->EventInfo.InstructionSize = 3;
343 VdmTib->EventInfo.BopNumber = Eip[2];
344 VdmTib->EventInfo.Event = VdmBop;
345
346 /* End VDM Execution */
347 VdmEndExecution(TrapFrame, VdmTib);
348 }
349 else
350 {
351 /* Not a BOP */
352 return FALSE;
353 }
354 }
355 else
356 {
357 /* FIXME: Shouldn't happen on ROS */
358 ASSERT(FALSE);
359 }
360
361 /* Return success */
362 return TRUE;
363}
#define NtCurrentTeb
@ VdmBop
Definition: vdm.h:60
ULONG BopNumber
Definition: vdm.h:96
VDMEVENTCLASS Event
Definition: vdm.h:90
ULONG InstructionSize
Definition: vdm.h:91
Definition: vdm.h:135
VDMEVENTINFO EventInfo
Definition: vdm.h:141
uint16_t * PUSHORT
Definition: typedefs.h:56
unsigned char * PUCHAR
Definition: typedefs.h:53
ULONG VdmBopCount
Definition: vdmexec.c:17
VOID NTAPI VdmEndExecution(IN PKTRAP_FRAME TrapFrame, IN PVDM_TIB VdmTib)
Definition: vdmexec.c:253

Referenced by KiTrap06Handler(), and KiVdmOpcodeIRET().

◆ VdmDispatchPageFault()

BOOLEAN NTAPI VdmDispatchPageFault ( _In_ PKTRAP_FRAME  TrapFrame)

Definition at line 367 of file vdmexec.c.

369{
371 PVDM_TIB VdmTib;
372
373 PAGED_CODE();
374
375 /* Get the VDM TIB so we can terminate V86 execution */
376 Status = VdmpGetVdmTib(&VdmTib);
377 if (!NT_SUCCESS(Status))
378 {
379 /* Not a proper VDM fault, keep looking */
380 DPRINT1("VdmDispatchPageFault: no VDM TIB, Vdm=%p\n", NtCurrentTeb()->Vdm);
381 return FALSE;
382 }
383
384 /* Must be coming from V86 code */
385 ASSERT(TrapFrame->EFlags & EFLAGS_V86_MASK);
386
388 {
389 /* Fill out a VDM Event */
390 VdmTib->EventInfo.Event = VdmMemAccess;
391 VdmTib->EventInfo.InstructionSize = 0;
392
393 /* End VDM Execution */
394 VdmEndExecution(TrapFrame, VdmTib);
395 }
397 {
399 }
400 _SEH2_END;
401
402 /* Consider the exception handled if we succeeded */
403 DPRINT1("VdmDispatchPageFault EFlags %lx exit with 0x%lx\n", TrapFrame->EFlags, Status);
404 return NT_SUCCESS(Status);
405}
#define PAGED_CODE()
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:90
@ VdmMemAccess
Definition: vdm.h:58
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:66
#define _SEH2_END
Definition: pseh2_64.h:155
#define _SEH2_TRY
Definition: pseh2_64.h:55
NTSTATUS NTAPI VdmpGetVdmTib(OUT PVDM_TIB *VdmTib)
Definition: vdmexec.c:23

Referenced by KiTrap0EHandler().

Variable Documentation

◆ KeI386CpuStep

ULONG KeI386CpuStep
extern

Definition at line 25 of file cpu.c.

◆ KeI386CpuType

ULONG KeI386CpuType
extern

Definition at line 24 of file cpu.c.

Referenced by KeInvalidateAllCaches().

◆ KeI386EFlagsAndMaskV86

ULONG KeI386EFlagsAndMaskV86
extern

Definition at line 21 of file v86vdm.c.

Referenced by VdmSwapContext().

◆ KeI386EFlagsOrMaskV86

ULONG KeI386EFlagsOrMaskV86
extern

Definition at line 22 of file v86vdm.c.

Referenced by VdmSwapContext().

◆ KeI386FxsrPresent

ULONG KeI386FxsrPresent
extern

Definition at line 33 of file cpu.c.

Referenced by KiFlushNPXState().

◆ KeI386NpxPresent

ULONG KeI386NpxPresent
extern

Definition at line 27 of file cpu.c.

Referenced by KeRestoreFloatingPointState(), and KeSaveFloatingPointState().

◆ KeI386VirtualIntExtensions

◆ KeI386XMMIPresent

ULONG KeI386XMMIPresent
extern

Definition at line 32 of file cpu.c.

◆ Ki386IopmSaveArea

PVOID Ki386IopmSaveArea
extern

Definition at line 23 of file v86vdm.c.

Referenced by Ke386CallBios(), and KiInitializeKernel().

◆ KiDebugRegisterContextOffsets

UCHAR KiDebugRegisterContextOffsets[9]
extern

◆ KiDebugRegisterTrapOffsets

UCHAR KiDebugRegisterTrapOffsets[9]
extern

◆ KiFastSystemCallDisable

ULONG KiFastSystemCallDisable
extern

Definition at line 28 of file cpu.c.

Referenced by KiRestoreFastSyscallReturnState().

◆ KiI386PentiumLockErrataPresent

BOOLEAN KiI386PentiumLockErrataPresent
extern

Definition at line 42 of file cpu.c.

Referenced by KiGetFeatureBits(), KiInitMachineDependent(), and MiInitMachineDependent().

◆ KiIdt

KIDTENTRY KiIdt[MAXIMUM_IDTVECTOR+1]
extern

Definition at line 50 of file except.c.

Referenced by KeInitExceptions().

◆ KiIdtDescriptor

KDESCRIPTOR KiIdtDescriptor
extern

Definition at line 51 of file except.c.

Referenced by KeInitExceptions(), and KiSystemStartup().

◆ KiMXCsrMask

ULONG KiMXCsrMask
extern

Definition at line 30 of file cpu.c.

Referenced by KeContextToTrapFrame(), and KiInitMachineDependent().

◆ KiSystemCallExit

CHAR KiSystemCallExit[]
extern

◆ KiSystemCallExit2

CHAR KiSystemCallExit2[]
extern

◆ KiSystemCallExitBranch

CHAR KiSystemCallExitBranch[]
extern