start.S 12 KB

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