ReactOS 0.4.17-dev-1190-g4c812f4
cpu.c File Reference
#include <ntoskrnl.h>
#include <xmmintrin.h>
#include <debug.h>
Include dependency graph for cpu.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define FXSAVE_ALIGN   15
 
#define CX86_CCR1   0xc1
 

Functions

static __inline UCHAR getCx86 (UCHAR reg)
 
static __inline void setCx86 (UCHAR reg, UCHAR data)
 
static ULONG KiGetCpuVendor (VOID)
 
VOID NTAPI KiSetProcessorType (VOID)
 
ULONG64 NTAPI KiGetFeatureBits (VOID)
 Evaluates the KeFeatureFlag bits for the current CPU.
 
VOID NTAPI KiGetCacheInformation (VOID)
 
VOID NTAPI KiSetCR0Bits (VOID)
 
VOID NTAPI KiInitializeTSS2 (IN PKTSS Tss, IN PKGDTENTRY TssEntry OPTIONAL)
 
VOID NTAPI KiInitializeTSS (IN PKTSS Tss)
 
VOID FASTCALL Ki386InitializeTss (IN PKTSS Tss, IN PKIDTENTRY Idt, IN PKGDTENTRY Gdt)
 
VOID NTAPI KeFlushCurrentTb (VOID)
 
VOID NTAPI KiRestoreProcessorControlState (PKPROCESSOR_STATE ProcessorState)
 
VOID NTAPI KiSaveProcessorControlState (OUT PKPROCESSOR_STATE ProcessorState)
 
VOID NTAPI KiInitializeMachineType (VOID)
 
ULONG_PTR NTAPI KiLoadFastSyscallMachineSpecificRegisters (IN ULONG_PTR Context)
 
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)
 
VOID NTAPI KiI386PentiumLockErrataFixup (VOID)
 
BOOLEAN NTAPI KeInvalidateAllCaches (VOID)
 
VOID NTAPI KiSaveProcessorState (IN PKTRAP_FRAME TrapFrame, IN PKEXCEPTION_FRAME ExceptionFrame)
 
BOOLEAN NTAPI KiIsNpxErrataPresent (VOID)
 
VOID NTAPI KiFlushNPXState (IN PFLOATING_SAVE_AREA SaveArea)
 
VOID NTAPI KiCoprocessorError (VOID)
 
NTSTATUS NTAPI KeSaveFloatingPointState (_Out_ PKFLOATING_SAVE Save)
 Saves the current floating point unit state context of the current calling thread.
 
NTSTATUS NTAPI KeRestoreFloatingPointState (_In_ PKFLOATING_SAVE Save)
 Restores the original FPU state context that has been saved by a API call of KeSaveFloatingPointState. Callers are expected to restore the floating point state by calling this function when they've finished doing FPU operations.
 
ULONG NTAPI KeGetRecommendedSharedDataAlignment (VOID)
 
VOID NTAPI KiFlushTargetEntireTb (IN PKIPI_CONTEXT PacketContext, IN PVOID Ignored1, IN PVOID Ignored2, IN PVOID Ignored3)
 
VOID NTAPI KeFlushEntireTb (IN BOOLEAN Invalid, IN BOOLEAN AllProcessors)
 
VOID NTAPI KeSetDmaIoCoherency (IN ULONG Coherency)
 
VOID __cdecl KeSaveStateForHibernate (IN PKPROCESSOR_STATE State)
 

Variables

UCHAR KiDoubleFaultTSS [KTSS_IO_MAPS]
 
UCHAR KiNMITSS [KTSS_IO_MAPS]
 
ULONG KeI386CpuType
 
ULONG KeI386CpuStep
 
ULONG KiFastSystemCallDisable = 0
 
ULONG KeI386NpxPresent = TRUE
 
ULONG KiMXCsrMask = 0
 
ULONG MxcsrFeatureMask = 0
 
ULONG KeI386XMMIPresent = 0
 
ULONG KeI386FxsrPresent = 0
 
ULONG KeI386MachineType
 
ULONG Ke386Pae = FALSE
 
ULONG Ke386NoExecute = FALSE
 
ULONG KeLargestCacheLine = 0x40
 
ULONG KeDcacheFlushCount = 0
 
ULONG KeIcacheFlushCount = 0
 
ULONG KiDmaIoCoherency = 0
 
ULONG KePrefetchNTAGranularity = 32
 
BOOLEAN KiI386PentiumLockErrataPresent
 
BOOLEAN KiSMTProcessorsPresent
 
UCHAR KiSystemCallExitAdjust
 
UCHAR KiSystemCallExitAdjusted
 
BOOLEAN KiFastCallCopyDoneOnce
 
volatile LONG KiTbFlushTimeStamp
 

Macro Definition Documentation

◆ CX86_CCR1

#define CX86_CCR1   0xc1

Definition at line 63 of file cpu.c.

◆ FXSAVE_ALIGN

#define FXSAVE_ALIGN   15

Definition at line 58 of file cpu.c.

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file cpu.c.

Function Documentation

◆ getCx86()

static __inline UCHAR getCx86 ( UCHAR  reg)
static

Definition at line 68 of file cpu.c.

69{
71 return READ_PORT_UCHAR((PUCHAR)(ULONG_PTR)0x23);
72}
static int reg
Definition: i386-dis.c:1290
#define READ_PORT_UCHAR(p)
Definition: pc98vid.h:22
#define WRITE_PORT_UCHAR(p, d)
Definition: pc98vid.h:21
uint32_t ULONG_PTR
Definition: typedefs.h:65
unsigned char * PUCHAR
Definition: typedefs.h:53

Referenced by KiGetFeatureBits().

◆ KeFlushCurrentTb()

VOID NTAPI KeFlushCurrentTb ( VOID  )

Definition at line 595 of file cpu.c.

596{
597
598#if !defined(_GLOBAL_PAGES_ARE_AWESOME_)
599
600 /* Flush the TLB by resetting CR3 */
602
603#else
604
605 /* Check if global pages are enabled */
607 {
608 ULONG Cr4;
609
610 /* Disable PGE (Note: may not have been enabled yet) */
611 Cr4 = __readcr4();
612 __writecr4(Cr4 & ~CR4_PGE);
613
614 /* Flush everything */
616
617 /* Re-enable PGE */
618 __writecr4(Cr4);
619 }
620 else
621 {
622 /* No global pages, resetting CR3 is enough */
624 }
625
626#endif
627
628}
ULONG64 KeFeatureBits
Definition: krnlinit.c:22
__INTRIN_INLINE unsigned long __readcr3(void)
Definition: intrin_x86.h:1850
__INTRIN_INLINE unsigned long __readcr4(void)
Definition: intrin_x86.h:1857
__INTRIN_INLINE void __writecr3(unsigned int Data)
Definition: intrin_x86.h:1826
__INTRIN_INLINE void __writecr4(unsigned int Data)
Definition: intrin_x86.h:1831
#define CR4_PGE
Definition: ketypes.h:161
#define KF_GLOBAL_PAGE
Definition: ketypes.h:35
uint32_t ULONG
Definition: typedefs.h:59

Referenced by KeThawExecution(), Ki386InitializePATTarget(), MiDeletePte(), MiFlushTbAndCapture(), MiFlushTlbIpiRoutine(), MiInitializePageTable(), MiInitMachineDependent(), MiProcessValidPteList(), MiRemoveMappedPtes(), MmChangeKernelResourceSectionProtection(), and MmFreeLoaderBlock().

◆ KeFlushEntireTb()

VOID NTAPI KeFlushEntireTb ( IN BOOLEAN  Invalid,
IN BOOLEAN  AllProcessors 
)

Definition at line 1286 of file cpu.c.

1288{
1289 KIRQL OldIrql;
1290#ifdef CONFIG_SMP
1291 KAFFINITY TargetAffinity;
1292 PKPRCB Prcb = KeGetCurrentPrcb();
1293#endif
1294
1295 /* Raise the IRQL for the TB Flush */
1297
1298#ifdef CONFIG_SMP
1299 /* FIXME: Use KiTbFlushTimeStamp to synchronize TB flush */
1300
1301 /* Get the current processor affinity, and exclude ourselves */
1302 TargetAffinity = KeActiveProcessors;
1303 TargetAffinity &= ~Prcb->SetMember;
1304
1305 /* Make sure this is MP */
1306 if (TargetAffinity)
1307 {
1308 /* Send an IPI TB flush to the other processors */
1309 KiIpiSendPacket(TargetAffinity,
1311 NULL,
1312 0,
1313 NULL);
1314 }
1315#endif
1316
1317 /* Flush the TB for the Current CPU, and update the flush stamp */
1319
1320#ifdef CONFIG_SMP
1321 /* If this is MP, wait for the other processors to finish */
1322 if (TargetAffinity)
1323 {
1324 /* Sanity check */
1325 ASSERT(Prcb == KeGetCurrentPrcb());
1326
1327 /* FIXME: TODO */
1328 ASSERTMSG("Not yet implemented\n", FALSE);
1329 }
1330#endif
1331
1332 /* Update the flush stamp and return to original IRQL */
1335}
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
ULONG_PTR KAFFINITY
Definition: compat.h:85
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
KIRQL NTAPI KeRaiseIrqlToSynchLevel(VOID)
Definition: pic.c:156
#define InterlockedExchangeAdd
Definition: interlocked.h:196
#define ASSERT(a)
Definition: mode.c:44
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1197
#define ASSERTMSG(msg, exp)
Definition: nt_native.h:431
KAFFINITY KeActiveProcessors
Definition: processor.c:16
VOID NTAPI KiIpiSendPacket(IN KAFFINITY TargetProcessors, IN PKIPI_WORKER WorkerFunction, IN PKIPI_BROADCAST_WORKER BroadcastFunction, IN ULONG_PTR Context, IN PULONG Count)
Definition: ipi.c:45
VOID NTAPI KeFlushCurrentTb(VOID)
Definition: cpu.c:361
volatile LONG KiTbFlushTimeStamp
Definition: cpu.c:34
VOID NTAPI KiFlushTargetEntireTb(IN PKIPI_CONTEXT PacketContext, IN PVOID Ignored1, IN PVOID Ignored2, IN PVOID Ignored3)
Definition: cpu.c:1269
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778

