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

Subversion Repositories ion

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

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
    .set XRAM_BASE,     0x80000000          # 1st XRAM address
26
    .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
    #--- Trap handler address: we don't expect any traps -----------------------
45
    .org    0x3c
46
interrupt_vector:
47
    b       interrupt_vector
48
    nop
49
 
50
#-------------------------------------------------------------------------------
51
 
52
start_test:
53
    mtc0    $0,$12              # disable interrupts
54
 
55
    la      $a0,msg0
56
    jal     puts
57
    nop
58
    li      $a0,XRAM_BASE
59
    li      $a1,8
60
    jal     put_hex
61
    nop
62
    la      $a0,crlf
63
    jal     puts
64
    nop
65
 
66
    la      $t0,XRAM_BASE       # address of memory word being tested
67
    li      $t2,XRAM_MAX        # max amount of KBs to test for
68
    li      $t3,1               # (used to decrement $t2)
69
    li      $t4,0               # no. of KBs found
70
    move    $t5,$t0             # keep the start addr at hand for comparison
71
 
72
    sw      $zero,0($t0)        # clear 1st test word (in case of prev. run)
73
 
74
test_loop:
75
    lw      $t1,0($t0)          # read word contents
76
    beq     $t5,$t1,hit_mirror  # if it's the start address, we hit a mirror
77
    nop                         # we rolled off the end of the RAM back here
78
    sw      $t0,0($t0)          # word = word address
79
    lw      $t1,0($t0)          # read word back...
80
    bne     $t1,$t0,bad_word    # ...and if no match, we run off the RAM
81
    nop                         #
82
    sub     $t2,$t2,$t3         # decrement loop counter...
83
    bnez    $t2,test_loop       # ...and go back if there's more to go
84
    addiu   $t0,0x400           # in any case, increment test address by 1KB
85
 
86
    b       end_test            # end of memory found, result is in $t4
87
    nop
88
 
89
hit_mirror:                     # memory mirror detected
90
    .ifgt   DEBUG
91
    la      $a0,msg_mirror
92
    jal     puts
93
    nop
94
    .endif
95
    b       end_test
96
    nop
97
 
98
bad_word:                       # readback error detected (maybe r/o area?)
99
    .ifgt   DEBUG
100
    la      $a0,msg_bad
101
    jal     puts
102
    nop
103
    .endif
104
    b       end_test
105
    nop
106
 
107
end_test:                       # test done, ramtop+1 in $t0, #KB in $t4
108
    la      $a0,msg1            # Print ramtop message...
109
    jal     puts
110
    nop
111
    move    $a0,$t0
112
    li      $a1,8
113
    jal     put_hex
114
    nop
115
    la      $a0,crlf
116
    jal     puts
117
    nop
118
 
119
$DONE:
120
    j       $DONE               # ...and freeze here
121
    nop
122
 
123
 
124
#---- Functions ----------------------------------------------------------------
125
# WARNING: Not for general use!
126
# All parameters in $a0..$a4, stack unused. No attempt to comply with any ABI
127
# has been made.
128
# Since we can't use any RAM, register have been used liberally with no regard
129
# for intended usage -- have to share reg bank with calling function.
130
 
131
# void puts(char *s) -- print zero-terminated string
132
puts:
133
    la      $s0,UART_BASE       # UART base address
134
puts_loop:
135
    lb      $v0,0($a0)
136
    beqz    $v0,puts_end
137
    addiu   $a0,1
138
puts_wait_tx_rdy:
139
    lw      $v1,UART_STATUS($s0)
140
    andi    $v1,$v1,0x02
141
    beqz    $v1,puts_wait_tx_rdy
142
    nop
143
    sw      $v0,UART_TX($s0)
144
    b       puts_loop
145
    nop
146
 
147
puts_end:
148
    jr      $ra
149
    nop
150
 
151
# void put_hex(int n, int d) -- print integer as d-digit hex
152
put_hex:
153
    la      $s0,UART_BASE
154
    la      $s1,put_hex_table
155
    addi    $a1,-1
156
    add     $a1,$a1,$a1
157
    add     $a1,$a1,$a1
158
 
159
put_hex_loop:
160
    srlv    $v0,$a0,$a1
161
    andi    $v0,$v0,0x0f
162
    addu    $s2,$s1,$v0
163
    lb      $v0,0($s2)
164
put_hex_wait_tx_rdy:
165
    lw      $v1,UART_STATUS($s0)
166
    andi    $v1,$v1,0x02
167
    beqz    $v1,put_hex_wait_tx_rdy
168
    nop
169
    sw      $v0,UART_TX($s0)
170
 
171
    bnez    $a1,put_hex_loop
172
    addi    $a1,-4
173
 
174
    jr      $ra
175
    nop
176
 
177
 
178
#---- Constant data (note we keep it in the text section) ----------------------
179
 
180
put_hex_table:
181
    .ascii  "0123456789abcdef"
182
 
183
msg0:
184
    .ascii  "\n\r"
185
    .asciz  "Scanning external memory at 0x"
186
msg1:
187
    .asciz  "Found XRAM top at           0x"
188
crlf:
189
    .asciz "\n\r"
190
space:
191
    .asciz "  "
192
msg_mirror:
193
    .asciz "hit mirror!\n\r"
194
msg_bad:
195
    .asciz "bad readback!\n\r"
196
 
197
    .set    reorder
198
    .end    entry
199
 

powered by: WebSVN 2.1.0

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