start.S 6.8 KB

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