except.c 2.62 KB
#include <R4300.h>
#include "romloader.h"
extern int      _ExceptionPreamble[];


typedef struct {
	unsigned int inst1;		/* lui	k0,XXXX */
	unsigned int inst2;		/* addiu k0,k0,XXXX */
	unsigned int inst3;		/* jr k0 */
	unsigned int inst4;		/* nop */
} vector;

typedef struct {
	unsigned int     at, v0, v1, a0, a1, a2, a3;
	unsigned int t0, t1, t2, t3, t4, t5, t6, t7;
	unsigned int s0, s1, s2, s3, s4, s5, s6, s7;
	unsigned int t8, t9,         gp, sp, s8, ra;
	unsigned int pagemask;
	unsigned int wired;
	unsigned int entrylo0;
	unsigned int entrylo1;
	unsigned int context;
	unsigned int badvaddr;
	unsigned int entryhi;
	unsigned int compare;
	unsigned int sr;
	unsigned int cause;
	unsigned int epc;
	unsigned int config;
} eframe;

eframe _ExceptionFrame;

void
_ExceptionInitialize(void)
{
	*(vector *)UT_VEC = *(vector *)_ExceptionPreamble;
	*(vector *)XUT_VEC = *(vector *)_ExceptionPreamble;
	*(vector *)ECC_VEC = *(vector *)_ExceptionPreamble;
	*(vector *)E_VEC = *(vector *)_ExceptionPreamble;
}


static char *excCodeNames[32] = {
	"Int",  "Mod",  "TLBL", "TLBS", "AdEL", "AdES", "IBE",  "DBE",
	"Sys",  "Bp",   "RI",   "CpU",  "Ov",   "Tr",   "VCEI", "FPE",
	"!!!!", "!!!!", "!!!!", "!!!!", "!!!!", "!!!!", "!!!!", "WATCH",
	"!!!!", "!!!!", "!!!!", "!!!!", "!!!!", "!!!!", "!!!!", "VCED"
};

void
_ExceptionPrint(void)
{
	register int i;
	register eframe *ef = &_ExceptionFrame;

	printf("PANIC:\n");
	printf("epc\t0x%08x\n", ef->epc);
	printf("cause\t0x%08b<%s>\n", ef->cause, CAUSE_FMT,
		excCodeNames[(ef->cause & CAUSE_EXCMASK) >> CAUSE_EXCSHIFT]);
	printf("sr\t0x%b\n", ef->sr, SR_FMT);
	printf("badvaddr\t0x%08x\n", ef->badvaddr);
	printf("pagemask\t0x%08x\n", ef->pagemask);
	printf("wired\t0x%08x\n", ef->wired);
	printf("entrylo0\t0x%08x\n", ef->entrylo0);
	printf("entrylo1\t0x%08x\n", ef->entrylo1);
	printf("context\t0x%08x\n", ef->context);
	printf("entryhi\t0x%08x\n", ef->entryhi);
	printf("compare\t0x%08x\n", ef->compare);
	printf("config\t0x%08x\n", ef->config);

	printf("at 0x%08x v0\t0x%08x v1\t0x%08x\n",
		ef->at, ef->v0, ef->v1);
	printf("a0 0x%08x a1\t0x%08x a2\t0x%08x a3\t0x%08x\n",
		ef->a0, ef->a1, ef->a2, ef->a3);
	printf("t0 0x%08x t1\t0x%08x t2\t0x%08x t3\t0x%08x\n",
		ef->t0, ef->t1, ef->t2, ef->t3);
	printf("t4 0x%08x t5\t0x%08x t6\t0x%08x t7\t0x%08x\n",
		ef->t4, ef->t5, ef->t6, ef->t7);
	printf("s0 0x%08x s1\t0x%08x s2\t0x%08x s3\t0x%08x\n",
		ef->s0, ef->s1, ef->s2, ef->s3);
	printf("s4 0x%08x s5\t0x%08x s6\t0x%08x s7\t0x%08x\n",
		ef->s4, ef->s5, ef->s6, ef->s7);
	printf("t8 0x%08x t9\t0x%08x\n",
		ef->t8, ef->t9);
	printf("gp 0x%08x sp\t0x%08x s8\t0x%08x ra\t0x%08x\n\n",
		ef->gp, ef->sp, ef->s8, ef->ra);

	for (;;);

}