start.S 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  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. #if defined(CONFIG_OMAP1610)
  38. #include <./configs/omap1510.h>
  39. #elif defined(CONFIG_OMAP730)
  40. #include <./configs/omap730.h>
  41. #endif
  42. /*
  43. *************************************************************************
  44. *
  45. * Jump vector table as in table 3.1 in [1]
  46. *
  47. *************************************************************************
  48. */
  49. #ifdef CONFIG_SYS_DV_NOR_BOOT_CFG
  50. .globl _start
  51. _start:
  52. .globl _NOR_BOOT_CFG
  53. _NOR_BOOT_CFG:
  54. .word CONFIG_SYS_DV_NOR_BOOT_CFG
  55. b reset
  56. #else
  57. .globl _start
  58. _start:
  59. b reset
  60. #endif
  61. #ifdef CONFIG_SPL_BUILD
  62. /* No exception handlers in preloader */
  63. ldr pc, _hang
  64. ldr pc, _hang
  65. ldr pc, _hang
  66. ldr pc, _hang
  67. ldr pc, _hang
  68. ldr pc, _hang
  69. ldr pc, _hang
  70. _hang:
  71. .word do_hang
  72. /* pad to 64 byte boundary */
  73. .word 0x12345678
  74. .word 0x12345678
  75. .word 0x12345678
  76. .word 0x12345678
  77. .word 0x12345678
  78. .word 0x12345678
  79. .word 0x12345678
  80. #else
  81. ldr pc, _undefined_instruction
  82. ldr pc, _software_interrupt
  83. ldr pc, _prefetch_abort
  84. ldr pc, _data_abort
  85. ldr pc, _not_used
  86. ldr pc, _irq
  87. ldr pc, _fiq
  88. _undefined_instruction:
  89. .word undefined_instruction
  90. _software_interrupt:
  91. .word software_interrupt
  92. _prefetch_abort:
  93. .word prefetch_abort
  94. _data_abort:
  95. .word data_abort
  96. _not_used:
  97. .word not_used
  98. _irq:
  99. .word irq
  100. _fiq:
  101. .word fiq
  102. #endif /* CONFIG_SPL_BUILD */
  103. .balignl 16,0xdeadbeef
  104. /*
  105. *************************************************************************
  106. *
  107. * Startup Code (reset vector)
  108. *
  109. * do important init only if we don't start from memory!
  110. * setup Memory and board specific bits prior to relocation.
  111. * relocate armboot to ram
  112. * setup stack
  113. *
  114. *************************************************************************
  115. */
  116. .globl _TEXT_BASE
  117. _TEXT_BASE:
  118. #ifdef CONFIG_NAND_SPL /* deprecated, use instead CONFIG_SPL_BUILD */
  119. .word CONFIG_SYS_TEXT_BASE
  120. #else
  121. #ifdef CONFIG_SPL_BUILD
  122. .word CONFIG_SPL_TEXT_BASE
  123. #else
  124. .word CONFIG_SYS_TEXT_BASE
  125. #endif
  126. #endif
  127. /*
  128. * These are defined in the board-specific linker script.
  129. * Subtracting _start from them lets the linker put their
  130. * relative position in the executable instead of leaving
  131. * them null.
  132. */
  133. .globl _bss_start_ofs
  134. _bss_start_ofs:
  135. .word __bss_start - _start
  136. .globl _bss_end_ofs
  137. _bss_end_ofs:
  138. .word __bss_end__ - _start
  139. .globl _end_ofs
  140. _end_ofs:
  141. .word _end - _start
  142. #ifdef CONFIG_NAND_U_BOOT
  143. .globl _end
  144. _end:
  145. .word __bss_end__
  146. #endif
  147. #ifdef CONFIG_USE_IRQ
  148. /* IRQ stack memory (calculated at run-time) */
  149. .globl IRQ_STACK_START
  150. IRQ_STACK_START:
  151. .word 0x0badc0de
  152. /* IRQ stack memory (calculated at run-time) */
  153. .globl FIQ_STACK_START
  154. FIQ_STACK_START:
  155. .word 0x0badc0de
  156. #endif
  157. /* IRQ stack memory (calculated at run-time) + 8 bytes */
  158. .globl IRQ_STACK_START_IN
  159. IRQ_STACK_START_IN:
  160. .word 0x0badc0de
  161. /*
  162. * the actual reset code
  163. */
  164. reset:
  165. /*
  166. * set the cpu to SVC32 mode
  167. */
  168. mrs r0,cpsr
  169. bic r0,r0,#0x1f
  170. orr r0,r0,#0xd3
  171. msr cpsr,r0
  172. /*
  173. * we do sys-critical inits only at reboot,
  174. * not when booting from ram!
  175. */
  176. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  177. bl cpu_init_crit
  178. #endif
  179. /* Set stackpointer in internal RAM to call board_init_f */
  180. call_board_init_f:
  181. #ifdef CONFIG_NAND_SPL /* deprecated, use instead CONFIG_SPL_BUILD */
  182. ldr sp, =(CONFIG_SYS_INIT_SP_ADDR)
  183. #else
  184. #ifdef CONFIG_SPL_BUILD
  185. ldr sp, =(CONFIG_SPL_STACK)
  186. #else
  187. ldr sp, =(CONFIG_SYS_INIT_SP_ADDR)
  188. #endif
  189. #endif
  190. bic sp, sp, #7 /* 8-byte alignment for ABI compliance */
  191. ldr r0,=0x00000000
  192. bl board_init_f
  193. /*------------------------------------------------------------------------------*/
  194. #if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_NAND_SPL)
  195. /*
  196. * void relocate_code (addr_sp, gd, addr_moni)
  197. *
  198. * This "function" does not return, instead it continues in RAM
  199. * after relocating the monitor code.
  200. *
  201. */
  202. .globl relocate_code
  203. relocate_code:
  204. mov r4, r0 /* save addr_sp */
  205. mov r5, r1 /* save addr of gd */
  206. mov r6, r2 /* save addr of destination */
  207. /* Set up the stack */
  208. stack_setup:
  209. mov sp, r4
  210. adr r0, _start
  211. sub r9, r6, r0 /* r9 <- relocation offset */
  212. cmp r0, r6
  213. moveq r9, #0 /* no relocation. relocation offset(r9) = 0 */
  214. beq clear_bss /* skip relocation */
  215. mov r1, r6 /* r1 <- scratch for copy loop */
  216. ldr r3, _bss_start_ofs
  217. add r2, r0, r3 /* r2 <- source end address */
  218. copy_loop:
  219. ldmia r0!, {r9-r10} /* copy from source address [r0] */
  220. stmia r1!, {r9-r10} /* copy to target address [r1] */
  221. cmp r0, r2 /* until source end address [r2] */
  222. blo copy_loop
  223. #ifndef CONFIG_SPL_BUILD
  224. /*
  225. * fix .rel.dyn relocations
  226. */
  227. ldr r0, _TEXT_BASE /* r0 <- Text base */
  228. sub r9, r6, r0 /* r9 <- relocation offset */
  229. ldr r10, _dynsym_start_ofs /* r10 <- sym table ofs */
  230. add r10, r10, r0 /* r10 <- sym table in FLASH */
  231. ldr r2, _rel_dyn_start_ofs /* r2 <- rel dyn start ofs */
  232. add r2, r2, r0 /* r2 <- rel dyn start in FLASH */
  233. ldr r3, _rel_dyn_end_ofs /* r3 <- rel dyn end ofs */
  234. add r3, r3, r0 /* r3 <- rel dyn end in FLASH */
  235. fixloop:
  236. ldr r0, [r2] /* r0 <- location to fix up, IN FLASH! */
  237. add r0, r0, r9 /* r0 <- location to fix up in RAM */
  238. ldr r1, [r2, #4]
  239. and r7, r1, #0xff
  240. cmp r7, #23 /* relative fixup? */
  241. beq fixrel
  242. cmp r7, #2 /* absolute fixup? */
  243. beq fixabs
  244. /* ignore unknown type of fixup */
  245. b fixnext
  246. fixabs:
  247. /* absolute fix: set location to (offset) symbol value */
  248. mov r1, r1, LSR #4 /* r1 <- symbol index in .dynsym */
  249. add r1, r10, r1 /* r1 <- address of symbol in table */
  250. ldr r1, [r1, #4] /* r1 <- symbol value */
  251. add r1, r1, r9 /* r1 <- relocated sym addr */
  252. b fixnext
  253. fixrel:
  254. /* relative fix: increase location by offset */
  255. ldr r1, [r0]
  256. add r1, r1, r9
  257. fixnext:
  258. str r1, [r0]
  259. add r2, r2, #8 /* each rel.dyn entry is 8 bytes */
  260. cmp r2, r3
  261. blo fixloop
  262. #endif
  263. clear_bss:
  264. #ifdef CONFIG_SPL_BUILD
  265. /* No relocation for SPL */
  266. ldr r0, =__bss_start
  267. ldr r1, =__bss_end__
  268. #else
  269. ldr r0, _bss_start_ofs
  270. ldr r1, _bss_end_ofs
  271. mov r4, r6 /* reloc addr */
  272. add r0, r0, r4
  273. add r1, r1, r4
  274. #endif
  275. mov r2, #0x00000000 /* clear */
  276. clbss_l:cmp r0, r1 /* clear loop... */
  277. bhs clbss_e /* if reached end of bss, exit */
  278. str r2, [r0]
  279. add r0, r0, #4
  280. b clbss_l
  281. clbss_e:
  282. #ifndef CONFIG_SPL_BUILD
  283. bl coloured_LED_init
  284. bl red_led_on
  285. #endif
  286. /*
  287. * We are done. Do not return, instead branch to second part of board
  288. * initialization, now running from RAM.
  289. */
  290. #ifdef CONFIG_NAND_SPL
  291. ldr r0, _nand_boot_ofs
  292. mov pc, r0
  293. _nand_boot_ofs:
  294. .word nand_boot
  295. #else
  296. ldr r0, _board_init_r_ofs
  297. ldr r1, _TEXT_BASE
  298. add lr, r0, r1
  299. add lr, lr, r9
  300. /* setup parameters for board_init_r */
  301. mov r0, r5 /* gd_t */
  302. mov r1, r6 /* dest_addr */
  303. /* jump to it ... */
  304. mov pc, lr
  305. _board_init_r_ofs:
  306. .word board_init_r - _start
  307. #endif
  308. _rel_dyn_start_ofs:
  309. .word __rel_dyn_start - _start
  310. _rel_dyn_end_ofs:
  311. .word __rel_dyn_end - _start
  312. _dynsym_start_ofs:
  313. .word __dynsym_start - _start
  314. #endif
  315. /*
  316. *************************************************************************
  317. *
  318. * CPU_init_critical registers
  319. *
  320. * setup important registers
  321. * setup memory timing
  322. *
  323. *************************************************************************
  324. */
  325. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  326. cpu_init_crit:
  327. /*
  328. * flush D cache before disabling it
  329. */
  330. mov r0, #0
  331. flush_dcache:
  332. mrc p15, 0, r15, c7, c10, 3
  333. bne flush_dcache
  334. mcr p15, 0, r0, c8, c7, 0 /* invalidate TLB */
  335. mcr p15, 0, r0, c7, c5, 0 /* invalidate I Cache */
  336. /*
  337. * disable MMU and D cache
  338. * enable I cache if CONFIG_SYS_ICACHE_OFF is not defined
  339. */
  340. mrc p15, 0, r0, c1, c0, 0
  341. bic r0, r0, #0x00000300 /* clear bits 9:8 (---- --RS) */
  342. bic r0, r0, #0x00000087 /* clear bits 7, 2:0 (B--- -CAM) */
  343. #ifdef CONFIG_SYS_EXCEPTION_VECTORS_HIGH
  344. orr r0, r0, #0x00002000 /* set bit 13 (--V- ----) */
  345. #else
  346. bic r0, r0, #0x00002000 /* clear bit 13 (--V- ----) */
  347. #endif
  348. orr r0, r0, #0x00000002 /* set bit 2 (A) Align */
  349. #ifndef CONFIG_SYS_ICACHE_OFF
  350. orr r0, r0, #0x00001000 /* set bit 12 (I) I-Cache */
  351. #endif
  352. mcr p15, 0, r0, c1, c0, 0
  353. /*
  354. * Go setup Memory and board specific bits prior to relocation.
  355. */
  356. mov ip, lr /* perserve link reg across call */
  357. bl lowlevel_init /* go setup pll,mux,memory */
  358. mov lr, ip /* restore link */
  359. mov pc, lr /* back to my caller */
  360. #endif /* CONFIG_SKIP_LOWLEVEL_INIT */
  361. #ifndef CONFIG_SPL_BUILD
  362. /*
  363. *************************************************************************
  364. *
  365. * Interrupt handling
  366. *
  367. *************************************************************************
  368. */
  369. @
  370. @ IRQ stack frame.
  371. @
  372. #define S_FRAME_SIZE 72
  373. #define S_OLD_R0 68
  374. #define S_PSR 64
  375. #define S_PC 60
  376. #define S_LR 56
  377. #define S_SP 52
  378. #define S_IP 48
  379. #define S_FP 44
  380. #define S_R10 40
  381. #define S_R9 36
  382. #define S_R8 32
  383. #define S_R7 28
  384. #define S_R6 24
  385. #define S_R5 20
  386. #define S_R4 16
  387. #define S_R3 12
  388. #define S_R2 8
  389. #define S_R1 4
  390. #define S_R0 0
  391. #define MODE_SVC 0x13
  392. #define I_BIT 0x80
  393. /*
  394. * use bad_save_user_regs for abort/prefetch/undef/swi ...
  395. * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling
  396. */
  397. .macro bad_save_user_regs
  398. @ carve out a frame on current user stack
  399. sub sp, sp, #S_FRAME_SIZE
  400. stmia sp, {r0 - r12} @ Save user registers (now in svc mode) r0-r12
  401. ldr r2, IRQ_STACK_START_IN
  402. @ get values for "aborted" pc and cpsr (into parm regs)
  403. ldmia r2, {r2 - r3}
  404. add r0, sp, #S_FRAME_SIZE @ grab pointer to old stack
  405. add r5, sp, #S_SP
  406. mov r1, lr
  407. stmia r5, {r0 - r3} @ save sp_SVC, lr_SVC, pc, cpsr
  408. mov r0, sp @ save current stack into r0 (param register)
  409. .endm
  410. .macro irq_save_user_regs
  411. sub sp, sp, #S_FRAME_SIZE
  412. stmia sp, {r0 - r12} @ Calling r0-r12
  413. @ !!!! R8 NEEDS to be saved !!!! a reserved stack spot would be good.
  414. add r8, sp, #S_PC
  415. stmdb r8, {sp, lr}^ @ Calling SP, LR
  416. str lr, [r8, #0] @ Save calling PC
  417. mrs r6, spsr
  418. str r6, [r8, #4] @ Save CPSR
  419. str r0, [r8, #8] @ Save OLD_R0
  420. mov r0, sp
  421. .endm
  422. .macro irq_restore_user_regs
  423. ldmia sp, {r0 - lr}^ @ Calling r0 - lr
  424. mov r0, r0
  425. ldr lr, [sp, #S_PC] @ Get PC
  426. add sp, sp, #S_FRAME_SIZE
  427. subs pc, lr, #4 @ return & move spsr_svc into cpsr
  428. .endm
  429. .macro get_bad_stack
  430. ldr r13, IRQ_STACK_START_IN @ setup our mode stack
  431. str lr, [r13] @ save caller lr in position 0 of saved stack
  432. mrs lr, spsr @ get the spsr
  433. str lr, [r13, #4] @ save spsr in position 1 of saved stack
  434. mov r13, #MODE_SVC @ prepare SVC-Mode
  435. @ msr spsr_c, r13
  436. msr spsr, r13 @ switch modes, make sure moves will execute
  437. mov lr, pc @ capture return pc
  438. movs pc, lr @ jump to next instruction & switch modes.
  439. .endm
  440. .macro get_irq_stack @ setup IRQ stack
  441. ldr sp, IRQ_STACK_START
  442. .endm
  443. .macro get_fiq_stack @ setup FIQ stack
  444. ldr sp, FIQ_STACK_START
  445. .endm
  446. #endif /* CONFIG_SPL_BUILD */
  447. /*
  448. * exception handlers
  449. */
  450. #ifdef CONFIG_SPL_BUILD
  451. .align 5
  452. do_hang:
  453. ldr sp, _TEXT_BASE /* switch to abort stack */
  454. 1:
  455. bl 1b /* hang and never return */
  456. #else /* !CONFIG_SPL_BUILD */
  457. .align 5
  458. undefined_instruction:
  459. get_bad_stack
  460. bad_save_user_regs
  461. bl do_undefined_instruction
  462. .align 5
  463. software_interrupt:
  464. get_bad_stack
  465. bad_save_user_regs
  466. bl do_software_interrupt
  467. .align 5
  468. prefetch_abort:
  469. get_bad_stack
  470. bad_save_user_regs
  471. bl do_prefetch_abort
  472. .align 5
  473. data_abort:
  474. get_bad_stack
  475. bad_save_user_regs
  476. bl do_data_abort
  477. .align 5
  478. not_used:
  479. get_bad_stack
  480. bad_save_user_regs
  481. bl do_not_used
  482. #ifdef CONFIG_USE_IRQ
  483. .align 5
  484. irq:
  485. get_irq_stack
  486. irq_save_user_regs
  487. bl do_irq
  488. irq_restore_user_regs
  489. .align 5
  490. fiq:
  491. get_fiq_stack
  492. /* someone ought to write a more effiction fiq_save_user_regs */
  493. irq_save_user_regs
  494. bl do_fiq
  495. irq_restore_user_regs
  496. #else
  497. .align 5
  498. irq:
  499. get_bad_stack
  500. bad_save_user_regs
  501. bl do_irq
  502. .align 5
  503. fiq:
  504. get_bad_stack
  505. bad_save_user_regs
  506. bl do_fiq
  507. #endif
  508. #endif /* CONFIG_SPL_BUILD */