ReactOS  0.4.13-dev-39-g8b6696f
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
 

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 KeGetContextPc(Context)   ((Context)->Eip)
 
#define KeSetContextPc(Context, ProgramCounter)   ((Context)->Eip = (ProgramCounter))
 
#define KeGetTrapFramePc(TrapFrame)   ((TrapFrame)->Eip)
 
#define KiGetLinkedTrapFrame(x)   (PKTRAP_FRAME)((x)->Edx)
 
#define KeGetContextReturnRegister(Context)   ((Context)->Eax)
 
#define KeSetContextReturnRegister(Context, ReturnValue)   ((Context)->Eax = (ReturnValue))
 
#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
 

Functions

 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)
 
FORCEINLINE VOID Ke386SetGdtEntryBase (PKGDTENTRY GdtEntry, PVOID BaseAddress)
 
FORCEINLINE VOID KiSetTebBase (PKPCR Pcr, PVOID TebAddress)
 
INIT_FUNCTION VOID FASTCALL Ki386InitializeTss (IN PKTSS Tss, IN PKIDTENTRY Idt, IN PKGDTENTRY Gdt)
 
INIT_FUNCTION VOID NTAPI KiSetCR0Bits (VOID)
 
INIT_FUNCTION VOID NTAPI KiGetCacheInformation (VOID)
 
INIT_FUNCTION BOOLEAN NTAPI KiIsNpxPresent (VOID)
 
INIT_FUNCTION BOOLEAN NTAPI KiIsNpxErrataPresent (VOID)
 
INIT_FUNCTION VOID NTAPI KiSetProcessorType (VOID)
 
INIT_FUNCTION ULONG NTAPI KiGetFeatureBits (VOID)
 
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)
 
INIT_FUNCTION VOID NTAPI KeI386VdmInitialize (VOID)
 
INIT_FUNCTION ULONG_PTR NTAPI Ki386EnableGlobalPage (IN ULONG_PTR Context)
 
INIT_FUNCTION 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)
 
INIT_FUNCTION VOID NTAPI KiI386PentiumLockErrataFixup (VOID)
 
INIT_FUNCTION VOID NTAPI KiInitializePAT (VOID)
 
INIT_FUNCTION VOID NTAPI KiInitializeMTRR (IN BOOLEAN FinalCpu)
 
INIT_FUNCTION VOID NTAPI KiAmdK6InitializeMTRR (VOID)
 
INIT_FUNCTION VOID NTAPI KiRestoreFastSyscallReturnState (VOID)
 
INIT_FUNCTION ULONG_PTR NTAPI Ki386EnableDE (IN ULONG_PTR Context)
 
INIT_FUNCTION ULONG_PTR NTAPI Ki386EnableFxsr (IN ULONG_PTR Context)
 
INIT_FUNCTION 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 __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)
 
FORCEINLINE VOID KiCheckForApcDelivery (IN PKTRAP_FRAME TrapFrame)
 
INIT_FUNCTION FORCEINLINE 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 10 of file ke.h.

◆ DR_REG_MASK

#define DR_REG_MASK   0x4F

Definition at line 11 of file ke.h.

◆ KD_BREAKPOINT_SIZE

#define KD_BREAKPOINT_SIZE   sizeof(UCHAR)

Definition at line 17 of file ke.h.

◆ KD_BREAKPOINT_TYPE

#define KD_BREAKPOINT_TYPE   UCHAR

Definition at line 16 of file ke.h.

◆ KD_BREAKPOINT_VALUE

#define KD_BREAKPOINT_VALUE   0xCC

Definition at line 18 of file ke.h.

◆ KeGetContextPc

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

Definition at line 23 of file ke.h.

◆ KeGetContextReturnRegister

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

Definition at line 35 of file ke.h.

◆ KeGetContextSwitches

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

Definition at line 56 of file ke.h.

◆ KeGetExceptionFrame

#define KeGetExceptionFrame (   Thread)    NULL

Definition at line 49 of file ke.h.

◆ KeGetTrapFrame

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

Definition at line 44 of file ke.h.

◆ KeGetTrapFrameInterruptState

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

Definition at line 69 of file ke.h.

◆ KeGetTrapFramePc

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

Definition at line 29 of file ke.h.

◆ KeSetContextPc

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

Definition at line 26 of file ke.h.

◆ KeSetContextReturnRegister

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

Definition at line 38 of file ke.h.

◆ KiCallVdmHandler

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

Definition at line 131 of file ke.h.

◆ KiCallVdmPrefixHandler

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

Definition at line 132 of file ke.h.

◆ KiGetLinkedTrapFrame

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

Definition at line 32 of file ke.h.

◆ KiGetSecondLevelDCacheSize

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

Definition at line 63 of file ke.h.

◆ KiVdmClearVdmEFlags

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

Definition at line 130 of file ke.h.

◆ KiVdmSetVdmEFlags

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

Definition at line 129 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 IN
Definition: typedefs.h:38
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
unsigned int ULONG
Definition: retypes.h:1

Definition at line 133 of file ke.h.

◆ KTE_SKIP_PM_BIT

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

Definition at line 75 of file ke.h.

◆ KTE_SKIP_SEG_BIT

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

Definition at line 76 of file ke.h.

◆ KTE_SKIP_VOL_BIT

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

Definition at line 77 of file ke.h.

◆ PFX_FLAG_ADDR32

#define PFX_FLAG_ADDR32   0x00008000

Definition at line 102 of file ke.h.

◆ PFX_FLAG_CS

#define PFX_FLAG_CS   0x00000200

Definition at line 96 of file ke.h.

◆ PFX_FLAG_DS

#define PFX_FLAG_DS   0x00000800

Definition at line 98 of file ke.h.

◆ PFX_FLAG_ES

#define PFX_FLAG_ES   0x00000100

Definition at line 95 of file ke.h.

◆ PFX_FLAG_FS

#define PFX_FLAG_FS   0x00001000

Definition at line 99 of file ke.h.

◆ PFX_FLAG_GS

#define PFX_FLAG_GS   0x00002000

Definition at line 100 of file ke.h.

◆ PFX_FLAG_LOCK

#define PFX_FLAG_LOCK   0x00010000

Definition at line 103 of file ke.h.

◆ PFX_FLAG_OPER32

#define PFX_FLAG_OPER32   0x00004000

Definition at line 101 of file ke.h.

◆ PFX_FLAG_REP

#define PFX_FLAG_REP   0x00040000

Definition at line 105 of file ke.h.

◆ PFX_FLAG_REPNE

#define PFX_FLAG_REPNE   0x00020000

Definition at line 104 of file ke.h.

◆ PFX_FLAG_SS

#define PFX_FLAG_SS   0x00000400

Definition at line 97 of file ke.h.

Typedef Documentation

◆ KTRAP_EXIT_SKIP_BITS

◆ KV8086_STACK_FRAME

◆ KV86_FRAME

◆ LARGE_IDENTITY_MAP

◆ 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 KiTrap0EHandler().

◆ 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 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define KeGetPcr()
Definition: ke.h:25
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define KGDT_LDT
Definition: ketypes.h:81
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
Definition: utils.h:160
#define KGDT_R3_TEB
Definition: ketypes.h:80
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
#define KGDT_NUMBER
Definition: ketypes.h:88
unsigned char UCHAR
Definition: xmlstorage.h:181
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:228
unsigned short USHORT
Definition: pedump.c:61
return STATUS_SUCCESS
Definition: btrfs.c:2725
_In_ PSTORAGE_PROPERTY_ID _Outptr_ PSTORAGE_DESCRIPTOR_HEADER * Descriptor
Definition: classpnp.h:966

Referenced by PspQueryDescriptorThread().

◆ Ke386SanitizeDr()

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

Definition at line 645 of file ke.h.

647 {
648  //
649  // Check if we're in kernel-mode, and return the address directly if so.
650  // Otherwise, make sure it's not inside the kernel-mode address space.
651  // If it is, then clear the address.
652  //
653  return ((Mode == KernelMode) ? DrAddress :
654  (DrAddress <= MM_HIGHEST_USER_ADDRESS) ? DrAddress : 0);
655 }
#define MM_HIGHEST_USER_ADDRESS
Definition: armddk.h:17
_In_ ULONG Mode
Definition: hubbusif.h:303

◆ Ke386SanitizeFlags()

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

Definition at line 628 of file ke.h.

