Dirk Behme | 0b02b18 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 1 | /* |
| 2 | * armboot - Startup Code for OMAP3530/ARM Cortex CPU-core |
| 3 | * |
| 4 | * Copyright (c) 2004 Texas Instruments <r-woodruff2@ti.com> |
| 5 | * |
| 6 | * Copyright (c) 2001 Marius Gröger <mag@sysgo.de> |
| 7 | * Copyright (c) 2002 Alex Züpke <azu@sysgo.de> |
Detlev Zundel | 792a09e | 2009-05-13 10:54:10 +0200 | [diff] [blame] | 8 | * Copyright (c) 2002 Gary Jennejohn <garyj@denx.de> |
Dirk Behme | 0b02b18 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 9 | * Copyright (c) 2003 Richard Woodruff <r-woodruff2@ti.com> |
| 10 | * Copyright (c) 2003 Kshitij <kshitij@ti.com> |
| 11 | * Copyright (c) 2006-2008 Syed Mohammed Khasim <x0khasim@ti.com> |
| 12 | * |
Wolfgang Denk | 3765b3e | 2013-10-07 13:07:26 +0200 | [diff] [blame] | 13 | * SPDX-License-Identifier: GPL-2.0+ |
Dirk Behme | 0b02b18 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 14 | */ |
| 15 | |
Wolfgang Denk | 25ddd1f | 2010-10-26 14:34:52 +0200 | [diff] [blame] | 16 | #include <asm-offsets.h> |
Dirk Behme | 0b02b18 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 17 | #include <config.h> |
| 18 | #include <version.h> |
Aneesh V | a8c6863 | 2011-11-21 23:34:00 +0000 | [diff] [blame] | 19 | #include <asm/system.h> |
Aneesh V | 74236ac | 2012-03-08 07:20:18 +0000 | [diff] [blame] | 20 | #include <linux/linkage.h> |
Dirk Behme | 0b02b18 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 21 | |
| 22 | .globl _start |
| 23 | _start: b reset |
| 24 | ldr pc, _undefined_instruction |
| 25 | ldr pc, _software_interrupt |
| 26 | ldr pc, _prefetch_abort |
| 27 | ldr pc, _data_abort |
| 28 | ldr pc, _not_used |
| 29 | ldr pc, _irq |
| 30 | ldr pc, _fiq |
Aneesh V | 033ca72 | 2011-07-21 09:10:18 -0400 | [diff] [blame] | 31 | #ifdef CONFIG_SPL_BUILD |
| 32 | _undefined_instruction: .word _undefined_instruction |
| 33 | _software_interrupt: .word _software_interrupt |
| 34 | _prefetch_abort: .word _prefetch_abort |
| 35 | _data_abort: .word _data_abort |
| 36 | _not_used: .word _not_used |
| 37 | _irq: .word _irq |
| 38 | _fiq: .word _fiq |
| 39 | _pad: .word 0x12345678 /* now 16*4=64 */ |
| 40 | #else |
Marek Vasut | 7cbe638 | 2013-12-14 05:55:26 +0100 | [diff] [blame] | 41 | .globl _undefined_instruction |
Dirk Behme | 0b02b18 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 42 | _undefined_instruction: .word undefined_instruction |
Marek Vasut | 7cbe638 | 2013-12-14 05:55:26 +0100 | [diff] [blame] | 43 | .globl _software_interrupt |
Dirk Behme | 0b02b18 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 44 | _software_interrupt: .word software_interrupt |
Marek Vasut | 7cbe638 | 2013-12-14 05:55:26 +0100 | [diff] [blame] | 45 | .globl _prefetch_abort |
Dirk Behme | 0b02b18 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 46 | _prefetch_abort: .word prefetch_abort |
Marek Vasut | 7cbe638 | 2013-12-14 05:55:26 +0100 | [diff] [blame] | 47 | .globl _data_abort |
Dirk Behme | 0b02b18 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 48 | _data_abort: .word data_abort |
Marek Vasut | 7cbe638 | 2013-12-14 05:55:26 +0100 | [diff] [blame] | 49 | .globl _not_used |
Dirk Behme | 0b02b18 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 50 | _not_used: .word not_used |
Marek Vasut | 7cbe638 | 2013-12-14 05:55:26 +0100 | [diff] [blame] | 51 | .globl _irq |
Dirk Behme | 0b02b18 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 52 | _irq: .word irq |
Marek Vasut | 7cbe638 | 2013-12-14 05:55:26 +0100 | [diff] [blame] | 53 | .globl _fiq |
Dirk Behme | 0b02b18 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 54 | _fiq: .word fiq |
| 55 | _pad: .word 0x12345678 /* now 16*4=64 */ |
Aneesh V | 033ca72 | 2011-07-21 09:10:18 -0400 | [diff] [blame] | 56 | #endif /* CONFIG_SPL_BUILD */ |
| 57 | |
Dirk Behme | 0b02b18 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 58 | .balignl 16,0xdeadbeef |
| 59 | /************************************************************************* |
| 60 | * |
| 61 | * Startup Code (reset vector) |
| 62 | * |
| 63 | * do important init only if we don't start from memory! |
| 64 | * setup Memory and board specific bits prior to relocation. |
| 65 | * relocate armboot to ram |
| 66 | * setup stack |
| 67 | * |
| 68 | *************************************************************************/ |
| 69 | |
Dirk Behme | 0b02b18 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 70 | #ifdef CONFIG_USE_IRQ |
| 71 | /* IRQ stack memory (calculated at run-time) */ |
| 72 | .globl IRQ_STACK_START |
| 73 | IRQ_STACK_START: |
| 74 | .word 0x0badc0de |
| 75 | |
| 76 | /* IRQ stack memory (calculated at run-time) */ |
| 77 | .globl FIQ_STACK_START |
| 78 | FIQ_STACK_START: |
| 79 | .word 0x0badc0de |
| 80 | #endif |
| 81 | |
Heiko Schocher | 561142a | 2010-09-17 13:10:41 +0200 | [diff] [blame] | 82 | /* IRQ stack memory (calculated at run-time) + 8 bytes */ |
| 83 | .globl IRQ_STACK_START_IN |
| 84 | IRQ_STACK_START_IN: |
| 85 | .word 0x0badc0de |
| 86 | |
Heiko Schocher | 561142a | 2010-09-17 13:10:41 +0200 | [diff] [blame] | 87 | /* |
| 88 | * the actual reset code |
| 89 | */ |
| 90 | |
| 91 | reset: |
Aneesh V | 8cf686e | 2011-07-21 09:10:27 -0400 | [diff] [blame] | 92 | bl save_boot_params |
Heiko Schocher | 561142a | 2010-09-17 13:10:41 +0200 | [diff] [blame] | 93 | /* |
Andre Przywara | c4a4e2e | 2013-04-02 05:43:36 +0000 | [diff] [blame] | 94 | * disable interrupts (FIQ and IRQ), also set the cpu to SVC32 mode, |
| 95 | * except if in HYP mode already |
Heiko Schocher | 561142a | 2010-09-17 13:10:41 +0200 | [diff] [blame] | 96 | */ |
| 97 | mrs r0, cpsr |
Andre Przywara | c4a4e2e | 2013-04-02 05:43:36 +0000 | [diff] [blame] | 98 | and r1, r0, #0x1f @ mask mode bits |
| 99 | teq r1, #0x1a @ test for HYP mode |
| 100 | bicne r0, r0, #0x1f @ clear all mode bits |
| 101 | orrne r0, r0, #0x13 @ set SVC mode |
| 102 | orr r0, r0, #0xc0 @ disable FIQ and IRQ |
Heiko Schocher | 561142a | 2010-09-17 13:10:41 +0200 | [diff] [blame] | 103 | msr cpsr,r0 |
| 104 | |
Aneesh V | a8c6863 | 2011-11-21 23:34:00 +0000 | [diff] [blame] | 105 | /* |
| 106 | * Setup vector: |
| 107 | * (OMAP4 spl TEXT_BASE is not 32 byte aligned. |
| 108 | * Continue to use ROM code vector only in OMAP4 spl) |
| 109 | */ |
| 110 | #if !(defined(CONFIG_OMAP44XX) && defined(CONFIG_SPL_BUILD)) |
| 111 | /* Set V=0 in CP15 SCTRL register - for VBAR to point to vector */ |
| 112 | mrc p15, 0, r0, c1, c0, 0 @ Read CP15 SCTRL Register |
| 113 | bic r0, #CR_V @ V = 0 |
| 114 | mcr p15, 0, r0, c1, c0, 0 @ Write CP15 SCTRL Register |
| 115 | |
| 116 | /* Set vector address in CP15 VBAR register */ |
| 117 | ldr r0, =_start |
| 118 | mcr p15, 0, r0, c12, c0, 0 @Set VBAR |
| 119 | #endif |
| 120 | |
Heiko Schocher | 561142a | 2010-09-17 13:10:41 +0200 | [diff] [blame] | 121 | /* the mask ROM code should have PLL and others stable */ |
| 122 | #ifndef CONFIG_SKIP_LOWLEVEL_INIT |
Simon Glass | 80433c9 | 2011-11-05 03:56:51 +0000 | [diff] [blame] | 123 | bl cpu_init_cp15 |
Heiko Schocher | 561142a | 2010-09-17 13:10:41 +0200 | [diff] [blame] | 124 | bl cpu_init_crit |
| 125 | #endif |
| 126 | |
Albert ARIBAUD | e05e5de | 2013-01-08 10:18:02 +0000 | [diff] [blame] | 127 | bl _main |
Heiko Schocher | 561142a | 2010-09-17 13:10:41 +0200 | [diff] [blame] | 128 | |
| 129 | /*------------------------------------------------------------------------------*/ |
| 130 | |
Albert ARIBAUD | e05e5de | 2013-01-08 10:18:02 +0000 | [diff] [blame] | 131 | ENTRY(c_runtime_cpu_setup) |
Aneesh V | c2dd0d4 | 2011-06-16 23:30:49 +0000 | [diff] [blame] | 132 | /* |
| 133 | * If I-cache is enabled invalidate it |
| 134 | */ |
| 135 | #ifndef CONFIG_SYS_ICACHE_OFF |
| 136 | mcr p15, 0, r0, c7, c5, 0 @ invalidate icache |
| 137 | mcr p15, 0, r0, c7, c10, 4 @ DSB |
| 138 | mcr p15, 0, r0, c7, c5, 4 @ ISB |
| 139 | #endif |
Tetsuyuki Kobayashi | f8b9d1d | 2012-06-25 02:40:57 +0000 | [diff] [blame] | 140 | /* |
| 141 | * Move vector table |
| 142 | */ |
Tetsuyuki Kobayashi | f8b9d1d | 2012-06-25 02:40:57 +0000 | [diff] [blame] | 143 | /* Set vector address in CP15 VBAR register */ |
| 144 | ldr r0, =_start |
Tetsuyuki Kobayashi | f8b9d1d | 2012-06-25 02:40:57 +0000 | [diff] [blame] | 145 | mcr p15, 0, r0, c12, c0, 0 @Set VBAR |
Tetsuyuki Kobayashi | f8b9d1d | 2012-06-25 02:40:57 +0000 | [diff] [blame] | 146 | |
Albert ARIBAUD | e05e5de | 2013-01-08 10:18:02 +0000 | [diff] [blame] | 147 | bx lr |
Heiko Schocher | 561142a | 2010-09-17 13:10:41 +0200 | [diff] [blame] | 148 | |
Albert ARIBAUD | e05e5de | 2013-01-08 10:18:02 +0000 | [diff] [blame] | 149 | ENDPROC(c_runtime_cpu_setup) |
Heiko Schocher | c3d3a54 | 2010-10-11 14:08:15 +0200 | [diff] [blame] | 150 | |
Dirk Behme | 0b02b18 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 151 | /************************************************************************* |
| 152 | * |
Tetsuyuki Kobayashi | 6f0dba8 | 2012-07-06 21:14:20 +0000 | [diff] [blame] | 153 | * void save_boot_params(u32 r0, u32 r1, u32 r2, u32 r3) |
| 154 | * __attribute__((weak)); |
| 155 | * |
| 156 | * Stack pointer is not yet initialized at this moment |
| 157 | * Don't save anything to stack even if compiled with -O0 |
| 158 | * |
| 159 | *************************************************************************/ |
| 160 | ENTRY(save_boot_params) |
| 161 | bx lr @ back to my caller |
| 162 | ENDPROC(save_boot_params) |
| 163 | .weak save_boot_params |
| 164 | |
| 165 | /************************************************************************* |
| 166 | * |
Simon Glass | 80433c9 | 2011-11-05 03:56:51 +0000 | [diff] [blame] | 167 | * cpu_init_cp15 |
Dirk Behme | 0b02b18 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 168 | * |
Simon Glass | 80433c9 | 2011-11-05 03:56:51 +0000 | [diff] [blame] | 169 | * Setup CP15 registers (cache, MMU, TLBs). The I-cache is turned on unless |
| 170 | * CONFIG_SYS_ICACHE_OFF is defined. |
Dirk Behme | 0b02b18 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 171 | * |
| 172 | *************************************************************************/ |
Aneesh V | 74236ac | 2012-03-08 07:20:18 +0000 | [diff] [blame] | 173 | ENTRY(cpu_init_cp15) |
Dirk Behme | 0b02b18 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 174 | /* |
| 175 | * Invalidate L1 I/D |
| 176 | */ |
| 177 | mov r0, #0 @ set up for MCR |
| 178 | mcr p15, 0, r0, c8, c7, 0 @ invalidate TLBs |
| 179 | mcr p15, 0, r0, c7, c5, 0 @ invalidate icache |
Aneesh V | c2dd0d4 | 2011-06-16 23:30:49 +0000 | [diff] [blame] | 180 | mcr p15, 0, r0, c7, c5, 6 @ invalidate BP array |
| 181 | mcr p15, 0, r0, c7, c10, 4 @ DSB |
| 182 | mcr p15, 0, r0, c7, c5, 4 @ ISB |
Dirk Behme | 0b02b18 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 183 | |
| 184 | /* |
| 185 | * disable MMU stuff and caches |
| 186 | */ |
| 187 | mrc p15, 0, r0, c1, c0, 0 |
| 188 | bic r0, r0, #0x00002000 @ clear bits 13 (--V-) |
| 189 | bic r0, r0, #0x00000007 @ clear bits 2:0 (-CAM) |
| 190 | orr r0, r0, #0x00000002 @ set bit 1 (--A-) Align |
Aneesh V | c2dd0d4 | 2011-06-16 23:30:49 +0000 | [diff] [blame] | 191 | orr r0, r0, #0x00000800 @ set bit 11 (Z---) BTB |
| 192 | #ifdef CONFIG_SYS_ICACHE_OFF |
| 193 | bic r0, r0, #0x00001000 @ clear bit 12 (I) I-cache |
| 194 | #else |
| 195 | orr r0, r0, #0x00001000 @ set bit 12 (I) I-cache |
| 196 | #endif |
Dirk Behme | 0b02b18 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 197 | mcr p15, 0, r0, c1, c0, 0 |
Stephen Warren | 0678587 | 2013-02-26 12:28:27 +0000 | [diff] [blame] | 198 | |
Stephen Warren | c5d4752 | 2013-03-04 13:29:40 +0000 | [diff] [blame] | 199 | #ifdef CONFIG_ARM_ERRATA_716044 |
| 200 | mrc p15, 0, r0, c1, c0, 0 @ read system control register |
| 201 | orr r0, r0, #1 << 11 @ set bit #11 |
| 202 | mcr p15, 0, r0, c1, c0, 0 @ write system control register |
| 203 | #endif |
| 204 | |
Nitin Garg | f71cbfe | 2014-04-02 08:55:01 -0500 | [diff] [blame] | 205 | #if (defined(CONFIG_ARM_ERRATA_742230) || defined(CONFIG_ARM_ERRATA_794072)) |
Stephen Warren | 0678587 | 2013-02-26 12:28:27 +0000 | [diff] [blame] | 206 | mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register |
| 207 | orr r0, r0, #1 << 4 @ set bit #4 |
| 208 | mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register |
| 209 | #endif |
| 210 | |
| 211 | #ifdef CONFIG_ARM_ERRATA_743622 |
| 212 | mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register |
| 213 | orr r0, r0, #1 << 6 @ set bit #6 |
| 214 | mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register |
| 215 | #endif |
| 216 | |
| 217 | #ifdef CONFIG_ARM_ERRATA_751472 |
| 218 | mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register |
| 219 | orr r0, r0, #1 << 11 @ set bit #11 |
| 220 | mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register |
| 221 | #endif |
Nitin Garg | b7588e3 | 2014-04-02 08:55:02 -0500 | [diff] [blame] | 222 | #ifdef CONFIG_ARM_ERRATA_761320 |
| 223 | mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register |
| 224 | orr r0, r0, #1 << 21 @ set bit #21 |
| 225 | mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register |
| 226 | #endif |
Stephen Warren | 0678587 | 2013-02-26 12:28:27 +0000 | [diff] [blame] | 227 | |
Simon Glass | 80433c9 | 2011-11-05 03:56:51 +0000 | [diff] [blame] | 228 | mov pc, lr @ back to my caller |
Aneesh V | 74236ac | 2012-03-08 07:20:18 +0000 | [diff] [blame] | 229 | ENDPROC(cpu_init_cp15) |
Simon Glass | 80433c9 | 2011-11-05 03:56:51 +0000 | [diff] [blame] | 230 | |
| 231 | #ifndef CONFIG_SKIP_LOWLEVEL_INIT |
| 232 | /************************************************************************* |
| 233 | * |
| 234 | * CPU_init_critical registers |
| 235 | * |
| 236 | * setup important registers |
| 237 | * setup memory timing |
| 238 | * |
| 239 | *************************************************************************/ |
Aneesh V | 74236ac | 2012-03-08 07:20:18 +0000 | [diff] [blame] | 240 | ENTRY(cpu_init_crit) |
Dirk Behme | 0b02b18 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 241 | /* |
| 242 | * Jump to board specific initialization... |
| 243 | * The Mask ROM will have already initialized |
| 244 | * basic memory. Go here to bump up clock rate and handle |
| 245 | * wake up conditions. |
| 246 | */ |
Benoît Thébaudeau | 63ee53a | 2012-08-10 12:05:16 +0000 | [diff] [blame] | 247 | b lowlevel_init @ go setup pll,mux,memory |
Aneesh V | 74236ac | 2012-03-08 07:20:18 +0000 | [diff] [blame] | 248 | ENDPROC(cpu_init_crit) |
Rob Herring | 2219354 | 2011-06-28 05:39:38 +0000 | [diff] [blame] | 249 | #endif |
Aneesh V | 033ca72 | 2011-07-21 09:10:18 -0400 | [diff] [blame] | 250 | |
| 251 | #ifndef CONFIG_SPL_BUILD |
Dirk Behme | 0b02b18 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 252 | /* |
| 253 | ************************************************************************* |
| 254 | * |
| 255 | * Interrupt handling |
| 256 | * |
| 257 | ************************************************************************* |
| 258 | */ |
| 259 | @ |
| 260 | @ IRQ stack frame. |
| 261 | @ |
| 262 | #define S_FRAME_SIZE 72 |
| 263 | |
| 264 | #define S_OLD_R0 68 |
| 265 | #define S_PSR 64 |
| 266 | #define S_PC 60 |
| 267 | #define S_LR 56 |
| 268 | #define S_SP 52 |
| 269 | |
| 270 | #define S_IP 48 |
| 271 | #define S_FP 44 |
| 272 | #define S_R10 40 |
| 273 | #define S_R9 36 |
| 274 | #define S_R8 32 |
| 275 | #define S_R7 28 |
| 276 | #define S_R6 24 |
| 277 | #define S_R5 20 |
| 278 | #define S_R4 16 |
| 279 | #define S_R3 12 |
| 280 | #define S_R2 8 |
| 281 | #define S_R1 4 |
| 282 | #define S_R0 0 |
| 283 | |
| 284 | #define MODE_SVC 0x13 |
| 285 | #define I_BIT 0x80 |
| 286 | |
| 287 | /* |
| 288 | * use bad_save_user_regs for abort/prefetch/undef/swi ... |
| 289 | * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling |
| 290 | */ |
| 291 | |
| 292 | .macro bad_save_user_regs |
| 293 | sub sp, sp, #S_FRAME_SIZE @ carve out a frame on current |
| 294 | @ user stack |
| 295 | stmia sp, {r0 - r12} @ Save user registers (now in |
| 296 | @ svc mode) r0-r12 |
Heiko Schocher | 561142a | 2010-09-17 13:10:41 +0200 | [diff] [blame] | 297 | ldr r2, IRQ_STACK_START_IN @ set base 2 words into abort |
Dirk Behme | 0b02b18 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 298 | @ stack |
| 299 | ldmia r2, {r2 - r3} @ get values for "aborted" pc |
| 300 | @ and cpsr (into parm regs) |
| 301 | add r0, sp, #S_FRAME_SIZE @ grab pointer to old stack |
| 302 | |
| 303 | add r5, sp, #S_SP |
| 304 | mov r1, lr |
| 305 | stmia r5, {r0 - r3} @ save sp_SVC, lr_SVC, pc, cpsr |
| 306 | mov r0, sp @ save current stack into r0 |
| 307 | @ (param register) |
| 308 | .endm |
| 309 | |
| 310 | .macro irq_save_user_regs |
| 311 | sub sp, sp, #S_FRAME_SIZE |
| 312 | stmia sp, {r0 - r12} @ Calling r0-r12 |
| 313 | add r8, sp, #S_PC @ !! R8 NEEDS to be saved !! |
| 314 | @ a reserved stack spot would |
| 315 | @ be good. |
| 316 | stmdb r8, {sp, lr}^ @ Calling SP, LR |
| 317 | str lr, [r8, #0] @ Save calling PC |
| 318 | mrs r6, spsr |
| 319 | str r6, [r8, #4] @ Save CPSR |
| 320 | str r0, [r8, #8] @ Save OLD_R0 |
| 321 | mov r0, sp |
| 322 | .endm |
| 323 | |
| 324 | .macro irq_restore_user_regs |
| 325 | ldmia sp, {r0 - lr}^ @ Calling r0 - lr |
| 326 | mov r0, r0 |
| 327 | ldr lr, [sp, #S_PC] @ Get PC |
| 328 | add sp, sp, #S_FRAME_SIZE |
| 329 | subs pc, lr, #4 @ return & move spsr_svc into |
| 330 | @ cpsr |
| 331 | .endm |
| 332 | |
| 333 | .macro get_bad_stack |
Heiko Schocher | 561142a | 2010-09-17 13:10:41 +0200 | [diff] [blame] | 334 | ldr r13, IRQ_STACK_START_IN @ setup our mode stack (enter |
| 335 | @ in banked mode) |
Dirk Behme | 0b02b18 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 336 | |
| 337 | str lr, [r13] @ save caller lr in position 0 |
| 338 | @ of saved stack |
| 339 | mrs lr, spsr @ get the spsr |
| 340 | str lr, [r13, #4] @ save spsr in position 1 of |
| 341 | @ saved stack |
| 342 | |
| 343 | mov r13, #MODE_SVC @ prepare SVC-Mode |
| 344 | @ msr spsr_c, r13 |
| 345 | msr spsr, r13 @ switch modes, make sure |
| 346 | @ moves will execute |
| 347 | mov lr, pc @ capture return pc |
| 348 | movs pc, lr @ jump to next instruction & |
| 349 | @ switch modes. |
| 350 | .endm |
| 351 | |
| 352 | .macro get_bad_stack_swi |
| 353 | sub r13, r13, #4 @ space on current stack for |
| 354 | @ scratch reg. |
| 355 | str r0, [r13] @ save R0's value. |
Heiko Schocher | 561142a | 2010-09-17 13:10:41 +0200 | [diff] [blame] | 356 | ldr r0, IRQ_STACK_START_IN @ get data regions start |
Dirk Behme | 0b02b18 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 357 | @ spots for abort stack |
| 358 | str lr, [r0] @ save caller lr in position 0 |
| 359 | @ of saved stack |
Tetsuyuki Kobayashi | 4411b2a | 2013-04-05 00:12:51 +0000 | [diff] [blame] | 360 | mrs lr, spsr @ get the spsr |
Dirk Behme | 0b02b18 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 361 | str lr, [r0, #4] @ save spsr in position 1 of |
| 362 | @ saved stack |
Tetsuyuki Kobayashi | 4411b2a | 2013-04-05 00:12:51 +0000 | [diff] [blame] | 363 | ldr lr, [r0] @ restore lr |
Dirk Behme | 0b02b18 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 364 | ldr r0, [r13] @ restore r0 |
| 365 | add r13, r13, #4 @ pop stack entry |
| 366 | .endm |
| 367 | |
| 368 | .macro get_irq_stack @ setup IRQ stack |
| 369 | ldr sp, IRQ_STACK_START |
| 370 | .endm |
| 371 | |
| 372 | .macro get_fiq_stack @ setup FIQ stack |
| 373 | ldr sp, FIQ_STACK_START |
| 374 | .endm |
| 375 | |
| 376 | /* |
| 377 | * exception handlers |
| 378 | */ |
| 379 | .align 5 |
| 380 | undefined_instruction: |
| 381 | get_bad_stack |
| 382 | bad_save_user_regs |
| 383 | bl do_undefined_instruction |
| 384 | |
| 385 | .align 5 |
| 386 | software_interrupt: |
| 387 | get_bad_stack_swi |
| 388 | bad_save_user_regs |
| 389 | bl do_software_interrupt |
| 390 | |
| 391 | .align 5 |
| 392 | prefetch_abort: |
| 393 | get_bad_stack |
| 394 | bad_save_user_regs |
| 395 | bl do_prefetch_abort |
| 396 | |
| 397 | .align 5 |
| 398 | data_abort: |
| 399 | get_bad_stack |
| 400 | bad_save_user_regs |
| 401 | bl do_data_abort |
| 402 | |
| 403 | .align 5 |
| 404 | not_used: |
| 405 | get_bad_stack |
| 406 | bad_save_user_regs |
| 407 | bl do_not_used |
| 408 | |
| 409 | #ifdef CONFIG_USE_IRQ |
| 410 | |
| 411 | .align 5 |
| 412 | irq: |
| 413 | get_irq_stack |
| 414 | irq_save_user_regs |
| 415 | bl do_irq |
| 416 | irq_restore_user_regs |
| 417 | |
| 418 | .align 5 |
| 419 | fiq: |
| 420 | get_fiq_stack |
| 421 | /* someone ought to write a more effective fiq_save_user_regs */ |
| 422 | irq_save_user_regs |
| 423 | bl do_fiq |
| 424 | irq_restore_user_regs |
| 425 | |
| 426 | #else |
| 427 | |
| 428 | .align 5 |
| 429 | irq: |
| 430 | get_bad_stack |
| 431 | bad_save_user_regs |
| 432 | bl do_irq |
| 433 | |
| 434 | .align 5 |
| 435 | fiq: |
| 436 | get_bad_stack |
| 437 | bad_save_user_regs |
| 438 | bl do_fiq |
| 439 | |
Aneesh V | 033ca72 | 2011-07-21 09:10:18 -0400 | [diff] [blame] | 440 | #endif /* CONFIG_USE_IRQ */ |
| 441 | #endif /* CONFIG_SPL_BUILD */ |