start.S 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. #ifndef CONFIG_IDENT_STRING
  12. #define CONFIG_IDENT_STRING ""
  13. #endif
  14. #define _START _start
  15. #define _FAULT _fault
  16. #define SAVE_ALL \
  17. move.w #0x2700,%sr; /* disable intrs */ \
  18. subl #60,%sp; /* space for 15 regs */ \
  19. moveml %d0-%d7/%a0-%a6,%sp@;
  20. #define RESTORE_ALL \
  21. moveml %sp@,%d0-%d7/%a0-%a6; \
  22. addl #60,%sp; /* space for 15 regs */ \
  23. rte;
  24. .text
  25. /*
  26. * Vector table. This is used for initial platform startup.
  27. * These vectors are to catch any un-intended traps.
  28. */
  29. _vectors:
  30. INITSP: .long 0x00000000 /* Initial SP */
  31. INITPC: .long _START /* Initial PC */
  32. vector02: .long _FAULT /* Access Error */
  33. vector03: .long _FAULT /* Address Error */
  34. vector04: .long _FAULT /* Illegal Instruction */
  35. vector05: .long _FAULT /* Reserved */
  36. vector06: .long _FAULT /* Reserved */
  37. vector07: .long _FAULT /* Reserved */
  38. vector08: .long _FAULT /* Privilege Violation */
  39. vector09: .long _FAULT /* Trace */
  40. vector0A: .long _FAULT /* Unimplemented A-Line */
  41. vector0B: .long _FAULT /* Unimplemented F-Line */
  42. vector0C: .long _FAULT /* Debug Interrupt */
  43. vector0D: .long _FAULT /* Reserved */
  44. vector0E: .long _FAULT /* Format Error */
  45. vector0F: .long _FAULT /* Unitialized Int. */
  46. /* Reserved */
  47. vector10_17:
  48. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  49. vector18: .long _FAULT /* Spurious Interrupt */
  50. vector19: .long _FAULT /* Autovector Level 1 */
  51. vector1A: .long _FAULT /* Autovector Level 2 */
  52. vector1B: .long _FAULT /* Autovector Level 3 */
  53. vector1C: .long _FAULT /* Autovector Level 4 */
  54. vector1D: .long _FAULT /* Autovector Level 5 */
  55. vector1E: .long _FAULT /* Autovector Level 6 */
  56. vector1F: .long _FAULT /* Autovector Level 7 */
  57. /* TRAP #0 - #15 */
  58. vector20_2F:
  59. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  60. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  61. /* Reserved */
  62. vector30_3F:
  63. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  64. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  65. vector64_127:
  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. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  73. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  74. vector128_191:
  75. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  76. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  77. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  78. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  79. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  80. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  81. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  82. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  83. vector192_255:
  84. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  85. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  86. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  87. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  88. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  89. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  90. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  91. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  92. .text
  93. .globl _start
  94. _start:
  95. nop
  96. nop
  97. move.w #0x2700,%sr /* Mask off Interrupt */
  98. /* Set vector base register at the beginning of the Flash */
  99. move.l #CONFIG_SYS_FLASH_BASE, %d0
  100. movec %d0, %VBR
  101. move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0
  102. movec %d0, %RAMBAR0
  103. move.l #(CONFIG_SYS_INIT_RAM1_ADDR + CONFIG_SYS_INIT_RAM1_CTRL), %d0
  104. movec %d0, %RAMBAR1
  105. move.l #CONFIG_SYS_MBAR, %d0 /* set MBAR address */
  106. move.c %d0, %MBAR
  107. /* invalidate and disable cache */
  108. move.l #0x01040100, %d0 /* Invalidate cache cmd */
  109. movec %d0, %CACR /* Invalidate cache */
  110. move.l #0, %d0
  111. movec %d0, %ACR0
  112. movec %d0, %ACR1
  113. movec %d0, %ACR2
  114. movec %d0, %ACR3
  115. /* initialize general use internal ram */
  116. move.l #0, %d0
  117. move.l #(ICACHE_STATUS), %a1 /* icache */
  118. move.l #(DCACHE_STATUS), %a2 /* icache */
  119. move.l %d0, (%a1)
  120. move.l %d0, (%a2)
  121. /* set stackpointer to end of internal ram to get some stackspace for the
  122. first c-code */
  123. move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET), %sp
  124. clr.l %sp@-
  125. move.l #__got_start, %a5 /* put relocation table address to a5 */
  126. jbsr cpu_init_f /* run low-level CPU init code (from flash) */
  127. jbsr board_init_f /* run low-level board init code (from flash) */
  128. /* board_init_f() does not return */
  129. /*------------------------------------------------------------------------------*/
  130. /*
  131. * void relocate_code (addr_sp, gd, addr_moni)
  132. *
  133. * This "function" does not return, instead it continues in RAM
  134. * after relocating the monitor code.
  135. *
  136. * r3 = dest
  137. * r4 = src
  138. * r5 = length in bytes
  139. * r6 = cachelinesize
  140. */
  141. .globl relocate_code
  142. relocate_code:
  143. link.w %a6,#0
  144. move.l 8(%a6), %sp /* set new stack pointer */
  145. move.l 12(%a6), %d0 /* Save copy of Global Data pointer */
  146. move.l 16(%a6), %a0 /* Save copy of Destination Address */
  147. move.l #CONFIG_SYS_MONITOR_BASE, %a1
  148. move.l #__init_end, %a2
  149. move.l %a0, %a3
  150. /* copy the code to RAM */
  151. 1:
  152. move.l (%a1)+, (%a3)+
  153. cmp.l %a1,%a2
  154. bgt.s 1b
  155. /*
  156. * We are done. Do not return, instead branch to second part of board
  157. * initialization, now running from RAM.
  158. */
  159. move.l %a0, %a1
  160. add.l #(in_ram - CONFIG_SYS_MONITOR_BASE), %a1
  161. jmp (%a1)
  162. in_ram:
  163. clear_bss:
  164. /*
  165. * Now clear BSS segment
  166. */
  167. move.l %a0, %a1
  168. add.l #(_sbss - CONFIG_SYS_MONITOR_BASE),%a1
  169. move.l %a0, %d1
  170. add.l #(_ebss - CONFIG_SYS_MONITOR_BASE),%d1
  171. 6:
  172. clr.l (%a1)+
  173. cmp.l %a1,%d1
  174. bgt.s 6b
  175. /*
  176. * fix got table in RAM
  177. */
  178. move.l %a0, %a1
  179. add.l #(__got_start - CONFIG_SYS_MONITOR_BASE),%a1
  180. move.l %a1,%a5 /* * fix got pointer register a5 */
  181. move.l %a0, %a2
  182. add.l #(__got_end - CONFIG_SYS_MONITOR_BASE),%a2
  183. 7:
  184. move.l (%a1),%d1
  185. sub.l #_start,%d1
  186. add.l %a0,%d1
  187. move.l %d1,(%a1)+
  188. cmp.l %a2, %a1
  189. bne 7b
  190. /* calculate relative jump to board_init_r in ram */
  191. move.l %a0, %a1
  192. add.l #(board_init_r - CONFIG_SYS_MONITOR_BASE), %a1
  193. /* set parameters for board_init_r */
  194. move.l %a0,-(%sp) /* dest_addr */
  195. move.l %d0,-(%sp) /* gd */
  196. jsr (%a1)
  197. /*------------------------------------------------------------------------------*/
  198. /* exception code */
  199. .globl _fault
  200. _fault:
  201. bra _fault
  202. .globl _exc_handler
  203. _exc_handler:
  204. SAVE_ALL
  205. movel %sp,%sp@-
  206. bsr exc_handler
  207. addql #4,%sp
  208. RESTORE_ALL
  209. .globl _int_handler
  210. _int_handler:
  211. SAVE_ALL
  212. movel %sp,%sp@-
  213. bsr int_handler
  214. addql #4,%sp
  215. RESTORE_ALL
  216. /*------------------------------------------------------------------------------*/
  217. .globl version_string
  218. version_string:
  219. .ascii U_BOOT_VERSION_STRING, "\0"
  220. .align 4