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.0rc1/] [testsuite/] [test-code-or1k/] [lws-test/] [lws-test.S] - Blame information for rev 460

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 104 jeremybenn
/* lws-test.S. l.lws instruction test of 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
 * Test coverage
27
 *
28
 * The l.lws instruction was omitted from Or1ksim originally. It is specified
29
 * for ORBIS32, even though it is functionally equivalent to l.lwz.
30
 *
31
 * Having fixed the problem, this is (in good software engineering style), a
32
 * regresison test to go with the fix.
33
 *
34
 * Of course what is really needed is a comprehensive instruction test...
35
 * ------------------------------------------------------------------------- */
36
 
37
 
38
#include "spr-defs.h"
39
#include "board.h"
40
 
41
/* ----------------------------------------------------------------------------
42
 * Coding conventions
43
 *
44
 * A simple rising stack is provided starting at _stack and pointed to by
45
 * r1. r1 points to the next free word. Only 32-bit registers may be pushed
46
 * onto the stack.
47
 *
48
 * Temporary labels up to 49 are reserved for macros and subroutines. Each is
49
 * used only once in any macro or subroutine. You can get in a serious mess if
50
 * you get local label clashing in macros.
51
 *
52
 * Arguments to functions are passed in r3 through r8.
53
 * r9 is the link (return address)
54
 * r11 is for returning results
55
 * r2 through r11 are not preserved across calls. All other registers are.
56
 * ------------------------------------------------------------------------- */
57
 
58
 
59
/* ----------------------------------------------------------------------------
60
 * Memory controller constants
61
 * ------------------------------------------------------------------------- */
62
 
63
#define MEM_RAM 0x00000000
64
 
65
#define MC_CSR          (0x00)
66
#define MC_POC          (0x04)
67
#define MC_BA_MASK      (0x08)
68
#define MC_CSC(i)       (0x10 + (i) * 8)
69
#define MC_TMS(i)       (0x14 + (i) * 8)
70
 
71
/* ----------------------------------------------------------------------------
72
 * Useful constants
73
 * ------------------------------------------------------------------------- */
74
 
75
/* Indicator of completion */
76
#define  ALL_DONE     (0xdeaddead)
77
 
78
/* Logical values */
79
#define TRUE   1
80
#define FALSE  0
81
 
82
 
83
/* ----------------------------------------------------------------------------
84
 * Macro to push a register onto the stack
85
 *
86
 * r1 points to the next free slot. Push the supplied register on, then
87
 * advance the stack pointer.
88
 *
89
 * Arguments:
90
 *   reg  The register to push
91
 *
92
 * Registers modified
93
 *   r1
94
 * ------------------------------------------------------------------------- */
95
#define PUSH(reg)                                                        \
96
        l.sw    0(r1),reg               /* Push */                      ;\
97
        l.addi  r1,r1,4                 /* Advance the stack */
98
 
99
/* ----------------------------------------------------------------------------
100
 * Macro to pop a register off the stack
101
 *
102
 * r1 points to the next free slot. Decrement the stack pointer, then pop the
103
 * requested register.
104
 *
105
 * Arguments:
106
 *   reg  The register to pop
107
 *
108
 * Registers modified
109
 *   r1
110
 * ------------------------------------------------------------------------- */
111
#define POP(reg)                                                         \
112
        l.addi  r1,r1,-4                /* Decrement the stack */       ;\
113
        l.lws   reg,0(r1)               /* Pop */
114
 
115
/* ----------------------------------------------------------------------------
116
 * Macro to load a 32-bit constant into a register
117
 *
118
 * Arguments:
119
 *   reg  The register to load
120
 *   val  The value to load
121
 *
122
 * ------------------------------------------------------------------------- */
123
#define LOAD_CONST(reg,val)                                              \
124
        l.movhi reg,hi(val)                                             ;\
125
        l.ori   reg,reg,lo(val)
126
 
127
/* ----------------------------------------------------------------------------
128
 * Macro to define and load a pointer to a string
129
 *
130
 * Arguments:
131
 *   reg  The register to load
132
 *   str  The string
133
 *
134
 * ------------------------------------------------------------------------- */
