Merge branch 'for-upstream' of git://git.kernel.org/pub/scm/linux/kernel/git/dvrabel/uwb
[pandora-kernel.git] / arch / blackfin / mach-common / head.S
1 /*
2  * Common Blackfin startup code
3  *
4  * Copyright 2004-2008 Analog Devices Inc.
5  *
6  * Enter bugs at http://blackfin.uclinux.org/
7  *
8  * Licensed under the GPL-2 or later.
9  */
10
11 #include <linux/linkage.h>
12 #include <linux/init.h>
13 #include <asm/blackfin.h>
14 #include <asm/thread_info.h>
15 #include <asm/trace.h>
16 #include <asm/asm-offsets.h>
17
18 __INIT
19
20 ENTRY(__init_clear_bss)
21         r2 = r2 - r1;
22         cc = r2 == 0;
23         if cc jump .L_bss_done;
24         r2 >>= 2;
25         p1 = r1;
26         p2 = r2;
27         lsetup (1f, 1f) lc0 = p2;
28 1:      [p1++] = r0;
29 .L_bss_done:
30         rts;
31 ENDPROC(__init_clear_bss)
32
33 ENTRY(__start)
34         /* R0: argument of command line string, passed from uboot, save it */
35         R7 = R0;
36         /* Enable Cycle Counter and Nesting Of Interrupts */
37 #ifdef CONFIG_BFIN_SCRATCH_REG_CYCLES
38         R0 = SYSCFG_SNEN;
39 #else
40         R0 = SYSCFG_SNEN | SYSCFG_CCEN;
41 #endif
42         SYSCFG = R0;
43         R0 = 0;
44
45         /* Clear Out All the data and pointer Registers */
46         R1 = R0;
47         R2 = R0;
48         R3 = R0;
49         R4 = R0;
50         R5 = R0;
51         R6 = R0;
52
53         P0 = R0;
54         P1 = R0;
55         P2 = R0;
56         P3 = R0;
57         P4 = R0;
58         P5 = R0;
59
60         LC0 = r0;
61         LC1 = r0;
62         L0 = r0;
63         L1 = r0;
64         L2 = r0;
65         L3 = r0;
66
67         /* Clear Out All the DAG Registers */
68         B0 = r0;
69         B1 = r0;
70         B2 = r0;
71         B3 = r0;
72
73         I0 = r0;
74         I1 = r0;
75         I2 = r0;
76         I3 = r0;
77
78         M0 = r0;
79         M1 = r0;
80         M2 = r0;
81         M3 = r0;
82
83         /*
84          * Clear ITEST_COMMAND and DTEST_COMMAND registers,
85          * Leaving these as non-zero can confuse the emulator
86          */
87         p0.L = LO(DTEST_COMMAND);
88         p0.H = HI(DTEST_COMMAND);
89         [p0] = R0;
90         [p0 + (ITEST_COMMAND - DTEST_COMMAND)] = R0;
91         CSYNC;
92
93         trace_buffer_init(p0,r0);
94         P0 = R1;
95         R0 = R1;
96
97         /* Turn off the icache */
98         p0.l = LO(IMEM_CONTROL);
99         p0.h = HI(IMEM_CONTROL);
100         R1 = [p0];
101         R0 = ~ENICPLB;
102         R0 = R0 & R1;
103         [p0] = R0;
104         SSYNC;
105
106         /* Turn off the dcache */
107         p0.l = LO(DMEM_CONTROL);
108         p0.h = HI(DMEM_CONTROL);
109         R1 = [p0];
110         R0 = ~ENDCPLB;
111         R0 = R0 & R1;
112         [p0] = R0;
113         SSYNC;
114
115         /* in case of double faults, save a few things */
116         p0.l = _init_retx;
117         p0.h = _init_retx;
118         R0 = RETX;
119         [P0] = R0;
120
121 #ifdef CONFIG_DEBUG_DOUBLEFAULT
122         /* Only save these if we are storing them,
123          * This happens here, since L1 gets clobbered
124          * below
125          */
126         GET_PDA(p0, r0);
127         r6 = [p0 + PDA_RETX];
128         p1.l = _init_saved_retx;
129         p1.h = _init_saved_retx;
130         [p1] = r6;
131
132         r6 = [p0 + PDA_DCPLB];
133         p1.l = _init_saved_dcplb_fault_addr;
134         p1.h = _init_saved_dcplb_fault_addr;
135         [p1] = r6;
136
137         r6 = [p0 + PDA_ICPLB];
138         p1.l = _init_saved_icplb_fault_addr;
139         p1.h = _init_saved_icplb_fault_addr;
140         [p1] = r6;
141
142         r6 = [p0 + PDA_SEQSTAT];
143         p1.l = _init_saved_seqstat;
144         p1.h = _init_saved_seqstat;
145         [p1] = r6;
146 #endif
147
148         /* Initialize stack pointer */
149         sp.l = _init_thread_union;
150         sp.h = _init_thread_union;
151         fp = sp;
152         usp = sp;
153
154 #ifdef CONFIG_EARLY_PRINTK
155         call _init_early_exception_vectors;
156 #endif
157
158         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
187         /* Put The Code for PLL Programming and SDRAM Programming in L1 ISRAM */
188         call _bfin_relocate_l1_mem;
189 #ifdef CONFIG_BFIN_KERNEL_CLOCK
190         /* Only use on-chip scratch space for stack when absolutely required
191          * to avoid Anomaly 05000227 ... we know the init_clocks() func only
192          * uses L1 text and stack space and no other memory region.
193          */
194 # define KERNEL_CLOCK_STACK (L1_SCRATCH_START + L1_SCRATCH_LENGTH - 12)
195         sp.l = lo(KERNEL_CLOCK_STACK);
196         sp.h = hi(KERNEL_CLOCK_STACK);
197         call _init_clocks;
198         sp = usp;       /* usp hasnt been touched, so restore from there */
199 #endif
200
201         /* This section keeps the processor in supervisor mode
202          * during kernel boot.  Switches to user mode at end of boot.
203          * See page 3-9 of Hardware Reference manual for documentation.
204          */
205
206         /* EVT15 = _real_start */
207
208         p0.l = lo(EVT15);
209         p0.h = hi(EVT15);
210         p1.l = _real_start;
211         p1.h = _real_start;
212         [p0] = p1;
213         csync;
214
215         r0 = EVT_IVG15 (z);
216         sti r0;
217
218         raise 15;
219         p0.l = .LWAIT_HERE;
220         p0.h = .LWAIT_HERE;
221         reti = p0;
222 #if ANOMALY_05000281
223         nop; nop; nop;
224 #endif
225         rti;
226
227 .LWAIT_HERE:
228         jump .LWAIT_HERE;
229 ENDPROC(__start)
230
231 /* A little BF561 glue ... */
232 #ifndef WDOG_CTL
233 # define WDOG_CTL WDOGA_CTL
234 #endif
235
236 ENTRY(_real_start)
237         /* Enable nested interrupts */
238         [--sp] = reti;
239
240         /* watchdog off for now */
241         p0.l = lo(WDOG_CTL);
242         p0.h = hi(WDOG_CTL);
243         r0 = 0xAD6(z);
244         w[p0] = r0;
245         ssync;
246
247         /* Pass the u-boot arguments to the global value command line */
248         R0 = R7;
249         call _cmdline_init;
250
251         /* Load the current thread pointer and stack */
252         p1 = THREAD_SIZE + 4 (z);       /* +4 is for reti loading */
253         sp = sp + p1;
254         usp = sp;
255         fp = sp;
256         sp += -12;
257         call _init_pda
258         sp += 12;
259         jump.l _start_kernel;
260 ENDPROC(_real_start)
261
262 __FINIT