addind more important kernel files and also fixing bugs

This commit is contained in:
2025-05-15 02:37:06 -07:00
parent 512bd49ff7
commit a9f2826014
21 changed files with 489 additions and 17 deletions

35
kernel/cpu.c Normal file
View File

@@ -0,0 +1,35 @@
#include "cpu.h"
#include "serial.h"
#include "terminal.h"
void cpuid(uint32_t function, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) {
asm volatile (
"cpuid"
: "=a"(*eax), "=b"(*ebx), "=c"(*ecx), "=d"(*edx)
: "a"(function)
);
}
void identify_cpu() {
uint32_t eax, ebx, ecx, edx;
char vendor[13];
cpuid(0, &eax, &ebx, &ecx, &edx);
*(uint32_t *)&vendor[0] = ebx;
*(uint32_t *)&vendor[4] = edx;
*(uint32_t *)&vendor[8] = ecx;
vendor[12] = '\0';
terminal_write("CPU Vendor: ");
terminal_write(vendor);
terminal_write("\n");
serial_write("CPU Vendor: ");
serial_write(vendor);
serial_write("\n");
terminal_write("CPUID max leaf: ");
print_hex(eax); // You must implement this (see below)
terminal_write("\n");
}