ReactOS 0.4.17-dev-1190-g4c812f4
ke.h File Reference

Go to the source code of this file.

Macros

#define CPU_VENDOR_STR_LEN   13
 

Functions

VOID NTAPI KiGetCpuVendorString (_Out_writes_z_(CPU_VENDOR_STR_LEN) CHAR VendorString[CPU_VENDOR_STR_LEN])
 Get the CPUID information for a given CPU.
 
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.
 
VOID NTAPI KiGetCpuSignature (_Out_ PUSHORT Family, _Out_ PUSHORT Model, _Out_ PUSHORT Stepping)
 Get the CPU signature.
 
ULONG NTAPI KiGetCpuCacheDescriptors (_Out_writes_(MaxCount) PCACHE_DESCRIPTOR CacheDescriptors, _In_ ULONG MaxCount, _In_ CPU_VENDORS Vendor)
 Retrieves cache descriptors for the current CPU.
 

Macro Definition Documentation

◆ CPU_VENDOR_STR_LEN

#define CPU_VENDOR_STR_LEN   13

Definition at line 10 of file ke.h.

Function Documentation

◆ KiGetCpuCacheDescriptors()

ULONG NTAPI KiGetCpuCacheDescriptors ( _Out_writes_(MaxCount) PCACHE_DESCRIPTOR  CacheDescriptors,
_In_ ULONG  MaxCount,
_In_ CPU_VENDORS  Vendor 
)

Retrieves cache descriptors for the current CPU.

Parameters
[out]CacheDescriptors- An array to receive the cache descriptors
[in]MaxCount- The maximum number of cache descriptors to fill
[in]Vendor- The CPU vendor
Returns
The number of cache descriptors retrieved

Definition at line 484 of file cacheinfo.c.

488{
490 CPUID_EXTENDED_FUNCTION_REGS ExtendedFunction;
491 ULONG Count = 0;
492
493 /* Get the maximum leaf and maximum extended leaf */
495 __cpuid(ExtendedFunction.AsInt32, CPUID_EXTENDED_FUNCTION);
496
497 /* Distinguish by vendor: AMD (and Hygon) have their own custom cpuid leaves. */
498 if (Vendor == CPU_AMD)
499 {
500 if (ExtendedFunction.MaxLeaf >= CPUID_CACHE_PARAMS_AMD)
501 {
502 Count = KiGetCacheInfoModern(CacheDescriptors, MaxCount, CPUID_CACHE_PARAMS_AMD);
503 }
504
505 if ((Count == 0) && (ExtendedFunction.MaxLeaf >= CPUID_EXTENDED_CACHE_INFO))
506 {
507 Count = GetCacheInfoAmdLegacy(CacheDescriptors, MaxCount);
508 }
509 }
510 else
511 {
512 if (Signature.MaxLeaf >= CPUID_CACHE_PARAMS)
513 {
514 Count = KiGetCacheInfoModern(CacheDescriptors, MaxCount, CPUID_CACHE_PARAMS);
515 }
516
517 if ((Count == 0) && (Signature.MaxLeaf >= CPUID_CACHE_INFO))
518 {
519 Count = GetCacheInfoIntelLeaf2(CacheDescriptors, MaxCount);
520 }
521 }
522
523 /* Normalize the descriptors */
524 Count = NormalizeCacheDescriptors(CacheDescriptors, Count, MaxCount);
525
526 return Count;
527}
#define CPUID_CACHE_PARAMS_AMD
Definition: Cpuid.h:393
#define CPUID_EXTENDED_FUNCTION
Definition: Cpuid.h:3802
#define CPUID_SIGNATURE
Definition: Cpuid.h:45
#define CPUID_CACHE_PARAMS
Definition: Cpuid.h:802
#define CPUID_CACHE_INFO
Definition: Cpuid.h:710
#define CPUID_EXTENDED_CACHE_INFO
Definition: Cpuid.h:3998
static ULONG NormalizeCacheDescriptors(_Inout_updates_(MaxCount) PCACHE_DESCRIPTOR CacheDescriptors, _In_ ULONG CacheCount, _In_ ULONG MaxCount)
Normalizes the cache descriptors by removing duplicates and sorting them.
Definition: cacheinfo.c:425
static ULONG GetCacheInfoIntelLeaf2(_Out_cap_(MaxCount) PCACHE_DESCRIPTOR CacheDescriptors, _In_ ULONG MaxCount)
Retrieves cache information using CPUID leaf 2 for Intel processors.
Definition: cacheinfo.c:207
static ULONG KiGetCacheInfoModern(_Out_cap_(MaxCount) PCACHE_DESCRIPTOR CacheDescriptors, _In_ ULONG MaxCount, _In_ ULONG CpuIdLeaf)
Retrieves cache information for modern Intel/AMD processors.
Definition: cacheinfo.c:355
static ULONG GetCacheInfoAmdLegacy(_Out_cap_(MaxCount) PCACHE_DESCRIPTOR CacheDescriptors, _In_ ULONG MaxCount)
Retrieves cache information for legacy AMD processors.
Definition: cacheinfo.c:281
static const WCHAR Signature[]
Definition: parser.c:141
PPC_QUAL void __cpuid(int CPUInfo[], const int InfoType)
Definition: intrin_ppc.h:682
@ CPU_AMD
Definition: ketypes.h:99
int Count
Definition: noreturn.cpp:7
uint32_t ULONG
Definition: typedefs.h:59

