1 # See LICENSE for license details.
3 #*****************************************************************************
5 #-----------------------------------------------------------------------------
7 # Test CSRRx and CSRRxI instructions.
10 #include "riscv_test.h"
11 #include "test_macros.h"
17 #define sscratch mscratch
18 #define sstatus mstatus
21 #define stvec_handler mtvec_handler
23 #define SSTATUS_SPP MSTATUS_MPP
27 TEST_CASE( 2, a0, 3, csrr a0, sscratch);
28 TEST_CASE( 3, a1, 3, csrrci a1, sscratch, 1);
29 TEST_CASE( 4, a2, 2, csrrsi a2, sscratch, 4);
30 TEST_CASE( 5, a3, 6, csrrwi a3, sscratch, 2);
31 TEST_CASE( 6, a1, 2, li a0, 0xbad1dea; csrrw a1, sscratch, a0);
32 TEST_CASE( 7, a0, 0xbad1dea, li a0, 0x0001dea; csrrc a0, sscratch, a0);
33 TEST_CASE( 8, a0, 0xbad0000, li a0, 0x000beef; csrrs a0, sscratch, a0);
34 TEST_CASE( 9, a0, 0xbadbeef, csrr a0, sscratch);
36 # Make sure writing the cycle counter causes an exception.
37 # Don't run in supervisor, as we don't delegate illegal instruction traps.
39 TEST_CASE(10, a0, 255, li a0, 255; csrrw a0, cycle, x0);
50 # Make sure reading status in user mode causes an exception.
51 # Don't run in supervisor, as we don't delegate illegal instruction traps.
53 TEST_CASE(11, a0, 255, li a0, 255; csrr a0, sstatus)
55 TEST_CASE(11, x0, 0, nop)
58 # Exit by doing a syscall.
59 TEST_CASE(12, x0, 1, scall)
61 # We should only fall through to this if scall failed.
65 # Trapping on tests 11 and 12 is usually good news.
66 # Note that since the test didn't complete, TESTNUM is smaller by 1.
68 beq TESTNUM, t0, privileged
70 beq TESTNUM, t0, privileged
72 beq TESTNUM, t0, syscall
74 # Trapping on other tests is bad news.
78 # Make sure scause indicates a lack of privilege.
80 li t1, CAUSE_ILLEGAL_INSTRUCTION
82 # Return to user mode, but skip the trapping instruction.
89 # Make sure scause indicates a syscall.
91 li t1, CAUSE_USER_ECALL