################################################################################
|
################################################################################
|
# flash.s -- Chunk of code and data to be written to simulated FLASH
|
# flash.s -- Chunk of code and data to be written to simulated FLASH
|
# and executed from there as part of program memtest.
|
# and executed from there as part of program memtest.
|
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
# This program tests the external 8-bit static memory interface (FLASH) in
|
# This program tests the external 8-bit static memory interface (FLASH) in
|
# simulation.
|
# simulation.
|
#
|
#
|
# The program assumes there's no useable r/w memory other than the XRAM so it
|
# The program assumes there's no useable r/w memory other than the XRAM so it
|
# does not use any memory for variables or stack.
|
# does not use any memory for variables or stack.
|
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
#
|
#
|
################################################################################
|
################################################################################
|
|
|
#---- Test parameters
|
#---- Test parameters
|
.ifndef FLASH_BASE
|
.ifndef FLASH_BASE
|
.set FLASH_BASE, 0xb0000000 # 1st FLASH address
|
.set FLASH_BASE, 0xb0000000 # 1st FLASH address
|
.endif
|
.endif
|
.ifndef XRAM_BASE
|
.ifndef XRAM_BASE
|
.set XRAM_BASE, 0x00000000 # 1st XRAM address
|
.set XRAM_BASE, 0x00000000 # 1st XRAM address
|
.endif
|
.endif
|
|
|
|
|
#---- Set to >0 to enable a few debug messages
|
#---- Set to >0 to enable a few debug messages
|
.set DEBUG, 0
|
.set DEBUG, 0
|
|
|
#---- Cache parameters
|
#---- Cache parameters
|
.set ICACHE_NUM_LINES, 256 # no. of lines in the I-Cache
|
.set ICACHE_NUM_LINES, 256 # no. of lines in the I-Cache
|
.set DCACHE_NUM_LINES, 256 # no. of lines in the D-Cache
|
.set DCACHE_NUM_LINES, 256 # no. of lines in the D-Cache
|
.set DCACHE_LINE_SIZE, 4 # D-Cache line size in words
|
.set DCACHE_LINE_SIZE, 4 # D-Cache line size in words
|
|
|
|
|
#---- UART stuff
|
#---- UART stuff
|
.set UART_BASE, 0x20000000 # UART base address
|
.set UART_BASE, 0x20000000 # UART base address
|
.set UART_TX, 0x0000 # TX reg offset
|
.set UART_TX, 0x0000 # TX reg offset
|
.set UART_STATUS, 0x0020 # status reg offset
|
.set UART_STATUS, 0x0004 # status reg offset
|
|
.set UART_TX_RDY, 0x0001 # tx ready flag mask
|
|
|
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
|
|
.text
|
.text
|
.align 2
|
.align 2
|
.global flash_test
|
.global flash_test
|
.ent flash_test
|
.ent flash_test
|
flash_test:
|
flash_test:
|
.set noreorder
|
.set noreorder
|
|
|
#---- Print 'running from flash' message
|
#---- Print 'running from flash' message
|
la $a0,msg0
|
la $a0,msg0
|
jal puts
|
jal puts
|
nop
|
nop
|
|
|
sw $a1,0($a0)
|
sw $a1,0($a0)
|
sw $a2,4($a0)
|
sw $a2,4($a0)
|
sw $a3,8($a0)
|
sw $a3,8($a0)
|
|
|
|
|
|
|
#---- D-Cache back-to-back loads and stores
|
#---- D-Cache back-to-back loads and stores
|
la $a0,msg3
|
la $a0,msg3
|
jal puts
|
jal puts
|
nop
|
nop
|
|
|
li $a0,XRAM_BASE+4
|
li $a0,XRAM_BASE+4
|
ori $t8,$zero,16
|
ori $t8,$zero,16
|
|
|
rw_test_loop:
|
rw_test_loop:
|
li $s0,0x10001010
|
li $s0,0x10001010
|
|
|
addu $s1,$s0,$s0
|
addu $s1,$s0,$s0
|
addu $s2,$s1,$s1
|
addu $s2,$s1,$s1
|
addu $s3,$s2,$s2
|
addu $s3,$s2,$s2
|
or $s4,$zero,$s0
|
or $s4,$zero,$s0
|
or $s5,$zero,$s1
|
or $s5,$zero,$s1
|
or $s6,$zero,$s2
|
or $s6,$zero,$s2
|
or $s7,$zero,$s3
|
or $s7,$zero,$s3
|
|
|
sw $s0,0($a0)
|
sw $s0,0($a0)
|
sw $s1,4($a0)
|
sw $s1,4($a0)
|
sw $s2,8($a0)
|
sw $s2,8($a0)
|
sw $s3,12($a0)
|
sw $s3,12($a0)
|
sw $s4,16($a0)
|
sw $s4,16($a0)
|
sw $s5,20($a0)
|
sw $s5,20($a0)
|
sw $s6,24($a0)
|
sw $s6,24($a0)
|
sw $s7,28($a0)
|
sw $s7,28($a0)
|
|
|
lw $t0,0($a0)
|
lw $t0,0($a0)
|
lw $t1,4($a0)
|
lw $t1,4($a0)
|
lw $t2,8($a0)
|
lw $t2,8($a0)
|
lw $t3,12($a0)
|
lw $t3,12($a0)
|
lw $t4,16($a0)
|
lw $t4,16($a0)
|
lw $t5,20($a0)
|
lw $t5,20($a0)
|
lw $t6,24($a0)
|
lw $t6,24($a0)
|
lw $t7,28($a0)
|
lw $t7,28($a0)
|
|
|
bne $s0,$t0,rw_mismatch
|
bne $s0,$t0,rw_mismatch
|
nop
|
nop
|
bne $s1,$t1,rw_mismatch
|
bne $s1,$t1,rw_mismatch
|
nop
|
nop
|
bne $s2,$t2,rw_mismatch
|
bne $s2,$t2,rw_mismatch
|
nop
|
nop
|
bne $s3,$t3,rw_mismatch
|
bne $s3,$t3,rw_mismatch
|
nop
|
nop
|
bne $s4,$t4,rw_mismatch
|
bne $s4,$t4,rw_mismatch
|
nop
|
nop
|
bne $s5,$t5,rw_mismatch
|
bne $s5,$t5,rw_mismatch
|
nop
|
nop
|
bne $s6,$t6,rw_mismatch
|
bne $s6,$t6,rw_mismatch
|
nop
|
nop
|
bne $s7,$t7,rw_mismatch
|
bne $s7,$t7,rw_mismatch
|
nop
|
nop
|
.ifgt 0
|
.ifgt 0
|
andi $s0,$s0,0xffff
|
andi $s0,$s0,0xffff
|
andi $s1,$s1,0xff
|
andi $s1,$s1,0xff
|
andi $s2,$s2,0xffff
|
andi $s2,$s2,0xffff
|
andi $s3,$s3,0xff
|
andi $s3,$s3,0xff
|
andi $s4,$s4,0xff
|
andi $s4,$s4,0xff
|
andi $s5,$s5,0xff
|
andi $s5,$s5,0xff
|
andi $s6,$s6,0xff
|
andi $s6,$s6,0xff
|
andi $s7,$s7,0xff
|
andi $s7,$s7,0xff
|
|
|
sh $s0,2($a0)
|
sh $s0,2($a0)
|
sb $s1,3($a0)
|
sb $s1,3($a0)
|
sh $s2,4($a0)
|
sh $s2,4($a0)
|
sb $s3,5($a0)
|
sb $s3,5($a0)
|
sb $s4,2($a0)
|
sb $s4,2($a0)
|
sb $s5,3($a0)
|
sb $s5,3($a0)
|
sb $s6,4($a0)
|
sb $s6,4($a0)
|
sb $s7,5($a0)
|
sb $s7,5($a0)
|
sh $s0,2($a0)
|
sh $s0,2($a0)
|
sh $s2,4($a0)
|
sh $s2,4($a0)
|
sh $s2,6($a0)
|
sh $s2,6($a0)
|
sh $s0,10($a0)
|
sh $s0,10($a0)
|
|
|
lh $t0,2($a0)
|
lh $t0,2($a0)
|
lb $t1,3($a0)
|
lb $t1,3($a0)
|
lh $t2,4($a0)
|
lh $t2,4($a0)
|
lb $t3,5($a0)
|
lb $t3,5($a0)
|
lb $t4,2($a0)
|
lb $t4,2($a0)
|
lb $t5,3($a0)
|
lb $t5,3($a0)
|
lb $t6,4($a0)
|
lb $t6,4($a0)
|
lb $t7,5($a0)
|
lb $t7,5($a0)
|
lh $t0,2($a0)
|
lh $t0,2($a0)
|
lh $t2,4($a0)
|
lh $t2,4($a0)
|
lh $t2,6($a0)
|
lh $t2,6($a0)
|
lh $t0,10($a0)
|
lh $t0,10($a0)
|
|
|
bne $s0,$t0,rw_mismatch
|
bne $s0,$t0,rw_mismatch
|
nop
|
nop
|
bne $s1,$t1,rw_mismatch
|
bne $s1,$t1,rw_mismatch
|
nop
|
nop
|
bne $s2,$t2,rw_mismatch
|
bne $s2,$t2,rw_mismatch
|
nop
|
nop
|
bne $s3,$t3,rw_mismatch
|
bne $s3,$t3,rw_mismatch
|
nop
|
nop
|
bne $s4,$t4,rw_mismatch
|
bne $s4,$t4,rw_mismatch
|
nop
|
nop
|
bne $s5,$t5,rw_mismatch
|
bne $s5,$t5,rw_mismatch
|
nop
|
nop
|
bne $s6,$t6,rw_mismatch
|
bne $s6,$t6,rw_mismatch
|
nop
|
nop
|
bne $s7,$t7,rw_mismatch
|
bne $s7,$t7,rw_mismatch
|
nop
|
nop
|
.endif
|
.endif
|
addi $t8,$t8,-1
|
addi $t8,$t8,-1
|
bnez $t8,rw_test_loop
|
bnez $t8,rw_test_loop
|
addiu $a0,$a0,0x100
|
addiu $a0,$a0,0x100
|
|
|
la $a0,msg_ok
|
la $a0,msg_ok
|
jal puts
|
jal puts
|
nop
|
nop
|
|
|
j rw_done
|
j rw_done
|
nop
|
nop
|
|
|
rw_mismatch:
|
rw_mismatch:
|
la $a0,msg_fail
|
la $a0,msg_fail
|
jal puts
|
jal puts
|
nop
|
nop
|
|
|
rw_done:
|
rw_done:
|
la $a0,crlf
|
la $a0,crlf
|
jal puts
|
jal puts
|
nop
|
nop
|
|
|
|
|
test_xram:
|
test_xram:
|
la $a0,msg1
|
la $a0,msg1
|
jal puts
|
jal puts
|
nop
|
nop
|
|
|
li $t0,XRAM_BASE
|
li $t0,XRAM_BASE
|
li $t1,256
|
li $t1,256
|
li $t2,0x12345678
|
li $t2,0x12345678
|
|
|
xram_fill_loop:
|
xram_fill_loop:
|
sw $t2,0($t0)
|
sw $t2,0($t0)
|
addi $t0,$t0,4
|
addi $t0,$t0,4
|
addi $t2,$t2,0x0333
|
addi $t2,$t2,0x0333
|
bgtz $t1,xram_fill_loop
|
bgtz $t1,xram_fill_loop
|
addi $t1,$t1,-1
|
addi $t1,$t1,-1
|
|
|
li $t0,XRAM_BASE
|
li $t0,XRAM_BASE
|
li $t1,256
|
li $t1,256
|
li $t2,0x12345678
|
li $t2,0x12345678
|
li $t3,0x12345678
|
li $t3,0x12345678
|
|
|
xram_test_loop:
|
xram_test_loop:
|
lw $t3,0($t0)
|
lw $t3,0($t0)
|
bne $t2,$t3,xram_test_failed
|
bne $t2,$t3,xram_test_failed
|
addi $t0,$t0,4
|
addi $t0,$t0,4
|
addi $t2,$t2,0x0333
|
addi $t2,$t2,0x0333
|
bgtz $t1,xram_test_loop
|
bgtz $t1,xram_test_loop
|
addi $t1,$t1,-1
|
addi $t1,$t1,-1
|
|
|
la $a0,msg_ok
|
la $a0,msg_ok
|
jal puts
|
jal puts
|
nop
|
nop
|
j xram_test_end
|
j xram_test_end
|
nop
|
nop
|
|
|
xram_test_failed:
|
xram_test_failed:
|
la $a0,msg_fail
|
la $a0,msg_fail
|
jal puts
|
jal puts
|
nop
|
nop
|
|
|
xram_test_end:
|
xram_test_end:
|
la $a0,crlf
|
la $a0,crlf
|
jal puts
|
jal puts
|
nop
|
nop
|
|
|
|
|
la $a0,msg2
|
la $a0,msg2
|
jal puts
|
jal puts
|
nop
|
nop
|
|
|
$DONE:
|
$DONE:
|
j $DONE # freeze here
|
j $DONE # freeze here
|
nop
|
nop
|
|
|
|
|
#--- Special functions that do not use any RAM ---------------------------------
|
#--- Special functions that do not use any RAM ---------------------------------
|
# WARNING: Not for general use!
|
# WARNING: Not for general use!
|
# All parameters in $a0..$a4, stack unused. No attempt to comply with any ABI
|
# All parameters in $a0..$a4, stack unused. No attempt to comply with any ABI
|
# has been made.
|
# has been made.
|
# Since we can't use any RAM, registers have been used with no regard for
|
# Since we can't use any RAM, registers have been used with no regard for
|
# intended usage -- have to share reg bank with calling function.
|
# intended usage -- have to share reg bank with calling function.
|
|
|
# void puts(char *s) -- print zero-terminated string
|
# void puts(char *s) -- print zero-terminated string
|
puts:
|
puts:
|
la $a2,UART_BASE # UART base address
|
la $a2,UART_BASE # UART base address
|
puts_loop:
|
puts_loop:
|
lb $v0,0($a0)
|
lb $v0,0($a0)
|
beqz $v0,puts_end
|
beqz $v0,puts_end
|
addiu $a0,1
|
addiu $a0,1
|
puts_wait_tx_rdy:
|
puts_wait_tx_rdy:
|
lw $v1,UART_STATUS($a2)
|
lw $v1,UART_STATUS($a2)
|
andi $v1,$v1,0x02
|
andi $v1,$v1,UART_TX_RDY
|
beqz $v1,puts_wait_tx_rdy
|
beqz $v1,puts_wait_tx_rdy
|
nop
|
nop
|
sw $v0,UART_TX($a2)
|
sw $v0,UART_TX($a2)
|
b puts_loop
|
b puts_loop
|
nop
|
nop
|
|
|
puts_end:
|
puts_end:
|
jr $ra
|
jr $ra
|
nop
|
nop
|
|
|
# void put_hex(int n, int d) -- print integer as d-digit hex
|
# void put_hex(int n, int d) -- print integer as d-digit hex
|
put_hex:
|
put_hex:
|
la $a2,UART_BASE
|
la $a2,UART_BASE
|
la $a3,put_hex_table
|
la $a3,put_hex_table
|
addi $a1,-1
|
addi $a1,-1
|
add $a1,$a1,$a1
|
add $a1,$a1,$a1
|
add $a1,$a1,$a1
|
add $a1,$a1,$a1
|
|
|
put_hex_loop:
|
put_hex_loop:
|
srlv $v0,$a0,$a1
|
srlv $v0,$a0,$a1
|
andi $v0,$v0,0x0f
|
andi $v0,$v0,0x0f
|
addu $s2,$a3,$v0
|
addu $s2,$a3,$v0
|
lb $v0,0($s2)
|
lb $v0,0($s2)
|
put_hex_wait_tx_rdy:
|
put_hex_wait_tx_rdy:
|
lw $v1,UART_STATUS($a2)
|
lw $v1,UART_STATUS($a2)
|
andi $v1,$v1,0x02
|
andi $v1,$v1,UART_TX_RDY
|
beqz $v1,put_hex_wait_tx_rdy
|
beqz $v1,put_hex_wait_tx_rdy
|
nop
|
nop
|
sw $v0,UART_TX($a2)
|
sw $v0,UART_TX($a2)
|
|
|
bnez $a1,put_hex_loop
|
bnez $a1,put_hex_loop
|
addi $a1,-4
|
addi $a1,-4
|
|
|
jr $ra
|
jr $ra
|
nop
|
nop
|
|
|
|
|
#---- Constant data (note we keep it in the text section) ----------------------
|
#---- Constant data (note we keep it in the text section) ----------------------
|
|
|
put_hex_table:
|
put_hex_table:
|
.ascii "0123456789abcdef"
|
.ascii "0123456789abcdef"
|
|
|
msg1:
|
msg1:
|
.asciz "Testing 16-bit static R/W... "
|
.asciz "Testing 16-bit static R/W... "
|
msg2:
|
msg2:
|
.asciz "End of test, program frozen.\n\r"
|
.asciz "End of test, program frozen.\n\r"
|
msg3:
|
msg3:
|
.asciz "Testing bursts of back-to-back R/W... "
|
.asciz "Testing bursts of back-to-back R/W... "
|
msg_ok:
|
msg_ok:
|
.asciz "OK"
|
.asciz "OK"
|
msg_fail:
|
msg_fail:
|
.asciz "FAIL"
|
.asciz "FAIL"
|
crlf:
|
crlf:
|
.asciz "\n\r"
|
.asciz "\n\r"
|
space:
|
space:
|
.asciz " "
|
.asciz " "
|
msg0:
|
msg0:
|
.asciz "\n\rNow running from 8-bit static memory.\n\r"
|
.asciz "\n\rNow running from 8-bit static memory.\n\r"
|
|
|
.set reorder
|
.set reorder
|
.end flash_test
|
.end flash_test
|
|
|
|
|