start.S 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. /*
  2. * Startup Code for S3C44B0 CPU-core
  3. *
  4. * (C) Copyright 2004
  5. * DAVE Srl
  6. *
  7. * http://www.dave-tech.it
  8. * http://www.wawnet.biz
  9. * mailto:info@wawnet.biz
  10. *
  11. * See file CREDITS for list of people who contributed to this
  12. * project.
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License as
  16. * published by the Free Software Foundation; either version 2 of
  17. * the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  27. * MA 02111-1307 USA
  28. */
  29. #include <asm-offsets.h>
  30. #include <config.h>
  31. #include <version.h>
  32. /*
  33. * Jump vector table
  34. */
  35. .globl _start
  36. _start: b reset
  37. add pc, pc, #0x0c000000
  38. add pc, pc, #0x0c000000
  39. add pc, pc, #0x0c000000
  40. add pc, pc, #0x0c000000
  41. add pc, pc, #0x0c000000
  42. add pc, pc, #0x0c000000
  43. add pc, pc, #0x0c000000
  44. .balignl 16,0xdeadbeef
  45. /*
  46. *************************************************************************
  47. *
  48. * Startup Code (reset vector)
  49. *
  50. * do important init only if we don't start from memory!
  51. * relocate u-boot to ram
  52. * setup stack
  53. * jump to second stage
  54. *
  55. *************************************************************************
  56. */
  57. .globl _TEXT_BASE
  58. _TEXT_BASE:
  59. .word CONFIG_SYS_TEXT_BASE
  60. #if defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
  61. .globl _armboot_start
  62. _armboot_start:
  63. .word _start
  64. #endif
  65. /*
  66. * These are defined in the board-specific linker script.
  67. */
  68. .globl _bss_start
  69. _bss_start:
  70. .word __bss_start
  71. .globl _bss_end
  72. _bss_end:
  73. .word _end
  74. #ifdef CONFIG_USE_IRQ
  75. /* IRQ stack memory (calculated at run-time) */
  76. .globl IRQ_STACK_START
  77. IRQ_STACK_START:
  78. .word 0x0badc0de
  79. /* IRQ stack memory (calculated at run-time) */
  80. .globl FIQ_STACK_START
  81. FIQ_STACK_START:
  82. .word 0x0badc0de
  83. #endif
  84. #if !defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
  85. /* IRQ stack memory (calculated at run-time) + 8 bytes */
  86. .globl IRQ_STACK_START_IN
  87. IRQ_STACK_START_IN:
  88. .word 0x0badc0de
  89. .globl _datarel_start
  90. _datarel_start:
  91. .word __datarel_start
  92. .globl _datarelrolocal_start
  93. _datarelrolocal_start:
  94. .word __datarelrolocal_start
  95. .globl _datarellocal_start
  96. _datarellocal_start:
  97. .word __datarellocal_start
  98. .globl _datarelro_start
  99. _datarelro_start:
  100. .word __datarelro_start
  101. .globl _got_start
  102. _got_start:
  103. .word __got_start
  104. .globl _got_end
  105. _got_end:
  106. .word __got_end
  107. /*
  108. * the actual reset code
  109. */
  110. reset:
  111. /*
  112. * set the cpu to SVC32 mode
  113. */
  114. mrs r0,cpsr
  115. bic r0,r0,#0x1f
  116. orr r0,r0,#0xd3
  117. msr cpsr,r0
  118. /*
  119. * we do sys-critical inits only at reboot,
  120. * not when booting from ram!
  121. */
  122. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  123. bl cpu_init_crit
  124. /*
  125. * before relocating, we have to setup RAM timing
  126. * because memory timing is board-dependend, you will
  127. * find a lowlevel_init.S in your board directory.
  128. */
  129. bl lowlevel_init
  130. #endif
  131. /* Set stackpointer in internal RAM to call board_init_f */
  132. call_board_init_f:
  133. ldr sp, =(CONFIG_SYS_INIT_SP_ADDR)
  134. ldr r0,=0x00000000
  135. bl board_init_f
  136. /*------------------------------------------------------------------------------*/
  137. /*
  138. * void relocate_code (addr_sp, gd, addr_moni)
  139. *
  140. * This "function" does not return, instead it continues in RAM
  141. * after relocating the monitor code.
  142. *
  143. */
  144. .globl relocate_code
  145. relocate_code:
  146. mov r4, r0 /* save addr_sp */
  147. mov r5, r1 /* save addr of gd */
  148. mov r6, r2 /* save addr of destination */
  149. mov r7, r2 /* save addr of destination */
  150. /* Set up the stack */
  151. stack_setup:
  152. mov sp, r4
  153. adr r0, _start
  154. ldr r2, _TEXT_BASE
  155. ldr r3, _bss_start
  156. sub r2, r3, r2 /* r2 <- size of armboot */
  157. add r2, r0, r2 /* r2 <- source end address */
  158. cmp r0, r6
  159. beq clear_bss
  160. #ifndef CONFIG_SKIP_RELOCATE_UBOOT
  161. copy_loop:
  162. ldmia r0!, {r9-r10} /* copy from source address [r0] */
  163. stmia r6!, {r9-r10} /* copy to target address [r1] */
  164. cmp r0, r2 /* until source end address [r2] */
  165. blo copy_loop
  166. #ifndef CONFIG_PRELOADER
  167. /* fix got entries */
  168. ldr r1, _TEXT_BASE /* Text base */
  169. mov r0, r7 /* reloc addr */
  170. ldr r2, _got_start /* addr in Flash */
  171. ldr r3, _got_end /* addr in Flash */
  172. sub r3, r3, r1
  173. add r3, r3, r0
  174. sub r2, r2, r1
  175. add r2, r2, r0
  176. fixloop:
  177. ldr r4, [r2]
  178. sub r4, r4, r1
  179. add r4, r4, r0
  180. str r4, [r2]
  181. add r2, r2, #4
  182. cmp r2, r3
  183. bne fixloop
  184. #endif
  185. /*
  186. now copy to sram the interrupt vector
  187. */
  188. adr r0, real_vectors
  189. add r2, r0, #1024
  190. ldr r1, =0x0c000000
  191. add r1, r1, #0x08
  192. vector_copy_loop:
  193. ldmia r0!, {r3-r10}
  194. stmia r1!, {r3-r10}
  195. cmp r0, r2
  196. blo vector_copy_loop
  197. #endif /* #ifndef CONFIG_SKIP_RELOCATE_UBOOT */
  198. clear_bss:
  199. #ifndef CONFIG_PRELOADER
  200. ldr r0, _bss_start
  201. ldr r1, _bss_end
  202. ldr r3, _TEXT_BASE /* Text base */
  203. mov r4, r7 /* reloc addr */
  204. sub r0, r0, r3
  205. add r0, r0, r4
  206. sub r1, r1, r3
  207. add r1, r1, r4
  208. mov r2, #0x00000000 /* clear */
  209. clbss_l:str r2, [r0] /* clear loop... */
  210. add r0, r0, #4
  211. cmp r0, r1
  212. bne clbss_l
  213. bl coloured_LED_init
  214. bl red_LED_on
  215. #endif
  216. /*
  217. * We are done. Do not return, instead branch to second part of board
  218. * initialization, now running from RAM.
  219. */
  220. ldr r0, _TEXT_BASE
  221. ldr r2, _board_init_r
  222. sub r2, r2, r0
  223. add r2, r2, r7 /* position from board_init_r in RAM */
  224. /* setup parameters for board_init_r */
  225. mov r0, r5 /* gd_t */
  226. mov r1, r7 /* dest_addr */
  227. /* jump to it ... */
  228. mov lr, r2
  229. mov pc, lr
  230. _board_init_r: .word board_init_r
  231. #else /* #if !defined(CONFIG_SYS_ARM_WITHOUT_RELOC) */
  232. /*
  233. * the actual reset code
  234. */
  235. reset:
  236. /*
  237. * set the cpu to SVC32 mode
  238. */
  239. mrs r0,cpsr
  240. bic r0,r0,#0x1f
  241. orr r0,r0,#0x13
  242. msr cpsr,r0
  243. /*
  244. * we do sys-critical inits only at reboot,
  245. * not when booting from ram!
  246. */
  247. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  248. bl cpu_init_crit
  249. /*
  250. * before relocating, we have to setup RAM timing
  251. * because memory timing is board-dependend, you will
  252. * find a lowlevel_init.S in your board directory.
  253. */
  254. bl lowlevel_init
  255. #endif
  256. #ifndef CONFIG_SKIP_RELOCATE_UBOOT
  257. relocate: /* relocate U-Boot to RAM */
  258. adr r0, _start /* r0 <- current position of code */
  259. ldr r1, _TEXT_BASE /* test if we run from flash or RAM */
  260. cmp r0, r1 /* don't reloc during debug */
  261. beq stack_setup
  262. ldr r2, _armboot_start
  263. ldr r3, _bss_start
  264. sub r2, r3, r2 /* r2 <- size of armboot */
  265. add r2, r0, r2 /* r2 <- source end address */
  266. copy_loop:
  267. ldmia r0!, {r3-r10} /* copy from source address [r0] */
  268. stmia r1!, {r3-r10} /* copy to target address [r1] */
  269. cmp r0, r2 /* until source end address [r2] */
  270. blo copy_loop
  271. /*
  272. now copy to sram the interrupt vector
  273. */
  274. adr r0, real_vectors
  275. add r2, r0, #1024
  276. ldr r1, =0x0c000000
  277. add r1, r1, #0x08
  278. vector_copy_loop:
  279. ldmia r0!, {r3-r10}
  280. stmia r1!, {r3-r10}
  281. cmp r0, r2
  282. blo vector_copy_loop
  283. #endif /* CONFIG_SKIP_RELOCATE_UBOOT */
  284. /* Set up the stack */
  285. stack_setup:
  286. ldr r0, _TEXT_BASE /* upper 128 KiB: relocated uboot */
  287. sub r0, r0, #CONFIG_SYS_MALLOC_LEN /* malloc area */
  288. sub r0, r0, #GENERATED_GBL_DATA_SIZE /* bdinfo */
  289. #ifdef CONFIG_USE_IRQ
  290. sub r0, r0, #(CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ)
  291. #endif
  292. sub sp, r0, #12 /* leave 3 words for abort-stack */
  293. bic sp, sp, #7 /* 8-byte alignment for ABI compliance */
  294. ldr pc, _start_armboot
  295. _start_armboot: .word start_armboot
  296. #endif /* #if !defined(CONFIG_SYS_ARM_WITHOUT_RELOC) */
  297. /*
  298. *************************************************************************
  299. *
  300. * CPU_init_critical registers
  301. *
  302. * setup important registers
  303. * setup memory timing
  304. *
  305. *************************************************************************
  306. */
  307. #define INTCON (0x01c00000+0x200000)
  308. #define INTMSK (0x01c00000+0x20000c)
  309. #define LOCKTIME (0x01c00000+0x18000c)
  310. #define PLLCON (0x01c00000+0x180000)
  311. #define CLKCON (0x01c00000+0x180004)
  312. #define WTCON (0x01c00000+0x130000)
  313. cpu_init_crit:
  314. /* disable watch dog */
  315. ldr r0, =WTCON
  316. ldr r1, =0x0
  317. str r1, [r0]
  318. /*
  319. * mask all IRQs by clearing all bits in the INTMRs
  320. */
  321. ldr r1,=INTMSK
  322. ldr r0, =0x03fffeff
  323. str r0, [r1]
  324. ldr r1, =INTCON
  325. ldr r0, =0x05
  326. str r0, [r1]
  327. /* Set Clock Control Register */
  328. ldr r1, =LOCKTIME
  329. ldrb r0, =800
  330. strb r0, [r1]
  331. ldr r1, =PLLCON
  332. #if CONFIG_S3C44B0_CLOCK_SPEED==66
  333. ldr r0, =0x34031 /* 66MHz (Quartz=11MHz) */
  334. #elif CONFIG_S3C44B0_CLOCK_SPEED==75
  335. ldr r0, =0x610c1 /*B2: Xtal=20mhz Fclk=75MHz */
  336. #else
  337. # error CONFIG_S3C44B0_CLOCK_SPEED undefined
  338. #endif
  339. str r0, [r1]
  340. ldr r1,=CLKCON
  341. ldr r0, =0x7ff8
  342. str r0, [r1]
  343. mov pc, lr
  344. /*************************************************/
  345. /* interrupt vectors */
  346. /*************************************************/
  347. real_vectors:
  348. b reset
  349. b undefined_instruction
  350. b software_interrupt
  351. b prefetch_abort
  352. b data_abort
  353. b not_used
  354. b irq
  355. b fiq
  356. /*************************************************/
  357. undefined_instruction:
  358. mov r6, #3
  359. b reset
  360. software_interrupt:
  361. mov r6, #4
  362. b reset
  363. prefetch_abort:
  364. mov r6, #5
  365. b reset
  366. data_abort:
  367. mov r6, #6
  368. b reset
  369. not_used:
  370. /* we *should* never reach this */
  371. mov r6, #7
  372. b reset
  373. irq:
  374. mov r6, #8
  375. b reset
  376. fiq:
  377. mov r6, #9
  378. b reset