start.S 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  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. bic sp, sp, #7 /* 8-byte alignment for ABI compliance */
  250. clear_bss:
  251. ldr r0, _bss_start /* find start of bss segment */
  252. ldr r1, _bss_end /* stop here */
  253. mov r2, #0 /* clear */
  254. clbss_l:
  255. str r2, [r0] /* clear loop... */
  256. add r0, r0, #4
  257. cmp r0, r1
  258. ble clbss_l
  259. #ifndef CONFIG_NAND_SPL
  260. ldr pc, _start_armboot
  261. _start_armboot:
  262. .word start_armboot
  263. #else
  264. b nand_boot
  265. /* .word nand_boot*/
  266. #endif
  267. #ifdef CONFIG_ENABLE_MMU
  268. _mmu_table_base:
  269. .word mmu_table
  270. #endif
  271. #ifndef CONFIG_NAND_SPL
  272. /*
  273. * we assume that cache operation is done before. (eg. cleanup_before_linux())
  274. * actually, we don't need to do anything about cache if not use d-cache in
  275. * U-Boot. So, in this function we clean only MMU. by scsuh
  276. *
  277. * void theLastJump(void *kernel, int arch_num, uint boot_params);
  278. */
  279. #ifdef CONFIG_ENABLE_MMU
  280. .globl theLastJump
  281. theLastJump:
  282. mov r9, r0
  283. ldr r3, =0xfff00000
  284. ldr r4, _TEXT_PHY_BASE
  285. adr r5, phy_last_jump
  286. bic r5, r5, r3
  287. orr r5, r5, r4
  288. mov pc, r5
  289. phy_last_jump:
  290. /*
  291. * disable MMU stuff
  292. */
  293. mrc p15, 0, r0, c1, c0, 0
  294. bic r0, r0, #0x00002300 /* clear bits 13, 9:8 (--V- --RS) */
  295. bic r0, r0, #0x00000087 /* clear bits 7, 2:0 (B--- -CAM) */
  296. orr r0, r0, #0x00000002 /* set bit 2 (A) Align */
  297. orr r0, r0, #0x00001000 /* set bit 12 (I) I-Cache */
  298. mcr p15, 0, r0, c1, c0, 0
  299. mcr p15, 0, r0, c8, c7, 0 /* flush v4 TLB */
  300. mov r0, #0
  301. mov pc, r9
  302. #endif
  303. /*
  304. *************************************************************************
  305. *
  306. * Interrupt handling
  307. *
  308. *************************************************************************
  309. */
  310. @
  311. @ IRQ stack frame.
  312. @
  313. #define S_FRAME_SIZE 72
  314. #define S_OLD_R0 68
  315. #define S_PSR 64
  316. #define S_PC 60
  317. #define S_LR 56
  318. #define S_SP 52
  319. #define S_IP 48
  320. #define S_FP 44
  321. #define S_R10 40
  322. #define S_R9 36
  323. #define S_R8 32
  324. #define S_R7 28
  325. #define S_R6 24
  326. #define S_R5 20
  327. #define S_R4 16
  328. #define S_R3 12
  329. #define S_R2 8
  330. #define S_R1 4
  331. #define S_R0 0
  332. #define MODE_SVC 0x13
  333. #define I_BIT 0x80
  334. /*
  335. * use bad_save_user_regs for abort/prefetch/undef/swi ...
  336. */
  337. .macro bad_save_user_regs
  338. /* carve out a frame on current user stack */
  339. sub sp, sp, #S_FRAME_SIZE
  340. /* Save user registers (now in svc mode) r0-r12 */
  341. stmia sp, {r0 - r12}
  342. ldr r2, _armboot_start
  343. sub r2, r2, #(CONFIG_SYS_MALLOC_LEN)
  344. /* set base 2 words into abort stack */
  345. sub r2, r2, #(CONFIG_SYS_GBL_DATA_SIZE+8)
  346. /* get values for "aborted" pc and cpsr (into parm regs) */
  347. ldmia r2, {r2 - r3}
  348. /* grab pointer to old stack */
  349. add r0, sp, #S_FRAME_SIZE
  350. add r5, sp, #S_SP
  351. mov r1, lr
  352. /* save sp_SVC, lr_SVC, pc, cpsr */
  353. stmia r5, {r0 - r3}
  354. /* save current stack into r0 (param register) */
  355. mov r0, sp
  356. .endm
  357. .macro get_bad_stack
  358. /* setup our mode stack (enter in banked mode) */
  359. ldr r13, _armboot_start
  360. /* move past malloc pool */
  361. sub r13, r13, #(CONFIG_SYS_MALLOC_LEN)
  362. /* move to reserved a couple spots for abort stack */
  363. sub r13, r13, #(CONFIG_SYS_GBL_DATA_SIZE + 8)
  364. /* save caller lr in position 0 of saved stack */
  365. str lr, [r13]
  366. /* get the spsr */
  367. mrs lr, spsr
  368. /* save spsr in position 1 of saved stack */
  369. str lr, [r13, #4]
  370. /* prepare SVC-Mode */
  371. mov r13, #MODE_SVC
  372. @ msr spsr_c, r13
  373. /* switch modes, make sure moves will execute */
  374. msr spsr, r13
  375. /* capture return pc */
  376. mov lr, pc
  377. /* jump to next instruction & switch modes. */
  378. movs pc, lr
  379. .endm
  380. .macro get_bad_stack_swi
  381. /* space on current stack for scratch reg. */
  382. sub r13, r13, #4
  383. /* save R0's value. */
  384. str r0, [r13]
  385. /* get data regions start */
  386. ldr r0, _armboot_start
  387. /* move past malloc pool */
  388. sub r0, r0, #(CONFIG_SYS_MALLOC_LEN)
  389. /* move past gbl and a couple spots for abort stack */
  390. sub r0, r0, #(CONFIG_SYS_GBL_DATA_SIZE + 8)
  391. /* save caller lr in position 0 of saved stack */
  392. str lr, [r0]
  393. /* get the spsr */
  394. mrs r0, spsr
  395. /* save spsr in position 1 of saved stack */
  396. str lr, [r0, #4]
  397. /* restore r0 */
  398. ldr r0, [r13]
  399. /* pop stack entry */
  400. add r13, r13, #4
  401. .endm
  402. /*
  403. * exception handlers
  404. */
  405. .align 5
  406. undefined_instruction:
  407. get_bad_stack
  408. bad_save_user_regs
  409. bl do_undefined_instruction
  410. .align 5
  411. software_interrupt:
  412. get_bad_stack_swi
  413. bad_save_user_regs
  414. bl do_software_interrupt
  415. .align 5
  416. prefetch_abort:
  417. get_bad_stack
  418. bad_save_user_regs
  419. bl do_prefetch_abort
  420. .align 5
  421. data_abort:
  422. get_bad_stack
  423. bad_save_user_regs
  424. bl do_data_abort
  425. .align 5
  426. not_used:
  427. get_bad_stack
  428. bad_save_user_regs
  429. bl do_not_used
  430. .align 5
  431. irq:
  432. get_bad_stack
  433. bad_save_user_regs
  434. bl do_irq
  435. .align 5
  436. fiq:
  437. get_bad_stack
  438. bad_save_user_regs
  439. bl do_fiq
  440. #endif /* CONFIG_NAND_SPL */