start.S 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. /*
  2. * armboot - Startup Code for ARM926EJS CPU-core
  3. *
  4. * Copyright (c) 2003 Texas Instruments
  5. *
  6. * ----- Adapted for OMAP1610 OMAP730 from ARM925t code ------
  7. *
  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) 2003 Richard Woodruff <r-woodruff2@ti.com>
  12. * Copyright (c) 2003 Kshitij <kshitij@ti.com>
  13. *
  14. * SPDX-License-Identifier: GPL-2.0+
  15. */
  16. #include <asm-offsets.h>
  17. #include <config.h>
  18. #include <version.h>
  19. /*
  20. *************************************************************************
  21. *
  22. * Jump vector table
  23. *
  24. *************************************************************************
  25. */
  26. .globl _start
  27. _start:
  28. b reset
  29. ldr pc, _undefined_instruction
  30. ldr pc, _software_interrupt
  31. ldr pc, _prefetch_abort
  32. ldr pc, _data_abort
  33. ldr pc, _not_used
  34. ldr pc, _irq
  35. ldr pc, _fiq
  36. _undefined_instruction:
  37. .word undefined_instruction
  38. _software_interrupt:
  39. .word software_interrupt
  40. _prefetch_abort:
  41. .word prefetch_abort
  42. _data_abort:
  43. .word data_abort
  44. _not_used:
  45. .word not_used
  46. _irq:
  47. .word irq
  48. _fiq:
  49. .word fiq
  50. .balignl 16,0xdeadbeef
  51. /*
  52. *************************************************************************
  53. *
  54. * Startup Code (reset vector)
  55. *
  56. * do important init only if we don't start from memory!
  57. * setup memory and board specific bits prior to relocation.
  58. * relocate armboot to ram
  59. * setup stack
  60. *
  61. *************************************************************************
  62. */
  63. #ifdef CONFIG_USE_IRQ
  64. /* IRQ stack memory (calculated at run-time) */
  65. .globl IRQ_STACK_START
  66. IRQ_STACK_START:
  67. .word 0x0badc0de
  68. /* IRQ stack memory (calculated at run-time) */
  69. .globl FIQ_STACK_START
  70. FIQ_STACK_START:
  71. .word 0x0badc0de
  72. #endif
  73. /* IRQ stack memory (calculated at run-time) + 8 bytes */
  74. .globl IRQ_STACK_START_IN
  75. IRQ_STACK_START_IN:
  76. .word 0x0badc0de
  77. /*
  78. * the actual reset code
  79. */
  80. reset:
  81. /*
  82. * set the cpu to SVC32 mode
  83. */
  84. mrs r0,cpsr
  85. bic r0,r0,#0x1f
  86. orr r0,r0,#0xd3
  87. msr cpsr,r0
  88. /*
  89. * we do sys-critical inits only at reboot,
  90. * not when booting from ram!
  91. */
  92. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  93. bl cpu_init_crit
  94. #endif
  95. bl _main
  96. /*------------------------------------------------------------------------------*/
  97. .globl c_runtime_cpu_setup
  98. c_runtime_cpu_setup:
  99. mov pc, lr
  100. /*
  101. *************************************************************************
  102. *
  103. * CPU_init_critical registers
  104. *
  105. * setup important registers
  106. * setup memory timing
  107. *
  108. *************************************************************************
  109. */
  110. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  111. cpu_init_crit:
  112. /* arm_int_generic assumes the ARM boot monitor, or user software,
  113. * has initialized the platform
  114. */
  115. mov pc, lr /* back to my caller */
  116. #endif
  117. /*
  118. *************************************************************************
  119. *
  120. * Interrupt handling
  121. *
  122. *************************************************************************
  123. */
  124. @
  125. @ IRQ stack frame.
  126. @
  127. #define S_FRAME_SIZE 72
  128. #define S_OLD_R0 68
  129. #define S_PSR 64
  130. #define S_PC 60
  131. #define S_LR 56
  132. #define S_SP 52
  133. #define S_IP 48
  134. #define S_FP 44
  135. #define S_R10 40
  136. #define S_R9 36
  137. #define S_R8 32
  138. #define S_R7 28
  139. #define S_R6 24
  140. #define S_R5 20
  141. #define S_R4 16
  142. #define S_R3 12
  143. #define S_R2 8
  144. #define S_R1 4
  145. #define S_R0 0
  146. #define MODE_SVC 0x13
  147. #define I_BIT 0x80
  148. /*
  149. * use bad_save_user_regs for abort/prefetch/undef/swi ...
  150. * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling
  151. */
  152. .macro bad_save_user_regs
  153. @ carve out a frame on current user stack
  154. sub sp, sp, #S_FRAME_SIZE
  155. stmia sp, {r0 - r12} @ Save user registers (now in svc mode) r0-r12
  156. ldr r2, IRQ_STACK_START_IN
  157. @ get values for "aborted" pc and cpsr (into parm regs)
  158. ldmia r2, {r2 - r3}
  159. add r0, sp, #S_FRAME_SIZE @ grab pointer to old stack
  160. add r5, sp, #S_SP
  161. mov r1, lr
  162. stmia r5, {r0 - r3} @ save sp_SVC, lr_SVC, pc, cpsr
  163. mov r0, sp @ save current stack into r0 (param register)
  164. .endm
  165. .macro irq_save_user_regs
  166. sub sp, sp, #S_FRAME_SIZE
  167. stmia sp, {r0 - r12} @ Calling r0-r12
  168. @ !!!! R8 NEEDS to be saved !!!! a reserved stack spot would be good.
  169. add r8, sp, #S_PC
  170. stmdb r8, {sp, lr}^ @ Calling SP, LR
  171. str lr, [r8, #0] @ Save calling PC
  172. mrs r6, spsr
  173. str r6, [r8, #4] @ Save CPSR
  174. str r0, [r8, #8] @ Save OLD_R0
  175. mov r0, sp
  176. .endm
  177. .macro irq_restore_user_regs
  178. ldmia sp, {r0 - lr}^ @ Calling r0 - lr
  179. mov r0, r0
  180. ldr lr, [sp, #S_PC] @ Get PC
  181. add sp, sp, #S_FRAME_SIZE
  182. subs pc, lr, #4 @ return & move spsr_svc into cpsr
  183. .endm
  184. .macro get_bad_stack
  185. ldr r13, IRQ_STACK_START_IN @ setup our mode stack
  186. str lr, [r13] @ save caller lr in position 0 of saved stack
  187. mrs lr, spsr @ get the spsr
  188. str lr, [r13, #4] @ save spsr in position 1 of saved stack
  189. mov r13, #MODE_SVC @ prepare SVC-Mode
  190. @ msr spsr_c, r13
  191. msr spsr, r13 @ switch modes, make sure moves will execute
  192. mov lr, pc @ capture return pc
  193. movs pc, lr @ jump to next instruction & switch modes.
  194. .endm
  195. .macro get_irq_stack @ setup IRQ stack
  196. ldr sp, IRQ_STACK_START
  197. .endm
  198. .macro get_fiq_stack @ setup FIQ stack
  199. ldr sp, FIQ_STACK_START
  200. .endm
  201. /*
  202. * exception handlers
  203. */
  204. .align 5
  205. .globl undefined_instruction
  206. undefined_instruction:
  207. get_bad_stack
  208. bad_save_user_regs
  209. bl do_undefined_instruction
  210. .align 5
  211. .globl software_interrupt
  212. software_interrupt:
  213. get_bad_stack
  214. bad_save_user_regs
  215. bl do_software_interrupt
  216. .align 5
  217. .globl prefetch_abort
  218. prefetch_abort:
  219. get_bad_stack
  220. bad_save_user_regs
  221. bl do_prefetch_abort
  222. .align 5
  223. .globl data_abort
  224. data_abort:
  225. get_bad_stack
  226. bad_save_user_regs
  227. bl do_data_abort
  228. .align 5
  229. .globl not_used
  230. not_used:
  231. get_bad_stack
  232. bad_save_user_regs
  233. bl do_not_used
  234. #ifdef CONFIG_USE_IRQ
  235. .align 5
  236. .globl irq
  237. irq:
  238. get_irq_stack
  239. irq_save_user_regs
  240. bl do_irq
  241. irq_restore_user_regs
  242. .align 5
  243. .globl fiq
  244. fiq:
  245. get_fiq_stack
  246. /* someone ought to write a more effiction fiq_save_user_regs */
  247. irq_save_user_regs
  248. bl do_fiq
  249. irq_restore_user_regs
  250. #else
  251. .align 5
  252. .globl irq
  253. irq:
  254. get_bad_stack
  255. bad_save_user_regs
  256. bl do_irq
  257. .align 5
  258. .globl fiq
  259. fiq:
  260. get_bad_stack
  261. bad_save_user_regs
  262. bl do_fiq
  263. #endif