start.S 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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. #ifdef CONFIG_SYS_LITTLE_ENDIAN
  32. #define MIPS64_R_INFO(ssym, r_type3, r_type2, r_type) \
  33. (((r_type) << 24) | ((r_type2) << 16) | ((r_type3) << 8) | (ssym))
  34. #else
  35. #define MIPS64_R_INFO(ssym, r_type3, r_type2, r_type) \
  36. ((r_type) | ((r_type2) << 8) | ((r_type3) << 16) | (ssym) << 24)
  37. #endif
  38. /*
  39. * For the moment disable interrupts, mark the kernel mode and
  40. * set ST0_KX so that the CPU does not spit fire when using
  41. * 64-bit addresses.
  42. */
  43. .macro setup_c0_status set clr
  44. .set push
  45. mfc0 t0, CP0_STATUS
  46. or t0, ST0_CU0 | \set | 0x1f | \clr
  47. xor t0, 0x1f | \clr
  48. mtc0 t0, CP0_STATUS
  49. .set noreorder
  50. sll zero, 3 # ehb
  51. .set pop
  52. .endm
  53. .set noreorder
  54. .globl _start
  55. .text
  56. _start:
  57. /* U-boot entry point */
  58. b reset
  59. nop
  60. .org 0x200
  61. /* TLB refill, 32 bit task */
  62. 1: b 1b
  63. nop
  64. .org 0x280
  65. /* XTLB refill, 64 bit task */
  66. 1: b 1b
  67. nop
  68. .org 0x300
  69. /* Cache error exception */
  70. 1: b 1b
  71. nop
  72. .org 0x380
  73. /* General exception */
  74. 1: b 1b
  75. nop
  76. .org 0x400
  77. /* Catch interrupt exceptions */
  78. 1: b 1b
  79. nop
  80. .org 0x480
  81. /* EJTAG debug exception */
  82. 1: b 1b
  83. nop
  84. .align 4
  85. reset:
  86. /* Clear watch registers */
  87. dmtc0 zero, CP0_WATCHLO
  88. dmtc0 zero, CP0_WATCHHI
  89. /* WP(Watch Pending), SW0/1 should be cleared */
  90. mtc0 zero, CP0_CAUSE
  91. setup_c0_status ST0_KX 0
  92. /* Init Timer */
  93. mtc0 zero, CP0_COUNT
  94. mtc0 zero, CP0_COMPARE
  95. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  96. /* CONFIG0 register */
  97. dli t0, CONF_CM_UNCACHED
  98. mtc0 t0, CP0_CONFIG
  99. #endif
  100. /*
  101. * Initialize $gp, force 8 byte alignment of bal instruction to forbid
  102. * the compiler to put nop's between bal and _gp. This is required to
  103. * keep _gp and ra aligned to 8 byte.
  104. */
  105. .align 3
  106. bal 1f
  107. nop
  108. .dword _gp
  109. 1:
  110. ld gp, 0(ra)
  111. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  112. /* Initialize any external memory */
  113. dla t9, lowlevel_init
  114. jalr t9
  115. nop
  116. /* Initialize caches... */
  117. dla t9, mips_cache_reset
  118. jalr t9
  119. nop
  120. /* ... and enable them */
  121. dli t0, CONFIG_SYS_MIPS_CACHE_MODE
  122. mtc0 t0, CP0_CONFIG
  123. #endif
  124. /* Set up temporary stack */
  125. dli sp, CONFIG_SYS_SDRAM_BASE + CONFIG_SYS_INIT_SP_OFFSET
  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. move s0, a1 # save gd in s0
  144. move s2, a2 # save destination address in s2
  145. dli t0, CONFIG_SYS_MONITOR_BASE
  146. dsub s1, s2, t0 # s1 <-- relocation offset
  147. dla t3, in_ram
  148. ld t2, -24(t3) # t2 <-- __image_copy_end
  149. move t1, a2
  150. dadd gp, s1 # adjust gp
  151. /*
  152. * t0 = source address
  153. * t1 = target address
  154. * t2 = source end address
  155. */
  156. 1:
  157. lw t3, 0(t0)
  158. sw t3, 0(t1)
  159. daddu t0, 4
  160. blt t0, t2, 1b
  161. daddu t1, 4
  162. /* If caches were enabled, we would have to flush them here. */
  163. dsub a1, t1, s2 # a1 <-- size
  164. dla t9, flush_cache
  165. jalr t9
  166. move a0, s2 # a0 <-- destination address
  167. /* Jump to where we've relocated ourselves */
  168. daddi t0, s2, in_ram - _start
  169. jr t0
  170. nop
  171. .dword __rel_dyn_end
  172. .dword __rel_dyn_start
  173. .dword __image_copy_end
  174. .dword _GLOBAL_OFFSET_TABLE_
  175. .dword num_got_entries
  176. in_ram:
  177. /*
  178. * Now we want to update GOT.
  179. *
  180. * GOT[0] is reserved. GOT[1] is also reserved for the dynamic object
  181. * generated by GNU ld. Skip these reserved entries from relocation.
  182. */
  183. ld t3, -8(t0) # t3 <-- num_got_entries
  184. ld t8, -16(t0) # t8 <-- _GLOBAL_OFFSET_TABLE_
  185. dadd t8, s1 # t8 now holds relocated _G_O_T_
  186. daddi t8, t8, 16 # skipping first two entries
  187. dli t2, 2
  188. 1:
  189. ld t1, 0(t8)
  190. beqz t1, 2f
  191. dadd t1, s1
  192. sd t1, 0(t8)
  193. 2:
  194. daddi t2, 1
  195. blt t2, t3, 1b
  196. daddi t8, 8
  197. /* Update dynamic relocations */
  198. ld t1, -32(t0) # t1 <-- __rel_dyn_start
  199. ld t2, -40(t0) # t2 <-- __rel_dyn_end
  200. b 2f # skip first reserved entry
  201. daddi t1, 16
  202. 1:
  203. lw t8, -4(t1) # t8 <-- relocation info
  204. dli t3, MIPS64_R_INFO(0x00, 0x00, 0x12, 0x03)
  205. bne t8, t3, 2f # skip non R_MIPS_REL32 entries
  206. nop
  207. ld t3, -16(t1) # t3 <-- location to fix up in FLASH
  208. ld t8, 0(t3) # t8 <-- original pointer
  209. dadd t8, s1 # t8 <-- adjusted pointer
  210. dadd t3, s1 # t3 <-- location to fix up in RAM
  211. sd t8, 0(t3)
  212. 2:
  213. blt t1, t2, 1b
  214. daddi t1, 16 # each rel.dyn entry is 16 bytes
  215. /*
  216. * Clear BSS
  217. *
  218. * GOT is now relocated. Thus __bss_start and __bss_end can be
  219. * accessed directly via $gp.
  220. */
  221. dla t1, __bss_start # t1 <-- __bss_start
  222. dla t2, __bss_end # t2 <-- __bss_end
  223. 1:
  224. sd zero, 0(t1)
  225. blt t1, t2, 1b
  226. daddi t1, 8
  227. move a0, s0 # a0 <-- gd
  228. dla t9, board_init_r
  229. jr t9
  230. move a1, s2
  231. .end relocate_code