OpenCores
URL https://opencores.org/ocsvn/ion/ion/trunk

Subversion Repositories ion

[/] [ion/] [trunk/] [src/] [memtest/] [memtest.s] - Blame information for rev 90

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

Line No. Rev Author Line
1 50 ja_rd
################################################################################
2
# memtest.s -- Test external RAM memory (XRAM)
3
#-------------------------------------------------------------------------------
4
# This program tests the external RAM (connected to the core through the cache
5
# module). Currently it only finds the RAM top address if given the bottom
6
# address. Subsequent versions will add some minimal diagnostic capability,
7
# which will be needed when DRAM access is implemented.
8
#
9
# This program does only support a single continuous chunk of RAM. If the cache
10
# module ever supports more than one chunk (e.g. DRAM and SRAM as in the DE-1
11
# board) this program will be modified accordingly.
12
#
13
# The program assumes there's no useable r/w memory other than the XRAM so it
14
# does not use any memory for variables or stack.
15
#
16
#-------------------------------------------------------------------------------
17
# To be run from reset vector, standalone. Interrupts must be disabled.
18
#
19
################################################################################
20
 
21
    #---- Set to >0 to enable a few debug messages
22
    .set DEBUG,         0
23
 
24
    #----
25 66 ja_rd
    #.set XRAM_BASE,     0x80000000          # 1st XRAM address
26 50 ja_rd
    .set XRAM_MAX,      1024                # max. no. of KB to test for
27
 
28
    .set UART_BASE,     0x20000000          # UART base address
29
    .set UART_TX,       0x0000              # TX reg offset
30
    .set UART_STATUS,   0x0020              # status reg offset
31
 
32
    #---------------------------------------------------------------------------
33
 
34
    .text
35
    .align  2
36
    .globl  entry
37
    .ent    entry
38
entry:
39
    .set    noreorder
40
 
41
    b       start_test
42
    nop
43
 
44 66 ja_rd
    .ifgt   0
45 50 ja_rd
    #--- Trap handler address: we don't expect any traps -----------------------
46 66 ja_rd
    #.org    0x3c
47
    .org    0x0180
48 50 ja_rd
interrupt_vector:
49
    b       interrupt_vector
50
    nop
51 66 ja_rd
    .endif
52
 
53 50 ja_rd
#-------------------------------------------------------------------------------
54
 
55
start_test:
56
    mtc0    $0,$12              # disable interrupts
57
 
58
    la      $a0,msg0
59
    jal     puts
60
    nop
61
    li      $a0,XRAM_BASE
62
    li      $a1,8
63
    jal     put_hex
64
    nop
65
    la      $a0,crlf
66
    jal     puts
67
    nop
68
 
69 66 ja_rd
    la      $t0,XRAM_BASE+4     # address of memory word being tested
70 50 ja_rd
    li      $t2,XRAM_MAX        # max amount of KBs to test for
71
    li      $t3,1               # (used to decrement $t2)
72
    li      $t4,0               # no. of KBs found
73
    move    $t5,$t0             # keep the start addr at hand for comparison
74
 
75
    sw      $zero,0($t0)        # clear 1st test word (in case of prev. run)
76
 
77
test_loop:
78
    lw      $t1,0($t0)          # read word contents
79
    beq     $t5,$t1,hit_mirror  # if it's the start address, we hit a mirror
80
    nop                         # we rolled off the end of the RAM back here
81
    sw      $t0,0($t0)          # word = word address
82
    lw      $t1,0($t0)          # read word back...
83
    bne     $t1,$t0,bad_word    # ...and if no match, we run off the RAM
84
    nop                         #
85
    sub     $t2,$t2,$t3         # decrement loop counter...
86
    bnez    $t2,test_loop       # ...and go back if there's more to go
87
    addiu   $t0,0x400           # in any case, increment test address by 1KB
88
 
89
    b       end_test            # end of memory found, result is in $t4
90
    nop
91
 
92
hit_mirror:                     # memory mirror detected
93
    .ifgt   DEBUG
94
    la      $a0,msg_mirror
95
    jal     puts
96
    nop
97
    .endif
98
    b       end_test
99
    nop
100
 
101
bad_word:                       # readback error detected (maybe r/o area?)
102
    .ifgt   DEBUG
103
    la      $a0,msg_bad
104
    jal     puts
105
    nop
106
    .endif
107
    b       end_test
108
    nop
109
 
110 78 ja_rd
end_test:                       # test done, ramtop+4 in $t0, #KB in $t4
111
 
112
 
113 50 ja_rd
    la      $a0,msg1            # Print ramtop message...
114
    jal     puts
115
    nop
116 66 ja_rd
    addi    $a0,$t0,-4          # substract the +4 offset we added before
117 78 ja_rd
    move    $sp,$t0             # init SP at the top of RAM space
118 90 ja_rd
    addi    $sp,$sp,-16
119 50 ja_rd
    li      $a1,8
120
    jal     put_hex
121
    nop
122
    la      $a0,crlf
123
    jal     puts
124
    nop
125
 
126 90 ja_rd
    # Test code execution from SRAM. We copy the test_exec_sram routine to
127
    # the base of the SRAM and then jal to it
128
    li      $a1,64
129
    li      $a0,XRAM_BASE
130
    la      $a3,test_exec_sram
131
copy_to_sram:
132
    lw      $a2,0($a3)
133
    nop
134
    sw      $a2,0($a0)
135
    addi    $a1,$a1,-4
136
    addi    $a3,$a3,4
137
    bnez    $a1,copy_to_sram
138
    addi    $a0,$a0,4
139
 
140
    .ifgt 0
141
    li      $a0,0
142
    jal     dump_hex
143
    ori     $a1,$zero,16
