void _general_exception_handler( unsigned int cause, unsigned int status ) { uint32_t excep_code; uint32_t excep_addr; excep_code = (cause & 0x0000007C) >> 2; excep_addr = __builtin_mfc0(_CP0_EPC, _CP0_EPC_SELECT); if ((cause & 0x80000000) != 0) { excep_addr += 4; } while (1); }
/* enable this if ReadCoreTimer and WriteCoreTimer are missing */ unsigned int ReadCoreTimer(void) { unsigned int timer; timer = __builtin_mfc0(9, 0); return timer; }
typedef enum { EXCEP_IRQ = 0, // interrupt EXCEP_ADDR_ERR_L = 4, // address error exception (load or ifetch) EXCEP_ADDR_ERR_S, // address error exception (store) EXCEP_BUS_ERR_F, // bus error (ifetch) EXCEP_BUS_ERR_LS, // bus error (load/store) EXCEP_SYSCALL, // syscall EXCEP_BREAKPOINT, // breakpoint EXCEP_RES_OPCODE, // reserved instruction EXCEP_CP_UNUSE, // coprocessor unusable EXCEP_OVERFLOW, // arithmetic overflow EXCEP_TRAP, // trap (possible divide by zero) EXCEP_IS1 = 16, // implementation specfic 1 EXCEP_CEU, // CorExtend Unuseable EXCEP_C2E // coprocessor 2 } _EXCEP_CODE; volatile _EXCEP_CODE _excep_code; volatile void *_excep_addr; void _general_exception_handler (void) { _excep_code = (__builtin_mfc0(13, 0) & 0x0000007C) >> 2; _excep_addr = (void*)__builtin_mfc0(14, 0); //for (;;); }