2015-04-04 22:08:32 +08:00
|
|
|
#include <generated/csr.h>
|
|
|
|
|
2014-10-19 23:51:49 +08:00
|
|
|
#include "comm.h"
|
2015-04-06 19:40:12 +08:00
|
|
|
#include "exceptions.h"
|
2014-09-21 23:32:14 +08:00
|
|
|
|
2014-09-22 13:18:48 +08:00
|
|
|
#define MAX_EXCEPTION_CONTEXTS 64
|
|
|
|
|
|
|
|
struct exception_context {
|
2014-09-23 22:09:08 +08:00
|
|
|
void *jb[13];
|
2014-09-22 13:18:48 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct exception_context exception_contexts[MAX_EXCEPTION_CONTEXTS];
|
|
|
|
static int ec_top;
|
2014-09-21 23:32:14 +08:00
|
|
|
static int stored_id;
|
2015-04-05 22:04:50 +08:00
|
|
|
static long long int stored_params[3];
|
2014-09-21 23:32:14 +08:00
|
|
|
|
2014-09-22 13:18:48 +08:00
|
|
|
void *exception_push(void)
|
2014-09-21 23:32:14 +08:00
|
|
|
{
|
2014-09-22 13:18:48 +08:00
|
|
|
if(ec_top >= MAX_EXCEPTION_CONTEXTS)
|
2015-04-05 22:04:50 +08:00
|
|
|
exception_raise(EID_INTERNAL_ERROR);
|
2014-09-22 13:18:48 +08:00
|
|
|
return exception_contexts[ec_top++].jb;
|
2014-09-21 23:32:14 +08:00
|
|
|
}
|
|
|
|
|
2014-09-23 16:22:32 +08:00
|
|
|
void exception_pop(int levels)
|
2014-09-21 23:32:14 +08:00
|
|
|
{
|
2014-09-23 16:22:32 +08:00
|
|
|
ec_top -= levels;
|
2014-09-21 23:32:14 +08:00
|
|
|
}
|
|
|
|
|
2015-04-05 22:04:50 +08:00
|
|
|
int exception_getid(long long int *eparams)
|
2014-09-21 23:32:14 +08:00
|
|
|
{
|
2015-04-05 22:04:50 +08:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if(eparams)
|
|
|
|
for(i=0;i<3;i++)
|
|
|
|
eparams[i] = stored_params[i];
|
2014-09-22 13:18:48 +08:00
|
|
|
return stored_id;
|
|
|
|
}
|
2014-09-21 23:32:14 +08:00
|
|
|
|
2014-09-22 13:18:48 +08:00
|
|
|
void exception_raise(int id)
|
2015-03-13 21:55:18 +08:00
|
|
|
{
|
|
|
|
exception_raise_params(id, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void exception_raise_params(int id,
|
|
|
|
long long int p0, long long int p1,
|
|
|
|
long long int p2)
|
2014-09-22 13:18:48 +08:00
|
|
|
{
|
2014-10-05 10:33:27 +08:00
|
|
|
if(ec_top > 0) {
|
|
|
|
stored_id = id;
|
2015-04-05 22:04:50 +08:00
|
|
|
stored_params[0] = p0;
|
|
|
|
stored_params[1] = p1;
|
|
|
|
stored_params[2] = p2;
|
2014-10-05 10:33:27 +08:00
|
|
|
exception_longjmp(exception_contexts[--ec_top].jb);
|
2014-10-15 16:11:28 +08:00
|
|
|
} else {
|
2014-10-19 23:51:49 +08:00
|
|
|
comm_log("ERROR: uncaught exception, ID=%d\n", id);
|
2014-10-15 16:11:28 +08:00
|
|
|
while(1);
|
|
|
|
}
|
2014-09-21 23:32:14 +08:00
|
|
|
}
|