From 2720d0ddffc85818036e7d1c06ab965da9a40886 Mon Sep 17 00:00:00 2001 From: Ry Date: Wed, 26 Oct 2022 21:50:29 -0700 Subject: [PATCH] Ignore the pushed value in interrupts and exceptions Also handle more types of exceptions. *** First commit compatible with the C rewrite!! *** --- audio.asm | 4 ++++ exception.asm | 26 ++++++++++++++++++++++++++ main.asm | 11 ++++++++++- monitor/vsync.asm | 1 + panic.asm | 1 - vsync.asm | 1 + 6 files changed, 42 insertions(+), 2 deletions(-) diff --git a/audio.asm b/audio.asm index 3683d73..d167456 100644 --- a/audio.asm +++ b/audio.asm @@ -158,6 +158,7 @@ stop_audio: ret refill_buffer_0: + add rsp, 4 push r0 push r1 push r31 @@ -181,6 +182,7 @@ refill_buffer_0_loop: reti refill_buffer_1: + add rsp, 4 push r0 push r1 push r31 @@ -204,6 +206,7 @@ refill_buffer_1_loop: reti refill_buffer_2: + add rsp, 4 push r0 push r1 push r31 @@ -227,6 +230,7 @@ refill_buffer_2_loop: reti refill_buffer_3: + add rsp, 4 push r0 push r1 push r31 diff --git a/exception.asm b/exception.asm index 78b3dfb..4b138a6 100644 --- a/exception.asm +++ b/exception.asm @@ -1,5 +1,19 @@ ; exception handling routines +; called if a divide by zero occurs +; does not return, calls panic +system_div_zero_handler: + mov r0, system_div_zero_str + jmp panic +system_div_zero_str: data.str "Divide by zero" data.8 10 data.8 0 + +; called if an invalid opcode is executed +; does not return, calls panic +system_invalid_op_handler: + mov r0, system_invalid_op_str + jmp panic +system_invalid_op_str: data.str "Invalid opcode" data.8 10 data.8 0 + ; called if a page fault occurs ; does not return, calls panic system_page_fault_handler: @@ -7,3 +21,15 @@ system_page_fault_handler: pop r1 jmp panic system_page_fault_str: data.str "Page fault at virtual address r1" data.8 10 data.8 0 + +; called upon execution of a `brk` instruction +system_breakpoint_handler: + add rsp, 4 + push r0 + + mov r0, system_breakpoint_str + call debug_print + + pop r0 + reti +system_breakpoint_str: data.str "Breakpoint reached!" data.8 10 data.8 0 diff --git a/main.asm b/main.asm index 9367ce0..b9827f5 100644 --- a/main.asm +++ b/main.asm @@ -4,7 +4,7 @@ const FOX32ROM_VERSION_MAJOR: 0 const FOX32ROM_VERSION_MINOR: 5 -const FOX32ROM_VERSION_PATCH: 0 +const FOX32ROM_VERSION_PATCH: 2 const SYSTEM_STACK: 0x01FFF800 const BACKGROUND_COLOR: 0xFF674764 @@ -39,12 +39,21 @@ entry_seed_done: ; set the interrupt vector for interrupt 0xFF - vsync mov [0x000003FC], system_vsync_handler + ; set the exception vector for exception 0x00 - divide by zero + mov [0x00000400], system_div_zero_handler + + ; set the exception vector for exception 0x01 - invalid opcode + mov [0x00000404], system_invalid_op_handler + ; set the exception vector for exception 0x02 - page fault read mov [0x00000408], system_page_fault_handler ; set the exception vector for exception 0x03 - page fault write mov [0x0000040C], system_page_fault_handler + ; set the exception vector for exception 0x04 - breakpoint + mov [0x0000040C], system_breakpoint_handler + ; enable interrupts ise diff --git a/monitor/vsync.asm b/monitor/vsync.asm index b03a622..e4ca087 100644 --- a/monitor/vsync.asm +++ b/monitor/vsync.asm @@ -1,6 +1,7 @@ ; debug monitor vsync routine monitor_vsync_handler: + add rsp, 4 push r0 push r1 push r2 diff --git a/panic.asm b/panic.asm index ea23e98..c1ab6fd 100644 --- a/panic.asm +++ b/panic.asm @@ -6,7 +6,6 @@ ; outputs: ; none, does not return panic: - brk cmp r0, 0 ifz mov r0, panic_string call debug_print diff --git a/vsync.asm b/vsync.asm index 58cc6fc..62a6f24 100644 --- a/vsync.asm +++ b/vsync.asm @@ -1,6 +1,7 @@ ; vsync interrupt routine system_vsync_handler: + add rsp, 4 push r0 push r1 push r2