start.S 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. /*
  2. * armboot - Startup Code for ARM1176 CPU-core
  3. *
  4. * Copyright (c) 2007 Samsung Electronics
  5. *
  6. * Copyright (C) 2008
  7. * Guennadi Liakhovetki, DENX Software Engineering, <lg@denx.de>
  8. *
  9. * See file CREDITS for list of people who contributed to this
  10. * project.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  25. * MA 02111-1307 USA
  26. *
  27. * 2007-09-21 - Restructured codes by jsgood (jsgood.yang@samsung.com)
  28. * 2007-09-21 - Added MoviNAND and OneNAND boot codes by
  29. * jsgood (jsgood.yang@samsung.com)
  30. * Base codes by scsuh (sc.suh)
  31. */
  32. #include <config.h>
  33. #include <version.h>
  34. #ifdef CONFIG_ENABLE_MMU
  35. #include <asm/proc/domain.h>
  36. #endif
  37. #if !defined(CONFIG_ENABLE_MMU) && !defined(CONFIG_SYS_PHY_UBOOT_BASE)
  38. #define CONFIG_SYS_PHY_UBOOT_BASE CONFIG_SYS_UBOOT_BASE
  39. #endif
  40. /*
  41. *************************************************************************
  42. *
  43. * Jump vector table as in table 3.1 in [1]
  44. *
  45. *************************************************************************
  46. */
  47. .globl _start
  48. _start: b reset
  49. #ifndef CONFIG_NAND_SPL
  50. ldr pc, _undefined_instruction
  51. ldr pc, _software_interrupt
  52. ldr pc, _prefetch_abort
  53. ldr pc, _data_abort
  54. ldr pc, _not_used
  55. ldr pc, _irq
  56. ldr pc, _fiq
  57. _undefined_instruction:
  58. .word undefined_instruction
  59. _software_interrupt:
  60. .word software_interrupt
  61. _prefetch_abort:
  62. .word prefetch_abort
  63. _data_abort:
  64. .word data_abort
  65. _not_used:
  66. .word not_used
  67. _irq:
  68. .word irq
  69. _fiq:
  70. .word fiq
  71. _pad:
  72. .word 0x12345678 /* now 16*4=64 */
  73. #else
  74. . = _start + 64
  75. #endif
  76. .global _end_vect
  77. _end_vect:
  78. .balignl 16,0xdeadbeef
  79. /*
  80. *************************************************************************
  81. *
  82. * Startup Code (reset vector)
  83. *
  84. * do important init only if we don't start from memory!
  85. * setup Memory and board specific bits prior to relocation.
  86. * relocate armboot to ram
  87. * setup stack
  88. *
  89. *************************************************************************
  90. */
  91. _TEXT_BASE:
  92. .word TEXT_BASE
  93. /*
  94. * Below variable is very important because we use MMU in U-Boot.
  95. * Without it, we cannot run code correctly before MMU is ON.
  96. * by scsuh.
  97. */
  98. _TEXT_PHY_BASE:
  99. .word CONFIG_SYS_PHY_UBOOT_BASE
  100. .globl _armboot_start
  101. _armboot_start:
  102. .word _start
  103. /*
  104. * These are defined in the board-specific linker script.
  105. */
  106. .globl _bss_start
  107. _bss_start:
  108. .word __bss_start
  109. .globl _bss_end
  110. _bss_end:
  111. .word _end
  112. /*
  113. * the actual reset code
  114. */
  115. reset:
  116. /*
  117. * set the cpu to SVC32 mode
  118. */
  119. mrs r0, cpsr
  120. bic r0, r0, #0x3f
  121. orr r0, r0, #0xd3
  122. msr cpsr, r0
  123. /*
  124. *************************************************************************
  125. *
  126. * CPU_init_critical registers
  127. *
  128. * setup important registers
  129. * setup memory timing
  130. *
  131. *************************************************************************
  132. */
  133. /*
  134. * we do sys-critical inits only at reboot,
  135. * not when booting from ram!
  136. */
  137. cpu_init_crit:
  138. /*
  139. * When booting from NAND - it has definitely been a reset, so, no need
  140. * to flush caches and disable the MMU
  141. */
  142. #ifndef CONFIG_NAND_SPL
  143. /*
  144. * flush v4 I/D caches
  145. */
  146. mov r0, #0
  147. mcr p15, 0, r0, c7, c7, 0 /* flush v3/v4 cache */
  148. mcr p15, 0, r0, c8, c7, 0 /* flush v4 TLB */
  149. /*
  150. * disable MMU stuff and caches
  151. */
  152. mrc p15, 0, r0, c1, c0, 0
  153. bic r0, r0, #0x00002300 @ clear bits 13, 9:8 (--V- --RS)
  154. bic r0, r0, #0x00000087 @ clear bits 7, 2:0 (B--- -CAM)
  155. orr r0, r0, #0x00000002 @ set bit 2 (A) Align
  156. orr r0, r0, #0x00001000 @ set bit 12 (I) I-Cache
  157. /* Prepare to disable the MMU */
  158. adr r2, mmu_disable_phys
  159. sub r2, r2, #(CONFIG_SYS_PHY_UBOOT_BASE - TEXT_BASE)
  160. b mmu_disable
  161. .align 5
  162. /* Run in a single cache-line */
  163. mmu_disable:
  164. mcr p15, 0, r0, c1, c0, 0
  165. nop
  166. nop
  167. mov pc, r2
  168. mmu_disable_phys:
  169. #ifdef CONFIG_DISABLE_TCM
  170. /*
  171. * Disable the TCMs
  172. */
  173. mrc p15, 0, r0, c0, c0, 2 /* Return TCM details */
  174. cmp r0, #0
  175. beq skip_tcmdisable
  176. mov r1, #0
  177. mov r2, #1
  178. tst r0, r2
  179. mcrne p15, 0, r1, c9, c1, 1 /* Disable Instruction TCM if present*/
  180. tst r0, r2, LSL #16
  181. mcrne p15, 0, r1, c9, c1, 0 /* Disable Data TCM if present*/
  182. skip_tcmdisable:
  183. #endif
  184. #endif
  185. #ifdef CONFIG_PERIPORT_REMAP
  186. /* Peri port setup */
  187. ldr r0, =CONFIG_PERIPORT_BASE
  188. orr r0, r0, #CONFIG_PERIPORT_SIZE
  189. mcr p15,0,r0,c15,c2,4
  190. #endif
  191. /*
  192. * Go setup Memory and board specific bits prior to relocation.
  193. */
  194. bl lowlevel_init /* go setup pll,mux,memory */
  195. #ifndef CONFIG_SKIP_RELOCATE_UBOOT
  196. relocate: /* relocate U-Boot to RAM */
  197. adr r0, _start /* r0 <- current position of code */
  198. ldr r1, _TEXT_BASE /* test if we run from flash or RAM */
  199. cmp r0, r1 /* don't reloc during debug */
  200. beq stack_setup
  201. ldr r2, _armboot_start
  202. ldr r3, _bss_start
  203. sub r2, r3, r2 /* r2 <- size of armboot */
  204. add r2, r0, r2 /* r2 <- source end address */
  205. copy_loop:
  206. ldmia r0!, {r3-r10} /* copy from source address [r0] */
  207. stmia r1!, {r3-r10} /* copy to target address [r1] */
  208. cmp r0, r2 /* until source end addreee [r2] */
  209. ble copy_loop
  210. #endif /* CONFIG_SKIP_RELOCATE_UBOOT */
  211. #ifdef CONFIG_ENABLE_MMU
  212. enable_mmu:
  213. /* enable domain access */
  214. ldr r5, =0x0000ffff
  215. mcr p15, 0, r5, c3, c0, 0 /* load domain access register */
  216. /* Set the TTB register */
  217. ldr r0, _mmu_table_base
  218. ldr r1, =CONFIG_SYS_PHY_UBOOT_BASE
  219. ldr r2, =0xfff00000
  220. bic r0, r0, r2
  221. orr r1, r0, r1
  222. mcr p15, 0, r1, c2, c0, 0
  223. /* Enable the MMU */
  224. mrc p15, 0, r0, c1, c0, 0
  225. orr r0, r0, #1 /* Set CR_M to enable MMU */
  226. /* Prepare to enable the MMU */
  227. adr r1, skip_hw_init
  228. and r1, r1, #0x3fc
  229. ldr r2, _TEXT_BASE
  230. ldr r3, =0xfff00000
  231. and r2, r2, r3
  232. orr r2, r2, r1
  233. b mmu_enable
  234. .align 5
  235. /* Run in a single cache-line */
  236. mmu_enable:
  237. mcr p15, 0, r0, c1, c0, 0
  238. nop
  239. nop
  240. mov pc, r2
  241. skip_hw_init:
  242. #endif
  243. /* Set up the stack */
  244. stack_setup:
  245. ldr r0, =CONFIG_SYS_UBOOT_BASE /* base of copy in DRAM */
  246. sub r0, r0, #CONFIG_SYS_MALLOC_LEN /* malloc area */
  247. sub r0, r0, #CONFIG_SYS_GBL_DATA_SIZE /* bdinfo */
  248. sub sp, r0, #12 /* leave 3 words for abort-stack */
  249. clear_bss:
  250. ldr r0, _bss_start /* find start of bss segment */
  251. ldr r1, _bss_end /* stop here */
  252. mov r2, #0 /* clear */
  253. clbss_l:
  254. str r2, [r0] /* clear loop... */
  255. add r0, r0, #4
  256. cmp r0, r1
  257. ble clbss_l
  258. #ifndef CONFIG_NAND_SPL
  259. ldr pc, _start_armboot
  260. _start_armboot:
  261. .word start_armboot
  262. #else
  263. b nand_boot
  264. /* .word nand_boot*/
  265. #endif
  266. #ifdef CONFIG_ENABLE_MMU
  267. _mmu_table_base:
  268. .word mmu_table
  269. #endif
  270. #ifndef CONFIG_NAND_SPL
  271. /*
  272. * we assume that cache operation is done before. (eg. cleanup_before_linux())
  273. * actually, we don't need to do anything about cache if not use d-cache in
  274. * U-Boot. So, in this function we clean only MMU. by scsuh
  275. *
  276. * void theLastJump(void *kernel, int arch_num, uint boot_params);
  277. */
  278. #ifdef CONFIG_ENABLE_MMU
  279. .globl theLastJump
  280. theLastJump:
  281. mov r9, r0
  282. ldr r3, =0xfff00000
  283. ldr r4, _TEXT_PHY_BASE
  284. adr r5, phy_last_jump
  285. bic r5, r5, r3
  286. orr r5, r5, r4
  287. mov pc, r5
  288. phy_last_jump:
  289. /*
  290. * disable MMU stuff
  291. */
  292. mrc p15, 0, r0, c1, c0, 0
  293. bic r0, r0, #0x00002300 /* clear bits 13, 9:8 (--V- --RS) */
  294. bic r0, r0, #0x00000087 /* clear bits 7, 2:0 (B--- -CAM) */
  295. orr r0, r0, #0x00000002 /* set bit 2 (A) Align */
  296. orr r0, r0, #0x00001000 /* set bit 12 (I) I-Cache */
  297. mcr p15, 0, r0, c1, c0, 0
  298. mcr p15, 0, r0, c8, c7, 0 /* flush v4 TLB */
  299. mov r0, #0
  300. mov pc, r9
  301. #endif
  302. /*
  303. *************************************************************************
  304. *
  305. * Interrupt handling
  306. *
  307. *************************************************************************
  308. */
  309. @
  310. @ IRQ stack frame.
  311. @
  312. #define S_FRAME_SIZE 72
  313. #define S_OLD_R0 68
  314. #define S_PSR 64
  315. #define S_PC 60
  316. #define S_LR 56
  317. #define S_SP 52
  318. #define S_IP 48
  319. #define S_FP 44
  320. #define S_R10 40
  321. #define S_R9 36
  322. #define S_R8 32
  323. #define S_R7 28
  324. #define S_R6 24
  325. #define S_R5 20
  326. #define S_R4 16
  327. #define S_R3 12
  328. #define S_R2 8
  329. #define S_R1 4
  330. #define S_R0 0
  331. #define MODE_SVC 0x13
  332. #define I_BIT 0x80
  333. /*
  334. * use bad_save_user_regs for abort/prefetch/undef/swi ...
  335. */
  336. .macro bad_save_user_regs
  337. /* carve out a frame on current user stack */
  338. sub sp, sp, #S_FRAME_SIZE
  339. /* Save user registers (now in svc mode) r0-r12 */
  340. stmia sp, {r0 - r12}
  341. ldr r2, _armboot_start
  342. sub r2, r2, #(CONFIG_SYS_MALLOC_LEN)
  343. /* set base 2 words into abort stack */
  344. sub r2, r2, #(CONFIG_SYS_GBL_DATA_SIZE+8)
  345. /* get values for "aborted" pc and cpsr (into parm regs) */
  346. ldmia r2, {r2 - r3}
  347. /* grab pointer to old stack */
  348. add r0, sp, #S_FRAME_SIZE
  349. add r5, sp, #S_SP
  350. mov r1, lr
  351. /* save sp_SVC, lr_SVC, pc, cpsr */
  352. stmia r5, {r0 - r3}
  353. /* save current stack into r0 (param register) */
  354. mov r0, sp
  355. .endm
  356. .macro get_bad_stack
  357. /* setup our mode stack (enter in banked mode) */
  358. ldr r13, _armboot_start
  359. /* move past malloc pool */
  360. sub r13, r13, #(CONFIG_SYS_MALLOC_LEN)
  361. /* move to reserved a couple spots for abort stack */
  362. sub r13, r13, #(CONFIG_SYS_GBL_DATA_SIZE + 8)
  363. /* save caller lr in position 0 of saved stack */
  364. str lr, [r13]
  365. /* get the spsr */
  366. mrs lr, spsr
  367. /* save spsr in position 1 of saved stack */
  368. str lr, [r13, #4]
  369. /* prepare SVC-Mode */
  370. mov r13, #MODE_SVC
  371. @ msr spsr_c, r13
  372. /* switch modes, make sure moves will execute */
  373. msr spsr, r13
  374. /* capture return pc */
  375. mov lr, pc
  376. /* jump to next instruction & switch modes. */
  377. movs pc, lr
  378. .endm
  379. .macro get_bad_stack_swi
  380. /* space on current stack for scratch reg. */
  381. sub r13, r13, #4
  382. /* save R0's value. */
  383. str r0, [r13]
  384. /* get data regions start */
  385. ldr r0, _armboot_start
  386. /* move past malloc pool */
  387. sub r0, r0, #(CONFIG_SYS_MALLOC_LEN)
  388. /* move past gbl and a couple spots for abort stack */
  389. sub r0, r0, #(CONFIG_SYS_GBL_DATA_SIZE + 8)
  390. /* save caller lr in position 0 of saved stack */
  391. str lr, [r0]
  392. /* get the spsr */
  393. mrs r0, spsr
  394. /* save spsr in position 1 of saved stack */
  395. str lr, [r0, #4]
  396. /* restore r0 */
  397. ldr r0, [r13]
  398. /* pop stack entry */
  399. add r13, r13, #4
  400. .endm
  401. /*
  402. * exception handlers
  403. */
  404. .align 5
  405. undefined_instruction:
  406. get_bad_stack
  407. bad_save_user_regs
  408. bl do_undefined_instruction
  409. .align 5
  410. software_interrupt:
  411. get_bad_stack_swi
  412. bad_save_user_regs
  413. bl do_software_interrupt
  414. .align 5
  415. prefetch_abort:
  416. get_bad_stack
  417. bad_save_user_regs
  418. bl do_prefetch_abort
  419. .align 5
  420. data_abort:
  421. get_bad_stack
  422. bad_save_user_regs
  423. bl do_data_abort
  424. .align 5
  425. not_used:
  426. get_bad_stack
  427. bad_save_user_regs
  428. bl do_not_used
  429. .align 5
  430. irq:
  431. get_bad_stack
  432. bad_save_user_regs
  433. bl do_irq
  434. .align 5
  435. fiq:
  436. get_bad_stack
  437. bad_save_user_regs
  438. bl do_fiq
  439. #endif /* CONFIG_NAND_SPL */