start.S 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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/core.h>
  35. #include <asm/mach-common/bits/dma.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. #ifdef CONFIG_HW_WATCHDOG
  50. # ifndef CONFIG_HW_WATCHDOG_TIMEOUT_START
  51. # define CONFIG_HW_WATCHDOG_TIMEOUT_START 5000
  52. # endif
  53. /* Program the watchdog with an initial timeout of ~5 seconds.
  54. * That should be long enough to bootstrap ourselves up and
  55. * then the common u-boot code can take over.
  56. */
  57. P0.L = LO(WDOG_CNT);
  58. P0.H = HI(WDOG_CNT);
  59. R0.L = 0;
  60. R0.H = HI(MSEC_TO_SCLK(CONFIG_HW_WATCHDOG_TIMEOUT_START));
  61. [P0] = R0;
  62. /* fire up the watchdog - R0.L above needs to be 0x0000 */
  63. W[P0 + (WDOG_CTL - WDOG_CNT)] = R0;
  64. #endif
  65. /* Turn on the serial for debugging the init process */
  66. serial_early_init
  67. serial_early_set_baud
  68. serial_early_puts("Init Registers");
  69. /* Disable self-nested interrupts and enable CYCLES for udelay() */
  70. R0 = CCEN | 0x30;
  71. SYSCFG = R0;
  72. /* Zero out registers required by Blackfin ABI.
  73. * http://docs.blackfin.uclinux.org/doku.php?id=application_binary_interface
  74. */
  75. r1 = 0 (x);
  76. /* Disable circular buffers */
  77. l0 = r1;
  78. l1 = r1;
  79. l2 = r1;
  80. l3 = r1;
  81. /* Disable hardware loops in case we were started by 'go' */
  82. lc0 = r1;
  83. lc1 = r1;
  84. /* Save RETX so we can pass it while booting Linux */
  85. r7 = RETX;
  86. /* Figure out where we are currently executing so that we can decide
  87. * how to best reprogram and relocate things. We'll pass below:
  88. * R4: load address of _start
  89. * R5: current (not load) address of _start
  90. */
  91. serial_early_puts("Find ourselves");
  92. call _get_pc;
  93. .Loffset:
  94. r1.l = .Loffset;
  95. r1.h = .Loffset;
  96. r4.l = _start;
  97. r4.h = _start;
  98. r3 = r1 - r4;
  99. r5 = r0 - r3;
  100. /* Inform upper layers if we had to do the relocation ourselves.
  101. * This allows us to detect whether we were loaded by 'go 0x1000'
  102. * or by the bootrom from an LDR. "R6" is "loaded_from_ldr".
  103. */
  104. r6 = 1 (x);
  105. cc = r4 == r5;
  106. if cc jump .Lnorelocate;
  107. r6 = 0 (x);
  108. /* In bypass mode, we don't have an LDR with an init block
  109. * so we need to explicitly call it ourselves. This will
  110. * reprogram our clocks, memory, and setup our async banks.
  111. */
  112. serial_early_puts("Program Clocks");
  113. /* if we're executing >=0x20000000, then we dont need to dma */
  114. r3 = 0x0;
  115. r3.h = 0x2000;
  116. cc = r5 < r3 (iu);
  117. if cc jump .Ldma_and_reprogram;
  118. r0 = 0 (x); /* set bootstruct to NULL */
  119. call _initcode;
  120. jump .Lprogrammed;
  121. /* we're sitting in external memory, so dma into L1 and reprogram */
  122. .Ldma_and_reprogram:
  123. r0.l = LO(L1_INST_SRAM);
  124. r0.h = HI(L1_INST_SRAM);
  125. r1.l = __initcode_start;
  126. r1.h = __initcode_start;
  127. r2.l = __initcode_end;
  128. r2.h = __initcode_end;
  129. r2 = r2 - r1; /* convert r2 into length of initcode */
  130. r1 = r1 - r4; /* convert r1 from load address of initcode ... */
  131. r1 = r1 + r5; /* ... to current (not load) address of initcode */
  132. p3 = r0;
  133. call _dma_memcpy_nocache;
  134. r0 = 0 (x); /* set bootstruct to NULL */
  135. call (p3);
  136. /* Since we reprogrammed SCLK, we need to update the serial divisor */
  137. .Lprogrammed:
  138. serial_early_set_baud
  139. /* Relocate from wherever we are (FLASH/RAM/etc...) to the hardcoded
  140. * monitor location in the end of RAM. We know that memcpy() only
  141. * uses registers, so it is safe to call here. Note that this only
  142. * copies to external memory ... we do not start executing out of
  143. * it yet (see "lower to 15" below).
  144. */
  145. serial_early_puts("Relocate");
  146. r0 = r4;
  147. r1 = r5;
  148. r2.l = LO(CONFIG_SYS_MONITOR_LEN);
  149. r2.h = HI(CONFIG_SYS_MONITOR_LEN);
  150. call _memcpy_ASM;
  151. /* Initialize BSS section ... we know that memset() does not
  152. * use the BSS, so it is safe to call here. The bootrom LDR
  153. * takes care of clearing things for us.
  154. */
  155. serial_early_puts("Zero BSS");
  156. r0.l = __bss_start;
  157. r0.h = __bss_start;
  158. r1 = 0 (x);
  159. r2.l = __bss_end;
  160. r2.h = __bss_end;
  161. r2 = r2 - r0;
  162. call _memset;
  163. .Lnorelocate:
  164. /* Setup the actual stack in external memory */
  165. sp.h = HI(CONFIG_STACKBASE);
  166. sp.l = LO(CONFIG_STACKBASE);
  167. fp = sp;
  168. /* Now lower ourselves from the highest interrupt level to
  169. * the lowest. We do this by masking all interrupts but 15,
  170. * setting the 15 handler to ".Lenable_nested", raising the 15
  171. * interrupt, and then returning from the highest interrupt
  172. * level to the dummy "jump" until the interrupt controller
  173. * services the pending 15 interrupt. If executing out of
  174. * flash, these steps also changes the code flow from flash
  175. * to external memory.
  176. */
  177. serial_early_puts("Lower to 15");
  178. r0 = r7;
  179. r1 = r6;
  180. p0.l = LO(EVT15);
  181. p0.h = HI(EVT15);
  182. p1.l = .Lenable_nested;
  183. p1.h = .Lenable_nested;
  184. [p0] = p1;
  185. r7 = EVT_IVG15 (z);
  186. sti r7;
  187. raise 15;
  188. p4.l = .LWAIT_HERE;
  189. p4.h = .LWAIT_HERE;
  190. reti = p4;
  191. rti;
  192. /* Enable nested interrupts before continuing with cpu init */
  193. .Lenable_nested:
  194. cli r7;
  195. [--sp] = reti;
  196. jump.l _cpu_init_f;
  197. .LWAIT_HERE:
  198. jump .LWAIT_HERE;
  199. ENDPROC(_start)
  200. LENTRY(_get_pc)
  201. r0 = rets;
  202. #if ANOMALY_05000371
  203. NOP;
  204. NOP;
  205. NOP;
  206. #endif
  207. rts;
  208. ENDPROC(_get_pc)