Re: [PATCH v1 07/12] tools/x86/kcpuid: Add rudimentary CPU vendor detection
From: Andrew Cooper
Date: Thu Mar 06 2025 - 16:08:15 EST
On 06/03/2025 8:49 pm, Ahmed S. Darwish wrote:
> @@ -145,6 +166,40 @@ static inline bool has_subleafs(u32 f)
> return false;
> }
>
> +/*
> + * Leaf 0x0 EDX output, CPU vendor ID string bytes 4 - 7.
> + */
> +enum {
> + EDX_INTEL = fourcc('i', 'n', 'e', 'I'), /* Genu_ineI_ntel */
> + EDX_AMD = fourcc('e', 'n', 't', 'i'), /* Auth_enti_cAMD */
> + EDX_HYGON = fourcc('n', 'G', 'e', 'n'), /* Hygo_nGen_uine */
> + EDX_TRANSMETA = fourcc('i', 'n', 'e', 'T'), /* Genu_ineT_Mx86 */
> + EDX_CENTAUR = fourcc('a', 'u', 'r', 'H'), /* Cent_aurH_auls */
> + EDX_ZHAOXIN = fourcc('a', 'n', 'g', 'h'), /* Sh_angh_ai */
> +};
> +
> +static enum cpu_vendor identify_cpu_vendor(void)
> +{
> + u32 eax = 0, ebx, ecx = 0, edx;
> +
> + cpuid(&eax, &ebx, &ecx, &edx);
> +
> + switch (edx) {
> + case EDX_INTEL:
> + return VENDOR_INTEL;
> + case EDX_AMD:
> + case EDX_HYGON:
> + return VENDOR_AMD;
> + case EDX_TRANSMETA:
> + return VENDOR_TRANSMETA;
> + case EDX_CENTAUR:
> + case EDX_ZHAOXIN:
> + return VENDOR_CENTAUR;
> + default:
> + return VENDOR_UNKNOWN;
> + }
Many CPUs have ways of overriding the vendor string, thanks to
GenuineIntel being hardcoded in too many pieces of software.
I suggest you check all registers, lest you find yourself on a CPU
claiming EBX=0x68747541, ECX=0x6C65746E, EDX=0x6E65476E
~Andrew