start.S 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  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 0x00020000 /* image length */
  124. .long CONFIG_SYS_TEXT_BASE /* image to be relocated at */
  125. asm_dram_init:
  126. move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0
  127. movec %d0, %RAMBAR1 /* init Rambar */
  128. move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET), %sp
  129. clr.l %sp@-
  130. /* Must disable global address */
  131. move.l #0xFC008000, %a1
  132. move.l #(CONFIG_SYS_CS0_BASE), (%a1)
  133. move.l #0xFC008008, %a1
  134. move.l #(CONFIG_SYS_CS0_CTRL), (%a1)
  135. move.l #0xFC008004, %a1
  136. move.l #(CONFIG_SYS_CS0_MASK), (%a1)
  137. /*
  138. * Dram Initialization
  139. * a1, a2, and d0
  140. */
  141. /* mscr sdram */
  142. move.l #0xFC0A4074, %a1
  143. move.b #(CONFIG_SYS_SDRAM_DRV_STRENGTH), (%a1)
  144. nop
  145. /* SDRAM Chip 0 and 1 */
  146. move.l #0xFC0B8110, %a1
  147. move.l #0xFC0B8114, %a2
  148. /* calculate the size */
  149. move.l #0x13, %d1
  150. move.l #(CONFIG_SYS_SDRAM_SIZE), %d2
  151. #ifdef CONFIG_SYS_SDRAM_BASE1
  152. lsr.l #1, %d2
  153. #endif
  154. dramsz_loop:
  155. lsr.l #1, %d2
  156. add.l #1, %d1
  157. cmp.l #1, %d2
  158. bne dramsz_loop
  159. /* SDRAM Chip 0 and 1 */
  160. move.l #(CONFIG_SYS_SDRAM_BASE), (%a1)
  161. or.l %d1, (%a1)
  162. #ifdef CONFIG_SYS_SDRAM_BASE1
  163. move.l #(CONFIG_SYS_SDRAM_BASE1), (%a2)
  164. or.l %d1, (%a2)
  165. #endif
  166. nop
  167. /* dram cfg1 and cfg2 */
  168. move.l #0xFC0B8008, %a1
  169. move.l #(CONFIG_SYS_SDRAM_CFG1), (%a1)
  170. nop
  171. move.l #0xFC0B800C, %a2
  172. move.l #(CONFIG_SYS_SDRAM_CFG2), (%a2)
  173. nop
  174. move.l #0xFC0B8000, %a1 /* Mode */
  175. move.l #0xFC0B8004, %a2 /* Ctrl */
  176. /* Issue PALL */
  177. move.l #(CONFIG_SYS_SDRAM_CTRL + 2), (%a2)
  178. nop
  179. /* Issue LEMR */
  180. move.l #(CONFIG_SYS_SDRAM_MODE), (%a1)
  181. nop
  182. move.l #(CONFIG_SYS_SDRAM_EMOD), (%a1)
  183. nop
  184. move.l #1000, %d0
  185. wait1000:
  186. nop
  187. subq.l #1, %d0
  188. bne wait1000
  189. /* Issue PALL */
  190. move.l #(CONFIG_SYS_SDRAM_CTRL + 2), (%a2)
  191. nop
  192. /* Perform two refresh cycles */
  193. move.l #(CONFIG_SYS_SDRAM_CTRL + 4), %d0
  194. nop
  195. move.l %d0, (%a2)
  196. move.l %d0, (%a2)
  197. nop
  198. move.l #(CONFIG_SYS_SDRAM_CTRL), %d0
  199. and.l #0x7FFFFFFF, %d0
  200. or.l #0x10000c00, %d0
  201. move.l %d0, (%a2)
  202. nop
  203. /*
  204. * DSPI Initialization
  205. * a0 - general, sram - 0x80008000 - 32, see M52277EVB.h
  206. * a1 - dspi status
  207. * a2 - dtfr
  208. * a3 - drfr
  209. * a4 - Dst addr
  210. */
  211. /* Enable pins for DSPI mode - chip-selects are enabled later */
  212. move.l #0xFC0A4036, %a0
  213. move.b #0x3F, %d0
  214. move.b %d0, (%a0)
  215. /* DSPI CS */
  216. #ifdef CONFIG_SYS_DSPI_CS0
  217. move.b (%a0), %d0
  218. or.l #0xC0, %d0
  219. move.b %d0, (%a0)
  220. #endif
  221. #ifdef CONFIG_SYS_DSPI_CS2
  222. move.l #0xFC0A4037, %a0
  223. move.b (%a0), %d0
  224. or.l #0x10, %d0
  225. move.b %d0, (%a0)
  226. #endif
  227. nop
  228. /* Configure DSPI module */
  229. move.l #0xFC05C000, %a0
  230. move.l #0x80FF0C00, (%a0) /* Master, clear TX/RX FIFO */
  231. move.l #0xFC05C00C, %a0
  232. move.l #0x3E000011, (%a0)
  233. move.l #0xFC05C034, %a2 /* dtfr */
  234. move.l #0xFC05C03B, %a3 /* drfr */
  235. move.l #(ASM_SBF_IMG_HDR + 4), %a1
  236. move.l (%a1)+, %d5
  237. move.l (%a1), %a4
  238. move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_SBFHDR_DATA_OFFSET), %a0
  239. move.l #(CONFIG_SYS_SBFHDR_SIZE), %d4
  240. move.l #0xFC05C02C, %a1 /* dspi status */
  241. /* Issue commands and address */
  242. move.l #0x8004000B, %d2 /* Fast Read Cmd */
  243. jsr asm_dspi_wr_status
  244. jsr asm_dspi_rd_status
  245. move.l #0x80040000, %d2 /* Address byte 2 */
  246. jsr asm_dspi_wr_status
  247. jsr asm_dspi_rd_status
  248. move.l #0x80040000, %d2 /* Address byte 1 */
  249. jsr asm_dspi_wr_status
  250. jsr asm_dspi_rd_status
  251. move.l #0x80040000, %d2 /* Address byte 0 */
  252. jsr asm_dspi_wr_status
  253. jsr asm_dspi_rd_status
  254. move.l #0x80040000, %d2 /* Dummy Wr and Rd */
  255. jsr asm_dspi_wr_status
  256. jsr asm_dspi_rd_status
  257. /* Transfer serial boot header to sram */
  258. asm_dspi_rd_loop1:
  259. move.l #0x80040000, %d2
  260. jsr asm_dspi_wr_status
  261. jsr asm_dspi_rd_status
  262. move.b %d1, (%a0) /* read, copy to dst */
  263. add.l #1, %a0 /* inc dst by 1 */
  264. sub.l #1, %d4 /* dec cnt by 1 */
  265. bne asm_dspi_rd_loop1
  266. /* Transfer u-boot from serial flash to memory */
  267. asm_dspi_rd_loop2:
  268. move.l #0x80040000, %d2
  269. jsr asm_dspi_wr_status
  270. jsr asm_dspi_rd_status
  271. move.b %d1, (%a4) /* read, copy to dst */
  272. add.l #1, %a4 /* inc dst by 1 */
  273. sub.l #1, %d5 /* dec cnt by 1 */
  274. bne asm_dspi_rd_loop2
  275. move.l #0x00040000, %d2 /* Terminate */
  276. jsr asm_dspi_wr_status
  277. jsr asm_dspi_rd_status
  278. /* jump to memory and execute */
  279. move.l #(CONFIG_SYS_TEXT_BASE + 0x400), %a0
  280. move.l %a0, (%a1)
  281. jmp (%a0)
  282. asm_dspi_wr_status:
  283. move.l (%a1), %d0 /* status */
  284. and.l #0x0000F000, %d0
  285. cmp.l #0x00003000, %d0
  286. bgt asm_dspi_wr_status
  287. move.l %d2, (%a2)
  288. rts
  289. asm_dspi_rd_status:
  290. move.l (%a1), %d0 /* status */
  291. and.l #0x000000F0, %d0
  292. lsr.l #4, %d0
  293. cmp.l #0, %d0
  294. beq asm_dspi_rd_status
  295. move.b (%a3), %d1
  296. rts
  297. #endif /* CONFIG_CF_SBF */
  298. .text
  299. . = 0x400
  300. .globl _start
  301. _start:
  302. nop
  303. nop
  304. move.w #0x2700,%sr /* Mask off Interrupt */
  305. /* Set vector base register at the beginning of the Flash */
  306. #if defined(CONFIG_CF_SBF)
  307. move.l #CONFIG_SYS_TEXT_BASE, %d0
  308. movec %d0, %VBR
  309. #else
  310. move.l #CONFIG_SYS_FLASH_BASE, %d0
  311. movec %d0, %VBR
  312. move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0
  313. movec %d0, %RAMBAR1
  314. #endif
  315. /* invalidate and disable cache */
  316. move.l #CF_CACR_CINV, %d0 /* Invalidate cache cmd */
  317. movec %d0, %CACR /* Invalidate cache */
  318. move.l #0, %d0
  319. movec %d0, %ACR0
  320. movec %d0, %ACR1
  321. /* initialize general use internal ram */
  322. move.l #0, %d0
  323. move.l #(ICACHE_STATUS), %a1 /* icache */
  324. move.l #(DCACHE_STATUS), %a2 /* icache */
  325. move.l %d0, (%a1)
  326. move.l %d0, (%a2)
  327. /* set stackpointer to end of internal ram to get some stackspace for
  328. the first c-code */
  329. move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET), %sp
  330. clr.l %sp@-
  331. move.l #__got_start, %a5 /* put relocation table address to a5 */
  332. bsr cpu_init_f /* run low-level CPU init code (from flash) */
  333. bsr board_init_f /* run low-level board init code (from flash) */
  334. /* board_init_f() does not return */
  335. /*------------------------------------------------------------------------------*/
  336. /*
  337. * void relocate_code (addr_sp, gd, addr_moni)
  338. *
  339. * This "function" does not return, instead it continues in RAM
  340. * after relocating the monitor code.
  341. *
  342. * r3 = dest
  343. * r4 = src
  344. * r5 = length in bytes
  345. * r6 = cachelinesize
  346. */
  347. .globl relocate_code
  348. relocate_code:
  349. link.w %a6,#0
  350. move.l 8(%a6), %sp /* set new stack pointer */
  351. move.l 12(%a6), %d0 /* Save copy of Global Data pointer */
  352. move.l 16(%a6), %a0 /* Save copy of Destination Address */
  353. move.l #CONFIG_SYS_MONITOR_BASE, %a1
  354. move.l #__init_end, %a2
  355. move.l %a0, %a3
  356. /* copy the code to RAM */
  357. 1:
  358. move.l (%a1)+, (%a3)+
  359. cmp.l %a1,%a2
  360. bgt.s 1b
  361. /*
  362. * We are done. Do not return, instead branch to second part of board
  363. * initialization, now running from RAM.
  364. */
  365. move.l %a0, %a1
  366. add.l #(in_ram - CONFIG_SYS_MONITOR_BASE), %a1
  367. jmp (%a1)
  368. in_ram:
  369. clear_bss:
  370. /*
  371. * Now clear BSS segment
  372. */
  373. move.l %a0, %a1
  374. add.l #(_sbss - CONFIG_SYS_MONITOR_BASE),%a1
  375. move.l %a0, %d1
  376. add.l #(_ebss - CONFIG_SYS_MONITOR_BASE),%d1
  377. 6:
  378. clr.l (%a1)+
  379. cmp.l %a1,%d1
  380. bgt.s 6b
  381. /*
  382. * fix got table in RAM
  383. */
  384. move.l %a0, %a1
  385. add.l #(__got_start - CONFIG_SYS_MONITOR_BASE),%a1
  386. move.l %a1,%a5 /* * fix got pointer register a5 */
  387. move.l %a0, %a2
  388. add.l #(__got_end - CONFIG_SYS_MONITOR_BASE),%a2
  389. 7:
  390. move.l (%a1),%d1
  391. sub.l #_start,%d1
  392. add.l %a0,%d1
  393. move.l %d1,(%a1)+
  394. cmp.l %a2, %a1
  395. bne 7b
  396. /* calculate relative jump to board_init_r in ram */
  397. move.l %a0, %a1
  398. add.l #(board_init_r - CONFIG_SYS_MONITOR_BASE), %a1
  399. /* set parameters for board_init_r */
  400. move.l %a0,-(%sp) /* dest_addr */
  401. move.l %d0,-(%sp) /* gd */
  402. jsr (%a1)
  403. /*------------------------------------------------------------------------------*/
  404. /* exception code */
  405. .globl _fault
  406. _fault:
  407. jmp _fault
  408. .globl _exc_handler
  409. _exc_handler:
  410. SAVE_ALL
  411. movel %sp,%sp@-
  412. bsr exc_handler
  413. addql #4,%sp
  414. RESTORE_ALL
  415. .globl _int_handler
  416. _int_handler:
  417. SAVE_ALL
  418. movel %sp,%sp@-
  419. bsr int_handler
  420. addql #4,%sp
  421. RESTORE_ALL
  422. /*------------------------------------------------------------------------------*/
  423. .globl version_string
  424. version_string:
  425. .ascii U_BOOT_VERSION
  426. .ascii " (", U_BOOT_DATE, " - ", U_BOOT_TIME, ")"
  427. .ascii CONFIG_IDENT_STRING, "\0"
  428. .align 4