Hopefully fix FS#8506 (OF cant be loaded on some PP targets). also hopefully fixes...
[Rockbox.git] / firmware / target / arm / crt0-pp-bl.S
blob7aabd2b06af33c192f0bb723317dc7a7bc8e767e
1 /***************************************************************************
2  *             __________               __   ___.
3  *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
4  *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
5  *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
6  *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
7  *                     \/            \/     \/    \/            \/
8  * $Id$
9  *
10  * Copyright (C) 2002 by Linus Nielsen Feltzing
11  *
12  * All files in this archive are subject to the GNU General Public License.
13  * See the file COPYING in the source tree root for full license agreement.
14  *
15  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16  * KIND, either express or implied.
17  *
18  ****************************************************************************/
19 #include "config.h"
20 #include "cpu.h"
22     .section .init.text,"ax",%progbits
24     .global    start
25 start:
27 /* PortalPlayer bootloader and startup code based on startup.s from the iPodLinux 
28  * loader
29  *
30  * Copyright (c) 2003, Daniel Palffy (dpalffy (at) rainstorm.org)
31  * Copyright (c) 2005, Bernard Leach <leachbj@bouncycastle.org>
32  *
33  */
34 #if CONFIG_CPU == PP5002
35     .equ    PROC_ID,     0xc4000000
36     .equ    CPU_CTRL,    0xcf004054
37     .equ    CPU_STATUS,  0xcf004050
38     .equ    COP_CTRL,    0xcf004058
39     .equ    COP_STATUS,  0xcf004050
40     .equ    IIS_CONFIG,  0xc0002500
41     .equ    SLEEP,       0xca
42     .equ    WAKE,        0xce
43     .equ    CPUSLEEPING, 0x8000
44     .equ    COPSLEEPING, 0x4000
45     .equ    CACHE_CTRL,  0xcf004024
46     .equ    CACHE_ENAB,  0x2 /* Actually the CACHE_INIT flag */
47 #else
48     .equ    PROC_ID,     0x60000000
49     .equ    CPU_CTRL,    0x60007000
50     .equ    CPU_STATUS,  0x60007000
51     .equ    COP_CTRL,    0x60007004
52     .equ    COP_STATUS,  0x60007004
53     .equ    IIS_CONFIG,  0x70002800
54     .equ    SLEEP,       0x80000000
55     .equ    WAKE,        0x0
56     .equ    CPUSLEEPING, 0x80000000
57     .equ    COPSLEEPING, 0x80000000
58     .equ    CACHE_CTRL,  0x6000c000
59     .equ    CACHE_ENAB,  0x1
60 #endif
62     msr    cpsr_c, #0xd3 /* enter supervisor mode, disable IRQ */
63 #ifndef E200R_INSTALLER
64 /* 1 - Copy the bootloader to IRAM */
65     /* get the high part of our execute address */
66     bic    r0, pc, #0xff /* r4 = pc & 0xffffff00 */
68     /* Copy bootloader to safe area - 0x40000000 (IRAM) */
69     mov    r1, #0x40000000
70     ldr    r2, =_dataend
72     cmp    r2, r1
73     ldrhi  r3, [r0], #4
74     strhi  r3, [r1], #4
75     bhi    1b
77 #ifndef IPOD_ARCH
78     /* For builds on targets with mi4 firmware, scramble writes data to 
79        0xe0-0xeb, so jump past that. pad_skip must then exist at an
80        address >= 0xec */
81     b      pad_skip
83 .space 60*4 
85 pad_skip:
86 #endif /* IPOD_ARCH */
89 /* 2 - Jump both CPU and COP there */
90     ldr    pc, =start_loc    /* jump to the relocated start_loc:  */
91 #endif /* E200R_INSTALLER */
93 start_loc:
94     /* Find out which processor we are */
95     ldr    r0, =PROC_ID
96     ldrb   r0, [r0]
97     cmp    r0, #0x55
98     beq    cpu
100 cop:
101     /* put us (co-processor) to sleep */
102     ldr    r0, =COP_CTRL
103     mov    r1, #SLEEP
104     str    r1, [r0]
105     nop
106     nop
107     
108     /* Invalidate cache */
109     mov    r0, #1
110     bl     cache_op
112     ldr    r0, =startup_loc
113     ldr    pc, [r0]
115 cpu:
116     /* Wait for COP to be sleeping */
117     ldr    r0, =COP_STATUS
119     ldr    r1, [r0]
120     tst    r1, #COPSLEEPING
121     beq    1b
122     
123     /* Initialise bss section to zero */
124     ldr    r0, =_edata
125     ldr    r1, =_end
126     mov    r2, #0
128     cmp    r1, r0
129     strhi  r2, [r0], #4
130     bhi    1b
131        
132     /* Set up some stack and munge it with 0xdeadbeef */
133     ldr    sp, =stackend
134     ldr    r0, =stackbegin
135     ldr    r1, =0xdeadbeef
137     cmp    sp, r0
138     strhi  r1, [r0], #4
139     bhi    1b
141     /* execute the loader - this will load an image to 0x10000000 */
142     bl     main
144     /* store actual startup location returned by main() */
145     ldr    r1, =startup_loc
146     str    r0, [r1]
148     /* flush cache */    
149     mov    r0, #0
150     bl     cache_op
152     /* Wake up the coprocessor before executing the firmware */
153     ldr    r0, =COP_CTRL
154     mov    r1, #WAKE
155     str    r1, [r0]
157 #ifdef SANSA_C200
158     /* Magic for loading the c200 OF */
159     ldr    r0, =0xb00d10ad
160     mov    r1, #0x700
161     ldr    r2, =0xfff0
162     mov    r3, #0x7
163 #endif
165     ldr    r4, =startup_loc
166     ldr    pc, [r4]
168 startup_loc:
169     .word    0x0
170     
171 #ifdef IPOD_ARCH
172 .align 8    /* starts at 0x100 */
173 .global boot_table
174 boot_table:
175     /* here comes the boot table, don't move its offset - preceding
176        code+data must stay <= 256 bytes */
177     .space 400
178 #endif
180 cache_op:
181     ldr    r2, =CACHE_CTRL
182     ldr    r1, [r2]
183     tst    r1, #CACHE_ENAB
184     bxeq   lr
185     cmp    r0, #0
186 #ifdef CPU_PP502x
187     ldr    r0, =0xf000f044
188     ldr    r1, [r0]
189     orrne  r1, r1, #0x6
190     orreq  r1, r1, #0x2
191     str    r1, [r0]
193     ldr    r1, [r2]
194     tst    r1, #0x8000
195     bne    1b
196 #elif CONFIG_CPU == PP5002
197     ldrne  r0, =0xf0004000
198     ldreq  r0, =0xf000c000
199     add    r1, r0, #0x2000
200     mov    r2, #0
202     cmp    r1, r0
203     strhi  r2, [r0], #16
204     bhi    1b
205 #endif /* CPU type */
206     bx     lr