2 * U-Boot - start.S Startup file for Blackfin U-Boot
4 * Copyright (c) 2005-2008 Analog Devices Inc.
6 * This file is based on head.S
7 * Copyright (c) 2003 Metrowerks/Motorola
10 * The Silver Hammer Group, Ltd.
11 * (c) 1995, Dionne & Associates
12 * (c) 1995, DKG Display Tech.
14 * SPDX-License-Identifier: GPL-2.0+
18 #include <asm/blackfin.h>
19 #include <asm/mach-common/bits/watchdog.h>
20 #include <asm/mach-common/bits/core.h>
21 #include <asm/mach-common/bits/pll.h>
22 #include <asm/serial.h>
24 /* It may seem odd that we make calls to functions even though we haven't
25 * relocated ourselves yet out of {flash,ram,wherever}. This is OK because
26 * the "call" instruction in the Blackfin architecture is actually PC
27 * relative. So we can call functions all we want and not worry about them
28 * not being relocated yet.
34 /* Set our initial stack to L1 scratch space */
35 sp.l = LO(L1_SRAM_SCRATCH_END - 20);
36 sp.h = HI(L1_SRAM_SCRATCH_END - 20);
38 /* Optimization register tricks: keep a base value in the
39 * reserved P registers so we use the load/store with an
40 * offset syntax. R0 = [P5 + <constant>];
41 * P4 - system MMR base
44 #ifdef CONFIG_HW_WATCHDOG
46 p4.h = HI(SYSMMR_BASE);
49 p5.h = HI(COREMMR_BASE);
51 #ifdef CONFIG_HW_WATCHDOG
52 /* Program the watchdog with default timeout of ~5 seconds.
53 * That should be long enough to bootstrap ourselves up and
54 * then the common U-Boot code can take over.
58 [p4 + (WDOG_CTL - SYSMMR_BASE)] = r1;
60 W[p4 + (WDOG_CTL - SYSMMR_BASE)] = r1;
64 r0.h = HI(MSEC_TO_SCLK(CONFIG_WATCHDOG_TIMEOUT_MSECS));
65 [p4 + (WDOG_CNT - SYSMMR_BASE)] = r0;
68 /* fire up the watchdog - R0.L above needs to be 0x0000 */
70 [p4 + (WDOG_CTL - SYSMMR_BASE)] = r1;
72 W[p4 + (WDOG_CTL - SYSMMR_BASE)] = r1;
77 /* Turn on the serial for debugging the init process */
81 serial_early_puts("Init Registers");
83 /* Disable self-nested interrupts and enable CYCLES for udelay() */
87 /* Zero out registers required by Blackfin ABI.
88 * http://docs.blackfin.uclinux.org/doku.php?id=application_binary_interface
91 /* Disable circular buffers */
96 /* Disable hardware loops in case we were started by 'go' */
100 /* Save RETX so we can pass it while booting Linux */
104 /* Figure out where we are currently executing so that we can decide
105 * how to best reprogram and relocate things. We'll pass below:
106 * R4: load address of _start
107 * R5: current (not load) address of _start
109 serial_early_puts("Find ourselves");
120 /* Inform upper layers if we had to do the relocation ourselves.
121 * This allows us to detect whether we were loaded by 'go 0x1000'
122 * or by the bootrom from an LDR. "R6" is "loaded_from_ldr".
126 if cc jump .Lnorelocate;
129 /* Turn off caches as they require CPLBs and a CPLB miss requires
130 * a software exception handler to process it. But we're about to
131 * clobber any previous executing software (like U-Boot that just
132 * launched a new U-Boot via 'go'), so any handler state will be
133 * unreliable after the memcpy below.
135 serial_early_puts("Kill Caches");
137 [p5 + (IMEM_CONTROL - COREMMR_BASE)] = r0;
138 [p5 + (DMEM_CONTROL - COREMMR_BASE)] = r0;
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.
145 serial_early_puts("Program Clocks");
147 /* if we're executing >=0x20000000, then we dont need to dma */
151 if cc jump .Ldma_and_reprogram;
153 r6 = 1 (x); /* fake loaded_from_ldr = 1 */
155 r0 = 0 (x); /* set bootstruct to NULL */
159 /* we're sitting in external memory, so dma into L1 and reprogram */
161 r0.l = LO(L1_INST_SRAM);
162 r0.h = HI(L1_INST_SRAM);
163 r1.l = __initcode_lma;
164 r1.h = __initcode_lma;
165 r2.l = __initcode_len;
166 r2.h = __initcode_len;
167 r1 = r1 - r4; /* convert r1 from load address of initcode ... */
168 r1 = r1 + r5; /* ... to current (not load) address of initcode */
170 call _dma_memcpy_nocache;
171 r0 = 0 (x); /* set bootstruct to NULL */
174 /* Since we reprogrammed SCLK, we need to update the serial divisor */
176 serial_early_set_baud
179 /* Relocate from wherever we are (FLASH/RAM/etc...) to the hardcoded
180 * monitor location in the end of RAM. We know that memcpy() only
181 * uses registers, so it is safe to call here. Note that this only
182 * copies to external memory ... we do not start executing out of
183 * it yet (see "lower to 15" below).
185 serial_early_puts("Relocate");
188 r2.l = LO(CONFIG_SYS_MONITOR_LEN);
189 r2.h = HI(CONFIG_SYS_MONITOR_LEN);
194 /* Initialize BSS section ... we know that memset() does not
195 * use the BSS, so it is safe to call here. The bootrom LDR
196 * takes care of clearing things for us.
198 serial_early_puts("Zero BSS");
207 /* Setup the actual stack in external memory */
208 sp.h = HI(CONFIG_STACKBASE);
209 sp.l = LO(CONFIG_STACKBASE);
212 /* Now lower ourselves from the highest interrupt level to
213 * the lowest. We do this by masking all interrupts but 15,
214 * setting the 15 handler to ".Lenable_nested", raising the 15
215 * interrupt, and then returning from the highest interrupt
216 * level to the dummy "jump" until the interrupt controller
217 * services the pending 15 interrupt. If executing out of
218 * flash, these steps also changes the code flow from flash
219 * to external memory.
221 serial_early_puts("Lower to 15");
224 p1.l = .Lenable_nested;
225 p1.h = .Lenable_nested;
226 [p5 + (EVT15 - COREMMR_BASE)] = p1;
235 /* Enable nested interrupts before continuing with cpu init */
255 ENTRY(_relocate_code)
256 /* Fake relocate code. Setup the new stack only */
263 ENDPROC(_relocate_code)