start.S 6.6 KB

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