CPU Name identification

This commit is contained in:
2026-03-26 16:53:39 +01:00
parent ac788c55d3
commit 532953da4d
3 changed files with 78 additions and 0 deletions
+47
View File
@@ -8,6 +8,7 @@
#include <stdint.h>
#include <arch/x86.h>
#include <kernel.h>
#include <mem/utils.h>
/*
* x86_overwrite_pat - Set PAT to WC
@@ -41,6 +42,52 @@ static void x86_overwrite_pat()
void x86_arch_init()
{
x86_overwrite_pat();
x86_cpu_identification();
idt_init();
gdt_init();
}
/*
* cpu_supports_brandstring - Does the CPU support brand strings?
*
* Return:
* true - if it does
* false - if it doesn't
*/
bool cpu_supports_brandstring() {
uint32_t eax, ebx, ecx, edx;
cpuid(0x80000000, &eax, &ebx, &ecx, &edx);
if (eax < 0x80000004) {
return false;
} else {
return true;
}
}
/*
* x86_cpu_idenfitication - get info about the CPU
*
* This function displays the CPU vendor name or the
* extended "brand string" if it's supported, on
* debug output.
*/
void x86_cpu_identification()
{
if (cpu_supports_brandstring()) {
uint32_t regs[12];
// Some CPUs don't return null-terminated values so we do it as a failsafe default
char str[sizeof(regs)+1] = {0};
cpuid(0x80000002, &regs[0], &regs[1], &regs[2], &regs[3]);
cpuid(0x80000003, &regs[4], &regs[5], &regs[6], &regs[7]);
cpuid(0x80000004, &regs[8], &regs[9], &regs[10], &regs[11]);
memcpy(str, regs, sizeof(regs));
str[sizeof(regs)] = '\0';
DEBUG("CPU: %s", str);
} else {
char vendor_string[13] = {0};
cpuid_get_vendor_string(vendor_string);
DEBUG("CPU vendor is: %s", vendor_string);
}
}