blob: fb7e2d426999a073198661487c2d0d9bbdde41eb [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 *
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>
Mike Frysinger67618fd2008-08-06 17:18:31 +080014#include <asm/thread_info.h>
Mike Frysinger09e1f702008-08-06 17:15:27 +080015#include <asm/trace.h>
16
Mike Frysinger17e89bc2008-08-06 17:23:50 +080017__INIT
18
19#define INITIAL_STACK (L1_SCRATCH_START + L1_SCRATCH_LENGTH - 12)
20
21ENTRY(__start)
22 /* R0: argument of command line string, passed from uboot, save it */
23 R7 = R0;
24 /* Enable Cycle Counter and Nesting Of Interrupts */
25#ifdef CONFIG_BFIN_SCRATCH_REG_CYCLES
26 R0 = SYSCFG_SNEN;
27#else
28 R0 = SYSCFG_SNEN | SYSCFG_CCEN;
29#endif
30 SYSCFG = R0;
31 R0 = 0;
32
33 /* Clear Out All the data and pointer Registers */
34 R1 = R0;
35 R2 = R0;
36 R3 = R0;
37 R4 = R0;
38 R5 = R0;
39 R6 = R0;
40
41 P0 = R0;
42 P1 = R0;
43 P2 = R0;
44 P3 = R0;
45 P4 = R0;
46 P5 = R0;
47
48 LC0 = r0;
49 LC1 = r0;
50 L0 = r0;
51 L1 = r0;
52 L2 = r0;
53 L3 = r0;
54
55 /* Clear Out All the DAG Registers */
56 B0 = r0;
57 B1 = r0;
58 B2 = r0;
59 B3 = r0;
60
61 I0 = r0;
62 I1 = r0;
63 I2 = r0;
64 I3 = r0;
65
66 M0 = r0;
67 M1 = r0;
68 M2 = r0;
69 M3 = r0;
70
71 trace_buffer_init(p0,r0);
72 P0 = R1;
73 R0 = R1;
74
75 /* Turn off the icache */
76 p0.l = LO(IMEM_CONTROL);
77 p0.h = HI(IMEM_CONTROL);
78 R1 = [p0];
79 R0 = ~ENICPLB;
80 R0 = R0 & R1;
81 [p0] = R0;
82 SSYNC;
83
84 /* Turn off the dcache */
85 p0.l = LO(DMEM_CONTROL);
86 p0.h = HI(DMEM_CONTROL);
87 R1 = [p0];
88 R0 = ~ENDCPLB;
89 R0 = R0 & R1;
90 [p0] = R0;
91 SSYNC;
92
Robin Getzcd8fb8d2008-08-14 14:44:33 +080093 /* Save RETX, in case of doublefault */
94 p0.l = ___retx;
95 p0.h = ___retx;
96 R0 = RETX;
97 [P0] = R0;
98
Mike Frysinger17e89bc2008-08-06 17:23:50 +080099 /* Let each Blackfin family do its own thing */
100 call _mach_early_start;
101
102 /* Initialize stack pointer */
103 sp.l = lo(INITIAL_STACK);
104 sp.h = hi(INITIAL_STACK);
105 fp = sp;
106 usp = sp;
107
108#ifdef CONFIG_EARLY_PRINTK
109 call _init_early_exception_vectors;
110#endif
111
112 /* Put The Code for PLL Programming and SDRAM Programming in L1 ISRAM */
113 call _bf53x_relocate_l1_mem;
114#ifdef CONFIG_BFIN_KERNEL_CLOCK
115 call _start_dma_code;
116#endif
117
118 /* This section keeps the processor in supervisor mode
119 * during kernel boot. Switches to user mode at end of boot.
120 * See page 3-9 of Hardware Reference manual for documentation.
121 */
122
123 /* EVT15 = _real_start */
124
125 p0.l = lo(EVT15);
126 p0.h = hi(EVT15);
127 p1.l = _real_start;
128 p1.h = _real_start;
129 [p0] = p1;
130 csync;
131
132 p0.l = lo(IMASK);
133 p0.h = hi(IMASK);
134 p1.l = IMASK_IVG15;
135 p1.h = 0x0;
136 [p0] = p1;
137 csync;
138
139 raise 15;
140 p0.l = .LWAIT_HERE;
141 p0.h = .LWAIT_HERE;
142 reti = p0;
143#if ANOMALY_05000281
144 nop; nop; nop;
145#endif
146 rti;
147
148.LWAIT_HERE:
149 jump .LWAIT_HERE;
150ENDPROC(__start)
151
Mike Frysinger09e1f702008-08-06 17:15:27 +0800152/* A little BF561 glue ... */
153#ifndef WDOG_CTL
154# define WDOG_CTL WDOGA_CTL
155#endif
156
Mike Frysinger09e1f702008-08-06 17:15:27 +0800157ENTRY(_real_start)
158 /* Enable nested interrupts */
159 [--sp] = reti;
160
161 /* watchdog off for now */
162 p0.l = lo(WDOG_CTL);
163 p0.h = hi(WDOG_CTL);
164 r0 = 0xAD6(z);
165 w[p0] = r0;
166 ssync;
167
168 /* Zero out the bss region
169 * Note: this will fail if bss is 0 bytes ...
170 */
171 r0 = 0 (z);
172 r1.l = ___bss_start;
173 r1.h = ___bss_start;
174 r2.l = ___bss_stop;
175 r2.h = ___bss_stop;
176 r2 = r2 - r1;
177 r2 >>= 2;
178 p1 = r1;
179 p2 = r2;
180 lsetup (.L_clear_bss, .L_clear_bss) lc0 = p2;
181.L_clear_bss:
182 [p1++] = r0;
183
184 /* In case there is a NULL pointer reference,
185 * zero out region before stext
186 */
187 p1 = r0;
188 r2.l = __stext;
189 r2.h = __stext;
190 r2 >>= 2;
191 p2 = r2;
192 lsetup (.L_clear_zero, .L_clear_zero) lc0 = p2;
193.L_clear_zero:
194 [p1++] = r0;
195
196 /* Pass the u-boot arguments to the global value command line */
197 R0 = R7;
198 call _cmdline_init;
199
200 /* Load the current thread pointer and stack */
201 sp.l = _init_thread_union;
202 sp.h = _init_thread_union;
203 p1 = THREAD_SIZE (z);
204 sp = sp + p1;
205 usp = sp;
206 fp = sp;
207 jump.l _start_kernel;
208ENDPROC(_real_start)
209
210__FINIT