]> git.sur5r.net Git - u-boot/blob - cpu/bf561/start.S
19578a5262883404678e0423ef55d1159233c617
[u-boot] / cpu / bf561 / start.S
1 /*
2  * U-boot - start.S Startup file of u-boot for BF533/BF561
3  *
4  * Copyright (c) 2005-2007 Analog Devices Inc.
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 /*
34  * Note: A change in this file subsequently requires a change in
35  *       board/$(board_name)/config.mk for a valid u-boot.bin
36  */
37
38 #define ASSEMBLY
39
40 #include <linux/config.h>
41 #include <config.h>
42 #include <asm/blackfin.h>
43
44 #include <asm/mach-common/bits/core.h>
45 #include <asm/mach-common/bits/dma.h>
46 #include <asm/mach-common/bits/pll.h>
47
48 .global _stext;
49 .global __bss_start;
50 .global start;
51 .global _start;
52 .global _rambase;
53 .global _ramstart;
54 .global _ramend;
55 .global edata;
56 .global _initialize;
57 .global _exit;
58 .global flashdataend;
59 .global init_sdram;
60
61 .text
62 _start:
63 start:
64 _stext:
65
66         R0 = 0x32;
67         SYSCFG = R0;
68         SSYNC;
69
70         /*
71          * As per HW reference manual DAG registers,
72          * DATA and Address resgister shall be zero'd
73          * in initialization, after a reset state
74          */
75         r1 = 0; /* Data registers zero'd */
76         r2 = 0;
77         r3 = 0;
78         r4 = 0;
79         r5 = 0;
80         r6 = 0;
81         r7 = 0;
82
83         p0 = 0; /* Address registers zero'd */
84         p1 = 0;
85         p2 = 0;
86         p3 = 0;
87         p4 = 0;
88         p5 = 0;
89
90         i0 = 0; /* DAG Registers zero'd */
91         i1 = 0;
92         i2 = 0;
93         i3 = 0;
94         m0 = 0;
95         m1 = 0;
96         m3 = 0;
97         m3 = 0;
98         l0 = 0;
99         l1 = 0;
100         l2 = 0;
101         l3 = 0;
102         b0 = 0;
103         b1 = 0;
104         b2 = 0;
105         b3 = 0;
106
107         /*
108          * Set loop counters to zero, to make sure that
109          * hw loops are disabled.
110          */
111         r0  = 0;
112         lc0 = r0;
113         lc1 = r0;
114
115         SSYNC;
116
117         /* Check soft reset status */
118         p0.h = SWRST >> 16;
119         p0.l = SWRST & 0xFFFF;
120         r0.l = w[p0];
121
122         cc = bittst(r0, 15);
123         if !cc jump no_soft_reset;
124
125         /* Clear Soft reset */
126         r0 = 0x0000;
127         w[p0] = r0;
128         ssync;
129
130 no_soft_reset:
131         nop;
132
133         /* Clear EVT registers */
134         p0.h = (EVT0 >> 16);
135         p0.l = (EVT0 & 0xFFFF);
136         p0 += 8;
137         p1 = 14;
138         r1 = 0;
139         LSETUP(4,4) lc0 = p1;
140         [ p0 ++ ] = r1;
141
142         p0.h = hi(SICA_IWR0);
143         p0.l = lo(SICA_IWR0);
144         r0.l = 0x1;
145         w[p0] = r0.l;
146         SSYNC;
147
148         sp.l = (0xffb01000 & 0xFFFF);
149         sp.h = (0xffb01000 >> 16);
150
151         /*
152          * Check if the code is in SDRAM
153          * If the code is in SDRAM, skip SDRAM initializaiton
154          */
155         call get_pc;
156         r3.l = 0x0;
157         r3.h = 0x2000;
158         cc = r0 < r3 (iu);
159         if cc jump sdram_initialized;
160         call init_sdram;
161         /* relocate into to RAM */
162 sdram_initialized:
163         call get_pc;
164 offset:
165         r2.l = offset;
166         r2.h = offset;
167         r3.l = start;
168         r3.h = start;
169         r1 = r2 - r3;
170
171         r0 = r0 - r1;
172         p1 = r0;
173
174         p2.l = (CFG_MONITOR_BASE & 0xffff);
175         p2.h = (CFG_MONITOR_BASE >> 16);
176
177         p3 = 0x04;
178         p4.l = ((CFG_MONITOR_BASE + CFG_MONITOR_LEN) & 0xffff);
179         p4.h = ((CFG_MONITOR_BASE + CFG_MONITOR_LEN) >> 16);
180 loop1:
181         r1 = [p1 ++ p3];
182         [p2 ++ p3] = r1;
183         cc=p2==p4;
184         if !cc jump loop1;
185         /*
186          * configure STACK
187          */
188         r0.h = (CONFIG_STACKBASE >> 16);
189         r0.l = (CONFIG_STACKBASE & 0xFFFF);
190         sp = r0;
191         fp = sp;
192
193         /*
194          * This next section keeps the processor in supervisor mode
195          * during kernel boot.  Switches to user mode at end of boot.
196          * See page 3-9 of Hardware Reference manual for documentation.
197          */
198
199         /* To keep ourselves in the supervisor mode */
200         p0.l = (EVT15 & 0xFFFF);
201         p0.h = (EVT15 >> 16);
202
203         p1.l = _real_start;
204         p1.h = _real_start;
205         [p0] = p1;
206
207         p0.l = (IMASK & 0xFFFF);
208         p0.h = (IMASK >> 16);
209         r0.l = LO(EVT_IVG15);
210         r0.h = HI(EVT_IVG15);
211         [p0] = r0;
212         raise 15;
213         p0.l = WAIT_HERE;
214         p0.h = WAIT_HERE;
215         reti = p0;
216         rti;
217
218 WAIT_HERE:
219         jump WAIT_HERE;
220
221 .global _real_start;
222 _real_start:
223         [ -- sp ] = reti;
224
225         /* DMA reset code to Hi of L1 SRAM */
226 copy:
227         P1.H = hi(SYSMMR_BASE); /* P1 Points to the beginning of SYSTEM MMR Space */
228         P1.L = lo(SYSMMR_BASE);
229
230         R0.H = reset_start;     /* Source Address (high) */
231         R0.L = reset_start;     /* Source Address (low) */
232         R1.H = reset_end;
233         R1.L = reset_end;
234         R2 = R1 - R0;           /* Count */
235         R1.H = hi(L1_INST_SRAM);        /* Destination Address (high) */
236         R1.L = lo(L1_INST_SRAM);        /* Destination Address (low) */
237         R3.L = DMAEN;           /* Source DMAConfig Value (8-bit words) */
238         R4.L = (DI_EN | WNR | DMAEN);   /* Destination DMAConfig Value (8-bit words) */
239
240 DMA:
241         R6 = 0x1 (Z);
242         W[P1+OFFSET_(IMDMA_S0_X_MODIFY)] = R6;  /* Source Modify = 1 */
243         W[P1+OFFSET_(IMDMA_D0_X_MODIFY)] = R6;  /* Destination Modify = 1 */
244
245         [P1+OFFSET_(IMDMA_S0_START_ADDR)] = R0; /* Set Source Base Address */
246         W[P1+OFFSET_(IMDMA_S0_X_COUNT)] = R2;   /* Set Source Count */
247         /* Set Source  DMAConfig = DMA Enable,
248         Memory Read,  8-Bit Transfers, 1-D DMA, Flow - Stop */
249         W[P1+OFFSET_(IMDMA_S0_CONFIG)] = R3;
250
251         [P1+OFFSET_(IMDMA_D0_START_ADDR)] = R1; /* Set Destination Base Address */
252         W[P1+OFFSET_(IMDMA_D0_X_COUNT)] = R2;   /* Set Destination Count */
253         /* Set Destination DMAConfig = DMA Enable,
254         Memory Write, 8-Bit Transfers, 1-D DMA, Flow - Stop, IOC */
255         W[P1+OFFSET_(IMDMA_D0_CONFIG)] = R4;
256
257 WAIT_DMA_DONE:
258         p0.h = hi(IMDMA_D0_IRQ_STATUS);
259         p0.l = lo(IMDMA_D0_IRQ_STATUS);
260         R0 = W[P0](Z);
261         CC = BITTST(R0, 0);
262         if ! CC jump WAIT_DMA_DONE
263
264         R0 = 0x1;
265         W[P1+OFFSET_(IMDMA_D0_IRQ_STATUS)] = R0;        /* Write 1 to clear DMA interrupt */
266
267         /* Initialize BSS Section with 0 s */
268         p1.l = __bss_start;
269         p1.h = __bss_start;
270         p2.l = _end;
271         p2.h = _end;
272         r1 = p1;
273         r2 = p2;
274         r3 = r2 - r1;
275         r3 = r3 >> 2;
276         p3 = r3;
277         lsetup (_clear_bss, _clear_bss_end ) lc1 = p3;
278         CC = p2<=p1;
279         if CC jump _clear_bss_skip;
280         r0 = 0;
281 _clear_bss:
282 _clear_bss_end:
283         [p1++] = r0;
284 _clear_bss_skip:
285
286         p0.l = _start1;
287         p0.h = _start1;
288         jump (p0);
289
290 reset_start:
291         p0.h = WDOG_CNT >> 16;
292         p0.l = WDOG_CNT & 0xffff;
293         r0 = 0x0010;
294         w[p0] = r0;
295         p0.h = WDOG_CTL >> 16;
296         p0.l = WDOG_CTL & 0xffff;
297         r0 = 0x0000;
298         w[p0] = r0;
299 reset_wait:
300         jump reset_wait;
301
302 reset_end: nop;
303
304 _exit:
305         jump.s  _exit;
306 get_pc:
307         r0 = rets;
308         rts;