diff options
author | Marvin Borner | 2019-10-18 22:28:39 +0200 |
---|---|---|
committer | Marvin Borner | 2019-10-18 22:28:39 +0200 |
commit | 00761c54b2a41007e611a2470669b334618152b9 (patch) | |
tree | 8aecb5d5d7203af4aad819803280a239daf60c98 /src | |
parent | 17c6b30949ce7d4a293862ec8f9b873e17fe0cd8 (diff) |
Improved error logging and debugging possibilities
Diffstat (limited to 'src')
-rw-r--r-- | src/kernel/interrupts/isr.c | 21 | ||||
-rw-r--r-- | src/kernel/paging/paging.c | 25 | ||||
-rw-r--r-- | src/kernel/system.h | 5 |
3 files changed, 23 insertions, 28 deletions
diff --git a/src/kernel/interrupts/isr.c b/src/kernel/interrupts/isr.c index d4f2e3d..b615816 100644 --- a/src/kernel/interrupts/isr.c +++ b/src/kernel/interrupts/isr.c @@ -145,9 +145,28 @@ const char *exception_messages[] = { "Reserved" }; -// Master exception handler - halt via endless loop +// Master exception/interrupt/fault handler - halt via panic void fault_handler(struct regs *r) { if (r->int_no < 32) { + uint32_t faulting_address; + asm volatile("mov %%cr2, %0" : "=r" (faulting_address)); + + serial_write("\n[DEBUG]\nEIP: "); + serial_write_hex(r->eip); + serial_write("\nEAX: "); + serial_write_hex(r->eax); + serial_write("\nEBX: "); + serial_write_hex(r->ebx); + serial_write("\nECX: "); + serial_write_hex(r->ecx); + serial_write("\nEDX: "); + serial_write_hex(r->edx); + serial_write("\nFaulting address: "); + serial_write_hex(faulting_address); + serial_write("\nError flags: "); + serial_write_hex(r->eflags); + serial_write("\nError code: "); + serial_write_hex(r->err_code); char *message = (char *) exception_messages[r->int_no]; strcat(message, " Exception"); panic(message); diff --git a/src/kernel/paging/paging.c b/src/kernel/paging/paging.c index 1712f7e..0b7428e 100644 --- a/src/kernel/paging/paging.c +++ b/src/kernel/paging/paging.c @@ -98,11 +98,11 @@ void initialise_paging() { for (i = KHEAP_START; i < KHEAP_START + KHEAP_INITIAL_SIZE; i += 0x1000) alloc_frame(get_page(i, 1, kernel_directory), 0, 0); - irq_install_handler(14, page_fault); switch_page_directory(kernel_directory); kheap = create_heap(KHEAP_START, KHEAP_START + KHEAP_INITIAL_SIZE, 0xCFFFF000, 0, 0); current_directory = clone_directory(kernel_directory); switch_page_directory(current_directory); + serial_write("Paging init successful!\n"); } void disable_paging() { @@ -143,29 +143,6 @@ page_t *get_page(uint32_t address, int make, page_directory_t *dir) { } } -void page_fault(struct regs *r) { - uint32_t faulting_address; - asm volatile("mov %%cr2, %0" : "=r" (faulting_address)); - - int present = !(r->err_code & 0x1); - int rw = r->err_code & 0x2; - int us = r->err_code & 0x4; - int reserved = r->err_code & 0x8; - // int id = r->err_code & 0x10; - - serial_write("Page fault! ( "); - if (present) serial_write("present "); - if (rw) serial_write("read-only "); - if (us) serial_write("user-mode "); - if (reserved) serial_write("reserved "); - serial_write(") at 0x"); - serial_write_hex(faulting_address); - serial_write(" - EIP: "); - serial_write_hex(r->eip); - serial_write("\n"); - panic("Page fault"); -} - static page_table_t *clone_table(page_table_t *src, uint32_t *physAddr) { page_table_t *table = (page_table_t *) kmalloc_ap(sizeof(page_table_t), physAddr); memory_set(table, 0, sizeof(page_directory_t)); diff --git a/src/kernel/system.h b/src/kernel/system.h index 8fe7296..363b073 100644 --- a/src/kernel/system.h +++ b/src/kernel/system.h @@ -120,10 +120,9 @@ static inline void panic(char *msg) { asm volatile ("cli"); terminal_set_color(4); kernel_time(); - terminal_write_string("PANIC: "); - terminal_write_string(msg); - terminal_write_string(" - System Halted!"); + serial_write("PANIC: "); serial_write(msg); + serial_write(" - System Halted!\n"); loop: asm volatile ("hlt"); goto loop; |