ERET -> xRET; new memory map
[riscv-tests.git] / isa / rv64si / ma_fetch.S
1 # See LICENSE for license details.
2
3 #*****************************************************************************
4 # ma_fetch.S
5 #-----------------------------------------------------------------------------
6 #
7 # Test misaligned fetch trap.
8 #
9
10 #include "riscv_test.h"
11 #include "test_macros.h"
12
13 RVTEST_RV64S
14 RVTEST_CODE_BEGIN
15
16 #ifdef __MACHINE_MODE
17 #define sscratch mscratch
18 #define sstatus mstatus
19 #define scause mcause
20 #define sepc mepc
21 #define sret mret
22 #define stvec_handler mtvec_handler
23 #endif
24
25 .option norvc
26
27 # Without RVC, the jalr should trap, and the handler will skip ahead.
28 # With RVC, the jalr should not trap, and "j fail" should get skipped.
29 li TESTNUM, 2
30 li t1, 0
31 la t0, 1f
32 jalr t1, t0, 2
33 1:
34 .option rvc
35 c.j fail
36 c.j 2f
37 .option norvc
38 j fail
39 2:
40
41 // This test should pass, since JALR ignores the target LSB
42 li TESTNUM, 3
43 la t0, 1f
44 jalr t1, t0, 1
45 1:
46 j 1f
47 j fail
48 1:
49
50 li TESTNUM, 4
51 li t1, 0
52 la t0, 1f
53 jalr t1, t0, 3
54 1:
55 .option rvc
56 c.j fail
57 c.j 2f
58 .option norvc
59 j fail
60 2:
61
62 j pass
63
64 TEST_PASSFAIL
65
66 stvec_handler:
67 # tests 2 and 4 should trap
68 li a0, 2
69 beq TESTNUM, a0, 1f
70 li a0, 4
71 beq TESTNUM, a0, 1f
72 j fail
73 1:
74
75 # verify that return address was not written
76 bnez t1, fail
77
78 # verify trap cause
79 li a1, CAUSE_MISALIGNED_FETCH
80 csrr a0, scause
81 bne a0, a1, fail
82
83 # verify that epc == &jalr (== t0 - 4)
84 csrr a1, sepc
85 addi t0, t0, -4
86 bne t0, a1, fail
87
88 addi a1, a1, 12
89 csrw sepc, a1
90 sret
91
92 RVTEST_CODE_END
93
94 .data
95 RVTEST_DATA_BEGIN
96
97 TEST_DATA
98
99 RVTEST_DATA_END