start.S 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. * (C) Copyright 2004, Psyent Corporation <www.psyent.com>
  3. * Scott McNutt <smcnutt@psyent.com>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <asm-offsets.h>
  8. #include <config.h>
  9. #include <version.h>
  10. /*
  11. * icache and dcache configuration used only for start.S.
  12. * the values are chosen so that it will work for all configuration.
  13. */
  14. #define ICACHE_LINE_SIZE 32 /* fixed 32 */
  15. #define ICACHE_SIZE_MAX 0x10000 /* 64k max */
  16. #define DCACHE_LINE_SIZE_MIN 4 /* 4, 16, 32 */
  17. #define DCACHE_SIZE_MAX 0x10000 /* 64k max */
  18. /* RESTART */
  19. .text
  20. .global _start, _except_start, _except_end
  21. _start:
  22. wrctl status, r0 /* Disable interrupts */
  23. /*
  24. * ICACHE INIT -- only the icache line at the reset address
  25. * is invalidated at reset. So the init must stay within
  26. * the cache line size (8 words). If GERMS is used, we'll
  27. * just be invalidating the cache a second time. If cache
  28. * is not implemented initi behaves as nop.
  29. */
  30. ori r4, r0, %lo(ICACHE_LINE_SIZE)
  31. movhi r5, %hi(ICACHE_SIZE_MAX)
  32. ori r5, r5, %lo(ICACHE_SIZE_MAX)
  33. 0: initi r5
  34. sub r5, r5, r4
  35. bgt r5, r0, 0b
  36. br _except_end /* Skip the tramp */
  37. /*
  38. * EXCEPTION TRAMPOLINE -- the following gets copied
  39. * to the exception address (below), but is otherwise at the
  40. * default exception vector offset (0x0020).
  41. */
  42. _except_start:
  43. movhi et, %hi(_exception)
  44. ori et, et, %lo(_exception)
  45. jmp et
  46. _except_end:
  47. /*
  48. * INTERRUPTS -- for now, all interrupts masked and globally
  49. * disabled.
  50. */
  51. wrctl ienable, r0 /* All disabled */
  52. /*
  53. * DCACHE INIT -- if dcache not implemented, initd behaves as
  54. * nop.
  55. */
  56. ori r4, r0, %lo(DCACHE_LINE_SIZE_MIN)
  57. movhi r5, %hi(DCACHE_SIZE_MAX)
  58. ori r5, r5, %lo(DCACHE_SIZE_MAX)
  59. mov r6, r0
  60. 1: initd 0(r6)
  61. add r6, r6, r4
  62. bltu r6, r5, 1b
  63. /*
  64. * RELOCATE CODE, DATA & COMMAND TABLE -- the following code
  65. * assumes code, data and the command table are all
  66. * contiguous. This lets us relocate everything as a single
  67. * block. Make sure the linker script matches this ;-)
  68. */
  69. nextpc r4
  70. _cur: movhi r5, %hi(_cur - _start)
  71. ori r5, r5, %lo(_cur - _start)
  72. sub r4, r4, r5 /* r4 <- cur _start */
  73. mov r8, r4
  74. movhi r5, %hi(_start)
  75. ori r5, r5, %lo(_start) /* r5 <- linked _start */
  76. mov sp, r5 /* initial stack below u-boot code */
  77. beq r4, r5, 3f
  78. movhi r6, %hi(CONFIG_SYS_MONITOR_LEN)
  79. ori r6, r6, %lo(CONFIG_SYS_MONITOR_LEN)
  80. add r6, r6, r5
  81. 2: ldwio r7, 0(r4)
  82. addi r4, r4, 4
  83. stwio r7, 0(r5)
  84. addi r5, r5, 4
  85. bne r5, r6, 2b
  86. 3:
  87. /* JUMP TO RELOC ADDR */
  88. movhi r4, %hi(_reloc)
  89. ori r4, r4, %lo(_reloc)
  90. jmp r4
  91. _reloc:
  92. /* STACK INIT -- zero top two words for call back chain. */
  93. addi sp, sp, -8
  94. stw r0, 0(sp)
  95. stw r0, 4(sp)
  96. mov fp, sp
  97. #ifdef CONFIG_DEBUG_UART
  98. /* Set up the debug UART */
  99. movhi r2, %hi(debug_uart_init@h)
  100. ori r2, r2, %lo(debug_uart_init@h)
  101. callr r2
  102. #endif
  103. /* Allocate and initialize reserved area, update SP */
  104. mov r4, sp
  105. movhi r2, %hi(board_init_f_alloc_reserve@h)
  106. ori r2, r2, %lo(board_init_f_alloc_reserve@h)
  107. callr r2
  108. mov sp, r2
  109. mov r4, sp
  110. movhi r2, %hi(board_init_f_init_reserve@h)
  111. ori r2, r2, %lo(board_init_f_init_reserve@h)
  112. callr r2
  113. /* Update frame-pointer */
  114. mov fp, sp
  115. /* Call board_init_f -- never returns */
  116. mov r4, r0
  117. movhi r2, %hi(board_init_f@h)
  118. ori r2, r2, %lo(board_init_f@h)
  119. callr r2
  120. /*
  121. * NEVER RETURNS -- but branch to the _start just
  122. * in case ;-)
  123. */
  124. br _start
  125. /*
  126. * relocate_code -- Nios2 handles the relocation above. But
  127. * the generic board code monkeys with the heap, stack, etc.
  128. * (it makes some assumptions that may not be appropriate
  129. * for Nios). Nevertheless, we capitulate here.
  130. *
  131. * We'll call the board_init_r from here since this isn't
  132. * supposed to return.
  133. *
  134. * void relocate_code (ulong sp, gd_t *global_data,
  135. * ulong reloc_addr)
  136. * __attribute__ ((noreturn));
  137. */
  138. .text
  139. .global relocate_code
  140. relocate_code:
  141. mov sp, r4 /* Set the new sp */
  142. mov r4, r5
  143. /*
  144. * ZERO BSS/SBSS -- bss and sbss are assumed to be adjacent
  145. * and between __bss_start and __bss_end.
  146. */
  147. movhi r5, %hi(__bss_start)
  148. ori r5, r5, %lo(__bss_start)
  149. movhi r6, %hi(__bss_end)
  150. ori r6, r6, %lo(__bss_end)
  151. beq r5, r6, 5f
  152. 4: stw r0, 0(r5)
  153. addi r5, r5, 4
  154. bne r5, r6, 4b
  155. 5:
  156. movhi r8, %hi(board_init_r@h)
  157. ori r8, r8, %lo(board_init_r@h)
  158. callr r8
  159. ret