xref: /rk3399_rockchip-uboot/arch/arm/cpu/armv7/start.S (revision f8b9d1d30ece82abccefac3c860c06f8b7da8fbb)
1f56348afSSteve Sakoman/*
2f56348afSSteve Sakoman * armboot - Startup Code for OMAP3530/ARM Cortex CPU-core
3f56348afSSteve Sakoman *
4f56348afSSteve Sakoman * Copyright (c) 2004	Texas Instruments <r-woodruff2@ti.com>
5f56348afSSteve Sakoman *
6f56348afSSteve Sakoman * Copyright (c) 2001	Marius Gröger <mag@sysgo.de>
7f56348afSSteve Sakoman * Copyright (c) 2002	Alex Züpke <azu@sysgo.de>
8f56348afSSteve Sakoman * Copyright (c) 2002	Gary Jennejohn <garyj@denx.de>
9f56348afSSteve Sakoman * Copyright (c) 2003	Richard Woodruff <r-woodruff2@ti.com>
10f56348afSSteve Sakoman * Copyright (c) 2003	Kshitij <kshitij@ti.com>
11f56348afSSteve Sakoman * Copyright (c) 2006-2008 Syed Mohammed Khasim <x0khasim@ti.com>
12f56348afSSteve Sakoman *
13f56348afSSteve Sakoman * See file CREDITS for list of people who contributed to this
14f56348afSSteve Sakoman * project.
15f56348afSSteve Sakoman *
16f56348afSSteve Sakoman * This program is free software; you can redistribute it and/or
17f56348afSSteve Sakoman * modify it under the terms of the GNU General Public License as
18f56348afSSteve Sakoman * published by the Free Software Foundation; either version 2 of
19f56348afSSteve Sakoman * the License, or (at your option) any later version.
20f56348afSSteve Sakoman *
21f56348afSSteve Sakoman * This program is distributed in the hope that it will be useful,
22f56348afSSteve Sakoman * but WITHOUT ANY WARRANTY; without even the implied warranty of
23f56348afSSteve Sakoman * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the
24f56348afSSteve Sakoman * GNU General Public License for more details.
25f56348afSSteve Sakoman *
26f56348afSSteve Sakoman * You should have received a copy of the GNU General Public License
27f56348afSSteve Sakoman * along with this program; if not, write to the Free Software
28f56348afSSteve Sakoman * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29f56348afSSteve Sakoman * MA 02111-1307 USA
30f56348afSSteve Sakoman */
31f56348afSSteve Sakoman
3225ddd1fbSWolfgang Denk#include <asm-offsets.h>
33f56348afSSteve Sakoman#include <config.h>
34f56348afSSteve Sakoman#include <version.h>
35a8c68639SAneesh V#include <asm/system.h>
3674236acaSAneesh V#include <linux/linkage.h>
37f56348afSSteve Sakoman
38f56348afSSteve Sakoman.globl _start
39f56348afSSteve Sakoman_start: b	reset
40f56348afSSteve Sakoman	ldr	pc, _undefined_instruction
41f56348afSSteve Sakoman	ldr	pc, _software_interrupt
42f56348afSSteve Sakoman	ldr	pc, _prefetch_abort
43f56348afSSteve Sakoman	ldr	pc, _data_abort
44f56348afSSteve Sakoman	ldr	pc, _not_used
45f56348afSSteve Sakoman	ldr	pc, _irq
46f56348afSSteve Sakoman	ldr	pc, _fiq
47033ca724SAneesh V#ifdef CONFIG_SPL_BUILD
48033ca724SAneesh V_undefined_instruction: .word _undefined_instruction
49033ca724SAneesh V_software_interrupt:	.word _software_interrupt
50033ca724SAneesh V_prefetch_abort:	.word _prefetch_abort
51033ca724SAneesh V_data_abort:		.word _data_abort
52033ca724SAneesh V_not_used:		.word _not_used
53033ca724SAneesh V_irq:			.word _irq
54033ca724SAneesh V_fiq:			.word _fiq
55033ca724SAneesh V_pad:			.word 0x12345678 /* now 16*4=64 */
56033ca724SAneesh V#else
57f56348afSSteve Sakoman_undefined_instruction: .word undefined_instruction
58f56348afSSteve Sakoman_software_interrupt:	.word software_interrupt
59f56348afSSteve Sakoman_prefetch_abort:	.word prefetch_abort
60f56348afSSteve Sakoman_data_abort:		.word data_abort
61f56348afSSteve Sakoman_not_used:		.word not_used
62f56348afSSteve Sakoman_irq:			.word irq
63f56348afSSteve Sakoman_fiq:			.word fiq
64f56348afSSteve Sakoman_pad:			.word 0x12345678 /* now 16*4=64 */
65033ca724SAneesh V#endif	/* CONFIG_SPL_BUILD */
66033ca724SAneesh V
67f56348afSSteve Sakoman.global _end_vect
68f56348afSSteve Sakoman_end_vect:
69f56348afSSteve Sakoman
70f56348afSSteve Sakoman	.balignl 16,0xdeadbeef
71f56348afSSteve Sakoman/*************************************************************************
72f56348afSSteve Sakoman *
73f56348afSSteve Sakoman * Startup Code (reset vector)
74f56348afSSteve Sakoman *
75f56348afSSteve Sakoman * do important init only if we don't start from memory!
76f56348afSSteve Sakoman * setup Memory and board specific bits prior to relocation.
77f56348afSSteve Sakoman * relocate armboot to ram
78f56348afSSteve Sakoman * setup stack
79f56348afSSteve Sakoman *
80f56348afSSteve Sakoman *************************************************************************/
81f56348afSSteve Sakoman
82561142afSHeiko Schocher.globl _TEXT_BASE
83f56348afSSteve Sakoman_TEXT_BASE:
8414d0a02aSWolfgang Denk	.word	CONFIG_SYS_TEXT_BASE
85f56348afSSteve Sakoman
86f56348afSSteve Sakoman/*
87f56348afSSteve Sakoman * These are defined in the board-specific linker script.
88f56348afSSteve Sakoman */
89c3d3a541SHeiko Schocher.globl _bss_start_ofs
90c3d3a541SHeiko Schocher_bss_start_ofs:
91c3d3a541SHeiko Schocher	.word __bss_start - _start
92f56348afSSteve Sakoman
93033ca724SAneesh V.global	_image_copy_end_ofs
94033ca724SAneesh V_image_copy_end_ofs:
95033ca724SAneesh V	.word 	__image_copy_end - _start
96033ca724SAneesh V
97c3d3a541SHeiko Schocher.globl _bss_end_ofs
98c3d3a541SHeiko Schocher_bss_end_ofs:
9944c6e659SPo-Yu Chuang	.word __bss_end__ - _start
100f56348afSSteve Sakoman
101f326cbbaSPo-Yu Chuang.globl _end_ofs
102f326cbbaSPo-Yu Chuang_end_ofs:
103f326cbbaSPo-Yu Chuang	.word _end - _start
104f326cbbaSPo-Yu Chuang
105f56348afSSteve Sakoman#ifdef CONFIG_USE_IRQ
106f56348afSSteve Sakoman/* IRQ stack memory (calculated at run-time) */
107f56348afSSteve Sakoman.globl IRQ_STACK_START
108f56348afSSteve SakomanIRQ_STACK_START:
109f56348afSSteve Sakoman	.word	0x0badc0de
110f56348afSSteve Sakoman
111f56348afSSteve Sakoman/* IRQ stack memory (calculated at run-time) */
112f56348afSSteve Sakoman.globl FIQ_STACK_START
113f56348afSSteve SakomanFIQ_STACK_START:
114f56348afSSteve Sakoman	.word 0x0badc0de
115f56348afSSteve Sakoman#endif
116f56348afSSteve Sakoman
117561142afSHeiko Schocher/* IRQ stack memory (calculated at run-time) + 8 bytes */
118561142afSHeiko Schocher.globl IRQ_STACK_START_IN
119561142afSHeiko SchocherIRQ_STACK_START_IN:
120561142afSHeiko Schocher	.word	0x0badc0de
121561142afSHeiko Schocher
122561142afSHeiko Schocher/*
123561142afSHeiko Schocher * the actual reset code
124561142afSHeiko Schocher */
125561142afSHeiko Schocher
126561142afSHeiko Schocherreset:
1278cf686e1SAneesh V	bl	save_boot_params
128561142afSHeiko Schocher	/*
129561142afSHeiko Schocher	 * set the cpu to SVC32 mode
130561142afSHeiko Schocher	 */
131561142afSHeiko Schocher	mrs	r0, cpsr
132561142afSHeiko Schocher	bic	r0, r0, #0x1f
133561142afSHeiko Schocher	orr	r0, r0, #0xd3
134561142afSHeiko Schocher	msr	cpsr,r0
135561142afSHeiko Schocher
136e2132c29STom Warren#if !defined(CONFIG_TEGRA2)
137a8c68639SAneesh V/*
138a8c68639SAneesh V * Setup vector:
139a8c68639SAneesh V * (OMAP4 spl TEXT_BASE is not 32 byte aligned.
140a8c68639SAneesh V * Continue to use ROM code vector only in OMAP4 spl)
141a8c68639SAneesh V */
142a8c68639SAneesh V#if !(defined(CONFIG_OMAP44XX) && defined(CONFIG_SPL_BUILD))
143a8c68639SAneesh V	/* Set V=0 in CP15 SCTRL register - for VBAR to point to vector */
144a8c68639SAneesh V	mrc	p15, 0, r0, c1, c0, 0	@ Read CP15 SCTRL Register
145a8c68639SAneesh V	bic	r0, #CR_V		@ V = 0
146a8c68639SAneesh V	mcr	p15, 0, r0, c1, c0, 0	@ Write CP15 SCTRL Register
147a8c68639SAneesh V
148a8c68639SAneesh V	/* Set vector address in CP15 VBAR register */
149a8c68639SAneesh V	ldr	r0, =_start
150a8c68639SAneesh V	mcr	p15, 0, r0, c12, c0, 0	@Set VBAR
151a8c68639SAneesh V#endif
152e2132c29STom Warren#endif	/* !Tegra2 */
153a8c68639SAneesh V
154561142afSHeiko Schocher	/* the mask ROM code should have PLL and others stable */
155561142afSHeiko Schocher#ifndef CONFIG_SKIP_LOWLEVEL_INIT
15680433c9aSSimon Glass	bl	cpu_init_cp15
157561142afSHeiko Schocher	bl	cpu_init_crit
158561142afSHeiko Schocher#endif
159561142afSHeiko Schocher
160561142afSHeiko Schocher/* Set stackpointer in internal RAM to call board_init_f */
161561142afSHeiko Schochercall_board_init_f:
162561142afSHeiko Schocher	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR)
163296cae73SHeiko Schocher	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
164561142afSHeiko Schocher	ldr	r0,=0x00000000
165561142afSHeiko Schocher	bl	board_init_f
166561142afSHeiko Schocher
167561142afSHeiko Schocher/*------------------------------------------------------------------------------*/
168561142afSHeiko Schocher
169561142afSHeiko Schocher/*
170561142afSHeiko Schocher * void relocate_code (addr_sp, gd, addr_moni)
171561142afSHeiko Schocher *
172561142afSHeiko Schocher * This "function" does not return, instead it continues in RAM
173561142afSHeiko Schocher * after relocating the monitor code.
174561142afSHeiko Schocher *
175561142afSHeiko Schocher */
17674236acaSAneesh VENTRY(relocate_code)
177561142afSHeiko Schocher	mov	r4, r0	/* save addr_sp */
178561142afSHeiko Schocher	mov	r5, r1	/* save addr of gd */
179561142afSHeiko Schocher	mov	r6, r2	/* save addr of destination */
180561142afSHeiko Schocher
181561142afSHeiko Schocher	/* Set up the stack						    */
182561142afSHeiko Schocherstack_setup:
183561142afSHeiko Schocher	mov	sp, r4
184561142afSHeiko Schocher
185561142afSHeiko Schocher	adr	r0, _start
186b9c5081dSAndreas Bießmann	cmp	r0, r6
187033ca724SAneesh V	moveq	r9, #0		/* no relocation. relocation offset(r9) = 0 */
188b9c5081dSAndreas Bießmann	beq	clear_bss		/* skip relocation */
189a1a47d3cSAndreas Bießmann	mov	r1, r6			/* r1 <- scratch for copy_loop */
190033ca724SAneesh V	ldr	r3, _image_copy_end_ofs
191a1a47d3cSAndreas Bießmann	add	r2, r0, r3		/* r2 <- source end address	    */
192561142afSHeiko Schocher
193561142afSHeiko Schochercopy_loop:
194561142afSHeiko Schocher	ldmia	r0!, {r9-r10}		/* copy from source address [r0]    */
195a78fb68fSAndreas Bießmann	stmia	r1!, {r9-r10}		/* copy to   target address [r1]    */
196da90d4ceSAlbert Aribaud	cmp	r0, r2			/* until source end address [r2]    */
197da90d4ceSAlbert Aribaud	blo	copy_loop
198561142afSHeiko Schocher
199401bb30bSAneesh V#ifndef CONFIG_SPL_BUILD
200c3d3a541SHeiko Schocher	/*
201c3d3a541SHeiko Schocher	 * fix .rel.dyn relocations
202c3d3a541SHeiko Schocher	 */
203c3d3a541SHeiko Schocher	ldr	r0, _TEXT_BASE		/* r0 <- Text base */
204a78fb68fSAndreas Bießmann	sub	r9, r6, r0		/* r9 <- relocation offset */
205c3d3a541SHeiko Schocher	ldr	r10, _dynsym_start_ofs	/* r10 <- sym table ofs */
206c3d3a541SHeiko Schocher	add	r10, r10, r0		/* r10 <- sym table in FLASH */
207c3d3a541SHeiko Schocher	ldr	r2, _rel_dyn_start_ofs	/* r2 <- rel dyn start ofs */
208c3d3a541SHeiko Schocher	add	r2, r2, r0		/* r2 <- rel dyn start in FLASH */
209c3d3a541SHeiko Schocher	ldr	r3, _rel_dyn_end_ofs	/* r3 <- rel dyn end ofs */
210c3d3a541SHeiko Schocher	add	r3, r3, r0		/* r3 <- rel dyn end in FLASH */
211561142afSHeiko Schocherfixloop:
212c3d3a541SHeiko Schocher	ldr	r0, [r2]		/* r0 <- location to fix up, IN FLASH! */
2138c0c2b90SGray Remlin	add	r0, r0, r9		/* r0 <- location to fix up in RAM */
214c3d3a541SHeiko Schocher	ldr	r1, [r2, #4]
2151f52d89fSAndreas Bießmann	and	r7, r1, #0xff
2161f52d89fSAndreas Bießmann	cmp	r7, #23			/* relative fixup? */
217c3d3a541SHeiko Schocher	beq	fixrel
2181f52d89fSAndreas Bießmann	cmp	r7, #2			/* absolute fixup? */
219c3d3a541SHeiko Schocher	beq	fixabs
220c3d3a541SHeiko Schocher	/* ignore unknown type of fixup */
221c3d3a541SHeiko Schocher	b	fixnext
222c3d3a541SHeiko Schocherfixabs:
223c3d3a541SHeiko Schocher	/* absolute fix: set location to (offset) symbol value */
224c3d3a541SHeiko Schocher	mov	r1, r1, LSR #4		/* r1 <- symbol index in .dynsym */
225c3d3a541SHeiko Schocher	add	r1, r10, r1		/* r1 <- address of symbol in table */
226c3d3a541SHeiko Schocher	ldr	r1, [r1, #4]		/* r1 <- symbol value */
2273600945bSWolfgang Denk	add	r1, r1, r9		/* r1 <- relocated sym addr */
228c3d3a541SHeiko Schocher	b	fixnext
229c3d3a541SHeiko Schocherfixrel:
230c3d3a541SHeiko Schocher	/* relative fix: increase location by offset */
231c3d3a541SHeiko Schocher	ldr	r1, [r0]
232c3d3a541SHeiko Schocher	add	r1, r1, r9
233c3d3a541SHeiko Schocherfixnext:
234c3d3a541SHeiko Schocher	str	r1, [r0]
235c3d3a541SHeiko Schocher	add	r2, r2, #8		/* each rel.dyn entry is 8 bytes */
236561142afSHeiko Schocher	cmp	r2, r3
237c3d3a541SHeiko Schocher	blo	fixloop
238033ca724SAneesh V	b	clear_bss
239033ca724SAneesh V_rel_dyn_start_ofs:
240033ca724SAneesh V	.word __rel_dyn_start - _start
241033ca724SAneesh V_rel_dyn_end_ofs:
242033ca724SAneesh V	.word __rel_dyn_end - _start
243033ca724SAneesh V_dynsym_start_ofs:
244033ca724SAneesh V	.word __dynsym_start - _start
245033ca724SAneesh V
246033ca724SAneesh V#endif	/* #ifndef CONFIG_SPL_BUILD */
247561142afSHeiko Schocher
248561142afSHeiko Schocherclear_bss:
249033ca724SAneesh V#ifdef CONFIG_SPL_BUILD
250033ca724SAneesh V	/* No relocation for SPL */
251033ca724SAneesh V	ldr	r0, =__bss_start
252033ca724SAneesh V	ldr	r1, =__bss_end__
253033ca724SAneesh V#else
254c3d3a541SHeiko Schocher	ldr	r0, _bss_start_ofs
255c3d3a541SHeiko Schocher	ldr	r1, _bss_end_ofs
256a78fb68fSAndreas Bießmann	mov	r4, r6			/* reloc addr */
257561142afSHeiko Schocher	add	r0, r0, r4
258561142afSHeiko Schocher	add	r1, r1, r4
259033ca724SAneesh V#endif
260561142afSHeiko Schocher	mov	r2, #0x00000000		/* clear			    */
261561142afSHeiko Schocher
262561142afSHeiko Schocherclbss_l:str	r2, [r0]		/* clear loop...		    */
263561142afSHeiko Schocher	add	r0, r0, #4
264561142afSHeiko Schocher	cmp	r0, r1
265561142afSHeiko Schocher	bne	clbss_l
266561142afSHeiko Schocher
267561142afSHeiko Schocher/*
268561142afSHeiko Schocher * We are done. Do not return, instead branch to second part of board
269561142afSHeiko Schocher * initialization, now running from RAM.
270561142afSHeiko Schocher */
271561142afSHeiko Schocherjump_2_ram:
272c2dd0d45SAneesh V/*
273c2dd0d45SAneesh V * If I-cache is enabled invalidate it
274c2dd0d45SAneesh V */
275c2dd0d45SAneesh V#ifndef CONFIG_SYS_ICACHE_OFF
276c2dd0d45SAneesh V	mcr	p15, 0, r0, c7, c5, 0	@ invalidate icache
277c2dd0d45SAneesh V	mcr     p15, 0, r0, c7, c10, 4	@ DSB
278c2dd0d45SAneesh V	mcr     p15, 0, r0, c7, c5, 4	@ ISB
279c2dd0d45SAneesh V#endif
280*f8b9d1d3STetsuyuki Kobayashi/*
281*f8b9d1d3STetsuyuki Kobayashi * Move vector table
282*f8b9d1d3STetsuyuki Kobayashi */
283*f8b9d1d3STetsuyuki Kobayashi#if !defined(CONFIG_TEGRA2)
284*f8b9d1d3STetsuyuki Kobayashi#if !(defined(CONFIG_OMAP44XX) && defined(CONFIG_SPL_BUILD))
285*f8b9d1d3STetsuyuki Kobayashi	/* Set vector address in CP15 VBAR register */
286*f8b9d1d3STetsuyuki Kobayashi	ldr     r0, =_start
287*f8b9d1d3STetsuyuki Kobayashi	add     r0, r0, r9
288*f8b9d1d3STetsuyuki Kobayashi	mcr     p15, 0, r0, c12, c0, 0  @Set VBAR
289*f8b9d1d3STetsuyuki Kobayashi#endif
290*f8b9d1d3STetsuyuki Kobayashi#endif /* !Tegra2 */
291*f8b9d1d3STetsuyuki Kobayashi
292c3d3a541SHeiko Schocher	ldr	r0, _board_init_r_ofs
293c3d3a541SHeiko Schocher	adr	r1, _start
294123fb7deSDarius Augulis	add	lr, r0, r1
295123fb7deSDarius Augulis	add	lr, lr, r9
296561142afSHeiko Schocher	/* setup parameters for board_init_r */
297561142afSHeiko Schocher	mov	r0, r5		/* gd_t */
298a78fb68fSAndreas Bießmann	mov	r1, r6		/* dest_addr */
299561142afSHeiko Schocher	/* jump to it ... */
300561142afSHeiko Schocher	mov	pc, lr
301561142afSHeiko Schocher
302c3d3a541SHeiko Schocher_board_init_r_ofs:
303c3d3a541SHeiko Schocher	.word board_init_r - _start
30474236acaSAneesh VENDPROC(relocate_code)
305c3d3a541SHeiko Schocher
306f56348afSSteve Sakoman/*************************************************************************
307f56348afSSteve Sakoman *
30880433c9aSSimon Glass * cpu_init_cp15
309f56348afSSteve Sakoman *
31080433c9aSSimon Glass * Setup CP15 registers (cache, MMU, TLBs). The I-cache is turned on unless
31180433c9aSSimon Glass * CONFIG_SYS_ICACHE_OFF is defined.
312f56348afSSteve Sakoman *
313f56348afSSteve Sakoman *************************************************************************/
31474236acaSAneesh VENTRY(cpu_init_cp15)
315f56348afSSteve Sakoman	/*
316f56348afSSteve Sakoman	 * Invalidate L1 I/D
317f56348afSSteve Sakoman	 */
318f56348afSSteve Sakoman	mov	r0, #0			@ set up for MCR
319f56348afSSteve Sakoman	mcr	p15, 0, r0, c8, c7, 0	@ invalidate TLBs
320f56348afSSteve Sakoman	mcr	p15, 0, r0, c7, c5, 0	@ invalidate icache
321c2dd0d45SAneesh V	mcr	p15, 0, r0, c7, c5, 6	@ invalidate BP array
322c2dd0d45SAneesh V	mcr     p15, 0, r0, c7, c10, 4	@ DSB
323c2dd0d45SAneesh V	mcr     p15, 0, r0, c7, c5, 4	@ ISB
324f56348afSSteve Sakoman
325f56348afSSteve Sakoman	/*
326f56348afSSteve Sakoman	 * disable MMU stuff and caches
327f56348afSSteve Sakoman	 */
328f56348afSSteve Sakoman	mrc	p15, 0, r0, c1, c0, 0
329f56348afSSteve Sakoman	bic	r0, r0, #0x00002000	@ clear bits 13 (--V-)
330f56348afSSteve Sakoman	bic	r0, r0, #0x00000007	@ clear bits 2:0 (-CAM)
331f56348afSSteve Sakoman	orr	r0, r0, #0x00000002	@ set bit 1 (--A-) Align
332c2dd0d45SAneesh V	orr	r0, r0, #0x00000800	@ set bit 11 (Z---) BTB
333c2dd0d45SAneesh V#ifdef CONFIG_SYS_ICACHE_OFF
334c2dd0d45SAneesh V	bic	r0, r0, #0x00001000	@ clear bit 12 (I) I-cache
335c2dd0d45SAneesh V#else
336c2dd0d45SAneesh V	orr	r0, r0, #0x00001000	@ set bit 12 (I) I-cache
337c2dd0d45SAneesh V#endif
338f56348afSSteve Sakoman	mcr	p15, 0, r0, c1, c0, 0
33980433c9aSSimon Glass	mov	pc, lr			@ back to my caller
34074236acaSAneesh VENDPROC(cpu_init_cp15)
34180433c9aSSimon Glass
34280433c9aSSimon Glass#ifndef CONFIG_SKIP_LOWLEVEL_INIT
34380433c9aSSimon Glass/*************************************************************************
34480433c9aSSimon Glass *
34580433c9aSSimon Glass * CPU_init_critical registers
34680433c9aSSimon Glass *
34780433c9aSSimon Glass * setup important registers
34880433c9aSSimon Glass * setup memory timing
34980433c9aSSimon Glass *
35080433c9aSSimon Glass *************************************************************************/
35174236acaSAneesh VENTRY(cpu_init_crit)
352f56348afSSteve Sakoman	/*
353f56348afSSteve Sakoman	 * Jump to board specific initialization...
354f56348afSSteve Sakoman	 * The Mask ROM will have already initialized
355f56348afSSteve Sakoman	 * basic memory. Go here to bump up clock rate and handle
356f56348afSSteve Sakoman	 * wake up conditions.
357f56348afSSteve Sakoman	 */
358f56348afSSteve Sakoman	mov	ip, lr			@ persevere link reg across call
359f56348afSSteve Sakoman	bl	lowlevel_init		@ go setup pll,mux,memory
360f56348afSSteve Sakoman	mov	lr, ip			@ restore link
361f56348afSSteve Sakoman	mov	pc, lr			@ back to my caller
36274236acaSAneesh VENDPROC(cpu_init_crit)
36322193540SRob Herring#endif
364033ca724SAneesh V
365033ca724SAneesh V#ifndef CONFIG_SPL_BUILD
366f56348afSSteve Sakoman/*
367f56348afSSteve Sakoman *************************************************************************
368f56348afSSteve Sakoman *
369f56348afSSteve Sakoman * Interrupt handling
370f56348afSSteve Sakoman *
371f56348afSSteve Sakoman *************************************************************************
372f56348afSSteve Sakoman */
373f56348afSSteve Sakoman@
374f56348afSSteve Sakoman@ IRQ stack frame.
375f56348afSSteve Sakoman@
376f56348afSSteve Sakoman#define S_FRAME_SIZE	72
377f56348afSSteve Sakoman
378f56348afSSteve Sakoman#define S_OLD_R0	68
379f56348afSSteve Sakoman#define S_PSR		64
380f56348afSSteve Sakoman#define S_PC		60
381f56348afSSteve Sakoman#define S_LR		56
382f56348afSSteve Sakoman#define S_SP		52
383f56348afSSteve Sakoman
384f56348afSSteve Sakoman#define S_IP		48
385f56348afSSteve Sakoman#define S_FP		44
386f56348afSSteve Sakoman#define S_R10		40
387f56348afSSteve Sakoman#define S_R9		36
388f56348afSSteve Sakoman#define S_R8		32
389f56348afSSteve Sakoman#define S_R7		28
390f56348afSSteve Sakoman#define S_R6		24
391f56348afSSteve Sakoman#define S_R5		20
392f56348afSSteve Sakoman#define S_R4		16
393f56348afSSteve Sakoman#define S_R3		12
394f56348afSSteve Sakoman#define S_R2		8
395f56348afSSteve Sakoman#define S_R1		4
396f56348afSSteve Sakoman#define S_R0		0
397f56348afSSteve Sakoman
398f56348afSSteve Sakoman#define MODE_SVC 0x13
399f56348afSSteve Sakoman#define I_BIT	 0x80
400f56348afSSteve Sakoman
401f56348afSSteve Sakoman/*
402f56348afSSteve Sakoman * use bad_save_user_regs for abort/prefetch/undef/swi ...
403f56348afSSteve Sakoman * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling
404f56348afSSteve Sakoman */
405f56348afSSteve Sakoman
406f56348afSSteve Sakoman	.macro	bad_save_user_regs
407f56348afSSteve Sakoman	sub	sp, sp, #S_FRAME_SIZE		@ carve out a frame on current
408f56348afSSteve Sakoman						@ user stack
409f56348afSSteve Sakoman	stmia	sp, {r0 - r12}			@ Save user registers (now in
410f56348afSSteve Sakoman						@ svc mode) r0-r12
411561142afSHeiko Schocher	ldr	r2, IRQ_STACK_START_IN		@ set base 2 words into abort
412f56348afSSteve Sakoman						@ stack
413f56348afSSteve Sakoman	ldmia	r2, {r2 - r3}			@ get values for "aborted" pc
414f56348afSSteve Sakoman						@ and cpsr (into parm regs)
415f56348afSSteve Sakoman	add	r0, sp, #S_FRAME_SIZE		@ grab pointer to old stack
416f56348afSSteve Sakoman
417f56348afSSteve Sakoman	add	r5, sp, #S_SP
418f56348afSSteve Sakoman	mov	r1, lr
419f56348afSSteve Sakoman	stmia	r5, {r0 - r3}			@ save sp_SVC, lr_SVC, pc, cpsr
420f56348afSSteve Sakoman	mov	r0, sp				@ save current stack into r0
421f56348afSSteve Sakoman						@ (param register)
422f56348afSSteve Sakoman	.endm
423f56348afSSteve Sakoman
424f56348afSSteve Sakoman	.macro	irq_save_user_regs
425f56348afSSteve Sakoman	sub	sp, sp, #S_FRAME_SIZE
426f56348afSSteve Sakoman	stmia	sp, {r0 - r12}			@ Calling r0-r12
427f56348afSSteve Sakoman	add	r8, sp, #S_PC			@ !! R8 NEEDS to be saved !!
428f56348afSSteve Sakoman						@ a reserved stack spot would
429f56348afSSteve Sakoman						@ be good.
430f56348afSSteve Sakoman	stmdb	r8, {sp, lr}^			@ Calling SP, LR
431f56348afSSteve Sakoman	str	lr, [r8, #0]			@ Save calling PC
432f56348afSSteve Sakoman	mrs	r6, spsr
433f56348afSSteve Sakoman	str	r6, [r8, #4]			@ Save CPSR
434f56348afSSteve Sakoman	str	r0, [r8, #8]			@ Save OLD_R0
435f56348afSSteve Sakoman	mov	r0, sp
436f56348afSSteve Sakoman	.endm
437f56348afSSteve Sakoman
438f56348afSSteve Sakoman	.macro	irq_restore_user_regs
439f56348afSSteve Sakoman	ldmia	sp, {r0 - lr}^			@ Calling r0 - lr
440f56348afSSteve Sakoman	mov	r0, r0
441f56348afSSteve Sakoman	ldr	lr, [sp, #S_PC]			@ Get PC
442f56348afSSteve Sakoman	add	sp, sp, #S_FRAME_SIZE
443f56348afSSteve Sakoman	subs	pc, lr, #4			@ return & move spsr_svc into
444f56348afSSteve Sakoman						@ cpsr
445f56348afSSteve Sakoman	.endm
446f56348afSSteve Sakoman
447f56348afSSteve Sakoman	.macro get_bad_stack
448561142afSHeiko Schocher	ldr	r13, IRQ_STACK_START_IN		@ setup our mode stack (enter
449561142afSHeiko Schocher						@ in banked mode)
450f56348afSSteve Sakoman
451f56348afSSteve Sakoman	str	lr, [r13]			@ save caller lr in position 0
452f56348afSSteve Sakoman						@ of saved stack
453f56348afSSteve Sakoman	mrs	lr, spsr			@ get the spsr
454f56348afSSteve Sakoman	str	lr, [r13, #4]			@ save spsr in position 1 of
455f56348afSSteve Sakoman						@ saved stack
456f56348afSSteve Sakoman
457f56348afSSteve Sakoman	mov	r13, #MODE_SVC			@ prepare SVC-Mode
458f56348afSSteve Sakoman	@ msr	spsr_c, r13
459f56348afSSteve Sakoman	msr	spsr, r13			@ switch modes, make sure
460f56348afSSteve Sakoman						@ moves will execute
461f56348afSSteve Sakoman	mov	lr, pc				@ capture return pc
462f56348afSSteve Sakoman	movs	pc, lr				@ jump to next instruction &
463f56348afSSteve Sakoman						@ switch modes.
464f56348afSSteve Sakoman	.endm
465f56348afSSteve Sakoman
466f56348afSSteve Sakoman	.macro get_bad_stack_swi
467f56348afSSteve Sakoman	sub	r13, r13, #4			@ space on current stack for
468f56348afSSteve Sakoman						@ scratch reg.
469f56348afSSteve Sakoman	str	r0, [r13]			@ save R0's value.
470561142afSHeiko Schocher	ldr	r0, IRQ_STACK_START_IN		@ get data regions start
471f56348afSSteve Sakoman						@ spots for abort stack
472f56348afSSteve Sakoman	str	lr, [r0]			@ save caller lr in position 0
473f56348afSSteve Sakoman						@ of saved stack
474f56348afSSteve Sakoman	mrs	r0, spsr			@ get the spsr
475f56348afSSteve Sakoman	str	lr, [r0, #4]			@ save spsr in position 1 of
476f56348afSSteve Sakoman						@ saved stack
477f56348afSSteve Sakoman	ldr	r0, [r13]			@ restore r0
478f56348afSSteve Sakoman	add	r13, r13, #4			@ pop stack entry
479f56348afSSteve Sakoman	.endm
480f56348afSSteve Sakoman
481f56348afSSteve Sakoman	.macro get_irq_stack			@ setup IRQ stack
482f56348afSSteve Sakoman	ldr	sp, IRQ_STACK_START
483f56348afSSteve Sakoman	.endm
484f56348afSSteve Sakoman
485f56348afSSteve Sakoman	.macro get_fiq_stack			@ setup FIQ stack
486f56348afSSteve Sakoman	ldr	sp, FIQ_STACK_START
487f56348afSSteve Sakoman	.endm
488f56348afSSteve Sakoman
489f56348afSSteve Sakoman/*
490f56348afSSteve Sakoman * exception handlers
491f56348afSSteve Sakoman */
492f56348afSSteve Sakoman	.align	5
493f56348afSSteve Sakomanundefined_instruction:
494f56348afSSteve Sakoman	get_bad_stack
495f56348afSSteve Sakoman	bad_save_user_regs
496f56348afSSteve Sakoman	bl	do_undefined_instruction
497f56348afSSteve Sakoman
498f56348afSSteve Sakoman	.align	5
499f56348afSSteve Sakomansoftware_interrupt:
500f56348afSSteve Sakoman	get_bad_stack_swi
501f56348afSSteve Sakoman	bad_save_user_regs
502f56348afSSteve Sakoman	bl	do_software_interrupt
503f56348afSSteve Sakoman
504f56348afSSteve Sakoman	.align	5
505f56348afSSteve Sakomanprefetch_abort:
506f56348afSSteve Sakoman	get_bad_stack
507f56348afSSteve Sakoman	bad_save_user_regs
508f56348afSSteve Sakoman	bl	do_prefetch_abort
509f56348afSSteve Sakoman
510f56348afSSteve Sakoman	.align	5
511f56348afSSteve Sakomandata_abort:
512f56348afSSteve Sakoman	get_bad_stack
513f56348afSSteve Sakoman	bad_save_user_regs
514f56348afSSteve Sakoman	bl	do_data_abort
515f56348afSSteve Sakoman
516f56348afSSteve Sakoman	.align	5
517f56348afSSteve Sakomannot_used:
518f56348afSSteve Sakoman	get_bad_stack
519f56348afSSteve Sakoman	bad_save_user_regs
520f56348afSSteve Sakoman	bl	do_not_used
521f56348afSSteve Sakoman
522f56348afSSteve Sakoman#ifdef CONFIG_USE_IRQ
523f56348afSSteve Sakoman
524f56348afSSteve Sakoman	.align	5
525f56348afSSteve Sakomanirq:
526f56348afSSteve Sakoman	get_irq_stack
527f56348afSSteve Sakoman	irq_save_user_regs
528f56348afSSteve Sakoman	bl	do_irq
529f56348afSSteve Sakoman	irq_restore_user_regs
530f56348afSSteve Sakoman
531f56348afSSteve Sakoman	.align	5
532f56348afSSteve Sakomanfiq:
533f56348afSSteve Sakoman	get_fiq_stack
534f56348afSSteve Sakoman	/* someone ought to write a more effective fiq_save_user_regs */
535f56348afSSteve Sakoman	irq_save_user_regs
536f56348afSSteve Sakoman	bl	do_fiq
537f56348afSSteve Sakoman	irq_restore_user_regs
538f56348afSSteve Sakoman
539f56348afSSteve Sakoman#else
540f56348afSSteve Sakoman
541f56348afSSteve Sakoman	.align	5
542f56348afSSteve Sakomanirq:
543f56348afSSteve Sakoman	get_bad_stack
544f56348afSSteve Sakoman	bad_save_user_regs
545f56348afSSteve Sakoman	bl	do_irq
546f56348afSSteve Sakoman
547f56348afSSteve Sakoman	.align	5
548f56348afSSteve Sakomanfiq:
549f56348afSSteve Sakoman	get_bad_stack
550f56348afSSteve Sakoman	bad_save_user_regs
551f56348afSSteve Sakoman	bl	do_fiq
552f56348afSSteve Sakoman
553033ca724SAneesh V#endif /* CONFIG_USE_IRQ */
554033ca724SAneesh V#endif /* CONFIG_SPL_BUILD */
555