start.S 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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 <timestamp.h>
  25. #include <version.h>
  26. /*************************************************************************
  27. * RESTART
  28. ************************************************************************/
  29. .text
  30. .global _start
  31. _start:
  32. /* ICACHE INIT -- only the icache line at the reset address
  33. * is invalidated at reset. So the init must stay within
  34. * the cache line size (8 words). If GERMS is used, we'll
  35. * just be invalidating the cache a second time. If cache
  36. * is not implemented initi behaves as nop.
  37. */
  38. ori r4, r0, %lo(CONFIG_SYS_ICACHELINE_SIZE)
  39. movhi r5, %hi(CONFIG_SYS_ICACHE_SIZE)
  40. ori r5, r5, %lo(CONFIG_SYS_ICACHE_SIZE)
  41. mov r6, r0
  42. 0: initi r6
  43. add r6, r6, r4
  44. bltu r6, r5, 0b
  45. br _except_end /* Skip the tramp */
  46. /* EXCEPTION TRAMPOLINE -- the following gets copied
  47. * to the exception address (below), but is otherwise at the
  48. * default exception vector offset (0x0020).
  49. */
  50. _except_start:
  51. movhi et, %hi(_exception)
  52. ori et, et, %lo(_exception)
  53. jmp et
  54. _except_end:
  55. /* INTERRUPTS -- for now, all interrupts masked and globally
  56. * disabled.
  57. */
  58. wrctl status, r0 /* Disable interrupts */
  59. wrctl ienable, r0 /* All disabled */
  60. /* DCACHE INIT -- if dcache not implemented, initd behaves as
  61. * nop.
  62. */
  63. movhi r4, %hi(CONFIG_SYS_DCACHELINE_SIZE)
  64. ori r4, r4, %lo(CONFIG_SYS_DCACHELINE_SIZE)
  65. movhi r5, %hi(CONFIG_SYS_DCACHE_SIZE)
  66. ori r5, r5, %lo(CONFIG_SYS_DCACHE_SIZE)
  67. mov r6, r0
  68. 1: initd 0(r6)
  69. add r6, r6, r4
  70. bltu r6, r5, 1b
  71. /* RELOCATE CODE, DATA & COMMAND TABLE -- the following code
  72. * assumes code, data and the command table are all
  73. * contiguous. This lets us relocate everything as a single
  74. * block. Make sure the linker script matches this ;-)
  75. */
  76. nextpc r4
  77. _cur: movhi r5, %hi(_cur - _start)
  78. ori r5, r5, %lo(_cur - _start)
  79. sub r4, r4, r5 /* r4 <- cur _start */
  80. mov r8, r4
  81. movhi r5, %hi(_start)
  82. ori r5, r5, %lo(_start) /* r5 <- linked _start */
  83. beq r4, r5, 3f
  84. movhi r6, %hi(_edata)
  85. ori r6, r6, %lo(_edata)
  86. 2: ldwio r7, 0(r4)
  87. addi r4, r4, 4
  88. stwio r7, 0(r5)
  89. addi r5, r5, 4
  90. bne r5, r6, 2b
  91. 3:
  92. /* ZERO BSS/SBSS -- bss and sbss are assumed to be adjacent
  93. * and between __bss_start and _end.
  94. */
  95. movhi r5, %hi(__bss_start)
  96. ori r5, r5, %lo(__bss_start)
  97. movhi r6, %hi(_end)
  98. ori r6, r6, %lo(_end)
  99. beq r5, r6, 5f
  100. 4: stwio r0, 0(r5)
  101. addi r5, r5, 4
  102. bne r5, r6, 4b
  103. 5:
  104. /* GLOBAL POINTER -- the global pointer is used to reference
  105. * "small data" (see -G switch). The linker script must
  106. * provide the gp address.
  107. */
  108. movhi gp, %hi(_gp)
  109. ori gp, gp, %lo(_gp)
  110. /* JUMP TO RELOC ADDR */
  111. movhi r4, %hi(_reloc)
  112. ori r4, r4, %lo(_reloc)
  113. jmp r4
  114. _reloc:
  115. /* COPY EXCEPTION TRAMPOLINE -- copy the tramp to the
  116. * exception address. Define CONFIG_ROM_STUBS to prevent
  117. * the copy (e.g. exception in flash or in other
  118. * softare/firmware component).
  119. */
  120. #if !defined(CONFIG_ROM_STUBS)
  121. movhi r4, %hi(_except_start)
  122. ori r4, r4, %lo(_except_start)
  123. movhi r5, %hi(_except_end)
  124. ori r5, r5, %lo(_except_end)
  125. movhi r6, %hi(CONFIG_SYS_EXCEPTION_ADDR)
  126. ori r6, r6, %lo(CONFIG_SYS_EXCEPTION_ADDR)
  127. beq r4, r6, 7f /* Skip if at proper addr */
  128. 6: ldwio r7, 0(r4)
  129. stwio r7, 0(r6)
  130. addi r4, r4, 4
  131. addi r6, r6, 4
  132. bne r4, r5, 6b
  133. 7:
  134. #endif
  135. /* STACK INIT -- zero top two words for call back chain.
  136. */
  137. movhi sp, %hi(CONFIG_SYS_INIT_SP)
  138. ori sp, sp, %lo(CONFIG_SYS_INIT_SP)
  139. addi sp, sp, -8
  140. stw r0, 0(sp)
  141. stw r0, 4(sp)
  142. mov fp, sp
  143. /*
  144. * Call board_init -- never returns
  145. */
  146. movhi r4, %hi(board_init@h)
  147. ori r4, r4, %lo(board_init@h)
  148. callr r4
  149. /* NEVER RETURNS -- but branch to the _start just
  150. * in case ;-)
  151. */
  152. br _start
  153. /*
  154. * dly_clks -- Nios2 (like Nios1) doesn't have a timebase in
  155. * the core. For simple delay loops, we do our best by counting
  156. * instruction cycles.
  157. *
  158. * Instruction performance varies based on the core. For cores
  159. * with icache and static/dynamic branch prediction (II/f, II/s):
  160. *
  161. * Normal ALU (e.g. add, cmp, etc): 1 cycle
  162. * Branch (correctly predicted, taken): 2 cycles
  163. * Negative offset is predicted (II/s).
  164. *
  165. * For cores without icache and no branch prediction (II/e):
  166. *
  167. * Normal ALU (e.g. add, cmp, etc): 6 cycles
  168. * Branch (no prediction): 6 cycles
  169. *
  170. * For simplicity, if an instruction cache is implemented we
  171. * assume II/f or II/s. Otherwise, we use the II/e.
  172. *
  173. */
  174. .globl dly_clks
  175. dly_clks:
  176. #if (CONFIG_SYS_ICACHE_SIZE > 0)
  177. subi r4, r4, 3 /* 3 clocks/loop */
  178. #else
  179. subi r4, r4, 12 /* 12 clocks/loop */
  180. #endif
  181. bge r4, r0, dly_clks
  182. ret
  183. #if !defined(CONFIG_IDENT_STRING)
  184. #define CONFIG_IDENT_STRING ""
  185. #endif
  186. .data
  187. .globl version_string
  188. version_string:
  189. .ascii U_BOOT_VERSION
  190. .ascii " (", U_BOOT_DATE, " - ", U_BOOT_TIME, ")"
  191. .ascii CONFIG_IDENT_STRING, "\0"