start.S 10 KB

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