- added function to register exception handlers

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@446 cc03376c-175c-47c8-b038-4cd826a8556b
This commit is contained in:
2009-04-15 14:05:33 +00:00
parent 133df33e35
commit 4452820f09
2 changed files with 29 additions and 12 deletions
+14 -12
View File
@@ -7,7 +7,9 @@
#include "xcpt.h" #include "xcpt.h"
#include "irq.h" #include "irq.h"
char *_xcpt_code_str[32] = static fp_xcpt_t g_xcpt_handler[MAX_NUM_XCPT] = {NULL};
char *_xcpt_code_str[MAX_NUM_XCPT] =
{ {
"Int", "Mod", "TLBL", "TLBS", "AdEL", "AdES", "IBE", "DBE", "Int", "Mod", "TLBL", "TLBS", "AdEL", "AdES", "IBE", "DBE",
"Sys", "Bp", "RI", "CpU", "Ov", "Tr", "NCD/VCEI", "MC/FPE", "Sys", "Bp", "RI", "CpU", "Ov", "Tr", "NCD/VCEI", "MC/FPE",
@@ -15,22 +17,20 @@ char *_xcpt_code_str[32] =
"Res(24)", "Res(25)", "Res(26)", "Res(27)", "Res(28)", "Res(29)", "Res(30)", "VCED" "Res(24)", "Res(25)", "Res(26)", "Res(27)", "Res(28)", "Res(29)", "Res(30)", "VCED"
}; };
#define PRINT_REG(tag_str, reg) \ void xcpt_register(int xcpt_num, fp_xcpt_t fp)
sputs(tag_str); \
print_word(reg); \
sputs(" ");
int _xcpt_default_dispatch(struct xcptcontext * xcp)
{ {
return 1; if ((xcpt_num >= Mod) && (xcpt_num <= VCED))
g_xcpt_handler[xcpt_num] = fp;
} }
int _xcpt_dispatch(struct xcptcontext * xcp) int _xcpt_dispatch(struct xcptcontext * xcp)
{ {
int xcpt_code, result; int xcpt_code, result, i;
xcpt_code = ((0xFF & xcp->cr) >> 2); xcpt_code = ((0xFF & xcp->cr) >> 2);
result = XCPT_ERR_NOTHANDLED;
switch(xcpt_code) switch(xcpt_code)
{ {
case Int: case Int:
@@ -38,10 +38,12 @@ int _xcpt_dispatch(struct xcptcontext * xcp)
break; break;
default: default:
result = _xcpt_default_dispatch(xcp); if (g_xcpt_handler[xcpt_code])
{
result = (g_xcpt_handler[xcpt_code])(xcp);
}
break; break;
} }
return result; return result;
} }
@@ -52,7 +54,7 @@ int _xcpt_deliver(struct xcptcontext * _xcp)
volatile int *pInstr; volatile int *pInstr;
/* This function gets called by the low-level exception handler. */ /* This function gets called by the low-level exception handler. */
if (_xcpt_dispatch(_xcp)) if (_xcpt_dispatch(_xcp) == XCPT_ERR_NOTHANDLED)
{ {
sputs("\n"); sputs("\n");
PRINT_REG(" Status : ", _xcp->sr); PRINT_REG(" Status : ", _xcp->sr);
+15
View File
@@ -1,6 +1,9 @@
#ifndef XCPT_H #ifndef XCPT_H
#define XCPT_H #define XCPT_H
#define MAX_NUM_XCPT 32
#define XCPT_ERR_NOTHANDLED 0x80000000
typedef enum typedef enum
{ {
Int = 0, Mod = 1, TLBL = 2, TLBS = 3, AdEL = 4, AdES = 5, Int = 0, Mod = 1, TLBL = 2, TLBS = 3, AdEL = 4, AdES = 5,
@@ -31,4 +34,16 @@ typedef struct xcptcontext
} EXCEPTION_CONTEXT; } EXCEPTION_CONTEXT;
typedef int (*fp_xcpt_t)(struct xcptcontext * xcp);
#define PRINT_REG(tag_str, reg) \
sputs(tag_str); \
print_word(reg); \
sputs(" ");
// Public functions
void xcpt_register(int xcpt_num, fp_xcpt_t fp);
#endif // XCPT_H #endif // XCPT_H