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