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