◆ KeGetRecommendedSharedDataAlignment()

ULONG NTAPI KeGetRecommendedSharedDataAlignment ( VOID  )

Definition at line 1261 of file cpu.c.

1262{
1263 /* Return the global variable */
1264 return KeLargestCacheLine;
1265}
ULONG KeLargestCacheLine
Definition: cpu.c:29

◆ KeInvalidateAllCaches()

BOOLEAN NTAPI KeInvalidateAllCaches ( VOID  )

Definition at line 842 of file cpu.c.

843{
844 /* Only supported on Pentium Pro and higher */
845 if (KeI386CpuType < 6) return FALSE;
846
847 /* Invalidate all caches */
848 __wbinvd();
849 return TRUE;
850}
#define TRUE
Definition: types.h:120
PPC_QUAL void __wbinvd(void)
Definition: intrin_ppc.h:759
ULONG KeI386CpuType
Definition: cpu.c:26

Referenced by Ki386InitializePATTarget(), MiMapLockedPagesInUserSpace(), and MmMapIoSpace().

◆ KeRestoreFloatingPointState()

NTSTATUS NTAPI KeRestoreFloatingPointState ( _In_ PKFLOATING_SAVE  Save)

Restores the original FPU state context that has been saved by a API call of KeSaveFloatingPointState. Callers are expected to restore the floating point state by calling this function when they've finished doing FPU operations.

Parameters
[in]SaveThe saved floating point context that is to be given to the function to restore the FPU state.
Returns
Returns STATUS_SUCCESS indicating the function has fully completed its operations.

Definition at line 1185 of file cpu.c.

1187{
1189
1190 /* Sanity checks */
1191 ASSERT(Save);
1194
1195 /* Cache the saved FS context */
1196 FsContext = *((PVOID *) Save);
1197
1198 /*
1199 * We have to restore the regular saved FPU
1200 * state. For this we must first do some
1201 * validation checks so that we are sure
1202 * ourselves the state context is saved
1203 * properly. Check if we are in the same
1204 * calling thread.
1205 */
1206 if (FsContext->CurrentThread != KeGetCurrentThread())
1207 {
1208 /*
1209 * This isn't the thread that saved the
1210 * FPU state context, crash the system!
1211 */
1212 KeBugCheckEx(INVALID_FLOATING_POINT_STATE,
1213 0x2,
1214 (ULONG_PTR)FsContext->CurrentThread,
1216 0);
1217 }
1218
1219 /* Are we under the same NPX interrupt level? */
1220 if (FsContext->CurrentThread->Header.NpxIrql != KeGetCurrentIrql())
1221 {
1222 /* The interrupt level has changed, crash the system! */
1223 KeBugCheckEx(INVALID_FLOATING_POINT_STATE,
1224 0x1,
1225 (ULONG_PTR)FsContext->CurrentThread->Header.NpxIrql,
1227 0);
1228 }
1229
1230 /* Disable interrupts */
1231 _disable();
1232
1233 /*
1234 * The saved FPU state context is valid,
1235 * it's time to restore the state. First,
1236 * clear FPU exceptions now.
1237 */
1238 Ke386ClearFpExceptions();
1239
1240 /* Restore the state */
1241 Ke386RestoreFpuState(FsContext->PfxSaveArea);
1242
1243 /* Give the saved NPX IRQL back to the NPX thread */
1244 FsContext->CurrentThread->Header.NpxIrql = FsContext->OldNpxIrql;
1245
1246 /* Enable interrupts back */
1247 _enable();
1248
1249 /* We're done, free the allocated area and context */
1252
1253 return STATUS_SUCCESS;
1254}
DECLSPEC_NORETURN VOID NTAPI KeBugCheckEx(IN ULONG BugCheckCode, IN ULONG_PTR BugCheckParameter1, IN ULONG_PTR BugCheckParameter2, IN ULONG_PTR BugCheckParameter3, IN ULONG_PTR BugCheckParameter4)
Definition: debug.c:485
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
_Inout_ PLIST_ENTRY _In_ PVOID FsContext
Definition: fltkernel.h:2239
#define KeGetCurrentThread
Definition: hal.h:55
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
ULONG KeI386NpxPresent
Definition: cpu.c:29
void __cdecl _disable(void)
Definition: intrin_arm.h:365
void __cdecl _enable(void)
Definition: intrin_arm.h:373
#define STATUS_SUCCESS
Definition: shellext.h:65
#define TAG_FLOATING_POINT_CONTEXT
Definition: tag.h:44
#define TAG_FLOATING_POINT_FX
Definition: tag.h:43
static int Save(const char **args)
Definition: vfdcmd.c:1851

◆ KeSaveFloatingPointState()

NTSTATUS NTAPI KeSaveFloatingPointState ( _Out_ PKFLOATING_SAVE  Save)

Saves the current floating point unit state context of the current calling thread.

Parameters
[out]SaveThe saved floating point context given to the caller at the end of function's operations. The structure whose data contents are opaque to the calling thread.
Returns
Returns STATUS_SUCCESS if the function has successfully completed its operations. STATUS_INSUFFICIENT_RESOURCES is returned if the function couldn't allocate memory for FPU state information.
Remarks
The function performs a FPU state save in two ways. A normal FPU save (FNSAVE) is performed if the system doesn't have SSE/SSE2, otherwise the function performs a save of FPU, MMX and SSE states save (FXSAVE).

Definition at line 1059 of file cpu.c.

1061{
1063 PFX_SAVE_AREA FxSaveAreaFrame;
1064 PKPRCB CurrentPrcb;
1065
1066 /* Sanity checks */
1067 ASSERT(Save);
1070
1071 /* Initialize the floating point context */
1073 sizeof(FLOATING_SAVE_CONTEXT),
1075 if (!FsContext)
1076 {
1077 /* Bail out if we failed */
1079 }
1080
1081 /*
1082 * Allocate some memory pool for the buffer. The size
1083 * of this allocated buffer is the FX area plus the
1084 * alignment requirement needed for FXSAVE as a 16-byte
1085 * aligned pointer is compulsory in order to save the
1086 * FPU state.
1087 */
1089 sizeof(FX_SAVE_AREA) + FXSAVE_ALIGN,
1091 if (!FsContext->Buffer)
1092 {
1093 /* Bail out if we failed */
1096 }
1097
1098 /*
1099 * Now cache the allocated buffer into the save area
1100 * and align the said area to a 16-byte boundary. Why
1101 * do we have to do this is because of ExAllocate function.
1102 * We gave the necessary alignment requirement in the pool
1103 * allocation size although the function will always return
1104 * a 8-byte aligned pointer. Aligning the given pointer directly
1105 * can cause issues when freeing it from memory afterwards. With
1106 * that said, we have to cache the buffer to the area so that we
1107 * do not touch or mess the allocated buffer any further.
1108 */
1109 FsContext->PfxSaveArea = ALIGN_UP_POINTER_BY(FsContext->Buffer, 16);
1110
1111 /* Disable interrupts and get the current processor control region */
1112 _disable();
1113 CurrentPrcb = KeGetCurrentPrcb();
1114
1115 /* Store the current thread to context */
1116 FsContext->CurrentThread = KeGetCurrentThread();
1117
1118 /*
1119 * Save the previous NPX thread state registers (aka Numeric
1120 * Processor eXtension) into the current context so that
1121 * we are informing the scheduler the current FPU state
1122 * belongs to this thread.
1123 */
1124 if (FsContext->CurrentThread != CurrentPrcb->NpxThread)
1125 {
1126 if ((CurrentPrcb->NpxThread != NULL) &&
1127 (CurrentPrcb->NpxThread->NpxState == NPX_STATE_LOADED))
1128 {
1129 /* Get the FX frame */
1130 FxSaveAreaFrame = KiGetThreadNpxArea(CurrentPrcb->NpxThread);
1131
1132 /* Save the FPU state */
1133 Ke386SaveFpuState(FxSaveAreaFrame);
1134
1135 /* NPX thread has lost its state */
1136 CurrentPrcb->NpxThread->NpxState = NPX_STATE_NOT_LOADED;
1137 FxSaveAreaFrame->NpxSavedCpu = 0;
1138 }
1139
1140 /* The new NPX thread is the current thread */
1141 CurrentPrcb->NpxThread = FsContext->CurrentThread;
1142 }
1143
1144 /* Perform the save */
1145 Ke386SaveFpuState(FsContext->PfxSaveArea);
1146
1147 /* Store the NPX IRQL */
1148 FsContext->OldNpxIrql = FsContext->CurrentThread->Header.NpxIrql;
1149
1150 /* Set the current IRQL to NPX */
1151 FsContext->CurrentThread->Header.NpxIrql = KeGetCurrentIrql();
1152
1153 /* Initialize the FPU */
1154 Ke386FnInit();
1155
1156 /* Enable interrupts back */
1157 _enable();
1158
1159 /* Give the saved FPU context to the caller */
1160 *((PVOID *) Save) = FsContext;
1161 return STATUS_SUCCESS;
1162}
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define NonPagedPool
Definition: env_spec_w32.h:307
#define NPX_STATE_NOT_LOADED
Definition: asm.h:265
#define NPX_STATE_LOADED
Definition: asm.h:266
FORCEINLINE PFX_SAVE_AREA KiGetThreadNpxArea(IN PKTHREAD Thread)
Definition: ke.h:769
#define FXSAVE_ALIGN
Definition: cpu.c:58
ULONG NpxSavedCpu
Definition: ketypes.h:515
struct _KTHREAD * NpxThread
Definition: ketypes.h:578
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define ALIGN_UP_POINTER_BY(ptr, align)
Definition: umtypes.h:85

