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.S] - Blame information for rev 787

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 107 jeremybenn
/* inst-set-test.S. Instruction set test library for Or1ksim
2
 *
3
 * Copyright (C) 1999-2006 OpenCores
4
 * Copyright (C) 2010 Embecosm Limited
5
 *
6
 * Contributors various OpenCores participants
7
 * Contributor Jeremy Bennett 
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 .
23
 */
24
 
25
/* ----------------------------------------------------------------------------
26
 * Coding conventions
27
 *
28
 * A simple rising stack is provided starting at _stack and pointed to by
29
 * r1. r1 points to the next free word. Only 32-bit registers may be pushed
30
 * onto the stack.
31
 *
32
 * Local labels up to 49 are reserved for macros. Each is used only once in
33
 * all macros. You can get in a serious mess if you get local label clashing
34
 * in macros.
35
 *
36
 * Arguments to functions are passed in r3 through r8.
37
 * r9 is the link (return address)
38
 * r11 is for returning results
39
 *
40 116 jeremybenn
 * All registers apart from r2, r9 and r11 are preserved across function calls.
41 107 jeremybenn
 * ------------------------------------------------------------------------- */
42
 
43
/* ----------------------------------------------------------------------------
44
 * This library contains the stack implementation and reset sequence and a set
45
 * of library functions.
46
 *
47
 * The functions provided here provide simple utilities that are useful when
48
 * writing tests in assembler.
49
 * ------------------------------------------------------------------------- */
50
 
51
#include "inst-set-test.h"
52
 
53
/* ----------------------------------------------------------------------------
54
 * Simple stack, will be pointed to by r1, which is the next empty slot
55
 * ------------------------------------------------------------------------- */
56
        .section .stack
57
        .balign 4
58
        .global _stack
59
_stack:
60
        .space  0x1000,0x0
61
 
62
/* ----------------------------------------------------------------------------
63
 * Exception handling
64
 * ------------------------------------------------------------------------- */
65
        .section .boot-text
66
 
67
/* ----------------------------------------------------------------------------
68
 * Reset exception
69
 *
70
 * Set up the stack and jump to _start
71
 * ------------------------------------------------------------------------- */
72
        .org 0x100
73
        .global _reset
74
_reset:
75 787 jeremybenn
    // Clear R0 on start-up. There is no guarantee that R0 is hardwired to zero,
76
    // and indeed it is not when simulating the or1200 Verilog core.
77
    l.andi  r0,r0,0x0
78
 
79 107 jeremybenn
        l.movhi r1,hi(_stack)           /* Set up the stack */
80
        l.ori   r1,r1,lo(_stack)
81
 
82
        l.j     _start                  /* Jump to the start of code */
83
        l.nop
84
 
85
/* ----------------------------------------------------------------------------
86 121 jeremybenn
 * Alignment exception
87 107 jeremybenn
 *
88
 * Don't be tempted to use the LOAD_STR macro here, it will dump us back into
89 121 jeremybenn
 * text section.
90
 *
91
 * The handling is a bit dubious at present. We just patch the instruction and
92
 * restart. This will go wrong in branch delay slots. Really we need to single
93
 * step past and then continue.
94
 *
95
 * Print a message identifying the exception type.
96 107 jeremybenn
 * ------------------------------------------------------------------------- */
97
        .section .rodata
98 121 jeremybenn
50:     .string "  ALIGNMENT exception\n"
99 107 jeremybenn
 
100
        .section .boot-text
101 121 jeremybenn
        .org    0x600
102
        .global _align
103
_align:
104
        /* Report exception */
105 107 jeremybenn
        LOAD_CONST (r3, 50b)
106
        l.jal   _puts
107
        l.nop
108
 
109 121 jeremybenn
        /* Patch with l.nop */
110
        l.mfspr r2,r0,SPR_EPCR_BASE     /* Addr of problem instr */
111
        LOAD_CONST (r3, 0x15000000)     /* l.nop */
112
        l.sw    0(r2),r3
113
 
114
        /* All done */
115
        l.rfe
116
_align_end:
117
 
118
/* ----------------------------------------------------------------------------
119
 * Illegal instruction exception
120
 *
121
 * Don't be tempted to use the LOAD_STR macro here, it will dump us back into
122
 * text section.
123
 *
124
 * The handling is a bit dubious at present. We just patch the instruction and
125
 * restart. This will go wrong in branch delay slots. Really we need to single
126
 * step past and then continue.
127
 *
128
 * Print a message identifying the exception type.
129
 * ------------------------------------------------------------------------- */
