diff options
author | Jon Santmyer <jon@jonsantmyer.com> | 2024-03-11 21:30:31 -0400 |
---|---|---|
committer | Jon Santmyer <jon@jonsantmyer.com> | 2024-03-11 21:30:31 -0400 |
commit | d1ff7bcc91886626dc9060ec5fb67ee102ab7c1d (patch) | |
tree | 8f0b5cd8aad31089131785dc6e37b659490f9955 /arch/x86_64/idt.c | |
download | jove-kernel-d1ff7bcc91886626dc9060ec5fb67ee102ab7c1d.tar.gz jove-kernel-d1ff7bcc91886626dc9060ec5fb67ee102ab7c1d.tar.bz2 jove-kernel-d1ff7bcc91886626dc9060ec5fb67ee102ab7c1d.zip |
usermode capable kernel with logging syscall
Diffstat (limited to 'arch/x86_64/idt.c')
-rw-r--r-- | arch/x86_64/idt.c | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/arch/x86_64/idt.c b/arch/x86_64/idt.c new file mode 100644 index 0000000..567dead --- /dev/null +++ b/arch/x86_64/idt.c @@ -0,0 +1,70 @@ +#include "tables.h" +#include "cpu.h" +#include "lib/jove.h" +#include "io/log.h" + +PAGEALIGN +static struct InterruptTrapGate s_idtd[48]; +static struct InterruptState *(*s_int_handlers[48])(struct Registers*); +static struct XDTR s_idtr = { + .length = sizeof(s_idtd) - 1, + .address = (uintptr_t)&s_idtd +}; + +uint64_t __isr_err; +uint64_t __isr_num; + +struct Registers* +irq_handle(struct Registers *state) +{ + if(__isr_num < 48) { + if(s_int_handlers[__isr_num] != NULL) { + s_int_handlers[__isr_num](state); + return state; + } + } + klogf("Interrupt %i\nerror code %#016X\n", __isr_num, __isr_err); + klogf("IP: %#016X\n", state->ip); + klogf("AX: %#016X\n", state->ax); + klogf("BX: %#016X\n", state->bx); + klogf("CX: %#016X\n", state->cx); + klogf("DX: %#016X\n", state->dx); + klogf("SI: %#016X\n", state->si); + klogf("DI: %#016X\n", state->di); + klogf("BP: %#016X\n", state->bp); + klogf("R8: %#016X\n", state->r8); + klogf("R9: %#016X\n", state->r9); + klogf("R10: %#016X\n", state->r10); + klogf("R11: %#016X\n", state->r11); + klogf("R12: %#016X\n", state->r12); + klogf("R13: %#016X\n", state->r13); + klogf("R14: %#016X\n", state->r14); + klogf("R15: %#016X\n", state->r15); + kpanic("Unhandled exception\n"); + return state; +} + +extern void x86_64_lidt(struct XDTR *idtr); +void +x86_64_load_idt(void) +{ + extern uintptr_t __isr_stubs[22]; + for(int i = 0; i < 22; i++) + { + uintptr_t base = __isr_stubs[i]; + klogf("INT %2i : %#016X\n", i, base); + s_idtd[i] = (struct InterruptTrapGate){ + .base_0_15 = (base & 0xFFFF), + .segment_selector = 0x10, + .ist = 0, + .zero_0 = 0, + .type = 0xE, + .zero_1 = 0, + .dpl = 0, + .p = 1, + .base_16_31 = (base >> 16) & 0xFFFF, + .base_32_63 = (base >> 32) & 0xFFFFFFFF + }; + } + x86_64_lidt(&s_idtr); +} |