2 * This is the common part of the loader relocation and initialization
3 * process. All of the board/processor specific initialization is
4 * done before we get here.
8 * Derived from arch/ppc/boot/prep/head.S (Cort Dougan, many others).
10 * 2001-2004 (c) MontaVista, Software, Inc. This file is licensed under
11 * the terms of the GNU General Public License version 2. This program
12 * is licensed "as is" without any warranty of any kind, whether express
16 #include <asm/cache.h>
17 #include <asm/ppc_asm.h>
19 #define GETSYM(reg, sym) \
20 lis reg, sym@h; ori reg, reg, sym@l
23 /* We get called from the early initialization code.
24 * Register 3 has the address where we were loaded,
25 * Register 4 contains any residual data passed from the
30 /* Save r3, r4 for later.
31 * The r8/r11 are legacy registers so I don't have to
32 * rewrite the code below :-).
37 /* compute the size of the whole image in words. */
41 addi r5,r5,3 /* round up */
42 sub r5,r5,r4 /* end - start */
44 mr r7,r5 /* Save for later use. */
47 * Check if we need to relocate ourselves to the link addr or were
48 * we loaded there to begin with.
51 beq start_ldr /* If 0, we don't need to relocate */
53 /* Move this code somewhere safe. This is max(load + size, end)
60 add r6,r8,r6 /* r6 == phys(load + size) */
69 /* Ensure alignment --- this code is precautionary */
74 /* Find physical address and size of do_relocate */
75 GETSYM(r5, __relocate_start)
76 GETSYM(r4, __relocate_end)
83 /* Src addr to copy (= __relocate_start - start + where_loaded) */
98 GETSYM(r4, __relocate_start)
99 GETSYM(r5, do_relocate)
101 sub r4,r5,r4 /* Get entry point for do_relocate in */
102 add r6,r6,r4 /* relocated section */
104 /* This will return to the relocated do_relocate */
106 b flush_instruction_cache
108 .section ".relocate_code","xa"
111 /* We have 2 cases --- start < load, or start > load
112 * This determines whether we copy from the end, or the start.
113 * Its easier to have 2 loops than to have paramaterised
116 li r6,0 /* Clear checksum */
117 mtctr r7 /* Setup for a loop */
120 mr r3,r8 /* Get the load addr */
122 cmpw cr0,r4,r3 /* If we need to copy from the end, do so */
123 bgt do_relocate_from_end
125 do_relocate_from_start:
126 1: lwz r5,0(r3) /* Load and decrement */
127 stw r5,0(r4) /* Store and decrement */
130 xor r6,r6,r5 /* Update checksum */
131 bdnz 1b /* Are we done? */
132 b do_relocate_out /* Finished */
134 do_relocate_from_end:
137 add r4,r8,r4 /* Get the physical end */
145 mtlr r3 /* Easiest way to do an absolute jump */
146 /* Some boards don't boot up with the I-cache enabled. Do that
147 * now because the decompress runs much faster that way.
148 * As a side effect, we have to ensure the data cache is not enabled
149 * so we can access the serial I/O without trouble.
151 b flush_instruction_cache
156 /* Clear all of BSS and set up stack for C calls */
167 90: mr r9,r1 /* Save old stack pointer (in case it matters) */
172 li r2,0x000F /* Mask pointer to 16-byte boundary */
178 mr r3,r8 /* Load point */
179 mr r4,r7 /* Program length */
180 mr r5,r6 /* Checksum */
181 mr r6,r11 /* Residual data */
182 mr r7,r25 /* Validated OFW interface */
186 * Make sure the kernel knows we don't have things set in
194 * Start at the begining.
196 #ifdef CONFIG_PPC_PREP
199 /* tell kernel we're prep, by putting 0xdeadc0de at KERNELLOAD,
200 * and tell the kernel to start on the 4th instruction since we
201 * overwrite the first 3 sometimes (which are 'nop').
204 ori r10,r10,0xdeadc0de@l
213 .comm .stack,4096*2,4