start.S 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. /*
  2. * armboot - Startup Code for OMAP3530/ARM Cortex CPU-core
  3. *
  4. * Copyright (c) 2004 Texas Instruments <r-woodruff2@ti.com>
  5. *
  6. * Copyright (c) 2001 Marius Gröger <mag@sysgo.de>
  7. * Copyright (c) 2002 Alex Züpke <azu@sysgo.de>
  8. * Copyright (c) 2002 Gary Jennejohn <garyj@denx.de>
  9. * Copyright (c) 2003 Richard Woodruff <r-woodruff2@ti.com>
  10. * Copyright (c) 2003 Kshitij <kshitij@ti.com>
  11. * Copyright (c) 2006-2008 Syed Mohammed Khasim <x0khasim@ti.com>
  12. *
  13. * SPDX-License-Identifier: GPL-2.0+
  14. */
  15. #include <asm-offsets.h>
  16. #include <config.h>
  17. #include <version.h>
  18. #include <asm/system.h>
  19. #include <linux/linkage.h>
  20. .globl _start
  21. _start: b reset
  22. ldr pc, _undefined_instruction
  23. ldr pc, _software_interrupt
  24. ldr pc, _prefetch_abort
  25. ldr pc, _data_abort
  26. ldr pc, _not_used
  27. ldr pc, _irq
  28. ldr pc, _fiq
  29. #ifdef CONFIG_SPL_BUILD
  30. _undefined_instruction: .word _undefined_instruction
  31. _software_interrupt: .word _software_interrupt
  32. _prefetch_abort: .word _prefetch_abort
  33. _data_abort: .word _data_abort
  34. _not_used: .word _not_used
  35. _irq: .word _irq
  36. _fiq: .word _fiq
  37. _pad: .word 0x12345678 /* now 16*4=64 */
  38. #else
  39. .globl _undefined_instruction
  40. _undefined_instruction: .word undefined_instruction
  41. .globl _software_interrupt
  42. _software_interrupt: .word software_interrupt
  43. .globl _prefetch_abort
  44. _prefetch_abort: .word prefetch_abort
  45. .globl _data_abort
  46. _data_abort: .word data_abort
  47. .globl _not_used
  48. _not_used: .word not_used
  49. .globl _irq
  50. _irq: .word irq
  51. .globl _fiq
  52. _fiq: .word fiq
  53. _pad: .word 0x12345678 /* now 16*4=64 */
  54. #endif /* CONFIG_SPL_BUILD */
  55. .global _end_vect
  56. _end_vect:
  57. .balignl 16,0xdeadbeef
  58. /*************************************************************************
  59. *
  60. * Startup Code (reset vector)
  61. *
  62. * do important init only if we don't start from memory!
  63. * setup Memory and board specific bits prior to relocation.
  64. * relocate armboot to ram
  65. * setup stack
  66. *
  67. *************************************************************************/
  68. #ifdef CONFIG_USE_IRQ
  69. /* IRQ stack memory (calculated at run-time) */
  70. .globl IRQ_STACK_START
  71. IRQ_STACK_START:
  72. .word 0x0badc0de
  73. /* IRQ stack memory (calculated at run-time) */
  74. .globl FIQ_STACK_START
  75. FIQ_STACK_START:
  76. .word 0x0badc0de
  77. #endif
  78. /* IRQ stack memory (calculated at run-time) + 8 bytes */
  79. .globl IRQ_STACK_START_IN
  80. IRQ_STACK_START_IN:
  81. .word 0x0badc0de
  82. /*
  83. * the actual reset code
  84. */
  85. reset:
  86. bl save_boot_params
  87. /*
  88. * disable interrupts (FIQ and IRQ), also set the cpu to SVC32 mode,
  89. * except if in HYP mode already
  90. */
  91. mrs r0, cpsr
  92. and r1, r0, #0x1f @ mask mode bits
  93. teq r1, #0x1a @ test for HYP mode
  94. bicne r0, r0, #0x1f @ clear all mode bits
  95. orrne r0, r0, #0x13 @ set SVC mode
  96. orr r0, r0, #0xc0 @ disable FIQ and IRQ
  97. msr cpsr,r0
  98. /*
  99. * Setup vector:
  100. * (OMAP4 spl TEXT_BASE is not 32 byte aligned.
  101. * Continue to use ROM code vector only in OMAP4 spl)
  102. */
  103. #if !(defined(CONFIG_OMAP44XX) && defined(CONFIG_SPL_BUILD))
  104. /* Set V=0 in CP15 SCTRL register - for VBAR to point to vector */
  105. mrc p15, 0, r0, c1, c0, 0 @ Read CP15 SCTRL Register
  106. bic r0, #CR_V @ V = 0
  107. mcr p15, 0, r0, c1, c0, 0 @ Write CP15 SCTRL Register
  108. /* Set vector address in CP15 VBAR register */
  109. ldr r0, =_start
  110. mcr p15, 0, r0, c12, c0, 0 @Set VBAR
  111. #endif
  112. /* the mask ROM code should have PLL and others stable */
  113. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  114. bl cpu_init_cp15
  115. bl cpu_init_crit
  116. #endif
  117. bl _main
  118. /*------------------------------------------------------------------------------*/
  119. ENTRY(c_runtime_cpu_setup)
  120. /*
  121. * If I-cache is enabled invalidate it
  122. */
  123. #ifndef CONFIG_SYS_ICACHE_OFF
  124. mcr p15, 0, r0, c7, c5, 0 @ invalidate icache
  125. mcr p15, 0, r0, c7, c10, 4 @ DSB
  126. mcr p15, 0, r0, c7, c5, 4 @ ISB
  127. #endif
  128. /*
  129. * Move vector table
  130. */
  131. /* Set vector address in CP15 VBAR register */
  132. ldr r0, =_start
  133. mcr p15, 0, r0, c12, c0, 0 @Set VBAR
  134. bx lr
  135. ENDPROC(c_runtime_cpu_setup)
  136. /*************************************************************************
  137. *
  138. * void save_boot_params(u32 r0, u32 r1, u32 r2, u32 r3)
  139. * __attribute__((weak));
  140. *
  141. * Stack pointer is not yet initialized at this moment
  142. * Don't save anything to stack even if compiled with -O0
  143. *
  144. *************************************************************************/
  145. ENTRY(save_boot_params)
  146. bx lr @ back to my caller
  147. ENDPROC(save_boot_params)
  148. .weak save_boot_params
  149. /*************************************************************************
  150. *
  151. * cpu_init_cp15
  152. *
  153. * Setup CP15 registers (cache, MMU, TLBs). The I-cache is turned on unless
  154. * CONFIG_SYS_ICACHE_OFF is defined.
  155. *
  156. *************************************************************************/
  157. ENTRY(cpu_init_cp15)
  158. /*
  159. * Invalidate L1 I/D
  160. */
  161. mov r0, #0 @ set up for MCR
  162. mcr p15, 0, r0, c8, c7, 0 @ invalidate TLBs
  163. mcr p15, 0, r0, c7, c5, 0 @ invalidate icache
  164. mcr p15, 0, r0, c7, c5, 6 @ invalidate BP array
  165. mcr p15, 0, r0, c7, c10, 4 @ DSB
  166. mcr p15, 0, r0, c7, c5, 4 @ ISB
  167. /*
  168. * disable MMU stuff and caches
  169. */
  170. mrc p15, 0, r0, c1, c0, 0
  171. bic r0, r0, #0x00002000 @ clear bits 13 (--V-)
  172. bic r0, r0, #0x00000007 @ clear bits 2:0 (-CAM)
  173. orr r0, r0, #0x00000002 @ set bit 1 (--A-) Align
  174. orr r0, r0, #0x00000800 @ set bit 11 (Z---) BTB
  175. #ifdef CONFIG_SYS_ICACHE_OFF
  176. bic r0, r0, #0x00001000 @ clear bit 12 (I) I-cache
  177. #else
  178. orr r0, r0, #0x00001000 @ set bit 12 (I) I-cache
  179. #endif
  180. mcr p15, 0, r0, c1, c0, 0
  181. #ifdef CONFIG_ARM_ERRATA_716044
  182. mrc p15, 0, r0, c1, c0, 0 @ read system control register
  183. orr r0, r0, #1 << 11 @ set bit #11
  184. mcr p15, 0, r0, c1, c0, 0 @ write system control register
  185. #endif
  186. #if (defined(CONFIG_ARM_ERRATA_742230) || defined(CONFIG_ARM_ERRATA_794072))
  187. mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register
  188. orr r0, r0, #1 << 4 @ set bit #4
  189. mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register
  190. #endif
  191. #ifdef CONFIG_ARM_ERRATA_743622
  192. mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register
  193. orr r0, r0, #1 << 6 @ set bit #6
  194. mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register
  195. #endif
  196. #ifdef CONFIG_ARM_ERRATA_751472
  197. mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register
  198. orr r0, r0, #1 << 11 @ set bit #11
  199. mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register
  200. #endif
  201. #ifdef CONFIG_ARM_ERRATA_761320
  202. mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register
  203. orr r0, r0, #1 << 21 @ set bit #21
  204. mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register
  205. #endif
  206. mov pc, lr @ back to my caller
  207. ENDPROC(cpu_init_cp15)
  208. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  209. /*************************************************************************
  210. *
  211. * CPU_init_critical registers
  212. *
  213. * setup important registers
  214. * setup memory timing
  215. *
  216. *************************************************************************/
  217. ENTRY(cpu_init_crit)
  218. /*
  219. * Jump to board specific initialization...
  220. * The Mask ROM will have already initialized
  221. * basic memory. Go here to bump up clock rate and handle
  222. * wake up conditions.
  223. */
  224. b lowlevel_init @ go setup pll,mux,memory
  225. ENDPROC(cpu_init_crit)
  226. #endif
  227. #ifndef CONFIG_SPL_BUILD
  228. /*
  229. *************************************************************************
  230. *
  231. * Interrupt handling
  232. *
  233. *************************************************************************
  234. */
  235. @
  236. @ IRQ stack frame.
  237. @
  238. #define S_FRAME_SIZE 72
  239. #define S_OLD_R0 68
  240. #define S_PSR 64
  241. #define S_PC 60
  242. #define S_LR 56
  243. #define S_SP 52
  244. #define S_IP 48
  245. #define S_FP 44
  246. #define S_R10 40
  247. #define S_R9 36
  248. #define S_R8 32
  249. #define S_R7 28
  250. #define S_R6 24
  251. #define S_R5 20
  252. #define S_R4 16
  253. #define S_R3 12
  254. #define S_R2 8
  255. #define S_R1 4
  256. #define S_R0 0
  257. #define MODE_SVC 0x13
  258. #define I_BIT 0x80
  259. /*
  260. * use bad_save_user_regs for abort/prefetch/undef/swi ...
  261. * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling
  262. */
  263. .macro bad_save_user_regs
  264. sub sp, sp, #S_FRAME_SIZE @ carve out a frame on current
  265. @ user stack
  266. stmia sp, {r0 - r12} @ Save user registers (now in
  267. @ svc mode) r0-r12
  268. ldr r2, IRQ_STACK_START_IN @ set base 2 words into abort
  269. @ stack
  270. ldmia r2, {r2 - r3} @ get values for "aborted" pc
  271. @ and cpsr (into parm regs)
  272. add r0, sp, #S_FRAME_SIZE @ grab pointer to old stack
  273. add r5, sp, #S_SP
  274. mov r1, lr
  275. stmia r5, {r0 - r3} @ save sp_SVC, lr_SVC, pc, cpsr
  276. mov r0, sp @ save current stack into r0
  277. @ (param register)
  278. .endm
  279. .macro irq_save_user_regs
  280. sub sp, sp, #S_FRAME_SIZE
  281. stmia sp, {r0 - r12} @ Calling r0-r12
  282. add r8, sp, #S_PC @ !! R8 NEEDS to be saved !!
  283. @ a reserved stack spot would
  284. @ be good.
  285. stmdb r8, {sp, lr}^ @ Calling SP, LR
  286. str lr, [r8, #0] @ Save calling PC
  287. mrs r6, spsr
  288. str r6, [r8, #4] @ Save CPSR
  289. str r0, [r8, #8] @ Save OLD_R0
  290. mov r0, sp
  291. .endm
  292. .macro irq_restore_user_regs
  293. ldmia sp, {r0 - lr}^ @ Calling r0 - lr
  294. mov r0, r0
  295. ldr lr, [sp, #S_PC] @ Get PC
  296. add sp, sp, #S_FRAME_SIZE
  297. subs pc, lr, #4 @ return & move spsr_svc into
  298. @ cpsr
  299. .endm
  300. .macro get_bad_stack
  301. ldr r13, IRQ_STACK_START_IN @ setup our mode stack (enter
  302. @ in banked mode)
  303. str lr, [r13] @ save caller lr in position 0
  304. @ of saved stack
  305. mrs lr, spsr @ get the spsr
  306. str lr, [r13, #4] @ save spsr in position 1 of
  307. @ saved stack
  308. mov r13, #MODE_SVC @ prepare SVC-Mode
  309. @ msr spsr_c, r13
  310. msr spsr, r13 @ switch modes, make sure
  311. @ moves will execute
  312. mov lr, pc @ capture return pc
  313. movs pc, lr @ jump to next instruction &
  314. @ switch modes.
  315. .endm
  316. .macro get_bad_stack_swi
  317. sub r13, r13, #4 @ space on current stack for
  318. @ scratch reg.
  319. str r0, [r13] @ save R0's value.
  320. ldr r0, IRQ_STACK_START_IN @ get data regions start
  321. @ spots for abort stack
  322. str lr, [r0] @ save caller lr in position 0
  323. @ of saved stack
  324. mrs lr, spsr @ get the spsr
  325. str lr, [r0, #4] @ save spsr in position 1 of
  326. @ saved stack
  327. ldr lr, [r0] @ restore lr
  328. ldr r0, [r13] @ restore r0
  329. add r13, r13, #4 @ pop stack entry
  330. .endm
  331. .macro get_irq_stack @ setup IRQ stack
  332. ldr sp, IRQ_STACK_START
  333. .endm
  334. .macro get_fiq_stack @ setup FIQ stack
  335. ldr sp, FIQ_STACK_START
  336. .endm
  337. /*
  338. * exception handlers
  339. */
  340. .align 5
  341. undefined_instruction:
  342. get_bad_stack
  343. bad_save_user_regs
  344. bl do_undefined_instruction
  345. .align 5
  346. software_interrupt:
  347. get_bad_stack_swi
  348. bad_save_user_regs
  349. bl do_software_interrupt
  350. .align 5
  351. prefetch_abort:
  352. get_bad_stack
  353. bad_save_user_regs
  354. bl do_prefetch_abort
  355. .align 5
  356. data_abort:
  357. get_bad_stack
  358. bad_save_user_regs
  359. bl do_data_abort
  360. .align 5
  361. not_used:
  362. get_bad_stack
  363. bad_save_user_regs
  364. bl do_not_used
  365. #ifdef CONFIG_USE_IRQ
  366. .align 5
  367. irq:
  368. get_irq_stack
  369. irq_save_user_regs
  370. bl do_irq
  371. irq_restore_user_regs
  372. .align 5
  373. fiq:
  374. get_fiq_stack
  375. /* someone ought to write a more effective fiq_save_user_regs */
  376. irq_save_user_regs
  377. bl do_fiq
  378. irq_restore_user_regs
  379. #else
  380. .align 5
  381. irq:
  382. get_bad_stack
  383. bad_save_user_regs
  384. bl do_irq
  385. .align 5
  386. fiq:
  387. get_bad_stack
  388. bad_save_user_regs
  389. bl do_fiq
  390. #endif /* CONFIG_USE_IRQ */
  391. #endif /* CONFIG_SPL_BUILD */