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

Subversion Repositories ion

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

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
    addi    $sp,$sp,-4
119 50 ja_rd
    li      $a1,8
120
    jal     put_hex
121
    nop
122
    la      $a0,crlf
123
    jal     puts
124
    nop
125
 
126 78 ja_rd
    # FIXME now we should so some strong test on the RAM to see if it's wired
127
    # correctly, using the right timing, etc.
128
 
129
    # Ok, now we know we have some RAM and stack space we can do some further
130
    # testing.
131
    # dump the first few words of FLASH
132
 
133
    la      $a0,msg2
134
    jal     puts
135
    nop
136
 
137
    # FIXME flash base address is hardcoded
138
    li      $a0,0xb0000000
139
    jal     put_hex
140
    ori     $a1,$zero,8
141
 
142
    la      $a0,crlf
143
    jal     puts
144
    nop
145
 
146
    la      $a0,crlf
147
    jal     puts
148
    nop
149
 
150
    li      $a0,0xb0000000
151
    jal     dump_hex
152
    ori     $a1,$zero,24
153
 
154
 
155 50 ja_rd
$DONE:
156
    j       $DONE               # ...and freeze here
157
    nop
158
 
159
 
160
#---- Functions ----------------------------------------------------------------
161 78 ja_rd
 
162
# void dump_hex(int *address, int len)
163
dump_hex:
164
    move    $t7,$a0
165
    move    $t8,$a1
166
    sw      $ra,0($sp)
167
    addi    $sp,$sp,-4
168
 
169
dump_hex_loop:
170
    lw      $a0,0($t7)
171
    jal     put_hex
172
    li      $a1,8
173
 
174
    la      $a0,space
175
    jal     puts
176
    addi    $t7,4
177
 
178
    addi    $t8,$t8,-1
179
    bnez    $t8,dump_hex_loop
180
    nop
181
 
182
    lw      $ra,4($sp)
183
    jr      $ra
184
    addi    $sp,$sp,4
185
 
186
 
187
#--- Special functions that do not use any RAM ---------------------------------
188 50 ja_rd
# WARNING: Not for general use!
189
# All parameters in $a0..$a4, stack unused. No attempt to comply with any ABI
190
# has been made.
191
# Since we can't use any RAM, register have been used liberally with no regard
192
# for intended usage -- have to share reg bank with calling function.
193
 
194
# void puts(char *s) -- print zero-terminated string
195
puts:
196 78 ja_rd
    la      $a2,UART_BASE       # UART base address
197 50 ja_rd
puts_loop:
198
    lb      $v0,0($a0)
199
    beqz    $v0,puts_end
200
    addiu   $a0,1
201
puts_wait_tx_rdy:
202 78 ja_rd
    lw      $v1,UART_STATUS($a2)
203 50 ja_rd
    andi    $v1,$v1,0x02
204
    beqz    $v1,puts_wait_tx_rdy
205
    nop
206 78 ja_rd
    sw      $v0,UART_TX($a2)
207 50 ja_rd
    b       puts_loop
208
    nop
209
 
210
puts_end:
211
    jr      $ra
212
    nop
213
 
214
# void put_hex(int n, int d) -- print integer as d-digit hex
215
put_hex:
216 78 ja_rd
    la      $a2,UART_BASE
217
    la      $a3,put_hex_table
218 50 ja_rd
    addi    $a1,-1
219
    add     $a1,$a1,$a1
220
    add     $a1,$a1,$a1
221
 
222
put_hex_loop:
223
    srlv    $v0,$a0,$a1
224
    andi    $v0,$v0,0x0f
225 78 ja_rd
    addu    $s2,$a3,$v0
226 50 ja_rd
    lb      $v0,0($s2)
227
put_hex_wait_tx_rdy:
228 78 ja_rd
    lw      $v1,UART_STATUS($a2)
229 50 ja_rd
    andi    $v1,$v1,0x02
230
    beqz    $v1,put_hex_wait_tx_rdy
231
    nop
232 78 ja_rd
    sw      $v0,UART_TX($a2)
233 50 ja_rd
 
234
    bnez    $a1,put_hex_loop
235
    addi    $a1,-4
236
 
237
    jr      $ra
238
    nop
239
 
240
 
241
#---- Constant data (note we keep it in the text section) ----------------------
242
 
243
put_hex_table:
244
    .ascii  "0123456789abcdef"
245
 
246
msg0:
247
    .ascii  "\n\r"
248
    .asciz  "Scanning external memory at 0x"
249
msg1:
250
    .asciz  "Found XRAM top at           0x"
251
crlf:
252
    .asciz "\n\r"
253
space:
254
    .asciz "  "
255
msg_mirror:
256
    .asciz "hit mirror!\n\r"
257
msg_bad:
258
    .asciz "bad readback!\n\r"
259 78 ja_rd
msg2:
260
    .asciz "\n\rDumping the first few words of FLASH at address 0x"
261 50 ja_rd
 
262
    .set    reorder
263
    .end    entry
264
 

powered by: WebSVN 2.1.0

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