From c4bae42dd97bb29de2a9306afb1c37f48250ba4f Mon Sep 17 00:00:00 2001 From: shockrahwow Date: Sun, 27 Oct 2019 22:08:21 -0700 Subject: [PATCH] putch + broken interrupt handlers int handlers only break when ran --- interrupts.c | 22 +++++++++++----------- kernel.c | 3 +++ stlio.c | 3 +++ stlio.h | 1 + tests.c | 26 +++++++++++++++++++------- tests.h | 1 + 6 files changed, 38 insertions(+), 18 deletions(-) diff --git a/interrupts.c b/interrupts.c index ac65cda..4f81616 100644 --- a/interrupts.c +++ b/interrupts.c @@ -79,11 +79,10 @@ void setup_idt_entry(u32 t_idx, u32 base, u16 sel, u8 type_attrs) { void int_keyboard(struct cpu_reg_state* cpu) { // Get the keycode from the serial buffer - u8 buf[5]; - memset(buf, 0x00, 5); - u8 scancode = serial_read_buffer(0x60); - buf[0] = scancode; - printf((char*)buf); + char code = serial_read_buffer(0x60); + if((u8)code < 0x80 || (u8)code > 0x1f) { + putch(code); + } serial_pic_ack(cpu->int_no); } @@ -91,11 +90,12 @@ void int_keyboard(struct cpu_reg_state* cpu) { void interrupt_handler(struct cpu_reg_state cpu) { // treating things on the stack like it were a cpu_reg_state // NOTE: dummy stuff to stop gcc from complaining atm - switch(cpu.int_no) { - case(i_Keyboard): { - // keyboard interrupt handler gets the stuff now - int_keyboard(&cpu); - } + if(cpu.int_no < 32) { + printf("int response is:\n"); + printf(err_msg[cpu.int_no]); + } + else { + printf("Unhandled exception"); } return; } @@ -120,7 +120,7 @@ void init_idt() { setup_idt_entry(8,(u32)no_err_handler_9,0x08, 0x8e); setup_idt_entry(9,(u32)err_code_handler_10,0x08, 0x8e); - setup_idt_entry(0,(u32)err_code_handler_11,0x08, 0x8e); + setup_idt_entry(10,(u32)err_code_handler_11,0x08, 0x8e); setup_idt_entry(11,(u32)err_code_handler_12,0x08, 0x8e); setup_idt_entry(12,(u32)err_code_handler_13,0x08, 0x8e); setup_idt_entry(13,(u32)err_code_handler_14,0x08, 0x8e); diff --git a/kernel.c b/kernel.c index 19d829d..8dd8e36 100644 --- a/kernel.c +++ b/kernel.c @@ -2,10 +2,13 @@ #include "types.h" #include "tests.h" #include "interrupts.h" +#include "stlio.h" #include "gdt.h" void kinit() { + printf("setting up gdt\n"); gdt_configure(); + printf("setting idt\n"); init_idt(); test_dispatcher(); } diff --git a/stlio.c b/stlio.c index 73e0431..941dccb 100644 --- a/stlio.c +++ b/stlio.c @@ -49,3 +49,6 @@ void printf(const char* fmt) { } } +void putch(const char c) { + write_char(c); +} \ No newline at end of file diff --git a/stlio.h b/stlio.h index a99400b..2a37b61 100644 --- a/stlio.h +++ b/stlio.h @@ -11,3 +11,4 @@ u32 read(const u32); void printf(const char*); +void putch(const char); \ No newline at end of file diff --git a/tests.c b/tests.c index 9d16719..1474bed 100644 --- a/tests.c +++ b/tests.c @@ -3,17 +3,29 @@ #include "tests.h" #include "serial.h" -void test_write() { - clear_fb(); - char* msg1 = "Writing this to fbout\n"; - char* serial1 = "0123456789abcdef0123456789abcdef"; - char* msg2 = "serial write has finished"; +void divide_by_zero() { + // here we can test the divide by zero without gcc noticing + int x = 0; + int y = 5; + int z = y/x; + if(z) { + printf("hmm\n"); + } +} - printf(msg1); +void test_serial_write() { + char* serial1 = "0123456789abcdef0123456789abcdef"; serial_write(serial1, strlen(serial1)); - printf(msg2); + printf("serial test write finished\n"); +} + +void test_write() { + char* msg1 = "Writing to fbout\n"; + printf(msg1); } void test_dispatcher() { + clear_fb(); test_write(); + divide_by_zero(); } diff --git a/tests.h b/tests.h index a5389b5..eda0d5d 100644 --- a/tests.h +++ b/tests.h @@ -1,5 +1,6 @@ #include "types.h" #include "stlio.h" +void divide_by_zero(); void test_write(); void test_dispatcher();