Implement GDT and basic IDT setup

This commit adds GDT initialization with proper code/data segments and reloads CS.

It also adds the initial IDT structure and loads an empty IDT.

Build configuration updated to disable SSE/MMX to prevent compiler generation of unsupported instructions in early boot.
This commit is contained in:
AI
2026-02-23 10:05:17 +00:00
parent c7e9833819
commit e4cc638a8d
12 changed files with 227 additions and 8 deletions

View File

@@ -1,6 +1,8 @@
#include <multiboot2.h>
#include <stdint.h>
#include <stddef.h>
#include "gdt.h"
#include "idt.h"
static inline void outb(uint16_t port, uint8_t val)
{
@@ -17,15 +19,33 @@ void offset_print(const char *str)
#define MULTIBOOT_BOOTLOADER_MAGIC 0x2BADB002
void print_hex(uint32_t val)
{
const char *hex = "0123456789ABCDEF";
outb(0xE9, '0');
outb(0xE9, 'x');
for (int i = 28; i >= 0; i -= 4) {
outb(0xE9, hex[(val >> i) & 0xF]);
}
outb(0xE9, '\n');
}
void kernel_main(uint32_t magic, uint32_t addr) {
(void)addr; // Unused for now
if (magic != MULTIBOOT2_BOOTLOADER_MAGIC && magic != MULTIBOOT_BOOTLOADER_MAGIC) {
offset_print("Invalid magic number: ");
// I don't have hex print yet, but I can print something generic
offset_print("Unknown\n");
print_hex(magic);
return;
}
offset_print("Booting...\n");
init_gdt();
offset_print("GDT initialized\n");
init_idt();
offset_print("IDT initialized\n");
offset_print("Hello, world\n");
}