start.S 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  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. /* If we come from a pre-loader we don't need an initial exception
  40. * table.
  41. */
  42. #if !defined(CONFIG_MONITOR_IS_IN_RAM)
  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. .long 0x00000000 /* Flash offset is 0 until we setup CS0 */
  50. #if defined(CONFIG_M5282) && (TEXT_BASE == CONFIG_SYS_INT_FLASH_BASE)
  51. .long _start - TEXT_BASE
  52. #else
  53. .long _START
  54. #endif
  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, _FAULT, _FAULT
  61. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  62. .long _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. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  86. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  87. #endif
  88. .text
  89. #if defined(CONFIG_SYS_INT_FLASH_BASE) && \
  90. (defined(CONFIG_M5282) || defined(CONFIG_M5281))
  91. #if (TEXT_BASE == CONFIG_SYS_INT_FLASH_BASE)
  92. .long 0x55AA55AA,0xAA55AA55 /* CFM Backdoorkey */
  93. .long 0xFFFFFFFF /* all sectors protected */
  94. .long 0x00000000 /* supervisor/User restriction */
  95. .long 0x00000000 /* programm/data space restriction */
  96. .long 0x00000000 /* Flash security */
  97. #endif
  98. #endif
  99. .globl _start
  100. _start:
  101. nop
  102. nop
  103. move.w #0x2700,%sr
  104. #if defined(CONFIG_M5208)
  105. /* Initialize RAMBAR: locate SRAM and validate it */
  106. move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0
  107. movec %d0, %RAMBAR1
  108. #endif
  109. #if defined(CONFIG_M5272) || defined(CONFIG_M5249) || defined(CONFIG_M5253)
  110. move.l #(CONFIG_SYS_MBAR + 1), %d0 /* set MBAR address + valid flag */
  111. move.c %d0, %MBAR
  112. /*** The 5249 has MBAR2 as well ***/
  113. #ifdef CONFIG_SYS_MBAR2
  114. move.l #(CONFIG_SYS_MBAR2 + 1), %d0 /* Get MBAR2 address */
  115. movec %d0, #0xc0e /* Set MBAR2 */
  116. #endif
  117. move.l #(CONFIG_SYS_INIT_RAM_ADDR + 1), %d0
  118. movec %d0, %RAMBAR0
  119. #endif /* CONFIG_M5272 || CONFIG_M5249 || CONFIG_M5253 */
  120. #if defined(CONFIG_M5282) || defined(CONFIG_M5271)
  121. /* Initialize IPSBAR */
  122. move.l #(CONFIG_SYS_MBAR + 1), %d0 /* set IPSBAR address + valid flag */
  123. move.l %d0, 0x40000000
  124. /* Initialize RAMBAR1: locate SRAM and validate it */
  125. move.l #(CONFIG_SYS_INIT_RAM_ADDR + 0x21), %d0
  126. movec %d0, %RAMBAR1
  127. #if defined(CONFIG_M5282)
  128. #if (TEXT_BASE == CONFIG_SYS_INT_FLASH_BASE)
  129. /* Setup code in SRAM to initialize FLASHBAR, if start from internal Flash */
  130. move.l #(_flashbar_setup-CONFIG_SYS_INT_FLASH_BASE), %a0
  131. move.l #(_flashbar_setup_end-CONFIG_SYS_INT_FLASH_BASE), %a1
  132. move.l #(CONFIG_SYS_INIT_RAM_ADDR), %a2
  133. _copy_flash:
  134. move.l (%a0)+, (%a2)+
  135. cmp.l %a0, %a1
  136. bgt.s _copy_flash
  137. jmp CONFIG_SYS_INIT_RAM_ADDR
  138. _flashbar_setup:
  139. /* Initialize FLASHBAR: locate internal Flash and validate it */
  140. move.l #(CONFIG_SYS_INT_FLASH_BASE + CONFIG_SYS_INT_FLASH_ENABLE), %d0
  141. movec %d0, %FLASHBAR
  142. jmp _after_flashbar_copy.L /* Force jump to absolute address */
  143. _flashbar_setup_end:
  144. nop
  145. _after_flashbar_copy:
  146. #else
  147. /* Setup code to initialize FLASHBAR, if start from external Memory */
  148. move.l #(CONFIG_SYS_INT_FLASH_BASE + CONFIG_SYS_INT_FLASH_ENABLE), %d0
  149. movec %d0, %FLASHBAR
  150. #endif /* (TEXT_BASE == CONFIG_SYS_INT_FLASH_BASE) */
  151. #endif
  152. #endif
  153. /* if we come from a pre-loader we have no exception table and
  154. * therefore no VBR to set
  155. */
  156. #if !defined(CONFIG_MONITOR_IS_IN_RAM)
  157. #if defined(CONFIG_M5282) && (TEXT_BASE == CONFIG_SYS_INT_FLASH_BASE)
  158. move.l #CONFIG_SYS_INT_FLASH_BASE, %d0
  159. #else
  160. move.l #CONFIG_SYS_FLASH_BASE, %d0
  161. #endif
  162. movec %d0, %VBR
  163. #endif
  164. #ifdef CONFIG_M5275
  165. /* Initialize IPSBAR */
  166. move.l #(CONFIG_SYS_MBAR + 1), %d0 /* set IPSBAR address + valid flag */
  167. move.l %d0, 0x40000000
  168. /* movec %d0, %MBAR */
  169. /* Initialize RAMBAR: locate SRAM and validate it */
  170. move.l #(CONFIG_SYS_INIT_RAM_ADDR + 0x21), %d0
  171. movec %d0, %RAMBAR1
  172. #endif
  173. /* set stackpointer to end of internal ram to get some stackspace for the first c-code */
  174. move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET), %sp
  175. clr.l %sp@-
  176. move.l #__got_start, %a5 /* put relocation table address to a5 */
  177. bsr cpu_init_f /* run low-level CPU init code (from flash) */
  178. bsr board_init_f /* run low-level board init code (from flash) */
  179. /* board_init_f() does not return */
  180. /*------------------------------------------------------------------------------*/
  181. /*
  182. * void relocate_code (addr_sp, gd, addr_moni)
  183. *
  184. * This "function" does not return, instead it continues in RAM
  185. * after relocating the monitor code.
  186. *
  187. * r3 = dest
  188. * r4 = src
  189. * r5 = length in bytes
  190. * r6 = cachelinesize
  191. */
  192. .globl relocate_code
  193. relocate_code:
  194. link.w %a6,#0
  195. move.l 8(%a6), %sp /* set new stack pointer */
  196. move.l 12(%a6), %d0 /* Save copy of Global Data pointer */
  197. move.l 16(%a6), %a0 /* Save copy of Destination Address */
  198. move.l #CONFIG_SYS_MONITOR_BASE, %a1
  199. move.l #__init_end, %a2
  200. move.l %a0, %a3
  201. /* copy the code to RAM */
  202. 1:
  203. move.l (%a1)+, (%a3)+
  204. cmp.l %a1,%a2
  205. bgt.s 1b
  206. /*
  207. * We are done. Do not return, instead branch to second part of board
  208. * initialization, now running from RAM.
  209. */
  210. move.l %a0, %a1
  211. add.l #(in_ram - CONFIG_SYS_MONITOR_BASE), %a1
  212. jmp (%a1)
  213. in_ram:
  214. clear_bss:
  215. /*
  216. * Now clear BSS segment
  217. */
  218. move.l %a0, %a1
  219. add.l #(_sbss - CONFIG_SYS_MONITOR_BASE),%a1
  220. move.l %a0, %d1
  221. add.l #(_ebss - CONFIG_SYS_MONITOR_BASE),%d1
  222. 6:
  223. clr.l (%a1)+
  224. cmp.l %a1,%d1
  225. bgt.s 6b
  226. /*
  227. * fix got table in RAM
  228. */
  229. move.l %a0, %a1
  230. add.l #(__got_start - CONFIG_SYS_MONITOR_BASE),%a1
  231. move.l %a1,%a5 /* * fix got pointer register a5 */
  232. move.l %a0, %a2
  233. add.l #(__got_end - CONFIG_SYS_MONITOR_BASE),%a2
  234. 7:
  235. move.l (%a1),%d1
  236. sub.l #_start,%d1
  237. add.l %a0,%d1
  238. move.l %d1,(%a1)+
  239. cmp.l %a2, %a1
  240. bne 7b
  241. #if defined(CONFIG_M5281) || defined(CONFIG_M5282)
  242. /* patch the 3 accesspoints to 3 ichache_state */
  243. /* quick and dirty */
  244. move.l %a0,%d1
  245. add.l #(icache_state - CONFIG_SYS_MONITOR_BASE),%d1
  246. move.l %a0,%a1
  247. add.l #(icache_state_access_1+2 - CONFIG_SYS_MONITOR_BASE),%a1
  248. move.l %d1,(%a1)
  249. move.l %a0,%a1
  250. add.l #(icache_state_access_2+2 - CONFIG_SYS_MONITOR_BASE),%a1
  251. move.l %d1,(%a1)
  252. move.l %a0,%a1
  253. add.l #(icache_state_access_3+2 - CONFIG_SYS_MONITOR_BASE),%a1
  254. move.l %d1,(%a1)
  255. #endif
  256. /* calculate relative jump to board_init_r in ram */
  257. move.l %a0, %a1
  258. add.l #(board_init_r - CONFIG_SYS_MONITOR_BASE), %a1
  259. /* set parameters for board_init_r */
  260. move.l %a0,-(%sp) /* dest_addr */
  261. move.l %d0,-(%sp) /* gd */
  262. #if defined(DEBUG) && (TEXT_BASE != CONFIG_SYS_INT_FLASH_BASE) && \
  263. defined(CONFIG_SYS_HALT_BEFOR_RAM_JUMP)
  264. halt
  265. #endif
  266. jsr (%a1)
  267. /*------------------------------------------------------------------------------*/
  268. /* exception code */
  269. .globl _fault
  270. _fault:
  271. jmp _fault
  272. .globl _exc_handler
  273. _exc_handler:
  274. SAVE_ALL
  275. movel %sp,%sp@-
  276. bsr exc_handler
  277. addql #4,%sp
  278. RESTORE_ALL
  279. .globl _int_handler
  280. _int_handler:
  281. SAVE_ALL
  282. movel %sp,%sp@-
  283. bsr int_handler
  284. addql #4,%sp
  285. RESTORE_ALL
  286. /*------------------------------------------------------------------------------*/
  287. /* cache functions */
  288. #ifdef CONFIG_M5208
  289. .globl icache_enable
  290. icache_enable:
  291. move.l #0x01000000, %d0 /* Invalidate cache cmd */
  292. movec %d0, %CACR /* Invalidate cache */
  293. move.l #(CONFIG_SYS_SDRAM_BASE + 0xC000), %d0 /* Setup cache mask */
  294. movec %d0, %ACR0 /* Enable cache */
  295. move.l #0x80000200, %d0 /* Setup cache mask */
  296. movec %d0, %CACR /* Enable cache */
  297. nop
  298. move.l #(CONFIG_SYS_INIT_RAM_ADDR+CONFIG_SYS_INIT_RAM_END-8), %a1
  299. moveq #1, %d0
  300. move.l %d0, (%a1)
  301. rts
  302. #endif
  303. #ifdef CONFIG_M5271
  304. .globl icache_enable
  305. icache_enable:
  306. move.l #0x01000000, %d0 /* Invalidate cache cmd */
  307. movec %d0, %CACR /* Invalidate cache */
  308. move.l #(CONFIG_SYS_SDRAM_BASE + 0xc000), %d0 /* Setup cache mask */
  309. movec %d0, %ACR0 /* Enable cache */
  310. move.l #0x80000200, %d0 /* Setup cache mask */
  311. movec %d0, %CACR /* Enable cache */
  312. nop
  313. move.l #(CONFIG_SYS_INIT_RAM_ADDR+CONFIG_SYS_INIT_RAM_END-8), %a1
  314. moveq #1, %d0
  315. move.l %d0, (%a1)
  316. rts
  317. #endif
  318. #ifdef CONFIG_M5272
  319. .globl icache_enable
  320. icache_enable:
  321. move.l #0x01000000, %d0 /* Invalidate cache cmd */
  322. movec %d0, %CACR /* Invalidate cache */
  323. move.l #0x0000c000, %d0 /* Setup cache mask */
  324. movec %d0, %ACR0 /* Enable cache */
  325. move.l #0xff00c000, %d0 /* Setup cache mask */
  326. movec %d0, %ACR1 /* Enable cache */
  327. move.l #0x80000100, %d0 /* Setup cache mask */
  328. movec %d0, %CACR /* Enable cache */
  329. moveq #1, %d0
  330. move.l %d0, icache_state
  331. rts
  332. #endif
  333. #if defined(CONFIG_M5275)
  334. /*
  335. * Instruction cache only
  336. */
  337. .globl icache_enable
  338. icache_enable:
  339. move.l #0x01400000, %d0 /* Invalidate cache cmd */
  340. movec %d0, %CACR /* Invalidate cache */
  341. move.l #0x0000c000, %d0 /* Setup SDRAM caching */
  342. movec %d0, %ACR0 /* Enable cache */
  343. move.l #0x00000000, %d0 /* No other caching */
  344. movec %d0, %ACR1 /* Enable cache */
  345. move.l #0x80400100, %d0 /* Setup cache mask */
  346. movec %d0, %CACR /* Enable cache */
  347. moveq #1, %d0
  348. move.l %d0, icache_state
  349. rts
  350. #endif
  351. #ifdef CONFIG_M5282
  352. .globl icache_enable
  353. icache_enable:
  354. move.l #0x01000000, %d0 /* Invalidate cache cmd */
  355. movec %d0, %CACR /* Invalidate cache */
  356. move.l #0x0000c000, %d0 /* Setup cache mask */
  357. movec %d0, %ACR0 /* Enable cache */
  358. move.l #0xff00c000, %d0 /* Setup cache mask */
  359. movec %d0, %ACR1 /* Enable cache */
  360. move.l #0x80400100, %d0 /* Setup cache mask, data cache disabel*/
  361. movec %d0, %CACR /* Enable cache */
  362. moveq #1, %d0
  363. icache_state_access_1:
  364. move.l %d0, icache_state
  365. rts
  366. #endif
  367. #if defined(CONFIG_M5249) || defined(CONFIG_M5253)
  368. .globl icache_enable
  369. icache_enable:
  370. /*
  371. * Note: The 5249 Documentation doesn't give a bit position for CINV!
  372. * From the 5272 and the 5307 documentation, I have deduced that it is
  373. * probably CACR[24]. Should someone say something to Motorola?
  374. * ~Jeremy
  375. */
  376. move.l #0x01000000, %d0 /* Invalidate whole cache */
  377. move.c %d0,%CACR
  378. move.l #0xff00c000, %d0 /* Set FLASH cachable: always match (SM=0b10) */
  379. move.c %d0, %ACR0
  380. move.l #0x0000c000, %d0 /* Set SDRAM cachable: always match (SM=0b10) */
  381. move.c %d0, %ACR1
  382. move.l #0x90000200, %d0 /* Set cache enable cmd */
  383. move.c %d0,%CACR
  384. moveq #1, %d0
  385. move.l %d0, icache_state
  386. rts
  387. #endif
  388. .globl icache_disable
  389. icache_disable:
  390. move.l #0x00000100, %d0 /* Setup cache mask */
  391. movec %d0, %CACR /* Enable cache */
  392. clr.l %d0 /* Setup cache mask */
  393. movec %d0, %ACR0 /* Enable cache */
  394. movec %d0, %ACR1 /* Enable cache */
  395. moveq #0, %d0
  396. icache_state_access_2:
  397. move.l %d0, icache_state
  398. rts
  399. .globl icache_status
  400. icache_status:
  401. icache_state_access_3:
  402. move.l #(icache_state), %a0
  403. move.l (%a0), %d0
  404. rts
  405. .data
  406. icache_state:
  407. .long 0 /* cache is diabled on inirialization */
  408. .globl dcache_enable
  409. dcache_enable:
  410. /* dummy function */
  411. rts
  412. .globl dcache_disable
  413. dcache_disable:
  414. /* dummy function */
  415. rts
  416. .globl dcache_status
  417. dcache_status:
  418. /* dummy function */
  419. rts
  420. /*------------------------------------------------------------------------------*/
  421. .globl version_string
  422. version_string:
  423. .ascii U_BOOT_VERSION
  424. .ascii " (", U_BOOT_DATE, " - ", U_BOOT_TIME, ")"
  425. .ascii CONFIG_IDENT_STRING, "\0"
  426. .align 4