630 {
631  //
632  // Check if we're in kernel-mode, and sanitize EFLAGS if so.
633  // Otherwise, also force interrupt mask on.
634  //
635  return ((Mode == KernelMode) ?
638 }
_In_ ULONG Mode
Definition: hubbusif.h:303
#define EFLAGS_USER_SANITIZE
Definition: ketypes.h:133
#define EFLAGS_INTERRUPT_MASK
Definition: ketypes.h:126

Referenced by KeContextToTrapFrame(), and KiInitializeUserApc().

◆ Ke386SanitizeSeg()

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

Definition at line 611 of file ke.h.

613 {
614  //
615  // Check if we're in kernel-mode, and force CPL 0 if so.
616  // Otherwise, force CPL 3.
617  //
618  return ((Mode == KernelMode) ?
619  (Cs & (0xFFFF & ~RPL_MASK)) :
620  (RPL_MASK | (Cs & 0xFFFF)));
621 }
_In_ ULONG Mode
Definition: hubbusif.h:303
#define RPL_MASK
Definition: ketypes.h:69

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

◆ Ke386SetGdtEntryBase()

FORCEINLINE VOID Ke386SetGdtEntryBase ( PKGDTENTRY  GdtEntry,
PVOID  BaseAddress 
)

Definition at line 309 of file ke.h.

310 {
311  GdtEntry->BaseLow = (USHORT)((ULONG_PTR)BaseAddress & 0xFFFF);
312  GdtEntry->HighWord.Bytes.BaseMid = (UCHAR)((ULONG_PTR)BaseAddress >> 16);
313  GdtEntry->HighWord.Bytes.BaseHi = (UCHAR)((ULONG_PTR)BaseAddress >> 24);
314 }
USHORT BaseLow
Definition: ketypes.h:334
union _KGDTENTRY::@2323 HighWord
struct _KGDTENTRY::@2323::@2324 Bytes
uint32_t ULONG_PTR
Definition: typedefs.h:63
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
unsigned char UCHAR
Definition: xmlstorage.h:181
unsigned short USHORT
Definition: pedump.c:61

Referenced by KiSetTebBase().

◆ KeDisableInterrupts()

FORCEINLINE BOOLEAN KeDisableInterrupts ( VOID  )

Definition at line 181 of file ke.h.

182 {
183  ULONG Flags;
184  BOOLEAN Return;
185 
186  /* Get EFLAGS and check if the interrupt bit is set */
187  Flags = __readeflags();
188  Return = (Flags & EFLAGS_INTERRUPT_MASK) ? TRUE: FALSE;
189 
190  /* Disable interrupts */
191  _disable();
192  return Return;
193 }
#define TRUE
Definition: types.h:120
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
__INTRIN_INLINE uintptr_t __readeflags(void)
Definition: intrin_x86.h:1555
unsigned char BOOLEAN
void __cdecl _disable(void)
Definition: intrin_arm.h:365
unsigned int ULONG
Definition: retypes.h:1
#define EFLAGS_INTERRUPT_MASK
Definition: ketypes.h:126

◆ KeFlushProcessTb()

FORCEINLINE VOID KeFlushProcessTb ( VOID  )

Definition at line 263 of file ke.h.

264 {
265  /* Flush the TLB by resetting CR3 */
267 }
__INTRIN_INLINE unsigned long __readcr3(void)
Definition: intrin_x86.h:1706
__INTRIN_INLINE void __writecr3(unsigned int Data)
Definition: intrin_x86.h:1675

◆ KeGetCurrentThread()

FORCEINLINE PRKTHREAD KeGetCurrentThread ( VOID  )

Definition at line 284 of file ke.h.

285 {
286  /* Return the current thread */
287  return ((PKIPCR)KeGetPcr())->PrcbData.CurrentThread;
288 }
FORCEINLINE PKPCR KeGetPcr(VOID)
Definition: ke.h:318

Referenced by KiCheckForApcDelivery(), and KiGetUserModeStackAddress().

◆ KeI386VdmInitialize()

INIT_FUNCTION VOID NTAPI KeI386VdmInitialize ( VOID  )

Definition at line 156 of file stubs.c.

157 {
158 }

Referenced by Phase1InitializationDiscard().

◆ KeInvalidateTlbEntry()

FORCEINLINE VOID KeInvalidateTlbEntry ( IN PVOID  Address)

Definition at line 255 of file ke.h.

256 {
257  /* Invalidate the TLB entry for this address */
258  __invlpg(Address);
259 }
static WCHAR Address[46]
Definition: ping.c:68
__INTRIN_INLINE void __invlpg(void *Address)
Definition: intrin_x86.h:1865

◆ KeQueryInterruptHandler()

FORCEINLINE PVOID KeQueryInterruptHandler ( IN ULONG  Vector)

Definition at line 233 of file ke.h.

234 {
235  PKIPCR Pcr = (PKIPCR)KeGetPcr();
236  UCHAR Entry;
237 
238  //
239  // Get the entry from the HAL
240  //
242 
243  //
244  // Read the entry from the IDT
245  //
246  return (PVOID)(((Pcr->IDT[Entry].ExtendedOffset << 16) & 0xFFFF0000) |
247  (Pcr->IDT[Entry].Offset & 0xFFFF));
248 }
struct _Entry Entry
Definition: kefuncs.h:640
struct _KIPCR * PKIPCR
USHORT Offset
Definition: ketypes.h:384
USHORT ExtendedOffset
Definition: ketypes.h:387
unsigned char UCHAR
Definition: xmlstorage.h:181
FORCEINLINE PKPCR KeGetPcr(VOID)
Definition: ke.h:318
PKIDTENTRY IDT
Definition: ketypes.h:756
base of all file and directory entries
Definition: entries.h:82
#define HalVectorToIDTEntry
Definition: halfuncs.h:51

◆ KeRegisterInterruptHandler()

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

Definition at line 208 of file ke.h.

210 {
211  UCHAR Entry;
213  PKIPCR Pcr = (PKIPCR)KeGetPcr();
214 
215  //
216  // Get the entry from the HAL
217  //
220 
221  //
222  // Now set the data
223  //
224  Pcr->IDT[Entry].ExtendedOffset = (USHORT)(Address >> 16);
225  Pcr->IDT[Entry].Offset = (USHORT)Address;
226 }
struct _Entry Entry
Definition: kefuncs.h:640
struct _KIPCR * PKIPCR
uint32_t ULONG_PTR
Definition: typedefs.h:63
static WCHAR Address[46]
Definition: ping.c:68
#define PtrToUlong(u)
Definition: config.h:107
USHORT Offset
Definition: ketypes.h:384
USHORT ExtendedOffset
Definition: ketypes.h:387
unsigned char UCHAR
Definition: xmlstorage.h:181
ACPI_PHYSICAL_ADDRESS ACPI_SIZE BOOLEAN Warn BOOLEAN Physical UINT32 ACPI_TABLE_HEADER *OutTableHeader ACPI_TABLE_HEADER **OutTable ACPI_HANDLE UINT32 ACPI_WALK_CALLBACK ACPI_WALK_CALLBACK void void **ReturnValue UINT32 ACPI_BUFFER *RetPathPtr ACPI_OBJECT_HANDLER Handler
Definition: acpixf.h:656
FORCEINLINE PKPCR KeGetPcr(VOID)
Definition: ke.h:318
unsigned short USHORT
Definition: pedump.c:61
PKIDTENTRY IDT
Definition: ketypes.h:756
base of all file and directory entries
Definition: entries.h:82
#define HalVectorToIDTEntry
Definition: halfuncs.h:51

◆ KeRestoreInterrupts()

FORCEINLINE VOID KeRestoreInterrupts ( BOOLEAN  WereEnabled)

Definition at line 198 of file ke.h.

199 {
200  if (WereEnabled) _enable();
201 }
void __cdecl _enable(void)
Definition: intrin_arm.h:373

◆ KeSweepICache()

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

Definition at line 271 of file ke.h.

273 {
274  //
275  // Always sweep the whole cache
276  //
278  UNREFERENCED_PARAMETER(FlushSize);
279  __wbinvd();
280 }
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
PPC_QUAL void __wbinvd(void)
Definition: intrin_ppc.h:759

◆ Ki386AdjustEsp0()

VOID NTAPI Ki386AdjustEsp0 ( IN PKTRAP_FRAME  TrapFrame)

Definition at line 280 of file exp.c.

281 {
283  ULONG_PTR Stack;
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 -= (FIELD_OFFSET(KTRAP_FRAME, V86Gs) -
295  FIELD_OFFSET(KTRAP_FRAME, HardwareSegSs));
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 KeGetPcr()
Definition: ke.h:25
#define EFLAGS_V86_MASK
Definition: ketypes.h:129
uint32_t ULONG_PTR
Definition: typedefs.h:63
__INTRIN_INLINE uintptr_t __readeflags(void)
Definition: intrin_x86.h:1555
struct _FX_SAVE_AREA FX_SAVE_AREA
if(!(yy_init))
Definition: macro.lex.yy.c:714
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
__INTRIN_INLINE void __writeeflags(uintptr_t Value)
Definition: intrin_x86.h:1550
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
void __cdecl _disable(void)
Definition: intrin_arm.h:365
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
#define KeGetCurrentThread
Definition: hal.h:44

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()

INIT_FUNCTION ULONG_PTR NTAPI Ki386EnableDE ( IN ULONG_PTR  Context)

Definition at line 1045 of file cpu.c.

1046 {
1047  /* Enable DE */
1049  return 0;
1050 }
__INTRIN_INLINE void __writecr4(unsigned int Data)
Definition: intrin_x86.h:1680
#define CR4_DE
Definition: ketypes.h:87
__INTRIN_INLINE unsigned long __readcr4(void)
Definition: intrin_x86.h:1713

Referenced by KiInitMachineDependent().

◆ Ki386EnableFxsr()

INIT_FUNCTION ULONG_PTR NTAPI Ki386EnableFxsr ( IN ULONG_PTR  Context)

Definition at line 1055 of file cpu.c.

1056 {
1057  /* Enable FXSR */
1059  return 0;
1060 }
__INTRIN_INLINE void __writecr4(unsigned int Data)
Definition: intrin_x86.h:1680
#define CR4_FXSR
Definition: ketypes.h:92
__INTRIN_INLINE unsigned long __readcr4(void)
Definition: intrin_x86.h:1713

Referenced by KiInitMachineDependent().

◆ Ki386EnableGlobalPage()

INIT_FUNCTION 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 }
__INTRIN_INLINE void __writecr4(unsigned int Data)
Definition: intrin_x86.h:1680
_In_ ULONGLONG _In_ ULONGLONG _In_ BOOLEAN Enable
Definition: ntddpcm.h:140
__INTRIN_INLINE unsigned long __readcr3(void)
Definition: intrin_x86.h:1706
#define CR4_PGE
Definition: ketypes.h:91
__INTRIN_INLINE void __writecr3(unsigned int Data)
Definition: intrin_x86.h:1675
unsigned char BOOLEAN
FORCEINLINE BOOLEAN KeDisableInterrupts(VOID)
Definition: ke.h:176
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
__INTRIN_INLINE unsigned long __readcr4(void)
Definition: intrin_x86.h:1713
FORCEINLINE VOID KeRestoreInterrupts(BOOLEAN WereEnabled)
Definition: ke.h:191
unsigned int ULONG
Definition: retypes.h:1

Referenced by KiInitMachineDependent().

◆ Ki386EnableTargetLargePage()

INIT_FUNCTION 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 }
ULONG_PTR StartAddress
Definition: ke.h:173
VOID NTAPI Ki386EnableCurrentLargePage(IN ULONG_PTR StartAddress, IN ULONG Cr3)
struct _LARGE_IDENTITY_MAP * PLARGE_IDENTITY_MAP

Referenced by KiInitMachineDependent().

◆ Ki386EnableXMMIExceptions()

