memtest:
mov r10, lr @ 保存返回地址
@ print prompt information 打印信息“MTST ”
ldr r1, SerBase
mov r0, #'M'
bl PrintChar
mov r0, #'T'
bl PrintChar
mov r0, #'S'
bl PrintChar
mov r0, #'T'
bl PrintChar
mov r0, #' '
bl PrintChar
@ check the first 1MB in increments of 4k ,检查sdram开头的1M。每4k检测一次
mov r7, #0x1000 @ 4k
mov r6, r7, lsl #8 @ 1M
mov r5, #DRAM_BASE @ 0x30000000
mem_test_loop:
mov r0, r5
bl testram_nostack @每4k检测这一次
teq r0, #1
beq badram @ 有错误
add r5, r5, r7 @暂时无错误则继续下4k的检测,直到检测完1M
subs r6, r6, r7
bne mem_test_loop
@ the first magabyte is OK. clear it
@ 程序走到这里,说明前1M检测完毕,且无错误。
mov r0, #((1024 * 1024) / (8 * 4))
mov r1, #DRAM_BASE
mov r2, #0
mov r3, #0
mov r4, #0
mov r5, #0
mov r6, #0
mov r7, #0
mov r8, #0
mov r9, #0
clear_loop_memtest: stmia r1!, {r2-r9} subs r0, r0, #(8 * 4) bne clear_loop_memtest
ldr r0, STR_OK ldr r1, SerBase bl PrintWord
mov pc, r10
badram:
ldr r0, STR_FAIL
ldr r1, SerBase
bl PrintWord
b .
testram_nostack:
@ 这里用到的算法很简单,步骤如下:
@ 1. 存储4k中的前两个字的值。(检测是以4k为单位的,每4k只测试前两个字是否能正确读写)
@ 2. 向第一个字中写0x55(0x01010101),向第二个字中写0xaa(0x10101010)。其特点都是10交错的。
@ 3. 立即读出刚刚写入的值,判断读出值是否与写入值相等?
@ 4. 根据上一步的结果,在r0中置标志位。
ldmia r0, {r1, r2}
mov r3, #0x55
mov r4, #0xaa
stmia r0, {r3, r4}
ldmia r0, {r3, r4}
teq r3, #0x55
teqeq r4, #0xaa
bne bad
mov r3, #0xaa
mov r4, #0x55
stmia r0, {r3, r4}
ldmia r0, {r3, r4}
teq r3, #0xaa
teqeq r4, #0x55
bad:
stmia r0, {r1, r2}
moveq r0, #0
movne r0, #1
mov pc, lr
@----------------------------------------------- End of memtest ------------------------------------
|