start.S 7.0 KB

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