start.S 5.4 KB

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