start.S 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. /* U-boot entry point */
  51. b reset
  52. nop
  53. .org 0x200
  54. /* TLB refill, 32 bit task */
  55. 1: b 1b
  56. nop
  57. .org 0x280
  58. /* XTLB refill, 64 bit task */
  59. 1: b 1b
  60. nop
  61. .org 0x300
  62. /* Cache error exception */
  63. 1: b 1b
  64. nop
  65. .org 0x380
  66. /* General exception */
  67. 1: b 1b
  68. nop
  69. .org 0x400
  70. /* Catch interrupt exceptions */
  71. 1: b 1b
  72. nop
  73. .org 0x480
  74. /* EJTAG debug exception */
  75. 1: b 1b
  76. nop
  77. .align 4
  78. reset:
  79. /* Clear watch registers */
  80. dmtc0 zero, CP0_WATCHLO
  81. dmtc0 zero, CP0_WATCHHI
  82. /* WP(Watch Pending), SW0/1 should be cleared */
  83. mtc0 zero, CP0_CAUSE
  84. setup_c0_status ST0_KX 0
  85. /* Init Timer */
  86. mtc0 zero, CP0_COUNT
  87. mtc0 zero, CP0_COMPARE
  88. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  89. /* CONFIG0 register */
  90. dli t0, CONF_CM_UNCACHED
  91. mtc0 t0, CP0_CONFIG
  92. #endif
  93. /*
  94. * Initialize $gp, force 8 byte alignment of bal instruction to forbid
  95. * the compiler to put nop's between bal and _gp. This is required to
  96. * keep _gp and ra aligned to 8 byte.
  97. */
  98. .align 3
  99. bal 1f
  100. nop
  101. .dword _gp
  102. 1:
  103. ld gp, 0(ra)
  104. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  105. /* Initialize any external memory */
  106. dla t9, lowlevel_init
  107. jalr t9
  108. nop
  109. /* Initialize caches... */
  110. dla t9, mips_cache_reset
  111. jalr t9
  112. nop
  113. /* ... and enable them */
  114. dli t0, CONFIG_SYS_MIPS_CACHE_MODE
  115. mtc0 t0, CP0_CONFIG
  116. #endif
  117. /* Set up temporary stack */
  118. dli sp, CONFIG_SYS_SDRAM_BASE + CONFIG_SYS_INIT_SP_OFFSET
  119. dla t9, board_init_f
  120. jr t9
  121. nop
  122. /*
  123. * void relocate_code (addr_sp, gd, addr_moni)
  124. *
  125. * This "function" does not return, instead it continues in RAM
  126. * after relocating the monitor code.
  127. *
  128. * a0 = addr_sp
  129. * a1 = gd
  130. * a2 = destination address
  131. */
  132. .globl relocate_code
  133. .ent relocate_code
  134. relocate_code:
  135. move sp, a0 # set new stack pointer
  136. move s0, a1 # save gd in s0
  137. move s2, a2 # save destination address in s2
  138. dli t0, CONFIG_SYS_MONITOR_BASE
  139. dsub s1, s2, t0 # s1 <-- relocation offset
  140. dla t3, in_ram
  141. ld t2, -24(t3) # t2 <-- __image_copy_end
  142. move t1, a2
  143. dadd gp, s1 # adjust gp
  144. /*
  145. * t0 = source address
  146. * t1 = target address
  147. * t2 = source end address
  148. */
  149. 1:
  150. lw t3, 0(t0)
  151. sw t3, 0(t1)
  152. daddu t0, 4
  153. blt t0, t2, 1b
  154. daddu t1, 4
  155. /* If caches were enabled, we would have to flush them here. */
  156. dsub a1, t1, s2 # a1 <-- size
  157. dla t9, flush_cache
  158. jalr t9
  159. move a0, s2 # a0 <-- destination address
  160. /* Jump to where we've relocated ourselves */
  161. daddi t0, s2, in_ram - _start
  162. jr t0
  163. nop
  164. .dword __image_copy_end
  165. .dword _GLOBAL_OFFSET_TABLE_
  166. .dword num_got_entries
  167. in_ram:
  168. /*
  169. * Now we want to update GOT.
  170. *
  171. * GOT[0] is reserved. GOT[1] is also reserved for the dynamic object
  172. * generated by GNU ld. Skip these reserved entries from relocation.
  173. */
  174. ld t3, -8(t0) # t3 <-- num_got_entries
  175. ld t8, -16(t0) # t8 <-- _GLOBAL_OFFSET_TABLE_
  176. dadd t8, s1 # t8 now holds relocated _G_O_T_
  177. daddi t8, t8, 16 # skipping first two entries
  178. dli t2, 2
  179. 1:
  180. ld t1, 0(t8)
  181. beqz t1, 2f
  182. dadd t1, s1
  183. sd t1, 0(t8)
  184. 2:
  185. daddi t2, 1
  186. blt t2, t3, 1b
  187. daddi t8, 8
  188. /*
  189. * Clear BSS
  190. *
  191. * GOT is now relocated. Thus __bss_start and __bss_end can be
  192. * accessed directly via $gp.
  193. */
  194. dla t1, __bss_start # t1 <-- __bss_start
  195. dla t2, __bss_end # t2 <-- __bss_end
  196. 1:
  197. sd zero, 0(t1)
  198. blt t1, t2, 1b
  199. daddi t1, 8
  200. move a0, s0 # a0 <-- gd
  201. dla t9, board_init_r
  202. jr t9
  203. move a1, s2
  204. .end relocate_code