130
        .section .rodata
131
51:     .string "  ILLEGAL INSTRUCTION exception\n"
132
 
133
        .section .boot-text
134
        .org    0x700
135
        .global _illegal
136
_illegal:
137
        /* Report exception */
138 107 jeremybenn
        LOAD_CONST (r3, 51b)
139
        l.jal   _puts
140
        l.nop
141
 
142 121 jeremybenn
        /* Patch with l.nop */
143 107 jeremybenn
        l.mfspr r2,r0,SPR_EPCR_BASE     /* Addr of problem instr */
144 121 jeremybenn
        LOAD_CONST (r3, 0x15000000)     /* l.nop */
145
        l.sw    0(r2),r3
146 107 jeremybenn
 
147 121 jeremybenn
        /* All done */
148
        l.rfe
149
_illegal_end:
150
 
151
/* ----------------------------------------------------------------------------
152
 * Range exception
153
 *
154
 * Don't be tempted to use the LOAD_STR macro here, it will dump us back into
155
 * text section.
156
 *
157
 * The handling is a bit dubious at present. We just patch the instruction and
158
 * restart. This will go wrong in branch delay slots. Really we need to single
159
 * step past and then continue.
160
 *
161
 * Print a message identifying the exception type.
162
 * ------------------------------------------------------------------------- */
163
        .section .rodata
164
52:     .string "  RANGE exception\n"
165
 
166
        .section .boot-text
167
        .org    0xb00
168
        .global _range
169
_range:
170
        /* Report exception */
171 107 jeremybenn
        LOAD_CONST (r3, 52b)
172
        l.jal   _puts
173
        l.nop
174
 
175
        /* Patch with l.nop */
176
        l.mfspr r2,r0,SPR_EPCR_BASE     /* Addr of problem instr */
177
        LOAD_CONST (r3, 0x15000000)     /* l.nop */
178
        l.sw    0(r2),r3
179
 
180
        /* All done */
181
        l.rfe
182
_range_end:
183
 
184
/* ----------------------------------------------------------------------------
185
 * End of exception vectors
186
 *
187
 * Guarantee the exception vector space does not have general purpose code
188
 * ------------------------------------------------------------------------- */
189
        .org    0xffc
190
        l.nop
191
 
192
/* ----------------------------------------------------------------------------
193
 * All subroutines are in the text section.
194
 * ------------------------------------------------------------------------- */
195
        .section .text
196
 
197
/* ----------------------------------------------------------------------------
198
 * Subroutine to print out a string
199
 *
200
 * The string is followed by a newline
201
 *
202
 * Parameters:
203
 *  r3  Pointer to the string to print
204
 * ------------------------------------------------------------------------- */
205
        .global _puts
206
_puts:
207 116 jeremybenn
        PUSH (r3)
208 107 jeremybenn
        l.add   r2,r0,r3                /* Copy the string pointer */
209
 
210
        /* Loop getting and printing each char until end of string */
211
60:     l.lbz   r3,0(r2)
212
        l.sfeq  r3,r0                   /* NULL termination? */
213
        l.bf    61f
214
 
215
        l.addi  r2,r2,1                 /* Delay slot, move to next char */
216
        l.j     60b                     /* Repeat */
217
        l.nop   NOP_PUTC                /* Delay slot */
218
 
219 116 jeremybenn
61:     POP (r3)
220
        l.jr    r9                      /* Return */
221 107 jeremybenn
        l.nop
222
 
223
/* ----------------------------------------------------------------------------
224 116 jeremybenn
 * Subroutine to print out a register in hex
225
 *
226
 * Parameters:
227
 *  r3  The value to print
228
 * ------------------------------------------------------------------------- */
229
        .section .rodata
230
62:     .string "0123456789abcdef"
231
        .section .text
232
 
233
        .global _puth
234
_puth:
235
        PUSH (r3)
236
        PUSH (r4)
237
 
238
        l.add   r2,r0,r3                /* Copy the value pointer */
239
        LOAD_CONST (r4,62b)             /* Ptr to digit chars */
240
 
241
        l.srli  r3,r2,28                /* Print each digit in turn. */
242
        l.add   r3,r4,r3
243
        l.lbz   r3,0(r3)
244
        l.nop   NOP_PUTC
245
 
