start.S 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. /*
  2. * Startup Code for MIPS32 CPU-core
  3. *
  4. * Copyright (c) 2003 Wolfgang Denk <wd@denx.de>
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #include <asm-offsets.h>
  25. #include <config.h>
  26. #include <asm/regdef.h>
  27. #include <asm/mipsregs.h>
  28. #ifndef CONFIG_SYS_MIPS_CACHE_MODE
  29. #define CONFIG_SYS_MIPS_CACHE_MODE CONF_CM_CACHABLE_NONCOHERENT
  30. #endif
  31. /*
  32. * For the moment disable interrupts, mark the kernel mode and
  33. * set ST0_KX so that the CPU does not spit fire when using
  34. * 64-bit addresses.
  35. */
  36. .macro setup_c0_status set clr
  37. .set push
  38. mfc0 t0, CP0_STATUS
  39. or t0, ST0_CU0 | \set | 0x1f | \clr
  40. xor t0, 0x1f | \clr
  41. mtc0 t0, CP0_STATUS
  42. .set noreorder
  43. sll zero, 3 # ehb
  44. .set pop
  45. .endm
  46. .macro setup_c0_status_reset
  47. #ifdef CONFIG_64BIT
  48. setup_c0_status ST0_KX 0
  49. #else
  50. setup_c0_status 0 0
  51. #endif
  52. .endm
  53. #define RVECENT(f,n) \
  54. b f; nop
  55. #define XVECENT(f,bev) \
  56. b f ; \
  57. li k0,bev
  58. .set noreorder
  59. .globl _start
  60. .text
  61. _start:
  62. RVECENT(reset,0) # U-boot entry point
  63. RVECENT(reset,1) # software reboot
  64. #ifdef CONFIG_SYS_XWAY_EBU_BOOTCFG
  65. /*
  66. * Almost all Lantiq XWAY SoC devices have an external bus unit (EBU) to
  67. * access external NOR flashes. If the board boots from NOR flash the
  68. * internal BootROM does a blind read at address 0xB0000010 to read the
  69. * initial configuration for that EBU in order to access the flash
  70. * device with correct parameters. This config option is board-specific.
  71. */
  72. .word CONFIG_SYS_XWAY_EBU_BOOTCFG
  73. .word 0x00000000
  74. #else
  75. RVECENT(romReserved,2)
  76. #endif
  77. RVECENT(romReserved,3)
  78. RVECENT(romReserved,4)
  79. RVECENT(romReserved,5)
  80. RVECENT(romReserved,6)
  81. RVECENT(romReserved,7)
  82. RVECENT(romReserved,8)
  83. RVECENT(romReserved,9)
  84. RVECENT(romReserved,10)
  85. RVECENT(romReserved,11)
  86. RVECENT(romReserved,12)
  87. RVECENT(romReserved,13)
  88. RVECENT(romReserved,14)
  89. RVECENT(romReserved,15)
  90. RVECENT(romReserved,16)
  91. RVECENT(romReserved,17)
  92. RVECENT(romReserved,18)
  93. RVECENT(romReserved,19)
  94. RVECENT(romReserved,20)
  95. RVECENT(romReserved,21)
  96. RVECENT(romReserved,22)
  97. RVECENT(romReserved,23)
  98. RVECENT(romReserved,24)
  99. RVECENT(romReserved,25)
  100. RVECENT(romReserved,26)
  101. RVECENT(romReserved,27)
  102. RVECENT(romReserved,28)
  103. RVECENT(romReserved,29)
  104. RVECENT(romReserved,30)
  105. RVECENT(romReserved,31)
  106. RVECENT(romReserved,32)
  107. RVECENT(romReserved,33)
  108. RVECENT(romReserved,34)
  109. RVECENT(romReserved,35)
  110. RVECENT(romReserved,36)
  111. RVECENT(romReserved,37)
  112. RVECENT(romReserved,38)
  113. RVECENT(romReserved,39)
  114. RVECENT(romReserved,40)
  115. RVECENT(romReserved,41)
  116. RVECENT(romReserved,42)
  117. RVECENT(romReserved,43)
  118. RVECENT(romReserved,44)
  119. RVECENT(romReserved,45)
  120. RVECENT(romReserved,46)
  121. RVECENT(romReserved,47)
  122. RVECENT(romReserved,48)
  123. RVECENT(romReserved,49)
  124. RVECENT(romReserved,50)
  125. RVECENT(romReserved,51)
  126. RVECENT(romReserved,52)
  127. RVECENT(romReserved,53)
  128. RVECENT(romReserved,54)
  129. RVECENT(romReserved,55)
  130. RVECENT(romReserved,56)
  131. RVECENT(romReserved,57)
  132. RVECENT(romReserved,58)
  133. RVECENT(romReserved,59)
  134. RVECENT(romReserved,60)
  135. RVECENT(romReserved,61)
  136. RVECENT(romReserved,62)
  137. RVECENT(romReserved,63)
  138. XVECENT(romExcHandle,0x200) # bfc00200: R4000 tlbmiss vector
  139. RVECENT(romReserved,65)
  140. RVECENT(romReserved,66)
  141. RVECENT(romReserved,67)
  142. RVECENT(romReserved,68)
  143. RVECENT(romReserved,69)
  144. RVECENT(romReserved,70)
  145. RVECENT(romReserved,71)
  146. RVECENT(romReserved,72)
  147. RVECENT(romReserved,73)
  148. RVECENT(romReserved,74)
  149. RVECENT(romReserved,75)
  150. RVECENT(romReserved,76)
  151. RVECENT(romReserved,77)
  152. RVECENT(romReserved,78)
  153. RVECENT(romReserved,79)
  154. XVECENT(romExcHandle,0x280) # bfc00280: R4000 xtlbmiss vector
  155. RVECENT(romReserved,81)
  156. RVECENT(romReserved,82)
  157. RVECENT(romReserved,83)
  158. RVECENT(romReserved,84)
  159. RVECENT(romReserved,85)
  160. RVECENT(romReserved,86)
  161. RVECENT(romReserved,87)
  162. RVECENT(romReserved,88)
  163. RVECENT(romReserved,89)
  164. RVECENT(romReserved,90)
  165. RVECENT(romReserved,91)
  166. RVECENT(romReserved,92)
  167. RVECENT(romReserved,93)
  168. RVECENT(romReserved,94)
  169. RVECENT(romReserved,95)
  170. XVECENT(romExcHandle,0x300) # bfc00300: R4000 cache vector
  171. RVECENT(romReserved,97)
  172. RVECENT(romReserved,98)
  173. RVECENT(romReserved,99)
  174. RVECENT(romReserved,100)
  175. RVECENT(romReserved,101)
  176. RVECENT(romReserved,102)
  177. RVECENT(romReserved,103)
  178. RVECENT(romReserved,104)
  179. RVECENT(romReserved,105)
  180. RVECENT(romReserved,106)
  181. RVECENT(romReserved,107)
  182. RVECENT(romReserved,108)
  183. RVECENT(romReserved,109)
  184. RVECENT(romReserved,110)
  185. RVECENT(romReserved,111)
  186. XVECENT(romExcHandle,0x380) # bfc00380: R4000 general vector
  187. RVECENT(romReserved,113)
  188. RVECENT(romReserved,114)
  189. RVECENT(romReserved,115)
  190. RVECENT(romReserved,116)
  191. RVECENT(romReserved,116)
  192. RVECENT(romReserved,118)
  193. RVECENT(romReserved,119)
  194. RVECENT(romReserved,120)
  195. RVECENT(romReserved,121)
  196. RVECENT(romReserved,122)
  197. RVECENT(romReserved,123)
  198. RVECENT(romReserved,124)
  199. RVECENT(romReserved,125)
  200. RVECENT(romReserved,126)
  201. RVECENT(romReserved,127)
  202. /*
  203. * We hope there are no more reserved vectors!
  204. * 128 * 8 == 1024 == 0x400
  205. * so this is address R_VEC+0x400 == 0xbfc00400
  206. */
  207. .align 4
  208. reset:
  209. /* Clear watch registers */
  210. mtc0 zero, CP0_WATCHLO
  211. mtc0 zero, CP0_WATCHHI
  212. /* WP(Watch Pending), SW0/1 should be cleared */
  213. mtc0 zero, CP0_CAUSE
  214. setup_c0_status_reset
  215. /* Init Timer */
  216. mtc0 zero, CP0_COUNT
  217. mtc0 zero, CP0_COMPARE
  218. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  219. /* CONFIG0 register */
  220. li t0, CONF_CM_UNCACHED
  221. mtc0 t0, CP0_CONFIG
  222. #endif
  223. /* Initialize $gp */
  224. bal 1f
  225. nop
  226. .word _gp
  227. 1:
  228. lw gp, 0(ra)
  229. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  230. /* Initialize any external memory */
  231. la t9, lowlevel_init
  232. jalr t9
  233. nop
  234. /* Initialize caches... */
  235. la t9, mips_cache_reset
  236. jalr t9
  237. nop
  238. /* ... and enable them */
  239. li t0, CONFIG_SYS_MIPS_CACHE_MODE
  240. mtc0 t0, CP0_CONFIG
  241. #endif
  242. /* Set up temporary stack */
  243. li t0, CONFIG_SYS_SDRAM_BASE + CONFIG_SYS_INIT_SP_OFFSET
  244. la sp, 0(t0)
  245. la t9, board_init_f
  246. jr t9
  247. nop
  248. /*
  249. * void relocate_code (addr_sp, gd, addr_moni)
  250. *
  251. * This "function" does not return, instead it continues in RAM
  252. * after relocating the monitor code.
  253. *
  254. * a0 = addr_sp
  255. * a1 = gd
  256. * a2 = destination address
  257. */
  258. .globl relocate_code
  259. .ent relocate_code
  260. relocate_code:
  261. move sp, a0 # set new stack pointer
  262. li t0, CONFIG_SYS_MONITOR_BASE
  263. la t3, in_ram
  264. lw t2, -12(t3) # t2 <-- uboot_end_data
  265. move t1, a2
  266. move s2, a2 # s2 <-- destination address
  267. /*
  268. * Fix $gp:
  269. *
  270. * New $gp = (Old $gp - CONFIG_SYS_MONITOR_BASE) + Destination Address
  271. */
  272. move t6, gp
  273. sub gp, CONFIG_SYS_MONITOR_BASE
  274. add gp, a2 # gp now adjusted
  275. sub s1, gp, t6 # s1 <-- relocation offset
  276. /*
  277. * t0 = source address
  278. * t1 = target address
  279. * t2 = source end address
  280. */
  281. /*
  282. * Save destination address and size for later usage in flush_cache()
  283. */
  284. move s0, a1 # save gd in s0
  285. move a0, t1 # a0 <-- destination addr
  286. sub a1, t2, t0 # a1 <-- size
  287. 1:
  288. lw t3, 0(t0)
  289. sw t3, 0(t1)
  290. addu t0, 4
  291. ble t0, t2, 1b
  292. addu t1, 4
  293. /* If caches were enabled, we would have to flush them here. */
  294. /* a0 & a1 are already set up for flush_cache(start, size) */
  295. la t9, flush_cache
  296. jalr t9
  297. nop
  298. /* Jump to where we've relocated ourselves */
  299. addi t0, s2, in_ram - _start
  300. jr t0
  301. nop
  302. .word _gp
  303. .word _GLOBAL_OFFSET_TABLE_
  304. .word uboot_end_data
  305. .word uboot_end
  306. .word num_got_entries
  307. in_ram:
  308. /*
  309. * Now we want to update GOT.
  310. *
  311. * GOT[0] is reserved. GOT[1] is also reserved for the dynamic object
  312. * generated by GNU ld. Skip these reserved entries from relocation.
  313. */
  314. lw t3, -4(t0) # t3 <-- num_got_entries
  315. lw t4, -16(t0) # t4 <-- _GLOBAL_OFFSET_TABLE_
  316. lw t5, -20(t0) # t5 <-- _gp
  317. sub t4, t5 # compute offset
  318. add t4, t4, gp # t4 now holds relocated _G_O_T_
  319. addi t4, t4, 8 # skipping first two entries
  320. li t2, 2
  321. 1:
  322. lw t1, 0(t4)
  323. beqz t1, 2f
  324. add t1, s1
  325. sw t1, 0(t4)
  326. 2:
  327. addi t2, 1
  328. blt t2, t3, 1b
  329. addi t4, 4
  330. /* Clear BSS */
  331. lw t1, -12(t0) # t1 <-- uboot_end_data
  332. lw t2, -8(t0) # t2 <-- uboot_end
  333. add t1, s1 # adjust pointers
  334. add t2, s1
  335. sub t1, 4
  336. 1:
  337. addi t1, 4
  338. bltl t1, t2, 1b
  339. sw zero, 0(t1)
  340. move a0, s0 # a0 <-- gd
  341. la t9, board_init_r
  342. jr t9
  343. move a1, s2
  344. .end relocate_code
  345. /* Exception handlers */
  346. romReserved:
  347. b romReserved
  348. romExcHandle:
  349. b romExcHandle