start.S 9.5 KB

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