246
        l.srli  r3,r2,24
247
        l.andi  r3,r3,0xf
248
        l.add   r3,r4,r3
249
        l.lbz   r3,0(r3)
250
        l.nop   NOP_PUTC
251
 
252
        l.srli  r3,r2,20
253
        l.andi  r3,r3,0xf
254
        l.add   r3,r4,r3
255
        l.lbz   r3,0(r3)
256
        l.nop   NOP_PUTC
257
 
258
        l.srli  r3,r2,16
259
        l.andi  r3,r3,0xf
260
        l.add   r3,r4,r3
261
        l.lbz   r3,0(r3)
262
        l.nop   NOP_PUTC
263
 
264
        l.srli  r3,r2,12
265
        l.andi  r3,r3,0xf
266
        l.add   r3,r4,r3
267
        l.lbz   r3,0(r3)
268
        l.nop   NOP_PUTC
269
 
270
        l.srli  r3,r2,8
271
        l.andi  r3,r3,0xf
272
        l.add   r3,r4,r3
273
        l.lbz   r3,0(r3)
274
        l.nop   NOP_PUTC
275
 
276
        l.srli  r3,r2,4
277
        l.andi  r3,r3,0xf
278
        l.add   r3,r4,r3
279
        l.lbz   r3,0(r3)
280
        l.nop   NOP_PUTC
281
 
282
        l.andi  r3,r2,0xf
283
        l.add   r3,r4,r3
284
        l.lbz   r3,0(r3)
285
        l.nop   NOP_PUTC
286
 
287
        POP (r4)                        /* Return */
288
        POP (r3)
289
        l.jr    r9
290
        l.nop
291
 
292
/* ----------------------------------------------------------------------------
293 118 jeremybenn
 * Subroutine to print out the lower half of a register in hex
294
 *
295
 * Parameters:
296
 *  r3  The value to print
297
 * ------------------------------------------------------------------------- */
298
        .section .rodata
299
63:     .string "0123456789abcdef"
300
        .section .text
301
 
302
        .global _puthh
303
_puthh:
304
        PUSH (r3)
305
        PUSH (r4)
306
 
307
        l.add   r2,r0,r3                /* Copy the value pointer */
308
        LOAD_CONST (r4,63b)             /* Ptr to digit chars */
309
 
310
        l.srli  r3,r2,12                /* Print each digit in turn. */
311
        l.andi  r3,r3,0xf
312
        l.add   r3,r4,r3
313
        l.lbz   r3,0(r3)
314
        l.nop   NOP_PUTC
315
 
316
        l.srli  r3,r2,8
317
        l.andi  r3,r3,0xf
318
        l.add   r3,r4,r3
319
        l.lbz   r3,0(r3)
320
        l.nop   NOP_PUTC
321
 
322
        l.srli  r3,r2,4
323
        l.andi  r3,r3,0xf
324
        l.add   r3,r4,r3
325
        l.lbz   r3,0(r3)
326
        l.nop   NOP_PUTC
327
 
328
        l.andi  r3,r2,0xf
329
        l.add   r3,r4,r3
330
        l.lbz   r3,0(r3)
331
        l.nop   NOP_PUTC
332
 
333
        POP (r4)                        /* Return */
334
        POP (r3)
335
        l.jr    r9
336
        l.nop
337
 
338
/* ----------------------------------------------------------------------------
339
 * Subroutine to print out the lowest byte of a register in hex
340
 *
341
 * Parameters:
342
 *  r3  The value to print
343
 * ------------------------------------------------------------------------- */
344
        .section .rodata
345
63:     .string "0123456789abcdef"
346
        .section .text
347
 
348
        .global _puthq
349
_puthq:
350
        PUSH (r3)
351
        PUSH (r4)
352
 
353
        l.add   r2,r0,r3                /* Copy the value pointer */
354
        LOAD_CONST (r4,63b)             /* Ptr to digit chars */
355
 
356
        l.srli  r3,r2,4                 /* Print each digit in turn. */
357
        l.andi  r3,r3,0xf
358
        l.add   r3,r4,r3
359
        l.lbz   r3,0(r3)
360
        l.nop   NOP_PUTC
361
 
362
        l.andi  r3,r2,0xf
363
        l.add   r3,r4,r3
364
        l.lbz   r3,0(r3)
365
        l.nop   NOP_PUTC
366
 
367
        POP (r4)                        /* Return */
