start.S 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. /*
  2. * armboot - Startup Code for S3C6400/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. #include <asm/arch/s3c6400.h>
  38. #if !defined(CONFIG_ENABLE_MMU) && !defined(CONFIG_SYS_PHY_UBOOT_BASE)
  39. #define CONFIG_SYS_PHY_UBOOT_BASE CONFIG_SYS_UBOOT_BASE
  40. #endif
  41. /*
  42. *************************************************************************
  43. *
  44. * Jump vector table as in table 3.1 in [1]
  45. *
  46. *************************************************************************
  47. */
  48. .globl _start
  49. _start: b reset
  50. #ifndef CONFIG_NAND_SPL
  51. ldr pc, _undefined_instruction
  52. ldr pc, _software_interrupt
  53. ldr pc, _prefetch_abort
  54. ldr pc, _data_abort
  55. ldr pc, _not_used
  56. ldr pc, _irq
  57. ldr pc, _fiq
  58. _undefined_instruction:
  59. .word undefined_instruction
  60. _software_interrupt:
  61. .word software_interrupt
  62. _prefetch_abort:
  63. .word prefetch_abort
  64. _data_abort:
  65. .word data_abort
  66. _not_used:
  67. .word not_used
  68. _irq:
  69. .word irq
  70. _fiq:
  71. .word fiq
  72. _pad:
  73. .word 0x12345678 /* now 16*4=64 */
  74. #else
  75. . = _start + 64
  76. #endif
  77. .global _end_vect
  78. _end_vect:
  79. .balignl 16,0xdeadbeef
  80. /*
  81. *************************************************************************
  82. *
  83. * Startup Code (reset vector)
  84. *
  85. * do important init only if we don't start from memory!
  86. * setup Memory and board specific bits prior to relocation.
  87. * relocate armboot to ram
  88. * setup stack
  89. *
  90. *************************************************************************
  91. */
  92. _TEXT_BASE:
  93. .word TEXT_BASE
  94. /*
  95. * Below variable is very important because we use MMU in U-Boot.
  96. * Without it, we cannot run code correctly before MMU is ON.
  97. * by scsuh.
  98. */
  99. _TEXT_PHY_BASE:
  100. .word CONFIG_SYS_PHY_UBOOT_BASE
  101. .globl _armboot_start
  102. _armboot_start:
  103. .word _start
  104. /*
  105. * These are defined in the board-specific linker script.
  106. */
  107. .globl _bss_start
  108. _bss_start:
  109. .word __bss_start
  110. .globl _bss_end
  111. _bss_end:
  112. .word _end
  113. /*
  114. * the actual reset code
  115. */
  116. reset:
  117. /*
  118. * set the cpu to SVC32 mode
  119. */
  120. mrs r0, cpsr
  121. bic r0, r0, #0x3f
  122. orr r0, r0, #0xd3
  123. msr cpsr, r0
  124. /*
  125. *************************************************************************
  126. *
  127. * CPU_init_critical registers
  128. *
  129. * setup important registers
  130. * setup memory timing
  131. *
  132. *************************************************************************
  133. */
  134. /*
  135. * we do sys-critical inits only at reboot,
  136. * not when booting from ram!
  137. */
  138. cpu_init_crit:
  139. /*
  140. * When booting from NAND - it has definitely been a reset, so, no need
  141. * to flush caches and disable the MMU
  142. */
  143. #ifndef CONFIG_NAND_SPL
  144. /*
  145. * flush v4 I/D caches
  146. */
  147. mov r0, #0
  148. mcr p15, 0, r0, c7, c7, 0 /* flush v3/v4 cache */
  149. mcr p15, 0, r0, c8, c7, 0 /* flush v4 TLB */
  150. /*
  151. * disable MMU stuff and caches
  152. */
  153. mrc p15, 0, r0, c1, c0, 0
  154. bic r0, r0, #0x00002300 @ clear bits 13, 9:8 (--V- --RS)
  155. bic r0, r0, #0x00000087 @ clear bits 7, 2:0 (B--- -CAM)
  156. orr r0, r0, #0x00000002 @ set bit 2 (A) Align
  157. orr r0, r0, #0x00001000 @ set bit 12 (I) I-Cache
  158. /* Prepare to disable the MMU */
  159. adr r1, mmu_disable_phys
  160. /* We presume we're within the first 1024 bytes */
  161. and r1, r1, #0x3fc
  162. ldr r2, _TEXT_PHY_BASE
  163. ldr r3, =0xfff00000
  164. and r2, r2, r3
  165. orr r2, r2, r1
  166. b mmu_disable
  167. .align 5
  168. /* Run in a single cache-line */
  169. mmu_disable:
  170. mcr p15, 0, r0, c1, c0, 0
  171. nop
  172. nop
  173. mov pc, r2
  174. #endif
  175. mmu_disable_phys:
  176. /* Peri port setup */
  177. ldr r0, =0x70000000
  178. orr r0, r0, #0x13
  179. mcr p15,0,r0,c15,c2,4 @ 256M (0x70000000 - 0x7fffffff)
  180. /*
  181. * Go setup Memory and board specific bits prior to relocation.
  182. */
  183. bl lowlevel_init /* go setup pll,mux,memory */
  184. after_copy:
  185. #ifdef CONFIG_ENABLE_MMU
  186. enable_mmu:
  187. /* enable domain access */
  188. ldr r5, =0x0000ffff
  189. mcr p15, 0, r5, c3, c0, 0 /* load domain access register */
  190. /* Set the TTB register */
  191. ldr r0, _mmu_table_base
  192. ldr r1, =CONFIG_SYS_PHY_UBOOT_BASE
  193. ldr r2, =0xfff00000
  194. bic r0, r0, r2
  195. orr r1, r0, r1
  196. mcr p15, 0, r1, c2, c0, 0
  197. /* Enable the MMU */
  198. mrc p15, 0, r0, c1, c0, 0
  199. orr r0, r0, #1 /* Set CR_M to enable MMU */
  200. /* Prepare to enable the MMU */
  201. adr r1, skip_hw_init
  202. and r1, r1, #0x3fc
  203. ldr r2, _TEXT_BASE
  204. ldr r3, =0xfff00000
  205. and r2, r2, r3
  206. orr r2, r2, r1
  207. b mmu_enable
  208. .align 5
  209. /* Run in a single cache-line */
  210. mmu_enable:
  211. mcr p15, 0, r0, c1, c0, 0
  212. nop
  213. nop
  214. mov pc, r2
  215. #endif
  216. skip_hw_init:
  217. /* Set up the stack */
  218. stack_setup:
  219. ldr r0, =CONFIG_SYS_UBOOT_BASE /* base of copy in DRAM */
  220. sub r0, r0, #CONFIG_SYS_MALLOC_LEN /* malloc area */
  221. sub r0, r0, #CONFIG_SYS_GBL_DATA_SIZE /* bdinfo */
  222. sub sp, r0, #12 /* leave 3 words for abort-stack */
  223. clear_bss:
  224. ldr r0, _bss_start /* find start of bss segment */
  225. ldr r1, _bss_end /* stop here */
  226. mov r2, #0 /* clear */
  227. clbss_l:
  228. str r2, [r0] /* clear loop... */
  229. add r0, r0, #4
  230. cmp r0, r1
  231. ble clbss_l
  232. #ifndef CONFIG_NAND_SPL
  233. ldr pc, _start_armboot
  234. _start_armboot:
  235. .word start_armboot
  236. #else
  237. b nand_boot
  238. /* .word nand_boot*/
  239. #endif
  240. #ifdef CONFIG_ENABLE_MMU
  241. _mmu_table_base:
  242. .word mmu_table
  243. #endif
  244. #ifndef CONFIG_NAND_SPL
  245. /*
  246. * we assume that cache operation is done before. (eg. cleanup_before_linux())
  247. * actually, we don't need to do anything about cache if not use d-cache in
  248. * U-Boot. So, in this function we clean only MMU. by scsuh
  249. *
  250. * void theLastJump(void *kernel, int arch_num, uint boot_params);
  251. */
  252. #ifdef CONFIG_ENABLE_MMU
  253. .globl theLastJump
  254. theLastJump:
  255. mov r9, r0
  256. ldr r3, =0xfff00000
  257. ldr r4, _TEXT_PHY_BASE
  258. adr r5, phy_last_jump
  259. bic r5, r5, r3
  260. orr r5, r5, r4
  261. mov pc, r5
  262. phy_last_jump:
  263. /*
  264. * disable MMU stuff
  265. */
  266. mrc p15, 0, r0, c1, c0, 0
  267. bic r0, r0, #0x00002300 /* clear bits 13, 9:8 (--V- --RS) */
  268. bic r0, r0, #0x00000087 /* clear bits 7, 2:0 (B--- -CAM) */
  269. orr r0, r0, #0x00000002 /* set bit 2 (A) Align */
  270. orr r0, r0, #0x00001000 /* set bit 12 (I) I-Cache */
  271. mcr p15, 0, r0, c1, c0, 0
  272. mcr p15, 0, r0, c8, c7, 0 /* flush v4 TLB */
  273. mov r0, #0
  274. mov pc, r9
  275. #endif
  276. /*
  277. *************************************************************************
  278. *
  279. * Interrupt handling
  280. *
  281. *************************************************************************
  282. */
  283. @
  284. @ IRQ stack frame.
  285. @
  286. #define S_FRAME_SIZE 72
  287. #define S_OLD_R0 68
  288. #define S_PSR 64
  289. #define S_PC 60
  290. #define S_LR 56
  291. #define S_SP 52
  292. #define S_IP 48
  293. #define S_FP 44
  294. #define S_R10 40
  295. #define S_R9 36
  296. #define S_R8 32
  297. #define S_R7 28
  298. #define S_R6 24
  299. #define S_R5 20
  300. #define S_R4 16
  301. #define S_R3 12
  302. #define S_R2 8
  303. #define S_R1 4
  304. #define S_R0 0
  305. #define MODE_SVC 0x13
  306. #define I_BIT 0x80
  307. /*
  308. * use bad_save_user_regs for abort/prefetch/undef/swi ...
  309. */
  310. .macro bad_save_user_regs
  311. /* carve out a frame on current user stack */
  312. sub sp, sp, #S_FRAME_SIZE
  313. /* Save user registers (now in svc mode) r0-r12 */
  314. stmia sp, {r0 - r12}
  315. ldr r2, _armboot_start
  316. sub r2, r2, #(CONFIG_SYS_MALLOC_LEN)
  317. /* set base 2 words into abort stack */
  318. sub r2, r2, #(CONFIG_SYS_GBL_DATA_SIZE+8)
  319. /* get values for "aborted" pc and cpsr (into parm regs) */
  320. ldmia r2, {r2 - r3}
  321. /* grab pointer to old stack */
  322. add r0, sp, #S_FRAME_SIZE
  323. add r5, sp, #S_SP
  324. mov r1, lr
  325. /* save sp_SVC, lr_SVC, pc, cpsr */
  326. stmia r5, {r0 - r3}
  327. /* save current stack into r0 (param register) */
  328. mov r0, sp
  329. .endm
  330. .macro get_bad_stack
  331. /* setup our mode stack (enter in banked mode) */
  332. ldr r13, _armboot_start
  333. /* move past malloc pool */
  334. sub r13, r13, #(CONFIG_SYS_MALLOC_LEN)
  335. /* move to reserved a couple spots for abort stack */
  336. sub r13, r13, #(CONFIG_SYS_GBL_DATA_SIZE + 8)
  337. /* save caller lr in position 0 of saved stack */
  338. str lr, [r13]
  339. /* get the spsr */
  340. mrs lr, spsr
  341. /* save spsr in position 1 of saved stack */
  342. str lr, [r13, #4]
  343. /* prepare SVC-Mode */
  344. mov r13, #MODE_SVC
  345. @ msr spsr_c, r13
  346. /* switch modes, make sure moves will execute */
  347. msr spsr, r13
  348. /* capture return pc */
  349. mov lr, pc
  350. /* jump to next instruction & switch modes. */
  351. movs pc, lr
  352. .endm
  353. .macro get_bad_stack_swi
  354. /* space on current stack for scratch reg. */
  355. sub r13, r13, #4
  356. /* save R0's value. */
  357. str r0, [r13]
  358. /* get data regions start */
  359. ldr r0, _armboot_start
  360. /* move past malloc pool */
  361. sub r0, r0, #(CONFIG_SYS_MALLOC_LEN)
  362. /* move past gbl and a couple spots for abort stack */
  363. sub r0, r0, #(CONFIG_SYS_GBL_DATA_SIZE + 8)
  364. /* save caller lr in position 0 of saved stack */
  365. str lr, [r0]
  366. /* get the spsr */
  367. mrs r0, spsr
  368. /* save spsr in position 1 of saved stack */
  369. str lr, [r0, #4]
  370. /* restore r0 */
  371. ldr r0, [r13]
  372. /* pop stack entry */
  373. add r13, r13, #4
  374. .endm
  375. /*
  376. * exception handlers
  377. */
  378. .align 5
  379. undefined_instruction:
  380. get_bad_stack
  381. bad_save_user_regs
  382. bl do_undefined_instruction
  383. .align 5
  384. software_interrupt:
  385. get_bad_stack_swi
  386. bad_save_user_regs
  387. bl do_software_interrupt
  388. .align 5
  389. prefetch_abort:
  390. get_bad_stack
  391. bad_save_user_regs
  392. bl do_prefetch_abort
  393. .align 5
  394. data_abort:
  395. get_bad_stack
  396. bad_save_user_regs
  397. bl do_data_abort
  398. .align 5
  399. not_used:
  400. get_bad_stack
  401. bad_save_user_regs
  402. bl do_not_used
  403. .align 5
  404. irq:
  405. get_bad_stack
  406. bad_save_user_regs
  407. bl do_irq
  408. .align 5
  409. fiq:
  410. get_bad_stack
  411. bad_save_user_regs
  412. bl do_fiq
  413. #endif /* CONFIG_NAND_SPL */