start.S 8.9 KB

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