OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [or1ksim/] [testsuite/] [test-code-or1k/] [inst-set-test/] [inst-set-test.h] - Blame information for rev 118

Details | Compare with Previous | View Log

Line No. Rev Author Line
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 118 jeremybenn
 * Macro to print a half word hex value
144
 *
145
 * Arguments:
146
 *   v  The value to print
147
 * ------------------------------------------------------------------------- */
148
#define PUTHH(v)                                                         \
149
        LOAD_CONST (r3, v)                                              ;\
150
        PUSH (r9)                                                       ;\
151
        l.jal   _puthh                                                  ;\
152
        l.nop                                                           ;\
153
        POP (r9)
154
 
155
/* ----------------------------------------------------------------------------
156
 * Macro to print a byte hex value
157
 *
158
 * Arguments:
159
 *   v  The value to print
160
 * ------------------------------------------------------------------------- */
161
#define PUTHQ(v)                                                         \
162
        LOAD_CONST (r3, v)                                              ;\
163
        PUSH (r9)                                                       ;\
164
        l.jal   _puthq                                                  ;\
165
        l.nop                                                           ;\
166
        POP (r9)
167
 
168
/* ----------------------------------------------------------------------------
169 107 jeremybenn
 * Macro for recording the result of a test
170
 *
171 116 jeremybenn
 * The test result is in reg. Print out the name of test indented two spaces,
172 107 jeremybenn
 * followed by  ": ", either "OK" or "Failed" and a newline.
173
 *
174
 * Arguments:
175
 *   str  Textual name of the test
176
 *   reg  The result to test (not r2)
177
 *   val  Desired result of the test
178
 * ------------------------------------------------------------------------- */
179
#define CHECK_RES(str,reg,val)                                           \
180
        .section .rodata                                                ;\
181
2:                                                                      ;\
182
        .string str                                                     ;\
183
                                                                        ;\
184
        .section .text                                                  ;\
185
        PUSH (reg)                      /* Save the register to test */ ;\
186
                                                                        ;\
187
        LOAD_CONST (r3,2b)              /* Print out the string */      ;\
188
        l.jal   _ptest                                                  ;\
189
        l.nop                                                           ;\
190
                                                                        ;\
191
        LOAD_CONST(r2,val)              /* The desired result */        ;\
192
        POP (reg)                       /* The register to test */      ;\
193
        PUSH (reg)                      /* May need again later */      ;\
194
        l.sfeq  r2,reg                  /* Does the result match? */    ;\
195
        l.bf    3f                                                      ;\
196
        l.nop                                                           ;\
197
                                                                        ;\
198
        l.jal   _pfail                  /* Test failed */               ;\
199
        l.nop                                                           ;\
200
        POP (reg)                       /* Report the register */       ;\
201
        l.add   r3,r0,reg                                               ;\
202
        l.j     4f                                                      ;\
203
        l.nop   NOP_REPORT                                              ;\
204
3:                                                                      ;\
205
        POP (reg)                       /* Discard the register */      ;\
206
        l.jal   _pok                    /* Test succeeded */            ;\
207
        l.nop                                                           ;\
208
4:
209
 
210
/* ----------------------------------------------------------------------------
211
 * Macro for recording the result of a comparison
212
 *
213
 * If the flag is set print the string argument indented by 2 spaces, followed
214
 * by "TRUE" and a  newline, otherwise print the string argument indented by
215
 * two spaces, followed by "FALSE" and a newline.
216
 *
217
 * Arguments:
218
 *   str  Textual name of the test
219
 *   res  Expected result (TRUE or FALSE)
220
 * ------------------------------------------------------------------------- */
221
#define CHECK_FLAG(str,res)                                              \
222
        .section .rodata                                                ;\
223
5:                                                                      ;\
224
        .string str                                                     ;\
225
                                                                        ;\
226
        .section .text                                                  ;\
227
        l.bnf   7f                      /* Branch if result FALSE */    ;\
