start.S 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. sub t6, a2, t0 # t6 <-- relocation offset
  61. la t3, in_ram
  62. lw t2, -12(t3) # t2 <-- uboot_end_data
  63. move t1, a2
  64. add gp, t6 # adjust gp
  65. /*
  66. * t0 = source address
  67. * t1 = target address
  68. * t2 = source end address
  69. */
  70. 1:
  71. lw t3, 0(t0)
  72. sw t3, 0(t1)
  73. addu t0, 4
  74. blt t0, t2, 1b
  75. addu t1, 4
  76. /* If caches were enabled, we would have to flush them here. */
  77. /* flush d-cache */
  78. li t0, KSEG0
  79. addi t1, t0, CONFIG_SYS_DCACHE_SIZE
  80. 2:
  81. cache INDEX_WRITEBACK_INV_D, 0(t0)
  82. bne t0, t1, 2b
  83. addi t0, CONFIG_SYS_CACHELINE_SIZE
  84. sync
  85. /* flush i-cache */
  86. li t0, KSEG0
  87. addi t1, t0, CONFIG_SYS_ICACHE_SIZE
  88. 3:
  89. cache INDEX_INVALIDATE_I, 0(t0)
  90. bne t0, t1, 3b
  91. addi t0, CONFIG_SYS_CACHELINE_SIZE
  92. /* Invalidate BTB */
  93. mfc0 t0, CP0_CONFIG, 7
  94. nop
  95. ori t0, 2
  96. mtc0 t0, CP0_CONFIG, 7
  97. nop
  98. /* Jump to where we've relocated ourselves */
  99. addi t0, a2, in_ram - _start
  100. jr t0
  101. nop
  102. .word _GLOBAL_OFFSET_TABLE_
  103. .word uboot_end_data
  104. .word uboot_end
  105. .word num_got_entries
  106. in_ram:
  107. /*
  108. * Now we want to update GOT.
  109. *
  110. * GOT[0] is reserved. GOT[1] is also reserved for the dynamic object
  111. * generated by GNU ld. Skip these reserved entries from relocation.
  112. */
  113. lw t3, -4(t0) # t3 <-- num_got_entries
  114. lw t4, -16(t0) # t4 <-- _GLOBAL_OFFSET_TABLE_
  115. add t4, t6 # t4 now holds relocated _G_O_T_
  116. addi t4, t4, 8 # skipping first two entries
  117. li t2, 2
  118. 1:
  119. lw t1, 0(t4)
  120. beqz t1, 2f
  121. add t1, t6
  122. sw t1, 0(t4)
  123. 2:
  124. addi t2, 1
  125. blt t2, t3, 1b
  126. addi t4, 4
  127. /*
  128. * Clear BSS
  129. *
  130. * GOT is now relocated. Thus __bss_start and __bss_end can be
  131. * accessed directly via $gp.
  132. */
  133. la t1, __bss_start # t1 <-- __bss_start
  134. la t2, __bss_end # t2 <-- __bss_end
  135. 1:
  136. sw zero, 0(t1)
  137. blt t1, t2, 1b
  138. addi t1, 4
  139. move a0, a1 # a0 <-- gd
  140. la t9, board_init_r
  141. jr t9
  142. move a1, a2
  143. .end relocate_code