blob: 07d0c859cb839a975ab44429f20ee706532c3ee5 [file] [log] [blame]
wdenk8ed96042005-01-09 23:16:25 +00001/*
2 * armboot - Startup Code for OMP2420/ARM1136 CPU-core
3 *
wdenk082acfd2005-01-10 00:01:04 +00004 * Copyright (c) 2004 Texas Instruments <r-woodruff2@ti.com>
wdenk8ed96042005-01-09 23:16:25 +00005 *
6 * Copyright (c) 2001 Marius Gröger <mag@sysgo.de>
7 * Copyright (c) 2002 Alex Züpke <azu@sysgo.de>
Detlev Zundel792a09e2009-05-13 10:54:10 +02008 * Copyright (c) 2002 Gary Jennejohn <garyj@denx.de>
wdenk8ed96042005-01-09 23:16:25 +00009 * Copyright (c) 2003 Richard Woodruff <r-woodruff2@ti.com>
10 * Copyright (c) 2003 Kshitij <kshitij@ti.com>
11 *
12 * See file CREDITS for list of people who contributed to this
13 * project.
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License as
17 * published by the Free Software Foundation; either version 2 of
18 * the License, or (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
wdenk082acfd2005-01-10 00:01:04 +000022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wdenk8ed96042005-01-09 23:16:25 +000023 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 * MA 02111-1307 USA
29 */
30
Wolfgang Denk25ddd1f2010-10-26 14:34:52 +020031#include <asm-offsets.h>
wdenk8ed96042005-01-09 23:16:25 +000032#include <config.h>
33#include <version.h>
wdenk8ed96042005-01-09 23:16:25 +000034.globl _start
wdenk082acfd2005-01-10 00:01:04 +000035_start: b reset
Magnus Liljadf812382009-06-13 20:50:00 +020036#ifdef CONFIG_PRELOADER
Kyungmin Park751b9b52008-01-17 16:43:25 +090037 ldr pc, _hang
38 ldr pc, _hang
39 ldr pc, _hang
40 ldr pc, _hang
41 ldr pc, _hang
42 ldr pc, _hang
43 ldr pc, _hang
44
45_hang:
46 .word do_hang
47 .word 0x12345678
48 .word 0x12345678
49 .word 0x12345678
50 .word 0x12345678
51 .word 0x12345678
52 .word 0x12345678
53 .word 0x12345678 /* now 16*4=64 */
54#else
wdenk8ed96042005-01-09 23:16:25 +000055 ldr pc, _undefined_instruction
56 ldr pc, _software_interrupt
57 ldr pc, _prefetch_abort
58 ldr pc, _data_abort
59 ldr pc, _not_used
60 ldr pc, _irq
61 ldr pc, _fiq
62
wdenk082acfd2005-01-10 00:01:04 +000063_undefined_instruction: .word undefined_instruction
wdenk8ed96042005-01-09 23:16:25 +000064_software_interrupt: .word software_interrupt
65_prefetch_abort: .word prefetch_abort
66_data_abort: .word data_abort
67_not_used: .word not_used
68_irq: .word irq
69_fiq: .word fiq
wdenk082acfd2005-01-10 00:01:04 +000070_pad: .word 0x12345678 /* now 16*4=64 */
Magnus Liljadf812382009-06-13 20:50:00 +020071#endif /* CONFIG_PRELOADER */
wdenk8ed96042005-01-09 23:16:25 +000072.global _end_vect
73_end_vect:
74
75 .balignl 16,0xdeadbeef
76/*
77 *************************************************************************
78 *
79 * Startup Code (reset vector)
80 *
81 * do important init only if we don't start from memory!
82 * setup Memory and board specific bits prior to relocation.
83 * relocate armboot to ram
84 * setup stack
85 *
86 *************************************************************************
87 */
88
Heiko Schochere48b7c02010-09-17 13:10:40 +020089.globl _TEXT_BASE
wdenk8ed96042005-01-09 23:16:25 +000090_TEXT_BASE:
Wolfgang Denk14d0a022010-10-07 21:51:12 +020091 .word CONFIG_SYS_TEXT_BASE
wdenk8ed96042005-01-09 23:16:25 +000092
wdenk8ed96042005-01-09 23:16:25 +000093/*
94 * These are defined in the board-specific linker script.
Heiko Schocherbafe7432010-10-13 07:57:14 +020095 * Subtracting _start from them lets the linker put their
96 * relative position in the executable instead of leaving
97 * them null.
wdenk8ed96042005-01-09 23:16:25 +000098 */
Heiko Schocherbafe7432010-10-13 07:57:14 +020099.globl _bss_start_ofs
100_bss_start_ofs:
101 .word __bss_start - _start
wdenk8ed96042005-01-09 23:16:25 +0000102
Heiko Schocherbafe7432010-10-13 07:57:14 +0200103.globl _bss_end_ofs
104_bss_end_ofs:
105 .word _end - _start
wdenk8ed96042005-01-09 23:16:25 +0000106
Heiko Schocherbafe7432010-10-13 07:57:14 +0200107.globl _datarel_start_ofs
108_datarel_start_ofs:
109 .word __datarel_start - _start
Heiko Schochere48b7c02010-09-17 13:10:40 +0200110
Heiko Schocherbafe7432010-10-13 07:57:14 +0200111.globl _datarelrolocal_start_ofs
112_datarelrolocal_start_ofs:
113 .word __datarelrolocal_start - _start
Heiko Schochere48b7c02010-09-17 13:10:40 +0200114
Heiko Schocherbafe7432010-10-13 07:57:14 +0200115.globl _datarellocal_start_ofs
116_datarellocal_start_ofs:
117 .word __datarellocal_start - _start
Heiko Schochere48b7c02010-09-17 13:10:40 +0200118
Heiko Schocherbafe7432010-10-13 07:57:14 +0200119.globl _datarelro_start_ofs
120_datarelro_start_ofs:
121 .word __datarelro_start - _start
Heiko Schochere48b7c02010-09-17 13:10:40 +0200122
wdenk8ed96042005-01-09 23:16:25 +0000123#ifdef CONFIG_USE_IRQ
124/* IRQ stack memory (calculated at run-time) */
125.globl IRQ_STACK_START
126IRQ_STACK_START:
127 .word 0x0badc0de
128
129/* IRQ stack memory (calculated at run-time) */
130.globl FIQ_STACK_START
131FIQ_STACK_START:
132 .word 0x0badc0de
133#endif
134
Heiko Schochere48b7c02010-09-17 13:10:40 +0200135#if !defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
136/* IRQ stack memory (calculated at run-time) + 8 bytes */
137.globl IRQ_STACK_START_IN
138IRQ_STACK_START_IN:
139 .word 0x0badc0de
140#endif
141
142#if !defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
143/*
144 * the actual reset code
145 */
146
147reset:
148 /*
149 * set the cpu to SVC32 mode
150 */
151 mrs r0,cpsr
152 bic r0,r0,#0x1f
153 orr r0,r0,#0xd3
154 msr cpsr,r0
155
156#ifdef CONFIG_OMAP2420H4
157 /* Copy vectors to mask ROM indirect addr */
158 adr r0, _start /* r0 <- current position of code */
159 add r0, r0, #4 /* skip reset vector */
160 mov r2, #64 /* r2 <- size to copy */
161 add r2, r0, r2 /* r2 <- source end address */
162 mov r1, #SRAM_OFFSET0 /* build vect addr */
163 mov r3, #SRAM_OFFSET1
164 add r1, r1, r3
165 mov r3, #SRAM_OFFSET2
166 add r1, r1, r3
167next:
168 ldmia r0!, {r3-r10} /* copy from source address [r0] */
169 stmia r1!, {r3-r10} /* copy to target address [r1] */
170 cmp r0, r2 /* until source end address [r2] */
171 bne next /* loop until equal */
172 bl cpy_clk_code /* put dpll adjust code behind vectors */
173#endif
174 /* the mask ROM code should have PLL and others stable */
175#ifndef CONFIG_SKIP_LOWLEVEL_INIT
176 bl cpu_init_crit
177#endif
178
179/* Set stackpointer in internal RAM to call board_init_f */
180call_board_init_f:
181 ldr sp, =(CONFIG_SYS_INIT_SP_ADDR)
182 ldr r0,=0x00000000
183
184#ifdef CONFIG_NAND_SPL
185 bl nand_boot
186#else
187#ifdef CONFIG_ONENAND_IPL
188 bl start_oneboot
189#else
190 bl board_init_f
191#endif /* CONFIG_ONENAND_IPL */
192#endif /* CONFIG_NAND_SPL */
193
194/*------------------------------------------------------------------------------*/
195
196/*
197 * void relocate_code (addr_sp, gd, addr_moni)
198 *
199 * This "function" does not return, instead it continues in RAM
200 * after relocating the monitor code.
201 *
202 */
203 .globl relocate_code
204relocate_code:
205 mov r4, r0 /* save addr_sp */
206 mov r5, r1 /* save addr of gd */
207 mov r6, r2 /* save addr of destination */
208 mov r7, r2 /* save addr of destination */
209
210 /* Set up the stack */
211stack_setup:
212 mov sp, r4
213
214 adr r0, _start
215 ldr r2, _TEXT_BASE
Heiko Schocherbafe7432010-10-13 07:57:14 +0200216 ldr r3, _bss_start_ofs
217 add r2, r0, r3 /* r2 <- source end address */
Heiko Schochere48b7c02010-09-17 13:10:40 +0200218 cmp r0, r6
219 beq clear_bss
220
221#ifndef CONFIG_SKIP_RELOCATE_UBOOT
222copy_loop:
223 ldmia r0!, {r9-r10} /* copy from source address [r0] */
224 stmia r6!, {r9-r10} /* copy to target address [r1] */
Albert Aribaudda90d4c2010-10-05 16:06:39 +0200225 cmp r0, r2 /* until source end address [r2] */
226 blo copy_loop
Heiko Schochere48b7c02010-09-17 13:10:40 +0200227
228#ifndef CONFIG_PRELOADER
Heiko Schocherbafe7432010-10-13 07:57:14 +0200229 /*
230 * fix .rel.dyn relocations
231 */
232 ldr r0, _TEXT_BASE /* r0 <- Text base */
233 sub r9, r7, r0 /* r9 <- relocation offset */
234 ldr r10, _dynsym_start_ofs /* r10 <- sym table ofs */
235 add r10, r10, r0 /* r10 <- sym table in FLASH */
236 ldr r2, _rel_dyn_start_ofs /* r2 <- rel dyn start ofs */
237 add r2, r2, r0 /* r2 <- rel dyn start in FLASH */
238 ldr r3, _rel_dyn_end_ofs /* r3 <- rel dyn end ofs */
239 add r3, r3, r0 /* r3 <- rel dyn end in FLASH */
Heiko Schochere48b7c02010-09-17 13:10:40 +0200240fixloop:
Gray Remlin8c0c2b92010-10-24 16:18:31 +0100241 ldr r0, [r2] /* r0 <- location to fix up, IN FLASH! */
242 add r0, r0, r9 /* r0 <- location to fix up in RAM */
Heiko Schocherbafe7432010-10-13 07:57:14 +0200243 ldr r1, [r2, #4]
244 and r8, r1, #0xff
Gray Remlin8c0c2b92010-10-24 16:18:31 +0100245 cmp r8, #23 /* relative fixup? */
Heiko Schocherbafe7432010-10-13 07:57:14 +0200246 beq fixrel
Gray Remlin8c0c2b92010-10-24 16:18:31 +0100247 cmp r8, #2 /* absolute fixup? */
Heiko Schocherbafe7432010-10-13 07:57:14 +0200248 beq fixabs
249 /* ignore unknown type of fixup */
250 b fixnext
251fixabs:
252 /* absolute fix: set location to (offset) symbol value */
253 mov r1, r1, LSR #4 /* r1 <- symbol index in .dynsym */
254 add r1, r10, r1 /* r1 <- address of symbol in table */
255 ldr r1, [r1, #4] /* r1 <- symbol value */
256 add r1, r9 /* r1 <- relocated sym addr */
257 b fixnext
258fixrel:
259 /* relative fix: increase location by offset */
260 ldr r1, [r0]
261 add r1, r1, r9
262fixnext:
263 str r1, [r0]
Gray Remlin8c0c2b92010-10-24 16:18:31 +0100264 add r2, r2, #8 /* each rel.dyn entry is 8 bytes */
Heiko Schochere48b7c02010-09-17 13:10:40 +0200265 cmp r2, r3
Heiko Schocherbafe7432010-10-13 07:57:14 +0200266 ble fixloop
Heiko Schochere48b7c02010-09-17 13:10:40 +0200267#endif
268#endif /* #ifndef CONFIG_SKIP_RELOCATE_UBOOT */
269
270clear_bss:
271#ifndef CONFIG_PRELOADER
Heiko Schocherbafe7432010-10-13 07:57:14 +0200272 ldr r0, _bss_start_ofs
273 ldr r1, _bss_end_ofs
Heiko Schochere48b7c02010-09-17 13:10:40 +0200274 ldr r3, _TEXT_BASE /* Text base */
275 mov r4, r7 /* reloc addr */
Heiko Schochere48b7c02010-09-17 13:10:40 +0200276 add r0, r0, r4
Heiko Schochere48b7c02010-09-17 13:10:40 +0200277 add r1, r1, r4
278 mov r2, #0x00000000 /* clear */
279
280clbss_l:str r2, [r0] /* clear loop... */
281 add r0, r0, #4
282 cmp r0, r1
283 bne clbss_l
284#endif /* #ifndef CONFIG_PRELOADER */
285
286/*
287 * We are done. Do not return, instead branch to second part of board
288 * initialization, now running from RAM.
289 */
290#ifdef CONFIG_NAND_SPL
Heiko Schocherbafe7432010-10-13 07:57:14 +0200291 ldr r0, _nand_boot_ofs
292 adr r1, _start
293 add pc, r0, r1
294_nand_boot_ofs
295 : .word nand_boot - _start
Heiko Schochere48b7c02010-09-17 13:10:40 +0200296#else
297jump_2_ram:
Heiko Schocherbafe7432010-10-13 07:57:14 +0200298 ldr r0, _board_init_r_ofs
299 adr r1, _start
300 add r0, r0, r1
301 add lr, r0, r9
Heiko Schochere48b7c02010-09-17 13:10:40 +0200302 /* setup parameters for board_init_r */
303 mov r0, r5 /* gd_t */
304 mov r1, r7 /* dest_addr */
305 /* jump to it ... */
Heiko Schochere48b7c02010-09-17 13:10:40 +0200306 mov pc, lr
307
Heiko Schocherbafe7432010-10-13 07:57:14 +0200308_board_init_r_ofs:
309 .word board_init_r - _start
Heiko Schochere48b7c02010-09-17 13:10:40 +0200310#endif
Heiko Schocherbafe7432010-10-13 07:57:14 +0200311
312_rel_dyn_start_ofs:
313 .word __rel_dyn_start - _start
314_rel_dyn_end_ofs:
315 .word __rel_dyn_end - _start
316_dynsym_start_ofs:
317 .word __dynsym_start - _start
318
Heiko Schochere48b7c02010-09-17 13:10:40 +0200319#else /* #if !defined(CONFIG_SYS_ARM_WITHOUT_RELOC) */
wdenk8ed96042005-01-09 23:16:25 +0000320/*
321 * the actual reset code
322 */
323
324reset:
325 /*
326 * set the cpu to SVC32 mode
327 */
328 mrs r0,cpsr
329 bic r0,r0,#0x1f
330 orr r0,r0,#0xd3
331 msr cpsr,r0
332
333#ifdef CONFIG_OMAP2420H4
wdenk082acfd2005-01-10 00:01:04 +0000334 /* Copy vectors to mask ROM indirect addr */
335 adr r0, _start /* r0 <- current position of code */
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200336 add r0, r0, #4 /* skip reset vector */
wdenk082acfd2005-01-10 00:01:04 +0000337 mov r2, #64 /* r2 <- size to copy */
338 add r2, r0, r2 /* r2 <- source end address */
339 mov r1, #SRAM_OFFSET0 /* build vect addr */
340 mov r3, #SRAM_OFFSET1
341 add r1, r1, r3
342 mov r3, #SRAM_OFFSET2
343 add r1, r1, r3
wdenk8ed96042005-01-09 23:16:25 +0000344next:
wdenk082acfd2005-01-10 00:01:04 +0000345 ldmia r0!, {r3-r10} /* copy from source address [r0] */
346 stmia r1!, {r3-r10} /* copy to target address [r1] */
347 cmp r0, r2 /* until source end address [r2] */
348 bne next /* loop until equal */
wdenk082acfd2005-01-10 00:01:04 +0000349 bl cpy_clk_code /* put dpll adjust code behind vectors */
wdenk8ed96042005-01-09 23:16:25 +0000350#endif
wdenk8ed96042005-01-09 23:16:25 +0000351 /* the mask ROM code should have PLL and others stable */
wdenk8aa1a2d2005-04-04 12:44:11 +0000352#ifndef CONFIG_SKIP_LOWLEVEL_INIT
wdenk8ed96042005-01-09 23:16:25 +0000353 bl cpu_init_crit
wdenk8aa1a2d2005-04-04 12:44:11 +0000354#endif
wdenk8ed96042005-01-09 23:16:25 +0000355
wdenk8aa1a2d2005-04-04 12:44:11 +0000356#ifndef CONFIG_SKIP_RELOCATE_UBOOT
wdenk8ed96042005-01-09 23:16:25 +0000357relocate: /* relocate U-Boot to RAM */
358 adr r0, _start /* r0 <- current position of code */
359 ldr r1, _TEXT_BASE /* test if we run from flash or RAM */
wdenk082acfd2005-01-10 00:01:04 +0000360 cmp r0, r1 /* don't reloc during debug */
Magnus Liljadf812382009-06-13 20:50:00 +0200361#ifndef CONFIG_PRELOADER
wdenk082acfd2005-01-10 00:01:04 +0000362 beq stack_setup
Magnus Liljadf812382009-06-13 20:50:00 +0200363#endif /* CONFIG_PRELOADER */
wdenk8ed96042005-01-09 23:16:25 +0000364
365 ldr r2, _armboot_start
366 ldr r3, _bss_start
wdenk082acfd2005-01-10 00:01:04 +0000367 sub r2, r3, r2 /* r2 <- size of armboot */
368 add r2, r0, r2 /* r2 <- source end address */
wdenk8ed96042005-01-09 23:16:25 +0000369
370copy_loop:
371 ldmia r0!, {r3-r10} /* copy from source address [r0] */
372 stmia r1!, {r3-r10} /* copy to target address [r1] */
Albert Aribaudda90d4c2010-10-05 16:06:39 +0200373 cmp r0, r2 /* until source end address [r2] */
374 blo copy_loop
wdenk8aa1a2d2005-04-04 12:44:11 +0000375#endif /* CONFIG_SKIP_RELOCATE_UBOOT */
wdenk8ed96042005-01-09 23:16:25 +0000376
377 /* Set up the stack */
378stack_setup:
379 ldr r0, _TEXT_BASE /* upper 128 KiB: relocated uboot */
Magnus Liljadf812382009-06-13 20:50:00 +0200380#ifdef CONFIG_PRELOADER
Kyungmin Park751b9b52008-01-17 16:43:25 +0900381 sub sp, r0, #128 /* leave 32 words for abort-stack */
382#else
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200383 sub r0, r0, #CONFIG_SYS_MALLOC_LEN /* malloc area */
Wolfgang Denk25ddd1f2010-10-26 14:34:52 +0200384 sub r0, r0, #GENERATED_GBL_DATA_SIZE /* bdinfo */
wdenk8ed96042005-01-09 23:16:25 +0000385#ifdef CONFIG_USE_IRQ
386 sub r0, r0, #(CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ)
387#endif
388 sub sp, r0, #12 /* leave 3 words for abort-stack */
Magnus Liljadf812382009-06-13 20:50:00 +0200389#endif /* CONFIG_PRELOADER */
Vitaly Kuzmichev1a27f7d2010-06-15 22:18:11 +0400390 bic sp, sp, #7 /* 8-byte alignment for ABI compliance */
wdenk8ed96042005-01-09 23:16:25 +0000391
392clear_bss:
Heiko Schocherbafe7432010-10-13 07:57:14 +0200393 adr r2, _start
394 ldr r0, _bss_start_ofs /* find start of bss segment */
395 add r0, r0, r2
396 ldr r1, _bss_end_ofs /* stop here */
397 add r1, r1, r2
wdenk082acfd2005-01-10 00:01:04 +0000398 mov r2, #0x00000000 /* clear */
wdenk8ed96042005-01-09 23:16:25 +0000399
Magnus Liljadf812382009-06-13 20:50:00 +0200400#ifndef CONFIG_PRELOADER
wdenk082acfd2005-01-10 00:01:04 +0000401clbss_l:str r2, [r0] /* clear loop... */
wdenk8ed96042005-01-09 23:16:25 +0000402 add r0, r0, #4
403 cmp r0, r1
404 bne clbss_l
Kyungmin Park751b9b52008-01-17 16:43:25 +0900405#endif
wdenk8ed96042005-01-09 23:16:25 +0000406
Heiko Schocherbafe7432010-10-13 07:57:14 +0200407 ldr r0, _start_armboot_ofs
408 adr r1, _start
409 add r0, r0, r1
410 ldr pc, r0
wdenk8ed96042005-01-09 23:16:25 +0000411
Heiko Schocherbafe7432010-10-13 07:57:14 +0200412_start_armboot_ofs:
Magnus Lilja40c642b2009-06-13 20:50:01 +0200413#ifdef CONFIG_NAND_SPL
Heiko Schocherbafe7432010-10-13 07:57:14 +0200414 .word nand_boot - _start
Magnus Lilja40c642b2009-06-13 20:50:01 +0200415#else
Kyungmin Park751b9b52008-01-17 16:43:25 +0900416#ifdef CONFIG_ONENAND_IPL
Heiko Schocherbafe7432010-10-13 07:57:14 +0200417 .word start_oneboot - _start
Kyungmin Park751b9b52008-01-17 16:43:25 +0900418#else
Heiko Schocherbafe7432010-10-13 07:57:14 +0200419 .word start_armboot - _start
Magnus Lilja40c642b2009-06-13 20:50:01 +0200420#endif /* CONFIG_ONENAND_IPL */
421#endif /* CONFIG_NAND_SPL */
wdenk8ed96042005-01-09 23:16:25 +0000422
Heiko Schochere48b7c02010-09-17 13:10:40 +0200423#endif /* #if !defined(CONFIG_SYS_ARM_WITHOUT_RELOC) */
424
wdenk8ed96042005-01-09 23:16:25 +0000425/*
426 *************************************************************************
427 *
428 * CPU_init_critical registers
429 *
430 * setup important registers
431 * setup memory timing
432 *
433 *************************************************************************
434 */
Magnus Lilja40c642b2009-06-13 20:50:01 +0200435#ifndef CONFIG_SKIP_LOWLEVEL_INIT
wdenk8ed96042005-01-09 23:16:25 +0000436cpu_init_crit:
437 /*
438 * flush v4 I/D caches
439 */
440 mov r0, #0
George G. Davis409a07c2010-05-11 10:15:36 -0400441 mcr p15, 0, r0, c7, c7, 0 /* Invalidate I+D+BTB caches */
442 mcr p15, 0, r0, c8, c7, 0 /* Invalidate Unified TLB */
wdenk8ed96042005-01-09 23:16:25 +0000443
444 /*
445 * disable MMU stuff and caches
446 */
447 mrc p15, 0, r0, c1, c0, 0
448 bic r0, r0, #0x00002300 @ clear bits 13, 9:8 (--V- --RS)
449 bic r0, r0, #0x00000087 @ clear bits 7, 2:0 (B--- -CAM)
450 orr r0, r0, #0x00000002 @ set bit 2 (A) Align
wdenk8ed96042005-01-09 23:16:25 +0000451 orr r0, r0, #0x00001000 @ set bit 12 (I) I-Cache
wdenk8ed96042005-01-09 23:16:25 +0000452 mcr p15, 0, r0, c1, c0, 0
453
454 /*
wdenk082acfd2005-01-10 00:01:04 +0000455 * Jump to board specific initialization... The Mask ROM will have already initialized
456 * basic memory. Go here to bump up clock rate and handle wake up conditions.
wdenk8ed96042005-01-09 23:16:25 +0000457 */
wdenk082acfd2005-01-10 00:01:04 +0000458 mov ip, lr /* persevere link reg across call */
Wolfgang Denk87cb6862005-10-06 17:08:18 +0200459 bl lowlevel_init /* go setup pll,mux,memory */
wdenk082acfd2005-01-10 00:01:04 +0000460 mov lr, ip /* restore link */
461 mov pc, lr /* back to my caller */
Magnus Lilja40c642b2009-06-13 20:50:01 +0200462#endif /* CONFIG_SKIP_LOWLEVEL_INIT */
Kyungmin Park751b9b52008-01-17 16:43:25 +0900463
Magnus Liljadf812382009-06-13 20:50:00 +0200464#ifndef CONFIG_PRELOADER
wdenk8ed96042005-01-09 23:16:25 +0000465/*
466 *************************************************************************
467 *
468 * Interrupt handling
469 *
470 *************************************************************************
471 */
472@
473@ IRQ stack frame.
474@
475#define S_FRAME_SIZE 72
476
477#define S_OLD_R0 68
478#define S_PSR 64
479#define S_PC 60
480#define S_LR 56
481#define S_SP 52
482
483#define S_IP 48
484#define S_FP 44
485#define S_R10 40
486#define S_R9 36
487#define S_R8 32
488#define S_R7 28
489#define S_R6 24
490#define S_R5 20
491#define S_R4 16
492#define S_R3 12
493#define S_R2 8
494#define S_R1 4
495#define S_R0 0
496
497#define MODE_SVC 0x13
498#define I_BIT 0x80
499
500/*
501 * use bad_save_user_regs for abort/prefetch/undef/swi ...
502 * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling
503 */
504
505 .macro bad_save_user_regs
wdenk082acfd2005-01-10 00:01:04 +0000506 sub sp, sp, #S_FRAME_SIZE @ carve out a frame on current user stack
wdenk8ed96042005-01-09 23:16:25 +0000507 stmia sp, {r0 - r12} @ Save user registers (now in svc mode) r0-r12
508
Heiko Schochere48b7c02010-09-17 13:10:40 +0200509#if !defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
510 ldr r2, IRQ_STACK_START_IN @ set base 2 words into abort stack
511#else
Heiko Schocherbafe7432010-10-13 07:57:14 +0200512 adr r2, _start
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200513 sub r2, r2, #(CONFIG_SYS_MALLOC_LEN)
Wolfgang Denk25ddd1f2010-10-26 14:34:52 +0200514 sub r2, r2, #(GENERATED_GBL_DATA_SIZE+8) @ set base 2 words into abort stack
Heiko Schochere48b7c02010-09-17 13:10:40 +0200515#endif
wdenk082acfd2005-01-10 00:01:04 +0000516 ldmia r2, {r2 - r3} @ get values for "aborted" pc and cpsr (into parm regs)
wdenk8ed96042005-01-09 23:16:25 +0000517 add r0, sp, #S_FRAME_SIZE @ grab pointer to old stack
518
519 add r5, sp, #S_SP
520 mov r1, lr
wdenk082acfd2005-01-10 00:01:04 +0000521 stmia r5, {r0 - r3} @ save sp_SVC, lr_SVC, pc, cpsr
522 mov r0, sp @ save current stack into r0 (param register)
wdenk8ed96042005-01-09 23:16:25 +0000523 .endm
524
525 .macro irq_save_user_regs
526 sub sp, sp, #S_FRAME_SIZE
527 stmia sp, {r0 - r12} @ Calling r0-r12
wdenk082acfd2005-01-10 00:01:04 +0000528 add r8, sp, #S_PC @ !!!! R8 NEEDS to be saved !!!! a reserved stack spot would be good.
529 stmdb r8, {sp, lr}^ @ Calling SP, LR
530 str lr, [r8, #0] @ Save calling PC
531 mrs r6, spsr
532 str r6, [r8, #4] @ Save CPSR
533 str r0, [r8, #8] @ Save OLD_R0
wdenk8ed96042005-01-09 23:16:25 +0000534 mov r0, sp
535 .endm
536
537 .macro irq_restore_user_regs
538 ldmia sp, {r0 - lr}^ @ Calling r0 - lr
539 mov r0, r0
540 ldr lr, [sp, #S_PC] @ Get PC
541 add sp, sp, #S_FRAME_SIZE
542 subs pc, lr, #4 @ return & move spsr_svc into cpsr
543 .endm
544
545 .macro get_bad_stack
Heiko Schochere48b7c02010-09-17 13:10:40 +0200546#if !defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
547 ldr r13, IRQ_STACK_START_IN @ setup our mode stack (enter in banked mode)
548#else
Heiko Schocherbafe7432010-10-13 07:57:14 +0200549 adr r13, _start @ setup our mode stack (enter in banked mode)
550 sub r13, r13, #(CONFIG_STACKSIZE+CONFIG_SYS_MALLOC_LEN) @ move past malloc pool
Wolfgang Denk25ddd1f2010-10-26 14:34:52 +0200551 sub r13, r13, #(GENERATED_GBL_DATA_SIZE+8) @ move to reserved a couple spots for abort stack
Heiko Schochere48b7c02010-09-17 13:10:40 +0200552#endif
wdenk8ed96042005-01-09 23:16:25 +0000553
554 str lr, [r13] @ save caller lr in position 0 of saved stack
wdenk082acfd2005-01-10 00:01:04 +0000555 mrs lr, spsr @ get the spsr
556 str lr, [r13, #4] @ save spsr in position 1 of saved stack
wdenk8ed96042005-01-09 23:16:25 +0000557
558 mov r13, #MODE_SVC @ prepare SVC-Mode
559 @ msr spsr_c, r13
wdenk082acfd2005-01-10 00:01:04 +0000560 msr spsr, r13 @ switch modes, make sure moves will execute
561 mov lr, pc @ capture return pc
562 movs pc, lr @ jump to next instruction & switch modes.
wdenk8ed96042005-01-09 23:16:25 +0000563 .endm
564
565 .macro get_bad_stack_swi
wdenk082acfd2005-01-10 00:01:04 +0000566 sub r13, r13, #4 @ space on current stack for scratch reg.
567 str r0, [r13] @ save R0's value.
Heiko Schochere48b7c02010-09-17 13:10:40 +0200568#if !defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
569 ldr r0, IRQ_STACK_START_IN @ get data regions start
570#else
wdenk8ed96042005-01-09 23:16:25 +0000571 ldr r0, _armboot_start @ get data regions start
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200572 sub r0, r0, #(CONFIG_SYS_MALLOC_LEN) @ move past malloc pool
Wolfgang Denk25ddd1f2010-10-26 14:34:52 +0200573 sub r0, r0, #(GENERATED_GBL_DATA_SIZE+8) @ move past gbl and a couple spots for abort stack
Heiko Schochere48b7c02010-09-17 13:10:40 +0200574#endif
wdenk8ed96042005-01-09 23:16:25 +0000575 str lr, [r0] @ save caller lr in position 0 of saved stack
wdenk082acfd2005-01-10 00:01:04 +0000576 mrs r0, spsr @ get the spsr
577 str lr, [r0, #4] @ save spsr in position 1 of saved stack
578 ldr r0, [r13] @ restore r0
579 add r13, r13, #4 @ pop stack entry
wdenk8ed96042005-01-09 23:16:25 +0000580 .endm
581
582 .macro get_irq_stack @ setup IRQ stack
583 ldr sp, IRQ_STACK_START
584 .endm
585
586 .macro get_fiq_stack @ setup FIQ stack
587 ldr sp, FIQ_STACK_START
588 .endm
Magnus Liljadf812382009-06-13 20:50:00 +0200589#endif /* CONFIG_PRELOADER */
wdenk8ed96042005-01-09 23:16:25 +0000590
591/*
592 * exception handlers
593 */
Magnus Liljadf812382009-06-13 20:50:00 +0200594#ifdef CONFIG_PRELOADER
Kyungmin Park751b9b52008-01-17 16:43:25 +0900595 .align 5
596do_hang:
597 ldr sp, _TEXT_BASE /* use 32 words about stack */
598 bl hang /* hang and never return */
Magnus Liljadf812382009-06-13 20:50:00 +0200599#else /* !CONFIG_PRELOADER */
wdenk082acfd2005-01-10 00:01:04 +0000600 .align 5
wdenk8ed96042005-01-09 23:16:25 +0000601undefined_instruction:
602 get_bad_stack
603 bad_save_user_regs
wdenk082acfd2005-01-10 00:01:04 +0000604 bl do_undefined_instruction
wdenk8ed96042005-01-09 23:16:25 +0000605
606 .align 5
607software_interrupt:
608 get_bad_stack_swi
609 bad_save_user_regs
wdenk082acfd2005-01-10 00:01:04 +0000610 bl do_software_interrupt
wdenk8ed96042005-01-09 23:16:25 +0000611
612 .align 5
613prefetch_abort:
614 get_bad_stack
615 bad_save_user_regs
wdenk082acfd2005-01-10 00:01:04 +0000616 bl do_prefetch_abort
wdenk8ed96042005-01-09 23:16:25 +0000617
618 .align 5
619data_abort:
620 get_bad_stack
621 bad_save_user_regs
wdenk082acfd2005-01-10 00:01:04 +0000622 bl do_data_abort
wdenk8ed96042005-01-09 23:16:25 +0000623
624 .align 5
625not_used:
626 get_bad_stack
627 bad_save_user_regs
wdenk082acfd2005-01-10 00:01:04 +0000628 bl do_not_used
wdenk8ed96042005-01-09 23:16:25 +0000629
630#ifdef CONFIG_USE_IRQ
631
632 .align 5
633irq:
634 get_irq_stack
635 irq_save_user_regs
wdenk082acfd2005-01-10 00:01:04 +0000636 bl do_irq
wdenk8ed96042005-01-09 23:16:25 +0000637 irq_restore_user_regs
638
639 .align 5
640fiq:
641 get_fiq_stack
642 /* someone ought to write a more effiction fiq_save_user_regs */
643 irq_save_user_regs
wdenk082acfd2005-01-10 00:01:04 +0000644 bl do_fiq
wdenk8ed96042005-01-09 23:16:25 +0000645 irq_restore_user_regs
646
647#else
648
649 .align 5
650irq:
651 get_bad_stack
652 bad_save_user_regs
wdenk082acfd2005-01-10 00:01:04 +0000653 bl do_irq
wdenk8ed96042005-01-09 23:16:25 +0000654
655 .align 5
656fiq:
657 get_bad_stack
658 bad_save_user_regs
wdenk082acfd2005-01-10 00:01:04 +0000659 bl do_fiq
wdenk8ed96042005-01-09 23:16:25 +0000660
661#endif
662 .align 5
663.global arm1136_cache_flush
664arm1136_cache_flush:
Heiko Schocher7e4a9e62010-09-17 13:10:32 +0200665#if !defined(CONFIG_SYS_NO_ICACHE)
wdenk8ed96042005-01-09 23:16:25 +0000666 mcr p15, 0, r1, c7, c5, 0 @ invalidate I cache
Heiko Schocher7e4a9e62010-09-17 13:10:32 +0200667#endif
668#if !defined(CONFIG_SYS_NO_DCACHE)
669 mcr p15, 0, r1, c7, c14, 0 @ invalidate D cache
670#endif
wdenk8ed96042005-01-09 23:16:25 +0000671 mov pc, lr @ back to caller
Magnus Liljadf812382009-06-13 20:50:00 +0200672#endif /* CONFIG_PRELOADER */