detect if the compiler supports -fno-builtin and -fno-builtin-vsnprintf. (NicJA)
[AROS.git] / arch / m68k-amiga / expansion / memorytest.S
blob1f0b9370124b8afdb0a7220c2b327e43152e32c7
1 /*
2  * Copyright (C) 2013, The AROS Development Team
3  * All right reserved.
4  * Author: Jason S. McMullan <jason.mcmullan@gmail.com>
5  *
6  * Licensed under the AROS PUBLIC LICENSE (APL) Version 1.1
7  * 
8  * $Id$
9  */
11 #include <aros/config.h>
13         .text
14         .chip 68000
15         .align 4 
17         .globl MemoryTest
18 MemoryTest:
19         movem.l %d2-%d5/%a2-%a3/%a5,%sp@-
20         move.w  0xdff01c,%sp@-  /* save INTENA */
21         subq.l  #8,%sp
22         move.l  %sp,%a5
23         /* Not bsr.s, since GAS turns that into a R_M68K_PC8 relocation, which
24          * won't translate properly via elf2hunk
25          */
26         jsr             __MemoryTest
27         addq.l  #8,%sp
28         move.w  %sp@+,%d1
29         or.w    #0x8000,%d1
30         move.w  %d1,0xdff09a    /* restore INTENA */
31         movem.l %sp@+,%d2-%d5/%a2-%a3/%a5
32         rts
34         /******** Memory tester *******/
35          * IN: A0 - Address, A1 - Max end address, A5 - outtable
36          * IN: D0 = block size
37          * OUT: D0 - Detected size
38          * TRASH: D1, D2, D3, D4, D5, A1, A2, A3
39          */
40         .globl __MemoryTest
41 __MemoryTest:
42         move.l  %d0,%d5
43         move.l  %a0,%a5@                        /* write start address */
44         move.l  %a1,%d0
45         sub.l   %a0,%d0                         /* max size */
47         move.l  %a0,%d1
48         and.l   #0xff000000,%d1
49         beq.s   __MemoryTest_24bitaddr
50         /* test if 32bit address mirrors address zero */
51         move.l  %d1,%a1
52         move.l  0.w,%d2                         /* save old */
53         move.l  0x100.w,%d3
54         move.l  #0xfecaf00d,%d1
55         move.l  %d1,0.w
56         nop
57         not.w   %d1
58         move.l  %d1,0x100.w                     /* write something else, some bus types "remember" old value */
59         not.w   %d1
60         nop                                                     /* force 68040/060 bus cycle to finish */
61         cmp.l   %a1@,%d1
62         bne.s   __MemoryTest_32bitok    /* different? no mirror */
63         move.l  #0xcafed00d,%d1
64         move.l  %d1,0.w
65         nop
66         not.w   %d1
67         move.l  %d1,0x100.w
68         not.w   %d1
69         nop
70         cmp.l   %a1@,%d1
71         bne.s   __MemoryTest_32bitok    /* check again, maybe 0 already had our test value */
72         move.l  %d2,0.w                         /* restore saved value */
73         move.l  %d3,0x100.w
74         moveq   #-1,%d1
75         bra             __MemoryTest_none               /* 24-bit CPU, do not test this range */
76 __MemoryTest_32bitok:
77         move.l  %d2,0.w                         /* restore saved value */
78         move.l  %d3,0x100.w
79 __MemoryTest_24bitaddr:
81         /* a0 = tested address, d0 = max size, d1 = current size */
83         clr.l   %d1
84 __MemoryTest_loop:
85         cmp.l   %d0,%d1
86         bge             __MemoryTest_done
88         move.l  %a0,%d2
89         and.l   #0xff000000,%d2
90         bne.s   __MemoryTest_chipcheck_done     /* no chiptest if 32bit address */
91         move.w  #0x7fff,0xdff09a
92         nop
93         tst.w   %a0@(0x1c,%d1)                          /* If non-zero, this is not INTENAR */
94         bne.s   __MemoryTest_chipcheck_done
95         /* It was zero ... */
96         move.w  #0xc000,0xdff09a                        /* Try the master enable */
97         nop
98         tst.w   %a0@(0x1c,%d1)                          /* If still zero, not INTENAR */
99         bne     __MemoryTest_done                               /* It was a custom chip. */
100 __MemoryTest_chipcheck_done:
102         move.l  %a0,%a2
103         add.l   %d1,%a2
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 */
113         nop
114         move.l  #0xcafed00d,%d2
115         move.l  %d2,%a0@(%d1)           /* write test pattern */
116         nop
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:
125         not.l   %d2
126         move.l  %a0@(4,%d1),%a3         /* read temp address */
127         move.l  %d2,%a0@(4,%d1)         /* fill bus with something else */
128         not.l   %d2
129         nop
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 */
138         nop
139         not.l   %d2
140         move.l  %a0@(4,%d1),%a3         /* read temp address */
141         move.l  %d2,%a0@(4,%d1)         /* fill bus with something else */
142         not.l   %d2
143         nop
144         move.l  %a0@(%d1),%d4           /* read test pattern */
145         move.l  %a3,%a0@(4,%d1)         /* restore */
147         cmp.l   %d4,%d2
148         bne.s   __MemoryTest_done
149         not.l   %d2
150         move.l  %d3,%a0@(%d1)           /* write old value back */
152         move.l  %a2,%a0@                        /* restore mirror test contents */
153 __MemoryTest_next:
154         add.l   %d5,%d1                         /* next block */
155         bra             __MemoryTest_loop
157 __MemoryTest_done:
158         tst.l   %d1                                     /* nothing found? */
159         beq.s   __MemoryTest_none
160         addq.l  #4,%a5
161         move.l  %d1,%a5@+
162 __MemoryTest_none:
163         move.l  %d1,%d0
164         rts
165 __MemoryTest_end: