Skip to content

Commit 9b00202

Browse files
committed
[NTOS:KE/x86] Detect more KeFeatureBits
1 parent d09eb6f commit 9b00202

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

ntoskrnl/include/internal/i386/ke.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ extern "C"
2222
#define KD_BREAKPOINT_SIZE sizeof(UCHAR)
2323
#define KD_BREAKPOINT_VALUE 0xCC
2424

25+
/* CPUID 1 - ECX flags */
26+
#define X86_FEATURE_SSE3 0x00000001
27+
#define X86_FEATURE_SSSE3 0x00000200
28+
#define X86_FEATURE_SSE4_1 0x00080000
29+
#define X86_FEATURE_SSE4_2 0x00100000
30+
#define X86_FEATURE_XSAVE 0x04000000
31+
#define X86_FEATURE_RDRAND 0x40000000
32+
2533
/* CPUID 1 - EDX flags */
2634
#define X86_FEATURE_FPU 0x00000001 /* x87 FPU is present */
2735
#define X86_FEATURE_VME 0x00000002 /* Virtual 8086 Extensions are present */

ntoskrnl/ke/i386/cpu.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,14 @@ KiGetFeatureBits(VOID)
361361
break;
362362
}
363363

364+
/* Get some features from ECX */
365+
if (CpuInfo.Ecx & X86_FEATURE_SSE3) FeatureBits |= KF_SSE3;
366+
if (CpuInfo.Ecx & X86_FEATURE_SSSE3) FeatureBits |= KF_SSSE3;
367+
if (CpuInfo.Ecx & X86_FEATURE_SSE4_1) FeatureBits |= KF_SSE4_1;
368+
if (CpuInfo.Ecx & X86_FEATURE_SSE4_2) FeatureBits |= KF_SSE4_2;
369+
if (CpuInfo.Ecx & X86_FEATURE_XSAVE) FeatureBits |= KF_XSTATE;
370+
if (CpuInfo.Ecx & X86_FEATURE_RDRAND) FeatureBits |= KF_RDRAND;
371+
364372
/* Set the current features */
365373
CpuFeatures = CpuInfo.Edx;
366374

ntoskrnl/ke/i386/kiinit.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,17 @@ KiInitializeKernel(IN PKPROCESS InitProcess,
572572
(KeFeatureBits & KF_3DNOW) ? TRUE: FALSE;
573573
SharedUserData->ProcessorFeatures[PF_RDTSC_INSTRUCTION_AVAILABLE] =
574574
(KeFeatureBits & KF_RDTSC) ? TRUE: FALSE;
575+
SharedUserData->ProcessorFeatures[PF_RDRAND_INSTRUCTION_AVAILABLE] =
576+
(KeFeatureBits & KF_RDRAND) ? TRUE : FALSE;
577+
// Note: On x86 we lack support for saving/restoring SSE state
578+
SharedUserData->ProcessorFeatures[PF_SSE3_INSTRUCTIONS_AVAILABLE] =
579+
(KeFeatureBits & KF_SSE3) ? TRUE : FALSE;
580+
SharedUserData->ProcessorFeatures[PF_SSSE3_INSTRUCTIONS_AVAILABLE] =
581+
(KeFeatureBits & KF_SSSE3) ? TRUE : FALSE;
582+
SharedUserData->ProcessorFeatures[PF_SSE4_1_INSTRUCTIONS_AVAILABLE] =
583+
(KeFeatureBits & KF_SSE4_1) ? TRUE : FALSE;
584+
SharedUserData->ProcessorFeatures[PF_SSE4_2_INSTRUCTIONS_AVAILABLE] =
585+
(KeFeatureBits & KF_SSE4_2) ? TRUE : FALSE;
575586

576587
/* Set up the thread-related fields in the PRCB */
577588
Prcb->CurrentThread = InitThread;

0 commit comments

Comments
 (0)