start.S 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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 <version.h>
  26. /*************************************************************************
  27. * RESTART
  28. ************************************************************************/
  29. .text
  30. .global _start
  31. _start:
  32. wrctl status, r0 /* Disable interrupts */
  33. /* ICACHE INIT -- only the icache line at the reset address
  34. * is invalidated at reset. So the init must stay within
  35. * the cache line size (8 words). If GERMS is used, we'll
  36. * just be invalidating the cache a second time. If cache
  37. * is not implemented initi behaves as nop.
  38. */
  39. ori r4, r0, %lo(CONFIG_SYS_ICACHELINE_SIZE)
  40. movhi r5, %hi(CONFIG_SYS_ICACHE_SIZE)
  41. ori r5, r5, %lo(CONFIG_SYS_ICACHE_SIZE)
  42. 0: initi r5
  43. sub r5, r5, r4
  44. bgt r5, r0, 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 ienable, r0 /* All disabled */
  59. /* DCACHE INIT -- if dcache not implemented, initd behaves as
  60. * nop.
  61. */
  62. movhi r4, %hi(CONFIG_SYS_DCACHELINE_SIZE)
  63. ori r4, r4, %lo(CONFIG_SYS_DCACHELINE_SIZE)
  64. movhi r5, %hi(CONFIG_SYS_DCACHE_SIZE)
  65. ori r5, r5, %lo(CONFIG_SYS_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 __bss_end__.
  93. */
  94. movhi r5, %hi(__bss_start)
  95. ori r5, r5, %lo(__bss_start)
  96. movhi r6, %hi(__bss_end__)
  97. ori r6, r6, %lo(__bss_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. /* JUMP TO RELOC ADDR */
  104. movhi r4, %hi(_reloc)
  105. ori r4, r4, %lo(_reloc)
  106. jmp r4
  107. _reloc:
  108. /* COPY EXCEPTION TRAMPOLINE -- copy the tramp to the
  109. * exception address. Define CONFIG_ROM_STUBS to prevent
  110. * the copy (e.g. exception in flash or in other
  111. * softare/firmware component).
  112. */
  113. #if !defined(CONFIG_ROM_STUBS)
  114. movhi r4, %hi(_except_start)
  115. ori r4, r4, %lo(_except_start)
  116. movhi r5, %hi(_except_end)
  117. ori r5, r5, %lo(_except_end)
  118. movhi r6, %hi(CONFIG_SYS_EXCEPTION_ADDR)
  119. ori r6, r6, %lo(CONFIG_SYS_EXCEPTION_ADDR)
  120. beq r4, r6, 7f /* Skip if at proper addr */
  121. 6: ldwio r7, 0(r4)
  122. stwio r7, 0(r6)
  123. addi r4, r4, 4
  124. addi r6, r6, 4
  125. bne r4, r5, 6b
  126. 7:
  127. #endif
  128. /* STACK INIT -- zero top two words for call back chain.
  129. */
  130. movhi sp, %hi(CONFIG_SYS_INIT_SP)
  131. ori sp, sp, %lo(CONFIG_SYS_INIT_SP)
  132. addi sp, sp, -8
  133. stw r0, 0(sp)
  134. stw r0, 4(sp)
  135. mov fp, sp
  136. /*
  137. * Call board_init -- never returns
  138. */
  139. movhi r4, %hi(board_init@h)
  140. ori r4, r4, %lo(board_init@h)
  141. callr r4
  142. /* NEVER RETURNS -- but branch to the _start just
  143. * in case ;-)
  144. */
  145. br _start
  146. /*
  147. * dly_clks -- Nios2 (like Nios1) doesn't have a timebase in
  148. * the core. For simple delay loops, we do our best by counting
  149. * instruction cycles.
  150. *
  151. * Instruction performance varies based on the core. For cores
  152. * with icache and static/dynamic branch prediction (II/f, II/s):
  153. *
  154. * Normal ALU (e.g. add, cmp, etc): 1 cycle
  155. * Branch (correctly predicted, taken): 2 cycles
  156. * Negative offset is predicted (II/s).
  157. *
  158. * For cores without icache and no branch prediction (II/e):
  159. *
  160. * Normal ALU (e.g. add, cmp, etc): 6 cycles
  161. * Branch (no prediction): 6 cycles
  162. *
  163. * For simplicity, if an instruction cache is implemented we
  164. * assume II/f or II/s. Otherwise, we use the II/e.
  165. *
  166. */
  167. .globl dly_clks
  168. dly_clks:
  169. #if (CONFIG_SYS_ICACHE_SIZE > 0)
  170. subi r4, r4, 3 /* 3 clocks/loop */
  171. #else
  172. subi r4, r4, 12 /* 12 clocks/loop */
  173. #endif
  174. bge r4, r0, dly_clks
  175. ret
  176. .data
  177. .globl version_string
  178. version_string:
  179. .ascii U_BOOT_VERSION_STRING, "\0"