k-tana-zero/k/idt.c

59 lines
1.1 KiB
C
Raw Normal View History

2021-07-14 19:32:15 +00:00
#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)
2021-07-14 19:32:15 +00:00
{
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)
2021-07-14 19:32:15 +00:00
{
create_idt();
2021-07-14 19:32:15 +00:00
load_idt();
}