INIT_FUNCTION ULONG_PTR NTAPI Ki386EnableXMMIExceptions ( IN ULONG_PTR  Context)

Definition at line 1065 of file cpu.c.

1066 {
1068 
1069  /* Get the IDT Entry for Interrupt 0x13 */
1070  IdtEntry = &((PKIPCR)KeGetPcr())->IDT[0x13];
1071 
1072  /* Set it up */
1073  IdtEntry->Selector = KGDT_R0_CODE;
1074  IdtEntry->Offset = ((ULONG_PTR)KiTrap13 & 0xFFFF);
1075  IdtEntry->ExtendedOffset = ((ULONG_PTR)KiTrap13 >> 16) & 0xFFFF;
1076  ((PKIDT_ACCESS)&IdtEntry->Access)->Dpl = 0;
1077  ((PKIDT_ACCESS)&IdtEntry->Access)->Present = 1;
1078  ((PKIDT_ACCESS)&IdtEntry->Access)->SegmentType = I386_INTERRUPT_GATE;
1079 
1080  /* Enable XMMI exceptions */
1082  return 0;
1083 }
__INTRIN_INLINE void __writecr4(unsigned int Data)
Definition: intrin_x86.h:1680
struct _KIPCR * PKIPCR
#define KGDT_R0_CODE
Definition: ketypes.h:74
#define KeGetPcr()
Definition: ke.h:25
Definition: hooks.h:42
Definition: utils.h:177
#define CR4_XMMEXCPT
Definition: ketypes.h:93
struct _KIDT_ACCESS * PKIDT_ACCESS
VOID __cdecl KiTrap13(VOID)
__INTRIN_INLINE unsigned long __readcr4(void)
Definition: intrin_x86.h:1713
#define I386_INTERRUPT_GATE
Definition: ketypes.h:63
#define ULONG_PTR
Definition: config.h:101

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()

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

Definition at line 799 of file cpu.c.

802 {
803  PKGDTENTRY TssEntry, TaskGateEntry;
804 
805  /* Initialize the boot TSS. */
806  TssEntry = &Gdt[KGDT_TSS / sizeof(KGDTENTRY)];
807  TssEntry->HighWord.Bits.Type = I386_TSS;
808  TssEntry->HighWord.Bits.Pres = 1;
809  TssEntry->HighWord.Bits.Dpl = 0;
810  KiInitializeTSS2(Tss, TssEntry);
811  KiInitializeTSS(Tss);
812 
813  /* Load the task register */
814  Ke386SetTr(KGDT_TSS);
815 
816  /* Setup the Task Gate for Double Fault Traps */
817  TaskGateEntry = (PKGDTENTRY)&Idt[8];
818  TaskGateEntry->HighWord.Bits.Type = I386_TASK_GATE;
819  TaskGateEntry->HighWord.Bits.Pres = 1;
820  TaskGateEntry->HighWord.Bits.Dpl = 0;
821  ((PKIDTENTRY)TaskGateEntry)->Selector = KGDT_DF_TSS;
822 
823  /* Initialize the TSS used for handling double faults. */
824  Tss = (PKTSS)KiDoubleFaultTSS;
825  KiInitializeTSS(Tss);
826  Tss->CR3 = __readcr3();
827  Tss->Esp0 = KiDoubleFaultStack;
828  Tss->Esp = KiDoubleFaultStack;
829  Tss->Eip = PtrToUlong(KiTrap08);
830  Tss->Cs = KGDT_R0_CODE;
831  Tss->Fs = KGDT_R0_PCR;
832  Tss->Ss = Ke386GetSs();
833  Tss->Es = KGDT_R3_DATA | RPL_MASK;
834  Tss->Ds = KGDT_R3_DATA | RPL_MASK;
835 
836  /* Setup the Double Trap TSS entry in the GDT */
837  TssEntry = &Gdt[KGDT_DF_TSS / sizeof(KGDTENTRY)];
838  TssEntry->HighWord.Bits.Type = I386_TSS;
839  TssEntry->HighWord.Bits.Pres = 1;
840  TssEntry->HighWord.Bits.Dpl = 0;
841  TssEntry->BaseLow = (USHORT)((ULONG_PTR)Tss & 0xFFFF);
842  TssEntry->HighWord.Bytes.BaseMid = (UCHAR)((ULONG_PTR)Tss >> 16);
843  TssEntry->HighWord.Bytes.BaseHi = (UCHAR)((ULONG_PTR)Tss >> 24);
844  TssEntry->LimitLow = KTSS_IO_MAPS;
845 
846  /* Now setup the NMI Task Gate */
847  TaskGateEntry = (PKGDTENTRY)&Idt[2];
848  TaskGateEntry->HighWord.Bits.Type = I386_TASK_GATE;
849  TaskGateEntry->HighWord.Bits.Pres = 1;
850  TaskGateEntry->HighWord.Bits.Dpl = 0;
851  ((PKIDTENTRY)TaskGateEntry)->Selector = KGDT_NMI_TSS;
852 
853  /* Initialize the actual TSS */
854  Tss = (PKTSS)KiNMITSS;
855  KiInitializeTSS(Tss);
856  Tss->CR3 = __readcr3();
857  Tss->Esp0 = KiDoubleFaultStack;
858  Tss->Esp = KiDoubleFaultStack;
859  Tss->Eip = PtrToUlong(KiTrap02);
860  Tss->Cs = KGDT_R0_CODE;
861  Tss->Fs = KGDT_R0_PCR;
862  Tss->Ss = Ke386GetSs();
863  Tss->Es = KGDT_R3_DATA | RPL_MASK;
864  Tss->Ds = KGDT_R3_DATA | RPL_MASK;
865 
866  /* And its associated TSS Entry */
867  TssEntry = &Gdt[KGDT_NMI_TSS / sizeof(KGDTENTRY)];
868  TssEntry->HighWord.Bits.Type = I386_TSS;
869  TssEntry->HighWord.Bits.Pres = 1;
870  TssEntry->HighWord.Bits.Dpl = 0;
871  TssEntry->BaseLow = (USHORT)((ULONG_PTR)Tss & 0xFFFF);
872  TssEntry->HighWord.Bytes.BaseMid = (UCHAR)((ULONG_PTR)Tss >> 16);
873  TssEntry->HighWord.Bytes.BaseHi = (UCHAR)((ULONG_PTR)Tss >> 24);
874  TssEntry->LimitLow = KTSS_IO_MAPS;
875 }
#define PKGDTENTRY
Definition: ketypes.h:438
#define I386_TASK_GATE
Definition: ketypes.h:59
USHORT BaseLow
Definition: ketypes.h:334
DECLSPEC_NORETURN VOID __cdecl KiTrap02(VOID)
Definition: traphdlr.c:461
#define KGDT_R0_CODE
Definition: ketypes.h:74
__INTRIN_INLINE unsigned long __readcr3(void)
Definition: intrin_x86.h:1706
union _KGDTENTRY::@2323 HighWord
#define KGDTENTRY
Definition: ketypes.h:437
struct _KGDTENTRY::@2323::@2324 Bytes
uint32_t ULONG_PTR
Definition: typedefs.h:63
INIT_FUNCTION VOID NTAPI KiInitializeTSS2(IN PKTSS Tss, IN PKGDTENTRY TssEntry OPTIONAL)
Definition: cpu.c:745
#define KGDT_NMI_TSS
Definition: ketypes.h:83
#define KGDT_DF_TSS
Definition: ketypes.h:82
#define RPL_MASK
Definition: ketypes.h:69
VOID NTAPI KiInitializeTSS(IN PKTSS Tss)
Definition: cpu.c:783
#define KGDT_R3_DATA
Definition: ketypes.h:77
UCHAR KiDoubleFaultTSS[KTSS_IO_MAPS]
Definition: cpu.c:18
#define PtrToUlong(u)
Definition: config.h:107
#define KGDT_TSS
Definition: ketypes.h:78
UCHAR KiNMITSS[KTSS_IO_MAPS]
Definition: cpu.c:21
#define KGDT_R0_PCR
Definition: ketypes.h:79
#define PKTSS
Definition: ketypes.h:921
unsigned char UCHAR
Definition: xmlstorage.h:181
struct _KGDTENTRY::@2323::@2325 Bits
#define PKIDTENTRY
Definition: ketypes.h:480
ULONG_PTR KiDoubleFaultStack
Definition: kiinit.c:35
VOID __cdecl KiTrap08(VOID)
unsigned short USHORT
Definition: pedump.c:61
#define KTSS_IO_MAPS
Definition: asm.h:81
#define I386_TSS
Definition: ketypes.h:60
USHORT LimitLow
Definition: ketypes.h:333

Referenced by KiSystemStartup().

◆ Ki386PerfEnd()

FORCEINLINE VOID Ki386PerfEnd ( VOID  )

Definition at line 893 of file ke.h.

894 {
897  DbgPrint("Boot took %I64u cycles!\n", BootCyclesEnd - BootCycles);
898  DbgPrint("Interrupts: %u System Calls: %u Context Switches: %u\n",
899  KeGetCurrentPrcb()->InterruptCount,
900  KeGetCurrentPrcb()->KeSystemCalls,
902 }
#define DbgPrint
Definition: loader.c:25
ULONGLONG BootCycles
Definition: kiinit.c:30
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1062
PPC_QUAL unsigned long long __rdtsc(void)
Definition: intrin_ppc.h:688
ULONGLONG BootCyclesEnd
Definition: kiinit.c:30
uint64_t ULONGLONG
Definition: typedefs.h:65
#define KeGetContextSwitches(Prcb)
Definition: ke.h:56

Referenced by NtInitializeRegistry(), and PspCreateProcess().

◆ Ki386SetupAndExitToV86Mode()

VOID NTAPI Ki386SetupAndExitToV86Mode ( OUT PTEB  VdmTeb)

Referenced by Ke386CallBios().

◆ KiAmdK6InitializeMTRR()

INIT_FUNCTION 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 }
void DPRINT(...)
Definition: polytest.cpp:61

Referenced by KiInitMachineDependent().

◆ KiCheckForApcDelivery()

FORCEINLINE VOID KiCheckForApcDelivery ( IN PKTRAP_FRAME  TrapFrame)

Definition at line 777 of file ke.h.

778 {
780  KIRQL OldIrql;
781 
782  /* Check for V8086 or user-mode trap */
783  if ((TrapFrame->EFlags & EFLAGS_V86_MASK) || (KiUserTrap(TrapFrame)))
784  {
785  /* Get the thread */
787  while (TRUE)
788  {
789  /* Turn off the alerted state for kernel mode */
790  Thread->Alerted[KernelMode] = FALSE;
791 
792  /* Are there pending user APCs? */
793  if (!Thread->ApcState.UserApcPending) break;
794 
795  /* Raise to APC level and enable interrupts */
797  _enable();
798 
799  /* Deliver APCs */
800  KiDeliverApc(UserMode, NULL, TrapFrame);
801 
802  /* Restore IRQL and disable interrupts once again */
804  _disable();
805  }
806  }
807 }
#define TRUE
Definition: types.h:120
void __cdecl _enable(void)
Definition: intrin_arm.h:373
#define EFLAGS_V86_MASK
Definition: ketypes.h:129
UCHAR KIRQL
Definition: env_spec_w32.h:591
NTKERNELAPI KIRQL NTAPI KfRaiseIrql(IN KIRQL NewIrql)
Definition: pic.c:187
FORCEINLINE PRKTHREAD KeGetCurrentThread(VOID)
Definition: ke.h:284
smooth NULL
Definition: ftsmooth.c:416
#define APC_LEVEL
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
NTKERNELAPI VOID NTAPI KfLowerIrql(IN KIRQL NewIrql)
Definition: pic.c:232
void __cdecl _disable(void)
Definition: intrin_arm.h:365
VOID NTAPI KiDeliverApc(IN KPROCESSOR_MODE DeliveryMode, IN PKEXCEPTION_FRAME ExceptionFrame, IN PKTRAP_FRAME TrapFrame)
Definition: apc.c:302
BOOLEAN FORCEINLINE KiUserTrap(IN PKTRAP_FRAME TrapFrame)
Definition: ke.h:305

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 663 of file ke.h.

666 {
667  /* Helper for exceptions with no arguments */
668  KiDispatchExceptionFromTrapFrame(Code, 0, Address, 0, 0, 0, 0, TrapFrame);
669 }
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:1100
static WCHAR Address[46]
Definition: ping.c:68
#define Code
Definition: deflate.h:80

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 677 of file ke.h.

681 {
682  /* Helper for exceptions with no arguments */
683  KiDispatchExceptionFromTrapFrame(Code, 0, Address, 1, P1, 0, 0, TrapFrame);
684 }
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:1100
static WCHAR Address[46]
Definition: ping.c:68
#define Code
Definition: deflate.h:80

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 692 of file ke.h.

697 {
698  /* Helper for exceptions with no arguments */
699  KiDispatchExceptionFromTrapFrame(Code, 0, Address, 2, P1, P2, 0, TrapFrame);
700 }
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:1100
static WCHAR Address[46]
Definition: ping.c:68
#define Code
Definition: deflate.h:80

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 1100 of file exp.c.

1108 {
1109  EXCEPTION_RECORD ExceptionRecord;
1110 
1111  /* Build the exception record */
1112  ExceptionRecord.ExceptionCode = Code;
1113  ExceptionRecord.ExceptionFlags = Flags;
1114  ExceptionRecord.ExceptionRecord = NULL;
1115  ExceptionRecord.ExceptionAddress = (PVOID)Address;
1116  ExceptionRecord.NumberParameters = ParameterCount;
1117  if (ParameterCount)
1118  {
1119  /* Copy extra parameters */
1120  ExceptionRecord.ExceptionInformation[0] = Parameter1;
1121  ExceptionRecord.ExceptionInformation[1] = Parameter2;
1122  ExceptionRecord.ExceptionInformation[2] = Parameter3;
1123  }
1124 
1125  /* Now go dispatch the exception */
1126  KiDispatchException(&ExceptionRecord,
1127  NULL,
1128  TrapFrame,
1129  TrapFrame->EFlags & EFLAGS_V86_MASK ?
1130  -1 : KiUserTrap(TrapFrame),
1131  TRUE);
1132 
1133  /* Return from this trap */
1134  KiEoiHelper(TrapFrame);
1135 }
#define TRUE
Definition: types.h:120
DECLSPEC_NORETURN VOID FASTCALL KiEoiHelper(IN PKTRAP_FRAME TrapFrame)
Definition: traphdlr.c:126
PVOID ExceptionAddress
Definition: compat.h:199
#define EFLAGS_V86_MASK
Definition: ketypes.h:129
DWORD ExceptionCode
Definition: compat.h:196
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
smooth NULL
Definition: ftsmooth.c:416
static WCHAR Address[46]
Definition: ping.c:68
void * PVOID
Definition: retypes.h:9
#define Code
Definition: deflate.h:80
ULONG_PTR ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS]
Definition: compat.h:201
struct _EXCEPTION_RECORD * ExceptionRecord
Definition: compat.h:198
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:151
DWORD ExceptionFlags
Definition: compat.h:197
DWORD NumberParameters
Definition: compat.h:200
BOOLEAN FORCEINLINE KiUserTrap(IN PKTRAP_FRAME TrapFrame)
Definition: ke.h:305

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

◆ KiEndInterrupt()

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

Definition at line 877 of file ke.h.

879 {
880  /* Disable interrupts and end the interrupt */
881  _disable();
882  HalEndSystemInterrupt(Irql, TrapFrame);
883 
884  /* Exit the interrupt */
885  KiEoiHelper(TrapFrame);
886 }
VOID NTAPI HalEndSystemInterrupt(IN KIRQL OldIrql, IN PKTRAP_FRAME TrapFrame)
Definition: pic.c:335
_Out_ PKIRQL Irql
Definition: csq.h:179
DECLSPEC_NORETURN VOID FASTCALL KiEoiHelper(IN PKTRAP_FRAME TrapFrame)
Definition: traphdlr.c:126
void __cdecl _disable(void)
Definition: intrin_arm.h:365

◆ 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 */
144  KiTrapReturnNoSegmentsRet8(TrapFrame);
145 }
#define TRUE
Definition: types.h:120
DECLSPEC_NORETURN VOID FASTCALL KiTrapReturnNoSegmentsRet8(IN PKTRAP_FRAME TrapFrame)
DECLSPEC_NORETURN VOID FASTCALL KiTrapReturnNoSegments(IN PKTRAP_FRAME TrapFrame)
FORCEINLINE BOOLEAN KiIsFrameEdited(IN PKTRAP_FRAME TrapFrame)
Definition: traphdlr.c:87
DECLSPEC_NORETURN VOID FASTCALL KiTrapReturn(IN PKTRAP_FRAME TrapFrame)
FORCEINLINE VOID KiCommonExit(IN PKTRAP_FRAME TrapFrame, BOOLEAN SkipPreviousMode)
Definition: traphdlr.c:96
#define EFLAGS_V86_MASK
Definition: ketypes.h:129
#define EFLAGS_TF
Definition: ketypes.h:125
BOOLEAN FORCEINLINE KiUserTrap(IN PKTRAP_FRAME TrapFrame)
Definition: ke.h:305
DECLSPEC_NORETURN VOID FASTCALL KiEditedTrapReturn(IN PKTRAP_FRAME TrapFrame)

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

◆ KiExitV86Mode()

ULONG_PTR FASTCALL KiExitV86Mode ( IN PKTRAP_FRAME  TrapFrame)

Definition at line 468 of file v86vdm.c.

469 {
470  ULONG_PTR StackFrameUnaligned;
471  PKV8086_STACK_FRAME StackFrame;
473  PKTRAP_FRAME PmTrapFrame;
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  PmTrapFrame = &StackFrame->TrapFrame;
481  V86Frame = &StackFrame->V86Frame;
482  NpxFrame = &StackFrame->NpxArea;
483  ASSERT((ULONG_PTR)NpxFrame % 16 == 0);
484 
485  /* Copy the FPU frame back */
488 
489  /* Set initial stack back */
490  Thread->InitialStack = (PVOID)((ULONG_PTR)V86Frame->ThreadStack + sizeof(FX_SAVE_AREA));
491 
492  /* Set ESP0 back in the KTSS */
493  KeGetPcr()->TSS->Esp0 = (ULONG_PTR)&PmTrapFrame->V86Es;
494 
495  /* Restore TEB addresses */
496  Thread->Teb = V86Frame->ThreadTeb;
497  KiSetTebBase(KeGetPcr(), V86Frame->ThreadTeb);
498 
499  /* Enable interrupts and return a pointer to the trap frame */
500  _enable();
501  return StackFrameUnaligned;
502 }
KV86_FRAME V86Frame
Definition: ke.h:163
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
ULONG V86Es
Definition: ketypes.h:270
#define ROUND_UP(n, align)
Definition: eventvwr.h:31
FX_SAVE_AREA NpxArea
Definition: ke.h:162
struct _KV8086_STACK_FRAME * PKV8086_STACK_FRAME
void __cdecl _enable(void)
Definition: intrin_arm.h:373
#define KeGetPcr()
Definition: ke.h:25
uint32_t ULONG_PTR
Definition: typedefs.h:63
PVOID ThreadStack
Definition: ke.h:151
void * PVOID
Definition: retypes.h:9
FORCEINLINE PFX_SAVE_AREA KiGetThreadNpxArea(IN PKTHREAD Thread)
Definition: ke.h:600
struct _FX_SAVE_AREA FX_SAVE_AREA
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
PVOID ThreadTeb
Definition: ke.h:152
FORCEINLINE VOID KiSetTebBase(PKPCR Pcr, PVOID TebAddress)
Definition: ke.h:318
#define ULONG_PTR
Definition: config.h:101
#define KeGetCurrentThread
Definition: hal.h:44
KTRAP_FRAME TrapFrame
Definition: ke.h:161

◆ KiFastCallEntry()

VOID __cdecl KiFastCallEntry ( VOID  )

◆ KiFlushNPXState()

VOID NTAPI KiFlushNPXState ( IN FLOATING_SAVE_AREA SaveArea)

