diff options
author | Danny Holman <dholman@gymli.xyz> | 2021-08-30 08:26:05 -0500 |
---|---|---|
committer | Danny Holman <dholman@gymli.xyz> | 2021-08-30 08:26:05 -0500 |
commit | 7bf2c634fdb55d67affe74a2ed0a157610308942 (patch) | |
tree | c8a0d7bbc1b03669e10a8b18d6b453708e099378 /arch/i386/boot/idt.c | |
parent | 8cd620d25f31c4e0a87d6099accd9915e93a5815 (diff) |
i386: create idt.c and isr.s
Create files that add IDT support for i386.
Signed-off-by: Danny Holman <dholman@gymli.xyz>
Diffstat (limited to 'arch/i386/boot/idt.c')
-rw-r--r-- | arch/i386/boot/idt.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/arch/i386/boot/idt.c b/arch/i386/boot/idt.c new file mode 100644 index 0000000..752b679 --- /dev/null +++ b/arch/i386/boot/idt.c @@ -0,0 +1,50 @@ +#include <kernel/io.h> +#include <stdint.h> + +struct idt_entry { + uint16_t isr_low; + uint16_t kernel_cs; + uint8_t reserved; + uint8_t attributes; + uint16_t isr_high; +} __attribute__((packed)); + +struct idt_ptr { + uint16_t limit; + uint32_t base; +} __attribute__((packed)); + +__attribute__((aligned(0x10))) +static struct idt_entry idt[256]; +static struct idt_ptr idtr; + +__attribute__((noreturn)) +void exception_handler(int in) { + kprintf("EXCEPTION %d CAUGHT\n", in); +} + +extern void* isr_stub_table[]; + +void idt_set_descriptor(uint8_t vector, void *isr, uint8_t flags) { + struct idt_entry *desc = &idt[vector]; + + desc->isr_low = (uint32_t)isr & 0xFFFF; + desc->kernel_cs = 0x08; + desc->attributes = flags; + desc->isr_high = (uint32_t)isr >> 16; + desc->reserved = 0; +} + +void idt_install(void) { + idtr.base = (uintptr_t)&idt[0]; + idtr.limit = (uint16_t)sizeof(struct idt_entry) * 256 - 1; + + for (uint8_t vector = 0; vector < 32; vector++) { + idt_set_descriptor(vector, isr_stub_table[vector], 0x8E); + isr_stub_table[vector] = 1; + } + + __asm__ volatile("lidt %0" : : "memory"(idtr)); + __asm__ volatile("sti"); + kprintf("Interrupts on\n"); +} |