135
#define LOAD_STR(reg,str)                                                \
136
        .section .rodata                                                ;\
137
1:                                                                      ;\
138
        .string str                                                     ;\
139
                                                                        ;\
140
        .section .text                                                  ;\
141
        l.movhi reg,hi(1b)                                              ;\
142
        l.ori   reg,reg,lo(1b)
143
 
144
/* ----------------------------------------------------------------------------
145
 * Macro to print a character
146
 *
147
 * Arguments:
148
 *   c  The character to print
149
 * ------------------------------------------------------------------------- */
150
#define PUTC(c)                                                          \
151
        l.addi  r3,r0,c                                                 ;\
152
        l.nop   NOP_PUTC
153
 
154
/* ----------------------------------------------------------------------------
155
 * Macro for recording the result of a test
156
 *
157
 * The test result is in r4. Print out the name of test indented two spaces,
158
 * followed by  ": ", either "OK" or "Failed" and a newline.
159
 *
160
 * Arguments:
161
 *   str  Textual name of the test
162
 *   reg  The result to test (not r2)
163
 *   val  Desired result of the test
164
 * ------------------------------------------------------------------------- */
165
#define CHECK_RES(str,reg,val)                                           \
166
        .section .rodata                                                ;\
167
2:                                                                      ;\
168
        .string str                                                     ;\
169
                                                                        ;\
170
        .section .text                                                  ;\
171
        PUSH (reg)                      /* Save the register to test */ ;\
172
                                                                        ;\
173
        LOAD_CONST (r3,2b)              /* Print out the string */      ;\
174
        l.jal   _ptest                                                  ;\
175
        l.nop                                                           ;\
176
                                                                        ;\
177
        LOAD_CONST(r2,val)              /* The desired result */        ;\
178
        POP (reg)                       /* The register to test */      ;\
179
        PUSH (reg)                      /* May need again later */      ;\
180
        l.sfeq  r2,reg                  /* Does the result match? */    ;\
181
        l.bf    3f                                                      ;\
182
        l.nop                                                           ;\
183
                                                                        ;\
184
        l.jal   _pfail                  /* Test failed */               ;\
185
        l.nop                                                           ;\
186
        POP (reg)                       /* Report the register */       ;\
187
        l.add   r3,r0,reg                                               ;\
188
        l.j     4f                                                      ;\
189
        l.nop   NOP_REPORT                                              ;\
190
3:                                                                      ;\
191
        POP (reg)                       /* Discard the register */      ;\
192
        l.jal   _pok                    /* Test succeeded */            ;\
193
        l.nop                                                           ;\
194
4:
195
 
196
/* ----------------------------------------------------------------------------
197
 * Macro for recording the result of a comparison
198
 *
199
 * If the flag is set print the string argument indented by 2 spaces, followed
200
 * by "TRUE" and a  newline, otherwise print the string argument indented by
201
 * two spaces, followed by "FALSE" and a newline.
202
 *
203
 * Arguments:
204
 *   str  Textual name of the test
205
 *   res  Expected result (TRUE or FALSE)
206
 * ------------------------------------------------------------------------- */
207
#define CHECK_FLAG(str,res)                                              \
208
        .section .rodata                                                ;\
209
5:                                                                      ;\
210
        .string str                                                     ;\
211
                                                                        ;\
212
        .section .text                                                  ;\
213
        l.bnf   7f                      /* Branch if result FALSE */    ;\
214
                                                                        ;\
215
        /* Branch for TRUE result */                                    ;\
216
        LOAD_CONST (r3,5b)              /* The string to print */       ;\
217
        l.jal   _ptest                                                  ;\
218
        l.nop                                                           ;\
219
                                                                        ;\
220
        l.addi  r2,r0,TRUE              /* Was it expected? */          ;\
221
        l.addi  r3,r0,res                                               ;\
222
        l.sfeq  r2,r3                                                   ;\
223
        l.bnf   6f                      /* Branch if not expected */    ;\
224
                                                                        ;\
225
        /* Sub-branch for TRUE found and expected */                    ;\
226
        l.jal   _ptrue                                                  ;\
227
        l.nop                                                           ;\
