sd-as3525.c: disable wide bus, it corrupts writes
[kugel-rb.git] / firmware / target / arm / crt0-pp-bl.S
blob79235a6371b61429ba5de0baf66085c2837ef78a
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 /* PortalPlayer bootloader and startup code based on startup.s from the iPodLinux 
30  * loader
31  *
32  * Copyright (c) 2003, Daniel Palffy (dpalffy (at) rainstorm.org)
33  * Copyright (c) 2005, Bernard Leach <leachbj@bouncycastle.org>
34  *
35  */
36 #if CONFIG_CPU == PP5002
37     .equ    PROC_ID,     0xc4000000
38     .equ    CPU_CTRL,    0xcf004054
39     .equ    CPU_STATUS,  0xcf004050
40     .equ    COP_CTRL,    0xcf004058
41     .equ    COP_STATUS,  0xcf004050
42     .equ    IIS_CONFIG,  0xc0002500
43     .equ    SLEEP,       0xca
44     .equ    WAKE,        0xce
45     .equ    CPUSLEEPING, 0x8000
46     .equ    COPSLEEPING, 0x4000
47     .equ    CACHE_CTRL,  0xcf004024
48     .equ    CACHE_ENAB,  0x2 /* Actually the CACHE_CTL_INIT flag */
49 #else
50     .equ    PROC_ID,     0x60000000
51     .equ    CPU_CTRL,    0x60007000
52     .equ    CPU_STATUS,  0x60007000
53     .equ    COP_CTRL,    0x60007004
54     .equ    COP_STATUS,  0x60007004
55     .equ    IIS_CONFIG,  0x70002800
56     .equ    SLEEP,       0x80000000
57     .equ    WAKE,        0x0
58     .equ    CPUSLEEPING, 0x80000000
59     .equ    COPSLEEPING, 0x80000000
60     .equ    CACHE_CTRL,  0x6000c000
61     .equ    CACHE_ENAB,  0x1
62 #endif
64     msr    cpsr_c, #0xd3 /* enter supervisor mode, disable IRQ */
65 #ifndef E200R_INSTALLER
66 /* 1 - Copy the bootloader to IRAM */
67     /* get the high part of our execute address */
68     bic    r0, pc, #0xff /* r4 = pc & 0xffffff00 */
70     /* Copy bootloader to safe area - 0x40000000 (IRAM) */
71     mov    r1, #0x40000000
72     ldr    r2, =_dataend
74     cmp    r2, r1
75     ldrhi  r3, [r0], #4
76     strhi  r3, [r1], #4
77     bhi    1b
79 #ifndef IPOD_ARCH
80     /* For builds on targets with mi4 firmware, scramble writes data to 
81        0xe0-0xeb, so jump past that. pad_skip must then exist at an
82        address >= 0xec */
83     b      pad_skip
85 .space 60*4 
87 pad_skip:
88 #endif /* IPOD_ARCH */
91 /* 2 - Jump both CPU and COP there */
92     ldr    pc, =start_loc    /* jump to the relocated start_loc:  */
93 #endif /* E200R_INSTALLER */
95 start_loc:
96     /* Find out which processor we are */
97     ldr    r0, =PROC_ID
98     ldrb   r0, [r0]
99     cmp    r0, #0x55
100     beq    cpu
102 cop:
103     /* put us (co-processor) to sleep */
104     ldr    r0, =COP_CTRL
105     mov    r1, #SLEEP
106     str    r1, [r0]
107     nop
108     nop
109     
110     /* Invalidate cache */
111     mov    r0, #1
112     bl     cache_op
114     ldr    r0, =startup_loc
115     ldr    pc, [r0]
117 cpu:
118     /* Wait for COP to be sleeping */
119     ldr    r0, =COP_STATUS
121     ldr    r1, [r0]
122     tst    r1, #COPSLEEPING
123     beq    1b
124     
125     /* Initialise bss section to zero */
126     ldr    r0, =_edata
127     ldr    r1, =_end
128     mov    r2, #0
130     cmp    r1, r0
131     strhi  r2, [r0], #4
132     bhi    1b
133        
134     /* Set up some stack and munge it with 0xdeadbeef */
135     ldr    sp, =stackend
136     ldr    r0, =stackbegin
137     ldr    r1, =0xdeadbeef
139     cmp    sp, r0
140     strhi  r1, [r0], #4
141     bhi    1b
143     /* execute the loader - this will load an image to 0x10000000 */
144     bl     main
146     /* store actual startup location returned by main() */
147     ldr    r1, =startup_loc
148     str    r0, [r1]
150     /* flush cache */    
151     mov    r0, #0
152     bl     cache_op
154     /* Wake up the coprocessor before executing the firmware */
155     ldr    r0, =COP_CTRL
156     mov    r1, #WAKE
157     str    r1, [r0]
159 #if defined(SANSA_C200) || defined(PHILIPS_HDD1630) || defined(PHILIPS_HDD6330)
160     /* Magic for loading the c200 OF */
161     ldr    r0, =0xb00d10ad
162     mov    r1, #0x700
163     ldr    r2, =0xfff0
164     mov    r3, #0x7
165 #endif
167     ldr    r4, =startup_loc
168     ldr    pc, [r4]
170 startup_loc:
171     .word    0x0
172     
173 #ifdef IPOD_ARCH
174 .align 8    /* starts at 0x100 */
175 .global boot_table
176 boot_table:
177     /* here comes the boot table, don't move its offset - preceding
178        code+data must stay <= 256 bytes */
179     .space 400
180 #endif
182 cache_op:
183     ldr    r2, =CACHE_CTRL
184     ldr    r1, [r2]
185     tst    r1, #CACHE_ENAB
186     bxeq   lr
187     cmp    r0, #0
188 #ifdef CPU_PP502x
189     ldr    r0, =0xf000f044
190     ldr    r1, [r0]
191     orrne  r1, r1, #0x6
192     orreq  r1, r1, #0x2
193     str    r1, [r0]
195     ldr    r1, [r2]
196     tst    r1, #0x8000
197     bne    1b
198 #elif CONFIG_CPU == PP5002
199     ldrne  r0, =0xf0004000
200     ldreq  r0, =0xf000c000
201     add    r1, r0, #0x2000
202     mov    r2, #0
204     cmp    r1, r0
205     strhi  r2, [r0], #16
206     bhi    1b
207 #endif /* CPU type */
208     bx     lr