Fix to solve the failing tests shamt, csr and scall (#151)
[riscv-tests.git] / isa / rv64si / scall.S
1 # See LICENSE for license details.
2
3 #*****************************************************************************
4 # scall.S
5 #-----------------------------------------------------------------------------
6 #
7 # Test syscall trap.
8 #
9 # If the pmp registers are implemented, then the pmp registers have
10 # to be configured before jumping to the privilaged modes
11
12 #include "riscv_test.h"
13 #include "test_macros.h"
14
15 RVTEST_RV64S
16 RVTEST_CODE_BEGIN
17
18 #ifdef __MACHINE_MODE
19 #define sscratch mscratch
20 #define sstatus mstatus
21 #define scause mcause
22 #define sepc mepc
23 #define sret mret
24 #define stvec_handler mtvec_handler
25 #undef SSTATUS_SPP
26 #define SSTATUS_SPP MSTATUS_MPP
27 #endif
28
29 li TESTNUM, 2
30
31 #ifdef __MACHINE_MODE
32 # If running in M mode, use mstatus.MPP to check existence of U mode.
33 # Otherwise, if in S mode, then U mode must exist and we don't need to check.
34
35 la t0, user_mode_end
36 srli t0, t0, PMP_SHIFT
37 csrr t1, pmpcfg0
38 csrw pmpaddr0, t0
39 csrr t1, pmpaddr0
40 bne t0, t1, fail
41 li t0, (PMP_R | PMP_W | PMP_X) # giving read, write and execute permissions
42 or t0, t0, PMP_TOR # setting mode to TOR
43 li t1, 255
44 csrrc t1, pmpcfg0, t1
45 csrrs t1, pmpcfg0, t0
46 csrr t1, pmpcfg0
47 andi t1, t1, 255
48 bne t0, t1, fail
49 .global no_pmp_implemented
50 no_pmp_implemented:
51 li t0, MSTATUS_MPP
52 csrc mstatus, t0
53 csrr t1, mstatus
54 and t0, t0, t1
55
56 # This is the expected trap code.
57 li t1, CAUSE_USER_ECALL
58 beqz t0, 1f
59
60 # If U mode doesn't exist, mcause should indicate ECALL from M mode.
61 li t1, CAUSE_MACHINE_ECALL
62 #endif
63
64 1:
65 li t0, SSTATUS_SPP
66 csrc sstatus, t0
67 la t0, 1f
68 csrw sepc, t0
69 sret
70 1:
71
72 li TESTNUM, 1
73 do_scall:
74 scall
75 j fail
76
77 .align 2
78 .global user_mode_end
79 user_mode_end:
80 nop
81
82 TEST_PASSFAIL
83
84 .align 2
85 .global stvec_handler
86 stvec_handler:
87 csrr t0, scause
88 bne t0, t1, check_for_pmp
89 la t2, do_scall
90 csrr t0, sepc
91 bne t0, t2, fail
92 j pass
93
94 check_for_pmp:
95 li t1, CAUSE_ILLEGAL_INSTRUCTION
96 bne t0, t1, fail
97 j no_pmp_implemented
98 RVTEST_CODE_END
99
100 .data
101 RVTEST_DATA_BEGIN
102
103 TEST_DATA
104
105 RVTEST_DATA_END