1 # See LICENSE for license details.
3 #*****************************************************************************
5 #-----------------------------------------------------------------------------
7 # Test CSRRx and CSRRxI instructions.
10 #include "riscv_test.h"
11 #include "test_macros.h"
16 # Set up evec in case we trap.
22 TEST_CASE( 2, a0, 3, csrr a0, sup0);
23 TEST_CASE( 3, a1, 3, csrrci a1, sup0, 1);
24 TEST_CASE( 4, a2, 2, csrrsi a2, sup0, 4);
25 TEST_CASE( 5, a3, 6, csrrwi a3, sup0, 2);
26 TEST_CASE( 6, a1, 2, li a0, 0xbad1dea; csrrw a1, sup0, a0);
27 TEST_CASE( 7, a0, 0xbad1dea, li a0, 0x0001dea; csrrc a0, sup0, a0);
28 TEST_CASE( 8, a0, 0xbad0000, li a0, 0x000beef; csrrs a0, sup0, a0);
29 TEST_CASE( 9, a0, 0xbadbeef, csrr a0, sup0);
31 # Make sure writing the cycle counter causes an exception.
32 TEST_CASE(10, a0, 255, li a0, 255; csrrw a0, cycle, x0);
34 # Make sure reading status in user mode causes an exception.
35 csrci status, SR_S|SR_PS
36 TEST_CASE(11, a0, 255, li a0, 255; csrr a0, status);
38 # Make sure rdcycle is legal in user mode.
39 TEST_CASE(12, x0, 0, rdcycle a0)
41 # Exit by doing a syscall.
42 TEST_CASE(13, x0, 1, scall)
44 # We should only fall through to this if scall failed.
48 # Trapping on tests 10, 11, and 13 is usually good news.
49 # Note that since the test didn't complete, TESTNUM is smaller by 1.
51 beq TESTNUM, t0, privileged
53 beq TESTNUM, t0, privileged
55 beq TESTNUM, t0, syscall
57 # Trapping on other tests is bad news.
61 # Make sure CAUSE indicates a lack of privilege.
63 li t1, CAUSE_PRIVILEGED_INSTRUCTION
65 # Return to user mode, but skip the trapping instruction.
72 # Make sure CAUSE indicates a syscall.