1 # See LICENSE for license details.
3 #*****************************************************************************
5 #-----------------------------------------------------------------------------
7 # Test misaligned fetch trap.
10 #include "riscv_test.h"
11 #include "test_macros.h"
17 #define sscratch mscratch
18 #define sstatus mstatus
20 #define sbadaddr mbadaddr
23 #define stvec_handler mtvec_handler
29 # Without RVC, the jalr should trap, and the handler will skip ahead.
30 # With RVC, the jalr should not trap, and "j fail" should get skipped.
44 // This test should pass, since JALR ignores the target LSB
66 # Like test 2, but with jal instead of jalr.
81 # Like test 2, but with a taken branch instead of jalr.
96 # Not-taken branches should not trap, even without RVC.
109 #ifdef __MACHINE_MODE
110 # If RVC can be disabled, then disabling it should cause a misaligned
111 # instruction exception on the next instruction. (This test assumes
112 # no other extensions that support misalignment are present.)
115 andi t2, t2, 1 << ('c' - 'a')
121 csrci misa, 1 << ('c' - 'a')
126 # If we got here, we trapped. Re-enable RVC and proceed.
127 csrsi misa, 1 << ('c' - 'a')
131 # If we got here, we didn't trap, so RVC had better be enabled.
133 andi t2, t2, 1 << ('c' - 'a')
137 # mret to a misaligned mepc should either align the mepc or raise a
138 # misaligned instruction exception.
143 # Try to disable RVC; if it can't be disabled, skip the test.
144 csrci misa, 1 << ('c' - 'a')
146 andi t2, t2, 1 << ('c' - 'a')
153 # If the implementation chose to align mepc, mret will transfer control
154 # to this branch. Otherwise, it will transfer control two bytes into
155 # the branch, which happens to be the illegal instruction c.unimp.
156 # But c.unimp should not be executed, since the PC is misaligned.
163 li a1, CAUSE_MISALIGNED_FETCH
167 # check that mepc == t0, and advance mepc past the misalignment
173 # check that badaddr == t0 or zero
188 .global stvec_handler
190 # tests 2, 4, 5, 6, and 8 should trap
199 #ifdef __MACHINE_MODE
201 beq TESTNUM, a0, test8_handler
206 # verify that return address was not written
210 li a1, CAUSE_MISALIGNED_FETCH
214 # verify that epc == &jalr (== t0 - 4)
219 # verify that badaddr == 0 or badaddr == t0+2.