start.S 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  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. #include <asm/cache.h>
  27. #ifndef CONFIG_IDENT_STRING
  28. #define CONFIG_IDENT_STRING ""
  29. #endif
  30. #define _START _start
  31. #define _FAULT _fault
  32. #define SAVE_ALL \
  33. move.w #0x2700,%sr; /* disable intrs */ \
  34. subl #60,%sp; /* space for 15 regs */ \
  35. moveml %d0-%d7/%a0-%a6,%sp@;
  36. #define RESTORE_ALL \
  37. moveml %sp@,%d0-%d7/%a0-%a6; \
  38. addl #60,%sp; /* space for 15 regs */ \
  39. rte;
  40. #if defined(CONFIG_CF_SBF)
  41. #define ASM_DRAMINIT (asm_dram_init - CONFIG_SYS_TEXT_BASE + CONFIG_SYS_INIT_RAM_ADDR)
  42. #define ASM_SBF_IMG_HDR (asm_sbf_img_hdr - CONFIG_SYS_TEXT_BASE + CONFIG_SYS_INIT_RAM_ADDR)
  43. #endif
  44. .text
  45. /*
  46. * Vector table. This is used for initial platform startup.
  47. * These vectors are to catch any un-intended traps.
  48. */
  49. _vectors:
  50. #if defined(CONFIG_CF_SBF)
  51. INITSP: .long 0 /* Initial SP */
  52. INITPC: .long ASM_DRAMINIT /* Initial PC */
  53. #else
  54. INITSP: .long 0 /* Initial SP */
  55. INITPC: .long _START /* Initial PC */
  56. #endif
  57. vector02: .long _FAULT /* Access Error */
  58. vector03: .long _FAULT /* Address Error */
  59. vector04: .long _FAULT /* Illegal Instruction */
  60. vector05: .long _FAULT /* Reserved */
  61. vector06: .long _FAULT /* Reserved */
  62. vector07: .long _FAULT /* Reserved */
  63. vector08: .long _FAULT /* Privilege Violation */
  64. vector09: .long _FAULT /* Trace */
  65. vector0A: .long _FAULT /* Unimplemented A-Line */
  66. vector0B: .long _FAULT /* Unimplemented F-Line */
  67. vector0C: .long _FAULT /* Debug Interrupt */
  68. vector0D: .long _FAULT /* Reserved */
  69. vector0E: .long _FAULT /* Format Error */
  70. vector0F: .long _FAULT /* Unitialized Int. */
  71. /* Reserved */
  72. vector10_17:
  73. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  74. vector18: .long _FAULT /* Spurious Interrupt */
  75. vector19: .long _FAULT /* Autovector Level 1 */
  76. vector1A: .long _FAULT /* Autovector Level 2 */
  77. vector1B: .long _FAULT /* Autovector Level 3 */
  78. vector1C: .long _FAULT /* Autovector Level 4 */
  79. vector1D: .long _FAULT /* Autovector Level 5 */
  80. vector1E: .long _FAULT /* Autovector Level 6 */
  81. vector1F: .long _FAULT /* Autovector Level 7 */
  82. #if !defined(CONFIG_CF_SBF)
  83. /* TRAP #0 - #15 */
  84. vector20_2F:
  85. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  86. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  87. /* Reserved */
  88. vector30_3F:
  89. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  90. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  91. vector64_127:
  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. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  99. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  100. vector128_191:
  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. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  108. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  109. vector192_255:
  110. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  111. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  112. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  113. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  114. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  115. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  116. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  117. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  118. #endif
  119. #if defined(CONFIG_CF_SBF)
  120. /* Image header: chksum 4 bytes, len 4 bytes, img dest 4 bytes */
  121. asm_sbf_img_hdr:
  122. .long 0x00000000 /* checksum, not yet implemented */
  123. .long 0x00030000 /* image length */
  124. .long CONFIG_SYS_TEXT_BASE /* image to be relocated at */
  125. asm_dram_init:
  126. move.w #0x2700,%sr /* Mask off Interrupt */
  127. move.l #CONFIG_SYS_INIT_RAM_ADDR, %d0
  128. movec %d0, %VBR
  129. move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0
  130. movec %d0, %RAMBAR1
  131. /* initialize general use internal ram */
  132. move.l #0, %d0
  133. move.l #(ICACHE_STATUS), %a1 /* icache */
  134. move.l #(DCACHE_STATUS), %a2 /* dcache */
  135. move.l %d0, (%a1)
  136. move.l %d0, (%a2)
  137. /* invalidate and disable cache */
  138. move.l #(CONFIG_SYS_ICACHE_INV + CONFIG_SYS_DCACHE_INV), %d0
  139. movec %d0, %CACR /* Invalidate cache */
  140. move.l #0, %d0
  141. movec %d0, %ACR0
  142. movec %d0, %ACR1
  143. movec %d0, %ACR2
  144. movec %d0, %ACR3
  145. move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET), %sp
  146. clr.l %sp@-
  147. /* Must disable global address */
  148. move.l #0xFC008000, %a1
  149. move.l #(CONFIG_SYS_CS0_BASE), (%a1)
  150. move.l #0xFC008008, %a1
  151. move.l #(CONFIG_SYS_CS0_CTRL), (%a1)
  152. move.l #0xFC008004, %a1
  153. move.l #(CONFIG_SYS_CS0_MASK), (%a1)
  154. /* Dram Initialization a1, a2, and d0 */
  155. /* mscr sdram */
  156. move.l #0xFC0A4074, %a1
  157. move.b #(CONFIG_SYS_SDRAM_DRV_STRENGTH), (%a1)
  158. nop
  159. /* SDRAM Chip 0 and 1 */
  160. move.l #0xFC0B8110, %a1
  161. move.l #0xFC0B8114, %a2
  162. /* calculate the size */
  163. move.l #0x13, %d1
  164. move.l #(CONFIG_SYS_SDRAM_SIZE), %d2
  165. #ifdef CONFIG_SYS_SDRAM_BASE1
  166. lsr.l #1, %d2
  167. #endif
  168. dramsz_loop:
  169. lsr.l #1, %d2
  170. add.l #1, %d1
  171. cmp.l #1, %d2
  172. bne dramsz_loop
  173. /* SDRAM Chip 0 and 1 */
  174. move.l #(CONFIG_SYS_SDRAM_BASE), (%a1)
  175. or.l %d1, (%a1)
  176. #ifdef CONFIG_SYS_SDRAM_BASE1
  177. move.l #(CONFIG_SYS_SDRAM_BASE1), (%a2)
  178. or.l %d1, (%a2)
  179. #endif
  180. nop
  181. /* dram cfg1 and cfg2 */
  182. move.l #0xFC0B8008, %a1
  183. move.l #(CONFIG_SYS_SDRAM_CFG1), (%a1)
  184. nop
  185. move.l #0xFC0B800C, %a2
  186. move.l #(CONFIG_SYS_SDRAM_CFG2), (%a2)
  187. nop
  188. move.l #0xFC0B8000, %a1 /* Mode */
  189. move.l #0xFC0B8004, %a2 /* Ctrl */
  190. /* Issue PALL */
  191. move.l #(CONFIG_SYS_SDRAM_CTRL + 2), (%a2)
  192. nop
  193. #ifdef CONFIG_M54455EVB
  194. /* Issue LEMR */
  195. move.l #(CONFIG_SYS_SDRAM_EMOD + 0x408), (%a1)
  196. nop
  197. move.l #(CONFIG_SYS_SDRAM_MODE + 0x300), (%a1)
  198. nop
  199. #endif
  200. move.l #1000, %d1
  201. jsr asm_delay
  202. /* Issue PALL */
  203. move.l #(CONFIG_SYS_SDRAM_CTRL + 2), (%a2)
  204. nop
  205. /* Perform two refresh cycles */
  206. move.l #(CONFIG_SYS_SDRAM_CTRL + 4), %d0
  207. nop
  208. move.l %d0, (%a2)
  209. move.l %d0, (%a2)
  210. nop
  211. #ifdef CONFIG_M54455EVB
  212. move.l #(CONFIG_SYS_SDRAM_MODE + 0x200), (%a1)
  213. nop
  214. #elif defined(CONFIG_M54451EVB)
  215. /* Issue LEMR */
  216. move.l #(CONFIG_SYS_SDRAM_MODE), (%a1)
  217. nop
  218. move.l #(CONFIG_SYS_SDRAM_EMOD), (%a1)
  219. #endif
  220. move.l #500, %d1
  221. jsr asm_delay
  222. move.l #(CONFIG_SYS_SDRAM_CTRL), %d1
  223. and.l #0x7FFFFFFF, %d1
  224. #ifdef CONFIG_M54455EVB
  225. or.l #0x10000C00, %d1
  226. #elif defined(CONFIG_M54451EVB)
  227. or.l #0x10000C00, %d1
  228. #endif
  229. move.l %d1, (%a2)
  230. nop
  231. move.l #2000, %d1
  232. jsr asm_delay
  233. /*
  234. * DSPI Initialization
  235. * a0 - general, sram - 0x80008000 - 32, see M54455EVB.h
  236. * a1 - dspi status
  237. * a2 - dtfr
  238. * a3 - drfr
  239. * a4 - Dst addr
  240. */
  241. /* Enable pins for DSPI mode - chip-selects are enabled later */
  242. asm_dspi_init:
  243. move.l #0xFC0A4063, %a0
  244. move.b #0x7F, (%a0)
  245. /* Configure DSPI module */
  246. move.l #0xFC05C000, %a0
  247. move.l #0x80FF0C00, (%a0) /* Master, clear TX/RX FIFO */
  248. move.l #0xFC05C00C, %a0
  249. move.l #0x3E000011, (%a0)
  250. move.l #0xFC05C034, %a2 /* dtfr */
  251. move.l #0xFC05C03B, %a3 /* drfr */
  252. move.l #(ASM_SBF_IMG_HDR + 4), %a1
  253. move.l (%a1)+, %d5
  254. move.l (%a1), %a4
  255. move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_SBFHDR_DATA_OFFSET), %a0
  256. move.l #(CONFIG_SYS_SBFHDR_SIZE), %d4
  257. move.l #0xFC05C02C, %a1 /* dspi status */
  258. /* Issue commands and address */
  259. move.l #0x8002000B, %d2 /* Fast Read Cmd */
  260. jsr asm_dspi_wr_status
  261. jsr asm_dspi_rd_status
  262. move.l #0x80020000, %d2 /* Address byte 2 */
  263. jsr asm_dspi_wr_status
  264. jsr asm_dspi_rd_status
  265. move.l #0x80020000, %d2 /* Address byte 1 */
  266. jsr asm_dspi_wr_status
  267. jsr asm_dspi_rd_status
  268. move.l #0x80020000, %d2 /* Address byte 0 */
  269. jsr asm_dspi_wr_status
  270. jsr asm_dspi_rd_status
  271. move.l #0x80020000, %d2 /* Dummy Wr and Rd */
  272. jsr asm_dspi_wr_status
  273. jsr asm_dspi_rd_status
  274. /* Transfer serial boot header to sram */
  275. asm_dspi_rd_loop1:
  276. move.l #0x80020000, %d2
  277. jsr asm_dspi_wr_status
  278. jsr asm_dspi_rd_status
  279. move.b %d1, (%a0) /* read, copy to dst */
  280. add.l #1, %a0 /* inc dst by 1 */
  281. sub.l #1, %d4 /* dec cnt by 1 */
  282. bne asm_dspi_rd_loop1
  283. /* Transfer u-boot from serial flash to memory */
  284. asm_dspi_rd_loop2:
  285. move.l #0x80020000, %d2
  286. jsr asm_dspi_wr_status
  287. jsr asm_dspi_rd_status
  288. move.b %d1, (%a4) /* read, copy to dst */
  289. add.l #1, %a4 /* inc dst by 1 */
  290. sub.l #1, %d5 /* dec cnt by 1 */
  291. bne asm_dspi_rd_loop2
  292. move.l #0x00020000, %d2 /* Terminate */
  293. jsr asm_dspi_wr_status
  294. jsr asm_dspi_rd_status
  295. /* jump to memory and execute */
  296. move.l #(CONFIG_SYS_TEXT_BASE + 0x400), %a0
  297. jmp (%a0)
  298. asm_dspi_wr_status:
  299. move.l (%a1), %d0 /* status */
  300. and.l #0x0000F000, %d0
  301. cmp.l #0x00003000, %d0
  302. bgt asm_dspi_wr_status
  303. move.l %d2, (%a2)
  304. rts
  305. asm_dspi_rd_status:
  306. move.l (%a1), %d0 /* status */
  307. and.l #0x000000F0, %d0
  308. lsr.l #4, %d0
  309. cmp.l #0, %d0
  310. beq asm_dspi_rd_status
  311. move.b (%a3), %d1
  312. rts
  313. asm_delay:
  314. nop
  315. subq.l #1, %d1
  316. bne asm_delay
  317. rts
  318. #endif /* CONFIG_CF_SBF */
  319. .text
  320. . = 0x400
  321. .globl _start
  322. _start:
  323. #if !defined(CONFIG_CF_SBF)
  324. nop
  325. nop
  326. move.w #0x2700,%sr /* Mask off Interrupt */
  327. /* Set vector base register at the beginning of the Flash */
  328. move.l #CONFIG_SYS_FLASH_BASE, %d0
  329. movec %d0, %VBR
  330. move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0
  331. movec %d0, %RAMBAR1
  332. /* initialize general use internal ram */
  333. move.l #0, %d0
  334. move.l #(ICACHE_STATUS), %a1 /* icache */
  335. move.l #(DCACHE_STATUS), %a2 /* dcache */
  336. move.l %d0, (%a1)
  337. move.l %d0, (%a2)
  338. /* invalidate and disable cache */
  339. move.l #(CONFIG_SYS_ICACHE_INV + CONFIG_SYS_DCACHE_INV), %d0
  340. movec %d0, %CACR /* Invalidate cache */
  341. move.l #0, %d0
  342. movec %d0, %ACR0
  343. movec %d0, %ACR1
  344. movec %d0, %ACR2
  345. movec %d0, %ACR3
  346. /* set stackpointer to end of internal ram to get some stackspace for
  347. the first c-code */
  348. move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET), %sp
  349. clr.l %sp@-
  350. #endif
  351. move.l #__got_start, %a5 /* put relocation table address to a5 */
  352. bsr cpu_init_f /* run low-level CPU init code (from flash) */
  353. bsr board_init_f /* run low-level board init code (from flash) */
  354. /* board_init_f() does not return */
  355. /*------------------------------------------------------------------------------*/
  356. /*
  357. * void relocate_code (addr_sp, gd, addr_moni)
  358. *
  359. * This "function" does not return, instead it continues in RAM
  360. * after relocating the monitor code.
  361. *
  362. * r3 = dest
  363. * r4 = src
  364. * r5 = length in bytes
  365. * r6 = cachelinesize
  366. */
  367. .globl relocate_code
  368. relocate_code:
  369. link.w %a6,#0
  370. move.l 8(%a6), %sp /* set new stack pointer */
  371. move.l 12(%a6), %d0 /* Save copy of Global Data pointer */
  372. move.l 16(%a6), %a0 /* Save copy of Destination Address */
  373. move.l #CONFIG_SYS_MONITOR_BASE, %a1
  374. move.l #__init_end, %a2
  375. move.l %a0, %a3
  376. /* copy the code to RAM */
  377. 1:
  378. move.l (%a1)+, (%a3)+
  379. cmp.l %a1,%a2
  380. bgt.s 1b
  381. /*
  382. * We are done. Do not return, instead branch to second part of board
  383. * initialization, now running from RAM.
  384. */
  385. move.l %a0, %a1
  386. add.l #(in_ram - CONFIG_SYS_MONITOR_BASE), %a1
  387. jmp (%a1)
  388. in_ram:
  389. clear_bss:
  390. /*
  391. * Now clear BSS segment
  392. */
  393. move.l %a0, %a1
  394. add.l #(_sbss - CONFIG_SYS_MONITOR_BASE),%a1
  395. move.l %a0, %d1
  396. add.l #(_ebss - CONFIG_SYS_MONITOR_BASE),%d1
  397. 6:
  398. clr.l (%a1)+
  399. cmp.l %a1,%d1
  400. bgt.s 6b
  401. /*
  402. * fix got table in RAM
  403. */
  404. move.l %a0, %a1
  405. add.l #(__got_start - CONFIG_SYS_MONITOR_BASE),%a1
  406. move.l %a1,%a5 /* * fix got pointer register a5 */
  407. move.l %a0, %a2
  408. add.l #(__got_end - CONFIG_SYS_MONITOR_BASE),%a2
  409. 7:
  410. move.l (%a1),%d1
  411. sub.l #_start,%d1
  412. add.l %a0,%d1
  413. move.l %d1,(%a1)+
  414. cmp.l %a2, %a1
  415. bne 7b
  416. /* calculate relative jump to board_init_r in ram */
  417. move.l %a0, %a1
  418. add.l #(board_init_r - CONFIG_SYS_MONITOR_BASE), %a1
  419. /* set parameters for board_init_r */
  420. move.l %a0,-(%sp) /* dest_addr */
  421. move.l %d0,-(%sp) /* gd */
  422. jsr (%a1)
  423. /*------------------------------------------------------------------------------*/
  424. /* exception code */
  425. .globl _fault
  426. _fault:
  427. bra _fault
  428. .globl _exc_handler
  429. _exc_handler:
  430. SAVE_ALL
  431. movel %sp,%sp@-
  432. bsr exc_handler
  433. addql #4,%sp
  434. RESTORE_ALL
  435. .globl _int_handler
  436. _int_handler:
  437. SAVE_ALL
  438. movel %sp,%sp@-
  439. bsr int_handler
  440. addql #4,%sp
  441. RESTORE_ALL
  442. /*------------------------------------------------------------------------------*/
  443. .globl version_string
  444. version_string:
  445. .ascii U_BOOT_VERSION
  446. .ascii " (", U_BOOT_DATE, " - ", U_BOOT_TIME, ")"
  447. .ascii CONFIG_IDENT_STRING, "\0"
  448. .align 4