start.S 10 KB

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