vectors.S 6.4 KB

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