start.S 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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. #define _START _start
  12. #define _FAULT _fault
  13. #define SAVE_ALL \
  14. move.w #0x2700,%sr; /* disable intrs */ \
  15. subl #60,%sp; /* space for 15 regs */ \
  16. moveml %d0-%d7/%a0-%a6,%sp@; \
  17. #define RESTORE_ALL \
  18. moveml %sp@,%d0-%d7/%a0-%a6; \
  19. addl #60,%sp; /* space for 15 regs */ \
  20. rte
  21. /* If we come from a pre-loader we don't need an initial exception
  22. * table.
  23. */
  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. .long 0x00000000 /* Flash offset is 0 until we setup CS0 */
  32. #if defined(CONFIG_M5282) && (CONFIG_SYS_TEXT_BASE == CONFIG_SYS_INT_FLASH_BASE)
  33. .long _start - CONFIG_SYS_TEXT_BASE
  34. #else
  35. .long _START
  36. #endif
  37. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  38. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  39. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  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
  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, _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. #endif
  70. .text
  71. #if defined(CONFIG_SYS_INT_FLASH_BASE) && \
  72. (defined(CONFIG_M5282) || defined(CONFIG_M5281))
  73. #if (CONFIG_SYS_TEXT_BASE == CONFIG_SYS_INT_FLASH_BASE)
  74. .long 0x55AA55AA,0xAA55AA55 /* CFM Backdoorkey */
  75. .long 0xFFFFFFFF /* all sectors protected */
  76. .long 0x00000000 /* supervisor/User restriction */
  77. .long 0x00000000 /* programm/data space restriction */
  78. .long 0x00000000 /* Flash security */
  79. #endif
  80. #endif
  81. .globl _start
  82. _start:
  83. nop
  84. nop
  85. move.w #0x2700,%sr
  86. #if defined(CONFIG_M5208)
  87. /* Initialize RAMBAR: locate SRAM and validate it */
  88. move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0
  89. movec %d0, %RAMBAR1
  90. #endif
  91. #if defined(CONFIG_M5272) || defined(CONFIG_M5249) || defined(CONFIG_M5253)
  92. /* set MBAR address + valid flag */
  93. move.l #(CONFIG_SYS_MBAR + 1), %d0
  94. move.c %d0, %MBAR
  95. /*** The 5249 has MBAR2 as well ***/
  96. #ifdef CONFIG_SYS_MBAR2
  97. /* Get MBAR2 address */
  98. move.l #(CONFIG_SYS_MBAR2 + 1), %d0
  99. /* Set MBAR2 */
  100. movec %d0, #0xc0e
  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. /* set MBAR address + valid flag */
  107. move.l #(CONFIG_SYS_MBAR + 1), %d0
  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. /*
  115. * Setup code in SRAM to initialize FLASHBAR,
  116. * if start from internal Flash
  117. */
  118. move.l #(_flashbar_setup-CONFIG_SYS_INT_FLASH_BASE), %a0
  119. move.l #(_flashbar_setup_end-CONFIG_SYS_INT_FLASH_BASE), %a1
  120. move.l #(CONFIG_SYS_INIT_RAM_ADDR), %a2
  121. _copy_flash:
  122. move.l (%a0)+, (%a2)+
  123. cmp.l %a0, %a1
  124. bgt.s _copy_flash
  125. jmp CONFIG_SYS_INIT_RAM_ADDR
  126. _flashbar_setup:
  127. /* Initialize FLASHBAR: locate internal Flash and validate it */
  128. move.l #(CONFIG_SYS_INT_FLASH_BASE + CONFIG_SYS_INT_FLASH_ENABLE), %d0
  129. movec %d0, %FLASHBAR
  130. jmp _after_flashbar_copy.L /* Force jump to absolute address */
  131. _flashbar_setup_end:
  132. nop
  133. _after_flashbar_copy:
  134. #else
  135. /* Setup code to initialize FLASHBAR, if start from external Memory */
  136. move.l #(CONFIG_SYS_INT_FLASH_BASE + CONFIG_SYS_INT_FLASH_ENABLE), %d0
  137. movec %d0, %FLASHBAR
  138. #endif /* (CONFIG_SYS_TEXT_BASE == CONFIG_SYS_INT_FLASH_BASE) */
  139. #endif
  140. #endif
  141. /*
  142. * if we come from a pre-loader we have no exception table and
  143. * therefore no VBR to set
  144. */
  145. #if !defined(CONFIG_MONITOR_IS_IN_RAM)
  146. #if defined(CONFIG_M5282) && (CONFIG_SYS_TEXT_BASE == CONFIG_SYS_INT_FLASH_BASE)
  147. move.l #CONFIG_SYS_INT_FLASH_BASE, %d0
  148. #else
  149. move.l #CONFIG_SYS_FLASH_BASE, %d0
  150. #endif
  151. movec %d0, %VBR
  152. #endif
  153. #ifdef CONFIG_M5275
  154. /* set MBAR address + valid flag */
  155. move.l #(CONFIG_SYS_MBAR + 1), %d0
  156. move.l %d0, 0x40000000
  157. /* movec %d0, %MBAR */
  158. /* Initialize RAMBAR: locate SRAM and validate it */
  159. move.l #(CONFIG_SYS_INIT_RAM_ADDR + 0x21), %d0
  160. movec %d0, %RAMBAR1
  161. #endif
  162. /* initialize general use internal ram */
  163. move.l #0, %d0
  164. move.l #(ICACHE_STATUS), %a1 /* icache */
  165. move.l #(DCACHE_STATUS), %a2 /* icache */
  166. move.l %d0, (%a1)
  167. move.l %d0, (%a2)
  168. /* put relocation table address to a5 */
  169. move.l #__got_start, %a5
  170. /* setup stack initially on top of internal static ram */
  171. move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_SIZE), %sp
  172. /*
  173. * if configured, malloc_f arena will be reserved first,
  174. * then (and always) gd struct space will be reserved
  175. */
  176. move.l %sp, -(%sp)
  177. move.l #board_init_f_alloc_reserve, %a1
  178. jsr (%a1)
  179. /* update stack and frame-pointers */
  180. move.l %d0, %sp
  181. move.l %sp, %fp
  182. /* initialize reserved area */
  183. move.l %d0, -(%sp)
  184. move.l #board_init_f_init_reserve, %a1
  185. jsr (%a1)
  186. /* run low-level CPU init code (from flash) */
  187. move.l #cpu_init_f, %a1
  188. jsr (%a1)
  189. /* run low-level board init code (from flash) */
  190. clr.l %sp@-
  191. move.l #board_init_f, %a1
  192. jsr (%a1)
  193. /* board_init_f() does not return */
  194. /******************************************************************************/
  195. /*
  196. * void relocate_code (addr_sp, gd, addr_moni)
  197. *
  198. * This "function" does not return, instead it continues in RAM
  199. * after relocating the monitor code.
  200. *
  201. * r3 = dest
  202. * r4 = src
  203. * r5 = length in bytes
  204. * r6 = cachelinesize
  205. */
  206. .globl relocate_code
  207. relocate_code:
  208. link.w %a6,#0
  209. move.l 8(%a6), %sp /* set new stack pointer */
  210. move.l 12(%a6), %d0 /* Save copy of Global Data pointer */
  211. move.l 16(%a6), %a0 /* Save copy of Destination Address */
  212. move.l #CONFIG_SYS_MONITOR_BASE, %a1
  213. move.l #__init_end, %a2
  214. move.l %a0, %a3
  215. /* copy the code to RAM */
  216. 1:
  217. move.l (%a1)+, (%a3)+
  218. cmp.l %a1,%a2
  219. bgt.s 1b
  220. /*
  221. * We are done. Do not return, instead branch to second part of board
  222. * initialization, now running from RAM.
  223. */
  224. move.l %a0, %a1
  225. add.l #(in_ram - CONFIG_SYS_MONITOR_BASE), %a1
  226. jmp (%a1)
  227. in_ram:
  228. clear_bss:
  229. /*
  230. * Now clear BSS segment
  231. */
  232. move.l %a0, %a1
  233. add.l #(_sbss - CONFIG_SYS_MONITOR_BASE),%a1
  234. move.l %a0, %d1
  235. add.l #(_ebss - CONFIG_SYS_MONITOR_BASE),%d1
  236. 6:
  237. clr.l (%a1)+
  238. cmp.l %a1,%d1
  239. bgt.s 6b
  240. /*
  241. * fix got table in RAM
  242. */
  243. move.l %a0, %a1
  244. add.l #(__got_start - CONFIG_SYS_MONITOR_BASE),%a1
  245. move.l %a1,%a5 /* fix got pointer register a5 */
  246. move.l %a0, %a2
  247. add.l #(__got_end - CONFIG_SYS_MONITOR_BASE),%a2
  248. 7:
  249. move.l (%a1),%d1
  250. sub.l #_start,%d1
  251. add.l %a0,%d1
  252. move.l %d1,(%a1)+
  253. cmp.l %a2, %a1
  254. bne 7b
  255. /* calculate relative jump to board_init_r in ram */
  256. move.l %a0, %a1
  257. add.l #(board_init_r - CONFIG_SYS_MONITOR_BASE), %a1
  258. /* set parameters for board_init_r */
  259. move.l %a0,-(%sp) /* dest_addr */
  260. move.l %d0,-(%sp) /* gd */
  261. #if defined(DEBUG) && (CONFIG_SYS_TEXT_BASE != CONFIG_SYS_INT_FLASH_BASE) && \
  262. defined(CONFIG_SYS_HALT_BEFOR_RAM_JUMP)
  263. halt
  264. #endif
  265. jsr (%a1)
  266. /******************************************************************************/
  267. /* exception code */
  268. .globl _fault
  269. _fault:
  270. bra _fault
  271. .globl _exc_handler
  272. _exc_handler:
  273. SAVE_ALL
  274. movel %sp,%sp@-
  275. bsr exc_handler
  276. addql #4,%sp
  277. RESTORE_ALL
  278. .globl _int_handler
  279. _int_handler:
  280. SAVE_ALL
  281. movel %sp,%sp@-
  282. bsr int_handler
  283. addql #4,%sp
  284. RESTORE_ALL
  285. /******************************************************************************/
  286. .globl version_string
  287. version_string:
  288. .ascii U_BOOT_VERSION_STRING, "\0"
  289. .align 4