start.S 7.4 KB

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