◆ KeSaveStateForHibernate()

VOID __cdecl KeSaveStateForHibernate ( IN PKPROCESSOR_STATE  State)

Definition at line 1353 of file cpu.c.

1354{
1355 /* Capture the context */
1356 RtlCaptureContext(&State->ContextFrame);
1357
1358 /* Capture the control state */
1360}
NTSYSAPI VOID NTAPI RtlCaptureContext(_Out_ PCONTEXT ContextRecord)
VOID NTAPI KiSaveProcessorControlState(OUT PKPROCESSOR_STATE ProcessorState)
Definition: cpu.c:411

◆ KeSetDmaIoCoherency()

VOID NTAPI KeSetDmaIoCoherency ( IN ULONG  Coherency)

Definition at line 1342 of file cpu.c.

1343{
1344 /* Save the coherency globally */
1345 KiDmaIoCoherency = Coherency;
1346}
ULONG KiDmaIoCoherency
Definition: cpu.c:30

◆ Ki386EnableDE()

ULONG_PTR NTAPI Ki386EnableDE ( IN ULONG_PTR  Context)

Definition at line 761 of file cpu.c.

762{
763 /* Enable DE */
765 return 0;
766}
#define CR4_DE
Definition: ketypes.h:157

Referenced by KiInitMachineDependent().

◆ Ki386EnableFxsr()

ULONG_PTR NTAPI Ki386EnableFxsr ( IN ULONG_PTR  Context)

Definition at line 771 of file cpu.c.

772{
773 /* Enable FXSR */
775 return 0;
776}
#define CR4_FXSR
Definition: ketypes.h:162

Referenced by KiInitMachineDependent().

◆ Ki386EnableXMMIExceptions()

ULONG_PTR NTAPI Ki386EnableXMMIExceptions ( IN ULONG_PTR  Context)

Definition at line 781 of file cpu.c.

782{
783 PKIDTENTRY IdtEntry;
784
785 /* Get the IDT Entry for Interrupt 0x13 */
786 IdtEntry = &((PKIPCR)KeGetPcr())->IDT[0x13];
787
788 /* Set it up */
789 IdtEntry->Selector = KGDT_R0_CODE;
790 IdtEntry->Offset = ((ULONG_PTR)KiTrap13 & 0xFFFF);
791 IdtEntry->ExtendedOffset = ((ULONG_PTR)KiTrap13 >> 16) & 0xFFFF;
792 ((PKIDT_ACCESS)&IdtEntry->Access)->Dpl = 0;
793 ((PKIDT_ACCESS)&IdtEntry->Access)->Present = 1;
794 ((PKIDT_ACCESS)&IdtEntry->Access)->SegmentType = I386_INTERRUPT_GATE;
795
796 /* Enable XMMI exceptions */
798 return 0;
799}
#define ULONG_PTR
Definition: config.h:101
#define CR4_XMMEXCPT
Definition: ketypes.h:163
struct _KIPCR * PKIPCR
#define I386_INTERRUPT_GATE
Definition: ketypes.h:118
struct _KIDT_ACCESS * PKIDT_ACCESS
#define KeGetPcr()
Definition: ketypes.h:81
#define KGDT_R0_CODE
Definition: ketypes.h:123
VOID __cdecl KiTrap13(VOID)
USHORT Offset
Definition: ketypes.h:451
USHORT Selector
Definition: ketypes.h:452
USHORT Access
Definition: ketypes.h:453
USHORT ExtendedOffset
Definition: ketypes.h:454

Referenced by KiInitMachineDependent().

◆ Ki386InitializeTss()

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

Definition at line 515 of file cpu.c.

518{
519 PKGDTENTRY TssEntry, TaskGateEntry;
520
521 /* Initialize the boot TSS. */
522 TssEntry = &Gdt[KGDT_TSS / sizeof(KGDTENTRY)];
523 TssEntry->HighWord.Bits.Type = I386_TSS;
524 TssEntry->HighWord.Bits.Pres = 1;
525 TssEntry->HighWord.Bits.Dpl = 0;
526 KiInitializeTSS2(Tss, TssEntry);
527 KiInitializeTSS(Tss);
528
529 /* Load the task register */
530 Ke386SetTr(KGDT_TSS);
531
532 /* Setup the Task Gate for Double Fault Traps */
533 TaskGateEntry = (PKGDTENTRY)&Idt[8];
534 TaskGateEntry->HighWord.Bits.Type = I386_TASK_GATE;
535 TaskGateEntry->HighWord.Bits.Pres = 1;
536 TaskGateEntry->HighWord.Bits.Dpl = 0;
537 ((PKIDTENTRY)TaskGateEntry)->Selector = KGDT_DF_TSS;
538
539 /* Initialize the TSS used for handling double faults. */
540 Tss = (PKTSS)KiDoubleFaultTSS;
541 KiInitializeTSS(Tss);
542 Tss->CR3 = __readcr3();
543 Tss->Esp0 = KiDoubleFaultStack;
544 Tss->Esp = KiDoubleFaultStack;
545 Tss->Eip = PtrToUlong(KiTrap08);
546 Tss->Cs = KGDT_R0_CODE;
547 Tss->Fs = KGDT_R0_PCR;
548 Tss->Ss = Ke386GetSs();
549 Tss->Es = KGDT_R3_DATA | RPL_MASK;
550 Tss->Ds = KGDT_R3_DATA | RPL_MASK;
551
552 /* Setup the Double Trap TSS entry in the GDT */
553 TssEntry = &Gdt[KGDT_DF_TSS / sizeof(KGDTENTRY)];
554 TssEntry->HighWord.Bits.Type = I386_TSS;
555 TssEntry->HighWord.Bits.Pres = 1;
556 TssEntry->HighWord.Bits.Dpl = 0;
557 TssEntry->BaseLow = (USHORT)((ULONG_PTR)Tss & 0xFFFF);
558 TssEntry->HighWord.Bytes.BaseMid = (UCHAR)((ULONG_PTR)Tss >> 16);
559 TssEntry->HighWord.Bytes.BaseHi = (UCHAR)((ULONG_PTR)Tss >> 24);
560 TssEntry->LimitLow = KTSS_IO_MAPS;
561
562 /* Now setup the NMI Task Gate */
563 TaskGateEntry = (PKGDTENTRY)&Idt[2];
564 TaskGateEntry->HighWord.Bits.Type = I386_TASK_GATE;
565 TaskGateEntry->HighWord.Bits.Pres = 1;
566 TaskGateEntry->HighWord.Bits.Dpl = 0;
567 ((PKIDTENTRY)TaskGateEntry)->Selector = KGDT_NMI_TSS;
568
569 /* Initialize the actual TSS */
570 Tss = (PKTSS)KiNMITSS;
571 KiInitializeTSS(Tss);
572 Tss->CR3 = __readcr3();
573 Tss->Esp0 = KiDoubleFaultStack;
574 Tss->Esp = KiDoubleFaultStack;
575 Tss->Eip = PtrToUlong(KiTrap02);
576 Tss->Cs = KGDT_R0_CODE;
577 Tss->Fs = KGDT_R0_PCR;
578 Tss->Ss = Ke386GetSs();
579 Tss->Es = KGDT_R3_DATA | RPL_MASK;
580 Tss->Ds = KGDT_R3_DATA | RPL_MASK;
581
582 /* And its associated TSS Entry */
583 TssEntry = &Gdt[KGDT_NMI_TSS / sizeof(KGDTENTRY)];
584 TssEntry->HighWord.Bits.Type = I386_TSS;
585 TssEntry->HighWord.Bits.Pres = 1;
586 TssEntry->HighWord.Bits.Dpl = 0;
587 TssEntry->BaseLow = (USHORT)((ULONG_PTR)Tss & 0xFFFF);
588 TssEntry->HighWord.Bytes.BaseMid = (UCHAR)((ULONG_PTR)Tss >> 16);
589 TssEntry->HighWord.Bytes.BaseHi = (UCHAR)((ULONG_PTR)Tss >> 24);
590 TssEntry->LimitLow = KTSS_IO_MAPS;
591}
#define KGDT_R3_DATA
#define RPL_MASK
#define PtrToUlong(u)
Definition: config.h:107
#define PKIDTENTRY
Definition: ketypes.h:585
#define I386_TASK_GATE
Definition: ketypes.h:114
#define I386_TSS
Definition: ketypes.h:115
#define PKTSS
Definition: ketypes.h:1034
#define PKGDTENTRY
Definition: ketypes.h:543
#define KGDTENTRY
Definition: ketypes.h:542
#define KTSS_IO_MAPS
Definition: asm.h:84
#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:499
VOID NTAPI KiInitializeTSS2(IN PKTSS Tss, IN PKGDTENTRY TssEntry OPTIONAL)
Definition: cpu.c:461
UCHAR KiNMITSS[KTSS_IO_MAPS]
Definition: cpu.c:23
unsigned short USHORT
Definition: pedump.c:61
struct _KGDTENTRY::@2942::@2944 Bits
USHORT BaseLow
Definition: ketypes.h:401
USHORT LimitLow
Definition: ketypes.h:400
struct _KGDTENTRY::@2942::@2943 Bytes
union _KGDTENTRY::@2942 HighWord
unsigned char UCHAR
Definition: typedefs.h:53

