start.S 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. /*
  2. * Copyright (C) 2003 Josef Baumgartner <josef.baumgartner@telex.de>
  3. * Based on code from Bernhard Kuhn <bkuhn@metrowerks.com>
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <asm-offsets.h>
  24. #include <config.h>
  25. #include <timestamp.h>
  26. #include "version.h"
  27. #include <asm/cache.h>
  28. #ifndef CONFIG_IDENT_STRING
  29. #define CONFIG_IDENT_STRING ""
  30. #endif
  31. #define _START _start
  32. #define _FAULT _fault
  33. #define SAVE_ALL \
  34. move.w #0x2700,%sr; /* disable intrs */ \
  35. subl #60,%sp; /* space for 15 regs */ \
  36. moveml %d0-%d7/%a0-%a6,%sp@; \
  37. #define RESTORE_ALL \
  38. moveml %sp@,%d0-%d7/%a0-%a6; \
  39. addl #60,%sp; /* space for 15 regs */ \
  40. rte
  41. /* If we come from a pre-loader we don't need an initial exception
  42. * table.
  43. */
  44. #if !defined(CONFIG_MONITOR_IS_IN_RAM)
  45. .text
  46. /*
  47. * Vector table. This is used for initial platform startup.
  48. * These vectors are to catch any un-intended traps.
  49. */
  50. _vectors:
  51. .long 0x00000000 /* Flash offset is 0 until we setup CS0 */
  52. #if defined(CONFIG_M5282) && (CONFIG_SYS_TEXT_BASE == CONFIG_SYS_INT_FLASH_BASE)
  53. .long _start - CONFIG_SYS_TEXT_BASE
  54. #else
  55. .long _START
  56. #endif
  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
  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. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  77. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  78. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  79. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  80. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  81. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  82. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  83. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  84. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  85. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  86. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  87. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  88. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  89. #endif
  90. .text
  91. #if defined(CONFIG_SYS_INT_FLASH_BASE) && \
  92. (defined(CONFIG_M5282) || defined(CONFIG_M5281))
  93. #if (CONFIG_SYS_TEXT_BASE == CONFIG_SYS_INT_FLASH_BASE)
  94. .long 0x55AA55AA,0xAA55AA55 /* CFM Backdoorkey */
  95. .long 0xFFFFFFFF /* all sectors protected */
  96. .long 0x00000000 /* supervisor/User restriction */
  97. .long 0x00000000 /* programm/data space restriction */
  98. .long 0x00000000 /* Flash security */
  99. #endif
  100. #endif
  101. .globl _start
  102. _start:
  103. nop
  104. nop
  105. move.w #0x2700,%sr
  106. #if defined(CONFIG_M5208)
  107. /* Initialize RAMBAR: locate SRAM and validate it */
  108. move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0
  109. movec %d0, %RAMBAR1
  110. #endif
  111. #if defined(CONFIG_M5272) || defined(CONFIG_M5249) || defined(CONFIG_M5253)
  112. move.l #(CONFIG_SYS_MBAR + 1), %d0 /* set MBAR address + valid flag */
  113. move.c %d0, %MBAR
  114. /*** The 5249 has MBAR2 as well ***/
  115. #ifdef CONFIG_SYS_MBAR2
  116. move.l #(CONFIG_SYS_MBAR2 + 1), %d0 /* Get MBAR2 address */
  117. movec %d0, #0xc0e /* Set MBAR2 */
  118. #endif
  119. move.l #(CONFIG_SYS_INIT_RAM_ADDR + 1), %d0
  120. movec %d0, %RAMBAR0
  121. #endif /* CONFIG_M5272 || CONFIG_M5249 || CONFIG_M5253 */
  122. #if defined(CONFIG_M5282) || defined(CONFIG_M5271)
  123. /* Initialize IPSBAR */
  124. move.l #(CONFIG_SYS_MBAR + 1), %d0 /* set IPSBAR address + valid flag */
  125. move.l %d0, 0x40000000
  126. /* Initialize RAMBAR1: locate SRAM and validate it */
  127. move.l #(CONFIG_SYS_INIT_RAM_ADDR + 0x21), %d0
  128. movec %d0, %RAMBAR1
  129. #if defined(CONFIG_M5282)
  130. #if (CONFIG_SYS_TEXT_BASE == CONFIG_SYS_INT_FLASH_BASE)
  131. /* Setup code in SRAM to initialize FLASHBAR, if start from internal Flash */
  132. move.l #(_flashbar_setup-CONFIG_SYS_INT_FLASH_BASE), %a0
  133. move.l #(_flashbar_setup_end-CONFIG_SYS_INT_FLASH_BASE), %a1
  134. move.l #(CONFIG_SYS_INIT_RAM_ADDR), %a2
  135. _copy_flash:
  136. move.l (%a0)+, (%a2)+
  137. cmp.l %a0, %a1
  138. bgt.s _copy_flash
  139. jmp CONFIG_SYS_INIT_RAM_ADDR
  140. _flashbar_setup:
  141. /* Initialize FLASHBAR: locate internal Flash and validate it */
  142. move.l #(CONFIG_SYS_INT_FLASH_BASE + CONFIG_SYS_INT_FLASH_ENABLE), %d0
  143. movec %d0, %FLASHBAR
  144. jmp _after_flashbar_copy.L /* Force jump to absolute address */
  145. _flashbar_setup_end:
  146. nop
  147. _after_flashbar_copy:
  148. #else
  149. /* Setup code to initialize FLASHBAR, if start from external Memory */
  150. move.l #(CONFIG_SYS_INT_FLASH_BASE + CONFIG_SYS_INT_FLASH_ENABLE), %d0
  151. movec %d0, %FLASHBAR
  152. #endif /* (CONFIG_SYS_TEXT_BASE == CONFIG_SYS_INT_FLASH_BASE) */
  153. #endif
  154. #endif
  155. /* if we come from a pre-loader we have no exception table and
  156. * therefore no VBR to set
  157. */
  158. #if !defined(CONFIG_MONITOR_IS_IN_RAM)
  159. #if defined(CONFIG_M5282) && (CONFIG_SYS_TEXT_BASE == CONFIG_SYS_INT_FLASH_BASE)
  160. move.l #CONFIG_SYS_INT_FLASH_BASE, %d0
  161. #else
  162. move.l #CONFIG_SYS_FLASH_BASE, %d0
  163. #endif
  164. movec %d0, %VBR
  165. #endif
  166. #ifdef CONFIG_M5275
  167. /* Initialize IPSBAR */
  168. move.l #(CONFIG_SYS_MBAR + 1), %d0 /* set IPSBAR address + valid flag */
  169. move.l %d0, 0x40000000
  170. /* movec %d0, %MBAR */
  171. /* Initialize RAMBAR: locate SRAM and validate it */
  172. move.l #(CONFIG_SYS_INIT_RAM_ADDR + 0x21), %d0
  173. movec %d0, %RAMBAR1
  174. #endif
  175. /* initialize general use internal ram */
  176. move.l #0, %d0
  177. move.l #(ICACHE_STATUS), %a1 /* icache */
  178. move.l #(DCACHE_STATUS), %a2 /* icache */
  179. move.l %d0, (%a1)
  180. move.l %d0, (%a2)
  181. /* set stackpointer to end of internal ram to get some stackspace for the first c-code */
  182. move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET), %sp
  183. clr.l %sp@-
  184. move.l #__got_start, %a5 /* put relocation table address to a5 */
  185. bsr cpu_init_f /* run low-level CPU init code (from flash) */
  186. bsr board_init_f /* run low-level board init code (from flash) */
  187. /* board_init_f() does not return */
  188. /*------------------------------------------------------------------------------*/
  189. /*
  190. * void relocate_code (addr_sp, gd, addr_moni)
  191. *
  192. * This "function" does not return, instead it continues in RAM
  193. * after relocating the monitor code.
  194. *
  195. * r3 = dest
  196. * r4 = src
  197. * r5 = length in bytes
  198. * r6 = cachelinesize
  199. */
  200. .globl relocate_code
  201. relocate_code:
  202. link.w %a6,#0
  203. move.l 8(%a6), %sp /* set new stack pointer */
  204. move.l 12(%a6), %d0 /* Save copy of Global Data pointer */
  205. move.l 16(%a6), %a0 /* Save copy of Destination Address */
  206. move.l #CONFIG_SYS_MONITOR_BASE, %a1
  207. move.l #__init_end, %a2
  208. move.l %a0, %a3
  209. /* copy the code to RAM */
  210. 1:
  211. move.l (%a1)+, (%a3)+
  212. cmp.l %a1,%a2
  213. bgt.s 1b
  214. /*
  215. * We are done. Do not return, instead branch to second part of board
  216. * initialization, now running from RAM.
  217. */
  218. move.l %a0, %a1
  219. add.l #(in_ram - CONFIG_SYS_MONITOR_BASE), %a1
  220. jmp (%a1)
  221. in_ram:
  222. clear_bss:
  223. /*
  224. * Now clear BSS segment
  225. */
  226. move.l %a0, %a1
  227. add.l #(_sbss - CONFIG_SYS_MONITOR_BASE),%a1
  228. move.l %a0, %d1
  229. add.l #(_ebss - CONFIG_SYS_MONITOR_BASE),%d1
  230. 6:
  231. clr.l (%a1)+
  232. cmp.l %a1,%d1
  233. bgt.s 6b
  234. /*
  235. * fix got table in RAM
  236. */
  237. move.l %a0, %a1
  238. add.l #(__got_start - CONFIG_SYS_MONITOR_BASE),%a1
  239. move.l %a1,%a5 /* * fix got pointer register a5 */
  240. move.l %a0, %a2
  241. add.l #(__got_end - CONFIG_SYS_MONITOR_BASE),%a2
  242. 7:
  243. move.l (%a1),%d1
  244. sub.l #_start,%d1
  245. add.l %a0,%d1
  246. move.l %d1,(%a1)+
  247. cmp.l %a2, %a1
  248. bne 7b
  249. /* calculate relative jump to board_init_r in ram */
  250. move.l %a0, %a1
  251. add.l #(board_init_r - CONFIG_SYS_MONITOR_BASE), %a1
  252. /* set parameters for board_init_r */
  253. move.l %a0,-(%sp) /* dest_addr */
  254. move.l %d0,-(%sp) /* gd */
  255. #if defined(DEBUG) && (CONFIG_SYS_TEXT_BASE != CONFIG_SYS_INT_FLASH_BASE) && \
  256. defined(CONFIG_SYS_HALT_BEFOR_RAM_JUMP)
  257. halt
  258. #endif
  259. jsr (%a1)
  260. /*------------------------------------------------------------------------------*/
  261. /* exception code */
  262. .globl _fault
  263. _fault:
  264. jmp _fault
  265. .globl _exc_handler
  266. _exc_handler:
  267. SAVE_ALL
  268. movel %sp,%sp@-
  269. bsr exc_handler
  270. addql #4,%sp
  271. RESTORE_ALL
  272. .globl _int_handler
  273. _int_handler:
  274. SAVE_ALL
  275. movel %sp,%sp@-
  276. bsr int_handler
  277. addql #4,%sp
  278. RESTORE_ALL
  279. /*------------------------------------------------------------------------------*/
  280. .globl version_string
  281. version_string:
  282. .ascii U_BOOT_VERSION
  283. .ascii " (", U_BOOT_DATE, " - ", U_BOOT_TIME, ")"
  284. .ascii CONFIG_IDENT_STRING, "\0"
  285. .align 4