#include "idt.h" #include "core_interrupt.h" namespace IDT { // Interrupt Descriptor Table, 8 Byte aligned constinit struct InterruptDescriptor idt[256] = {}; // Struct used for loading (the address of) the Interrupt Descriptor Table into // the IDT-Register struct Register { uint16_t limit = sizeof(idt) - 1; // Address of the last valid byte (relative to base) struct InterruptDescriptor* base = idt; } __attribute__((packed)); static_assert(sizeof(InterruptDescriptor) == 16, "IDT::InterruptDescriptor has wrong size"); static_assert(sizeof(Register) == 10, "IDT::Register has wrong size"); static_assert(alignof(decltype(idt)) % 8 == 0, "IDT must be 8 byte aligned!"); void load() { // Create structure required for writing to idtr and load via lidt Register idtr; asm volatile("lidt %0\n\t" ::"m"(idtr)); } void set(Core::Interrupt::Vector vector, InterruptDescriptor descriptor) { idt[static_cast(vector)] = descriptor; } } // namespace IDT