Improved test_exception_sim

This commit is contained in:
2022-09-10 08:46:54 +02:00
parent 29144e3aab
commit e5235ffb4a
2 changed files with 82 additions and 52 deletions
+1 -1
View File
@@ -13,7 +13,7 @@ DEFINES := -D$(BOARD)
CCFLAGS := -fno-rtti -fno-use-cxa-atexit -fno-threadsafe-statics
CFLAGS := -fno-exceptions -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -nostartfiles
CFLAGS_TLB-y := -DSYS_IO_BASE=0xAC000000 -DSDRAM_BASE=0x80000000 -DFLASH_BASE_IO=0xA4000000 -DFLASH_BASE_MEM=0x88000000
CFLAGS_TLB-y := -DWITH_TLB -DSYS_IO_BASE=0xAC000000 -DSDRAM_BASE=0x80000000 -DFLASH_BASE_IO=0xA4000000 -DFLASH_BASE_MEM=0x88000000
CFLAGS_TLB-n := -DSYS_IO_BASE=0xA0000000 -DSDRAM_BASE=0x40000000 -DFLASH_BASE_IO=0xA4000000 -DFLASH_BASE_MEM=0x00000000
ENDIAN_FLAGS-eb := -EB
+81 -51
View File
@@ -220,39 +220,69 @@ void _exc_dbe(void)
void handler0(struct xcptcontext *xcp)
{
sputs("Interrupt 0\n");
sputs("Interrupt 0 handled\n");
interrupt_clr(0);
}
void handler1(struct xcptcontext *xcp)
{
sputs("Interrupt 1\n");
sputs("Interrupt 1 handled\n");
interrupt_clr(1);
}
int xcp_handler(struct xcptcontext * xcp)
int xcp_handler_syscall(struct xcptcontext *xcp)
{
sputs("----------------------------------------\n");
sputs("Exception Type: ");xcpt_exctype_print(xcp);sputs("\n");
sputs("----------------------------------------\n");
xcpt_registers_print(xcp);
sputs("\n");
sputs("SYSCALL handled\n");
xcp->epc += 4;
return 0;
}
if (xcpt_get_type(xcp) == EXC_INT)
{
interrupt_disable(0);
interrupt_disable(1);
}
else
{
// Skip instruction that caused exception
xcp->epc += 4;
if (xcp->cr & 0x80000000)
{
xcp->epc += 4;
}
}
int xcp_handler_break(struct xcptcontext *xcp)
{
sputs("BREAK handled\n");
xcp->epc += 4;
return 0;
}
int xcp_handler_ov(struct xcptcontext *xcp)
{
sputs("OV handled\n");
xcp->epc += 4;
return 0;
}
int xcp_handler_ri(struct xcptcontext *xcp)
{
sputs("RI handled\n");
xcp->epc += 4;
return 0;
}
int xcp_handler_adel(struct xcptcontext *xcp)
{
sputs("ADEL handled\n");
xcp->epc += 4;
return 0;
}
int xcp_handler_ades(struct xcptcontext *xcp)
{
sputs("ADES handled\n");
xcp->epc += 4;
return 0;
}
int xcp_handler_tlbl(struct xcptcontext *xcp)
{
sputs("TLBL handled\n");
xcp->epc += 4;
return 0;
}
int xcp_handler_tlbs(struct xcptcontext *xcp)
{
sputs("TLBS handled\n");
xcp->epc += 4;
return 0;
}
@@ -261,56 +291,48 @@ int main(void)
int buf[256];
int i, sel;
xcpt_register(EXC_INT, xcp_handler);
xcpt_register(EXC_RI, xcp_handler);
xcpt_register(EXC_OV, xcp_handler);
xcpt_register(EXC_BP, xcp_handler);
xcpt_register(EXC_SYSCALL, xcp_handler);
xcpt_register(EXC_TLBL, xcp_handler);
xcpt_register(EXC_TLBS, xcp_handler);
// xcpt_register(EXC_INT, xcp_handler);
xcpt_register(EXC_RI, xcp_handler_ri);
xcpt_register(EXC_OV, xcp_handler_ov);
xcpt_register(EXC_BP, xcp_handler_break);
xcpt_register(EXC_SYSCALL, xcp_handler_syscall);
xcpt_register(EXC_ADEL, xcp_handler_adel);
xcpt_register(EXC_ADES, xcp_handler_ades);
xcpt_register(EXC_TLBL, xcp_handler_tlbl);
xcpt_register(EXC_TLBS, xcp_handler_tlbs);
interrupt_register(0, handler0);
interrupt_enable(0);
interrupt_register(1, handler1);
interrupt_enable(1);
sputs("11 : SW-interrupt 0\n");
sputs("SW-interrupt : ");
interrupt_set(0);
sputs("12 : SW-interrupt 1\n");
sputs("SW-interrupt : ");
interrupt_set(1);
sputs(" 4 : Syscall\n");
sputs("Syscall : ");
_exc_syscall(4, (uint32_t)((char*)"Hallo Syscall ("));
_exc_syscall(1, 12345678);
_exc_syscall(4, (uint32_t)((char*)")\n"));
sputs(" 5 : Breakpoint\n");
sputs("Breakpoint : ");
_exc_break();
sputs(" 3 : Arithmetic overflow\n");
sputs("Arithmetic overflow : ");
_exc_arith();
sputs(" 1 : Reserved instruction\n");
sputs("Reserved instruction : ");
_exc_ri();
sputs(" 2 : DTLBS (BadVAddr = 0x00000000)\n");
_exc_dtlbs_err();
sputs(" 2 : DTLBL (BadVAddr = 0x00000000)\n");
_exc_dtlbl_err();
return 0;
sputs(" 2 : Privileged address (BadVAddr = 0x80000000)\n");
sputs("Privileged address (BadVAddr = 0x80000000) : ");
_exc_kaddr_err();
sputs(" 6 : Load error on instruction (BadVAddr = 0x40000003)\n");
sputs("Load error on instruction (BadVAddr = 0x40000003) : ");
_exc_iaddr_err();
sputs(" 7 : Load error on data (BadVAddr = 0x40000002)\n");
sputs("Load error on data (BadVAddr = 0x40000002) : ");
_exc_load_err();
sputs(" 8 : Store error on data (BadVAddr = 0x40000001)\n");
sputs("Store error on data (BadVAddr = 0x40000001) : ");
_exc_store_err();
// sputs(" 9 : Bus error on instruction\n");
@@ -321,11 +343,19 @@ int main(void)
// sputs("DBE: Exception not implemented in current CPU!\nPush reset to restart!\n");
// _exc_dbe();
sputs("13 : Load error on instruction and Load error on data (BadVAddr = 0x40000003)\n");
sputs("Load error on instruction and Load error on data (BadVAddr = 0x40000003) : ");
_exc_iaddr_daddr_err();
sputs("14 : Load error on data and Load error on instruction (BadVAddr = 0x40000002)\n");
sputs("Load error on data and Load error on instruction (BadVAddr = 0x40000002) :");
_exc_daddr_iaddr_err();
#ifdef WITH_TLB
sputs("TLBS (BadVAddr = 0x00000000) : ");
_exc_dtlbs_err();
sputs("TLBL (BadVAddr = 0x00000000) : ");
_exc_dtlbl_err();
#endif
return 0;
}