summaryrefslogtreecommitdiff
path: root/software/shared/init.c
diff options
context:
space:
mode:
authorMegan Wachs <megan@sifive.com>2016-07-20 23:59:02 +0000
committerMegan Wachs <megan@sifive.com>2016-07-26 08:40:12 -0700
commit2887165ae2990e7f93038f3220ed74ee429b5244 (patch)
tree13c4cb83e47d6ab390e0465e883acf0973611e8e /software/shared/init.c
parenta2d28c8318ab3ed40b3674aeee8b9487a3129f15 (diff)
Initial Checkin
Diffstat (limited to 'software/shared/init.c')
-rw-r--r--software/shared/init.c48
1 files changed, 48 insertions, 0 deletions
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 <stdlib.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <unistd.h>
+
+#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;
+}