start.S 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * (C) Copyright 2015 Angelo Dureghello <angelo@sysam.it>
  4. * Based on code from Bernhard Kuhn <bkuhn@metrowerks.com>
  5. */
  6. #include <asm-offsets.h>
  7. #include <config.h>
  8. #include "version.h"
  9. #include <asm/cache.h>
  10. #define _START _start
  11. #define _FAULT _fault
  12. .macro SAVE_ALL
  13. move.w #0x2700,%sr; /* disable intrs */
  14. subl #60,%sp; /* space for 15 regs */
  15. moveml %d0-%d7/%a0-%a6,%sp@
  16. .endm
  17. .macro RESTORE_ALL
  18. moveml %sp@,%d0-%d7/%a0-%a6;
  19. addl #60,%sp; /* space for 15 regs */
  20. rte
  21. .endm
  22. /* If we come from a pre-loader we don't need an initial exception
  23. * table.
  24. */
  25. #if !defined(CONFIG_MONITOR_IS_IN_RAM)
  26. .text
  27. /*
  28. * Vector table. This is used for initial platform startup.
  29. * These vectors are to catch any un-intended traps.
  30. */
  31. _vectors:
  32. /* Flash offset is 0 until we setup CS0 */
  33. .long 0x00000000
  34. #if defined(CONFIG_M5307) && \
  35. (CONFIG_SYS_TEXT_BASE == CONFIG_SYS_INT_FLASH_BASE)
  36. .long _start - CONFIG_SYS_TEXT_BASE
  37. #else
  38. .long _START
  39. #endif
  40. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  41. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  42. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  43. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  44. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  45. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  46. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  47. .long _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. .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. .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. .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. #endif
  73. .text
  74. .globl _start
  75. _start:
  76. nop
  77. nop
  78. move.w #0x2700,%sr
  79. /* set MBAR address + valid flag */
  80. move.l #(CONFIG_SYS_MBAR + 1), %d0
  81. move.c %d0, %MBAR
  82. move.l #(CONFIG_SYS_INIT_RAM_ADDR + 1), %d0
  83. move.c %d0, %RAMBAR
  84. /* DS 4.8.2 (Cache Organization) invalidate and disable cache */
  85. move.l #CF_CACR_CINVA, %d0
  86. movec %d0, %CACR
  87. move.l #0, %d0
  88. movec %d0, %ACR0
  89. movec %d0, %ACR1
  90. /*
  91. * if we come from a pre-loader we have no exception table and
  92. * therefore no VBR to set
  93. */
  94. #if !defined(CONFIG_MONITOR_IS_IN_RAM)
  95. move.l #CONFIG_SYS_FLASH_BASE, %d0
  96. movec %d0, %VBR
  97. #endif
  98. /* initialize general use internal ram */
  99. move.l #0, %d0
  100. move.l #(ICACHE_STATUS), %a1 /* icache */
  101. move.l #(DCACHE_STATUS), %a2 /* dcache */
  102. move.l %d0, (%a1)
  103. move.l %d0, (%a2)
  104. /* put relocation table address to a5 */
  105. move.l #__got_start, %a5
  106. /* setup stack initially on top of internal static ram */
  107. move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_SIZE), %sp
  108. /*
  109. * if configured, malloc_f arena will be reserved first,
  110. * then (and always) gd struct space will be reserved
  111. */
  112. move.l %sp, -(%sp)
  113. bsr board_init_f_alloc_reserve
  114. /* update stack and frame-pointers */
  115. move.l %d0, %sp
  116. move.l %sp, %fp
  117. /* initialize reserved area */
  118. move.l %d0, -(%sp)
  119. bsr board_init_f_init_reserve
  120. /* run low-level CPU init code (from flash) */
  121. bsr cpu_init_f
  122. /* run low-level board init code (from flash) */
  123. clr.l %sp@-
  124. bsr board_init_f
  125. /* board_init_f() does not return */
  126. /******************************************************************************/
  127. /*
  128. * void relocate_code(addr_sp, gd, addr_moni)
  129. *
  130. * This "function" does not return, instead it continues in RAM
  131. * after relocating the monitor code.
  132. *
  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. /* fix got pointer register a5 */
  174. move.l %a1,%a5
  175. move.l %a0, %a2
  176. add.l #(__got_end - CONFIG_SYS_MONITOR_BASE), %a2
  177. 7:
  178. move.l (%a1),%d1
  179. sub.l #_start, %d1
  180. add.l %a0,%d1
  181. move.l %d1,(%a1)+
  182. cmp.l %a2, %a1
  183. bne 7b
  184. /* calculate relative jump to board_init_r in ram */
  185. move.l %a0, %a1
  186. add.l #(board_init_r - CONFIG_SYS_MONITOR_BASE), %a1
  187. /* set parameters for board_init_r */
  188. move.l %a0,-(%sp) /* dest_addr */
  189. move.l %d0,-(%sp) /* gd */
  190. #if defined(DEBUG) && (CONFIG_SYS_TEXT_BASE!=CONFIG_SYS_INT_FLASH_BASE) && \
  191. defined(CONFIG_SYS_HALT_BEFOR_RAM_JUMP)
  192. halt
  193. #endif
  194. jsr (%a1)
  195. /******************************************************************************/
  196. /* exception code */
  197. .globl _fault
  198. _fault:
  199. bra _fault
  200. .globl _exc_handler
  201. _exc_handler:
  202. SAVE_ALL
  203. movel %sp,%sp@-
  204. bsr exc_handler
  205. addql #4,%sp
  206. RESTORE_ALL
  207. .globl _int_handler
  208. _int_handler:
  209. SAVE_ALL
  210. movel %sp,%sp@-
  211. bsr int_handler
  212. addql #4,%sp
  213. RESTORE_ALL
  214. /******************************************************************************/
  215. .globl version_string
  216. version_string:
  217. .ascii U_BOOT_VERSION
  218. .ascii " (", U_BOOT_DATE, " - ", U_BOOT_TIME, ")"
  219. .ascii CONFIG_IDENT_STRING, "\0"
  220. .align 4