bump env
[riscv-tests.git] / benchmarks / common / crt.S
index 919461b8c35b178cc5e20d5a5553379af044582c..d75e81e06548df82100a010c21a6310927cadc7c 100644 (file)
@@ -2,7 +2,7 @@
 
 #include "encoding.h"
 
-#ifdef __riscv64
+#if __riscv_xlen == 64
 # define LREG ld
 # define SREG sd
 # define REGBYTES 8
 # define REGBYTES 4
 #endif
 
-  .text
+  .section ".text.init"
   .globl _start
 _start:
-  j handle_reset
-
-nmi_vector:
-  j nmi_vector
-
-trap_vector:
-  j trap_entry
-
-handle_reset:
   li  x1, 0
   li  x2, 0
   li  x3, 0
@@ -56,29 +47,29 @@ handle_reset:
   li  x30,0
   li  x31,0
 
-  li t0, MSTATUS_FS;   csrs mstatus, t0    # enable FPU
-  li t0, MSTATUS_XS;   csrs mstatus, t0    # enable accelerator
+  # enable FPU and accelerator if present
+  li t0, MSTATUS_FS | MSTATUS_XS
+  csrs mstatus, t0
 
-#ifdef __riscv64
-  csrr t0, misa
-  # make sure processor supports RV64 if this was compiled for RV64
+  # make sure XLEN agrees with compilation choice
+  li t0, 1
+  slli t0, t0, 31
+#if __riscv_xlen == 64
+  bgez t0, 1f
+#else
   bltz t0, 1f
-  li a0, 1234
-  j tohost_exit
-1:
 #endif
+2:
+  li a0, 1
+  sw a0, tohost, t0
+  j 2b
+1:
 
-  csrr t0, mstatus
-  li t1, MSTATUS_XS
-  and t1, t0, t1
-  sw t1, have_vec, t2
-
-  ## if that didn't stick, we don't have a FPU, so don't initialize it
-  li t1, MSTATUS_FS
-  and t1, t0, t1
-  beqz t1, 1f
+#ifdef __riscv_flen
+  # initialize FPU if we have one
+  la t0, 1f
+  csrw mtvec, t0
 
-#ifdef __riscv_hard_float
   fssr    x0
   fmv.s.x f0, x0
   fmv.s.x f1, x0
@@ -112,12 +103,18 @@ handle_reset:
   fmv.s.x f29,x0
   fmv.s.x f30,x0
   fmv.s.x f31,x0
+1:
 #endif
 
-1:
+  # initialize trap vector
+  la t0, trap_entry
+  csrw mtvec, t0
 
   # initialize global pointer
-  la gp, _gp
+.option push
+.option norelax
+  la gp, __global_pointer$
+.option pop
 
   la  tp, _end + 63
   and tp, tp, -64
@@ -138,6 +135,7 @@ handle_reset:
 
   j _init
 
+  .align 2
 trap_entry:
   addi sp, sp, -272
 
@@ -216,7 +214,7 @@ trap_entry:
   LREG x31, 31*REGBYTES(sp)
 
   addi sp, sp, 272
-  eret
+  mret
 
 .section ".tdata.begin"
 .globl _tdata_begin
@@ -229,3 +227,11 @@ _tdata_end:
 .section ".tbss.end"
 .globl _tbss_end
 _tbss_end:
+
+.section ".tohost","aw",@progbits
+.align 6
+.globl tohost
+tohost: .dword 0
+.align 6
+.globl fromhost
+fromhost: .dword 0