From 29e3c5303d8d5b44d09ee010587f3c61daebb444 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Mon, 18 Apr 2022 20:23:54 +0200 Subject: [PATCH] Wtf is happening --- drivers/vga.c | 13 +++++++++++-- drivers/vga.h | 1 + kernel/idt.c | 17 +++++++++++------ kernel/idt.h | 4 +--- kernel/isr.asm | 4 +++- kernel/kernel.c | 23 +++++++++++++---------- 6 files changed, 40 insertions(+), 22 deletions(-) diff --git a/drivers/vga.c b/drivers/vga.c index cedf3af..64a80f6 100644 --- a/drivers/vga.c +++ b/drivers/vga.c @@ -69,10 +69,19 @@ void print(char* str, int attribute_byte) { cursor_col += strlen(str); } +void new_line() { + cursor_row++; + cursor_col = 0; +} + void println(char* str, int attribute_byte) { + if( cursor_row > MAX_ROWS ) { + set_cursor_pos(0, MAX_ROWS); + println(str, attribute_byte); + return; + } print(str, attribute_byte); - cursor_row++; // Increment to next y-pos (newline) - cursor_col = 0; + new_line(); } void printint(int i, int attribute_byte) { diff --git a/drivers/vga.h b/drivers/vga.h index 2a7bc20..cfa90e6 100644 --- a/drivers/vga.h +++ b/drivers/vga.h @@ -20,6 +20,7 @@ void clear_row(unsigned int row); void set_cursor_pos(); void print(); void println(); +void new_line(); void printint(int i, int attribute_byte); void printalign(char* str, int attribute_byte, enum align alignment); void vga_init(); diff --git a/kernel/idt.c b/kernel/idt.c index c1d6873..8d8244e 100644 --- a/kernel/idt.c +++ b/kernel/idt.c @@ -18,13 +18,18 @@ static idt_entry IDT[IDT_MAX_DESCS]; static idtr IDTR; void exception_handler() { - __asm__ __volatile__("cli; hlt"); -} + uint* debug_ptr = 0xe222; + uint8 debug = *debug_ptr; + + char* buf; + + new_line(); + print("Exception: ", INT_COLOR); + + buf = itoa(debug, buf, 10); + println(buf, 0x0f); -void interupt_handler() { - __asm__("pusha"); - // handle stuff - __asm__("popa; leave; iret"); + //__asm__ __volatile__("cli; hlt"); } void idt_set_desc(uint8 idx, void* isr, uint8 flags) { diff --git a/kernel/idt.h b/kernel/idt.h index 3655d42..f66c3ed 100644 --- a/kernel/idt.h +++ b/kernel/idt.h @@ -1,12 +1,10 @@ #include "../lib/types.h" #define IDT_MAX_DESCS 256 +#define INT_COLOR 0x08 __attribute__((noreturn)) void exception_handler(); -__attribute__((noreturn)) -void interupt_handler(); - void idt_set_desc(uint8, void*, uint8); void idt_init(); diff --git a/kernel/isr.asm b/kernel/isr.asm index 6f0891d..500c9b6 100644 --- a/kernel/isr.asm +++ b/kernel/isr.asm @@ -1,13 +1,15 @@ -; osdev crap +isr_debug_ptr equ 0xe222 %macro isr_err_stub 1 isr_stub_%+%1: + mov [isr_debug_ptr], byte %1 call exception_handler iret %endmacro %macro isr_no_err_stub 1 isr_stub_%+%1: + mov [isr_debug_ptr], byte %1 call exception_handler iret %endmacro diff --git a/kernel/kernel.c b/kernel/kernel.c index 80a8b1e..9f53d9f 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -1,6 +1,7 @@ #include "kernel.h" void print_kernel_motd() { + set_cursor_pos(0, 0); printalign(" ___ ____ ", BANNER_COLOR, MIDDLE); printalign(" ___ / _ \\/ ___| ", BANNER_COLOR, MIDDLE); printalign(" / _ \\ | | \\___ \\ ", BANNER_COLOR, MIDDLE); @@ -50,15 +51,6 @@ void print_kernel_stats() { buf = itoa(MAX_ROWS, buf, 10); println(buf, DEFAULT_COLOR); - uint i = 0; - set_cursor_pos(0, 9); - printalign("[Ticks since boot]", 0xf0, MIDDLE); - while(true) { - set_cursor_pos(0, 10); - buf = itoa(i, buf, 10); - printalign(buf, 0x0f, MIDDLE); - ++i; - } } void kernel_init() { @@ -73,5 +65,16 @@ void kernel_init() { clear_screen(); print_kernel_motd(); - print_kernel_stats(); + + char* buf; + uint i = 0; + set_cursor_pos(0, 9); + printalign("[Ticks since boot]", 0xf0, MIDDLE); + while(true) { + set_cursor_pos(0, 10); + buf = itoa(i, buf, 10); + printalign(buf, 0x0f, MIDDLE); + ++i; + } + //print_kernel_stats(); }