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 584

Go to most recent revision | 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
        l.movhi r1,hi(_stack)           /* Set up the stack */
76
        l.ori   r1,r1,lo(_stack)
77
 
78
        l.j     _start                  /* Jump to the start of code */
79
        l.nop
80
 
81
/* ----------------------------------------------------------------------------
82 121 jeremybenn
 * Alignment exception
83 107 jeremybenn
 *
84
 * Don't be tempted to use the LOAD_STR macro here, it will dump us back into
85 121 jeremybenn
 * text section.
86
 *
87
 * The handling is a bit dubious at present. We just patch the instruction and
88
 * restart. This will go wrong in branch delay slots. Really we need to single
89
 * step past and then continue.
90
 *
91
 * Print a message identifying the exception type.
92 107 jeremybenn
 * ------------------------------------------------------------------------- */
93
        .section .rodata
94 121 jeremybenn
50:     .string "  ALIGNMENT exception\n"
95 107 jeremybenn
 
96
        .section .boot-text
97 121 jeremybenn
        .org    0x600
98
        .global _align
99
_align:
100
        /* Report exception */
101 107 jeremybenn
        LOAD_CONST (r3, 50b)
102
        l.jal   _puts
103
        l.nop
104
 
105 121 jeremybenn
        /* Patch with l.nop */
106
        l.mfspr r2,r0,SPR_EPCR_BASE     /* Addr of problem instr */
107
        LOAD_CONST (r3, 0x15000000)     /* l.nop */
108
        l.sw    0(r2),r3
109
 
110
        /* All done */
111
        l.rfe
112
_align_end:
113
 
114
/* ----------------------------------------------------------------------------
115
 * Illegal instruction exception
116
 *
117
 * Don't be tempted to use the LOAD_STR macro here, it will dump us back into
118
 * text section.
119
 *
120
 * The handling is a bit dubious at present. We just patch the instruction and
121
 * restart. This will go wrong in branch delay slots. Really we need to single
122
 * step past and then continue.
123
 *
124
 * Print a message identifying the exception type.
125
 * ------------------------------------------------------------------------- */
126
        .section .rodata
127
51:     .string "  ILLEGAL INSTRUCTION exception\n"
128
 
129
        .section .boot-text
130
        .org    0x700
131
        .global _illegal
132
_illegal:
133
        /* Report exception */
134 107 jeremybenn
        LOAD_CONST (r3, 51b)
135
        l.jal   _puts
136
        l.nop
137
 
138 121 jeremybenn
        /* Patch with l.nop */
139 107 jeremybenn
        l.mfspr r2,r0,SPR_EPCR_BASE     /* Addr of problem instr */
140 121 jeremybenn
        LOAD_CONST (r3, 0x15000000)     /* l.nop */
141
        l.sw    0(r2),r3
142 107 jeremybenn
 
143 121 jeremybenn
        /* All done */
144
        l.rfe
145
_illegal_end:
146
 
147
/* ----------------------------------------------------------------------------
148
 * Range exception
149
 *
150
 * Don't be tempted to use the LOAD_STR macro here, it will dump us back into
151
 * text section.
152
 *
153
 * The handling is a bit dubious at present. We just patch the instruction and
154
 * restart. This will go wrong in branch delay slots. Really we need to single
155
 * step past and then continue.
156
 *
157
 * Print a message identifying the exception type.
158
 * ------------------------------------------------------------------------- */
159
        .section .rodata
160
52:     .string "  RANGE exception\n"
161
 
162
        .section .boot-text
163
        .org    0xb00
164
        .global _range
165
_range:
166
        /* Report exception */
167 107 jeremybenn
        LOAD_CONST (r3, 52b)
168
        l.jal   _puts
169
        l.nop
170
 
171
        /* Patch with l.nop */
172
        l.mfspr r2,r0,SPR_EPCR_BASE     /* Addr of problem instr */
173
        LOAD_CONST (r3, 0x15000000)     /* l.nop */
174
        l.sw    0(r2),r3
175
 
176
        /* All done */
177
        l.rfe
178
_range_end:
179
 
180
/* ----------------------------------------------------------------------------
181
 * End of exception vectors
182
 *
183
 * Guarantee the exception vector space does not have general purpose code
184
 * ------------------------------------------------------------------------- */
185
        .org    0xffc
186
        l.nop
187
 
188
/* ----------------------------------------------------------------------------
189
 * All subroutines are in the text section.
190
 * ------------------------------------------------------------------------- */
191
        .section .text
192
 
193
/* ----------------------------------------------------------------------------
194
 * Subroutine to print out a string
195
 *
196
 * The string is followed by a newline
197
 *
198
 * Parameters:
199
 *  r3  Pointer to the string to print
200
 * ------------------------------------------------------------------------- */
201
        .global _puts
202
_puts:
203 116 jeremybenn
        PUSH (r3)
204 107 jeremybenn
        l.add   r2,r0,r3                /* Copy the string pointer */
205
 
206
        /* Loop getting and printing each char until end of string */
207
60:     l.lbz   r3,0(r2)
208
        l.sfeq  r3,r0                   /* NULL termination? */
209
        l.bf    61f
210
 
211
        l.addi  r2,r2,1                 /* Delay slot, move to next char */
212
        l.j     60b                     /* Repeat */
213
        l.nop   NOP_PUTC                /* Delay slot */
214
 
215 116 jeremybenn
61:     POP (r3)
216
        l.jr    r9                      /* Return */
217 107 jeremybenn
        l.nop
218
 
219
/* ----------------------------------------------------------------------------
220 116 jeremybenn
 * Subroutine to print out a register in hex
221
 *
222
 * Parameters:
223
 *  r3  The value to print
224
 * ------------------------------------------------------------------------- */
225
        .section .rodata
226
62:     .string "0123456789abcdef"
227
        .section .text
228
 
229
        .global _puth
230
_puth:
231
        PUSH (r3)
232
        PUSH (r4)
233
 
234
        l.add   r2,r0,r3                /* Copy the value pointer */
235
        LOAD_CONST (r4,62b)             /* Ptr to digit chars */
236
 
237
        l.srli  r3,r2,28                /* Print each digit in turn. */
238
        l.add   r3,r4,r3
239
        l.lbz   r3,0(r3)
240
        l.nop   NOP_PUTC
241
 
242
        l.srli  r3,r2,24
243
        l.andi  r3,r3,0xf
244
        l.add   r3,r4,r3
245
        l.lbz   r3,0(r3)
246
        l.nop   NOP_PUTC
247
 
248
        l.srli  r3,r2,20
249
        l.andi  r3,r3,0xf
250
        l.add   r3,r4,r3
251
        l.lbz   r3,0(r3)
252
        l.nop   NOP_PUTC
253
 
254
        l.srli  r3,r2,16
255
        l.andi  r3,r3,0xf
256
        l.add   r3,r4,r3
257
        l.lbz   r3,0(r3)
258
        l.nop   NOP_PUTC
259
 
260
        l.srli  r3,r2,12
261
        l.andi  r3,r3,0xf
262
        l.add   r3,r4,r3
263
        l.lbz   r3,0(r3)
264
        l.nop   NOP_PUTC
265
 
266
        l.srli  r3,r2,8
267
        l.andi  r3,r3,0xf
268
        l.add   r3,r4,r3
269
        l.lbz   r3,0(r3)
270
        l.nop   NOP_PUTC
271
 
272
        l.srli  r3,r2,4
273
        l.andi  r3,r3,0xf
274
        l.add   r3,r4,r3
275
        l.lbz   r3,0(r3)
276
        l.nop   NOP_PUTC
277
 
278
        l.andi  r3,r2,0xf
279
        l.add   r3,r4,r3
280
        l.lbz   r3,0(r3)
281
        l.nop   NOP_PUTC
282
 
283
        POP (r4)                        /* Return */
284
        POP (r3)
285
        l.jr    r9
286
        l.nop
287
 
288
/* ----------------------------------------------------------------------------
289 118 jeremybenn
 * Subroutine to print out the lower half of a register in hex
290
 *
291
 * Parameters:
292
 *  r3  The value to print
293
 * ------------------------------------------------------------------------- */
294
        .section .rodata
295
63:     .string "0123456789abcdef"
296
        .section .text
297
 
298
        .global _puthh
299
_puthh:
300
        PUSH (r3)
301
        PUSH (r4)
302
 
303
        l.add   r2,r0,r3                /* Copy the value pointer */
304
        LOAD_CONST (r4,63b)             /* Ptr to digit chars */
305
 
306
        l.srli  r3,r2,12                /* Print each digit in turn. */
307
        l.andi  r3,r3,0xf
308
        l.add   r3,r4,r3
309
        l.lbz   r3,0(r3)
310
        l.nop   NOP_PUTC
311
 
312
        l.srli  r3,r2,8
313
        l.andi  r3,r3,0xf
314
        l.add   r3,r4,r3
315
        l.lbz   r3,0(r3)
316
        l.nop   NOP_PUTC
317
 
318
        l.srli  r3,r2,4
319
        l.andi  r3,r3,0xf
320
        l.add   r3,r4,r3
321
        l.lbz   r3,0(r3)
322
        l.nop   NOP_PUTC
323
 
324
        l.andi  r3,r2,0xf
325
        l.add   r3,r4,r3
326
        l.lbz   r3,0(r3)
327
        l.nop   NOP_PUTC
328
 
329
        POP (r4)                        /* Return */
330
        POP (r3)
331
        l.jr    r9
332
        l.nop
333
 
334
/* ----------------------------------------------------------------------------
335
 * Subroutine to print out the lowest byte of a register in hex
336
 *
337
 * Parameters:
338
 *  r3  The value to print
339
 * ------------------------------------------------------------------------- */
340
        .section .rodata
341
63:     .string "0123456789abcdef"
342
        .section .text
343
 
344
        .global _puthq
345
_puthq:
346
        PUSH (r3)
347
        PUSH (r4)
348
 
