start.S 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. /*
  2. * Startup Code for MIPS32 CPU-core
  3. *
  4. * Copyright (c) 2003 Wolfgang Denk <wd@denx.de>
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. #include <asm-offsets.h>
  9. #include <config.h>
  10. #include <asm/regdef.h>
  11. #include <asm/mipsregs.h>
  12. #ifndef CONFIG_SYS_MIPS_CACHE_MODE
  13. #define CONFIG_SYS_MIPS_CACHE_MODE CONF_CM_CACHABLE_NONCOHERENT
  14. #endif
  15. #ifndef CONFIG_SYS_INIT_SP_ADDR
  16. #define CONFIG_SYS_INIT_SP_ADDR (CONFIG_SYS_SDRAM_BASE + \
  17. CONFIG_SYS_INIT_SP_OFFSET)
  18. #endif
  19. /*
  20. * For the moment disable interrupts, mark the kernel mode and
  21. * set ST0_KX so that the CPU does not spit fire when using
  22. * 64-bit addresses.
  23. */
  24. .macro setup_c0_status set clr
  25. .set push
  26. mfc0 t0, CP0_STATUS
  27. or t0, ST0_CU0 | \set | 0x1f | \clr
  28. xor t0, 0x1f | \clr
  29. mtc0 t0, CP0_STATUS
  30. .set noreorder
  31. sll zero, 3 # ehb
  32. .set pop
  33. .endm
  34. .set noreorder
  35. .globl _start
  36. .text
  37. _start:
  38. /* U-boot entry point */
  39. b reset
  40. nop
  41. .org 0x10
  42. #if defined(CONFIG_SYS_XWAY_EBU_BOOTCFG)
  43. /*
  44. * Almost all Lantiq XWAY SoC devices have an external bus unit (EBU) to
  45. * access external NOR flashes. If the board boots from NOR flash the
  46. * internal BootROM does a blind read at address 0xB0000010 to read the
  47. * initial configuration for that EBU in order to access the flash
  48. * device with correct parameters. This config option is board-specific.
  49. */
  50. .word CONFIG_SYS_XWAY_EBU_BOOTCFG
  51. .word 0x0
  52. #elif defined(CONFIG_MALTA)
  53. /*
  54. * Linux expects the Board ID here.
  55. */
  56. .word 0x00000420 # 0x420 (Malta Board with CoreLV)
  57. .word 0x00000000
  58. #endif
  59. .org 0x200
  60. /* TLB refill, 32 bit task */
  61. 1: b 1b
  62. nop
  63. .org 0x280
  64. /* XTLB refill, 64 bit task */
  65. 1: b 1b
  66. nop
  67. .org 0x300
  68. /* Cache error exception */
  69. 1: b 1b
  70. nop
  71. .org 0x380
  72. /* General exception */
  73. 1: b 1b
  74. nop
  75. .org 0x400
  76. /* Catch interrupt exceptions */
  77. 1: b 1b
  78. nop
  79. .org 0x480
  80. /* EJTAG debug exception */
  81. 1: b 1b
  82. nop
  83. .align 4
  84. reset:
  85. /* Clear watch registers */
  86. mtc0 zero, CP0_WATCHLO
  87. mtc0 zero, CP0_WATCHHI
  88. /* WP(Watch Pending), SW0/1 should be cleared */
  89. mtc0 zero, CP0_CAUSE
  90. setup_c0_status 0 0
  91. /* Init Timer */
  92. mtc0 zero, CP0_COUNT
  93. mtc0 zero, CP0_COMPARE
  94. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  95. /* CONFIG0 register */
  96. li t0, CONF_CM_UNCACHED
  97. mtc0 t0, CP0_CONFIG
  98. #endif
  99. /* Initialize $gp */
  100. bal 1f
  101. nop
  102. .word _gp
  103. 1:
  104. lw gp, 0(ra)
  105. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  106. /* Initialize any external memory */
  107. la t9, lowlevel_init
  108. jalr t9
  109. nop
  110. /* Initialize caches... */
  111. la t9, mips_cache_reset
  112. jalr t9
  113. nop
  114. /* ... and enable them */
  115. li t0, CONFIG_SYS_MIPS_CACHE_MODE
  116. mtc0 t0, CP0_CONFIG
  117. #endif
  118. /* Set up temporary stack */
  119. li sp, CONFIG_SYS_INIT_SP_ADDR
  120. move fp, sp
  121. la t9, board_init_f
  122. jr t9
  123. move ra, zero
  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. move fp, sp
  139. move s0, a1 # save gd in s0
  140. move s2, a2 # save destination address in s2
  141. li t0, CONFIG_SYS_MONITOR_BASE
  142. sub s1, s2, t0 # s1 <-- relocation offset
  143. la t3, in_ram
  144. lw t2, -12(t3) # t2 <-- __image_copy_end
  145. move t1, a2
  146. add gp, s1 # adjust gp
  147. /*
  148. * t0 = source address
  149. * t1 = target address
  150. * t2 = source end address
  151. */
  152. 1:
  153. lw t3, 0(t0)
  154. sw t3, 0(t1)
  155. addu t0, 4
  156. blt t0, t2, 1b
  157. addu t1, 4
  158. /* If caches were enabled, we would have to flush them here. */
  159. sub a1, t1, s2 # a1 <-- size
  160. la t9, flush_cache
  161. jalr t9
  162. move a0, s2 # a0 <-- destination address
  163. /* Jump to where we've relocated ourselves */
  164. addi t0, s2, in_ram - _start
  165. jr t0
  166. nop
  167. .word __rel_dyn_end
  168. .word __rel_dyn_start
  169. .word __image_copy_end
  170. .word _GLOBAL_OFFSET_TABLE_
  171. .word num_got_entries
  172. in_ram:
  173. /*
  174. * Now we want to update GOT.
  175. *
  176. * GOT[0] is reserved. GOT[1] is also reserved for the dynamic object
  177. * generated by GNU ld. Skip these reserved entries from relocation.
  178. */
  179. lw t3, -4(t0) # t3 <-- num_got_entries
  180. lw t8, -8(t0) # t8 <-- _GLOBAL_OFFSET_TABLE_
  181. add t8, s1 # t8 now holds relocated _G_O_T_
  182. addi t8, t8, 8 # skipping first two entries
  183. li t2, 2
  184. 1:
  185. lw t1, 0(t8)
  186. beqz t1, 2f
  187. add t1, s1
  188. sw t1, 0(t8)
  189. 2:
  190. addi t2, 1
  191. blt t2, t3, 1b
  192. addi t8, 4
  193. /* Update dynamic relocations */
  194. lw t1, -16(t0) # t1 <-- __rel_dyn_start
  195. lw t2, -20(t0) # t2 <-- __rel_dyn_end
  196. b 2f # skip first reserved entry
  197. addi t1, 8
  198. 1:
  199. lw t8, -4(t1) # t8 <-- relocation info
  200. li t3, 3
  201. bne t8, t3, 2f # skip non R_MIPS_REL32 entries
  202. nop
  203. lw t3, -8(t1) # t3 <-- location to fix up in FLASH
  204. lw t8, 0(t3) # t8 <-- original pointer
  205. add t8, s1 # t8 <-- adjusted pointer
  206. add t3, s1 # t3 <-- location to fix up in RAM
  207. sw t8, 0(t3)
  208. 2:
  209. blt t1, t2, 1b
  210. addi t1, 8 # each rel.dyn entry is 8 bytes
  211. /*
  212. * Clear BSS
  213. *
  214. * GOT is now relocated. Thus __bss_start and __bss_end can be
  215. * accessed directly via $gp.
  216. */
  217. la t1, __bss_start # t1 <-- __bss_start
  218. la t2, __bss_end # t2 <-- __bss_end
  219. 1:
  220. sw zero, 0(t1)
  221. blt t1, t2, 1b
  222. addi t1, 4
  223. move a0, s0 # a0 <-- gd
  224. move a1, s2
  225. la t9, board_init_r
  226. jr t9
  227. move ra, zero
  228. .end relocate_code