Referenced by KiSystemStartup().

◆ KiCoprocessorError()

VOID NTAPI KiCoprocessorError ( VOID  )

Definition at line 1017 of file cpu.c.

1018{
1019 PFX_SAVE_AREA NpxArea;
1020
1021 /* Get the FPU area */
1023
1024 /* Set CR0_TS */
1025 NpxArea->Cr0NpxState = CR0_TS;
1027}
__INTRIN_INLINE unsigned long __readcr0(void)
Definition: intrin_x86.h:1836
__INTRIN_INLINE void __writecr0(unsigned int Data)
Definition: intrin_x86.h:1821
#define CR0_TS
Definition: ketypes.h:142
ULONG Cr0NpxState
Definition: ketypes.h:516

◆ KiFlushNPXState()

VOID NTAPI KiFlushNPXState ( IN PFLOATING_SAVE_AREA  SaveArea)

Definition at line 926 of file cpu.c.

927{
928 ULONG EFlags, Cr0;
929 PKTHREAD Thread, NpxThread;
930 PFX_SAVE_AREA FxSaveArea;
931
932 /* Save volatiles and disable interrupts */
933 EFlags = __readeflags();
934 _disable();
935
936 /* Save the PCR and get the current thread */
938
939 /* Check if we're already loaded */
940 if (Thread->NpxState != NPX_STATE_LOADED)
941 {
942 /* If there's nothing to load, quit */
943 if (!SaveArea)
944 {
945 /* Restore interrupt state and return */
946 __writeeflags(EFlags);
947 return;
948 }
949
950 /* Need FXSR support for this */
952
953 /* Check for sane CR0 */
954 Cr0 = __readcr0();
955 if (Cr0 & (CR0_MP | CR0_TS | CR0_EM))
956 {
957 /* Mask out FPU flags */
958 __writecr0(Cr0 & ~(CR0_MP | CR0_TS | CR0_EM));
959 }
960
961 /* Get the NPX thread and check its FPU state */
962 NpxThread = KeGetCurrentPrcb()->NpxThread;
963 if ((NpxThread) && (NpxThread->NpxState == NPX_STATE_LOADED))
964 {
965 /* Get the FX frame and store the state there */
966 FxSaveArea = KiGetThreadNpxArea(NpxThread);
967 Ke386FxSave(FxSaveArea);
968
969 /* NPX thread has lost its state */
970 NpxThread->NpxState = NPX_STATE_NOT_LOADED;
971 }
972
973 /* Now load NPX state from the NPX area */
974 FxSaveArea = KiGetThreadNpxArea(Thread);
975 Ke386FxStore(FxSaveArea);
976 }
977 else
978 {
979 /* Check for sane CR0 */
980 Cr0 = __readcr0();
981 if (Cr0 & (CR0_MP | CR0_TS | CR0_EM))
982 {
983 /* Mask out FPU flags */
984 __writecr0(Cr0 & ~(CR0_MP | CR0_TS | CR0_EM));
985 }
986
987 /* Get FX frame */
988 FxSaveArea = KiGetThreadNpxArea(Thread);
989 Thread->NpxState = NPX_STATE_NOT_LOADED;
990
991 /* Save state if supported by CPU */
992 if (KeI386FxsrPresent) Ke386FxSave(FxSaveArea);
993 }
994
995 /* Now save the FN state wherever it was requested */
996 if (SaveArea) Ke386FnSave(SaveArea);
997
998 /* Clear NPX thread */
999 KeGetCurrentPrcb()->NpxThread = NULL;
1000
1001 /* Add the CR0 from the NPX frame */
1002 Cr0 |= NPX_STATE_NOT_LOADED;
1003 Cr0 |= FxSaveArea->Cr0NpxState;
1004 __writecr0(Cr0);
1005
1006 /* Restore interrupt state */
1007 __writeeflags(EFlags);
1008}
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
__INTRIN_INLINE void __writeeflags(uintptr_t Value)
Definition: intrin_x86.h:1701
__INTRIN_INLINE uintptr_t __readeflags(void)
Definition: intrin_x86.h:1706
#define CR0_MP
Definition: ketypes.h:140
#define CR0_EM
Definition: ketypes.h:141
ULONG KeI386FxsrPresent
Definition: cpu.c:33
ULONG64 NpxState
Definition: ketypes.h:2215

◆ KiFlushTargetEntireTb()

VOID NTAPI KiFlushTargetEntireTb ( IN PKIPI_CONTEXT  PacketContext,
IN PVOID  Ignored1,
IN PVOID  Ignored2,
IN PVOID  Ignored3 
)

Definition at line 1269 of file cpu.c.

1273{
1274 /* Signal this packet as done */
1275 KiIpiSignalPacketDone(PacketContext);
1276
1277 /* Flush the TB for the Current CPU */
1279}
VOID FASTCALL KiIpiSignalPacketDone(IN PKIPI_CONTEXT PacketContext)
Definition: ipi.c:57

Referenced by KeFlushEntireTb().

◆ KiGetCacheInformation()

VOID NTAPI KiGetCacheInformation ( VOID  )

Definition at line 395 of file cpu.c.

