blob: 88fdf88c342746d6511f34bd4b8f69aa8ba4b3bb [file] [log] [blame]
wdenk47d1a6e2002-11-03 00:01:44 +00001/*
2 * Copyright (C) 1998 Dan Malek <dmalek@jlc.net>
3 * Copyright (C) 1999 Magnus Damm <kieraypc01.p.y.kie.era.ericsson.se>
4 * Copyright (C) 2000,2001,2002 Wolfgang Denk <wd@denx.de>
5 * Copyright (C) 2001 Josh Huber <huber@mclx.com>
6 *
7 * See file CREDITS for list of people who contributed to this
8 * project.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23 * MA 02111-1307 USA
24 */
25
26/* U-Boot - Startup Code for PowerPC based Embedded Boards
27 *
28 *
29 * The processor starts at 0xfff00100 and the code is executed
30 * from flash. The code is organized to be at an other address
31 * in memory, but as long we don't jump around before relocating.
32 * board_init lies at a quite high address and when the cpu has
33 * jumped there, everything is ok.
34 */
35#include <config.h>
36#include <74xx_7xx.h>
Peter Tyser62948502008-11-03 09:30:59 -060037#include <timestamp.h>
wdenk47d1a6e2002-11-03 00:01:44 +000038#include <version.h>
39
40#include <ppc_asm.tmpl>
41#include <ppc_defs.h>
42
43#include <asm/cache.h>
44#include <asm/mmu.h>
45
wdenk5da7f2f2004-01-03 00:43:19 +000046#if !defined(CONFIG_DB64360) && \
stroese054466a2004-12-16 18:10:54 +000047 !defined(CONFIG_DB64460) && \
Stefan Roese45993ea2006-11-29 15:42:37 +010048 !defined(CONFIG_CPCI750) && \
49 !defined(CONFIG_P3Mx)
wdenk47d1a6e2002-11-03 00:01:44 +000050#include <galileo/gt64260R.h>
wdenk5da7f2f2004-01-03 00:43:19 +000051#endif
wdenk47d1a6e2002-11-03 00:01:44 +000052
53#ifndef CONFIG_IDENT_STRING
54#define CONFIG_IDENT_STRING ""
55#endif
56
57/* We don't want the MMU yet.
58*/
59#undef MSR_KERNEL
60/* Machine Check and Recoverable Interr. */
61#define MSR_KERNEL ( MSR_ME | MSR_RI )
62
63/*
64 * Set up GOT: Global Offset Table
65 *
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +010066 * Use r12 to access the GOT
wdenk47d1a6e2002-11-03 00:01:44 +000067 */
68 START_GOT
69 GOT_ENTRY(_GOT2_TABLE_)
70 GOT_ENTRY(_FIXUP_TABLE_)
71
72 GOT_ENTRY(_start)
73 GOT_ENTRY(_start_of_vectors)
74 GOT_ENTRY(_end_of_vectors)
75 GOT_ENTRY(transfer_to_handler)
76
wdenkb9a83a92003-05-30 12:48:29 +000077 GOT_ENTRY(__init_end)
wdenk47d1a6e2002-11-03 00:01:44 +000078 GOT_ENTRY(_end)
wdenkbf2f8c92003-05-22 22:52:13 +000079 GOT_ENTRY(__bss_start)
wdenk47d1a6e2002-11-03 00:01:44 +000080 END_GOT
81
82/*
83 * r3 - 1st arg to board_init(): IMMP pointer
84 * r4 - 2nd arg to board_init(): boot flag
85 */
86 .text
87 .long 0x27051956 /* U-Boot Magic Number */
88 .globl version_string
89version_string:
90 .ascii U_BOOT_VERSION
Peter Tyser62948502008-11-03 09:30:59 -060091 .ascii " (", U_BOOT_DATE, " - ", U_BOOT_TIME, ")"
wdenk47d1a6e2002-11-03 00:01:44 +000092 .ascii CONFIG_IDENT_STRING, "\0"
93
94 . = EXC_OFF_SYS_RESET
95 .globl _start
96_start:
97 li r21, BOOTFLAG_COLD /* Normal Power-On: Boot from FLASH */
98 b boot_cold
99 sync
100
101 . = EXC_OFF_SYS_RESET + 0x10
102
103 .globl _start_warm
104_start_warm:
105 li r21, BOOTFLAG_WARM /* Software reboot */
106 b boot_warm
107 sync
108
109 /* the boot code is located below the exception table */
110
111 .globl _start_of_vectors
112_start_of_vectors:
113
114/* Machine check */
115 STD_EXCEPTION(0x200, MachineCheck, MachineCheckException)
116
117/* Data Storage exception. "Never" generated on the 860. */
118 STD_EXCEPTION(0x300, DataStorage, UnknownException)
119
120/* Instruction Storage exception. "Never" generated on the 860. */
121 STD_EXCEPTION(0x400, InstStorage, UnknownException)
122
123/* External Interrupt exception. */
124 STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
125
126/* Alignment exception. */
127 . = 0x600
128Alignment:
Rafal Jaworowski06244e42007-06-22 14:58:04 +0200129 EXCEPTION_PROLOG(SRR0, SRR1)
wdenk47d1a6e2002-11-03 00:01:44 +0000130 mfspr r4,DAR
131 stw r4,_DAR(r21)
132 mfspr r5,DSISR
133 stw r5,_DSISR(r21)
134 addi r3,r1,STACK_FRAME_OVERHEAD
Joakim Tjernlund4ff6bc02010-01-19 14:41:55 +0100135 EXC_XFER_TEMPLATE(Alignment, AlignmentException, MSR_KERNEL, COPY_EE)
wdenk47d1a6e2002-11-03 00:01:44 +0000136
137/* Program check exception */
138 . = 0x700
139ProgramCheck:
Rafal Jaworowski06244e42007-06-22 14:58:04 +0200140 EXCEPTION_PROLOG(SRR0, SRR1)
wdenk47d1a6e2002-11-03 00:01:44 +0000141 addi r3,r1,STACK_FRAME_OVERHEAD
Joakim Tjernlund4ff6bc02010-01-19 14:41:55 +0100142 EXC_XFER_TEMPLATE(ProgramCheck, ProgramCheckException,
143 MSR_KERNEL, COPY_EE)
wdenk47d1a6e2002-11-03 00:01:44 +0000144
145 /* No FPU on MPC8xx. This exception is not supposed to happen.
146 */
147 STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
148
149 /* I guess we could implement decrementer, and may have
150 * to someday for timekeeping.
151 */
152 STD_EXCEPTION(0x900, Decrementer, timer_interrupt)
153 STD_EXCEPTION(0xa00, Trap_0a, UnknownException)
154 STD_EXCEPTION(0xb00, Trap_0b, UnknownException)
wdenk874ac262003-07-24 23:38:38 +0000155 STD_EXCEPTION(0xc00, SystemCall, UnknownException)
wdenk47d1a6e2002-11-03 00:01:44 +0000156 STD_EXCEPTION(0xd00, SingleStep, UnknownException)
157
158 STD_EXCEPTION(0xe00, Trap_0e, UnknownException)
159 STD_EXCEPTION(0xf00, Trap_0f, UnknownException)
160
wdenk57b2d802003-06-27 21:31:46 +0000161 /*
162 * On the MPC8xx, this is a software emulation interrupt. It
163 * occurs for all unimplemented and illegal instructions.
wdenk47d1a6e2002-11-03 00:01:44 +0000164 */
165 STD_EXCEPTION(0x1000, SoftEmu, SoftEmuException)
166
167 STD_EXCEPTION(0x1100, InstructionTLBMiss, UnknownException)
168 STD_EXCEPTION(0x1200, DataTLBMiss, UnknownException)
169 STD_EXCEPTION(0x1300, InstructionTLBError, UnknownException)
170 STD_EXCEPTION(0x1400, DataTLBError, UnknownException)
171
172 STD_EXCEPTION(0x1500, Reserved5, UnknownException)
173 STD_EXCEPTION(0x1600, Reserved6, UnknownException)
174 STD_EXCEPTION(0x1700, Reserved7, UnknownException)
175 STD_EXCEPTION(0x1800, Reserved8, UnknownException)
176 STD_EXCEPTION(0x1900, Reserved9, UnknownException)
177 STD_EXCEPTION(0x1a00, ReservedA, UnknownException)
178 STD_EXCEPTION(0x1b00, ReservedB, UnknownException)
179
180 STD_EXCEPTION(0x1c00, DataBreakpoint, UnknownException)
181 STD_EXCEPTION(0x1d00, InstructionBreakpoint, UnknownException)
182 STD_EXCEPTION(0x1e00, PeripheralBreakpoint, UnknownException)
183 STD_EXCEPTION(0x1f00, DevPortBreakpoint, UnknownException)
184
185 .globl _end_of_vectors
186_end_of_vectors:
187
188 . = 0x2000
189
190boot_cold:
191boot_warm:
192 /* disable everything */
193 li r0, 0
194 mtspr HID0, r0
195 sync
196 mtmsr 0
197 bl invalidate_bats
198 sync
199
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200200#ifdef CONFIG_SYS_L2
wdenk47d1a6e2002-11-03 00:01:44 +0000201 /* init the L2 cache */
202 addis r3, r0, L2_INIT@h
203 ori r3, r3, L2_INIT@l
204 sync
205 mtspr l2cr, r3
206#endif
207#if defined(CONFIG_ALTIVEC) && defined(CONFIG_74xx)
208 .long 0x7e00066c
209 /*
wdenk57b2d802003-06-27 21:31:46 +0000210 * dssall instruction, gas doesn't have it yet
211 * ...for altivec, data stream stop all this probably
212 * isn't needed unless we warm (software) reboot U-Boot
wdenk47d1a6e2002-11-03 00:01:44 +0000213 */
214#endif
215
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200216#ifdef CONFIG_SYS_L2
wdenk47d1a6e2002-11-03 00:01:44 +0000217 /* invalidate the L2 cache */
218 bl l2cache_invalidate
219 sync
220#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200221#ifdef CONFIG_SYS_BOARD_ASM_INIT
wdenk47d1a6e2002-11-03 00:01:44 +0000222 /* do early init */
223 bl board_asm_init
224#endif
225
226 /*
227 * Calculate absolute address in FLASH and jump there
228 *------------------------------------------------------*/
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200229 lis r3, CONFIG_SYS_MONITOR_BASE@h
230 ori r3, r3, CONFIG_SYS_MONITOR_BASE@l
wdenk47d1a6e2002-11-03 00:01:44 +0000231 addi r3, r3, in_flash - _start + EXC_OFF_SYS_RESET
232 mtlr r3
233 blr
234
235in_flash:
236 /* let the C-code set up the rest */
237 /* */
238 /* Be careful to keep code relocatable ! */
239 /*------------------------------------------------------*/
240
241 /* perform low-level init */
242 /* sdram init, galileo init, etc */
243 /* r3: NHR bit from HID0 */
244
245 /* setup the bats */
246 bl setup_bats
247 sync
248
249 /*
250 * Cache must be enabled here for stack-in-cache trick.
251 * This means we need to enable the BATS.
252 * This means:
wdenk57b2d802003-06-27 21:31:46 +0000253 * 1) for the EVB, original gt regs need to be mapped
wdenk47d1a6e2002-11-03 00:01:44 +0000254 * 2) need to have an IBAT for the 0xf region,
255 * we are running there!
wdenk57b2d802003-06-27 21:31:46 +0000256 * Cache should be turned on after BATs, since by default
257 * everything is write-through.
258 * The init-mem BAT can be reused after reloc. The old
259 * gt-regs BAT can be reused after board_init_f calls
wdenkda55c6e2004-01-20 23:12:12 +0000260 * board_early_init_f (EVB only).
wdenk57b2d802003-06-27 21:31:46 +0000261 */
Stefan Roese45993ea2006-11-29 15:42:37 +0100262#if !defined(CONFIG_BAB7xx) && !defined(CONFIG_ELPPC) && !defined(CONFIG_P3Mx)
wdenk47d1a6e2002-11-03 00:01:44 +0000263 /* enable address translation */
264 bl enable_addr_trans
265 sync
266
267 /* enable and invalidate the data cache */
268 bl l1dcache_enable
269 sync
270#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200271#ifdef CONFIG_SYS_INIT_RAM_LOCK
wdenk47d1a6e2002-11-03 00:01:44 +0000272 bl lock_ram_in_cache
273 sync
274#endif
275
276 /* set up the stack pointer in our newly created
277 * cache-ram (r1) */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200278 lis r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET)@h
279 ori r1, r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET)@l
wdenk47d1a6e2002-11-03 00:01:44 +0000280
281 li r0, 0 /* Make room for stack frame header and */
282 stwu r0, -4(r1) /* clear final stack frame so that */
283 stwu r0, -4(r1) /* stack backtraces terminate cleanly */
284
285 GET_GOT /* initialize GOT access */
286
287 /* run low-level CPU init code (from Flash) */
288 bl cpu_init_f
289 sync
290
291 mr r3, r21
292
293 /* r3: BOOTFLAG */
294 /* run 1st part of board init code (from Flash) */
295 bl board_init_f
296 sync
297
298 /* NOTREACHED */
299
300 .globl invalidate_bats
301invalidate_bats:
302 /* invalidate BATs */
303 mtspr IBAT0U, r0
304 mtspr IBAT1U, r0
305 mtspr IBAT2U, r0
306 mtspr IBAT3U, r0
Becky Bruce03ea1be2008-05-08 19:02:12 -0500307#ifdef CONFIG_HIGH_BATS
wdenkaaf48a92003-06-20 23:10:58 +0000308 mtspr IBAT4U, r0
309 mtspr IBAT5U, r0
310 mtspr IBAT6U, r0
311 mtspr IBAT7U, r0
312#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000313 isync
314 mtspr DBAT0U, r0
315 mtspr DBAT1U, r0
316 mtspr DBAT2U, r0
317 mtspr DBAT3U, r0
Becky Bruce03ea1be2008-05-08 19:02:12 -0500318#ifdef CONFIG_HIGH_BATS
wdenk57b2d802003-06-27 21:31:46 +0000319 mtspr DBAT4U, r0
320 mtspr DBAT5U, r0
321 mtspr DBAT6U, r0
322 mtspr DBAT7U, r0
wdenkaaf48a92003-06-20 23:10:58 +0000323#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000324 isync
325 sync
326 blr
327
328 /* setup_bats - set them up to some initial state */
329 .globl setup_bats
330setup_bats:
331 addis r0, r0, 0x0000
332
333 /* IBAT 0 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200334 addis r4, r0, CONFIG_SYS_IBAT0L@h
335 ori r4, r4, CONFIG_SYS_IBAT0L@l
336 addis r3, r0, CONFIG_SYS_IBAT0U@h
337 ori r3, r3, CONFIG_SYS_IBAT0U@l
wdenk47d1a6e2002-11-03 00:01:44 +0000338 mtspr IBAT0L, r4
339 mtspr IBAT0U, r3
340 isync
341
342 /* DBAT 0 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200343 addis r4, r0, CONFIG_SYS_DBAT0L@h
344 ori r4, r4, CONFIG_SYS_DBAT0L@l
345 addis r3, r0, CONFIG_SYS_DBAT0U@h
346 ori r3, r3, CONFIG_SYS_DBAT0U@l
wdenk47d1a6e2002-11-03 00:01:44 +0000347 mtspr DBAT0L, r4
348 mtspr DBAT0U, r3
349 isync
350
351 /* IBAT 1 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200352 addis r4, r0, CONFIG_SYS_IBAT1L@h
353 ori r4, r4, CONFIG_SYS_IBAT1L@l
354 addis r3, r0, CONFIG_SYS_IBAT1U@h
355 ori r3, r3, CONFIG_SYS_IBAT1U@l
wdenk47d1a6e2002-11-03 00:01:44 +0000356 mtspr IBAT1L, r4
357 mtspr IBAT1U, r3
358 isync
359
360 /* DBAT 1 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200361 addis r4, r0, CONFIG_SYS_DBAT1L@h
362 ori r4, r4, CONFIG_SYS_DBAT1L@l
363 addis r3, r0, CONFIG_SYS_DBAT1U@h
364 ori r3, r3, CONFIG_SYS_DBAT1U@l
wdenk47d1a6e2002-11-03 00:01:44 +0000365 mtspr DBAT1L, r4
366 mtspr DBAT1U, r3
367 isync
368
369 /* IBAT 2 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200370 addis r4, r0, CONFIG_SYS_IBAT2L@h
371 ori r4, r4, CONFIG_SYS_IBAT2L@l
372 addis r3, r0, CONFIG_SYS_IBAT2U@h
373 ori r3, r3, CONFIG_SYS_IBAT2U@l
wdenk47d1a6e2002-11-03 00:01:44 +0000374 mtspr IBAT2L, r4
375 mtspr IBAT2U, r3
376 isync
377
378 /* DBAT 2 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200379 addis r4, r0, CONFIG_SYS_DBAT2L@h
380 ori r4, r4, CONFIG_SYS_DBAT2L@l
381 addis r3, r0, CONFIG_SYS_DBAT2U@h
382 ori r3, r3, CONFIG_SYS_DBAT2U@l
wdenk47d1a6e2002-11-03 00:01:44 +0000383 mtspr DBAT2L, r4
384 mtspr DBAT2U, r3
385 isync
386
387 /* IBAT 3 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200388 addis r4, r0, CONFIG_SYS_IBAT3L@h
389 ori r4, r4, CONFIG_SYS_IBAT3L@l
390 addis r3, r0, CONFIG_SYS_IBAT3U@h
391 ori r3, r3, CONFIG_SYS_IBAT3U@l
wdenk47d1a6e2002-11-03 00:01:44 +0000392 mtspr IBAT3L, r4
393 mtspr IBAT3U, r3
394 isync
395
396 /* DBAT 3 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200397 addis r4, r0, CONFIG_SYS_DBAT3L@h
398 ori r4, r4, CONFIG_SYS_DBAT3L@l
399 addis r3, r0, CONFIG_SYS_DBAT3U@h
400 ori r3, r3, CONFIG_SYS_DBAT3U@l
wdenk47d1a6e2002-11-03 00:01:44 +0000401 mtspr DBAT3L, r4
402 mtspr DBAT3U, r3
403 isync
404
Becky Bruce03ea1be2008-05-08 19:02:12 -0500405#ifdef CONFIG_HIGH_BATS
wdenkaaf48a92003-06-20 23:10:58 +0000406 /* IBAT 4 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200407 addis r4, r0, CONFIG_SYS_IBAT4L@h
408 ori r4, r4, CONFIG_SYS_IBAT4L@l
409 addis r3, r0, CONFIG_SYS_IBAT4U@h
410 ori r3, r3, CONFIG_SYS_IBAT4U@l
wdenk57b2d802003-06-27 21:31:46 +0000411 mtspr IBAT4L, r4
412 mtspr IBAT4U, r3
413 isync
wdenkaaf48a92003-06-20 23:10:58 +0000414
415 /* DBAT 4 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200416 addis r4, r0, CONFIG_SYS_DBAT4L@h
417 ori r4, r4, CONFIG_SYS_DBAT4L@l
418 addis r3, r0, CONFIG_SYS_DBAT4U@h
419 ori r3, r3, CONFIG_SYS_DBAT4U@l
wdenk57b2d802003-06-27 21:31:46 +0000420 mtspr DBAT4L, r4
421 mtspr DBAT4U, r3
422 isync
wdenkaaf48a92003-06-20 23:10:58 +0000423
wdenk57b2d802003-06-27 21:31:46 +0000424 /* IBAT 5 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200425 addis r4, r0, CONFIG_SYS_IBAT5L@h
426 ori r4, r4, CONFIG_SYS_IBAT5L@l
427 addis r3, r0, CONFIG_SYS_IBAT5U@h
428 ori r3, r3, CONFIG_SYS_IBAT5U@l
wdenk57b2d802003-06-27 21:31:46 +0000429 mtspr IBAT5L, r4
430 mtspr IBAT5U, r3
431 isync
wdenkaaf48a92003-06-20 23:10:58 +0000432
433 /* DBAT 5 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200434 addis r4, r0, CONFIG_SYS_DBAT5L@h
435 ori r4, r4, CONFIG_SYS_DBAT5L@l
436 addis r3, r0, CONFIG_SYS_DBAT5U@h
437 ori r3, r3, CONFIG_SYS_DBAT5U@l
wdenk57b2d802003-06-27 21:31:46 +0000438 mtspr DBAT5L, r4
439 mtspr DBAT5U, r3
440 isync
wdenkaaf48a92003-06-20 23:10:58 +0000441
wdenk57b2d802003-06-27 21:31:46 +0000442 /* IBAT 6 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200443 addis r4, r0, CONFIG_SYS_IBAT6L@h
444 ori r4, r4, CONFIG_SYS_IBAT6L@l
445 addis r3, r0, CONFIG_SYS_IBAT6U@h
446 ori r3, r3, CONFIG_SYS_IBAT6U@l
wdenk57b2d802003-06-27 21:31:46 +0000447 mtspr IBAT6L, r4
448 mtspr IBAT6U, r3
449 isync
wdenkaaf48a92003-06-20 23:10:58 +0000450
451 /* DBAT 6 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200452 addis r4, r0, CONFIG_SYS_DBAT6L@h
453 ori r4, r4, CONFIG_SYS_DBAT6L@l
454 addis r3, r0, CONFIG_SYS_DBAT6U@h
455 ori r3, r3, CONFIG_SYS_DBAT6U@l
wdenk57b2d802003-06-27 21:31:46 +0000456 mtspr DBAT6L, r4
457 mtspr DBAT6U, r3
458 isync
wdenkaaf48a92003-06-20 23:10:58 +0000459
wdenk57b2d802003-06-27 21:31:46 +0000460 /* IBAT 7 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200461 addis r4, r0, CONFIG_SYS_IBAT7L@h
462 ori r4, r4, CONFIG_SYS_IBAT7L@l
463 addis r3, r0, CONFIG_SYS_IBAT7U@h
464 ori r3, r3, CONFIG_SYS_IBAT7U@l
wdenk57b2d802003-06-27 21:31:46 +0000465 mtspr IBAT7L, r4
466 mtspr IBAT7U, r3
467 isync
wdenkaaf48a92003-06-20 23:10:58 +0000468
469 /* DBAT 7 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200470 addis r4, r0, CONFIG_SYS_DBAT7L@h
471 ori r4, r4, CONFIG_SYS_DBAT7L@l
472 addis r3, r0, CONFIG_SYS_DBAT7U@h
473 ori r3, r3, CONFIG_SYS_DBAT7U@l
wdenk57b2d802003-06-27 21:31:46 +0000474 mtspr DBAT7L, r4
475 mtspr DBAT7U, r3
476 isync
wdenkaaf48a92003-06-20 23:10:58 +0000477#endif
478
wdenk47d1a6e2002-11-03 00:01:44 +0000479 /* bats are done, now invalidate the TLBs */
480
481 addis r3, 0, 0x0000
482 addis r5, 0, 0x4 /* upper bound of 0x00040000 for 7400/750 */
483
484 isync
485
486tlblp:
487 tlbie r3
488 sync
489 addi r3, r3, 0x1000
490 cmp 0, 0, r3, r5
491 blt tlblp
492
493 blr
494
495 .globl enable_addr_trans
496enable_addr_trans:
497 /* enable address translation */
498 mfmsr r5
499 ori r5, r5, (MSR_IR | MSR_DR)
500 mtmsr r5
501 isync
502 blr
503
504 .globl disable_addr_trans
505disable_addr_trans:
506 /* disable address translation */
507 mflr r4
508 mfmsr r3
509 andi. r0, r3, (MSR_IR | MSR_DR)
510 beqlr
511 andc r3, r3, r0
512 mtspr SRR0, r4
513 mtspr SRR1, r3
514 rfi
515
516/*
517 * This code finishes saving the registers to the exception frame
518 * and jumps to the appropriate handler for the exception.
519 * Register r21 is pointer into trap frame, r1 has new stack pointer.
520 */
521 .globl transfer_to_handler
522transfer_to_handler:
523 stw r22,_NIP(r21)
524 lis r22,MSR_POW@h
525 andc r23,r23,r22
526 stw r23,_MSR(r21)
527 SAVE_GPR(7, r21)
528 SAVE_4GPRS(8, r21)
529 SAVE_8GPRS(12, r21)
530 SAVE_8GPRS(24, r21)
531 mflr r23
532 andi. r24,r23,0x3f00 /* get vector offset */
533 stw r24,TRAP(r21)
534 li r22,0
535 stw r22,RESULT(r21)
536 mtspr SPRG2,r22 /* r1 is now kernel sp */
537 lwz r24,0(r23) /* virtual address of handler */
538 lwz r23,4(r23) /* where to go when done */
539 mtspr SRR0,r24
540 mtspr SRR1,r20
541 mtlr r23
542 SYNC
543 rfi /* jump to handler, enable MMU */
544
545int_return:
546 mfmsr r28 /* Disable interrupts */
547 li r4,0
548 ori r4,r4,MSR_EE
549 andc r28,r28,r4
550 SYNC /* Some chip revs need this... */
551 mtmsr r28
552 SYNC
553 lwz r2,_CTR(r1)
554 lwz r0,_LINK(r1)
555 mtctr r2
556 mtlr r0
557 lwz r2,_XER(r1)
558 lwz r0,_CCR(r1)
559 mtspr XER,r2
560 mtcrf 0xFF,r0
561 REST_10GPRS(3, r1)
562 REST_10GPRS(13, r1)
563 REST_8GPRS(23, r1)
564 REST_GPR(31, r1)
565 lwz r2,_NIP(r1) /* Restore environment */
566 lwz r0,_MSR(r1)
567 mtspr SRR0,r2
568 mtspr SRR1,r0
569 lwz r0,GPR0(r1)
570 lwz r2,GPR2(r1)
571 lwz r1,GPR1(r1)
572 SYNC
573 rfi
574
575 .globl dc_read
576dc_read:
577 blr
578
579 .globl get_pvr
580get_pvr:
581 mfspr r3, PVR
582 blr
583
584/*-----------------------------------------------------------------------*/
585/*
586 * void relocate_code (addr_sp, gd, addr_moni)
587 *
588 * This "function" does not return, instead it continues in RAM
589 * after relocating the monitor code.
590 *
591 * r3 = dest
592 * r4 = src
593 * r5 = length in bytes
594 * r6 = cachelinesize
595 */
596 .globl relocate_code
597relocate_code:
598 mr r1, r3 /* Set new stack pointer */
599 mr r9, r4 /* Save copy of Global Data pointer */
600 mr r10, r5 /* Save copy of Destination Address */
601
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +0100602 GET_GOT
wdenk47d1a6e2002-11-03 00:01:44 +0000603 mr r3, r5 /* Destination Address */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200604 lis r4, CONFIG_SYS_MONITOR_BASE@h /* Source Address */
605 ori r4, r4, CONFIG_SYS_MONITOR_BASE@l
wdenkb9a83a92003-05-30 12:48:29 +0000606 lwz r5, GOT(__init_end)
607 sub r5, r5, r4
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200608 li r6, CONFIG_SYS_CACHELINE_SIZE /* Cache Line Size */
wdenk47d1a6e2002-11-03 00:01:44 +0000609
610 /*
611 * Fix GOT pointer:
612 *
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200613 * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE) + Destination Address
wdenk47d1a6e2002-11-03 00:01:44 +0000614 *
615 * Offset:
616 */
617 sub r15, r10, r4
618
619 /* First our own GOT */
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +0100620 add r12, r12, r15
wdenk47d1a6e2002-11-03 00:01:44 +0000621 /* then the one used by the C code */
622 add r30, r30, r15
623
624 /*
625 * Now relocate code
626 */
627#ifdef CONFIG_ECC
628 bl board_relocate_rom
629 sync
630 mr r3, r10 /* Destination Address */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200631 lis r4, CONFIG_SYS_MONITOR_BASE@h /* Source Address */
632 ori r4, r4, CONFIG_SYS_MONITOR_BASE@l
wdenkb9a83a92003-05-30 12:48:29 +0000633 lwz r5, GOT(__init_end)
634 sub r5, r5, r4
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200635 li r6, CONFIG_SYS_CACHELINE_SIZE /* Cache Line Size */
wdenk47d1a6e2002-11-03 00:01:44 +0000636#else
637 cmplw cr1,r3,r4
638 addi r0,r5,3
639 srwi. r0,r0,2
640 beq cr1,4f /* In place copy is not necessary */
641 beq 7f /* Protect against 0 count */
642 mtctr r0
643 bge cr1,2f
644
645 la r8,-4(r4)
646 la r7,-4(r3)
6471: lwzu r0,4(r8)
648 stwu r0,4(r7)
649 bdnz 1b
650 b 4f
651
6522: slwi r0,r0,2
653 add r8,r4,r0
654 add r7,r3,r0
6553: lwzu r0,-4(r8)
656 stwu r0,-4(r7)
657 bdnz 3b
658#endif
659/*
660 * Now flush the cache: note that we must start from a cache aligned
661 * address. Otherwise we might miss one cache line.
662 */
6634: cmpwi r6,0
664 add r5,r3,r5
665 beq 7f /* Always flush prefetch queue in any case */
666 subi r0,r6,1
667 andc r3,r3,r0
668 mr r4,r3
6695: dcbst 0,r4
670 add r4,r4,r6
671 cmplw r4,r5
672 blt 5b
673 sync /* Wait for all dcbst to complete on bus */
674 mr r4,r3
6756: icbi 0,r4
676 add r4,r4,r6
677 cmplw r4,r5
678 blt 6b
6797: sync /* Wait for all icbi to complete on bus */
680 isync
681
682/*
683 * We are done. Do not return, instead branch to second part of board
684 * initialization, now running from RAM.
685 */
686 addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
687 mtlr r0
688 blr
689
690in_ram:
691#ifdef CONFIG_ECC
692 bl board_init_ecc
693#endif
694 /*
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +0100695 * Relocation Function, r12 point to got2+0x8000
wdenk47d1a6e2002-11-03 00:01:44 +0000696 *
wdenk57b2d802003-06-27 21:31:46 +0000697 * Adjust got2 pointers, no need to check for 0, this code
698 * already puts a few entries in the table.
wdenk47d1a6e2002-11-03 00:01:44 +0000699 */
700 li r0,__got2_entries@sectoff@l
701 la r3,GOT(_GOT2_TABLE_)
702 lwz r11,GOT(_GOT2_TABLE_)
703 mtctr r0
704 sub r11,r3,r11
705 addi r3,r3,-4
7061: lwzu r0,4(r3)
Joakim Tjernlund4f2fdac2009-10-08 02:03:51 +0200707 cmpwi r0,0
708 beq- 2f
wdenk47d1a6e2002-11-03 00:01:44 +0000709 add r0,r0,r11
710 stw r0,0(r3)
Joakim Tjernlund4f2fdac2009-10-08 02:03:51 +02007112: bdnz 1b
wdenk47d1a6e2002-11-03 00:01:44 +0000712
713 /*
wdenk57b2d802003-06-27 21:31:46 +0000714 * Now adjust the fixups and the pointers to the fixups
wdenk47d1a6e2002-11-03 00:01:44 +0000715 * in case we need to move ourselves again.
716 */
Joakim Tjernlund4f2fdac2009-10-08 02:03:51 +0200717 li r0,__fixup_entries@sectoff@l
wdenk47d1a6e2002-11-03 00:01:44 +0000718 lwz r3,GOT(_FIXUP_TABLE_)
719 cmpwi r0,0
720 mtctr r0
721 addi r3,r3,-4
722 beq 4f
7233: lwzu r4,4(r3)
724 lwzux r0,r4,r11
725 add r0,r0,r11
726 stw r10,0(r3)
727 stw r0,0(r4)
728 bdnz 3b
7294:
730/* clear_bss: */
731 /*
732 * Now clear BSS segment
733 */
wdenkbf2f8c92003-05-22 22:52:13 +0000734 lwz r3,GOT(__bss_start)
wdenk47d1a6e2002-11-03 00:01:44 +0000735 lwz r4,GOT(_end)
736
737 cmplw 0, r3, r4
738 beq 6f
739
740 li r0, 0
7415:
742 stw r0, 0(r3)
743 addi r3, r3, 4
744 cmplw 0, r3, r4
745 bne 5b
7466:
747 mr r3, r10 /* Destination Address */
wdenk5da7f2f2004-01-03 00:43:19 +0000748#if defined(CONFIG_AMIGAONEG3SE) || \
749 defined(CONFIG_DB64360) || \
stroese054466a2004-12-16 18:10:54 +0000750 defined(CONFIG_DB64460) || \
Heiko Schocherd7f77fb2006-06-19 11:02:41 +0200751 defined(CONFIG_CPCI750) || \
Stefan Roese45993ea2006-11-29 15:42:37 +0100752 defined(CONFIG_PPMC7XX) || \
753 defined(CONFIG_P3Mx)
wdenkbb444c92002-12-07 00:20:59 +0000754 mr r4, r9 /* Use RAM copy of the global data */
755#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000756 bl after_reloc
757
758 /* not reached - end relocate_code */
759/*-----------------------------------------------------------------------*/
760
wdenk47d1a6e2002-11-03 00:01:44 +0000761 /*
762 * Copy exception vector code to low memory
763 *
764 * r3: dest_addr
765 * r7: source address, r8: end address, r9: target address
766 */
767 .globl trap_init
768trap_init:
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +0100769 mflr r4 /* save link register */
770 GET_GOT
wdenk47d1a6e2002-11-03 00:01:44 +0000771 lwz r7, GOT(_start)
772 lwz r8, GOT(_end_of_vectors)
773
wdenk4e112c12003-06-03 23:54:09 +0000774 li r9, 0x100 /* reset vector always at 0x100 */
wdenk47d1a6e2002-11-03 00:01:44 +0000775
776 cmplw 0, r7, r8
777 bgelr /* return if r7>=r8 - just in case */
wdenk47d1a6e2002-11-03 00:01:44 +00007781:
779 lwz r0, 0(r7)
780 stw r0, 0(r9)
781 addi r7, r7, 4
782 addi r9, r9, 4
783 cmplw 0, r7, r8
784 bne 1b
785
786 /*
787 * relocate `hdlr' and `int_return' entries
788 */
789 li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
790 li r8, Alignment - _start + EXC_OFF_SYS_RESET
7912:
792 bl trap_reloc
793 addi r7, r7, 0x100 /* next exception vector */
794 cmplw 0, r7, r8
795 blt 2b
796
797 li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
798 bl trap_reloc
799
800 li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
801 bl trap_reloc
802
803 li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
804 li r8, SystemCall - _start + EXC_OFF_SYS_RESET
8053:
806 bl trap_reloc
807 addi r7, r7, 0x100 /* next exception vector */
808 cmplw 0, r7, r8
809 blt 3b
810
811 li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
812 li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
8134:
814 bl trap_reloc
815 addi r7, r7, 0x100 /* next exception vector */
816 cmplw 0, r7, r8
817 blt 4b
818
819 /* enable execptions from RAM vectors */
820 mfmsr r7
821 li r8,MSR_IP
822 andc r7,r7,r8
823 mtmsr r7
824
825 mtlr r4 /* restore link register */
826 blr
827
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200828#ifdef CONFIG_SYS_INIT_RAM_LOCK
wdenk47d1a6e2002-11-03 00:01:44 +0000829lock_ram_in_cache:
830 /* Allocate Initial RAM in data cache.
831 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200832 lis r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@h
833 ori r3, r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@l
Dave Liuce2b1d02008-10-23 21:59:35 +0800834 li r4, ((CONFIG_SYS_INIT_RAM_END & ~31) + \
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200835 (CONFIG_SYS_INIT_RAM_ADDR & 31) + 31) / 32
Dave Liuce2b1d02008-10-23 21:59:35 +0800836 mtctr r4
wdenk47d1a6e2002-11-03 00:01:44 +00008371:
838 dcbz r0, r3
839 addi r3, r3, 32
840 bdnz 1b
841
842 /* Lock the data cache */
843 mfspr r0, HID0
844 ori r0, r0, 0x1000
845 sync
846 mtspr HID0, r0
847 sync
848 blr
849
850.globl unlock_ram_in_cache
851unlock_ram_in_cache:
852 /* invalidate the INIT_RAM section */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200853 lis r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@h
854 ori r3, r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@l
Dave Liuce2b1d02008-10-23 21:59:35 +0800855 li r4, ((CONFIG_SYS_INIT_RAM_END & ~31) + \
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200856 (CONFIG_SYS_INIT_RAM_ADDR & 31) + 31) / 32
Dave Liuce2b1d02008-10-23 21:59:35 +0800857 mtctr r4
wdenk47d1a6e2002-11-03 00:01:44 +00008581: icbi r0, r3
859 addi r3, r3, 32
860 bdnz 1b
861 sync /* Wait for all icbi to complete on bus */
862 isync
863
864 /* Unlock the data cache and invalidate it */
865 mfspr r0, HID0
866 li r3,0x1000
867 andc r0,r0,r3
868 li r3,0x0400
869 or r0,r0,r3
870 sync
871 mtspr HID0, r0
872 sync
873 blr
874#endif