riscv_test.h revision 12771:75508af5d8dc
1// See LICENSE for license details.
2
3#ifndef _ENV_PHYSICAL_SINGLE_CORE_H
4#define _ENV_PHYSICAL_SINGLE_CORE_H
5
6#include "../encoding.h"
7
8//-----------------------------------------------------------------------
9// Begin Macro
10//-----------------------------------------------------------------------
11
12#define RVTEST_RV64U                                                    \
13  .macro init;                                                          \
14  .endm
15
16#define RVTEST_RV64UF                                                   \
17  .macro init;                                                          \
18  RVTEST_FP_ENABLE;                                                     \
19  .endm
20
21#define RVTEST_RV32U                                                    \
22  .macro init;                                                          \
23  .endm
24
25#define RVTEST_RV32UF                                                   \
26  .macro init;                                                          \
27  RVTEST_FP_ENABLE;                                                     \
28  .endm
29
30#define RVTEST_RV64M                                                    \
31  .macro init;                                                          \
32  RVTEST_ENABLE_MACHINE;                                                \
33  .endm
34
35#define RVTEST_RV64S                                                    \
36  .macro init;                                                          \
37  RVTEST_ENABLE_SUPERVISOR;                                             \
38  .endm
39
40#define RVTEST_RV32M                                                    \
41  .macro init;                                                          \
42  RVTEST_ENABLE_MACHINE;                                                \
43  .endm
44
45#define RVTEST_RV32S                                                    \
46  .macro init;                                                          \
47  RVTEST_ENABLE_SUPERVISOR;                                             \
48  .endm
49
50#if __riscv_xlen == 64
51# define CHECK_XLEN li a0, 1; slli a0, a0, 31; bgez a0, 1f; RVTEST_PASS; 1:
52#else
53# define CHECK_XLEN li a0, 1; slli a0, a0, 31; bltz a0, 1f; RVTEST_PASS; 1:
54#endif
55
56#define INIT_PMP                                                        \
57  la t0, 1f;                                                            \
58  csrw mtvec, t0;                                                       \
59  li t0, -1;        /* Set up a PMP to permit all accesses */           \
60  csrw pmpaddr0, t0;                                                    \
61  li t0, PMP_NAPOT | PMP_R | PMP_W | PMP_X;                             \
62  csrw pmpcfg0, t0;                                                     \
63  .align 2;                                                             \
641:
65
66#define INIT_SATP                                                      \
67  la t0, 1f;                                                            \
68  csrw mtvec, t0;                                                       \
69  csrwi sptbr, 0;                                                       \
70  .align 2;                                                             \
711:
72
73#define DELEGATE_NO_TRAPS                                               \
74  la t0, 1f;                                                            \
75  csrw mtvec, t0;                                                       \
76  csrwi medeleg, 0;                                                     \
77  csrwi mideleg, 0;                                                     \
78  csrwi mie, 0;                                                         \
79  .align 2;                                                             \
801:
81
82#define RVTEST_ENABLE_SUPERVISOR                                        \
83  li a0, MSTATUS_MPP & (MSTATUS_MPP >> 1);                              \
84  csrs mstatus, a0;                                                     \
85  li a0, SIP_SSIP | SIP_STIP;                                           \
86  csrs mideleg, a0;                                                     \
87
88#define RVTEST_ENABLE_MACHINE                                           \
89  li a0, MSTATUS_MPP;                                                   \
90  csrs mstatus, a0;                                                     \
91
92#define RVTEST_FP_ENABLE                                                \
93  li a0, MSTATUS_FS & (MSTATUS_FS >> 1);                                \
94  csrs mstatus, a0;                                                     \
95  csrwi fcsr, 0
96
97#define RISCV_MULTICORE_DISABLE                                         \
98  csrr a0, mhartid;                                                     \
99  1: bnez a0, 1b
100
101#define EXTRA_TVEC_USER
102#define EXTRA_TVEC_MACHINE
103#define EXTRA_INIT
104#define EXTRA_INIT_TIMER
105
106//-----------------------------------------------------------------------
107// Begin Macro
108//    Jump to the first test case
109//-----------------------------------------------------------------------
110
111#define RVTEST_CODE_BEGIN                                               \
112        .section .text.init;                                            \
113        .align  6;                                                      \
114        .weak stvec_handler;                                            \
115        .weak mtvec_handler;                                            \
116        .globl _start;                                                  \
117_start:                                                                 \
118        la t0, 1f;                                                      \
119        jr t0;                                                          \
120        .align 2;                                                       \
1211:
122
123//-----------------------------------------------------------------------
124// RVTEST_CODE_END Macro
125//    Call exit syscall to terminate the simulation
126//-----------------------------------------------------------------------
127
128#define EXIT_SYSCALL 93
129#define RVTEST_CODE_END                                                 \
130        li a7, EXIT_SYSCALL;                                            \
131        ecall
132
133//-----------------------------------------------------------------------
134// RVTEST_PASS Macro
135//    Pass 0 as a return code to an EXIT ecall
136//-----------------------------------------------------------------------
137
138#define TESTNUM gp
139#define RVTEST_PASS                                                     \
140        fence;                                                          \
141        li a0, 0;
142
143//-----------------------------------------------------------------------
144// RVTEST_FAIL Macro
145//    Pass test case number as a return code to an EXIT ecall
146//-----------------------------------------------------------------------
147
148#define TESTNUM gp
149#define RVTEST_FAIL                                                     \
150        fence;                                                          \
151        mv a0, TESTNUM;                                                 \
152        RVTEST_CODE_END
153
154//-----------------------------------------------------------------------
155// Data Section Macro
156//-----------------------------------------------------------------------
157
158#define EXTRA_DATA
159
160#define RVTEST_DATA_BEGIN                                               \
161        EXTRA_DATA                                                      \
162        .pushsection .tohost,"aw",@progbits;                            \
163        .align 6; .global tohost; tohost: .dword 0;                     \
164        .align 6; .global fromhost; fromhost: .dword 0;                 \
165        .popsection;                                                    \
166        .align 4; .global begin_signature; begin_signature:
167
168#define RVTEST_DATA_END .align 4; .global end_signature; end_signature:
169
170#endif
171