k-chow/k/idt.c
Julien CLEMENT 96610353c8 feat(idt): add idt creation
Signed-off-by: Julien CLEMENT <julien.clement@epita.fr>
2021-07-14 22:57:38 +02:00

59 lines
1.1 KiB
C

#include "idt.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();
}