blob: dbe2b54e4101af8f0c591e5b6b48360dcae75440 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
angelo@sysam.ite77e65d2015-02-12 01:40:00 +01002/*
3 * (C) Copyright 2015 Angelo Dureghello <angelo@sysam.it>
4 * Based on code from Bernhard Kuhn <bkuhn@metrowerks.com>
angelo@sysam.ite77e65d2015-02-12 01:40:00 +01005 */
6
7#include <asm-offsets.h>
8#include <config.h>
angelo@sysam.ite77e65d2015-02-12 01:40:00 +01009#include <asm/cache.h>
10
angelo@sysam.ite77e65d2015-02-12 01:40:00 +010011#define _START _start
12#define _FAULT _fault
13
14
15.macro SAVE_ALL
16 move.w #0x2700,%sr; /* disable intrs */
17 subl #60,%sp; /* space for 15 regs */
18 moveml %d0-%d7/%a0-%a6,%sp@
19.endm
20
21.macro RESTORE_ALL
22 moveml %sp@,%d0-%d7/%a0-%a6;
23 addl #60,%sp; /* space for 15 regs */
24 rte
25.endm
26
27/* If we come from a pre-loader we don't need an initial exception
28 * table.
29 */
30#if !defined(CONFIG_MONITOR_IS_IN_RAM)
31
32.text
Angelo Dureghello5c928d02016-05-22 00:14:29 +020033
angelo@sysam.ite77e65d2015-02-12 01:40:00 +010034/*
Angelo Dureghello5c928d02016-05-22 00:14:29 +020035 * Vector table. This is used for initial platform startup.
36 * These vectors are to catch any un-intended traps.
angelo@sysam.ite77e65d2015-02-12 01:40:00 +010037 */
38_vectors:
angelo@sysam.ite77e65d2015-02-12 01:40:00 +010039/* Flash offset is 0 until we setup CS0 */
40.long 0x00000000
41#if defined(CONFIG_M5307) && \
Tom Rini65cc0e22022-11-16 13:10:41 -050042 (CONFIG_TEXT_BASE == CFG_SYS_INT_FLASH_BASE)
Simon Glass98463902022-10-20 18:22:39 -060043.long _start - CONFIG_TEXT_BASE
angelo@sysam.ite77e65d2015-02-12 01:40:00 +010044#else
45.long _START
46#endif
47
48.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
49.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
50.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
51.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
52.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
53.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
54.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
55.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
56
57.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
58.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
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
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.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
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.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
84#endif
85
Angelo Dureghello5c928d02016-05-22 00:14:29 +020086.text
87
88.globl _start
angelo@sysam.ite77e65d2015-02-12 01:40:00 +010089_start:
90 nop
91 nop
Angelo Dureghello5c928d02016-05-22 00:14:29 +020092 move.w #0x2700,%sr
angelo@sysam.ite77e65d2015-02-12 01:40:00 +010093
94 /* set MBAR address + valid flag */
Tom Rini65cc0e22022-11-16 13:10:41 -050095 move.l #(CFG_SYS_MBAR + 1), %d0
angelo@sysam.ite77e65d2015-02-12 01:40:00 +010096 move.c %d0, %MBAR
97
Tom Rini65cc0e22022-11-16 13:10:41 -050098 move.l #(CFG_SYS_INIT_RAM_ADDR + 1), %d0
angelo@sysam.ite77e65d2015-02-12 01:40:00 +010099 move.c %d0, %RAMBAR
100
101 /* DS 4.8.2 (Cache Organization) invalidate and disable cache */
Angelo Dureghello5c928d02016-05-22 00:14:29 +0200102 move.l #CF_CACR_CINVA, %d0
103 movec %d0, %CACR
104 move.l #0, %d0
105 movec %d0, %ACR0
106 movec %d0, %ACR1
angelo@sysam.ite77e65d2015-02-12 01:40:00 +0100107
108 /*
109 * if we come from a pre-loader we have no exception table and
110 * therefore no VBR to set
111 */
112#if !defined(CONFIG_MONITOR_IS_IN_RAM)
Tom Rini65cc0e22022-11-16 13:10:41 -0500113 move.l #CFG_SYS_FLASH_BASE, %d0
angelo@sysam.ite77e65d2015-02-12 01:40:00 +0100114 movec %d0, %VBR
115#endif
116
117 /* initialize general use internal ram */
118 move.l #0, %d0
119 move.l #(ICACHE_STATUS), %a1 /* icache */
120 move.l #(DCACHE_STATUS), %a2 /* dcache */
121 move.l %d0, (%a1)
122 move.l %d0, (%a2)
123
angelo@sysam.ite77e65d2015-02-12 01:40:00 +0100124 /* put relocation table address to a5 */
Angelo Dureghello5c928d02016-05-22 00:14:29 +0200125 move.l #__got_start, %a5
angelo@sysam.ite77e65d2015-02-12 01:40:00 +0100126
angelo@sysam.it5044c9c2016-04-27 21:50:44 +0200127 /* setup stack initially on top of internal static ram */
Tom Rini65cc0e22022-11-16 13:10:41 -0500128 move.l #(CFG_SYS_INIT_RAM_ADDR + CFG_SYS_INIT_RAM_SIZE), %sp
angelo@sysam.it5044c9c2016-04-27 21:50:44 +0200129
130 /*
131 * if configured, malloc_f arena will be reserved first,
132 * then (and always) gd struct space will be reserved
133 */
134 move.l %sp, -(%sp)
135 bsr board_init_f_alloc_reserve
136
137 /* update stack and frame-pointers */
Angelo Dureghello5c928d02016-05-22 00:14:29 +0200138 move.l %d0, %sp
139 move.l %sp, %fp
angelo@sysam.it5044c9c2016-04-27 21:50:44 +0200140
141 /* initialize reserved area */
Angelo Dureghello5c928d02016-05-22 00:14:29 +0200142 move.l %d0, -(%sp)
143 bsr board_init_f_init_reserve
angelo@sysam.it5044c9c2016-04-27 21:50:44 +0200144
angelo@sysam.ite77e65d2015-02-12 01:40:00 +0100145 /* run low-level CPU init code (from flash) */
Angelo Dureghello5c928d02016-05-22 00:14:29 +0200146 bsr cpu_init_f
angelo@sysam.ite77e65d2015-02-12 01:40:00 +0100147
148 /* run low-level board init code (from flash) */
Angelo Dureghello5c928d02016-05-22 00:14:29 +0200149 clr.l %sp@-
150 bsr board_init_f
angelo@sysam.ite77e65d2015-02-12 01:40:00 +0100151
152 /* board_init_f() does not return */
153
Angelo Dureghello5c928d02016-05-22 00:14:29 +0200154/******************************************************************************/
angelo@sysam.ite77e65d2015-02-12 01:40:00 +0100155
156/*
Simon Glass94133872019-12-28 10:44:45 -0700157 * void relocate_code(addr_sp, gd, addr_moni)
angelo@sysam.ite77e65d2015-02-12 01:40:00 +0100158 *
159 * This "function" does not return, instead it continues in RAM
160 * after relocating the monitor code.
161 *
162 */
Angelo Dureghello5c928d02016-05-22 00:14:29 +0200163.globl relocate_code
angelo@sysam.ite77e65d2015-02-12 01:40:00 +0100164relocate_code:
165 link.w %a6,#0
166 move.l 8(%a6), %sp /* set new stack pointer */
167 move.l 12(%a6), %d0 /* Save copy of Global Data pointer */
168 move.l 16(%a6), %a0 /* Save copy of Destination Address */
169
170 move.l #CONFIG_SYS_MONITOR_BASE, %a1
171 move.l #__init_end, %a2
172 move.l %a0, %a3
173 /* copy the code to RAM */
1741:
175 move.l (%a1)+, (%a3)+
176 cmp.l %a1,%a2
177 bgt.s 1b
178
179/*
180 * We are done. Do not return, instead branch to second part of board
181 * initialization, now running from RAM.
182 */
183 move.l %a0, %a1
184 add.l #(in_ram - CONFIG_SYS_MONITOR_BASE), %a1
185 jmp (%a1)
186
187in_ram:
188
189clear_bss:
190 /*
191 * Now clear BSS segment
192 */
193 move.l %a0, %a1
194 add.l #(_sbss - CONFIG_SYS_MONITOR_BASE), %a1
195 move.l %a0, %d1
196 add.l #(_ebss - CONFIG_SYS_MONITOR_BASE), %d1
1976:
198 clr.l (%a1)+
199 cmp.l %a1,%d1
200 bgt.s 6b
201
202 /*
203 * fix got table in RAM
204 */
205 move.l %a0, %a1
206 add.l #(__got_start - CONFIG_SYS_MONITOR_BASE), %a1
Angelo Dureghello5c928d02016-05-22 00:14:29 +0200207
208 /* fix got pointer register a5 */
angelo@sysam.ite77e65d2015-02-12 01:40:00 +0100209 move.l %a1,%a5
210
211 move.l %a0, %a2
212 add.l #(__got_end - CONFIG_SYS_MONITOR_BASE), %a2
213
2147:
215 move.l (%a1),%d1
216 sub.l #_start, %d1
217 add.l %a0,%d1
218 move.l %d1,(%a1)+
219 cmp.l %a2, %a1
220 bne 7b
221
222 /* calculate relative jump to board_init_r in ram */
223 move.l %a0, %a1
224 add.l #(board_init_r - CONFIG_SYS_MONITOR_BASE), %a1
225
226 /* set parameters for board_init_r */
227 move.l %a0,-(%sp) /* dest_addr */
228 move.l %d0,-(%sp) /* gd */
angelo@sysam.ite77e65d2015-02-12 01:40:00 +0100229 jsr (%a1)
230
Angelo Dureghello5c928d02016-05-22 00:14:29 +0200231/******************************************************************************/
232
angelo@sysam.ite77e65d2015-02-12 01:40:00 +0100233/* exception code */
Angelo Dureghello5c928d02016-05-22 00:14:29 +0200234.globl _fault
angelo@sysam.ite77e65d2015-02-12 01:40:00 +0100235_fault:
236 bra _fault
237
Angelo Dureghello5c928d02016-05-22 00:14:29 +0200238.globl _exc_handler
angelo@sysam.ite77e65d2015-02-12 01:40:00 +0100239_exc_handler:
240 SAVE_ALL
241 movel %sp,%sp@-
Angelo Dureghello5c928d02016-05-22 00:14:29 +0200242 bsr exc_handler
angelo@sysam.ite77e65d2015-02-12 01:40:00 +0100243 addql #4,%sp
244 RESTORE_ALL
245
Angelo Dureghello5c928d02016-05-22 00:14:29 +0200246.globl _int_handler
angelo@sysam.ite77e65d2015-02-12 01:40:00 +0100247_int_handler:
248 SAVE_ALL
249 movel %sp,%sp@-
Angelo Dureghello5c928d02016-05-22 00:14:29 +0200250 bsr int_handler
angelo@sysam.ite77e65d2015-02-12 01:40:00 +0100251 addql #4,%sp
252 RESTORE_ALL
253
Angelo Dureghello5c928d02016-05-22 00:14:29 +0200254/******************************************************************************/
angelo@sysam.ite77e65d2015-02-12 01:40:00 +0100255
Angelo Dureghello5c928d02016-05-22 00:14:29 +0200256.align 4