start.S 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  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. * Copyright (c) 2010 Albert Aribaud <albert.u.boot@aribaud.net>
  14. *
  15. * SPDX-License-Identifier: GPL-2.0+
  16. */
  17. #include <asm-offsets.h>
  18. #include <config.h>
  19. #include <common.h>
  20. #include <version.h>
  21. /*
  22. *************************************************************************
  23. *
  24. * Jump vector table as in table 3.1 in [1]
  25. *
  26. *************************************************************************
  27. */
  28. #ifdef CONFIG_SYS_DV_NOR_BOOT_CFG
  29. .globl _start
  30. _start:
  31. .globl _NOR_BOOT_CFG
  32. _NOR_BOOT_CFG:
  33. .word CONFIG_SYS_DV_NOR_BOOT_CFG
  34. b reset
  35. #else
  36. .globl _start
  37. _start:
  38. b reset
  39. #endif
  40. #ifdef CONFIG_SPL_BUILD
  41. /* No exception handlers in preloader */
  42. ldr pc, _hang
  43. ldr pc, _hang
  44. ldr pc, _hang
  45. ldr pc, _hang
  46. ldr pc, _hang
  47. ldr pc, _hang
  48. ldr pc, _hang
  49. _hang:
  50. .word do_hang
  51. /* pad to 64 byte boundary */
  52. .word 0x12345678
  53. .word 0x12345678
  54. .word 0x12345678
  55. .word 0x12345678
  56. .word 0x12345678
  57. .word 0x12345678
  58. .word 0x12345678
  59. #else
  60. ldr pc, _undefined_instruction
  61. ldr pc, _software_interrupt
  62. ldr pc, _prefetch_abort
  63. ldr pc, _data_abort
  64. ldr pc, _not_used
  65. ldr pc, _irq
  66. ldr pc, _fiq
  67. _undefined_instruction:
  68. .word undefined_instruction
  69. _software_interrupt:
  70. .word software_interrupt
  71. _prefetch_abort:
  72. .word prefetch_abort
  73. _data_abort:
  74. .word data_abort
  75. _not_used:
  76. .word not_used
  77. _irq:
  78. .word irq
  79. _fiq:
  80. .word fiq
  81. #endif /* CONFIG_SPL_BUILD */
  82. .balignl 16,0xdeadbeef
  83. /*
  84. *************************************************************************
  85. *
  86. * Startup Code (reset vector)
  87. *
  88. * do important init only if we don't start from memory!
  89. * setup Memory and board specific bits prior to relocation.
  90. * relocate armboot to ram
  91. * setup stack
  92. *
  93. *************************************************************************
  94. */
  95. .globl _TEXT_BASE
  96. _TEXT_BASE:
  97. #if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_TEXT_BASE)
  98. .word CONFIG_SPL_TEXT_BASE
  99. #else
  100. .word CONFIG_SYS_TEXT_BASE
  101. #endif
  102. /*
  103. * These are defined in the board-specific linker script.
  104. * Subtracting _start from them lets the linker put their
  105. * relative position in the executable instead of leaving
  106. * them null.
  107. */
  108. .globl _bss_start_ofs
  109. _bss_start_ofs:
  110. .word __bss_start - _start
  111. .globl _bss_end_ofs
  112. _bss_end_ofs:
  113. .word __bss_end - _start
  114. .globl _end_ofs
  115. _end_ofs:
  116. .word _end - _start
  117. #ifdef CONFIG_USE_IRQ
  118. /* IRQ stack memory (calculated at run-time) */
  119. .globl IRQ_STACK_START
  120. IRQ_STACK_START:
  121. .word 0x0badc0de
  122. /* IRQ stack memory (calculated at run-time) */
  123. .globl FIQ_STACK_START
  124. FIQ_STACK_START:
  125. .word 0x0badc0de
  126. #endif
  127. /* IRQ stack memory (calculated at run-time) + 8 bytes */
  128. .globl IRQ_STACK_START_IN
  129. IRQ_STACK_START_IN:
  130. .word 0x0badc0de
  131. /*
  132. * the actual reset code
  133. */
  134. reset:
  135. /*
  136. * set the cpu to SVC32 mode
  137. */
  138. mrs r0,cpsr
  139. bic r0,r0,#0x1f
  140. orr r0,r0,#0xd3
  141. msr cpsr,r0
  142. /*
  143. * we do sys-critical inits only at reboot,
  144. * not when booting from ram!
  145. */
  146. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  147. bl cpu_init_crit
  148. #endif
  149. bl _main
  150. /*------------------------------------------------------------------------------*/
  151. .globl c_runtime_cpu_setup
  152. c_runtime_cpu_setup:
  153. bx lr
  154. /*
  155. *************************************************************************
  156. *
  157. * CPU_init_critical registers
  158. *
  159. * setup important registers
  160. * setup memory timing
  161. *
  162. *************************************************************************
  163. */
  164. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  165. cpu_init_crit:
  166. /*
  167. * flush D cache before disabling it
  168. */
  169. mov r0, #0
  170. flush_dcache:
  171. mrc p15, 0, r15, c7, c10, 3
  172. bne flush_dcache
  173. mcr p15, 0, r0, c8, c7, 0 /* invalidate TLB */
  174. mcr p15, 0, r0, c7, c5, 0 /* invalidate I Cache */
  175. /*
  176. * disable MMU and D cache
  177. * enable I cache if CONFIG_SYS_ICACHE_OFF is not defined
  178. */
  179. mrc p15, 0, r0, c1, c0, 0
  180. bic r0, r0, #0x00000300 /* clear bits 9:8 (---- --RS) */
  181. bic r0, r0, #0x00000087 /* clear bits 7, 2:0 (B--- -CAM) */
  182. #ifdef CONFIG_SYS_EXCEPTION_VECTORS_HIGH
  183. orr r0, r0, #0x00002000 /* set bit 13 (--V- ----) */
  184. #else
  185. bic r0, r0, #0x00002000 /* clear bit 13 (--V- ----) */
  186. #endif
  187. orr r0, r0, #0x00000002 /* set bit 2 (A) Align */
  188. #ifndef CONFIG_SYS_ICACHE_OFF
  189. orr r0, r0, #0x00001000 /* set bit 12 (I) I-Cache */
  190. #endif
  191. mcr p15, 0, r0, c1, c0, 0
  192. /*
  193. * Go setup Memory and board specific bits prior to relocation.
  194. */
  195. mov ip, lr /* perserve link reg across call */
  196. bl lowlevel_init /* go setup pll,mux,memory */
  197. mov lr, ip /* restore link */
  198. mov pc, lr /* back to my caller */
  199. #endif /* CONFIG_SKIP_LOWLEVEL_INIT */
  200. #ifndef CONFIG_SPL_BUILD
  201. /*
  202. *************************************************************************
  203. *
  204. * Interrupt handling
  205. *
  206. *************************************************************************
  207. */
  208. @
  209. @ IRQ stack frame.
  210. @
  211. #define S_FRAME_SIZE 72
  212. #define S_OLD_R0 68
  213. #define S_PSR 64
  214. #define S_PC 60
  215. #define S_LR 56
  216. #define S_SP 52
  217. #define S_IP 48
  218. #define S_FP 44
  219. #define S_R10 40
  220. #define S_R9 36
  221. #define S_R8 32
  222. #define S_R7 28
  223. #define S_R6 24
  224. #define S_R5 20
  225. #define S_R4 16
  226. #define S_R3 12
  227. #define S_R2 8
  228. #define S_R1 4
  229. #define S_R0 0
  230. #define MODE_SVC 0x13
  231. #define I_BIT 0x80
  232. /*
  233. * use bad_save_user_regs for abort/prefetch/undef/swi ...
  234. * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling
  235. */
  236. .macro bad_save_user_regs
  237. @ carve out a frame on current user stack
  238. sub sp, sp, #S_FRAME_SIZE
  239. stmia sp, {r0 - r12} @ Save user registers (now in svc mode) r0-r12
  240. ldr r2, IRQ_STACK_START_IN
  241. @ get values for "aborted" pc and cpsr (into parm regs)
  242. ldmia r2, {r2 - r3}
  243. add r0, sp, #S_FRAME_SIZE @ grab pointer to old stack
  244. add r5, sp, #S_SP
  245. mov r1, lr
  246. stmia r5, {r0 - r3} @ save sp_SVC, lr_SVC, pc, cpsr
  247. mov r0, sp @ save current stack into r0 (param register)
  248. .endm
  249. .macro irq_save_user_regs
  250. sub sp, sp, #S_FRAME_SIZE
  251. stmia sp, {r0 - r12} @ Calling r0-r12
  252. @ !!!! R8 NEEDS to be saved !!!! a reserved stack spot would be good.
  253. add r8, sp, #S_PC
  254. stmdb r8, {sp, lr}^ @ Calling SP, LR
  255. str lr, [r8, #0] @ Save calling PC
  256. mrs r6, spsr
  257. str r6, [r8, #4] @ Save CPSR
  258. str r0, [r8, #8] @ Save OLD_R0
  259. mov r0, sp
  260. .endm
  261. .macro irq_restore_user_regs
  262. ldmia sp, {r0 - lr}^ @ Calling r0 - lr
  263. mov r0, r0
  264. ldr lr, [sp, #S_PC] @ Get PC
  265. add sp, sp, #S_FRAME_SIZE
  266. subs pc, lr, #4 @ return & move spsr_svc into cpsr
  267. .endm
  268. .macro get_bad_stack
  269. ldr r13, IRQ_STACK_START_IN @ setup our mode stack
  270. str lr, [r13] @ save caller lr in position 0 of saved stack
  271. mrs lr, spsr @ get the spsr
  272. str lr, [r13, #4] @ save spsr in position 1 of saved stack
  273. mov r13, #MODE_SVC @ prepare SVC-Mode
  274. @ msr spsr_c, r13
  275. msr spsr, r13 @ switch modes, make sure moves will execute
  276. mov lr, pc @ capture return pc
  277. movs pc, lr @ jump to next instruction & switch modes.
  278. .endm
  279. .macro get_irq_stack @ setup IRQ stack
  280. ldr sp, IRQ_STACK_START
  281. .endm
  282. .macro get_fiq_stack @ setup FIQ stack
  283. ldr sp, FIQ_STACK_START
  284. .endm
  285. #endif /* CONFIG_SPL_BUILD */
  286. /*
  287. * exception handlers
  288. */
  289. #ifdef CONFIG_SPL_BUILD
  290. .align 5
  291. do_hang:
  292. ldr sp, _TEXT_BASE /* switch to abort stack */
  293. 1:
  294. bl 1b /* hang and never return */
  295. #else /* !CONFIG_SPL_BUILD */
  296. .align 5
  297. undefined_instruction:
  298. get_bad_stack
  299. bad_save_user_regs
  300. bl do_undefined_instruction
  301. .align 5
  302. software_interrupt:
  303. get_bad_stack
  304. bad_save_user_regs
  305. bl do_software_interrupt
  306. .align 5
  307. prefetch_abort:
  308. get_bad_stack
  309. bad_save_user_regs
  310. bl do_prefetch_abort
  311. .align 5
  312. data_abort:
  313. get_bad_stack
  314. bad_save_user_regs
  315. bl do_data_abort
  316. .align 5
  317. not_used:
  318. get_bad_stack
  319. bad_save_user_regs
  320. bl do_not_used
  321. #ifdef CONFIG_USE_IRQ
  322. .align 5
  323. irq:
  324. get_irq_stack
  325. irq_save_user_regs
  326. bl do_irq
  327. irq_restore_user_regs
  328. .align 5
  329. fiq:
  330. get_fiq_stack
  331. /* someone ought to write a more effiction fiq_save_user_regs */
  332. irq_save_user_regs
  333. bl do_fiq
  334. irq_restore_user_regs
  335. #else
  336. .align 5
  337. irq:
  338. get_bad_stack
  339. bad_save_user_regs
  340. bl do_irq
  341. .align 5
  342. fiq:
  343. get_bad_stack
  344. bad_save_user_regs
  345. bl do_fiq
  346. #endif
  347. #endif /* CONFIG_SPL_BUILD */