start.S 14 KB

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