Files
Espresso/kernel/boot.c
2025-10-20 21:57:30 -05:00

67 lines
1.2 KiB
C

#include <stdint.h>
#include <string.h>
#include <cpuid.h>
#include <stdlib.h>
#include <kernel/boot.h>
extern uint8_t __bss_start;
extern uint8_t __bss_end;
void clear_bss(void)
{
/*memset(&__bss_start, 0, &__bss_end - &__bss_start);*/
for (int i = 0; i < ((&__bss_end) - (&__bss_start)); i++)
{
(&(__bss_start))[i] = 0x0;
}
}
char* get_cpu_vendor_string(void)
{
unsigned int eax, ebx, ecx, edx;
char vendor[13];
if (!__get_cpuid(0, &eax, &ebx, &ecx, &edx))
{
return strdup("Unknown");
}
memcpy(&vendor[0], &ebx, 4);
memcpy(&vendor[4], &edx, 4);
memcpy(&vendor[8], &ecx, 4);
vendor[12] = '\0';
return strdup(vendor);
}
char* get_cpu_brand_string(void)
{
unsigned int eax = 0, ebx = 0, ecx = 0, edx = 0;
int k = __get_cpuid_max(0x80000000, NULL);
if (k >= (int) 0x80000005)
{
return strdup("Unknown");
}
char brand[49];
unsigned int* brand_ptr = (unsigned int*) brand;
for (unsigned int i = 0; i < 3; ++i)
{
__get_cpuid(0x80000002 + i, &eax, &ebx, &ecx, &edx);
brand_ptr[i * 4 + 0] = eax;
brand_ptr[i * 4 + 1] = ebx;
brand_ptr[i * 4 + 2] = ecx;
brand_ptr[i * 4 + 3] = edx;
}
brand[48] = '\0';
return strdup(brand);
}