start.S 9.3 KB

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