◆ KiGetCacheInformation()

INIT_FUNCTION VOID NTAPI KiGetCacheInformation ( VOID  )

Definition at line 214 of file cpu.c.

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

◆ KiGetFeatureBits()

INIT_FUNCTION ULONG NTAPI KiGetFeatureBits ( VOID  )

Definition at line 125 of file cpu.c.

126 {
127  PKPRCB Prcb = KeGetCurrentPrcb();
128  ULONG Vendor;
129  ULONG FeatureBits = KF_WORKING_PTE;
130  CPU_INFO CpuInfo;
131 
132  /* Get the Vendor ID */
133  Vendor = KiGetCpuVendor();
134 
135  /* Make sure we got a valid vendor ID at least. */
136  if (!Vendor) return FeatureBits;
137 
138  /* Get the CPUID Info. */
139  KiCpuId(&CpuInfo, 1);
140 
141  /* Set the initial APIC ID */
142  Prcb->InitialApicId = (UCHAR)(CpuInfo.Ebx >> 24);
143 
144  /* Convert all CPUID Feature bits into our format */
145  if (CpuInfo.Edx & X86_FEATURE_VME) FeatureBits |= KF_V86_VIS | KF_CR4;
146  if (CpuInfo.Edx & X86_FEATURE_PSE) FeatureBits |= KF_LARGE_PAGE | KF_CR4;
147  if (CpuInfo.Edx & X86_FEATURE_TSC) FeatureBits |= KF_RDTSC;
148  if (CpuInfo.Edx & X86_FEATURE_CX8) FeatureBits |= KF_CMPXCHG8B;
149  if (CpuInfo.Edx & X86_FEATURE_SYSCALL) FeatureBits |= KF_FAST_SYSCALL;
150  if (CpuInfo.Edx & X86_FEATURE_MTTR) FeatureBits |= KF_MTRR;
151  if (CpuInfo.Edx & X86_FEATURE_PGE) FeatureBits |= KF_GLOBAL_PAGE | KF_CR4;
152  if (CpuInfo.Edx & X86_FEATURE_CMOV) FeatureBits |= KF_CMOV;
153  if (CpuInfo.Edx & X86_FEATURE_PAT) FeatureBits |= KF_PAT;
154  if (CpuInfo.Edx & X86_FEATURE_DS) FeatureBits |= KF_DTS;
155  if (CpuInfo.Edx & X86_FEATURE_MMX) FeatureBits |= KF_MMX;
156  if (CpuInfo.Edx & X86_FEATURE_FXSR) FeatureBits |= KF_FXSR;
157  if (CpuInfo.Edx & X86_FEATURE_SSE) FeatureBits |= KF_XMMI;
158  if (CpuInfo.Edx & X86_FEATURE_SSE2) FeatureBits |= KF_XMMI64;
159 
160  if (CpuInfo.Ecx & X86_FEATURE_SSE3) FeatureBits |= KF_SSE3;
161  //if (CpuInfo.Ecx & X86_FEATURE_MONITOR) FeatureBits |= KF_MONITOR;
162  //if (CpuInfo.Ecx & X86_FEATURE_SSSE3) FeatureBits |= KF_SSE3SUP;
163  if (CpuInfo.Ecx & X86_FEATURE_CX16) FeatureBits |= KF_CMPXCHG16B;
164  //if (CpuInfo.Ecx & X86_FEATURE_SSE41) FeatureBits |= KF_SSE41;
165  //if (CpuInfo.Ecx & X86_FEATURE_POPCNT) FeatureBits |= KF_POPCNT;
166  if (CpuInfo.Ecx & X86_FEATURE_XSAVE) FeatureBits |= KF_XSTATE;
167 
168  /* Check if the CPU has hyper-threading */
169  if (CpuInfo.Edx & X86_FEATURE_HT)
170  {
171  /* Set the number of logical CPUs */
172  Prcb->LogicalProcessorsPerPhysicalProcessor = (UCHAR)(CpuInfo.Ebx >> 16);
174  {
175  /* We're on dual-core */
177  }
178  }
179  else
180  {
181  /* We only have a single CPU */
183  }
184 
185  /* Check extended cpuid features */
186  KiCpuId(&CpuInfo, 0x80000000);
187  if ((CpuInfo.Eax & 0xffffff00) == 0x80000000)
188  {
189  /* Check if CPUID 0x80000001 is supported */
190  if (CpuInfo.Eax >= 0x80000001)
191  {
192  /* Check which extended features are available. */
193  KiCpuId(&CpuInfo, 0x80000001);
194 
195  /* Check if NX-bit is supported */
196  if (CpuInfo.Edx & X86_FEATURE_NX) FeatureBits |= KF_NX_BIT;
197 
198  /* Now handle each features for each CPU Vendor */
199  switch (Vendor)
200  {
201  case CPU_AMD:
202  if (CpuInfo.Edx & 0x80000000) FeatureBits |= KF_3DNOW;
203  break;
204  }
205  }
206  }
207 
208  /* Return the Feature Bits */
209  return FeatureBits;
210 }
#define X86_FEATURE_PGE
Definition: ke.h:35
#define X86_FEATURE_SYSCALL
Definition: ke.h:33
#define TRUE
Definition: types.h:120
#define X86_FEATURE_VME
Definition: ke.h:27
UCHAR LogicalProcessorsPerPhysicalProcessor
Definition: ketypes.h:703
#define KF_CMPXCHG8B
Definition: ketypes.h:150
#define X86_FEATURE_MMX
Definition: ke.h:39
#define X86_FEATURE_SSE2
Definition: ke.h:42
#define X86_FEATURE_HT
Definition: ke.h:43
#define KF_RDTSC
Definition: ketypes.h:144
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1062
#define KF_MMX
Definition: ketypes.h:151
#define X86_FEATURE_FXSR
Definition: ke.h:40
#define KF_NX_BIT
Definition: ketypes.h:165
#define X86_FEATURE_XSAVE
Definition: ke.h:56
ULONG NTAPI KiGetCpuVendor(VOID)
Definition: cpu.c:85
#define KF_LARGE_PAGE
Definition: ketypes.h:148
#define KF_PAT
Definition: ketypes.h:153
#define KF_XMMI
Definition: ketypes.h:156
#define X86_FEATURE_CX16
Definition: ke.h:51
#define X86_FEATURE_PSE
Definition: ke.h:29
ULONG Eax
Definition: ketypes.h:296
#define X86_FEATURE_PAT
Definition: ke.h:37
#define KF_CR4
Definition: ketypes.h:145
ULONG Ebx
Definition: ketypes.h:297
#define KF_MTRR
Definition: ketypes.h:149
ULONG Ecx
Definition: ketypes.h:298
#define X86_FEATURE_NX
Definition: ke.h:59
#define KF_WORKING_PTE
Definition: ketypes.h:152
#define KF_FAST_SYSCALL
Definition: ketypes.h:155
#define KF_V86_VIS
Definition: ketypes.h:143
#define KF_FXSR
Definition: ketypes.h:154
#define KF_3DNOW
Definition: ketypes.h:157
#define X86_FEATURE_MTTR
Definition: ke.h:34
unsigned char UCHAR
Definition: xmlstorage.h:181
#define KF_XMMI64
Definition: ketypes.h:159
#define KF_CMPXCHG16B
Definition: ketypes.h:163
#define X86_FEATURE_SSE
Definition: ke.h:41
#define X86_FEATURE_CX8
Definition: ke.h:32
#define KF_SSE3
Definition: ketypes.h:162
#define X86_FEATURE_CMOV
Definition: ke.h:36
unsigned int ULONG
Definition: retypes.h:1
#define KF_DTS
Definition: ketypes.h:160
#define X86_FEATURE_TSC
Definition: ke.h:30
#define KF_XSTATE
Definition: ketypes.h:164
#define X86_FEATURE_DS
Definition: ke.h:38
#define KF_GLOBAL_PAGE
Definition: ketypes.h:147
ULONG Edx
Definition: ketypes.h:299
BOOLEAN KiSMTProcessorsPresent
Definition: cpu.c:34
#define KF_CMOV
Definition: ketypes.h:146
#define X86_FEATURE_SSE3
Definition: ke.h:46
ULONG InitialApicId
Definition: ketypes.h:617

◆ KiGetThreadNpxArea()

FORCEINLINE PFX_SAVE_AREA KiGetThreadNpxArea ( IN PKTHREAD  Thread)

Definition at line 600 of file ke.h.

601 {
602  ASSERT((ULONG_PTR)Thread->InitialStack % 16 == 0);
603  return (PFX_SAVE_AREA)((ULONG_PTR)Thread->InitialStack - sizeof(FX_SAVE_AREA));
604 }
uint32_t ULONG_PTR
Definition: typedefs.h:63
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ULONG_PTR
Definition: config.h:101

Referenced by KiCoprocessorError(), KiEnterV86Mode(), KiExitV86Mode(), KiFlushNPXState(), KiInitMachineDependent(), KiSwapContextEntry(), KiTrap07Handler(), KiTrap10Handler(), and KiTrap13Handler().

◆ KiGetUserModeStackAddress()

FORCEINLINE PULONG KiGetUserModeStackAddress ( void  )

Definition at line 906 of file ke.h.

907 {
909 }
PKTRAP_FRAME TrapFrame
Definition: ketypes.h:1664
FORCEINLINE PRKTHREAD KeGetCurrentThread(VOID)
Definition: ke.h:284
ULONG HardwareEsp
Definition: ketypes.h:268

Referenced by KeUserModeCallback().

◆ KiI386PentiumLockErrataFixup()

INIT_FUNCTION VOID NTAPI KiI386PentiumLockErrataFixup ( VOID  )

Definition at line 1088 of file cpu.c.

