start.S 9.2 KB

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