Sony PlayStation2 Study
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

223 lines
4.1 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Startup Code for MIPS r5900
  3. *
  4. * Copyright (c) 2003 Wolfgang Denk <wd@denx.de>
  5. * Copyright (c) 2014 Juergen Urban
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. */
  9. #include <asm-offsets.h>
  10. #include <config.h>
  11. #include <asm/regdef.h>
  12. #include <asm/mipsregs.h>
  13. #ifndef CONFIG_SYS_MIPS_CACHE_MODE
  14. #define CONFIG_SYS_MIPS_CACHE_MODE CONF_CM_CACHABLE_NONCOHERENT
  15. #endif
  16. /*
  17. * For the moment disable interrupts, mark the kernel mode and
  18. * set ST0_KX so that the CPU does not spit fire when using
  19. * 64-bit addresses.
  20. */
  21. .macro setup_c0_status set clr
  22. .set push
  23. sync.p
  24. mfc0 t0, CP0_STATUS
  25. or t0, ST0_CU0 | \set | 0x1f | \clr
  26. xor t0, 0x1f | \clr
  27. mtc0 t0, CP0_STATUS
  28. sync.p
  29. .set noreorder
  30. sll zero, 3 # ehb
  31. .set pop
  32. .endm
  33. .set noreorder
  34. .globl _start
  35. .text
  36. _start:
  37. /* U-boot entry point */
  38. /* Clear watch registers */
  39. mtc0 zero, CP0_WATCHLO
  40. sync.p
  41. mtc0 zero, CP0_WATCHHI
  42. sync.p
  43. /* WP(Watch Pending), SW0/1 should be cleared */
  44. mtc0 zero, CP0_CAUSE
  45. sync.p
  46. setup_c0_status 0 0
  47. /* Init Timer */
  48. mtc0 zero, CP0_COUNT
  49. sync.p
  50. mtc0 zero, CP0_COMPARE
  51. sync.p
  52. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  53. /* CONFIG0 register */
  54. li t0, CONF_CM_UNCACHED
  55. mtc0 t0, CP0_CONFIG
  56. sync.p
  57. #endif
  58. /* Initialize $gp */
  59. bal 1f
  60. nop
  61. .word _gp
  62. 1:
  63. lw gp, 0(ra)
  64. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  65. /* Initialize any external memory */
  66. la t9, lowlevel_init
  67. jalr t9
  68. nop
  69. /* Initialize caches... */
  70. la t9, mips_cache_reset
  71. jalr t9
  72. nop
  73. /* ... and enable them */
  74. li t0, CONFIG_SYS_MIPS_CACHE_MODE
  75. mtc0 t0, CP0_CONFIG
  76. sync.p
  77. #endif
  78. /* Set up temporary stack */
  79. li sp, CONFIG_SYS_SDRAM_BASE + CONFIG_SYS_INIT_SP_OFFSET
  80. la t9, board_init_f
  81. jr t9
  82. nop
  83. /*
  84. * void relocate_code (addr_sp, gd, addr_moni)
  85. *
  86. * This "function" does not return, instead it continues in RAM
  87. * after relocating the monitor code.
  88. *
  89. * a0 = addr_sp
  90. * a1 = gd
  91. * a2 = destination address
  92. */
  93. .globl relocate_code
  94. .ent relocate_code
  95. relocate_code:
  96. move sp, a0 # set new stack pointer
  97. move s0, a1 # save gd in s0
  98. move s2, a2 # save destination address in s2
  99. li t0, CONFIG_SYS_MONITOR_BASE
  100. sub s1, s2, t0 # s1 <-- relocation offset
  101. la t3, in_ram
  102. lw t2, -12(t3) # t2 <-- __image_copy_end
  103. move t1, a2
  104. add gp, s1 # adjust gp
  105. /*
  106. * t0 = source address
  107. * t1 = target address
  108. * t2 = source end address
  109. */
  110. 1:
  111. lw t3, 0(t0)
  112. sw t3, 0(t1)
  113. addu t0, 4
  114. blt t0, t2, 1b
  115. addu t1, 4
  116. /* If caches were enabled, we would have to flush them here. */
  117. sub a1, t1, s2 # a1 <-- size
  118. la t9, flush_cache
  119. jalr t9
  120. move a0, s2 # a0 <-- destination address
  121. /* Jump to where we've relocated ourselves */
  122. addi t0, s2, in_ram - _start
  123. jr t0
  124. nop
  125. .word __rel_dyn_end
  126. .word __rel_dyn_start
  127. .word __image_copy_end
  128. .word _GLOBAL_OFFSET_TABLE_
  129. .word num_got_entries
  130. in_ram:
  131. /*
  132. * Now we want to update GOT.
  133. *
  134. * GOT[0] is reserved. GOT[1] is also reserved for the dynamic object
  135. * generated by GNU ld. Skip these reserved entries from relocation.
  136. */
  137. lw t3, -4(t0) # t3 <-- num_got_entries
  138. lw t8, -8(t0) # t8 <-- _GLOBAL_OFFSET_TABLE_
  139. add t8, s1 # t8 now holds relocated _G_O_T_
  140. addi t8, t8, 8 # skipping first two entries
  141. li t2, 2
  142. 1:
  143. lw t1, 0(t8)
  144. beqz t1, 2f
  145. add t1, s1
  146. sw t1, 0(t8)
  147. 2:
  148. addi t2, 1
  149. blt t2, t3, 1b
  150. addi t8, 4
  151. /* Update dynamic relocations */
  152. lw t1, -16(t0) # t1 <-- __rel_dyn_start
  153. lw t2, -20(t0) # t2 <-- __rel_dyn_end
  154. b 2f # skip first reserved entry
  155. addi t1, 8
  156. 1:
  157. lw t8, -4(t1) # t8 <-- relocation info
  158. li t3, 3
  159. bne t8, t3, 2f # skip non R_MIPS_REL32 entries
  160. nop
  161. lw t3, -8(t1) # t3 <-- location to fix up in FLASH
  162. lw t8, 0(t3) # t8 <-- original pointer
  163. add t8, s1 # t8 <-- adjusted pointer
  164. add t3, s1 # t3 <-- location to fix up in RAM
  165. sw t8, 0(t3)
  166. 2:
  167. blt t1, t2, 1b
  168. addi t1, 8 # each rel.dyn entry is 8 bytes
  169. /*
  170. * Clear BSS
  171. *
  172. * GOT is now relocated. Thus __bss_start and __bss_end can be
  173. * accessed directly via $gp.
  174. */
  175. la t1, __bss_start # t1 <-- __bss_start
  176. la t2, __bss_end # t2 <-- __bss_end
  177. 1:
  178. sw zero, 0(t1)
  179. blt t1, t2, 1b
  180. addi t1, 4
  181. move a0, s0 # a0 <-- gd
  182. la t9, board_init_r
  183. jr t9
  184. move a1, s2
  185. .end relocate_code