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 |
|
|
/* ----------------------------------------------------------------------------
|
26 |
|
|
* Test coverage
|
27 |
|
|
*
|
28 |
|
|
* The l.lws instruction was omitted from Or1ksim originally. It is specified
|
29 |
|
|
* for ORBIS32, even though it is functionally equivalent to l.lwz.
|
30 |
|
|
*
|
31 |
|
|
* Having fixed the problem, this is (in good software engineering style), a
|
32 |
|
|
* regresison test to go with the fix.
|
33 |
|
|
*
|
34 |
|
|
* Of course what is really needed is a comprehensive instruction test...
|
35 |
|
|
* ------------------------------------------------------------------------- */
|
36 |
|
|
|
37 |
|
|
|
38 |
|
|
#include "spr-defs.h"
|
39 |
|
|
#include "board.h"
|
40 |
|
|
|
41 |
|
|
/* ----------------------------------------------------------------------------
|
42 |
|
|
* Coding conventions
|
43 |
|
|
*
|
44 |
|
|
* A simple rising stack is provided starting at _stack and pointed to by
|
45 |
|
|
* r1. r1 points to the next free word. Only 32-bit registers may be pushed
|
46 |
|
|
* onto the stack.
|
47 |
|
|
*
|
48 |
|
|
* Local labels up to 49 are reserved for macros. Each is used only once in
|
49 |
|
|
* all macros. You can get in a serious mess if you get local label clashing
|
50 |
|
|
* in macros.
|
51 |
|
|
*
|
52 |
|
|
* Arguments to functions are passed in r3 through r8.
|
53 |
|
|
* r9 is the link (return address)
|
54 |
|
|
* r11 is for returning results
|
55 |
|
|
*
|
56 |
|
|
* Only r1 and r2 are preserved across function calls. It is up to the callee
|
57 |
|
|
* to save any other registers required.
|
58 |
|
|
* ------------------------------------------------------------------------- */
|
59 |
|
|
|
60 |
|
|
|
61 |
|
|
/* ----------------------------------------------------------------------------
|
62 |
|
|
* Useful constants
|
63 |
|
|
* ------------------------------------------------------------------------- */
|
64 |
|
|
|
65 |
|
|
/* Indicator of completion */
|
66 |
|
|
#define ALL_DONE (0xdeaddead)
|
67 |
|
|
|
68 |
|
|
/* Logical values */
|
69 |
|
|
#define TRUE 1
|
70 |
|
|
#define FALSE 0
|
71 |
|
|
|
72 |
|
|
|
73 |
|
|
/* ----------------------------------------------------------------------------
|
74 |
|
|
* Macro to push a register onto the stack
|
75 |
|
|
*
|
76 |
|
|
* r1 points to the next free slot. Push the supplied register on, then
|
77 |
|
|
* advance the stack pointer.
|
78 |
|
|
*
|
79 |
|
|
* Arguments:
|
80 |
|
|
* reg The register to push
|
81 |
|
|
*
|
82 |
|
|
* Registers modified
|
83 |
|
|
* r1
|
84 |
|
|
* ------------------------------------------------------------------------- */
|
85 |
|
|
#define PUSH(reg) \
|
86 |
|
|
l.sw 0(r1),reg /* Push */ ;\
|
87 |
|
|
l.addi r1,r1,4 /* Advance the stack */
|
88 |
|
|
|
89 |
|
|
/* ----------------------------------------------------------------------------
|
90 |
|
|
* Macro to pop a register off the stack
|
91 |
|
|
*
|
92 |
|
|
* r1 points to the next free slot. Decrement the stack pointer, then pop the
|
93 |
|
|
* requested register.
|
94 |
|
|
*
|
95 |
|
|
* Arguments:
|
96 |
|
|
* reg The register to pop
|
97 |
|
|
*
|
98 |
|
|
* Registers modified
|
99 |
|
|
* r1
|
100 |
|
|
* ------------------------------------------------------------------------- */
|
101 |
|
|
#define POP(reg) \
|
102 |
|
|
l.addi r1,r1,-4 /* Decrement the stack */ ;\
|
103 |
|
|
l.lws reg,0(r1) /* Pop */
|
104 |
|
|
|
105 |
|
|
/* ----------------------------------------------------------------------------
|
106 |
|
|
* Macro to load a 32-bit constant into a register
|
107 |
|
|
*
|
108 |
|
|
* Arguments:
|
109 |
|
|
* reg The register to load
|
110 |
|
|
* val The value to load
|
111 |
|
|
*
|
112 |
|
|
* ------------------------------------------------------------------------- */
|
113 |
|
|
#define LOAD_CONST(reg,val) \
|
114 |
|
|
l.movhi reg,hi(val) ;\
|
115 |
|
|
l.ori reg,reg,lo(val)
|
116 |
|
|
|
117 |
|
|
/* ----------------------------------------------------------------------------
|
118 |
|
|
* Macro to define and load a pointer to a string
|
119 |
|
|
*
|
120 |
|
|
* Arguments:
|
121 |
|
|
* reg The register to load
|
122 |
|
|
* str The string
|
123 |
|
|
*
|
124 |
|
|
* ------------------------------------------------------------------------- */
|
125 |
|
|
#define LOAD_STR(reg,str) \
|
126 |
|
|
.section .rodata ;\
|
127 |
|
|
1: ;\
|
128 |
|
|
.string str ;\
|
129 |
|
|
;\
|
130 |
|
|
.section .text ;\
|
131 |
|
|
l.movhi reg,hi(1b) ;\
|
132 |
|
|
l.ori reg,reg,lo(1b)
|
133 |
|
|
|
134 |
|
|
/* ----------------------------------------------------------------------------
|
135 |
|
|
* Macro to print a character
|
136 |
|
|
*
|
137 |
|
|
* Arguments:
|
138 |
|
|
* c The character to print
|
139 |
|
|
* ------------------------------------------------------------------------- */
|
140 |
|
|
#define PUTC(c) \
|
141 |
|
|
l.addi r3,r0,c ;\
|
142 |
|
|
l.nop NOP_PUTC
|
143 |
|
|
|
144 |
|
|
/* ----------------------------------------------------------------------------
|
145 |
|
|
* Macro for recording the result of a test
|
146 |
|
|
*
|
147 |
|
|
* The test result is in r4. Print out the name of test indented two spaces,
|
148 |
|
|
* followed by ": ", either "OK" or "Failed" and a newline.
|
149 |
|
|
*
|
150 |
|
|
* Arguments:
|
151 |
|
|
* str Textual name of the test
|
152 |
|
|
* reg The result to test (not r2)
|
153 |
|
|
* val Desired result of the test
|
154 |
|
|
* ------------------------------------------------------------------------- */
|
155 |
|
|
#define CHECK_RES(str,reg,val) \
|
156 |
|
|
.section .rodata ;\
|
157 |
|
|
2: ;\
|
158 |
|
|
.string str ;\
|
159 |
|
|
;\
|
160 |
|
|
.section .text ;\
|
161 |
|
|
PUSH (reg) /* Save the register to test */ ;\
|
162 |
|
|
;\
|
163 |
|
|
LOAD_CONST (r3,2b) /* Print out the string */ ;\
|
164 |
|
|
l.jal _ptest ;\
|
165 |
|
|
l.nop ;\
|
166 |
|
|
;\
|
167 |
|
|
LOAD_CONST(r2,val) /* The desired result */ ;\
|
168 |
|
|
POP (reg) /* The register to test */ ;\
|
169 |
|
|
PUSH (reg) /* May need again later */ ;\
|
170 |
|
|
l.sfeq r2,reg /* Does the result match? */ ;\
|
171 |
|
|
l.bf 3f ;\
|
172 |
|
|
l.nop ;\
|
173 |
|
|
;\
|
174 |
|
|
l.jal _pfail /* Test failed */ ;\
|
175 |
|
|
l.nop ;\
|
176 |
|
|
POP (reg) /* Report the register */ ;\
|
177 |
|
|
l.add r3,r0,reg ;\
|
178 |
|
|
l.j 4f ;\
|
179 |
|
|
l.nop NOP_REPORT ;\
|
180 |
|
|
3: ;\
|
181 |
|
|
POP (reg) /* Discard the register */ ;\
|
182 |
|
|
l.jal _pok /* Test succeeded */ ;\
|
183 |
|
|
l.nop ;\
|
184 |
|
|
4:
|
185 |
|
|
|
186 |
|
|
/* ----------------------------------------------------------------------------
|
187 |
|
|
* Macro for recording the result of a comparison
|
188 |
|
|
*
|
189 |
|
|
* If the flag is set print the string argument indented by 2 spaces, followed
|
190 |
|
|
* by "TRUE" and a newline, otherwise print the string argument indented by
|
191 |
|
|
* two spaces, followed by "FALSE" and a newline.
|
192 |
|
|
*
|
193 |
|
|
* Arguments:
|
194 |
|
|
* str Textual name of the test
|
195 |
|
|
* res Expected result (TRUE or FALSE)
|
196 |
|
|
* ------------------------------------------------------------------------- */
|
197 |
|
|
#define CHECK_FLAG(str,res) \
|
198 |
|
|
.section .rodata ;\
|
199 |
|
|
5: ;\
|
200 |
|
|
.string str ;\
|
201 |
|
|
;\
|
202 |
|
|
.section .text ;\
|
203 |
|
|
l.bnf 7f /* Branch if result FALSE */ ;\
|
204 |
|
|
;\
|
205 |
|
|
/* Branch for TRUE result */ ;\
|
206 |
|
|
LOAD_CONST (r3,5b) /* The string to print */ ;\
|
207 |
|
|
l.jal _ptest ;\
|
208 |
|
|
l.nop ;\
|
209 |
|
|
;\
|
210 |
|
|
l.addi r2,r0,TRUE /* Was it expected? */ ;\
|
211 |
|
|
l.addi r3,r0,res ;\
|
212 |
|
|
l.sfeq r2,r3 ;\
|
213 |
|
|
l.bnf 6f /* Branch if not expected */ ;\
|
214 |
|
|
;\
|
215 |
|
|
/* Sub-branch for TRUE found and expected */ ;\
|
216 |
|
|
l.jal _ptrue ;\
|
217 |
|
|
l.nop ;\
|
218 |
|
|
PUTC ('\n') ;\
|
219 |
|
|
l.j 9f ;\
|
220 |
|
|
l.nop ;\
|
221 |
|
|
6: ;\
|
222 |
|
|
/* Sub-branch for TRUE found and not expected */ ;\
|
223 |
|
|
l.jal _ptrue ;\
|
224 |
|
|
l.nop ;\
|
225 |
|
|
l.jal _punexpected ;\
|
226 |
|
|
l.nop ;\
|
227 |
|
|
l.j 9f ;\
|
228 |
|
|
l.nop ;\
|
229 |
|
|
;\
|
230 |
|
|
7: ;\
|
231 |
|
|
/* Branch for FALSE result */ ;\
|
232 |
|
|
LOAD_CONST (r3,5b) /* The string to print */ ;\
|
233 |
|
|
l.jal _ptest ;\
|
234 |
|
|
l.nop ;\
|
235 |
|
|
;\
|
236 |
|
|
l.addi r2,r0,FALSE /* Was it expected? */ ;\
|
237 |
|
|
l.addi r3,r0,res ;\
|
238 |
|
|
l.sfeq r2,r3 ;\
|
239 |
|
|
l.bnf 8f /* Branch if not expected */ ;\
|
240 |
|
|
;\
|
241 |
|
|
/* Sub-branch for FALSE found and expected */ ;\
|
242 |
|
|
l.jal _pfalse ;\
|
243 |
|
|
l.nop ;\
|
244 |
|
|
PUTC ('\n') ;\
|
245 |
|
|
l.j 9f ;\
|
246 |
|
|
l.nop ;\
|
247 |
|
|
8: ;\
|
248 |
|
|
/* Sub-branch for FALSE found and not expected */ ;\
|
249 |
|
|
l.jal _pfalse ;\
|
250 |
|
|
l.nop ;\
|
251 |
|
|
l.jal _punexpected ;\
|
252 |
|
|
l.nop ;\
|
253 |
|
|
9:
|
254 |
|
|
|
255 |
|
|
/* ----------------------------------------------------------------------------
|
256 |
|
|
* Macro to report 0xdeaddead and then terminate
|
257 |
|
|
* ------------------------------------------------------------------------- */
|
258 |
|
|
#define TEST_EXIT \
|
259 |
|
|
l.movhi r3,hi(ALL_DONE) ;\
|
260 |
|
|
l.ori r3,r3,lo(ALL_DONE) ;\
|
261 |
|
|
l.nop NOP_REPORT ;\
|
262 |
|
|
;\
|
263 |
|
|
l.addi r3,r0,0 ;\
|
264 |
|
|
l.nop NOP_EXIT
|