start.S 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  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. * See file CREDITS for list of people who contributed to this
  14. * project.
  15. *
  16. * This program is free software; you can redistribute it and/or
  17. * modify it under the terms of the GNU General Public License as
  18. * published by the Free Software Foundation; either version 2 of
  19. * the License, or (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program; if not, write to the Free Software
  28. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  29. * MA 02111-1307 USA
  30. */
  31. #include <asm-offsets.h>
  32. #include <config.h>
  33. #include <version.h>
  34. #include <asm/system.h>
  35. .globl _start
  36. _start: b reset
  37. ldr pc, _undefined_instruction
  38. ldr pc, _software_interrupt
  39. ldr pc, _prefetch_abort
  40. ldr pc, _data_abort
  41. ldr pc, _not_used
  42. ldr pc, _irq
  43. ldr pc, _fiq
  44. #ifdef CONFIG_SPL_BUILD
  45. _undefined_instruction: .word _undefined_instruction
  46. _software_interrupt: .word _software_interrupt
  47. _prefetch_abort: .word _prefetch_abort
  48. _data_abort: .word _data_abort
  49. _not_used: .word _not_used
  50. _irq: .word _irq
  51. _fiq: .word _fiq
  52. _pad: .word 0x12345678 /* now 16*4=64 */
  53. #else
  54. _undefined_instruction: .word undefined_instruction
  55. _software_interrupt: .word software_interrupt
  56. _prefetch_abort: .word prefetch_abort
  57. _data_abort: .word data_abort
  58. _not_used: .word not_used
  59. _irq: .word irq
  60. _fiq: .word fiq
  61. _pad: .word 0x12345678 /* now 16*4=64 */
  62. #endif /* CONFIG_SPL_BUILD */
  63. .global _end_vect
  64. _end_vect:
  65. .balignl 16,0xdeadbeef
  66. /*************************************************************************
  67. *
  68. * Startup Code (reset vector)
  69. *
  70. * do important init only if we don't start from memory!
  71. * setup Memory and board specific bits prior to relocation.
  72. * relocate armboot to ram
  73. * setup stack
  74. *
  75. *************************************************************************/
  76. .globl _TEXT_BASE
  77. _TEXT_BASE:
  78. .word CONFIG_SYS_TEXT_BASE
  79. /*
  80. * These are defined in the board-specific linker script.
  81. */
  82. .globl _bss_start_ofs
  83. _bss_start_ofs:
  84. .word __bss_start - _start
  85. .global _image_copy_end_ofs
  86. _image_copy_end_ofs:
  87. .word __image_copy_end - _start
  88. .globl _bss_end_ofs
  89. _bss_end_ofs:
  90. .word __bss_end__ - _start
  91. .globl _end_ofs
  92. _end_ofs:
  93. .word _end - _start
  94. #ifdef CONFIG_USE_IRQ
  95. /* IRQ stack memory (calculated at run-time) */
  96. .globl IRQ_STACK_START
  97. IRQ_STACK_START:
  98. .word 0x0badc0de
  99. /* IRQ stack memory (calculated at run-time) */
  100. .globl FIQ_STACK_START
  101. FIQ_STACK_START:
  102. .word 0x0badc0de
  103. #endif
  104. /* IRQ stack memory (calculated at run-time) + 8 bytes */
  105. .globl IRQ_STACK_START_IN
  106. IRQ_STACK_START_IN:
  107. .word 0x0badc0de
  108. /*
  109. * the actual reset code
  110. */
  111. reset:
  112. bl save_boot_params
  113. /*
  114. * set the cpu to SVC32 mode
  115. */
  116. mrs r0, cpsr
  117. bic r0, r0, #0x1f
  118. orr r0, r0, #0xd3
  119. msr cpsr,r0
  120. #if !defined(CONFIG_TEGRA2)
  121. /*
  122. * Setup vector:
  123. * (OMAP4 spl TEXT_BASE is not 32 byte aligned.
  124. * Continue to use ROM code vector only in OMAP4 spl)
  125. */
  126. #if !(defined(CONFIG_OMAP44XX) && defined(CONFIG_SPL_BUILD))
  127. /* Set V=0 in CP15 SCTRL register - for VBAR to point to vector */
  128. mrc p15, 0, r0, c1, c0, 0 @ Read CP15 SCTRL Register
  129. bic r0, #CR_V @ V = 0
  130. mcr p15, 0, r0, c1, c0, 0 @ Write CP15 SCTRL Register
  131. /* Set vector address in CP15 VBAR register */
  132. ldr r0, =_start
  133. mcr p15, 0, r0, c12, c0, 0 @Set VBAR
  134. #endif
  135. #endif /* !Tegra2 */
  136. /* the mask ROM code should have PLL and others stable */
  137. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  138. bl cpu_init_cp15
  139. bl cpu_init_crit
  140. #endif
  141. /* Set stackpointer in internal RAM to call board_init_f */
  142. call_board_init_f:
  143. ldr sp, =(CONFIG_SYS_INIT_SP_ADDR)
  144. bic sp, sp, #7 /* 8-byte alignment for ABI compliance */
  145. ldr r0,=0x00000000
  146. bl board_init_f
  147. /*------------------------------------------------------------------------------*/
  148. /*
  149. * void relocate_code (addr_sp, gd, addr_moni)
  150. *
  151. * This "function" does not return, instead it continues in RAM
  152. * after relocating the monitor code.
  153. *
  154. */
  155. .globl relocate_code
  156. relocate_code:
  157. mov r4, r0 /* save addr_sp */
  158. mov r5, r1 /* save addr of gd */
  159. mov r6, r2 /* save addr of destination */
  160. /* Set up the stack */
  161. stack_setup:
  162. mov sp, r4
  163. adr r0, _start
  164. cmp r0, r6
  165. moveq r9, #0 /* no relocation. relocation offset(r9) = 0 */
  166. beq clear_bss /* skip relocation */
  167. mov r1, r6 /* r1 <- scratch for copy_loop */
  168. ldr r3, _image_copy_end_ofs
  169. add r2, r0, r3 /* r2 <- source end address */
  170. copy_loop:
  171. ldmia r0!, {r9-r10} /* copy from source address [r0] */
  172. stmia r1!, {r9-r10} /* copy to target address [r1] */
  173. cmp r0, r2 /* until source end address [r2] */
  174. blo copy_loop
  175. #ifndef CONFIG_SPL_BUILD
  176. /*
  177. * fix .rel.dyn relocations
  178. */
  179. ldr r0, _TEXT_BASE /* r0 <- Text base */
  180. sub r9, r6, r0 /* r9 <- relocation offset */
  181. ldr r10, _dynsym_start_ofs /* r10 <- sym table ofs */
  182. add r10, r10, r0 /* r10 <- sym table in FLASH */
  183. ldr r2, _rel_dyn_start_ofs /* r2 <- rel dyn start ofs */
  184. add r2, r2, r0 /* r2 <- rel dyn start in FLASH */
  185. ldr r3, _rel_dyn_end_ofs /* r3 <- rel dyn end ofs */
  186. add r3, r3, r0 /* r3 <- rel dyn end in FLASH */
  187. fixloop:
  188. ldr r0, [r2] /* r0 <- location to fix up, IN FLASH! */
  189. add r0, r0, r9 /* r0 <- location to fix up in RAM */
  190. ldr r1, [r2, #4]
  191. and r7, r1, #0xff
  192. cmp r7, #23 /* relative fixup? */
  193. beq fixrel
  194. cmp r7, #2 /* absolute fixup? */
  195. beq fixabs
  196. /* ignore unknown type of fixup */
  197. b fixnext
  198. fixabs:
  199. /* absolute fix: set location to (offset) symbol value */
  200. mov r1, r1, LSR #4 /* r1 <- symbol index in .dynsym */
  201. add r1, r10, r1 /* r1 <- address of symbol in table */
  202. ldr r1, [r1, #4] /* r1 <- symbol value */
  203. add r1, r1, r9 /* r1 <- relocated sym addr */
  204. b fixnext
  205. fixrel:
  206. /* relative fix: increase location by offset */
  207. ldr r1, [r0]
  208. add r1, r1, r9
  209. fixnext:
  210. str r1, [r0]
  211. add r2, r2, #8 /* each rel.dyn entry is 8 bytes */
  212. cmp r2, r3
  213. blo fixloop
  214. b clear_bss
  215. _rel_dyn_start_ofs:
  216. .word __rel_dyn_start - _start
  217. _rel_dyn_end_ofs:
  218. .word __rel_dyn_end - _start
  219. _dynsym_start_ofs:
  220. .word __dynsym_start - _start
  221. #endif /* #ifndef CONFIG_SPL_BUILD */
  222. clear_bss:
  223. #ifdef CONFIG_SPL_BUILD
  224. /* No relocation for SPL */
  225. ldr r0, =__bss_start
  226. ldr r1, =__bss_end__
  227. #else
  228. ldr r0, _bss_start_ofs
  229. ldr r1, _bss_end_ofs
  230. mov r4, r6 /* reloc addr */
  231. add r0, r0, r4
  232. add r1, r1, r4
  233. #endif
  234. mov r2, #0x00000000 /* clear */
  235. clbss_l:str r2, [r0] /* clear loop... */
  236. add r0, r0, #4
  237. cmp r0, r1
  238. bne clbss_l
  239. /*
  240. * We are done. Do not return, instead branch to second part of board
  241. * initialization, now running from RAM.
  242. */
  243. jump_2_ram:
  244. /*
  245. * If I-cache is enabled invalidate it
  246. */
  247. #ifndef CONFIG_SYS_ICACHE_OFF
  248. mcr p15, 0, r0, c7, c5, 0 @ invalidate icache
  249. mcr p15, 0, r0, c7, c10, 4 @ DSB
  250. mcr p15, 0, r0, c7, c5, 4 @ ISB
  251. #endif
  252. ldr r0, _board_init_r_ofs
  253. adr r1, _start
  254. add lr, r0, r1
  255. add lr, lr, r9
  256. /* setup parameters for board_init_r */
  257. mov r0, r5 /* gd_t */
  258. mov r1, r6 /* dest_addr */
  259. /* jump to it ... */
  260. mov pc, lr
  261. _board_init_r_ofs:
  262. .word board_init_r - _start
  263. /*************************************************************************
  264. *
  265. * cpu_init_cp15
  266. *
  267. * Setup CP15 registers (cache, MMU, TLBs). The I-cache is turned on unless
  268. * CONFIG_SYS_ICACHE_OFF is defined.
  269. *
  270. *************************************************************************/
  271. .globl cpu_init_cp15
  272. cpu_init_cp15:
  273. /*
  274. * Invalidate L1 I/D
  275. */
  276. mov r0, #0 @ set up for MCR
  277. mcr p15, 0, r0, c8, c7, 0 @ invalidate TLBs
  278. mcr p15, 0, r0, c7, c5, 0 @ invalidate icache
  279. mcr p15, 0, r0, c7, c5, 6 @ invalidate BP array
  280. mcr p15, 0, r0, c7, c10, 4 @ DSB
  281. mcr p15, 0, r0, c7, c5, 4 @ ISB
  282. /*
  283. * disable MMU stuff and caches
  284. */
  285. mrc p15, 0, r0, c1, c0, 0
  286. bic r0, r0, #0x00002000 @ clear bits 13 (--V-)
  287. bic r0, r0, #0x00000007 @ clear bits 2:0 (-CAM)
  288. orr r0, r0, #0x00000002 @ set bit 1 (--A-) Align
  289. orr r0, r0, #0x00000800 @ set bit 11 (Z---) BTB
  290. #ifdef CONFIG_SYS_ICACHE_OFF
  291. bic r0, r0, #0x00001000 @ clear bit 12 (I) I-cache
  292. #else
  293. orr r0, r0, #0x00001000 @ set bit 12 (I) I-cache
  294. #endif
  295. mcr p15, 0, r0, c1, c0, 0
  296. mov pc, lr @ back to my caller
  297. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  298. /*************************************************************************
  299. *
  300. * CPU_init_critical registers
  301. *
  302. * setup important registers
  303. * setup memory timing
  304. *
  305. *************************************************************************/
  306. cpu_init_crit:
  307. /*
  308. * Jump to board specific initialization...
  309. * The Mask ROM will have already initialized
  310. * basic memory. Go here to bump up clock rate and handle
  311. * wake up conditions.
  312. */
  313. mov ip, lr @ persevere link reg across call
  314. bl lowlevel_init @ go setup pll,mux,memory
  315. mov lr, ip @ restore link
  316. mov pc, lr @ back to my caller
  317. #endif
  318. #ifndef CONFIG_SPL_BUILD
  319. /*
  320. *************************************************************************
  321. *
  322. * Interrupt handling
  323. *
  324. *************************************************************************
  325. */
  326. @
  327. @ IRQ stack frame.
  328. @
  329. #define S_FRAME_SIZE 72
  330. #define S_OLD_R0 68
  331. #define S_PSR 64
  332. #define S_PC 60
  333. #define S_LR 56
  334. #define S_SP 52
  335. #define S_IP 48
  336. #define S_FP 44
  337. #define S_R10 40
  338. #define S_R9 36
  339. #define S_R8 32
  340. #define S_R7 28
  341. #define S_R6 24
  342. #define S_R5 20
  343. #define S_R4 16
  344. #define S_R3 12
  345. #define S_R2 8
  346. #define S_R1 4
  347. #define S_R0 0
  348. #define MODE_SVC 0x13
  349. #define I_BIT 0x80
  350. /*
  351. * use bad_save_user_regs for abort/prefetch/undef/swi ...
  352. * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling
  353. */
  354. .macro bad_save_user_regs
  355. sub sp, sp, #S_FRAME_SIZE @ carve out a frame on current
  356. @ user stack
  357. stmia sp, {r0 - r12} @ Save user registers (now in
  358. @ svc mode) r0-r12
  359. ldr r2, IRQ_STACK_START_IN @ set base 2 words into abort
  360. @ stack
  361. ldmia r2, {r2 - r3} @ get values for "aborted" pc
  362. @ and cpsr (into parm regs)
  363. add r0, sp, #S_FRAME_SIZE @ grab pointer to old stack
  364. add r5, sp, #S_SP
  365. mov r1, lr
  366. stmia r5, {r0 - r3} @ save sp_SVC, lr_SVC, pc, cpsr
  367. mov r0, sp @ save current stack into r0
  368. @ (param register)
  369. .endm
  370. .macro irq_save_user_regs
  371. sub sp, sp, #S_FRAME_SIZE
  372. stmia sp, {r0 - r12} @ Calling r0-r12
  373. add r8, sp, #S_PC @ !! R8 NEEDS to be saved !!
  374. @ a reserved stack spot would
  375. @ be good.
  376. stmdb r8, {sp, lr}^ @ Calling SP, LR
  377. str lr, [r8, #0] @ Save calling PC
  378. mrs r6, spsr
  379. str r6, [r8, #4] @ Save CPSR
  380. str r0, [r8, #8] @ Save OLD_R0
  381. mov r0, sp
  382. .endm
  383. .macro irq_restore_user_regs
  384. ldmia sp, {r0 - lr}^ @ Calling r0 - lr
  385. mov r0, r0
  386. ldr lr, [sp, #S_PC] @ Get PC
  387. add sp, sp, #S_FRAME_SIZE
  388. subs pc, lr, #4 @ return & move spsr_svc into
  389. @ cpsr
  390. .endm
  391. .macro get_bad_stack
  392. ldr r13, IRQ_STACK_START_IN @ setup our mode stack (enter
  393. @ in banked mode)
  394. str lr, [r13] @ save caller lr in position 0
  395. @ of saved stack
  396. mrs lr, spsr @ get the spsr
  397. str lr, [r13, #4] @ save spsr in position 1 of
  398. @ saved stack
  399. mov r13, #MODE_SVC @ prepare SVC-Mode
  400. @ msr spsr_c, r13
  401. msr spsr, r13 @ switch modes, make sure
  402. @ moves will execute
  403. mov lr, pc @ capture return pc
  404. movs pc, lr @ jump to next instruction &
  405. @ switch modes.
  406. .endm
  407. .macro get_bad_stack_swi
  408. sub r13, r13, #4 @ space on current stack for
  409. @ scratch reg.
  410. str r0, [r13] @ save R0's value.
  411. ldr r0, IRQ_STACK_START_IN @ get data regions start
  412. @ spots for abort stack
  413. str lr, [r0] @ save caller lr in position 0
  414. @ of saved stack
  415. mrs r0, spsr @ get the spsr
  416. str lr, [r0, #4] @ save spsr in position 1 of
  417. @ saved stack
  418. ldr r0, [r13] @ restore r0
  419. add r13, r13, #4 @ pop stack entry
  420. .endm
  421. .macro get_irq_stack @ setup IRQ stack
  422. ldr sp, IRQ_STACK_START
  423. .endm
  424. .macro get_fiq_stack @ setup FIQ stack
  425. ldr sp, FIQ_STACK_START
  426. .endm
  427. /*
  428. * exception handlers
  429. */
  430. .align 5
  431. undefined_instruction:
  432. get_bad_stack
  433. bad_save_user_regs
  434. bl do_undefined_instruction
  435. .align 5
  436. software_interrupt:
  437. get_bad_stack_swi
  438. bad_save_user_regs
  439. bl do_software_interrupt
  440. .align 5
  441. prefetch_abort:
  442. get_bad_stack
  443. bad_save_user_regs
  444. bl do_prefetch_abort
  445. .align 5
  446. data_abort:
  447. get_bad_stack
  448. bad_save_user_regs
  449. bl do_data_abort
  450. .align 5
  451. not_used:
  452. get_bad_stack
  453. bad_save_user_regs
  454. bl do_not_used
  455. #ifdef CONFIG_USE_IRQ
  456. .align 5
  457. irq:
  458. get_irq_stack
  459. irq_save_user_regs
  460. bl do_irq
  461. irq_restore_user_regs
  462. .align 5
  463. fiq:
  464. get_fiq_stack
  465. /* someone ought to write a more effective fiq_save_user_regs */
  466. irq_save_user_regs
  467. bl do_fiq
  468. irq_restore_user_regs
  469. #else
  470. .align 5
  471. irq:
  472. get_bad_stack
  473. bad_save_user_regs
  474. bl do_irq
  475. .align 5
  476. fiq:
  477. get_bad_stack
  478. bad_save_user_regs
  479. bl do_fiq
  480. #endif /* CONFIG_USE_IRQ */
  481. #endif /* CONFIG_SPL_BUILD */