start.S 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. /* Initialize $gp */
  100. bal 1f
  101. nop
  102. .dword _gp
  103. 1:
  104. ld gp, 0(ra)
  105. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  106. /* Initialize any external memory */
  107. dla t9, lowlevel_init
  108. jalr t9
  109. nop
  110. /* Initialize caches... */
  111. dla t9, mips_cache_reset
  112. jalr t9
  113. nop
  114. /* ... and enable them */
  115. dli t0, CONFIG_SYS_MIPS_CACHE_MODE
  116. mtc0 t0, CP0_CONFIG
  117. #endif
  118. /* Set up temporary stack */
  119. dli t0, CONFIG_SYS_SDRAM_BASE + CONFIG_SYS_INIT_SP_OFFSET
  120. dla sp, 0(t0)
  121. dla t9, board_init_f
  122. jr t9
  123. nop
  124. /*
  125. * void relocate_code (addr_sp, gd, addr_moni)
  126. *
  127. * This "function" does not return, instead it continues in RAM
  128. * after relocating the monitor code.
  129. *
  130. * a0 = addr_sp
  131. * a1 = gd
  132. * a2 = destination address
  133. */
  134. .globl relocate_code
  135. .ent relocate_code
  136. relocate_code:
  137. move sp, a0 # set new stack pointer
  138. dli t0, CONFIG_SYS_MONITOR_BASE
  139. dla t3, in_ram
  140. ld t2, -24(t3) # t2 <-- uboot_end_data
  141. move t1, a2
  142. move s2, a2 # s2 <-- destination address
  143. /*
  144. * Fix $gp:
  145. *
  146. * New $gp = (Old $gp - CONFIG_SYS_MONITOR_BASE) + Destination Address
  147. */
  148. move t8, gp
  149. dsub gp, CONFIG_SYS_MONITOR_BASE
  150. dadd gp, a2 # gp now adjusted
  151. dsub s1, gp, t8 # s1 <-- relocation offset
  152. /*
  153. * t0 = source address
  154. * t1 = target address
  155. * t2 = source end address
  156. */
  157. /*
  158. * Save destination address and size for dlater usage in flush_cache()
  159. */
  160. move s0, a1 # save gd in s0
  161. move a0, t1 # a0 <-- destination addr
  162. dsub a1, t2, t0 # a1 <-- size
  163. 1:
  164. lw t3, 0(t0)
  165. sw t3, 0(t1)
  166. daddu t0, 4
  167. ble t0, t2, 1b
  168. daddu t1, 4
  169. /* If caches were enabled, we would have to flush them here. */
  170. /* a0 & a1 are already set up for flush_cache(start, size) */
  171. dla t9, flush_cache
  172. jalr t9
  173. nop
  174. /* Jump to where we've relocated ourselves */
  175. daddi t0, s2, in_ram - _start
  176. jr t0
  177. nop
  178. .dword _gp
  179. .dword _GLOBAL_OFFSET_TABLE_
  180. .dword uboot_end_data
  181. .dword uboot_end
  182. .dword num_got_entries
  183. in_ram:
  184. /*
  185. * Now we want to update GOT.
  186. *
  187. * GOT[0] is reserved. GOT[1] is also reserved for the dynamic object
  188. * generated by GNU ld. Skip these reserved entries from relocation.
  189. */
  190. ld t3, -8(t0) # t3 <-- num_got_entries
  191. ld t8, -32(t0) # t8 <-- _GLOBAL_OFFSET_TABLE_
  192. ld t9, -40(t0) # t9 <-- _gp
  193. dsub t8, t9 # compute offset
  194. dadd t8, t8, gp # t8 now holds relocated _G_O_T_
  195. daddi t8, t8, 16 # skipping first two entries
  196. dli t2, 2
  197. 1:
  198. ld t1, 0(t8)
  199. beqz t1, 2f
  200. dadd t1, s1
  201. sd t1, 0(t8)
  202. 2:
  203. daddi t2, 1
  204. blt t2, t3, 1b
  205. daddi t8, 8
  206. /* Clear BSS */
  207. ld t1, -24(t0) # t1 <-- uboot_end_data
  208. ld t2, -16(t0) # t2 <-- uboot_end
  209. dadd t1, s1 # adjust pointers
  210. dadd t2, s1
  211. dsub t1, 8
  212. 1:
  213. daddi t1, 8
  214. bltl t1, t2, 1b
  215. sd zero, 0(t1)
  216. move a0, s0 # a0 <-- gd
  217. dla t9, board_init_r
  218. jr t9
  219. move a1, s2
  220. .end relocate_code
  221. /* Exception handlers */
  222. romReserved:
  223. b romReserved