Don't rely on reset values of MSTATUS_UA/SA
[riscv-tests.git] / benchmarks / common / syscalls.c
index 1e4efab1e3f28ff6cf70b4463f5d7e1e48aaa8cd..3c08bc2f9a59089b46db462e592faf33b404bedd 100644 (file)
@@ -1,11 +1,14 @@
+// See LICENSE for license details.
+
 #include <stdint.h>
 #include <string.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <limits.h>
-#include <machine/syscall.h>
 #include "util.h"
 
+#define SYS_write 64
+#define SYS_exit 93
 #define SYS_stats 1234
 
 // initialized in crt.S
@@ -57,13 +60,13 @@ static int handle_stats(int enable)
   return 0;
 }
 
-static void tohost_exit(int code)
+void tohost_exit(long code)
 {
   write_csr(tohost, (code << 1) | 1);
   while (1);
 }
 
-long handle_trap(long cause, long epc, long regs[32])
+long handle_trap(long cause, long epc, long long regs[32])
 {
   int* csr_insn;
   asm ("jal %0, 1f; csrr a0, stats; 1:" : "=r"(csr_insn));
@@ -72,7 +75,7 @@ long handle_trap(long cause, long epc, long regs[32])
   if (cause == CAUSE_ILLEGAL_INSTRUCTION &&
       (*(int*)epc & *csr_insn) == *csr_insn)
     ;
-  else if (cause != CAUSE_SYSCALL)
+  else if (cause != CAUSE_ECALL)
     tohost_exit(1337);
   else if (regs[17] == SYS_exit)
     tohost_exit(regs[10]);