forked from CHatingPython/towos
feat: add IDT
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user