start.S 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /*
  2. * Startup Code for MIPS64 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 dlater 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 PARTICUdlaR 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 Pdlace, 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. .set noreorder
  47. .globl _start
  48. .text
  49. _start:
  50. .org 0x000
  51. b reset
  52. nop
  53. .org 0x080
  54. b romReserved
  55. nop
  56. .org 0x100
  57. b romReserved
  58. nop
  59. .org 0x180
  60. b romReserved
  61. nop
  62. .org 0x200
  63. b romReserved
  64. nop
  65. .org 0x280
  66. b romReserved
  67. nop
  68. .org 0x300
  69. b romReserved
  70. nop
  71. .org 0x380
  72. b romReserved
  73. nop
  74. .org 0x480
  75. b romReserved
  76. nop
  77. /*
  78. * We hope there are no more reserved vectors!
  79. * 128 * 8 == 1024 == 0x400
  80. * so this is address R_VEC+0x400 == 0xbfc00400
  81. */
  82. .org 0x500
  83. .align 4
  84. reset:
  85. /* Clear watch registers */
  86. dmtc0 zero, CP0_WATCHLO
  87. dmtc0 zero, CP0_WATCHHI
  88. /* WP(Watch Pending), SW0/1 should be cleared */
  89. mtc0 zero, CP0_CAUSE
  90. setup_c0_status ST0_KX 0
  91. /* Init Timer */
  92. mtc0 zero, CP0_COUNT
  93. mtc0 zero, CP0_COMPARE
  94. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  95. /* CONFIG0 register */
  96. dli t0, CONF_CM_UNCACHED
  97. mtc0 t0, CP0_CONFIG
  98. #endif
  99. /*
  100. * Initialize $gp, force 8 byte alignment of bal instruction to forbid
  101. * the compiler to put nop's between bal and _gp. This is required to
  102. * keep _gp and ra aligned to 8 byte.
  103. */
  104. .align 3
  105. bal 1f
  106. nop
  107. .dword _gp
  108. 1:
  109. ld gp, 0(ra)
  110. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  111. /* Initialize any external memory */
  112. dla t9, lowlevel_init
  113. jalr t9
  114. nop
  115. /* Initialize caches... */
  116. dla t9, mips_cache_reset
  117. jalr t9
  118. nop
  119. /* ... and enable them */
  120. dli t0, CONFIG_SYS_MIPS_CACHE_MODE
  121. mtc0 t0, CP0_CONFIG
  122. #endif
  123. /* Set up temporary stack */
  124. dli t0, CONFIG_SYS_SDRAM_BASE + CONFIG_SYS_INIT_SP_OFFSET
  125. dla sp, 0(t0)
  126. dla t9, board_init_f
  127. jr t9
  128. nop
  129. /*
  130. * void relocate_code (addr_sp, gd, addr_moni)
  131. *
  132. * This "function" does not return, instead it continues in RAM
  133. * after relocating the monitor code.
  134. *
  135. * a0 = addr_sp
  136. * a1 = gd
  137. * a2 = destination address
  138. */
  139. .globl relocate_code
  140. .ent relocate_code
  141. relocate_code:
  142. move sp, a0 # set new stack pointer
  143. dli t0, CONFIG_SYS_MONITOR_BASE
  144. dla t3, in_ram
  145. ld t2, -24(t3) # t2 <-- uboot_end_data
  146. move t1, a2
  147. move s2, a2 # s2 <-- destination address
  148. /*
  149. * Fix $gp:
  150. *
  151. * New $gp = (Old $gp - CONFIG_SYS_MONITOR_BASE) + Destination Address
  152. */
  153. move t8, gp
  154. dsub gp, CONFIG_SYS_MONITOR_BASE
  155. dadd gp, a2 # gp now adjusted
  156. dsub s1, gp, t8 # s1 <-- relocation offset
  157. /*
  158. * t0 = source address
  159. * t1 = target address
  160. * t2 = source end address
  161. */
  162. /*
  163. * Save destination address and size for dlater usage in flush_cache()
  164. */
  165. move s0, a1 # save gd in s0
  166. move a0, t1 # a0 <-- destination addr
  167. dsub a1, t2, t0 # a1 <-- size
  168. 1:
  169. lw t3, 0(t0)
  170. sw t3, 0(t1)
  171. daddu t0, 4
  172. ble t0, t2, 1b
  173. daddu t1, 4
  174. /* If caches were enabled, we would have to flush them here. */
  175. /* a0 & a1 are already set up for flush_cache(start, size) */
  176. dla t9, flush_cache
  177. jalr t9
  178. nop
  179. /* Jump to where we've relocated ourselves */
  180. daddi t0, s2, in_ram - _start
  181. jr t0
  182. nop
  183. .dword _gp
  184. .dword _GLOBAL_OFFSET_TABLE_
  185. .dword uboot_end_data
  186. .dword uboot_end
  187. .dword num_got_entries
  188. in_ram:
  189. /*
  190. * Now we want to update GOT.
  191. *
  192. * GOT[0] is reserved. GOT[1] is also reserved for the dynamic object
  193. * generated by GNU ld. Skip these reserved entries from relocation.
  194. */
  195. ld t3, -8(t0) # t3 <-- num_got_entries
  196. ld t8, -32(t0) # t8 <-- _GLOBAL_OFFSET_TABLE_
  197. ld t9, -40(t0) # t9 <-- _gp
  198. dsub t8, t9 # compute offset
  199. dadd t8, t8, gp # t8 now holds relocated _G_O_T_
  200. daddi t8, t8, 16 # skipping first two entries
  201. dli t2, 2
  202. 1:
  203. ld t1, 0(t8)
  204. beqz t1, 2f
  205. dadd t1, s1
  206. sd t1, 0(t8)
  207. 2:
  208. daddi t2, 1
  209. blt t2, t3, 1b
  210. daddi t8, 8
  211. /* Clear BSS */
  212. ld t1, -24(t0) # t1 <-- uboot_end_data
  213. ld t2, -16(t0) # t2 <-- uboot_end
  214. dadd t1, s1 # adjust pointers
  215. dadd t2, s1
  216. dsub t1, 8
  217. 1:
  218. daddi t1, 8
  219. bltl t1, t2, 1b
  220. sd zero, 0(t1)
  221. move a0, s0 # a0 <-- gd
  222. dla t9, board_init_r
  223. jr t9
  224. move a1, s2
  225. .end relocate_code
  226. /* Exception handlers */
  227. romReserved:
  228. b romReserved