start.S 10.0 KB

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