]> git.ipfire.org Git - people/ms/u-boot.git/blob - arch/arm/cpu/arm_intcm/start.S
Drop support for CONFIG_SYS_ARM_WITHOUT_RELOC
[people/ms/u-boot.git] / arch / arm / cpu / arm_intcm / start.S
1 /*
2 * armboot - Startup Code for ARM926EJS CPU-core
3 *
4 * Copyright (c) 2003 Texas Instruments
5 *
6 * ----- Adapted for OMAP1610 OMAP730 from ARM925t code ------
7 *
8 * Copyright (c) 2001 Marius Gröger <mag@sysgo.de>
9 * Copyright (c) 2002 Alex Züpke <azu@sysgo.de>
10 * Copyright (c) 2002 Gary Jennejohn <garyj@denx.de>
11 * Copyright (c) 2003 Richard Woodruff <r-woodruff2@ti.com>
12 * Copyright (c) 2003 Kshitij <kshitij@ti.com>
13 *
14 * See file CREDITS for list of people who contributed to this
15 * project.
16 *
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License as
19 * published by the Free Software Foundation; either version 2 of
20 * the License, or (at your option) any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
30 * MA 02111-1307 USA
31 */
32
33 #include <asm-offsets.h>
34 #include <config.h>
35 #include <version.h>
36
37 /*
38 *************************************************************************
39 *
40 * Jump vector table
41 *
42 *************************************************************************
43 */
44
45 .globl _start
46 _start:
47 b reset
48 ldr pc, _undefined_instruction
49 ldr pc, _software_interrupt
50 ldr pc, _prefetch_abort
51 ldr pc, _data_abort
52 ldr pc, _not_used
53 ldr pc, _irq
54 ldr pc, _fiq
55
56 _undefined_instruction:
57 .word undefined_instruction
58 _software_interrupt:
59 .word software_interrupt
60 _prefetch_abort:
61 .word prefetch_abort
62 _data_abort:
63 .word data_abort
64 _not_used:
65 .word not_used
66 _irq:
67 .word irq
68 _fiq:
69 .word fiq
70
71 .balignl 16,0xdeadbeef
72
73 /*
74 *************************************************************************
75 *
76 * Startup Code (reset vector)
77 *
78 * do important init only if we don't start from memory!
79 * setup memory and board specific bits prior to relocation.
80 * relocate armboot to ram
81 * setup stack
82 *
83 *************************************************************************
84 */
85
86 .globl _TEXT_BASE
87 _TEXT_BASE:
88 .word CONFIG_SYS_TEXT_BASE /* address of _start in the linked image */
89
90 /*
91 * These are defined in the board-specific linker script.
92 */
93 .globl _bss_start
94 _bss_start:
95 .word __bss_start
96
97 .globl _bss_end
98 _bss_end:
99 .word _end
100
101 #ifdef CONFIG_USE_IRQ
102 /* IRQ stack memory (calculated at run-time) */
103 .globl IRQ_STACK_START
104 IRQ_STACK_START:
105 .word 0x0badc0de
106
107 /* IRQ stack memory (calculated at run-time) */
108 .globl FIQ_STACK_START
109 FIQ_STACK_START:
110 .word 0x0badc0de
111 #endif
112
113 /* IRQ stack memory (calculated at run-time) + 8 bytes */
114 .globl IRQ_STACK_START_IN
115 IRQ_STACK_START_IN:
116 .word 0x0badc0de
117
118 .globl _datarel_start
119 _datarel_start:
120 .word __datarel_start
121
122 .globl _datarelrolocal_start
123 _datarelrolocal_start:
124 .word __datarelrolocal_start
125
126 .globl _datarellocal_start
127 _datarellocal_start:
128 .word __datarellocal_start
129
130 .globl _datarelro_start
131 _datarelro_start:
132 .word __datarelro_start
133
134 .globl _got_start
135 _got_start:
136 .word __got_start
137
138 .globl _got_end
139 _got_end:
140 .word __got_end
141
142 /*
143 * the actual reset code
144 */
145
146 reset:
147 /*
148 * set the cpu to SVC32 mode
149 */
150 mrs r0,cpsr
151 bic r0,r0,#0x1f
152 orr r0,r0,#0xd3
153 msr cpsr,r0
154
155 /*
156 * we do sys-critical inits only at reboot,
157 * not when booting from ram!
158 */
159 #ifndef CONFIG_SKIP_LOWLEVEL_INIT
160 bl cpu_init_crit
161 #endif
162
163 /* Set stackpointer in internal RAM to call board_init_f */
164 call_board_init_f:
165 ldr sp, =(CONFIG_SYS_INIT_SP_ADDR)
166 ldr r0,=0x00000000
167 bl board_init_f
168
169 /*------------------------------------------------------------------------------*/
170
171 /*
172 * void relocate_code (addr_sp, gd, addr_moni)
173 *
174 * This "function" does not return, instead it continues in RAM
175 * after relocating the monitor code.
176 *
177 */
178 .globl relocate_code
179 relocate_code:
180 mov r4, r0 /* save addr_sp */
181 mov r5, r1 /* save addr of gd */
182 mov r6, r2 /* save addr of destination */
183 mov r7, r2 /* save addr of destination */
184
185 /* Set up the stack */
186 stack_setup:
187 mov sp, r4
188
189 adr r0, _start
190 ldr r2, _TEXT_BASE
191 ldr r3, _bss_start
192 sub r2, r3, r2 /* r2 <- size of armboot */
193 add r2, r0, r2 /* r2 <- source end address */
194 cmp r0, r6
195 beq clear_bss
196
197 #ifndef CONFIG_SKIP_RELOCATE_UBOOT
198 copy_loop:
199 ldmia r0!, {r9-r10} /* copy from source address [r0] */
200 stmia r6!, {r9-r10} /* copy to target address [r1] */
201 cmp r0, r2 /* until source end address [r2] */
202 blo copy_loop
203
204 #ifndef CONFIG_PRELOADER
205 /* fix got entries */
206 ldr r1, _TEXT_BASE /* Text base */
207 mov r0, r7 /* reloc addr */
208 ldr r2, _got_start /* addr in Flash */
209 ldr r3, _got_end /* addr in Flash */
210 sub r3, r3, r1
211 add r3, r3, r0
212 sub r2, r2, r1
213 add r2, r2, r0
214
215 fixloop:
216 ldr r4, [r2]
217 sub r4, r4, r1
218 add r4, r4, r0
219 str r4, [r2]
220 add r2, r2, #4
221 cmp r2, r3
222 blo fixloop
223 #endif
224 #endif /* #ifndef CONFIG_SKIP_RELOCATE_UBOOT */
225
226 clear_bss:
227 #ifndef CONFIG_PRELOADER
228 ldr r0, _bss_start
229 ldr r1, _bss_end
230 ldr r3, _TEXT_BASE /* Text base */
231 mov r4, r7 /* reloc addr */
232 sub r0, r0, r3
233 add r0, r0, r4
234 sub r1, r1, r3
235 add r1, r1, r4
236 mov r2, #0x00000000 /* clear */
237
238 clbss_l:str r2, [r0] /* clear loop... */
239 add r0, r0, #4
240 cmp r0, r1
241 bne clbss_l
242
243 bl coloured_LED_init
244 bl red_LED_on
245 #endif
246
247 /*
248 * We are done. Do not return, instead branch to second part of board
249 * initialization, now running from RAM.
250 */
251 ldr r0, _TEXT_BASE
252 ldr r2, _board_init_r
253 sub r2, r2, r0
254 add r2, r2, r7 /* position from board_init_r in RAM */
255 /* setup parameters for board_init_r */
256 mov r0, r5 /* gd_t */
257 mov r1, r7 /* dest_addr */
258 /* jump to it ... */
259 mov lr, r2
260 mov pc, lr
261
262 _board_init_r: .word board_init_r
263
264 /*
265 *************************************************************************
266 *
267 * CPU_init_critical registers
268 *
269 * setup important registers
270 * setup memory timing
271 *
272 *************************************************************************
273 */
274
275 #ifndef CONFIG_SKIP_LOWLEVEL_INIT
276 cpu_init_crit:
277 /* arm_int_generic assumes the ARM boot monitor, or user software,
278 * has initialized the platform
279 */
280 mov pc, lr /* back to my caller */
281 #endif
282 /*
283 *************************************************************************
284 *
285 * Interrupt handling
286 *
287 *************************************************************************
288 */
289
290 @
291 @ IRQ stack frame.
292 @
293 #define S_FRAME_SIZE 72
294
295 #define S_OLD_R0 68
296 #define S_PSR 64
297 #define S_PC 60
298 #define S_LR 56
299 #define S_SP 52
300
301 #define S_IP 48
302 #define S_FP 44
303 #define S_R10 40
304 #define S_R9 36
305 #define S_R8 32
306 #define S_R7 28
307 #define S_R6 24
308 #define S_R5 20
309 #define S_R4 16
310 #define S_R3 12
311 #define S_R2 8
312 #define S_R1 4
313 #define S_R0 0
314
315 #define MODE_SVC 0x13
316 #define I_BIT 0x80
317
318 /*
319 * use bad_save_user_regs for abort/prefetch/undef/swi ...
320 * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling
321 */
322
323 .macro bad_save_user_regs
324 @ carve out a frame on current user stack
325 sub sp, sp, #S_FRAME_SIZE
326 stmia sp, {r0 - r12} @ Save user registers (now in svc mode) r0-r12
327
328 ldr r2, IRQ_STACK_START_IN
329 @ get values for "aborted" pc and cpsr (into parm regs)
330 ldmia r2, {r2 - r3}
331 add r0, sp, #S_FRAME_SIZE @ grab pointer to old stack
332 add r5, sp, #S_SP
333 mov r1, lr
334 stmia r5, {r0 - r3} @ save sp_SVC, lr_SVC, pc, cpsr
335 mov r0, sp @ save current stack into r0 (param register)
336 .endm
337
338 .macro irq_save_user_regs
339 sub sp, sp, #S_FRAME_SIZE
340 stmia sp, {r0 - r12} @ Calling r0-r12
341 @ !!!! R8 NEEDS to be saved !!!! a reserved stack spot would be good.
342 add r8, sp, #S_PC
343 stmdb r8, {sp, lr}^ @ Calling SP, LR
344 str lr, [r8, #0] @ Save calling PC
345 mrs r6, spsr
346 str r6, [r8, #4] @ Save CPSR
347 str r0, [r8, #8] @ Save OLD_R0
348 mov r0, sp
349 .endm
350
351 .macro irq_restore_user_regs
352 ldmia sp, {r0 - lr}^ @ Calling r0 - lr
353 mov r0, r0
354 ldr lr, [sp, #S_PC] @ Get PC
355 add sp, sp, #S_FRAME_SIZE
356 subs pc, lr, #4 @ return & move spsr_svc into cpsr
357 .endm
358
359 .macro get_bad_stack
360 ldr r13, IRQ_STACK_START_IN @ setup our mode stack
361
362 str lr, [r13] @ save caller lr in position 0 of saved stack
363 mrs lr, spsr @ get the spsr
364 str lr, [r13, #4] @ save spsr in position 1 of saved stack
365 mov r13, #MODE_SVC @ prepare SVC-Mode
366 @ msr spsr_c, r13
367 msr spsr, r13 @ switch modes, make sure moves will execute
368 mov lr, pc @ capture return pc
369 movs pc, lr @ jump to next instruction & switch modes.
370 .endm
371
372 .macro get_irq_stack @ setup IRQ stack
373 ldr sp, IRQ_STACK_START
374 .endm
375
376 .macro get_fiq_stack @ setup FIQ stack
377 ldr sp, FIQ_STACK_START
378 .endm
379
380 /*
381 * exception handlers
382 */
383 .align 5
384 .globl undefined_instruction
385 undefined_instruction:
386 get_bad_stack
387 bad_save_user_regs
388 bl do_undefined_instruction
389
390 .align 5
391 .globl software_interrupt
392 software_interrupt:
393 get_bad_stack
394 bad_save_user_regs
395 bl do_software_interrupt
396
397 .align 5
398 .globl prefetch_abort
399 prefetch_abort:
400 get_bad_stack
401 bad_save_user_regs
402 bl do_prefetch_abort
403
404 .align 5
405 .globl data_abort
406 data_abort:
407 get_bad_stack
408 bad_save_user_regs
409 bl do_data_abort
410
411 .align 5
412 .globl not_used
413 not_used:
414 get_bad_stack
415 bad_save_user_regs
416 bl do_not_used
417
418 #ifdef CONFIG_USE_IRQ
419 .align 5
420 .globl irq
421 irq:
422 get_irq_stack
423 irq_save_user_regs
424 bl do_irq
425 irq_restore_user_regs
426
427 .align 5
428 .globl fiq
429 fiq:
430 get_fiq_stack
431 /* someone ought to write a more effiction fiq_save_user_regs */
432 irq_save_user_regs
433 bl do_fiq
434 irq_restore_user_regs
435
436 #else
437
438 .align 5
439 .globl irq
440 irq:
441 get_bad_stack
442 bad_save_user_regs
443 bl do_irq
444
445 .align 5
446 .globl fiq
447 fiq:
448 get_bad_stack
449 bad_save_user_regs
450 bl do_fiq
451
452 #endif