From 2887165ae2990e7f93038f3220ed74ee429b5244 Mon Sep 17 00:00:00 2001 From: Megan Wachs Date: Wed, 20 Jul 2016 23:59:02 +0000 Subject: Initial Checkin --- software/shared/init.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 software/shared/init.c (limited to 'software/shared/init.c') diff --git a/software/shared/init.c b/software/shared/init.c new file mode 100644 index 0000000..ab790b2 --- /dev/null +++ b/software/shared/init.c @@ -0,0 +1,48 @@ +// See LICENSE for license details. + +#include +#include +#include +#include + +#include "encoding.h" +#include "shared.h" + +int main(void); + +#ifdef USE_PLIC +extern void handle_m_ext_interrupt(); +#endif + + +#ifdef USE_M_TIME +extern void handle_m_time_interrupt(); +#endif + + +void _init(void) +{ + + exit(main()); +} + +uintptr_t handle_trap(uintptr_t mcause, uintptr_t epc) +{ + if (0){ +#ifdef USE_PLIC + // External Machine-Level Interrupt from PLIC + }else if ((mcause & MCAUSE_INT) && ((mcause & MCAUSE_CAUSE) == IRQ_M_EXT)) { + handle_m_ext_interrupt(); +#endif +#ifdef USE_M_TIME + // External Machine-Level Interrupt from PLIC + }else if ((mcause & MCAUSE_INT) && ((mcause & MCAUSE_CAUSE) == IRQ_M_TIMER)) { + handle_m_time_interrupt(); +#endif + } + else{ + write(1, "trap\n", 5); + _exit(1 + mcause); + } + return epc; +} -- cgit v1.2.3