diff options
Diffstat (limited to 'firmware/target/arm/crt0-pp.S')
-rw-r--r-- | firmware/target/arm/crt0-pp.S | 135 |
1 files changed, 29 insertions, 106 deletions
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 | ||
65 | pad_skip: | 59 | pad_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 | ||
124 | 1: | ||
125 | 120 | ||
126 | #ifndef DEBUG | 121 | cpu_init: |
122 | /* Wait for COP to be sleeping */ | ||
123 | ldr r4, =COP_STATUS | ||
124 | 1: | ||
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 | |||
208 | cop_wake_start: | ||
209 | /* jump the COP to startup */ | ||
210 | ldr r0, =startup_loc | ||
211 | ldr pc, [r0] | ||
212 | |||
213 | 1: | ||
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 */ | ||
224 | 1: | ||
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 | |||
232 | start_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 | ||
245 | 1: | ||
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 | |||
258 | startup_loc: | ||
259 | .word 0x0 | ||
260 | |||
261 | .align 8 /* starts at 0x100 */ | ||
262 | .global boot_table | ||
263 | boot_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 | ||
292 | cop_init: | 200 | cop_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 | ||
209 | 1: | ||
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 |
387 | fiq_stack: | 312 | fiq_stack: |
388 | |||
389 | #endif /* BOOTLOADER */ | ||