https://git.reactos.org/?p=reactos.git;a=commitdiff;h=00b3e4bc689519d67a81b…
commit 00b3e4bc689519d67a81b59a8dad8dfe5fafdb5d
Author: Marcus Boillat <marcus.boillat(a)gmail.com>
AuthorDate: Sat May 7 23:27:25 2022 +0200
Commit: Stanislav Motylkov <x86corez(a)gmail.com>
CommitDate: Mon May 9 21:50:24 2022 +0300
[NTOS:KE] Use bitfield structure for x86 CPU signature in EAX register
This makes code a lot more readable. CORE-17974
---
ntoskrnl/ke/amd64/cpu.c | 29 +++++++++++++++++++++--------
ntoskrnl/ke/i386/cpu.c | 29 +++++++++++++++++++++--------
2 files changed, 42 insertions(+), 16 deletions(-)
diff --git a/ntoskrnl/ke/amd64/cpu.c b/ntoskrnl/ke/amd64/cpu.c
index cbce873f619..4ed7e5470fe 100644
--- a/ntoskrnl/ke/amd64/cpu.c
+++ b/ntoskrnl/ke/amd64/cpu.c
@@ -35,6 +35,21 @@ static const CHAR CmpIntelID[] = "GenuineIntel";
static const CHAR CmpAmdID[] = "AuthenticAMD";
static const CHAR CmpCentaurID[] = "CentaurHauls";
+typedef union _CPU_SIGNATURE
+{
+ struct
+ {
+ ULONG Step : 4;
+ ULONG Model : 4;
+ ULONG Family : 4;
+ ULONG Unused : 4;
+ ULONG ExtendedModel : 4;
+ ULONG ExtendedFamily : 8;
+ ULONG Unused2 : 4;
+ };
+ ULONG AsULONG;
+} CPU_SIGNATURE;
+
/* FUNCTIONS *****************************************************************/
ULONG
@@ -82,6 +97,7 @@ NTAPI
KiSetProcessorType(VOID)
{
CPU_INFO CpuInfo;
+ CPU_SIGNATURE CpuSignature;
ULONG Stepping, Type;
/* Do CPUID 1 now */
@@ -89,17 +105,14 @@ KiSetProcessorType(VOID)
/*
* Get the Stepping and Type. The stepping contains both the
- * Model and the Step, while the Type contains the returned Type.
- * We ignore the family.
+ * Model and the Step, while the Type contains the returned Family.
*
* For the stepping, we convert this: zzzzzzxy into this: x0y
*/
- Stepping = CpuInfo.Eax & 0xF0;
- Stepping <<= 4;
- Stepping += (CpuInfo.Eax & 0xFF);
- Stepping &= 0xF0F;
- Type = CpuInfo.Eax & 0xF00;
- Type >>= 8;
+ CpuSignature.AsULONG = CpuInfo.Eax;
+ Stepping = CpuSignature.Model;
+ Stepping = (Stepping << 8) | CpuSignature.Step;
+ Type = CpuSignature.Family;
/* Save them in the PRCB */
KeGetCurrentPrcb()->CpuID = TRUE;
diff --git a/ntoskrnl/ke/i386/cpu.c b/ntoskrnl/ke/i386/cpu.c
index 4a53f407800..711070eeb07 100644
--- a/ntoskrnl/ke/i386/cpu.c
+++ b/ntoskrnl/ke/i386/cpu.c
@@ -60,6 +60,21 @@ static const CHAR CmpTransmetaID[] = "GenuineTMx86";
static const CHAR CmpCentaurID[] = "CentaurHauls";
static const CHAR CmpRiseID[] = "RiseRiseRise";
+typedef union _CPU_SIGNATURE
+{
+ struct
+ {
+ ULONG Step : 4;
+ ULONG Model : 4;
+ ULONG Family : 4;
+ ULONG Unused : 4;
+ ULONG ExtendedModel : 4;
+ ULONG ExtendedFamily : 8;
+ ULONG Unused2 : 4;
+ };
+ ULONG AsULONG;
+} CPU_SIGNATURE;
+
/* SUPPORT ROUTINES FOR MSVC COMPATIBILITY ***********************************/
/* NSC/Cyrix CPU configuration register index */
@@ -143,6 +158,7 @@ NTAPI
KiSetProcessorType(VOID)
{
CPU_INFO CpuInfo;
+ CPU_SIGNATURE CpuSignature;
ULONG Stepping, Type;
/* Do CPUID 1 now */
@@ -150,17 +166,14 @@ KiSetProcessorType(VOID)
/*
* Get the Stepping and Type. The stepping contains both the
- * Model and the Step, while the Type contains the returned Type.
- * We ignore the family.
+ * Model and the Step, while the Type contains the returned Family.
*
* For the stepping, we convert this: zzzzzzxy into this: x0y
*/
- Stepping = CpuInfo.Eax & 0xF0;
- Stepping <<= 4;
- Stepping += (CpuInfo.Eax & 0xFF);
- Stepping &= 0xF0F;
- Type = CpuInfo.Eax & 0xF00;
- Type >>= 8;
+ CpuSignature.AsULONG = CpuInfo.Eax;
+ Stepping = CpuSignature.Model;
+ Stepping = (Stepping << 8) | CpuSignature.Step;
+ Type = CpuSignature.Family;
/* Save them in the PRCB */
KeGetCurrentPrcb()->CpuID = TRUE;