blob: c4f608230df35143b5dabe3fbb6fdc9d5f59644b [file] [log] [blame]
TsiChungLiewb859ef12007-08-16 19:23:50 -05001/*
2 * Copyright (C) 2003 Josef Baumgartner <josef.baumgartner@telex.de>
3 * Based on code from Bernhard Kuhn <bkuhn@metrowerks.com>
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
TsiChungLiewb859ef12007-08-16 19:23:50 -05006 */
7
Wolfgang Denk0191e472010-10-26 14:34:52 +02008#include <asm-offsets.h>
TsiChungLiewb859ef12007-08-16 19:23:50 -05009#include <config.h>
10#include "version.h"
TsiChung Liew0ee47d42010-03-11 22:12:53 -060011#include <asm/cache.h>
TsiChungLiewb859ef12007-08-16 19:23:50 -050012
13#ifndef CONFIG_IDENT_STRING
14#define CONFIG_IDENT_STRING ""
15#endif
16
17#define _START _start
18#define _FAULT _fault
19
20#define SAVE_ALL \
21 move.w #0x2700,%sr; /* disable intrs */ \
22 subl #60,%sp; /* space for 15 regs */ \
23 moveml %d0-%d7/%a0-%a6,%sp@;
24
25#define RESTORE_ALL \
26 moveml %sp@,%d0-%d7/%a0-%a6; \
27 addl #60,%sp; /* space for 15 regs */ \
28 rte;
29
30.text
Angelo Dureghello65d59912016-05-22 00:14:29 +020031
TsiChungLiewb859ef12007-08-16 19:23:50 -050032/*
Angelo Dureghello65d59912016-05-22 00:14:29 +020033 * Vector table. This is used for initial platform startup.
34 * These vectors are to catch any un-intended traps.
TsiChungLiewb859ef12007-08-16 19:23:50 -050035 */
36_vectors:
Angelo Dureghello65d59912016-05-22 00:14:29 +020037INITSP: .long 0x00000000 /* Initial SP */
38INITPC: .long _START /* Initial PC */
TsiChungLiewb859ef12007-08-16 19:23:50 -050039
Angelo Dureghello65d59912016-05-22 00:14:29 +020040vector02_0F:
41.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
42.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
TsiChungLiewb859ef12007-08-16 19:23:50 -050043
44/* Reserved */
45vector10_17:
46.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
47
Angelo Dureghello65d59912016-05-22 00:14:29 +020048vector18_1F:
49.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
TsiChungLiewb859ef12007-08-16 19:23:50 -050050
51/* TRAP #0 - #15 */
52vector20_2F:
53.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
54.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
55
56/* Reserved */
57vector30_3F:
58.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
59.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
60
61vector64_127:
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, _FAULT, _FAULT
67.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
68.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
69.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
70
71vector128_191:
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.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
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
81vector192_255:
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.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
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
Angelo Dureghello65d59912016-05-22 00:14:29 +020091.text
TsiChungLiewb859ef12007-08-16 19:23:50 -050092
Angelo Dureghello65d59912016-05-22 00:14:29 +020093.globl _start
TsiChungLiewb859ef12007-08-16 19:23:50 -050094_start:
95 nop
96 nop
Angelo Dureghello65d59912016-05-22 00:14:29 +020097 move.w #0x2700,%sr /* Mask off Interrupt */
TsiChungLiewb859ef12007-08-16 19:23:50 -050098
99 /* Set vector base register at the beginning of the Flash */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200100 move.l #CONFIG_SYS_FLASH_BASE, %d0
TsiChungLiewb859ef12007-08-16 19:23:50 -0500101 movec %d0, %VBR
102
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200103 move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0
TsiChungLiewb859ef12007-08-16 19:23:50 -0500104 movec %d0, %RAMBAR1
105
106 /* invalidate and disable cache */
Angelo Dureghello65d59912016-05-22 00:14:29 +0200107 move.l #CF_CACR_CINV, %d0 /* Invalidate cache cmd */
108 movec %d0, %CACR /* Invalidate cache */
TsiChungLiewb859ef12007-08-16 19:23:50 -0500109 nop
110 move.l #0, %d0
111 movec %d0, %ACR0
112 movec %d0, %ACR1
113
114 /* initialize general use internal ram */
Angelo Dureghello65d59912016-05-22 00:14:29 +0200115 move.l #0, %d0
116 move.l #(ICACHE_STATUS), %a1 /* icache */
117 move.l #(DCACHE_STATUS), %a2 /* icache */
118 move.l %d0, (%a1)
119 move.l %d0, (%a2)
TsiChungLiewb859ef12007-08-16 19:23:50 -0500120
angelo@sysam.itef9707c2016-04-27 21:50:44 +0200121 /* put relocation table address to a5 */
Angelo Dureghello65d59912016-05-22 00:14:29 +0200122 move.l #__got_start, %a5
TsiChungLiewb859ef12007-08-16 19:23:50 -0500123
angelo@sysam.itef9707c2016-04-27 21:50:44 +0200124 /* setup stack initially on top of internal static ram */
125 move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_SIZE), %sp
126
127 /*
128 * if configured, malloc_f arena will be reserved first,
129 * then (and always) gd struct space will be reserved
130 */
131 move.l %sp, -(%sp)
132 move.l #board_init_f_alloc_reserve, %a1
133 jsr (%a1)
134
135 /* update stack and frame-pointers */
Angelo Dureghello65d59912016-05-22 00:14:29 +0200136 move.l %d0, %sp
137 move.l %sp, %fp
angelo@sysam.itef9707c2016-04-27 21:50:44 +0200138
139 /* initialize reserved area */
Angelo Dureghello65d59912016-05-22 00:14:29 +0200140 move.l %d0, -(%sp)
angelo@sysam.itef9707c2016-04-27 21:50:44 +0200141 move.l #board_init_f_init_reserve, %a1
142 jsr (%a1)
TsiChungLiewb859ef12007-08-16 19:23:50 -0500143
angelo@sysam.itb8cd1322016-04-12 00:30:59 +0200144 /* run low-level CPU init code (from flash) */
Angelo Dureghello65d59912016-05-22 00:14:29 +0200145 move.l #cpu_init_f, %a1
146 jsr (%a1)
147
angelo@sysam.itb8cd1322016-04-12 00:30:59 +0200148 /* run low-level board init code (from flash) */
Angelo Dureghello65d59912016-05-22 00:14:29 +0200149 clr.l %sp@-
150 move.l #board_init_f, %a1
151 jsr (%a1)
TsiChungLiewb859ef12007-08-16 19:23:50 -0500152
153 /* board_init_f() does not return */
154
Angelo Dureghello65d59912016-05-22 00:14:29 +0200155/******************************************************************************/
TsiChungLiewb859ef12007-08-16 19:23:50 -0500156
157/*
158 * void relocate_code (addr_sp, gd, addr_moni)
159 *
160 * This "function" does not return, instead it continues in RAM
161 * after relocating the monitor code.
162 *
163 * r3 = dest
164 * r4 = src
165 * r5 = length in bytes
166 * r6 = cachelinesize
167 */
Angelo Dureghello65d59912016-05-22 00:14:29 +0200168.globl relocate_code
TsiChungLiewb859ef12007-08-16 19:23:50 -0500169relocate_code:
Angelo Dureghello65d59912016-05-22 00:14:29 +0200170 link.w %a6,#0
171 move.l 8(%a6), %sp /* set new stack pointer */
TsiChungLiewb859ef12007-08-16 19:23:50 -0500172
Angelo Dureghello65d59912016-05-22 00:14:29 +0200173 move.l 12(%a6), %d0 /* Save copy of Global Data pointer */
174 move.l 16(%a6), %a0 /* Save copy of Destination Address */
TsiChungLiewb859ef12007-08-16 19:23:50 -0500175
Angelo Dureghello65d59912016-05-22 00:14:29 +0200176 move.l #CONFIG_SYS_MONITOR_BASE, %a1
177 move.l #__init_end, %a2
178 move.l %a0, %a3
TsiChungLiewb859ef12007-08-16 19:23:50 -0500179
180 /* copy the code to RAM */
1811:
Angelo Dureghello65d59912016-05-22 00:14:29 +0200182 move.l (%a1)+, (%a3)+
183 cmp.l %a1,%a2
184 bgt.s 1b
TsiChungLiewb859ef12007-08-16 19:23:50 -0500185
186/*
187 * We are done. Do not return, instead branch to second part of board
188 * initialization, now running from RAM.
189 */
190 move.l %a0, %a1
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200191 add.l #(in_ram - CONFIG_SYS_MONITOR_BASE), %a1
TsiChungLiewb859ef12007-08-16 19:23:50 -0500192 jmp (%a1)
193
194in_ram:
195
196clear_bss:
197 /*
198 * Now clear BSS segment
199 */
200 move.l %a0, %a1
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200201 add.l #(_sbss - CONFIG_SYS_MONITOR_BASE),%a1
TsiChungLiewb859ef12007-08-16 19:23:50 -0500202 move.l %a0, %d1
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200203 add.l #(_ebss - CONFIG_SYS_MONITOR_BASE),%d1
TsiChungLiewb859ef12007-08-16 19:23:50 -05002046:
205 clr.l (%a1)+
206 cmp.l %a1,%d1
207 bgt.s 6b
208
209 /*
210 * fix got table in RAM
211 */
212 move.l %a0, %a1
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200213 add.l #(__got_start - CONFIG_SYS_MONITOR_BASE),%a1
TsiChungLiewb859ef12007-08-16 19:23:50 -0500214 move.l %a1,%a5 /* * fix got pointer register a5 */
215
216 move.l %a0, %a2
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200217 add.l #(__got_end - CONFIG_SYS_MONITOR_BASE),%a2
TsiChungLiewb859ef12007-08-16 19:23:50 -0500218
2197:
220 move.l (%a1),%d1
221 sub.l #_start,%d1
222 add.l %a0,%d1
223 move.l %d1,(%a1)+
224 cmp.l %a2, %a1
225 bne 7b
226
227 /* calculate relative jump to board_init_r in ram */
Angelo Dureghello65d59912016-05-22 00:14:29 +0200228 move.l %a0, %a1
229 add.l #(board_init_r - CONFIG_SYS_MONITOR_BASE), %a1
TsiChungLiewb859ef12007-08-16 19:23:50 -0500230
231 /* set parameters for board_init_r */
Angelo Dureghello65d59912016-05-22 00:14:29 +0200232 move.l %a0,-(%sp) /* dest_addr */
233 move.l %d0,-(%sp) /* gd */
TsiChungLiewb859ef12007-08-16 19:23:50 -0500234 jsr (%a1)
235
Angelo Dureghello65d59912016-05-22 00:14:29 +0200236/******************************************************************************/
237
TsiChungLiewb859ef12007-08-16 19:23:50 -0500238/* exception code */
Angelo Dureghello65d59912016-05-22 00:14:29 +0200239.globl _fault
TsiChungLiewb859ef12007-08-16 19:23:50 -0500240_fault:
Angelo Dureghello65d59912016-05-22 00:14:29 +0200241 bra _fault
TsiChungLiewb859ef12007-08-16 19:23:50 -0500242
Angelo Dureghello65d59912016-05-22 00:14:29 +0200243.globl _exc_handler
TsiChungLiewb859ef12007-08-16 19:23:50 -0500244_exc_handler:
245 SAVE_ALL
246 movel %sp,%sp@-
Angelo Dureghello65d59912016-05-22 00:14:29 +0200247 bsr exc_handler
TsiChungLiewb859ef12007-08-16 19:23:50 -0500248 addql #4,%sp
249 RESTORE_ALL
250
Angelo Dureghello65d59912016-05-22 00:14:29 +0200251.globl _int_handler
TsiChungLiewb859ef12007-08-16 19:23:50 -0500252_int_handler:
253 SAVE_ALL
254 movel %sp,%sp@-
Angelo Dureghello65d59912016-05-22 00:14:29 +0200255 bsr int_handler
TsiChungLiewb859ef12007-08-16 19:23:50 -0500256 addql #4,%sp
257 RESTORE_ALL
258
Angelo Dureghello65d59912016-05-22 00:14:29 +0200259/******************************************************************************/
TsiChungLiewb859ef12007-08-16 19:23:50 -0500260
Angelo Dureghello65d59912016-05-22 00:14:29 +0200261.globl version_string
TsiChungLiewb859ef12007-08-16 19:23:50 -0500262version_string:
Angelo Dureghello65d59912016-05-22 00:14:29 +0200263.ascii U_BOOT_VERSION_STRING, "\0"
264.align 4