228
        PUTC ('\n')                                                     ;\
229
        l.j     9f                                                      ;\
230
        l.nop                                                           ;\
231
6:                                                                      ;\
232
        /* Sub-branch for TRUE found and not expected */                ;\
233
        l.jal   _ptrue                                                  ;\
234
        l.nop                                                           ;\
235
        l.jal   _punexpected                                            ;\
236
        l.nop                                                           ;\
237
        l.j     9f                                                      ;\
238
        l.nop                                                           ;\
239
                                                                        ;\
240
7:                                                                      ;\
241
        /* Branch for FALSE result */                                   ;\
242
        LOAD_CONST (r3,5b)              /* The string to print */       ;\
243
        l.jal   _ptest                                                  ;\
244
        l.nop                                                           ;\
245
                                                                        ;\
246
        l.addi  r2,r0,FALSE             /* Was it expected? */          ;\
247
        l.addi  r3,r0,res                                               ;\
248
        l.sfeq  r2,r3                                                   ;\
249
        l.bnf   8f                      /* Branch if not expected */    ;\
250
                                                                        ;\
251
        /* Sub-branch for FALSE found and expected */                   ;\
252
        l.jal   _pfalse                                                 ;\
253
        l.nop                                                           ;\
254
        PUTC ('\n')                                                     ;\
255
        l.j     9f                                                      ;\
256
        l.nop                                                           ;\
257
8:                                                                      ;\
258
        /* Sub-branch for FALSE found and not expected */               ;\
259
        l.jal   _pfalse                                                 ;\
260
        l.nop                                                           ;\
261
        l.jal   _punexpected                                            ;\
262
        l.nop                                                           ;\
263
9:
264
 
265
/* ----------------------------------------------------------------------------
266
 * Simple stack, will be pointed to by r1, which is the next empty slot
267
 * ------------------------------------------------------------------------- */
268
        .section .data
269
        .balign 4
270
        .global _stack
271
_stack:
272
        .space  0x1000,0x0
273
 
274
/* ----------------------------------------------------------------------------
275
 * reset exception
276
 * ------------------------------------------------------------------------- */
277
        .section .except, "ax"
278
        l.addi    r1,r0,0
279
 
280
        .section .text
281
        .org 0x100
282
_reset:
283
        l.movhi r1,hi(_stack)           /* Set up the stack */
284
        l.ori   r1,r1,lo(_stack)
285
 
286
        l.movhi r3,hi(_init_mc)         /* Code starts with MC setup */
287
        l.ori   r3,r3,lo(_init_mc)
288
        l.jr    r3
289
        l.nop
290
 
291
/* ----------------------------------------------------------------------------
292
 * Subroutine to print out a string
293
 *
294
 * The string is followed by a newline
295
 *
296
 * Parameters:
297
 *  r3  Pointer to the string to print
298
 * ------------------------------------------------------------------------- */
299
_puts:
300
        l.add   r2,r0,r3                /* Copy the string pointer */
301
 
302
        /* Loop getting and printing each char until end of string */
303
10:
304
        l.lbz   r3,0(r2)
305
        l.sfeq  r3,r0                   /* NULL termination? */
306
        l.bf    11f
307
 
308
        l.addi  r2,r2,1                 /* Delay slot, move to next char */
309
        l.j     10b                     /* Repeat */
310
        l.nop   NOP_PUTC                /* Delay slot */
311
 
312
11:
313
        l.jr    r9                      /* Return */
314
        l.nop
315
 
316
/* ----------------------------------------------------------------------------
317
 * Subroutine to print out a test name prompt
318
 *
319
 * The string is preceded by two spaces
320
 *
321
 * Parameters:
322
 *  r3  Pointer to the test name to print
323
 * ------------------------------------------------------------------------- */
324
_ptest:
325
        PUSH(r9)                        /* Save the return address */
326
        PUSH(r3)                        /* Save the test name for later */
327
 
328
        LOAD_STR(r3, "  ")              /* Prefix */
329
        l.jal   _puts
330
        l.nop
331
 
332
        POP(r3)                         /* Test name */
333
        l.jal   _puts
334
        l.nop
335
 
