start.S 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /*
  2. * (C) Copyright 2015 Angelo Dureghello <angelo@sysam.it>
  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. .macro 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. .endm
  21. .macro RESTORE_ALL
  22. moveml %sp@,%d0-%d7/%a0-%a6;
  23. addl #60,%sp; /* space for 15 regs */
  24. rte
  25. .endm
  26. /* If we come from a pre-loader we don't need an initial exception
  27. * table.
  28. */
  29. #if !defined(CONFIG_MONITOR_IS_IN_RAM)
  30. .text
  31. /*
  32. * Vector table. This is used for initial platform startup.
  33. * These vectors are to catch any un-intended traps.
  34. */
  35. _vectors:
  36. /* Flash offset is 0 until we setup CS0 */
  37. .long 0x00000000
  38. #if defined(CONFIG_M5307) && \
  39. (CONFIG_SYS_TEXT_BASE == CONFIG_SYS_INT_FLASH_BASE)
  40. .long _start - CONFIG_SYS_TEXT_BASE
  41. #else
  42. .long _START
  43. #endif
  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, _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
  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. .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
  77. .text
  78. .globl _start
  79. _start:
  80. nop
  81. nop
  82. move.w #0x2700,%sr
  83. /* set MBAR address + valid flag */
  84. move.l #(CONFIG_SYS_MBAR + 1), %d0
  85. move.c %d0, %MBAR
  86. move.l #(CONFIG_SYS_INIT_RAM_ADDR + 1), %d0
  87. move.c %d0, %RAMBAR
  88. /* DS 4.8.2 (Cache Organization) invalidate and disable cache */
  89. move.l #CF_CACR_CINVA, %d0
  90. movec %d0, %CACR
  91. move.l #0, %d0
  92. movec %d0, %ACR0
  93. movec %d0, %ACR1
  94. /*
  95. * if we come from a pre-loader we have no exception table and
  96. * therefore no VBR to set
  97. */
  98. #if !defined(CONFIG_MONITOR_IS_IN_RAM)
  99. move.l #CONFIG_SYS_FLASH_BASE, %d0
  100. movec %d0, %VBR
  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 /* dcache */
  106. move.l %d0, (%a1)
  107. move.l %d0, (%a2)
  108. /*
  109. * set stackpointer to internal sram end - 80
  110. * (global data struct size + some bytes)
  111. * get some stackspace for the first c-code,
  112. */
  113. move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET), %sp
  114. clr.l %sp@-
  115. /* put relocation table address to a5 */
  116. move.l #__got_start, %a5
  117. /* run low-level CPU init code (from flash) */
  118. bsr cpu_init_f
  119. /* run low-level board init code (from flash) */
  120. bsr board_init_f
  121. /* board_init_f() does not return */
  122. /*--------------------------------------------------------------------------*/
  123. /*
  124. * void relocate_code (addr_sp, gd, addr_moni)
  125. *
  126. * This "function" does not return, instead it continues in RAM
  127. * after relocating the monitor code.
  128. *
  129. */
  130. .globl relocate_code
  131. relocate_code:
  132. link.w %a6,#0
  133. move.l 8(%a6), %sp /* set new stack pointer */
  134. move.l 12(%a6), %d0 /* Save copy of Global Data pointer */
  135. move.l 16(%a6), %a0 /* Save copy of Destination Address */
  136. move.l #CONFIG_SYS_MONITOR_BASE, %a1
  137. move.l #__init_end, %a2
  138. move.l %a0, %a3
  139. /* copy the code to RAM */
  140. 1:
  141. move.l (%a1)+, (%a3)+
  142. cmp.l %a1,%a2
  143. bgt.s 1b
  144. /*
  145. * We are done. Do not return, instead branch to second part of board
  146. * initialization, now running from RAM.
  147. */
  148. move.l %a0, %a1
  149. add.l #(in_ram - CONFIG_SYS_MONITOR_BASE), %a1
  150. jmp (%a1)
  151. in_ram:
  152. clear_bss:
  153. /*
  154. * Now clear BSS segment
  155. */
  156. move.l %a0, %a1
  157. add.l #(_sbss - CONFIG_SYS_MONITOR_BASE), %a1
  158. move.l %a0, %d1
  159. add.l #(_ebss - CONFIG_SYS_MONITOR_BASE), %d1
  160. 6:
  161. clr.l (%a1)+
  162. cmp.l %a1,%d1
  163. bgt.s 6b
  164. /*
  165. * fix got table in RAM
  166. */
  167. move.l %a0, %a1
  168. add.l #(__got_start - CONFIG_SYS_MONITOR_BASE), %a1
  169. /* * fix got pointer register a5 */
  170. move.l %a1,%a5
  171. move.l %a0, %a2
  172. add.l #(__got_end - CONFIG_SYS_MONITOR_BASE), %a2
  173. 7:
  174. move.l (%a1),%d1
  175. sub.l #_start, %d1
  176. add.l %a0,%d1
  177. move.l %d1,(%a1)+
  178. cmp.l %a2, %a1
  179. bne 7b
  180. /* calculate relative jump to board_init_r in ram */
  181. move.l %a0, %a1
  182. add.l #(board_init_r - CONFIG_SYS_MONITOR_BASE), %a1
  183. /* set parameters for board_init_r */
  184. move.l %a0,-(%sp) /* dest_addr */
  185. move.l %d0,-(%sp) /* gd */
  186. #if defined(DEBUG) && (CONFIG_SYS_TEXT_BASE!=CONFIG_SYS_INT_FLASH_BASE) && \
  187. defined(CONFIG_SYS_HALT_BEFOR_RAM_JUMP)
  188. halt
  189. #endif
  190. jsr (%a1)
  191. /*--------------------------------------------------------------------------*/
  192. /* exception code */
  193. .globl _fault
  194. _fault:
  195. bra _fault
  196. .globl _exc_handler
  197. _exc_handler:
  198. SAVE_ALL
  199. movel %sp,%sp@-
  200. bsr exc_handler
  201. addql #4,%sp
  202. RESTORE_ALL
  203. .globl _int_handler
  204. _int_handler:
  205. SAVE_ALL
  206. movel %sp,%sp@-
  207. bsr int_handler
  208. addql #4,%sp
  209. RESTORE_ALL
  210. /*--------------------------------------------------------------------------*/
  211. .globl version_string
  212. version_string:
  213. .ascii U_BOOT_VERSION
  214. .ascii " (", U_BOOT_DATE, " - ", U_BOOT_TIME, ")"
  215. .ascii CONFIG_IDENT_STRING, "\0"
  216. .align 4