Check sepc for rv64si/scall test. (#107)
[riscv-tests.git] / isa / rv64si / scall.S
index f4752d15e9dd05027e407bd612baa3d403eed58b..0579806e9af0770cf7c04eb689e25ec29d055c9e 100644 (file)
@@ -26,6 +26,23 @@ RVTEST_CODE_BEGIN
 
   li TESTNUM, 2
 
+  # This is the expected trap code.
+  li t1, CAUSE_USER_ECALL
+
+#ifdef __MACHINE_MODE
+  # If running in M mode, use mstatus.MPP to check existence of U mode.
+  # Otherwise, if in S mode, then U mode must exist and we don't need to check.
+  li t0, MSTATUS_MPP
+  csrc mstatus, t0
+  csrr t1, mstatus
+  and t0, t0, t1
+  beqz t0, 1f
+
+  # If U mode doesn't exist, mcause should indicate ECALL from M mode.
+  li t1, CAUSE_MACHINE_ECALL
+#endif
+
+1:
   li t0, SSTATUS_SPP
   csrc sstatus, t0
   la t0, 1f
@@ -34,15 +51,20 @@ RVTEST_CODE_BEGIN
 1:
 
   li TESTNUM, 1
+do_scall:
   scall
   j fail
 
   TEST_PASSFAIL
 
+  .align 2
+  .global stvec_handler
 stvec_handler:
-  li t1, CAUSE_USER_ECALL
   csrr t0, scause
   bne t0, t1, fail
+  la t2, do_scall
+  csrr t0, sepc
+  bne t0, t2, fail
   j pass
 
 RVTEST_CODE_END