FS#11968 by Peter Lecky - Slovak language update
[maemo-rb.git] / firmware / target / coldfire / crt0.S
blobe6717710b1928b0f25425d7bb6f2bcf8e1a8624a
1 /***************************************************************************
2  *             __________               __   ___.
3  *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
4  *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
5  *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
6  *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
7  *                     \/            \/     \/    \/            \/
8  * $Id$
9  *
10  * Copyright (C) 2002 by Linus Nielsen Feltzing
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18  * KIND, either express or implied.
19  *
20  ****************************************************************************/
21 #include "config.h"
22 #include "cpu.h"
24     .section .init.text,"ax",@progbits
26     .global    start
27 start:
29     move.w  #0x2700,%sr
31     move.l  #vectors,%d0
32     movec.l %d0,%vbr
33         
34     move.l  #MBAR+1,%d0
35     movec.l %d0,%mbar
36         
37     move.l  #MBAR2+1,%d0
38     movec.l %d0,%mbar2
40     lea     MBAR,%a0
41     lea     MBAR2,%a1
42         
43     clr.l  (0x180,%a1)  /* PLLCR = 0 */
45     /* 64K DMA-capable SRAM at 0x10000000
46        DMA is enabled and has priority in both banks
47        All types of accesses are allowed
48        (We might want to restrict that to save power) */
49     move.l  #0x10000e01,%d0
50     movec.l %d0,%rambar1
52     /* 32K Non-DMA SRAM at 0x10010000
53        All types of accesses are allowed
54        (We might want to restrict that to save power) */
55     move.l  #0x10010001,%d0
56     movec.l %d0,%rambar0
58     /* Chip select 0 - Flash ROM */
59     moveq.l #0x00,%d0      /* CSAR0 - Base = 0x00000000 */
60     move.l  %d0,(0x080,%a0)
61     move.l  #FLASH_SIZE-0x10000+1,%d0 /* CSMR0 - All access */
62     move.l  %d0,(0x084,%a0)
63     move.l  #0x00000180,%d0 /* CSCR0 - no wait states, 16 bits, no bursts */
64     move.l  %d0,(0x088,%a0)
65         
66 #if (defined MPIO_HD200) || (defined MPIO_HD300)
67     /* Chip select 3 - LCD controller */
68     move.l  #0xf0000000,%d0 /* CSAR3 - Base = 0xf0000000 */
69     move.l  %d0,(0x0a4,%a0)
70     moveq.l #0x1,%d0        /* CSMR3 - 64K */
71     move.l  %d0,(0x0a8,%a0)
72     move.l  #0x00000180,%d0 /* CSCR3 - no wait states, 16 bits no bursts */
73     move.l  %d0,(0x0ac,%a0)
74 #elif !(defined IAUDIO_M3)
75     /* Chip select 1 - LCD controller */
76     move.l  #0xf0000000,%d0 /* CSAR1 - Base = 0xf0000000 */
77     move.l  %d0,(0x08c,%a0)
78     moveq.l #0x1,%d0        /* CSMR1 - 64K */
79     move.l  %d0,(0x090,%a0)
80     move.l  #0x00000180,%d0 /* CSCR1 - no wait states, 16 bits, no bursts */
81     move.l  %d0,(0x094,%a0)
82 #endif
83         
84     /* Chip select 2 - ATA controller */
85     move.l  #0x20000000,%d0 /* CSAR2 - Base = 0x20000000 */
86     move.l  %d0,(0x098,%a0)
87     moveq.l #0x1,%d0        /* CSMR2 - 64K */
88     move.l  %d0,(0x09c,%a0)
89     move.l  #0x00000080,%d0 /* CSCR2 - no wait states, 16 bits, no bursts */
90     move.l  %d0,(0x0a0,%a0) /* wait states are handled by the coldfire
91                              * IDE interface logic. */
93 #if defined(CONFIG_USBOTG) && CONFIG_USBOTG == USBOTG_ISP1362
94     /* Chip select 3 - USBOTG controller */
95     move.l  #0xc0000000,%d0 /* CSAR3 - Base = 0xc0000000 */
96     move.l  %d0,(0x0a4,%a0)
97     moveq.l #0x1,%d0        /* CSMR3 - 64K */
98     move.l  %d0,(0x0a8,%a0)
99     move.l  #0x00000180,%d0 /* CSCR3 - no wait states, 16 bits, no bursts */
100     move.l  %d0,(0x0ac,%a0)
101 #endif
103 #ifdef BOOTLOADER
104     /* Check if we have a Rockbox ROM image */
105     lea     0x00100000,%a2
106     move.l  (%a2),%d0
107     move.l  #FLASH_MAGIC,%d1
108     cmp.l   %d0,%d1
109     beq.b   .imagefound
110     
111     /* Check for RAM image */
112     lea     0x00001000,%a2
113     move.l  (%a2),%d0
114     move.l  #FLASH_MAGIC,%d1
115     cmp.l   %d0,%d1
116     beq.b   .imagefound
117     
118     /* Not either ROM or RAM image was found, so original firmware
119        should be still present. */
121     /* Check if the cookie is present. */
122     lea     0x10017ffc,%a2
123     move.l  (%a2),%d0
124     move.l  #0xc0015a17,%d1
125     cmp.l   %d0,%d1
126     bne.b   .nocookie
127     
128     /* The cookie is not reset. This must mean that the boot loader
129        has crashed. Let's start the original firmware immediately. */
130     lea     0x10017ffc,%a2
131     clr.l   (%a2)
132     jmp     8
133         
134 .nocookie:
135     /* Set the cookie */
136     move.l  %d1,(%a2)
137 .imagefound:
139     /* Set up the DRAM controller. The refresh is based on the 11.2896MHz
140        clock (5.6448MHz bus frequency). We haven't yet started the PLL */
141 #if MEMORYSIZE < 32
142     move.w  #0x8004,%d0 /* DCR - Synchronous, 80 cycle refresh */
143 #else
144     move.w  #0x8001,%d0 /* DCR - Synchronous, 32 cycle refresh */
145 #endif
146     move.w  %d0,(0x100,%a0)
148     /* Note on 32Mbyte models:
149        We place the SDRAM on an 0x1000000 (16M) offset because
150        the 5249 BGA chip has a fault which disables the use of A24. The
151        suggested workaround by FreeScale is to offset the base address by
152        half the DRAM size and increase the mask to the double.
153        In our case this means that we set the base address 16M ahead and
154        use a 64M mask.
155     */
156 #if MEMORYSIZE < 32
157     move.l  #0x31002324,%d0 /* DACR0 - Base 0x31000000, Banks on 21 and up,
158                                CAS latency 2, Page mode, No refresh yet */
159     move.l  %d0,(0x108,%a0)
160     move.l  #0x00fc0001,%d0 /* Size: 16M */
161     move.l  %d0,(0x10c,%a0) /* DMR0 - 32Mb */
162 #else
163     move.l  #0x31002524,%d0 /* DACR0 - Base 0x31000000, Banks on 23 and up,
164                                CAS latency 2, Page mode, No refresh yet */
165     move.l  %d0,(0x108,%a0)
166     move.l  #0x03fc0001,%d0 /* Size: 64M because of workaround above */
167     move.l  %d0,(0x10c,%a0) /* DMR0 - 32Mb */
168 #endif
170     /* Precharge */
171     moveq.l #8,%d0
172     or.l    %d0,(0x108,%a0) /* DACR0[IP] = 1, next access will issue a
173                                Precharge command */
174     move.l  #0xabcd1234,%d0
175     move.l  %d0,0x31000000  /* Issue precharge command */
177     move.l  #0x8000,%d0
178     or.l    %d0,(0x108,%a0) /* Enable refresh */
180     /* Let it refresh */
181     move.l  #500,%d0
182 .delayloop:
183     subq.l  #1,%d0
184     bne.b   .delayloop
186     /* Mode Register init */
187     moveq.l #0x40,%d0       /* DACR0[IMRS] = 1, next access will set the
188                                Mode Register */
189     or.l    %d0,(0x108,%a0)
191     move.l  #0xabcd1234,%d0
192     move.l  %d0,0x31000800  /* A11=1 means CASL=2 (connected to SDRAM A5). */
194     /* DACR0[IMRS] gets deactivated by the SDRAM controller */
195     
196     /* Check if we have a Rockbox ROM image. For RAM image only cookie is
197        not set at all. But we could support also RAM images loading. */
198     lea     0x00100000,%a2
199     move.l  (%a2),%d0
200     move.l  #FLASH_MAGIC,%d1
201     cmp.l   %d0,%d1
202     bne.b   .noromimage
203     
204     /* Check again if the cookie is present. */
205     lea     0x10017ffc,%a2
206     move.l  (%a2),%d0
207     move.l  #0xc0015a17,%d1
208     cmp.l   %d0,%d1
209     bne.b   .nocookie2
210     
211     /* We have found Rockbox in ROM!
212        Clear the cookie and load the ROM image */
213     lea     0x10017ffc,%a2
214     clr.l   (%a2)
215     lea     0x00100028+4,%a2
216     move.l  (%a2),%sp
217     lea     0x00100028+8,%a2
218     move.l  (%a2),%d0
219     move.l  %d0,%a2
220     jmp     (%a2)
221     
222 .nocookie2:
223     /* Set the cookie */
224     move.l  %d1,(%a2)
225 .noromimage:
227 #endif /* BOOTLOADER */
229     /* Invalicate cache */
230     move.l  #0x01000000,%d0
231     movec.l %d0,%cacr
232         
233     /* Enable cache, default=non-cacheable, no buffered writes */
234     move.l  #0x80000000,%d0
235     movec.l %d0,%cacr
237     /* Cache enabled in SDRAM only, buffered writes enabled */
238     move.l  #0x3103c020,%d0
239     movec.l %d0,%acr0
240     /* Buffered writes enabled for the LCD */
241     move.l  #0xf000c060,%d0
242     movec.l %d0,%acr1
244 #ifndef BOOTLOADER
245     /* .iram copy is done first since it is reclaimed for other
246      * uninitialized sections */
248     /* copy the .iram section */
249     lea     _iramcopy,%a2
250     lea     _iramstart,%a3
251     lea     _iramend,%a4
252     bra.b   .iramstart
253 .iramloop:
254     move.l  (%a2)+,(%a3)+
255 .iramstart:
256     cmp.l   %a3,%a4
257     bhi.b   .iramloop
259     /* zero out .ibss */
260     lea     _iedata,%a2
261     lea     _iend,%a4
262     bra.b   .iedatastart
263 .iedataloop:
264     clr.l   (%a2)+
265 .iedatastart:
266     cmp.l   %a2,%a4
267     bhi.b   .iedataloop
268 #endif /* !BOOTLOADER */
270 #ifdef IRIVER_H300_SERIES
271     /* Set KEEP_ACT before doing the lengthy copy and zero-fill operations */
272     move.l #0x00080000,%d0
273     or.l %d0,(0xb4,%a1)
274     or.l %d0,(0xb8,%a1)
275     or.l %d0,(0xbc,%a1)
276 #endif
278 #if (defined MPIO_HD200) || (defined MPIO_HD300)
279     /* Set KEEP_ACT
280      * Set GPIO57 high to remove hissing nois on startup
281      */
282     move.l #0x02200000,%d0
283     or.l %d0,(0xb4,%a1)
284     or.l %d0,(0xb8,%a1)
285     or.l %d0,(0xbc,%a1)
286 #endif
288     /* zero out bss */
289     lea     _edata,%a2
290     lea     _end,%a4
291     bra.b   .edatastart
292 .edataloop:
293     clr.l   (%a2)+
294 .edatastart:
295     cmp.l   %a2,%a4
296     bhi.b   .edataloop
298     /* copy the .data section */
299     lea     _datacopy,%a2
300     lea     _datastart,%a3
301     cmp.l   %a2,%a3
302     beq.b   .nodatacopy   /* Don't copy if src and dest are equal */
303     lea     _dataend,%a4
304     bra.b   .datastart
305 .dataloop:
306     move.l  (%a2)+,(%a3)+
307 .datastart:
308     cmp.l   %a3,%a4
309     bhi.b   .dataloop
310 .nodatacopy:
312     /* Munge the main stack */
313     lea     stackbegin,%a2
314     lea     stackend,%a4
315     move.l  %a4,%sp
316     move.l  #0xdeadbeef,%d0
317 .mungeloop:
318     move.l  %d0,(%a2)+
319     cmp.l   %a2,%a4
320     bhi.b   .mungeloop
322     jsr     main
323 .hoo:
324     bra.b   .hoo
326     .section .resetvectors
327 vectors:
328     .long   stackend
329     .long   start