349
        l.add   r2,r0,r3                /* Copy the value pointer */
350
        LOAD_CONST (r4,63b)             /* Ptr to digit chars */
351
 
352
        l.srli  r3,r2,4                 /* Print each digit in turn. */
353
        l.andi  r3,r3,0xf
354
        l.add   r3,r4,r3
355
        l.lbz   r3,0(r3)
356
        l.nop   NOP_PUTC
357
 
358
        l.andi  r3,r2,0xf
359
        l.add   r3,r4,r3
360
        l.lbz   r3,0(r3)
361
        l.nop   NOP_PUTC
362
 
363
        POP (r4)                        /* Return */
364
        POP (r3)
365
        l.jr    r9
366
        l.nop
367
 
368
/* ----------------------------------------------------------------------------
369 107 jeremybenn
 * Subroutine to print out a test name prompt
370
 *
371
 * The string is preceded by two spaces
372
 *
373
 * Parameters:
374
 *  r3  Pointer to the test name to print
375
 * ------------------------------------------------------------------------- */
376
        .global _ptest
377
_ptest:
378 116 jeremybenn
        PUSH (r9)                       /* Save the return address */
379
        PUSH (r3)                       /* Save the test name for later */
380 107 jeremybenn
 
381 116 jeremybenn
        LOAD_STR (r3, "  ")             /* Prefix */
382 107 jeremybenn
        l.jal   _puts
383
        l.nop
384
 
385
        POP(r3)                         /* Test name */
386
        l.jal   _puts
387
        l.nop
388
 
389
        POP (r9)
390
        l.jr    r9
391
        l.nop
392
 
393
/* ----------------------------------------------------------------------------
394
 * Subroutine to print out "OK"
395
 *
396
 * The string is followed by a newline
397
 * ------------------------------------------------------------------------- */
398
        .global _pok
399
_pok:
400 116 jeremybenn
        PUSH (r9)                       /* Save the return address */
401
        PUSH (r3)
402 107 jeremybenn
 
403 116 jeremybenn
        LOAD_STR (r3, "OK\n")
404 107 jeremybenn
        l.jal   _puts
405
        l.nop
406
 
407 116 jeremybenn
        POP (r3)
408 107 jeremybenn
        POP (r9)
409
        l.jr    r9
410
        l.nop
411
 
412
/* ----------------------------------------------------------------------------
413
 * Subroutine to print out "Failed"
414
 *
415
 * The string is followed by a ": ", which will then allow a report
416
 * ------------------------------------------------------------------------- */
417
        .global _pfail
418
_pfail:
419 116 jeremybenn
        PUSH (r9)                       /* Save the return address */
420
        PUSH (r3)
421 107 jeremybenn
 
422 116 jeremybenn
        LOAD_STR (r3, "Failed: ")
423 107 jeremybenn
        l.jal   _puts
424
        l.nop
425
 
426 116 jeremybenn
        POP (r3)
427 107 jeremybenn
        POP (r9)
428
        l.jr    r9
429
        l.nop
430
 
431
/* ----------------------------------------------------------------------------
432
 * Subroutine to print out "TRUE"
433
 * ------------------------------------------------------------------------- */
434
        .global _ptrue
435
_ptrue:
436 116 jeremybenn
        PUSH (r9)                       /* Save the return address */
437
        PUSH (r3)
438 107 jeremybenn
 
439 116 jeremybenn
        LOAD_STR (r3, "TRUE")
440 107 jeremybenn
        l.jal   _puts
441
        l.nop
442
 
443 116 jeremybenn
        POP (r3)
444 107 jeremybenn
        POP (r9)
445
        l.jr    r9
446
        l.nop
447
 
448
/* ----------------------------------------------------------------------------
449
 * Subroutine to print out "FALSE"
450
 * ------------------------------------------------------------------------- */
451
        .global _pfalse
452
_pfalse:
453 116 jeremybenn
        PUSH (r9)                       /* Save the return address */
454
        PUSH (r3)
455 107 jeremybenn
 
456 116 jeremybenn
        LOAD_STR (r3, "FALSE")
457 107 jeremybenn
        l.jal   _puts
458
        l.nop
459
 
460 116 jeremybenn
        POP (r3)
461 107 jeremybenn
        POP (r9)
462
        l.jr    r9
463
        l.nop
464
 
465
/* ----------------------------------------------------------------------------
466
 * Subroutine to print out "unexpected"
467
 *
468
 * Preceded by a space and followed by a newline
469
 * ------------------------------------------------------------------------- */
470
        .global _punexpected
471
_punexpected:
472 116 jeremybenn
        PUSH (r9)                       /* Save the return address */
473
        PUSH (r3)
474 107 jeremybenn
 
475 116 jeremybenn
        LOAD_STR (r3, " unexpected\n")
476 107 jeremybenn
        l.jal   _puts
477
        l.nop
478
 
479 116 jeremybenn
        POP (r3)
480 107 jeremybenn
        POP (r9)
481
        l.jr    r9
482
        l.nop

powered by: WebSVN 2.1.0

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