228
                                                                        ;\
229
        /* Branch for TRUE result */                                    ;\
230
        LOAD_CONST (r3,5b)              /* The string to print */       ;\
231
        l.jal   _ptest                                                  ;\
232
        l.nop                                                           ;\
233
                                                                        ;\
234
        l.addi  r2,r0,TRUE              /* Was it expected? */          ;\
235
        l.addi  r3,r0,res                                               ;\
236
        l.sfeq  r2,r3                                                   ;\
237
        l.bnf   6f                      /* Branch if not expected */    ;\
238
                                                                        ;\
239
        /* Sub-branch for TRUE found and expected */                    ;\
240
        l.jal   _ptrue                                                  ;\
241
        l.nop                                                           ;\
242
        PUTC ('\n')                                                     ;\
243
        l.j     9f                                                      ;\
244
        l.nop                                                           ;\
245
6:                                                                      ;\
246
        /* Sub-branch for TRUE found and not expected */                ;\
247
        l.jal   _ptrue                                                  ;\
248
        l.nop                                                           ;\
249
        l.jal   _punexpected                                            ;\
250
        l.nop                                                           ;\
251
        l.j     9f                                                      ;\
252
        l.nop                                                           ;\
253
                                                                        ;\
254
7:                                                                      ;\
255
        /* Branch for FALSE result */                                   ;\
256
        LOAD_CONST (r3,5b)              /* The string to print */       ;\
257
        l.jal   _ptest                                                  ;\
258
        l.nop                                                           ;\
259
                                                                        ;\
260
        l.addi  r2,r0,FALSE             /* Was it expected? */          ;\
261
        l.addi  r3,r0,res                                               ;\
262
        l.sfeq  r2,r3                                                   ;\
263
        l.bnf   8f                      /* Branch if not expected */    ;\
264
                                                                        ;\
265
        /* Sub-branch for FALSE found and expected */                   ;\
266
        l.jal   _pfalse                                                 ;\
267
        l.nop                                                           ;\
268
        PUTC ('\n')                                                     ;\
269
        l.j     9f                                                      ;\
270
        l.nop                                                           ;\
271
8:                                                                      ;\
272
        /* Sub-branch for FALSE found and not expected */               ;\
273
        l.jal   _pfalse                                                 ;\
274
        l.nop                                                           ;\
275
        l.jal   _punexpected                                            ;\
276
        l.nop                                                           ;\
277
9:
278
 
279
/* ----------------------------------------------------------------------------
280 116 jeremybenn
 * Macro for recording the result of a test (in two regs)
281
 *
282
 * The test result is in reg1 and reg2. Print out the name of test indented
283
 * two spaces, followed by  ": ", either "OK" or "Failed" and a newline.
284
 *
285
 * Arguments:
286
 *   str   Textual name of the test
287
 *   reg1  The result to test (not r2)
288
 *   reg2  The result to test (not r2)
289
 *   val1  Desired result of the test
290
 *   val2  Desired result of the test
291
 * ------------------------------------------------------------------------- */
292
#define CHECK_RES2(reg1, reg2, val1, val2)                               \
293
        PUSH (reg2)                     /* Save the test registers */   ;\
294
        PUSH (reg1)                                                     ;\
295
                                                                        ;\
296
        LOAD_CONST(r2,val1)             /* First desired result */      ;\
297
        POP (reg1)                      /* First register to test */    ;\
298
        PUSH (reg1)                     /* May need again later */      ;\
299
        l.sfeq  r2,reg1                 /* Does the result match? */    ;\
300
        l.bf    10f                                                     ;\
301
        l.nop                                                           ;\
302
                                                                        ;\
303
        /* First register failed. */                                    ;\
304
        l.jal   _pfail                  /* Test failed */               ;\
305
        l.nop                                                           ;\
306
        POP (reg1)                      /* Report the registers */      ;\
307
        l.add   r3,r0,reg1                                              ;\
