start.S 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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, %RAMBAR1
  117. /* invalidate and disable cache */
  118. move.l #0x01000000, %d0 /* Invalidate cache cmd */
  119. movec %d0, %CACR /* Invalidate cache */
  120. nop
  121. move.l #0, %d0
  122. movec %d0, %ACR0
  123. movec %d0, %ACR1
  124. /* initialize general use internal ram */
  125. move.l #0, %d0
  126. move.l #(CFG_INIT_RAM_ADDR+CFG_INIT_RAM_END-8), %a1
  127. move.l #(CFG_INIT_RAM_ADDR+CFG_INIT_RAM_END-4), %a2
  128. move.l %d0, (%a1)
  129. move.l %d0, (%a2)
  130. /* set stackpointer to end of internal ram to get some stackspace for the
  131. first c-code */
  132. move.l #(CFG_INIT_RAM_ADDR + CFG_INIT_SP_OFFSET), %sp
  133. clr.l %sp@-
  134. move.l #__got_start, %a5 /* put relocation table address to a5 */
  135. bsr cpu_init_f /* run low-level CPU init code (from flash) */
  136. bsr board_init_f /* run low-level board init code (from flash) */
  137. /* board_init_f() does not return */
  138. /*------------------------------------------------------------------------------*/
  139. /*
  140. * void relocate_code (addr_sp, gd, addr_moni)
  141. *
  142. * This "function" does not return, instead it continues in RAM
  143. * after relocating the monitor code.
  144. *
  145. * r3 = dest
  146. * r4 = src
  147. * r5 = length in bytes
  148. * r6 = cachelinesize
  149. */
  150. .globl relocate_code
  151. relocate_code:
  152. link.w %a6,#0
  153. move.l 8(%a6), %sp /* set new stack pointer */
  154. move.l 12(%a6), %d0 /* Save copy of Global Data pointer */
  155. move.l 16(%a6), %a0 /* Save copy of Destination Address */
  156. move.l #CFG_MONITOR_BASE, %a1
  157. move.l #__init_end, %a2
  158. move.l %a0, %a3
  159. /* copy the code to RAM */
  160. 1:
  161. move.l (%a1)+, (%a3)+
  162. cmp.l %a1,%a2
  163. bgt.s 1b
  164. /*
  165. * We are done. Do not return, instead branch to second part of board
  166. * initialization, now running from RAM.
  167. */
  168. move.l %a0, %a1
  169. add.l #(in_ram - CFG_MONITOR_BASE), %a1
  170. jmp (%a1)
  171. in_ram:
  172. clear_bss:
  173. /*
  174. * Now clear BSS segment
  175. */
  176. move.l %a0, %a1
  177. add.l #(_sbss - CFG_MONITOR_BASE),%a1
  178. move.l %a0, %d1
  179. add.l #(_ebss - CFG_MONITOR_BASE),%d1
  180. 6:
  181. clr.l (%a1)+
  182. cmp.l %a1,%d1
  183. bgt.s 6b
  184. /*
  185. * fix got table in RAM
  186. */
  187. move.l %a0, %a1
  188. add.l #(__got_start - CFG_MONITOR_BASE),%a1
  189. move.l %a1,%a5 /* * fix got pointer register a5 */
  190. move.l %a0, %a2
  191. add.l #(__got_end - CFG_MONITOR_BASE),%a2
  192. 7:
  193. move.l (%a1),%d1
  194. sub.l #_start,%d1
  195. add.l %a0,%d1
  196. move.l %d1,(%a1)+
  197. cmp.l %a2, %a1
  198. bne 7b
  199. /* calculate relative jump to board_init_r in ram */
  200. move.l %a0, %a1
  201. add.l #(board_init_r - CFG_MONITOR_BASE), %a1
  202. /* set parameters for board_init_r */
  203. move.l %a0,-(%sp) /* dest_addr */
  204. move.l %d0,-(%sp) /* gd */
  205. jsr (%a1)
  206. /*------------------------------------------------------------------------------*/
  207. /* exception code */
  208. .globl _fault
  209. _fault:
  210. jmp _fault
  211. .globl _exc_handler
  212. _exc_handler:
  213. SAVE_ALL
  214. movel %sp,%sp@-
  215. bsr exc_handler
  216. addql #4,%sp
  217. RESTORE_ALL
  218. .globl _int_handler
  219. _int_handler:
  220. SAVE_ALL
  221. movel %sp,%sp@-
  222. bsr int_handler
  223. addql #4,%sp
  224. RESTORE_ALL
  225. /*------------------------------------------------------------------------------*/
  226. /* cache functions */
  227. .globl icache_enable
  228. icache_enable:
  229. move.l #0x01000000, %d0 /* Invalidate cache cmd */
  230. movec %d0, %CACR /* Invalidate cache */
  231. nop
  232. move.l #(CFG_SDRAM_BASE + 0xc000), %d0 /* Setup cache mask */
  233. movec %d0, %ACR0 /* Enable cache */
  234. move.l #(CFG_FLASH_BASE + 0xc000), %d0 /* Setup cache mask */
  235. movec %d0, %ACR1 /* Enable cache */
  236. move.l #0x80400100, %d0 /* Setup cache mask */
  237. movec %d0, %CACR /* Enable cache */
  238. nop
  239. move.l #(CFG_INIT_RAM_ADDR+CFG_INIT_RAM_END-8), %a1
  240. moveq #1, %d0
  241. move.l %d0, (%a1)
  242. rts
  243. .globl icache_disable
  244. icache_disable:
  245. move.l #0x00000100, %d0 /* Setup cache mask */
  246. movec %d0, %CACR /* Disable cache */
  247. clr.l %d0 /* Setup cache mask */
  248. movec %d0, %ACR0
  249. movec %d0, %ACR1
  250. move.l #(CFG_INIT_RAM_ADDR+CFG_INIT_RAM_END-8), %a1
  251. moveq #0, %d0
  252. move.l %d0, (%a1)
  253. rts
  254. .globl icache_status
  255. icache_status:
  256. move.l #(CFG_INIT_RAM_ADDR+CFG_INIT_RAM_END-8), %a1
  257. move.l (%a1), %d0
  258. rts
  259. .globl icache_invalid
  260. icache_invalid:
  261. move.l #0x80600100, %d0 /* Setup cache mask */
  262. movec %d0, %CACR /* Enable cache */
  263. nop
  264. rts
  265. .globl dcache_enable
  266. dcache_enable:
  267. move.l #(CFG_INIT_RAM_ADDR+CFG_INIT_RAM_END-4), %a1
  268. moveq #1, %d0
  269. move.l %d0, (%a1)
  270. rts
  271. /* No dcache, just a dummy function */
  272. .globl dcache_disable
  273. dcache_disable:
  274. move.l #(CFG_INIT_RAM_ADDR+CFG_INIT_RAM_END-4), %a1
  275. moveq #0, %d0
  276. move.l %d0, (%a1)
  277. rts
  278. .globl dcache_status
  279. dcache_status:
  280. move.l #(CFG_INIT_RAM_ADDR+CFG_INIT_RAM_END-4), %a1
  281. move.l (%a1), %d0
  282. rts
  283. /*------------------------------------------------------------------------------*/
  284. .globl version_string
  285. version_string:
  286. .ascii U_BOOT_VERSION
  287. .ascii " (", __DATE__, " - ", __TIME__, ")"
  288. .ascii CONFIG_IDENT_STRING, "\0"