336
        POP (r9)
337
        l.jr    r9
338
 
339
 
340
/* ----------------------------------------------------------------------------
341
 * Subroutine to print out "OK"
342
 *
343
 * The string is followed by a newline
344
 * ------------------------------------------------------------------------- */
345
_pok:
346
        PUSH(r9)                        /* Save the return address */
347
 
348
        LOAD_STR(r3, "OK\n")
349
        l.jal   _puts
350
        l.nop
351
 
352
        POP (r9)
353
        l.jr    r9
354
 
355
 
356
/* ----------------------------------------------------------------------------
357
 * Subroutine to print out "Failed"
358
 *
359
 * The string is followed by a ": ", which will then allow a report
360
 * ------------------------------------------------------------------------- */
361
_pfail:
362
        PUSH(r9)                        /* Save the return address */
363
 
364
        LOAD_STR(r3, "Failed: ")
365
        l.jal   _puts
366
        l.nop
367
 
368
        POP (r9)
369
        l.jr    r9
370
 
371
/* ----------------------------------------------------------------------------
372
 * Subroutine to print out "TRUE"
373
 * ------------------------------------------------------------------------- */
374
_ptrue:
375
        PUSH(r9)                        /* Save the return address */
376
 
377
        LOAD_STR(r3, "TRUE")
378
        l.jal   _puts
379
        l.nop
380
 
381
        POP (r9)
382
        l.jr    r9
383
 
384
 
385
/* ----------------------------------------------------------------------------
386
 * Subroutine to print out "FALSE"
387
 * ------------------------------------------------------------------------- */
388
_pfalse:
389
        PUSH(r9)                        /* Save the return address */
390
 
391
        LOAD_STR(r3, "FALSE")
392
        l.jal   _puts
393
        l.nop
394
 
395
        POP (r9)
396
        l.jr    r9
397
 
398
/* ----------------------------------------------------------------------------
399
 * Subroutine to print out "unexpected"
400
 *
401
 * Preceded by a space and followed by a newline
402
 * ------------------------------------------------------------------------- */
403
_punexpected:
404
        PUSH(r9)                        /* Save the return address */
405
 
406
        LOAD_STR(r3, " unexpected\n")
407
        l.jal   _puts
408
        l.nop
409
 
410
        POP (r9)
411
        l.jr    r9
412
 
413
/* ----------------------------------------------------------------------------
414
 * Memory controller initialization initialization
415
 * ------------------------------------------------------------------------- */
416
_init_mc:
417
 
418
        l.movhi r3,hi(MC_BASE_ADDR)
419
        l.ori   r3,r3,lo(MC_BASE_ADDR)
420
 
421
        l.addi  r4,r3,MC_CSC(0)
422
        l.movhi r5,hi(FLASH_BASE_ADDR)
423
        l.srai  r5,r5,6
424
        l.ori   r5,r5,0x0025
425
        l.sw    0(r4),r5
426
 
427
        l.addi  r4,r3,MC_TMS(0)
428
        l.movhi r5,hi(FLASH_TMS_VAL)
429
        l.ori   r5,r5,lo(FLASH_TMS_VAL)
430
        l.sw    0(r4),r5
431
 
432
        l.addi  r4,r3,MC_BA_MASK
433
        l.addi  r5,r0,MC_MASK_VAL
434
        l.sw    0(r4),r5
435
 
436
        l.addi  r4,r3,MC_CSR
437
        l.movhi r5,hi(MC_CSR_VAL)
438
        l.ori   r5,r5,lo(MC_CSR_VAL)
439
        l.sw    0(r4),r5
440
 
441
        l.addi  r4,r3,MC_TMS(1)
442
        l.movhi r5,hi(SDRAM_TMS_VAL)
443
        l.ori   r5,r5,lo(SDRAM_TMS_VAL)
444
        l.sw    0(r4),r5
445
 
446
        l.addi  r4,r3,MC_CSC(1)
447
        l.movhi r5,hi(SDRAM_BASE_ADDR)
448
        l.srai  r5,r5,6
449
        l.ori   r5,r5,0x0411
450
        l.sw    0(r4),r5
451
 
