start.S 14 KB

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