start.S 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. /*
  2. * Startup Code for MIPS32 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 later 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 PARTICULAR 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 Place, 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 0x10
  54. #ifdef CONFIG_SYS_XWAY_EBU_BOOTCFG
  55. /*
  56. * Almost all Lantiq XWAY SoC devices have an external bus unit (EBU) to
  57. * access external NOR flashes. If the board boots from NOR flash the
  58. * internal BootROM does a blind read at address 0xB0000010 to read the
  59. * initial configuration for that EBU in order to access the flash
  60. * device with correct parameters. This config option is board-specific.
  61. */
  62. .word CONFIG_SYS_XWAY_EBU_BOOTCFG
  63. .word 0x0
  64. #endif
  65. .org 0x200
  66. /* TLB refill, 32 bit task */
  67. 1: b 1b
  68. nop
  69. .org 0x280
  70. /* XTLB refill, 64 bit task */
  71. 1: b 1b
  72. nop
  73. .org 0x300
  74. /* Cache error exception */
  75. 1: b 1b
  76. nop
  77. .org 0x380
  78. /* General exception */
  79. 1: b 1b
  80. nop
  81. .org 0x400
  82. /* Catch interrupt exceptions */
  83. 1: b 1b
  84. nop
  85. .org 0x480
  86. /* EJTAG debug exception */
  87. 1: b 1b
  88. nop
  89. .align 4
  90. reset:
  91. /* Clear watch registers */
  92. mtc0 zero, CP0_WATCHLO
  93. mtc0 zero, CP0_WATCHHI
  94. /* WP(Watch Pending), SW0/1 should be cleared */
  95. mtc0 zero, CP0_CAUSE
  96. setup_c0_status 0 0
  97. /* Init Timer */
  98. mtc0 zero, CP0_COUNT
  99. mtc0 zero, CP0_COMPARE
  100. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  101. /* CONFIG0 register */
  102. li t0, CONF_CM_UNCACHED
  103. mtc0 t0, CP0_CONFIG
  104. #endif
  105. /* Initialize $gp */
  106. bal 1f
  107. nop
  108. .word _gp
  109. 1:
  110. lw gp, 0(ra)
  111. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  112. /* Initialize any external memory */
  113. la t9, lowlevel_init
  114. jalr t9
  115. nop
  116. /* Initialize caches... */
  117. la t9, mips_cache_reset
  118. jalr t9
  119. nop
  120. /* ... and enable them */
  121. li t0, CONFIG_SYS_MIPS_CACHE_MODE
  122. mtc0 t0, CP0_CONFIG
  123. #endif
  124. /* Set up temporary stack */
  125. li sp, CONFIG_SYS_SDRAM_BASE + CONFIG_SYS_INIT_SP_OFFSET
  126. la 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. li t0, CONFIG_SYS_MONITOR_BASE
  146. sub s1, s2, t0 # s1 <-- relocation offset
  147. la t3, in_ram
  148. lw t2, -12(t3) # t2 <-- __image_copy_end
  149. move t1, a2
  150. add 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. addu t0, 4
  160. blt t0, t2, 1b
  161. addu t1, 4
  162. /* If caches were enabled, we would have to flush them here. */
  163. sub a1, t1, s2 # a1 <-- size
  164. la t9, flush_cache
  165. jalr t9
  166. move a0, s2 # a0 <-- destination address
  167. /* Jump to where we've relocated ourselves */
  168. addi t0, s2, in_ram - _start
  169. jr t0
  170. nop
  171. .word __rel_dyn_end
  172. .word __rel_dyn_start
  173. .word __image_copy_end
  174. .word _GLOBAL_OFFSET_TABLE_
  175. .word 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. lw t3, -4(t0) # t3 <-- num_got_entries
  184. lw t4, -8(t0) # t4 <-- _GLOBAL_OFFSET_TABLE_
  185. add t4, s1 # t4 now holds relocated _G_O_T_
  186. addi t4, t4, 8 # skipping first two entries
  187. li t2, 2
  188. 1:
  189. lw t1, 0(t4)
  190. beqz t1, 2f
  191. add t1, s1
  192. sw t1, 0(t4)
  193. 2:
  194. addi t2, 1
  195. blt t2, t3, 1b
  196. addi t4, 4
  197. /* Update dynamic relocations */
  198. lw t1, -16(t0) # t1 <-- __rel_dyn_start
  199. lw t2, -20(t0) # t2 <-- __rel_dyn_end
  200. b 2f # skip first reserved entry
  201. addi t1, 8
  202. 1:
  203. lw t3, -4(t1) # t3 <-- relocation info
  204. sub t3, 3
  205. bnez t3, 2f # skip non R_MIPS_REL32 entries
  206. nop
  207. lw t3, -8(t1) # t3 <-- location to fix up in FLASH
  208. lw t4, 0(t3) # t4 <-- original pointer
  209. add t4, s1 # t4 <-- adjusted pointer
  210. add t3, s1 # t3 <-- location to fix up in RAM
  211. sw t4, 0(t3)
  212. 2:
  213. blt t1, t2, 1b
  214. addi t1, 8 # each rel.dyn entry is 8 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. la t1, __bss_start # t1 <-- __bss_start
  222. la t2, __bss_end # t2 <-- __bss_end
  223. 1:
  224. sw zero, 0(t1)
  225. blt t1, t2, 1b
  226. addi t1, 4
  227. move a0, s0 # a0 <-- gd
  228. la t9, board_init_r
  229. jr t9
  230. move a1, s2
  231. .end relocate_code