396{
397 PKIPCR Pcr = (PKIPCR)KeGetPcr();
398 ULONG CacheCount;
399
400 /* Set default L2 size */
401 Pcr->SecondLevelCacheSize = 0;
402
403#if (NTDDI_VERSION >= NTDDI_VISTA)
404 /* Retrieve the cache descriptors */
405 PKPRCB Prcb = KeGetCurrentPrcb();
406 CacheCount = KiGetCpuCacheDescriptors(Prcb->Cache,
407 ARRAYSIZE(Prcb->Cache),
409 Prcb->CacheCount = CacheCount;
410#else
411 /* Retrieve the cache descriptors */
412 CACHE_DESCRIPTOR CacheDescriptors[5];
413 CacheCount = KiGetCpuCacheDescriptors(CacheDescriptors,
414 ARRAYSIZE(CacheDescriptors),
416#endif
417
418 /* Loop the descriptors to find the L2 cache size */
419 for (ULONG i = 0; i < CacheCount; i++)
420 {
421 KeLargestCacheLine = max(KeLargestCacheLine, CacheDescriptors[i].LineSize);
422 if ((CacheDescriptors[i].Level == 1) && (CacheDescriptors[i].Type != CacheInstruction))
423 {
424 KePrefetchNTAGranularity = CacheDescriptors[i].LineSize;
425 }
426 else if (CacheDescriptors[i].Level == 2)
427 {
428 Pcr->SecondLevelCacheSize = CacheDescriptors[i].Size;
429 Pcr->SecondLevelCacheAssociativity = CacheDescriptors[i].Associativity;
430 }
431 }
432
433 /* Set the cache line */
434 DPRINT1("Prefetch Cache: %lu bytes\tL2 Cache: %lu bytes\tL2 Cache Line: %lu bytes\tL2 Cache Associativity: %lu\n",
439}
Type
Definition: Type.h:7
#define DPRINT1
Definition: precomp.h:8
#define ARRAYSIZE(a)
Definition: cat.c:25
_In_ ULONG _In_ UCHAR Level
Definition: dispmprt.h:1329
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
ULONG NTAPI KiGetCpuCacheDescriptors(_Out_writes_(MaxCount) PCACHE_DESCRIPTOR CacheDescriptors, _In_ ULONG MaxCount, _In_ CPU_VENDORS Vendor)
Retrieves cache descriptors for the current CPU.
Definition: cacheinfo.c:484
ULONG KePrefetchNTAGranularity
Definition: cpu.c:41
static ULONG KiGetCpuVendor(VOID)
Definition: cpu.c:87
UCHAR Associativity
Definition: ketypes.h:52
USHORT LineSize
Definition: ketypes.h:53
ULONG SecondLevelCacheSize
Definition: ketypes.h:995
UCHAR SecondLevelCacheAssociativity
Definition: ketypes.h:986
ULONG CacheCount
Definition: ketypes.h:908
CACHE_DESCRIPTOR Cache[5]
Definition: ketypes.h:907
#define max(a, b)
Definition: svc.c:63
@ CacheInstruction
Definition: ketypes.h:45

Referenced by KiInitializeKernel(), and KiSystemStartupBootStack().

◆ KiGetCpuVendor()

static ULONG KiGetCpuVendor ( VOID  )
static

Definition at line 87 of file cpu.c.

88{
89 ASSERT(KeGetCurrentPrcb()->VendorString[0] != 0);
90 return KiIdentifyCpuVendor(KeGetCurrentPrcb()->VendorString);
91}
CPU_VENDORS NTAPI KiIdentifyCpuVendor(_In_reads_z_(CPU_VENDOR_STR_LEN) const CHAR VendorString[CPU_VENDOR_STR_LEN])
Identify the CPU vendor by the vendor string.
Definition: cpuinfo.c:55

Referenced by KiGetCacheInformation(), and KiGetFeatureBits().

◆ 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 116 of file cpu.c.

117{
118 PKPRCB Prcb = KeGetCurrentPrcb();
119 ULONG Vendor;
120 ULONG64 FeatureBits = KF_WORKING_PTE;
121 CPU_INFO CpuInfo, DummyCpuInfo;
122 UCHAR Ccr1;
123 BOOLEAN ExtendedCPUID = TRUE;
124 ULONG CpuFeatures = 0;
125
126 /* Get the Vendor ID */
127 Vendor = KiGetCpuVendor();
128
129 /* Make sure we got a valid vendor ID at least. */
130 if (!Vendor) return FeatureBits;
131
132 /* Get the CPUID Info. Features are in Reg[3]. */
133 KiCpuId(&CpuInfo, 1);
134
135 /* Set the initial APIC ID */
136 Prcb->InitialApicId = (UCHAR)(CpuInfo.Ebx >> 24);
137
138 switch (Vendor)
139 {
140 /* Intel CPUs */
141 case CPU_INTEL:
142
143 /* Check if it's a P6 */
144 if (Prcb->CpuType == 6)
145 {
146 /* Perform the special sequence to get the MicroCode Signature */
147 __writemsr(0x8B, 0);
148 KiCpuId(&DummyCpuInfo, 1);
149 Prcb->UpdateSignature.QuadPart = __readmsr(0x8B);
150 }
151 else if (Prcb->CpuType == 5)
152 {
153 /* On P5, enable workaround for the LOCK errata. */
155 }
156
157 /* Check for broken P6 with bad SMP PTE implementation */
158 if (((CpuInfo.Eax & 0x0FF0) == 0x0610 && (CpuInfo.Eax & 0x000F) <= 0x9) ||
159 ((CpuInfo.Eax & 0x0FF0) == 0x0630 && (CpuInfo.Eax & 0x000F) <= 0x4))
160 {
161 /* Remove support for correct PTE support. */
162 FeatureBits &= ~KF_WORKING_PTE;
163 }
164
165 /* Check if the CPU is too old to support SYSENTER */
166 if ((Prcb->CpuType < 6) ||
167 ((Prcb->CpuType == 6) && (Prcb->CpuStep < 0x0303)))
168 {
169 /* Disable it */
170 CpuInfo.Edx &= ~0x800;
171 }
172
173 break;
174
175 /* AMD CPUs */
176 case CPU_AMD:
177
178 /* Check if this is a K5 or K6. (family 5) */
179 if ((CpuInfo.Eax & 0x0F00) == 0x0500)
180 {
181 /* Get the Model Number */
182 switch (CpuInfo.Eax & 0x00F0)
183 {
184 /* Model 1: K5 - 5k86 (initial models) */
185 case 0x0010:
186
187 /* Check if this is Step 0 or 1. They don't support PGE */
188 if ((CpuInfo.Eax & 0x000F) > 0x03) break;
189
190 /* Model 0: K5 - SSA5 */
191 case 0x0000:
192
193 /* Model 0 doesn't support PGE at all. */
194 CpuInfo.Edx &= ~0x2000;
195 break;
196
197 /* Model 8: K6-2 */
198 case 0x0080:
199
200 /* K6-2, Step 8 and over have support for MTRR. */
201 if ((CpuInfo.Eax & 0x000F) >= 0x8) FeatureBits |= KF_AMDK6MTRR;
202 break;
203
204 /* Model 9: K6-III
205 Model D: K6-2+, K6-III+ */
206 case 0x0090:
207 case 0x00D0:
208
209 FeatureBits |= KF_AMDK6MTRR;
210 break;
211 }
212 }
213 else if((CpuInfo.Eax & 0x0F00) < 0x0500)
214 {
215 /* Families below 5 don't support PGE, PSE or CMOV at all */
216 CpuInfo.Edx &= ~(0x08 | 0x2000 | 0x8000);
217
218 /* They also don't support advanced CPUID functions. */
219 ExtendedCPUID = FALSE;
220 }
221
222 break;
223
224 /* Cyrix CPUs */
225 case CPU_CYRIX:
226
227 /* Workaround the "COMA" bug on 6x family of Cyrix CPUs */
228 if (Prcb->CpuType == 6 &&
229 Prcb->CpuStep <= 1)
230 {
231 /* Get CCR1 value */
232 Ccr1 = getCx86(CX86_CCR1);
233
234 /* Enable the NO_LOCK bit */
235 Ccr1 |= 0x10;
236
237 /* Set the new CCR1 value */
238 setCx86(CX86_CCR1, Ccr1);
239 }
240
241 break;
242
243 /* Transmeta CPUs */
244 case CPU_TRANSMETA:
245
246 /* Enable CMPXCHG8B if the family (>= 5), model and stepping (>= 4.2) support it */
247 if ((CpuInfo.Eax & 0x0FFF) >= 0x0542)
248 {
249 __writemsr(0x80860004, __readmsr(0x80860004) | 0x0100);
250 FeatureBits |= KF_CMPXCHG8B;
251 }
252
253 break;
254
255 /* Centaur, IDT, Rise and VIA CPUs */
256 case CPU_CENTAUR:
257 case CPU_RISE:
258
259 /* These CPUs don't report the presence of CMPXCHG8B through CPUID.
260 However, this feature exists and operates properly without any additional steps. */
261 FeatureBits |= KF_CMPXCHG8B;
262
263 break;
264 }
265
266 /* Get some features from ECX */
267 if (CpuInfo.Ecx & X86_FEATURE_SSE3) FeatureBits |= KF_SSE3;
268 if (CpuInfo.Ecx & X86_FEATURE_SSSE3) FeatureBits |= KF_SSSE3;
269 if (CpuInfo.Ecx & X86_FEATURE_SSE4_1) FeatureBits |= KF_SSE4_1;
270 if (CpuInfo.Ecx & X86_FEATURE_SSE4_2) FeatureBits |= KF_SSE4_2;
271 if (CpuInfo.Ecx & X86_FEATURE_XSAVE) FeatureBits |= KF_XSTATE;
272 if (CpuInfo.Ecx & X86_FEATURE_RDRAND) FeatureBits |= KF_RDRAND;
273
274 /* Set the current features */
275 CpuFeatures = CpuInfo.Edx;
276
277 /* Convert all CPUID Feature bits into our format */
278 if (CpuFeatures & X86_FEATURE_VME) FeatureBits |= KF_V86_VIS | KF_CR4;
279 if (CpuFeatures & X86_FEATURE_PSE) FeatureBits |= KF_LARGE_PAGE | KF_CR4;
280 if (CpuFeatures & X86_FEATURE_TSC) FeatureBits |= KF_RDTSC;
281 if (CpuFeatures & X86_FEATURE_CX8) FeatureBits |= KF_CMPXCHG8B;
282 if (CpuFeatures & X86_FEATURE_SYSCALL) FeatureBits |= KF_FAST_SYSCALL;
283 if (CpuFeatures & X86_FEATURE_MTRR) FeatureBits |= KF_MTRR;
284 if (CpuFeatures & X86_FEATURE_PGE) FeatureBits |= KF_GLOBAL_PAGE | KF_CR4;
285 if (CpuFeatures & X86_FEATURE_CMOV) FeatureBits |= KF_CMOV;
286 if (CpuFeatures & X86_FEATURE_PAT) FeatureBits |= KF_PAT;
287 if (CpuFeatures & X86_FEATURE_DS) FeatureBits |= KF_DTS;
288 if (CpuFeatures & X86_FEATURE_MMX) FeatureBits |= KF_MMX;
289 if (CpuFeatures & X86_FEATURE_FXSR) FeatureBits |= KF_FXSR;
290 if (CpuFeatures & X86_FEATURE_SSE) FeatureBits |= KF_XMMI;
291 if (CpuFeatures & X86_FEATURE_SSE2) FeatureBits |= KF_XMMI64;
292
293 /* Check if the CPU has hyper-threading */
294 if (CpuFeatures & X86_FEATURE_HT)
295 {
296 /* Set the number of logical CPUs */
297 Prcb->LogicalProcessorsPerPhysicalProcessor = (UCHAR)(CpuInfo.Ebx >> 16);
299 {
300 /* We're on dual-core */
302 }
303 }
304 else
305 {
306 /* We only have a single CPU */
308 }
309
310 /* Check if CPUID 0x80000000 is supported */
311 if (ExtendedCPUID)
312 {
313 /* Do the call */
314 KiCpuId(&CpuInfo, 0x80000000);
315 if ((CpuInfo.Eax & 0xffffff00) == 0x80000000)
316 {
317 /* Check if CPUID 0x80000001 is supported */
318 if (CpuInfo.Eax >= 0x80000001)
319 {
320 /* Check which extended features are available. */
321 KiCpuId(&CpuInfo, 0x80000001);
322
323 /* Check if NX-bit is supported */
324 if (CpuInfo.Edx & X86_FEATURE_NX) FeatureBits |= KF_NX_BIT;
325
326 /* Now handle each features for each CPU Vendor */
327 switch (Vendor)
328 {
329 case CPU_AMD:
330 case CPU_CENTAUR:
331 if (CpuInfo.Edx & 0x80000000) FeatureBits |= KF_3DNOW;
332 break;
333 }
334 }
335 }
336 }
337
338 /* Return the Feature Bits */
339 return FeatureBits;
340}
unsigned char BOOLEAN
Definition: actypes.h:127
PPC_QUAL void __writemsr(const unsigned long Value)
Definition: intrin_ppc.h:748
PPC_QUAL unsigned long long __readmsr()
Definition: intrin_ppc.h:741
unsigned __int64 ULONG64
Definition: imports.h:198
#define KF_SSE4_2
Definition: ketypes.h:74
#define KF_SSSE3
Definition: ketypes.h:72
#define KF_MTRR
Definition: ketypes.h:37
#define KF_XSTATE
Definition: ketypes.h:55
#define KF_DTS
Definition: ketypes.h:40
#define KF_CR4
Definition: ketypes.h:33
#define KF_XMMI64
Definition: ketypes.h:48
#define KF_CMOV
Definition: ketypes.h:34
#define KF_AMDK6MTRR
Definition: ketypes.h:46
#define KF_SSE4_1
Definition: ketypes.h:73
#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_INTEL
Definition: ketypes.h:100
@ CPU_AMD
Definition: ketypes.h:99
#define KF_LARGE_PAGE
Definition: ketypes.h:36
#define KF_XMMI
Definition: ketypes.h:44
#define KF_MMX
Definition: ketypes.h:39
#define KF_SSE3
Definition: ketypes.h:51
#define KF_PAT
Definition: ketypes.h:41
#define KF_WORKING_PTE
Definition: ketypes.h:39
#define KF_V86_VIS
Definition: ketypes.h:30
@ CPU_RISE
Definition: ketypes.h:96
@ CPU_CENTAUR
Definition: ketypes.h:95
@ CPU_CYRIX
Definition: ketypes.h:92
@ CPU_TRANSMETA
Definition: ketypes.h:93
#define X86_FEATURE_TSC
Definition: ke.h:34
#define X86_FEATURE_HT
Definition: ke.h:47
#define X86_FEATURE_SSE2
Definition: ke.h:46
#define X86_FEATURE_SSE
Definition: ke.h:45
#define X86_FEATURE_PGE
Definition: ke.h:39
#define X86_FEATURE_XSAVE
Definition: ke.h:60
#define X86_FEATURE_DS
Definition: ke.h:42
#define X86_FEATURE_VME
Definition: ke.h:31
#define X86_FEATURE_MMX
Definition: ke.h:43
#define X86_FEATURE_PSE
Definition: ke.h:33
#define X86_FEATURE_SSE3
Definition: ke.h:50
#define X86_FEATURE_PAT
Definition: ke.h:41
#define X86_FEATURE_CMOV
Definition: ke.h:40
#define X86_FEATURE_CX8
Definition: ke.h:36
#define X86_FEATURE_SYSCALL
Definition: ke.h:37
#define X86_FEATURE_NX
Definition: ke.h:63
#define X86_FEATURE_SSSE3
Definition: ke.h:53
#define X86_FEATURE_FXSR
Definition: ke.h:44
#define X86_FEATURE_MTRR
Definition: ke.h:38
#define X86_FEATURE_RDRAND
Definition: ke.h:31
#define X86_FEATURE_SSE4_2
Definition: ke.h:29
#define X86_FEATURE_SSE4_1
Definition: ke.h:28
BOOLEAN KiSMTProcessorsPresent
Definition: cpu.c:31
#define CX86_CCR1
Definition: cpu.c:63
static __inline void setCx86(UCHAR reg, UCHAR data)
Definition: cpu.c:76
static __inline UCHAR getCx86(UCHAR reg)
Definition: cpu.c:68
BOOLEAN KiI386PentiumLockErrataPresent
Definition: cpu.c:42
CHAR CpuType
Definition: ketypes.h:684
USHORT CpuStep
Definition: ketypes.h:689
UCHAR LogicalProcessorsPerPhysicalProcessor
Definition: ketypes.h:770
ULONG InitialApicId
Definition: ketypes.h:721
LARGE_INTEGER UpdateSignature
Definition: ketypes.h:904
ULONG Ebx
Definition: ketypes.h:402
ULONG Eax
Definition: ketypes.h:401
ULONG Ecx
Definition: ketypes.h:403
ULONG Edx
Definition: ketypes.h:404
LONGLONG QuadPart
Definition: typedefs.h:114

Referenced by KiInitializeCpu(), and KiVerifyCpuFeatures().

◆ KiI386PentiumLockErrataFixup()

VOID NTAPI KiI386PentiumLockErrataFixup ( VOID  )

Definition at line 804 of file cpu.c.

805{
806 KDESCRIPTOR IdtDescriptor = {0, 0, 0};
807 PKIDTENTRY NewIdt, NewIdt2;
808 PMMPTE PointerPte;
809
810 /* Allocate memory for a new IDT */
812
813 /* Put everything after the first 7 entries on a new page */
814 NewIdt2 = (PVOID)((ULONG_PTR)NewIdt + PAGE_SIZE - (7 * sizeof(KIDTENTRY)));
815
816 /* Disable interrupts */
817 _disable();
818
819 /* Get the current IDT and copy it */
820 __sidt(&IdtDescriptor.Limit);
821 RtlCopyMemory(NewIdt2,
822 (PVOID)IdtDescriptor.Base,
823 IdtDescriptor.Limit + 1);
824 IdtDescriptor.Base = (ULONG)NewIdt2;
825
826 /* Set the new IDT */
827 __lidt(&IdtDescriptor.Limit);
828 ((PKIPCR)KeGetPcr())->IDT = NewIdt2;
829
830 /* Restore interrupts */
831 _enable();
832
833 /* Set the first 7 entries as read-only to produce a fault */
834 PointerPte = MiAddressToPte(NewIdt);
835 ASSERT(PointerPte->u.Hard.Write == 1);
836 PointerPte->u.Hard.Write = 0;
837 KeInvalidateTlbEntry(NewIdt);
838}
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
__INTRIN_INLINE void __lidt(void *Source)
Definition: intrin_x86.h:2059
__INTRIN_INLINE void __sidt(void *Destination)
Definition: intrin_x86.h:2064
#define KIDTENTRY
Definition: ketypes.h:584
FORCEINLINE VOID KeInvalidateTlbEntry(IN PVOID Address)
Definition: ke.h:274
#define MiAddressToPte(x)
Definition: mm.h:144
PVOID Base
Definition: ketypes.h:591
USHORT Limit
Definition: ketypes.h:590
ULONG64 Write
Definition: mmtypes.h:170
union _MMPTE::@2788 u
MMPTE_HARDWARE Hard
Definition: mmtypes.h:217
void * PVOID
Definition: typedefs.h:50
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263

Referenced by KiInitMachineDependent().

◆ KiInitializeMachineType()

VOID NTAPI KiInitializeMachineType ( VOID  )

Definition at line 704 of file cpu.c.

705{
706 /* Set the Machine Type we got from NTLDR */
708}
ULONG KeI386MachineType
Definition: cpu.c:34
NTSYSAPI PLOADER_PARAMETER_BLOCK KeLoaderBlock
Definition: krnlinit.c:28
ULONG MachineType
Definition: arc.h:713
I386_LOADER_BLOCK I386
Definition: arc.h:861
union _LOADER_PARAMETER_BLOCK::@4172 u

◆ KiInitializeTSS()

VOID NTAPI KiInitializeTSS ( IN PKTSS  Tss)

Definition at line 499 of file cpu.c.

500{
501 /* Set an invalid map base */
502 Tss->IoMapBase = KiComputeIopmOffset(IO_ACCESS_MAP_NONE);
503
504 /* Disable traps during Task Switches */
505 Tss->Flags = 0;
506
507 /* Set LDT and Ring 0 SS */
508 Tss->LDT = 0;
509 Tss->Ss0 = KGDT_R0_DATA;
510}
#define KiComputeIopmOffset(MapNumber)
Definition: ketypes.h:363
#define IO_ACCESS_MAP_NONE
Definition: ketypes.h:361
#define KGDT_R0_DATA
Definition: ketypes.h:124

Referenced by Ki386InitializeTss().

◆ KiInitializeTSS2()

VOID NTAPI KiInitializeTSS2 ( IN PKTSS  Tss,
IN PKGDTENTRY TssEntry  OPTIONAL 
)

Definition at line 461 of file cpu.c.

463{
464 PUCHAR p;
465
466 /* Make sure the GDT Entry is valid */
467 if (TssEntry)
468 {
469 /* Set the Limit */
470 TssEntry->LimitLow = sizeof(KTSS) - 1;
471 TssEntry->HighWord.Bits.LimitHi = 0;
472 }
473
474 /* Now clear the I/O Map */
475 ASSERT(IOPM_COUNT == 1);
476 RtlFillMemory(Tss->IoMaps[0].IoMap, IOPM_FULL_SIZE, 0xFF);
477
478 /* Initialize Interrupt Direction Maps */
479 p = (PUCHAR)(Tss->IoMaps[0].DirectionMap);
481
482 /* Add DPMI support for interrupts */
483 p[0] = 4;
484 p[3] = 0x18;
485 p[4] = 0x18;
486
487 /* Initialize the default Interrupt Direction Map */
488 p = Tss->IntDirectionMap;
489 RtlZeroMemory(Tss->IntDirectionMap, IOPM_DIRECTION_MAP_SIZE);
490
491 /* Add DPMI support */
492 p[0] = 4;
493 p[3] = 0x18;
494 p[4] = 0x18;
495}
GLfloat GLfloat p
Definition: glext.h:8902
#define KTSS
Definition: ketypes.h:1033
#define IOPM_FULL_SIZE
Definition: ketypes.h:240
#define IOPM_DIRECTION_MAP_SIZE
Definition: ketypes.h:242
#define IOPM_COUNT
Definition: ketypes.h:238
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:603
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262

Referenced by Ki386InitializeTss().

◆ KiIsNpxErrataPresent()

BOOLEAN NTAPI KiIsNpxErrataPresent ( VOID  )

Definition at line 875 of file cpu.c.

876{
877 static double Value1 = 4195835.0, Value2 = 3145727.0;
878 INT ErrataPresent;
879 ULONG Cr0;
880
881 /* Interrupts have to be disabled here. */
883
884 /* Read CR0 and remove FPU flags */
885 Cr0 = __readcr0();
886 __writecr0(Cr0 & ~(CR0_MP | CR0_TS | CR0_EM));
887
888 /* Initialize FPU state */
889 Ke386FnInit();
890
891 /* Multiply the magic values and divide, we should get the result back */
892#ifdef __GNUC__
893 __asm__ __volatile__
894 (
895 "fldl %1\n\t"
896 "fdivl %2\n\t"
897 "fmull %2\n\t"
898 "fldl %1\n\t"
899 "fsubp\n\t"
900 "fistpl %0\n\t"
901 : "=m" (ErrataPresent)
902 : "m" (Value1),
903 "m" (Value2)
904 );
905#else
906 __asm
907 {
908 fld Value1
909 fdiv Value2
910 fmul Value2
911 fld Value1
912 fsubp st(1), st(0)
913 fistp ErrataPresent
914 };
915#endif
916
917 /* Restore CR0 */
918 __writecr0(Cr0);
919
920 /* Return if there's an errata */
921 return ErrataPresent != 0;
922}
#define EFLAGS_INTERRUPT_MASK
__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" "\tpush %rbx\n" "\t.seh_pushreg %rbx\n" "\tpush %rdi\n" "\t.seh_pushreg %rdi\n" "\tpush %rsi\n" "\t.seh_pushreg %rsi\n" "\tpush %r12\n" "\t.seh_pushreg %r12\n" "\tpush %r13\n" "\t.seh_pushreg %r13\n" "\tpush %r14\n" "\t.seh_pushreg %r14\n" "\tpush %r15\n" "\t.seh_pushreg %r15\n" "\tsub $40, %rsp\n" "\t.seh_stackalloc 40\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 $40, %rsp\n" "\tpop %r15\n" "\tpop %r14\n" "\tpop %r13\n" "\tpop %r12\n" "\tpop %rsi\n" "\tpop %rdi\n" "\tpop %rbx\n" "\tpop %rbp\n" "\tret\n" "\t.seh_endproc")
int32_t INT
Definition: typedefs.h:58

Referenced by KiVerifyCpuFeatures().

◆ KiLoadFastSyscallMachineSpecificRegisters()

ULONG_PTR NTAPI KiLoadFastSyscallMachineSpecificRegisters ( IN ULONG_PTR  Context)

Definition at line 713 of file cpu.c.

714{
715 /* Set CS and ESP */
716 __writemsr(0x174, KGDT_R0_CODE);
717 __writemsr(0x175, (ULONG_PTR)KeGetCurrentPrcb()->DpcStack);
718
719 /* Set LSTAR */
721 return 0;
722}
VOID __cdecl KiFastCallEntry(VOID)

Referenced by KiRestoreFastSyscallReturnState().

◆ KiRestoreFastSyscallReturnState()

VOID NTAPI KiRestoreFastSyscallReturnState ( VOID  )

Definition at line 727 of file cpu.c.

728{
729 /* Check if the CPU Supports fast system call */
731 {
732 /* Check if it has been disabled */
734 {
735 /* Disable fast system call */
736 KeFeatureBits &= ~KF_FAST_SYSCALL;
738 DPRINT1("Support for SYSENTER disabled.\n");
739 }
740 else
741 {
742 /* Do an IPI to enable it */
744
745 /* It's enabled, so use the proper exit stub */
747 DPRINT("Support for SYSENTER detected.\n");
748 }
749 }
750 else
751 {
752 /* Use the IRET handler */
754 DPRINT1("No support for SYSENTER detected.\n");
755 }
756}
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:713
#define DPRINT
Definition: sndvol32.h:73
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().

◆ KiRestoreProcessorControlState()

VOID NTAPI KiRestoreProcessorControlState ( PKPROCESSOR_STATE  ProcessorState)

Definition at line 632 of file cpu.c.

633{
634 PKGDTENTRY TssEntry;
635
636 //
637 // Restore the CR registers
638 //
639 __writecr0(ProcessorState->SpecialRegisters.Cr0);
640 Ke386SetCr2(ProcessorState->SpecialRegisters.Cr2);
641 __writecr3(ProcessorState->SpecialRegisters.Cr3);
642 if (KeFeatureBits & KF_CR4) __writecr4(ProcessorState->SpecialRegisters.Cr4);
643
644 //
645 // Restore the DR registers
646 //
647 __writedr(0, ProcessorState->SpecialRegisters.KernelDr0);
648 __writedr(1, ProcessorState->SpecialRegisters.KernelDr1);
649 __writedr(2, ProcessorState->SpecialRegisters.KernelDr2);
650 __writedr(3, ProcessorState->SpecialRegisters.KernelDr3);
651 __writedr(6, ProcessorState->SpecialRegisters.KernelDr6);
652 __writedr(7, ProcessorState->SpecialRegisters.KernelDr7);
653
654 //
655 // Restore GDT and IDT
656 //
658 __lidt(&ProcessorState->SpecialRegisters.Idtr.Limit);
659
660 //
661 // Clear the busy flag so we don't crash if we reload the same selector
662 //
663 TssEntry = (PKGDTENTRY)(ProcessorState->SpecialRegisters.Gdtr.Base +
664 ProcessorState->SpecialRegisters.Tr);
665 TssEntry->HighWord.Bytes.Flags1 &= ~0x2;
666
667 //
668 // Restore TSS and LDT
669 //
670 Ke386SetTr(ProcessorState->SpecialRegisters.Tr);
671 Ke386SetLocalDescriptorTable(ProcessorState->SpecialRegisters.Ldtr);
672}
#define Ke386SetGlobalDescriptorTable
Definition: intrin_i.h:453
__INTRIN_INLINE void __writedr(unsigned reg, unsigned int value)
Definition: intrin_x86.h:1967
ULONG Base
Definition: ketypes.h:461
USHORT Limit
Definition: ketypes.h:460
KSPECIAL_REGISTERS SpecialRegisters
Definition: ketypes.h:635
ULONG64 KernelDr1
Definition: ketypes.h:606
ULONG64 KernelDr2
Definition: ketypes.h:607
ULONG64 KernelDr0
Definition: ketypes.h:605
KDESCRIPTOR Gdtr
Definition: ketypes.h:611
KDESCRIPTOR Idtr
Definition: ketypes.h:612
ULONG64 KernelDr7
Definition: ketypes.h:610
ULONG64 KernelDr6
Definition: ketypes.h:609
ULONG64 KernelDr3
Definition: ketypes.h:608

◆ KiSaveProcessorControlState()

VOID NTAPI KiSaveProcessorControlState ( OUT PKPROCESSOR_STATE  ProcessorState)

Definition at line 676 of file cpu.c.

677{
678 /* Save the CR registers */
679 ProcessorState->SpecialRegisters.Cr0 = __readcr0();
680 ProcessorState->SpecialRegisters.Cr2 = __readcr2();
681 ProcessorState->SpecialRegisters.Cr3 = __readcr3();
682 ProcessorState->SpecialRegisters.Cr4 = (KeFeatureBits & KF_CR4) ?
683 __readcr4() : 0;
684
685 /* Save the DR registers */
686 ProcessorState->SpecialRegisters.KernelDr0 = __readdr(0);
687 ProcessorState->SpecialRegisters.KernelDr1 = __readdr(1);
688 ProcessorState->SpecialRegisters.KernelDr2 = __readdr(2);
689 ProcessorState->SpecialRegisters.KernelDr3 = __readdr(3);
690 ProcessorState->SpecialRegisters.KernelDr6 = __readdr(6);
691 ProcessorState->SpecialRegisters.KernelDr7 = __readdr(7);
692 __writedr(7, 0);
693
694 /* Save GDT, IDT, LDT and TSS */
695 Ke386GetGlobalDescriptorTable(&ProcessorState->SpecialRegisters.Gdtr.Limit);
696 __sidt(&ProcessorState->SpecialRegisters.Idtr.Limit);
697 ProcessorState->SpecialRegisters.Tr = Ke386GetTr();
698 Ke386GetLocalDescriptorTable(&ProcessorState->SpecialRegisters.Ldtr);
699}
#define Ke386GetGlobalDescriptorTable
Definition: intrin_i.h:452
#define Ke386GetLocalDescriptorTable
Definition: intrin_i.h:454
__INTRIN_INLINE unsigned int __readdr(unsigned int reg)
Definition: intrin_x86.h:1934
__INTRIN_INLINE unsigned long __readcr2(void)
Definition: intrin_x86.h:1843

Referenced by KdpCommandString(), KdpReport(), KdpSymbol(), KeBugCheckWithTf(), KiInitializeKernel(), and KiSystemStartupBootStack().

◆ KiSaveProcessorState()

VOID NTAPI KiSaveProcessorState ( IN PKTRAP_FRAME  TrapFrame,
IN PKEXCEPTION_FRAME  ExceptionFrame 
)

Definition at line 854 of file cpu.c.

856{
857 PKPRCB Prcb = KeGetCurrentPrcb();
858
859 //
860 // Save full context
861 //
865
866 //
867 // Save control registers
868 //
870}
#define CONTEXT_DEBUG_REGISTERS
Definition: nt_native.h:1376
#define CONTEXT_FULL
Definition: nt_native.h:1378
VOID NTAPI KeTrapFrameToContext(IN PKTRAP_FRAME TrapFrame, IN PKEXCEPTION_FRAME ExceptionFrame, IN OUT PCONTEXT Context)
Definition: context.c:169
ULONG ContextFlags
Definition: nt_native.h:1429
KPROCESSOR_STATE ProcessorState
Definition: ketypes.h:683
CONTEXT ContextFrame
Definition: ketypes.h:636

◆ KiSetCR0Bits()

VOID NTAPI KiSetCR0Bits ( VOID  )

Definition at line 444 of file cpu.c.

445{
446 ULONG Cr0;
447
448 /* Save current CR0 */
449 Cr0 = __readcr0();
450
451 /* If this is a 486, enable Write-Protection */
452 if (KeGetCurrentPrcb()->CpuType > 3) Cr0 |= CR0_WP;
453
454 /* Set new Cr0 */
455 __writecr0(Cr0);
456}
#define CR0_WP
Definition: ketypes.h:145

Referenced by KiInitMachineDependent().

◆ KiSetProcessorType()

VOID NTAPI KiSetProcessorType ( VOID  )

Definition at line 96 of file cpu.c.

97{
98 PKPRCB Prcb = KeGetCurrentPrcb();
99 USHORT Family, Model, Stepping;
100
101 /* Get the CPU vendor string */
103
104 /* Get the family, model and stepping */
105 KiGetCpuSignature(&Family, &Model, &Stepping);
106
107 /* Save them in the PRCB */
108 Prcb->CpuID = TRUE;
109 Prcb->CpuType = (UCHAR)Family;
110 Prcb->CpuStep = ((Model << 8) | Stepping);
111}
VOID NTAPI KiGetCpuSignature(_Out_ PUSHORT Family, _Out_ PUSHORT Model, _Out_ PUSHORT Stepping)
Get the CPU signature.
Definition: cpuinfo.c:118
VOID NTAPI KiGetCpuVendorString(_Out_writes_z_(CPU_VENDOR_STR_LEN) CHAR VendorString[CPU_VENDOR_STR_LEN])
Get the CPUID information for a given CPU.
Definition: cpuinfo.c:24
static int Family
Definition: ping.c:62
CHAR CpuID
Definition: ketypes.h:685
UCHAR VendorString[13]
Definition: ketypes.h:901

Referenced by KiInitializeCpu(), and KiVerifyCpuFeatures().

◆ setCx86()

static __inline void setCx86 ( UCHAR  reg,
UCHAR  data 
)
static

Definition at line 76 of file cpu.c.

77{
80}
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950

Referenced by KiGetFeatureBits().

Variable Documentation

◆ Ke386NoExecute

ULONG Ke386NoExecute = FALSE

Definition at line 36 of file cpu.c.

Referenced by ProtectToPTE().

◆ Ke386Pae

◆ KeDcacheFlushCount

ULONG KeDcacheFlushCount = 0

Definition at line 38 of file cpu.c.

◆ KeI386CpuStep

ULONG KeI386CpuStep

Definition at line 27 of file cpu.c.

Referenced by KiInitializeKernel(), and KiInitializeKernelMachineDependent().

◆ KeI386CpuType

ULONG KeI386CpuType

Definition at line 26 of file cpu.c.

Referenced by KiInitializeKernel(), and KiInitializeKernelMachineDependent().

◆ KeI386FxsrPresent

◆ KeI386MachineType

ULONG KeI386MachineType

Definition at line 34 of file cpu.c.

Referenced by CmpInitializeHardwareConfiguration().

◆ KeI386NpxPresent

ULONG KeI386NpxPresent = TRUE

Definition at line 29 of file cpu.c.

Referenced by CmpInitializeMachineDependentConfiguration().

◆ KeI386XMMIPresent

ULONG KeI386XMMIPresent = 0

Definition at line 32 of file cpu.c.

Referenced by KiInitializeKernel().

◆ KeIcacheFlushCount

ULONG KeIcacheFlushCount = 0

Definition at line 39 of file cpu.c.

◆ KeLargestCacheLine

ULONG KeLargestCacheLine = 0x40

Definition at line 37 of file cpu.c.

◆ KePrefetchNTAGranularity

ULONG KePrefetchNTAGranularity = 32

Definition at line 41 of file cpu.c.

Referenced by KiGetCacheInformation().

◆ KiDmaIoCoherency

ULONG KiDmaIoCoherency = 0

Definition at line 40 of file cpu.c.

◆ KiDoubleFaultTSS

UCHAR KiDoubleFaultTSS[KTSS_IO_MAPS]

Definition at line 20 of file cpu.c.

Referenced by Ki386InitializeTss().

◆ KiFastCallCopyDoneOnce

BOOLEAN KiFastCallCopyDoneOnce

Definition at line 52 of file cpu.c.

◆ KiFastSystemCallDisable

ULONG KiFastSystemCallDisable = 0

Definition at line 28 of file cpu.c.

Referenced by KiRestoreFastSyscallReturnState().

◆ KiI386PentiumLockErrataPresent

BOOLEAN KiI386PentiumLockErrataPresent

Definition at line 42 of file cpu.c.

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

◆ KiMXCsrMask

ULONG KiMXCsrMask = 0

Definition at line 30 of file cpu.c.

Referenced by KeContextToTrapFrame(), and KiInitMachineDependent().

◆ KiNMITSS

UCHAR KiNMITSS[KTSS_IO_MAPS]

Definition at line 23 of file cpu.c.

Referenced by Ki386InitializeTss().

◆ KiSMTProcessorsPresent

BOOLEAN KiSMTProcessorsPresent

Definition at line 43 of file cpu.c.

◆ KiSystemCallExitAdjust

UCHAR KiSystemCallExitAdjust

Definition at line 46 of file cpu.c.

◆ KiSystemCallExitAdjusted

UCHAR KiSystemCallExitAdjusted

Definition at line 49 of file cpu.c.

◆ KiTbFlushTimeStamp

volatile LONG KiTbFlushTimeStamp

Definition at line 55 of file cpu.c.

◆ MxcsrFeatureMask

ULONG MxcsrFeatureMask = 0

Definition at line 31 of file cpu.c.