blob: f7fc922af0b8eb81bfc9687e08b1a1c7615db1c4 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Eran Liberty9095d4a2005-07-28 10:08:46 -05002/*
3 * Copyright (C) 1998 Dan Malek <dmalek@jlc.net>
4 * Copyright (C) 1999 Magnus Damm <kieraypc01.p.y.kie.era.ericsson.se>
5 * Copyright (C) 2000, 2001,2002 Wolfgang Denk <wd@denx.de>
Scott Woodb71689b2008-06-30 14:13:28 -05006 * Copyright Freescale Semiconductor, Inc. 2004, 2006, 2008.
Eran Liberty9095d4a2005-07-28 10:08:46 -05007 */
8
9/*
10 * U-Boot - Startup Code for MPC83xx PowerPC based Embedded Boards
11 */
12
Wolfgang Denk0191e472010-10-26 14:34:52 +020013#include <asm-offsets.h>
Eran Liberty9095d4a2005-07-28 10:08:46 -050014#include <config.h>
Jon Loeligerebc72242005-08-01 13:20:47 -050015#include <mpc83xx.h>
Eran Liberty9095d4a2005-07-28 10:08:46 -050016#include <version.h>
17
18#define CONFIG_83XX 1 /* needed for Linux kernel header files*/
Eran Liberty9095d4a2005-07-28 10:08:46 -050019
20#include <ppc_asm.tmpl>
21#include <ppc_defs.h>
22
23#include <asm/cache.h>
24#include <asm/mmu.h>
Peter Tyser3a1362d2010-10-14 23:33:24 -050025#include <asm/u-boot.h>
Eran Liberty9095d4a2005-07-28 10:08:46 -050026
Mario Six94867102019-01-21 09:17:54 +010027#include "hrcw/hrcw.h"
Mario Sixa861ea62019-01-21 09:17:57 +010028#include "bats/bats.h"
Mario Six94867102019-01-21 09:17:54 +010029
Eran Liberty9095d4a2005-07-28 10:08:46 -050030/* We don't want the MMU yet.
31 */
32#undef MSR_KERNEL
33
34/*
35 * Floating Point enable, Machine Check and Recoverable Interr.
36 */
37#ifdef DEBUG
38#define MSR_KERNEL (MSR_FP|MSR_RI)
39#else
40#define MSR_KERNEL (MSR_FP|MSR_ME|MSR_RI)
41#endif
42
Scott Wood2b36fbb2012-12-06 13:33:17 +000043#if defined(CONFIG_NAND_SPL) || \
44 (defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_INIT_MINIMAL))
45#define MINIMAL_SPL
46#endif
47
48#if !defined(CONFIG_SPL_BUILD) && !defined(CONFIG_NAND_SPL) && \
49 !defined(CONFIG_SYS_RAMBOOT)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020050#define CONFIG_SYS_FLASHBOOT
Scott Woodb71689b2008-06-30 14:13:28 -050051#endif
52
Eran Liberty9095d4a2005-07-28 10:08:46 -050053/*
54 * Set up GOT: Global Offset Table
55 *
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +010056 * Use r12 to access the GOT
Eran Liberty9095d4a2005-07-28 10:08:46 -050057 */
58 START_GOT
59 GOT_ENTRY(_GOT2_TABLE_)
Scott Woodb71689b2008-06-30 14:13:28 -050060 GOT_ENTRY(__bss_start)
Simon Glassed70c8f2013-03-14 06:54:53 +000061 GOT_ENTRY(__bss_end)
Eran Liberty9095d4a2005-07-28 10:08:46 -050062
Scott Wood2b36fbb2012-12-06 13:33:17 +000063#ifndef MINIMAL_SPL
Scott Woodb71689b2008-06-30 14:13:28 -050064 GOT_ENTRY(_FIXUP_TABLE_)
Eran Liberty9095d4a2005-07-28 10:08:46 -050065 GOT_ENTRY(_start)
66 GOT_ENTRY(_start_of_vectors)
67 GOT_ENTRY(_end_of_vectors)
68 GOT_ENTRY(transfer_to_handler)
Scott Woodb71689b2008-06-30 14:13:28 -050069#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -050070 END_GOT
71
72/*
Jerry Van Baren93eb9312006-12-06 21:23:55 -050073 * The Hard Reset Configuration Word (HRCW) table is in the first 64
74 * (0x40) bytes of flash. It has 8 bytes, but each byte is repeated 8
75 * times so the processor can fetch it out of flash whether the flash
76 * is 8, 16, 32, or 64 bits wide (hardware trickery).
Eran Liberty9095d4a2005-07-28 10:08:46 -050077 */
Eran Liberty9095d4a2005-07-28 10:08:46 -050078 .text
79#define _HRCW_TABLE_ENTRY(w) \
80 .fill 8,1,(((w)>>24)&0xff); \
81 .fill 8,1,(((w)>>16)&0xff); \
82 .fill 8,1,(((w)>> 8)&0xff); \
83 .fill 8,1,(((w) )&0xff)
84
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020085 _HRCW_TABLE_ENTRY(CONFIG_SYS_HRCW_LOW)
86 _HRCW_TABLE_ENTRY(CONFIG_SYS_HRCW_HIGH)
Eran Liberty9095d4a2005-07-28 10:08:46 -050087
Jerry Van Baren93eb9312006-12-06 21:23:55 -050088/*
89 * Magic number and version string - put it after the HRCW since it
90 * cannot be first in flash like it is in many other processors.
91 */
92 .long 0x27051956 /* U-Boot Magic Number */
93
94 .globl version_string
95version_string:
Andreas Bießmann61d01952011-07-18 20:24:04 +020096 .ascii U_BOOT_VERSION_STRING, "\0"
Jerry Van Baren93eb9312006-12-06 21:23:55 -050097
Ron Madrid787b61d2008-12-12 13:12:45 -080098 .align 2
99
100 .globl enable_addr_trans
101enable_addr_trans:
102 /* enable address translation */
103 mfmsr r5
104 ori r5, r5, (MSR_IR | MSR_DR)
105 mtmsr r5
106 isync
107 blr
108
109 .globl disable_addr_trans
110disable_addr_trans:
111 /* disable address translation */
112 mflr r4
113 mfmsr r3
114 andi. r0, r3, (MSR_IR | MSR_DR)
115 beqlr
116 andc r3, r3, r0
117 mtspr SRR0, r4
118 mtspr SRR1, r3
119 rfi
120
Ron Madrid787b61d2008-12-12 13:12:45 -0800121 .globl ppcDWstore
122ppcDWstore:
123 lfd 1, 0(r4)
124 stfd 1, 0(r3)
125 blr
126
127 .globl ppcDWload
128ppcDWload:
129 lfd 1, 0(r3)
130 stfd 1, 0(r4)
131 blr
Eran Liberty9095d4a2005-07-28 10:08:46 -0500132
Eran Liberty9095d4a2005-07-28 10:08:46 -0500133#ifndef CONFIG_DEFAULT_IMMR
134#error CONFIG_DEFAULT_IMMR must be defined
Heiko Schocher71cb3e92017-06-07 17:33:10 +0200135#endif /* CONFIG_DEFAULT_IMMR */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200136#ifndef CONFIG_SYS_IMMR
137#define CONFIG_SYS_IMMR CONFIG_DEFAULT_IMMR
138#endif /* CONFIG_SYS_IMMR */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500139
140/*
141 * After configuration, a system reset exception is executed using the
142 * vector at offset 0x100 relative to the base set by MSR[IP]. If
143 * MSR[IP] is 0, the base address is 0x00000000. If MSR[IP] is 1, the
144 * base address is 0xfff00000. In the case of a Power On Reset or Hard
145 * Reset, the value of MSR[IP] is determined by the CIP field in the
146 * HRCW.
147 *
148 * Other bits in the HRCW set up the Base Address and Port Size in BR0.
149 * This determines the location of the boot ROM (flash or EPROM) in the
150 * processor's address space at boot time. As long as the HRCW is set up
151 * so that we eventually end up executing the code below when the
152 * processor executes the reset exception, the actual values used should
153 * not matter.
154 *
155 * Once we have got here, the address mask in OR0 is cleared so that the
156 * bottom 32K of the boot ROM is effectively repeated all throughout the
157 * processor's address space, after which we can jump to the absolute
158 * address at which the boot ROM was linked at compile time, and proceed
159 * to initialise the memory controller without worrying if the rug will
160 * be pulled out from under us, so to speak (it will be fine as long as
161 * we configure BR0 with the same boot ROM link address).
162 */
163 . = EXC_OFF_SYS_RESET
164
165 .globl _start
166_start: /* time t 0 */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500167 lis r4, CONFIG_DEFAULT_IMMR@h
168 nop
Peter Tyser0c44caf2010-09-14 19:13:53 -0500169
Eran Liberty9095d4a2005-07-28 10:08:46 -0500170 mfmsr r5 /* save msr contents */
Scott Wood838450e2009-01-20 11:56:11 -0600171
172 /* 83xx manuals prescribe a specific sequence for updating IMMRBAR. */
173 bl 1f
1741: mflr r7
175
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200176 lis r3, CONFIG_SYS_IMMR@h
177 ori r3, r3, CONFIG_SYS_IMMR@l
Scott Wood838450e2009-01-20 11:56:11 -0600178
179 lwz r6, IMMRBAR(r4)
180 isync
181
Eran Liberty9095d4a2005-07-28 10:08:46 -0500182 stw r3, IMMRBAR(r4)
Scott Wood838450e2009-01-20 11:56:11 -0600183 lwz r6, 0(r7) /* Arbitrary external load */
184 isync
185
186 lwz r6, IMMRBAR(r3)
187 isync
Jon Loeligerebc72242005-08-01 13:20:47 -0500188
Eran Liberty9095d4a2005-07-28 10:08:46 -0500189 /* Initialise the E300 processor core */
190 /*------------------------------------------*/
Jon Loeligerebc72242005-08-01 13:20:47 -0500191
Scott Wood2b36fbb2012-12-06 13:33:17 +0000192#if (defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_MPC83XX_WAIT_FOR_NAND)) || \
193 defined(CONFIG_NAND_SPL)
Lepcha Suchit7ed421f2008-10-16 13:38:00 -0500194 /* The FCM begins execution after only the first page
195 * is loaded. Wait for the rest before branching
196 * to another flash page.
197 */
Scott Wood838450e2009-01-20 11:56:11 -06001981: lwz r6, 0x50b0(r3)
Lepcha Suchit7ed421f2008-10-16 13:38:00 -0500199 andi. r6, r6, 1
200 beq 1b
201#endif
202
Eran Liberty9095d4a2005-07-28 10:08:46 -0500203 bl init_e300_core
Jon Loeligerebc72242005-08-01 13:20:47 -0500204
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200205#ifdef CONFIG_SYS_FLASHBOOT
Eran Liberty9095d4a2005-07-28 10:08:46 -0500206
207 /* Inflate flash location so it appears everywhere, calculate */
208 /* the absolute address in final location of the FLASH, jump */
209 /* there and deflate the flash size back to minimal size */
210 /*------------------------------------------------------------*/
211 bl map_flash_by_law1
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200212 lis r4, (CONFIG_SYS_MONITOR_BASE)@h
213 ori r4, r4, (CONFIG_SYS_MONITOR_BASE)@l
Eran Liberty9095d4a2005-07-28 10:08:46 -0500214 addi r5, r4, in_flash - _start + EXC_OFF_SYS_RESET
215 mtlr r5
216 blr
217in_flash:
218#if 1 /* Remapping flash with LAW0. */
219 bl remap_flash_by_law0
220#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200221#endif /* CONFIG_SYS_FLASHBOOT */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500222
Kumar Galad5d94d62006-02-10 15:40:06 -0600223 /* setup the bats */
224 bl setup_bats
225 sync
226
227 /*
228 * Cache must be enabled here for stack-in-cache trick.
229 * This means we need to enable the BATS.
230 * This means:
231 * 1) for the EVB, original gt regs need to be mapped
232 * 2) need to have an IBAT for the 0xf region,
233 * we are running there!
234 * Cache should be turned on after BATs, since by default
235 * everything is write-through.
236 * The init-mem BAT can be reused after reloc. The old
237 * gt-regs BAT can be reused after board_init_f calls
238 * board_early_init_f (EVB only).
239 */
240 /* enable address translation */
241 bl enable_addr_trans
242 sync
243
Nick Spence7c20aef2008-08-28 14:09:25 -0700244 /* enable the data cache */
Kumar Galad5d94d62006-02-10 15:40:06 -0600245 bl dcache_enable
246 sync
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200247#ifdef CONFIG_SYS_INIT_RAM_LOCK
Kumar Galad5d94d62006-02-10 15:40:06 -0600248 bl lock_ram_in_cache
249 sync
250#endif
251
252 /* set up the stack pointer in our newly created
mario.six@gdsys.ccd4f4a542017-01-17 08:33:47 +0100253 * cache-ram; use r3 to keep the new SP for now to
254 * avoid overiding the SP it uselessly */
255 lis r3, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET)@h
256 ori r3, r3, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET)@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600257
mario.six@gdsys.cc85df7b42017-01-17 08:33:48 +0100258 /* r4 = end of GD area */
259 addi r4, r3, GENERATED_GBL_DATA_SIZE
260
261 /* Zero GD area */
262 li r0, 0
2631:
264 subi r4, r4, 1
265 stb r0, 0(r4)
266 cmplw r3, r4
267 bne 1b
268
Andy Yanad0ac4b2017-07-24 17:47:27 +0800269#if CONFIG_VAL(SYS_MALLOC_F_LEN)
mario.six@gdsys.cc85df7b42017-01-17 08:33:48 +0100270
Andy Yanad0ac4b2017-07-24 17:47:27 +0800271#if CONFIG_VAL(SYS_MALLOC_F_LEN) + GENERATED_GBL_DATA_SIZE > CONFIG_SYS_INIT_RAM_SIZE
272#error "SYS_MALLOC_F_LEN too large to fit into initial RAM."
mario.six@gdsys.cc85df7b42017-01-17 08:33:48 +0100273#endif
274
275 /* r3 = new stack pointer / pre-reloc malloc area */
Andy Yanad0ac4b2017-07-24 17:47:27 +0800276 subi r3, r3, CONFIG_VAL(SYS_MALLOC_F_LEN)
mario.six@gdsys.cc85df7b42017-01-17 08:33:48 +0100277
278 /* Set pointer to pre-reloc malloc area in GD */
279 stw r3, GD_MALLOC_BASE(r4)
280#endif
Kumar Galad5d94d62006-02-10 15:40:06 -0600281 li r0, 0 /* Make room for stack frame header and */
mario.six@gdsys.ccd4f4a542017-01-17 08:33:47 +0100282 stwu r0, -4(r3) /* clear final stack frame so that */
283 stwu r0, -4(r3) /* stack backtraces terminate cleanly */
Kumar Galad5d94d62006-02-10 15:40:06 -0600284
mario.six@gdsys.ccd4f4a542017-01-17 08:33:47 +0100285 /* Finally, actually set SP */
286 mr r1, r3
Eran Liberty9095d4a2005-07-28 10:08:46 -0500287
288 /* let the C-code set up the rest */
Kumar Galad5d94d62006-02-10 15:40:06 -0600289 /* */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500290 /* Be careful to keep code relocatable & stack humble */
291 /*------------------------------------------------------*/
292
293 GET_GOT /* initialize GOT access */
Joakim Tjernlundf14554d2018-11-28 10:59:55 +0100294 /* Needed for -msingle-pic-base */
295 bl _GLOBAL_OFFSET_TABLE_@local-4
296 mflr r30
Wolfgang Denkb2d36ea2011-04-20 22:11:21 +0200297
Eran Liberty9095d4a2005-07-28 10:08:46 -0500298 /* r3: IMMR */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200299 lis r3, CONFIG_SYS_IMMR@h
Eran Liberty9095d4a2005-07-28 10:08:46 -0500300 /* run low-level CPU init code (in Flash)*/
301 bl cpu_init_f
302
Eran Liberty9095d4a2005-07-28 10:08:46 -0500303 /* run 1st part of board init code (in Flash)*/
Valentin Longchampe91e10a2014-10-03 11:45:23 +0200304 li r3, 0 /* clear boot_flag for calling board_init_f */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500305 bl board_init_f
306
Peter Tyser0c44caf2010-09-14 19:13:53 -0500307 /* NOTREACHED - board_init_f() does not return */
308
Scott Wood2b36fbb2012-12-06 13:33:17 +0000309#ifndef MINIMAL_SPL
Eran Liberty9095d4a2005-07-28 10:08:46 -0500310/*
311 * Vector Table
312 */
313
314 .globl _start_of_vectors
315_start_of_vectors:
316
317/* Machine check */
318 STD_EXCEPTION(0x200, MachineCheck, MachineCheckException)
319
320/* Data Storage exception. */
321 STD_EXCEPTION(0x300, DataStorage, UnknownException)
322
323/* Instruction Storage exception. */
324 STD_EXCEPTION(0x400, InstStorage, UnknownException)
325
326/* External Interrupt exception. */
327#ifndef FIXME
328 STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
Jon Loeligerebc72242005-08-01 13:20:47 -0500329#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -0500330
331/* Alignment exception. */
332 . = 0x600
333Alignment:
Rafal Jaworowski06244e42007-06-22 14:58:04 +0200334 EXCEPTION_PROLOG(SRR0, SRR1)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500335 mfspr r4,DAR
336 stw r4,_DAR(r21)
337 mfspr r5,DSISR
338 stw r5,_DSISR(r21)
339 addi r3,r1,STACK_FRAME_OVERHEAD
Joakim Tjernlund4ff6bc02010-01-19 14:41:55 +0100340 EXC_XFER_TEMPLATE(Alignment, AlignmentException, MSR_KERNEL, COPY_EE)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500341
342/* Program check exception */
343 . = 0x700
344ProgramCheck:
Rafal Jaworowski06244e42007-06-22 14:58:04 +0200345 EXCEPTION_PROLOG(SRR0, SRR1)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500346 addi r3,r1,STACK_FRAME_OVERHEAD
Joakim Tjernlund4ff6bc02010-01-19 14:41:55 +0100347 EXC_XFER_TEMPLATE(ProgramCheck, ProgramCheckException,
348 MSR_KERNEL, COPY_EE)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500349
350 STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
351
352 /* I guess we could implement decrementer, and may have
353 * to someday for timekeeping.
354 */
355 STD_EXCEPTION(0x900, Decrementer, timer_interrupt)
356
357 STD_EXCEPTION(0xa00, Trap_0a, UnknownException)
358 STD_EXCEPTION(0xb00, Trap_0b, UnknownException)
359 STD_EXCEPTION(0xc00, SystemCall, UnknownException)
360 STD_EXCEPTION(0xd00, SingleStep, UnknownException)
361
362 STD_EXCEPTION(0xe00, Trap_0e, UnknownException)
363 STD_EXCEPTION(0xf00, Trap_0f, UnknownException)
364
365 STD_EXCEPTION(0x1000, InstructionTLBMiss, UnknownException)
366 STD_EXCEPTION(0x1100, DataLoadTLBMiss, UnknownException)
367 STD_EXCEPTION(0x1200, DataStoreTLBMiss, UnknownException)
368#ifdef DEBUG
369 . = 0x1300
370 /*
371 * This exception occurs when the program counter matches the
372 * Instruction Address Breakpoint Register (IABR).
373 *
374 * I want the cpu to halt if this occurs so I can hunt around
375 * with the debugger and look at things.
376 *
377 * When DEBUG is defined, both machine check enable (in the MSR)
378 * and checkstop reset enable (in the reset mode register) are
379 * turned off and so a checkstop condition will result in the cpu
380 * halting.
381 *
382 * I force the cpu into a checkstop condition by putting an illegal
383 * instruction here (at least this is the theory).
384 *
385 * well - that didnt work, so just do an infinite loop!
386 */
3871: b 1b
388#else
389 STD_EXCEPTION(0x1300, InstructionBreakpoint, DebugException)
390#endif
391 STD_EXCEPTION(0x1400, SMI, UnknownException)
392
393 STD_EXCEPTION(0x1500, Trap_15, UnknownException)
394 STD_EXCEPTION(0x1600, Trap_16, UnknownException)
395 STD_EXCEPTION(0x1700, Trap_17, UnknownException)
396 STD_EXCEPTION(0x1800, Trap_18, UnknownException)
397 STD_EXCEPTION(0x1900, Trap_19, UnknownException)
398 STD_EXCEPTION(0x1a00, Trap_1a, UnknownException)
399 STD_EXCEPTION(0x1b00, Trap_1b, UnknownException)
400 STD_EXCEPTION(0x1c00, Trap_1c, UnknownException)
401 STD_EXCEPTION(0x1d00, Trap_1d, UnknownException)
402 STD_EXCEPTION(0x1e00, Trap_1e, UnknownException)
403 STD_EXCEPTION(0x1f00, Trap_1f, UnknownException)
404 STD_EXCEPTION(0x2000, Trap_20, UnknownException)
405 STD_EXCEPTION(0x2100, Trap_21, UnknownException)
406 STD_EXCEPTION(0x2200, Trap_22, UnknownException)
407 STD_EXCEPTION(0x2300, Trap_23, UnknownException)
408 STD_EXCEPTION(0x2400, Trap_24, UnknownException)
409 STD_EXCEPTION(0x2500, Trap_25, UnknownException)
410 STD_EXCEPTION(0x2600, Trap_26, UnknownException)
411 STD_EXCEPTION(0x2700, Trap_27, UnknownException)
412 STD_EXCEPTION(0x2800, Trap_28, UnknownException)
413 STD_EXCEPTION(0x2900, Trap_29, UnknownException)
414 STD_EXCEPTION(0x2a00, Trap_2a, UnknownException)
415 STD_EXCEPTION(0x2b00, Trap_2b, UnknownException)
416 STD_EXCEPTION(0x2c00, Trap_2c, UnknownException)
417 STD_EXCEPTION(0x2d00, Trap_2d, UnknownException)
418 STD_EXCEPTION(0x2e00, Trap_2e, UnknownException)
419 STD_EXCEPTION(0x2f00, Trap_2f, UnknownException)
420
421
422 .globl _end_of_vectors
423_end_of_vectors:
424
425 . = 0x3000
426
427/*
428 * This code finishes saving the registers to the exception frame
429 * and jumps to the appropriate handler for the exception.
430 * Register r21 is pointer into trap frame, r1 has new stack pointer.
431 */
432 .globl transfer_to_handler
433transfer_to_handler:
434 stw r22,_NIP(r21)
435 lis r22,MSR_POW@h
436 andc r23,r23,r22
437 stw r23,_MSR(r21)
438 SAVE_GPR(7, r21)
439 SAVE_4GPRS(8, r21)
440 SAVE_8GPRS(12, r21)
441 SAVE_8GPRS(24, r21)
442 mflr r23
443 andi. r24,r23,0x3f00 /* get vector offset */
444 stw r24,TRAP(r21)
445 li r22,0
446 stw r22,RESULT(r21)
447 lwz r24,0(r23) /* virtual address of handler */
448 lwz r23,4(r23) /* where to go when done */
449 mtspr SRR0,r24
450 mtspr SRR1,r20
451 mtlr r23
452 SYNC
453 rfi /* jump to handler, enable MMU */
454
455int_return:
456 mfmsr r28 /* Disable interrupts */
457 li r4,0
458 ori r4,r4,MSR_EE
459 andc r28,r28,r4
460 SYNC /* Some chip revs need this... */
461 mtmsr r28
462 SYNC
463 lwz r2,_CTR(r1)
464 lwz r0,_LINK(r1)
465 mtctr r2
466 mtlr r0
467 lwz r2,_XER(r1)
468 lwz r0,_CCR(r1)
469 mtspr XER,r2
470 mtcrf 0xFF,r0
471 REST_10GPRS(3, r1)
472 REST_10GPRS(13, r1)
473 REST_8GPRS(23, r1)
474 REST_GPR(31, r1)
475 lwz r2,_NIP(r1) /* Restore environment */
476 lwz r0,_MSR(r1)
477 mtspr SRR0,r2
478 mtspr SRR1,r0
479 lwz r0,GPR0(r1)
480 lwz r2,GPR2(r1)
481 lwz r1,GPR1(r1)
482 SYNC
483 rfi
Scott Wood2b36fbb2012-12-06 13:33:17 +0000484#endif /* !MINIMAL_SPL */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500485
486/*
487 * This code initialises the E300 processor core
488 * (conforms to PowerPC 603e spec)
489 * Note: expects original MSR contents to be in r5.
490 */
491 .globl init_e300_core
492init_e300_core: /* time t 10 */
493 /* Initialize machine status; enable machine check interrupt */
494 /*-----------------------------------------------------------*/
495
496 li r3, MSR_KERNEL /* Set ME and RI flags */
497 rlwimi r3, r5, 0, 25, 25 /* preserve IP bit set by HRCW */
498#ifdef DEBUG
499 rlwimi r3, r5, 0, 21, 22 /* debugger might set SE & BE bits */
500#endif
501 SYNC /* Some chip revs need this... */
502 mtmsr r3
503 SYNC
504 mtspr SRR1, r3 /* Make SRR1 match MSR */
505
506
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200507 lis r3, CONFIG_SYS_IMMR@h
Eran Liberty9095d4a2005-07-28 10:08:46 -0500508#if defined(CONFIG_WATCHDOG)
Horst Kronstorfer4565e042010-05-18 10:37:05 +0200509 /* Initialise the Watchdog values and reset it (if req) */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500510 /*------------------------------------------------------*/
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200511 lis r4, CONFIG_SYS_WATCHDOG_VALUE
Eran Liberty9095d4a2005-07-28 10:08:46 -0500512 ori r4, r4, (SWCRR_SWEN | SWCRR_SWRI | SWCRR_SWPR)
513 stw r4, SWCRR(r3)
Jon Loeligerebc72242005-08-01 13:20:47 -0500514
Eran Liberty9095d4a2005-07-28 10:08:46 -0500515 /* and reset it */
Jon Loeligerebc72242005-08-01 13:20:47 -0500516
Eran Liberty9095d4a2005-07-28 10:08:46 -0500517 li r4, 0x556C
518 sth r4, SWSRR@l(r3)
Heiko Schocher6dfb2e52008-01-11 15:15:17 +0100519 li r4, -0x55C7
Eran Liberty9095d4a2005-07-28 10:08:46 -0500520 sth r4, SWSRR@l(r3)
521#else
Horst Kronstorfer4565e042010-05-18 10:37:05 +0200522 /* Disable Watchdog */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500523 /*-------------------*/
Kumar Galab42751c2006-01-11 11:23:01 -0600524 lwz r4, SWCRR(r3)
525 /* Check to see if its enabled for disabling
526 once disabled by SW you can't re-enable */
527 andi. r4, r4, 0x4
528 beq 1f
Eran Liberty9095d4a2005-07-28 10:08:46 -0500529 xor r4, r4, r4
530 stw r4, SWCRR(r3)
Kumar Galab42751c2006-01-11 11:23:01 -06005311:
Eran Liberty9095d4a2005-07-28 10:08:46 -0500532#endif /* CONFIG_WATCHDOG */
533
Nick Spence56fd3c22008-08-28 14:09:19 -0700534#if defined(CONFIG_MASK_AER_AO)
535 /* Write the Arbiter Event Enable to mask Address Only traps. */
536 /* This prevents the dcbz instruction from being trapped when */
537 /* HID0_ABE Address Broadcast Enable is set and the MEMORY */
538 /* COHERENCY bit is set in the WIMG bits, which is often */
539 /* needed for PCI operation. */
540 lwz r4, 0x0808(r3)
541 rlwinm r0, r4, 0, ~AER_AO
542 stw r0, 0x0808(r3)
543#endif /* CONFIG_MASK_AER_AO */
544
Eran Liberty9095d4a2005-07-28 10:08:46 -0500545 /* Initialize the Hardware Implementation-dependent Registers */
546 /* HID0 also contains cache control */
Nick Spence7c20aef2008-08-28 14:09:25 -0700547 /* - force invalidation of data and instruction caches */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500548 /*------------------------------------------------------*/
549
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200550 lis r3, CONFIG_SYS_HID0_INIT@h
551 ori r3, r3, (CONFIG_SYS_HID0_INIT | HID0_ICFI | HID0_DCFI)@l
Eran Liberty9095d4a2005-07-28 10:08:46 -0500552 SYNC
553 mtspr HID0, r3
554
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200555 lis r3, CONFIG_SYS_HID0_FINAL@h
556 ori r3, r3, (CONFIG_SYS_HID0_FINAL & ~(HID0_ICFI | HID0_DCFI))@l
Eran Liberty9095d4a2005-07-28 10:08:46 -0500557 SYNC
558 mtspr HID0, r3
559
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200560 lis r3, CONFIG_SYS_HID2@h
561 ori r3, r3, CONFIG_SYS_HID2@l
Eran Liberty9095d4a2005-07-28 10:08:46 -0500562 SYNC
563 mtspr HID2, r3
564
Eran Liberty9095d4a2005-07-28 10:08:46 -0500565 /* Done! */
566 /*------------------------------*/
Jon Loeligerebc72242005-08-01 13:20:47 -0500567 blr
Eran Liberty9095d4a2005-07-28 10:08:46 -0500568
Kumar Galad5d94d62006-02-10 15:40:06 -0600569 /* setup_bats - set them up to some initial state */
570 .globl setup_bats
571setup_bats:
572 addis r0, r0, 0x0000
573
574 /* IBAT 0 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200575 addis r4, r0, CONFIG_SYS_IBAT0L@h
576 ori r4, r4, CONFIG_SYS_IBAT0L@l
577 addis r3, r0, CONFIG_SYS_IBAT0U@h
578 ori r3, r3, CONFIG_SYS_IBAT0U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600579 mtspr IBAT0L, r4
580 mtspr IBAT0U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600581
582 /* DBAT 0 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200583 addis r4, r0, CONFIG_SYS_DBAT0L@h
584 ori r4, r4, CONFIG_SYS_DBAT0L@l
585 addis r3, r0, CONFIG_SYS_DBAT0U@h
586 ori r3, r3, CONFIG_SYS_DBAT0U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600587 mtspr DBAT0L, r4
588 mtspr DBAT0U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600589
590 /* IBAT 1 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200591 addis r4, r0, CONFIG_SYS_IBAT1L@h
592 ori r4, r4, CONFIG_SYS_IBAT1L@l
593 addis r3, r0, CONFIG_SYS_IBAT1U@h
594 ori r3, r3, CONFIG_SYS_IBAT1U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600595 mtspr IBAT1L, r4
596 mtspr IBAT1U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600597
598 /* DBAT 1 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200599 addis r4, r0, CONFIG_SYS_DBAT1L@h
600 ori r4, r4, CONFIG_SYS_DBAT1L@l
601 addis r3, r0, CONFIG_SYS_DBAT1U@h
602 ori r3, r3, CONFIG_SYS_DBAT1U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600603 mtspr DBAT1L, r4
604 mtspr DBAT1U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600605
606 /* IBAT 2 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200607 addis r4, r0, CONFIG_SYS_IBAT2L@h
608 ori r4, r4, CONFIG_SYS_IBAT2L@l
609 addis r3, r0, CONFIG_SYS_IBAT2U@h
610 ori r3, r3, CONFIG_SYS_IBAT2U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600611 mtspr IBAT2L, r4
612 mtspr IBAT2U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600613
614 /* DBAT 2 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200615 addis r4, r0, CONFIG_SYS_DBAT2L@h
616 ori r4, r4, CONFIG_SYS_DBAT2L@l
617 addis r3, r0, CONFIG_SYS_DBAT2U@h
618 ori r3, r3, CONFIG_SYS_DBAT2U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600619 mtspr DBAT2L, r4
620 mtspr DBAT2U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600621
622 /* IBAT 3 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200623 addis r4, r0, CONFIG_SYS_IBAT3L@h
624 ori r4, r4, CONFIG_SYS_IBAT3L@l
625 addis r3, r0, CONFIG_SYS_IBAT3U@h
626 ori r3, r3, CONFIG_SYS_IBAT3U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600627 mtspr IBAT3L, r4
628 mtspr IBAT3U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600629
630 /* DBAT 3 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200631 addis r4, r0, CONFIG_SYS_DBAT3L@h
632 ori r4, r4, CONFIG_SYS_DBAT3L@l
633 addis r3, r0, CONFIG_SYS_DBAT3U@h
634 ori r3, r3, CONFIG_SYS_DBAT3U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600635 mtspr DBAT3L, r4
636 mtspr DBAT3U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600637
Becky Bruce03ea1be2008-05-08 19:02:12 -0500638#ifdef CONFIG_HIGH_BATS
Kumar Galad5d94d62006-02-10 15:40:06 -0600639 /* IBAT 4 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200640 addis r4, r0, CONFIG_SYS_IBAT4L@h
641 ori r4, r4, CONFIG_SYS_IBAT4L@l
642 addis r3, r0, CONFIG_SYS_IBAT4U@h
643 ori r3, r3, CONFIG_SYS_IBAT4U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600644 mtspr IBAT4L, r4
645 mtspr IBAT4U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600646
647 /* DBAT 4 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200648 addis r4, r0, CONFIG_SYS_DBAT4L@h
649 ori r4, r4, CONFIG_SYS_DBAT4L@l
650 addis r3, r0, CONFIG_SYS_DBAT4U@h
651 ori r3, r3, CONFIG_SYS_DBAT4U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600652 mtspr DBAT4L, r4
653 mtspr DBAT4U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600654
655 /* IBAT 5 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200656 addis r4, r0, CONFIG_SYS_IBAT5L@h
657 ori r4, r4, CONFIG_SYS_IBAT5L@l
658 addis r3, r0, CONFIG_SYS_IBAT5U@h
659 ori r3, r3, CONFIG_SYS_IBAT5U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600660 mtspr IBAT5L, r4
661 mtspr IBAT5U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600662
663 /* DBAT 5 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200664 addis r4, r0, CONFIG_SYS_DBAT5L@h
665 ori r4, r4, CONFIG_SYS_DBAT5L@l
666 addis r3, r0, CONFIG_SYS_DBAT5U@h
667 ori r3, r3, CONFIG_SYS_DBAT5U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600668 mtspr DBAT5L, r4
669 mtspr DBAT5U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600670
671 /* IBAT 6 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200672 addis r4, r0, CONFIG_SYS_IBAT6L@h
673 ori r4, r4, CONFIG_SYS_IBAT6L@l
674 addis r3, r0, CONFIG_SYS_IBAT6U@h
675 ori r3, r3, CONFIG_SYS_IBAT6U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600676 mtspr IBAT6L, r4
677 mtspr IBAT6U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600678
679 /* DBAT 6 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200680 addis r4, r0, CONFIG_SYS_DBAT6L@h
681 ori r4, r4, CONFIG_SYS_DBAT6L@l
682 addis r3, r0, CONFIG_SYS_DBAT6U@h
683 ori r3, r3, CONFIG_SYS_DBAT6U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600684 mtspr DBAT6L, r4
685 mtspr DBAT6U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600686
687 /* IBAT 7 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200688 addis r4, r0, CONFIG_SYS_IBAT7L@h
689 ori r4, r4, CONFIG_SYS_IBAT7L@l
690 addis r3, r0, CONFIG_SYS_IBAT7U@h
691 ori r3, r3, CONFIG_SYS_IBAT7U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600692 mtspr IBAT7L, r4
693 mtspr IBAT7U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600694
695 /* DBAT 7 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200696 addis r4, r0, CONFIG_SYS_DBAT7L@h
697 ori r4, r4, CONFIG_SYS_DBAT7L@l
698 addis r3, r0, CONFIG_SYS_DBAT7U@h
699 ori r3, r3, CONFIG_SYS_DBAT7U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600700 mtspr DBAT7L, r4
701 mtspr DBAT7U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600702#endif
703
Scott Woodb71689b2008-06-30 14:13:28 -0500704 isync
705
706 /* invalidate all tlb's
707 *
708 * From the 603e User Manual: "The 603e provides the ability to
709 * invalidate a TLB entry. The TLB Invalidate Entry (tlbie)
710 * instruction invalidates the TLB entry indexed by the EA, and
711 * operates on both the instruction and data TLBs simultaneously
712 * invalidating four TLB entries (both sets in each TLB). The
713 * index corresponds to bits 15-19 of the EA. To invalidate all
714 * entries within both TLBs, 32 tlbie instructions should be
715 * issued, incrementing this field by one each time."
716 *
717 * "Note that the tlbia instruction is not implemented on the
718 * 603e."
719 *
720 * bits 15-19 correspond to addresses 0x00000000 to 0x0001F000
721 * incrementing by 0x1000 each time. The code below is sort of
Stefan Roese88fbf932010-04-15 16:07:28 +0200722 * based on code in "flush_tlbs" from arch/powerpc/kernel/head.S
Scott Woodb71689b2008-06-30 14:13:28 -0500723 *
Kumar Galad5d94d62006-02-10 15:40:06 -0600724 */
725 lis r3, 0
726 lis r5, 2
727
7281:
729 tlbie r3
730 addi r3, r3, 0x1000
731 cmp 0, 0, r3, r5
732 blt 1b
733
734 blr
735
Eran Liberty9095d4a2005-07-28 10:08:46 -0500736/* Cache functions.
737 *
738 * Note: requires that all cache bits in
739 * HID0 are in the low half word.
740 */
Scott Wood2b36fbb2012-12-06 13:33:17 +0000741#ifndef MINIMAL_SPL
Eran Liberty9095d4a2005-07-28 10:08:46 -0500742 .globl icache_enable
743icache_enable:
744 mfspr r3, HID0
745 ori r3, r3, HID0_ICE
Nick Spence7c20aef2008-08-28 14:09:25 -0700746 li r4, HID0_ICFI|HID0_ILOCK
Eran Liberty9095d4a2005-07-28 10:08:46 -0500747 andc r3, r3, r4
748 ori r4, r3, HID0_ICFI
749 isync
750 mtspr HID0, r4 /* sets enable and invalidate, clears lock */
751 isync
752 mtspr HID0, r3 /* clears invalidate */
753 blr
754
755 .globl icache_disable
756icache_disable:
757 mfspr r3, HID0
758 lis r4, 0
Nick Spence7c20aef2008-08-28 14:09:25 -0700759 ori r4, r4, HID0_ICE|HID0_ICFI|HID0_ILOCK
Eran Liberty9095d4a2005-07-28 10:08:46 -0500760 andc r3, r3, r4
Eran Liberty9095d4a2005-07-28 10:08:46 -0500761 isync
Nick Spence7c20aef2008-08-28 14:09:25 -0700762 mtspr HID0, r3 /* clears invalidate, enable and lock */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500763 blr
764
765 .globl icache_status
766icache_status:
767 mfspr r3, HID0
Marian Balakowicz758e5d32006-03-14 16:01:25 +0100768 rlwinm r3, r3, (31 - HID0_ICE_SHIFT + 1), 31, 31
Eran Liberty9095d4a2005-07-28 10:08:46 -0500769 blr
Scott Wood2b36fbb2012-12-06 13:33:17 +0000770#endif /* !MINIMAL_SPL */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500771
772 .globl dcache_enable
773dcache_enable:
774 mfspr r3, HID0
Kumar Galad5d94d62006-02-10 15:40:06 -0600775 li r5, HID0_DCFI|HID0_DLOCK
776 andc r3, r3, r5
Kumar Galad5d94d62006-02-10 15:40:06 -0600777 ori r3, r3, HID0_DCE
Eran Liberty9095d4a2005-07-28 10:08:46 -0500778 sync
Nick Spence7c20aef2008-08-28 14:09:25 -0700779 mtspr HID0, r3 /* enable, no invalidate */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500780 blr
781
782 .globl dcache_disable
783dcache_disable:
Nick Spence7c20aef2008-08-28 14:09:25 -0700784 mflr r4
785 bl flush_dcache /* uses r3 and r5 */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500786 mfspr r3, HID0
Nick Spence7c20aef2008-08-28 14:09:25 -0700787 li r5, HID0_DCE|HID0_DLOCK
788 andc r3, r3, r5
789 ori r5, r3, HID0_DCFI
Eran Liberty9095d4a2005-07-28 10:08:46 -0500790 sync
Nick Spence7c20aef2008-08-28 14:09:25 -0700791 mtspr HID0, r5 /* sets invalidate, clears enable and lock */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500792 sync
793 mtspr HID0, r3 /* clears invalidate */
Nick Spence7c20aef2008-08-28 14:09:25 -0700794 mtlr r4
Eran Liberty9095d4a2005-07-28 10:08:46 -0500795 blr
796
797 .globl dcache_status
798dcache_status:
799 mfspr r3, HID0
Marian Balakowicz758e5d32006-03-14 16:01:25 +0100800 rlwinm r3, r3, (31 - HID0_DCE_SHIFT + 1), 31, 31
Eran Liberty9095d4a2005-07-28 10:08:46 -0500801 blr
802
Nick Spence7c20aef2008-08-28 14:09:25 -0700803 .globl flush_dcache
804flush_dcache:
805 lis r3, 0
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200806 lis r5, CONFIG_SYS_CACHELINE_SIZE
Nick Spence7c20aef2008-08-28 14:09:25 -07008071: cmp 0, 1, r3, r5
808 bge 2f
809 lwz r5, 0(r3)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200810 lis r5, CONFIG_SYS_CACHELINE_SIZE
Nick Spence7c20aef2008-08-28 14:09:25 -0700811 addi r3, r3, 0x4
812 b 1b
8132: blr
814
Eran Liberty9095d4a2005-07-28 10:08:46 -0500815/*-------------------------------------------------------------------*/
816
817/*
818 * void relocate_code (addr_sp, gd, addr_moni)
819 *
820 * This "function" does not return, instead it continues in RAM
821 * after relocating the monitor code.
822 *
823 * r3 = dest
824 * r4 = src
825 * r5 = length in bytes
826 * r6 = cachelinesize
827 */
828 .globl relocate_code
829relocate_code:
830 mr r1, r3 /* Set new stack pointer */
831 mr r9, r4 /* Save copy of Global Data pointer */
832 mr r10, r5 /* Save copy of Destination Address */
833
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +0100834 GET_GOT
Eran Liberty9095d4a2005-07-28 10:08:46 -0500835 mr r3, r5 /* Destination Address */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200836 lis r4, CONFIG_SYS_MONITOR_BASE@h /* Source Address */
837 ori r4, r4, CONFIG_SYS_MONITOR_BASE@l
Scott Woodb71689b2008-06-30 14:13:28 -0500838 lwz r5, GOT(__bss_start)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500839 sub r5, r5, r4
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200840 li r6, CONFIG_SYS_CACHELINE_SIZE /* Cache Line Size */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500841
842 /*
843 * Fix GOT pointer:
844 *
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200845 * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500846 * + Destination Address
847 *
848 * Offset:
849 */
850 sub r15, r10, r4
851
852 /* First our own GOT */
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +0100853 add r12, r12, r15
Eran Liberty9095d4a2005-07-28 10:08:46 -0500854 /* then the one used by the C code */
855 add r30, r30, r15
856
857 /*
858 * Now relocate code
859 */
860
861 cmplw cr1,r3,r4
862 addi r0,r5,3
863 srwi. r0,r0,2
864 beq cr1,4f /* In place copy is not necessary */
865 beq 7f /* Protect against 0 count */
866 mtctr r0
867 bge cr1,2f
868 la r8,-4(r4)
869 la r7,-4(r3)
870
871 /* copy */
8721: lwzu r0,4(r8)
873 stwu r0,4(r7)
874 bdnz 1b
875
876 addi r0,r5,3
877 srwi. r0,r0,2
878 mtctr r0
879 la r8,-4(r4)
880 la r7,-4(r3)
Jon Loeligerebc72242005-08-01 13:20:47 -0500881
882 /* and compare */
Eran Liberty9095d4a2005-07-28 10:08:46 -050088320: lwzu r20,4(r8)
884 lwzu r21,4(r7)
885 xor. r22, r20, r21
886 bne 30f
887 bdnz 20b
888 b 4f
889
890 /* compare failed */
89130: li r3, 0
892 blr
893
8942: slwi r0,r0,2 /* re copy in reverse order ... y do we needed it? */
895 add r8,r4,r0
896 add r7,r3,r0
8973: lwzu r0,-4(r8)
898 stwu r0,-4(r7)
899 bdnz 3b
Eran Liberty9095d4a2005-07-28 10:08:46 -0500900
901/*
902 * Now flush the cache: note that we must start from a cache aligned
903 * address. Otherwise we might miss one cache line.
904 */
Kumar Galad5d94d62006-02-10 15:40:06 -06009054: cmpwi r6,0
Eran Liberty9095d4a2005-07-28 10:08:46 -0500906 add r5,r3,r5
Kumar Galad5d94d62006-02-10 15:40:06 -0600907 beq 7f /* Always flush prefetch queue in any case */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500908 subi r0,r6,1
909 andc r3,r3,r0
Eran Liberty9095d4a2005-07-28 10:08:46 -0500910 mr r4,r3
9115: dcbst 0,r4
912 add r4,r4,r6
913 cmplw r4,r5
914 blt 5b
Kumar Galad5d94d62006-02-10 15:40:06 -0600915 sync /* Wait for all dcbst to complete on bus */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500916 mr r4,r3
9176: icbi 0,r4
918 add r4,r4,r6
919 cmplw r4,r5
920 blt 6b
Kumar Galad5d94d62006-02-10 15:40:06 -06009217: sync /* Wait for all icbi to complete on bus */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500922 isync
923
924/*
925 * We are done. Do not return, instead branch to second part of board
926 * initialization, now running from RAM.
927 */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500928 addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
929 mtlr r0
930 blr
931
932in_ram:
933
934 /*
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +0100935 * Relocation Function, r12 point to got2+0x8000
Eran Liberty9095d4a2005-07-28 10:08:46 -0500936 *
937 * Adjust got2 pointers, no need to check for 0, this code
938 * already puts a few entries in the table.
939 */
940 li r0,__got2_entries@sectoff@l
941 la r3,GOT(_GOT2_TABLE_)
942 lwz r11,GOT(_GOT2_TABLE_)
943 mtctr r0
944 sub r11,r3,r11
945 addi r3,r3,-4
9461: lwzu r0,4(r3)
Joakim Tjernlund4f2fdac2009-10-08 02:03:51 +0200947 cmpwi r0,0
948 beq- 2f
Eran Liberty9095d4a2005-07-28 10:08:46 -0500949 add r0,r0,r11
950 stw r0,0(r3)
Joakim Tjernlund4f2fdac2009-10-08 02:03:51 +02009512: bdnz 1b
Eran Liberty9095d4a2005-07-28 10:08:46 -0500952
Scott Wood2b36fbb2012-12-06 13:33:17 +0000953#ifndef MINIMAL_SPL
Eran Liberty9095d4a2005-07-28 10:08:46 -0500954 /*
955 * Now adjust the fixups and the pointers to the fixups
956 * in case we need to move ourselves again.
957 */
Joakim Tjernlund4f2fdac2009-10-08 02:03:51 +0200958 li r0,__fixup_entries@sectoff@l
Eran Liberty9095d4a2005-07-28 10:08:46 -0500959 lwz r3,GOT(_FIXUP_TABLE_)
960 cmpwi r0,0
961 mtctr r0
962 addi r3,r3,-4
963 beq 4f
9643: lwzu r4,4(r3)
965 lwzux r0,r4,r11
Joakim Tjernlundc61b25a2010-10-14 11:51:44 +0200966 cmpwi r0,0
Eran Liberty9095d4a2005-07-28 10:08:46 -0500967 add r0,r0,r11
Joakim Tjernlund401b5922010-11-04 19:02:00 +0100968 stw r4,0(r3)
Joakim Tjernlundc61b25a2010-10-14 11:51:44 +0200969 beq- 5f
Eran Liberty9095d4a2005-07-28 10:08:46 -0500970 stw r0,0(r4)
Joakim Tjernlundc61b25a2010-10-14 11:51:44 +02009715: bdnz 3b
Eran Liberty9095d4a2005-07-28 10:08:46 -05009724:
Scott Woodb71689b2008-06-30 14:13:28 -0500973#endif
974
Eran Liberty9095d4a2005-07-28 10:08:46 -0500975clear_bss:
976 /*
977 * Now clear BSS segment
978 */
979 lwz r3,GOT(__bss_start)
Simon Glassed70c8f2013-03-14 06:54:53 +0000980 lwz r4,GOT(__bss_end)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500981
982 cmplw 0, r3, r4
983 beq 6f
984
985 li r0, 0
9865:
987 stw r0, 0(r3)
988 addi r3, r3, 4
989 cmplw 0, r3, r4
990 bne 5b
9916:
992
993 mr r3, r9 /* Global Data pointer */
994 mr r4, r10 /* Destination Address */
995 bl board_init_r
996
Scott Wood2b36fbb2012-12-06 13:33:17 +0000997#ifndef MINIMAL_SPL
Eran Liberty9095d4a2005-07-28 10:08:46 -0500998 /*
999 * Copy exception vector code to low memory
1000 *
1001 * r3: dest_addr
1002 * r7: source address, r8: end address, r9: target address
1003 */
1004 .globl trap_init
1005trap_init:
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +01001006 mflr r4 /* save link register */
1007 GET_GOT
Eran Liberty9095d4a2005-07-28 10:08:46 -05001008 lwz r7, GOT(_start)
1009 lwz r8, GOT(_end_of_vectors)
1010
1011 li r9, 0x100 /* reset vector always at 0x100 */
1012
1013 cmplw 0, r7, r8
1014 bgelr /* return if r7>=r8 - just in case */
Eran Liberty9095d4a2005-07-28 10:08:46 -050010151:
1016 lwz r0, 0(r7)
1017 stw r0, 0(r9)
1018 addi r7, r7, 4
1019 addi r9, r9, 4
1020 cmplw 0, r7, r8
1021 bne 1b
1022
1023 /*
1024 * relocate `hdlr' and `int_return' entries
1025 */
1026 li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
1027 li r8, Alignment - _start + EXC_OFF_SYS_RESET
10282:
1029 bl trap_reloc
1030 addi r7, r7, 0x100 /* next exception vector */
1031 cmplw 0, r7, r8
1032 blt 2b
1033
1034 li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
1035 bl trap_reloc
1036
1037 li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
1038 bl trap_reloc
1039
1040 li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
1041 li r8, SystemCall - _start + EXC_OFF_SYS_RESET
10423:
1043 bl trap_reloc
1044 addi r7, r7, 0x100 /* next exception vector */
1045 cmplw 0, r7, r8
1046 blt 3b
1047
1048 li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
1049 li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
10504:
1051 bl trap_reloc
1052 addi r7, r7, 0x100 /* next exception vector */
1053 cmplw 0, r7, r8
1054 blt 4b
1055
1056 mfmsr r3 /* now that the vectors have */
1057 lis r7, MSR_IP@h /* relocated into low memory */
1058 ori r7, r7, MSR_IP@l /* MSR[IP] can be turned off */
1059 andc r3, r3, r7 /* (if it was on) */
1060 SYNC /* Some chip revs need this... */
1061 mtmsr r3
1062 SYNC
1063
1064 mtlr r4 /* restore link register */
1065 blr
1066
Scott Wood2b36fbb2012-12-06 13:33:17 +00001067#endif /* !MINIMAL_SPL */
Eran Liberty9095d4a2005-07-28 10:08:46 -05001068
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001069#ifdef CONFIG_SYS_INIT_RAM_LOCK
Kumar Galad5d94d62006-02-10 15:40:06 -06001070lock_ram_in_cache:
1071 /* Allocate Initial RAM in data cache.
1072 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001073 lis r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@h
1074 ori r3, r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@l
Wolfgang Denk1c2e98e2010-10-26 13:32:32 +02001075 li r4, ((CONFIG_SYS_INIT_RAM_SIZE & ~31) + \
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001076 (CONFIG_SYS_INIT_RAM_ADDR & 31) + 31) / 32
Nick Spenceb89d6fb2008-08-28 14:09:11 -07001077 mtctr r4
Kumar Galad5d94d62006-02-10 15:40:06 -060010781:
1079 dcbz r0, r3
1080 addi r3, r3, 32
1081 bdnz 1b
1082
1083 /* Lock the data cache */
1084 mfspr r0, HID0
Nick Spence7c20aef2008-08-28 14:09:25 -07001085 ori r0, r0, HID0_DLOCK
Kumar Galad5d94d62006-02-10 15:40:06 -06001086 sync
1087 mtspr HID0, r0
1088 sync
1089 blr
1090
Scott Wood2b36fbb2012-12-06 13:33:17 +00001091#ifndef MINIMAL_SPL
Eran Liberty9095d4a2005-07-28 10:08:46 -05001092.globl unlock_ram_in_cache
1093unlock_ram_in_cache:
1094 /* invalidate the INIT_RAM section */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001095 lis r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@h
1096 ori r3, r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@l
Wolfgang Denk1c2e98e2010-10-26 13:32:32 +02001097 li r4, ((CONFIG_SYS_INIT_RAM_SIZE & ~31) + \
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001098 (CONFIG_SYS_INIT_RAM_ADDR & 31) + 31) / 32
Nick Spenceb89d6fb2008-08-28 14:09:11 -07001099 mtctr r4
Eran Liberty9095d4a2005-07-28 10:08:46 -050011001: icbi r0, r3
1101 dcbi r0, r3
1102 addi r3, r3, 32
1103 bdnz 1b
1104 sync /* Wait for all icbi to complete on bus */
1105 isync
Kumar Galad5d94d62006-02-10 15:40:06 -06001106
1107 /* Unlock the data cache and invalidate it */
1108 mfspr r3, HID0
1109 li r5, HID0_DLOCK|HID0_DCFI
1110 andc r3, r3, r5 /* no invalidate, unlock */
1111 ori r5, r3, HID0_DCFI /* invalidate, unlock */
Nick Spence7c20aef2008-08-28 14:09:25 -07001112 sync
Kumar Galad5d94d62006-02-10 15:40:06 -06001113 mtspr HID0, r5 /* invalidate, unlock */
Kumar Galad5d94d62006-02-10 15:40:06 -06001114 sync
Nick Spence7c20aef2008-08-28 14:09:25 -07001115 mtspr HID0, r3 /* no invalidate, unlock */
Eran Liberty9095d4a2005-07-28 10:08:46 -05001116 blr
Scott Wood2b36fbb2012-12-06 13:33:17 +00001117#endif /* !MINIMAL_SPL */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001118#endif /* CONFIG_SYS_INIT_RAM_LOCK */
Eran Liberty9095d4a2005-07-28 10:08:46 -05001119
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001120#ifdef CONFIG_SYS_FLASHBOOT
Eran Liberty9095d4a2005-07-28 10:08:46 -05001121map_flash_by_law1:
1122 /* When booting from ROM (Flash or EPROM), clear the */
1123 /* Address Mask in OR0 so ROM appears everywhere */
1124 /*----------------------------------------------------*/
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001125 lis r3, (CONFIG_SYS_IMMR)@h /* r3 <= CONFIG_SYS_IMMR */
Jon Loeligerebc72242005-08-01 13:20:47 -05001126 lwz r4, OR0@l(r3)
Eran Liberty9095d4a2005-07-28 10:08:46 -05001127 li r5, 0x7fff /* r5 <= 0x00007FFFF */
Jon Loeligerebc72242005-08-01 13:20:47 -05001128 and r4, r4, r5
Eran Liberty9095d4a2005-07-28 10:08:46 -05001129 stw r4, OR0@l(r3) /* OR0 <= OR0 & 0x00007FFFF */
1130
1131 /* As MPC8349E User's Manual presented, when RCW[BMS] is set to 0,
1132 * system will boot from 0x0000_0100, and the LBLAWBAR0[BASE_ADDR]
1133 * reset value is 0x00000; when RCW[BMS] is set to 1, system will boot
1134 * from 0xFFF0_0100, and the LBLAWBAR0[BASE_ADDR] reset value is
1135 * 0xFF800. From the hard resetting to here, the processor fetched and
1136 * executed the instructions one by one. There is not absolutely
1137 * jumping happened. Laterly, the u-boot code has to do an absolutely
1138 * jumping to tell the CPU instruction fetching component what the
1139 * u-boot TEXT base address is. Because the TEXT base resides in the
1140 * boot ROM memory space, to garantee the code can run smoothly after
1141 * that jumping, we must map in the entire boot ROM by Local Access
1142 * Window. Sometimes, we desire an non-0x00000 or non-0xFF800 starting
1143 * address for boot ROM, such as 0xFE000000. In this case, the default
1144 * LBIU Local Access Widow 0 will not cover this memory space. So, we
1145 * need another window to map in it.
1146 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001147 lis r4, (CONFIG_SYS_FLASH_BASE)@h
1148 ori r4, r4, (CONFIG_SYS_FLASH_BASE)@l
1149 stw r4, LBLAWBAR1(r3) /* LBLAWBAR1 <= CONFIG_SYS_FLASH_BASE */
Timur Tabi53b46172006-08-22 17:07:00 -05001150
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001151 /* Store 0x80000012 + log2(CONFIG_SYS_FLASH_SIZE) into LBLAWAR1 */
Timur Tabi53b46172006-08-22 17:07:00 -05001152 lis r4, (0x80000012)@h
1153 ori r4, r4, (0x80000012)@l
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001154 li r5, CONFIG_SYS_FLASH_SIZE
Timur Tabi53b46172006-08-22 17:07:00 -050011551: srawi. r5, r5, 1 /* r5 = r5 >> 1 */
1156 addi r4, r4, 1
1157 bne 1b
1158
Eran Liberty9095d4a2005-07-28 10:08:46 -05001159 stw r4, LBLAWAR1(r3) /* LBLAWAR1 <= 8MB Flash Size */
Joakim Tjernlundb168d632010-11-19 14:15:33 +01001160 /* Wait for HW to catch up */
1161 lwz r4, LBLAWAR1(r3)
1162 twi 0,r4,0
1163 isync
Eran Liberty9095d4a2005-07-28 10:08:46 -05001164 blr
1165
1166 /* Though all the LBIU Local Access Windows and LBC Banks will be
1167 * initialized in the C code, we'd better configure boot ROM's
1168 * window 0 and bank 0 correctly at here.
1169 */
1170remap_flash_by_law0:
1171 /* Initialize the BR0 with the boot ROM starting address. */
1172 lwz r4, BR0(r3)
1173 li r5, 0x7FFF
Jon Loeligerebc72242005-08-01 13:20:47 -05001174 and r4, r4, r5
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001175 lis r5, (CONFIG_SYS_FLASH_BASE & 0xFFFF8000)@h
1176 ori r5, r5, (CONFIG_SYS_FLASH_BASE & 0xFFFF8000)@l
Eran Liberty9095d4a2005-07-28 10:08:46 -05001177 or r5, r5, r4
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001178 stw r5, BR0(r3) /* r5 <= (CONFIG_SYS_FLASH_BASE & 0xFFFF8000) | (BR0 & 0x00007FFF) */
Eran Liberty9095d4a2005-07-28 10:08:46 -05001179
1180 lwz r4, OR0(r3)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001181 lis r5, ~((CONFIG_SYS_FLASH_SIZE << 4) - 1)
Eran Liberty9095d4a2005-07-28 10:08:46 -05001182 or r4, r4, r5
Timur Tabi53b46172006-08-22 17:07:00 -05001183 stw r4, OR0(r3)
Eran Liberty9095d4a2005-07-28 10:08:46 -05001184
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001185 lis r4, (CONFIG_SYS_FLASH_BASE)@h
1186 ori r4, r4, (CONFIG_SYS_FLASH_BASE)@l
1187 stw r4, LBLAWBAR0(r3) /* LBLAWBAR0 <= CONFIG_SYS_FLASH_BASE */
Eran Liberty9095d4a2005-07-28 10:08:46 -05001188
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001189 /* Store 0x80000012 + log2(CONFIG_SYS_FLASH_SIZE) into LBLAWAR0 */
Timur Tabi53b46172006-08-22 17:07:00 -05001190 lis r4, (0x80000012)@h
1191 ori r4, r4, (0x80000012)@l
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001192 li r5, CONFIG_SYS_FLASH_SIZE
Timur Tabi53b46172006-08-22 17:07:00 -050011931: srawi. r5, r5, 1 /* r5 = r5 >> 1 */
1194 addi r4, r4, 1
1195 bne 1b
1196 stw r4, LBLAWAR0(r3) /* LBLAWAR0 <= Flash Size */
1197
Eran Liberty9095d4a2005-07-28 10:08:46 -05001198
1199 xor r4, r4, r4
1200 stw r4, LBLAWBAR1(r3)
1201 stw r4, LBLAWAR1(r3) /* Off LBIU LAW1 */
Joakim Tjernlundb168d632010-11-19 14:15:33 +01001202 /* Wait for HW to catch up */
1203 lwz r4, LBLAWAR1(r3)
1204 twi 0,r4,0
1205 isync
Eran Liberty9095d4a2005-07-28 10:08:46 -05001206 blr
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001207#endif /* CONFIG_SYS_FLASHBOOT */