308
        l.nop   NOP_REPORT                                              ;\
309
        POP (reg2)                      /* Report the registers */      ;\
310
        l.add   r3,r0,reg2                                              ;\
311
        l.j     12f                                                     ;\
312
        l.nop   NOP_REPORT                                              ;\
313
                                                                        ;\
314
        /* First register matched, check the second */                  ;\
315
10:                                                                     ;\
316
        LOAD_CONST(r2,val2)             /* Second desired result */     ;\
317
        POP (reg1)                      /* First register to test */    ;\
318
        POP (reg2)                      /* Second register to test */   ;\
319
        PUSH (reg2)                     /* May need again later */      ;\
320
        PUSH (reg1)                     /* May need again later */      ;\
321
        l.sfeq  r2,reg2                 /* Does the result match? */    ;\
322
        l.bf    11f                                                     ;\
323
        l.nop                                                           ;\
324
                                                                        ;\
325
        /* Second register failed. */                                   ;\
326
        l.jal   _pfail                  /* Test failed */               ;\
327
        l.nop                                                           ;\
328
        POP (reg1)                      /* Report the registers */      ;\
329
        l.add   r3,r0,reg1                                              ;\
330
        l.nop   NOP_REPORT                                              ;\
331
        POP (reg2)                      /* Report the registers */      ;\
332
        l.add   r3,r0,reg2                                              ;\
333
        l.j     12f                                                     ;\
334
        l.nop   NOP_REPORT                                              ;\
335
                                                                        ;\
336
        /* Both registers passed */                                     ;\
337
11:                                                                     ;\
338
        POP (reg1)                      /* Discard the registers */     ;\
339
        POP (reg2)                      /* Discard the registers */     ;\
340
        l.jal   _pok                    /* Test succeeded */            ;\
341
        l.nop                                                           ;\
342
12:
343
 
344
/* ----------------------------------------------------------------------------
345 118 jeremybenn
 * Macro for recording the result of a test
346
 *
347
 * This is a newer version of CHECK_RES, which should eventually become the
348
 * standard macro to use.
349
 *
350
 * The test result is in reg. If it matches the supplied val, print "OK" and a
351
 * newline, otherwise "Failed" and report the value of the register (which will
352
 * be followed by a newline).
353
 *
354
 * Arguments:
355
 *   reg  The result to test (not r2)
356
 *   val  Desired result of the test
357
 * ------------------------------------------------------------------------- */
358
#define CHECK_RES1(reg,val)                                              \
359
        LOAD_CONST(r2,val)              /* The desired result */        ;\
360
        PUSH (reg)                      /* May need again later */      ;\
361
        l.sfeq  r2,reg                  /* Does the result match? */    ;\
362
        l.bf    13f                                                     ;\
363
        l.nop                                                           ;\
364
                                                                        ;\
365
        l.jal   _pfail                  /* Test failed */               ;\
366
        l.nop                                                           ;\
367
        POP (reg)                       /* Report the register */       ;\
368
        l.add   r3,r0,reg                                               ;\
369
        l.j     14f                                                     ;\
370
        l.nop   NOP_REPORT                                              ;\
371
13:                                                                     ;\
372
        POP (reg)                       /* Discard the register */      ;\
373
        l.jal   _pok                    /* Test succeeded */            ;\
374
        l.nop                                                           ;\
375
14:
376
 
377
/* ----------------------------------------------------------------------------
378 107 jeremybenn
 * Macro to report 0xdeaddead and then terminate
379
 * ------------------------------------------------------------------------- */
380
#define TEST_EXIT                                                        \
381
  l.movhi       r3,hi(ALL_DONE)                                         ;\
382
        l.ori   r3,r3,lo(ALL_DONE)                                      ;\
383
        l.nop   NOP_REPORT                                              ;\
384
                                                                        ;\
385
        l.addi  r3,r0,0                                                  ;\
386
        l.nop   NOP_EXIT

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.