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
22 #define stvec_handler mtvec_handler
24 #define SSTATUS_SPP MSTATUS_MPP
27 # For RV64, make sure UXL encodes RV64. (UXL does not exist for RV32.)
28 #if __riscv_xlen == 64
29 TEST_CASE(13, a0, SSTATUS_UXL & (SSTATUS_UXL << 1), csrr a0, sstatus; li a1, SSTATUS_UXL; and a0, a0, a1)
33 TEST_CASE( 2, a0, 3, csrr a0, sscratch);
34 TEST_CASE( 3, a1, 3, csrrci a1, sscratch, 1);
35 TEST_CASE( 4, a2, 2, csrrsi a2, sscratch, 4);
36 TEST_CASE( 5, a3, 6, csrrwi a3, sscratch, 2);
37 TEST_CASE( 6, a1, 2, li a0, 0xbad1dea; csrrw a1, sscratch, a0);
38 TEST_CASE( 7, a0, 0xbad1dea, li a0, 0x0001dea; csrrc a0, sscratch, a0);
39 TEST_CASE( 8, a0, 0xbad0000, li a0, 0x000beef; csrrs a0, sscratch, a0);
40 TEST_CASE( 9, a0, 0xbadbeef, csrr a0, sscratch);
43 # Is F extension present?
45 andi a0, a0, (1 << ('F' - 'A'))
47 # If so, make sure FP stores have no effect when mstatus.FS is off.
54 TEST_CASE(10, a0, 1, fsw f0, (a1); lw a0, (a1));
56 # Fail if this test is compiled without F but executed on a core with F.
57 TEST_CASE(10, zero, 1)
61 # Figure out if 'U' is set in misa
62 csrr a0, misa # a0 = csr(misa)
63 srli a0, a0, 20 # a0 = a0 >> 20
64 andi a0, a0, 1 # a0 = a0 & 1
65 beqz a0, finish # if no user mode, skip the rest of these checks
66 #endif /* __MACHINE_MODE */
76 # Make sure writing the cycle counter causes an exception.
77 # Don't run in supervisor, as we don't delegate illegal instruction traps.
79 TEST_CASE(11, a0, 255, li a0, 255; csrrw a0, cycle, x0);
82 # Make sure reading status in user mode causes an exception.
83 # Don't run in supervisor, as we don't delegate illegal instruction traps.
85 TEST_CASE(12, a0, 255, li a0, 255; csrr a0, sstatus)
87 TEST_CASE(12, x0, 0, nop)
93 # We should only fall through to this if scall failed.
98 # Trapping on tests 10-12 is good news.
99 # Note that since the test didn't complete, TESTNUM is smaller by 1.
103 bleu TESTNUM, t0, privileged
106 # catch RVTEST_PASS and kick it up to M-mode
108 li t1, CAUSE_USER_ECALL
113 # Make sure scause indicates a lack of privilege.
115 li t1, CAUSE_ILLEGAL_INSTRUCTION
117 # Return to user mode, but skip the trapping instruction.