6e7be9480b47e8d530e6615d7ba06cf8ac55b802
[riscv-tests.git] / isa / rv64mi / ma_addr.S
1 # See LICENSE for license details.
2
3 #*****************************************************************************
4 # ma_addr.S
5 #-----------------------------------------------------------------------------
6 #
7 # Test misaligned ld/st trap.
8 #
9
10 #include "riscv_test.h"
11 #include "test_macros.h"
12
13 RVTEST_RV64M
14 RVTEST_CODE_BEGIN
15
16 .option norvc
17
18 la s0, data
19
20 # indicate it's a load test
21 li s1, CAUSE_MISALIGNED_LOAD
22
23 #define MISALIGNED_LDST_TEST(testnum, insn, base, offset) \
24 li TESTNUM, testnum; \
25 insn x0, offset(base); \
26 j fail \
27
28 MISALIGNED_LDST_TEST(2, lh, s0, 1)
29 MISALIGNED_LDST_TEST(3, lhu, s0, 1)
30 MISALIGNED_LDST_TEST(4, lw, s0, 1)
31 MISALIGNED_LDST_TEST(5, lw, s0, 2)
32 MISALIGNED_LDST_TEST(6, lw, s0, 3)
33
34 #ifdef __riscv64
35 MISALIGNED_LDST_TEST(7, lwu, s0, 1)
36 MISALIGNED_LDST_TEST(8, lwu, s0, 2)
37 MISALIGNED_LDST_TEST(9, lwu, s0, 3)
38
39 MISALIGNED_LDST_TEST(10, ld, s0, 1)
40 MISALIGNED_LDST_TEST(11, ld, s0, 2)
41 MISALIGNED_LDST_TEST(12, ld, s0, 3)
42 MISALIGNED_LDST_TEST(13, ld, s0, 4)
43 MISALIGNED_LDST_TEST(14, ld, s0, 5)
44 MISALIGNED_LDST_TEST(15, ld, s0, 6)
45 MISALIGNED_LDST_TEST(16, ld, s0, 7)
46 #endif
47
48 # indicate it's a store test
49 li s1, CAUSE_MISALIGNED_STORE
50
51 MISALIGNED_LDST_TEST(22, sh, s0, 1)
52 MISALIGNED_LDST_TEST(23, sw, s0, 1)
53 MISALIGNED_LDST_TEST(24, sw, s0, 2)
54 MISALIGNED_LDST_TEST(25, sw, s0, 3)
55
56 #ifdef __riscv64
57 MISALIGNED_LDST_TEST(26, sd, s0, 1)
58 MISALIGNED_LDST_TEST(27, sd, s0, 2)
59 MISALIGNED_LDST_TEST(28, sd, s0, 3)
60 MISALIGNED_LDST_TEST(29, sd, s0, 4)
61 MISALIGNED_LDST_TEST(30, sd, s0, 5)
62 MISALIGNED_LDST_TEST(31, sd, s0, 6)
63 MISALIGNED_LDST_TEST(32, sd, s0, 7)
64 #endif
65
66 TEST_PASSFAIL
67
68 .align 3
69 mtvec_handler:
70 csrr t0, mcause
71 bne t0, s1, fail
72
73 csrr t0, mepc
74 addi t0, t0, 8
75 csrw mepc, t0
76 mret
77
78 RVTEST_CODE_END
79
80 .data
81 RVTEST_DATA_BEGIN
82
83 data:
84 .dword 0
85
86 TEST_DATA
87
88 RVTEST_DATA_END