From 4b0bd4d1334f6b8f892f424d2555a68904803b00 Mon Sep 17 00:00:00 2001 From: Greg Bowne Date: Sun, 8 Oct 2023 18:32:10 -0700 Subject: [PATCH] fixing more of the mess --- CMakeLists.txt | 1 + linker.ld | 6 +++++- src/kernel/arch/x86/gdt.c | 19 ++----------------- src/kernel/arch/x86/idt.c | 5 +++-- src/kernel/arch/x86/isr.c | 11 ++--------- src/kernel/arch/x86/isr.h | 12 +++++++----- 6 files changed, 20 insertions(+), 34 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 40c9a84..7f11616 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,6 +68,7 @@ target_link_libraries(ClassicOS PRIVATE) set(CMAKE_C_COMPILER gcc) set(CMAKE_LINKER ld) set(CMAKE_EXE_LINKER_FLAGS "-g -s") +set(CMAKE_LINK_FLAGS "${CMAKE_LINK_FLAGS} -e kernel_main") set(CMAKE_CXX_FLAGS "-g -Wall") set(CMAKE_C_FLAGS "-g -Wall -m32") set(CMAKE_BUILD_TYPE Debug) diff --git a/linker.ld b/linker.ld index 118455f..6f90a30 100644 --- a/linker.ld +++ b/linker.ld @@ -1,4 +1,4 @@ -ENTRY(_start) +ENTRY(kernel_main) SECTIONS { . = 0x100000; @@ -7,6 +7,10 @@ SECTIONS { *(.text) } + .rodata : { + *(.rodata) + } + .data : { *(.data) } diff --git a/src/kernel/arch/x86/gdt.c b/src/kernel/arch/x86/gdt.c index 3a49d64..ed5f819 100644 --- a/src/kernel/arch/x86/gdt.c +++ b/src/kernel/arch/x86/gdt.c @@ -81,7 +81,7 @@ void gdt_init() // Exception handlers extern void divide_error(); -extern void page_fault(); +extern void page_fault(struct idt_regs *regs); extern void general_protection_fault(); extern void double_fault(); @@ -91,27 +91,12 @@ extern void timer(); extern void keyboard(); extern void device(); -// ISR table -void (*isr_table[ISR_TABLE_SIZE])(void) = {0}; - // Register an ISR -void isr_register(uint8_t num, void (*handler)(void)) +void isr_register(uint8_t num, void (*handler)(struct idt_regs *)) { isr_table[num] = handler; } -// ISR handler -void isr_handler(struct idt_regs *regs) -{ - void (*handler)(void) = isr_table[regs->int_no]; - - handler = isr_table[regs->int_no]; - if (handler) - { - handler(); - } -} - // Initialize the ISR void isr_init() { diff --git a/src/kernel/arch/x86/idt.c b/src/kernel/arch/x86/idt.c index 1cf09f6..b6af69e 100644 --- a/src/kernel/arch/x86/idt.c +++ b/src/kernel/arch/x86/idt.c @@ -1,4 +1,5 @@ #include "idt.h" +#include "isr.h" #include #include #include @@ -21,7 +22,7 @@ const struct idt_ptr idtp = {sizeof(idt) - 1, idt}; // Exception handlers extern void divide_error_handler(); -extern void page_fault_handler(); +extern void page_fault(struct idt_regs *regs); extern void general_protection_fault_handler(); extern void double_fault_handler(); @@ -57,7 +58,7 @@ void idt_init() // Set up exception handlers idt_set_gate(0, divide_error_handler, 0x08, 0x8E); - idt_set_gate(14, page_fault_handler, 0x08, 0x8E); + idt_set_gate(14, page_fault, 0x08, 0x8E); idt_set_gate(13, general_protection_fault_handler, 0x08, 0x8E); idt_set_gate(8, double_fault_handler, 0x08, 0x8E); diff --git a/src/kernel/arch/x86/isr.c b/src/kernel/arch/x86/isr.c index 5a348d9..5d508a6 100644 --- a/src/kernel/arch/x86/isr.c +++ b/src/kernel/arch/x86/isr.c @@ -18,17 +18,10 @@ void dummy_isr(struct isr_regs *regs) } // ISR table -void (*isr_table[256])(struct isr_regs *regs) = { - // initialize the dummy isr_table - [TIMER_INTERRUPT] = dummy_isr, // Timer interrupt - [KEYBOARD_INTERRUPT] = dummy_isr, // Keyboard interrupt - [NETWORK_INTERRUPT] = dummy_isr, // Network interrupt - [DISK_INTERRUPT] = dummy_isr, // Disk interrupt - [SERIAL_PORT_INTERRUPT] = dummy_isr // Serial port interrupt -}; +extern void (*isr_table[256])(struct isr_regs *regs); // Register an ISR -void isr_register(uint8_t num, void (*handler)(struct isr_regs *regs)) +extern void isr_register(uint8_t num, void (*handler)(struct isr_regs *regs)) { isr_table[num] = handler; } diff --git a/src/kernel/arch/x86/isr.h b/src/kernel/arch/x86/isr.h index 0b98787..989c56b 100644 --- a/src/kernel/arch/x86/isr.h +++ b/src/kernel/arch/x86/isr.h @@ -5,11 +5,13 @@ struct isr_regs { - uint32_t gs, fs, es, ds; // Segment selectors - uint32_t edi, esi, ebp, esp; // Pushed by pusha instruction - uint32_t ebx, edx, ecx, eax; // Pushed by the interrupt handler - uint32_t int_no, err_code; // Interrupt number and error code (if applicable) - uint32_t eip, cs, eflags, esp_at_signal; // Pushed by the processor automatically + uint32_t gs, fs, es, ds; // Segment selectors + uint32_t edi, esi, ebp, esp; // Pushed by pusha instruction + uint32_t ebx, edx, ecx, eax; // Pushed by the interrupt handler + uint32_t int_no, + err_code; // Interrupt number and error code (if applicable) + uint32_t eip, cs, eflags, + esp_at_signal; // Pushed by the processor automatically }; // Structure for storing register values during an ISR