-#define SV_REG_CSR(type, regkey, elwidth, regidx, isvec, packed) \
+#define SV_REG_CSR( type, regkey, elwidth, regidx, isvec, packed ) \
(regkey | (elwidth<<5) | (type<<7) | (regidx<<8) | (isvec<<14) | (packed<<15))
-#define SV_PRED_CSR(type, regkey, zero, inv, regidx, active) \
+
+#define SV_PRED_CSR( type, regkey, zero, inv, regidx, active ) \
(regkey | (zero<<5) | (inv<<6) | (type<<7) | (regidx<<8) | (active<<14))
+
+#define SET_SV_CSR( type, regkey, elwidth, regidx, isvec, packed ) \
+ li x1, SV_REG_CSR( type, regkey, elwidth, regidx, isvec, packed ); \
+ csrrw x0, 0x4c0, x1
+
+#define CLR_SV_CSRS( ) csrrw x0, 0x4c0, 0
+
+#define SET_SV_MVL( val ) csrrwi x0, 0x4f2, val
+#define SET_SV_VL( val ) csrrwi x0, 0x4f0, val
+
+#define SV_LD_DATA( reg, from, offs ) \
+ la x1, from; \
+ lw reg, offs(x1)
+
+#define TEST_SV_IMM( reg, imm ) \
+ li x1, imm; \
+ bne reg, x1, fail
# Test code region.
RVTEST_CODE_BEGIN # Start of test code.
- csrrw x0, 0x4f2, 2
- la x1, testdata
- lw x2, 0(x1)
- la x1, (testdata+8)
- lw x3, 0(x1)
- li x1, SV_REG_CSR(1, 2, 0, 2, 1, 0)
- csrrw x0, 0x4c0, x1
- csrrw x0, 0x4f0, 2
- addi x2, x2, 1 # Should be 42 into $2.
- csrrwi x0, 0x4f2, 0
- csrrwi x0, 0x4c0, 0
- csrrwi x0, 0x4f0, 0
- li x1, 42 # Desired result 1
- bne x2, x1, fail # Fail out if doesn't match.
- li x1, 43 # Desired result 2
- bne x3, x1, fail # Fail out if doesn't match.
+
+ SV_LD_DATA( x2, testdata , 0)
+ SV_LD_DATA( x3, testdata+8 , 0)
+ SV_LD_DATA( x4, testdata+16, 0)
+ SV_LD_DATA( x5, testdata+24, 0)
+
+ SET_SV_MVL(2)
+ SET_SV_CSR(1, 3, 0, 3, 1, 0)
+ SET_SV_VL(2)
+
+ addi x3, x3, 1
+
+ CLR_SV_CSRS()
+ SET_SV_VL(0)
+ SET_SV_MVL(0)
+
+ TEST_SV_IMM(x2, 1001) # should not be modified
+ TEST_SV_IMM(x3, 42)
+ TEST_SV_IMM(x4, 43)
+ TEST_SV_IMM(x5, 1002) # should not be modified
+
RVTEST_PASS # Signal success.
fail:
RVTEST_FAIL
.data
.align 3
testdata:
+ .dword 1001
.dword 41
.dword 42
- .dword 43
+ .dword 1002
# Output data section.
RVTEST_DATA_BEGIN # Start of test output data region.