368
        POP (r3)
369
        l.jr    r9
370
        l.nop
371
 
372
/* ----------------------------------------------------------------------------
373 107 jeremybenn
 * Subroutine to print out a test name prompt
374
 *
375
 * The string is preceded by two spaces
376
 *
377
 * Parameters:
378
 *  r3  Pointer to the test name to print
379
 * ------------------------------------------------------------------------- */
380
        .global _ptest
381
_ptest:
382 116 jeremybenn
        PUSH (r9)                       /* Save the return address */
383
        PUSH (r3)                       /* Save the test name for later */
384 107 jeremybenn
 
385 116 jeremybenn
        LOAD_STR (r3, "  ")             /* Prefix */
386 107 jeremybenn
        l.jal   _puts
387
        l.nop
388
 
389
        POP(r3)                         /* Test name */
390
        l.jal   _puts
391
        l.nop
392
 
393
        POP (r9)
394
        l.jr    r9
395
        l.nop
396
 
397
/* ----------------------------------------------------------------------------
398
 * Subroutine to print out "OK"
399
 *
400
 * The string is followed by a newline
401
 * ------------------------------------------------------------------------- */
402
        .global _pok
403
_pok:
404 116 jeremybenn
        PUSH (r9)                       /* Save the return address */
405
        PUSH (r3)
406 107 jeremybenn
 
407 116 jeremybenn
        LOAD_STR (r3, "OK\n")
408 107 jeremybenn
        l.jal   _puts
409
        l.nop
410
 
411 116 jeremybenn
        POP (r3)
412 107 jeremybenn
        POP (r9)
413
        l.jr    r9
414
        l.nop
415
 
416
/* ----------------------------------------------------------------------------
417
 * Subroutine to print out "Failed"
418
 *
419
 * The string is followed by a ": ", which will then allow a report
420
 * ------------------------------------------------------------------------- */
421
        .global _pfail
422
_pfail:
423 116 jeremybenn
        PUSH (r9)                       /* Save the return address */
424
        PUSH (r3)
425 107 jeremybenn
 
426 116 jeremybenn
        LOAD_STR (r3, "Failed: ")
427 107 jeremybenn
        l.jal   _puts
428
        l.nop
429
 
430 116 jeremybenn
        POP (r3)
431 107 jeremybenn
        POP (r9)
432
        l.jr    r9
433
        l.nop
434
 
435
/* ----------------------------------------------------------------------------
436
 * Subroutine to print out "TRUE"
437
 * ------------------------------------------------------------------------- */
438
        .global _ptrue
439
_ptrue:
440 116 jeremybenn
        PUSH (r9)                       /* Save the return address */
441
        PUSH (r3)
442 107 jeremybenn
 
443 116 jeremybenn
        LOAD_STR (r3, "TRUE")
444 107 jeremybenn
        l.jal   _puts
445
        l.nop
446
 
447 116 jeremybenn
        POP (r3)
448 107 jeremybenn
        POP (r9)
449
        l.jr    r9
450
        l.nop
451
 
452
/* ----------------------------------------------------------------------------
453
 * Subroutine to print out "FALSE"
454
 * ------------------------------------------------------------------------- */
455
        .global _pfalse
456
_pfalse:
457 116 jeremybenn
        PUSH (r9)                       /* Save the return address */
458
        PUSH (r3)
459 107 jeremybenn
 
460 116 jeremybenn
        LOAD_STR (r3, "FALSE")
461 107 jeremybenn
        l.jal   _puts
462
        l.nop
463
 
464 116 jeremybenn
        POP (r3)
465 107 jeremybenn
        POP (r9)
466
        l.jr    r9
467
        l.nop
468
 
469
/* ----------------------------------------------------------------------------
470
 * Subroutine to print out "unexpected"
471
 *
472
 * Preceded by a space and followed by a newline
473
 * ------------------------------------------------------------------------- */
474
        .global _punexpected
475
_punexpected:
476 116 jeremybenn
        PUSH (r9)                       /* Save the return address */
477
        PUSH (r3)
478 107 jeremybenn
 
479 116 jeremybenn
        LOAD_STR (r3, " unexpected\n")
480 107 jeremybenn
        l.jal   _puts
481
        l.nop
482
 
483 116 jeremybenn
        POP (r3)
484 107 jeremybenn
        POP (r9)
485
        l.jr    r9
486
        l.nop

powered by: WebSVN 2.1.0

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