blob: 36724e5aa5361fa698b7c8191b49a42e693a2284 [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>
Andreas Bießmann61d01952011-07-18 20:24:04 +020017#ifndef CONFIG_IDENT_STRING
18#define CONFIG_IDENT_STRING "MPC83XX"
19#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -050020#include <version.h>
21
22#define CONFIG_83XX 1 /* needed for Linux kernel header files*/
Eran Liberty9095d4a2005-07-28 10:08:46 -050023
24#include <ppc_asm.tmpl>
25#include <ppc_defs.h>
26
27#include <asm/cache.h>
28#include <asm/mmu.h>
Peter Tyser3a1362d2010-10-14 23:33:24 -050029#include <asm/u-boot.h>
Eran Liberty9095d4a2005-07-28 10:08:46 -050030
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
Ramneek Mehresh7cad2072014-01-03 12:11:55 +0530122 .globl get_svr
123get_svr:
124 mfspr r3, SVR
125 blr
126
Ron Madrid787b61d2008-12-12 13:12:45 -0800127 .globl get_pvr
128get_pvr:
129 mfspr r3, PVR
130 blr
131
132 .globl ppcDWstore
133ppcDWstore:
134 lfd 1, 0(r4)
135 stfd 1, 0(r3)
136 blr
137
138 .globl ppcDWload
139ppcDWload:
140 lfd 1, 0(r3)
141 stfd 1, 0(r4)
142 blr
Eran Liberty9095d4a2005-07-28 10:08:46 -0500143
Eran Liberty9095d4a2005-07-28 10:08:46 -0500144#ifndef CONFIG_DEFAULT_IMMR
145#error CONFIG_DEFAULT_IMMR must be defined
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200146#endif /* CONFIG_SYS_DEFAULT_IMMR */
147#ifndef CONFIG_SYS_IMMR
148#define CONFIG_SYS_IMMR CONFIG_DEFAULT_IMMR
149#endif /* CONFIG_SYS_IMMR */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500150
151/*
152 * After configuration, a system reset exception is executed using the
153 * vector at offset 0x100 relative to the base set by MSR[IP]. If
154 * MSR[IP] is 0, the base address is 0x00000000. If MSR[IP] is 1, the
155 * base address is 0xfff00000. In the case of a Power On Reset or Hard
156 * Reset, the value of MSR[IP] is determined by the CIP field in the
157 * HRCW.
158 *
159 * Other bits in the HRCW set up the Base Address and Port Size in BR0.
160 * This determines the location of the boot ROM (flash or EPROM) in the
161 * processor's address space at boot time. As long as the HRCW is set up
162 * so that we eventually end up executing the code below when the
163 * processor executes the reset exception, the actual values used should
164 * not matter.
165 *
166 * Once we have got here, the address mask in OR0 is cleared so that the
167 * bottom 32K of the boot ROM is effectively repeated all throughout the
168 * processor's address space, after which we can jump to the absolute
169 * address at which the boot ROM was linked at compile time, and proceed
170 * to initialise the memory controller without worrying if the rug will
171 * be pulled out from under us, so to speak (it will be fine as long as
172 * we configure BR0 with the same boot ROM link address).
173 */
174 . = EXC_OFF_SYS_RESET
175
176 .globl _start
177_start: /* time t 0 */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500178 lis r4, CONFIG_DEFAULT_IMMR@h
179 nop
Peter Tyser0c44caf2010-09-14 19:13:53 -0500180
Eran Liberty9095d4a2005-07-28 10:08:46 -0500181 mfmsr r5 /* save msr contents */
Scott Wood838450e2009-01-20 11:56:11 -0600182
183 /* 83xx manuals prescribe a specific sequence for updating IMMRBAR. */
184 bl 1f
1851: mflr r7
186
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200187 lis r3, CONFIG_SYS_IMMR@h
188 ori r3, r3, CONFIG_SYS_IMMR@l
Scott Wood838450e2009-01-20 11:56:11 -0600189
190 lwz r6, IMMRBAR(r4)
191 isync
192
Eran Liberty9095d4a2005-07-28 10:08:46 -0500193 stw r3, IMMRBAR(r4)
Scott Wood838450e2009-01-20 11:56:11 -0600194 lwz r6, 0(r7) /* Arbitrary external load */
195 isync
196
197 lwz r6, IMMRBAR(r3)
198 isync
Jon Loeligerebc72242005-08-01 13:20:47 -0500199
Eran Liberty9095d4a2005-07-28 10:08:46 -0500200 /* Initialise the E300 processor core */
201 /*------------------------------------------*/
Jon Loeligerebc72242005-08-01 13:20:47 -0500202
Scott Wood2b36fbb2012-12-06 13:33:17 +0000203#if (defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_MPC83XX_WAIT_FOR_NAND)) || \
204 defined(CONFIG_NAND_SPL)
Lepcha Suchit7ed421f2008-10-16 13:38:00 -0500205 /* The FCM begins execution after only the first page
206 * is loaded. Wait for the rest before branching
207 * to another flash page.
208 */
Scott Wood838450e2009-01-20 11:56:11 -06002091: lwz r6, 0x50b0(r3)
Lepcha Suchit7ed421f2008-10-16 13:38:00 -0500210 andi. r6, r6, 1
211 beq 1b
212#endif
213
Eran Liberty9095d4a2005-07-28 10:08:46 -0500214 bl init_e300_core
Jon Loeligerebc72242005-08-01 13:20:47 -0500215
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200216#ifdef CONFIG_SYS_FLASHBOOT
Eran Liberty9095d4a2005-07-28 10:08:46 -0500217
218 /* Inflate flash location so it appears everywhere, calculate */
219 /* the absolute address in final location of the FLASH, jump */
220 /* there and deflate the flash size back to minimal size */
221 /*------------------------------------------------------------*/
222 bl map_flash_by_law1
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200223 lis r4, (CONFIG_SYS_MONITOR_BASE)@h
224 ori r4, r4, (CONFIG_SYS_MONITOR_BASE)@l
Eran Liberty9095d4a2005-07-28 10:08:46 -0500225 addi r5, r4, in_flash - _start + EXC_OFF_SYS_RESET
226 mtlr r5
227 blr
228in_flash:
229#if 1 /* Remapping flash with LAW0. */
230 bl remap_flash_by_law0
231#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200232#endif /* CONFIG_SYS_FLASHBOOT */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500233
Kumar Galad5d94d62006-02-10 15:40:06 -0600234 /* setup the bats */
235 bl setup_bats
236 sync
237
238 /*
239 * Cache must be enabled here for stack-in-cache trick.
240 * This means we need to enable the BATS.
241 * This means:
242 * 1) for the EVB, original gt regs need to be mapped
243 * 2) need to have an IBAT for the 0xf region,
244 * we are running there!
245 * Cache should be turned on after BATs, since by default
246 * everything is write-through.
247 * The init-mem BAT can be reused after reloc. The old
248 * gt-regs BAT can be reused after board_init_f calls
249 * board_early_init_f (EVB only).
250 */
251 /* enable address translation */
252 bl enable_addr_trans
253 sync
254
Nick Spence7c20aef2008-08-28 14:09:25 -0700255 /* enable the data cache */
Kumar Galad5d94d62006-02-10 15:40:06 -0600256 bl dcache_enable
257 sync
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200258#ifdef CONFIG_SYS_INIT_RAM_LOCK
Kumar Galad5d94d62006-02-10 15:40:06 -0600259 bl lock_ram_in_cache
260 sync
261#endif
262
263 /* set up the stack pointer in our newly created
264 * cache-ram (r1) */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200265 lis r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET)@h
266 ori r1, r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET)@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600267
268 li r0, 0 /* Make room for stack frame header and */
269 stwu r0, -4(r1) /* clear final stack frame so that */
270 stwu r0, -4(r1) /* stack backtraces terminate cleanly */
271
Eran Liberty9095d4a2005-07-28 10:08:46 -0500272
273 /* let the C-code set up the rest */
Kumar Galad5d94d62006-02-10 15:40:06 -0600274 /* */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500275 /* Be careful to keep code relocatable & stack humble */
276 /*------------------------------------------------------*/
277
278 GET_GOT /* initialize GOT access */
Wolfgang Denkb2d36ea2011-04-20 22:11:21 +0200279
Eran Liberty9095d4a2005-07-28 10:08:46 -0500280 /* r3: IMMR */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200281 lis r3, CONFIG_SYS_IMMR@h
Eran Liberty9095d4a2005-07-28 10:08:46 -0500282 /* run low-level CPU init code (in Flash)*/
283 bl cpu_init_f
284
Eran Liberty9095d4a2005-07-28 10:08:46 -0500285 /* run 1st part of board init code (in Flash)*/
286 bl board_init_f
287
Peter Tyser0c44caf2010-09-14 19:13:53 -0500288 /* NOTREACHED - board_init_f() does not return */
289
Scott Wood2b36fbb2012-12-06 13:33:17 +0000290#ifndef MINIMAL_SPL
Eran Liberty9095d4a2005-07-28 10:08:46 -0500291/*
292 * Vector Table
293 */
294
295 .globl _start_of_vectors
296_start_of_vectors:
297
298/* Machine check */
299 STD_EXCEPTION(0x200, MachineCheck, MachineCheckException)
300
301/* Data Storage exception. */
302 STD_EXCEPTION(0x300, DataStorage, UnknownException)
303
304/* Instruction Storage exception. */
305 STD_EXCEPTION(0x400, InstStorage, UnknownException)
306
307/* External Interrupt exception. */
308#ifndef FIXME
309 STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
Jon Loeligerebc72242005-08-01 13:20:47 -0500310#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -0500311
312/* Alignment exception. */
313 . = 0x600
314Alignment:
Rafal Jaworowski06244e42007-06-22 14:58:04 +0200315 EXCEPTION_PROLOG(SRR0, SRR1)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500316 mfspr r4,DAR
317 stw r4,_DAR(r21)
318 mfspr r5,DSISR
319 stw r5,_DSISR(r21)
320 addi r3,r1,STACK_FRAME_OVERHEAD
Joakim Tjernlund4ff6bc02010-01-19 14:41:55 +0100321 EXC_XFER_TEMPLATE(Alignment, AlignmentException, MSR_KERNEL, COPY_EE)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500322
323/* Program check exception */
324 . = 0x700
325ProgramCheck:
Rafal Jaworowski06244e42007-06-22 14:58:04 +0200326 EXCEPTION_PROLOG(SRR0, SRR1)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500327 addi r3,r1,STACK_FRAME_OVERHEAD
Joakim Tjernlund4ff6bc02010-01-19 14:41:55 +0100328 EXC_XFER_TEMPLATE(ProgramCheck, ProgramCheckException,
329 MSR_KERNEL, COPY_EE)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500330
331 STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
332
333 /* I guess we could implement decrementer, and may have
334 * to someday for timekeeping.
335 */
336 STD_EXCEPTION(0x900, Decrementer, timer_interrupt)
337
338 STD_EXCEPTION(0xa00, Trap_0a, UnknownException)
339 STD_EXCEPTION(0xb00, Trap_0b, UnknownException)
340 STD_EXCEPTION(0xc00, SystemCall, UnknownException)
341 STD_EXCEPTION(0xd00, SingleStep, UnknownException)
342
343 STD_EXCEPTION(0xe00, Trap_0e, UnknownException)
344 STD_EXCEPTION(0xf00, Trap_0f, UnknownException)
345
346 STD_EXCEPTION(0x1000, InstructionTLBMiss, UnknownException)
347 STD_EXCEPTION(0x1100, DataLoadTLBMiss, UnknownException)
348 STD_EXCEPTION(0x1200, DataStoreTLBMiss, UnknownException)
349#ifdef DEBUG
350 . = 0x1300
351 /*
352 * This exception occurs when the program counter matches the
353 * Instruction Address Breakpoint Register (IABR).
354 *
355 * I want the cpu to halt if this occurs so I can hunt around
356 * with the debugger and look at things.
357 *
358 * When DEBUG is defined, both machine check enable (in the MSR)
359 * and checkstop reset enable (in the reset mode register) are
360 * turned off and so a checkstop condition will result in the cpu
361 * halting.
362 *
363 * I force the cpu into a checkstop condition by putting an illegal
364 * instruction here (at least this is the theory).
365 *
366 * well - that didnt work, so just do an infinite loop!
367 */
3681: b 1b
369#else
370 STD_EXCEPTION(0x1300, InstructionBreakpoint, DebugException)
371#endif
372 STD_EXCEPTION(0x1400, SMI, UnknownException)
373
374 STD_EXCEPTION(0x1500, Trap_15, UnknownException)
375 STD_EXCEPTION(0x1600, Trap_16, UnknownException)
376 STD_EXCEPTION(0x1700, Trap_17, UnknownException)
377 STD_EXCEPTION(0x1800, Trap_18, UnknownException)
378 STD_EXCEPTION(0x1900, Trap_19, UnknownException)
379 STD_EXCEPTION(0x1a00, Trap_1a, UnknownException)
380 STD_EXCEPTION(0x1b00, Trap_1b, UnknownException)
381 STD_EXCEPTION(0x1c00, Trap_1c, UnknownException)
382 STD_EXCEPTION(0x1d00, Trap_1d, UnknownException)
383 STD_EXCEPTION(0x1e00, Trap_1e, UnknownException)
384 STD_EXCEPTION(0x1f00, Trap_1f, UnknownException)
385 STD_EXCEPTION(0x2000, Trap_20, UnknownException)
386 STD_EXCEPTION(0x2100, Trap_21, UnknownException)
387 STD_EXCEPTION(0x2200, Trap_22, UnknownException)
388 STD_EXCEPTION(0x2300, Trap_23, UnknownException)
389 STD_EXCEPTION(0x2400, Trap_24, UnknownException)
390 STD_EXCEPTION(0x2500, Trap_25, UnknownException)
391 STD_EXCEPTION(0x2600, Trap_26, UnknownException)
392 STD_EXCEPTION(0x2700, Trap_27, UnknownException)
393 STD_EXCEPTION(0x2800, Trap_28, UnknownException)
394 STD_EXCEPTION(0x2900, Trap_29, UnknownException)
395 STD_EXCEPTION(0x2a00, Trap_2a, UnknownException)
396 STD_EXCEPTION(0x2b00, Trap_2b, UnknownException)
397 STD_EXCEPTION(0x2c00, Trap_2c, UnknownException)
398 STD_EXCEPTION(0x2d00, Trap_2d, UnknownException)
399 STD_EXCEPTION(0x2e00, Trap_2e, UnknownException)
400 STD_EXCEPTION(0x2f00, Trap_2f, UnknownException)
401
402
403 .globl _end_of_vectors
404_end_of_vectors:
405
406 . = 0x3000
407
408/*
409 * This code finishes saving the registers to the exception frame
410 * and jumps to the appropriate handler for the exception.
411 * Register r21 is pointer into trap frame, r1 has new stack pointer.
412 */
413 .globl transfer_to_handler
414transfer_to_handler:
415 stw r22,_NIP(r21)
416 lis r22,MSR_POW@h
417 andc r23,r23,r22
418 stw r23,_MSR(r21)
419 SAVE_GPR(7, r21)
420 SAVE_4GPRS(8, r21)
421 SAVE_8GPRS(12, r21)
422 SAVE_8GPRS(24, r21)
423 mflr r23
424 andi. r24,r23,0x3f00 /* get vector offset */
425 stw r24,TRAP(r21)
426 li r22,0
427 stw r22,RESULT(r21)
428 lwz r24,0(r23) /* virtual address of handler */
429 lwz r23,4(r23) /* where to go when done */
430 mtspr SRR0,r24
431 mtspr SRR1,r20
432 mtlr r23
433 SYNC
434 rfi /* jump to handler, enable MMU */
435
436int_return:
437 mfmsr r28 /* Disable interrupts */
438 li r4,0
439 ori r4,r4,MSR_EE
440 andc r28,r28,r4
441 SYNC /* Some chip revs need this... */
442 mtmsr r28
443 SYNC
444 lwz r2,_CTR(r1)
445 lwz r0,_LINK(r1)
446 mtctr r2
447 mtlr r0
448 lwz r2,_XER(r1)
449 lwz r0,_CCR(r1)
450 mtspr XER,r2
451 mtcrf 0xFF,r0
452 REST_10GPRS(3, r1)
453 REST_10GPRS(13, r1)
454 REST_8GPRS(23, r1)
455 REST_GPR(31, r1)
456 lwz r2,_NIP(r1) /* Restore environment */
457 lwz r0,_MSR(r1)
458 mtspr SRR0,r2
459 mtspr SRR1,r0
460 lwz r0,GPR0(r1)
461 lwz r2,GPR2(r1)
462 lwz r1,GPR1(r1)
463 SYNC
464 rfi
Scott Wood2b36fbb2012-12-06 13:33:17 +0000465#endif /* !MINIMAL_SPL */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500466
467/*
468 * This code initialises the E300 processor core
469 * (conforms to PowerPC 603e spec)
470 * Note: expects original MSR contents to be in r5.
471 */
472 .globl init_e300_core
473init_e300_core: /* time t 10 */
474 /* Initialize machine status; enable machine check interrupt */
475 /*-----------------------------------------------------------*/
476
477 li r3, MSR_KERNEL /* Set ME and RI flags */
478 rlwimi r3, r5, 0, 25, 25 /* preserve IP bit set by HRCW */
479#ifdef DEBUG
480 rlwimi r3, r5, 0, 21, 22 /* debugger might set SE & BE bits */
481#endif
482 SYNC /* Some chip revs need this... */
483 mtmsr r3
484 SYNC
485 mtspr SRR1, r3 /* Make SRR1 match MSR */
486
487
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200488 lis r3, CONFIG_SYS_IMMR@h
Eran Liberty9095d4a2005-07-28 10:08:46 -0500489#if defined(CONFIG_WATCHDOG)
Horst Kronstorfer4565e042010-05-18 10:37:05 +0200490 /* Initialise the Watchdog values and reset it (if req) */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500491 /*------------------------------------------------------*/
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200492 lis r4, CONFIG_SYS_WATCHDOG_VALUE
Eran Liberty9095d4a2005-07-28 10:08:46 -0500493 ori r4, r4, (SWCRR_SWEN | SWCRR_SWRI | SWCRR_SWPR)
494 stw r4, SWCRR(r3)
Jon Loeligerebc72242005-08-01 13:20:47 -0500495
Eran Liberty9095d4a2005-07-28 10:08:46 -0500496 /* and reset it */
Jon Loeligerebc72242005-08-01 13:20:47 -0500497
Eran Liberty9095d4a2005-07-28 10:08:46 -0500498 li r4, 0x556C
499 sth r4, SWSRR@l(r3)
Heiko Schocher6dfb2e52008-01-11 15:15:17 +0100500 li r4, -0x55C7
Eran Liberty9095d4a2005-07-28 10:08:46 -0500501 sth r4, SWSRR@l(r3)
502#else
Horst Kronstorfer4565e042010-05-18 10:37:05 +0200503 /* Disable Watchdog */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500504 /*-------------------*/
Kumar Galab42751c2006-01-11 11:23:01 -0600505 lwz r4, SWCRR(r3)
506 /* Check to see if its enabled for disabling
507 once disabled by SW you can't re-enable */
508 andi. r4, r4, 0x4
509 beq 1f
Eran Liberty9095d4a2005-07-28 10:08:46 -0500510 xor r4, r4, r4
511 stw r4, SWCRR(r3)
Kumar Galab42751c2006-01-11 11:23:01 -06005121:
Eran Liberty9095d4a2005-07-28 10:08:46 -0500513#endif /* CONFIG_WATCHDOG */
514
Nick Spence56fd3c22008-08-28 14:09:19 -0700515#if defined(CONFIG_MASK_AER_AO)
516 /* Write the Arbiter Event Enable to mask Address Only traps. */
517 /* This prevents the dcbz instruction from being trapped when */
518 /* HID0_ABE Address Broadcast Enable is set and the MEMORY */
519 /* COHERENCY bit is set in the WIMG bits, which is often */
520 /* needed for PCI operation. */
521 lwz r4, 0x0808(r3)
522 rlwinm r0, r4, 0, ~AER_AO
523 stw r0, 0x0808(r3)
524#endif /* CONFIG_MASK_AER_AO */
525
Eran Liberty9095d4a2005-07-28 10:08:46 -0500526 /* Initialize the Hardware Implementation-dependent Registers */
527 /* HID0 also contains cache control */
Nick Spence7c20aef2008-08-28 14:09:25 -0700528 /* - force invalidation of data and instruction caches */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500529 /*------------------------------------------------------*/
530
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200531 lis r3, CONFIG_SYS_HID0_INIT@h
532 ori r3, r3, (CONFIG_SYS_HID0_INIT | HID0_ICFI | HID0_DCFI)@l
Eran Liberty9095d4a2005-07-28 10:08:46 -0500533 SYNC
534 mtspr HID0, r3
535
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200536 lis r3, CONFIG_SYS_HID0_FINAL@h
537 ori r3, r3, (CONFIG_SYS_HID0_FINAL & ~(HID0_ICFI | HID0_DCFI))@l
Eran Liberty9095d4a2005-07-28 10:08:46 -0500538 SYNC
539 mtspr HID0, r3
540
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200541 lis r3, CONFIG_SYS_HID2@h
542 ori r3, r3, CONFIG_SYS_HID2@l
Eran Liberty9095d4a2005-07-28 10:08:46 -0500543 SYNC
544 mtspr HID2, r3
545
Eran Liberty9095d4a2005-07-28 10:08:46 -0500546 /* Done! */
547 /*------------------------------*/
Jon Loeligerebc72242005-08-01 13:20:47 -0500548 blr
Eran Liberty9095d4a2005-07-28 10:08:46 -0500549
Kumar Galad5d94d62006-02-10 15:40:06 -0600550 /* setup_bats - set them up to some initial state */
551 .globl setup_bats
552setup_bats:
553 addis r0, r0, 0x0000
554
555 /* IBAT 0 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200556 addis r4, r0, CONFIG_SYS_IBAT0L@h
557 ori r4, r4, CONFIG_SYS_IBAT0L@l
558 addis r3, r0, CONFIG_SYS_IBAT0U@h
559 ori r3, r3, CONFIG_SYS_IBAT0U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600560 mtspr IBAT0L, r4
561 mtspr IBAT0U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600562
563 /* DBAT 0 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200564 addis r4, r0, CONFIG_SYS_DBAT0L@h
565 ori r4, r4, CONFIG_SYS_DBAT0L@l
566 addis r3, r0, CONFIG_SYS_DBAT0U@h
567 ori r3, r3, CONFIG_SYS_DBAT0U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600568 mtspr DBAT0L, r4
569 mtspr DBAT0U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600570
571 /* IBAT 1 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200572 addis r4, r0, CONFIG_SYS_IBAT1L@h
573 ori r4, r4, CONFIG_SYS_IBAT1L@l
574 addis r3, r0, CONFIG_SYS_IBAT1U@h
575 ori r3, r3, CONFIG_SYS_IBAT1U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600576 mtspr IBAT1L, r4
577 mtspr IBAT1U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600578
579 /* DBAT 1 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200580 addis r4, r0, CONFIG_SYS_DBAT1L@h
581 ori r4, r4, CONFIG_SYS_DBAT1L@l
582 addis r3, r0, CONFIG_SYS_DBAT1U@h
583 ori r3, r3, CONFIG_SYS_DBAT1U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600584 mtspr DBAT1L, r4
585 mtspr DBAT1U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600586
587 /* IBAT 2 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200588 addis r4, r0, CONFIG_SYS_IBAT2L@h
589 ori r4, r4, CONFIG_SYS_IBAT2L@l
590 addis r3, r0, CONFIG_SYS_IBAT2U@h
591 ori r3, r3, CONFIG_SYS_IBAT2U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600592 mtspr IBAT2L, r4
593 mtspr IBAT2U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600594
595 /* DBAT 2 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200596 addis r4, r0, CONFIG_SYS_DBAT2L@h
597 ori r4, r4, CONFIG_SYS_DBAT2L@l
598 addis r3, r0, CONFIG_SYS_DBAT2U@h
599 ori r3, r3, CONFIG_SYS_DBAT2U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600600 mtspr DBAT2L, r4
601 mtspr DBAT2U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600602
603 /* IBAT 3 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200604 addis r4, r0, CONFIG_SYS_IBAT3L@h
605 ori r4, r4, CONFIG_SYS_IBAT3L@l
606 addis r3, r0, CONFIG_SYS_IBAT3U@h
607 ori r3, r3, CONFIG_SYS_IBAT3U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600608 mtspr IBAT3L, r4
609 mtspr IBAT3U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600610
611 /* DBAT 3 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200612 addis r4, r0, CONFIG_SYS_DBAT3L@h
613 ori r4, r4, CONFIG_SYS_DBAT3L@l
614 addis r3, r0, CONFIG_SYS_DBAT3U@h
615 ori r3, r3, CONFIG_SYS_DBAT3U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600616 mtspr DBAT3L, r4
617 mtspr DBAT3U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600618
Becky Bruce03ea1be2008-05-08 19:02:12 -0500619#ifdef CONFIG_HIGH_BATS
Kumar Galad5d94d62006-02-10 15:40:06 -0600620 /* IBAT 4 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200621 addis r4, r0, CONFIG_SYS_IBAT4L@h
622 ori r4, r4, CONFIG_SYS_IBAT4L@l
623 addis r3, r0, CONFIG_SYS_IBAT4U@h
624 ori r3, r3, CONFIG_SYS_IBAT4U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600625 mtspr IBAT4L, r4
626 mtspr IBAT4U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600627
628 /* DBAT 4 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200629 addis r4, r0, CONFIG_SYS_DBAT4L@h
630 ori r4, r4, CONFIG_SYS_DBAT4L@l
631 addis r3, r0, CONFIG_SYS_DBAT4U@h
632 ori r3, r3, CONFIG_SYS_DBAT4U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600633 mtspr DBAT4L, r4
634 mtspr DBAT4U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600635
636 /* IBAT 5 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200637 addis r4, r0, CONFIG_SYS_IBAT5L@h
638 ori r4, r4, CONFIG_SYS_IBAT5L@l
639 addis r3, r0, CONFIG_SYS_IBAT5U@h
640 ori r3, r3, CONFIG_SYS_IBAT5U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600641 mtspr IBAT5L, r4
642 mtspr IBAT5U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600643
644 /* DBAT 5 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200645 addis r4, r0, CONFIG_SYS_DBAT5L@h
646 ori r4, r4, CONFIG_SYS_DBAT5L@l
647 addis r3, r0, CONFIG_SYS_DBAT5U@h
648 ori r3, r3, CONFIG_SYS_DBAT5U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600649 mtspr DBAT5L, r4
650 mtspr DBAT5U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600651
652 /* IBAT 6 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200653 addis r4, r0, CONFIG_SYS_IBAT6L@h
654 ori r4, r4, CONFIG_SYS_IBAT6L@l
655 addis r3, r0, CONFIG_SYS_IBAT6U@h
656 ori r3, r3, CONFIG_SYS_IBAT6U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600657 mtspr IBAT6L, r4
658 mtspr IBAT6U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600659
660 /* DBAT 6 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200661 addis r4, r0, CONFIG_SYS_DBAT6L@h
662 ori r4, r4, CONFIG_SYS_DBAT6L@l
663 addis r3, r0, CONFIG_SYS_DBAT6U@h
664 ori r3, r3, CONFIG_SYS_DBAT6U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600665 mtspr DBAT6L, r4
666 mtspr DBAT6U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600667
668 /* IBAT 7 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200669 addis r4, r0, CONFIG_SYS_IBAT7L@h
670 ori r4, r4, CONFIG_SYS_IBAT7L@l
671 addis r3, r0, CONFIG_SYS_IBAT7U@h
672 ori r3, r3, CONFIG_SYS_IBAT7U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600673 mtspr IBAT7L, r4
674 mtspr IBAT7U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600675
676 /* DBAT 7 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200677 addis r4, r0, CONFIG_SYS_DBAT7L@h
678 ori r4, r4, CONFIG_SYS_DBAT7L@l
679 addis r3, r0, CONFIG_SYS_DBAT7U@h
680 ori r3, r3, CONFIG_SYS_DBAT7U@l
Kumar Galad5d94d62006-02-10 15:40:06 -0600681 mtspr DBAT7L, r4
682 mtspr DBAT7U, r3
Kumar Galad5d94d62006-02-10 15:40:06 -0600683#endif
684
Scott Woodb71689b2008-06-30 14:13:28 -0500685 isync
686
687 /* invalidate all tlb's
688 *
689 * From the 603e User Manual: "The 603e provides the ability to
690 * invalidate a TLB entry. The TLB Invalidate Entry (tlbie)
691 * instruction invalidates the TLB entry indexed by the EA, and
692 * operates on both the instruction and data TLBs simultaneously
693 * invalidating four TLB entries (both sets in each TLB). The
694 * index corresponds to bits 15-19 of the EA. To invalidate all
695 * entries within both TLBs, 32 tlbie instructions should be
696 * issued, incrementing this field by one each time."
697 *
698 * "Note that the tlbia instruction is not implemented on the
699 * 603e."
700 *
701 * bits 15-19 correspond to addresses 0x00000000 to 0x0001F000
702 * incrementing by 0x1000 each time. The code below is sort of
Stefan Roese88fbf932010-04-15 16:07:28 +0200703 * based on code in "flush_tlbs" from arch/powerpc/kernel/head.S
Scott Woodb71689b2008-06-30 14:13:28 -0500704 *
Kumar Galad5d94d62006-02-10 15:40:06 -0600705 */
706 lis r3, 0
707 lis r5, 2
708
7091:
710 tlbie r3
711 addi r3, r3, 0x1000
712 cmp 0, 0, r3, r5
713 blt 1b
714
715 blr
716
Eran Liberty9095d4a2005-07-28 10:08:46 -0500717/* Cache functions.
718 *
719 * Note: requires that all cache bits in
720 * HID0 are in the low half word.
721 */
Scott Wood2b36fbb2012-12-06 13:33:17 +0000722#ifndef MINIMAL_SPL
Eran Liberty9095d4a2005-07-28 10:08:46 -0500723 .globl icache_enable
724icache_enable:
725 mfspr r3, HID0
726 ori r3, r3, HID0_ICE
Nick Spence7c20aef2008-08-28 14:09:25 -0700727 li r4, HID0_ICFI|HID0_ILOCK
Eran Liberty9095d4a2005-07-28 10:08:46 -0500728 andc r3, r3, r4
729 ori r4, r3, HID0_ICFI
730 isync
731 mtspr HID0, r4 /* sets enable and invalidate, clears lock */
732 isync
733 mtspr HID0, r3 /* clears invalidate */
734 blr
735
736 .globl icache_disable
737icache_disable:
738 mfspr r3, HID0
739 lis r4, 0
Nick Spence7c20aef2008-08-28 14:09:25 -0700740 ori r4, r4, HID0_ICE|HID0_ICFI|HID0_ILOCK
Eran Liberty9095d4a2005-07-28 10:08:46 -0500741 andc r3, r3, r4
Eran Liberty9095d4a2005-07-28 10:08:46 -0500742 isync
Nick Spence7c20aef2008-08-28 14:09:25 -0700743 mtspr HID0, r3 /* clears invalidate, enable and lock */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500744 blr
745
746 .globl icache_status
747icache_status:
748 mfspr r3, HID0
Marian Balakowicz758e5d32006-03-14 16:01:25 +0100749 rlwinm r3, r3, (31 - HID0_ICE_SHIFT + 1), 31, 31
Eran Liberty9095d4a2005-07-28 10:08:46 -0500750 blr
Scott Wood2b36fbb2012-12-06 13:33:17 +0000751#endif /* !MINIMAL_SPL */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500752
753 .globl dcache_enable
754dcache_enable:
755 mfspr r3, HID0
Kumar Galad5d94d62006-02-10 15:40:06 -0600756 li r5, HID0_DCFI|HID0_DLOCK
757 andc r3, r3, r5
Kumar Galad5d94d62006-02-10 15:40:06 -0600758 ori r3, r3, HID0_DCE
Eran Liberty9095d4a2005-07-28 10:08:46 -0500759 sync
Nick Spence7c20aef2008-08-28 14:09:25 -0700760 mtspr HID0, r3 /* enable, no invalidate */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500761 blr
762
763 .globl dcache_disable
764dcache_disable:
Nick Spence7c20aef2008-08-28 14:09:25 -0700765 mflr r4
766 bl flush_dcache /* uses r3 and r5 */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500767 mfspr r3, HID0
Nick Spence7c20aef2008-08-28 14:09:25 -0700768 li r5, HID0_DCE|HID0_DLOCK
769 andc r3, r3, r5
770 ori r5, r3, HID0_DCFI
Eran Liberty9095d4a2005-07-28 10:08:46 -0500771 sync
Nick Spence7c20aef2008-08-28 14:09:25 -0700772 mtspr HID0, r5 /* sets invalidate, clears enable and lock */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500773 sync
774 mtspr HID0, r3 /* clears invalidate */
Nick Spence7c20aef2008-08-28 14:09:25 -0700775 mtlr r4
Eran Liberty9095d4a2005-07-28 10:08:46 -0500776 blr
777
778 .globl dcache_status
779dcache_status:
780 mfspr r3, HID0
Marian Balakowicz758e5d32006-03-14 16:01:25 +0100781 rlwinm r3, r3, (31 - HID0_DCE_SHIFT + 1), 31, 31
Eran Liberty9095d4a2005-07-28 10:08:46 -0500782 blr
783
Nick Spence7c20aef2008-08-28 14:09:25 -0700784 .globl flush_dcache
785flush_dcache:
786 lis r3, 0
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200787 lis r5, CONFIG_SYS_CACHELINE_SIZE
Nick Spence7c20aef2008-08-28 14:09:25 -07007881: cmp 0, 1, r3, r5
789 bge 2f
790 lwz r5, 0(r3)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200791 lis r5, CONFIG_SYS_CACHELINE_SIZE
Nick Spence7c20aef2008-08-28 14:09:25 -0700792 addi r3, r3, 0x4
793 b 1b
7942: blr
795
Eran Liberty9095d4a2005-07-28 10:08:46 -0500796/*-------------------------------------------------------------------*/
797
798/*
799 * void relocate_code (addr_sp, gd, addr_moni)
800 *
801 * This "function" does not return, instead it continues in RAM
802 * after relocating the monitor code.
803 *
804 * r3 = dest
805 * r4 = src
806 * r5 = length in bytes
807 * r6 = cachelinesize
808 */
809 .globl relocate_code
810relocate_code:
811 mr r1, r3 /* Set new stack pointer */
812 mr r9, r4 /* Save copy of Global Data pointer */
813 mr r10, r5 /* Save copy of Destination Address */
814
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +0100815 GET_GOT
Eran Liberty9095d4a2005-07-28 10:08:46 -0500816 mr r3, r5 /* Destination Address */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200817 lis r4, CONFIG_SYS_MONITOR_BASE@h /* Source Address */
818 ori r4, r4, CONFIG_SYS_MONITOR_BASE@l
Scott Woodb71689b2008-06-30 14:13:28 -0500819 lwz r5, GOT(__bss_start)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500820 sub r5, r5, r4
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200821 li r6, CONFIG_SYS_CACHELINE_SIZE /* Cache Line Size */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500822
823 /*
824 * Fix GOT pointer:
825 *
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200826 * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500827 * + Destination Address
828 *
829 * Offset:
830 */
831 sub r15, r10, r4
832
833 /* First our own GOT */
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +0100834 add r12, r12, r15
Eran Liberty9095d4a2005-07-28 10:08:46 -0500835 /* then the one used by the C code */
836 add r30, r30, r15
837
838 /*
839 * Now relocate code
840 */
841
842 cmplw cr1,r3,r4
843 addi r0,r5,3
844 srwi. r0,r0,2
845 beq cr1,4f /* In place copy is not necessary */
846 beq 7f /* Protect against 0 count */
847 mtctr r0
848 bge cr1,2f
849 la r8,-4(r4)
850 la r7,-4(r3)
851
852 /* copy */
8531: lwzu r0,4(r8)
854 stwu r0,4(r7)
855 bdnz 1b
856
857 addi r0,r5,3
858 srwi. r0,r0,2
859 mtctr r0
860 la r8,-4(r4)
861 la r7,-4(r3)
Jon Loeligerebc72242005-08-01 13:20:47 -0500862
863 /* and compare */
Eran Liberty9095d4a2005-07-28 10:08:46 -050086420: lwzu r20,4(r8)
865 lwzu r21,4(r7)
866 xor. r22, r20, r21
867 bne 30f
868 bdnz 20b
869 b 4f
870
871 /* compare failed */
87230: li r3, 0
873 blr
874
8752: slwi r0,r0,2 /* re copy in reverse order ... y do we needed it? */
876 add r8,r4,r0
877 add r7,r3,r0
8783: lwzu r0,-4(r8)
879 stwu r0,-4(r7)
880 bdnz 3b
Eran Liberty9095d4a2005-07-28 10:08:46 -0500881
882/*
883 * Now flush the cache: note that we must start from a cache aligned
884 * address. Otherwise we might miss one cache line.
885 */
Kumar Galad5d94d62006-02-10 15:40:06 -06008864: cmpwi r6,0
Eran Liberty9095d4a2005-07-28 10:08:46 -0500887 add r5,r3,r5
Kumar Galad5d94d62006-02-10 15:40:06 -0600888 beq 7f /* Always flush prefetch queue in any case */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500889 subi r0,r6,1
890 andc r3,r3,r0
Eran Liberty9095d4a2005-07-28 10:08:46 -0500891 mr r4,r3
8925: dcbst 0,r4
893 add r4,r4,r6
894 cmplw r4,r5
895 blt 5b
Kumar Galad5d94d62006-02-10 15:40:06 -0600896 sync /* Wait for all dcbst to complete on bus */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500897 mr r4,r3
8986: icbi 0,r4
899 add r4,r4,r6
900 cmplw r4,r5
901 blt 6b
Kumar Galad5d94d62006-02-10 15:40:06 -06009027: sync /* Wait for all icbi to complete on bus */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500903 isync
904
905/*
906 * We are done. Do not return, instead branch to second part of board
907 * initialization, now running from RAM.
908 */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500909 addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
910 mtlr r0
911 blr
912
913in_ram:
914
915 /*
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +0100916 * Relocation Function, r12 point to got2+0x8000
Eran Liberty9095d4a2005-07-28 10:08:46 -0500917 *
918 * Adjust got2 pointers, no need to check for 0, this code
919 * already puts a few entries in the table.
920 */
921 li r0,__got2_entries@sectoff@l
922 la r3,GOT(_GOT2_TABLE_)
923 lwz r11,GOT(_GOT2_TABLE_)
924 mtctr r0
925 sub r11,r3,r11
926 addi r3,r3,-4
9271: lwzu r0,4(r3)
Joakim Tjernlund4f2fdac2009-10-08 02:03:51 +0200928 cmpwi r0,0
929 beq- 2f
Eran Liberty9095d4a2005-07-28 10:08:46 -0500930 add r0,r0,r11
931 stw r0,0(r3)
Joakim Tjernlund4f2fdac2009-10-08 02:03:51 +02009322: bdnz 1b
Eran Liberty9095d4a2005-07-28 10:08:46 -0500933
Scott Wood2b36fbb2012-12-06 13:33:17 +0000934#ifndef MINIMAL_SPL
Eran Liberty9095d4a2005-07-28 10:08:46 -0500935 /*
936 * Now adjust the fixups and the pointers to the fixups
937 * in case we need to move ourselves again.
938 */
Joakim Tjernlund4f2fdac2009-10-08 02:03:51 +0200939 li r0,__fixup_entries@sectoff@l
Eran Liberty9095d4a2005-07-28 10:08:46 -0500940 lwz r3,GOT(_FIXUP_TABLE_)
941 cmpwi r0,0
942 mtctr r0
943 addi r3,r3,-4
944 beq 4f
9453: lwzu r4,4(r3)
946 lwzux r0,r4,r11
Joakim Tjernlundc61b25a2010-10-14 11:51:44 +0200947 cmpwi r0,0
Eran Liberty9095d4a2005-07-28 10:08:46 -0500948 add r0,r0,r11
Joakim Tjernlund401b5922010-11-04 19:02:00 +0100949 stw r4,0(r3)
Joakim Tjernlundc61b25a2010-10-14 11:51:44 +0200950 beq- 5f
Eran Liberty9095d4a2005-07-28 10:08:46 -0500951 stw r0,0(r4)
Joakim Tjernlundc61b25a2010-10-14 11:51:44 +02009525: bdnz 3b
Eran Liberty9095d4a2005-07-28 10:08:46 -05009534:
Scott Woodb71689b2008-06-30 14:13:28 -0500954#endif
955
Eran Liberty9095d4a2005-07-28 10:08:46 -0500956clear_bss:
957 /*
958 * Now clear BSS segment
959 */
960 lwz r3,GOT(__bss_start)
961#if defined(CONFIG_HYMOD)
962 /*
963 * For HYMOD - the environment is the very last item in flash.
964 * The real .bss stops just before environment starts, so only
965 * clear up to that point.
966 *
967 * taken from mods for FADS board
968 */
969 lwz r4,GOT(environment)
970#else
Simon Glassed70c8f2013-03-14 06:54:53 +0000971 lwz r4,GOT(__bss_end)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500972#endif
973
974 cmplw 0, r3, r4
975 beq 6f
976
977 li r0, 0
9785:
979 stw r0, 0(r3)
980 addi r3, r3, 4
981 cmplw 0, r3, r4
982 bne 5b
9836:
984
985 mr r3, r9 /* Global Data pointer */
986 mr r4, r10 /* Destination Address */
987 bl board_init_r
988
Scott Wood2b36fbb2012-12-06 13:33:17 +0000989#ifndef MINIMAL_SPL
Eran Liberty9095d4a2005-07-28 10:08:46 -0500990 /*
991 * Copy exception vector code to low memory
992 *
993 * r3: dest_addr
994 * r7: source address, r8: end address, r9: target address
995 */
996 .globl trap_init
997trap_init:
Joakim Tjernlund3fbaa4d2010-01-19 14:41:56 +0100998 mflr r4 /* save link register */
999 GET_GOT
Eran Liberty9095d4a2005-07-28 10:08:46 -05001000 lwz r7, GOT(_start)
1001 lwz r8, GOT(_end_of_vectors)
1002
1003 li r9, 0x100 /* reset vector always at 0x100 */
1004
1005 cmplw 0, r7, r8
1006 bgelr /* return if r7>=r8 - just in case */
Eran Liberty9095d4a2005-07-28 10:08:46 -050010071:
1008 lwz r0, 0(r7)
1009 stw r0, 0(r9)
1010 addi r7, r7, 4
1011 addi r9, r9, 4
1012 cmplw 0, r7, r8
1013 bne 1b
1014
1015 /*
1016 * relocate `hdlr' and `int_return' entries
1017 */
1018 li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
1019 li r8, Alignment - _start + EXC_OFF_SYS_RESET
10202:
1021 bl trap_reloc
1022 addi r7, r7, 0x100 /* next exception vector */
1023 cmplw 0, r7, r8
1024 blt 2b
1025
1026 li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
1027 bl trap_reloc
1028
1029 li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
1030 bl trap_reloc
1031
1032 li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
1033 li r8, SystemCall - _start + EXC_OFF_SYS_RESET
10343:
1035 bl trap_reloc
1036 addi r7, r7, 0x100 /* next exception vector */
1037 cmplw 0, r7, r8
1038 blt 3b
1039
1040 li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
1041 li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
10424:
1043 bl trap_reloc
1044 addi r7, r7, 0x100 /* next exception vector */
1045 cmplw 0, r7, r8
1046 blt 4b
1047
1048 mfmsr r3 /* now that the vectors have */
1049 lis r7, MSR_IP@h /* relocated into low memory */
1050 ori r7, r7, MSR_IP@l /* MSR[IP] can be turned off */
1051 andc r3, r3, r7 /* (if it was on) */
1052 SYNC /* Some chip revs need this... */
1053 mtmsr r3
1054 SYNC
1055
1056 mtlr r4 /* restore link register */
1057 blr
1058
Scott Wood2b36fbb2012-12-06 13:33:17 +00001059#endif /* !MINIMAL_SPL */
Eran Liberty9095d4a2005-07-28 10:08:46 -05001060
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001061#ifdef CONFIG_SYS_INIT_RAM_LOCK
Kumar Galad5d94d62006-02-10 15:40:06 -06001062lock_ram_in_cache:
1063 /* Allocate Initial RAM in data cache.
1064 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001065 lis r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@h
1066 ori r3, r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@l
Wolfgang Denk1c2e98e2010-10-26 13:32:32 +02001067 li r4, ((CONFIG_SYS_INIT_RAM_SIZE & ~31) + \
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001068 (CONFIG_SYS_INIT_RAM_ADDR & 31) + 31) / 32
Nick Spenceb89d6fb2008-08-28 14:09:11 -07001069 mtctr r4
Kumar Galad5d94d62006-02-10 15:40:06 -060010701:
1071 dcbz r0, r3
1072 addi r3, r3, 32
1073 bdnz 1b
1074
1075 /* Lock the data cache */
1076 mfspr r0, HID0
Nick Spence7c20aef2008-08-28 14:09:25 -07001077 ori r0, r0, HID0_DLOCK
Kumar Galad5d94d62006-02-10 15:40:06 -06001078 sync
1079 mtspr HID0, r0
1080 sync
1081 blr
1082
Scott Wood2b36fbb2012-12-06 13:33:17 +00001083#ifndef MINIMAL_SPL
Eran Liberty9095d4a2005-07-28 10:08:46 -05001084.globl unlock_ram_in_cache
1085unlock_ram_in_cache:
1086 /* invalidate the INIT_RAM section */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001087 lis r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@h
1088 ori r3, r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@l
Wolfgang Denk1c2e98e2010-10-26 13:32:32 +02001089 li r4, ((CONFIG_SYS_INIT_RAM_SIZE & ~31) + \
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001090 (CONFIG_SYS_INIT_RAM_ADDR & 31) + 31) / 32
Nick Spenceb89d6fb2008-08-28 14:09:11 -07001091 mtctr r4
Eran Liberty9095d4a2005-07-28 10:08:46 -050010921: icbi r0, r3
1093 dcbi r0, r3
1094 addi r3, r3, 32
1095 bdnz 1b
1096 sync /* Wait for all icbi to complete on bus */
1097 isync
Kumar Galad5d94d62006-02-10 15:40:06 -06001098
1099 /* Unlock the data cache and invalidate it */
1100 mfspr r3, HID0
1101 li r5, HID0_DLOCK|HID0_DCFI
1102 andc r3, r3, r5 /* no invalidate, unlock */
1103 ori r5, r3, HID0_DCFI /* invalidate, unlock */
Nick Spence7c20aef2008-08-28 14:09:25 -07001104 sync
Kumar Galad5d94d62006-02-10 15:40:06 -06001105 mtspr HID0, r5 /* invalidate, unlock */
Kumar Galad5d94d62006-02-10 15:40:06 -06001106 sync
Nick Spence7c20aef2008-08-28 14:09:25 -07001107 mtspr HID0, r3 /* no invalidate, unlock */
Eran Liberty9095d4a2005-07-28 10:08:46 -05001108 blr
Scott Wood2b36fbb2012-12-06 13:33:17 +00001109#endif /* !MINIMAL_SPL */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001110#endif /* CONFIG_SYS_INIT_RAM_LOCK */
Eran Liberty9095d4a2005-07-28 10:08:46 -05001111
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001112#ifdef CONFIG_SYS_FLASHBOOT
Eran Liberty9095d4a2005-07-28 10:08:46 -05001113map_flash_by_law1:
1114 /* When booting from ROM (Flash or EPROM), clear the */
1115 /* Address Mask in OR0 so ROM appears everywhere */
1116 /*----------------------------------------------------*/
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001117 lis r3, (CONFIG_SYS_IMMR)@h /* r3 <= CONFIG_SYS_IMMR */
Jon Loeligerebc72242005-08-01 13:20:47 -05001118 lwz r4, OR0@l(r3)
Eran Liberty9095d4a2005-07-28 10:08:46 -05001119 li r5, 0x7fff /* r5 <= 0x00007FFFF */
Jon Loeligerebc72242005-08-01 13:20:47 -05001120 and r4, r4, r5
Eran Liberty9095d4a2005-07-28 10:08:46 -05001121 stw r4, OR0@l(r3) /* OR0 <= OR0 & 0x00007FFFF */
1122
1123 /* As MPC8349E User's Manual presented, when RCW[BMS] is set to 0,
1124 * system will boot from 0x0000_0100, and the LBLAWBAR0[BASE_ADDR]
1125 * reset value is 0x00000; when RCW[BMS] is set to 1, system will boot
1126 * from 0xFFF0_0100, and the LBLAWBAR0[BASE_ADDR] reset value is
1127 * 0xFF800. From the hard resetting to here, the processor fetched and
1128 * executed the instructions one by one. There is not absolutely
1129 * jumping happened. Laterly, the u-boot code has to do an absolutely
1130 * jumping to tell the CPU instruction fetching component what the
1131 * u-boot TEXT base address is. Because the TEXT base resides in the
1132 * boot ROM memory space, to garantee the code can run smoothly after
1133 * that jumping, we must map in the entire boot ROM by Local Access
1134 * Window. Sometimes, we desire an non-0x00000 or non-0xFF800 starting
1135 * address for boot ROM, such as 0xFE000000. In this case, the default
1136 * LBIU Local Access Widow 0 will not cover this memory space. So, we
1137 * need another window to map in it.
1138 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001139 lis r4, (CONFIG_SYS_FLASH_BASE)@h
1140 ori r4, r4, (CONFIG_SYS_FLASH_BASE)@l
1141 stw r4, LBLAWBAR1(r3) /* LBLAWBAR1 <= CONFIG_SYS_FLASH_BASE */
Timur Tabi53b46172006-08-22 17:07:00 -05001142
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001143 /* Store 0x80000012 + log2(CONFIG_SYS_FLASH_SIZE) into LBLAWAR1 */
Timur Tabi53b46172006-08-22 17:07:00 -05001144 lis r4, (0x80000012)@h
1145 ori r4, r4, (0x80000012)@l
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001146 li r5, CONFIG_SYS_FLASH_SIZE
Timur Tabi53b46172006-08-22 17:07:00 -050011471: srawi. r5, r5, 1 /* r5 = r5 >> 1 */
1148 addi r4, r4, 1
1149 bne 1b
1150
Eran Liberty9095d4a2005-07-28 10:08:46 -05001151 stw r4, LBLAWAR1(r3) /* LBLAWAR1 <= 8MB Flash Size */
Joakim Tjernlundb168d632010-11-19 14:15:33 +01001152 /* Wait for HW to catch up */
1153 lwz r4, LBLAWAR1(r3)
1154 twi 0,r4,0
1155 isync
Eran Liberty9095d4a2005-07-28 10:08:46 -05001156 blr
1157
1158 /* Though all the LBIU Local Access Windows and LBC Banks will be
1159 * initialized in the C code, we'd better configure boot ROM's
1160 * window 0 and bank 0 correctly at here.
1161 */
1162remap_flash_by_law0:
1163 /* Initialize the BR0 with the boot ROM starting address. */
1164 lwz r4, BR0(r3)
1165 li r5, 0x7FFF
Jon Loeligerebc72242005-08-01 13:20:47 -05001166 and r4, r4, r5
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001167 lis r5, (CONFIG_SYS_FLASH_BASE & 0xFFFF8000)@h
1168 ori r5, r5, (CONFIG_SYS_FLASH_BASE & 0xFFFF8000)@l
Eran Liberty9095d4a2005-07-28 10:08:46 -05001169 or r5, r5, r4
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001170 stw r5, BR0(r3) /* r5 <= (CONFIG_SYS_FLASH_BASE & 0xFFFF8000) | (BR0 & 0x00007FFF) */
Eran Liberty9095d4a2005-07-28 10:08:46 -05001171
1172 lwz r4, OR0(r3)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001173 lis r5, ~((CONFIG_SYS_FLASH_SIZE << 4) - 1)
Eran Liberty9095d4a2005-07-28 10:08:46 -05001174 or r4, r4, r5
Timur Tabi53b46172006-08-22 17:07:00 -05001175 stw r4, OR0(r3)
Eran Liberty9095d4a2005-07-28 10:08:46 -05001176
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001177 lis r4, (CONFIG_SYS_FLASH_BASE)@h
1178 ori r4, r4, (CONFIG_SYS_FLASH_BASE)@l
1179 stw r4, LBLAWBAR0(r3) /* LBLAWBAR0 <= CONFIG_SYS_FLASH_BASE */
Eran Liberty9095d4a2005-07-28 10:08:46 -05001180
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001181 /* Store 0x80000012 + log2(CONFIG_SYS_FLASH_SIZE) into LBLAWAR0 */
Timur Tabi53b46172006-08-22 17:07:00 -05001182 lis r4, (0x80000012)@h
1183 ori r4, r4, (0x80000012)@l
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001184 li r5, CONFIG_SYS_FLASH_SIZE
Timur Tabi53b46172006-08-22 17:07:00 -050011851: srawi. r5, r5, 1 /* r5 = r5 >> 1 */
1186 addi r4, r4, 1
1187 bne 1b
1188 stw r4, LBLAWAR0(r3) /* LBLAWAR0 <= Flash Size */
1189
Eran Liberty9095d4a2005-07-28 10:08:46 -05001190
1191 xor r4, r4, r4
1192 stw r4, LBLAWBAR1(r3)
1193 stw r4, LBLAWAR1(r3) /* Off LBIU LAW1 */
Joakim Tjernlundb168d632010-11-19 14:15:33 +01001194 /* Wait for HW to catch up */
1195 lwz r4, LBLAWAR1(r3)
1196 twi 0,r4,0
1197 isync
Eran Liberty9095d4a2005-07-28 10:08:46 -05001198 blr
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001199#endif /* CONFIG_SYS_FLASHBOOT */