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