From 45f18251a94801e0b36af590fd6a32a866c95817 Mon Sep 17 00:00:00 2001 From: antifallobst Date: Thu, 9 Feb 2023 13:32:51 +0100 Subject: [PATCH] fix (kernel): made GDT selctors an enum --- kernel/inc/platform/gdt.h | 9 +++++ kernel/inc/platform/interrupts.h | 2 + kernel/src/platform/interrupts.c | 66 ++++++++++++++++---------------- 3 files changed, 44 insertions(+), 33 deletions(-) diff --git a/kernel/inc/platform/gdt.h b/kernel/inc/platform/gdt.h index 420fa06..72a5104 100644 --- a/kernel/inc/platform/gdt.h +++ b/kernel/inc/platform/gdt.h @@ -18,6 +18,15 @@ #include "utils/stdtypes.h" +typedef enum { + GDT_SELECTOR_NULL = 0x00, + GDT_SELECTOR_KERNEL_CODE = 0x08, + GDT_SELECTOR_KERNEL_DATA = 0x10, + GDT_SELECTOR_USER_NULL = 0x18, + GDT_SELECTOR_USER_CODE = 0x20, + GDT_SELECTOR_USER_DATA = 0x28 +} gdt_selector_E; + typedef struct { uint16_t size; uint64_t offset; diff --git a/kernel/inc/platform/interrupts.h b/kernel/inc/platform/interrupts.h index 2587f7a..aec4a69 100644 --- a/kernel/inc/platform/interrupts.h +++ b/kernel/inc/platform/interrupts.h @@ -37,6 +37,8 @@ typedef struct { uint32_t ignore; } idt_descriptor_entry_T; +extern idt_register_T g_idt_register; + void idt_init(); #endif //NOX_INTERRUPTS_H diff --git a/kernel/src/platform/interrupts.c b/kernel/src/platform/interrupts.c index a69c76e..e1560e6 100644 --- a/kernel/src/platform/interrupts.c +++ b/kernel/src/platform/interrupts.c @@ -15,6 +15,7 @@ #include "platform/interrupts.h" #include "platform/cpu.h" +#include "platform/gdt.h" #include "platform/exceptions.h" #include "mm/page_frame.h" #include "utils/logger.h" @@ -81,38 +82,38 @@ void idt_init() { g_idt_register.offset = (uint64_t)pframe_request(); - idt_set_gate((void*)interrupt_stub_0x00, 0x00, IDT_ENTRY_INTR_GATE, 0x08); - idt_set_gate((void*)interrupt_stub_0x01, 0x01, IDT_ENTRY_INTR_GATE, 0x08); - idt_set_gate((void*)interrupt_stub_0x02, 0x02, IDT_ENTRY_INTR_GATE, 0x08); - idt_set_gate((void*)interrupt_stub_0x03, 0x03, IDT_ENTRY_INTR_GATE, 0x08); - idt_set_gate((void*)interrupt_stub_0x04, 0x04, IDT_ENTRY_INTR_GATE, 0x08); - idt_set_gate((void*)interrupt_stub_0x05, 0x05, IDT_ENTRY_INTR_GATE, 0x08); - idt_set_gate((void*)interrupt_stub_0x06, 0x06, IDT_ENTRY_INTR_GATE, 0x08); - idt_set_gate((void*)interrupt_stub_0x07, 0x07, IDT_ENTRY_INTR_GATE, 0x08); - idt_set_gate((void*)interrupt_stub_0x08, 0x08, IDT_ENTRY_INTR_GATE, 0x08); - idt_set_gate((void*)interrupt_stub_0x09, 0x09, IDT_ENTRY_INTR_GATE, 0x08); - idt_set_gate((void*)interrupt_stub_0x0A, 0x0A, IDT_ENTRY_INTR_GATE, 0x08); - idt_set_gate((void*)interrupt_stub_0x0B, 0x0B, IDT_ENTRY_INTR_GATE, 0x08); - idt_set_gate((void*)interrupt_stub_0x0C, 0x0C, IDT_ENTRY_INTR_GATE, 0x08); - idt_set_gate((void*)interrupt_stub_0x0D, 0x0D, IDT_ENTRY_INTR_GATE, 0x08); - idt_set_gate((void*)interrupt_stub_0x0E, 0x0E, IDT_ENTRY_INTR_GATE, 0x08); - idt_set_gate((void*)interrupt_stub_0x0F, 0x0F, IDT_ENTRY_INTR_GATE, 0x08); - idt_set_gate((void*)interrupt_stub_0x10, 0x10, IDT_ENTRY_INTR_GATE, 0x08); - idt_set_gate((void*)interrupt_stub_0x11, 0x11, IDT_ENTRY_INTR_GATE, 0x08); - idt_set_gate((void*)interrupt_stub_0x12, 0x12, IDT_ENTRY_INTR_GATE, 0x08); - idt_set_gate((void*)interrupt_stub_0x13, 0x13, IDT_ENTRY_INTR_GATE, 0x08); - idt_set_gate((void*)interrupt_stub_0x14, 0x14, IDT_ENTRY_INTR_GATE, 0x08); - idt_set_gate((void*)interrupt_stub_0x15, 0x15, IDT_ENTRY_INTR_GATE, 0x08); - idt_set_gate((void*)interrupt_stub_0x16, 0x16, IDT_ENTRY_INTR_GATE, 0x08); - idt_set_gate((void*)interrupt_stub_0x17, 0x17, IDT_ENTRY_INTR_GATE, 0x08); - idt_set_gate((void*)interrupt_stub_0x18, 0x18, IDT_ENTRY_INTR_GATE, 0x08); - idt_set_gate((void*)interrupt_stub_0x19, 0x19, IDT_ENTRY_INTR_GATE, 0x08); - idt_set_gate((void*)interrupt_stub_0x1A, 0x1A, IDT_ENTRY_INTR_GATE, 0x08); - idt_set_gate((void*)interrupt_stub_0x1B, 0x1B, IDT_ENTRY_INTR_GATE, 0x08); - idt_set_gate((void*)interrupt_stub_0x1C, 0x1C, IDT_ENTRY_INTR_GATE, 0x08); - idt_set_gate((void*)interrupt_stub_0x1D, 0x1D, IDT_ENTRY_INTR_GATE, 0x08); - idt_set_gate((void*)interrupt_stub_0x1E, 0x1E, IDT_ENTRY_INTR_GATE, 0x08); - idt_set_gate((void*)interrupt_stub_0x1F, 0x1F, IDT_ENTRY_INTR_GATE, 0x08); + idt_set_gate((void*)interrupt_stub_0x00, 0x00, IDT_ENTRY_INTR_GATE, GDT_SELECTOR_KERNEL_CODE); + idt_set_gate((void*)interrupt_stub_0x01, 0x01, IDT_ENTRY_INTR_GATE, GDT_SELECTOR_KERNEL_CODE); + idt_set_gate((void*)interrupt_stub_0x02, 0x02, IDT_ENTRY_INTR_GATE, GDT_SELECTOR_KERNEL_CODE); + idt_set_gate((void*)interrupt_stub_0x03, 0x03, IDT_ENTRY_INTR_GATE, GDT_SELECTOR_KERNEL_CODE); + idt_set_gate((void*)interrupt_stub_0x04, 0x04, IDT_ENTRY_INTR_GATE, GDT_SELECTOR_KERNEL_CODE); + idt_set_gate((void*)interrupt_stub_0x05, 0x05, IDT_ENTRY_INTR_GATE, GDT_SELECTOR_KERNEL_CODE); + idt_set_gate((void*)interrupt_stub_0x06, 0x06, IDT_ENTRY_INTR_GATE, GDT_SELECTOR_KERNEL_CODE); + idt_set_gate((void*)interrupt_stub_0x07, 0x07, IDT_ENTRY_INTR_GATE, GDT_SELECTOR_KERNEL_CODE); + idt_set_gate((void*)interrupt_stub_0x08, 0x08, IDT_ENTRY_INTR_GATE, GDT_SELECTOR_KERNEL_CODE); + idt_set_gate((void*)interrupt_stub_0x09, 0x09, IDT_ENTRY_INTR_GATE, GDT_SELECTOR_KERNEL_CODE); + idt_set_gate((void*)interrupt_stub_0x0A, 0x0A, IDT_ENTRY_INTR_GATE, GDT_SELECTOR_KERNEL_CODE); + idt_set_gate((void*)interrupt_stub_0x0B, 0x0B, IDT_ENTRY_INTR_GATE, GDT_SELECTOR_KERNEL_CODE); + idt_set_gate((void*)interrupt_stub_0x0C, 0x0C, IDT_ENTRY_INTR_GATE, GDT_SELECTOR_KERNEL_CODE); + idt_set_gate((void*)interrupt_stub_0x0D, 0x0D, IDT_ENTRY_INTR_GATE, GDT_SELECTOR_KERNEL_CODE); + idt_set_gate((void*)interrupt_stub_0x0E, 0x0E, IDT_ENTRY_INTR_GATE, GDT_SELECTOR_KERNEL_CODE); + idt_set_gate((void*)interrupt_stub_0x0F, 0x0F, IDT_ENTRY_INTR_GATE, GDT_SELECTOR_KERNEL_CODE); + idt_set_gate((void*)interrupt_stub_0x10, 0x10, IDT_ENTRY_INTR_GATE, GDT_SELECTOR_KERNEL_CODE); + idt_set_gate((void*)interrupt_stub_0x11, 0x11, IDT_ENTRY_INTR_GATE, GDT_SELECTOR_KERNEL_CODE); + idt_set_gate((void*)interrupt_stub_0x12, 0x12, IDT_ENTRY_INTR_GATE, GDT_SELECTOR_KERNEL_CODE); + idt_set_gate((void*)interrupt_stub_0x13, 0x13, IDT_ENTRY_INTR_GATE, GDT_SELECTOR_KERNEL_CODE); + idt_set_gate((void*)interrupt_stub_0x14, 0x14, IDT_ENTRY_INTR_GATE, GDT_SELECTOR_KERNEL_CODE); + idt_set_gate((void*)interrupt_stub_0x15, 0x15, IDT_ENTRY_INTR_GATE, GDT_SELECTOR_KERNEL_CODE); + idt_set_gate((void*)interrupt_stub_0x16, 0x16, IDT_ENTRY_INTR_GATE, GDT_SELECTOR_KERNEL_CODE); + idt_set_gate((void*)interrupt_stub_0x17, 0x17, IDT_ENTRY_INTR_GATE, GDT_SELECTOR_KERNEL_CODE); + idt_set_gate((void*)interrupt_stub_0x18, 0x18, IDT_ENTRY_INTR_GATE, GDT_SELECTOR_KERNEL_CODE); + idt_set_gate((void*)interrupt_stub_0x19, 0x19, IDT_ENTRY_INTR_GATE, GDT_SELECTOR_KERNEL_CODE); + idt_set_gate((void*)interrupt_stub_0x1A, 0x1A, IDT_ENTRY_INTR_GATE, GDT_SELECTOR_KERNEL_CODE); + idt_set_gate((void*)interrupt_stub_0x1B, 0x1B, IDT_ENTRY_INTR_GATE, GDT_SELECTOR_KERNEL_CODE); + idt_set_gate((void*)interrupt_stub_0x1C, 0x1C, IDT_ENTRY_INTR_GATE, GDT_SELECTOR_KERNEL_CODE); + idt_set_gate((void*)interrupt_stub_0x1D, 0x1D, IDT_ENTRY_INTR_GATE, GDT_SELECTOR_KERNEL_CODE); + idt_set_gate((void*)interrupt_stub_0x1E, 0x1E, IDT_ENTRY_INTR_GATE, GDT_SELECTOR_KERNEL_CODE); + idt_set_gate((void*)interrupt_stub_0x1F, 0x1F, IDT_ENTRY_INTR_GATE, GDT_SELECTOR_KERNEL_CODE); idt_load(&g_idt_register); log(LOG_INFO, "Interrupts initialized"); @@ -123,7 +124,6 @@ cpu_state_T* interrupts_handle(cpu_state_T* state) { return exception_handle(state); } - log(LOG_WARNING, "Non exception interrupt detected"); return state;