1089 {
1090  KDESCRIPTOR IdtDescriptor = {0, 0, 0};
1091  PKIDTENTRY NewIdt, NewIdt2;
1092 
1093  /* Allocate memory for a new IDT */
1094  NewIdt = ExAllocatePool(NonPagedPool, 2 * PAGE_SIZE);
1095 
1096  /* Put everything after the first 7 entries on a new page */
1097  NewIdt2 = (PVOID)((ULONG_PTR)NewIdt + PAGE_SIZE - (7 * sizeof(KIDTENTRY)));
1098 
1099  /* Disable interrupts */
1100  _disable();
1101 
1102  /* Get the current IDT and copy it */
1103  __sidt(&IdtDescriptor.Limit);
1104  RtlCopyMemory(NewIdt2,
1105  (PVOID)IdtDescriptor.Base,
1106  IdtDescriptor.Limit + 1);
1107  IdtDescriptor.Base = (ULONG)NewIdt2;
1108 
1109  /* Set the new IDT */
1110  __lidt(&IdtDescriptor.Limit);
1111  ((PKIPCR)KeGetPcr())->IDT = NewIdt2;
1112 
1113  /* Restore interrupts */
1114  _enable();
1115 
1116  /* Set the first 7 entries as read-only to produce a fault */
1118 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
void __cdecl _enable(void)
Definition: intrin_arm.h:373
struct _KIPCR * PKIPCR
__INTRIN_INLINE void __lidt(void *Source)
Definition: intrin_x86.h:1915
PVOID Base
Definition: ketypes.h:486
#define KeGetPcr()
Definition: ke.h:25
USHORT Limit
Definition: ketypes.h:485
uint32_t ULONG_PTR
Definition: typedefs.h:63
__INTRIN_INLINE void __sidt(void *Destination)
Definition: intrin_x86.h:1920
smooth NULL
Definition: ftsmooth.c:416
void * PVOID
Definition: retypes.h:9
Definition: utils.h:177
VOID NTAPI MmSetPageProtect(struct _EPROCESS *Process, PVOID Address, ULONG flProtect)
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define KIDTENTRY
Definition: ketypes.h:479
#define PAGE_READONLY
Definition: compat.h:127
void __cdecl _disable(void)
Definition: intrin_arm.h:365
unsigned int ULONG
Definition: retypes.h:1

Referenced by KiInitMachineDependent().

◆ KiInitializeMTRR()

INIT_FUNCTION 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 }
void DPRINT(...)
Definition: polytest.cpp:61

Referenced by KiInitMachineDependent().

◆ KiInitializePAT()

INIT_FUNCTION 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 }
void DPRINT(...)
Definition: polytest.cpp:61

Referenced by KiInitMachineDependent().

◆ KiIret()

Definition at line 853 of file ke.h.

854 {
855 #if defined(__GNUC__)
856  __asm__ __volatile__
857  (
858  "iret"
859  );
860 #elif defined(_MSC_VER)
861  __asm
862  {
863  iretd
864  }
865 #else
866 #error Unsupported compiler
867 #endif
868  UNREACHABLE;
869 }
__asm__("\t.globl GetPhys\n" "GetPhys:\t\n" "mflr 0\n\t" "stwu 0,-16(1)\n\t" "mfmsr 5\n\t" "andi. 6,5,0xffef\n\t" "mtmsr 6\n\t" "isync\n\t" "sync\n\t" "lwz 3,0(3)\n\t" "mtmsr 5\n\t" "isync\n\t" "sync\n\t" "lwz 0,0(1)\n\t" "addi 1,1,16\n\t" "mtlr 0\n\t" "blr")

Referenced by KiTrap02().

◆ KiIsNpxErrataPresent()

INIT_FUNCTION BOOLEAN NTAPI KiIsNpxErrataPresent ( VOID  )

Definition at line 1205 of file cpu.c.

1206 {
1207  static double Value1 = 4195835.0, Value2 = 3145727.0;
1208  INT ErrataPresent;
1209  ULONG Cr0;
1210 
1211  /* Disable interrupts */
1212  _disable();
1213 
1214  /* Read CR0 and remove FPU flags */
1215  Cr0 = __readcr0();
1216  __writecr0(Cr0 & ~(CR0_MP | CR0_TS | CR0_EM));
1217 
1218  /* Initialize FPU state */
1219  Ke386FnInit();
1220 
1221  /* Multiply the magic values and divide, we should get the result back */
1222 #ifdef __GNUC__
1223  __asm__ __volatile__
1224  (
1225  "fldl %1\n\t"
1226  "fdivl %2\n\t"
1227  "fmull %2\n\t"
1228  "fldl %1\n\t"
1229  "fsubp\n\t"
1230  "fistpl %0\n\t"
1231  : "=m" (ErrataPresent)
1232  : "m" (Value1),
1233  "m" (Value2)
1234  );
1235 #else
1236  __asm
1237  {
1238  fld Value1
1239  fdiv Value2
1240  fmul Value2
1241  fld Value1
1242  fsubp st(1), st(0)
1243  fistp ErrataPresent
1244  };
1245 #endif
1246 
1247  /* Restore CR0 */
1248  __writecr0(Cr0);
1249 
1250  /* Enable interrupts */
1251  _enable();
1252 
1253  /* Return if there's an errata */
1254  return ErrataPresent != 0;
1255 }
#define CR0_MP
Definition: asm.h:246
void __cdecl _enable(void)
Definition: intrin_arm.h:373
#define CR0_TS
Definition: asm.h:248
int32_t INT
Definition: typedefs.h:56
__asm__("\t.globl GetPhys\n" "GetPhys:\t\n" "mflr 0\n\t" "stwu 0,-16(1)\n\t" "mfmsr 5\n\t" "andi. 6,5,0xffef\n\t" "mtmsr 6\n\t" "isync\n\t" "sync\n\t" "lwz 3,0(3)\n\t" "mtmsr 5\n\t" "isync\n\t" "sync\n\t" "lwz 0,0(1)\n\t" "addi 1,1,16\n\t" "mtlr 0\n\t" "blr")
__INTRIN_INLINE void __writecr0(unsigned int Data)
Definition: intrin_x86.h:1670
__INTRIN_INLINE unsigned long __readcr0(void)
Definition: intrin_x86.h:1692
void __cdecl _disable(void)
Definition: intrin_arm.h:365
unsigned int ULONG
Definition: retypes.h:1
#define CR0_EM
Definition: asm.h:247

Referenced by KiInitMachineDependent().

◆ KiIsNpxPresent()

INIT_FUNCTION BOOLEAN NTAPI KiIsNpxPresent ( VOID  )

Definition at line 1164 of file cpu.c.

1165 {
1166  ULONG Cr0;
1167  USHORT Magic;
1168 
1169  /* Set magic */
1170  Magic = 0xFFFF;
1171 
1172  /* Read CR0 and mask out FPU flags */
1173  Cr0 = __readcr0() & ~(CR0_MP | CR0_TS | CR0_EM | CR0_ET);
1174 
1175  /* Store on FPU stack */
1176 #ifdef _MSC_VER
1177  __asm fninit;
1178  __asm fnstsw Magic;
1179 #else
1180  asm volatile ("fninit;" "fnstsw %0" : "+m"(Magic));
1181 #endif
1182 
1183  /* Magic should now be cleared */
1184  if (Magic & 0xFF)
1185  {
1186  /* You don't have an FPU -- enable emulation for now */
1187  __writecr0(Cr0 | CR0_EM | CR0_TS);
1188  return FALSE;
1189  }
1190 
1191  /* You have an FPU, enable it */
1192  Cr0 |= CR0_ET;
1193 
1194  /* Enable INT 16 on 486 and higher */
1195  if (KeGetCurrentPrcb()->CpuType >= 3) Cr0 |= CR0_NE;
1196 
1197  /* Set FPU state */
1198  __writecr0(Cr0 | CR0_EM | CR0_TS);
1199  return TRUE;
1200 }
#define CR0_MP
Definition: asm.h:246
#define TRUE
Definition: types.h:120
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1062
#define CR0_TS
Definition: asm.h:248
#define CR0_NE
Definition: asm.h:250
__INTRIN_INLINE void __writecr0(unsigned int Data)
Definition: intrin_x86.h:1670
__INTRIN_INLINE unsigned long __readcr0(void)
Definition: intrin_x86.h:1692
#define CR0_ET
Definition: asm.h:249
unsigned short USHORT
Definition: pedump.c:61
unsigned int ULONG
Definition: retypes.h:1
#define CR0_EM
Definition: asm.h:247

Referenced by KiInitializeKernel().

◆ KiRestoreFastSyscallReturnState()

INIT_FUNCTION VOID NTAPI KiRestoreFastSyscallReturnState ( VOID  )

Definition at line 1011 of file cpu.c.

