vectors.S 6.8 KB

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