blob: 9fbbf59ce211e939d99dbfb43ee51bf17a2df205 [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 Six8b2141c2019-01-21 09:18:09 +010029#include "hid/hid.h"
Mario Six94867102019-01-21 09:17:54 +010030
Eran Liberty9095d4a2005-07-28 10:08:46 -050031/* We don't want the MMU yet.
32 */
33#undef MSR_KERNEL
34
35/*
36 * Floating Point enable, Machine Check and Recoverable Interr.
37 */
38#ifdef DEBUG
39#define MSR_KERNEL (MSR_FP|MSR_RI)
40#else
41#define MSR_KERNEL (MSR_FP|MSR_ME|MSR_RI)
42#endif
43
Scott Wood2b36fbb2012-12-06 13:33:17 +000044#if defined(CONFIG_NAND_SPL) || \
45 (defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_INIT_MINIMAL))
46#define MINIMAL_SPL
47#endif
48
49#if !defined(CONFIG_SPL_BUILD) && !defined(CONFIG_NAND_SPL) && \
50 !defined(CONFIG_SYS_RAMBOOT)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020051#define CONFIG_SYS_FLASHBOOT
Scott Woodb71689b2008-06-30 14:13:28 -050052#endif
53
Eran Liberty9095d4a2005-07-28 10:08:46 -050054/*
55 * Set up GOT: Global Offset Table
56 *
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +010057 * Use r12 to access the GOT
Eran Liberty9095d4a2005-07-28 10:08:46 -050058 */
59 START_GOT
60 GOT_ENTRY(_GOT2_TABLE_)
Scott Woodb71689b2008-06-30 14:13:28 -050061 GOT_ENTRY(__bss_start)
Simon Glassed70c8f2013-03-14 06:54:53 +000062 GOT_ENTRY(__bss_end)
Eran Liberty9095d4a2005-07-28 10:08:46 -050063
Scott Wood2b36fbb2012-12-06 13:33:17 +000064#ifndef MINIMAL_SPL
Scott Woodb71689b2008-06-30 14:13:28 -050065 GOT_ENTRY(_FIXUP_TABLE_)
Eran Liberty9095d4a2005-07-28 10:08:46 -050066 GOT_ENTRY(_start)
67 GOT_ENTRY(_start_of_vectors)
68 GOT_ENTRY(_end_of_vectors)
69 GOT_ENTRY(transfer_to_handler)
Scott Woodb71689b2008-06-30 14:13:28 -050070#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -050071 END_GOT
72
73/*
Jerry Van Baren93eb9312006-12-06 21:23:55 -050074 * The Hard Reset Configuration Word (HRCW) table is in the first 64
75 * (0x40) bytes of flash. It has 8 bytes, but each byte is repeated 8
76 * times so the processor can fetch it out of flash whether the flash
77 * is 8, 16, 32, or 64 bits wide (hardware trickery).
Eran Liberty9095d4a2005-07-28 10:08:46 -050078 */
Eran Liberty9095d4a2005-07-28 10:08:46 -050079 .text
80#define _HRCW_TABLE_ENTRY(w) \
81 .fill 8,1,(((w)>>24)&0xff); \
82 .fill 8,1,(((w)>>16)&0xff); \
83 .fill 8,1,(((w)>> 8)&0xff); \
84 .fill 8,1,(((w) )&0xff)
85
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020086 _HRCW_TABLE_ENTRY(CONFIG_SYS_HRCW_LOW)
87 _HRCW_TABLE_ENTRY(CONFIG_SYS_HRCW_HIGH)
Eran Liberty9095d4a2005-07-28 10:08:46 -050088
Jerry Van Baren93eb9312006-12-06 21:23:55 -050089/*
90 * Magic number and version string - put it after the HRCW since it
91 * cannot be first in flash like it is in many other processors.
92 */
93 .long 0x27051956 /* U-Boot Magic Number */
94
95 .globl version_string
96version_string:
Andreas Bießmann61d01952011-07-18 20:24:04 +020097 .ascii U_BOOT_VERSION_STRING, "\0"
Jerry Van Baren93eb9312006-12-06 21:23:55 -050098
Ron Madrid787b61d2008-12-12 13:12:45 -080099 .align 2
100
101 .globl enable_addr_trans
102enable_addr_trans:
103 /* enable address translation */
104 mfmsr r5
105 ori r5, r5, (MSR_IR | MSR_DR)
106 mtmsr r5
107 isync
108 blr
109
110 .globl disable_addr_trans
111disable_addr_trans:
112 /* disable address translation */
113 mflr r4
114 mfmsr r3
115 andi. r0, r3, (MSR_IR | MSR_DR)
116 beqlr
117 andc r3, r3, r0
118 mtspr SRR0, r4
119 mtspr SRR1, r3
120 rfi
121
Ron Madrid787b61d2008-12-12 13:12:45 -0800122 .globl ppcDWstore
123ppcDWstore:
124 lfd 1, 0(r4)
125 stfd 1, 0(r3)
126 blr
127
128 .globl ppcDWload
129ppcDWload:
130 lfd 1, 0(r3)
131 stfd 1, 0(r4)
132 blr
Eran Liberty9095d4a2005-07-28 10:08:46 -0500133
Eran Liberty9095d4a2005-07-28 10:08:46 -0500134#ifndef CONFIG_DEFAULT_IMMR
135#error CONFIG_DEFAULT_IMMR must be defined
Heiko Schocher71cb3e92017-06-07 17:33:10 +0200136#endif /* CONFIG_DEFAULT_IMMR */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200137#ifndef CONFIG_SYS_IMMR
138#define CONFIG_SYS_IMMR CONFIG_DEFAULT_IMMR
139#endif /* CONFIG_SYS_IMMR */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500140
141/*
142 * After configuration, a system reset exception is executed using the
143 * vector at offset 0x100 relative to the base set by MSR[IP]. If
144 * MSR[IP] is 0, the base address is 0x00000000. If MSR[IP] is 1, the
145 * base address is 0xfff00000. In the case of a Power On Reset or Hard
146 * Reset, the value of MSR[IP] is determined by the CIP field in the
147 * HRCW.
148 *
149 * Other bits in the HRCW set up the Base Address and Port Size in BR0.
150 * This determines the location of the boot ROM (flash or EPROM) in the
151 * processor's address space at boot time. As long as the HRCW is set up
152 * so that we eventually end up executing the code below when the
153 * processor executes the reset exception, the actual values used should
154 * not matter.
155 *
156 * Once we have got here, the address mask in OR0 is cleared so that the
157 * bottom 32K of the boot ROM is effectively repeated all throughout the
158 * processor's address space, after which we can jump to the absolute
159 * address at which the boot ROM was linked at compile time, and proceed
160 * to initialise the memory controller without worrying if the rug will
161 * be pulled out from under us, so to speak (it will be fine as long as
162 * we configure BR0 with the same boot ROM link address).
163 */
164 . = EXC_OFF_SYS_RESET
165
166 .globl _start
167_start: /* time t 0 */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500168 lis r4, CONFIG_DEFAULT_IMMR@h
169 nop
Peter Tyser0c44caf2010-09-14 19:13:53 -0500170
Eran Liberty9095d4a2005-07-28 10:08:46 -0500171 mfmsr r5 /* save msr contents */
Scott Wood838450e2009-01-20 11:56:11 -0600172
173 /* 83xx manuals prescribe a specific sequence for updating IMMRBAR. */
174 bl 1f
1751: mflr r7
176
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200177 lis r3, CONFIG_SYS_IMMR@h
178 ori r3, r3, CONFIG_SYS_IMMR@l
Scott Wood838450e2009-01-20 11:56:11 -0600179
180 lwz r6, IMMRBAR(r4)
181 isync
182
Eran Liberty9095d4a2005-07-28 10:08:46 -0500183 stw r3, IMMRBAR(r4)
Scott Wood838450e2009-01-20 11:56:11 -0600184 lwz r6, 0(r7) /* Arbitrary external load */
185 isync
186
187 lwz r6, IMMRBAR(r3)
188 isync
Jon Loeligerebc72242005-08-01 13:20:47 -0500189
Eran Liberty9095d4a2005-07-28 10:08:46 -0500190 /* Initialise the E300 processor core */
191 /*------------------------------------------*/
Jon Loeligerebc72242005-08-01 13:20:47 -0500192
Scott Wood2b36fbb2012-12-06 13:33:17 +0000193#if (defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_MPC83XX_WAIT_FOR_NAND)) || \
194 defined(CONFIG_NAND_SPL)
Lepcha Suchit7ed421f2008-10-16 13:38:00 -0500195 /* The FCM begins execution after only the first page
196 * is loaded. Wait for the rest before branching
197 * to another flash page.
198 */
Scott Wood838450e2009-01-20 11:56:11 -06001991: lwz r6, 0x50b0(r3)
Lepcha Suchit7ed421f2008-10-16 13:38:00 -0500200 andi. r6, r6, 1
201 beq 1b
202#endif
203
Eran Liberty9095d4a2005-07-28 10:08:46 -0500204 bl init_e300_core
Jon Loeligerebc72242005-08-01 13:20:47 -0500205
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200206#ifdef CONFIG_SYS_FLASHBOOT
Eran Liberty9095d4a2005-07-28 10:08:46 -0500207
208 /* Inflate flash location so it appears everywhere, calculate */
209 /* the absolute address in final location of the FLASH, jump */
210 /* there and deflate the flash size back to minimal size */
211 /*------------------------------------------------------------*/
212 bl map_flash_by_law1
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200213 lis r4, (CONFIG_SYS_MONITOR_BASE)@h
214 ori r4, r4, (CONFIG_SYS_MONITOR_BASE)@l
Eran Liberty9095d4a2005-07-28 10:08:46 -0500215 addi r5, r4, in_flash - _start + EXC_OFF_SYS_RESET
216 mtlr r5
217 blr
218in_flash:
219#if 1 /* Remapping flash with LAW0. */
220 bl remap_flash_by_law0
221#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200222#endif /* CONFIG_SYS_FLASHBOOT */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500223
Kumar Galad5d94d62006-02-10 15:40:06 -0600224 /* setup the bats */
225 bl setup_bats
226 sync
227
228 /*
229 * Cache must be enabled here for stack-in-cache trick.
230 * This means we need to enable the BATS.
231 * This means:
232 * 1) for the EVB, original gt regs need to be mapped
233 * 2) need to have an IBAT for the 0xf region,
234 * we are running there!
235 * Cache should be turned on after BATs, since by default
236 * everything is write-through.
237 * The init-mem BAT can be reused after reloc. The old
238 * gt-regs BAT can be reused after board_init_f calls
239 * board_early_init_f (EVB only).
240 */
241 /* enable address translation */
242 bl enable_addr_trans
243 sync
244
Nick Spence7c20aef2008-08-28 14:09:25 -0700245 /* enable the data cache */
Kumar Galad5d94d62006-02-10 15:40:06 -0600246 bl dcache_enable
247 sync
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200248#ifdef CONFIG_SYS_INIT_RAM_LOCK
Kumar Galad5d94d62006-02-10 15:40:06 -0600249 bl lock_ram_in_cache
250 sync
251#endif
252
253 /* set up the stack pointer in our newly created
mario.six@gdsys.ccd4f4a542017-01-17 08:33:47 +0100254 * cache-ram; use r3 to keep the new SP for now to
255 * avoid overiding the SP it uselessly */
256 lis r3, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET)@h
257 ori r3, r3, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET)@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600258
mario.six@gdsys.cc85df7b42017-01-17 08:33:48 +0100259 /* r4 = end of GD area */
260 addi r4, r3, GENERATED_GBL_DATA_SIZE
261
262 /* Zero GD area */
263 li r0, 0
2641:
265 subi r4, r4, 1
266 stb r0, 0(r4)
267 cmplw r3, r4
268 bne 1b
269
Andy Yanad0ac4b2017-07-24 17:47:27 +0800270#if CONFIG_VAL(SYS_MALLOC_F_LEN)
mario.six@gdsys.cc85df7b42017-01-17 08:33:48 +0100271
Andy Yanad0ac4b2017-07-24 17:47:27 +0800272#if CONFIG_VAL(SYS_MALLOC_F_LEN) + GENERATED_GBL_DATA_SIZE > CONFIG_SYS_INIT_RAM_SIZE
273#error "SYS_MALLOC_F_LEN too large to fit into initial RAM."
mario.six@gdsys.cc85df7b42017-01-17 08:33:48 +0100274#endif
275
276 /* r3 = new stack pointer / pre-reloc malloc area */
Andy Yanad0ac4b2017-07-24 17:47:27 +0800277 subi r3, r3, CONFIG_VAL(SYS_MALLOC_F_LEN)
mario.six@gdsys.cc85df7b42017-01-17 08:33:48 +0100278
279 /* Set pointer to pre-reloc malloc area in GD */
280 stw r3, GD_MALLOC_BASE(r4)
281#endif
Kumar Galad5d94d62006-02-10 15:40:06 -0600282 li r0, 0 /* Make room for stack frame header and */
mario.six@gdsys.ccd4f4a542017-01-17 08:33:47 +0100283 stwu r0, -4(r3) /* clear final stack frame so that */
284 stwu r0, -4(r3) /* stack backtraces terminate cleanly */
Kumar Galad5d94d62006-02-10 15:40:06 -0600285
mario.six@gdsys.ccd4f4a542017-01-17 08:33:47 +0100286 /* Finally, actually set SP */
287 mr r1, r3
Eran Liberty9095d4a2005-07-28 10:08:46 -0500288
289 /* let the C-code set up the rest */
Kumar Galad5d94d62006-02-10 15:40:06 -0600290 /* */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500291 /* Be careful to keep code relocatable & stack humble */
292 /*------------------------------------------------------*/
293
294 GET_GOT /* initialize GOT access */
Joakim Tjernlundf14554d2018-11-28 10:59:55 +0100295 /* Needed for -msingle-pic-base */
296 bl _GLOBAL_OFFSET_TABLE_@local-4
297 mflr r30
Wolfgang Denkb2d36ea2011-04-20 22:11:21 +0200298
Eran Liberty9095d4a2005-07-28 10:08:46 -0500299 /* r3: IMMR */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200300 lis r3, CONFIG_SYS_IMMR@h
Eran Liberty9095d4a2005-07-28 10:08:46 -0500301 /* run low-level CPU init code (in Flash)*/
302 bl cpu_init_f
303
Eran Liberty9095d4a2005-07-28 10:08:46 -0500304 /* run 1st part of board init code (in Flash)*/
Valentin Longchampe91e10a2014-10-03 11:45:23 +0200305 li r3, 0 /* clear boot_flag for calling board_init_f */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500306 bl board_init_f
307
Peter Tyser0c44caf2010-09-14 19:13:53 -0500308 /* NOTREACHED - board_init_f() does not return */
309
Scott Wood2b36fbb2012-12-06 13:33:17 +0000310#ifndef MINIMAL_SPL
Eran Liberty9095d4a2005-07-28 10:08:46 -0500311/*
312 * Vector Table
313 */
314
315 .globl _start_of_vectors
316_start_of_vectors:
317
318/* Machine check */
319 STD_EXCEPTION(0x200, MachineCheck, MachineCheckException)
320
321/* Data Storage exception. */
322 STD_EXCEPTION(0x300, DataStorage, UnknownException)
323
324/* Instruction Storage exception. */
325 STD_EXCEPTION(0x400, InstStorage, UnknownException)
326
327/* External Interrupt exception. */
328#ifndef FIXME
329 STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
Jon Loeligerebc72242005-08-01 13:20:47 -0500330#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -0500331
332/* Alignment exception. */
333 . = 0x600
334Alignment:
Rafal Jaworowski06244e42007-06-22 14:58:04 +0200335 EXCEPTION_PROLOG(SRR0, SRR1)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500336 mfspr r4,DAR
337 stw r4,_DAR(r21)
338 mfspr r5,DSISR
339 stw r5,_DSISR(r21)
340 addi r3,r1,STACK_FRAME_OVERHEAD
Joakim Tjernlund4ff6bc02010-01-19 14:41:55 +0100341 EXC_XFER_TEMPLATE(Alignment, AlignmentException, MSR_KERNEL, COPY_EE)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500342
343/* Program check exception */
344 . = 0x700
345ProgramCheck:
Rafal Jaworowski06244e42007-06-22 14:58:04 +0200346 EXCEPTION_PROLOG(SRR0, SRR1)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500347 addi r3,r1,STACK_FRAME_OVERHEAD
Joakim Tjernlund4ff6bc02010-01-19 14:41:55 +0100348 EXC_XFER_TEMPLATE(ProgramCheck, ProgramCheckException,
349 MSR_KERNEL, COPY_EE)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500350
351 STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
352
353 /* I guess we could implement decrementer, and may have
354 * to someday for timekeeping.
355 */
356 STD_EXCEPTION(0x900, Decrementer, timer_interrupt)
357
358 STD_EXCEPTION(0xa00, Trap_0a, UnknownException)
359 STD_EXCEPTION(0xb00, Trap_0b, UnknownException)
360 STD_EXCEPTION(0xc00, SystemCall, UnknownException)
361 STD_EXCEPTION(0xd00, SingleStep, UnknownException)
362
363 STD_EXCEPTION(0xe00, Trap_0e, UnknownException)
364 STD_EXCEPTION(0xf00, Trap_0f, UnknownException)
365
366 STD_EXCEPTION(0x1000, InstructionTLBMiss, UnknownException)
367 STD_EXCEPTION(0x1100, DataLoadTLBMiss, UnknownException)
368 STD_EXCEPTION(0x1200, DataStoreTLBMiss, UnknownException)
369#ifdef DEBUG
370 . = 0x1300
371 /*
372 * This exception occurs when the program counter matches the
373 * Instruction Address Breakpoint Register (IABR).
374 *
375 * I want the cpu to halt if this occurs so I can hunt around
376 * with the debugger and look at things.
377 *
378 * When DEBUG is defined, both machine check enable (in the MSR)
379 * and checkstop reset enable (in the reset mode register) are
380 * turned off and so a checkstop condition will result in the cpu
381 * halting.
382 *
383 * I force the cpu into a checkstop condition by putting an illegal
384 * instruction here (at least this is the theory).
385 *
386 * well - that didnt work, so just do an infinite loop!
387 */
3881: b 1b
389#else
390 STD_EXCEPTION(0x1300, InstructionBreakpoint, DebugException)
391#endif
392 STD_EXCEPTION(0x1400, SMI, UnknownException)
393
394 STD_EXCEPTION(0x1500, Trap_15, UnknownException)
395 STD_EXCEPTION(0x1600, Trap_16, UnknownException)
396 STD_EXCEPTION(0x1700, Trap_17, UnknownException)
397 STD_EXCEPTION(0x1800, Trap_18, UnknownException)
398 STD_EXCEPTION(0x1900, Trap_19, UnknownException)
399 STD_EXCEPTION(0x1a00, Trap_1a, UnknownException)
400 STD_EXCEPTION(0x1b00, Trap_1b, UnknownException)
401 STD_EXCEPTION(0x1c00, Trap_1c, UnknownException)
402 STD_EXCEPTION(0x1d00, Trap_1d, UnknownException)
403 STD_EXCEPTION(0x1e00, Trap_1e, UnknownException)
404 STD_EXCEPTION(0x1f00, Trap_1f, UnknownException)
405 STD_EXCEPTION(0x2000, Trap_20, UnknownException)
406 STD_EXCEPTION(0x2100, Trap_21, UnknownException)
407 STD_EXCEPTION(0x2200, Trap_22, UnknownException)
408 STD_EXCEPTION(0x2300, Trap_23, UnknownException)
409 STD_EXCEPTION(0x2400, Trap_24, UnknownException)
410 STD_EXCEPTION(0x2500, Trap_25, UnknownException)
411 STD_EXCEPTION(0x2600, Trap_26, UnknownException)
412 STD_EXCEPTION(0x2700, Trap_27, UnknownException)
413 STD_EXCEPTION(0x2800, Trap_28, UnknownException)
414 STD_EXCEPTION(0x2900, Trap_29, UnknownException)
415 STD_EXCEPTION(0x2a00, Trap_2a, UnknownException)
416 STD_EXCEPTION(0x2b00, Trap_2b, UnknownException)
417 STD_EXCEPTION(0x2c00, Trap_2c, UnknownException)
418 STD_EXCEPTION(0x2d00, Trap_2d, UnknownException)
419 STD_EXCEPTION(0x2e00, Trap_2e, UnknownException)
420 STD_EXCEPTION(0x2f00, Trap_2f, UnknownException)
421
422
423 .globl _end_of_vectors
424_end_of_vectors:
425
426 . = 0x3000
427
428/*
429 * This code finishes saving the registers to the exception frame
430 * and jumps to the appropriate handler for the exception.
431 * Register r21 is pointer into trap frame, r1 has new stack pointer.
432 */
433 .globl transfer_to_handler
434transfer_to_handler:
435 stw r22,_NIP(r21)
436 lis r22,MSR_POW@h
437 andc r23,r23,r22
438 stw r23,_MSR(r21)
439 SAVE_GPR(7, r21)
440 SAVE_4GPRS(8, r21)
441 SAVE_8GPRS(12, r21)
442 SAVE_8GPRS(24, r21)
443 mflr r23
444 andi. r24,r23,0x3f00 /* get vector offset */
445 stw r24,TRAP(r21)
446 li r22,0
447 stw r22,RESULT(r21)
448 lwz r24,0(r23) /* virtual address of handler */
449 lwz r23,4(r23) /* where to go when done */
450 mtspr SRR0,r24
451 mtspr SRR1,r20
452 mtlr r23
453 SYNC
454 rfi /* jump to handler, enable MMU */
455
456int_return:
457 mfmsr r28 /* Disable interrupts */
458 li r4,0
459 ori r4,r4,MSR_EE
460 andc r28,r28,r4
461 SYNC /* Some chip revs need this... */
462 mtmsr r28
463 SYNC
464 lwz r2,_CTR(r1)
465 lwz r0,_LINK(r1)
466 mtctr r2
467 mtlr r0
468 lwz r2,_XER(r1)
469 lwz r0,_CCR(r1)
470 mtspr XER,r2
471 mtcrf 0xFF,r0
472 REST_10GPRS(3, r1)
473 REST_10GPRS(13, r1)
474 REST_8GPRS(23, r1)
475 REST_GPR(31, r1)
476 lwz r2,_NIP(r1) /* Restore environment */
477 lwz r0,_MSR(r1)
478 mtspr SRR0,r2
479 mtspr SRR1,r0
480 lwz r0,GPR0(r1)
481 lwz r2,GPR2(r1)
482 lwz r1,GPR1(r1)
483 SYNC
484 rfi
Scott Wood2b36fbb2012-12-06 13:33:17 +0000485#endif /* !MINIMAL_SPL */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500486
487/*
488 * This code initialises the E300 processor core
489 * (conforms to PowerPC 603e spec)
490 * Note: expects original MSR contents to be in r5.
491 */
492 .globl init_e300_core
493init_e300_core: /* time t 10 */
494 /* Initialize machine status; enable machine check interrupt */
495 /*-----------------------------------------------------------*/
496
497 li r3, MSR_KERNEL /* Set ME and RI flags */
498 rlwimi r3, r5, 0, 25, 25 /* preserve IP bit set by HRCW */
499#ifdef DEBUG
500 rlwimi r3, r5, 0, 21, 22 /* debugger might set SE & BE bits */
501#endif
502 SYNC /* Some chip revs need this... */
503 mtmsr r3
504 SYNC
505 mtspr SRR1, r3 /* Make SRR1 match MSR */
506
507
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200508 lis r3, CONFIG_SYS_IMMR@h
Eran Liberty9095d4a2005-07-28 10:08:46 -0500509#if defined(CONFIG_WATCHDOG)
Horst Kronstorfer4565e042010-05-18 10:37:05 +0200510 /* Initialise the Watchdog values and reset it (if req) */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500511 /*------------------------------------------------------*/
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200512 lis r4, CONFIG_SYS_WATCHDOG_VALUE
Eran Liberty9095d4a2005-07-28 10:08:46 -0500513 ori r4, r4, (SWCRR_SWEN | SWCRR_SWRI | SWCRR_SWPR)
514 stw r4, SWCRR(r3)
Jon Loeligerebc72242005-08-01 13:20:47 -0500515
Eran Liberty9095d4a2005-07-28 10:08:46 -0500516 /* and reset it */
Jon Loeligerebc72242005-08-01 13:20:47 -0500517
Eran Liberty9095d4a2005-07-28 10:08:46 -0500518 li r4, 0x556C
519 sth r4, SWSRR@l(r3)
Heiko Schocher6dfb2e52008-01-11 15:15:17 +0100520 li r4, -0x55C7
Eran Liberty9095d4a2005-07-28 10:08:46 -0500521 sth r4, SWSRR@l(r3)
522#else
Horst Kronstorfer4565e042010-05-18 10:37:05 +0200523 /* Disable Watchdog */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500524 /*-------------------*/
Kumar Galab42751c2006-01-11 11:23:01 -0600525 lwz r4, SWCRR(r3)
526 /* Check to see if its enabled for disabling
527 once disabled by SW you can't re-enable */
528 andi. r4, r4, 0x4
529 beq 1f
Eran Liberty9095d4a2005-07-28 10:08:46 -0500530 xor r4, r4, r4
531 stw r4, SWCRR(r3)
Kumar Galab42751c2006-01-11 11:23:01 -06005321:
Eran Liberty9095d4a2005-07-28 10:08:46 -0500533#endif /* CONFIG_WATCHDOG */
534
Nick Spence56fd3c22008-08-28 14:09:19 -0700535#if defined(CONFIG_MASK_AER_AO)
536 /* Write the Arbiter Event Enable to mask Address Only traps. */
537 /* This prevents the dcbz instruction from being trapped when */
538 /* HID0_ABE Address Broadcast Enable is set and the MEMORY */
539 /* COHERENCY bit is set in the WIMG bits, which is often */
540 /* needed for PCI operation. */
541 lwz r4, 0x0808(r3)
542 rlwinm r0, r4, 0, ~AER_AO
543 stw r0, 0x0808(r3)
544#endif /* CONFIG_MASK_AER_AO */
545
Eran Liberty9095d4a2005-07-28 10:08:46 -0500546 /* Initialize the Hardware Implementation-dependent Registers */
547 /* HID0 also contains cache control */
Nick Spence7c20aef2008-08-28 14:09:25 -0700548 /* - force invalidation of data and instruction caches */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500549 /*------------------------------------------------------*/
550
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200551 lis r3, CONFIG_SYS_HID0_INIT@h
552 ori r3, r3, (CONFIG_SYS_HID0_INIT | HID0_ICFI | HID0_DCFI)@l
Eran Liberty9095d4a2005-07-28 10:08:46 -0500553 SYNC
554 mtspr HID0, r3
555
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200556 lis r3, CONFIG_SYS_HID0_FINAL@h
557 ori r3, r3, (CONFIG_SYS_HID0_FINAL & ~(HID0_ICFI | HID0_DCFI))@l
Eran Liberty9095d4a2005-07-28 10:08:46 -0500558 SYNC
559 mtspr HID0, r3
560
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200561 lis r3, CONFIG_SYS_HID2@h
562 ori r3, r3, CONFIG_SYS_HID2@l
Eran Liberty9095d4a2005-07-28 10:08:46 -0500563 SYNC
564 mtspr HID2, r3
565
Eran Liberty9095d4a2005-07-28 10:08:46 -0500566 /* Done! */
567 /*------------------------------*/
Jon Loeligerebc72242005-08-01 13:20:47 -0500568 blr
Eran Liberty9095d4a2005-07-28 10:08:46 -0500569
Kumar Galad5d94d62006-02-10 15:40:06 -0600570 /* setup_bats - set them up to some initial state */
571 .globl setup_bats
572setup_bats:
573 addis r0, r0, 0x0000
574
575 /* IBAT 0 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200576 addis r4, r0, CONFIG_SYS_IBAT0L@h
577 ori r4, r4, CONFIG_SYS_IBAT0L@l
578 addis r3, r0, CONFIG_SYS_IBAT0U@h
579 ori r3, r3, CONFIG_SYS_IBAT0U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600580 mtspr IBAT0L, r4
581 mtspr IBAT0U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600582
583 /* DBAT 0 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200584 addis r4, r0, CONFIG_SYS_DBAT0L@h
585 ori r4, r4, CONFIG_SYS_DBAT0L@l
586 addis r3, r0, CONFIG_SYS_DBAT0U@h
587 ori r3, r3, CONFIG_SYS_DBAT0U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600588 mtspr DBAT0L, r4
589 mtspr DBAT0U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600590
591 /* IBAT 1 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200592 addis r4, r0, CONFIG_SYS_IBAT1L@h
593 ori r4, r4, CONFIG_SYS_IBAT1L@l
594 addis r3, r0, CONFIG_SYS_IBAT1U@h
595 ori r3, r3, CONFIG_SYS_IBAT1U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600596 mtspr IBAT1L, r4
597 mtspr IBAT1U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600598
599 /* DBAT 1 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200600 addis r4, r0, CONFIG_SYS_DBAT1L@h
601 ori r4, r4, CONFIG_SYS_DBAT1L@l
602 addis r3, r0, CONFIG_SYS_DBAT1U@h
603 ori r3, r3, CONFIG_SYS_DBAT1U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600604 mtspr DBAT1L, r4
605 mtspr DBAT1U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600606
607 /* IBAT 2 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200608 addis r4, r0, CONFIG_SYS_IBAT2L@h
609 ori r4, r4, CONFIG_SYS_IBAT2L@l
610 addis r3, r0, CONFIG_SYS_IBAT2U@h
611 ori r3, r3, CONFIG_SYS_IBAT2U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600612 mtspr IBAT2L, r4
613 mtspr IBAT2U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600614
615 /* DBAT 2 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200616 addis r4, r0, CONFIG_SYS_DBAT2L@h
617 ori r4, r4, CONFIG_SYS_DBAT2L@l
618 addis r3, r0, CONFIG_SYS_DBAT2U@h
619 ori r3, r3, CONFIG_SYS_DBAT2U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600620 mtspr DBAT2L, r4
621 mtspr DBAT2U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600622
623 /* IBAT 3 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200624 addis r4, r0, CONFIG_SYS_IBAT3L@h
625 ori r4, r4, CONFIG_SYS_IBAT3L@l
626 addis r3, r0, CONFIG_SYS_IBAT3U@h
627 ori r3, r3, CONFIG_SYS_IBAT3U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600628 mtspr IBAT3L, r4
629 mtspr IBAT3U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600630
631 /* DBAT 3 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200632 addis r4, r0, CONFIG_SYS_DBAT3L@h
633 ori r4, r4, CONFIG_SYS_DBAT3L@l
634 addis r3, r0, CONFIG_SYS_DBAT3U@h
635 ori r3, r3, CONFIG_SYS_DBAT3U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600636 mtspr DBAT3L, r4
637 mtspr DBAT3U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600638
Becky Bruce03ea1be2008-05-08 19:02:12 -0500639#ifdef CONFIG_HIGH_BATS
Kumar Galad5d94d62006-02-10 15:40:06 -0600640 /* IBAT 4 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200641 addis r4, r0, CONFIG_SYS_IBAT4L@h
642 ori r4, r4, CONFIG_SYS_IBAT4L@l
643 addis r3, r0, CONFIG_SYS_IBAT4U@h
644 ori r3, r3, CONFIG_SYS_IBAT4U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600645 mtspr IBAT4L, r4
646 mtspr IBAT4U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600647
648 /* DBAT 4 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200649 addis r4, r0, CONFIG_SYS_DBAT4L@h
650 ori r4, r4, CONFIG_SYS_DBAT4L@l
651 addis r3, r0, CONFIG_SYS_DBAT4U@h
652 ori r3, r3, CONFIG_SYS_DBAT4U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600653 mtspr DBAT4L, r4
654 mtspr DBAT4U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600655
656 /* IBAT 5 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200657 addis r4, r0, CONFIG_SYS_IBAT5L@h
658 ori r4, r4, CONFIG_SYS_IBAT5L@l
659 addis r3, r0, CONFIG_SYS_IBAT5U@h
660 ori r3, r3, CONFIG_SYS_IBAT5U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600661 mtspr IBAT5L, r4
662 mtspr IBAT5U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600663
664 /* DBAT 5 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200665 addis r4, r0, CONFIG_SYS_DBAT5L@h
666 ori r4, r4, CONFIG_SYS_DBAT5L@l
667 addis r3, r0, CONFIG_SYS_DBAT5U@h
668 ori r3, r3, CONFIG_SYS_DBAT5U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600669 mtspr DBAT5L, r4
670 mtspr DBAT5U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600671
672 /* IBAT 6 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200673 addis r4, r0, CONFIG_SYS_IBAT6L@h
674 ori r4, r4, CONFIG_SYS_IBAT6L@l
675 addis r3, r0, CONFIG_SYS_IBAT6U@h
676 ori r3, r3, CONFIG_SYS_IBAT6U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600677 mtspr IBAT6L, r4
678 mtspr IBAT6U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600679
680 /* DBAT 6 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200681 addis r4, r0, CONFIG_SYS_DBAT6L@h
682 ori r4, r4, CONFIG_SYS_DBAT6L@l
683 addis r3, r0, CONFIG_SYS_DBAT6U@h
684 ori r3, r3, CONFIG_SYS_DBAT6U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600685 mtspr DBAT6L, r4
686 mtspr DBAT6U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600687
688 /* IBAT 7 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200689 addis r4, r0, CONFIG_SYS_IBAT7L@h
690 ori r4, r4, CONFIG_SYS_IBAT7L@l
691 addis r3, r0, CONFIG_SYS_IBAT7U@h
692 ori r3, r3, CONFIG_SYS_IBAT7U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600693 mtspr IBAT7L, r4
694 mtspr IBAT7U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600695
696 /* DBAT 7 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200697 addis r4, r0, CONFIG_SYS_DBAT7L@h
698 ori r4, r4, CONFIG_SYS_DBAT7L@l
699 addis r3, r0, CONFIG_SYS_DBAT7U@h
700 ori r3, r3, CONFIG_SYS_DBAT7U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600701 mtspr DBAT7L, r4
702 mtspr DBAT7U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600703#endif
704
Scott Woodb71689b2008-06-30 14:13:28 -0500705 isync
706
707 /* invalidate all tlb's
708 *
709 * From the 603e User Manual: "The 603e provides the ability to
710 * invalidate a TLB entry. The TLB Invalidate Entry (tlbie)
711 * instruction invalidates the TLB entry indexed by the EA, and
712 * operates on both the instruction and data TLBs simultaneously
713 * invalidating four TLB entries (both sets in each TLB). The
714 * index corresponds to bits 15-19 of the EA. To invalidate all
715 * entries within both TLBs, 32 tlbie instructions should be
716 * issued, incrementing this field by one each time."
717 *
718 * "Note that the tlbia instruction is not implemented on the
719 * 603e."
720 *
721 * bits 15-19 correspond to addresses 0x00000000 to 0x0001F000
722 * incrementing by 0x1000 each time. The code below is sort of
Stefan Roese88fbf932010-04-15 16:07:28 +0200723 * based on code in "flush_tlbs" from arch/powerpc/kernel/head.S
Scott Woodb71689b2008-06-30 14:13:28 -0500724 *
Kumar Galad5d94d62006-02-10 15:40:06 -0600725 */
726 lis r3, 0
727 lis r5, 2
728
7291:
730 tlbie r3
731 addi r3, r3, 0x1000
732 cmp 0, 0, r3, r5
733 blt 1b
734
735 blr
736
Eran Liberty9095d4a2005-07-28 10:08:46 -0500737/* Cache functions.
738 *
739 * Note: requires that all cache bits in
740 * HID0 are in the low half word.
741 */
Scott Wood2b36fbb2012-12-06 13:33:17 +0000742#ifndef MINIMAL_SPL
Eran Liberty9095d4a2005-07-28 10:08:46 -0500743 .globl icache_enable
744icache_enable:
745 mfspr r3, HID0
746 ori r3, r3, HID0_ICE
Nick Spence7c20aef2008-08-28 14:09:25 -0700747 li r4, HID0_ICFI|HID0_ILOCK
Eran Liberty9095d4a2005-07-28 10:08:46 -0500748 andc r3, r3, r4
749 ori r4, r3, HID0_ICFI
750 isync
751 mtspr HID0, r4 /* sets enable and invalidate, clears lock */
752 isync
753 mtspr HID0, r3 /* clears invalidate */
754 blr
755
756 .globl icache_disable
757icache_disable:
758 mfspr r3, HID0
759 lis r4, 0
Nick Spence7c20aef2008-08-28 14:09:25 -0700760 ori r4, r4, HID0_ICE|HID0_ICFI|HID0_ILOCK
Eran Liberty9095d4a2005-07-28 10:08:46 -0500761 andc r3, r3, r4
Eran Liberty9095d4a2005-07-28 10:08:46 -0500762 isync
Nick Spence7c20aef2008-08-28 14:09:25 -0700763 mtspr HID0, r3 /* clears invalidate, enable and lock */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500764 blr
765
766 .globl icache_status
767icache_status:
768 mfspr r3, HID0
Marian Balakowicz758e5d32006-03-14 16:01:25 +0100769 rlwinm r3, r3, (31 - HID0_ICE_SHIFT + 1), 31, 31
Eran Liberty9095d4a2005-07-28 10:08:46 -0500770 blr
Scott Wood2b36fbb2012-12-06 13:33:17 +0000771#endif /* !MINIMAL_SPL */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500772
773 .globl dcache_enable
774dcache_enable:
775 mfspr r3, HID0
Kumar Galad5d94d62006-02-10 15:40:06 -0600776 li r5, HID0_DCFI|HID0_DLOCK
777 andc r3, r3, r5
Kumar Galad5d94d62006-02-10 15:40:06 -0600778 ori r3, r3, HID0_DCE
Eran Liberty9095d4a2005-07-28 10:08:46 -0500779 sync
Nick Spence7c20aef2008-08-28 14:09:25 -0700780 mtspr HID0, r3 /* enable, no invalidate */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500781 blr
782
783 .globl dcache_disable
784dcache_disable:
Nick Spence7c20aef2008-08-28 14:09:25 -0700785 mflr r4
786 bl flush_dcache /* uses r3 and r5 */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500787 mfspr r3, HID0
Nick Spence7c20aef2008-08-28 14:09:25 -0700788 li r5, HID0_DCE|HID0_DLOCK
789 andc r3, r3, r5
790 ori r5, r3, HID0_DCFI
Eran Liberty9095d4a2005-07-28 10:08:46 -0500791 sync
Nick Spence7c20aef2008-08-28 14:09:25 -0700792 mtspr HID0, r5 /* sets invalidate, clears enable and lock */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500793 sync
794 mtspr HID0, r3 /* clears invalidate */
Nick Spence7c20aef2008-08-28 14:09:25 -0700795 mtlr r4
Eran Liberty9095d4a2005-07-28 10:08:46 -0500796 blr
797
798 .globl dcache_status
799dcache_status:
800 mfspr r3, HID0
Marian Balakowicz758e5d32006-03-14 16:01:25 +0100801 rlwinm r3, r3, (31 - HID0_DCE_SHIFT + 1), 31, 31
Eran Liberty9095d4a2005-07-28 10:08:46 -0500802 blr
803
Nick Spence7c20aef2008-08-28 14:09:25 -0700804 .globl flush_dcache
805flush_dcache:
806 lis r3, 0
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200807 lis r5, CONFIG_SYS_CACHELINE_SIZE
Nick Spence7c20aef2008-08-28 14:09:25 -07008081: cmp 0, 1, r3, r5
809 bge 2f
810 lwz r5, 0(r3)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200811 lis r5, CONFIG_SYS_CACHELINE_SIZE
Nick Spence7c20aef2008-08-28 14:09:25 -0700812 addi r3, r3, 0x4
813 b 1b
8142: blr
815
Eran Liberty9095d4a2005-07-28 10:08:46 -0500816/*-------------------------------------------------------------------*/
817
818/*
819 * void relocate_code (addr_sp, gd, addr_moni)
820 *
821 * This "function" does not return, instead it continues in RAM
822 * after relocating the monitor code.
823 *
824 * r3 = dest
825 * r4 = src
826 * r5 = length in bytes
827 * r6 = cachelinesize
828 */
829 .globl relocate_code
830relocate_code:
831 mr r1, r3 /* Set new stack pointer */
832 mr r9, r4 /* Save copy of Global Data pointer */
833 mr r10, r5 /* Save copy of Destination Address */
834
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +0100835 GET_GOT
Eran Liberty9095d4a2005-07-28 10:08:46 -0500836 mr r3, r5 /* Destination Address */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200837 lis r4, CONFIG_SYS_MONITOR_BASE@h /* Source Address */
838 ori r4, r4, CONFIG_SYS_MONITOR_BASE@l
Scott Woodb71689b2008-06-30 14:13:28 -0500839 lwz r5, GOT(__bss_start)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500840 sub r5, r5, r4
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200841 li r6, CONFIG_SYS_CACHELINE_SIZE /* Cache Line Size */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500842
843 /*
844 * Fix GOT pointer:
845 *
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200846 * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500847 * + Destination Address
848 *
849 * Offset:
850 */
851 sub r15, r10, r4
852
853 /* First our own GOT */
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +0100854 add r12, r12, r15
Eran Liberty9095d4a2005-07-28 10:08:46 -0500855 /* then the one used by the C code */
856 add r30, r30, r15
857
858 /*
859 * Now relocate code
860 */
861
862 cmplw cr1,r3,r4
863 addi r0,r5,3
864 srwi. r0,r0,2
865 beq cr1,4f /* In place copy is not necessary */
866 beq 7f /* Protect against 0 count */
867 mtctr r0
868 bge cr1,2f
869 la r8,-4(r4)
870 la r7,-4(r3)
871
872 /* copy */
8731: lwzu r0,4(r8)
874 stwu r0,4(r7)
875 bdnz 1b
876
877 addi r0,r5,3
878 srwi. r0,r0,2
879 mtctr r0
880 la r8,-4(r4)
881 la r7,-4(r3)
Jon Loeligerebc72242005-08-01 13:20:47 -0500882
883 /* and compare */
Eran Liberty9095d4a2005-07-28 10:08:46 -050088420: lwzu r20,4(r8)
885 lwzu r21,4(r7)
886 xor. r22, r20, r21
887 bne 30f
888 bdnz 20b
889 b 4f
890
891 /* compare failed */
89230: li r3, 0
893 blr
894
8952: slwi r0,r0,2 /* re copy in reverse order ... y do we needed it? */
896 add r8,r4,r0
897 add r7,r3,r0
8983: lwzu r0,-4(r8)
899 stwu r0,-4(r7)
900 bdnz 3b
Eran Liberty9095d4a2005-07-28 10:08:46 -0500901
902/*
903 * Now flush the cache: note that we must start from a cache aligned
904 * address. Otherwise we might miss one cache line.
905 */
Kumar Galad5d94d62006-02-10 15:40:06 -06009064: cmpwi r6,0
Eran Liberty9095d4a2005-07-28 10:08:46 -0500907 add r5,r3,r5
Kumar Galad5d94d62006-02-10 15:40:06 -0600908 beq 7f /* Always flush prefetch queue in any case */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500909 subi r0,r6,1
910 andc r3,r3,r0
Eran Liberty9095d4a2005-07-28 10:08:46 -0500911 mr r4,r3
9125: dcbst 0,r4
913 add r4,r4,r6
914 cmplw r4,r5
915 blt 5b
Kumar Galad5d94d62006-02-10 15:40:06 -0600916 sync /* Wait for all dcbst to complete on bus */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500917 mr r4,r3
9186: icbi 0,r4
919 add r4,r4,r6
920 cmplw r4,r5
921 blt 6b
Kumar Galad5d94d62006-02-10 15:40:06 -06009227: sync /* Wait for all icbi to complete on bus */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500923 isync
924
925/*
926 * We are done. Do not return, instead branch to second part of board
927 * initialization, now running from RAM.
928 */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500929 addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
930 mtlr r0
931 blr
932
933in_ram:
934
935 /*
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +0100936 * Relocation Function, r12 point to got2+0x8000
Eran Liberty9095d4a2005-07-28 10:08:46 -0500937 *
938 * Adjust got2 pointers, no need to check for 0, this code
939 * already puts a few entries in the table.
940 */
941 li r0,__got2_entries@sectoff@l
942 la r3,GOT(_GOT2_TABLE_)
943 lwz r11,GOT(_GOT2_TABLE_)
944 mtctr r0
945 sub r11,r3,r11
946 addi r3,r3,-4
9471: lwzu r0,4(r3)
Joakim Tjernlund4f2fdac2009-10-08 02:03:51 +0200948 cmpwi r0,0
949 beq- 2f
Eran Liberty9095d4a2005-07-28 10:08:46 -0500950 add r0,r0,r11
951 stw r0,0(r3)
Joakim Tjernlund4f2fdac2009-10-08 02:03:51 +02009522: bdnz 1b
Eran Liberty9095d4a2005-07-28 10:08:46 -0500953
Scott Wood2b36fbb2012-12-06 13:33:17 +0000954#ifndef MINIMAL_SPL
Eran Liberty9095d4a2005-07-28 10:08:46 -0500955 /*
956 * Now adjust the fixups and the pointers to the fixups
957 * in case we need to move ourselves again.
958 */
Joakim Tjernlund4f2fdac2009-10-08 02:03:51 +0200959 li r0,__fixup_entries@sectoff@l
Eran Liberty9095d4a2005-07-28 10:08:46 -0500960 lwz r3,GOT(_FIXUP_TABLE_)
961 cmpwi r0,0
962 mtctr r0
963 addi r3,r3,-4
964 beq 4f
9653: lwzu r4,4(r3)
966 lwzux r0,r4,r11
Joakim Tjernlundc61b25a2010-10-14 11:51:44 +0200967 cmpwi r0,0
Eran Liberty9095d4a2005-07-28 10:08:46 -0500968 add r0,r0,r11
Joakim Tjernlund401b5922010-11-04 19:02:00 +0100969 stw r4,0(r3)
Joakim Tjernlundc61b25a2010-10-14 11:51:44 +0200970 beq- 5f
Eran Liberty9095d4a2005-07-28 10:08:46 -0500971 stw r0,0(r4)
Joakim Tjernlundc61b25a2010-10-14 11:51:44 +02009725: bdnz 3b
Eran Liberty9095d4a2005-07-28 10:08:46 -05009734:
Scott Woodb71689b2008-06-30 14:13:28 -0500974#endif
975
Eran Liberty9095d4a2005-07-28 10:08:46 -0500976clear_bss:
977 /*
978 * Now clear BSS segment
979 */
980 lwz r3,GOT(__bss_start)
Simon Glassed70c8f2013-03-14 06:54:53 +0000981 lwz r4,GOT(__bss_end)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500982
983 cmplw 0, r3, r4
984 beq 6f
985
986 li r0, 0
9875:
988 stw r0, 0(r3)
989 addi r3, r3, 4
990 cmplw 0, r3, r4
991 bne 5b
9926:
993
994 mr r3, r9 /* Global Data pointer */
995 mr r4, r10 /* Destination Address */
996 bl board_init_r
997
Scott Wood2b36fbb2012-12-06 13:33:17 +0000998#ifndef MINIMAL_SPL
Eran Liberty9095d4a2005-07-28 10:08:46 -0500999 /*
1000 * Copy exception vector code to low memory
1001 *
1002 * r3: dest_addr
1003 * r7: source address, r8: end address, r9: target address
1004 */
1005 .globl trap_init
1006trap_init:
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +01001007 mflr r4 /* save link register */
1008 GET_GOT
Eran Liberty9095d4a2005-07-28 10:08:46 -05001009 lwz r7, GOT(_start)
1010 lwz r8, GOT(_end_of_vectors)
1011
1012 li r9, 0x100 /* reset vector always at 0x100 */
1013
1014 cmplw 0, r7, r8
1015 bgelr /* return if r7>=r8 - just in case */
Eran Liberty9095d4a2005-07-28 10:08:46 -050010161:
1017 lwz r0, 0(r7)
1018 stw r0, 0(r9)
1019 addi r7, r7, 4
1020 addi r9, r9, 4
1021 cmplw 0, r7, r8
1022 bne 1b
1023
1024 /*
1025 * relocate `hdlr' and `int_return' entries
1026 */
1027 li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
1028 li r8, Alignment - _start + EXC_OFF_SYS_RESET
10292:
1030 bl trap_reloc
1031 addi r7, r7, 0x100 /* next exception vector */
1032 cmplw 0, r7, r8
1033 blt 2b
1034
1035 li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
1036 bl trap_reloc
1037
1038 li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
1039 bl trap_reloc
1040
1041 li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
1042 li r8, SystemCall - _start + EXC_OFF_SYS_RESET
10433:
1044 bl trap_reloc
1045 addi r7, r7, 0x100 /* next exception vector */
1046 cmplw 0, r7, r8
1047 blt 3b
1048
1049 li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
1050 li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
10514:
1052 bl trap_reloc
1053 addi r7, r7, 0x100 /* next exception vector */
1054 cmplw 0, r7, r8
1055 blt 4b
1056
1057 mfmsr r3 /* now that the vectors have */
1058 lis r7, MSR_IP@h /* relocated into low memory */
1059 ori r7, r7, MSR_IP@l /* MSR[IP] can be turned off */
1060 andc r3, r3, r7 /* (if it was on) */
1061 SYNC /* Some chip revs need this... */
1062 mtmsr r3
1063 SYNC
1064
1065 mtlr r4 /* restore link register */
1066 blr
1067
Scott Wood2b36fbb2012-12-06 13:33:17 +00001068#endif /* !MINIMAL_SPL */
Eran Liberty9095d4a2005-07-28 10:08:46 -05001069
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001070#ifdef CONFIG_SYS_INIT_RAM_LOCK
Kumar Galad5d94d62006-02-10 15:40:06 -06001071lock_ram_in_cache:
1072 /* Allocate Initial RAM in data cache.
1073 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001074 lis r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@h
1075 ori r3, r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@l
Wolfgang Denk1c2e98e2010-10-26 13:32:32 +02001076 li r4, ((CONFIG_SYS_INIT_RAM_SIZE & ~31) + \
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001077 (CONFIG_SYS_INIT_RAM_ADDR & 31) + 31) / 32
Nick Spenceb89d6fb2008-08-28 14:09:11 -07001078 mtctr r4
Kumar Galad5d94d62006-02-10 15:40:06 -060010791:
1080 dcbz r0, r3
1081 addi r3, r3, 32
1082 bdnz 1b
1083
1084 /* Lock the data cache */
1085 mfspr r0, HID0
Nick Spence7c20aef2008-08-28 14:09:25 -07001086 ori r0, r0, HID0_DLOCK
Kumar Galad5d94d62006-02-10 15:40:06 -06001087 sync
1088 mtspr HID0, r0
1089 sync
1090 blr
1091
Scott Wood2b36fbb2012-12-06 13:33:17 +00001092#ifndef MINIMAL_SPL
Eran Liberty9095d4a2005-07-28 10:08:46 -05001093.globl unlock_ram_in_cache
1094unlock_ram_in_cache:
1095 /* invalidate the INIT_RAM section */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001096 lis r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@h
1097 ori r3, r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@l
Wolfgang Denk1c2e98e2010-10-26 13:32:32 +02001098 li r4, ((CONFIG_SYS_INIT_RAM_SIZE & ~31) + \
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001099 (CONFIG_SYS_INIT_RAM_ADDR & 31) + 31) / 32
Nick Spenceb89d6fb2008-08-28 14:09:11 -07001100 mtctr r4
Eran Liberty9095d4a2005-07-28 10:08:46 -050011011: icbi r0, r3
1102 dcbi r0, r3
1103 addi r3, r3, 32
1104 bdnz 1b
1105 sync /* Wait for all icbi to complete on bus */
1106 isync
Kumar Galad5d94d62006-02-10 15:40:06 -06001107
1108 /* Unlock the data cache and invalidate it */
1109 mfspr r3, HID0
1110 li r5, HID0_DLOCK|HID0_DCFI
1111 andc r3, r3, r5 /* no invalidate, unlock */
1112 ori r5, r3, HID0_DCFI /* invalidate, unlock */
Nick Spence7c20aef2008-08-28 14:09:25 -07001113 sync
Kumar Galad5d94d62006-02-10 15:40:06 -06001114 mtspr HID0, r5 /* invalidate, unlock */
Kumar Galad5d94d62006-02-10 15:40:06 -06001115 sync
Nick Spence7c20aef2008-08-28 14:09:25 -07001116 mtspr HID0, r3 /* no invalidate, unlock */
Eran Liberty9095d4a2005-07-28 10:08:46 -05001117 blr
Scott Wood2b36fbb2012-12-06 13:33:17 +00001118#endif /* !MINIMAL_SPL */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001119#endif /* CONFIG_SYS_INIT_RAM_LOCK */
Eran Liberty9095d4a2005-07-28 10:08:46 -05001120
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001121#ifdef CONFIG_SYS_FLASHBOOT
Eran Liberty9095d4a2005-07-28 10:08:46 -05001122map_flash_by_law1:
1123 /* When booting from ROM (Flash or EPROM), clear the */
1124 /* Address Mask in OR0 so ROM appears everywhere */
1125 /*----------------------------------------------------*/
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001126 lis r3, (CONFIG_SYS_IMMR)@h /* r3 <= CONFIG_SYS_IMMR */
Jon Loeligerebc72242005-08-01 13:20:47 -05001127 lwz r4, OR0@l(r3)
Eran Liberty9095d4a2005-07-28 10:08:46 -05001128 li r5, 0x7fff /* r5 <= 0x00007FFFF */
Jon Loeligerebc72242005-08-01 13:20:47 -05001129 and r4, r4, r5
Eran Liberty9095d4a2005-07-28 10:08:46 -05001130 stw r4, OR0@l(r3) /* OR0 <= OR0 & 0x00007FFFF */
1131
1132 /* As MPC8349E User's Manual presented, when RCW[BMS] is set to 0,
1133 * system will boot from 0x0000_0100, and the LBLAWBAR0[BASE_ADDR]
1134 * reset value is 0x00000; when RCW[BMS] is set to 1, system will boot
1135 * from 0xFFF0_0100, and the LBLAWBAR0[BASE_ADDR] reset value is
1136 * 0xFF800. From the hard resetting to here, the processor fetched and
1137 * executed the instructions one by one. There is not absolutely
1138 * jumping happened. Laterly, the u-boot code has to do an absolutely
1139 * jumping to tell the CPU instruction fetching component what the
1140 * u-boot TEXT base address is. Because the TEXT base resides in the
1141 * boot ROM memory space, to garantee the code can run smoothly after
1142 * that jumping, we must map in the entire boot ROM by Local Access
1143 * Window. Sometimes, we desire an non-0x00000 or non-0xFF800 starting
1144 * address for boot ROM, such as 0xFE000000. In this case, the default
1145 * LBIU Local Access Widow 0 will not cover this memory space. So, we
1146 * need another window to map in it.
1147 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001148 lis r4, (CONFIG_SYS_FLASH_BASE)@h
1149 ori r4, r4, (CONFIG_SYS_FLASH_BASE)@l
1150 stw r4, LBLAWBAR1(r3) /* LBLAWBAR1 <= CONFIG_SYS_FLASH_BASE */
Timur Tabi53b46172006-08-22 17:07:00 -05001151
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001152 /* Store 0x80000012 + log2(CONFIG_SYS_FLASH_SIZE) into LBLAWAR1 */
Timur Tabi53b46172006-08-22 17:07:00 -05001153 lis r4, (0x80000012)@h
1154 ori r4, r4, (0x80000012)@l
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001155 li r5, CONFIG_SYS_FLASH_SIZE
Timur Tabi53b46172006-08-22 17:07:00 -050011561: srawi. r5, r5, 1 /* r5 = r5 >> 1 */
1157 addi r4, r4, 1
1158 bne 1b
1159
Eran Liberty9095d4a2005-07-28 10:08:46 -05001160 stw r4, LBLAWAR1(r3) /* LBLAWAR1 <= 8MB Flash Size */
Joakim Tjernlundb168d632010-11-19 14:15:33 +01001161 /* Wait for HW to catch up */
1162 lwz r4, LBLAWAR1(r3)
1163 twi 0,r4,0
1164 isync
Eran Liberty9095d4a2005-07-28 10:08:46 -05001165 blr
1166
1167 /* Though all the LBIU Local Access Windows and LBC Banks will be
1168 * initialized in the C code, we'd better configure boot ROM's
1169 * window 0 and bank 0 correctly at here.
1170 */
1171remap_flash_by_law0:
1172 /* Initialize the BR0 with the boot ROM starting address. */
1173 lwz r4, BR0(r3)
1174 li r5, 0x7FFF
Jon Loeligerebc72242005-08-01 13:20:47 -05001175 and r4, r4, r5
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001176 lis r5, (CONFIG_SYS_FLASH_BASE & 0xFFFF8000)@h
1177 ori r5, r5, (CONFIG_SYS_FLASH_BASE & 0xFFFF8000)@l
Eran Liberty9095d4a2005-07-28 10:08:46 -05001178 or r5, r5, r4
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001179 stw r5, BR0(r3) /* r5 <= (CONFIG_SYS_FLASH_BASE & 0xFFFF8000) | (BR0 & 0x00007FFF) */
Eran Liberty9095d4a2005-07-28 10:08:46 -05001180
1181 lwz r4, OR0(r3)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001182 lis r5, ~((CONFIG_SYS_FLASH_SIZE << 4) - 1)
Eran Liberty9095d4a2005-07-28 10:08:46 -05001183 or r4, r4, r5
Timur Tabi53b46172006-08-22 17:07:00 -05001184 stw r4, OR0(r3)
Eran Liberty9095d4a2005-07-28 10:08:46 -05001185
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001186 lis r4, (CONFIG_SYS_FLASH_BASE)@h
1187 ori r4, r4, (CONFIG_SYS_FLASH_BASE)@l
1188 stw r4, LBLAWBAR0(r3) /* LBLAWBAR0 <= CONFIG_SYS_FLASH_BASE */
Eran Liberty9095d4a2005-07-28 10:08:46 -05001189
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001190 /* Store 0x80000012 + log2(CONFIG_SYS_FLASH_SIZE) into LBLAWAR0 */
Timur Tabi53b46172006-08-22 17:07:00 -05001191 lis r4, (0x80000012)@h
1192 ori r4, r4, (0x80000012)@l
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001193 li r5, CONFIG_SYS_FLASH_SIZE
Timur Tabi53b46172006-08-22 17:07:00 -050011941: srawi. r5, r5, 1 /* r5 = r5 >> 1 */
1195 addi r4, r4, 1
1196 bne 1b
1197 stw r4, LBLAWAR0(r3) /* LBLAWAR0 <= Flash Size */
1198
Eran Liberty9095d4a2005-07-28 10:08:46 -05001199
1200 xor r4, r4, r4
1201 stw r4, LBLAWBAR1(r3)
1202 stw r4, LBLAWAR1(r3) /* Off LBIU LAW1 */
Joakim Tjernlundb168d632010-11-19 14:15:33 +01001203 /* Wait for HW to catch up */
1204 lwz r4, LBLAWAR1(r3)
1205 twi 0,r4,0
1206 isync
Eran Liberty9095d4a2005-07-28 10:08:46 -05001207 blr
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001208#endif /* CONFIG_SYS_FLASHBOOT */