2
0
mirror of https://github.com/m-labs/artiq.git synced 2024-12-25 11:18:27 +08:00
artiq/soc/runtime/exceptions.c

41 lines
752 B
C
Raw Normal View History

#include "exceptions.h"
2014-10-19 23:51:49 +08:00
#include "comm.h"
2014-09-22 13:18:48 +08:00
#define MAX_EXCEPTION_CONTEXTS 64
struct exception_context {
void *jb[13];
2014-09-22 13:18:48 +08:00
};
static struct exception_context exception_contexts[MAX_EXCEPTION_CONTEXTS];
static int ec_top;
static int stored_id;
2014-09-22 13:18:48 +08:00
void *exception_push(void)
{
2014-09-22 13:18:48 +08:00
if(ec_top >= MAX_EXCEPTION_CONTEXTS)
exception_raise(EID_OUT_OF_MEMORY);
2014-09-22 13:18:48 +08:00
return exception_contexts[ec_top++].jb;
}
void exception_pop(int levels)
{
ec_top -= levels;
}
2014-09-22 13:18:48 +08:00
int exception_getid(void)
{
2014-09-22 13:18:48 +08:00
return stored_id;
}
2014-09-22 13:18:48 +08:00
void exception_raise(int id)
{
if(ec_top > 0) {
stored_id = id;
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);
}
}