blob: d2fced8aba86130351bf34539fbc01f4ace56fbd [file] [log] [blame]
Eran Libertyf046ccd2005-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 Woode4c09502008-06-30 14:13:28 -05005 * Copyright Freescale Semiconductor, Inc. 2004, 2006, 2008.
Eran Libertyf046ccd2005-07-28 10:08:46 -05006 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02007 * SPDX-License-Identifier: GPL-2.0+
Eran Libertyf046ccd2005-07-28 10:08:46 -05008 */
9
10/*
11 * U-Boot - Startup Code for MPC83xx PowerPC based Embedded Boards
12 */
13
Wolfgang Denk25ddd1f2010-10-26 14:34:52 +020014#include <asm-offsets.h>
Eran Libertyf046ccd2005-07-28 10:08:46 -050015#include <config.h>
Jon Loeligerde1d0a62005-08-01 13:20:47 -050016#include <mpc83xx.h>
Eran Libertyf046ccd2005-07-28 10:08:46 -050017#include <version.h>
18
19#define CONFIG_83XX 1 /* needed for Linux kernel header files*/
Eran Libertyf046ccd2005-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 Tyserd98b0522010-10-14 23:33:24 -050026#include <asm/u-boot.h>
Eran Libertyf046ccd2005-07-28 10:08:46 -050027
Eran Libertyf046ccd2005-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 Wood06f60ae2012-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-VILLARD6d0f6bc2008-10-16 15:01:15 +020048#define CONFIG_SYS_FLASHBOOT
Scott Woode4c09502008-06-30 14:13:28 -050049#endif
50
Eran Libertyf046ccd2005-07-28 10:08:46 -050051/*
52 * Set up GOT: Global Offset Table
53 *
Joakim Tjernlund0f8aa152010-01-19 14:41:56 +010054 * Use r12 to access the GOT
Eran Libertyf046ccd2005-07-28 10:08:46 -050055 */
56 START_GOT
57 GOT_ENTRY(_GOT2_TABLE_)
Scott Woode4c09502008-06-30 14:13:28 -050058 GOT_ENTRY(__bss_start)
Simon Glass3929fb02013-03-14 06:54:53 +000059 GOT_ENTRY(__bss_end)
Eran Libertyf046ccd2005-07-28 10:08:46 -050060
Scott Wood06f60ae2012-12-06 13:33:17 +000061#ifndef MINIMAL_SPL
Scott Woode4c09502008-06-30 14:13:28 -050062 GOT_ENTRY(_FIXUP_TABLE_)
Eran Libertyf046ccd2005-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 Woode4c09502008-06-30 14:13:28 -050067#endif
Eran Libertyf046ccd2005-07-28 10:08:46 -050068 END_GOT
69
70/*
Jerry Van Barenf35f3582006-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 Libertyf046ccd2005-07-28 10:08:46 -050075 */
Eran Libertyf046ccd2005-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-VILLARD6d0f6bc2008-10-16 15:01:15 +020083 _HRCW_TABLE_ENTRY(CONFIG_SYS_HRCW_LOW)
84 _HRCW_TABLE_ENTRY(CONFIG_SYS_HRCW_HIGH)
Eran Libertyf046ccd2005-07-28 10:08:46 -050085
Jerry Van Barenf35f3582006-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ßmann09c2e902011-07-18 20:24:04 +020094 .ascii U_BOOT_VERSION_STRING, "\0"
Jerry Van Barenf35f3582006-12-06 21:23:55 -050095
Ron Madrid455a4692008-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
Ron Madrid455a4692008-12-12 13:12:45 -0800119 .globl ppcDWstore
120ppcDWstore:
121 lfd 1, 0(r4)
122 stfd 1, 0(r3)
123 blr
124
125 .globl ppcDWload
126ppcDWload:
127 lfd 1, 0(r3)
128 stfd 1, 0(r4)
129 blr
Eran Libertyf046ccd2005-07-28 10:08:46 -0500130
Eran Libertyf046ccd2005-07-28 10:08:46 -0500131#ifndef CONFIG_DEFAULT_IMMR
132#error CONFIG_DEFAULT_IMMR must be defined
Heiko Schocher2eb48ff2017-06-07 17:33:10 +0200133#endif /* CONFIG_DEFAULT_IMMR */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200134#ifndef CONFIG_SYS_IMMR
135#define CONFIG_SYS_IMMR CONFIG_DEFAULT_IMMR
136#endif /* CONFIG_SYS_IMMR */
Eran Libertyf046ccd2005-07-28 10:08:46 -0500137
138/*
139 * After configuration, a system reset exception is executed using the
140 * vector at offset 0x100 relative to the base set by MSR[IP]. If
141 * MSR[IP] is 0, the base address is 0x00000000. If MSR[IP] is 1, the
142 * base address is 0xfff00000. In the case of a Power On Reset or Hard
143 * Reset, the value of MSR[IP] is determined by the CIP field in the
144 * HRCW.
145 *
146 * Other bits in the HRCW set up the Base Address and Port Size in BR0.
147 * This determines the location of the boot ROM (flash or EPROM) in the
148 * processor's address space at boot time. As long as the HRCW is set up
149 * so that we eventually end up executing the code below when the
150 * processor executes the reset exception, the actual values used should
151 * not matter.
152 *
153 * Once we have got here, the address mask in OR0 is cleared so that the
154 * bottom 32K of the boot ROM is effectively repeated all throughout the
155 * processor's address space, after which we can jump to the absolute
156 * address at which the boot ROM was linked at compile time, and proceed
157 * to initialise the memory controller without worrying if the rug will
158 * be pulled out from under us, so to speak (it will be fine as long as
159 * we configure BR0 with the same boot ROM link address).
160 */
161 . = EXC_OFF_SYS_RESET
162
163 .globl _start
164_start: /* time t 0 */
Eran Libertyf046ccd2005-07-28 10:08:46 -0500165 lis r4, CONFIG_DEFAULT_IMMR@h
166 nop
Peter Tyser52ebd9c2010-09-14 19:13:53 -0500167
Eran Libertyf046ccd2005-07-28 10:08:46 -0500168 mfmsr r5 /* save msr contents */
Scott Wood66778762009-01-20 11:56:11 -0600169
170 /* 83xx manuals prescribe a specific sequence for updating IMMRBAR. */
171 bl 1f
1721: mflr r7
173
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200174 lis r3, CONFIG_SYS_IMMR@h
175 ori r3, r3, CONFIG_SYS_IMMR@l
Scott Wood66778762009-01-20 11:56:11 -0600176
177 lwz r6, IMMRBAR(r4)
178 isync
179
Eran Libertyf046ccd2005-07-28 10:08:46 -0500180 stw r3, IMMRBAR(r4)
Scott Wood66778762009-01-20 11:56:11 -0600181 lwz r6, 0(r7) /* Arbitrary external load */
182 isync
183
184 lwz r6, IMMRBAR(r3)
185 isync
Jon Loeligerde1d0a62005-08-01 13:20:47 -0500186
Eran Libertyf046ccd2005-07-28 10:08:46 -0500187 /* Initialise the E300 processor core */
188 /*------------------------------------------*/
Jon Loeligerde1d0a62005-08-01 13:20:47 -0500189
Scott Wood06f60ae2012-12-06 13:33:17 +0000190#if (defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_MPC83XX_WAIT_FOR_NAND)) || \
191 defined(CONFIG_NAND_SPL)
Lepcha Suchitfa7b1c02008-10-16 13:38:00 -0500192 /* The FCM begins execution after only the first page
193 * is loaded. Wait for the rest before branching
194 * to another flash page.
195 */
Scott Wood66778762009-01-20 11:56:11 -06001961: lwz r6, 0x50b0(r3)
Lepcha Suchitfa7b1c02008-10-16 13:38:00 -0500197 andi. r6, r6, 1
198 beq 1b
199#endif
200
Eran Libertyf046ccd2005-07-28 10:08:46 -0500201 bl init_e300_core
Jon Loeligerde1d0a62005-08-01 13:20:47 -0500202
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200203#ifdef CONFIG_SYS_FLASHBOOT
Eran Libertyf046ccd2005-07-28 10:08:46 -0500204
205 /* Inflate flash location so it appears everywhere, calculate */
206 /* the absolute address in final location of the FLASH, jump */
207 /* there and deflate the flash size back to minimal size */
208 /*------------------------------------------------------------*/
209 bl map_flash_by_law1
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200210 lis r4, (CONFIG_SYS_MONITOR_BASE)@h
211 ori r4, r4, (CONFIG_SYS_MONITOR_BASE)@l
Eran Libertyf046ccd2005-07-28 10:08:46 -0500212 addi r5, r4, in_flash - _start + EXC_OFF_SYS_RESET
213 mtlr r5
214 blr
215in_flash:
216#if 1 /* Remapping flash with LAW0. */
217 bl remap_flash_by_law0
218#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200219#endif /* CONFIG_SYS_FLASHBOOT */
Eran Libertyf046ccd2005-07-28 10:08:46 -0500220
Kumar Gala2688e2f2006-02-10 15:40:06 -0600221 /* setup the bats */
222 bl setup_bats
223 sync
224
225 /*
226 * Cache must be enabled here for stack-in-cache trick.
227 * This means we need to enable the BATS.
228 * This means:
229 * 1) for the EVB, original gt regs need to be mapped
230 * 2) need to have an IBAT for the 0xf region,
231 * we are running there!
232 * Cache should be turned on after BATs, since by default
233 * everything is write-through.
234 * The init-mem BAT can be reused after reloc. The old
235 * gt-regs BAT can be reused after board_init_f calls
236 * board_early_init_f (EVB only).
237 */
238 /* enable address translation */
239 bl enable_addr_trans
240 sync
241
Nick Spence6eb2a442008-08-28 14:09:25 -0700242 /* enable the data cache */
Kumar Gala2688e2f2006-02-10 15:40:06 -0600243 bl dcache_enable
244 sync
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200245#ifdef CONFIG_SYS_INIT_RAM_LOCK
Kumar Gala2688e2f2006-02-10 15:40:06 -0600246 bl lock_ram_in_cache
247 sync
248#endif
249
250 /* set up the stack pointer in our newly created
mario.six@gdsys.cce80311a2017-01-17 08:33:47 +0100251 * cache-ram; use r3 to keep the new SP for now to
252 * avoid overiding the SP it uselessly */
253 lis r3, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET)@h
254 ori r3, r3, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET)@l
Kumar Gala2688e2f2006-02-10 15:40:06 -0600255
mario.six@gdsys.ccdbcb2c02017-01-17 08:33:48 +0100256 /* r4 = end of GD area */
257 addi r4, r3, GENERATED_GBL_DATA_SIZE
258
259 /* Zero GD area */
260 li r0, 0
2611:
262 subi r4, r4, 1
263 stb r0, 0(r4)
264 cmplw r3, r4
265 bne 1b
266
Andy Yan2b71d092017-07-24 17:47:27 +0800267#if CONFIG_VAL(SYS_MALLOC_F_LEN)
mario.six@gdsys.ccdbcb2c02017-01-17 08:33:48 +0100268
Andy Yan2b71d092017-07-24 17:47:27 +0800269#if CONFIG_VAL(SYS_MALLOC_F_LEN) + GENERATED_GBL_DATA_SIZE > CONFIG_SYS_INIT_RAM_SIZE
270#error "SYS_MALLOC_F_LEN too large to fit into initial RAM."
mario.six@gdsys.ccdbcb2c02017-01-17 08:33:48 +0100271#endif
272
273 /* r3 = new stack pointer / pre-reloc malloc area */
Andy Yan2b71d092017-07-24 17:47:27 +0800274 subi r3, r3, CONFIG_VAL(SYS_MALLOC_F_LEN)
mario.six@gdsys.ccdbcb2c02017-01-17 08:33:48 +0100275
276 /* Set pointer to pre-reloc malloc area in GD */
277 stw r3, GD_MALLOC_BASE(r4)
278#endif
Kumar Gala2688e2f2006-02-10 15:40:06 -0600279 li r0, 0 /* Make room for stack frame header and */
mario.six@gdsys.cce80311a2017-01-17 08:33:47 +0100280 stwu r0, -4(r3) /* clear final stack frame so that */
281 stwu r0, -4(r3) /* stack backtraces terminate cleanly */
Kumar Gala2688e2f2006-02-10 15:40:06 -0600282
mario.six@gdsys.cce80311a2017-01-17 08:33:47 +0100283 /* Finally, actually set SP */
284 mr r1, r3
Eran Libertyf046ccd2005-07-28 10:08:46 -0500285
286 /* let the C-code set up the rest */
Kumar Gala2688e2f2006-02-10 15:40:06 -0600287 /* */
Eran Libertyf046ccd2005-07-28 10:08:46 -0500288 /* Be careful to keep code relocatable & stack humble */
289 /*------------------------------------------------------*/
290
291 GET_GOT /* initialize GOT access */
Wolfgang Denk8c4734e2011-04-20 22:11:21 +0200292
Eran Libertyf046ccd2005-07-28 10:08:46 -0500293 /* r3: IMMR */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200294 lis r3, CONFIG_SYS_IMMR@h
Eran Libertyf046ccd2005-07-28 10:08:46 -0500295 /* run low-level CPU init code (in Flash)*/
296 bl cpu_init_f
297
Eran Libertyf046ccd2005-07-28 10:08:46 -0500298 /* run 1st part of board init code (in Flash)*/
Valentin Longchampe83a7e92014-10-03 11:45:23 +0200299 li r3, 0 /* clear boot_flag for calling board_init_f */
Eran Libertyf046ccd2005-07-28 10:08:46 -0500300 bl board_init_f
301
Peter Tyser52ebd9c2010-09-14 19:13:53 -0500302 /* NOTREACHED - board_init_f() does not return */
303
Scott Wood06f60ae2012-12-06 13:33:17 +0000304#ifndef MINIMAL_SPL
Eran Libertyf046ccd2005-07-28 10:08:46 -0500305/*
306 * Vector Table
307 */
308
309 .globl _start_of_vectors
310_start_of_vectors:
311
312/* Machine check */
313 STD_EXCEPTION(0x200, MachineCheck, MachineCheckException)
314
315/* Data Storage exception. */
316 STD_EXCEPTION(0x300, DataStorage, UnknownException)
317
318/* Instruction Storage exception. */
319 STD_EXCEPTION(0x400, InstStorage, UnknownException)
320
321/* External Interrupt exception. */
322#ifndef FIXME
323 STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
Jon Loeligerde1d0a62005-08-01 13:20:47 -0500324#endif
Eran Libertyf046ccd2005-07-28 10:08:46 -0500325
326/* Alignment exception. */
327 . = 0x600
328Alignment:
Rafal Jaworowski02032e82007-06-22 14:58:04 +0200329 EXCEPTION_PROLOG(SRR0, SRR1)
Eran Libertyf046ccd2005-07-28 10:08:46 -0500330 mfspr r4,DAR
331 stw r4,_DAR(r21)
332 mfspr r5,DSISR
333 stw r5,_DSISR(r21)
334 addi r3,r1,STACK_FRAME_OVERHEAD
Joakim Tjernlundfc4e1882010-01-19 14:41:55 +0100335 EXC_XFER_TEMPLATE(Alignment, AlignmentException, MSR_KERNEL, COPY_EE)
Eran Libertyf046ccd2005-07-28 10:08:46 -0500336
337/* Program check exception */
338 . = 0x700
339ProgramCheck:
Rafal Jaworowski02032e82007-06-22 14:58:04 +0200340 EXCEPTION_PROLOG(SRR0, SRR1)
Eran Libertyf046ccd2005-07-28 10:08:46 -0500341 addi r3,r1,STACK_FRAME_OVERHEAD
Joakim Tjernlundfc4e1882010-01-19 14:41:55 +0100342 EXC_XFER_TEMPLATE(ProgramCheck, ProgramCheckException,
343 MSR_KERNEL, COPY_EE)
Eran Libertyf046ccd2005-07-28 10:08:46 -0500344
345 STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
346
347 /* I guess we could implement decrementer, and may have
348 * to someday for timekeeping.
349 */
350 STD_EXCEPTION(0x900, Decrementer, timer_interrupt)
351
352 STD_EXCEPTION(0xa00, Trap_0a, UnknownException)
353 STD_EXCEPTION(0xb00, Trap_0b, UnknownException)
354 STD_EXCEPTION(0xc00, SystemCall, UnknownException)
355 STD_EXCEPTION(0xd00, SingleStep, UnknownException)
356
357 STD_EXCEPTION(0xe00, Trap_0e, UnknownException)
358 STD_EXCEPTION(0xf00, Trap_0f, UnknownException)
359
360 STD_EXCEPTION(0x1000, InstructionTLBMiss, UnknownException)
361 STD_EXCEPTION(0x1100, DataLoadTLBMiss, UnknownException)
362 STD_EXCEPTION(0x1200, DataStoreTLBMiss, UnknownException)
363#ifdef DEBUG
364 . = 0x1300
365 /*
366 * This exception occurs when the program counter matches the
367 * Instruction Address Breakpoint Register (IABR).
368 *
369 * I want the cpu to halt if this occurs so I can hunt around
370 * with the debugger and look at things.
371 *
372 * When DEBUG is defined, both machine check enable (in the MSR)
373 * and checkstop reset enable (in the reset mode register) are
374 * turned off and so a checkstop condition will result in the cpu
375 * halting.
376 *
377 * I force the cpu into a checkstop condition by putting an illegal
378 * instruction here (at least this is the theory).
379 *
380 * well - that didnt work, so just do an infinite loop!
381 */
3821: b 1b
383#else
384 STD_EXCEPTION(0x1300, InstructionBreakpoint, DebugException)
385#endif
386 STD_EXCEPTION(0x1400, SMI, UnknownException)
387
388 STD_EXCEPTION(0x1500, Trap_15, UnknownException)
389 STD_EXCEPTION(0x1600, Trap_16, UnknownException)
390 STD_EXCEPTION(0x1700, Trap_17, UnknownException)
391 STD_EXCEPTION(0x1800, Trap_18, UnknownException)
392 STD_EXCEPTION(0x1900, Trap_19, UnknownException)
393 STD_EXCEPTION(0x1a00, Trap_1a, UnknownException)
394 STD_EXCEPTION(0x1b00, Trap_1b, UnknownException)
395 STD_EXCEPTION(0x1c00, Trap_1c, UnknownException)
396 STD_EXCEPTION(0x1d00, Trap_1d, UnknownException)
397 STD_EXCEPTION(0x1e00, Trap_1e, UnknownException)
398 STD_EXCEPTION(0x1f00, Trap_1f, UnknownException)
399 STD_EXCEPTION(0x2000, Trap_20, UnknownException)
400 STD_EXCEPTION(0x2100, Trap_21, UnknownException)
401 STD_EXCEPTION(0x2200, Trap_22, UnknownException)
402 STD_EXCEPTION(0x2300, Trap_23, UnknownException)
403 STD_EXCEPTION(0x2400, Trap_24, UnknownException)
404 STD_EXCEPTION(0x2500, Trap_25, UnknownException)
405 STD_EXCEPTION(0x2600, Trap_26, UnknownException)
406 STD_EXCEPTION(0x2700, Trap_27, UnknownException)
407 STD_EXCEPTION(0x2800, Trap_28, UnknownException)
408 STD_EXCEPTION(0x2900, Trap_29, UnknownException)
409 STD_EXCEPTION(0x2a00, Trap_2a, UnknownException)
410 STD_EXCEPTION(0x2b00, Trap_2b, UnknownException)
411 STD_EXCEPTION(0x2c00, Trap_2c, UnknownException)
412 STD_EXCEPTION(0x2d00, Trap_2d, UnknownException)
413 STD_EXCEPTION(0x2e00, Trap_2e, UnknownException)
414 STD_EXCEPTION(0x2f00, Trap_2f, UnknownException)
415
416
417 .globl _end_of_vectors
418_end_of_vectors:
419
420 . = 0x3000
421
422/*
423 * This code finishes saving the registers to the exception frame
424 * and jumps to the appropriate handler for the exception.
425 * Register r21 is pointer into trap frame, r1 has new stack pointer.
426 */
427 .globl transfer_to_handler
428transfer_to_handler:
429 stw r22,_NIP(r21)
430 lis r22,MSR_POW@h
431 andc r23,r23,r22
432 stw r23,_MSR(r21)
433 SAVE_GPR(7, r21)
434 SAVE_4GPRS(8, r21)
435 SAVE_8GPRS(12, r21)
436 SAVE_8GPRS(24, r21)
437 mflr r23
438 andi. r24,r23,0x3f00 /* get vector offset */
439 stw r24,TRAP(r21)
440 li r22,0
441 stw r22,RESULT(r21)
442 lwz r24,0(r23) /* virtual address of handler */
443 lwz r23,4(r23) /* where to go when done */
444 mtspr SRR0,r24
445 mtspr SRR1,r20
446 mtlr r23
447 SYNC
448 rfi /* jump to handler, enable MMU */
449
450int_return:
451 mfmsr r28 /* Disable interrupts */
452 li r4,0
453 ori r4,r4,MSR_EE
454 andc r28,r28,r4
455 SYNC /* Some chip revs need this... */
456 mtmsr r28
457 SYNC
458 lwz r2,_CTR(r1)
459 lwz r0,_LINK(r1)
460 mtctr r2
461 mtlr r0
462 lwz r2,_XER(r1)
463 lwz r0,_CCR(r1)
464 mtspr XER,r2
465 mtcrf 0xFF,r0
466 REST_10GPRS(3, r1)
467 REST_10GPRS(13, r1)
468 REST_8GPRS(23, r1)
469 REST_GPR(31, r1)
470 lwz r2,_NIP(r1) /* Restore environment */
471 lwz r0,_MSR(r1)
472 mtspr SRR0,r2
473 mtspr SRR1,r0
474 lwz r0,GPR0(r1)
475 lwz r2,GPR2(r1)
476 lwz r1,GPR1(r1)
477 SYNC
478 rfi
Scott Wood06f60ae2012-12-06 13:33:17 +0000479#endif /* !MINIMAL_SPL */
Eran Libertyf046ccd2005-07-28 10:08:46 -0500480
481/*
482 * This code initialises the E300 processor core
483 * (conforms to PowerPC 603e spec)
484 * Note: expects original MSR contents to be in r5.
485 */
486 .globl init_e300_core
487init_e300_core: /* time t 10 */
488 /* Initialize machine status; enable machine check interrupt */
489 /*-----------------------------------------------------------*/
490
491 li r3, MSR_KERNEL /* Set ME and RI flags */
492 rlwimi r3, r5, 0, 25, 25 /* preserve IP bit set by HRCW */
493#ifdef DEBUG
494 rlwimi r3, r5, 0, 21, 22 /* debugger might set SE & BE bits */
495#endif
496 SYNC /* Some chip revs need this... */
497 mtmsr r3
498 SYNC
499 mtspr SRR1, r3 /* Make SRR1 match MSR */
500
501
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200502 lis r3, CONFIG_SYS_IMMR@h
Eran Libertyf046ccd2005-07-28 10:08:46 -0500503#if defined(CONFIG_WATCHDOG)
Horst Kronstorferf6970d02010-05-18 10:37:05 +0200504 /* Initialise the Watchdog values and reset it (if req) */
Eran Libertyf046ccd2005-07-28 10:08:46 -0500505 /*------------------------------------------------------*/
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200506 lis r4, CONFIG_SYS_WATCHDOG_VALUE
Eran Libertyf046ccd2005-07-28 10:08:46 -0500507 ori r4, r4, (SWCRR_SWEN | SWCRR_SWRI | SWCRR_SWPR)
508 stw r4, SWCRR(r3)
Jon Loeligerde1d0a62005-08-01 13:20:47 -0500509
Eran Libertyf046ccd2005-07-28 10:08:46 -0500510 /* and reset it */
Jon Loeligerde1d0a62005-08-01 13:20:47 -0500511
Eran Libertyf046ccd2005-07-28 10:08:46 -0500512 li r4, 0x556C
513 sth r4, SWSRR@l(r3)
Heiko Schocherf6db9452008-01-11 15:15:17 +0100514 li r4, -0x55C7
Eran Libertyf046ccd2005-07-28 10:08:46 -0500515 sth r4, SWSRR@l(r3)
516#else
Horst Kronstorferf6970d02010-05-18 10:37:05 +0200517 /* Disable Watchdog */
Eran Libertyf046ccd2005-07-28 10:08:46 -0500518 /*-------------------*/
Kumar Galaec00c332006-01-11 11:23:01 -0600519 lwz r4, SWCRR(r3)
520 /* Check to see if its enabled for disabling
521 once disabled by SW you can't re-enable */
522 andi. r4, r4, 0x4
523 beq 1f
Eran Libertyf046ccd2005-07-28 10:08:46 -0500524 xor r4, r4, r4
525 stw r4, SWCRR(r3)
Kumar Galaec00c332006-01-11 11:23:01 -06005261:
Eran Libertyf046ccd2005-07-28 10:08:46 -0500527#endif /* CONFIG_WATCHDOG */
528
Nick Spence46497052008-08-28 14:09:19 -0700529#if defined(CONFIG_MASK_AER_AO)
530 /* Write the Arbiter Event Enable to mask Address Only traps. */
531 /* This prevents the dcbz instruction from being trapped when */
532 /* HID0_ABE Address Broadcast Enable is set and the MEMORY */
533 /* COHERENCY bit is set in the WIMG bits, which is often */
534 /* needed for PCI operation. */
535 lwz r4, 0x0808(r3)
536 rlwinm r0, r4, 0, ~AER_AO
537 stw r0, 0x0808(r3)
538#endif /* CONFIG_MASK_AER_AO */
539
Eran Libertyf046ccd2005-07-28 10:08:46 -0500540 /* Initialize the Hardware Implementation-dependent Registers */
541 /* HID0 also contains cache control */
Nick Spence6eb2a442008-08-28 14:09:25 -0700542 /* - force invalidation of data and instruction caches */
Eran Libertyf046ccd2005-07-28 10:08:46 -0500543 /*------------------------------------------------------*/
544
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200545 lis r3, CONFIG_SYS_HID0_INIT@h
546 ori r3, r3, (CONFIG_SYS_HID0_INIT | HID0_ICFI | HID0_DCFI)@l
Eran Libertyf046ccd2005-07-28 10:08:46 -0500547 SYNC
548 mtspr HID0, r3
549
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200550 lis r3, CONFIG_SYS_HID0_FINAL@h
551 ori r3, r3, (CONFIG_SYS_HID0_FINAL & ~(HID0_ICFI | HID0_DCFI))@l
Eran Libertyf046ccd2005-07-28 10:08:46 -0500552 SYNC
553 mtspr HID0, r3
554
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200555 lis r3, CONFIG_SYS_HID2@h
556 ori r3, r3, CONFIG_SYS_HID2@l
Eran Libertyf046ccd2005-07-28 10:08:46 -0500557 SYNC
558 mtspr HID2, r3
559
Scott Woode4c09502008-06-30 14:13:28 -0500560 /* Done! */
561 /*------------------------------*/
562 blr
Eran Libertyf046ccd2005-07-28 10:08:46 -0500563
Scott Woode4c09502008-06-30 14:13:28 -0500564 /* setup_bats - set them up to some initial state */
565 .globl setup_bats
566setup_bats:
567 addis r0, r0, 0x0000
568
569 /* IBAT 0 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200570 addis r4, r0, CONFIG_SYS_IBAT0L@h
571 ori r4, r4, CONFIG_SYS_IBAT0L@l
572 addis r3, r0, CONFIG_SYS_IBAT0U@h
573 ori r3, r3, CONFIG_SYS_IBAT0U@l
Scott Woode4c09502008-06-30 14:13:28 -0500574 mtspr IBAT0L, r4
575 mtspr IBAT0U, r3
576
577 /* DBAT 0 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200578 addis r4, r0, CONFIG_SYS_DBAT0L@h
579 ori r4, r4, CONFIG_SYS_DBAT0L@l
580 addis r3, r0, CONFIG_SYS_DBAT0U@h
581 ori r3, r3, CONFIG_SYS_DBAT0U@l
Scott Woode4c09502008-06-30 14:13:28 -0500582 mtspr DBAT0L, r4
583 mtspr DBAT0U, r3
584
585 /* IBAT 1 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200586 addis r4, r0, CONFIG_SYS_IBAT1L@h
587 ori r4, r4, CONFIG_SYS_IBAT1L@l
588 addis r3, r0, CONFIG_SYS_IBAT1U@h
589 ori r3, r3, CONFIG_SYS_IBAT1U@l
Scott Woode4c09502008-06-30 14:13:28 -0500590 mtspr IBAT1L, r4
591 mtspr IBAT1U, r3
592
593 /* DBAT 1 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200594 addis r4, r0, CONFIG_SYS_DBAT1L@h
595 ori r4, r4, CONFIG_SYS_DBAT1L@l
596 addis r3, r0, CONFIG_SYS_DBAT1U@h
597 ori r3, r3, CONFIG_SYS_DBAT1U@l
Scott Woode4c09502008-06-30 14:13:28 -0500598 mtspr DBAT1L, r4
599 mtspr DBAT1U, r3
600
601 /* IBAT 2 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200602 addis r4, r0, CONFIG_SYS_IBAT2L@h
603 ori r4, r4, CONFIG_SYS_IBAT2L@l
604 addis r3, r0, CONFIG_SYS_IBAT2U@h
605 ori r3, r3, CONFIG_SYS_IBAT2U@l
Scott Woode4c09502008-06-30 14:13:28 -0500606 mtspr IBAT2L, r4
607 mtspr IBAT2U, r3
608
609 /* DBAT 2 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200610 addis r4, r0, CONFIG_SYS_DBAT2L@h
611 ori r4, r4, CONFIG_SYS_DBAT2L@l
612 addis r3, r0, CONFIG_SYS_DBAT2U@h
613 ori r3, r3, CONFIG_SYS_DBAT2U@l
Scott Woode4c09502008-06-30 14:13:28 -0500614 mtspr DBAT2L, r4
615 mtspr DBAT2U, r3
616
617 /* IBAT 3 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200618 addis r4, r0, CONFIG_SYS_IBAT3L@h
619 ori r4, r4, CONFIG_SYS_IBAT3L@l
620 addis r3, r0, CONFIG_SYS_IBAT3U@h
621 ori r3, r3, CONFIG_SYS_IBAT3U@l
Scott Woode4c09502008-06-30 14:13:28 -0500622 mtspr IBAT3L, r4
623 mtspr IBAT3U, r3
624
625 /* DBAT 3 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200626 addis r4, r0, CONFIG_SYS_DBAT3L@h
627 ori r4, r4, CONFIG_SYS_DBAT3L@l
628 addis r3, r0, CONFIG_SYS_DBAT3U@h
629 ori r3, r3, CONFIG_SYS_DBAT3U@l
Scott Woode4c09502008-06-30 14:13:28 -0500630 mtspr DBAT3L, r4
631 mtspr DBAT3U, r3
632
633#ifdef CONFIG_HIGH_BATS
634 /* IBAT 4 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200635 addis r4, r0, CONFIG_SYS_IBAT4L@h
636 ori r4, r4, CONFIG_SYS_IBAT4L@l
637 addis r3, r0, CONFIG_SYS_IBAT4U@h
638 ori r3, r3, CONFIG_SYS_IBAT4U@l
Scott Woode4c09502008-06-30 14:13:28 -0500639 mtspr IBAT4L, r4
640 mtspr IBAT4U, r3
641
642 /* DBAT 4 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200643 addis r4, r0, CONFIG_SYS_DBAT4L@h
644 ori r4, r4, CONFIG_SYS_DBAT4L@l
645 addis r3, r0, CONFIG_SYS_DBAT4U@h
646 ori r3, r3, CONFIG_SYS_DBAT4U@l
Scott Woode4c09502008-06-30 14:13:28 -0500647 mtspr DBAT4L, r4
648 mtspr DBAT4U, r3
649
650 /* IBAT 5 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200651 addis r4, r0, CONFIG_SYS_IBAT5L@h
652 ori r4, r4, CONFIG_SYS_IBAT5L@l
653 addis r3, r0, CONFIG_SYS_IBAT5U@h
654 ori r3, r3, CONFIG_SYS_IBAT5U@l
Scott Woode4c09502008-06-30 14:13:28 -0500655 mtspr IBAT5L, r4
656 mtspr IBAT5U, r3
657
658 /* DBAT 5 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200659 addis r4, r0, CONFIG_SYS_DBAT5L@h
660 ori r4, r4, CONFIG_SYS_DBAT5L@l
661 addis r3, r0, CONFIG_SYS_DBAT5U@h
662 ori r3, r3, CONFIG_SYS_DBAT5U@l
Scott Woode4c09502008-06-30 14:13:28 -0500663 mtspr DBAT5L, r4
664 mtspr DBAT5U, r3
665
666 /* IBAT 6 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200667 addis r4, r0, CONFIG_SYS_IBAT6L@h
668 ori r4, r4, CONFIG_SYS_IBAT6L@l
669 addis r3, r0, CONFIG_SYS_IBAT6U@h
670 ori r3, r3, CONFIG_SYS_IBAT6U@l
Scott Woode4c09502008-06-30 14:13:28 -0500671 mtspr IBAT6L, r4
672 mtspr IBAT6U, r3
673
674 /* DBAT 6 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200675 addis r4, r0, CONFIG_SYS_DBAT6L@h
676 ori r4, r4, CONFIG_SYS_DBAT6L@l
677 addis r3, r0, CONFIG_SYS_DBAT6U@h
678 ori r3, r3, CONFIG_SYS_DBAT6U@l
Scott Woode4c09502008-06-30 14:13:28 -0500679 mtspr DBAT6L, r4
680 mtspr DBAT6U, r3
681
682 /* IBAT 7 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200683 addis r4, r0, CONFIG_SYS_IBAT7L@h
684 ori r4, r4, CONFIG_SYS_IBAT7L@l
685 addis r3, r0, CONFIG_SYS_IBAT7U@h
686 ori r3, r3, CONFIG_SYS_IBAT7U@l
Scott Woode4c09502008-06-30 14:13:28 -0500687 mtspr IBAT7L, r4
688 mtspr IBAT7U, r3
689
690 /* DBAT 7 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200691 addis r4, r0, CONFIG_SYS_DBAT7L@h
692 ori r4, r4, CONFIG_SYS_DBAT7L@l
693 addis r3, r0, CONFIG_SYS_DBAT7U@h
694 ori r3, r3, CONFIG_SYS_DBAT7U@l
Scott Woode4c09502008-06-30 14:13:28 -0500695 mtspr DBAT7L, r4
696 mtspr DBAT7U, r3
697#endif
698
699 isync
Eran Libertyf046ccd2005-07-28 10:08:46 -0500700
701 /* invalidate all tlb's
702 *
703 * From the 603e User Manual: "The 603e provides the ability to
704 * invalidate a TLB entry. The TLB Invalidate Entry (tlbie)
705 * instruction invalidates the TLB entry indexed by the EA, and
706 * operates on both the instruction and data TLBs simultaneously
707 * invalidating four TLB entries (both sets in each TLB). The
708 * index corresponds to bits 15-19 of the EA. To invalidate all
709 * entries within both TLBs, 32 tlbie instructions should be
710 * issued, incrementing this field by one each time."
711 *
712 * "Note that the tlbia instruction is not implemented on the
713 * 603e."
714 *
715 * bits 15-19 correspond to addresses 0x00000000 to 0x0001F000
716 * incrementing by 0x1000 each time. The code below is sort of
Stefan Roesea47a12b2010-04-15 16:07:28 +0200717 * based on code in "flush_tlbs" from arch/powerpc/kernel/head.S
Eran Libertyf046ccd2005-07-28 10:08:46 -0500718 *
719 */
Kumar Gala2688e2f2006-02-10 15:40:06 -0600720 lis r3, 0
721 lis r5, 2
722
7231:
724 tlbie r3
725 addi r3, r3, 0x1000
726 cmp 0, 0, r3, r5
727 blt 1b
728
729 blr
730
Eran Libertyf046ccd2005-07-28 10:08:46 -0500731/* Cache functions.
732 *
733 * Note: requires that all cache bits in
734 * HID0 are in the low half word.
735 */
Scott Wood06f60ae2012-12-06 13:33:17 +0000736#ifndef MINIMAL_SPL
Eran Libertyf046ccd2005-07-28 10:08:46 -0500737 .globl icache_enable
738icache_enable:
739 mfspr r3, HID0
740 ori r3, r3, HID0_ICE
Nick Spence6eb2a442008-08-28 14:09:25 -0700741 li r4, HID0_ICFI|HID0_ILOCK
Eran Libertyf046ccd2005-07-28 10:08:46 -0500742 andc r3, r3, r4
743 ori r4, r3, HID0_ICFI
744 isync
745 mtspr HID0, r4 /* sets enable and invalidate, clears lock */
746 isync
747 mtspr HID0, r3 /* clears invalidate */
748 blr
749
750 .globl icache_disable
751icache_disable:
752 mfspr r3, HID0
753 lis r4, 0
Nick Spence6eb2a442008-08-28 14:09:25 -0700754 ori r4, r4, HID0_ICE|HID0_ICFI|HID0_ILOCK
Eran Libertyf046ccd2005-07-28 10:08:46 -0500755 andc r3, r3, r4
Eran Libertyf046ccd2005-07-28 10:08:46 -0500756 isync
Nick Spence6eb2a442008-08-28 14:09:25 -0700757 mtspr HID0, r3 /* clears invalidate, enable and lock */
Eran Libertyf046ccd2005-07-28 10:08:46 -0500758 blr
759
760 .globl icache_status
761icache_status:
762 mfspr r3, HID0
Marian Balakowicza7c66ad2006-03-14 16:01:25 +0100763 rlwinm r3, r3, (31 - HID0_ICE_SHIFT + 1), 31, 31
Eran Libertyf046ccd2005-07-28 10:08:46 -0500764 blr
Scott Wood06f60ae2012-12-06 13:33:17 +0000765#endif /* !MINIMAL_SPL */
Eran Libertyf046ccd2005-07-28 10:08:46 -0500766
767 .globl dcache_enable
768dcache_enable:
769 mfspr r3, HID0
Kumar Gala2688e2f2006-02-10 15:40:06 -0600770 li r5, HID0_DCFI|HID0_DLOCK
771 andc r3, r3, r5
Kumar Gala2688e2f2006-02-10 15:40:06 -0600772 ori r3, r3, HID0_DCE
Eran Libertyf046ccd2005-07-28 10:08:46 -0500773 sync
Nick Spence6eb2a442008-08-28 14:09:25 -0700774 mtspr HID0, r3 /* enable, no invalidate */
Eran Libertyf046ccd2005-07-28 10:08:46 -0500775 blr
776
777 .globl dcache_disable
778dcache_disable:
Nick Spence6eb2a442008-08-28 14:09:25 -0700779 mflr r4
780 bl flush_dcache /* uses r3 and r5 */
Eran Libertyf046ccd2005-07-28 10:08:46 -0500781 mfspr r3, HID0
Nick Spence6eb2a442008-08-28 14:09:25 -0700782 li r5, HID0_DCE|HID0_DLOCK
783 andc r3, r3, r5
784 ori r5, r3, HID0_DCFI
Eran Libertyf046ccd2005-07-28 10:08:46 -0500785 sync
Nick Spence6eb2a442008-08-28 14:09:25 -0700786 mtspr HID0, r5 /* sets invalidate, clears enable and lock */
Eran Libertyf046ccd2005-07-28 10:08:46 -0500787 sync
788 mtspr HID0, r3 /* clears invalidate */
Nick Spence6eb2a442008-08-28 14:09:25 -0700789 mtlr r4
Eran Libertyf046ccd2005-07-28 10:08:46 -0500790 blr
791
792 .globl dcache_status
793dcache_status:
794 mfspr r3, HID0
Marian Balakowicza7c66ad2006-03-14 16:01:25 +0100795 rlwinm r3, r3, (31 - HID0_DCE_SHIFT + 1), 31, 31
Eran Libertyf046ccd2005-07-28 10:08:46 -0500796 blr
797
Nick Spence6eb2a442008-08-28 14:09:25 -0700798 .globl flush_dcache
799flush_dcache:
800 lis r3, 0
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200801 lis r5, CONFIG_SYS_CACHELINE_SIZE
Nick Spence6eb2a442008-08-28 14:09:25 -07008021: cmp 0, 1, r3, r5
803 bge 2f
804 lwz r5, 0(r3)
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200805 lis r5, CONFIG_SYS_CACHELINE_SIZE
Nick Spence6eb2a442008-08-28 14:09:25 -0700806 addi r3, r3, 0x4
807 b 1b
8082: blr
809
Eran Libertyf046ccd2005-07-28 10:08:46 -0500810/*-------------------------------------------------------------------*/
811
812/*
813 * void relocate_code (addr_sp, gd, addr_moni)
814 *
815 * This "function" does not return, instead it continues in RAM
816 * after relocating the monitor code.
817 *
818 * r3 = dest
819 * r4 = src
820 * r5 = length in bytes
821 * r6 = cachelinesize
822 */
823 .globl relocate_code
824relocate_code:
825 mr r1, r3 /* Set new stack pointer */
826 mr r9, r4 /* Save copy of Global Data pointer */
827 mr r10, r5 /* Save copy of Destination Address */
828
Joakim Tjernlund0f8aa152010-01-19 14:41:56 +0100829 GET_GOT
Eran Libertyf046ccd2005-07-28 10:08:46 -0500830 mr r3, r5 /* Destination Address */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200831 lis r4, CONFIG_SYS_MONITOR_BASE@h /* Source Address */
832 ori r4, r4, CONFIG_SYS_MONITOR_BASE@l
Scott Woode4c09502008-06-30 14:13:28 -0500833 lwz r5, GOT(__bss_start)
Eran Libertyf046ccd2005-07-28 10:08:46 -0500834 sub r5, r5, r4
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200835 li r6, CONFIG_SYS_CACHELINE_SIZE /* Cache Line Size */
Eran Libertyf046ccd2005-07-28 10:08:46 -0500836
837 /*
838 * Fix GOT pointer:
839 *
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200840 * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE)
Eran Libertyf046ccd2005-07-28 10:08:46 -0500841 * + Destination Address
842 *
843 * Offset:
844 */
845 sub r15, r10, r4
846
847 /* First our own GOT */
Joakim Tjernlund0f8aa152010-01-19 14:41:56 +0100848 add r12, r12, r15
Eran Libertyf046ccd2005-07-28 10:08:46 -0500849 /* then the one used by the C code */
850 add r30, r30, r15
851
852 /*
853 * Now relocate code
854 */
855
856 cmplw cr1,r3,r4
857 addi r0,r5,3
858 srwi. r0,r0,2
859 beq cr1,4f /* In place copy is not necessary */
860 beq 7f /* Protect against 0 count */
861 mtctr r0
862 bge cr1,2f
863 la r8,-4(r4)
864 la r7,-4(r3)
865
866 /* copy */
8671: lwzu r0,4(r8)
868 stwu r0,4(r7)
869 bdnz 1b
870
871 addi r0,r5,3
872 srwi. r0,r0,2
873 mtctr r0
874 la r8,-4(r4)
875 la r7,-4(r3)
Jon Loeligerde1d0a62005-08-01 13:20:47 -0500876
877 /* and compare */
Eran Libertyf046ccd2005-07-28 10:08:46 -050087820: lwzu r20,4(r8)
879 lwzu r21,4(r7)
880 xor. r22, r20, r21
881 bne 30f
882 bdnz 20b
883 b 4f
884
885 /* compare failed */
88630: li r3, 0
887 blr
888
8892: slwi r0,r0,2 /* re copy in reverse order ... y do we needed it? */
890 add r8,r4,r0
891 add r7,r3,r0
8923: lwzu r0,-4(r8)
893 stwu r0,-4(r7)
894 bdnz 3b
Eran Libertyf046ccd2005-07-28 10:08:46 -0500895
896/*
897 * Now flush the cache: note that we must start from a cache aligned
898 * address. Otherwise we might miss one cache line.
899 */
Kumar Gala2688e2f2006-02-10 15:40:06 -06009004: cmpwi r6,0
Eran Libertyf046ccd2005-07-28 10:08:46 -0500901 add r5,r3,r5
Kumar Gala2688e2f2006-02-10 15:40:06 -0600902 beq 7f /* Always flush prefetch queue in any case */
Eran Libertyf046ccd2005-07-28 10:08:46 -0500903 subi r0,r6,1
904 andc r3,r3,r0
Eran Libertyf046ccd2005-07-28 10:08:46 -0500905 mr r4,r3
9065: dcbst 0,r4
907 add r4,r4,r6
908 cmplw r4,r5
909 blt 5b
Kumar Gala2688e2f2006-02-10 15:40:06 -0600910 sync /* Wait for all dcbst to complete on bus */
Eran Libertyf046ccd2005-07-28 10:08:46 -0500911 mr r4,r3
9126: icbi 0,r4
913 add r4,r4,r6
914 cmplw r4,r5
915 blt 6b
Kumar Gala2688e2f2006-02-10 15:40:06 -06009167: sync /* Wait for all icbi to complete on bus */
Eran Libertyf046ccd2005-07-28 10:08:46 -0500917 isync
918
919/*
920 * We are done. Do not return, instead branch to second part of board
921 * initialization, now running from RAM.
922 */
Eran Libertyf046ccd2005-07-28 10:08:46 -0500923 addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
924 mtlr r0
925 blr
926
927in_ram:
928
929 /*
Joakim Tjernlund0f8aa152010-01-19 14:41:56 +0100930 * Relocation Function, r12 point to got2+0x8000
Eran Libertyf046ccd2005-07-28 10:08:46 -0500931 *
932 * Adjust got2 pointers, no need to check for 0, this code
933 * already puts a few entries in the table.
934 */
935 li r0,__got2_entries@sectoff@l
936 la r3,GOT(_GOT2_TABLE_)
937 lwz r11,GOT(_GOT2_TABLE_)
938 mtctr r0
939 sub r11,r3,r11
940 addi r3,r3,-4
9411: lwzu r0,4(r3)
Joakim Tjernlundafc3ba02009-10-08 02:03:51 +0200942 cmpwi r0,0
943 beq- 2f
Eran Libertyf046ccd2005-07-28 10:08:46 -0500944 add r0,r0,r11
945 stw r0,0(r3)
Joakim Tjernlundafc3ba02009-10-08 02:03:51 +02009462: bdnz 1b
Eran Libertyf046ccd2005-07-28 10:08:46 -0500947
Scott Wood06f60ae2012-12-06 13:33:17 +0000948#ifndef MINIMAL_SPL
Eran Libertyf046ccd2005-07-28 10:08:46 -0500949 /*
950 * Now adjust the fixups and the pointers to the fixups
951 * in case we need to move ourselves again.
952 */
Joakim Tjernlundafc3ba02009-10-08 02:03:51 +0200953 li r0,__fixup_entries@sectoff@l
Eran Libertyf046ccd2005-07-28 10:08:46 -0500954 lwz r3,GOT(_FIXUP_TABLE_)
955 cmpwi r0,0
956 mtctr r0
957 addi r3,r3,-4
958 beq 4f
9593: lwzu r4,4(r3)
960 lwzux r0,r4,r11
Joakim Tjernlundd1e0b102010-10-14 11:51:44 +0200961 cmpwi r0,0
Eran Libertyf046ccd2005-07-28 10:08:46 -0500962 add r0,r0,r11
Joakim Tjernlund34bbf612010-11-04 19:02:00 +0100963 stw r4,0(r3)
Joakim Tjernlundd1e0b102010-10-14 11:51:44 +0200964 beq- 5f
Eran Libertyf046ccd2005-07-28 10:08:46 -0500965 stw r0,0(r4)
Joakim Tjernlundd1e0b102010-10-14 11:51:44 +02009665: bdnz 3b
Eran Libertyf046ccd2005-07-28 10:08:46 -05009674:
Scott Woode4c09502008-06-30 14:13:28 -0500968#endif
969
Eran Libertyf046ccd2005-07-28 10:08:46 -0500970clear_bss:
971 /*
972 * Now clear BSS segment
973 */
974 lwz r3,GOT(__bss_start)
Simon Glass3929fb02013-03-14 06:54:53 +0000975 lwz r4,GOT(__bss_end)
Eran Libertyf046ccd2005-07-28 10:08:46 -0500976
977 cmplw 0, r3, r4
978 beq 6f
979
980 li r0, 0
9815:
982 stw r0, 0(r3)
983 addi r3, r3, 4
984 cmplw 0, r3, r4
985 bne 5b
9866:
987
988 mr r3, r9 /* Global Data pointer */
989 mr r4, r10 /* Destination Address */
990 bl board_init_r
991
Scott Wood06f60ae2012-12-06 13:33:17 +0000992#ifndef MINIMAL_SPL
Eran Libertyf046ccd2005-07-28 10:08:46 -0500993 /*
994 * Copy exception vector code to low memory
995 *
996 * r3: dest_addr
997 * r7: source address, r8: end address, r9: target address
998 */
999 .globl trap_init
1000trap_init:
Joakim Tjernlund0f8aa152010-01-19 14:41:56 +01001001 mflr r4 /* save link register */
1002 GET_GOT
Eran Libertyf046ccd2005-07-28 10:08:46 -05001003 lwz r7, GOT(_start)
1004 lwz r8, GOT(_end_of_vectors)
1005
1006 li r9, 0x100 /* reset vector always at 0x100 */
1007
1008 cmplw 0, r7, r8
1009 bgelr /* return if r7>=r8 - just in case */
Eran Libertyf046ccd2005-07-28 10:08:46 -050010101:
1011 lwz r0, 0(r7)
1012 stw r0, 0(r9)
1013 addi r7, r7, 4
1014 addi r9, r9, 4
1015 cmplw 0, r7, r8
1016 bne 1b
1017
1018 /*
1019 * relocate `hdlr' and `int_return' entries
1020 */
1021 li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
1022 li r8, Alignment - _start + EXC_OFF_SYS_RESET
10232:
1024 bl trap_reloc
1025 addi r7, r7, 0x100 /* next exception vector */
1026 cmplw 0, r7, r8
1027 blt 2b
1028
1029 li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
1030 bl trap_reloc
1031
1032 li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
1033 bl trap_reloc
1034
1035 li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
1036 li r8, SystemCall - _start + EXC_OFF_SYS_RESET
10373:
1038 bl trap_reloc
1039 addi r7, r7, 0x100 /* next exception vector */
1040 cmplw 0, r7, r8
1041 blt 3b
1042
1043 li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
1044 li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
10454:
1046 bl trap_reloc
1047 addi r7, r7, 0x100 /* next exception vector */
1048 cmplw 0, r7, r8
1049 blt 4b
1050
1051 mfmsr r3 /* now that the vectors have */
1052 lis r7, MSR_IP@h /* relocated into low memory */
1053 ori r7, r7, MSR_IP@l /* MSR[IP] can be turned off */
1054 andc r3, r3, r7 /* (if it was on) */
1055 SYNC /* Some chip revs need this... */
1056 mtmsr r3
1057 SYNC
1058
1059 mtlr r4 /* restore link register */
1060 blr
1061
Scott Wood06f60ae2012-12-06 13:33:17 +00001062#endif /* !MINIMAL_SPL */
Eran Libertyf046ccd2005-07-28 10:08:46 -05001063
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001064#ifdef CONFIG_SYS_INIT_RAM_LOCK
Kumar Gala2688e2f2006-02-10 15:40:06 -06001065lock_ram_in_cache:
1066 /* Allocate Initial RAM in data cache.
1067 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001068 lis r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@h
1069 ori r3, r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@l
Wolfgang Denk553f0982010-10-26 13:32:32 +02001070 li r4, ((CONFIG_SYS_INIT_RAM_SIZE & ~31) + \
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001071 (CONFIG_SYS_INIT_RAM_ADDR & 31) + 31) / 32
Nick Spenceade50c72008-08-28 14:09:11 -07001072 mtctr r4
Kumar Gala2688e2f2006-02-10 15:40:06 -060010731:
1074 dcbz r0, r3
1075 addi r3, r3, 32
1076 bdnz 1b
1077
1078 /* Lock the data cache */
1079 mfspr r0, HID0
Nick Spence6eb2a442008-08-28 14:09:25 -07001080 ori r0, r0, HID0_DLOCK
Kumar Gala2688e2f2006-02-10 15:40:06 -06001081 sync
1082 mtspr HID0, r0
1083 sync
1084 blr
1085
Scott Wood06f60ae2012-12-06 13:33:17 +00001086#ifndef MINIMAL_SPL
Eran Libertyf046ccd2005-07-28 10:08:46 -05001087.globl unlock_ram_in_cache
1088unlock_ram_in_cache:
1089 /* invalidate the INIT_RAM section */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001090 lis r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@h
1091 ori r3, r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@l
Wolfgang Denk553f0982010-10-26 13:32:32 +02001092 li r4, ((CONFIG_SYS_INIT_RAM_SIZE & ~31) + \
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001093 (CONFIG_SYS_INIT_RAM_ADDR & 31) + 31) / 32
Nick Spenceade50c72008-08-28 14:09:11 -07001094 mtctr r4
Eran Libertyf046ccd2005-07-28 10:08:46 -050010951: icbi r0, r3
1096 dcbi r0, r3
1097 addi r3, r3, 32
1098 bdnz 1b
1099 sync /* Wait for all icbi to complete on bus */
1100 isync
Kumar Gala2688e2f2006-02-10 15:40:06 -06001101
1102 /* Unlock the data cache and invalidate it */
1103 mfspr r3, HID0
1104 li r5, HID0_DLOCK|HID0_DCFI
1105 andc r3, r3, r5 /* no invalidate, unlock */
1106 ori r5, r3, HID0_DCFI /* invalidate, unlock */
Kumar Gala2688e2f2006-02-10 15:40:06 -06001107 sync
Nick Spence6eb2a442008-08-28 14:09:25 -07001108 mtspr HID0, r5 /* invalidate, unlock */
1109 sync
1110 mtspr HID0, r3 /* no invalidate, unlock */
Eran Libertyf046ccd2005-07-28 10:08:46 -05001111 blr
Scott Wood06f60ae2012-12-06 13:33:17 +00001112#endif /* !MINIMAL_SPL */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001113#endif /* CONFIG_SYS_INIT_RAM_LOCK */
Eran Libertyf046ccd2005-07-28 10:08:46 -05001114
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001115#ifdef CONFIG_SYS_FLASHBOOT
Eran Libertyf046ccd2005-07-28 10:08:46 -05001116map_flash_by_law1:
1117 /* When booting from ROM (Flash or EPROM), clear the */
1118 /* Address Mask in OR0 so ROM appears everywhere */
1119 /*----------------------------------------------------*/
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001120 lis r3, (CONFIG_SYS_IMMR)@h /* r3 <= CONFIG_SYS_IMMR */
Jon Loeligerde1d0a62005-08-01 13:20:47 -05001121 lwz r4, OR0@l(r3)
Eran Libertyf046ccd2005-07-28 10:08:46 -05001122 li r5, 0x7fff /* r5 <= 0x00007FFFF */
Jon Loeligerde1d0a62005-08-01 13:20:47 -05001123 and r4, r4, r5
Eran Libertyf046ccd2005-07-28 10:08:46 -05001124 stw r4, OR0@l(r3) /* OR0 <= OR0 & 0x00007FFFF */
1125
1126 /* As MPC8349E User's Manual presented, when RCW[BMS] is set to 0,
1127 * system will boot from 0x0000_0100, and the LBLAWBAR0[BASE_ADDR]
1128 * reset value is 0x00000; when RCW[BMS] is set to 1, system will boot
1129 * from 0xFFF0_0100, and the LBLAWBAR0[BASE_ADDR] reset value is
1130 * 0xFF800. From the hard resetting to here, the processor fetched and
1131 * executed the instructions one by one. There is not absolutely
1132 * jumping happened. Laterly, the u-boot code has to do an absolutely
1133 * jumping to tell the CPU instruction fetching component what the
1134 * u-boot TEXT base address is. Because the TEXT base resides in the
1135 * boot ROM memory space, to garantee the code can run smoothly after
1136 * that jumping, we must map in the entire boot ROM by Local Access
1137 * Window. Sometimes, we desire an non-0x00000 or non-0xFF800 starting
1138 * address for boot ROM, such as 0xFE000000. In this case, the default
1139 * LBIU Local Access Widow 0 will not cover this memory space. So, we
1140 * need another window to map in it.
1141 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001142 lis r4, (CONFIG_SYS_FLASH_BASE)@h
1143 ori r4, r4, (CONFIG_SYS_FLASH_BASE)@l
1144 stw r4, LBLAWBAR1(r3) /* LBLAWBAR1 <= CONFIG_SYS_FLASH_BASE */
Timur Tabi31068b72006-08-22 17:07:00 -05001145
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001146 /* Store 0x80000012 + log2(CONFIG_SYS_FLASH_SIZE) into LBLAWAR1 */
Timur Tabi31068b72006-08-22 17:07:00 -05001147 lis r4, (0x80000012)@h
1148 ori r4, r4, (0x80000012)@l
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001149 li r5, CONFIG_SYS_FLASH_SIZE
Timur Tabi31068b72006-08-22 17:07:00 -050011501: srawi. r5, r5, 1 /* r5 = r5 >> 1 */
1151 addi r4, r4, 1
1152 bne 1b
1153
Eran Libertyf046ccd2005-07-28 10:08:46 -05001154 stw r4, LBLAWAR1(r3) /* LBLAWAR1 <= 8MB Flash Size */
Joakim Tjernlunde45c98a2010-11-19 14:15:33 +01001155 /* Wait for HW to catch up */
1156 lwz r4, LBLAWAR1(r3)
1157 twi 0,r4,0
1158 isync
Eran Libertyf046ccd2005-07-28 10:08:46 -05001159 blr
1160
1161 /* Though all the LBIU Local Access Windows and LBC Banks will be
1162 * initialized in the C code, we'd better configure boot ROM's
1163 * window 0 and bank 0 correctly at here.
1164 */
1165remap_flash_by_law0:
1166 /* Initialize the BR0 with the boot ROM starting address. */
1167 lwz r4, BR0(r3)
1168 li r5, 0x7FFF
Jon Loeligerde1d0a62005-08-01 13:20:47 -05001169 and r4, r4, r5
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001170 lis r5, (CONFIG_SYS_FLASH_BASE & 0xFFFF8000)@h
1171 ori r5, r5, (CONFIG_SYS_FLASH_BASE & 0xFFFF8000)@l
Eran Libertyf046ccd2005-07-28 10:08:46 -05001172 or r5, r5, r4
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001173 stw r5, BR0(r3) /* r5 <= (CONFIG_SYS_FLASH_BASE & 0xFFFF8000) | (BR0 & 0x00007FFF) */
Eran Libertyf046ccd2005-07-28 10:08:46 -05001174
1175 lwz r4, OR0(r3)
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001176 lis r5, ~((CONFIG_SYS_FLASH_SIZE << 4) - 1)
Eran Libertyf046ccd2005-07-28 10:08:46 -05001177 or r4, r4, r5
Timur Tabi31068b72006-08-22 17:07:00 -05001178 stw r4, OR0(r3)
Eran Libertyf046ccd2005-07-28 10:08:46 -05001179
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001180 lis r4, (CONFIG_SYS_FLASH_BASE)@h
1181 ori r4, r4, (CONFIG_SYS_FLASH_BASE)@l
1182 stw r4, LBLAWBAR0(r3) /* LBLAWBAR0 <= CONFIG_SYS_FLASH_BASE */
Eran Libertyf046ccd2005-07-28 10:08:46 -05001183
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001184 /* Store 0x80000012 + log2(CONFIG_SYS_FLASH_SIZE) into LBLAWAR0 */
Timur Tabi31068b72006-08-22 17:07:00 -05001185 lis r4, (0x80000012)@h
1186 ori r4, r4, (0x80000012)@l
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001187 li r5, CONFIG_SYS_FLASH_SIZE
Timur Tabi31068b72006-08-22 17:07:00 -050011881: srawi. r5, r5, 1 /* r5 = r5 >> 1 */
1189 addi r4, r4, 1
1190 bne 1b
1191 stw r4, LBLAWAR0(r3) /* LBLAWAR0 <= Flash Size */
1192
Eran Libertyf046ccd2005-07-28 10:08:46 -05001193
1194 xor r4, r4, r4
1195 stw r4, LBLAWBAR1(r3)
1196 stw r4, LBLAWAR1(r3) /* Off LBIU LAW1 */
Joakim Tjernlunde45c98a2010-11-19 14:15:33 +01001197 /* Wait for HW to catch up */
1198 lwz r4, LBLAWAR1(r3)
1199 twi 0,r4,0
1200 isync
Eran Libertyf046ccd2005-07-28 10:08:46 -05001201 blr
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001202#endif /* CONFIG_SYS_FLASHBOOT */