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 118

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

powered by: WebSVN 2.1.0

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