Add rv32si tests, including illegality of shamt[5]
[riscv-tests.git] / isa / rv64si / csr.S
1 #*****************************************************************************
2 # csr.S
3 #-----------------------------------------------------------------------------
4 #
5 # Test CSRRx and CSRRxI instructions.
6 #
7
8 #include "riscv_test.h"
9 #include "test_macros.h"
10
11 RVTEST_RV64S
12 RVTEST_CODE_BEGIN
13
14 # Set up evec in case we trap.
15 la t0, evec
16 csrw evec, t0
17 csrwi count, 0
18
19 csrwi sup0, 3
20 TEST_CASE( 2, a0, 3, csrr a0, sup0);
21 TEST_CASE( 3, a1, 3, csrrci a1, sup0, 1);
22 TEST_CASE( 4, a2, 2, csrrsi a2, sup0, 4);
23 TEST_CASE( 5, a3, 6, csrrwi a3, sup0, 2);
24 TEST_CASE( 6, a1, 2, li a0, 0xbad1dea; csrrw a1, sup0, a0);
25 TEST_CASE( 7, a0, 0xbad1dea, li a0, 0x0001dea; csrrc a0, sup0, a0);
26 TEST_CASE( 8, a0, 0xbad0000, li a0, 0x000beef; csrrs a0, sup0, a0);
27 TEST_CASE( 9, a0, 0xbadbeef, csrr a0, sup0);
28
29 # Make sure writing the cycle counter causes an exception.
30 TEST_CASE(10, a0, 255, li a0, 255; csrrw a0, cycle, x0);
31
32 # Make sure reading status in user mode causes an exception.
33 csrci status, SR_S|SR_PS
34 TEST_CASE(11, a0, 255, li a0, 255; csrr a0, status);
35
36 # Make sure rdcycle is legal in user mode.
37 TEST_CASE(12, x0, 0, rdcycle a0)
38
39 # Exit by doing a syscall.
40 TEST_CASE(13, x0, 1, scall)
41
42 # We should only fall through to this if scall failed.
43 TEST_PASSFAIL
44
45 evec:
46 # Trapping on tests 10, 11, and 13 is usually good news.
47 # Note that since the test didn't complete, TESTNUM is smaller by 1.
48 li t0, 9
49 beq TESTNUM, t0, privileged
50 li t0, 10
51 beq TESTNUM, t0, privileged
52 li t0, 12
53 beq TESTNUM, t0, syscall
54
55 # Trapping on other tests is bad news.
56 j fail
57
58 privileged:
59 # Make sure CAUSE indicates a lack of privilege.
60 csrr t0, cause
61 li t1, CAUSE_PRIVILEGED_INSTRUCTION
62 bne t0, t1, fail
63 # Return to user mode, but skip the trapping instruction.
64 csrr t0, epc
65 addi t0, t0, 4
66 csrw epc, t0
67 sret
68
69 syscall:
70 # Make sure CAUSE indicates a syscall.
71 csrr t0, cause
72 li t1, CAUSE_SYSCALL
73 bne t0, t1, fail
74
75 # We're done.
76 j pass
77
78 RVTEST_CODE_END
79
80 .data
81 RVTEST_DATA_BEGIN
82
83 TEST_DATA
84
85 RVTEST_DATA_END