452
/* ----------------------------------------------------------------------------
453
 * Test of load single word and extend with sign: l.lws
454
 * ------------------------------------------------------------------------- */
455
        .section .rodata
456
50:     .word   0xdeadbeef
457
51:     .word   0x00000000
458
52:     .word   0x7fffffff
459
53:     .word   0x80000000
460
54:     .word   0xffffffff
461
 
462
        .section .text
463
_lws:
464
        LOAD_STR (r3, "l.lws\n")
465
        l.jal   _puts
466
        l.nop
467
 
468
        /* Load with zero offset */
469
        LOAD_CONST (r5,50b)
470
        l.lws   r4,0(r5)
471
        CHECK_RES (" l.lws r4,0(r5): r4=0xdeadbeef:  ", r4, 0xdeadbeef)
472
 
473
        LOAD_CONST (r5,51b)
474
        l.lws   r4,0(r5)
475
        CHECK_RES (" l.lws r4,0(r5): r4=0x00000000:  ", r4, 0x00000000)
476
 
477
        LOAD_CONST (r5,52b)
478
        l.lws   r4,0(r5)
479
        CHECK_RES (" l.lws r4,0(r5): r4=0x7fffffff:  ", r4, 0x7fffffff)
480
 
481
        LOAD_CONST (r5,53b)
482
        l.lws   r4,0(r5)
483
        CHECK_RES (" l.lws r4,0(r5): r4=0x80000000:  ", r4, 0x80000000)
484
 
485
        LOAD_CONST (r5,54b)
486
        l.lws   r4,0(r5)
487
        CHECK_RES (" l.lws r4,0(r5): r4=0xffffffff:  ", r4, 0xffffffff)
488
 
489
        /* Load with positive offset */
490
        LOAD_CONST (r5,50b)
491
        l.lws   r4,4(r5)
492
        CHECK_RES (" l.lws r4,0(r5): r4=0x00000000:  ", r4, 0x00000000)
493
 
494
        LOAD_CONST (r5,50b)
495
        l.lws   r4,8(r5)
496
        CHECK_RES (" l.lws r4,0(r5): r4=0x7fffffff:  ", r4, 0x7fffffff)
497
 
498
        LOAD_CONST (r5,50b)
499
        l.lws   r4,12(r5)
500
        CHECK_RES (" l.lws r4,0(r5): r4=0x80000000:  ", r4, 0x80000000)
501
 
502
        LOAD_CONST (r5,50b)
503
        l.lws   r4,16(r5)
504
        CHECK_RES (" l.lws r4,0(r5): r4=0xffffffff:  ", r4, 0xffffffff)
505
 
506
        /* Load with negative offset */
507
        LOAD_CONST (r5,54b)
508
        l.lws   r4,-16(r5)
509
        CHECK_RES (" l.lws r4,0(r5): r4=0xdeadbeef:  ", r4, 0xdeadbeef)
510
 
511
        LOAD_CONST (r5,54b)
512
        l.lws   r4,-12(r5)
513
        CHECK_RES (" l.lws r4,0(r5): r4=0x00000000:  ", r4, 0x00000000)
514
 
515
        LOAD_CONST (r5,54b)
516
        l.lws   r4,-8(r5)
517
        CHECK_RES (" l.lws r4,0(r5): r4=0x7fffffff:  ", r4, 0x7fffffff)
518
 
519
        LOAD_CONST (r5,54b)
520
        l.lws   r4,-4(r5)
521
        CHECK_RES (" l.lws r4,0(r5): r4=0x80000000:  ", r4, 0x80000000)
522
 
523
/* ----------------------------------------------------------------------------
524
 * All done
525
 * ------------------------------------------------------------------------- */
526
_exit:
527
        LOAD_STR (r3, "Test completed\n")
528
        l.jal   _puts
529
        l.nop
530
 
531
        l.movhi r3,hi(ALL_DONE)
532
        l.ori   r3,r3,lo(ALL_DONE)
533
        l.nop   NOP_REPORT              /* Should be 0xdeaddead */
534
 
535
        l.addi  r3,r0,0
536
        l.nop   NOP_EXIT

powered by: WebSVN 2.1.0

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