start.S 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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. /*
  61. * These are defined in the board-specific linker script.
  62. * Subtracting _start from them lets the linker put their
  63. * relative position in the executable instead of leaving
  64. * them null.
  65. */
  66. .globl _bss_start_ofs
  67. _bss_start_ofs:
  68. .word __bss_start - _start
  69. .globl _bss_end_ofs
  70. _bss_end_ofs:
  71. .word __bss_end__ - _start
  72. .globl _end_ofs
  73. _end_ofs:
  74. .word _end - _start
  75. #ifdef CONFIG_USE_IRQ
  76. /* IRQ stack memory (calculated at run-time) */
  77. .globl IRQ_STACK_START
  78. IRQ_STACK_START:
  79. .word 0x0badc0de
  80. /* IRQ stack memory (calculated at run-time) */
  81. .globl FIQ_STACK_START
  82. FIQ_STACK_START:
  83. .word 0x0badc0de
  84. #endif
  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. /*
  90. * the actual reset code
  91. */
  92. reset:
  93. /*
  94. * set the cpu to SVC32 mode
  95. */
  96. mrs r0,cpsr
  97. bic r0,r0,#0x1f
  98. orr r0,r0,#0xd3
  99. msr cpsr,r0
  100. /*
  101. * we do sys-critical inits only at reboot,
  102. * not when booting from ram!
  103. */
  104. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  105. bl cpu_init_crit
  106. /*
  107. * before relocating, we have to setup RAM timing
  108. * because memory timing is board-dependend, you will
  109. * find a lowlevel_init.S in your board directory.
  110. */
  111. bl lowlevel_init
  112. #endif
  113. /* Set stackpointer in internal RAM to call board_init_f */
  114. call_board_init_f:
  115. ldr sp, =(CONFIG_SYS_INIT_SP_ADDR)
  116. bic sp, sp, #7 /* 8-byte alignment for ABI compliance */
  117. ldr r0,=0x00000000
  118. bl board_init_f
  119. /*------------------------------------------------------------------------------*/
  120. /*
  121. * void relocate_code (addr_sp, gd, addr_moni)
  122. *
  123. * This "function" does not return, instead it continues in RAM
  124. * after relocating the monitor code.
  125. *
  126. */
  127. .globl relocate_code
  128. relocate_code:
  129. mov r4, r0 /* save addr_sp */
  130. mov r5, r1 /* save addr of gd */
  131. mov r6, r2 /* save addr of destination */
  132. /* Set up the stack */
  133. stack_setup:
  134. mov sp, r4
  135. adr r0, _start
  136. cmp r0, r6
  137. moveq r9, #0 /* no relocation. relocation offset(r9) = 0 */
  138. beq clear_bss /* skip relocation */
  139. mov r1, r6 /* r1 <- scratch for copy_loop */
  140. ldr r3, _bss_start_ofs
  141. add r2, r0, r3 /* r2 <- source end address */
  142. copy_loop:
  143. ldmia r0!, {r9-r10} /* copy from source address [r0] */
  144. stmia r1!, {r9-r10} /* copy to target address [r1] */
  145. cmp r0, r2 /* until source end address [r2] */
  146. blo copy_loop
  147. #ifndef CONFIG_SPL_BUILD
  148. /*
  149. * fix .rel.dyn relocations
  150. */
  151. ldr r0, _TEXT_BASE /* r0 <- Text base */
  152. sub r9, r6, r0 /* r9 <- relocation offset */
  153. ldr r10, _dynsym_start_ofs /* r10 <- sym table ofs */
  154. add r10, r10, r0 /* r10 <- sym table in FLASH */
  155. ldr r2, _rel_dyn_start_ofs /* r2 <- rel dyn start ofs */
  156. add r2, r2, r0 /* r2 <- rel dyn start in FLASH */
  157. ldr r3, _rel_dyn_end_ofs /* r3 <- rel dyn end ofs */
  158. add r3, r3, r0 /* r3 <- rel dyn end in FLASH */
  159. fixloop:
  160. ldr r0, [r2] /* r0 <- location to fix up, IN FLASH! */
  161. add r0, r0, r9 /* r0 <- location to fix up in RAM */
  162. ldr r1, [r2, #4]
  163. and r7, r1, #0xff
  164. cmp r7, #23 /* relative fixup? */
  165. beq fixrel
  166. cmp r7, #2 /* absolute fixup? */
  167. beq fixabs
  168. /* ignore unknown type of fixup */
  169. b fixnext
  170. fixabs:
  171. /* absolute fix: set location to (offset) symbol value */
  172. mov r1, r1, LSR #4 /* r1 <- symbol index in .dynsym */
  173. add r1, r10, r1 /* r1 <- address of symbol in table */
  174. ldr r1, [r1, #4] /* r1 <- symbol value */
  175. add r1, r1, r9 /* r1 <- relocated sym addr */
  176. b fixnext
  177. fixrel:
  178. /* relative fix: increase location by offset */
  179. ldr r1, [r0]
  180. add r1, r1, r9
  181. fixnext:
  182. str r1, [r0]
  183. add r2, r2, #8 /* each rel.dyn entry is 8 bytes */
  184. cmp r2, r3
  185. blo fixloop
  186. #endif
  187. clear_bss:
  188. #ifndef CONFIG_SPL_BUILD
  189. ldr r0, _bss_start_ofs
  190. ldr r1, _bss_end_ofs
  191. mov r4, r6 /* reloc addr */
  192. add r0, r0, r4
  193. add r1, r1, r4
  194. mov r2, #0x00000000 /* clear */
  195. clbss_l:cmp r0, r1 /* clear loop... */
  196. bhs clbss_e /* if reached end of bss, exit */
  197. str r2, [r0]
  198. add r0, r0, #4
  199. b clbss_l
  200. clbss_e:
  201. bl coloured_LED_init
  202. bl red_led_on
  203. #endif
  204. /*
  205. * We are done. Do not return, instead branch to second part of board
  206. * initialization, now running from RAM.
  207. */
  208. ldr r0, _board_init_r_ofs
  209. adr r1, _start
  210. add lr, r0, r1
  211. add lr, lr, r9
  212. /* setup parameters for board_init_r */
  213. mov r0, r5 /* gd_t */
  214. mov r1, r6 /* dest_addr */
  215. /* jump to it ... */
  216. mov pc, lr
  217. _board_init_r_ofs:
  218. .word board_init_r - _start
  219. _rel_dyn_start_ofs:
  220. .word __rel_dyn_start - _start
  221. _rel_dyn_end_ofs:
  222. .word __rel_dyn_end - _start
  223. _dynsym_start_ofs:
  224. .word __dynsym_start - _start
  225. /*
  226. *************************************************************************
  227. *
  228. * CPU_init_critical registers
  229. *
  230. * setup important registers
  231. * setup memory timing
  232. *
  233. *************************************************************************
  234. */
  235. #define INTCON (0x01c00000+0x200000)
  236. #define INTMSK (0x01c00000+0x20000c)
  237. #define LOCKTIME (0x01c00000+0x18000c)
  238. #define PLLCON (0x01c00000+0x180000)
  239. #define CLKCON (0x01c00000+0x180004)
  240. #define WTCON (0x01c00000+0x130000)
  241. cpu_init_crit:
  242. /* disable watch dog */
  243. ldr r0, =WTCON
  244. ldr r1, =0x0
  245. str r1, [r0]
  246. /*
  247. * mask all IRQs by clearing all bits in the INTMRs
  248. */
  249. ldr r1,=INTMSK
  250. ldr r0, =0x03fffeff
  251. str r0, [r1]
  252. ldr r1, =INTCON
  253. ldr r0, =0x05
  254. str r0, [r1]
  255. /* Set Clock Control Register */
  256. ldr r1, =LOCKTIME
  257. ldrb r0, =800
  258. strb r0, [r1]
  259. ldr r1, =PLLCON
  260. #if CONFIG_S3C44B0_CLOCK_SPEED==66
  261. ldr r0, =0x34031 /* 66MHz (Quartz=11MHz) */
  262. #elif CONFIG_S3C44B0_CLOCK_SPEED==75
  263. ldr r0, =0x610c1 /*B2: Xtal=20mhz Fclk=75MHz */
  264. #else
  265. # error CONFIG_S3C44B0_CLOCK_SPEED undefined
  266. #endif
  267. str r0, [r1]
  268. ldr r1,=CLKCON
  269. ldr r0, =0x7ff8
  270. str r0, [r1]
  271. mov pc, lr
  272. /*************************************************/
  273. /* interrupt vectors */
  274. /*************************************************/
  275. real_vectors:
  276. b reset
  277. b undefined_instruction
  278. b software_interrupt
  279. b prefetch_abort
  280. b data_abort
  281. b not_used
  282. b irq
  283. b fiq
  284. /*************************************************/
  285. undefined_instruction:
  286. mov r6, #3
  287. b reset
  288. software_interrupt:
  289. mov r6, #4
  290. b reset
  291. prefetch_abort:
  292. mov r6, #5
  293. b reset
  294. data_abort:
  295. mov r6, #6
  296. b reset
  297. not_used:
  298. /* we *should* never reach this */
  299. mov r6, #7
  300. b reset
  301. irq:
  302. mov r6, #8
  303. b reset
  304. fiq:
  305. mov r6, #9
  306. b reset