Files
vhdl/lib/CPUs/MIPS/bsp/examples/xcpt.c
T
jens 8867efa451 Initial version
Committed on the Free edition of March Hare Software CVSNT Server.
Upgrade to CVS Suite for more features and support:
http://march-hare.com/cvsnt/


git-svn-id: http://moon:8086/svn/vhdl/trunk@272 cc03376c-175c-47c8-b038-4cd826a8556b
2009-01-21 08:52:05 +00:00

129 lines
3.2 KiB
C

#include <sys/times.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <errno.h>
#include <stdlib.h>
#include "libsys.h"
#include "xcpt.h"
#include "irq.h"
char *_xcpt_code_str[32] =
{
"Int", "Mod", "TLBL", "TLBS", "AdEL", "AdES", "IBE", "DBE",
"Sys", "Bp", "RI", "CpU", "Ov", "Tr", "NCD/VCEI", "MC/FPE",
"Res(16)", "Res(17)", "Res(18)", "Res(19)", "Res(20)", "Res(21)", "Res(22)", "WATCH",
"Res(24)", "Res(25)", "Res(26)", "Res(27)", "Res(28)", "Res(29)", "Res(30)", "VCED"
};
#define PRINT_REG(tag_str, reg) \
sputs(tag_str); \
print_word(reg); \
sputs("\n");
int _xcpt_default_dispatch(struct xcptcontext * xcp)
{
return 1;
}
int _xcpt_dispatch(struct xcptcontext * xcp)
{
int xcpt_code, result;
xcpt_code = ((0xFF & xcp->cr) >> 2);
switch(xcpt_code)
{
case Int:
result = _irq_dispatch(xcp);
break;
default:
result = _xcpt_default_dispatch(xcp);
break;
}
return result;
}
int _xcpt_deliver(struct xcptcontext * _xcp)
{
int exc_code;
volatile int *pInstr;
/* This function gets called by the low-level exception handler. */
if (_xcpt_dispatch(_xcp))
{
sputs("\n");
PRINT_REG("Status : ", _xcp->sr);
PRINT_REG("Cause : ", _xcp->cr);
PRINT_REG("EPC : ", _xcp->epc);
PRINT_REG("BadAddr : ", _xcp->baddr);
PRINT_REG("MDLO : ", _xcp->mdlo);
PRINT_REG("MDHI : ", _xcp->mdhi);
sputs("\n");
sputs("Registers:\n");
PRINT_REG(" 0 (zero) : ", _xcp->regs[0]);
PRINT_REG(" 1 (at) : ", _xcp->regs[1]);
PRINT_REG(" 2 (v0) : ", _xcp->regs[2]);
PRINT_REG(" 3 (v1) : ", _xcp->regs[3]);
PRINT_REG(" 4 (a0) : ", _xcp->regs[4]);
PRINT_REG(" 5 (a1) : ", _xcp->regs[5]);
PRINT_REG(" 6 (a2) : ", _xcp->regs[6]);
PRINT_REG(" 7 (a3) : ", _xcp->regs[7]);
PRINT_REG(" 8 (t0) : ", _xcp->regs[8]);
PRINT_REG(" 9 (t1) : ", _xcp->regs[9]);
PRINT_REG("10 (t2) : ", _xcp->regs[10]);
PRINT_REG("11 (t3) : ", _xcp->regs[11]);
PRINT_REG("12 (t4) : ", _xcp->regs[12]);
PRINT_REG("13 (t5) : ", _xcp->regs[13]);
PRINT_REG("14 (t6) : ", _xcp->regs[14]);
PRINT_REG("15 (t7) : ", _xcp->regs[15]);
PRINT_REG("16 (s0) : ", _xcp->regs[16]);
PRINT_REG("17 (s1) : ", _xcp->regs[17]);
PRINT_REG("18 (s2) : ", _xcp->regs[18]);
PRINT_REG("19 (s3) : ", _xcp->regs[19]);
PRINT_REG("20 (s4) : ", _xcp->regs[20]);
PRINT_REG("21 (s5) : ", _xcp->regs[21]);
PRINT_REG("22 (s6) : ", _xcp->regs[22]);
PRINT_REG("23 (s7) : ", _xcp->regs[23]);
PRINT_REG("24 (t8) : ", _xcp->regs[24]);
PRINT_REG("25 (t9) : ", _xcp->regs[25]);
PRINT_REG("26 (k0) : ", _xcp->regs[26]);
PRINT_REG("27 (k1) : ", _xcp->regs[27]);
PRINT_REG("28 (gp) : ", _xcp->regs[28]);
PRINT_REG("29 (sp) : ", _xcp->regs[29]);
PRINT_REG("30 (fp) : ", _xcp->regs[30]);
PRINT_REG("31 (ra) : ", _xcp->regs[31]);
sputs("\n");
exc_code = (_xcp->cr >> 2) & 0x1F;
sputs("Unhandled exception <");
sputs(_xcpt_code_str[exc_code]);
sputs("> at PC : ");
print_word(_xcp->epc);
sputs("\n");
if (_xcp->cr & 0x80000000)
{
pInstr = (int*)(_xcp->epc + 4);
}
else
{
pInstr = (int*)(_xcp->epc);
}
sputs("Instruction at exception address : ");
print_word(*pInstr);
sputs("\n");
sputs("Terminate.\n");
_exit(exc_code);
}
return 0;
}