start.S 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /*
  2. * (C) Copyright 2003, 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. #if !defined(CONFIG_IDENT_STRING)
  26. #define CONFIG_IDENT_STRING ""
  27. #endif
  28. #define STATUS_INIT 0x8600 /* IE=1, IPRI=2 */
  29. /*************************************************************************
  30. * RESTART
  31. ************************************************************************/
  32. .text
  33. .global _start
  34. _start:
  35. bsr 0f
  36. nop
  37. .long _start
  38. /* GERMS -- The "standard-32" configuration GERMS monitor looks
  39. * for the string "Nios" at flash_base + 0xc (actually it only
  40. * tests for 'N', 'i'). You can leave support for this in place
  41. * as it's only a few words.
  42. */
  43. . = _start + 0x000c
  44. .string "Nios"
  45. .align 4
  46. 0:
  47. /*
  48. * Early setup -- set cwp = HI_LIMIT, IPRI = 2, IE = 1 to
  49. * enable underflow exceptions. Disable cache.
  50. * NOTE: %o7 has return addr -- save in %g7 use later.
  51. */
  52. mov %g7, %o7
  53. pfx 2 /* WVALID */
  54. rdctl %g0
  55. lsri %g0, 1
  56. pfx %hi(STATUS_INIT)
  57. or %g0, %lo(STATUS_INIT)
  58. wrctl %g0 /* update status */
  59. nop
  60. /*
  61. * STACK
  62. */
  63. pfx %hi(CFG_INIT_SP)
  64. movi %sp, %lo(CFG_INIT_SP)
  65. pfx %xhi(CFG_INIT_SP)
  66. movhi %sp, %xlo(CFG_INIT_SP)
  67. mov %fp, %sp
  68. pfx %hi(4*16)
  69. subi %sp, %lo(4*16) /* Space for reg window mgmt */
  70. /*
  71. * RELOCATE -- %g7 has return addr from bsr at _start.
  72. */
  73. pfx %hi(__u_boot_cmd_end)
  74. movi %g5, %lo(__u_boot_cmd_end)
  75. pfx %xhi(__u_boot_cmd_end)
  76. movhi %g5, %xlo(__u_boot_cmd_end) /* %g5 <- end address */
  77. lsli %g7, 1 /* mem = retaddr << 1 */
  78. mov %g6, %g7
  79. subi %g6, 4 /* %g6 <- src addr */
  80. ld %g7, [%g7] /* %g7 <- dst addr */
  81. /* No need to move text sections if we're already located
  82. * at the proper address.
  83. */
  84. cmp %g7, %g6
  85. ifs cc_z
  86. br reloc
  87. nop /* delay slot */
  88. 1: cmp %g7, %g5
  89. skps cc_nz
  90. br 2f
  91. nop /* delay slot */
  92. ld %g0, [%g6]
  93. addi %g6, 4 /* src++ */
  94. st [%g7], %g0
  95. addi %g7, 4 /* dst++ */
  96. br 1b
  97. nop /* delay slot */
  98. 2:
  99. /*
  100. * Jump to relocation address
  101. */
  102. pfx %hi(reloc@h)
  103. movi %g0, %lo(reloc@h)
  104. pfx %xhi(reloc@h)
  105. movhi %g0, %xlo(reloc@h)
  106. jmp %g0
  107. nop /* delay slot */
  108. reloc:
  109. /*
  110. * CLEAR BSS
  111. */
  112. pfx %hi(__bss_end)
  113. movi %g5, %lo(__bss_end)
  114. pfx %xhi(__bss_end)
  115. movhi %g5, %xlo(__bss_end) /* %g5 <- end address */
  116. pfx %hi(__bss_start)
  117. movi %g7, %lo(__bss_start)
  118. pfx %xhi(__bss_start)
  119. movhi %g7, %xlo(__bss_start) /* %g7 <- end address */
  120. movi %g0, 0
  121. 3: cmp %g7, %g5
  122. skps cc_nz
  123. br 4f
  124. nop /* delay slot */
  125. st [%g7], %g0
  126. addi %g7, 4 /* (delay slot) dst++ */
  127. br 3b
  128. nop /* delay slot */
  129. 4:
  130. /*
  131. * INIT VECTOR TABLE
  132. */
  133. pfx %hi(CFG_VECT_BASE)
  134. movi %g0, %lo(CFG_VECT_BASE)
  135. pfx %xhi(CFG_VECT_BASE)
  136. movhi %g0, %xlo(CFG_VECT_BASE) /* dst */
  137. mov %l0, %g0
  138. pfx %hi(_vectors)
  139. movi %g1, %lo(_vectors)
  140. pfx %xhi(_vectors)
  141. movhi %g1, %xlo(_vectors) /* src */
  142. bgen %g2, 6 /* cnt = 64 */
  143. ldp %g3, [%l0, 3] /* bkpt vector */
  144. ldp %g4, [%l0, 4] /* single step vector */
  145. 5: ld %g7, [%g1]
  146. addi %g1, 4 /* src++ */
  147. st [%g0], %g7
  148. addi %g0, 4 /* dst++ */
  149. subi %g2, 1 /* cnt-- */
  150. ifrnz %g2
  151. br 5b
  152. nop /* delay slot */
  153. #if defined(CONFIG_ROM_STUBS)
  154. /* Restore the breakpoint and single step exception
  155. * vectors to their original values.
  156. */
  157. stp [%l0,3], %g3 /* breakpoint */
  158. stp [%l0,4], %g4 /* single step */
  159. #endif
  160. /* For debug startup convenience ... software breakpoints
  161. * set prior to this point may not succeed ;-)
  162. */
  163. .global __start
  164. __start:
  165. /*
  166. * Call board_init -- never returns
  167. */
  168. pfx %hi(board_init@h)
  169. movi %g1, %lo(board_init@h)
  170. pfx %xhi(board_init@h)
  171. movhi %g1, %xlo(board_init@h)
  172. call %g1
  173. nop /* Delaly slot */
  174. /* NEVER RETURNS */
  175. /*
  176. * dly_clks -- Nios doesn't have a time/clk reference for simple
  177. * delay loops, so we do our best by counting instruction cycles.
  178. * A control register that counts system clock cycles would be
  179. * a handy feature -- hint for Altera ;-)
  180. */
  181. .globl dly_clks
  182. /* Each loop is 4 instructions as delay slot is always
  183. * executed. Each instruction is approximately 4 clocks
  184. * (according to some lame info from Altera). So ...
  185. * ... each loop is about 16 clocks.
  186. */
  187. dly_clks:
  188. lsri %o0, 4 /* cnt/16 */
  189. 8: skprnz %o0
  190. br 9f
  191. subi %o0, 1 /* cnt--, Delay slot */
  192. br 8b
  193. nop
  194. 9: lret
  195. nop /* Delay slot */
  196. .data
  197. .globl version_string
  198. version_string:
  199. .ascii U_BOOT_VERSION
  200. .ascii " (", __DATE__, " - ", __TIME__, ")"
  201. .ascii CONFIG_IDENT_STRING, "\0"