start.S 7.5 KB

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