blob: d8072417d8db49aef2a1b4bbca5ce634cc75a71e [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
Marek Vasut20f7b1b2011-10-31 14:12:39 +01002 * armboot - Startup Code for XScale CPU-core
wdenkc6097192002-11-03 00:24:07 +00003 *
4 * Copyright (C) 1998 Dan Malek <dmalek@jlc.net>
5 * Copyright (C) 1999 Magnus Damm <kieraypc01.p.y.kie.era.ericsson.se>
6 * Copyright (C) 2000 Wolfgang Denk <wd@denx.de>
wdenka8c7c702003-12-06 19:49:23 +00007 * Copyright (C) 2001 Alex Zuepke <azu@sysgo.de>
Marek Vasut20f7b1b2011-10-31 14:12:39 +01008 * Copyright (C) 2001 Marius Groger <mag@sysgo.de>
9 * Copyright (C) 2002 Alex Zupke <azu@sysgo.de>
10 * Copyright (C) 2002 Gary Jennejohn <garyj@denx.de>
wdenk1cb8e982003-03-06 21:55:29 +000011 * Copyright (C) 2002 Kyle Harris <kharris@nexus-tech.net>
Wolfgang Denk951a9542006-03-06 23:18:48 +010012 * Copyright (C) 2003 Kai-Uwe Bloem <kai-uwe.bloem@auerswald.de>
Marek Vasut20f7b1b2011-10-31 14:12:39 +010013 * Copyright (C) 2003 Kshitij <kshitij@ti.com>
14 * Copyright (C) 2003 Richard Woodruff <r-woodruff2@ti.com>
15 * Copyright (C) 2003 Robert Schwebel <r.schwebel@pengutronix.de>
16 * Copyright (C) 2004 Texas Instruments <r-woodruff2@ti.com>
17 * Copyright (C) 2010 Marek Vasut <marek.vasut@gmail.com>
wdenkc6097192002-11-03 00:24:07 +000018 *
19 * See file CREDITS for list of people who contributed to this
20 * project.
21 *
22 * This program is free software; you can redistribute it and/or
23 * modify it under the terms of the GNU General Public License as
24 * published by the Free Software Foundation; either version 2 of
25 * the License, or (at your option) any later version.
26 *
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
wdenk384ae022002-11-05 00:17:55 +000029 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wdenkc6097192002-11-03 00:24:07 +000030 * GNU General Public License for more details.
31 *
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
35 * MA 02111-1307 USA
36 */
37
Wolfgang Denk25ddd1f2010-10-26 14:34:52 +020038#include <asm-offsets.h>
wdenkc6097192002-11-03 00:24:07 +000039#include <config.h>
40#include <version.h>
Marek Vasut7f4cfcf2011-11-05 19:26:47 +010041
Marek Vasutabc20ab2011-11-26 07:20:07 +010042#ifdef CONFIG_CPU_PXA25X
Marek Vasut7f4cfcf2011-11-05 19:26:47 +010043#if ((CONFIG_SYS_INIT_SP_ADDR) != 0xfffff800)
44#error "Init SP address must be set to 0xfffff800 for PXA250"
45#endif
46#endif
47
wdenkc6097192002-11-03 00:24:07 +000048.globl _start
wdenk384ae022002-11-05 00:17:55 +000049_start: b reset
Aneesh V401bb302011-07-13 05:11:07 +000050#ifdef CONFIG_SPL_BUILD
Marek Vasut5ab877b2010-07-06 02:48:35 +020051 ldr pc, _hang
52 ldr pc, _hang
53 ldr pc, _hang
54 ldr pc, _hang
55 ldr pc, _hang
56 ldr pc, _hang
57 ldr pc, _hang
58
59_hang:
60 .word do_hang
61 .word 0x12345678
62 .word 0x12345678
63 .word 0x12345678
64 .word 0x12345678
65 .word 0x12345678
66 .word 0x12345678
67 .word 0x12345678 /* now 16*4=64 */
68#else
wdenkc6097192002-11-03 00:24:07 +000069 ldr pc, _undefined_instruction
70 ldr pc, _software_interrupt
71 ldr pc, _prefetch_abort
72 ldr pc, _data_abort
73 ldr pc, _not_used
74 ldr pc, _irq
75 ldr pc, _fiq
76
wdenk384ae022002-11-05 00:17:55 +000077_undefined_instruction: .word undefined_instruction
wdenkc6097192002-11-03 00:24:07 +000078_software_interrupt: .word software_interrupt
79_prefetch_abort: .word prefetch_abort
80_data_abort: .word data_abort
81_not_used: .word not_used
82_irq: .word irq
83_fiq: .word fiq
Marek Vasut20f7b1b2011-10-31 14:12:39 +010084_pad: .word 0x12345678 /* now 16*4=64 */
Aneesh V401bb302011-07-13 05:11:07 +000085#endif /* CONFIG_SPL_BUILD */
Marek Vasut20f7b1b2011-10-31 14:12:39 +010086.global _end_vect
87_end_vect:
wdenkc6097192002-11-03 00:24:07 +000088
89 .balignl 16,0xdeadbeef
wdenkc6097192002-11-03 00:24:07 +000090/*
Marek Vasut20f7b1b2011-10-31 14:12:39 +010091 *************************************************************************
92 *
wdenkc6097192002-11-03 00:24:07 +000093 * Startup Code (reset vector)
94 *
Marek Vasut20f7b1b2011-10-31 14:12:39 +010095 * do important init only if we don't start from memory!
96 * setup Memory and board specific bits prior to relocation.
97 * relocate armboot to ram
98 * setup stack
99 *
100 *************************************************************************
wdenkc6097192002-11-03 00:24:07 +0000101 */
102
Heiko Schocher5347f682010-09-17 13:10:46 +0200103.globl _TEXT_BASE
wdenkc6097192002-11-03 00:24:07 +0000104_TEXT_BASE:
Benoît Thébaudeau508611b2013-04-11 09:35:42 +0000105#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_TEXT_BASE)
Marek Vasut20f7b1b2011-10-31 14:12:39 +0100106 .word CONFIG_SPL_TEXT_BASE
107#else
Wolfgang Denk14d0a022010-10-07 21:51:12 +0200108 .word CONFIG_SYS_TEXT_BASE
Marek Vasut20f7b1b2011-10-31 14:12:39 +0100109#endif
wdenkc6097192002-11-03 00:24:07 +0000110
wdenkc6097192002-11-03 00:24:07 +0000111/*
wdenkf6e20fc2004-02-08 19:38:38 +0000112 * These are defined in the board-specific linker script.
Marek Vasut20f7b1b2011-10-31 14:12:39 +0100113 * Subtracting _start from them lets the linker put their
114 * relative position in the executable instead of leaving
115 * them null.
wdenk47cd00f2003-03-06 13:39:27 +0000116 */
Marek Vasut6e96cf92010-10-20 19:36:39 +0200117.globl _bss_start_ofs
118_bss_start_ofs:
119 .word __bss_start - _start
wdenk47cd00f2003-03-06 13:39:27 +0000120
Marek Vasut6e96cf92010-10-20 19:36:39 +0200121.globl _bss_end_ofs
122_bss_end_ofs:
Simon Glass3929fb02013-03-14 06:54:53 +0000123 .word __bss_end - _start
wdenk47cd00f2003-03-06 13:39:27 +0000124
Po-Yu Chuangf326cbb2011-03-01 23:02:04 +0000125.globl _end_ofs
126_end_ofs:
127 .word _end - _start
128
wdenkc6097192002-11-03 00:24:07 +0000129#ifdef CONFIG_USE_IRQ
130/* IRQ stack memory (calculated at run-time) */
131.globl IRQ_STACK_START
132IRQ_STACK_START:
133 .word 0x0badc0de
134
135/* IRQ stack memory (calculated at run-time) */
136.globl FIQ_STACK_START
137FIQ_STACK_START:
138 .word 0x0badc0de
Marek Vasut20f7b1b2011-10-31 14:12:39 +0100139#endif
wdenkc6097192002-11-03 00:24:07 +0000140
Heiko Schocher5347f682010-09-17 13:10:46 +0200141/* IRQ stack memory (calculated at run-time) + 8 bytes */
142.globl IRQ_STACK_START_IN
143IRQ_STACK_START_IN:
144 .word 0x0badc0de
145
Heiko Schocher5347f682010-09-17 13:10:46 +0200146/*
147 * the actual reset code
148 */
149
150reset:
151 /*
152 * set the cpu to SVC32 mode
153 */
154 mrs r0,cpsr
155 bic r0,r0,#0x1f
156 orr r0,r0,#0xd3
157 msr cpsr,r0
158
Marek Vasut20f7b1b2011-10-31 14:12:39 +0100159#ifndef CONFIG_SKIP_LOWLEVEL_INIT
160 bl cpu_init_crit
161#endif
Heiko Schocher5347f682010-09-17 13:10:46 +0200162
Marek Vasutabc20ab2011-11-26 07:20:07 +0100163#ifdef CONFIG_CPU_PXA25X
Marek Vasut7f4cfcf2011-11-05 19:26:47 +0100164 bl lock_cache_for_stack
165#endif
166
Albert ARIBAUDe05e5de2013-01-08 10:18:02 +0000167 bl _main
Heiko Schocher5347f682010-09-17 13:10:46 +0200168
169/*------------------------------------------------------------------------------*/
Marek Vasut20f7b1b2011-10-31 14:12:39 +0100170#ifndef CONFIG_SPL_BUILD
Heiko Schocher5347f682010-09-17 13:10:46 +0200171/*
172 * void relocate_code (addr_sp, gd, addr_moni)
173 *
Benoît Thébaudeau959eaa72013-04-11 09:35:43 +0000174 * This function relocates the monitor code.
Heiko Schocher5347f682010-09-17 13:10:46 +0200175 */
176 .globl relocate_code
177relocate_code:
178 mov r4, r0 /* save addr_sp */
179 mov r5, r1 /* save addr of gd */
180 mov r6, r2 /* save addr of destination */
Heiko Schocher5347f682010-09-17 13:10:46 +0200181
Marek Vasut7f4cfcf2011-11-05 19:26:47 +0100182/* Disable the Dcache RAM lock for stack now */
Marek Vasutabc20ab2011-11-26 07:20:07 +0100183#ifdef CONFIG_CPU_PXA25X
Łukasz Dałekdf3ad6c2013-01-12 11:39:27 +0000184 mov r12, lr
Marek Vasut7f4cfcf2011-11-05 19:26:47 +0100185 bl cpu_init_crit
Łukasz Dałekdf3ad6c2013-01-12 11:39:27 +0000186 mov lr, r12
Marek Vasut7f4cfcf2011-11-05 19:26:47 +0100187#endif
188
Heiko Schocher5347f682010-09-17 13:10:46 +0200189 adr r0, _start
Benoît Thébaudeau4b3db1c2013-04-11 09:35:45 +0000190 subs r9, r6, r0 /* r9 <- relocation offset */
Albert ARIBAUDe05e5de2013-01-08 10:18:02 +0000191 beq relocate_done /* skip relocation */
Andreas Bießmanna78fb682010-12-01 00:58:33 +0100192 mov r1, r6 /* r1 <- scratch for copy_loop */
Marek Vasut6e96cf92010-10-20 19:36:39 +0200193 ldr r3, _bss_start_ofs
194 add r2, r0, r3 /* r2 <- source end address */
Heiko Schocher5347f682010-09-17 13:10:46 +0200195
Heiko Schocher5347f682010-09-17 13:10:46 +0200196copy_loop:
Benoît Thébaudeau4b3db1c2013-04-11 09:35:45 +0000197 ldmia r0!, {r10-r11} /* copy from source address [r0] */
198 stmia r1!, {r10-r11} /* copy to target address [r1] */
Albert Aribaudda90d4c2010-10-05 16:06:39 +0200199 cmp r0, r2 /* until source end address [r2] */
200 blo copy_loop
Heiko Schocher5347f682010-09-17 13:10:46 +0200201
Aneesh V401bb302011-07-13 05:11:07 +0000202#ifndef CONFIG_SPL_BUILD
Marek Vasut6e96cf92010-10-20 19:36:39 +0200203 /*
204 * fix .rel.dyn relocations
205 */
206 ldr r0, _TEXT_BASE /* r0 <- Text base */
Marek Vasut6e96cf92010-10-20 19:36:39 +0200207 ldr r10, _dynsym_start_ofs /* r10 <- sym table ofs */
208 add r10, r10, r0 /* r10 <- sym table in FLASH */
209 ldr r2, _rel_dyn_start_ofs /* r2 <- rel dyn start ofs */
210 add r2, r2, r0 /* r2 <- rel dyn start in FLASH */
211 ldr r3, _rel_dyn_end_ofs /* r3 <- rel dyn end ofs */
212 add r3, r3, r0 /* r3 <- rel dyn end in FLASH */
Heiko Schocher5347f682010-09-17 13:10:46 +0200213fixloop:
Marek Vasut20f7b1b2011-10-31 14:12:39 +0100214 ldr r0, [r2] /* r0 <- location to fix up, IN FLASH! */
215 add r0, r0, r9 /* r0 <- location to fix up in RAM */
Marek Vasut6e96cf92010-10-20 19:36:39 +0200216 ldr r1, [r2, #4]
Andreas Bießmann1f52d892010-12-01 00:58:35 +0100217 and r7, r1, #0xff
Marek Vasut20f7b1b2011-10-31 14:12:39 +0100218 cmp r7, #23 /* relative fixup? */
Marek Vasut6e96cf92010-10-20 19:36:39 +0200219 beq fixrel
Marek Vasut20f7b1b2011-10-31 14:12:39 +0100220 cmp r7, #2 /* absolute fixup? */
Marek Vasut6e96cf92010-10-20 19:36:39 +0200221 beq fixabs
222 /* ignore unknown type of fixup */
223 b fixnext
224fixabs:
225 /* absolute fix: set location to (offset) symbol value */
226 mov r1, r1, LSR #4 /* r1 <- symbol index in .dynsym */
227 add r1, r10, r1 /* r1 <- address of symbol in table */
228 ldr r1, [r1, #4] /* r1 <- symbol value */
Wolfgang Denk36009452010-12-09 11:26:24 +0100229 add r1, r1, r9 /* r1 <- relocated sym addr */
Marek Vasut6e96cf92010-10-20 19:36:39 +0200230 b fixnext
231fixrel:
232 /* relative fix: increase location by offset */
233 ldr r1, [r0]
234 add r1, r1, r9
235fixnext:
236 str r1, [r0]
Marek Vasut20f7b1b2011-10-31 14:12:39 +0100237 add r2, r2, #8 /* each rel.dyn entry is 8 bytes */
Heiko Schocher5347f682010-09-17 13:10:46 +0200238 cmp r2, r3
Marek Vasut6e96cf92010-10-20 19:36:39 +0200239 blo fixloop
Marek Vasut20f7b1b2011-10-31 14:12:39 +0100240#endif
Heiko Schocher5347f682010-09-17 13:10:46 +0200241
Albert ARIBAUDe05e5de2013-01-08 10:18:02 +0000242relocate_done:
Heiko Schocher5347f682010-09-17 13:10:46 +0200243
Albert ARIBAUDe05e5de2013-01-08 10:18:02 +0000244 bx lr
Heiko Schocher5347f682010-09-17 13:10:46 +0200245
Marek Vasut6e96cf92010-10-20 19:36:39 +0200246_rel_dyn_start_ofs:
247 .word __rel_dyn_start - _start
248_rel_dyn_end_ofs:
249 .word __rel_dyn_end - _start
250_dynsym_start_ofs:
251 .word __dynsym_start - _start
Albert ARIBAUDe05e5de2013-01-08 10:18:02 +0000252
Marek Vasut2cad92f2010-09-28 15:44:10 +0200253#endif
Albert ARIBAUDe05e5de2013-01-08 10:18:02 +0000254
255 .globl c_runtime_cpu_setup
256c_runtime_cpu_setup:
257
258 bx lr
259
Marek Vasut20f7b1b2011-10-31 14:12:39 +0100260/*
261 *************************************************************************
262 *
263 * CPU_init_critical registers
264 *
265 * setup important registers
266 * setup memory timing
267 *
268 *************************************************************************
269 */
Marek Vasutabc20ab2011-11-26 07:20:07 +0100270#if !defined(CONFIG_SKIP_LOWLEVEL_INIT) || defined(CONFIG_CPU_PXA25X)
Marek Vasut20f7b1b2011-10-31 14:12:39 +0100271cpu_init_crit:
272 /*
273 * flush v4 I/D caches
274 */
275 mov r0, #0
276 mcr p15, 0, r0, c7, c7, 0 /* Invalidate I+D+BTB caches */
277 mcr p15, 0, r0, c8, c7, 0 /* Invalidate Unified TLB */
Marek Vasut2cad92f2010-09-28 15:44:10 +0200278
Marek Vasut20f7b1b2011-10-31 14:12:39 +0100279 /*
280 * disable MMU stuff and caches
281 */
282 mrc p15, 0, r0, c1, c0, 0
283 bic r0, r0, #0x00002300 @ clear bits 13, 9:8 (--V- --RS)
284 bic r0, r0, #0x00000087 @ clear bits 7, 2:0 (B--- -CAM)
285 orr r0, r0, #0x00000002 @ set bit 2 (A) Align
286 orr r0, r0, #0x00001000 @ set bit 12 (I) I-Cache
287 mcr p15, 0, r0, c1, c0, 0
wdenkc6097192002-11-03 00:24:07 +0000288
Marek Vasut20f7b1b2011-10-31 14:12:39 +0100289 mov pc, lr /* back to my caller */
Marek Vasutabc20ab2011-11-26 07:20:07 +0100290#endif /* !CONFIG_SKIP_LOWLEVEL_INIT || CONFIG_CPU_PXA25X */
wdenkc6097192002-11-03 00:24:07 +0000291
Aneesh V401bb302011-07-13 05:11:07 +0000292#ifndef CONFIG_SPL_BUILD
Marek Vasut20f7b1b2011-10-31 14:12:39 +0100293/*
294 *************************************************************************
295 *
296 * Interrupt handling
297 *
298 *************************************************************************
299 */
300@
301@ IRQ stack frame.
302@
wdenkc6097192002-11-03 00:24:07 +0000303#define S_FRAME_SIZE 72
304
305#define S_OLD_R0 68
306#define S_PSR 64
307#define S_PC 60
308#define S_LR 56
309#define S_SP 52
310
311#define S_IP 48
312#define S_FP 44
313#define S_R10 40
314#define S_R9 36
315#define S_R8 32
316#define S_R7 28
317#define S_R6 24
318#define S_R5 20
319#define S_R4 16
320#define S_R3 12
321#define S_R2 8
322#define S_R1 4
323#define S_R0 0
324
325#define MODE_SVC 0x13
Marek Vasut20f7b1b2011-10-31 14:12:39 +0100326#define I_BIT 0x80
wdenkc6097192002-11-03 00:24:07 +0000327
Marek Vasut20f7b1b2011-10-31 14:12:39 +0100328/*
329 * use bad_save_user_regs for abort/prefetch/undef/swi ...
330 * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling
331 */
wdenkc6097192002-11-03 00:24:07 +0000332
333 .macro bad_save_user_regs
Marek Vasut20f7b1b2011-10-31 14:12:39 +0100334 sub sp, sp, #S_FRAME_SIZE @ carve out a frame on current user stack
335 stmia sp, {r0 - r12} @ Save user registers (now in svc mode) r0-r12
wdenkc6097192002-11-03 00:24:07 +0000336
Marek Vasut20f7b1b2011-10-31 14:12:39 +0100337 ldr r2, IRQ_STACK_START_IN @ set base 2 words into abort stack
338 ldmia r2, {r2 - r3} @ get values for "aborted" pc and cpsr (into parm regs)
339 add r0, sp, #S_FRAME_SIZE @ grab pointer to old stack
wdenkc6097192002-11-03 00:24:07 +0000340
341 add r5, sp, #S_SP
342 mov r1, lr
Marek Vasut20f7b1b2011-10-31 14:12:39 +0100343 stmia r5, {r0 - r3} @ save sp_SVC, lr_SVC, pc, cpsr
344 mov r0, sp @ save current stack into r0 (param register)
wdenkc6097192002-11-03 00:24:07 +0000345 .endm
346
wdenkc6097192002-11-03 00:24:07 +0000347 .macro irq_save_user_regs
348 sub sp, sp, #S_FRAME_SIZE
Marek Vasut20f7b1b2011-10-31 14:12:39 +0100349 stmia sp, {r0 - r12} @ Calling r0-r12
350 add r8, sp, #S_PC @ !!!! R8 NEEDS to be saved !!!! a reserved stack spot would be good.
351 stmdb r8, {sp, lr}^ @ Calling SP, LR
352 str lr, [r8, #0] @ Save calling PC
wdenk384ae022002-11-05 00:17:55 +0000353 mrs r6, spsr
Marek Vasut20f7b1b2011-10-31 14:12:39 +0100354 str r6, [r8, #4] @ Save CPSR
355 str r0, [r8, #8] @ Save OLD_R0
wdenkc6097192002-11-03 00:24:07 +0000356 mov r0, sp
357 .endm
358
359 .macro irq_restore_user_regs
360 ldmia sp, {r0 - lr}^ @ Calling r0 - lr
361 mov r0, r0
362 ldr lr, [sp, #S_PC] @ Get PC
363 add sp, sp, #S_FRAME_SIZE
364 subs pc, lr, #4 @ return & move spsr_svc into cpsr
365 .endm
366
367 .macro get_bad_stack
Marek Vasut20f7b1b2011-10-31 14:12:39 +0100368 ldr r13, IRQ_STACK_START_IN @ setup our mode stack (enter in banked mode)
wdenkc6097192002-11-03 00:24:07 +0000369
Marek Vasut20f7b1b2011-10-31 14:12:39 +0100370 str lr, [r13] @ save caller lr in position 0 of saved stack
371 mrs lr, spsr @ get the spsr
372 str lr, [r13, #4] @ save spsr in position 1 of saved stack
wdenkc6097192002-11-03 00:24:07 +0000373
374 mov r13, #MODE_SVC @ prepare SVC-Mode
Marek Vasut20f7b1b2011-10-31 14:12:39 +0100375 @ msr spsr_c, r13
376 msr spsr, r13 @ switch modes, make sure moves will execute
377 mov lr, pc @ capture return pc
378 movs pc, lr @ jump to next instruction & switch modes.
379 .endm
380
381 .macro get_bad_stack_swi
382 sub r13, r13, #4 @ space on current stack for scratch reg.
383 str r0, [r13] @ save R0's value.
384 ldr r0, IRQ_STACK_START_IN @ get data regions start
385 str lr, [r0] @ save caller lr in position 0 of saved stack
386 mrs r0, spsr @ get the spsr
387 str lr, [r0, #4] @ save spsr in position 1 of saved stack
388 ldr r0, [r13] @ restore r0
389 add r13, r13, #4 @ pop stack entry
wdenkc6097192002-11-03 00:24:07 +0000390 .endm
391
392 .macro get_irq_stack @ setup IRQ stack
393 ldr sp, IRQ_STACK_START
394 .endm
395
396 .macro get_fiq_stack @ setup FIQ stack
397 ldr sp, FIQ_STACK_START
398 .endm
Marek Vasut20f7b1b2011-10-31 14:12:39 +0100399#endif /* CONFIG_SPL_BUILD */
wdenkc6097192002-11-03 00:24:07 +0000400
Marek Vasut20f7b1b2011-10-31 14:12:39 +0100401/*
402 * exception handlers
403 */
Aneesh V401bb302011-07-13 05:11:07 +0000404#ifdef CONFIG_SPL_BUILD
Marek Vasut5ab877b2010-07-06 02:48:35 +0200405 .align 5
406do_hang:
Marek Vasut20f7b1b2011-10-31 14:12:39 +0100407 ldr sp, _TEXT_BASE /* use 32 words about stack */
Marek Vasut5ab877b2010-07-06 02:48:35 +0200408 bl hang /* hang and never return */
Marek Vasut20f7b1b2011-10-31 14:12:39 +0100409#else /* !CONFIG_SPL_BUILD */
wdenk384ae022002-11-05 00:17:55 +0000410 .align 5
wdenkc6097192002-11-03 00:24:07 +0000411undefined_instruction:
412 get_bad_stack
413 bad_save_user_regs
wdenk384ae022002-11-05 00:17:55 +0000414 bl do_undefined_instruction
wdenkc6097192002-11-03 00:24:07 +0000415
416 .align 5
417software_interrupt:
Marek Vasut20f7b1b2011-10-31 14:12:39 +0100418 get_bad_stack_swi
wdenkc6097192002-11-03 00:24:07 +0000419 bad_save_user_regs
wdenk384ae022002-11-05 00:17:55 +0000420 bl do_software_interrupt
wdenkc6097192002-11-03 00:24:07 +0000421
422 .align 5
423prefetch_abort:
424 get_bad_stack
425 bad_save_user_regs
wdenk384ae022002-11-05 00:17:55 +0000426 bl do_prefetch_abort
wdenkc6097192002-11-03 00:24:07 +0000427
428 .align 5
429data_abort:
430 get_bad_stack
431 bad_save_user_regs
wdenk384ae022002-11-05 00:17:55 +0000432 bl do_data_abort
wdenkc6097192002-11-03 00:24:07 +0000433
434 .align 5
435not_used:
436 get_bad_stack
437 bad_save_user_regs
wdenk384ae022002-11-05 00:17:55 +0000438 bl do_not_used
wdenkc6097192002-11-03 00:24:07 +0000439
440#ifdef CONFIG_USE_IRQ
441
442 .align 5
443irq:
444 get_irq_stack
445 irq_save_user_regs
wdenk384ae022002-11-05 00:17:55 +0000446 bl do_irq
wdenkc6097192002-11-03 00:24:07 +0000447 irq_restore_user_regs
448
449 .align 5
450fiq:
451 get_fiq_stack
Marek Vasut20f7b1b2011-10-31 14:12:39 +0100452 /* someone ought to write a more effiction fiq_save_user_regs */
453 irq_save_user_regs
454 bl do_fiq
wdenkc6097192002-11-03 00:24:07 +0000455 irq_restore_user_regs
456
Marek Vasut20f7b1b2011-10-31 14:12:39 +0100457#else
wdenkc6097192002-11-03 00:24:07 +0000458
459 .align 5
460irq:
461 get_bad_stack
462 bad_save_user_regs
wdenk384ae022002-11-05 00:17:55 +0000463 bl do_irq
wdenkc6097192002-11-03 00:24:07 +0000464
465 .align 5
466fiq:
467 get_bad_stack
468 bad_save_user_regs
wdenk384ae022002-11-05 00:17:55 +0000469 bl do_fiq
wdenkc6097192002-11-03 00:24:07 +0000470
Marek Vasut20f7b1b2011-10-31 14:12:39 +0100471#endif
472 .align 5
Aneesh V401bb302011-07-13 05:11:07 +0000473#endif /* CONFIG_SPL_BUILD */
Marek Vasut7f4cfcf2011-11-05 19:26:47 +0100474
475
476/*
477 * Enable MMU to use DCache as DRAM.
478 *
479 * This is useful on PXA25x and PXA26x in early bootstages, where there is no
480 * other possible memory available to hold stack.
481 */
Marek Vasutabc20ab2011-11-26 07:20:07 +0100482#ifdef CONFIG_CPU_PXA25X
Marek Vasut7f4cfcf2011-11-05 19:26:47 +0100483.macro CPWAIT reg
484 mrc p15, 0, \reg, c2, c0, 0
485 mov \reg, \reg
486 sub pc, pc, #4
487.endm
488lock_cache_for_stack:
489 /* Domain access -- enable for all CPs */
490 ldr r0, =0x0000ffff
491 mcr p15, 0, r0, c3, c0, 0
492
493 /* Point TTBR to MMU table */
494 ldr r0, =mmutable
495 mcr p15, 0, r0, c2, c0, 0
496
497 /* Kick in MMU, ICache, DCache, BTB */
498 mrc p15, 0, r0, c1, c0, 0
499 bic r0, #0x1b00
500 bic r0, #0x0087
501 orr r0, #0x1800
502 orr r0, #0x0005
503 mcr p15, 0, r0, c1, c0, 0
504 CPWAIT r0
505
506 /* Unlock Icache, Dcache */
507 mcr p15, 0, r0, c9, c1, 1
508 mcr p15, 0, r0, c9, c2, 1
509
510 /* Flush Icache, Dcache, BTB */
511 mcr p15, 0, r0, c7, c7, 0
512
513 /* Unlock I-TLB, D-TLB */
514 mcr p15, 0, r0, c10, c4, 1
515 mcr p15, 0, r0, c10, c8, 1
516
517 /* Flush TLB */
518 mcr p15, 0, r0, c8, c7, 0
519
520 /* Allocate 4096 bytes of Dcache as RAM */
521
522 /* Drain pending loads and stores */
523 mcr p15, 0, r0, c7, c10, 4
524
525 mov r4, #0x00
526 mov r5, #0x00
527 mov r2, #0x01
528 mcr p15, 0, r0, c9, c2, 0
529 CPWAIT r0
530
531 /* 128 lines reserved (128 x 32bytes = 4096 bytes total) */
532 mov r0, #128
533 ldr r1, =0xfffff000
534
535alloc:
536 mcr p15, 0, r1, c7, c2, 5
537 /* Drain pending loads and stores */
538 mcr p15, 0, r0, c7, c10, 4
539 strd r4, [r1], #8
540 strd r4, [r1], #8
541 strd r4, [r1], #8
542 strd r4, [r1], #8
543 subs r0, #0x01
544 bne alloc
545 /* Drain pending loads and stores */
546 mcr p15, 0, r0, c7, c10, 4
547 mov r2, #0x00
548 mcr p15, 0, r2, c9, c2, 0
549 CPWAIT r0
550
551 mov pc, lr
552
553.section .mmutable, "a"
554mmutable:
555 .align 14
556 /* 0x00000000 - 0xffe00000 : 1:1, uncached mapping */
557 .set __base, 0
558 .rept 0xfff
559 .word (__base << 20) | 0xc12
560 .set __base, __base + 1
561 .endr
562
563 /* 0xfff00000 : 1:1, cached mapping */
564 .word (0xfff << 20) | 0x1c1e
Marek Vasutabc20ab2011-11-26 07:20:07 +0100565#endif /* CONFIG_CPU_PXA25X */