* Some code cleanup
[platform/kernel/u-boot.git] / cpu / mcf52x2 / start.S
1 /*
2  * Copyright (C) 2003   Josef Baumgartner <josef.baumgartner@telex.de>
3  * Based on code from Bernhard Kuhn <bkuhn@metrowerks.com>
4  *
5  * See file CREDITS for list of people who contributed to this
6  * project.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of
11  * the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21  * MA 02111-1307 USA
22  */
23
24 #include <config.h>
25 #include "version.h"
26
27 #ifndef  CONFIG_IDENT_STRING
28 #define  CONFIG_IDENT_STRING ""
29 #endif
30
31
32 #define _START  _start
33 #define _FAULT  _fault
34
35
36 #define SAVE_ALL                                                \
37         move.w  #0x2700,%sr;            /* disable intrs */     \
38         subl    #60,%sp;                /* space for 15 regs */ \
39         moveml  %d0-%d7/%a0-%a6,%sp@;                           \
40
41 #define RESTORE_ALL                                             \
42         moveml  %sp@,%d0-%d7/%a0-%a6;                           \
43         addl    #60,%sp;                /* space for 15 regs */ \
44         rte
45
46 /* If we come from a pre-loader we don't need an initial exception
47  * table.
48  */
49 #if !defined(CONFIG_MONITOR_IS_IN_RAM)
50
51 .text
52 /*
53  *      Vector table. This is used for initial platform startup.
54  *      These vectors are to catch any un-intended traps.
55  */
56 _vectors:
57
58 .long   0x00000000, _START
59 .long   _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
60 .long   _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
61 .long   _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
62 .long   _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
63 .long   _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
64 .long   _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
65 .long   _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
66 .long   _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
67
68 .long   _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
69 .long   _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
70 .long   _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
71 .long   _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
72 .long   _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
73 .long   _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
74 .long   _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
75 .long   _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
76
77 .long   _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
78 .long   _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
79 .long   _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
80 .long   _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
81 .long   _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
82 .long   _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
83 .long   _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
84 .long   _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
85
86 .long   _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
87 .long   _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
88 .long   _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
89 .long   _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
90 .long   _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
91 .long   _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
92 .long   _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
93 .long   _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
94
95 #endif
96
97         .text
98
99         .globl  _start
100 _start:
101         nop
102         nop
103         move.w #0x2700,%sr
104
105         /* if we come from a pre-loader we have no exception table and
106          * therefore no VBR to set
107          */
108 #if !defined(CONFIG_MONITOR_IS_IN_RAM)
109         move.l  #CFG_FLASH_BASE, %d0
110         movec   %d0, %VBR
111 #endif
112
113 #ifdef CONFIG_M5272
114         move.l  #(CFG_MBAR + 1), %d0            /* set MBAR address + valid flag */
115         move.c  %d0, %MBAR
116
117         move.l  #(CFG_INIT_RAM_ADDR + 1), %d0
118         movec   %d0, %RAMBAR0
119 #endif
120
121 #ifdef CONFIG_M5282
122         /* Initialize IPSBAR */
123         move.l  #(CFG_MBAR + 1), %d0            /* set IPSBAR address + valid flag */
124         move.l  %d0, 0x40000000
125
126         /* Initialize FLASHBAR: locate internal Flash and validate it */
127         move.l  #(CFG_INT_FLASH_BASE + 0x21), %d0
128         movec   %d0, %RAMBAR0
129
130         /* Initialize RAMBAR1: locate SRAM and validate it */
131         move.l  #(CFG_INIT_RAM_ADDR + 0x21), %d0
132         movec   %d0, %RAMBAR1
133 #endif
134
135         /* invalidate and disable cache */
136         move.l  #0x01000000, %d0                /* Invalidate cache cmd */
137         movec   %d0, %CACR                      /* Invalidate cache */
138         move.l  #0, %d0
139         movec   %d0, %ACR0
140         movec   %d0, %ACR1
141
142         /* set stackpointer to end of internal ram to get some stackspace for the first c-code */
143         move.l  #(CFG_INIT_RAM_ADDR + CFG_INIT_SP_OFFSET), %sp
144         clr.l %sp@-
145
146         move.l #__got_start, %a5                /* put relocation table address to a5 */
147
148         bsr cpu_init_f                          /* run low-level CPU init code (from flash) */
149         bsr board_init_f                        /* run low-level board init code (from flash) */
150
151         /* board_init_f() does not return
152
153 /*------------------------------------------------------------------------------*/
154
155 /*
156  * void relocate_code (addr_sp, gd, addr_moni)
157  *
158  * This "function" does not return, instead it continues in RAM
159  * after relocating the monitor code.
160  *
161  * r3 = dest
162  * r4 = src
163  * r5 = length in bytes
164  * r6 = cachelinesize
165  */
166         .globl  relocate_code
167 relocate_code:
168         link.w %a6,#0
169         move.l 8(%a6), %sp              /* set new stack pointer */
170
171         move.l 12(%a6), %d0             /* Save copy of Global Data pointer */
172         move.l 16(%a6), %a0             /* Save copy of Destination Address */
173
174         move.l #CFG_MONITOR_BASE, %a1
175         move.l #__init_end, %a2
176         move.l %a0, %a3
177
178         /* copy the code to RAM */
179 1:
180         move.l (%a1)+, (%a3)+
181         cmp.l  %a1,%a2
182         bgt.s    1b
183
184 /*
185  * We are done. Do not return, instead branch to second part of board
186  * initialization, now running from RAM.
187  */
188         move.l  %a0, %a1
189         add.l   #(in_ram - CFG_MONITOR_BASE), %a1
190         jmp     (%a1)
191
192 in_ram:
193
194 clear_bss:
195         /*
196          * Now clear BSS segment
197          */
198         move.l  %a0, %a1
199         add.l   #(_sbss - CFG_MONITOR_BASE),%a1
200         move.l  %a0, %d1
201         add.l   #(_ebss - CFG_MONITOR_BASE),%d1
202 6:
203         clr.l   (%a1)+
204         cmp.l   %a1,%d1
205         bgt.s   6b
206
207         /*
208          * fix got table in RAM
209          */
210         move.l  %a0, %a1
211         add.l   #(__got_start - CFG_MONITOR_BASE),%a1
212         move.l  %a1,%a5         /* * fix got pointer register a5 */
213
214         move.l  %a0, %a2
215         add.l   #(__got_end - CFG_MONITOR_BASE),%a2
216
217 7:
218         move.l  (%a1),%d1
219         sub.l   #_start,%d1
220         add.l   %a0,%d1
221         move.l  %d1,(%a1)+
222         cmp.l   %a2, %a1
223         bne     7b
224
225         /* calculate relative jump to board_init_r in ram */
226         move.l %a0, %a1
227         add.l #(board_init_r - CFG_MONITOR_BASE), %a1
228
229         /* set parameters for board_init_r */
230         move.l %a0,-(%sp)               /* dest_addr */
231         move.l %d0,-(%sp)               /* gd */
232         jsr     (%a1)
233
234 /*------------------------------------------------------------------------------*/
235 /* exception code */
236         .globl _fault
237 _fault:
238         jmp _fault
239
240         .globl  _exc_handler
241 _exc_handler:
242         SAVE_ALL
243         movel   %sp,%sp@-
244         bsr exc_handler
245         addql   #4,%sp
246         RESTORE_ALL
247
248         .globl  _int_handler
249 _int_handler:
250         SAVE_ALL
251         movel   %sp,%sp@-
252         bsr int_handler
253         addql   #4,%sp
254         RESTORE_ALL
255
256 /*------------------------------------------------------------------------------*/
257 /* cache functions */
258 #ifdef  CONFIG_M5272
259         .globl  icache_enable
260 icache_enable:
261         move.l  #0x01000000, %d0                /* Invalidate cache cmd */
262         movec   %d0, %CACR                      /* Invalidate cache */
263         move.l  #0x0000c000, %d0                /* Setup cache mask */
264         movec   %d0, %ACR0                      /* Enable cache */
265         move.l  #0xff00c000, %d0                /* Setup cache mask */
266         movec   %d0, %ACR1                      /* Enable cache */
267         move.l  #0x80000100, %d0                /* Setup cache mask */
268         movec   %d0, %CACR                      /* Enable cache */
269         moveq   #1, %d0
270         move.l  %d0, icache_state
271         rts
272 #endif
273
274 #ifdef CONFIG_M5282
275         .globl  icache_enable
276 icache_enable:
277         move.l  #0x01000000, %d0                /* Invalidate cache cmd */
278         movec   %d0, %CACR                      /* Invalidate cache */
279         move.l  #0x0000c000, %d0                /* Setup cache mask */
280         movec   %d0, %ACR0                      /* Enable cache */
281         move.l  #0xff00c000, %d0                /* Setup cache mask */
282         movec   %d0, %ACR1                      /* Enable cache */
283         move.l  #0x80400100, %d0                /* Setup cache mask, data cache disabel*/
284         movec   %d0, %CACR                      /* Enable cache */
285         moveq   #1, %d0
286         move.l  %d0, icache_state
287         rts
288 #endif
289
290         .globl  icache_disable
291 icache_disable:
292         move.l  #0x00000100, %d0                /* Setup cache mask */
293         movec   %d0, %CACR                      /* Enable cache */
294         clr.l   %d0                             /* Setup cache mask */
295         movec   %d0, %ACR0                      /* Enable cache */
296         movec   %d0, %ACR1                      /* Enable cache */
297         moveq   #0, %d0
298         move.l  %d0, icache_state
299         rts
300
301         .globl  icache_status
302 icache_status:
303         move.l  icache_state, %d0
304         rts
305
306         .data
307 icache_state:
308         .long   1
309
310 /*------------------------------------------------------------------------------*/
311
312         .globl  version_string
313 version_string:
314         .ascii U_BOOT_VERSION
315         .ascii " (", __DATE__, " - ", __TIME__, ")"
316         .ascii CONFIG_IDENT_STRING, "\0"