1012 {
1013  /* Check if the CPU Supports fast system call */
1015  {
1016  /* Check if it has been disabled */
1018  {
1019  /* Disable fast system call */
1022  DPRINT1("Support for SYSENTER disabled.\n");
1023  }
1024  else
1025  {
1026  /* Do an IPI to enable it */
1028 
1029  /* It's enabled, so use the proper exit stub */
1031  DPRINT("Support for SYSENTER detected.\n");
1032  }
1033  }
1034  else
1035  {
1036  /* Use the IRET handler */
1038  DPRINT1("No support for SYSENTER detected.\n");
1039  }
1040 }
ULONG KeFeatureBits
Definition: krnlinit.c:22
void DPRINT(...)
Definition: polytest.cpp:61
ULONG KiFastSystemCallDisable
Definition: cpu.c:26
#define KF_FAST_SYSCALL
Definition: ketypes.h:155
DECLSPEC_NORETURN VOID FASTCALL KiSystemCallSysExitReturn(IN PKTRAP_FRAME TrapFrame)
INIT_FUNCTION ULONG_PTR NTAPI KiLoadFastSyscallMachineSpecificRegisters(IN ULONG_PTR Context)
Definition: cpu.c:997
#define DPRINT1
Definition: precomp.h:8
ULONG_PTR NTAPI KeIpiGenericCall(IN PKIPI_BROADCAST_WORKER Function, IN ULONG_PTR Argument)
Definition: ipi.c:196
DECLSPEC_NORETURN VOID FASTCALL KiSystemCallTrapReturn(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 292 of file ke.h.

293 {
294 #ifndef CONFIG_SMP
295  /* Check if this is the NPX Thread */
296  if (KeGetCurrentPrcb()->NpxThread == Thread)
297  {
298  /* Clear it */
299  KeGetCurrentPrcb()->NpxThread = NULL;
300  Ke386FnInit();
301  }
302 #else
303  /* Nothing to do */
304 #endif
305 }
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1062
smooth NULL
Definition: ftsmooth.c:416
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653

◆ KiSetCR0Bits()

INIT_FUNCTION VOID NTAPI KiSetCR0Bits ( VOID  )

Definition at line 728 of file cpu.c.

729 {
730  ULONG Cr0;
731 
732  /* Save current CR0 */
733  Cr0 = __readcr0();
734 
735  /* If this is a 486, enable Write-Protection */
736  if (KeGetCurrentPrcb()->CpuType > 3) Cr0 |= CR0_WP;
737 
738  /* Set new Cr0 */
739  __writecr0(Cr0);
740 }
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1062
__INTRIN_INLINE void __writecr0(unsigned int Data)
Definition: intrin_x86.h:1670
__INTRIN_INLINE unsigned long __readcr0(void)
Definition: intrin_x86.h:1692
unsigned int ULONG
Definition: retypes.h:1
#define CR0_WP
Definition: asm.h:251

Referenced by KiInitMachineDependent().

◆ KiSetProcessorType()

INIT_FUNCTION VOID NTAPI KiSetProcessorType ( VOID  )

Definition at line 55 of file cpu.c.

56 {
57  CPU_INFO CpuInfo;
58  ULONG Stepping, Type;
59 
60  /* Do CPUID 1 now */
61  KiCpuId(&CpuInfo, 1);
62 
63  /*
64  * Get the Stepping and Type. The stepping contains both the
65  * Model and the Step, while the Type contains the returned Type.
66  * We ignore the family.
67  *
68  * For the stepping, we convert this: zzzzzzxy into this: x0y
69  */
70  Stepping = CpuInfo.Eax & 0xF0;
71  Stepping <<= 4;
72  Stepping += (CpuInfo.Eax & 0xFF);
73  Stepping &= 0xF0F;
74  Type = CpuInfo.Eax & 0xF00;
75  Type >>= 8;
76 
77  /* Save them in the PRCB */
78  KeGetCurrentPrcb()->CpuID = TRUE;
79  KeGetCurrentPrcb()->CpuType = (UCHAR)Type;
80  KeGetCurrentPrcb()->CpuStep = (USHORT)Stepping;
81 }
#define TRUE
Definition: types.h:120
Type
Definition: Type.h:6
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1062
ULONG Eax
Definition: ketypes.h:296
unsigned char UCHAR
Definition: xmlstorage.h:181
unsigned short USHORT
Definition: pedump.c:61
unsigned int ULONG
Definition: retypes.h:1

◆ KiSetTebBase()

FORCEINLINE VOID KiSetTebBase ( PKPCR  Pcr,
PVOID  TebAddress 
)

Definition at line 318 of file ke.h.

319 {
320  Pcr->NtTib.Self = TebAddress;
321  Ke386SetGdtEntryBase(&Pcr->GDT[KGDT_R3_TEB / sizeof(KGDTENTRY)], TebAddress);
322 }
struct _NT_TIB * Self
Definition: compat.h:380
FORCEINLINE VOID Ke386SetGdtEntryBase(PKGDTENTRY GdtEntry, PVOID BaseAddress)
Definition: ke.h:309
#define KGDT_R3_TEB
Definition: ketypes.h:80
NT_TIB NtTib
Definition: ke.h:284
PUSHORT GDT
Definition: ke.h:53

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

◆ KiSwitchToBootStack()

INIT_FUNCTION FORCEINLINE VOID KiSwitchToBootStack ( IN ULONG_PTR  InitialStack)

Definition at line 815 of file ke.h.

816 {
817  INIT_FUNCTION VOID NTAPI KiSystemStartupBootStack(VOID);
818 
819  /* We have to switch to a new stack before continuing kernel initialization */
820 #ifdef __GNUC__
821  __asm__
822  (
823  "movl %0, %%esp\n\t"
824  "subl %1, %%esp\n\t"
825  "pushl %2\n\t"
826  "jmp _KiSystemStartupBootStack@0"
827  :
828  : "c"(InitialStack),
830  "i"(CR0_EM | CR0_TS | CR0_MP),
832  : "%esp"
833  );
834 #elif defined(_MSC_VER)
835  __asm
836  {
837  mov esp, InitialStack
839  push (CR0_EM | CR0_TS | CR0_MP)
841  }
842 #else
843 #error Unknown Compiler
844 #endif
845 }
#define CR0_MP
Definition: asm.h:246
#define NPX_FRAME_LENGTH
Definition: asm.h:244
#define CR0_TS
Definition: asm.h:248
#define KTRAP_FRAME_LENGTH
Definition: asm.h:126
#define KTRAP_FRAME_ALIGN
Definition: asm.h:125
VOID NTAPI INIT_FUNCTION KiSystemStartupBootStack(VOID)
Definition: krnlinit.c:57
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
__asm__("\t.globl GetPhys\n" "GetPhys:\t\n" "mflr 0\n\t" "stwu 0,-16(1)\n\t" "mfmsr 5\n\t" "andi. 6,5,0xffef\n\t" "mtmsr 6\n\t" "isync\n\t" "sync\n\t" "lwz 3,0(3)\n\t" "mtmsr 5\n\t" "isync\n\t" "sync\n\t" "lwz 0,0(1)\n\t" "addi 1,1,16\n\t" "mtlr 0\n\t" "blr")
static void push(calc_node_t *op)
Definition: rpn_ieee.c:113
#define CR0_EM
Definition: asm.h:247
jmp_buf jmp
Definition: mach.c:36

Referenced by KiSystemStartup().

◆ 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 }
PKSTART_ROUTINE StartRoutine
Definition: thrdini.c:25
PKSYSTEM_ROUTINE SystemRoutine
Definition: thrdini.c:24
KSTART_FRAME StartFrame
Definition: thrdini.c:19
VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1469
KTRAP_FRAME TrapFrame
Definition: thrdini.c:21
VOID FASTCALL KfLowerIrql(IN KIRQL NewIrql)
Definition: pic.c:232
PVOID StartContext
Definition: thrdini.c:26
#define KiServiceExit2
Definition: ke.h:5
#define KeGetCurrentThread
Definition: hal.h:44
BOOLEAN UserThread
Definition: thrdini.c:27
#define APC_LEVEL
Definition: env_spec_w32.h:695

Referenced by GspGetRegisters().

◆ KiTrap02()

Definition at line 461 of file traphdlr.c.

