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 # RVC cannot be disabled if doing so would cause a misaligned instruction
111 # exception on the next instruction fetch. (This test assumes no other
112 # extensions that support misalignment are present.)
115 andi t2, t2, 1 << ('c' - 'a')
120 csrci misa, 1 << ('c' - 'a')
126 andi t2, t2, 1 << ('c' - 'a')
129 # When RVC is disabled, mret to a misaligned mepc should succeed,
130 # masking off mepc[1].
135 # Try to disable RVC; if it can't be disabled, skip the test.
136 csrci misa, 1 << ('c' - 'a')
138 andi t2, t2, 1 << ('c' - 'a')
145 # mret should transfer control to this branch. Otherwise, it will
146 # transfer control two bytes into the branch, which happens to be the
147 # illegal instruction c.unimp.
150 csrsi misa, 1 << ('c' - 'a')
159 .global stvec_handler
161 # tests 2, 4, 5, 6, and 8 should trap
173 # verify that return address was not written
177 li a1, CAUSE_MISALIGNED_FETCH
181 # verify that epc == &jalr (== t0 - 4)
186 # verify that badaddr == 0 or badaddr == t0+2.