start.S 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (C) 2003 Josef Baumgartner <josef.baumgartner@telex.de>
  4. * Based on code from Bernhard Kuhn <bkuhn@metrowerks.com>
  5. */
  6. #include <asm-offsets.h>
  7. #include <config.h>
  8. #include "version.h"
  9. #include <asm/cache.h>
  10. #define _START _start
  11. #define _FAULT _fault
  12. #define SAVE_ALL \
  13. move.w #0x2700,%sr; /* disable intrs */ \
  14. subl #60,%sp; /* space for 15 regs */ \
  15. moveml %d0-%d7/%a0-%a6,%sp@;
  16. #define RESTORE_ALL \
  17. moveml %sp@,%d0-%d7/%a0-%a6; \
  18. addl #60,%sp; /* space for 15 regs */ \
  19. rte;
  20. .text
  21. /*
  22. * Vector table. This is used for initial platform startup.
  23. * These vectors are to catch any un-intended traps.
  24. */
  25. _vectors:
  26. INITSP: .long 0x00000000 /* Initial SP */
  27. INITPC: .long _START /* Initial PC */
  28. vector02_0F:
  29. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  30. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  31. /* Reserved */
  32. vector10_17:
  33. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  34. vector18_1F:
  35. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  36. /* TRAP #0 - #15 */
  37. vector20_2F:
  38. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  39. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  40. /* Reserved */
  41. vector30_3F:
  42. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  43. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  44. vector64_127:
  45. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  46. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  47. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  48. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  49. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  50. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  51. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  52. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  53. vector128_191:
  54. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  55. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  56. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  57. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  58. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  59. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  60. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  61. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  62. vector192_255:
  63. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  64. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  65. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  66. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  67. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  68. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  69. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  70. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  71. .text
  72. .globl _start
  73. _start:
  74. nop
  75. nop
  76. move.w #0x2700,%sr /* Mask off Interrupt */
  77. /* Set vector base register at the beginning of the Flash */
  78. move.l #CONFIG_SYS_FLASH_BASE, %d0
  79. movec %d0, %VBR
  80. move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0
  81. movec %d0, %RAMBAR0
  82. move.l #(CONFIG_SYS_INIT_RAM1_ADDR + CONFIG_SYS_INIT_RAM1_CTRL), %d0
  83. movec %d0, %RAMBAR1
  84. move.l #CONFIG_SYS_MBAR, %d0 /* set MBAR address */
  85. move.c %d0, %MBAR
  86. /* invalidate and disable cache */
  87. move.l #0x01040100, %d0 /* Invalidate cache cmd */
  88. movec %d0, %CACR /* Invalidate cache */
  89. move.l #0, %d0
  90. movec %d0, %ACR0
  91. movec %d0, %ACR1
  92. movec %d0, %ACR2
  93. movec %d0, %ACR3
  94. /* initialize general use internal ram */
  95. move.l #0, %d0
  96. move.l #(ICACHE_STATUS), %a1 /* icache */
  97. move.l #(DCACHE_STATUS), %a2 /* icache */
  98. move.l %d0, (%a1)
  99. move.l %d0, (%a2)
  100. /* put relocation table address to a5 */
  101. move.l #__got_start, %a5
  102. /* setup stack initially on top of internal static ram */
  103. move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_SIZE), %sp
  104. /*
  105. * if configured, malloc_f arena will be reserved first,
  106. * then (and always) gd struct space will be reserved
  107. */
  108. move.l %sp, -(%sp)
  109. move.l #board_init_f_alloc_reserve, %a1
  110. jsr (%a1)
  111. /* update stack and frame-pointers */
  112. move.l %d0, %sp
  113. move.l %sp, %fp
  114. /* initialize reserved area */
  115. move.l %d0, -(%sp)
  116. move.l #board_init_f_init_reserve, %a1
  117. jsr (%a1)
  118. /* run low-level CPU init code (from flash) */
  119. jbsr cpu_init_f
  120. /* run low-level board init code (from flash) */
  121. clr.l %sp@-
  122. jbsr board_init_f
  123. /* board_init_f() does not return */
  124. /******************************************************************************/
  125. /*
  126. * void relocate_code(addr_sp, gd, addr_moni)
  127. *
  128. * This "function" does not return, instead it continues in RAM
  129. * after relocating the monitor code.
  130. *
  131. * r3 = dest
  132. * r4 = src
  133. * r5 = length in bytes
  134. * r6 = cachelinesize
  135. */
  136. .globl relocate_code
  137. relocate_code:
  138. link.w %a6,#0
  139. move.l 8(%a6), %sp /* set new stack pointer */
  140. move.l 12(%a6), %d0 /* Save copy of Global Data pointer */
  141. move.l 16(%a6), %a0 /* Save copy of Destination Address */
  142. move.l #CONFIG_SYS_MONITOR_BASE, %a1
  143. move.l #__init_end, %a2
  144. move.l %a0, %a3
  145. /* copy the code to RAM */
  146. 1:
  147. move.l (%a1)+, (%a3)+
  148. cmp.l %a1,%a2
  149. bgt.s 1b
  150. /*
  151. * We are done. Do not return, instead branch to second part of board
  152. * initialization, now running from RAM.
  153. */
  154. move.l %a0, %a1
  155. add.l #(in_ram - CONFIG_SYS_MONITOR_BASE), %a1
  156. jmp (%a1)
  157. in_ram:
  158. clear_bss:
  159. /*
  160. * Now clear BSS segment
  161. */
  162. move.l %a0, %a1
  163. add.l #(_sbss - CONFIG_SYS_MONITOR_BASE),%a1
  164. move.l %a0, %d1
  165. add.l #(_ebss - CONFIG_SYS_MONITOR_BASE),%d1
  166. 6:
  167. clr.l (%a1)+
  168. cmp.l %a1,%d1
  169. bgt.s 6b
  170. /*
  171. * fix got table in RAM
  172. */
  173. move.l %a0, %a1
  174. add.l #(__got_start - CONFIG_SYS_MONITOR_BASE),%a1
  175. move.l %a1,%a5 /* fix got pointer register a5 */
  176. move.l %a0, %a2
  177. add.l #(__got_end - CONFIG_SYS_MONITOR_BASE),%a2
  178. 7:
  179. move.l (%a1),%d1
  180. sub.l #_start,%d1
  181. add.l %a0,%d1
  182. move.l %d1,(%a1)+
  183. cmp.l %a2, %a1
  184. bne 7b
  185. /* calculate relative jump to board_init_r in ram */
  186. move.l %a0, %a1
  187. add.l #(board_init_r - CONFIG_SYS_MONITOR_BASE), %a1
  188. /* set parameters for board_init_r */
  189. move.l %a0,-(%sp) /* dest_addr */
  190. move.l %d0,-(%sp) /* gd */
  191. jsr (%a1)
  192. /******************************************************************************/
  193. /* exception code */
  194. .globl _fault
  195. _fault:
  196. bra _fault
  197. .globl _exc_handler
  198. _exc_handler:
  199. SAVE_ALL
  200. movel %sp,%sp@-
  201. bsr exc_handler
  202. addql #4,%sp
  203. RESTORE_ALL
  204. .globl _int_handler
  205. _int_handler:
  206. SAVE_ALL
  207. movel %sp,%sp@-
  208. bsr int_handler
  209. addql #4,%sp
  210. RESTORE_ALL
  211. /******************************************************************************/
  212. .globl version_string
  213. version_string:
  214. .ascii U_BOOT_VERSION_STRING, "\0"
  215. .align 4