start.S 4.9 KB

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