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 107

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
 * Only r1 and r2 are preserved across function calls. It is up to the callee
41
 * to save any other registers required.
42
 * ------------------------------------------------------------------------- */
43
 
44
/* ----------------------------------------------------------------------------
45
 * This library contains the stack implementation and reset sequence and a set
46
 * of library functions.
47
 *
48
 * The functions provided here provide simple utilities that are useful when
49
 * writing tests in assembler.
50
 * ------------------------------------------------------------------------- */
51
 
52
#include "inst-set-test.h"
53
 
54
/* ----------------------------------------------------------------------------
55
 * Simple stack, will be pointed to by r1, which is the next empty slot
56
 * ------------------------------------------------------------------------- */
57
        .section .stack
58
        .balign 4
59
        .global _stack
60
_stack:
61
        .space  0x1000,0x0
62
 
63
/* ----------------------------------------------------------------------------
64
 * Exception handling
65
 * ------------------------------------------------------------------------- */
66
        .section .boot-text
67
 
68
/* ----------------------------------------------------------------------------
69
 * Reset exception
70
 *
71
 * Set up the stack and jump to _start
72
 * ------------------------------------------------------------------------- */
73
        .org 0x100
74
        .global _reset
75
_reset:
76
        l.movhi r1,hi(_stack)           /* Set up the stack */
77
        l.ori   r1,r1,lo(_stack)
78
 
79
        l.j     _start                  /* Jump to the start of code */
80
        l.nop
81
 
82
/* ----------------------------------------------------------------------------
83
 * Range exception
84
 *
85
 * Don't be tempted to use the LOAD_STR macro here, it will dump us back into
86
 * text space.
87
 *
88
 * Print a message about the instruction triggering the exception. Then
89
 * replace it by l.nop and return.
90
 * ------------------------------------------------------------------------- */
91
        .section .rodata
92
50:     .string "  RANGE exception\n"
93
51:     .string "  - caused by: "
94
52:     .string "  - SR value:  "
95
 
96
        .section .boot-text
97
        .org    0xb00
98
        .global _range
99
_range:
100
        /* Note exception */
101
        LOAD_CONST (r3, 50b)
102
        l.jal   _puts
103
        l.nop
104
 
105
        /* Report problem instruction */
106
        LOAD_CONST (r3, 51b)
107
        l.jal   _puts
108
        l.nop
109
 
110
        l.mfspr r2,r0,SPR_EPCR_BASE     /* Addr of problem instr */
111
        l.lws   r3,0(r2)                /* The actual instruction */
112
        l.nop   NOP_REPORT
113
 
114
        /* Report status register */
115
        LOAD_CONST (r3, 52b)
116
        l.jal   _puts
117
        l.nop
118
 
119
        l.mfspr r3,r0,SPR_ESR_BASE      /* Status reg */
120
        l.nop   NOP_REPORT
121
 
122
        /* Patch with l.nop */
123
        l.mfspr r2,r0,SPR_EPCR_BASE     /* Addr of problem instr */
124
        LOAD_CONST (r3, 0x15000000)     /* l.nop */
125
        l.sw    0(r2),r3
126
 
127
        /* All done */
128
        l.rfe
129
_range_end:
130
 
131
/* ----------------------------------------------------------------------------
132
 * End of exception vectors
133
 *
134
 * Guarantee the exception vector space does not have general purpose code
135
 * ------------------------------------------------------------------------- */
136
        .org    0xffc
137
        l.nop
138
 
139
/* ----------------------------------------------------------------------------
140
 * All subroutines are in the text section.
141
 * ------------------------------------------------------------------------- */
142
        .section .text
143
 
144
/* ----------------------------------------------------------------------------
145
 * Subroutine to print out a string
146
 *
147
 * The string is followed by a newline
148
 *
149
 * Parameters:
150
 *  r3  Pointer to the string to print
151
 * ------------------------------------------------------------------------- */
152
        .global _puts
153
_puts:
154
        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
61:     l.jr    r9                      /* Return */
166
        l.nop
167
 
168
/* ----------------------------------------------------------------------------
169
 * Subroutine to print out a test name prompt
170
 *
171
 * The string is preceded by two spaces
172
 *
173
 * Parameters:
174
 *  r3  Pointer to the test name to print
175
 * ------------------------------------------------------------------------- */
176
        .global _ptest
177
_ptest:
178
        PUSH(r9)                        /* Save the return address */
179
        PUSH(r3)                        /* Save the test name for later */
180
 
181
        LOAD_STR(r3, "  ")              /* Prefix */
182
        l.jal   _puts
183
        l.nop
184
 
185
        POP(r3)                         /* Test name */
186
        l.jal   _puts
187
        l.nop
188
 
189
        POP (r9)
190
        l.jr    r9
191
        l.nop
192
 
193
/* ----------------------------------------------------------------------------
194
 * Subroutine to print out "OK"
195
 *
196
 * The string is followed by a newline
197
 * ------------------------------------------------------------------------- */
198
        .global _pok
199
_pok:
200
        PUSH(r9)                        /* Save the return address */
201
 
202
        LOAD_STR(r3, "OK\n")
203
        l.jal   _puts
204
        l.nop
205
 
206
        POP (r9)
207
        l.jr    r9
208
        l.nop
209
 
210
/* ----------------------------------------------------------------------------
211
 * Subroutine to print out "Failed"
212
 *
213
 * The string is followed by a ": ", which will then allow a report
214
 * ------------------------------------------------------------------------- */
215
        .global _pfail
216
_pfail:
217
        PUSH(r9)                        /* Save the return address */
218
 
219
        LOAD_STR(r3, "Failed: ")
220
        l.jal   _puts
221
        l.nop
222
 
223
        POP (r9)
224
        l.jr    r9
225
        l.nop
226
 
227
/* ----------------------------------------------------------------------------
228
 * Subroutine to print out "TRUE"
229
 * ------------------------------------------------------------------------- */
230
        .global _ptrue
231
_ptrue:
232
        PUSH(r9)                        /* Save the return address */
233
 
234
        LOAD_STR(r3, "TRUE")
235
        l.jal   _puts
236
        l.nop
237
 
238
        POP (r9)
239
        l.jr    r9
240
        l.nop
241
 
242
/* ----------------------------------------------------------------------------
243
 * Subroutine to print out "FALSE"
244
 * ------------------------------------------------------------------------- */
245
        .global _pfalse
246
_pfalse:
247
        PUSH(r9)                        /* Save the return address */
248
 
249
        LOAD_STR(r3, "FALSE")
250
        l.jal   _puts
251
        l.nop
252
 
253
        POP (r9)
254
        l.jr    r9
255
        l.nop
256
 
257
/* ----------------------------------------------------------------------------
258
 * Subroutine to print out "unexpected"
259
 *
260
 * Preceded by a space and followed by a newline
261
 * ------------------------------------------------------------------------- */
262
        .global _punexpected
263
_punexpected:
264
        PUSH(r9)                        /* Save the return address */
265
 
266
        LOAD_STR(r3, " unexpected\n")
267
        l.jal   _puts
268
        l.nop
269
 
270
        POP (r9)
271
        l.jr    r9
272
        l.nop

powered by: WebSVN 2.1.0

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