From 20b23b7f7fc9f30c74c8ff98ca3112893ba04a58 Mon Sep 17 00:00:00 2001 From: Polprzewodnikowy Date: Sun, 23 Jan 2022 01:40:33 +0100 Subject: [PATCH] small exception changes --- sw/n64/src/error.c | 2 -- sw/n64/src/exception.S | 6 ++-- sw/n64/src/exception.c | 50 ++------------------------------- sw/n64/src/exception_regs.h | 55 +++++++++++++++++++++++++++++++++++++ sw/n64/src/interrupt.c | 4 +-- 5 files changed, 62 insertions(+), 55 deletions(-) create mode 100644 sw/n64/src/exception_regs.h diff --git a/sw/n64/src/error.c b/sw/n64/src/error.c index c76c080..027bfe9 100644 --- a/sw/n64/src/error.c +++ b/sw/n64/src/error.c @@ -8,6 +8,4 @@ void error_display (const char *fmt, ...) { va_start(args, fmt); EXCEPTION_TRIGGER(TRIGGER_CODE_ERROR); va_end(args); - - while (1); } diff --git a/sw/n64/src/exception.S b/sw/n64/src/exception.S index c7caa23..307ef10 100644 --- a/sw/n64/src/exception.S +++ b/sw/n64/src/exception.S @@ -36,7 +36,7 @@ #define K1_OFFSET (216) #define GP_OFFSET (224) #define SP_OFFSET (232) -#define FP_OFFSET (240) +#define S8_OFFSET (240) #define RA_OFFSET (248) #define C0_STATUS_OFFSET (256) #define C0_CAUSE_OFFSET (260) @@ -75,7 +75,7 @@ exception_handler: sd $t9, T9_OFFSET($k0) sd $gp, GP_OFFSET($k0) sd $sp, SP_OFFSET($k0) - sd $fp, FP_OFFSET($k0) + sd $s8, S8_OFFSET($k0) sd $ra, RA_OFFSET($k0) .set at @@ -141,7 +141,7 @@ exception_restore: ld $t9, T9_OFFSET($k0) ld $gp, GP_OFFSET($k0) ld $sp, SP_OFFSET($k0) - ld $fp, FP_OFFSET($k0) + ld $s8, S8_OFFSET($k0) ld $ra, RA_OFFSET($k0) .set at diff --git a/sw/n64/src/exception.c b/sw/n64/src/exception.c index c965c05..7a97283 100644 --- a/sw/n64/src/exception.c +++ b/sw/n64/src/exception.c @@ -1,6 +1,7 @@ #include #include #include "exception.h" +#include "exception_regs.h" #include "font.h" #include "io.h" #include "sc64.h" @@ -8,53 +9,6 @@ #include "vr4300.h" -typedef union { - uint64_t u64; - struct { - uint32_t u32_h; - uint32_t u32; - }; -} uint64_32_t; - -typedef struct { - uint64_32_t zr; - uint64_32_t at; - uint64_32_t v0; - uint64_32_t v1; - uint64_32_t a0; - uint64_32_t a1; - uint64_32_t a2; - uint64_32_t a3; - uint64_32_t t0; - uint64_32_t t1; - uint64_32_t t2; - uint64_32_t t3; - uint64_32_t t4; - uint64_32_t t5; - uint64_32_t t6; - uint64_32_t t7; - uint64_32_t s0; - uint64_32_t s1; - uint64_32_t s2; - uint64_32_t s3; - uint64_32_t s4; - uint64_32_t s5; - uint64_32_t s6; - uint64_32_t s7; - uint64_32_t t8; - uint64_32_t t9; - uint64_32_t k0; - uint64_32_t k1; - uint64_32_t gp; - uint64_32_t sp; - uint64_32_t fp; - uint64_32_t ra; - uint32_t sr; - uint32_t cr; - uint64_32_t epc; -} exception_t; - - #define EXCEPTION_INTERRUPT (0) #define EXCEPTION_SYSCALL (8) @@ -271,7 +225,7 @@ void exception_fatal_handler (uint32_t exception_code, uint32_t interrupt_mask, exception_print("s0: 0x%08lX s1: 0x%08lX s2: 0x%08lX s3: 0x%08lX\n", e->s0.u32, e->s1.u32, e->s2.u32, e->s3.u32); exception_print("s4: 0x%08lX s5: 0x%08lX s6: 0x%08lX s7: 0x%08lX\n", e->s4.u32, e->s5.u32, e->s6.u32, e->s7.u32); exception_print("t8: 0x%08lX t9: 0x%08lX k0: 0x%08lX k1: 0x%08lX\n", e->t8.u32, e->t9.u32, e->k0.u32, e->k1.u32); - exception_print("gp: 0x%08lX sp: 0x%08lX fp: 0x%08lX ra: 0x%08lX\n\n", e->gp.u32, e->sp.u32, e->fp.u32, e->ra.u32); + exception_print("gp: 0x%08lX sp: 0x%08lX s8: 0x%08lX ra: 0x%08lX\n\n", e->gp.u32, e->sp.u32, e->s8.u32, e->ra.u32); if (exception_code == EXCEPTION_INTERRUPT) { if (interrupt_mask & INTERRUPT_MASK_TIMER) { diff --git a/sw/n64/src/exception_regs.h b/sw/n64/src/exception_regs.h new file mode 100644 index 0000000..2710428 --- /dev/null +++ b/sw/n64/src/exception_regs.h @@ -0,0 +1,55 @@ +#ifndef EXCEPTION_REGS_H__ +#define EXCEPTION_REGS_H__ + + +#include + + +typedef union { + uint64_t u64; + struct { + uint32_t u32_h; + uint32_t u32; + }; +} uint64_32_t; + +typedef struct { + uint64_32_t zr; + uint64_32_t at; + uint64_32_t v0; + uint64_32_t v1; + uint64_32_t a0; + uint64_32_t a1; + uint64_32_t a2; + uint64_32_t a3; + uint64_32_t t0; + uint64_32_t t1; + uint64_32_t t2; + uint64_32_t t3; + uint64_32_t t4; + uint64_32_t t5; + uint64_32_t t6; + uint64_32_t t7; + uint64_32_t s0; + uint64_32_t s1; + uint64_32_t s2; + uint64_32_t s3; + uint64_32_t s4; + uint64_32_t s5; + uint64_32_t s6; + uint64_32_t s7; + uint64_32_t t8; + uint64_32_t t9; + uint64_32_t k0; + uint64_32_t k1; + uint64_32_t gp; + uint64_32_t sp; + uint64_32_t s8; + uint64_32_t ra; + uint32_t sr; + uint32_t cr; + uint64_32_t epc; +} exception_t; + + +#endif diff --git a/sw/n64/src/interrupt.c b/sw/n64/src/interrupt.c index 9ebc2f9..95d6a47 100644 --- a/sw/n64/src/interrupt.c +++ b/sw/n64/src/interrupt.c @@ -1,6 +1,6 @@ -#include "io.h" +#include "exception_regs.h" -void exception_interrupt_handler (uint32_t exception_code, uint32_t interrupt_mask) { +void exception_interrupt_handler (uint32_t exception_code, uint32_t interrupt_mask, exception_t *e) { while (1); }