start.S 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /*
  2. * U-Boot - start.S Startup file for Blackfin U-Boot
  3. *
  4. * Copyright (c) 2005-2008 Analog Devices Inc.
  5. *
  6. * This file is based on head.S
  7. * Copyright (c) 2003 Metrowerks/Motorola
  8. * Copyright (C) 1998 D. Jeff Dionne <jeff@ryeham.ee.ryerson.ca>,
  9. * Kenneth Albanowski <kjahds@kjahds.com>,
  10. * The Silver Hammer Group, Ltd.
  11. * (c) 1995, Dionne & Associates
  12. * (c) 1995, DKG Display Tech.
  13. *
  14. * SPDX-License-Identifier: GPL-2.0+
  15. */
  16. #include <config.h>
  17. #include <asm/blackfin.h>
  18. #include <asm/mach-common/bits/watchdog.h>
  19. #include <asm/mach-common/bits/core.h>
  20. #include <asm/mach-common/bits/pll.h>
  21. #include <asm/serial.h>
  22. /* It may seem odd that we make calls to functions even though we haven't
  23. * relocated ourselves yet out of {flash,ram,wherever}. This is OK because
  24. * the "call" instruction in the Blackfin architecture is actually PC
  25. * relative. So we can call functions all we want and not worry about them
  26. * not being relocated yet.
  27. */
  28. .text
  29. ENTRY(_start)
  30. /* Set our initial stack to L1 scratch space */
  31. sp.l = LO(L1_SRAM_SCRATCH_END - 20);
  32. sp.h = HI(L1_SRAM_SCRATCH_END - 20);
  33. /* Optimization register tricks: keep a base value in the
  34. * reserved P registers so we use the load/store with an
  35. * offset syntax. R0 = [P5 + <constant>];
  36. * P4 - system MMR base
  37. * P5 - core MMR base
  38. */
  39. #ifdef CONFIG_HW_WATCHDOG
  40. p4.l = 0;
  41. p4.h = HI(SYSMMR_BASE);
  42. #endif
  43. p5.l = 0;
  44. p5.h = HI(COREMMR_BASE);
  45. #ifdef CONFIG_HW_WATCHDOG
  46. /* Program the watchdog with default timeout of ~5 seconds.
  47. * That should be long enough to bootstrap ourselves up and
  48. * then the common U-Boot code can take over.
  49. */
  50. r1 = WDDIS;
  51. # ifdef __ADSPBF60x__
  52. [p4 + (WDOG_CTL - SYSMMR_BASE)] = r1;
  53. # else
  54. W[p4 + (WDOG_CTL - SYSMMR_BASE)] = r1;
  55. # endif
  56. SSYNC;
  57. r0 = 0;
  58. r0.h = HI(MSEC_TO_SCLK(CONFIG_WATCHDOG_TIMEOUT_MSECS));
  59. [p4 + (WDOG_CNT - SYSMMR_BASE)] = r0;
  60. SSYNC;
  61. r1 = WDEN;
  62. /* fire up the watchdog - R0.L above needs to be 0x0000 */
  63. # ifdef __ADSPBF60x__
  64. [p4 + (WDOG_CTL - SYSMMR_BASE)] = r1;
  65. # else
  66. W[p4 + (WDOG_CTL - SYSMMR_BASE)] = r1;
  67. # endif
  68. SSYNC;
  69. #endif
  70. /* Turn on the serial for debugging the init process */
  71. serial_early_init
  72. serial_early_set_baud
  73. serial_early_puts("Init Registers");
  74. /* Disable self-nested interrupts and enable CYCLES for udelay() */
  75. R0 = CCEN | 0x30;
  76. SYSCFG = R0;
  77. /* Zero out registers required by Blackfin ABI.
  78. * http://docs.blackfin.uclinux.org/doku.php?id=application_binary_interface
  79. */
  80. r1 = 0 (x);
  81. /* Disable circular buffers */
  82. l0 = r1;
  83. l1 = r1;
  84. l2 = r1;
  85. l3 = r1;
  86. /* Disable hardware loops in case we were started by 'go' */
  87. lc0 = r1;
  88. lc1 = r1;
  89. /* Save RETX so we can pass it while booting Linux */
  90. r7 = RETX;
  91. #if CONFIG_MEM_SIZE
  92. /* Figure out where we are currently executing so that we can decide
  93. * how to best reprogram and relocate things. We'll pass below:
  94. * R4: load address of _start
  95. * R5: current (not load) address of _start
  96. */
  97. serial_early_puts("Find ourselves");
  98. call _get_pc;
  99. .Loffset:
  100. r1.l = .Loffset;
  101. r1.h = .Loffset;
  102. r4.l = _start;
  103. r4.h = _start;
  104. r3 = r1 - r4;
  105. r5 = r0 - r3;
  106. /* Inform upper layers if we had to do the relocation ourselves.
  107. * This allows us to detect whether we were loaded by 'go 0x1000'
  108. * or by the bootrom from an LDR. "R6" is "loaded_from_ldr".
  109. */
  110. r6 = 1 (x);
  111. cc = r4 == r5;
  112. if cc jump .Lnorelocate;
  113. r6 = 0 (x);
  114. /* Turn off caches as they require CPLBs and a CPLB miss requires
  115. * a software exception handler to process it. But we're about to
  116. * clobber any previous executing software (like U-Boot that just
  117. * launched a new U-Boot via 'go'), so any handler state will be
  118. * unreliable after the memcpy below.
  119. */
  120. serial_early_puts("Kill Caches");
  121. r0 = 0;
  122. [p5 + (IMEM_CONTROL - COREMMR_BASE)] = r0;
  123. [p5 + (DMEM_CONTROL - COREMMR_BASE)] = r0;
  124. ssync;
  125. /* In bypass mode, we don't have an LDR with an init block
  126. * so we need to explicitly call it ourselves. This will
  127. * reprogram our clocks, memory, and setup our async banks.
  128. */
  129. serial_early_puts("Program Clocks");
  130. /* if we're executing >=0x20000000, then we dont need to dma */
  131. r3 = 0x0;
  132. r3.h = 0x2000;
  133. cc = r5 < r3 (iu);
  134. if cc jump .Ldma_and_reprogram;
  135. #else
  136. r6 = 1 (x); /* fake loaded_from_ldr = 1 */
  137. #endif
  138. r0 = 0 (x); /* set bootstruct to NULL */
  139. call _initcode;
  140. jump .Lprogrammed;
  141. /* we're sitting in external memory, so dma into L1 and reprogram */
  142. .Ldma_and_reprogram:
  143. r0.l = LO(L1_INST_SRAM);
  144. r0.h = HI(L1_INST_SRAM);
  145. r1.l = __initcode_lma;
  146. r1.h = __initcode_lma;
  147. r2.l = __initcode_len;
  148. r2.h = __initcode_len;
  149. r1 = r1 - r4; /* convert r1 from load address of initcode ... */
  150. r1 = r1 + r5; /* ... to current (not load) address of initcode */
  151. p3 = r0;
  152. call _dma_memcpy_nocache;
  153. r0 = 0 (x); /* set bootstruct to NULL */
  154. call (p3);
  155. /* Since we reprogrammed SCLK, we need to update the serial divisor */
  156. .Lprogrammed:
  157. serial_early_set_baud
  158. #if CONFIG_MEM_SIZE
  159. /* Relocate from wherever we are (FLASH/RAM/etc...) to the hardcoded
  160. * monitor location in the end of RAM. We know that memcpy() only
  161. * uses registers, so it is safe to call here. Note that this only
  162. * copies to external memory ... we do not start executing out of
  163. * it yet (see "lower to 15" below).
  164. */
  165. serial_early_puts("Relocate");
  166. r0 = r4;
  167. r1 = r5;
  168. r2.l = LO(CONFIG_SYS_MONITOR_LEN);
  169. r2.h = HI(CONFIG_SYS_MONITOR_LEN);
  170. call _memcpy_ASM;
  171. #endif
  172. .Lnorelocate:
  173. /* Initialize BSS section ... we know that memset() does not
  174. * use the BSS, so it is safe to call here. The bootrom LDR
  175. * takes care of clearing things for us.
  176. */
  177. serial_early_puts("Zero BSS");
  178. r0.l = __bss_start;
  179. r0.h = __bss_start;
  180. r1 = 0 (x);
  181. r2.l = __bss_len;
  182. r2.h = __bss_len;
  183. call _memset;
  184. /* Setup the actual stack in external memory */
  185. sp.h = HI(CONFIG_STACKBASE);
  186. sp.l = LO(CONFIG_STACKBASE);
  187. fp = sp;
  188. /* Now lower ourselves from the highest interrupt level to
  189. * the lowest. We do this by masking all interrupts but 15,
  190. * setting the 15 handler to ".Lenable_nested", raising the 15
  191. * interrupt, and then returning from the highest interrupt
  192. * level to the dummy "jump" until the interrupt controller
  193. * services the pending 15 interrupt. If executing out of
  194. * flash, these steps also changes the code flow from flash
  195. * to external memory.
  196. */
  197. serial_early_puts("Lower to 15");
  198. r0 = r7;
  199. r1 = r6;
  200. p1.l = .Lenable_nested;
  201. p1.h = .Lenable_nested;
  202. [p5 + (EVT15 - COREMMR_BASE)] = p1;
  203. r7 = EVT_IVG15 (z);
  204. sti r7;
  205. raise 15;
  206. p3.l = .LWAIT_HERE;
  207. p3.h = .LWAIT_HERE;
  208. reti = p3;
  209. rti;
  210. /* Enable nested interrupts before continuing with cpu init */
  211. .Lenable_nested:
  212. cli r7;
  213. [--sp] = reti;
  214. jump.l _cpu_init_f;
  215. .LWAIT_HERE:
  216. jump .LWAIT_HERE;
  217. ENDPROC(_start)
  218. LENTRY(_get_pc)
  219. r0 = rets;
  220. #if ANOMALY_05000371
  221. NOP;
  222. NOP;
  223. NOP;
  224. #endif
  225. rts;
  226. ENDPROC(_get_pc)
  227. ENTRY(_relocate_code)
  228. /* Fake relocate code. Setup the new stack only */
  229. sp = r0;
  230. fp = sp;
  231. r0 = p3;
  232. r1.h = 0x2000;
  233. r1.l = 0x10;
  234. jump.l _board_init_r
  235. ENDPROC(_relocate_code)