start.S 9.6 KB

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