start.S 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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. /* If we come from a pre-loader we don't need an initial exception
  39. * table.
  40. */
  41. #if !defined(CONFIG_MONITOR_IS_IN_RAM)
  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. #ifndef CONFIG_M5271
  49. .long 0x00000000, _START
  50. #else
  51. .long 0x00000000, 0x400 /* Flash offset is 0 until we setup CS0 */
  52. #endif
  53. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  54. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  55. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  56. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  57. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  58. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  59. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  60. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  61. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  62. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  63. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  64. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  65. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  66. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  67. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  68. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  69. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  70. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  71. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  72. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  73. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  74. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  75. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  76. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  77. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  78. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  79. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  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. #endif
  86. .text
  87. .globl _start
  88. _start:
  89. nop
  90. nop
  91. move.w #0x2700,%sr
  92. /* if we come from a pre-loader we have no exception table and
  93. * therefore no VBR to set
  94. */
  95. #if !defined(CONFIG_MONITOR_IS_IN_RAM)
  96. move.l #CFG_FLASH_BASE, %d0
  97. movec %d0, %VBR
  98. #endif
  99. #if defined(CONFIG_M5272) || defined(CONFIG_M5249)
  100. move.l #(CFG_MBAR + 1), %d0 /* set MBAR address + valid flag */
  101. move.c %d0, %MBAR
  102. /*** The 5249 has MBAR2 as well ***/
  103. #ifdef CFG_MBAR2
  104. move.l #(CFG_MBAR2 + 1), %d0 /* Get MBAR2 address */
  105. movec %d0, #0xc0e /* Set MBAR2 */
  106. #endif
  107. move.l #(CFG_INIT_RAM_ADDR + 1), %d0
  108. movec %d0, %RAMBAR0
  109. #endif /* #if defined(CONFIG_M5272) || defined(CONFIG_M5249) */
  110. #if defined(CONFIG_M5282) || defined(CONFIG_M5271)
  111. /* Initialize IPSBAR */
  112. move.l #(CFG_MBAR + 1), %d0 /* set IPSBAR address + valid flag */
  113. move.l %d0, 0x40000000
  114. #ifdef CONFIG_M5282
  115. /* Initialize FLASHBAR: locate internal Flash and validate it */
  116. move.l #(CFG_INT_FLASH_BASE + 0x21), %d0
  117. movec %d0, %RAMBAR0
  118. #endif
  119. /* Initialize RAMBAR1: locate SRAM and validate it */
  120. move.l #(CFG_INIT_RAM_ADDR + 0x21), %d0
  121. movec %d0, %RAMBAR1
  122. #ifdef CONFIG_M5271
  123. move.l #(_flash_setup-CFG_FLASH_BASE), %a0
  124. move.l #(_flash_setup_end-CFG_FLASH_BASE), %a1
  125. move.l #(CFG_INIT_RAM_ADDR), %a2
  126. _copy_flash:
  127. move.l (%a0)+, (%a2)+
  128. cmp.l %a0, %a1
  129. bgt.s _copy_flash
  130. #endif
  131. jmp CFG_INIT_RAM_ADDR
  132. _after_flash_copy:
  133. #endif
  134. #if 0
  135. /* invalidate and disable cache */
  136. move.l #0x01000000, %d0 /* Invalidate cache cmd */
  137. movec %d0, %CACR /* Invalidate cache */
  138. move.l #0, %d0
  139. movec %d0, %ACR0
  140. movec %d0, %ACR1
  141. #endif
  142. /* set stackpointer to end of internal ram to get some stackspace for the first c-code */
  143. move.l #(CFG_INIT_RAM_ADDR + CFG_INIT_SP_OFFSET), %sp
  144. clr.l %sp@-
  145. move.l #__got_start, %a5 /* put relocation table address to a5 */
  146. bsr cpu_init_f /* run low-level CPU init code (from flash) */
  147. bsr board_init_f /* run low-level board init code (from flash) */
  148. /* board_init_f() does not return
  149. /*------------------------------------------------------------------------------*/
  150. #ifdef CONFIG_M5271
  151. _flash_setup:
  152. move.l #0x1000, %d0
  153. move.w %d0, 0x40000080
  154. move.l #0x2180, %d0
  155. move.w %d0, 0x4000008A
  156. move.l #0x3f0001, %d0
  157. move.l %d0, 0x40000084
  158. jmp _after_flash_copy.L
  159. _flash_setup_end:
  160. #endif
  161. /*
  162. * void relocate_code (addr_sp, gd, addr_moni)
  163. *
  164. * This "function" does not return, instead it continues in RAM
  165. * after relocating the monitor code.
  166. *
  167. * r3 = dest
  168. * r4 = src
  169. * r5 = length in bytes
  170. * r6 = cachelinesize
  171. */
  172. .globl relocate_code
  173. relocate_code:
  174. link.w %a6,#0
  175. move.l 8(%a6), %sp /* set new stack pointer */
  176. move.l 12(%a6), %d0 /* Save copy of Global Data pointer */
  177. move.l 16(%a6), %a0 /* Save copy of Destination Address */
  178. move.l #CFG_MONITOR_BASE, %a1
  179. move.l #__init_end, %a2
  180. move.l %a0, %a3
  181. /* copy the code to RAM */
  182. 1:
  183. move.l (%a1)+, (%a3)+
  184. cmp.l %a1,%a2
  185. bgt.s 1b
  186. /*
  187. * We are done. Do not return, instead branch to second part of board
  188. * initialization, now running from RAM.
  189. */
  190. move.l %a0, %a1
  191. add.l #(in_ram - CFG_MONITOR_BASE), %a1
  192. jmp (%a1)
  193. in_ram:
  194. clear_bss:
  195. /*
  196. * Now clear BSS segment
  197. */
  198. move.l %a0, %a1
  199. add.l #(_sbss - CFG_MONITOR_BASE),%a1
  200. move.l %a0, %d1
  201. add.l #(_ebss - CFG_MONITOR_BASE),%d1
  202. 6:
  203. clr.l (%a1)+
  204. cmp.l %a1,%d1
  205. bgt.s 6b
  206. /*
  207. * fix got table in RAM
  208. */
  209. move.l %a0, %a1
  210. add.l #(__got_start - CFG_MONITOR_BASE),%a1
  211. move.l %a1,%a5 /* * fix got pointer register a5 */
  212. move.l %a0, %a2
  213. add.l #(__got_end - CFG_MONITOR_BASE),%a2
  214. 7:
  215. move.l (%a1),%d1
  216. sub.l #_start,%d1
  217. add.l %a0,%d1
  218. move.l %d1,(%a1)+
  219. cmp.l %a2, %a1
  220. bne 7b
  221. /* calculate relative jump to board_init_r in ram */
  222. move.l %a0, %a1
  223. add.l #(board_init_r - CFG_MONITOR_BASE), %a1
  224. /* set parameters for board_init_r */
  225. move.l %a0,-(%sp) /* dest_addr */
  226. move.l %d0,-(%sp) /* gd */
  227. jsr (%a1)
  228. /*------------------------------------------------------------------------------*/
  229. /* exception code */
  230. .globl _fault
  231. _fault:
  232. jmp _fault
  233. .globl _exc_handler
  234. _exc_handler:
  235. SAVE_ALL
  236. movel %sp,%sp@-
  237. bsr exc_handler
  238. addql #4,%sp
  239. RESTORE_ALL
  240. .globl _int_handler
  241. _int_handler:
  242. SAVE_ALL
  243. movel %sp,%sp@-
  244. bsr int_handler
  245. addql #4,%sp
  246. RESTORE_ALL
  247. /*------------------------------------------------------------------------------*/
  248. /* cache functions */
  249. #ifdef CONFIG_M5272
  250. .globl icache_enable
  251. icache_enable:
  252. move.l #0x01000000, %d0 /* Invalidate cache cmd */
  253. movec %d0, %CACR /* Invalidate cache */
  254. move.l #0x0000c000, %d0 /* Setup cache mask */
  255. movec %d0, %ACR0 /* Enable cache */
  256. move.l #0xff00c000, %d0 /* Setup cache mask */
  257. movec %d0, %ACR1 /* Enable cache */
  258. move.l #0x80000100, %d0 /* Setup cache mask */
  259. movec %d0, %CACR /* Enable cache */
  260. moveq #1, %d0
  261. move.l %d0, icache_state
  262. rts
  263. #endif
  264. #ifdef CONFIG_M5282
  265. .globl icache_enable
  266. icache_enable:
  267. move.l #0x01000000, %d0 /* Invalidate cache cmd */
  268. movec %d0, %CACR /* Invalidate cache */
  269. move.l #0x0000c000, %d0 /* Setup cache mask */
  270. movec %d0, %ACR0 /* Enable cache */
  271. move.l #0xff00c000, %d0 /* Setup cache mask */
  272. movec %d0, %ACR1 /* Enable cache */
  273. move.l #0x80400100, %d0 /* Setup cache mask, data cache disabel*/
  274. movec %d0, %CACR /* Enable cache */
  275. moveq #1, %d0
  276. move.l %d0, icache_state
  277. rts
  278. #endif
  279. #ifdef CONFIG_M5249
  280. .globl icache_enable
  281. icache_enable:
  282. /*
  283. * Note: The 5249 Documentation doesn't give a bit position for CINV!
  284. * From the 5272 and the 5307 documentation, I have deduced that it is
  285. * probably CACR[24]. Should someone say something to Motorola?
  286. * ~Jeremy
  287. */
  288. move.l #0x01000000, %d0 /* Invalidate whole cache */
  289. move.c %d0,%CACR
  290. move.l #0xff00c000, %d0 /* Set FLASH cachable: always match (SM=0b10) */
  291. move.c %d0, %ACR0
  292. move.l #0x0000c000, %d0 /* Set SDRAM cachable: always match (SM=0b10) */
  293. move.c %d0, %ACR1
  294. move.l #0x90000200, %d0 /* Set cache enable cmd */
  295. move.c %d0,%CACR
  296. moveq #1, %d0
  297. move.l %d0, icache_state
  298. rts
  299. #endif
  300. .globl icache_disable
  301. icache_disable:
  302. move.l #0x00000100, %d0 /* Setup cache mask */
  303. movec %d0, %CACR /* Enable cache */
  304. clr.l %d0 /* Setup cache mask */
  305. movec %d0, %ACR0 /* Enable cache */
  306. movec %d0, %ACR1 /* Enable cache */
  307. moveq #0, %d0
  308. move.l %d0, icache_state
  309. rts
  310. .globl icache_status
  311. icache_status:
  312. move.l icache_state, %d0
  313. rts
  314. .data
  315. icache_state:
  316. .long 1
  317. /*------------------------------------------------------------------------------*/
  318. .globl version_string
  319. version_string:
  320. .ascii U_BOOT_VERSION
  321. .ascii " (", __DATE__, " - ", __TIME__, ")"
  322. .ascii CONFIG_IDENT_STRING, "\0"