start.S 7.0 KB

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