2 * Copyright (C) 2013, The AROS Development Team
4 * Author: Jason S. McMullan <jason.mcmullan@gmail.com>
6 * Licensed under the AROS PUBLIC LICENSE (APL) Version 1.1
11 #include <aros/config.h>
19 movem.l %d2-%d5/%a2-%a3/%a5,%sp@-
20 move.w 0xdff01c,%sp@- /* save INTENA */
23 /* Not bsr.s, since GAS turns that into a R_M68K_PC8 relocation, which
24 * won't translate properly via elf2hunk
30 move.w %d1,0xdff09a /* restore INTENA */
31 movem.l %sp@+,%d2-%d5/%a2-%a3/%a5
34 /******** Memory tester *******/
35 * IN: A0 - Address, A1 - Max end address, A5 - outtable
37 * OUT: D0 - Detected size
38 * TRASH: D1, D2, D3, D4, D5, A1, A2, A3
43 move.l %a0,%a5@ /* write start address */
45 sub.l %a0,%d0 /* max size */
49 beq.s __MemoryTest_24bitaddr
50 /* test if 32bit address mirrors address zero */
52 move.l 0.w,%d2 /* save old */
54 move.l #0xfecaf00d,%d1
58 move.l %d1,0x100.w /* write something else, some bus types "remember" old value */
60 nop /* force 68040/060 bus cycle to finish */
62 bne.s __MemoryTest_32bitok /* different? no mirror */
63 move.l #0xcafed00d,%d1
71 bne.s __MemoryTest_32bitok /* check again, maybe 0 already had our test value */
72 move.l %d2,0.w /* restore saved value */
75 bra __MemoryTest_none /* 24-bit CPU, do not test this range */
77 move.l %d2,0.w /* restore saved value */
79 __MemoryTest_24bitaddr:
81 /* a0 = tested address, d0 = max size, d1 = current size */
90 bne.s __MemoryTest_chipcheck_done /* no chiptest if 32bit address */
91 move.w #0x7fff,0xdff09a
93 tst.w %a0@(0x1c,%d1) /* If non-zero, this is not INTENAR */
94 bne.s __MemoryTest_chipcheck_done
96 move.w #0xc000,0xdff09a /* Try the master enable */
98 tst.w %a0@(0x1c,%d1) /* If still zero, not INTENAR */
99 bne __MemoryTest_done /* It was a custom chip. */
100 __MemoryTest_chipcheck_done:
104 cmp.l #__MemoryTest,%a2 /* Make sure we don't modify our own test code */
105 bcs.s __MemoryTest_nottestcode
106 cmp.l #__MemoryTest_end,%a2
107 bcs.s __MemoryTest_next
108 __MemoryTest_nottestcode:
110 move.l %a0@(%d1),%d3 /* read old value */
111 move.l %a0@,%a2 /* save mirror test contents */
112 move.l #0xfecaf00d,%a0@ /* write mirror test value */
114 move.l #0xcafed00d,%d2
115 move.l %d2,%a0@(%d1) /* write test pattern */
117 tst.l %d1 /* first test addrress? */
118 beq.s __MemoryTest_nomirror
119 cmp.l %a0@,%d2 /* no, check mirrorirng */
120 bne.s __MemoryTest_nomirror
121 move.l %a2,%a0@ /* restore mirror test contents */
122 bra.s __MemoryTest_done
123 __MemoryTest_nomirror:
126 move.l %a0@(4,%d1),%a3 /* read temp address */
127 move.l %d2,%a0@(4,%d1) /* fill bus with something else */
130 move.l %a0@(%d1),%d4 /* read test pattern */
131 move.l %a3,%a0@(4,%d1) /* restore */
133 cmp.l %d4,%d2 /* pattern match? */
134 bne.s __MemoryTest_done
135 neg.l %d2 /* test pattern 2 */
137 move.l %d2,%a0@(%d1) /* write test pattern */
140 move.l %a0@(4,%d1),%a3 /* read temp address */
141 move.l %d2,%a0@(4,%d1) /* fill bus with something else */
144 move.l %a0@(%d1),%d4 /* read test pattern */
145 move.l %a3,%a0@(4,%d1) /* restore */
148 bne.s __MemoryTest_done
150 move.l %d3,%a0@(%d1) /* write old value back */
152 move.l %a2,%a0@ /* restore mirror test contents */
154 add.l %d5,%d1 /* next block */
155 bra __MemoryTest_loop
158 tst.l %d1 /* nothing found? */
159 beq.s __MemoryTest_none