feat: add IDT

This commit is contained in:
2026-10-03 09:05:40 +02:00
parent 58afc2fc61
commit 86027f21db
10 changed files with 204 additions and 46 deletions
+42
View File
@@ -0,0 +1,42 @@
#include "./idt.hpp"
#include "./gdt.hpp"
#include "types.hpp"
namespace x86_64 {
struct idtr {
u16 limit;
const void* base;
} PACKED;
extern "C" void exception_handler(void) {
asm volatile("cli; hlt");
}
extern "C" void* isrStubTable[32];
idt::idt()
: entries() {
for (u8 vector = 0; vector < 32; ++vector) {
entries[vector] = idt_entry{
static_cast<u16>(reinterpret_cast<u64>(isrStubTable[vector]) & 0xFFFF),
gdt::KERNEL_CS,
0,
0x8E,
static_cast<u16>((reinterpret_cast<u64>(isrStubTable[vector]) >> 16) & 0xFFFF),
static_cast<u32>((reinterpret_cast<u64>(isrStubTable[vector]) >> 32) & 0xFFFFFFFF),
0,
};
}
}
void idt::load() {
idtr idtr{ (sizeof(entries) - 1), entries };
asm volatile("cli\n"
"lidt %0" ::"m"(idtr)
: "memory");
}
} // namespace x86_64