start.S 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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 <asm-offsets.h>
  27. #include <config.h>
  28. #include <timestamp.h>
  29. #include "version.h"
  30. #include <asm/cache.h>
  31. #ifndef CONFIG_IDENT_STRING
  32. #define CONFIG_IDENT_STRING ""
  33. #endif
  34. #define _START _start
  35. #define _FAULT _fault
  36. #define SAVE_ALL \
  37. move.w #0x2700,%sr; /* disable intrs */ \
  38. subl #60,%sp; /* space for 15 regs */ \
  39. moveml %d0-%d7/%a0-%a6,%sp@;
  40. #define RESTORE_ALL \
  41. moveml %sp@,%d0-%d7/%a0-%a6; \
  42. addl #60,%sp; /* space for 15 regs */ \
  43. rte;
  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. INITSP: .long 0x00000000 /* Initial SP */
  52. INITPC: .long _START /* Initial PC */
  53. vector02: .long _FAULT /* Access Error */
  54. vector03: .long _FAULT /* Address Error */
  55. vector04: .long _FAULT /* Illegal Instruction */
  56. vector05: .long _FAULT /* Reserved */
  57. vector06: .long _FAULT /* Reserved */
  58. vector07: .long _FAULT /* Reserved */
  59. vector08: .long _FAULT /* Privilege Violation */
  60. vector09: .long _FAULT /* Trace */
  61. vector0A: .long _FAULT /* Unimplemented A-Line */
  62. vector0B: .long _FAULT /* Unimplemented F-Line */
  63. vector0C: .long _FAULT /* Debug Interrupt */
  64. vector0D: .long _FAULT /* Reserved */
  65. vector0E: .long _FAULT /* Format Error */
  66. vector0F: .long _FAULT /* Unitialized Int. */
  67. /* Reserved */
  68. vector10_17:
  69. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  70. vector18: .long _FAULT /* Spurious Interrupt */
  71. vector19: .long _FAULT /* Autovector Level 1 */
  72. vector1A: .long _FAULT /* Autovector Level 2 */
  73. vector1B: .long _FAULT /* Autovector Level 3 */
  74. vector1C: .long _FAULT /* Autovector Level 4 */
  75. vector1D: .long _FAULT /* Autovector Level 5 */
  76. vector1E: .long _FAULT /* Autovector Level 6 */
  77. vector1F: .long _FAULT /* Autovector Level 7 */
  78. /* TRAP #0 - #15 */
  79. vector20_2F:
  80. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  81. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  82. /* Reserved */
  83. vector30_3F:
  84. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  85. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  86. vector64_127:
  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. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  95. vector128_191:
  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. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  104. vector192_255:
  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. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  113. #endif /* !defined(CONFIG_MONITOR_IS_IN_RAM) */
  114. .text
  115. .globl _start
  116. _start:
  117. nop
  118. nop
  119. move.w #0x2700,%sr /* Mask off Interrupt */
  120. #if !defined(CONFIG_MONITOR_IS_IN_RAM)
  121. /* Set vector base register at the beginning of the Flash */
  122. move.l #CONFIG_SYS_FLASH_BASE, %d0
  123. movec %d0, %VBR
  124. #endif
  125. move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0
  126. movec %d0, %RAMBAR1
  127. /* invalidate and disable cache */
  128. move.l #CF_CACR_CINVA, %d0 /* Invalidate cache cmd */
  129. movec %d0, %CACR /* Invalidate cache */
  130. move.l #0, %d0
  131. movec %d0, %ACR0
  132. movec %d0, %ACR1
  133. #ifdef CONFIG_MCF5301x
  134. move.l #(0xFC0a0010), %a0
  135. move.w (%a0), %d0
  136. and.l %d0, 0xEFFF
  137. move.w %d0, (%a0)
  138. #endif
  139. /* initialize general use internal ram */
  140. move.l #0, %d0
  141. move.l #(ICACHE_STATUS), %a1 /* icache */
  142. move.l #(DCACHE_STATUS), %a2 /* icache */
  143. move.l %d0, (%a1)
  144. move.l %d0, (%a2)
  145. /* set stackpointer to end of internal ram to get some stackspace for the
  146. first c-code */
  147. move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET), %sp
  148. clr.l %sp@-
  149. move.l #__got_start, %a5 /* put relocation table address to a5 */
  150. bsr cpu_init_f /* run low-level CPU init code (from flash) */
  151. bsr board_init_f /* run low-level board init code (from flash) */
  152. /* board_init_f() does not return */
  153. /*------------------------------------------------------------------------------*/
  154. /*
  155. * void relocate_code (addr_sp, gd, addr_moni)
  156. *
  157. * This "function" does not return, instead it continues in RAM
  158. * after relocating the monitor code.
  159. *
  160. * r3 = dest
  161. * r4 = src
  162. * r5 = length in bytes
  163. * r6 = cachelinesize
  164. */
  165. .globl relocate_code
  166. relocate_code:
  167. link.w %a6,#0
  168. move.l 8(%a6), %sp /* set new stack pointer */
  169. move.l 12(%a6), %d0 /* Save copy of Global Data pointer */
  170. move.l 16(%a6), %a0 /* Save copy of Destination Address */
  171. move.l #CONFIG_SYS_MONITOR_BASE, %a1
  172. move.l #__init_end, %a2
  173. move.l %a0, %a3
  174. /* copy the code to RAM */
  175. 1:
  176. move.l (%a1)+, (%a3)+
  177. cmp.l %a1,%a2
  178. bgt.s 1b
  179. /*
  180. * We are done. Do not return, instead branch to second part of board
  181. * initialization, now running from RAM.
  182. */
  183. move.l %a0, %a1
  184. add.l #(in_ram - CONFIG_SYS_MONITOR_BASE), %a1
  185. jmp (%a1)
  186. in_ram:
  187. clear_bss:
  188. /*
  189. * Now clear BSS segment
  190. */
  191. move.l %a0, %a1
  192. add.l #(_sbss - CONFIG_SYS_MONITOR_BASE),%a1
  193. move.l %a0, %d1
  194. add.l #(_ebss - CONFIG_SYS_MONITOR_BASE),%d1
  195. 6:
  196. clr.l (%a1)+
  197. cmp.l %a1,%d1
  198. bgt.s 6b
  199. /*
  200. * fix got table in RAM
  201. */
  202. move.l %a0, %a1
  203. add.l #(__got_start - CONFIG_SYS_MONITOR_BASE),%a1
  204. move.l %a1,%a5 /* * fix got pointer register a5 */
  205. move.l %a0, %a2
  206. add.l #(__got_end - CONFIG_SYS_MONITOR_BASE),%a2
  207. 7:
  208. move.l (%a1),%d1
  209. sub.l #_start,%d1
  210. add.l %a0,%d1
  211. move.l %d1,(%a1)+
  212. cmp.l %a2, %a1
  213. bne 7b
  214. /* calculate relative jump to board_init_r in ram */
  215. move.l %a0, %a1
  216. add.l #(board_init_r - CONFIG_SYS_MONITOR_BASE), %a1
  217. /* set parameters for board_init_r */
  218. move.l %a0,-(%sp) /* dest_addr */
  219. move.l %d0,-(%sp) /* gd */
  220. jsr (%a1)
  221. /*------------------------------------------------------------------------------*/
  222. /* exception code */
  223. .globl _fault
  224. _fault:
  225. jmp _fault
  226. .globl _exc_handler
  227. _exc_handler:
  228. SAVE_ALL
  229. movel %sp,%sp@-
  230. bsr exc_handler
  231. addql #4,%sp
  232. RESTORE_ALL
  233. .globl _int_handler
  234. _int_handler:
  235. SAVE_ALL
  236. movel %sp,%sp@-
  237. bsr int_handler
  238. addql #4,%sp
  239. RESTORE_ALL
  240. /*------------------------------------------------------------------------------*/
  241. .globl version_string
  242. version_string:
  243. .ascii U_BOOT_VERSION
  244. .ascii " (", U_BOOT_DATE, " - ", U_BOOT_TIME, ")"
  245. .ascii CONFIG_IDENT_STRING, "\0"
  246. .align 4