462 {
463  PKTSS Tss, NmiTss;
466  PKGDTENTRY TssGdt;
467  KTRAP_FRAME TrapFrame;
468  KIRQL OldIrql;
469 
470  //
471  // In some sort of strange recursion case, we might end up here with the IF
472  // flag incorrectly on the interrupt frame -- during a normal NMI this would
473  // normally already be set.
474  //
475  // For sanity's sake, make sure interrupts are disabled for sure.
476  // NMIs will already be since the CPU does it for us.
477  //
478  _disable();
479 
480  //
481  // Get the current TSS, thread, and process
482  //
483  Tss = PCR->TSS;
484  Thread = ((PKIPCR)PCR)->PrcbData.CurrentThread;
485  Process = Thread->ApcState.Process;
486 
487  //
488  // Save data usually not in the TSS
489  //
490  Tss->CR3 = Process->DirectoryTableBase[0];
491  Tss->IoMapBase = Process->IopmOffset;
492  Tss->LDT = Process->LdtDescriptor.LimitLow ? KGDT_LDT : 0;
493 
494  //
495  // Now get the base address of the NMI TSS
496  //
497  TssGdt = &((PKIPCR)KeGetPcr())->GDT[KGDT_NMI_TSS / sizeof(KGDTENTRY)];
498  NmiTss = (PKTSS)(ULONG_PTR)(TssGdt->BaseLow |
499  TssGdt->HighWord.Bytes.BaseMid << 16 |
500  TssGdt->HighWord.Bytes.BaseHi << 24);
501 
502  //
503  // Switch to it and activate it, masking off the nested flag
504  //
505  // Note that in reality, we are already on the NMI tss -- we just need to
506  // update the PCR to reflect this
507  //
508  PCR->TSS = NmiTss;
510  TssGdt->HighWord.Bits.Dpl = 0;
511  TssGdt->HighWord.Bits.Pres = 1;
512  TssGdt->HighWord.Bits.Type = I386_TSS;
513 
514  //
515  // Now build the trap frame based on the original TSS
516  //
517  // The CPU does a hardware "Context switch" / task switch of sorts and so it
518  // takes care of saving our context in the normal TSS.
519  //
520  // We just have to go get the values...
521  //
522  RtlZeroMemory(&TrapFrame, sizeof(KTRAP_FRAME));
523  TrapFrame.HardwareSegSs = Tss->Ss0;
524  TrapFrame.HardwareEsp = Tss->Esp0;
525  TrapFrame.EFlags = Tss->EFlags;
526  TrapFrame.SegCs = Tss->Cs;
527  TrapFrame.Eip = Tss->Eip;
528  TrapFrame.Ebp = Tss->Ebp;
529  TrapFrame.Ebx = Tss->Ebx;
530  TrapFrame.Esi = Tss->Esi;
531  TrapFrame.Edi = Tss->Edi;
532  TrapFrame.SegFs = Tss->Fs;
533  TrapFrame.ExceptionList = PCR->NtTib.ExceptionList;
534  TrapFrame.PreviousPreviousMode = (ULONG)-1;
535  TrapFrame.Eax = Tss->Eax;
536  TrapFrame.Ecx = Tss->Ecx;
537  TrapFrame.Edx = Tss->Edx;
538  TrapFrame.SegDs = Tss->Ds;
539  TrapFrame.SegEs = Tss->Es;
540  TrapFrame.SegGs = Tss->Gs;
541  TrapFrame.DbgEip = Tss->Eip;
542  TrapFrame.DbgEbp = Tss->Ebp;
543 
544  //
545  // Store the trap frame in the KPRCB
546  //
547  KiSaveProcessorState(&TrapFrame, NULL);
548 
549  //
550  // Call any registered NMI handlers and see if they handled it or not
551  //
552  if (!KiHandleNmi())
553  {
554  //
555  // They did not, so call the platform HAL routine to bugcheck the system
556  //
557  // Make sure the HAL believes it's running at HIGH IRQL... we can't use
558  // the normal APIs here as playing with the IRQL could change the system
559  // state
560  //
561  OldIrql = PCR->Irql;
562  PCR->Irql = HIGH_LEVEL;
564  PCR->Irql = OldIrql;
565  }
566 
567  //
568  // Although the CPU disabled NMIs, we just did a BIOS Call, which could've
569  // totally changed things.
570  //
571  // We have to make sure we're still in our original NMI -- a nested NMI
572  // will point back to the NMI TSS, and in that case we're hosed.
573  //
574  if (PCR->TSS->Backlink != KGDT_NMI_TSS)
575  {
576  //
577  // Restore original TSS
578  //
579  PCR->TSS = Tss;
580 
581  //
582  // Set it back to busy
583  //
584  TssGdt->HighWord.Bits.Dpl = 0;
585  TssGdt->HighWord.Bits.Pres = 1;
586  TssGdt->HighWord.Bits.Type = I386_ACTIVE_TSS;
587 
588  //
589  // Restore nested flag
590  //
592 
593  //
594  // Handled, return from interrupt
595  //
596  KiIret();
597  }
598 
599  //
600  // Unhandled: crash the system
601  //
603 }
#define I386_ACTIVE_TSS
Definition: ketypes.h:61
USHORT Fs
Definition: ketypes.h:814
USHORT BaseLow
Definition: ketypes.h:334
ULONG CR3
Definition: ketypes.h:795
USHORT SegFs
Definition: ketypes.h:366
struct _KIPCR * PKIPCR
USHORT Cs
Definition: ketypes.h:808
USHORT Es
Definition: ketypes.h:806
ULONG HardwareSegSs
Definition: ketypes.h:269
ULONG Esi
Definition: ketypes.h:261
union _KGDTENTRY::@2323 HighWord
struct _KGDTENTRY::@2323::@2324 Bytes
VOID NTAPI HalHandleNMI(IN PVOID NmiInfo)
Definition: misc.c:53
#define KeGetPcr()
Definition: ke.h:25
USHORT LDT
Definition: ketypes.h:818
ULONG Edi
Definition: ketypes.h:260
uint32_t ULONG_PTR
Definition: typedefs.h:63
UCHAR KIRQL
Definition: env_spec_w32.h:591
USHORT Ds
Definition: ketypes.h:812
#define KGDT_NMI_TSS
Definition: ketypes.h:83
#define KGDT_LDT
Definition: ketypes.h:81
ULONG Edx
Definition: ketypes.h:800
__INTRIN_INLINE uintptr_t __readeflags(void)
Definition: intrin_x86.h:1555
ULONG Eax
Definition: ketypes.h:256
USHORT SegGs
Definition: ketypes.h:367
#define EFLAGS_NESTED_TASK
Definition: ketypes.h:128
#define PCR
Definition: ke.h:8
USHORT SegEs
Definition: ketypes.h:365
smooth NULL
Definition: ftsmooth.c:416
ULONG DbgEbp
Definition: ketypes.h:239
USHORT SegCs
Definition: ketypes.h:380
Definition: ketypes.h:787
Definition: utils.h:160
ULONG Ebx
Definition: ketypes.h:801
USHORT Ss0
Definition: ketypes.h:792
ULONG Eip
Definition: ketypes.h:796
ULONG Ecx
Definition: ketypes.h:799
ULONG HardwareEsp
Definition: ketypes.h:268
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
DECLSPEC_NORETURN VOID FASTCALL KiSystemFatalException(IN ULONG ExceptionCode, IN PKTRAP_FRAME TrapFrame)
Definition: except.c:402
struct _EXCEPTION_REGISTRATION_RECORD FAR * ExceptionList
Definition: ketypes.h:258
USHORT IoMapBase
Definition: ketypes.h:821
ULONG EFlags
Definition: ketypes.h:797
#define PKTSS
Definition: ketypes.h:921
FORCEINLINE DECLSPEC_NORETURN VOID KiIret(VOID)
Definition: ke.h:853
#define EXCEPTION_NMI
Definition: asm.h:615
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
struct _KGDTENTRY::@2323::@2325 Bits
__INTRIN_INLINE void __writeeflags(uintptr_t Value)
Definition: intrin_x86.h:1550
USHORT SegDs
Definition: ketypes.h:364
ULONG Ecx
Definition: ketypes.h:255
ULONG Eip
Definition: ketypes.h:265
ULONG Eax
Definition: ketypes.h:798
ULONG PreviousPreviousMode
Definition: ketypes.h:257
#define HIGH_LEVEL
Definition: env_spec_w32.h:703
ULONG DbgEip
Definition: ketypes.h:240
ULONG Ebx
Definition: ketypes.h:262
ULONG Esp0
Definition: ketypes.h:791
ULONG Edi
Definition: ketypes.h:805
ULONG Ebp
Definition: ketypes.h:803
BOOLEAN NTAPI KiHandleNmi(VOID)
Definition: bug.c:1206
VOID NTAPI KiSaveProcessorState(IN PKTRAP_FRAME TrapFrame, IN PKEXCEPTION_FRAME ExceptionFrame)
Definition: cpu.c:1143
#define I386_TSS
Definition: ketypes.h:60
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
ULONG Esi
Definition: ketypes.h:804
void __cdecl _disable(void)
Definition: intrin_arm.h:365
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
USHORT Gs
Definition: ketypes.h:816
ULONG EFlags
Definition: ketypes.h:384
ULONG Edx
Definition: ketypes.h:254
ULONG Ebp
Definition: ketypes.h:263

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 }
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
BOOLEAN FASTCALL KiVdmHandleOpcode(IN PKTRAP_FRAME TrapFrame, IN ULONG Flags)
Definition: v86vdm.c:379

◆ 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 TRUE
Definition: types.h:120
Definition: vdm.h:134
ULONG BopNumber
Definition: vdm.h:96
VDMEVENTCLASS Event
Definition: vdm.h:90
unsigned char * PUCHAR
Definition: retypes.h:3
ULONG VdmBopCount
Definition: vdmexec.c:17
#define EFLAGS_V86_MASK
Definition: ketypes.h:129
VDMEVENTINFO EventInfo
Definition: vdm.h:141
Definition: vdm.h:60
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420
ULONG InstructionSize
Definition: vdm.h:91
VOID NTAPI VdmEndExecution(IN PKTRAP_FRAME TrapFrame, IN PVDM_TIB VdmTib)
Definition: vdmexec.c:253
unsigned short * PUSHORT
Definition: retypes.h:2

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 
387  _SEH2_TRY
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 }
Definition: vdm.h:134
VDMEVENTCLASS Event
Definition: vdm.h:90
LONG NTSTATUS
Definition: precomp.h:26
#define PAGED_CODE()
Definition: video.h:57
#define EFLAGS_V86_MASK
Definition: ketypes.h:129
_SEH2_TRY
Definition: create.c:4250
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
VDMEVENTINFO EventInfo
Definition: vdm.h:141
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
_SEH2_END
Definition: create.c:4424
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420
NTSTATUS NTAPI VdmpGetVdmTib(OUT PVDM_TIB *VdmTib)
Definition: vdmexec.c:23
#define DPRINT1
Definition: precomp.h:8
ULONG InstructionSize
Definition: vdm.h:91
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
VOID NTAPI VdmEndExecution(IN PKTRAP_FRAME TrapFrame, IN PVDM_TIB VdmTib)
Definition: vdmexec.c:253

Referenced by KiTrap0EHandler().

Variable Documentation

◆ KeI386CpuStep

ULONG KeI386CpuStep

Definition at line 29 of file cpu.c.

◆ KeI386CpuType

ULONG KeI386CpuType

Definition at line 28 of file cpu.c.

Referenced by KeInvalidateAllCaches().

◆ KeI386EFlagsAndMaskV86

ULONG KeI386EFlagsAndMaskV86

Definition at line 21 of file v86vdm.c.

Referenced by VdmSwapContext().

◆ KeI386EFlagsOrMaskV86

ULONG KeI386EFlagsOrMaskV86

Definition at line 22 of file v86vdm.c.

Referenced by VdmSwapContext().

◆ KeI386FxsrPresent

ULONG KeI386FxsrPresent

Definition at line 31 of file cpu.c.

Referenced by KiFlushNPXState().

◆ KeI386NpxPresent

ULONG KeI386NpxPresent

Definition at line 31 of file cpu.c.

Referenced by KeSaveFloatingPointState().

◆ KeI386VirtualIntExtensions

◆ KeI386XMMIPresent

ULONG KeI386XMMIPresent

Definition at line 30 of file cpu.c.

◆ Ki386IopmSaveArea

PVOID Ki386IopmSaveArea

Definition at line 23 of file v86vdm.c.

Referenced by Ke386CallBios(), and KiInitializeKernel().

◆ KiDebugRegisterContextOffsets

UCHAR KiDebugRegisterContextOffsets[9]

◆ KiDebugRegisterTrapOffsets

UCHAR KiDebugRegisterTrapOffsets[9]

◆ KiFastSystemCallDisable

ULONG KiFastSystemCallDisable

Definition at line 26 of file cpu.c.

Referenced by KeRosDumpTriageForBugZillaReport(), and KiRestoreFastSyscallReturnState().

◆ KiI386PentiumLockErrataPresent

BOOLEAN KiI386PentiumLockErrataPresent

◆ KiIdt

Definition at line 50 of file except.c.

Referenced by KeInitExceptions().

◆ KiIdtDescriptor

KDESCRIPTOR KiIdtDescriptor

Definition at line 51 of file except.c.

Referenced by KeInitExceptions(), and KiSystemStartup().

◆ KiMXCsrMask

ULONG KiMXCsrMask

◆ KiSystemCallExit

CHAR KiSystemCallExit[]

◆ KiSystemCallExit2

CHAR KiSystemCallExit2[]

◆ KiSystemCallExitBranch

CHAR KiSystemCallExitBranch[]