start.S 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * (C) Copyright 2004, Psyent Corporation <www.psyent.com>
  3. * Scott McNutt <smcnutt@psyent.com>
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <config.h>
  24. #include <version.h>
  25. /*************************************************************************
  26. * RESTART
  27. ************************************************************************/
  28. .text
  29. .global _start
  30. _start:
  31. /* ICACHE INIT -- only the icache line at the reset address
  32. * is invalidated at reset. So the init must stay within
  33. * the cache line size (8 words). If GERMS is used, we'll
  34. * just be invalidating the cache a second time. If cache
  35. * is not implemented initi behaves as nop.
  36. */
  37. movhi r4, %hi(CFG_ICACHELINE_SIZE)
  38. ori r4, r4, %lo(CFG_ICACHELINE_SIZE)
  39. movhi r5, %hi(CFG_ICACHE_SIZE)
  40. ori r5, r5, %lo(CFG_ICACHE_SIZE)
  41. mov r6, r0
  42. 0: initi r6
  43. add r6, r6, r4
  44. bltu r6, r5, 0b
  45. /* INTERRUPTS -- for now, all interrupts masked and globally
  46. * disabled.
  47. */
  48. wrctl status, r0 /* Disable interrupts */
  49. wrctl ienable, r0 /* All disabled */
  50. /* DCACHE INIT -- if dcache not implemented, initd behaves as
  51. * nop.
  52. */
  53. movhi r4, %hi(CFG_DCACHELINE_SIZE)
  54. ori r4, r4, %lo(CFG_DCACHELINE_SIZE)
  55. movhi r5, %hi(CFG_DCACHE_SIZE)
  56. ori r5, r5, %lo(CFG_DCACHE_SIZE)
  57. mov r6, r0
  58. 1: initd 0(r6)
  59. add r6, r6, r4
  60. bltu r6, r5, 1b
  61. /* RELOCATE CODE, DATA & COMMAND TABLE -- the following code
  62. * assumes code, data and the command table are all
  63. * contiguous. This lets us relocate everything as a single
  64. * block. Make sure the linker script matches this ;-)
  65. */
  66. nextpc r4
  67. _cur: movhi r5, %hi(_cur - _start)
  68. ori r5, r5, %lo(_cur - _start)
  69. sub r4, r4, r5 /* r4 <- cur _start */
  70. mov r8, r4
  71. movhi r5, %hi(_start)
  72. ori r5, r5, %lo(_start) /* r5 <- linked _start */
  73. beq r4, r5, 3f
  74. movhi r6, %hi(_edata)
  75. ori r6, r6, %lo(_edata)
  76. 2: ldwio r7, 0(r4)
  77. addi r4, r4, 4
  78. stwio r7, 0(r5)
  79. addi r5, r5, 4
  80. bne r5, r6, 2b
  81. 3:
  82. /* ZERO BSS/SBSS -- bss and sbss are assumed to be adjacent
  83. * and between __bss_start and _end.
  84. */
  85. movhi r5, %hi(__bss_start)
  86. ori r5, r5, %lo(__bss_start)
  87. movhi r6, %hi(_end)
  88. ori r6, r6, %lo(_end)
  89. beq r5, r6, 5f
  90. 4: stwio r0, 0(r5)
  91. addi r5, r5, 4
  92. bne r5, r6, 4b
  93. 5:
  94. /* GLOBAL POINTER -- the global pointer is used to reference
  95. * "small data" (see -G switch). The linker script must
  96. * provide the gp address.
  97. */
  98. movhi gp, %hi(_gp)
  99. ori gp, gp, %lo(_gp)
  100. /* JUMP TO RELOC ADDR */
  101. movhi r4, %hi(_reloc)
  102. ori r4, r4, %lo(_reloc)
  103. jmp r4
  104. _reloc:
  105. /* COPY EXCEPTION TRAMPOLINE -- copy the tramp to the
  106. * exception address.
  107. */
  108. #if !defined(CONFIG_ROM_STUBS)
  109. movhi r4, %hi(_except_start)
  110. ori r4, r4, %lo(_except_start)
  111. movhi r5, %hi(_except_end)
  112. ori r5, r5, %lo(_except_end)
  113. movhi r6, %hi(CFG_EXCEPTION_ADDR)
  114. ori r6, r6, %lo(CFG_EXCEPTION_ADDR)
  115. 6: ldwio r7, 0(r4)
  116. stwio r7, 0(r6)
  117. addi r4, r4, 4
  118. addi r6, r6, 4
  119. bne r4, r5, 6b
  120. #endif
  121. /* STACK INIT -- zero top two words for call back chain.
  122. */
  123. movhi sp, %hi(CFG_INIT_SP)
  124. ori sp, sp, %lo(CFG_INIT_SP)
  125. addi sp, sp, -8
  126. stw r0, 0(sp)
  127. stw r0, 4(sp)
  128. mov fp, sp
  129. /*
  130. * Call board_init -- never returns
  131. */
  132. movhi r4, %hi(board_init@h)
  133. ori r4, r4, %lo(board_init@h)
  134. callr r4
  135. /* NEVER RETURNS -- but branch to the _start just
  136. * in case ;-)
  137. */
  138. br _start
  139. /* EXCEPTION TRAMPOLINE -- the following gets copied
  140. * to the exception address.
  141. */
  142. _except_start:
  143. movhi et, %hi(_exception)
  144. ori et, et, %lo(_exception)
  145. jmp et
  146. _except_end:
  147. /*
  148. * dly_clks -- Nios2 (like Nios1) doesn't have a timebase in
  149. * the core. For simple delay loops, we do our best by counting
  150. * instruction cycles.
  151. *
  152. * Instruction performance varies based on the core. For cores
  153. * with icache and static/dynamic branch prediction (II/f, II/s):
  154. *
  155. * Normal ALU (e.g. add, cmp, etc): 1 cycle
  156. * Branch (correctly predicted, taken): 2 cycles
  157. * Negative offset is predicted (II/s).
  158. *
  159. * For cores without icache and no branch prediction (II/e):
  160. *
  161. * Normal ALU (e.g. add, cmp, etc): 6 cycles
  162. * Branch (no prediction): 6 cycles
  163. *
  164. * For simplicity, if an instruction cache is implemented we
  165. * assume II/f or II/s. Otherwise, we use the II/e.
  166. *
  167. */
  168. .globl dly_clks
  169. dly_clks:
  170. #if (CFG_ICACHE_SIZE > 0)
  171. subi r4, r4, 3 /* 3 clocks/loop */
  172. #else
  173. subi r4, r4, 12 /* 12 clocks/loop */
  174. #endif
  175. bge r4, r0, dly_clks
  176. ret
  177. #if !defined(CONFIG_IDENT_STRING)
  178. #define CONFIG_IDENT_STRING ""
  179. #endif
  180. .data
  181. .globl version_string
  182. version_string:
  183. .ascii U_BOOT_VERSION
  184. .ascii " (", __DATE__, " - ", __TIME__, ")"
  185. .ascii CONFIG_IDENT_STRING, "\0"