start.S 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. /*
  2. * armboot - Startup Code for ARM720 CPU-core
  3. *
  4. * Copyright (c) 2001 Marius Gröger <mag@sysgo.de>
  5. * Copyright (c) 2002 Alex Züpke <azu@sysgo.de>
  6. *
  7. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. */
  25. #include <asm-offsets.h>
  26. #include <config.h>
  27. #include <version.h>
  28. #include <asm/hardware.h>
  29. /*
  30. *************************************************************************
  31. *
  32. * Jump vector table as in table 3.1 in [1]
  33. *
  34. *************************************************************************
  35. */
  36. .globl _start
  37. _start: b reset
  38. ldr pc, _undefined_instruction
  39. ldr pc, _software_interrupt
  40. ldr pc, _prefetch_abort
  41. ldr pc, _data_abort
  42. ldr pc, _not_used
  43. ldr pc, _irq
  44. ldr pc, _fiq
  45. #ifdef CONFIG_SPL_BUILD
  46. _undefined_instruction: .word _undefined_instruction
  47. _software_interrupt: .word _software_interrupt
  48. _prefetch_abort: .word _prefetch_abort
  49. _data_abort: .word _data_abort
  50. _not_used: .word _not_used
  51. _irq: .word _irq
  52. _fiq: .word _fiq
  53. _pad: .word 0x12345678 /* now 16*4=64 */
  54. #else
  55. _undefined_instruction: .word undefined_instruction
  56. _software_interrupt: .word software_interrupt
  57. _prefetch_abort: .word prefetch_abort
  58. _data_abort: .word data_abort
  59. _not_used: .word not_used
  60. _irq: .word irq
  61. _fiq: .word fiq
  62. _pad: .word 0x12345678 /* now 16*4=64 */
  63. #endif /* CONFIG_SPL_BUILD */
  64. .balignl 16,0xdeadbeef
  65. /*
  66. *************************************************************************
  67. *
  68. * Startup Code (reset vector)
  69. *
  70. * do important init only if we don't start from RAM!
  71. * relocate armboot to ram
  72. * setup stack
  73. * jump to second stage
  74. *
  75. *************************************************************************
  76. */
  77. .globl _TEXT_BASE
  78. _TEXT_BASE:
  79. #if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_TEXT_BASE)
  80. .word CONFIG_SPL_TEXT_BASE
  81. #else
  82. .word CONFIG_SYS_TEXT_BASE
  83. #endif
  84. /*
  85. * These are defined in the board-specific linker script.
  86. * Subtracting _start from them lets the linker put their
  87. * relative position in the executable instead of leaving
  88. * them null.
  89. */
  90. .globl _bss_start_ofs
  91. _bss_start_ofs:
  92. .word __bss_start - _start
  93. .globl _bss_end_ofs
  94. _bss_end_ofs:
  95. .word __bss_end - _start
  96. .globl _end_ofs
  97. _end_ofs:
  98. .word _end - _start
  99. #ifdef CONFIG_USE_IRQ
  100. /* IRQ stack memory (calculated at run-time) */
  101. .globl IRQ_STACK_START
  102. IRQ_STACK_START:
  103. .word 0x0badc0de
  104. /* IRQ stack memory (calculated at run-time) */
  105. .globl FIQ_STACK_START
  106. FIQ_STACK_START:
  107. .word 0x0badc0de
  108. #endif
  109. /* IRQ stack memory (calculated at run-time) + 8 bytes */
  110. .globl IRQ_STACK_START_IN
  111. IRQ_STACK_START_IN:
  112. .word 0x0badc0de
  113. /*
  114. * the actual reset code
  115. */
  116. reset:
  117. /*
  118. * set the cpu to SVC32 mode
  119. */
  120. mrs r0,cpsr
  121. bic r0,r0,#0x1f
  122. orr r0,r0,#0xd3
  123. msr cpsr,r0
  124. /*
  125. * we do sys-critical inits only at reboot,
  126. * not when booting from ram!
  127. */
  128. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  129. bl cpu_init_crit
  130. #endif
  131. bl _main
  132. /*------------------------------------------------------------------------------*/
  133. .globl c_runtime_cpu_setup
  134. c_runtime_cpu_setup:
  135. mov pc, lr
  136. /*
  137. *************************************************************************
  138. *
  139. * CPU_init_critical registers
  140. *
  141. * setup important registers
  142. * setup memory timing
  143. *
  144. *************************************************************************
  145. */
  146. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  147. cpu_init_crit:
  148. mov ip, lr
  149. /*
  150. * before relocating, we have to setup RAM timing
  151. * because memory timing is board-dependent, you will
  152. * find a lowlevel_init.S in your board directory.
  153. */
  154. bl lowlevel_init
  155. mov lr, ip
  156. mov pc, lr
  157. #endif /* CONFIG_SKIP_LOWLEVEL_INIT */
  158. #ifndef CONFIG_SPL_BUILD
  159. /*
  160. *************************************************************************
  161. *
  162. * Interrupt handling
  163. *
  164. *************************************************************************
  165. */
  166. @
  167. @ IRQ stack frame.
  168. @
  169. #define S_FRAME_SIZE 72
  170. #define S_OLD_R0 68
  171. #define S_PSR 64
  172. #define S_PC 60
  173. #define S_LR 56
  174. #define S_SP 52
  175. #define S_IP 48
  176. #define S_FP 44
  177. #define S_R10 40
  178. #define S_R9 36
  179. #define S_R8 32
  180. #define S_R7 28
  181. #define S_R6 24
  182. #define S_R5 20
  183. #define S_R4 16
  184. #define S_R3 12
  185. #define S_R2 8
  186. #define S_R1 4
  187. #define S_R0 0
  188. #define MODE_SVC 0x13
  189. #define I_BIT 0x80
  190. /*
  191. * use bad_save_user_regs for abort/prefetch/undef/swi ...
  192. * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling
  193. */
  194. .macro bad_save_user_regs
  195. sub sp, sp, #S_FRAME_SIZE
  196. stmia sp, {r0 - r12} @ Calling r0-r12
  197. add r8, sp, #S_PC
  198. ldr r2, IRQ_STACK_START_IN
  199. ldmia r2, {r2 - r4} @ get pc, cpsr, old_r0
  200. add r0, sp, #S_FRAME_SIZE @ restore sp_SVC
  201. add r5, sp, #S_SP
  202. mov r1, lr
  203. stmia r5, {r0 - r4} @ save sp_SVC, lr_SVC, pc, cpsr, old_r
  204. mov r0, sp
  205. .endm
  206. .macro irq_save_user_regs
  207. sub sp, sp, #S_FRAME_SIZE
  208. stmia sp, {r0 - r12} @ Calling r0-r12
  209. add r8, sp, #S_PC
  210. stmdb r8, {sp, lr}^ @ Calling SP, LR
  211. str lr, [r8, #0] @ Save calling PC
  212. mrs r6, spsr
  213. str r6, [r8, #4] @ Save CPSR
  214. str r0, [r8, #8] @ Save OLD_R0
  215. mov r0, sp
  216. .endm
  217. .macro irq_restore_user_regs
  218. ldmia sp, {r0 - lr}^ @ Calling r0 - lr
  219. mov r0, r0
  220. ldr lr, [sp, #S_PC] @ Get PC
  221. add sp, sp, #S_FRAME_SIZE
  222. subs pc, lr, #4 @ return & move spsr_svc into cpsr
  223. .endm
  224. .macro get_bad_stack
  225. ldr r13, IRQ_STACK_START_IN @ setup our mode stack
  226. str lr, [r13] @ save caller lr / spsr
  227. mrs lr, spsr
  228. str lr, [r13, #4]
  229. mov r13, #MODE_SVC @ prepare SVC-Mode
  230. msr spsr_c, r13
  231. mov lr, pc
  232. movs pc, lr
  233. .endm
  234. .macro get_irq_stack @ setup IRQ stack
  235. ldr sp, IRQ_STACK_START
  236. .endm
  237. .macro get_fiq_stack @ setup FIQ stack
  238. ldr sp, FIQ_STACK_START
  239. .endm
  240. /*
  241. * exception handlers
  242. */
  243. .align 5
  244. undefined_instruction:
  245. get_bad_stack
  246. bad_save_user_regs
  247. bl do_undefined_instruction
  248. .align 5
  249. software_interrupt:
  250. get_bad_stack
  251. bad_save_user_regs
  252. bl do_software_interrupt
  253. .align 5
  254. prefetch_abort:
  255. get_bad_stack
  256. bad_save_user_regs
  257. bl do_prefetch_abort
  258. .align 5
  259. data_abort:
  260. get_bad_stack
  261. bad_save_user_regs
  262. bl do_data_abort
  263. .align 5
  264. not_used:
  265. get_bad_stack
  266. bad_save_user_regs
  267. bl do_not_used
  268. #ifdef CONFIG_USE_IRQ
  269. .align 5
  270. irq:
  271. get_irq_stack
  272. irq_save_user_regs
  273. bl do_irq
  274. irq_restore_user_regs
  275. .align 5
  276. fiq:
  277. get_fiq_stack
  278. /* someone ought to write a more effiction fiq_save_user_regs */
  279. irq_save_user_regs
  280. bl do_fiq
  281. irq_restore_user_regs
  282. #else
  283. .align 5
  284. irq:
  285. get_bad_stack
  286. bad_save_user_regs
  287. bl do_irq
  288. .align 5
  289. fiq:
  290. get_bad_stack
  291. bad_save_user_regs
  292. bl do_fiq
  293. #endif
  294. #endif /* CONFIG_SPL_BUILD */