blob: 4391621d90488a1fcb7f89f72efca8bf707ecc6a [file] [log] [blame]
Mike Frysinger09e1f702008-08-06 17:15:27 +08001/*
2 * Common Blackfin startup code
3 *
4 * Copyright 2004-2008 Analog Devices Inc.
5 *
Mike Frysinger09e1f702008-08-06 17:15:27 +08006 * Licensed under the GPL-2 or later.
7 */
8
9#include <linux/linkage.h>
10#include <linux/init.h>
11#include <asm/blackfin.h>
Mike Frysinger67618fd2008-08-06 17:18:31 +080012#include <asm/thread_info.h>
Mike Frysinger09e1f702008-08-06 17:15:27 +080013#include <asm/trace.h>
Graf Yang6b3087c2009-01-07 23:14:39 +080014#include <asm/asm-offsets.h>
Mike Frysinger09e1f702008-08-06 17:15:27 +080015
Mike Frysinger17e89bc2008-08-06 17:23:50 +080016__INIT
17
Graf Yang9960aa62009-02-04 16:49:45 +080018ENTRY(__init_clear_bss)
19 r2 = r2 - r1;
20 cc = r2 == 0;
21 if cc jump .L_bss_done;
22 r2 >>= 2;
23 p1 = r1;
24 p2 = r2;
25 lsetup (1f, 1f) lc0 = p2;
261: [p1++] = r0;
27.L_bss_done:
28 rts;
29ENDPROC(__init_clear_bss)
30
Mike Frysinger17e89bc2008-08-06 17:23:50 +080031ENTRY(__start)
32 /* R0: argument of command line string, passed from uboot, save it */
33 R7 = R0;
34 /* Enable Cycle Counter and Nesting Of Interrupts */
35#ifdef CONFIG_BFIN_SCRATCH_REG_CYCLES
36 R0 = SYSCFG_SNEN;
37#else
38 R0 = SYSCFG_SNEN | SYSCFG_CCEN;
39#endif
40 SYSCFG = R0;
41 R0 = 0;
42
43 /* Clear Out All the data and pointer Registers */
44 R1 = R0;
45 R2 = R0;
46 R3 = R0;
47 R4 = R0;
48 R5 = R0;
49 R6 = R0;
50
51 P0 = R0;
52 P1 = R0;
53 P2 = R0;
54 P3 = R0;
55 P4 = R0;
56 P5 = R0;
57
58 LC0 = r0;
59 LC1 = r0;
60 L0 = r0;
61 L1 = r0;
62 L2 = r0;
63 L3 = r0;
64
65 /* Clear Out All the DAG Registers */
66 B0 = r0;
67 B1 = r0;
68 B2 = r0;
69 B3 = r0;
70
71 I0 = r0;
72 I1 = r0;
73 I2 = r0;
74 I3 = r0;
75
76 M0 = r0;
77 M1 = r0;
78 M2 = r0;
79 M3 = r0;
80
Robin Getz9df10282008-10-08 18:03:33 +080081 /*
82 * Clear ITEST_COMMAND and DTEST_COMMAND registers,
83 * Leaving these as non-zero can confuse the emulator
84 */
85 p0.L = LO(DTEST_COMMAND);
86 p0.H = HI(DTEST_COMMAND);
87 [p0] = R0;
88 [p0 + (ITEST_COMMAND - DTEST_COMMAND)] = R0;
89 CSYNC;
90
Mike Frysinger17e89bc2008-08-06 17:23:50 +080091 trace_buffer_init(p0,r0);
92 P0 = R1;
93 R0 = R1;
94
95 /* Turn off the icache */
96 p0.l = LO(IMEM_CONTROL);
97 p0.h = HI(IMEM_CONTROL);
98 R1 = [p0];
99 R0 = ~ENICPLB;
100 R0 = R0 & R1;
101 [p0] = R0;
102 SSYNC;
103
104 /* Turn off the dcache */
105 p0.l = LO(DMEM_CONTROL);
106 p0.h = HI(DMEM_CONTROL);
107 R1 = [p0];
108 R0 = ~ENDCPLB;
109 R0 = R0 & R1;
110 [p0] = R0;
111 SSYNC;
112
Robin Getz0c7a6b22008-10-08 16:27:12 +0800113 /* in case of double faults, save a few things */
114 p0.l = _init_retx;
115 p0.h = _init_retx;
Robin Getzcd8fb8d2008-08-14 14:44:33 +0800116 R0 = RETX;
117 [P0] = R0;
118
Robin Getz0c7a6b22008-10-08 16:27:12 +0800119#ifdef CONFIG_DEBUG_DOUBLEFAULT
120 /* Only save these if we are storing them,
121 * This happens here, since L1 gets clobbered
122 * below
123 */
Graf Yang6b3087c2009-01-07 23:14:39 +0800124 GET_PDA(p0, r0);
Graf Yang01b9f4b2009-07-22 11:56:24 +0000125 r6 = [p0 + PDA_DF_RETX];
Robin Getz0c7a6b22008-10-08 16:27:12 +0800126 p1.l = _init_saved_retx;
127 p1.h = _init_saved_retx;
Mike Frysinger37082512009-05-26 21:48:38 +0000128 [p1] = r6;
Robin Getz0c7a6b22008-10-08 16:27:12 +0800129
Graf Yang01b9f4b2009-07-22 11:56:24 +0000130 r6 = [p0 + PDA_DF_DCPLB];
Robin Getz0c7a6b22008-10-08 16:27:12 +0800131 p1.l = _init_saved_dcplb_fault_addr;
132 p1.h = _init_saved_dcplb_fault_addr;
Mike Frysinger37082512009-05-26 21:48:38 +0000133 [p1] = r6;
Robin Getz0c7a6b22008-10-08 16:27:12 +0800134
Graf Yang01b9f4b2009-07-22 11:56:24 +0000135 r6 = [p0 + PDA_DF_ICPLB];
Robin Getz0c7a6b22008-10-08 16:27:12 +0800136 p1.l = _init_saved_icplb_fault_addr;
137 p1.h = _init_saved_icplb_fault_addr;
Mike Frysinger37082512009-05-26 21:48:38 +0000138 [p1] = r6;
Robin Getz0c7a6b22008-10-08 16:27:12 +0800139
Graf Yang01b9f4b2009-07-22 11:56:24 +0000140 r6 = [p0 + PDA_DF_SEQSTAT];
Robin Getz0c7a6b22008-10-08 16:27:12 +0800141 p1.l = _init_saved_seqstat;
142 p1.h = _init_saved_seqstat;
Mike Frysinger37082512009-05-26 21:48:38 +0000143 [p1] = r6;
Robin Getz0c7a6b22008-10-08 16:27:12 +0800144#endif
145
Mike Frysinger17e89bc2008-08-06 17:23:50 +0800146 /* Initialize stack pointer */
Barry Songaad16f32010-01-05 07:25:24 +0000147 sp.l = _init_thread_union + THREAD_SIZE;
148 sp.h = _init_thread_union + THREAD_SIZE;
Mike Frysinger17e89bc2008-08-06 17:23:50 +0800149 fp = sp;
150 usp = sp;
151
152#ifdef CONFIG_EARLY_PRINTK
153 call _init_early_exception_vectors;
Robin Getz837ec2d2009-07-07 20:17:09 +0000154 r0 = (EVT_IVHW | EVT_IRPTEN | EVT_EVX | EVT_NMI | EVT_RST | EVT_EMU);
155 sti r0;
Mike Frysinger17e89bc2008-08-06 17:23:50 +0800156#endif
157
Graf Yang9960aa62009-02-04 16:49:45 +0800158 r0 = 0 (x);
159 /* Zero out all of the fun bss regions */
160#if L1_DATA_A_LENGTH > 0
161 r1.l = __sbss_l1;
162 r1.h = __sbss_l1;
163 r2.l = __ebss_l1;
164 r2.h = __ebss_l1;
165 call __init_clear_bss
166#endif
167#if L1_DATA_B_LENGTH > 0
168 r1.l = __sbss_b_l1;
169 r1.h = __sbss_b_l1;
170 r2.l = __ebss_b_l1;
171 r2.h = __ebss_b_l1;
172 call __init_clear_bss
173#endif
174#if L2_LENGTH > 0
175 r1.l = __sbss_l2;
176 r1.h = __sbss_l2;
177 r2.l = __ebss_l2;
178 r2.h = __ebss_l2;
179 call __init_clear_bss
180#endif
181 r1.l = ___bss_start;
182 r1.h = ___bss_start;
183 r2.l = ___bss_stop;
184 r2.h = ___bss_stop;
185 call __init_clear_bss
186
Mike Frysinger17e89bc2008-08-06 17:23:50 +0800187 /* Put The Code for PLL Programming and SDRAM Programming in L1 ISRAM */
Graf Yang5b04f272008-10-08 17:32:57 +0800188 call _bfin_relocate_l1_mem;
Barry Songd86bfb12010-01-07 04:11:17 +0000189
190#ifdef CONFIG_ROMKERNEL
191 call _bfin_relocate_xip_data;
192#endif
193
Mike Frysinger17e89bc2008-08-06 17:23:50 +0800194#ifdef CONFIG_BFIN_KERNEL_CLOCK
Mike Frysinger729a3fa2009-04-24 03:55:41 +0000195 /* Only use on-chip scratch space for stack when absolutely required
196 * to avoid Anomaly 05000227 ... we know the init_clocks() func only
197 * uses L1 text and stack space and no other memory region.
198 */
199# define KERNEL_CLOCK_STACK (L1_SCRATCH_START + L1_SCRATCH_LENGTH - 12)
200 sp.l = lo(KERNEL_CLOCK_STACK);
201 sp.h = hi(KERNEL_CLOCK_STACK);
Michael Hennerich73feb5c2009-01-07 23:14:39 +0800202 call _init_clocks;
Mike Frysinger729a3fa2009-04-24 03:55:41 +0000203 sp = usp; /* usp hasnt been touched, so restore from there */
Mike Frysinger17e89bc2008-08-06 17:23:50 +0800204#endif
205
206 /* This section keeps the processor in supervisor mode
207 * during kernel boot. Switches to user mode at end of boot.
208 * See page 3-9 of Hardware Reference manual for documentation.
209 */
210
211 /* EVT15 = _real_start */
212
213 p0.l = lo(EVT15);
214 p0.h = hi(EVT15);
215 p1.l = _real_start;
216 p1.h = _real_start;
217 [p0] = p1;
218 csync;
219
Robin Getz837ec2d2009-07-07 20:17:09 +0000220#ifdef CONFIG_EARLY_PRINTK
221 r0 = (EVT_IVG15 | EVT_IVHW | EVT_IRPTEN | EVT_EVX | EVT_NMI | EVT_RST | EVT_EMU) (z);
222#else
Mike Frysingerc2414bd2008-11-18 17:48:22 +0800223 r0 = EVT_IVG15 (z);
Robin Getz837ec2d2009-07-07 20:17:09 +0000224#endif
Mike Frysingerc2414bd2008-11-18 17:48:22 +0800225 sti r0;
Mike Frysinger17e89bc2008-08-06 17:23:50 +0800226
227 raise 15;
Robin Getz837ec2d2009-07-07 20:17:09 +0000228#ifdef CONFIG_EARLY_PRINTK
229 p0.l = _early_trap;
230 p0.h = _early_trap;
231#else
Mike Frysinger17e89bc2008-08-06 17:23:50 +0800232 p0.l = .LWAIT_HERE;
233 p0.h = .LWAIT_HERE;
Robin Getz837ec2d2009-07-07 20:17:09 +0000234#endif
Mike Frysinger17e89bc2008-08-06 17:23:50 +0800235 reti = p0;
236#if ANOMALY_05000281
237 nop; nop; nop;
238#endif
239 rti;
240
241.LWAIT_HERE:
242 jump .LWAIT_HERE;
243ENDPROC(__start)
244
Mike Frysinger09e1f702008-08-06 17:15:27 +0800245/* A little BF561 glue ... */
246#ifndef WDOG_CTL
247# define WDOG_CTL WDOGA_CTL
248#endif
249
Mike Frysinger09e1f702008-08-06 17:15:27 +0800250ENTRY(_real_start)
251 /* Enable nested interrupts */
252 [--sp] = reti;
253
254 /* watchdog off for now */
255 p0.l = lo(WDOG_CTL);
256 p0.h = hi(WDOG_CTL);
257 r0 = 0xAD6(z);
258 w[p0] = r0;
259 ssync;
260
Mike Frysinger09e1f702008-08-06 17:15:27 +0800261 /* Pass the u-boot arguments to the global value command line */
262 R0 = R7;
263 call _cmdline_init;
264
Barry Songaad16f32010-01-05 07:25:24 +0000265 sp += -12 + 4; /* +4 is for reti loading above */
Graf Yang6b3087c2009-01-07 23:14:39 +0800266 call _init_pda
267 sp += 12;
Mike Frysinger09e1f702008-08-06 17:15:27 +0800268 jump.l _start_kernel;
269ENDPROC(_real_start)
270
271__FINIT