wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1 | /* |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 2 | * armboot - Startup Code for XScale CPU-core |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 3 | * |
| 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> |
wdenk | a8c7c70 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 7 | * Copyright (C) 2001 Alex Zuepke <azu@sysgo.de> |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 8 | * 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> |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 11 | * Copyright (C) 2002 Kyle Harris <kharris@nexus-tech.net> |
Wolfgang Denk | 951a954 | 2006-03-06 23:18:48 +0100 | [diff] [blame] | 12 | * Copyright (C) 2003 Kai-Uwe Bloem <kai-uwe.bloem@auerswald.de> |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 13 | * 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> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 18 | * |
| 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 |
wdenk | 384ae02 | 2002-11-05 00:17:55 +0000 | [diff] [blame] | 29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 30 | * 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 Denk | 25ddd1f | 2010-10-26 14:34:52 +0200 | [diff] [blame] | 38 | #include <asm-offsets.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 39 | #include <config.h> |
| 40 | #include <version.h> |
Marek Vasut | 7f4cfcf | 2011-11-05 19:26:47 +0100 | [diff] [blame] | 41 | |
Marek Vasut | abc20ab | 2011-11-26 07:20:07 +0100 | [diff] [blame] | 42 | #ifdef CONFIG_CPU_PXA25X |
Marek Vasut | 7f4cfcf | 2011-11-05 19:26:47 +0100 | [diff] [blame] | 43 | #if ((CONFIG_SYS_INIT_SP_ADDR) != 0xfffff800) |
| 44 | #error "Init SP address must be set to 0xfffff800 for PXA250" |
| 45 | #endif |
| 46 | #endif |
| 47 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 48 | .globl _start |
wdenk | 384ae02 | 2002-11-05 00:17:55 +0000 | [diff] [blame] | 49 | _start: b reset |
Aneesh V | 401bb30 | 2011-07-13 05:11:07 +0000 | [diff] [blame] | 50 | #ifdef CONFIG_SPL_BUILD |
Marek Vasut | 5ab877b | 2010-07-06 02:48:35 +0200 | [diff] [blame] | 51 | 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 |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 69 | 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 | |
wdenk | 384ae02 | 2002-11-05 00:17:55 +0000 | [diff] [blame] | 77 | _undefined_instruction: .word undefined_instruction |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 78 | _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 Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 84 | _pad: .word 0x12345678 /* now 16*4=64 */ |
Aneesh V | 401bb30 | 2011-07-13 05:11:07 +0000 | [diff] [blame] | 85 | #endif /* CONFIG_SPL_BUILD */ |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 86 | .global _end_vect |
| 87 | _end_vect: |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 88 | |
| 89 | .balignl 16,0xdeadbeef |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 90 | /* |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 91 | ************************************************************************* |
| 92 | * |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 93 | * Startup Code (reset vector) |
| 94 | * |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 95 | * 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 | ************************************************************************* |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 101 | */ |
| 102 | |
Heiko Schocher | 5347f68 | 2010-09-17 13:10:46 +0200 | [diff] [blame] | 103 | .globl _TEXT_BASE |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 104 | _TEXT_BASE: |
Benoît Thébaudeau | 508611b | 2013-04-11 09:35:42 +0000 | [diff] [blame] | 105 | #if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_TEXT_BASE) |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 106 | .word CONFIG_SPL_TEXT_BASE |
| 107 | #else |
Wolfgang Denk | 14d0a02 | 2010-10-07 21:51:12 +0200 | [diff] [blame] | 108 | .word CONFIG_SYS_TEXT_BASE |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 109 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 110 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 111 | /* |
wdenk | f6e20fc | 2004-02-08 19:38:38 +0000 | [diff] [blame] | 112 | * These are defined in the board-specific linker script. |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 113 | * Subtracting _start from them lets the linker put their |
| 114 | * relative position in the executable instead of leaving |
| 115 | * them null. |
wdenk | 47cd00f | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 116 | */ |
Marek Vasut | 6e96cf9 | 2010-10-20 19:36:39 +0200 | [diff] [blame] | 117 | .globl _bss_start_ofs |
| 118 | _bss_start_ofs: |
| 119 | .word __bss_start - _start |
wdenk | 47cd00f | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 120 | |
Marek Vasut | 6e96cf9 | 2010-10-20 19:36:39 +0200 | [diff] [blame] | 121 | .globl _bss_end_ofs |
| 122 | _bss_end_ofs: |
Simon Glass | 3929fb0 | 2013-03-14 06:54:53 +0000 | [diff] [blame] | 123 | .word __bss_end - _start |
wdenk | 47cd00f | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 124 | |
Po-Yu Chuang | f326cbb | 2011-03-01 23:02:04 +0000 | [diff] [blame] | 125 | .globl _end_ofs |
| 126 | _end_ofs: |
| 127 | .word _end - _start |
| 128 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 129 | #ifdef CONFIG_USE_IRQ |
| 130 | /* IRQ stack memory (calculated at run-time) */ |
| 131 | .globl IRQ_STACK_START |
| 132 | IRQ_STACK_START: |
| 133 | .word 0x0badc0de |
| 134 | |
| 135 | /* IRQ stack memory (calculated at run-time) */ |
| 136 | .globl FIQ_STACK_START |
| 137 | FIQ_STACK_START: |
| 138 | .word 0x0badc0de |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 139 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 140 | |
Heiko Schocher | 5347f68 | 2010-09-17 13:10:46 +0200 | [diff] [blame] | 141 | /* IRQ stack memory (calculated at run-time) + 8 bytes */ |
| 142 | .globl IRQ_STACK_START_IN |
| 143 | IRQ_STACK_START_IN: |
| 144 | .word 0x0badc0de |
| 145 | |
Heiko Schocher | 5347f68 | 2010-09-17 13:10:46 +0200 | [diff] [blame] | 146 | /* |
| 147 | * the actual reset code |
| 148 | */ |
| 149 | |
| 150 | reset: |
| 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 Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 159 | #ifndef CONFIG_SKIP_LOWLEVEL_INIT |
| 160 | bl cpu_init_crit |
| 161 | #endif |
Heiko Schocher | 5347f68 | 2010-09-17 13:10:46 +0200 | [diff] [blame] | 162 | |
Marek Vasut | abc20ab | 2011-11-26 07:20:07 +0100 | [diff] [blame] | 163 | #ifdef CONFIG_CPU_PXA25X |
Marek Vasut | 7f4cfcf | 2011-11-05 19:26:47 +0100 | [diff] [blame] | 164 | bl lock_cache_for_stack |
| 165 | #endif |
| 166 | |
Albert ARIBAUD | e05e5de | 2013-01-08 10:18:02 +0000 | [diff] [blame] | 167 | bl _main |
Heiko Schocher | 5347f68 | 2010-09-17 13:10:46 +0200 | [diff] [blame] | 168 | |
| 169 | /*------------------------------------------------------------------------------*/ |
Albert ARIBAUD | e05e5de | 2013-01-08 10:18:02 +0000 | [diff] [blame] | 170 | |
| 171 | .globl c_runtime_cpu_setup |
| 172 | c_runtime_cpu_setup: |
| 173 | |
Albert ARIBAUD | 3da0e57 | 2013-05-19 01:48:15 +0000 | [diff] [blame] | 174 | #ifdef CONFIG_CPU_PXA25X |
| 175 | /* |
| 176 | * Unlock (actually, disable) the cache now that board_init_f |
| 177 | * is done. We could do this earlier but we would need to add |
| 178 | * a new C runtime hook, whereas c_runtime_cpu_setup already |
| 179 | * exists. |
| 180 | * As this routine is just a call to cpu_init_crit, let us |
| 181 | * tail-optimize and do a simple branch here. |
| 182 | */ |
| 183 | b cpu_init_crit |
| 184 | #else |
Albert ARIBAUD | e05e5de | 2013-01-08 10:18:02 +0000 | [diff] [blame] | 185 | bx lr |
Albert ARIBAUD | 3da0e57 | 2013-05-19 01:48:15 +0000 | [diff] [blame] | 186 | #endif |
Albert ARIBAUD | e05e5de | 2013-01-08 10:18:02 +0000 | [diff] [blame] | 187 | |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 188 | /* |
| 189 | ************************************************************************* |
| 190 | * |
| 191 | * CPU_init_critical registers |
| 192 | * |
| 193 | * setup important registers |
| 194 | * setup memory timing |
| 195 | * |
| 196 | ************************************************************************* |
| 197 | */ |
Marek Vasut | abc20ab | 2011-11-26 07:20:07 +0100 | [diff] [blame] | 198 | #if !defined(CONFIG_SKIP_LOWLEVEL_INIT) || defined(CONFIG_CPU_PXA25X) |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 199 | cpu_init_crit: |
| 200 | /* |
| 201 | * flush v4 I/D caches |
| 202 | */ |
| 203 | mov r0, #0 |
| 204 | mcr p15, 0, r0, c7, c7, 0 /* Invalidate I+D+BTB caches */ |
| 205 | mcr p15, 0, r0, c8, c7, 0 /* Invalidate Unified TLB */ |
Marek Vasut | 2cad92f | 2010-09-28 15:44:10 +0200 | [diff] [blame] | 206 | |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 207 | /* |
| 208 | * disable MMU stuff and caches |
| 209 | */ |
| 210 | mrc p15, 0, r0, c1, c0, 0 |
Mike Dunn | 097d86d | 2013-06-17 10:47:28 -0700 | [diff] [blame] | 211 | bic r0, r0, #0x00003300 @ clear bits 13:12, 9:8 (--VI --RS) |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 212 | bic r0, r0, #0x00000087 @ clear bits 7, 2:0 (B--- -CAM) |
| 213 | orr r0, r0, #0x00000002 @ set bit 2 (A) Align |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 214 | mcr p15, 0, r0, c1, c0, 0 |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 215 | |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 216 | mov pc, lr /* back to my caller */ |
Marek Vasut | abc20ab | 2011-11-26 07:20:07 +0100 | [diff] [blame] | 217 | #endif /* !CONFIG_SKIP_LOWLEVEL_INIT || CONFIG_CPU_PXA25X */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 218 | |
Aneesh V | 401bb30 | 2011-07-13 05:11:07 +0000 | [diff] [blame] | 219 | #ifndef CONFIG_SPL_BUILD |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 220 | /* |
| 221 | ************************************************************************* |
| 222 | * |
| 223 | * Interrupt handling |
| 224 | * |
| 225 | ************************************************************************* |
| 226 | */ |
| 227 | @ |
| 228 | @ IRQ stack frame. |
| 229 | @ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 230 | #define S_FRAME_SIZE 72 |
| 231 | |
| 232 | #define S_OLD_R0 68 |
| 233 | #define S_PSR 64 |
| 234 | #define S_PC 60 |
| 235 | #define S_LR 56 |
| 236 | #define S_SP 52 |
| 237 | |
| 238 | #define S_IP 48 |
| 239 | #define S_FP 44 |
| 240 | #define S_R10 40 |
| 241 | #define S_R9 36 |
| 242 | #define S_R8 32 |
| 243 | #define S_R7 28 |
| 244 | #define S_R6 24 |
| 245 | #define S_R5 20 |
| 246 | #define S_R4 16 |
| 247 | #define S_R3 12 |
| 248 | #define S_R2 8 |
| 249 | #define S_R1 4 |
| 250 | #define S_R0 0 |
| 251 | |
| 252 | #define MODE_SVC 0x13 |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 253 | #define I_BIT 0x80 |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 254 | |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 255 | /* |
| 256 | * use bad_save_user_regs for abort/prefetch/undef/swi ... |
| 257 | * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling |
| 258 | */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 259 | |
| 260 | .macro bad_save_user_regs |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 261 | sub sp, sp, #S_FRAME_SIZE @ carve out a frame on current user stack |
| 262 | stmia sp, {r0 - r12} @ Save user registers (now in svc mode) r0-r12 |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 263 | |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 264 | ldr r2, IRQ_STACK_START_IN @ set base 2 words into abort stack |
| 265 | ldmia r2, {r2 - r3} @ get values for "aborted" pc and cpsr (into parm regs) |
| 266 | add r0, sp, #S_FRAME_SIZE @ grab pointer to old stack |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 267 | |
| 268 | add r5, sp, #S_SP |
| 269 | mov r1, lr |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 270 | stmia r5, {r0 - r3} @ save sp_SVC, lr_SVC, pc, cpsr |
| 271 | mov r0, sp @ save current stack into r0 (param register) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 272 | .endm |
| 273 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 274 | .macro irq_save_user_regs |
| 275 | sub sp, sp, #S_FRAME_SIZE |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 276 | stmia sp, {r0 - r12} @ Calling r0-r12 |
| 277 | add r8, sp, #S_PC @ !!!! R8 NEEDS to be saved !!!! a reserved stack spot would be good. |
| 278 | stmdb r8, {sp, lr}^ @ Calling SP, LR |
| 279 | str lr, [r8, #0] @ Save calling PC |
wdenk | 384ae02 | 2002-11-05 00:17:55 +0000 | [diff] [blame] | 280 | mrs r6, spsr |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 281 | str r6, [r8, #4] @ Save CPSR |
| 282 | str r0, [r8, #8] @ Save OLD_R0 |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 283 | mov r0, sp |
| 284 | .endm |
| 285 | |
| 286 | .macro irq_restore_user_regs |
| 287 | ldmia sp, {r0 - lr}^ @ Calling r0 - lr |
| 288 | mov r0, r0 |
| 289 | ldr lr, [sp, #S_PC] @ Get PC |
| 290 | add sp, sp, #S_FRAME_SIZE |
| 291 | subs pc, lr, #4 @ return & move spsr_svc into cpsr |
| 292 | .endm |
| 293 | |
| 294 | .macro get_bad_stack |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 295 | ldr r13, IRQ_STACK_START_IN @ setup our mode stack (enter in banked mode) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 296 | |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 297 | str lr, [r13] @ save caller lr in position 0 of saved stack |
| 298 | mrs lr, spsr @ get the spsr |
| 299 | str lr, [r13, #4] @ save spsr in position 1 of saved stack |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 300 | |
| 301 | mov r13, #MODE_SVC @ prepare SVC-Mode |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 302 | @ msr spsr_c, r13 |
| 303 | msr spsr, r13 @ switch modes, make sure moves will execute |
| 304 | mov lr, pc @ capture return pc |
| 305 | movs pc, lr @ jump to next instruction & switch modes. |
| 306 | .endm |
| 307 | |
| 308 | .macro get_bad_stack_swi |
| 309 | sub r13, r13, #4 @ space on current stack for scratch reg. |
| 310 | str r0, [r13] @ save R0's value. |
| 311 | ldr r0, IRQ_STACK_START_IN @ get data regions start |
| 312 | str lr, [r0] @ save caller lr in position 0 of saved stack |
Tetsuyuki Kobayashi | 4411b2a | 2013-04-05 00:12:51 +0000 | [diff] [blame] | 313 | mrs lr, spsr @ get the spsr |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 314 | str lr, [r0, #4] @ save spsr in position 1 of saved stack |
Tetsuyuki Kobayashi | 4411b2a | 2013-04-05 00:12:51 +0000 | [diff] [blame] | 315 | ldr lr, [r0] @ restore lr |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 316 | ldr r0, [r13] @ restore r0 |
| 317 | add r13, r13, #4 @ pop stack entry |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 318 | .endm |
| 319 | |
| 320 | .macro get_irq_stack @ setup IRQ stack |
| 321 | ldr sp, IRQ_STACK_START |
| 322 | .endm |
| 323 | |
| 324 | .macro get_fiq_stack @ setup FIQ stack |
| 325 | ldr sp, FIQ_STACK_START |
| 326 | .endm |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 327 | #endif /* CONFIG_SPL_BUILD */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 328 | |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 329 | /* |
| 330 | * exception handlers |
| 331 | */ |
Aneesh V | 401bb30 | 2011-07-13 05:11:07 +0000 | [diff] [blame] | 332 | #ifdef CONFIG_SPL_BUILD |
Marek Vasut | 5ab877b | 2010-07-06 02:48:35 +0200 | [diff] [blame] | 333 | .align 5 |
| 334 | do_hang: |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 335 | ldr sp, _TEXT_BASE /* use 32 words about stack */ |
Marek Vasut | 5ab877b | 2010-07-06 02:48:35 +0200 | [diff] [blame] | 336 | bl hang /* hang and never return */ |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 337 | #else /* !CONFIG_SPL_BUILD */ |
wdenk | 384ae02 | 2002-11-05 00:17:55 +0000 | [diff] [blame] | 338 | .align 5 |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 339 | undefined_instruction: |
| 340 | get_bad_stack |
| 341 | bad_save_user_regs |
wdenk | 384ae02 | 2002-11-05 00:17:55 +0000 | [diff] [blame] | 342 | bl do_undefined_instruction |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 343 | |
| 344 | .align 5 |
| 345 | software_interrupt: |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 346 | get_bad_stack_swi |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 347 | bad_save_user_regs |
wdenk | 384ae02 | 2002-11-05 00:17:55 +0000 | [diff] [blame] | 348 | bl do_software_interrupt |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 349 | |
| 350 | .align 5 |
| 351 | prefetch_abort: |
| 352 | get_bad_stack |
| 353 | bad_save_user_regs |
wdenk | 384ae02 | 2002-11-05 00:17:55 +0000 | [diff] [blame] | 354 | bl do_prefetch_abort |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 355 | |
| 356 | .align 5 |
| 357 | data_abort: |
| 358 | get_bad_stack |
| 359 | bad_save_user_regs |
wdenk | 384ae02 | 2002-11-05 00:17:55 +0000 | [diff] [blame] | 360 | bl do_data_abort |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 361 | |
| 362 | .align 5 |
| 363 | not_used: |
| 364 | get_bad_stack |
| 365 | bad_save_user_regs |
wdenk | 384ae02 | 2002-11-05 00:17:55 +0000 | [diff] [blame] | 366 | bl do_not_used |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 367 | |
| 368 | #ifdef CONFIG_USE_IRQ |
| 369 | |
| 370 | .align 5 |
| 371 | irq: |
| 372 | get_irq_stack |
| 373 | irq_save_user_regs |
wdenk | 384ae02 | 2002-11-05 00:17:55 +0000 | [diff] [blame] | 374 | bl do_irq |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 375 | irq_restore_user_regs |
| 376 | |
| 377 | .align 5 |
| 378 | fiq: |
| 379 | get_fiq_stack |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 380 | /* someone ought to write a more effiction fiq_save_user_regs */ |
| 381 | irq_save_user_regs |
| 382 | bl do_fiq |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 383 | irq_restore_user_regs |
| 384 | |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 385 | #else |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 386 | |
| 387 | .align 5 |
| 388 | irq: |
| 389 | get_bad_stack |
| 390 | bad_save_user_regs |
wdenk | 384ae02 | 2002-11-05 00:17:55 +0000 | [diff] [blame] | 391 | bl do_irq |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 392 | |
| 393 | .align 5 |
| 394 | fiq: |
| 395 | get_bad_stack |
| 396 | bad_save_user_regs |
wdenk | 384ae02 | 2002-11-05 00:17:55 +0000 | [diff] [blame] | 397 | bl do_fiq |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 398 | |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 399 | #endif |
| 400 | .align 5 |
Aneesh V | 401bb30 | 2011-07-13 05:11:07 +0000 | [diff] [blame] | 401 | #endif /* CONFIG_SPL_BUILD */ |
Marek Vasut | 7f4cfcf | 2011-11-05 19:26:47 +0100 | [diff] [blame] | 402 | |
| 403 | |
| 404 | /* |
| 405 | * Enable MMU to use DCache as DRAM. |
| 406 | * |
| 407 | * This is useful on PXA25x and PXA26x in early bootstages, where there is no |
| 408 | * other possible memory available to hold stack. |
| 409 | */ |
Marek Vasut | abc20ab | 2011-11-26 07:20:07 +0100 | [diff] [blame] | 410 | #ifdef CONFIG_CPU_PXA25X |
Marek Vasut | 7f4cfcf | 2011-11-05 19:26:47 +0100 | [diff] [blame] | 411 | .macro CPWAIT reg |
| 412 | mrc p15, 0, \reg, c2, c0, 0 |
| 413 | mov \reg, \reg |
| 414 | sub pc, pc, #4 |
| 415 | .endm |
| 416 | lock_cache_for_stack: |
| 417 | /* Domain access -- enable for all CPs */ |
| 418 | ldr r0, =0x0000ffff |
| 419 | mcr p15, 0, r0, c3, c0, 0 |
| 420 | |
| 421 | /* Point TTBR to MMU table */ |
| 422 | ldr r0, =mmutable |
| 423 | mcr p15, 0, r0, c2, c0, 0 |
| 424 | |
| 425 | /* Kick in MMU, ICache, DCache, BTB */ |
| 426 | mrc p15, 0, r0, c1, c0, 0 |
| 427 | bic r0, #0x1b00 |
| 428 | bic r0, #0x0087 |
| 429 | orr r0, #0x1800 |
| 430 | orr r0, #0x0005 |
| 431 | mcr p15, 0, r0, c1, c0, 0 |
| 432 | CPWAIT r0 |
| 433 | |
| 434 | /* Unlock Icache, Dcache */ |
| 435 | mcr p15, 0, r0, c9, c1, 1 |
| 436 | mcr p15, 0, r0, c9, c2, 1 |
| 437 | |
| 438 | /* Flush Icache, Dcache, BTB */ |
| 439 | mcr p15, 0, r0, c7, c7, 0 |
| 440 | |
| 441 | /* Unlock I-TLB, D-TLB */ |
| 442 | mcr p15, 0, r0, c10, c4, 1 |
| 443 | mcr p15, 0, r0, c10, c8, 1 |
| 444 | |
| 445 | /* Flush TLB */ |
| 446 | mcr p15, 0, r0, c8, c7, 0 |
| 447 | |
| 448 | /* Allocate 4096 bytes of Dcache as RAM */ |
| 449 | |
| 450 | /* Drain pending loads and stores */ |
| 451 | mcr p15, 0, r0, c7, c10, 4 |
| 452 | |
| 453 | mov r4, #0x00 |
| 454 | mov r5, #0x00 |
| 455 | mov r2, #0x01 |
| 456 | mcr p15, 0, r0, c9, c2, 0 |
| 457 | CPWAIT r0 |
| 458 | |
| 459 | /* 128 lines reserved (128 x 32bytes = 4096 bytes total) */ |
| 460 | mov r0, #128 |
| 461 | ldr r1, =0xfffff000 |
| 462 | |
| 463 | alloc: |
| 464 | mcr p15, 0, r1, c7, c2, 5 |
| 465 | /* Drain pending loads and stores */ |
| 466 | mcr p15, 0, r0, c7, c10, 4 |
| 467 | strd r4, [r1], #8 |
| 468 | strd r4, [r1], #8 |
| 469 | strd r4, [r1], #8 |
| 470 | strd r4, [r1], #8 |
| 471 | subs r0, #0x01 |
| 472 | bne alloc |
| 473 | /* Drain pending loads and stores */ |
| 474 | mcr p15, 0, r0, c7, c10, 4 |
| 475 | mov r2, #0x00 |
| 476 | mcr p15, 0, r2, c9, c2, 0 |
| 477 | CPWAIT r0 |
| 478 | |
| 479 | mov pc, lr |
| 480 | |
| 481 | .section .mmutable, "a" |
| 482 | mmutable: |
| 483 | .align 14 |
| 484 | /* 0x00000000 - 0xffe00000 : 1:1, uncached mapping */ |
| 485 | .set __base, 0 |
| 486 | .rept 0xfff |
| 487 | .word (__base << 20) | 0xc12 |
| 488 | .set __base, __base + 1 |
| 489 | .endr |
| 490 | |
| 491 | /* 0xfff00000 : 1:1, cached mapping */ |
| 492 | .word (0xfff << 20) | 0x1c1e |
Marek Vasut | abc20ab | 2011-11-26 07:20:07 +0100 | [diff] [blame] | 493 | #endif /* CONFIG_CPU_PXA25X */ |