1/* 2 * vectors - Generic ARM exception table code 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> 7 * Copyright (c) 2001 Alex Züpke <azu@sysgo.de> 8 * Copyright (c) 2001 Marius Gröger <mag@sysgo.de> 9 * Copyright (c) 2002 Alex Züpke <azu@sysgo.de> 10 * Copyright (c) 2002 Gary Jennejohn <garyj@denx.de> 11 * Copyright (c) 2002 Kyle Harris <kharris@nexus-tech.net> 12 * 13 * SPDX-License-Identifier: GPL-2.0+ 14 */ 15 16#include <config.h> 17 18/* 19 * A macro to allow insertion of an ARM exception vector either 20 * for the non-boot0 case or by a boot0-header. 21 */ 22 .macro ARM_VECTORS 23 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 31 .endm 32 33 34/* 35 ************************************************************************* 36 * 37 * Symbol _start is referenced elsewhere, so make it global 38 * 39 ************************************************************************* 40 */ 41 42.globl _start 43 44/* 45 ************************************************************************* 46 * 47 * Vectors have their own section so linker script can map them easily 48 * 49 ************************************************************************* 50 */ 51 52 .section ".vectors", "ax" 53 54#if defined(CONFIG_ENABLE_ARM_SOC_BOOT0_HOOK) 55/* 56 * Various SoCs need something special and SoC-specific up front in 57 * order to boot, allow them to set that in their boot0.h file and then 58 * use it here. 59 * 60 * To allow a boot0 hook to insert a 'special' sequence after the vector 61 * table (e.g. for the socfpga), the presence of a boot0 hook supresses 62 * the below vector table and assumes that the vector table is filled in 63 * by the boot0 hook. The requirements for a boot0 hook thus are: 64 * (1) defines '_start:' as appropriate 65 * (2) inserts the vector table using ARM_VECTORS as appropriate 66 */ 67#include <asm/arch/boot0.h> 68 69#else 70 71/* 72 ************************************************************************* 73 * 74 * Exception vectors as described in ARM reference manuals 75 * 76 * Uses indirect branch to allow reaching handlers anywhere in memory. 77 * 78 ************************************************************************* 79 */ 80 81_start: 82#ifdef CONFIG_SYS_DV_NOR_BOOT_CFG 83 .word CONFIG_SYS_DV_NOR_BOOT_CFG 84#endif 85 ARM_VECTORS 86#endif /* !defined(CONFIG_ENABLE_ARM_SOC_BOOT0_HOOK) */ 87 88/* 89 ************************************************************************* 90 * 91 * Indirect vectors table 92 * 93 * Symbols referenced here must be defined somewhere else 94 * 95 ************************************************************************* 96 */ 97 98 .globl _undefined_instruction 99 .globl _software_interrupt 100 .globl _prefetch_abort 101 .globl _data_abort 102 .globl _not_used 103 .globl _irq 104 .globl _fiq 105 106_undefined_instruction: .word undefined_instruction 107_software_interrupt: .word software_interrupt 108_prefetch_abort: .word prefetch_abort 109_data_abort: .word data_abort 110_not_used: .word not_used 111_irq: .word irq 112_fiq: .word fiq 113 114 .balignl 16,0xdeadbeef 115 116/* 117 ************************************************************************* 118 * 119 * Interrupt handling 120 * 121 ************************************************************************* 122 */ 123 124/* SPL interrupt handling: just hang */ 125 126#ifdef CONFIG_SPL_BUILD 127 128 .align 5 129undefined_instruction: 130software_interrupt: 131prefetch_abort: 132data_abort: 133not_used: 134irq: 135fiq: 1361: 137 bl 1b /* hang and never return */ 138 139#else /* !CONFIG_SPL_BUILD */ 140 141/* IRQ stack memory (calculated at run-time) + 8 bytes */ 142.globl IRQ_STACK_START_IN 143IRQ_STACK_START_IN: 144#ifdef IRAM_BASE_ADDR 145 .word IRAM_BASE_ADDR + 0x20 146#else 147 .word 0x0badc0de 148#endif 149 150#if CONFIG_IS_ENABLED(IRQ) 151/* IRQ stack memory (calculated at run-time) */ 152.globl IRQ_STACK_START 153IRQ_STACK_START: 154 .word 0x0badc0de 155#endif 156 157@ 158@ IRQ stack frame. 159@ 160#define S_FRAME_SIZE 72 161 162#define S_OLD_R0 68 163#define S_PSR 64 164#define S_PC 60 165#define S_LR 56 166#define S_SP 52 167 168#define S_IP 48 169#define S_FP 44 170#define S_R10 40 171#define S_R9 36 172#define S_R8 32 173#define S_R7 28 174#define S_R6 24 175#define S_R5 20 176#define S_R4 16 177#define S_R3 12 178#define S_R2 8 179#define S_R1 4 180#define S_R0 0 181 182#define MODE_IRQ 0x12 183#define MODE_SVC 0x13 184#define I_BIT 0x80 185 186/* 187 * use bad_save_user_regs for abort/prefetch/undef/swi ... 188 * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling 189 */ 190 191 .macro bad_save_user_regs 192 @ carve out a frame on current user stack 193 sub sp, sp, #S_FRAME_SIZE 194 stmia sp, {r0 - r12} @ Save user registers (now in svc mode) r0-r12 195 ldr r2, IRQ_STACK_START_IN 196 @ get values for "aborted" pc and cpsr (into parm regs) 197 ldmia r2, {r2 - r3} 198 add r0, sp, #S_FRAME_SIZE @ grab pointer to old stack 199 add r5, sp, #S_SP 200 mov r1, lr 201 stmia r5, {r0 - r3} @ save sp_SVC, lr_SVC, pc, cpsr 202 mov r0, sp @ save current stack into r0 (param register) 203 .endm 204 205 .macro irq_save_user_regs 206 sub sp, sp, #S_FRAME_SIZE 207 stmia sp, {r0 - r12} @ Calling r0-r12 208 @ !!!! R8 NEEDS to be saved !!!! a reserved stack spot would be good. 209 add r8, sp, #S_PC 210 211 cps #MODE_SVC @ SVC-Mode 212 isb 213 mov r1, sp @ svc_sp 214 mov r2, lr @ svc_lr 215 cps #MODE_IRQ @ IRQ-Mode 216 isb 217 218 stmdb r8, {r1, r2}^ @ Calling svc_sp, svc_lr 219 str lr, [r8, #0] @ Save calling PC 220 mrs r6, spsr 221 str r6, [r8, #4] @ Save CPSR 222 str r0, [r8, #8] @ Save OLD_R0 223 mov r0, sp 224 .endm 225 226 .macro irq_restore_user_regs 227 ldmia sp, {r0 - lr}^ @ Calling r0 - lr 228 mov r0, r0 229 ldr lr, [sp, #S_PC] @ Get PC 230 add sp, sp, #S_FRAME_SIZE 231 subs pc, lr, #4 @ return & move spsr_svc into cpsr 232 .endm 233 234 .macro get_bad_stack 235 ldr r13, IRQ_STACK_START_IN @ setup our mode stack 236 237 str lr, [r13] @ save caller lr in position 0 of saved stack 238 mrs lr, spsr @ get the spsr 239 str lr, [r13, #4] @ save spsr in position 1 of saved stack 240 mov r13, #MODE_SVC @ prepare SVC-Mode 241 @ msr spsr_c, r13 242 msr spsr, r13 @ switch modes, make sure moves will execute 243 mov lr, pc @ capture return pc 244 movs pc, lr @ jump to next instruction & switch modes. 245 .endm 246 247 .macro get_irq_stack @ setup IRQ stack 248 ldr sp, IRQ_STACK_START 249 .endm 250 251 .macro get_fiq_stack @ setup FIQ stack 252 ldr sp, FIQ_STACK_START 253 .endm 254 255/* 256 * exception handlers 257 */ 258 259 .align 5 260undefined_instruction: 261 get_bad_stack 262 bad_save_user_regs 263 bl do_undefined_instruction 264 265 .align 5 266software_interrupt: 267 get_bad_stack 268 bad_save_user_regs 269 bl do_software_interrupt 270 271 .align 5 272prefetch_abort: 273 get_bad_stack 274 bad_save_user_regs 275 bl do_prefetch_abort 276 277 .align 5 278data_abort: 279 get_bad_stack 280 bad_save_user_regs 281 bl do_data_abort 282 283 .align 5 284not_used: 285 get_bad_stack 286 bad_save_user_regs 287 bl do_not_used 288 289 290 .align 5 291irq: 292#if CONFIG_IS_ENABLED(IRQ) 293 get_irq_stack 294 irq_save_user_regs 295 bl do_irq 296 irq_restore_user_regs 297#else 298 get_bad_stack 299 bad_save_user_regs 300 bl do_irq 301#endif 302 303 .align 5 304fiq: 305 get_bad_stack 306 bad_save_user_regs 307 bl do_fiq 308 309#endif /* CONFIG_SPL_BUILD */ 310