start.S 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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 <asm-offsets.h>
  24. #include <config.h>
  25. #include <timestamp.h>
  26. #include <version.h>
  27. /*************************************************************************
  28. * RESTART
  29. ************************************************************************/
  30. .text
  31. .global _start
  32. _start:
  33. wrctl status, r0 /* Disable interrupts */
  34. /* ICACHE INIT -- only the icache line at the reset address
  35. * is invalidated at reset. So the init must stay within
  36. * the cache line size (8 words). If GERMS is used, we'll
  37. * just be invalidating the cache a second time. If cache
  38. * is not implemented initi behaves as nop.
  39. */
  40. ori r4, r0, %lo(CONFIG_SYS_ICACHELINE_SIZE)
  41. movhi r5, %hi(CONFIG_SYS_ICACHE_SIZE)
  42. ori r5, r5, %lo(CONFIG_SYS_ICACHE_SIZE)
  43. 0: initi r5
  44. sub r5, r5, r4
  45. bgt r5, r0, 0b
  46. br _except_end /* Skip the tramp */
  47. /* EXCEPTION TRAMPOLINE -- the following gets copied
  48. * to the exception address (below), but is otherwise at the
  49. * default exception vector offset (0x0020).
  50. */
  51. _except_start:
  52. movhi et, %hi(_exception)
  53. ori et, et, %lo(_exception)
  54. jmp et
  55. _except_end:
  56. /* INTERRUPTS -- for now, all interrupts masked and globally
  57. * disabled.
  58. */
  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. /* JUMP TO RELOC ADDR */
  105. movhi r4, %hi(_reloc)
  106. ori r4, r4, %lo(_reloc)
  107. jmp r4
  108. _reloc:
  109. /* COPY EXCEPTION TRAMPOLINE -- copy the tramp to the
  110. * exception address. Define CONFIG_ROM_STUBS to prevent
  111. * the copy (e.g. exception in flash or in other
  112. * softare/firmware component).
  113. */
  114. #if !defined(CONFIG_ROM_STUBS)
  115. movhi r4, %hi(_except_start)
  116. ori r4, r4, %lo(_except_start)
  117. movhi r5, %hi(_except_end)
  118. ori r5, r5, %lo(_except_end)
  119. movhi r6, %hi(CONFIG_SYS_EXCEPTION_ADDR)
  120. ori r6, r6, %lo(CONFIG_SYS_EXCEPTION_ADDR)
  121. beq r4, r6, 7f /* Skip if at proper addr */
  122. 6: ldwio r7, 0(r4)
  123. stwio r7, 0(r6)
  124. addi r4, r4, 4
  125. addi r6, r6, 4
  126. bne r4, r5, 6b
  127. 7:
  128. #endif
  129. /* STACK INIT -- zero top two words for call back chain.
  130. */
  131. movhi sp, %hi(CONFIG_SYS_INIT_SP)
  132. ori sp, sp, %lo(CONFIG_SYS_INIT_SP)
  133. addi sp, sp, -8
  134. stw r0, 0(sp)
  135. stw r0, 4(sp)
  136. mov fp, sp
  137. /*
  138. * Call board_init -- never returns
  139. */
  140. movhi r4, %hi(board_init@h)
  141. ori r4, r4, %lo(board_init@h)
  142. callr r4
  143. /* NEVER RETURNS -- but branch to the _start just
  144. * in case ;-)
  145. */
  146. br _start
  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 (CONFIG_SYS_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 " (", U_BOOT_DATE, " - ", U_BOOT_TIME, ")"
  185. .ascii CONFIG_IDENT_STRING, "\0"