start.S 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. /*
  2. * Copyright (C) 2003 Josef Baumgartner <josef.baumgartner@telex.de>
  3. * Based on code from Bernhard Kuhn <bkuhn@metrowerks.com>
  4. *
  5. * (C) Copyright 2004-2008 Freescale Semiconductor, Inc.
  6. * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
  7. *
  8. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24. * MA 02111-1307 USA
  25. */
  26. #include <config.h>
  27. #include <timestamp.h>
  28. #include "version.h"
  29. #include <asm/cache.h>
  30. #ifndef CONFIG_IDENT_STRING
  31. #define CONFIG_IDENT_STRING ""
  32. #endif
  33. #define _START _start
  34. #define _FAULT _fault
  35. #define SAVE_ALL \
  36. move.w #0x2700,%sr; /* disable intrs */ \
  37. subl #60,%sp; /* space for 15 regs */ \
  38. moveml %d0-%d7/%a0-%a6,%sp@;
  39. #define RESTORE_ALL \
  40. moveml %sp@,%d0-%d7/%a0-%a6; \
  41. addl #60,%sp; /* space for 15 regs */ \
  42. rte;
  43. #if !defined(CONFIG_MONITOR_IS_IN_RAM)
  44. .text
  45. /*
  46. * Vector table. This is used for initial platform startup.
  47. * These vectors are to catch any un-intended traps.
  48. */
  49. _vectors:
  50. INITSP: .long 0x00000000 /* Initial SP */
  51. INITPC: .long _START /* Initial PC */
  52. vector02: .long _FAULT /* Access Error */
  53. vector03: .long _FAULT /* Address Error */
  54. vector04: .long _FAULT /* Illegal Instruction */
  55. vector05: .long _FAULT /* Reserved */
  56. vector06: .long _FAULT /* Reserved */
  57. vector07: .long _FAULT /* Reserved */
  58. vector08: .long _FAULT /* Privilege Violation */
  59. vector09: .long _FAULT /* Trace */
  60. vector0A: .long _FAULT /* Unimplemented A-Line */
  61. vector0B: .long _FAULT /* Unimplemented F-Line */
  62. vector0C: .long _FAULT /* Debug Interrupt */
  63. vector0D: .long _FAULT /* Reserved */
  64. vector0E: .long _FAULT /* Format Error */
  65. vector0F: .long _FAULT /* Unitialized Int. */
  66. /* Reserved */
  67. vector10_17:
  68. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  69. vector18: .long _FAULT /* Spurious Interrupt */
  70. vector19: .long _FAULT /* Autovector Level 1 */
  71. vector1A: .long _FAULT /* Autovector Level 2 */
  72. vector1B: .long _FAULT /* Autovector Level 3 */
  73. vector1C: .long _FAULT /* Autovector Level 4 */
  74. vector1D: .long _FAULT /* Autovector Level 5 */
  75. vector1E: .long _FAULT /* Autovector Level 6 */
  76. vector1F: .long _FAULT /* Autovector Level 7 */
  77. /* TRAP #0 - #15 */
  78. vector20_2F:
  79. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  80. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  81. /* Reserved */
  82. vector30_3F:
  83. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  84. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  85. vector64_127:
  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. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  90. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  91. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  92. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  93. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  94. vector128_191:
  95. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  96. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  97. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  98. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  99. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  100. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  101. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  102. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  103. vector192_255:
  104. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  105. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  106. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  107. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  108. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  109. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  110. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  111. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  112. #endif /* !defined(CONFIG_MONITOR_IS_IN_RAM) */
  113. .text
  114. .globl _start
  115. _start:
  116. nop
  117. nop
  118. move.w #0x2700,%sr /* Mask off Interrupt */
  119. #if !defined(CONFIG_MONITOR_IS_IN_RAM)
  120. /* Set vector base register at the beginning of the Flash */
  121. move.l #CONFIG_SYS_FLASH_BASE, %d0
  122. movec %d0, %VBR
  123. #endif
  124. move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0
  125. movec %d0, %RAMBAR1
  126. /* invalidate and disable cache */
  127. move.l #CF_CACR_CINVA, %d0 /* Invalidate cache cmd */
  128. movec %d0, %CACR /* Invalidate cache */
  129. move.l #0, %d0
  130. movec %d0, %ACR0
  131. movec %d0, %ACR1
  132. #ifdef CONFIG_MCF5301x
  133. move.l #(0xFC0a0010), %a0
  134. move.w (%a0), %d0
  135. and.l %d0, 0xEFFF
  136. move.w %d0, (%a0)
  137. #endif
  138. /* initialize general use internal ram */
  139. move.l #0, %d0
  140. move.l #(ICACHE_STATUS), %a1 /* icache */
  141. move.l #(DCACHE_STATUS), %a2 /* icache */
  142. move.l %d0, (%a1)
  143. move.l %d0, (%a2)
  144. /* set stackpointer to end of internal ram to get some stackspace for the
  145. first c-code */
  146. move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET), %sp
  147. clr.l %sp@-
  148. move.l #__got_start, %a5 /* put relocation table address to a5 */
  149. bsr cpu_init_f /* run low-level CPU init code (from flash) */
  150. bsr board_init_f /* run low-level board init code (from flash) */
  151. /* board_init_f() does not return */
  152. /*------------------------------------------------------------------------------*/
  153. /*
  154. * void relocate_code (addr_sp, gd, addr_moni)
  155. *
  156. * This "function" does not return, instead it continues in RAM
  157. * after relocating the monitor code.
  158. *
  159. * r3 = dest
  160. * r4 = src
  161. * r5 = length in bytes
  162. * r6 = cachelinesize
  163. */
  164. .globl relocate_code
  165. relocate_code:
  166. link.w %a6,#0
  167. move.l 8(%a6), %sp /* set new stack pointer */
  168. move.l 12(%a6), %d0 /* Save copy of Global Data pointer */
  169. move.l 16(%a6), %a0 /* Save copy of Destination Address */
  170. move.l #CONFIG_SYS_MONITOR_BASE, %a1
  171. move.l #__init_end, %a2
  172. move.l %a0, %a3
  173. /* copy the code to RAM */
  174. 1:
  175. move.l (%a1)+, (%a3)+
  176. cmp.l %a1,%a2
  177. bgt.s 1b
  178. /*
  179. * We are done. Do not return, instead branch to second part of board
  180. * initialization, now running from RAM.
  181. */
  182. move.l %a0, %a1
  183. add.l #(in_ram - CONFIG_SYS_MONITOR_BASE), %a1
  184. jmp (%a1)
  185. in_ram:
  186. clear_bss:
  187. /*
  188. * Now clear BSS segment
  189. */
  190. move.l %a0, %a1
  191. add.l #(_sbss - CONFIG_SYS_MONITOR_BASE),%a1
  192. move.l %a0, %d1
  193. add.l #(_ebss - CONFIG_SYS_MONITOR_BASE),%d1
  194. 6:
  195. clr.l (%a1)+
  196. cmp.l %a1,%d1
  197. bgt.s 6b
  198. /*
  199. * fix got table in RAM
  200. */
  201. move.l %a0, %a1
  202. add.l #(__got_start - CONFIG_SYS_MONITOR_BASE),%a1
  203. move.l %a1,%a5 /* * fix got pointer register a5 */
  204. move.l %a0, %a2
  205. add.l #(__got_end - CONFIG_SYS_MONITOR_BASE),%a2
  206. 7:
  207. move.l (%a1),%d1
  208. sub.l #_start,%d1
  209. add.l %a0,%d1
  210. move.l %d1,(%a1)+
  211. cmp.l %a2, %a1
  212. bne 7b
  213. /* calculate relative jump to board_init_r in ram */
  214. move.l %a0, %a1
  215. add.l #(board_init_r - CONFIG_SYS_MONITOR_BASE), %a1
  216. /* set parameters for board_init_r */
  217. move.l %a0,-(%sp) /* dest_addr */
  218. move.l %d0,-(%sp) /* gd */
  219. jsr (%a1)
  220. /*------------------------------------------------------------------------------*/
  221. /* exception code */
  222. .globl _fault
  223. _fault:
  224. jmp _fault
  225. .globl _exc_handler
  226. _exc_handler:
  227. SAVE_ALL
  228. movel %sp,%sp@-
  229. bsr exc_handler
  230. addql #4,%sp
  231. RESTORE_ALL
  232. .globl _int_handler
  233. _int_handler:
  234. SAVE_ALL
  235. movel %sp,%sp@-
  236. bsr int_handler
  237. addql #4,%sp
  238. RESTORE_ALL
  239. /*------------------------------------------------------------------------------*/
  240. .globl version_string
  241. version_string:
  242. .ascii U_BOOT_VERSION
  243. .ascii " (", U_BOOT_DATE, " - ", U_BOOT_TIME, ")"
  244. .ascii CONFIG_IDENT_STRING, "\0"
  245. .align 4