start.S 7.9 KB

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