1 |
107 |
jeremybenn |
/* inst-set-test.h. Macros for instruction set testing
|
2 |
|
|
|
3 |
|
|
Copyright (C) 1999-2006 OpenCores
|
4 |
|
|
Copyright (C) 2010 Embecosm Limited
|
5 |
|
|
|
6 |
|
|
Contributors various OpenCores participants
|
7 |
|
|
Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
|
8 |
|
|
|
9 |
|
|
This file is part of OpenRISC 1000 Architectural Simulator.
|
10 |
|
|
|
11 |
|
|
This program is free software; you can redistribute it and/or modify it
|
12 |
|
|
under the terms of the GNU General Public License as published by the Free
|
13 |
|
|
Software Foundation; either version 3 of the License, or (at your option)
|
14 |
|
|
any later version.
|
15 |
|
|
|
16 |
|
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
17 |
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
18 |
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
19 |
|
|
more details.
|
20 |
|
|
|
21 |
|
|
You should have received a copy of the GNU General Public License along
|
22 |
|
|
with this program. If not, see <http: www.gnu.org/licenses/>. */
|
23 |
|
|
|
24 |
|
|
|
25 |
|
|
#include "spr-defs.h"
|
26 |
|
|
#include "board.h"
|
27 |
|
|
|
28 |
|
|
/* ----------------------------------------------------------------------------
|
29 |
116 |
jeremybenn |
* Coding conventions are described in inst-set-test.S
|
30 |
107 |
jeremybenn |
* ------------------------------------------------------------------------- */
|
31 |
|
|
|
32 |
|
|
|
33 |
|
|
/* ----------------------------------------------------------------------------
|
34 |
|
|
* Useful constants
|
35 |
|
|
* ------------------------------------------------------------------------- */
|
36 |
|
|
|
37 |
|
|
/* Indicator of completion */
|
38 |
|
|
#define ALL_DONE (0xdeaddead)
|
39 |
|
|
|
40 |
|
|
/* Logical values */
|
41 |
|
|
#define TRUE 1
|
42 |
|
|
#define FALSE 0
|
43 |
|
|
|
44 |
|
|
|
45 |
|
|
/* ----------------------------------------------------------------------------
|
46 |
|
|
* Macro to push a register onto the stack
|
47 |
|
|
*
|
48 |
|
|
* r1 points to the next free slot. Push the supplied register on, then
|
49 |
|
|
* advance the stack pointer.
|
50 |
|
|
*
|
51 |
|
|
* Arguments:
|
52 |
|
|
* reg The register to push
|
53 |
|
|
*
|
54 |
|
|
* Registers modified
|
55 |
|
|
* r1
|
56 |
|
|
* ------------------------------------------------------------------------- */
|
57 |
|
|
#define PUSH(reg) \
|
58 |
|
|
l.sw 0(r1),reg /* Push */ ;\
|
59 |
|
|
l.addi r1,r1,4 /* Advance the stack */
|
60 |
|
|
|
61 |
|
|
/* ----------------------------------------------------------------------------
|
62 |
|
|
* Macro to pop a register off the stack
|
63 |
|
|
*
|
64 |
|
|
* r1 points to the next free slot. Decrement the stack pointer, then pop the
|
65 |
|
|
* requested register.
|
66 |
|
|
*
|
67 |
|
|
* Arguments:
|
68 |
|
|
* reg The register to pop
|
69 |
|
|
*
|
70 |
|
|
* Registers modified
|
71 |
|
|
* r1
|
72 |
|
|
* ------------------------------------------------------------------------- */
|
73 |
|
|
#define POP(reg) \
|
74 |
|
|
l.addi r1,r1,-4 /* Decrement the stack */ ;\
|
75 |
|
|
l.lws reg,0(r1) /* Pop */
|
76 |
|
|
|
77 |
|
|
/* ----------------------------------------------------------------------------
|
78 |
|
|
* Macro to load a 32-bit constant into a register
|
79 |
|
|
*
|
80 |
|
|
* Arguments:
|
81 |
|
|
* reg The register to load
|
82 |
|
|
* val The value to load
|
83 |
|
|
*
|
84 |
|
|
* ------------------------------------------------------------------------- */
|
85 |
|
|
#define LOAD_CONST(reg,val) \
|
86 |
|
|
l.movhi reg,hi(val) ;\
|
87 |
|
|
l.ori reg,reg,lo(val)
|
88 |
|
|
|
89 |
|
|
/* ----------------------------------------------------------------------------
|
90 |
|
|
* Macro to define and load a pointer to a string
|
91 |
|
|
*
|
92 |
|
|
* Arguments:
|
93 |
|
|
* reg The register to load
|
94 |
|
|
* str The string
|
95 |
|
|
*
|
96 |
|
|
* ------------------------------------------------------------------------- */
|
97 |
|
|
#define LOAD_STR(reg,str) \
|
98 |
|
|
.section .rodata ;\
|
99 |
|
|
1: ;\
|
100 |
|
|
.string str ;\
|
101 |
|
|
;\
|
102 |
|
|
.section .text ;\
|
103 |
|
|
l.movhi reg,hi(1b) ;\
|
104 |
|
|
l.ori reg,reg,lo(1b)
|
105 |
|
|
|
106 |
|
|
/* ----------------------------------------------------------------------------
|
107 |
|
|
* Macro to print a character
|
108 |
|
|
*
|
109 |
|
|
* Arguments:
|
110 |
|
|
* c The character to print
|
111 |
|
|
* ------------------------------------------------------------------------- */
|
112 |
|
|
#define PUTC(c) \
|
113 |
|
|
l.addi r3,r0,c ;\
|
114 |
|
|
l.nop NOP_PUTC
|
115 |
|
|
|
116 |
|
|
/* ----------------------------------------------------------------------------
|
117 |
116 |
jeremybenn |
* Macro to print a string
|
118 |
|
|
*
|
119 |
|
|
* Arguments:
|
120 |
|
|
* s The string to print
|
121 |
|
|
* ------------------------------------------------------------------------- */
|
122 |
|
|
#define PUTS(s) \
|
123 |
|
|
LOAD_STR (r3, s) ;\
|
124 |
|
|
PUSH (r9) ;\
|
125 |
|
|
l.jal _puts ;\
|
126 |
|
|
l.nop ;\
|
127 |
|
|
POP (r9)
|
128 |
|
|
|
129 |
|
|
/* ----------------------------------------------------------------------------
|
130 |
|
|
* Macro to print a hex value
|
131 |
|
|
*
|
132 |
|
|
* Arguments:
|
133 |
|
|
* v The value to print
|
134 |
|
|
* ------------------------------------------------------------------------- */
|
135 |
|
|
#define PUTH(v) \
|
136 |
|
|
LOAD_CONST (r3, v) ;\
|
137 |
|
|
PUSH (r9) ;\
|
138 |
|
|
l.jal _puth ;\
|
139 |
|
|
l.nop ;\
|
140 |
|
|
POP (r9)
|
141 |
|
|
|
142 |
|
|
/* ----------------------------------------------------------------------------
|
143 |
107 |
jeremybenn |
* Macro for recording the result of a test
|
144 |
|
|
*
|
145 |
116 |
jeremybenn |
* The test result is in reg. Print out the name of test indented two spaces,
|
146 |
107 |
jeremybenn |
* followed by ": ", either "OK" or "Failed" and a newline.
|
147 |
|
|
*
|
148 |
|
|
* Arguments:
|
149 |
|
|
* str Textual name of the test
|
150 |
|
|
* reg The result to test (not r2)
|
151 |
|
|
* val Desired result of the test
|
152 |
|
|
* ------------------------------------------------------------------------- */
|
153 |
|
|
#define CHECK_RES(str,reg,val) \
|
154 |
|
|
.section .rodata ;\
|
155 |
|
|
2: ;\
|
156 |
|
|
.string str ;\
|
157 |
|
|
;\
|
158 |
|
|
.section .text ;\
|
159 |
|
|
PUSH (reg) /* Save the register to test */ ;\
|
160 |
|
|
;\
|
161 |
|
|
LOAD_CONST (r3,2b) /* Print out the string */ ;\
|
162 |
|
|
l.jal _ptest ;\
|
163 |
|
|
l.nop ;\
|
164 |
|
|
;\
|
165 |
|
|
LOAD_CONST(r2,val) /* The desired result */ ;\
|
166 |
|
|
POP (reg) /* The register to test */ ;\
|
167 |
|
|
PUSH (reg) /* May need again later */ ;\
|
168 |
|
|
l.sfeq r2,reg /* Does the result match? */ ;\
|
169 |
|
|
l.bf 3f ;\
|
170 |
|
|
l.nop ;\
|
171 |
|
|
;\
|
172 |
|
|
l.jal _pfail /* Test failed */ ;\
|
173 |
|
|
l.nop ;\
|
174 |
|
|
POP (reg) /* Report the register */ ;\
|
175 |
|
|
l.add r3,r0,reg ;\
|
176 |
|
|
l.j 4f ;\
|
177 |
|
|
l.nop NOP_REPORT ;\
|
178 |
|
|
3: ;\
|
179 |
|
|
POP (reg) /* Discard the register */ ;\
|
180 |
|
|
l.jal _pok /* Test succeeded */ ;\
|
181 |
|
|
l.nop ;\
|
182 |
|
|
4:
|
183 |
|
|
|
184 |
|
|
/* ----------------------------------------------------------------------------
|
185 |
|
|
* Macro for recording the result of a comparison
|
186 |
|
|
*
|
187 |
|
|
* If the flag is set print the string argument indented by 2 spaces, followed
|
188 |
|
|
* by "TRUE" and a newline, otherwise print the string argument indented by
|
189 |
|
|
* two spaces, followed by "FALSE" and a newline.
|
190 |
|
|
*
|
191 |
|
|
* Arguments:
|
192 |
|
|
* str Textual name of the test
|
193 |
|
|
* res Expected result (TRUE or FALSE)
|
194 |
|
|
* ------------------------------------------------------------------------- */
|
195 |
|
|
#define CHECK_FLAG(str,res) \
|
196 |
|
|
.section .rodata ;\
|
197 |
|
|
5: ;\
|
198 |
|
|
.string str ;\
|
199 |
|
|
;\
|
200 |
|
|
.section .text ;\
|
201 |
|
|
l.bnf 7f /* Branch if result FALSE */ ;\
|
202 |
|
|
;\
|
203 |
|
|
/* Branch for TRUE result */ ;\
|
204 |
|
|
LOAD_CONST (r3,5b) /* The string to print */ ;\
|
205 |
|
|
l.jal _ptest ;\
|
206 |
|
|
l.nop ;\
|
207 |
|
|
;\
|
208 |
|
|
l.addi r2,r0,TRUE /* Was it expected? */ ;\
|
209 |
|
|
l.addi r3,r0,res ;\
|
210 |
|
|
l.sfeq r2,r3 ;\
|
211 |
|
|
l.bnf 6f /* Branch if not expected */ ;\
|
212 |
|
|
;\
|
213 |
|
|
/* Sub-branch for TRUE found and expected */ ;\
|
214 |
|
|
l.jal _ptrue ;\
|
215 |
|
|
l.nop ;\
|
216 |
|
|
PUTC ('\n') ;\
|
217 |
|
|
l.j 9f ;\
|
218 |
|
|
l.nop ;\
|
219 |
|
|
6: ;\
|
220 |
|
|
/* Sub-branch for TRUE found and not expected */ ;\
|
221 |
|
|
l.jal _ptrue ;\
|
222 |
|
|
l.nop ;\
|
223 |
|
|
l.jal _punexpected ;\
|
224 |
|
|
l.nop ;\
|
225 |
|
|
l.j 9f ;\
|
226 |
|
|
l.nop ;\
|
227 |
|
|
;\
|
228 |
|
|
7: ;\
|
229 |
|
|
/* Branch for FALSE result */ ;\
|
230 |
|
|
LOAD_CONST (r3,5b) /* The string to print */ ;\
|
231 |
|
|
l.jal _ptest ;\
|
232 |
|
|
l.nop ;\
|
233 |
|
|
;\
|
234 |
|
|
l.addi r2,r0,FALSE /* Was it expected? */ ;\
|
235 |
|
|
l.addi r3,r0,res ;\
|
236 |
|
|
l.sfeq r2,r3 ;\
|
237 |
|
|
l.bnf 8f /* Branch if not expected */ ;\
|
238 |
|
|
;\
|
239 |
|
|
/* Sub-branch for FALSE found and expected */ ;\
|
240 |
|
|
l.jal _pfalse ;\
|
241 |
|
|
l.nop ;\
|
242 |
|
|
PUTC ('\n') ;\
|
243 |
|
|
l.j 9f ;\
|
244 |
|
|
l.nop ;\
|
245 |
|
|
8: ;\
|
246 |
|
|
/* Sub-branch for FALSE found and not expected */ ;\
|
247 |
|
|
l.jal _pfalse ;\
|
248 |
|
|
l.nop ;\
|
249 |
|
|
l.jal _punexpected ;\
|
250 |
|
|
l.nop ;\
|
251 |
|
|
9:
|
252 |
|
|
|
253 |
|
|
/* ----------------------------------------------------------------------------
|
254 |
116 |
jeremybenn |
* Macro for recording the result of a test (in two regs)
|
255 |
|
|
*
|
256 |
|
|
* The test result is in reg1 and reg2. Print out the name of test indented
|
257 |
|
|
* two spaces, followed by ": ", either "OK" or "Failed" and a newline.
|
258 |
|
|
*
|
259 |
|
|
* Arguments:
|
260 |
|
|
* str Textual name of the test
|
261 |
|
|
* reg1 The result to test (not r2)
|
262 |
|
|
* reg2 The result to test (not r2)
|
263 |
|
|
* val1 Desired result of the test
|
264 |
|
|
* val2 Desired result of the test
|
265 |
|
|
* ------------------------------------------------------------------------- */
|
266 |
|
|
#define CHECK_RES2(reg1, reg2, val1, val2) \
|
267 |
|
|
PUSH (reg2) /* Save the test registers */ ;\
|
268 |
|
|
PUSH (reg1) ;\
|
269 |
|
|
;\
|
270 |
|
|
LOAD_CONST(r2,val1) /* First desired result */ ;\
|
271 |
|
|
POP (reg1) /* First register to test */ ;\
|
272 |
|
|
PUSH (reg1) /* May need again later */ ;\
|
273 |
|
|
l.sfeq r2,reg1 /* Does the result match? */ ;\
|
274 |
|
|
l.bf 10f ;\
|
275 |
|
|
l.nop ;\
|
276 |
|
|
;\
|
277 |
|
|
/* First register failed. */ ;\
|
278 |
|
|
l.jal _pfail /* Test failed */ ;\
|
279 |
|
|
l.nop ;\
|
280 |
|
|
POP (reg1) /* Report the registers */ ;\
|
281 |
|
|
l.add r3,r0,reg1 ;\
|
282 |
|
|
l.nop NOP_REPORT ;\
|
283 |
|
|
POP (reg2) /* Report the registers */ ;\
|
284 |
|
|
l.add r3,r0,reg2 ;\
|
285 |
|
|
l.j 12f ;\
|
286 |
|
|
l.nop NOP_REPORT ;\
|
287 |
|
|
;\
|
288 |
|
|
/* First register matched, check the second */ ;\
|
289 |
|
|
10: ;\
|
290 |
|
|
LOAD_CONST(r2,val2) /* Second desired result */ ;\
|
291 |
|
|
POP (reg1) /* First register to test */ ;\
|
292 |
|
|
POP (reg2) /* Second register to test */ ;\
|
293 |
|
|
PUSH (reg2) /* May need again later */ ;\
|
294 |
|
|
PUSH (reg1) /* May need again later */ ;\
|
295 |
|
|
l.sfeq r2,reg2 /* Does the result match? */ ;\
|
296 |
|
|
l.bf 11f ;\
|
297 |
|
|
l.nop ;\
|
298 |
|
|
;\
|
299 |
|
|
/* Second register failed. */ ;\
|
300 |
|
|
l.jal _pfail /* Test failed */ ;\
|
301 |
|
|
l.nop ;\
|
302 |
|
|
POP (reg1) /* Report the registers */ ;\
|
303 |
|
|
l.add r3,r0,reg1 ;\
|
304 |
|
|
l.nop NOP_REPORT ;\
|
305 |
|
|
POP (reg2) /* Report the registers */ ;\
|
306 |
|
|
l.add r3,r0,reg2 ;\
|
307 |
|
|
l.j 12f ;\
|
308 |
|
|
l.nop NOP_REPORT ;\
|
309 |
|
|
;\
|
310 |
|
|
/* Both registers passed */ ;\
|
311 |
|
|
11: ;\
|
312 |
|
|
POP (reg1) /* Discard the registers */ ;\
|
313 |
|
|
POP (reg2) /* Discard the registers */ ;\
|
314 |
|
|
l.jal _pok /* Test succeeded */ ;\
|
315 |
|
|
l.nop ;\
|
316 |
|
|
12:
|
317 |
|
|
|
318 |
|
|
/* ----------------------------------------------------------------------------
|
319 |
107 |
jeremybenn |
* Macro to report 0xdeaddead and then terminate
|
320 |
|
|
* ------------------------------------------------------------------------- */
|
321 |
|
|
#define TEST_EXIT \
|
322 |
|
|
l.movhi r3,hi(ALL_DONE) ;\
|
323 |
|
|
l.ori r3,r3,lo(ALL_DONE) ;\
|
324 |
|
|
l.nop NOP_REPORT ;\
|
325 |
|
|
;\
|
326 |
|
|
l.addi r3,r0,0 ;\
|
327 |
|
|
l.nop NOP_EXIT
|