start.S 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. /*
  2. * Copyright (C) 2003 Josef Baumgartner <josef.baumgartner@telex.de>
  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. #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 we come from a pre-loader we don't need an initial exception
  25. * table.
  26. */
  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. .long 0x00000000 /* Flash offset is 0 until we setup CS0 */
  35. #if defined(CONFIG_M5282) && (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. #if defined(CONFIG_SYS_INT_FLASH_BASE) && \
  75. (defined(CONFIG_M5282) || defined(CONFIG_M5281))
  76. #if (CONFIG_SYS_TEXT_BASE == CONFIG_SYS_INT_FLASH_BASE)
  77. .long 0x55AA55AA,0xAA55AA55 /* CFM Backdoorkey */
  78. .long 0xFFFFFFFF /* all sectors protected */
  79. .long 0x00000000 /* supervisor/User restriction */
  80. .long 0x00000000 /* programm/data space restriction */
  81. .long 0x00000000 /* Flash security */
  82. #endif
  83. #endif
  84. .globl _start
  85. _start:
  86. nop
  87. nop
  88. move.w #0x2700,%sr
  89. #if defined(CONFIG_M5208)
  90. /* Initialize RAMBAR: locate SRAM and validate it */
  91. move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0
  92. movec %d0, %RAMBAR1
  93. #endif
  94. #if defined(CONFIG_M5272) || defined(CONFIG_M5249) || defined(CONFIG_M5253)
  95. move.l #(CONFIG_SYS_MBAR + 1), %d0 /* set MBAR address + valid flag */
  96. move.c %d0, %MBAR
  97. /*** The 5249 has MBAR2 as well ***/
  98. #ifdef CONFIG_SYS_MBAR2
  99. move.l #(CONFIG_SYS_MBAR2 + 1), %d0 /* Get MBAR2 address */
  100. movec %d0, #0xc0e /* Set MBAR2 */
  101. #endif
  102. move.l #(CONFIG_SYS_INIT_RAM_ADDR + 1), %d0
  103. movec %d0, %RAMBAR0
  104. #endif /* CONFIG_M5272 || CONFIG_M5249 || CONFIG_M5253 */
  105. #if defined(CONFIG_M5282) || defined(CONFIG_M5271)
  106. /* Initialize IPSBAR */
  107. move.l #(CONFIG_SYS_MBAR + 1), %d0 /* set IPSBAR address + valid flag */
  108. move.l %d0, 0x40000000
  109. /* Initialize RAMBAR1: locate SRAM and validate it */
  110. move.l #(CONFIG_SYS_INIT_RAM_ADDR + 0x21), %d0
  111. movec %d0, %RAMBAR1
  112. #if defined(CONFIG_M5282)
  113. #if (CONFIG_SYS_TEXT_BASE == CONFIG_SYS_INT_FLASH_BASE)
  114. /* Setup code in SRAM to initialize FLASHBAR, if start from internal Flash */
  115. move.l #(_flashbar_setup-CONFIG_SYS_INT_FLASH_BASE), %a0
  116. move.l #(_flashbar_setup_end-CONFIG_SYS_INT_FLASH_BASE), %a1
  117. move.l #(CONFIG_SYS_INIT_RAM_ADDR), %a2
  118. _copy_flash:
  119. move.l (%a0)+, (%a2)+
  120. cmp.l %a0, %a1
  121. bgt.s _copy_flash
  122. jmp CONFIG_SYS_INIT_RAM_ADDR
  123. _flashbar_setup:
  124. /* Initialize FLASHBAR: locate internal Flash and validate it */
  125. move.l #(CONFIG_SYS_INT_FLASH_BASE + CONFIG_SYS_INT_FLASH_ENABLE), %d0
  126. movec %d0, %FLASHBAR
  127. jmp _after_flashbar_copy.L /* Force jump to absolute address */
  128. _flashbar_setup_end:
  129. nop
  130. _after_flashbar_copy:
  131. #else
  132. /* Setup code to initialize FLASHBAR, if start from external Memory */
  133. move.l #(CONFIG_SYS_INT_FLASH_BASE + CONFIG_SYS_INT_FLASH_ENABLE), %d0
  134. movec %d0, %FLASHBAR
  135. #endif /* (CONFIG_SYS_TEXT_BASE == CONFIG_SYS_INT_FLASH_BASE) */
  136. #endif
  137. #endif
  138. /* if we come from a pre-loader we have no exception table and
  139. * therefore no VBR to set
  140. */
  141. #if !defined(CONFIG_MONITOR_IS_IN_RAM)
  142. #if defined(CONFIG_M5282) && (CONFIG_SYS_TEXT_BASE == CONFIG_SYS_INT_FLASH_BASE)
  143. move.l #CONFIG_SYS_INT_FLASH_BASE, %d0
  144. #else
  145. move.l #CONFIG_SYS_FLASH_BASE, %d0
  146. #endif
  147. movec %d0, %VBR
  148. #endif
  149. #ifdef CONFIG_M5275
  150. /* Initialize IPSBAR */
  151. move.l #(CONFIG_SYS_MBAR + 1), %d0 /* set IPSBAR address + valid flag */
  152. move.l %d0, 0x40000000
  153. /* movec %d0, %MBAR */
  154. /* Initialize RAMBAR: locate SRAM and validate it */
  155. move.l #(CONFIG_SYS_INIT_RAM_ADDR + 0x21), %d0
  156. movec %d0, %RAMBAR1
  157. #endif
  158. /* initialize general use internal ram */
  159. move.l #0, %d0
  160. move.l #(ICACHE_STATUS), %a1 /* icache */
  161. move.l #(DCACHE_STATUS), %a2 /* icache */
  162. move.l %d0, (%a1)
  163. move.l %d0, (%a2)
  164. /* set stackpointer to end of internal ram to get some stackspace for the first c-code */
  165. move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET), %sp
  166. clr.l %sp@-
  167. move.l #__got_start, %a5 /* put relocation table address to a5 */
  168. bsr cpu_init_f /* run low-level CPU init code (from flash) */
  169. bsr board_init_f /* run low-level board init code (from flash) */
  170. /* board_init_f() does not return */
  171. /*------------------------------------------------------------------------------*/
  172. /*
  173. * void relocate_code (addr_sp, gd, addr_moni)
  174. *
  175. * This "function" does not return, instead it continues in RAM
  176. * after relocating the monitor code.
  177. *
  178. * r3 = dest
  179. * r4 = src
  180. * r5 = length in bytes
  181. * r6 = cachelinesize
  182. */
  183. .globl relocate_code
  184. relocate_code:
  185. link.w %a6,#0
  186. move.l 8(%a6), %sp /* set new stack pointer */
  187. move.l 12(%a6), %d0 /* Save copy of Global Data pointer */
  188. move.l 16(%a6), %a0 /* Save copy of Destination Address */
  189. move.l #CONFIG_SYS_MONITOR_BASE, %a1
  190. move.l #__init_end, %a2
  191. move.l %a0, %a3
  192. /* copy the code to RAM */
  193. 1:
  194. move.l (%a1)+, (%a3)+
  195. cmp.l %a1,%a2
  196. bgt.s 1b
  197. /*
  198. * We are done. Do not return, instead branch to second part of board
  199. * initialization, now running from RAM.
  200. */
  201. move.l %a0, %a1
  202. add.l #(in_ram - CONFIG_SYS_MONITOR_BASE), %a1
  203. jmp (%a1)
  204. in_ram:
  205. clear_bss:
  206. /*
  207. * Now clear BSS segment
  208. */
  209. move.l %a0, %a1
  210. add.l #(_sbss - CONFIG_SYS_MONITOR_BASE),%a1
  211. move.l %a0, %d1
  212. add.l #(_ebss - CONFIG_SYS_MONITOR_BASE),%d1
  213. 6:
  214. clr.l (%a1)+
  215. cmp.l %a1,%d1
  216. bgt.s 6b
  217. /*
  218. * fix got table in RAM
  219. */
  220. move.l %a0, %a1
  221. add.l #(__got_start - CONFIG_SYS_MONITOR_BASE),%a1
  222. move.l %a1,%a5 /* * fix got pointer register a5 */
  223. move.l %a0, %a2
  224. add.l #(__got_end - CONFIG_SYS_MONITOR_BASE),%a2
  225. 7:
  226. move.l (%a1),%d1
  227. sub.l #_start,%d1
  228. add.l %a0,%d1
  229. move.l %d1,(%a1)+
  230. cmp.l %a2, %a1
  231. bne 7b
  232. /* calculate relative jump to board_init_r in ram */
  233. move.l %a0, %a1
  234. add.l #(board_init_r - CONFIG_SYS_MONITOR_BASE), %a1
  235. /* set parameters for board_init_r */
  236. move.l %a0,-(%sp) /* dest_addr */
  237. move.l %d0,-(%sp) /* gd */
  238. #if defined(DEBUG) && (CONFIG_SYS_TEXT_BASE != CONFIG_SYS_INT_FLASH_BASE) && \
  239. defined(CONFIG_SYS_HALT_BEFOR_RAM_JUMP)
  240. halt
  241. #endif
  242. jsr (%a1)
  243. /*------------------------------------------------------------------------------*/
  244. /* exception code */
  245. .globl _fault
  246. _fault:
  247. bra _fault
  248. .globl _exc_handler
  249. _exc_handler:
  250. SAVE_ALL
  251. movel %sp,%sp@-
  252. bsr exc_handler
  253. addql #4,%sp
  254. RESTORE_ALL
  255. .globl _int_handler
  256. _int_handler:
  257. SAVE_ALL
  258. movel %sp,%sp@-
  259. bsr int_handler
  260. addql #4,%sp
  261. RESTORE_ALL
  262. /*------------------------------------------------------------------------------*/
  263. .globl version_string
  264. version_string:
  265. .ascii U_BOOT_VERSION_STRING, "\0"
  266. .align 4