summaryrefslogtreecommitdiff
path: root/firmware/target/arm
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm')
-rw-r--r--firmware/target/arm/crt0-pp-bl.S179
-rw-r--r--firmware/target/arm/crt0-pp.S135
2 files changed, 208 insertions, 106 deletions
diff --git a/firmware/target/arm/crt0-pp-bl.S b/firmware/target/arm/crt0-pp-bl.S
new file mode 100644
index 0000000000..4f50cac699
--- /dev/null
+++ b/firmware/target/arm/crt0-pp-bl.S
@@ -0,0 +1,179 @@
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"
21
22 .section .init.text,"ax",%progbits
23
24 .global start
25start:
26
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 COP_CTRL, 0xcf004058
37 .equ COP_STATUS, 0xcf004050
38 .equ IIS_CONFIG, 0xc0002500
39 .equ SLEEP, 0xca
40 .equ WAKE, 0xce
41 .equ SLEEPING, 0x4000
42#else
43 .equ PROC_ID, 0x60000000
44 .equ COP_CTRL, 0x60007004
45 .equ COP_STATUS, 0x60007004
46 .equ IIS_CONFIG, 0x70002800
47 .equ SLEEP, 0x80000000
48 .equ WAKE, 0x0
49 .equ SLEEPING, 0x80000000
50 .equ CACHE_CTRL, 0x6000c000
51#endif
52
53 msr cpsr_c, #0xd3 /* enter supervisor mode, disable IRQ */
54
55/* 1 - Copy the bootloader to IRAM */
56 /* get the high part of our execute address */
57 ldr r7, =0xffffff00
58 and r4, pc, r7
59
60 /* Copy bootloader to safe area - 0x40000000 (IRAM) */
61 mov r5, #0x40000000
62 ldr r6, = _dataend
631:
64 cmp r5, r6
65 ldrcc r2, [r4], #4
66 strcc r2, [r5], #4
67 bcc 1b
68
69#ifndef IPOD_ARCH
70 /* For builds on targets with mi4 firmware, scramble writes data to
71 0xe0-0xeb, so jump past that.*/
72 b pad_skip
73
74.space 60*4
75
76pad_skip:
77#endif
78
79
80/* 2 - Jump both CPU and COP there */
81 ldr pc, =start_loc /* jump to the relocated start_loc: */
82
83start_loc:
84
85 /* Find out which processor we are */
86 ldr r0, =PROC_ID
87 ldr r0, [r0]
88 and r0, r0, #0xff
89 cmp r0, #0x55
90 beq cpu
91
92 /* put us (co-processor) to sleep */
93 ldr r4, =COP_CTRL
94 mov r3, #SLEEP
95 str r3, [r4]
96 ldr pc, =cop_wake_start
97
98cop_wake_start:
99#if CONFIG_CPU != PP5002
100 /* COP: Invalidate cache */
101 ldr r0, =0xf000f044
102 ldr r1, [r0]
103 orr r1, r1, #0x6
104 str r1, [r0]
105
106 ldr r0, =CACHE_CTRL
1071:
108 ldr r1, [r0]
109 tst r1, #0x8000
110 bne 1b
111#endif
112
113 ldr r0, =startup_loc
114 ldr pc, [r0]
115
116cpu:
117 /* Wait for COP to be sleeping */
118 ldr r4, =COP_STATUS
1191:
120 ldr r3, [r4]
121 ands r3, r3, #SLEEPING
122 beq 1b
123
124 /* Initialise bss section to zero */
125 ldr r2, =_edata
126 ldr r3, =_end
127 mov r4, #0
1281:
129 cmp r3, r2
130 strhi r4, [r2], #4
131 bhi 1b
132
133 /* Set up some stack and munge it with 0xdeadbeef */
134 ldr sp, =stackend
135 mov r3, sp
136 ldr r2, =stackbegin
137 ldr r4, =0xdeadbeef
1381:
139 cmp r3, r2
140 strhi r4, [r2], #4
141 bhi 1b
142
143 /* execute the loader - this will load an image to 0x10000000 */
144 bl main
145
146 ldr r1, =startup_loc
147 str r0, [r1]
148
149#if CONFIG_CPU != PP5002
150 /* Flush cache */
151 ldr r3, =0xf000f044
152 ldr r4, [r3]
153 orr r4, r4, #0x2
154 str r4, [r3]
155
156 ldr r3, =CACHE_CTRL
1571:
158 ldr r4, [r3]
159 tst r4, #0x8000
160 bne 1b
161#endif
162
163 /* Wake up the coprocessor before executing the firmware */
164 ldr r4, =COP_CTRL
165 mov r3, #WAKE
166 str r3, [r4]
167
168 mov pc, r0
169
170startup_loc:
171 .word 0x0
172
173#ifdef IPOD_ARCH
174.align 8 /* starts at 0x100 */
175.global boot_table
176boot_table:
177 /* here comes the boot table, don't move its offset */
178 .space 400
179#endif
diff --git a/firmware/target/arm/crt0-pp.S b/firmware/target/arm/crt0-pp.S
index 17b1e8a4a3..892275e411 100644
--- a/firmware/target/arm/crt0-pp.S
+++ b/firmware/target/arm/crt0-pp.S
@@ -52,15 +52,9 @@ start:
52 52
53 msr cpsr_c, #0xd3 /* enter supervisor mode, disable IRQ */ 53 msr cpsr_c, #0xd3 /* enter supervisor mode, disable IRQ */
54 54
55#ifndef BOOTLOADER
56 b pad_skip 55 b pad_skip
57 56
58#if defined(SANSA_E200) 57.space 50*4 /* (more than enough) space for exception vectors */
59/* mi4tool writes junk between 0xe0 and 0xeb. Avoid this. */
60.space 60*4 /* (more than enough) space for exception vectors */
61#else
62.space 50*4
63#endif
64 58
65pad_skip: 59pad_skip:
66#ifdef SANSA_E200 60#ifdef SANSA_E200
@@ -108,11 +102,13 @@ remap_end:
108 102
109 /* After doing the remapping, send the COP to sleep. 103 /* After doing the remapping, send the COP to sleep.
110 On wakeup it will go to cop_init */ 104 On wakeup it will go to cop_init */
105
106 /* Find out which processor we are */
111 ldr r0, =PROC_ID 107 ldr r0, =PROC_ID
112 ldr r0, [r0] 108 ldr r0, [r0]
113 and r0, r0, #0xff 109 and r0, r0, #0xff
114 cmp r0, #0x55 110 cmp r0, #0x55
115 beq 1f 111 beq cpu_init
116 112
117 /* put us (co-processor) to sleep */ 113 /* put us (co-processor) to sleep */
118 ldr r4, =COP_CTRL 114 ldr r4, =COP_CTRL
@@ -121,9 +117,15 @@ remap_end:
121 117
122 ldr pc, =cop_init 118 ldr pc, =cop_init
123 119
1241:
125 120
126#ifndef DEBUG 121cpu_init:
122 /* Wait for COP to be sleeping */
123 ldr r4, =COP_STATUS
1241:
125 ldr r3, [r4]
126 ands r3, r3, #SLEEPING
127 beq 1b
128
127 /* Copy exception handler code to address 0 */ 129 /* Copy exception handler code to address 0 */
128 ldr r2, =_vectorsstart 130 ldr r2, =_vectorsstart
129 ldr r3, =_vectorsend 131 ldr r3, =_vectorsend
@@ -133,15 +135,7 @@ remap_end:
133 ldrhi r5, [r4], #4 135 ldrhi r5, [r4], #4
134 strhi r5, [r2], #4 136 strhi r5, [r2], #4
135 bhi 1b 137 bhi 1b
136#else
137 ldr r1, =vectors
138 ldr r0, =irq_handler
139 str r0, [r1, #24]
140 ldr r0, =fiq_handler
141 str r0, [r1, #28]
142#endif
143 138
144#ifndef STUB
145 /* Zero out IBSS */ 139 /* Zero out IBSS */
146 ldr r2, =_iedata 140 ldr r2, =_iedata
147 ldr r3, =_iend 141 ldr r3, =_iend
@@ -160,8 +154,6 @@ remap_end:
160 ldrhi r5, [r2], #4 154 ldrhi r5, [r2], #4
161 strhi r5, [r3], #4 155 strhi r5, [r3], #4
162 bhi 1b 156 bhi 1b
163#endif /* !STUB */
164#endif /* !BOOTLOADER */
165 157
166 /* Initialise bss section to zero */ 158 /* Initialise bss section to zero */
167 ldr r2, =_edata 159 ldr r2, =_edata
@@ -181,90 +173,6 @@ remap_end:
181 cmp r3, r2 173 cmp r3, r2
182 strhi r4, [r2], #4 174 strhi r4, [r2], #4
183 bhi 1b 175 bhi 1b
184
185#ifdef BOOTLOADER
186 /* TODO: the high part of the address is probably dependent on CONFIG_CPU.
187 Since we tend to use ifdefs for each chipset target
188 anyway, we might as well just hardcode it here.
189 */
190
191 /* get the high part of our execute address */
192 ldr r0, =0xff000000
193 and r8, pc, r0 @ r8 is used later
194
195 /* Find out which processor we are */
196 mov r0, #PROC_ID
197 ldr r0, [r0]
198 and r0, r0, #0xff
199 cmp r0, #0x55
200 beq 1f
201
202 /* put us (co-processor) to sleep */
203 ldr r4, =COP_CTRL
204 mov r3, #SLEEP
205 str r3, [r4]
206 ldr pc, =cop_wake_start
207
208cop_wake_start:
209 /* jump the COP to startup */
210 ldr r0, =startup_loc
211 ldr pc, [r0]
212
2131:
214
215 /* get the high part of our execute address */
216 ldr r2, =0xffffff00
217 and r4, pc, r2
218
219 /* Copy bootloader to safe area - 0x40000000 */
220 mov r5, #0x40000000
221 ldr r6, = _dataend
222 sub r0, r6, r5 /* length of loader */
223 add r0, r4, r0 /* r0 points to start of loader */
2241:
225 cmp r5, r6
226 ldrcc r2, [r4], #4
227 strcc r2, [r5], #4
228 bcc 1b
229
230 ldr pc, =start_loc /* jump to the relocated start_loc: */
231
232start_loc:
233
234 /* execute the loader - this will load an image to 0x10000000 */
235 bl main
236
237 /* Wake up the coprocessor before executing the firmware */
238
239 /* save the startup address for the COP */
240 ldr r1, =startup_loc
241 str r0, [r1]
242
243 /* make sure COP is sleeping */
244 ldr r4, =COP_STATUS
2451:
246 ldr r3, [r4]
247 ands r3, r3, #SLEEPING
248 beq 1b
249
250 /* wake up COP */
251 ldr r4, =COP_CTRL
252 mov r3, #WAKE
253 str r3, [r4]
254
255 /* jump to start location */
256 mov pc, r0
257
258startup_loc:
259 .word 0x0
260
261.align 8 /* starts at 0x100 */
262.global boot_table
263boot_table:
264 /* here comes the boot table, don't move its offset */
265 .space 400
266
267#else /* BOOTLOADER */
268 176
269 /* Set up stack for IRQ mode */ 177 /* Set up stack for IRQ mode */
270 msr cpsr_c, #0xd2 178 msr cpsr_c, #0xd2
@@ -290,6 +198,21 @@ boot_table:
290 /* main() should never return */ 198 /* main() should never return */
291 199
292cop_init: 200cop_init:
201#if CONFIG_CPU != PP5002
202 /* COP: Invalidate cache */
203 ldr r0, =0xf000f044
204 ldr r1, [r0]
205 orr r1, r1, #0x6
206 str r1, [r0]
207
208 ldr r0, =0x6000c000
2091:
210 ldr r1, [r0]
211 tst r1, #0x8000
212 bne 1b
213#endif
214
215 /* Setup stack for COP */
293 ldr sp, =cop_stackend 216 ldr sp, =cop_stackend
294 mov r3, sp 217 mov r3, sp
295 ldr r2, =cop_stackbegin 218 ldr r2, =cop_stackbegin
@@ -300,6 +223,8 @@ cop_init:
300 bhi 2b 223 bhi 2b
301 224
302 ldr sp, =cop_stackend 225 ldr sp, =cop_stackend
226
227 /* Run cop_main() in apps/main.c */
303 bl cop_main 228 bl cop_main
304 229
305/* Exception handlers. Will be copied to address 0 after memory remapping */ 230/* Exception handlers. Will be copied to address 0 after memory remapping */
@@ -385,5 +310,3 @@ irq_stack:
385/* 256 words of FIQ stack */ 310/* 256 words of FIQ stack */
386 .space 256*4 311 .space 256*4
387fiq_stack: 312fiq_stack:
388
389#endif /* BOOTLOADER */