144
    .endif
145
 
146
    li      $a0,XRAM_BASE
147
    jalr    $a0
148
    nop
149
 
150
    .ifgt   0
151
    # If all went well in the SRAM we'll have returned here
152
 
153
 
154 78 ja_rd
    # FIXME now we should so some strong test on the RAM to see if it's wired
155
    # correctly, using the right timing, etc.
156
 
157
    # Ok, now we know we have some RAM and stack space we can do some further
158
    # testing.
159
    # dump the first few words of FLASH
160
 
161
    la      $a0,msg2
162
    jal     puts
163
    nop
164
 
165
    # FIXME flash base address is hardcoded
166
    li      $a0,0xb0000000
167
    jal     put_hex
168
    ori     $a1,$zero,8
169
 
170
    la      $a0,crlf
171
    jal     puts
172
    nop
173
 
174
    la      $a0,crlf
175
    jal     puts
176
    nop
177
 
178
    li      $a0,0xb0000000
179
    jal     dump_hex
180
    ori     $a1,$zero,24
181 90 ja_rd
    .endif
182 78 ja_rd
 
183 50 ja_rd
$DONE:
184
    j       $DONE               # ...and freeze here
185
    nop
186
 
187
 
188 90 ja_rd
test_exec_sram:
189
    #jr      $ra
190
    #nop
191
    sw      $ra,0($sp)
192
    addi    $sp,$sp,-4
193
    la      $a0,msg3
194
    la      $a1,puts
195
    jalr    $a1
196
    nop
197
    lw      $ra,4($sp)
198
    jr      $ra
199
    addi    $sp,$sp,4
200
test_exec_sram_end:
201
 
202
 
203
 
204 50 ja_rd
#---- Functions ----------------------------------------------------------------
205 78 ja_rd
 
206
# void dump_hex(int *address, int len)
207
dump_hex:
208
    move    $t7,$a0
209
    move    $t8,$a1
210
    sw      $ra,0($sp)
211
    addi    $sp,$sp,-4
212
 
213
dump_hex_loop:
214
    lw      $a0,0($t7)
215
    jal     put_hex
216
    li      $a1,8
217
 
218
    la      $a0,space
219
    jal     puts
220
    addi    $t7,4
221
 
222
    addi    $t8,$t8,-1
223
    bnez    $t8,dump_hex_loop
224
    nop
225
 
226
    lw      $ra,4($sp)
227
    jr      $ra
228
    addi    $sp,$sp,4
229
 
230
 
231
#--- Special functions that do not use any RAM ---------------------------------
232 50 ja_rd
# WARNING: Not for general use!
233
# All parameters in $a0..$a4, stack unused. No attempt to comply with any ABI
234
# has been made.
235
# Since we can't use any RAM, register have been used liberally with no regard
236
# for intended usage -- have to share reg bank with calling function.
237
 
238
# void puts(char *s) -- print zero-terminated string
239
puts:
240 78 ja_rd
    la      $a2,UART_BASE       # UART base address
241 50 ja_rd
puts_loop:
242
    lb      $v0,0($a0)
243
    beqz    $v0,puts_end
244
    addiu   $a0,1
245
puts_wait_tx_rdy:
246 78 ja_rd
    lw      $v1,UART_STATUS($a2)
247 50 ja_rd
    andi    $v1,$v1,0x02
248
    beqz    $v1,puts_wait_tx_rdy
249
    nop
250 78 ja_rd
    sw      $v0,UART_TX($a2)
251 50 ja_rd
    b       puts_loop
252
    nop
253
 
254
puts_end:
255
    jr      $ra
256
    nop
257
 
258
# void put_hex(int n, int d) -- print integer as d-digit hex
259
put_hex:
260 78 ja_rd
    la      $a2,UART_BASE
261
    la      $a3,put_hex_table
262 50 ja_rd
    addi    $a1,-1
263
    add     $a1,$a1,$a1
264
    add     $a1,$a1,$a1
265
 
266
put_hex_loop:
267
    srlv    $v0,$a0,$a1
268
    andi    $v0,$v0,0x0f
269 78 ja_rd
    addu    $s2,$a3,$v0
270 50 ja_rd
    lb      $v0,0($s2)
271
put_hex_wait_tx_rdy:
272 78 ja_rd
    lw      $v1,UART_STATUS($a2)
273 50 ja_rd
    andi    $v1,$v1,0x02
274
    beqz    $v1,put_hex_wait_tx_rdy
275
    nop
276 78 ja_rd
    sw      $v0,UART_TX($a2)
277 50 ja_rd
 
278
    bnez    $a1,put_hex_loop
279
    addi    $a1,-4
280
 
281
    jr      $ra
282
    nop
283
 
284
 
285
#---- Constant data (note we keep it in the text section) ----------------------
286
 
287
put_hex_table:
288
    .ascii  "0123456789abcdef"
289
 
290
msg0:
291
    .ascii  "\n\r"
292
    .asciz  "Scanning external memory at 0x"
293
msg1:
294
    .asciz  "Found XRAM top at           0x"
295
crlf:
296
    .asciz "\n\r"
297
space:
298
    .asciz "  "
299
msg_mirror:
300
    .asciz "hit mirror!\n\r"
301
msg_bad:
302
    .asciz "bad readback!\n\r"
303 78 ja_rd
msg2:
304
    .asciz "\n\rDumping the first few words of FLASH at address 0x"
305 90 ja_rd
msg3:
306
    .ascii "\n\rTesting code execution from SRAM...  "
307
    .asciz "if you see this, it worked\n\r"
308 50 ja_rd
 
309
    .set    reorder
310
    .end    entry
311
 

powered by: WebSVN 2.1.0

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