start.S 7.0 KB

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