start.S 14 KB

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