forked from M-Labs/artiq
1
0
Fork 0

soc/runtime: add exception management functions

This commit is contained in:
Sebastien Bourdeauducq 2014-09-21 23:32:14 +08:00
parent e821f9eb83
commit 0c9f05dc80
3 changed files with 48 additions and 1 deletions

View File

@ -3,7 +3,7 @@ include $(MSCDIR)/software/common.mak
BOARD=papilio_pro
SERIAL=/dev/ttyUSB1
OBJECTS=isr.o elf_loader.o services.o corecom_serial.o gpio.o rtio.o dds.o main.o
OBJECTS=isr.o elf_loader.o exceptions.o services.o corecom_serial.o gpio.o rtio.o dds.o main.o
all: runtime.bin

32
soc/runtime/exceptions.c Normal file
View File

@ -0,0 +1,32 @@
#include <setjmp.h>
#include "exceptions.h"
static struct exception_env *env_top;
static int stored_id;
int exception_catch(struct exception_env *ee, int *id)
{
ee->prev = env_top;
env_top = ee;
if(setjmp(env_top->jb)) {
*id = stored_id;
return 1;
} else
return 0;
}
void exception_pop(void)
{
env_top = env_top->prev;
}
void exception_raise(int id)
{
struct exception_env *ee;
ee = env_top;
env_top = env_top->prev;
stored_id = id; /* __builtin_longjmp needs its second argument set to 1 */
longjmp(ee->jb, 1);
}

15
soc/runtime/exceptions.h Normal file
View File

@ -0,0 +1,15 @@
#ifndef __EXCEPTIONS_H
#define __EXCEPTIONS_H
#include <setjmp.h>
struct exception_env {
jmp_buf jb;
struct exception_env *prev;
};
int exception_catch(struct exception_env *ee, int *id);
void exception_pop(void);
void exception_raise(int id) __attribute__((noreturn));
#endif /* __EXCEPTIONS_H */