start.S 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * Startup Code for MIPS32 XBURST CPU-core
  3. *
  4. * Copyright (c) 2010 Xiangfu Liu <xiangfu@sharism.cc>
  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 <config.h>
  25. #include <version.h>
  26. #include <asm/regdef.h>
  27. #include <asm/mipsregs.h>
  28. #include <asm/addrspace.h>
  29. #include <asm/cacheops.h>
  30. .set noreorder
  31. .globl _start
  32. .text
  33. _start:
  34. /* Initialize $gp */
  35. bal 1f
  36. nop
  37. .word _gp
  38. 1:
  39. lw gp, 0(ra)
  40. /* Set up temporary stack */
  41. li sp, CONFIG_SYS_SDRAM_BASE + CONFIG_SYS_INIT_SP_OFFSET
  42. la t9, board_init_f
  43. jr t9
  44. nop
  45. /*
  46. * void relocate_code (addr_sp, gd, addr_moni)
  47. *
  48. * This "function" does not return, instead it continues in RAM
  49. * after relocating the monitor code.
  50. *
  51. * a0 = addr_sp
  52. * a1 = gd
  53. * a2 = destination address
  54. */
  55. .globl relocate_code
  56. .ent relocate_code
  57. relocate_code:
  58. move sp, a0 # set new stack pointer
  59. li t0, CONFIG_SYS_MONITOR_BASE
  60. la t3, in_ram
  61. lw t2, -12(t3) # t2 <-- uboot_end_data
  62. move t1, a2
  63. /*
  64. * Fix $gp:
  65. *
  66. * New $gp = (Old $gp - CONFIG_SYS_MONITOR_BASE) + Destination Address
  67. */
  68. move t6, gp
  69. sub gp, CONFIG_SYS_MONITOR_BASE
  70. add gp, a2 # gp now adjusted
  71. sub t6, gp, t6 # t6 <-- relocation offset
  72. /*
  73. * t0 = source address
  74. * t1 = target address
  75. * t2 = source end address
  76. */
  77. 1:
  78. lw t3, 0(t0)
  79. sw t3, 0(t1)
  80. addu t0, 4
  81. ble t0, t2, 1b
  82. addu t1, 4
  83. /* If caches were enabled, we would have to flush them here. */
  84. /* flush d-cache */
  85. li t0, KSEG0
  86. addi t1, t0, CONFIG_SYS_DCACHE_SIZE
  87. 2:
  88. cache Index_Writeback_Inv_D, 0(t0)
  89. bne t0, t1, 2b
  90. addi t0, CONFIG_SYS_CACHELINE_SIZE
  91. sync
  92. /* flush i-cache */
  93. li t0, KSEG0
  94. addi t1, t0, CONFIG_SYS_ICACHE_SIZE
  95. 3:
  96. cache Index_Invalidate_I, 0(t0)
  97. bne t0, t1, 3b
  98. addi t0, CONFIG_SYS_CACHELINE_SIZE
  99. /* Invalidate BTB */
  100. mfc0 t0, CP0_CONFIG, 7
  101. nop
  102. ori t0, 2
  103. mtc0 t0, CP0_CONFIG, 7
  104. nop
  105. /* Jump to where we've relocated ourselves */
  106. addi t0, a2, in_ram - _start
  107. jr t0
  108. nop
  109. .word _gp
  110. .word _GLOBAL_OFFSET_TABLE_
  111. .word uboot_end_data
  112. .word uboot_end
  113. .word num_got_entries
  114. in_ram:
  115. /*
  116. * Now we want to update GOT.
  117. *
  118. * GOT[0] is reserved. GOT[1] is also reserved for the dynamic object
  119. * generated by GNU ld. Skip these reserved entries from relocation.
  120. */
  121. lw t3, -4(t0) # t3 <-- num_got_entries
  122. lw t4, -16(t0) # t4 <-- _GLOBAL_OFFSET_TABLE_
  123. lw t5, -20(t0) # t5 <-- _gp
  124. sub t4, t5 # compute offset
  125. add t4, t4, gp # t4 now holds relocated _G_O_T_
  126. addi t4, t4, 8 # skipping first two entries
  127. li t2, 2
  128. 1:
  129. lw t1, 0(t4)
  130. beqz t1, 2f
  131. add t1, t6
  132. sw t1, 0(t4)
  133. 2:
  134. addi t2, 1
  135. blt t2, t3, 1b
  136. addi t4, 4
  137. /* Clear BSS */
  138. lw t1, -12(t0) # t1 <-- uboot_end_data
  139. lw t2, -8(t0) # t2 <-- uboot_end
  140. add t1, t6 # adjust pointers
  141. add t2, t6
  142. sub t1, 4
  143. 1: addi t1, 4
  144. bltl t1, t2, 1b
  145. sw zero, 0(t1)
  146. move a0, a1 # a0 <-- gd
  147. la t9, board_init_r
  148. jr t9
  149. move a1, a2
  150. .end relocate_code