Referenced by KiGetCacheInformation().

◆ KiGetCpuSignature()

VOID NTAPI KiGetCpuSignature ( _Out_ PUSHORT  Family,
_Out_ PUSHORT  Model,
_Out_ PUSHORT  Stepping 
)

Get the CPU signature.

Parameters
[out]Family- Pointer to a USHORT to receive the family
[out]Model- Pointer to a USHORT to receive the model
[out]Stepping- Pointer to a USHORT to receive the stepping

\See

Definition at line 118 of file cpuinfo.c.

122{
124
125 /* Get the CPUID */
126 __cpuid(VersionInfo.AsInt32, 1);
127
128 /* Get the family */
129 *Family = VersionInfo.Eax.Bits.FamilyId;
130 if (VersionInfo.Eax.Bits.FamilyId == 15)
131 {
132 *Family += VersionInfo.Eax.Bits.ExtendedFamilyId;
133 }
134
135 /* Get the model */
136 *Model = VersionInfo.Eax.Bits.Model;
137 if ((VersionInfo.Eax.Bits.FamilyId == 6) ||
138 (VersionInfo.Eax.Bits.FamilyId == 15))
139 {
140 /* For Family < 15, AMD documents extended model as RAZ (reads as zero) */
141 *Model |= VersionInfo.Eax.Bits.ExtendedModelId << 4;
142 }
143
144 /* Get the stepping */
145 *Stepping = VersionInfo.Eax.Bits.SteppingId;
146}
OSVERSIONINFOW VersionInfo
Definition: wkssvc.c:40
static int Family
Definition: ping.c:62

Referenced by KiSetProcessorType().

◆ KiGetCpuVendorString()

VOID NTAPI KiGetCpuVendorString ( _Out_writes_z_(CPU_VENDOR_STR_LEN) CHAR  VendorString[CPU_VENDOR_STR_LEN])

Get the CPUID information for a given CPU.

Parameters
[out]VendorString- Pointer to a buffer to receive the vendor string

Definition at line 24 of file cpuinfo.c.

26{
28
29 /* Get the Vendor string */
30 __cpuid(&Signature.AsInt32[0], CPUID_SIGNATURE);
31
32 /* Copy and null-terminate it */
33 *(ULONG*)&VendorString[0] = *(ULONG*)&Signature.SignatureScrambled[0];
34 *(ULONG*)&VendorString[4] = *(ULONG*)&Signature.SignatureScrambled[8];
35 *(ULONG*)&VendorString[8] = *(ULONG*)&Signature.SignatureScrambled[4];
36 VendorString[12] = 0;
37}

Referenced by KiSetProcessorType().

◆ KiIdentifyCpuVendor()

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.

Parameters
[in]VendorString- Pointer to a buffer containing the vendor string
Returns
The CPU_VENDOR enum value that corresponds to the vendor string
See also
Remarks
This function is called very early during the boot process, before the kernel debugger is initialized, so it must not do any debug prints.

Definition at line 55 of file cpuinfo.c.

57{
58 /* Identify the CPU vendor */
59 if (!strcmp(VendorString, "GenuineIntel") ||
60 !strcmp(VendorString, "GenuineIotel")) // Intel Xeon E3-1231 v3
61 {
62 return CPU_INTEL;
63 }
64 else if (!strcmp(VendorString, "AuthenticAMD") ||
65 !strcmp(VendorString, "HygonGenuine"))
66 {
67 return CPU_AMD;
68 }
69 else if (!strcmp(VendorString, "CentaurHauls") ||
70 !strcmp(VendorString, " Shanghai "))
71 {
72 return CPU_VIA; // == CPU_CENTAUR
73 }
74#ifdef _M_I386
75 else if (!strcmp(VendorString, "CyrixInstead"))
76 {
77 return CPU_CYRIX;
78 }
79 else if (!strcmp(VendorString, "GenuineTMx86"))
80 {
81 return CPU_TRANSMETA;
82 }
83 else if (!strcmp(VendorString, "RiseRiseRise"))
84 {
85 return CPU_RISE;
86 }
87#endif // _M_I386
88
89 return CPU_UNKNOWN;
90}
_ACRTIMP int __cdecl strcmp(const char *, const char *)
Definition: string.c:3324
@ CPU_VIA
Definition: ketypes.h:101
@ CPU_INTEL
Definition: ketypes.h:100
@ CPU_UNKNOWN
Definition: ketypes.h:98
@ CPU_RISE
Definition: ketypes.h:96
@ CPU_CYRIX
Definition: ketypes.h:92
@ CPU_TRANSMETA
Definition: ketypes.h:93

Referenced by KiGetCpuVendor(), and KiSetProcessorType().