OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [or1ksim/] [or1ksim-0.4.0/] [testsuite/] [test-code-or1k/] [inst-set-test/] [inst-set-test.S] - Blame information for rev 116

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 107 jeremybenn
 * Subroutine to print out a test name prompt
240
 *
241
 * The string is preceded by two spaces
242
 *
243
 * Parameters:
244
 *  r3  Pointer to the test name to print
245
 * ------------------------------------------------------------------------- */
246
        .global _ptest
247
_ptest:
248 116 jeremybenn
        PUSH (r9)                       /* Save the return address */
249
        PUSH (r3)                       /* Save the test name for later */
250 107 jeremybenn
 
251 116 jeremybenn
        LOAD_STR (r3, "  ")             /* Prefix */
252 107 jeremybenn
        l.jal   _puts
253
        l.nop
254
 
255
        POP(r3)                         /* Test name */
256
        l.jal   _puts
257
        l.nop
258
 
259
        POP (r9)
260
        l.jr    r9
261
        l.nop
262
 
263
/* ----------------------------------------------------------------------------
264
 * Subroutine to print out "OK"
265
 *
266
 * The string is followed by a newline
267
 * ------------------------------------------------------------------------- */
268
        .global _pok
269
_pok:
270 116 jeremybenn
        PUSH (r9)                       /* Save the return address */
271
        PUSH (r3)
272 107 jeremybenn
 
273 116 jeremybenn
        LOAD_STR (r3, "OK\n")
274 107 jeremybenn
        l.jal   _puts
275
        l.nop
276
 
277 116 jeremybenn
        POP (r3)
278 107 jeremybenn
        POP (r9)
279
        l.jr    r9
280
        l.nop
281
 
282
/* ----------------------------------------------------------------------------
283
 * Subroutine to print out "Failed"
284
 *
285
 * The string is followed by a ": ", which will then allow a report
286
 * ------------------------------------------------------------------------- */
287
        .global _pfail
288
_pfail:
289 116 jeremybenn
        PUSH (r9)                       /* Save the return address */
290
        PUSH (r3)
291 107 jeremybenn
 
292 116 jeremybenn
        LOAD_STR (r3, "Failed: ")
293 107 jeremybenn
        l.jal   _puts
294
        l.nop
295
 
296 116 jeremybenn
        POP (r3)
297 107 jeremybenn
        POP (r9)
298
        l.jr    r9
299
        l.nop
300
 
301
/* ----------------------------------------------------------------------------
302
 * Subroutine to print out "TRUE"
303
 * ------------------------------------------------------------------------- */
304
        .global _ptrue
305
_ptrue:
306 116 jeremybenn
        PUSH (r9)                       /* Save the return address */
307
        PUSH (r3)
308 107 jeremybenn
 
309 116 jeremybenn
        LOAD_STR (r3, "TRUE")
310 107 jeremybenn
        l.jal   _puts
311
        l.nop
312
 
313 116 jeremybenn
        POP (r3)
314 107 jeremybenn
        POP (r9)
315
        l.jr    r9
316
        l.nop
317
 
318
/* ----------------------------------------------------------------------------
319
 * Subroutine to print out "FALSE"
320
 * ------------------------------------------------------------------------- */
321
        .global _pfalse
322
_pfalse:
323 116 jeremybenn
        PUSH (r9)                       /* Save the return address */
324
        PUSH (r3)
325 107 jeremybenn
 
326 116 jeremybenn
        LOAD_STR (r3, "FALSE")
327 107 jeremybenn
        l.jal   _puts
328
        l.nop
329
 
330 116 jeremybenn
        POP (r3)
331 107 jeremybenn
        POP (r9)
332
        l.jr    r9
333
        l.nop
334
 
335
/* ----------------------------------------------------------------------------
336
 * Subroutine to print out "unexpected"
337
 *
338
 * Preceded by a space and followed by a newline
339
 * ------------------------------------------------------------------------- */
340
        .global _punexpected
341
_punexpected:
342 116 jeremybenn
        PUSH (r9)                       /* Save the return address */
343
        PUSH (r3)
344 107 jeremybenn
 
345 116 jeremybenn
        LOAD_STR (r3, " unexpected\n")
346 107 jeremybenn
        l.jal   _puts
347
        l.nop
348
 
349 116 jeremybenn
        POP (r3)
350 107 jeremybenn
        POP (r9)
351
        l.jr    r9
352
        l.nop

powered by: WebSVN 2.1.0

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