blob: c43835c8dcdadbe207ddca384c8c717556e436dd [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>
Timur Tabi53b46172006-08-22 17:07:00 -05005 * Copyright Freescale Semiconductor, Inc. 2004, 2006. All rights reserved.
Eran Liberty9095d4a2005-07-28 10:08:46 -05006 *
7 * See file CREDITS for list of people who contributed to this
8 * project.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23 * MA 02111-1307 USA
24 */
25
26/*
27 * U-Boot - Startup Code for MPC83xx PowerPC based Embedded Boards
28 */
29
30#include <config.h>
Jon Loeligerebc72242005-08-01 13:20:47 -050031#include <mpc83xx.h>
Eran Liberty9095d4a2005-07-28 10:08:46 -050032#include <version.h>
33
34#define CONFIG_83XX 1 /* needed for Linux kernel header files*/
35#define _LINUX_CONFIG_H 1 /* avoid reading Linux autoconf.h file */
36
37#include <ppc_asm.tmpl>
38#include <ppc_defs.h>
39
40#include <asm/cache.h>
41#include <asm/mmu.h>
42
43#ifndef CONFIG_IDENT_STRING
44#define CONFIG_IDENT_STRING "MPC83XX"
45#endif
46
47/* We don't want the MMU yet.
48 */
49#undef MSR_KERNEL
50
51/*
52 * Floating Point enable, Machine Check and Recoverable Interr.
53 */
54#ifdef DEBUG
55#define MSR_KERNEL (MSR_FP|MSR_RI)
56#else
57#define MSR_KERNEL (MSR_FP|MSR_ME|MSR_RI)
58#endif
59
60/*
61 * Set up GOT: Global Offset Table
62 *
63 * Use r14 to access the GOT
64 */
65 START_GOT
66 GOT_ENTRY(_GOT2_TABLE_)
67 GOT_ENTRY(_FIXUP_TABLE_)
68
69 GOT_ENTRY(_start)
70 GOT_ENTRY(_start_of_vectors)
71 GOT_ENTRY(_end_of_vectors)
72 GOT_ENTRY(transfer_to_handler)
73
74 GOT_ENTRY(__init_end)
75 GOT_ENTRY(_end)
76 GOT_ENTRY(__bss_start)
77 END_GOT
78
79/*
80 * Version string - must be in data segment because MPC83xx uses the
81 * first 256 bytes for the Hard Reset Configuration Word table (see
82 * below). Similarly, can't have the U-Boot Magic Number as the first
83 * thing in the image - don't know how this will affect the image tools,
84 * but I guess I'll find out soon.
85 */
86 .data
87 .globl version_string
88version_string:
89 .ascii U_BOOT_VERSION
90 .ascii " (", __DATE__, " - ", __TIME__, ")"
91 .ascii " ", CONFIG_IDENT_STRING, "\0"
Jon Loeligerebc72242005-08-01 13:20:47 -050092
Eran Liberty9095d4a2005-07-28 10:08:46 -050093 .text
94#define _HRCW_TABLE_ENTRY(w) \
95 .fill 8,1,(((w)>>24)&0xff); \
96 .fill 8,1,(((w)>>16)&0xff); \
97 .fill 8,1,(((w)>> 8)&0xff); \
98 .fill 8,1,(((w) )&0xff)
99
100 _HRCW_TABLE_ENTRY(CFG_HRCW_LOW)
101 _HRCW_TABLE_ENTRY(CFG_HRCW_HIGH)
102
103
Eran Liberty9095d4a2005-07-28 10:08:46 -0500104#ifndef CONFIG_DEFAULT_IMMR
105#error CONFIG_DEFAULT_IMMR must be defined
106#endif /* CFG_DEFAULT_IMMR */
107#ifndef CFG_IMMRBAR
108#define CFG_IMMRBAR CONFIG_DEFAULT_IMMR
109#endif /* CFG_IMMRBAR */
110
111/*
112 * After configuration, a system reset exception is executed using the
113 * vector at offset 0x100 relative to the base set by MSR[IP]. If
114 * MSR[IP] is 0, the base address is 0x00000000. If MSR[IP] is 1, the
115 * base address is 0xfff00000. In the case of a Power On Reset or Hard
116 * Reset, the value of MSR[IP] is determined by the CIP field in the
117 * HRCW.
118 *
119 * Other bits in the HRCW set up the Base Address and Port Size in BR0.
120 * This determines the location of the boot ROM (flash or EPROM) in the
121 * processor's address space at boot time. As long as the HRCW is set up
122 * so that we eventually end up executing the code below when the
123 * processor executes the reset exception, the actual values used should
124 * not matter.
125 *
126 * Once we have got here, the address mask in OR0 is cleared so that the
127 * bottom 32K of the boot ROM is effectively repeated all throughout the
128 * processor's address space, after which we can jump to the absolute
129 * address at which the boot ROM was linked at compile time, and proceed
130 * to initialise the memory controller without worrying if the rug will
131 * be pulled out from under us, so to speak (it will be fine as long as
132 * we configure BR0 with the same boot ROM link address).
133 */
134 . = EXC_OFF_SYS_RESET
135
136 .globl _start
137_start: /* time t 0 */
138 li r21, BOOTFLAG_COLD /* Normal Power-On: Boot from FLASH*/
139 nop
140 b boot_cold
141
142 . = EXC_OFF_SYS_RESET + 0x10
143
144 .globl _start_warm
Jon Loeligerebc72242005-08-01 13:20:47 -0500145_start_warm:
Eran Liberty9095d4a2005-07-28 10:08:46 -0500146 li r21, BOOTFLAG_WARM /* Software reboot */
147 b boot_warm
148
149
150boot_cold: /* time t 3 */
151 lis r4, CONFIG_DEFAULT_IMMR@h
152 nop
153boot_warm: /* time t 5 */
154 mfmsr r5 /* save msr contents */
155 lis r3, CFG_IMMRBAR@h
156 ori r3, r3, CFG_IMMRBAR@l
157 stw r3, IMMRBAR(r4)
Jon Loeligerebc72242005-08-01 13:20:47 -0500158
Eran Liberty9095d4a2005-07-28 10:08:46 -0500159 /* Initialise the E300 processor core */
160 /*------------------------------------------*/
Jon Loeligerebc72242005-08-01 13:20:47 -0500161
Eran Liberty9095d4a2005-07-28 10:08:46 -0500162 bl init_e300_core
Jon Loeligerebc72242005-08-01 13:20:47 -0500163
Eran Liberty9095d4a2005-07-28 10:08:46 -0500164#ifndef CFG_RAMBOOT
165
166 /* Inflate flash location so it appears everywhere, calculate */
167 /* the absolute address in final location of the FLASH, jump */
168 /* there and deflate the flash size back to minimal size */
169 /*------------------------------------------------------------*/
170 bl map_flash_by_law1
171 lis r4, (CFG_MONITOR_BASE)@h
172 ori r4, r4, (CFG_MONITOR_BASE)@l
173 addi r5, r4, in_flash - _start + EXC_OFF_SYS_RESET
174 mtlr r5
175 blr
176in_flash:
177#if 1 /* Remapping flash with LAW0. */
178 bl remap_flash_by_law0
179#endif
180#endif /* CFG_RAMBOOT */
181
Kumar Galad5d94d62006-02-10 15:40:06 -0600182 /* setup the bats */
183 bl setup_bats
184 sync
185
186 /*
187 * Cache must be enabled here for stack-in-cache trick.
188 * This means we need to enable the BATS.
189 * This means:
190 * 1) for the EVB, original gt regs need to be mapped
191 * 2) need to have an IBAT for the 0xf region,
192 * we are running there!
193 * Cache should be turned on after BATs, since by default
194 * everything is write-through.
195 * The init-mem BAT can be reused after reloc. The old
196 * gt-regs BAT can be reused after board_init_f calls
197 * board_early_init_f (EVB only).
198 */
199 /* enable address translation */
200 bl enable_addr_trans
201 sync
202
203 /* enable and invalidate the data cache */
204 bl dcache_enable
205 sync
206#ifdef CFG_INIT_RAM_LOCK
207 bl lock_ram_in_cache
208 sync
209#endif
210
211 /* set up the stack pointer in our newly created
212 * cache-ram (r1) */
213 lis r1, (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET)@h
214 ori r1, r1, (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET)@l
215
216 li r0, 0 /* Make room for stack frame header and */
217 stwu r0, -4(r1) /* clear final stack frame so that */
218 stwu r0, -4(r1) /* stack backtraces terminate cleanly */
219
Eran Liberty9095d4a2005-07-28 10:08:46 -0500220
221 /* let the C-code set up the rest */
Kumar Galad5d94d62006-02-10 15:40:06 -0600222 /* */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500223 /* Be careful to keep code relocatable & stack humble */
224 /*------------------------------------------------------*/
225
226 GET_GOT /* initialize GOT access */
227
228 /* r3: IMMR */
229 lis r3, CFG_IMMRBAR@h
230 /* run low-level CPU init code (in Flash)*/
231 bl cpu_init_f
232
233 /* r3: BOOTFLAG */
234 mr r3, r21
235 /* run 1st part of board init code (in Flash)*/
236 bl board_init_f
237
238/*
239 * Vector Table
240 */
241
242 .globl _start_of_vectors
243_start_of_vectors:
244
245/* Machine check */
246 STD_EXCEPTION(0x200, MachineCheck, MachineCheckException)
247
248/* Data Storage exception. */
249 STD_EXCEPTION(0x300, DataStorage, UnknownException)
250
251/* Instruction Storage exception. */
252 STD_EXCEPTION(0x400, InstStorage, UnknownException)
253
254/* External Interrupt exception. */
255#ifndef FIXME
256 STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
Jon Loeligerebc72242005-08-01 13:20:47 -0500257#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -0500258
259/* Alignment exception. */
260 . = 0x600
261Alignment:
262 EXCEPTION_PROLOG
263 mfspr r4,DAR
264 stw r4,_DAR(r21)
265 mfspr r5,DSISR
266 stw r5,_DSISR(r21)
267 addi r3,r1,STACK_FRAME_OVERHEAD
268 li r20,MSR_KERNEL
269 rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
270 rlwimi r20,r23,0,25,25 /* copy IP bit from saved MSR */
271 lwz r6,GOT(transfer_to_handler)
272 mtlr r6
273 blrl
274.L_Alignment:
275 .long AlignmentException - _start + EXC_OFF_SYS_RESET
276 .long int_return - _start + EXC_OFF_SYS_RESET
277
278/* Program check exception */
279 . = 0x700
280ProgramCheck:
281 EXCEPTION_PROLOG
282 addi r3,r1,STACK_FRAME_OVERHEAD
283 li r20,MSR_KERNEL
284 rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
285 rlwimi r20,r23,0,25,25 /* copy IP bit from saved MSR */
286 lwz r6,GOT(transfer_to_handler)
287 mtlr r6
288 blrl
289.L_ProgramCheck:
290 .long ProgramCheckException - _start + EXC_OFF_SYS_RESET
291 .long int_return - _start + EXC_OFF_SYS_RESET
292
293 STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
294
295 /* I guess we could implement decrementer, and may have
296 * to someday for timekeeping.
297 */
298 STD_EXCEPTION(0x900, Decrementer, timer_interrupt)
299
300 STD_EXCEPTION(0xa00, Trap_0a, UnknownException)
301 STD_EXCEPTION(0xb00, Trap_0b, UnknownException)
302 STD_EXCEPTION(0xc00, SystemCall, UnknownException)
303 STD_EXCEPTION(0xd00, SingleStep, UnknownException)
304
305 STD_EXCEPTION(0xe00, Trap_0e, UnknownException)
306 STD_EXCEPTION(0xf00, Trap_0f, UnknownException)
307
308 STD_EXCEPTION(0x1000, InstructionTLBMiss, UnknownException)
309 STD_EXCEPTION(0x1100, DataLoadTLBMiss, UnknownException)
310 STD_EXCEPTION(0x1200, DataStoreTLBMiss, UnknownException)
311#ifdef DEBUG
312 . = 0x1300
313 /*
314 * This exception occurs when the program counter matches the
315 * Instruction Address Breakpoint Register (IABR).
316 *
317 * I want the cpu to halt if this occurs so I can hunt around
318 * with the debugger and look at things.
319 *
320 * When DEBUG is defined, both machine check enable (in the MSR)
321 * and checkstop reset enable (in the reset mode register) are
322 * turned off and so a checkstop condition will result in the cpu
323 * halting.
324 *
325 * I force the cpu into a checkstop condition by putting an illegal
326 * instruction here (at least this is the theory).
327 *
328 * well - that didnt work, so just do an infinite loop!
329 */
3301: b 1b
331#else
332 STD_EXCEPTION(0x1300, InstructionBreakpoint, DebugException)
333#endif
334 STD_EXCEPTION(0x1400, SMI, UnknownException)
335
336 STD_EXCEPTION(0x1500, Trap_15, UnknownException)
337 STD_EXCEPTION(0x1600, Trap_16, UnknownException)
338 STD_EXCEPTION(0x1700, Trap_17, UnknownException)
339 STD_EXCEPTION(0x1800, Trap_18, UnknownException)
340 STD_EXCEPTION(0x1900, Trap_19, UnknownException)
341 STD_EXCEPTION(0x1a00, Trap_1a, UnknownException)
342 STD_EXCEPTION(0x1b00, Trap_1b, UnknownException)
343 STD_EXCEPTION(0x1c00, Trap_1c, UnknownException)
344 STD_EXCEPTION(0x1d00, Trap_1d, UnknownException)
345 STD_EXCEPTION(0x1e00, Trap_1e, UnknownException)
346 STD_EXCEPTION(0x1f00, Trap_1f, UnknownException)
347 STD_EXCEPTION(0x2000, Trap_20, UnknownException)
348 STD_EXCEPTION(0x2100, Trap_21, UnknownException)
349 STD_EXCEPTION(0x2200, Trap_22, UnknownException)
350 STD_EXCEPTION(0x2300, Trap_23, UnknownException)
351 STD_EXCEPTION(0x2400, Trap_24, UnknownException)
352 STD_EXCEPTION(0x2500, Trap_25, UnknownException)
353 STD_EXCEPTION(0x2600, Trap_26, UnknownException)
354 STD_EXCEPTION(0x2700, Trap_27, UnknownException)
355 STD_EXCEPTION(0x2800, Trap_28, UnknownException)
356 STD_EXCEPTION(0x2900, Trap_29, UnknownException)
357 STD_EXCEPTION(0x2a00, Trap_2a, UnknownException)
358 STD_EXCEPTION(0x2b00, Trap_2b, UnknownException)
359 STD_EXCEPTION(0x2c00, Trap_2c, UnknownException)
360 STD_EXCEPTION(0x2d00, Trap_2d, UnknownException)
361 STD_EXCEPTION(0x2e00, Trap_2e, UnknownException)
362 STD_EXCEPTION(0x2f00, Trap_2f, UnknownException)
363
364
365 .globl _end_of_vectors
366_end_of_vectors:
367
368 . = 0x3000
369
370/*
371 * This code finishes saving the registers to the exception frame
372 * and jumps to the appropriate handler for the exception.
373 * Register r21 is pointer into trap frame, r1 has new stack pointer.
374 */
375 .globl transfer_to_handler
376transfer_to_handler:
377 stw r22,_NIP(r21)
378 lis r22,MSR_POW@h
379 andc r23,r23,r22
380 stw r23,_MSR(r21)
381 SAVE_GPR(7, r21)
382 SAVE_4GPRS(8, r21)
383 SAVE_8GPRS(12, r21)
384 SAVE_8GPRS(24, r21)
385 mflr r23
386 andi. r24,r23,0x3f00 /* get vector offset */
387 stw r24,TRAP(r21)
388 li r22,0
389 stw r22,RESULT(r21)
390 lwz r24,0(r23) /* virtual address of handler */
391 lwz r23,4(r23) /* where to go when done */
392 mtspr SRR0,r24
393 mtspr SRR1,r20
394 mtlr r23
395 SYNC
396 rfi /* jump to handler, enable MMU */
397
398int_return:
399 mfmsr r28 /* Disable interrupts */
400 li r4,0
401 ori r4,r4,MSR_EE
402 andc r28,r28,r4
403 SYNC /* Some chip revs need this... */
404 mtmsr r28
405 SYNC
406 lwz r2,_CTR(r1)
407 lwz r0,_LINK(r1)
408 mtctr r2
409 mtlr r0
410 lwz r2,_XER(r1)
411 lwz r0,_CCR(r1)
412 mtspr XER,r2
413 mtcrf 0xFF,r0
414 REST_10GPRS(3, r1)
415 REST_10GPRS(13, r1)
416 REST_8GPRS(23, r1)
417 REST_GPR(31, r1)
418 lwz r2,_NIP(r1) /* Restore environment */
419 lwz r0,_MSR(r1)
420 mtspr SRR0,r2
421 mtspr SRR1,r0
422 lwz r0,GPR0(r1)
423 lwz r2,GPR2(r1)
424 lwz r1,GPR1(r1)
425 SYNC
426 rfi
427
428/*
429 * This code initialises the E300 processor core
430 * (conforms to PowerPC 603e spec)
431 * Note: expects original MSR contents to be in r5.
432 */
433 .globl init_e300_core
434init_e300_core: /* time t 10 */
435 /* Initialize machine status; enable machine check interrupt */
436 /*-----------------------------------------------------------*/
437
438 li r3, MSR_KERNEL /* Set ME and RI flags */
439 rlwimi r3, r5, 0, 25, 25 /* preserve IP bit set by HRCW */
440#ifdef DEBUG
441 rlwimi r3, r5, 0, 21, 22 /* debugger might set SE & BE bits */
442#endif
443 SYNC /* Some chip revs need this... */
444 mtmsr r3
445 SYNC
446 mtspr SRR1, r3 /* Make SRR1 match MSR */
447
448
449 lis r3, CFG_IMMRBAR@h
450#if defined(CONFIG_WATCHDOG)
451 /* Initialise the Wathcdog values and reset it (if req) */
452 /*------------------------------------------------------*/
453 lis r4, CFG_WATCHDOG_VALUE
454 ori r4, r4, (SWCRR_SWEN | SWCRR_SWRI | SWCRR_SWPR)
455 stw r4, SWCRR(r3)
Jon Loeligerebc72242005-08-01 13:20:47 -0500456
Eran Liberty9095d4a2005-07-28 10:08:46 -0500457 /* and reset it */
Jon Loeligerebc72242005-08-01 13:20:47 -0500458
Eran Liberty9095d4a2005-07-28 10:08:46 -0500459 li r4, 0x556C
460 sth r4, SWSRR@l(r3)
461 li r4, 0xAA39
462 sth r4, SWSRR@l(r3)
463#else
464 /* Disable Wathcdog */
465 /*-------------------*/
Kumar Galab42751c2006-01-11 11:23:01 -0600466 lwz r4, SWCRR(r3)
467 /* Check to see if its enabled for disabling
468 once disabled by SW you can't re-enable */
469 andi. r4, r4, 0x4
470 beq 1f
Eran Liberty9095d4a2005-07-28 10:08:46 -0500471 xor r4, r4, r4
472 stw r4, SWCRR(r3)
Kumar Galab42751c2006-01-11 11:23:01 -06004731:
Eran Liberty9095d4a2005-07-28 10:08:46 -0500474#endif /* CONFIG_WATCHDOG */
475
476 /* Initialize the Hardware Implementation-dependent Registers */
477 /* HID0 also contains cache control */
478 /*------------------------------------------------------*/
479
480 lis r3, CFG_HID0_INIT@h
481 ori r3, r3, CFG_HID0_INIT@l
482 SYNC
483 mtspr HID0, r3
484
485 lis r3, CFG_HID0_FINAL@h
486 ori r3, r3, CFG_HID0_FINAL@l
487 SYNC
488 mtspr HID0, r3
489
490 lis r3, CFG_HID2@h
491 ori r3, r3, CFG_HID2@l
492 SYNC
493 mtspr HID2, r3
494
495 /* clear all BAT's */
496 /*----------------------------------*/
497
498 xor r0, r0, r0
499 mtspr DBAT0U, r0
500 mtspr DBAT0L, r0
501 mtspr DBAT1U, r0
502 mtspr DBAT1L, r0
503 mtspr DBAT2U, r0
504 mtspr DBAT2L, r0
505 mtspr DBAT3U, r0
506 mtspr DBAT3L, r0
507 mtspr IBAT0U, r0
508 mtspr IBAT0L, r0
509 mtspr IBAT1U, r0
510 mtspr IBAT1L, r0
511 mtspr IBAT2U, r0
512 mtspr IBAT2L, r0
513 mtspr IBAT3U, r0
514 mtspr IBAT3L, r0
515 SYNC
516
517 /* invalidate all tlb's
518 *
519 * From the 603e User Manual: "The 603e provides the ability to
520 * invalidate a TLB entry. The TLB Invalidate Entry (tlbie)
521 * instruction invalidates the TLB entry indexed by the EA, and
522 * operates on both the instruction and data TLBs simultaneously
523 * invalidating four TLB entries (both sets in each TLB). The
524 * index corresponds to bits 15-19 of the EA. To invalidate all
525 * entries within both TLBs, 32 tlbie instructions should be
526 * issued, incrementing this field by one each time."
527 *
528 * "Note that the tlbia instruction is not implemented on the
529 * 603e."
530 *
531 * bits 15-19 correspond to addresses 0x00000000 to 0x0001F000
532 * incrementing by 0x1000 each time. The code below is sort of
533 * based on code in "flush_tlbs" from arch/ppc/kernel/head.S
534 *
535 */
536
537 li r3, 32
538 mtctr r3
539 li r3, 0
5401: tlbie r3
541 addi r3, r3, 0x1000
542 bdnz 1b
543 SYNC
544
545 /* Done! */
546 /*------------------------------*/
Jon Loeligerebc72242005-08-01 13:20:47 -0500547 blr
Eran Liberty9095d4a2005-07-28 10:08:46 -0500548
Kumar Galad5d94d62006-02-10 15:40:06 -0600549 .globl invalidate_bats
550invalidate_bats:
551 /* invalidate BATs */
552 mtspr IBAT0U, r0
553 mtspr IBAT1U, r0
554 mtspr IBAT2U, r0
555 mtspr IBAT3U, r0
556#if (CFG_HID2 & HID2_HBE)
557 mtspr IBAT4U, r0
558 mtspr IBAT5U, r0
559 mtspr IBAT6U, r0
560 mtspr IBAT7U, r0
561#endif
562 isync
563 mtspr DBAT0U, r0
564 mtspr DBAT1U, r0
565 mtspr DBAT2U, r0
566 mtspr DBAT3U, r0
567#if (CFG_HID2 & HID2_HBE)
568 mtspr DBAT4U, r0
569 mtspr DBAT5U, r0
570 mtspr DBAT6U, r0
571 mtspr DBAT7U, r0
572#endif
573 isync
574 sync
575 blr
576
577 /* setup_bats - set them up to some initial state */
578 .globl setup_bats
579setup_bats:
580 addis r0, r0, 0x0000
581
582 /* IBAT 0 */
583 addis r4, r0, CFG_IBAT0L@h
584 ori r4, r4, CFG_IBAT0L@l
585 addis r3, r0, CFG_IBAT0U@h
586 ori r3, r3, CFG_IBAT0U@l
587 mtspr IBAT0L, r4
588 mtspr IBAT0U, r3
589 isync
590
591 /* DBAT 0 */
592 addis r4, r0, CFG_DBAT0L@h
593 ori r4, r4, CFG_DBAT0L@l
594 addis r3, r0, CFG_DBAT0U@h
595 ori r3, r3, CFG_DBAT0U@l
596 mtspr DBAT0L, r4
597 mtspr DBAT0U, r3
598 isync
599
600 /* IBAT 1 */
601 addis r4, r0, CFG_IBAT1L@h
602 ori r4, r4, CFG_IBAT1L@l
603 addis r3, r0, CFG_IBAT1U@h
604 ori r3, r3, CFG_IBAT1U@l
605 mtspr IBAT1L, r4
606 mtspr IBAT1U, r3
607 isync
608
609 /* DBAT 1 */
610 addis r4, r0, CFG_DBAT1L@h
611 ori r4, r4, CFG_DBAT1L@l
612 addis r3, r0, CFG_DBAT1U@h
613 ori r3, r3, CFG_DBAT1U@l
614 mtspr DBAT1L, r4
615 mtspr DBAT1U, r3
616 isync
617
618 /* IBAT 2 */
619 addis r4, r0, CFG_IBAT2L@h
620 ori r4, r4, CFG_IBAT2L@l
621 addis r3, r0, CFG_IBAT2U@h
622 ori r3, r3, CFG_IBAT2U@l
623 mtspr IBAT2L, r4
624 mtspr IBAT2U, r3
625 isync
626
627 /* DBAT 2 */
628 addis r4, r0, CFG_DBAT2L@h
629 ori r4, r4, CFG_DBAT2L@l
630 addis r3, r0, CFG_DBAT2U@h
631 ori r3, r3, CFG_DBAT2U@l
632 mtspr DBAT2L, r4
633 mtspr DBAT2U, r3
634 isync
635
636 /* IBAT 3 */
637 addis r4, r0, CFG_IBAT3L@h
638 ori r4, r4, CFG_IBAT3L@l
639 addis r3, r0, CFG_IBAT3U@h
640 ori r3, r3, CFG_IBAT3U@l
641 mtspr IBAT3L, r4
642 mtspr IBAT3U, r3
643 isync
644
645 /* DBAT 3 */
646 addis r4, r0, CFG_DBAT3L@h
647 ori r4, r4, CFG_DBAT3L@l
648 addis r3, r0, CFG_DBAT3U@h
649 ori r3, r3, CFG_DBAT3U@l
650 mtspr DBAT3L, r4
651 mtspr DBAT3U, r3
652 isync
653
654#if (CFG_HID2 & HID2_HBE)
655 /* IBAT 4 */
656 addis r4, r0, CFG_IBAT4L@h
657 ori r4, r4, CFG_IBAT4L@l
658 addis r3, r0, CFG_IBAT4U@h
659 ori r3, r3, CFG_IBAT4U@l
660 mtspr IBAT4L, r4
661 mtspr IBAT4U, r3
662 isync
663
664 /* DBAT 4 */
665 addis r4, r0, CFG_DBAT4L@h
666 ori r4, r4, CFG_DBAT4L@l
667 addis r3, r0, CFG_DBAT4U@h
668 ori r3, r3, CFG_DBAT4U@l
669 mtspr DBAT4L, r4
670 mtspr DBAT4U, r3
671 isync
672
673 /* IBAT 5 */
674 addis r4, r0, CFG_IBAT5L@h
675 ori r4, r4, CFG_IBAT5L@l
676 addis r3, r0, CFG_IBAT5U@h
677 ori r3, r3, CFG_IBAT5U@l
678 mtspr IBAT5L, r4
679 mtspr IBAT5U, r3
680 isync
681
682 /* DBAT 5 */
683 addis r4, r0, CFG_DBAT5L@h
684 ori r4, r4, CFG_DBAT5L@l
685 addis r3, r0, CFG_DBAT5U@h
686 ori r3, r3, CFG_DBAT5U@l
687 mtspr DBAT5L, r4
688 mtspr DBAT5U, r3
689 isync
690
691 /* IBAT 6 */
692 addis r4, r0, CFG_IBAT6L@h
693 ori r4, r4, CFG_IBAT6L@l
694 addis r3, r0, CFG_IBAT6U@h
695 ori r3, r3, CFG_IBAT6U@l
696 mtspr IBAT6L, r4
697 mtspr IBAT6U, r3
698 isync
699
700 /* DBAT 6 */
701 addis r4, r0, CFG_DBAT6L@h
702 ori r4, r4, CFG_DBAT6L@l
703 addis r3, r0, CFG_DBAT6U@h
704 ori r3, r3, CFG_DBAT6U@l
705 mtspr DBAT6L, r4
706 mtspr DBAT6U, r3
707 isync
708
709 /* IBAT 7 */
710 addis r4, r0, CFG_IBAT7L@h
711 ori r4, r4, CFG_IBAT7L@l
712 addis r3, r0, CFG_IBAT7U@h
713 ori r3, r3, CFG_IBAT7U@l
714 mtspr IBAT7L, r4
715 mtspr IBAT7U, r3
716 isync
717
718 /* DBAT 7 */
719 addis r4, r0, CFG_DBAT7L@h
720 ori r4, r4, CFG_DBAT7L@l
721 addis r3, r0, CFG_DBAT7U@h
722 ori r3, r3, CFG_DBAT7U@l
723 mtspr DBAT7L, r4
724 mtspr DBAT7U, r3
725 isync
726#endif
727
728 /* Invalidate TLBs.
729 * -> for (val = 0; val < 0x20000; val+=0x1000)
730 * -> tlbie(val);
731 */
732 lis r3, 0
733 lis r5, 2
734
7351:
736 tlbie r3
737 addi r3, r3, 0x1000
738 cmp 0, 0, r3, r5
739 blt 1b
740
741 blr
742
743 .globl enable_addr_trans
744enable_addr_trans:
745 /* enable address translation */
746 mfmsr r5
747 ori r5, r5, (MSR_IR | MSR_DR)
748 mtmsr r5
749 isync
750 blr
751
752 .globl disable_addr_trans
753disable_addr_trans:
754 /* disable address translation */
755 mflr r4
756 mfmsr r3
757 andi. r0, r3, (MSR_IR | MSR_DR)
758 beqlr
759 andc r3, r3, r0
760 mtspr SRR0, r4
761 mtspr SRR1, r3
762 rfi
763
Eran Liberty9095d4a2005-07-28 10:08:46 -0500764/* Cache functions.
765 *
766 * Note: requires that all cache bits in
767 * HID0 are in the low half word.
768 */
769 .globl icache_enable
770icache_enable:
771 mfspr r3, HID0
772 ori r3, r3, HID0_ICE
773 lis r4, 0
774 ori r4, r4, HID0_ILOCK
775 andc r3, r3, r4
776 ori r4, r3, HID0_ICFI
777 isync
778 mtspr HID0, r4 /* sets enable and invalidate, clears lock */
779 isync
780 mtspr HID0, r3 /* clears invalidate */
781 blr
782
783 .globl icache_disable
784icache_disable:
785 mfspr r3, HID0
786 lis r4, 0
787 ori r4, r4, HID0_ICE|HID0_ILOCK
788 andc r3, r3, r4
789 ori r4, r3, HID0_ICFI
790 isync
791 mtspr HID0, r4 /* sets invalidate, clears enable and lock*/
792 isync
793 mtspr HID0, r3 /* clears invalidate */
794 blr
795
796 .globl icache_status
797icache_status:
798 mfspr r3, HID0
Marian Balakowicz758e5d32006-03-14 16:01:25 +0100799 rlwinm r3, r3, (31 - HID0_ICE_SHIFT + 1), 31, 31
Eran Liberty9095d4a2005-07-28 10:08:46 -0500800 blr
801
802 .globl dcache_enable
803dcache_enable:
804 mfspr r3, HID0
Kumar Galad5d94d62006-02-10 15:40:06 -0600805 li r5, HID0_DCFI|HID0_DLOCK
806 andc r3, r3, r5
807 mtspr HID0, r3 /* no invalidate, unlock */
808 ori r3, r3, HID0_DCE
809 ori r5, r3, HID0_DCFI
810 mtspr HID0, r5 /* enable + invalidate */
811 mtspr HID0, r3 /* enable */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500812 sync
Eran Liberty9095d4a2005-07-28 10:08:46 -0500813 blr
814
815 .globl dcache_disable
816dcache_disable:
817 mfspr r3, HID0
818 lis r4, 0
Kumar Galad5d94d62006-02-10 15:40:06 -0600819 ori r4, r4, HID0_DCE|HID0_DLOCK
Eran Liberty9095d4a2005-07-28 10:08:46 -0500820 andc r3, r3, r4
Kumar Galad5d94d62006-02-10 15:40:06 -0600821 ori r4, r3, HID0_DCI
Eran Liberty9095d4a2005-07-28 10:08:46 -0500822 sync
Kumar Galad5d94d62006-02-10 15:40:06 -0600823 mtspr HID0, r4 /* sets invalidate, clears enable and lock */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500824 sync
825 mtspr HID0, r3 /* clears invalidate */
826 blr
827
828 .globl dcache_status
829dcache_status:
830 mfspr r3, HID0
Marian Balakowicz758e5d32006-03-14 16:01:25 +0100831 rlwinm r3, r3, (31 - HID0_DCE_SHIFT + 1), 31, 31
Eran Liberty9095d4a2005-07-28 10:08:46 -0500832 blr
833
834 .globl get_pvr
835get_pvr:
836 mfspr r3, PVR
837 blr
838
Marian Balakowiczaf03ecb2006-03-14 16:02:31 +0100839/*------------------------------------------------------------------------------- */
840/* Function: ppcDcbf */
841/* Description: Data Cache block flush */
842/* Input: r3 = effective address */
843/* Output: none. */
844/*------------------------------------------------------------------------------- */
845 .globl ppcDcbf
846ppcDcbf:
847 dcbf r0,r3
848 blr
849
850/*------------------------------------------------------------------------------- */
851/* Function: ppcDcbi */
852/* Description: Data Cache block Invalidate */
853/* Input: r3 = effective address */
854/* Output: none. */
855/*------------------------------------------------------------------------------- */
856 .globl ppcDcbi
857ppcDcbi:
858 dcbi r0,r3
859 blr
860
861/*--------------------------------------------------------------------------
862 * Function: ppcDcbz
863 * Description: Data Cache block zero.
864 * Input: r3 = effective address
865 * Output: none.
866 *-------------------------------------------------------------------------- */
867
868 .globl ppcDcbz
869ppcDcbz:
870 dcbz r0,r3
871 blr
872
Dave Liu8c84e472006-11-02 18:05:50 -0600873 .globl ppcDWstore
874ppcDWstore:
875 lfd 1, 0(r4)
876 stfd 1, 0(r3)
877 blr
878
879 .globl ppcDWload
880ppcDWload:
881 lfd 1, 0(r3)
882 stfd 1, 0(r4)
883 blr
884
Eran Liberty9095d4a2005-07-28 10:08:46 -0500885/*-------------------------------------------------------------------*/
886
887/*
888 * void relocate_code (addr_sp, gd, addr_moni)
889 *
890 * This "function" does not return, instead it continues in RAM
891 * after relocating the monitor code.
892 *
893 * r3 = dest
894 * r4 = src
895 * r5 = length in bytes
896 * r6 = cachelinesize
897 */
898 .globl relocate_code
899relocate_code:
900 mr r1, r3 /* Set new stack pointer */
901 mr r9, r4 /* Save copy of Global Data pointer */
902 mr r10, r5 /* Save copy of Destination Address */
903
904 mr r3, r5 /* Destination Address */
905 lis r4, CFG_MONITOR_BASE@h /* Source Address */
906 ori r4, r4, CFG_MONITOR_BASE@l
907 lwz r5, GOT(__init_end)
908 sub r5, r5, r4
909 li r6, CFG_CACHELINE_SIZE /* Cache Line Size */
910
911 /*
912 * Fix GOT pointer:
913 *
914 * New GOT-PTR = (old GOT-PTR - CFG_MONITOR_BASE)
915 * + Destination Address
916 *
917 * Offset:
918 */
919 sub r15, r10, r4
920
921 /* First our own GOT */
922 add r14, r14, r15
923 /* then the one used by the C code */
924 add r30, r30, r15
925
926 /*
927 * Now relocate code
928 */
929
930 cmplw cr1,r3,r4
931 addi r0,r5,3
932 srwi. r0,r0,2
933 beq cr1,4f /* In place copy is not necessary */
934 beq 7f /* Protect against 0 count */
935 mtctr r0
936 bge cr1,2f
937 la r8,-4(r4)
938 la r7,-4(r3)
939
940 /* copy */
9411: lwzu r0,4(r8)
942 stwu r0,4(r7)
943 bdnz 1b
944
945 addi r0,r5,3
946 srwi. r0,r0,2
947 mtctr r0
948 la r8,-4(r4)
949 la r7,-4(r3)
Jon Loeligerebc72242005-08-01 13:20:47 -0500950
951 /* and compare */
Eran Liberty9095d4a2005-07-28 10:08:46 -050095220: lwzu r20,4(r8)
953 lwzu r21,4(r7)
954 xor. r22, r20, r21
955 bne 30f
956 bdnz 20b
957 b 4f
958
959 /* compare failed */
96030: li r3, 0
961 blr
962
9632: slwi r0,r0,2 /* re copy in reverse order ... y do we needed it? */
964 add r8,r4,r0
965 add r7,r3,r0
9663: lwzu r0,-4(r8)
967 stwu r0,-4(r7)
968 bdnz 3b
Eran Liberty9095d4a2005-07-28 10:08:46 -0500969
970/*
971 * Now flush the cache: note that we must start from a cache aligned
972 * address. Otherwise we might miss one cache line.
973 */
Kumar Galad5d94d62006-02-10 15:40:06 -06009744: cmpwi r6,0
Eran Liberty9095d4a2005-07-28 10:08:46 -0500975 add r5,r3,r5
Kumar Galad5d94d62006-02-10 15:40:06 -0600976 beq 7f /* Always flush prefetch queue in any case */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500977 subi r0,r6,1
978 andc r3,r3,r0
Eran Liberty9095d4a2005-07-28 10:08:46 -0500979 mr r4,r3
9805: dcbst 0,r4
981 add r4,r4,r6
982 cmplw r4,r5
983 blt 5b
Kumar Galad5d94d62006-02-10 15:40:06 -0600984 sync /* Wait for all dcbst to complete on bus */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500985 mr r4,r3
9866: icbi 0,r4
987 add r4,r4,r6
988 cmplw r4,r5
989 blt 6b
Kumar Galad5d94d62006-02-10 15:40:06 -06009907: sync /* Wait for all icbi to complete on bus */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500991 isync
992
993/*
994 * We are done. Do not return, instead branch to second part of board
995 * initialization, now running from RAM.
996 */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500997 addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
998 mtlr r0
999 blr
1000
1001in_ram:
1002
1003 /*
1004 * Relocation Function, r14 point to got2+0x8000
1005 *
1006 * Adjust got2 pointers, no need to check for 0, this code
1007 * already puts a few entries in the table.
1008 */
1009 li r0,__got2_entries@sectoff@l
1010 la r3,GOT(_GOT2_TABLE_)
1011 lwz r11,GOT(_GOT2_TABLE_)
1012 mtctr r0
1013 sub r11,r3,r11
1014 addi r3,r3,-4
10151: lwzu r0,4(r3)
1016 add r0,r0,r11
1017 stw r0,0(r3)
1018 bdnz 1b
1019
1020 /*
1021 * Now adjust the fixups and the pointers to the fixups
1022 * in case we need to move ourselves again.
1023 */
10242: li r0,__fixup_entries@sectoff@l
1025 lwz r3,GOT(_FIXUP_TABLE_)
1026 cmpwi r0,0
1027 mtctr r0
1028 addi r3,r3,-4
1029 beq 4f
10303: lwzu r4,4(r3)
1031 lwzux r0,r4,r11
1032 add r0,r0,r11
1033 stw r10,0(r3)
1034 stw r0,0(r4)
1035 bdnz 3b
10364:
1037clear_bss:
1038 /*
1039 * Now clear BSS segment
1040 */
1041 lwz r3,GOT(__bss_start)
1042#if defined(CONFIG_HYMOD)
1043 /*
1044 * For HYMOD - the environment is the very last item in flash.
1045 * The real .bss stops just before environment starts, so only
1046 * clear up to that point.
1047 *
1048 * taken from mods for FADS board
1049 */
1050 lwz r4,GOT(environment)
1051#else
1052 lwz r4,GOT(_end)
1053#endif
1054
1055 cmplw 0, r3, r4
1056 beq 6f
1057
1058 li r0, 0
10595:
1060 stw r0, 0(r3)
1061 addi r3, r3, 4
1062 cmplw 0, r3, r4
1063 bne 5b
10646:
1065
1066 mr r3, r9 /* Global Data pointer */
1067 mr r4, r10 /* Destination Address */
1068 bl board_init_r
1069
1070 /*
1071 * Copy exception vector code to low memory
1072 *
1073 * r3: dest_addr
1074 * r7: source address, r8: end address, r9: target address
1075 */
1076 .globl trap_init
1077trap_init:
1078 lwz r7, GOT(_start)
1079 lwz r8, GOT(_end_of_vectors)
1080
1081 li r9, 0x100 /* reset vector always at 0x100 */
1082
1083 cmplw 0, r7, r8
1084 bgelr /* return if r7>=r8 - just in case */
1085
1086 mflr r4 /* save link register */
10871:
1088 lwz r0, 0(r7)
1089 stw r0, 0(r9)
1090 addi r7, r7, 4
1091 addi r9, r9, 4
1092 cmplw 0, r7, r8
1093 bne 1b
1094
1095 /*
1096 * relocate `hdlr' and `int_return' entries
1097 */
1098 li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
1099 li r8, Alignment - _start + EXC_OFF_SYS_RESET
11002:
1101 bl trap_reloc
1102 addi r7, r7, 0x100 /* next exception vector */
1103 cmplw 0, r7, r8
1104 blt 2b
1105
1106 li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
1107 bl trap_reloc
1108
1109 li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
1110 bl trap_reloc
1111
1112 li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
1113 li r8, SystemCall - _start + EXC_OFF_SYS_RESET
11143:
1115 bl trap_reloc
1116 addi r7, r7, 0x100 /* next exception vector */
1117 cmplw 0, r7, r8
1118 blt 3b
1119
1120 li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
1121 li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
11224:
1123 bl trap_reloc
1124 addi r7, r7, 0x100 /* next exception vector */
1125 cmplw 0, r7, r8
1126 blt 4b
1127
1128 mfmsr r3 /* now that the vectors have */
1129 lis r7, MSR_IP@h /* relocated into low memory */
1130 ori r7, r7, MSR_IP@l /* MSR[IP] can be turned off */
1131 andc r3, r3, r7 /* (if it was on) */
1132 SYNC /* Some chip revs need this... */
1133 mtmsr r3
1134 SYNC
1135
1136 mtlr r4 /* restore link register */
1137 blr
1138
1139 /*
1140 * Function: relocate entries for one exception vector
1141 */
1142trap_reloc:
1143 lwz r0, 0(r7) /* hdlr ... */
1144 add r0, r0, r3 /* ... += dest_addr */
1145 stw r0, 0(r7)
1146
1147 lwz r0, 4(r7) /* int_return ... */
1148 add r0, r0, r3 /* ... += dest_addr */
1149 stw r0, 4(r7)
1150
1151 blr
1152
1153#ifdef CFG_INIT_RAM_LOCK
Kumar Galad5d94d62006-02-10 15:40:06 -06001154lock_ram_in_cache:
1155 /* Allocate Initial RAM in data cache.
1156 */
1157 lis r3, (CFG_INIT_RAM_ADDR & ~31)@h
1158 ori r3, r3, (CFG_INIT_RAM_ADDR & ~31)@l
1159 li r2, ((CFG_INIT_RAM_END & ~31) + \
1160 (CFG_INIT_RAM_ADDR & 31) + 31) / 32
1161 mtctr r2
11621:
1163 dcbz r0, r3
1164 addi r3, r3, 32
1165 bdnz 1b
1166
1167 /* Lock the data cache */
1168 mfspr r0, HID0
1169 ori r0, r0, 0x1000
1170 sync
1171 mtspr HID0, r0
1172 sync
1173 blr
1174
Eran Liberty9095d4a2005-07-28 10:08:46 -05001175.globl unlock_ram_in_cache
1176unlock_ram_in_cache:
1177 /* invalidate the INIT_RAM section */
1178 lis r3, (CFG_INIT_RAM_ADDR & ~31)@h
1179 ori r3, r3, (CFG_INIT_RAM_ADDR & ~31)@l
1180 li r2,512
1181 mtctr r2
11821: icbi r0, r3
1183 dcbi r0, r3
1184 addi r3, r3, 32
1185 bdnz 1b
1186 sync /* Wait for all icbi to complete on bus */
1187 isync
Kumar Galad5d94d62006-02-10 15:40:06 -06001188
1189 /* Unlock the data cache and invalidate it */
1190 mfspr r3, HID0
1191 li r5, HID0_DLOCK|HID0_DCFI
1192 andc r3, r3, r5 /* no invalidate, unlock */
1193 ori r5, r3, HID0_DCFI /* invalidate, unlock */
1194 mtspr HID0, r5 /* invalidate, unlock */
1195 mtspr HID0, r3 /* no invalidate, unlock */
1196 sync
Eran Liberty9095d4a2005-07-28 10:08:46 -05001197 blr
1198#endif
1199
1200map_flash_by_law1:
1201 /* When booting from ROM (Flash or EPROM), clear the */
1202 /* Address Mask in OR0 so ROM appears everywhere */
1203 /*----------------------------------------------------*/
1204 lis r3, (CFG_IMMRBAR)@h /* r3 <= CFG_IMMRBAR */
Jon Loeligerebc72242005-08-01 13:20:47 -05001205 lwz r4, OR0@l(r3)
Eran Liberty9095d4a2005-07-28 10:08:46 -05001206 li r5, 0x7fff /* r5 <= 0x00007FFFF */
Jon Loeligerebc72242005-08-01 13:20:47 -05001207 and r4, r4, r5
Eran Liberty9095d4a2005-07-28 10:08:46 -05001208 stw r4, OR0@l(r3) /* OR0 <= OR0 & 0x00007FFFF */
1209
1210 /* As MPC8349E User's Manual presented, when RCW[BMS] is set to 0,
1211 * system will boot from 0x0000_0100, and the LBLAWBAR0[BASE_ADDR]
1212 * reset value is 0x00000; when RCW[BMS] is set to 1, system will boot
1213 * from 0xFFF0_0100, and the LBLAWBAR0[BASE_ADDR] reset value is
1214 * 0xFF800. From the hard resetting to here, the processor fetched and
1215 * executed the instructions one by one. There is not absolutely
1216 * jumping happened. Laterly, the u-boot code has to do an absolutely
1217 * jumping to tell the CPU instruction fetching component what the
1218 * u-boot TEXT base address is. Because the TEXT base resides in the
1219 * boot ROM memory space, to garantee the code can run smoothly after
1220 * that jumping, we must map in the entire boot ROM by Local Access
1221 * Window. Sometimes, we desire an non-0x00000 or non-0xFF800 starting
1222 * address for boot ROM, such as 0xFE000000. In this case, the default
1223 * LBIU Local Access Widow 0 will not cover this memory space. So, we
1224 * need another window to map in it.
1225 */
1226 lis r4, (CFG_FLASH_BASE)@h
1227 ori r4, r4, (CFG_FLASH_BASE)@l
1228 stw r4, LBLAWBAR1(r3) /* LBLAWBAR1 <= CFG_FLASH_BASE */
Timur Tabi53b46172006-08-22 17:07:00 -05001229
1230 /* Store 0x80000012 + log2(CFG_FLASH_SIZE) into LBLAWAR1 */
1231 lis r4, (0x80000012)@h
1232 ori r4, r4, (0x80000012)@l
1233 li r5, CFG_FLASH_SIZE
12341: srawi. r5, r5, 1 /* r5 = r5 >> 1 */
1235 addi r4, r4, 1
1236 bne 1b
1237
Eran Liberty9095d4a2005-07-28 10:08:46 -05001238 stw r4, LBLAWAR1(r3) /* LBLAWAR1 <= 8MB Flash Size */
1239 blr
1240
1241 /* Though all the LBIU Local Access Windows and LBC Banks will be
1242 * initialized in the C code, we'd better configure boot ROM's
1243 * window 0 and bank 0 correctly at here.
1244 */
1245remap_flash_by_law0:
1246 /* Initialize the BR0 with the boot ROM starting address. */
1247 lwz r4, BR0(r3)
1248 li r5, 0x7FFF
Jon Loeligerebc72242005-08-01 13:20:47 -05001249 and r4, r4, r5
Eran Liberty9095d4a2005-07-28 10:08:46 -05001250 lis r5, (CFG_FLASH_BASE & 0xFFFF8000)@h
Jon Loeligerebc72242005-08-01 13:20:47 -05001251 ori r5, r5, (CFG_FLASH_BASE & 0xFFFF8000)@l
Eran Liberty9095d4a2005-07-28 10:08:46 -05001252 or r5, r5, r4
1253 stw r5, BR0(r3) /* r5 <= (CFG_FLASH_BASE & 0xFFFF8000) | (BR0 & 0x00007FFF) */
1254
1255 lwz r4, OR0(r3)
Timur Tabi53b46172006-08-22 17:07:00 -05001256 lis r5, ~((CFG_FLASH_SIZE << 4) - 1)
Eran Liberty9095d4a2005-07-28 10:08:46 -05001257 or r4, r4, r5
Timur Tabi53b46172006-08-22 17:07:00 -05001258 stw r4, OR0(r3)
Eran Liberty9095d4a2005-07-28 10:08:46 -05001259
1260 lis r4, (CFG_FLASH_BASE)@h
1261 ori r4, r4, (CFG_FLASH_BASE)@l
1262 stw r4, LBLAWBAR0(r3) /* LBLAWBAR0 <= CFG_FLASH_BASE */
1263
Timur Tabi53b46172006-08-22 17:07:00 -05001264 /* Store 0x80000012 + log2(CFG_FLASH_SIZE) into LBLAWAR0 */
1265 lis r4, (0x80000012)@h
1266 ori r4, r4, (0x80000012)@l
1267 li r5, CFG_FLASH_SIZE
12681: srawi. r5, r5, 1 /* r5 = r5 >> 1 */
1269 addi r4, r4, 1
1270 bne 1b
1271 stw r4, LBLAWAR0(r3) /* LBLAWAR0 <= Flash Size */
1272
Eran Liberty9095d4a2005-07-28 10:08:46 -05001273
1274 xor r4, r4, r4
1275 stw r4, LBLAWBAR1(r3)
1276 stw r4, LBLAWAR1(r3) /* Off LBIU LAW1 */
1277 blr