blob: ff312892bc13b5a4af3344523f193ea397c1e972 [file] [log] [blame]
Eran Liberty9095d4a2005-07-28 10:08:46 -05001/*
2 * Copyright (C) 1998 Dan Malek <dmalek@jlc.net>
3 * Copyright (C) 1999 Magnus Damm <kieraypc01.p.y.kie.era.ericsson.se>
4 * Copyright (C) 2000, 2001,2002 Wolfgang Denk <wd@denx.de>
Scott Woodb71689b2008-06-30 14:13:28 -05005 * Copyright Freescale Semiconductor, Inc. 2004, 2006, 2008.
Eran Liberty9095d4a2005-07-28 10:08:46 -05006 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02007 * SPDX-License-Identifier: GPL-2.0+
Eran Liberty9095d4a2005-07-28 10:08:46 -05008 */
9
10/*
11 * U-Boot - Startup Code for MPC83xx PowerPC based Embedded Boards
12 */
13
Wolfgang Denk0191e472010-10-26 14:34:52 +020014#include <asm-offsets.h>
Eran Liberty9095d4a2005-07-28 10:08:46 -050015#include <config.h>
Jon Loeligerebc72242005-08-01 13:20:47 -050016#include <mpc83xx.h>
Eran Liberty9095d4a2005-07-28 10:08:46 -050017#include <version.h>
18
19#define CONFIG_83XX 1 /* needed for Linux kernel header files*/
Eran Liberty9095d4a2005-07-28 10:08:46 -050020
21#include <ppc_asm.tmpl>
22#include <ppc_defs.h>
23
24#include <asm/cache.h>
25#include <asm/mmu.h>
Peter Tyser3a1362d2010-10-14 23:33:24 -050026#include <asm/u-boot.h>
Eran Liberty9095d4a2005-07-28 10:08:46 -050027
Eran Liberty9095d4a2005-07-28 10:08:46 -050028/* We don't want the MMU yet.
29 */
30#undef MSR_KERNEL
31
32/*
33 * Floating Point enable, Machine Check and Recoverable Interr.
34 */
35#ifdef DEBUG
36#define MSR_KERNEL (MSR_FP|MSR_RI)
37#else
38#define MSR_KERNEL (MSR_FP|MSR_ME|MSR_RI)
39#endif
40
Scott Wood2b36fbb2012-12-06 13:33:17 +000041#if defined(CONFIG_NAND_SPL) || \
42 (defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_INIT_MINIMAL))
43#define MINIMAL_SPL
44#endif
45
46#if !defined(CONFIG_SPL_BUILD) && !defined(CONFIG_NAND_SPL) && \
47 !defined(CONFIG_SYS_RAMBOOT)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020048#define CONFIG_SYS_FLASHBOOT
Scott Woodb71689b2008-06-30 14:13:28 -050049#endif
50
Eran Liberty9095d4a2005-07-28 10:08:46 -050051/*
52 * Set up GOT: Global Offset Table
53 *
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +010054 * Use r12 to access the GOT
Eran Liberty9095d4a2005-07-28 10:08:46 -050055 */
56 START_GOT
57 GOT_ENTRY(_GOT2_TABLE_)
Scott Woodb71689b2008-06-30 14:13:28 -050058 GOT_ENTRY(__bss_start)
Simon Glassed70c8f2013-03-14 06:54:53 +000059 GOT_ENTRY(__bss_end)
Eran Liberty9095d4a2005-07-28 10:08:46 -050060
Scott Wood2b36fbb2012-12-06 13:33:17 +000061#ifndef MINIMAL_SPL
Scott Woodb71689b2008-06-30 14:13:28 -050062 GOT_ENTRY(_FIXUP_TABLE_)
Eran Liberty9095d4a2005-07-28 10:08:46 -050063 GOT_ENTRY(_start)
64 GOT_ENTRY(_start_of_vectors)
65 GOT_ENTRY(_end_of_vectors)
66 GOT_ENTRY(transfer_to_handler)
Scott Woodb71689b2008-06-30 14:13:28 -050067#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -050068 END_GOT
69
70/*
Jerry Van Baren93eb9312006-12-06 21:23:55 -050071 * The Hard Reset Configuration Word (HRCW) table is in the first 64
72 * (0x40) bytes of flash. It has 8 bytes, but each byte is repeated 8
73 * times so the processor can fetch it out of flash whether the flash
74 * is 8, 16, 32, or 64 bits wide (hardware trickery).
Eran Liberty9095d4a2005-07-28 10:08:46 -050075 */
Eran Liberty9095d4a2005-07-28 10:08:46 -050076 .text
77#define _HRCW_TABLE_ENTRY(w) \
78 .fill 8,1,(((w)>>24)&0xff); \
79 .fill 8,1,(((w)>>16)&0xff); \
80 .fill 8,1,(((w)>> 8)&0xff); \
81 .fill 8,1,(((w) )&0xff)
82
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020083 _HRCW_TABLE_ENTRY(CONFIG_SYS_HRCW_LOW)
84 _HRCW_TABLE_ENTRY(CONFIG_SYS_HRCW_HIGH)
Eran Liberty9095d4a2005-07-28 10:08:46 -050085
Jerry Van Baren93eb9312006-12-06 21:23:55 -050086/*
87 * Magic number and version string - put it after the HRCW since it
88 * cannot be first in flash like it is in many other processors.
89 */
90 .long 0x27051956 /* U-Boot Magic Number */
91
92 .globl version_string
93version_string:
Andreas Bießmann61d01952011-07-18 20:24:04 +020094 .ascii U_BOOT_VERSION_STRING, "\0"
Jerry Van Baren93eb9312006-12-06 21:23:55 -050095
Ron Madrid787b61d2008-12-12 13:12:45 -080096 .align 2
97
98 .globl enable_addr_trans
99enable_addr_trans:
100 /* enable address translation */
101 mfmsr r5
102 ori r5, r5, (MSR_IR | MSR_DR)
103 mtmsr r5
104 isync
105 blr
106
107 .globl disable_addr_trans
108disable_addr_trans:
109 /* disable address translation */
110 mflr r4
111 mfmsr r3
112 andi. r0, r3, (MSR_IR | MSR_DR)
113 beqlr
114 andc r3, r3, r0
115 mtspr SRR0, r4
116 mtspr SRR1, r3
117 rfi
118
Ramneek Mehresh7cad2072014-01-03 12:11:55 +0530119 .globl get_svr
120get_svr:
121 mfspr r3, SVR
122 blr
123
Ron Madrid787b61d2008-12-12 13:12:45 -0800124 .globl get_pvr
125get_pvr:
126 mfspr r3, PVR
127 blr
128
129 .globl ppcDWstore
130ppcDWstore:
131 lfd 1, 0(r4)
132 stfd 1, 0(r3)
133 blr
134
135 .globl ppcDWload
136ppcDWload:
137 lfd 1, 0(r3)
138 stfd 1, 0(r4)
139 blr
Eran Liberty9095d4a2005-07-28 10:08:46 -0500140
Eran Liberty9095d4a2005-07-28 10:08:46 -0500141#ifndef CONFIG_DEFAULT_IMMR
142#error CONFIG_DEFAULT_IMMR must be defined
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200143#endif /* CONFIG_SYS_DEFAULT_IMMR */
144#ifndef CONFIG_SYS_IMMR
145#define CONFIG_SYS_IMMR CONFIG_DEFAULT_IMMR
146#endif /* CONFIG_SYS_IMMR */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500147
148/*
149 * After configuration, a system reset exception is executed using the
150 * vector at offset 0x100 relative to the base set by MSR[IP]. If
151 * MSR[IP] is 0, the base address is 0x00000000. If MSR[IP] is 1, the
152 * base address is 0xfff00000. In the case of a Power On Reset or Hard
153 * Reset, the value of MSR[IP] is determined by the CIP field in the
154 * HRCW.
155 *
156 * Other bits in the HRCW set up the Base Address and Port Size in BR0.
157 * This determines the location of the boot ROM (flash or EPROM) in the
158 * processor's address space at boot time. As long as the HRCW is set up
159 * so that we eventually end up executing the code below when the
160 * processor executes the reset exception, the actual values used should
161 * not matter.
162 *
163 * Once we have got here, the address mask in OR0 is cleared so that the
164 * bottom 32K of the boot ROM is effectively repeated all throughout the
165 * processor's address space, after which we can jump to the absolute
166 * address at which the boot ROM was linked at compile time, and proceed
167 * to initialise the memory controller without worrying if the rug will
168 * be pulled out from under us, so to speak (it will be fine as long as
169 * we configure BR0 with the same boot ROM link address).
170 */
171 . = EXC_OFF_SYS_RESET
172
173 .globl _start
174_start: /* time t 0 */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500175 lis r4, CONFIG_DEFAULT_IMMR@h
176 nop
Peter Tyser0c44caf2010-09-14 19:13:53 -0500177
Eran Liberty9095d4a2005-07-28 10:08:46 -0500178 mfmsr r5 /* save msr contents */
Scott Wood838450e2009-01-20 11:56:11 -0600179
180 /* 83xx manuals prescribe a specific sequence for updating IMMRBAR. */
181 bl 1f
1821: mflr r7
183
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200184 lis r3, CONFIG_SYS_IMMR@h
185 ori r3, r3, CONFIG_SYS_IMMR@l
Scott Wood838450e2009-01-20 11:56:11 -0600186
187 lwz r6, IMMRBAR(r4)
188 isync
189
Eran Liberty9095d4a2005-07-28 10:08:46 -0500190 stw r3, IMMRBAR(r4)
Scott Wood838450e2009-01-20 11:56:11 -0600191 lwz r6, 0(r7) /* Arbitrary external load */
192 isync
193
194 lwz r6, IMMRBAR(r3)
195 isync
Jon Loeligerebc72242005-08-01 13:20:47 -0500196
Eran Liberty9095d4a2005-07-28 10:08:46 -0500197 /* Initialise the E300 processor core */
198 /*------------------------------------------*/
Jon Loeligerebc72242005-08-01 13:20:47 -0500199
Scott Wood2b36fbb2012-12-06 13:33:17 +0000200#if (defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_MPC83XX_WAIT_FOR_NAND)) || \
201 defined(CONFIG_NAND_SPL)
Lepcha Suchit7ed421f2008-10-16 13:38:00 -0500202 /* The FCM begins execution after only the first page
203 * is loaded. Wait for the rest before branching
204 * to another flash page.
205 */
Scott Wood838450e2009-01-20 11:56:11 -06002061: lwz r6, 0x50b0(r3)
Lepcha Suchit7ed421f2008-10-16 13:38:00 -0500207 andi. r6, r6, 1
208 beq 1b
209#endif
210
Eran Liberty9095d4a2005-07-28 10:08:46 -0500211 bl init_e300_core
Jon Loeligerebc72242005-08-01 13:20:47 -0500212
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200213#ifdef CONFIG_SYS_FLASHBOOT
Eran Liberty9095d4a2005-07-28 10:08:46 -0500214
215 /* Inflate flash location so it appears everywhere, calculate */
216 /* the absolute address in final location of the FLASH, jump */
217 /* there and deflate the flash size back to minimal size */
218 /*------------------------------------------------------------*/
219 bl map_flash_by_law1
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200220 lis r4, (CONFIG_SYS_MONITOR_BASE)@h
221 ori r4, r4, (CONFIG_SYS_MONITOR_BASE)@l
Eran Liberty9095d4a2005-07-28 10:08:46 -0500222 addi r5, r4, in_flash - _start + EXC_OFF_SYS_RESET
223 mtlr r5
224 blr
225in_flash:
226#if 1 /* Remapping flash with LAW0. */
227 bl remap_flash_by_law0
228#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200229#endif /* CONFIG_SYS_FLASHBOOT */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500230
Kumar Galad5d94d62006-02-10 15:40:06 -0600231 /* setup the bats */
232 bl setup_bats
233 sync
234
235 /*
236 * Cache must be enabled here for stack-in-cache trick.
237 * This means we need to enable the BATS.
238 * This means:
239 * 1) for the EVB, original gt regs need to be mapped
240 * 2) need to have an IBAT for the 0xf region,
241 * we are running there!
242 * Cache should be turned on after BATs, since by default
243 * everything is write-through.
244 * The init-mem BAT can be reused after reloc. The old
245 * gt-regs BAT can be reused after board_init_f calls
246 * board_early_init_f (EVB only).
247 */
248 /* enable address translation */
249 bl enable_addr_trans
250 sync
251
Nick Spence7c20aef2008-08-28 14:09:25 -0700252 /* enable the data cache */
Kumar Galad5d94d62006-02-10 15:40:06 -0600253 bl dcache_enable
254 sync
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200255#ifdef CONFIG_SYS_INIT_RAM_LOCK
Kumar Galad5d94d62006-02-10 15:40:06 -0600256 bl lock_ram_in_cache
257 sync
258#endif
259
260 /* set up the stack pointer in our newly created
mario.six@gdsys.ccd4f4a542017-01-17 08:33:47 +0100261 * cache-ram; use r3 to keep the new SP for now to
262 * avoid overiding the SP it uselessly */
263 lis r3, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET)@h
264 ori r3, r3, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET)@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600265
mario.six@gdsys.cc85df7b42017-01-17 08:33:48 +0100266 /* r4 = end of GD area */
267 addi r4, r3, GENERATED_GBL_DATA_SIZE
268
269 /* Zero GD area */
270 li r0, 0
2711:
272 subi r4, r4, 1
273 stb r0, 0(r4)
274 cmplw r3, r4
275 bne 1b
276
277#ifdef CONFIG_SYS_MALLOC_F_LEN
278
279#if CONFIG_SYS_MALLOC_F_LEN + GENERATED_GBL_DATA_SIZE > CONFIG_SYS_INIT_RAM_SIZE
280#error "CONFIG_SYS_MALLOC_F_LEN too large to fit into initial RAM."
281#endif
282
283 /* r3 = new stack pointer / pre-reloc malloc area */
284 subi r3, r3, CONFIG_SYS_MALLOC_F_LEN
285
286 /* Set pointer to pre-reloc malloc area in GD */
287 stw r3, GD_MALLOC_BASE(r4)
288#endif
Kumar Galad5d94d62006-02-10 15:40:06 -0600289 li r0, 0 /* Make room for stack frame header and */
mario.six@gdsys.ccd4f4a542017-01-17 08:33:47 +0100290 stwu r0, -4(r3) /* clear final stack frame so that */
291 stwu r0, -4(r3) /* stack backtraces terminate cleanly */
Kumar Galad5d94d62006-02-10 15:40:06 -0600292
mario.six@gdsys.ccd4f4a542017-01-17 08:33:47 +0100293 /* Finally, actually set SP */
294 mr r1, r3
Eran Liberty9095d4a2005-07-28 10:08:46 -0500295
296 /* let the C-code set up the rest */
Kumar Galad5d94d62006-02-10 15:40:06 -0600297 /* */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500298 /* Be careful to keep code relocatable & stack humble */
299 /*------------------------------------------------------*/
300
301 GET_GOT /* initialize GOT access */
Wolfgang Denkb2d36ea2011-04-20 22:11:21 +0200302
Eran Liberty9095d4a2005-07-28 10:08:46 -0500303 /* r3: IMMR */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200304 lis r3, CONFIG_SYS_IMMR@h
Eran Liberty9095d4a2005-07-28 10:08:46 -0500305 /* run low-level CPU init code (in Flash)*/
306 bl cpu_init_f
307
Eran Liberty9095d4a2005-07-28 10:08:46 -0500308 /* run 1st part of board init code (in Flash)*/
Valentin Longchampe91e10a2014-10-03 11:45:23 +0200309 li r3, 0 /* clear boot_flag for calling board_init_f */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500310 bl board_init_f
311
Peter Tyser0c44caf2010-09-14 19:13:53 -0500312 /* NOTREACHED - board_init_f() does not return */
313
Scott Wood2b36fbb2012-12-06 13:33:17 +0000314#ifndef MINIMAL_SPL
Eran Liberty9095d4a2005-07-28 10:08:46 -0500315/*
316 * Vector Table
317 */
318
319 .globl _start_of_vectors
320_start_of_vectors:
321
322/* Machine check */
323 STD_EXCEPTION(0x200, MachineCheck, MachineCheckException)
324
325/* Data Storage exception. */
326 STD_EXCEPTION(0x300, DataStorage, UnknownException)
327
328/* Instruction Storage exception. */
329 STD_EXCEPTION(0x400, InstStorage, UnknownException)
330
331/* External Interrupt exception. */
332#ifndef FIXME
333 STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
Jon Loeligerebc72242005-08-01 13:20:47 -0500334#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -0500335
336/* Alignment exception. */
337 . = 0x600
338Alignment:
Rafal Jaworowski06244e42007-06-22 14:58:04 +0200339 EXCEPTION_PROLOG(SRR0, SRR1)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500340 mfspr r4,DAR
341 stw r4,_DAR(r21)
342 mfspr r5,DSISR
343 stw r5,_DSISR(r21)
344 addi r3,r1,STACK_FRAME_OVERHEAD
Joakim Tjernlund4ff6bc02010-01-19 14:41:55 +0100345 EXC_XFER_TEMPLATE(Alignment, AlignmentException, MSR_KERNEL, COPY_EE)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500346
347/* Program check exception */
348 . = 0x700
349ProgramCheck:
Rafal Jaworowski06244e42007-06-22 14:58:04 +0200350 EXCEPTION_PROLOG(SRR0, SRR1)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500351 addi r3,r1,STACK_FRAME_OVERHEAD
Joakim Tjernlund4ff6bc02010-01-19 14:41:55 +0100352 EXC_XFER_TEMPLATE(ProgramCheck, ProgramCheckException,
353 MSR_KERNEL, COPY_EE)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500354
355 STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
356
357 /* I guess we could implement decrementer, and may have
358 * to someday for timekeeping.
359 */
360 STD_EXCEPTION(0x900, Decrementer, timer_interrupt)
361
362 STD_EXCEPTION(0xa00, Trap_0a, UnknownException)
363 STD_EXCEPTION(0xb00, Trap_0b, UnknownException)
364 STD_EXCEPTION(0xc00, SystemCall, UnknownException)
365 STD_EXCEPTION(0xd00, SingleStep, UnknownException)
366
367 STD_EXCEPTION(0xe00, Trap_0e, UnknownException)
368 STD_EXCEPTION(0xf00, Trap_0f, UnknownException)
369
370 STD_EXCEPTION(0x1000, InstructionTLBMiss, UnknownException)
371 STD_EXCEPTION(0x1100, DataLoadTLBMiss, UnknownException)
372 STD_EXCEPTION(0x1200, DataStoreTLBMiss, UnknownException)
373#ifdef DEBUG
374 . = 0x1300
375 /*
376 * This exception occurs when the program counter matches the
377 * Instruction Address Breakpoint Register (IABR).
378 *
379 * I want the cpu to halt if this occurs so I can hunt around
380 * with the debugger and look at things.
381 *
382 * When DEBUG is defined, both machine check enable (in the MSR)
383 * and checkstop reset enable (in the reset mode register) are
384 * turned off and so a checkstop condition will result in the cpu
385 * halting.
386 *
387 * I force the cpu into a checkstop condition by putting an illegal
388 * instruction here (at least this is the theory).
389 *
390 * well - that didnt work, so just do an infinite loop!
391 */
3921: b 1b
393#else
394 STD_EXCEPTION(0x1300, InstructionBreakpoint, DebugException)
395#endif
396 STD_EXCEPTION(0x1400, SMI, UnknownException)
397
398 STD_EXCEPTION(0x1500, Trap_15, UnknownException)
399 STD_EXCEPTION(0x1600, Trap_16, UnknownException)
400 STD_EXCEPTION(0x1700, Trap_17, UnknownException)
401 STD_EXCEPTION(0x1800, Trap_18, UnknownException)
402 STD_EXCEPTION(0x1900, Trap_19, UnknownException)
403 STD_EXCEPTION(0x1a00, Trap_1a, UnknownException)
404 STD_EXCEPTION(0x1b00, Trap_1b, UnknownException)
405 STD_EXCEPTION(0x1c00, Trap_1c, UnknownException)
406 STD_EXCEPTION(0x1d00, Trap_1d, UnknownException)
407 STD_EXCEPTION(0x1e00, Trap_1e, UnknownException)
408 STD_EXCEPTION(0x1f00, Trap_1f, UnknownException)
409 STD_EXCEPTION(0x2000, Trap_20, UnknownException)
410 STD_EXCEPTION(0x2100, Trap_21, UnknownException)
411 STD_EXCEPTION(0x2200, Trap_22, UnknownException)
412 STD_EXCEPTION(0x2300, Trap_23, UnknownException)
413 STD_EXCEPTION(0x2400, Trap_24, UnknownException)
414 STD_EXCEPTION(0x2500, Trap_25, UnknownException)
415 STD_EXCEPTION(0x2600, Trap_26, UnknownException)
416 STD_EXCEPTION(0x2700, Trap_27, UnknownException)
417 STD_EXCEPTION(0x2800, Trap_28, UnknownException)
418 STD_EXCEPTION(0x2900, Trap_29, UnknownException)
419 STD_EXCEPTION(0x2a00, Trap_2a, UnknownException)
420 STD_EXCEPTION(0x2b00, Trap_2b, UnknownException)
421 STD_EXCEPTION(0x2c00, Trap_2c, UnknownException)
422 STD_EXCEPTION(0x2d00, Trap_2d, UnknownException)
423 STD_EXCEPTION(0x2e00, Trap_2e, UnknownException)
424 STD_EXCEPTION(0x2f00, Trap_2f, UnknownException)
425
426
427 .globl _end_of_vectors
428_end_of_vectors:
429
430 . = 0x3000
431
432/*
433 * This code finishes saving the registers to the exception frame
434 * and jumps to the appropriate handler for the exception.
435 * Register r21 is pointer into trap frame, r1 has new stack pointer.
436 */
437 .globl transfer_to_handler
438transfer_to_handler:
439 stw r22,_NIP(r21)
440 lis r22,MSR_POW@h
441 andc r23,r23,r22
442 stw r23,_MSR(r21)
443 SAVE_GPR(7, r21)
444 SAVE_4GPRS(8, r21)
445 SAVE_8GPRS(12, r21)
446 SAVE_8GPRS(24, r21)
447 mflr r23
448 andi. r24,r23,0x3f00 /* get vector offset */
449 stw r24,TRAP(r21)
450 li r22,0
451 stw r22,RESULT(r21)
452 lwz r24,0(r23) /* virtual address of handler */
453 lwz r23,4(r23) /* where to go when done */
454 mtspr SRR0,r24
455 mtspr SRR1,r20
456 mtlr r23
457 SYNC
458 rfi /* jump to handler, enable MMU */
459
460int_return:
461 mfmsr r28 /* Disable interrupts */
462 li r4,0
463 ori r4,r4,MSR_EE
464 andc r28,r28,r4
465 SYNC /* Some chip revs need this... */
466 mtmsr r28
467 SYNC
468 lwz r2,_CTR(r1)
469 lwz r0,_LINK(r1)
470 mtctr r2
471 mtlr r0
472 lwz r2,_XER(r1)
473 lwz r0,_CCR(r1)
474 mtspr XER,r2
475 mtcrf 0xFF,r0
476 REST_10GPRS(3, r1)
477 REST_10GPRS(13, r1)
478 REST_8GPRS(23, r1)
479 REST_GPR(31, r1)
480 lwz r2,_NIP(r1) /* Restore environment */
481 lwz r0,_MSR(r1)
482 mtspr SRR0,r2
483 mtspr SRR1,r0
484 lwz r0,GPR0(r1)
485 lwz r2,GPR2(r1)
486 lwz r1,GPR1(r1)
487 SYNC
488 rfi
Scott Wood2b36fbb2012-12-06 13:33:17 +0000489#endif /* !MINIMAL_SPL */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500490
491/*
492 * This code initialises the E300 processor core
493 * (conforms to PowerPC 603e spec)
494 * Note: expects original MSR contents to be in r5.
495 */
496 .globl init_e300_core
497init_e300_core: /* time t 10 */
498 /* Initialize machine status; enable machine check interrupt */
499 /*-----------------------------------------------------------*/
500
501 li r3, MSR_KERNEL /* Set ME and RI flags */
502 rlwimi r3, r5, 0, 25, 25 /* preserve IP bit set by HRCW */
503#ifdef DEBUG
504 rlwimi r3, r5, 0, 21, 22 /* debugger might set SE & BE bits */
505#endif
506 SYNC /* Some chip revs need this... */
507 mtmsr r3
508 SYNC
509 mtspr SRR1, r3 /* Make SRR1 match MSR */
510
511
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200512 lis r3, CONFIG_SYS_IMMR@h
Eran Liberty9095d4a2005-07-28 10:08:46 -0500513#if defined(CONFIG_WATCHDOG)
Horst Kronstorfer4565e042010-05-18 10:37:05 +0200514 /* Initialise the Watchdog values and reset it (if req) */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500515 /*------------------------------------------------------*/
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200516 lis r4, CONFIG_SYS_WATCHDOG_VALUE
Eran Liberty9095d4a2005-07-28 10:08:46 -0500517 ori r4, r4, (SWCRR_SWEN | SWCRR_SWRI | SWCRR_SWPR)
518 stw r4, SWCRR(r3)
Jon Loeligerebc72242005-08-01 13:20:47 -0500519
Eran Liberty9095d4a2005-07-28 10:08:46 -0500520 /* and reset it */
Jon Loeligerebc72242005-08-01 13:20:47 -0500521
Eran Liberty9095d4a2005-07-28 10:08:46 -0500522 li r4, 0x556C
523 sth r4, SWSRR@l(r3)
Heiko Schocher6dfb2e52008-01-11 15:15:17 +0100524 li r4, -0x55C7
Eran Liberty9095d4a2005-07-28 10:08:46 -0500525 sth r4, SWSRR@l(r3)
526#else
Horst Kronstorfer4565e042010-05-18 10:37:05 +0200527 /* Disable Watchdog */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500528 /*-------------------*/
Kumar Galab42751c2006-01-11 11:23:01 -0600529 lwz r4, SWCRR(r3)
530 /* Check to see if its enabled for disabling
531 once disabled by SW you can't re-enable */
532 andi. r4, r4, 0x4
533 beq 1f
Eran Liberty9095d4a2005-07-28 10:08:46 -0500534 xor r4, r4, r4
535 stw r4, SWCRR(r3)
Kumar Galab42751c2006-01-11 11:23:01 -06005361:
Eran Liberty9095d4a2005-07-28 10:08:46 -0500537#endif /* CONFIG_WATCHDOG */
538
Nick Spence56fd3c22008-08-28 14:09:19 -0700539#if defined(CONFIG_MASK_AER_AO)
540 /* Write the Arbiter Event Enable to mask Address Only traps. */
541 /* This prevents the dcbz instruction from being trapped when */
542 /* HID0_ABE Address Broadcast Enable is set and the MEMORY */
543 /* COHERENCY bit is set in the WIMG bits, which is often */
544 /* needed for PCI operation. */
545 lwz r4, 0x0808(r3)
546 rlwinm r0, r4, 0, ~AER_AO
547 stw r0, 0x0808(r3)
548#endif /* CONFIG_MASK_AER_AO */
549
Eran Liberty9095d4a2005-07-28 10:08:46 -0500550 /* Initialize the Hardware Implementation-dependent Registers */
551 /* HID0 also contains cache control */
Nick Spence7c20aef2008-08-28 14:09:25 -0700552 /* - force invalidation of data and instruction caches */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500553 /*------------------------------------------------------*/
554
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200555 lis r3, CONFIG_SYS_HID0_INIT@h
556 ori r3, r3, (CONFIG_SYS_HID0_INIT | 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_HID0_FINAL@h
561 ori r3, r3, (CONFIG_SYS_HID0_FINAL & ~(HID0_ICFI | HID0_DCFI))@l
Eran Liberty9095d4a2005-07-28 10:08:46 -0500562 SYNC
563 mtspr HID0, r3
564
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200565 lis r3, CONFIG_SYS_HID2@h
566 ori r3, r3, CONFIG_SYS_HID2@l
Eran Liberty9095d4a2005-07-28 10:08:46 -0500567 SYNC
568 mtspr HID2, r3
569
Eran Liberty9095d4a2005-07-28 10:08:46 -0500570 /* Done! */
571 /*------------------------------*/
Jon Loeligerebc72242005-08-01 13:20:47 -0500572 blr
Eran Liberty9095d4a2005-07-28 10:08:46 -0500573
Kumar Galad5d94d62006-02-10 15:40:06 -0600574 /* setup_bats - set them up to some initial state */
575 .globl setup_bats
576setup_bats:
577 addis r0, r0, 0x0000
578
579 /* IBAT 0 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200580 addis r4, r0, CONFIG_SYS_IBAT0L@h
581 ori r4, r4, CONFIG_SYS_IBAT0L@l
582 addis r3, r0, CONFIG_SYS_IBAT0U@h
583 ori r3, r3, CONFIG_SYS_IBAT0U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600584 mtspr IBAT0L, r4
585 mtspr IBAT0U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600586
587 /* DBAT 0 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200588 addis r4, r0, CONFIG_SYS_DBAT0L@h
589 ori r4, r4, CONFIG_SYS_DBAT0L@l
590 addis r3, r0, CONFIG_SYS_DBAT0U@h
591 ori r3, r3, CONFIG_SYS_DBAT0U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600592 mtspr DBAT0L, r4
593 mtspr DBAT0U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600594
595 /* IBAT 1 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200596 addis r4, r0, CONFIG_SYS_IBAT1L@h
597 ori r4, r4, CONFIG_SYS_IBAT1L@l
598 addis r3, r0, CONFIG_SYS_IBAT1U@h
599 ori r3, r3, CONFIG_SYS_IBAT1U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600600 mtspr IBAT1L, r4
601 mtspr IBAT1U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600602
603 /* DBAT 1 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200604 addis r4, r0, CONFIG_SYS_DBAT1L@h
605 ori r4, r4, CONFIG_SYS_DBAT1L@l
606 addis r3, r0, CONFIG_SYS_DBAT1U@h
607 ori r3, r3, CONFIG_SYS_DBAT1U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600608 mtspr DBAT1L, r4
609 mtspr DBAT1U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600610
611 /* IBAT 2 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200612 addis r4, r0, CONFIG_SYS_IBAT2L@h
613 ori r4, r4, CONFIG_SYS_IBAT2L@l
614 addis r3, r0, CONFIG_SYS_IBAT2U@h
615 ori r3, r3, CONFIG_SYS_IBAT2U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600616 mtspr IBAT2L, r4
617 mtspr IBAT2U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600618
619 /* DBAT 2 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200620 addis r4, r0, CONFIG_SYS_DBAT2L@h
621 ori r4, r4, CONFIG_SYS_DBAT2L@l
622 addis r3, r0, CONFIG_SYS_DBAT2U@h
623 ori r3, r3, CONFIG_SYS_DBAT2U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600624 mtspr DBAT2L, r4
625 mtspr DBAT2U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600626
627 /* IBAT 3 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200628 addis r4, r0, CONFIG_SYS_IBAT3L@h
629 ori r4, r4, CONFIG_SYS_IBAT3L@l
630 addis r3, r0, CONFIG_SYS_IBAT3U@h
631 ori r3, r3, CONFIG_SYS_IBAT3U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600632 mtspr IBAT3L, r4
633 mtspr IBAT3U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600634
635 /* DBAT 3 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200636 addis r4, r0, CONFIG_SYS_DBAT3L@h
637 ori r4, r4, CONFIG_SYS_DBAT3L@l
638 addis r3, r0, CONFIG_SYS_DBAT3U@h
639 ori r3, r3, CONFIG_SYS_DBAT3U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600640 mtspr DBAT3L, r4
641 mtspr DBAT3U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600642
Becky Bruce03ea1be2008-05-08 19:02:12 -0500643#ifdef CONFIG_HIGH_BATS
Kumar Galad5d94d62006-02-10 15:40:06 -0600644 /* IBAT 4 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200645 addis r4, r0, CONFIG_SYS_IBAT4L@h
646 ori r4, r4, CONFIG_SYS_IBAT4L@l
647 addis r3, r0, CONFIG_SYS_IBAT4U@h
648 ori r3, r3, CONFIG_SYS_IBAT4U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600649 mtspr IBAT4L, r4
650 mtspr IBAT4U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600651
652 /* DBAT 4 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200653 addis r4, r0, CONFIG_SYS_DBAT4L@h
654 ori r4, r4, CONFIG_SYS_DBAT4L@l
655 addis r3, r0, CONFIG_SYS_DBAT4U@h
656 ori r3, r3, CONFIG_SYS_DBAT4U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600657 mtspr DBAT4L, r4
658 mtspr DBAT4U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600659
660 /* IBAT 5 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200661 addis r4, r0, CONFIG_SYS_IBAT5L@h
662 ori r4, r4, CONFIG_SYS_IBAT5L@l
663 addis r3, r0, CONFIG_SYS_IBAT5U@h
664 ori r3, r3, CONFIG_SYS_IBAT5U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600665 mtspr IBAT5L, r4
666 mtspr IBAT5U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600667
668 /* DBAT 5 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200669 addis r4, r0, CONFIG_SYS_DBAT5L@h
670 ori r4, r4, CONFIG_SYS_DBAT5L@l
671 addis r3, r0, CONFIG_SYS_DBAT5U@h
672 ori r3, r3, CONFIG_SYS_DBAT5U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600673 mtspr DBAT5L, r4
674 mtspr DBAT5U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600675
676 /* IBAT 6 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200677 addis r4, r0, CONFIG_SYS_IBAT6L@h
678 ori r4, r4, CONFIG_SYS_IBAT6L@l
679 addis r3, r0, CONFIG_SYS_IBAT6U@h
680 ori r3, r3, CONFIG_SYS_IBAT6U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600681 mtspr IBAT6L, r4
682 mtspr IBAT6U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600683
684 /* DBAT 6 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200685 addis r4, r0, CONFIG_SYS_DBAT6L@h
686 ori r4, r4, CONFIG_SYS_DBAT6L@l
687 addis r3, r0, CONFIG_SYS_DBAT6U@h
688 ori r3, r3, CONFIG_SYS_DBAT6U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600689 mtspr DBAT6L, r4
690 mtspr DBAT6U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600691
692 /* IBAT 7 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200693 addis r4, r0, CONFIG_SYS_IBAT7L@h
694 ori r4, r4, CONFIG_SYS_IBAT7L@l
695 addis r3, r0, CONFIG_SYS_IBAT7U@h
696 ori r3, r3, CONFIG_SYS_IBAT7U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600697 mtspr IBAT7L, r4
698 mtspr IBAT7U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600699
700 /* DBAT 7 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200701 addis r4, r0, CONFIG_SYS_DBAT7L@h
702 ori r4, r4, CONFIG_SYS_DBAT7L@l
703 addis r3, r0, CONFIG_SYS_DBAT7U@h
704 ori r3, r3, CONFIG_SYS_DBAT7U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600705 mtspr DBAT7L, r4
706 mtspr DBAT7U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600707#endif
708
Scott Woodb71689b2008-06-30 14:13:28 -0500709 isync
710
711 /* invalidate all tlb's
712 *
713 * From the 603e User Manual: "The 603e provides the ability to
714 * invalidate a TLB entry. The TLB Invalidate Entry (tlbie)
715 * instruction invalidates the TLB entry indexed by the EA, and
716 * operates on both the instruction and data TLBs simultaneously
717 * invalidating four TLB entries (both sets in each TLB). The
718 * index corresponds to bits 15-19 of the EA. To invalidate all
719 * entries within both TLBs, 32 tlbie instructions should be
720 * issued, incrementing this field by one each time."
721 *
722 * "Note that the tlbia instruction is not implemented on the
723 * 603e."
724 *
725 * bits 15-19 correspond to addresses 0x00000000 to 0x0001F000
726 * incrementing by 0x1000 each time. The code below is sort of
Stefan Roese88fbf932010-04-15 16:07:28 +0200727 * based on code in "flush_tlbs" from arch/powerpc/kernel/head.S
Scott Woodb71689b2008-06-30 14:13:28 -0500728 *
Kumar Galad5d94d62006-02-10 15:40:06 -0600729 */
730 lis r3, 0
731 lis r5, 2
732
7331:
734 tlbie r3
735 addi r3, r3, 0x1000
736 cmp 0, 0, r3, r5
737 blt 1b
738
739 blr
740
Eran Liberty9095d4a2005-07-28 10:08:46 -0500741/* Cache functions.
742 *
743 * Note: requires that all cache bits in
744 * HID0 are in the low half word.
745 */
Scott Wood2b36fbb2012-12-06 13:33:17 +0000746#ifndef MINIMAL_SPL
Eran Liberty9095d4a2005-07-28 10:08:46 -0500747 .globl icache_enable
748icache_enable:
749 mfspr r3, HID0
750 ori r3, r3, HID0_ICE
Nick Spence7c20aef2008-08-28 14:09:25 -0700751 li r4, HID0_ICFI|HID0_ILOCK
Eran Liberty9095d4a2005-07-28 10:08:46 -0500752 andc r3, r3, r4
753 ori r4, r3, HID0_ICFI
754 isync
755 mtspr HID0, r4 /* sets enable and invalidate, clears lock */
756 isync
757 mtspr HID0, r3 /* clears invalidate */
758 blr
759
760 .globl icache_disable
761icache_disable:
762 mfspr r3, HID0
763 lis r4, 0
Nick Spence7c20aef2008-08-28 14:09:25 -0700764 ori r4, r4, HID0_ICE|HID0_ICFI|HID0_ILOCK
Eran Liberty9095d4a2005-07-28 10:08:46 -0500765 andc r3, r3, r4
Eran Liberty9095d4a2005-07-28 10:08:46 -0500766 isync
Nick Spence7c20aef2008-08-28 14:09:25 -0700767 mtspr HID0, r3 /* clears invalidate, enable and lock */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500768 blr
769
770 .globl icache_status
771icache_status:
772 mfspr r3, HID0
Marian Balakowicz758e5d32006-03-14 16:01:25 +0100773 rlwinm r3, r3, (31 - HID0_ICE_SHIFT + 1), 31, 31
Eran Liberty9095d4a2005-07-28 10:08:46 -0500774 blr
Scott Wood2b36fbb2012-12-06 13:33:17 +0000775#endif /* !MINIMAL_SPL */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500776
777 .globl dcache_enable
778dcache_enable:
779 mfspr r3, HID0
Kumar Galad5d94d62006-02-10 15:40:06 -0600780 li r5, HID0_DCFI|HID0_DLOCK
781 andc r3, r3, r5
Kumar Galad5d94d62006-02-10 15:40:06 -0600782 ori r3, r3, HID0_DCE
Eran Liberty9095d4a2005-07-28 10:08:46 -0500783 sync
Nick Spence7c20aef2008-08-28 14:09:25 -0700784 mtspr HID0, r3 /* enable, no invalidate */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500785 blr
786
787 .globl dcache_disable
788dcache_disable:
Nick Spence7c20aef2008-08-28 14:09:25 -0700789 mflr r4
790 bl flush_dcache /* uses r3 and r5 */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500791 mfspr r3, HID0
Nick Spence7c20aef2008-08-28 14:09:25 -0700792 li r5, HID0_DCE|HID0_DLOCK
793 andc r3, r3, r5
794 ori r5, r3, HID0_DCFI
Eran Liberty9095d4a2005-07-28 10:08:46 -0500795 sync
Nick Spence7c20aef2008-08-28 14:09:25 -0700796 mtspr HID0, r5 /* sets invalidate, clears enable and lock */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500797 sync
798 mtspr HID0, r3 /* clears invalidate */
Nick Spence7c20aef2008-08-28 14:09:25 -0700799 mtlr r4
Eran Liberty9095d4a2005-07-28 10:08:46 -0500800 blr
801
802 .globl dcache_status
803dcache_status:
804 mfspr r3, HID0
Marian Balakowicz758e5d32006-03-14 16:01:25 +0100805 rlwinm r3, r3, (31 - HID0_DCE_SHIFT + 1), 31, 31
Eran Liberty9095d4a2005-07-28 10:08:46 -0500806 blr
807
Nick Spence7c20aef2008-08-28 14:09:25 -0700808 .globl flush_dcache
809flush_dcache:
810 lis r3, 0
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200811 lis r5, CONFIG_SYS_CACHELINE_SIZE
Nick Spence7c20aef2008-08-28 14:09:25 -07008121: cmp 0, 1, r3, r5
813 bge 2f
814 lwz r5, 0(r3)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200815 lis r5, CONFIG_SYS_CACHELINE_SIZE
Nick Spence7c20aef2008-08-28 14:09:25 -0700816 addi r3, r3, 0x4
817 b 1b
8182: blr
819
Eran Liberty9095d4a2005-07-28 10:08:46 -0500820/*-------------------------------------------------------------------*/
821
822/*
823 * void relocate_code (addr_sp, gd, addr_moni)
824 *
825 * This "function" does not return, instead it continues in RAM
826 * after relocating the monitor code.
827 *
828 * r3 = dest
829 * r4 = src
830 * r5 = length in bytes
831 * r6 = cachelinesize
832 */
833 .globl relocate_code
834relocate_code:
835 mr r1, r3 /* Set new stack pointer */
836 mr r9, r4 /* Save copy of Global Data pointer */
837 mr r10, r5 /* Save copy of Destination Address */
838
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +0100839 GET_GOT
Eran Liberty9095d4a2005-07-28 10:08:46 -0500840 mr r3, r5 /* Destination Address */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200841 lis r4, CONFIG_SYS_MONITOR_BASE@h /* Source Address */
842 ori r4, r4, CONFIG_SYS_MONITOR_BASE@l
Scott Woodb71689b2008-06-30 14:13:28 -0500843 lwz r5, GOT(__bss_start)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500844 sub r5, r5, r4
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200845 li r6, CONFIG_SYS_CACHELINE_SIZE /* Cache Line Size */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500846
847 /*
848 * Fix GOT pointer:
849 *
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200850 * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500851 * + Destination Address
852 *
853 * Offset:
854 */
855 sub r15, r10, r4
856
857 /* First our own GOT */
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +0100858 add r12, r12, r15
Eran Liberty9095d4a2005-07-28 10:08:46 -0500859 /* then the one used by the C code */
860 add r30, r30, r15
861
862 /*
863 * Now relocate code
864 */
865
866 cmplw cr1,r3,r4
867 addi r0,r5,3
868 srwi. r0,r0,2
869 beq cr1,4f /* In place copy is not necessary */
870 beq 7f /* Protect against 0 count */
871 mtctr r0
872 bge cr1,2f
873 la r8,-4(r4)
874 la r7,-4(r3)
875
876 /* copy */
8771: lwzu r0,4(r8)
878 stwu r0,4(r7)
879 bdnz 1b
880
881 addi r0,r5,3
882 srwi. r0,r0,2
883 mtctr r0
884 la r8,-4(r4)
885 la r7,-4(r3)
Jon Loeligerebc72242005-08-01 13:20:47 -0500886
887 /* and compare */
Eran Liberty9095d4a2005-07-28 10:08:46 -050088820: lwzu r20,4(r8)
889 lwzu r21,4(r7)
890 xor. r22, r20, r21
891 bne 30f
892 bdnz 20b
893 b 4f
894
895 /* compare failed */
89630: li r3, 0
897 blr
898
8992: slwi r0,r0,2 /* re copy in reverse order ... y do we needed it? */
900 add r8,r4,r0
901 add r7,r3,r0
9023: lwzu r0,-4(r8)
903 stwu r0,-4(r7)
904 bdnz 3b
Eran Liberty9095d4a2005-07-28 10:08:46 -0500905
906/*
907 * Now flush the cache: note that we must start from a cache aligned
908 * address. Otherwise we might miss one cache line.
909 */
Kumar Galad5d94d62006-02-10 15:40:06 -06009104: cmpwi r6,0
Eran Liberty9095d4a2005-07-28 10:08:46 -0500911 add r5,r3,r5
Kumar Galad5d94d62006-02-10 15:40:06 -0600912 beq 7f /* Always flush prefetch queue in any case */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500913 subi r0,r6,1
914 andc r3,r3,r0
Eran Liberty9095d4a2005-07-28 10:08:46 -0500915 mr r4,r3
9165: dcbst 0,r4
917 add r4,r4,r6
918 cmplw r4,r5
919 blt 5b
Kumar Galad5d94d62006-02-10 15:40:06 -0600920 sync /* Wait for all dcbst to complete on bus */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500921 mr r4,r3
9226: icbi 0,r4
923 add r4,r4,r6
924 cmplw r4,r5
925 blt 6b
Kumar Galad5d94d62006-02-10 15:40:06 -06009267: sync /* Wait for all icbi to complete on bus */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500927 isync
928
929/*
930 * We are done. Do not return, instead branch to second part of board
931 * initialization, now running from RAM.
932 */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500933 addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
934 mtlr r0
935 blr
936
937in_ram:
938
939 /*
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +0100940 * Relocation Function, r12 point to got2+0x8000
Eran Liberty9095d4a2005-07-28 10:08:46 -0500941 *
942 * Adjust got2 pointers, no need to check for 0, this code
943 * already puts a few entries in the table.
944 */
945 li r0,__got2_entries@sectoff@l
946 la r3,GOT(_GOT2_TABLE_)
947 lwz r11,GOT(_GOT2_TABLE_)
948 mtctr r0
949 sub r11,r3,r11
950 addi r3,r3,-4
9511: lwzu r0,4(r3)
Joakim Tjernlund4f2fdac2009-10-08 02:03:51 +0200952 cmpwi r0,0
953 beq- 2f
Eran Liberty9095d4a2005-07-28 10:08:46 -0500954 add r0,r0,r11
955 stw r0,0(r3)
Joakim Tjernlund4f2fdac2009-10-08 02:03:51 +02009562: bdnz 1b
Eran Liberty9095d4a2005-07-28 10:08:46 -0500957
Scott Wood2b36fbb2012-12-06 13:33:17 +0000958#ifndef MINIMAL_SPL
Eran Liberty9095d4a2005-07-28 10:08:46 -0500959 /*
960 * Now adjust the fixups and the pointers to the fixups
961 * in case we need to move ourselves again.
962 */
Joakim Tjernlund4f2fdac2009-10-08 02:03:51 +0200963 li r0,__fixup_entries@sectoff@l
Eran Liberty9095d4a2005-07-28 10:08:46 -0500964 lwz r3,GOT(_FIXUP_TABLE_)
965 cmpwi r0,0
966 mtctr r0
967 addi r3,r3,-4
968 beq 4f
9693: lwzu r4,4(r3)
970 lwzux r0,r4,r11
Joakim Tjernlundc61b25a2010-10-14 11:51:44 +0200971 cmpwi r0,0
Eran Liberty9095d4a2005-07-28 10:08:46 -0500972 add r0,r0,r11
Joakim Tjernlund401b5922010-11-04 19:02:00 +0100973 stw r4,0(r3)
Joakim Tjernlundc61b25a2010-10-14 11:51:44 +0200974 beq- 5f
Eran Liberty9095d4a2005-07-28 10:08:46 -0500975 stw r0,0(r4)
Joakim Tjernlundc61b25a2010-10-14 11:51:44 +02009765: bdnz 3b
Eran Liberty9095d4a2005-07-28 10:08:46 -05009774:
Scott Woodb71689b2008-06-30 14:13:28 -0500978#endif
979
Eran Liberty9095d4a2005-07-28 10:08:46 -0500980clear_bss:
981 /*
982 * Now clear BSS segment
983 */
984 lwz r3,GOT(__bss_start)
Simon Glassed70c8f2013-03-14 06:54:53 +0000985 lwz r4,GOT(__bss_end)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500986
987 cmplw 0, r3, r4
988 beq 6f
989
990 li r0, 0
9915:
992 stw r0, 0(r3)
993 addi r3, r3, 4
994 cmplw 0, r3, r4
995 bne 5b
9966:
997
998 mr r3, r9 /* Global Data pointer */
999 mr r4, r10 /* Destination Address */
1000 bl board_init_r
1001
Scott Wood2b36fbb2012-12-06 13:33:17 +00001002#ifndef MINIMAL_SPL
Eran Liberty9095d4a2005-07-28 10:08:46 -05001003 /*
1004 * Copy exception vector code to low memory
1005 *
1006 * r3: dest_addr
1007 * r7: source address, r8: end address, r9: target address
1008 */
1009 .globl trap_init
1010trap_init:
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +01001011 mflr r4 /* save link register */
1012 GET_GOT
Eran Liberty9095d4a2005-07-28 10:08:46 -05001013 lwz r7, GOT(_start)
1014 lwz r8, GOT(_end_of_vectors)
1015
1016 li r9, 0x100 /* reset vector always at 0x100 */
1017
1018 cmplw 0, r7, r8
1019 bgelr /* return if r7>=r8 - just in case */
Eran Liberty9095d4a2005-07-28 10:08:46 -050010201:
1021 lwz r0, 0(r7)
1022 stw r0, 0(r9)
1023 addi r7, r7, 4
1024 addi r9, r9, 4
1025 cmplw 0, r7, r8
1026 bne 1b
1027
1028 /*
1029 * relocate `hdlr' and `int_return' entries
1030 */
1031 li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
1032 li r8, Alignment - _start + EXC_OFF_SYS_RESET
10332:
1034 bl trap_reloc
1035 addi r7, r7, 0x100 /* next exception vector */
1036 cmplw 0, r7, r8
1037 blt 2b
1038
1039 li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
1040 bl trap_reloc
1041
1042 li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
1043 bl trap_reloc
1044
1045 li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
1046 li r8, SystemCall - _start + EXC_OFF_SYS_RESET
10473:
1048 bl trap_reloc
1049 addi r7, r7, 0x100 /* next exception vector */
1050 cmplw 0, r7, r8
1051 blt 3b
1052
1053 li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
1054 li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
10554:
1056 bl trap_reloc
1057 addi r7, r7, 0x100 /* next exception vector */
1058 cmplw 0, r7, r8
1059 blt 4b
1060
1061 mfmsr r3 /* now that the vectors have */
1062 lis r7, MSR_IP@h /* relocated into low memory */
1063 ori r7, r7, MSR_IP@l /* MSR[IP] can be turned off */
1064 andc r3, r3, r7 /* (if it was on) */
1065 SYNC /* Some chip revs need this... */
1066 mtmsr r3
1067 SYNC
1068
1069 mtlr r4 /* restore link register */
1070 blr
1071
Scott Wood2b36fbb2012-12-06 13:33:17 +00001072#endif /* !MINIMAL_SPL */
Eran Liberty9095d4a2005-07-28 10:08:46 -05001073
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001074#ifdef CONFIG_SYS_INIT_RAM_LOCK
Kumar Galad5d94d62006-02-10 15:40:06 -06001075lock_ram_in_cache:
1076 /* Allocate Initial RAM in data cache.
1077 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001078 lis r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@h
1079 ori r3, r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@l
Wolfgang Denk1c2e98e2010-10-26 13:32:32 +02001080 li r4, ((CONFIG_SYS_INIT_RAM_SIZE & ~31) + \
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001081 (CONFIG_SYS_INIT_RAM_ADDR & 31) + 31) / 32
Nick Spenceb89d6fb2008-08-28 14:09:11 -07001082 mtctr r4
Kumar Galad5d94d62006-02-10 15:40:06 -060010831:
1084 dcbz r0, r3
1085 addi r3, r3, 32
1086 bdnz 1b
1087
1088 /* Lock the data cache */
1089 mfspr r0, HID0
Nick Spence7c20aef2008-08-28 14:09:25 -07001090 ori r0, r0, HID0_DLOCK
Kumar Galad5d94d62006-02-10 15:40:06 -06001091 sync
1092 mtspr HID0, r0
1093 sync
1094 blr
1095
Scott Wood2b36fbb2012-12-06 13:33:17 +00001096#ifndef MINIMAL_SPL
Eran Liberty9095d4a2005-07-28 10:08:46 -05001097.globl unlock_ram_in_cache
1098unlock_ram_in_cache:
1099 /* invalidate the INIT_RAM section */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001100 lis r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@h
1101 ori r3, r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@l
Wolfgang Denk1c2e98e2010-10-26 13:32:32 +02001102 li r4, ((CONFIG_SYS_INIT_RAM_SIZE & ~31) + \
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001103 (CONFIG_SYS_INIT_RAM_ADDR & 31) + 31) / 32
Nick Spenceb89d6fb2008-08-28 14:09:11 -07001104 mtctr r4
Eran Liberty9095d4a2005-07-28 10:08:46 -050011051: icbi r0, r3
1106 dcbi r0, r3
1107 addi r3, r3, 32
1108 bdnz 1b
1109 sync /* Wait for all icbi to complete on bus */
1110 isync
Kumar Galad5d94d62006-02-10 15:40:06 -06001111
1112 /* Unlock the data cache and invalidate it */
1113 mfspr r3, HID0
1114 li r5, HID0_DLOCK|HID0_DCFI
1115 andc r3, r3, r5 /* no invalidate, unlock */
1116 ori r5, r3, HID0_DCFI /* invalidate, unlock */
Nick Spence7c20aef2008-08-28 14:09:25 -07001117 sync
Kumar Galad5d94d62006-02-10 15:40:06 -06001118 mtspr HID0, r5 /* invalidate, unlock */
Kumar Galad5d94d62006-02-10 15:40:06 -06001119 sync
Nick Spence7c20aef2008-08-28 14:09:25 -07001120 mtspr HID0, r3 /* no invalidate, unlock */
Eran Liberty9095d4a2005-07-28 10:08:46 -05001121 blr
Scott Wood2b36fbb2012-12-06 13:33:17 +00001122#endif /* !MINIMAL_SPL */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001123#endif /* CONFIG_SYS_INIT_RAM_LOCK */
Eran Liberty9095d4a2005-07-28 10:08:46 -05001124
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001125#ifdef CONFIG_SYS_FLASHBOOT
Eran Liberty9095d4a2005-07-28 10:08:46 -05001126map_flash_by_law1:
1127 /* When booting from ROM (Flash or EPROM), clear the */
1128 /* Address Mask in OR0 so ROM appears everywhere */
1129 /*----------------------------------------------------*/
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001130 lis r3, (CONFIG_SYS_IMMR)@h /* r3 <= CONFIG_SYS_IMMR */
Jon Loeligerebc72242005-08-01 13:20:47 -05001131 lwz r4, OR0@l(r3)
Eran Liberty9095d4a2005-07-28 10:08:46 -05001132 li r5, 0x7fff /* r5 <= 0x00007FFFF */
Jon Loeligerebc72242005-08-01 13:20:47 -05001133 and r4, r4, r5
Eran Liberty9095d4a2005-07-28 10:08:46 -05001134 stw r4, OR0@l(r3) /* OR0 <= OR0 & 0x00007FFFF */
1135
1136 /* As MPC8349E User's Manual presented, when RCW[BMS] is set to 0,
1137 * system will boot from 0x0000_0100, and the LBLAWBAR0[BASE_ADDR]
1138 * reset value is 0x00000; when RCW[BMS] is set to 1, system will boot
1139 * from 0xFFF0_0100, and the LBLAWBAR0[BASE_ADDR] reset value is
1140 * 0xFF800. From the hard resetting to here, the processor fetched and
1141 * executed the instructions one by one. There is not absolutely
1142 * jumping happened. Laterly, the u-boot code has to do an absolutely
1143 * jumping to tell the CPU instruction fetching component what the
1144 * u-boot TEXT base address is. Because the TEXT base resides in the
1145 * boot ROM memory space, to garantee the code can run smoothly after
1146 * that jumping, we must map in the entire boot ROM by Local Access
1147 * Window. Sometimes, we desire an non-0x00000 or non-0xFF800 starting
1148 * address for boot ROM, such as 0xFE000000. In this case, the default
1149 * LBIU Local Access Widow 0 will not cover this memory space. So, we
1150 * need another window to map in it.
1151 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001152 lis r4, (CONFIG_SYS_FLASH_BASE)@h
1153 ori r4, r4, (CONFIG_SYS_FLASH_BASE)@l
1154 stw r4, LBLAWBAR1(r3) /* LBLAWBAR1 <= CONFIG_SYS_FLASH_BASE */
Timur Tabi53b46172006-08-22 17:07:00 -05001155
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001156 /* Store 0x80000012 + log2(CONFIG_SYS_FLASH_SIZE) into LBLAWAR1 */
Timur Tabi53b46172006-08-22 17:07:00 -05001157 lis r4, (0x80000012)@h
1158 ori r4, r4, (0x80000012)@l
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001159 li r5, CONFIG_SYS_FLASH_SIZE
Timur Tabi53b46172006-08-22 17:07:00 -050011601: srawi. r5, r5, 1 /* r5 = r5 >> 1 */
1161 addi r4, r4, 1
1162 bne 1b
1163
Eran Liberty9095d4a2005-07-28 10:08:46 -05001164 stw r4, LBLAWAR1(r3) /* LBLAWAR1 <= 8MB Flash Size */
Joakim Tjernlundb168d632010-11-19 14:15:33 +01001165 /* Wait for HW to catch up */
1166 lwz r4, LBLAWAR1(r3)
1167 twi 0,r4,0
1168 isync
Eran Liberty9095d4a2005-07-28 10:08:46 -05001169 blr
1170
1171 /* Though all the LBIU Local Access Windows and LBC Banks will be
1172 * initialized in the C code, we'd better configure boot ROM's
1173 * window 0 and bank 0 correctly at here.
1174 */
1175remap_flash_by_law0:
1176 /* Initialize the BR0 with the boot ROM starting address. */
1177 lwz r4, BR0(r3)
1178 li r5, 0x7FFF
Jon Loeligerebc72242005-08-01 13:20:47 -05001179 and r4, r4, r5
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001180 lis r5, (CONFIG_SYS_FLASH_BASE & 0xFFFF8000)@h
1181 ori r5, r5, (CONFIG_SYS_FLASH_BASE & 0xFFFF8000)@l
Eran Liberty9095d4a2005-07-28 10:08:46 -05001182 or r5, r5, r4
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001183 stw r5, BR0(r3) /* r5 <= (CONFIG_SYS_FLASH_BASE & 0xFFFF8000) | (BR0 & 0x00007FFF) */
Eran Liberty9095d4a2005-07-28 10:08:46 -05001184
1185 lwz r4, OR0(r3)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001186 lis r5, ~((CONFIG_SYS_FLASH_SIZE << 4) - 1)
Eran Liberty9095d4a2005-07-28 10:08:46 -05001187 or r4, r4, r5
Timur Tabi53b46172006-08-22 17:07:00 -05001188 stw r4, OR0(r3)
Eran Liberty9095d4a2005-07-28 10:08:46 -05001189
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001190 lis r4, (CONFIG_SYS_FLASH_BASE)@h
1191 ori r4, r4, (CONFIG_SYS_FLASH_BASE)@l
1192 stw r4, LBLAWBAR0(r3) /* LBLAWBAR0 <= CONFIG_SYS_FLASH_BASE */
Eran Liberty9095d4a2005-07-28 10:08:46 -05001193
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001194 /* Store 0x80000012 + log2(CONFIG_SYS_FLASH_SIZE) into LBLAWAR0 */
Timur Tabi53b46172006-08-22 17:07:00 -05001195 lis r4, (0x80000012)@h
1196 ori r4, r4, (0x80000012)@l
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001197 li r5, CONFIG_SYS_FLASH_SIZE
Timur Tabi53b46172006-08-22 17:07:00 -050011981: srawi. r5, r5, 1 /* r5 = r5 >> 1 */
1199 addi r4, r4, 1
1200 bne 1b
1201 stw r4, LBLAWAR0(r3) /* LBLAWAR0 <= Flash Size */
1202
Eran Liberty9095d4a2005-07-28 10:08:46 -05001203
1204 xor r4, r4, r4
1205 stw r4, LBLAWBAR1(r3)
1206 stw r4, LBLAWAR1(r3) /* Off LBIU LAW1 */
Joakim Tjernlundb168d632010-11-19 14:15:33 +01001207 /* Wait for HW to catch up */
1208 lwz r4, LBLAWAR1(r3)
1209 twi 0,r4,0
1210 isync
Eran Liberty9095d4a2005-07-28 10:08:46 -05001211 blr
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001212#endif /* CONFIG_SYS_FLASHBOOT */