k-tana-zero/k/idt.c

60 lines
1.1 KiB
C

#include "idt.h"
#include "isr.h"
static struct idt idt = { 0 };
void handle_interrupt()
{
return;
}
struct idt_entry create_idt_entry(uint32_t offset,
struct segment_selector selector)
{
struct idt_entry res = { 0 };
res.selector = selector;
res.offset_1 = offset & 0xffff;
res.offset_2 = (offset >> 16) & 0xffff;
res.type = INTERRUPT_TYPE;
res.size = 1;
res.desc_priv = 0;
res.present = 1;
return res;
}
static void create_idt(void)
{
struct segment_selector selector;
selector.rpl = 0;
selector.table_indicator = 0;
selector.index = KERNEL_CS_INDEX;
for (int i = 0; i < IDT_NB_ENTRIES; ++i)
{
struct idt_entry entry = create_idt_entry((uint32_t)&handle_interrupt,
selector);
idt.entries[i] = entry;
}
}
static void load_idt(void)
{
struct idt_r idtr;
idtr.addr = (uint32_t)&idt;
idtr.limit = IDT_SIZE - 1;
asm volatile("lidt %0\n"
:
: "m" (idtr)
: "memory");
}
void init_idt(void)
{
create_idt();
load_idt();
}