blob: 957ca34766c333baaf943c8018fa552ce64ce97d [file] [log] [blame]
Wolfgang Denkadf20a12005-09-25 01:48:28 +02001/*
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>
Detlev Zundelf1b3f2b2009-05-13 10:54:10 +020010 * Copyright (c) 2002 Gary Jennejohn <garyj@denx.de>
Wolfgang Denkadf20a12005-09-25 01:48:28 +020011 * 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
Wolfgang Denk0191e472010-10-26 14:34:52 +020033#include <asm-offsets.h>
Wolfgang Denkadf20a12005-09-25 01:48:28 +020034#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
Heiko Schocherc620af22010-09-17 13:10:51 +020086.globl _TEXT_BASE
Wolfgang Denkadf20a12005-09-25 01:48:28 +020087_TEXT_BASE:
Wolfgang Denk0708bc62010-10-07 21:51:12 +020088 .word CONFIG_SYS_TEXT_BASE /* address of _start in the linked image */
Wolfgang Denkadf20a12005-09-25 01:48:28 +020089
Wolfgang Denkadf20a12005-09-25 01:48:28 +020090/*
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
104IRQ_STACK_START:
105 .word 0x0badc0de
106
107/* IRQ stack memory (calculated at run-time) */
108.globl FIQ_STACK_START
109FIQ_STACK_START:
110 .word 0x0badc0de
111#endif
112
Heiko Schocherc620af22010-09-17 13:10:51 +0200113/* IRQ stack memory (calculated at run-time) + 8 bytes */
114.globl IRQ_STACK_START_IN
115IRQ_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
Wolfgang Denkadf20a12005-09-25 01:48:28 +0200141
142/*
143 * the actual reset code
144 */
Heiko Schocherc620af22010-09-17 13:10:51 +0200145
146reset:
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 */
164call_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
179relocate_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 */
186stack_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
Heiko Schocherc620af22010-09-17 13:10:51 +0200197copy_loop:
198 ldmia r0!, {r9-r10} /* copy from source address [r0] */
199 stmia r6!, {r9-r10} /* copy to target address [r1] */
Albert Aribaud0668d162010-10-05 16:06:39 +0200200 cmp r0, r2 /* until source end address [r2] */
201 blo copy_loop
Heiko Schocherc620af22010-09-17 13:10:51 +0200202
203#ifndef CONFIG_PRELOADER
204 /* fix got entries */
205 ldr r1, _TEXT_BASE /* Text base */
206 mov r0, r7 /* reloc addr */
207 ldr r2, _got_start /* addr in Flash */
208 ldr r3, _got_end /* addr in Flash */
209 sub r3, r3, r1
210 add r3, r3, r0
211 sub r2, r2, r1
212 add r2, r2, r0
213
214fixloop:
215 ldr r4, [r2]
216 sub r4, r4, r1
217 add r4, r4, r0
218 str r4, [r2]
219 add r2, r2, #4
220 cmp r2, r3
Wolfgang Denk98dd07c2010-10-23 23:22:38 +0200221 blo fixloop
Heiko Schocherc620af22010-09-17 13:10:51 +0200222#endif
Heiko Schocherc620af22010-09-17 13:10:51 +0200223
224clear_bss:
225#ifndef CONFIG_PRELOADER
226 ldr r0, _bss_start
227 ldr r1, _bss_end
228 ldr r3, _TEXT_BASE /* Text base */
229 mov r4, r7 /* reloc addr */
230 sub r0, r0, r3
231 add r0, r0, r4
232 sub r1, r1, r3
233 add r1, r1, r4
234 mov r2, #0x00000000 /* clear */
235
236clbss_l:str r2, [r0] /* clear loop... */
237 add r0, r0, #4
238 cmp r0, r1
239 bne clbss_l
240
241 bl coloured_LED_init
242 bl red_LED_on
243#endif
244
245/*
246 * We are done. Do not return, instead branch to second part of board
247 * initialization, now running from RAM.
248 */
249 ldr r0, _TEXT_BASE
250 ldr r2, _board_init_r
251 sub r2, r2, r0
252 add r2, r2, r7 /* position from board_init_r in RAM */
253 /* setup parameters for board_init_r */
254 mov r0, r5 /* gd_t */
255 mov r1, r7 /* dest_addr */
256 /* jump to it ... */
257 mov lr, r2
258 mov pc, lr
259
260_board_init_r: .word board_init_r
261
Heiko Schocherc620af22010-09-17 13:10:51 +0200262/*
Wolfgang Denkadf20a12005-09-25 01:48:28 +0200263 *************************************************************************
264 *
265 * CPU_init_critical registers
266 *
267 * setup important registers
268 * setup memory timing
269 *
270 *************************************************************************
271 */
272
Jean-Christophe PLAGNIOL-VILLARD314b7282009-05-15 23:45:20 +0200273#ifndef CONFIG_SKIP_LOWLEVEL_INIT
Wolfgang Denkadf20a12005-09-25 01:48:28 +0200274cpu_init_crit:
275 /* arm_int_generic assumes the ARM boot monitor, or user software,
276 * has initialized the platform
277 */
278 mov pc, lr /* back to my caller */
Jean-Christophe PLAGNIOL-VILLARD314b7282009-05-15 23:45:20 +0200279#endif
Wolfgang Denkadf20a12005-09-25 01:48:28 +0200280/*
281 *************************************************************************
282 *
283 * Interrupt handling
284 *
285 *************************************************************************
286 */
287
288@
289@ IRQ stack frame.
290@
291#define S_FRAME_SIZE 72
292
293#define S_OLD_R0 68
294#define S_PSR 64
295#define S_PC 60
296#define S_LR 56
297#define S_SP 52
298
299#define S_IP 48
300#define S_FP 44
301#define S_R10 40
302#define S_R9 36
303#define S_R8 32
304#define S_R7 28
305#define S_R6 24
306#define S_R5 20
307#define S_R4 16
308#define S_R3 12
309#define S_R2 8
310#define S_R1 4
311#define S_R0 0
312
313#define MODE_SVC 0x13
314#define I_BIT 0x80
315
316/*
317 * use bad_save_user_regs for abort/prefetch/undef/swi ...
318 * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling
319 */
320
321 .macro bad_save_user_regs
322 @ carve out a frame on current user stack
323 sub sp, sp, #S_FRAME_SIZE
324 stmia sp, {r0 - r12} @ Save user registers (now in svc mode) r0-r12
325
Heiko Schocherc620af22010-09-17 13:10:51 +0200326 ldr r2, IRQ_STACK_START_IN
Wolfgang Denkadf20a12005-09-25 01:48:28 +0200327 @ get values for "aborted" pc and cpsr (into parm regs)
328 ldmia r2, {r2 - r3}
329 add r0, sp, #S_FRAME_SIZE @ grab pointer to old stack
330 add r5, sp, #S_SP
331 mov r1, lr
332 stmia r5, {r0 - r3} @ save sp_SVC, lr_SVC, pc, cpsr
333 mov r0, sp @ save current stack into r0 (param register)
334 .endm
335
336 .macro irq_save_user_regs
337 sub sp, sp, #S_FRAME_SIZE
338 stmia sp, {r0 - r12} @ Calling r0-r12
339 @ !!!! R8 NEEDS to be saved !!!! a reserved stack spot would be good.
340 add r8, sp, #S_PC
341 stmdb r8, {sp, lr}^ @ Calling SP, LR
342 str lr, [r8, #0] @ Save calling PC
343 mrs r6, spsr
344 str r6, [r8, #4] @ Save CPSR
345 str r0, [r8, #8] @ Save OLD_R0
346 mov r0, sp
347 .endm
348
349 .macro irq_restore_user_regs
350 ldmia sp, {r0 - lr}^ @ Calling r0 - lr
351 mov r0, r0
352 ldr lr, [sp, #S_PC] @ Get PC
353 add sp, sp, #S_FRAME_SIZE
354 subs pc, lr, #4 @ return & move spsr_svc into cpsr
355 .endm
356
357 .macro get_bad_stack
Heiko Schocherc620af22010-09-17 13:10:51 +0200358 ldr r13, IRQ_STACK_START_IN @ setup our mode stack
Wolfgang Denkadf20a12005-09-25 01:48:28 +0200359
360 str lr, [r13] @ save caller lr in position 0 of saved stack
361 mrs lr, spsr @ get the spsr
362 str lr, [r13, #4] @ save spsr in position 1 of saved stack
363 mov r13, #MODE_SVC @ prepare SVC-Mode
364 @ msr spsr_c, r13
365 msr spsr, r13 @ switch modes, make sure moves will execute
366 mov lr, pc @ capture return pc
367 movs pc, lr @ jump to next instruction & switch modes.
368 .endm
369
370 .macro get_irq_stack @ setup IRQ stack
371 ldr sp, IRQ_STACK_START
372 .endm
373
374 .macro get_fiq_stack @ setup FIQ stack
375 ldr sp, FIQ_STACK_START
376 .endm
377
378/*
379 * exception handlers
380 */
381 .align 5
382.globl undefined_instruction
383undefined_instruction:
384 get_bad_stack
385 bad_save_user_regs
386 bl do_undefined_instruction
387
388 .align 5
389.globl software_interrupt
390software_interrupt:
391 get_bad_stack
392 bad_save_user_regs
393 bl do_software_interrupt
394
395 .align 5
396.globl prefetch_abort
397prefetch_abort:
398 get_bad_stack
399 bad_save_user_regs
400 bl do_prefetch_abort
401
402 .align 5
403.globl data_abort
404data_abort:
405 get_bad_stack
406 bad_save_user_regs
407 bl do_data_abort
408
409 .align 5
410.globl not_used
411not_used:
412 get_bad_stack
413 bad_save_user_regs
414 bl do_not_used
415
416#ifdef CONFIG_USE_IRQ
417 .align 5
418.globl irq
419irq:
420 get_irq_stack
421 irq_save_user_regs
Wolfgang Denka1be4762008-05-20 16:00:29 +0200422 bl do_irq
Wolfgang Denkadf20a12005-09-25 01:48:28 +0200423 irq_restore_user_regs
424
425 .align 5
426.globl fiq
427fiq:
428 get_fiq_stack
429 /* someone ought to write a more effiction fiq_save_user_regs */
430 irq_save_user_regs
Wolfgang Denka1be4762008-05-20 16:00:29 +0200431 bl do_fiq
Wolfgang Denkadf20a12005-09-25 01:48:28 +0200432 irq_restore_user_regs
433
434#else
435
436 .align 5
Wolfgang Denkc856ccc2005-09-25 02:00:47 +0200437.globl irq
Wolfgang Denkadf20a12005-09-25 01:48:28 +0200438irq:
439 get_bad_stack
440 bad_save_user_regs
441 bl do_irq
442
443 .align 5
Wolfgang Denkc856ccc2005-09-25 02:00:47 +0200444.globl fiq
Wolfgang Denkadf20a12005-09-25 01:48:28 +0200445fiq:
446 get_bad_stack
447 bad_save_user_regs
448 bl do_fiq
449
450#endif