start.S 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /*
  2. * U-boot - start.S Startup file for Blackfin u-boot
  3. *
  4. * Copyright (c) 2005-2007 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 + L1_SRAM_SCRATCH_SIZE);
  48. sp.h = HI(L1_SRAM_SCRATCH + L1_SRAM_SCRATCH_SIZE);
  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 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. #if (CONFIG_BFIN_BOOT_MODE == BFIN_BOOT_BYPASS)
  87. /* In bypass mode, we don't have an LDR with an init block
  88. * so we need to explicitly call it ourselves. This will
  89. * reprogram our clocks and setup our async banks.
  90. */
  91. /* XXX: we should DMA this into L1, put external memory into
  92. * self refresh, and then jump there ...
  93. */
  94. call _get_pc;
  95. r3 = 0x0;
  96. r3.h = 0x2000;
  97. cc = r0 < r3 (iu);
  98. if cc jump .Lproc_initialized;
  99. serial_early_puts("Program Clocks");
  100. call _initcode;
  101. /* Since we reprogrammed SCLK, we need to update the serial divisor */
  102. serial_early_set_baud
  103. .Lproc_initialized:
  104. #endif
  105. /* Inform upper layers if we had to do the relocation ourselves.
  106. * This allows us to detect whether we were loaded by 'go 0x1000'
  107. * or by the bootrom from an LDR. "r6" is "loaded_from_ldr".
  108. */
  109. r6 = 1 (x);
  110. /* Relocate from wherever are (FLASH/RAM/etc...) to the
  111. * hardcoded monitor location in the end of RAM.
  112. */
  113. serial_early_puts("Relocate");
  114. call _get_pc;
  115. .Loffset:
  116. r2.l = .Loffset;
  117. r2.h = .Loffset;
  118. r3.l = _start;
  119. r3.h = _start;
  120. r1 = r2 - r3;
  121. r0 = r0 - r1;
  122. cc = r0 == r3;
  123. if cc jump .Lnorelocate;
  124. r6 = 0 (x);
  125. p1 = r0;
  126. p2.l = LO(CFG_MONITOR_BASE);
  127. p2.h = HI(CFG_MONITOR_BASE);
  128. p3 = 0x04;
  129. p4.l = LO(CFG_MONITOR_BASE + CFG_MONITOR_LEN);
  130. p4.h = HI(CFG_MONITOR_BASE + CFG_MONITOR_LEN);
  131. .Lloop1:
  132. r1 = [p1 ++ p3];
  133. [p2 ++ p3] = r1;
  134. cc=p2==p4;
  135. if !cc jump .Lloop1;
  136. /* Initialize BSS section ... we know that memset() does not
  137. * use the BSS, so it is safe to call here. The bootrom LDR
  138. * takes care of clearing things for us.
  139. */
  140. serial_early_puts("Zero BSS");
  141. r0.l = __bss_start;
  142. r0.h = __bss_start;
  143. r1 = 0 (x);
  144. r2.l = __bss_end;
  145. r2.h = __bss_end;
  146. r2 = r2 - r0;
  147. call _memset;
  148. .Lnorelocate:
  149. /* Setup the actual stack in external memory */
  150. r0.h = HI(CONFIG_STACKBASE);
  151. r0.l = LO(CONFIG_STACKBASE);
  152. sp = r0;
  153. fp = sp;
  154. /* Now lower ourselves from the highest interrupt level to
  155. * the lowest. We do this by masking all interrupts but 15,
  156. * setting the 15 handler to "board_init_f", raising the 15
  157. * interrupt, and then returning from the highest interrupt
  158. * level to the dummy "jump" until the interrupt controller
  159. * services the pending 15 interrupt.
  160. */
  161. serial_early_puts("Lower to 15");
  162. r0 = r7;
  163. r1 = r6;
  164. p0.l = LO(EVT15);
  165. p0.h = HI(EVT15);
  166. p1.l = _cpu_init_f;
  167. p1.h = _cpu_init_f;
  168. [p0] = p1;
  169. p2.l = LO(IMASK);
  170. p2.h = HI(IMASK);
  171. p3.l = LO(EVT_IVG15);
  172. p3.h = HI(EVT_IVG15);
  173. [p2] = p3;
  174. raise 15;
  175. p4.l = .LWAIT_HERE;
  176. p4.h = .LWAIT_HERE;
  177. reti = p4;
  178. rti;
  179. .LWAIT_HERE:
  180. jump .LWAIT_HERE;
  181. ENDPROC(_start)
  182. LENTRY(_get_pc)
  183. r0 = rets;
  184. #if ANOMALY_05000371
  185. NOP;
  186. NOP;
  187. NOP;
  188. #endif
  189. rts;
  190. ENDPROC(_get_pc)