2 * arch/ppc/boot/simple/relocate.S
4 * This is the common part of the loader relocation and initialization
5 * process. All of the board/processor specific initialization is
6 * done before we get here.
10 * Derived from arch/ppc/boot/prep/head.S (Cort Dougan, many others).
12 * 2001-2004 (c) MontaVista, Software, Inc. This file is licensed under
13 * the terms of the GNU General Public License version 2. This program
14 * is licensed "as is" without any warranty of any kind, whether express
18 #include <linux/config.h>
19 #include <asm/cache.h>
20 #include <asm/ppc_asm.h>
22 #define GETSYM(reg, sym) \
23 lis reg, sym@h; ori reg, reg, sym@l
26 /* We get called from the early initialization code.
27 * Register 3 has the address where we were loaded,
28 * Register 4 contains any residual data passed from the
33 /* Save r3, r4 for later.
34 * The r8/r11 are legacy registers so I don't have to
35 * rewrite the code below :-).
40 /* compute the size of the whole image in words. */
44 addi r5,r5,3 /* round up */
45 sub r5,r5,r4 /* end - start */
47 mr r7,r5 /* Save for later use. */
50 * Check if we need to relocate ourselves to the link addr or were
51 * we loaded there to begin with.
54 beq start_ldr /* If 0, we don't need to relocate */
56 /* Move this code somewhere safe. This is max(load + size, end)
63 add r6,r8,r6 /* r6 == phys(load + size) */
72 /* Ensure alignment --- this code is precautionary */
77 /* Find physical address and size of do_relocate */
78 GETSYM(r5, __relocate_start)
79 GETSYM(r4, __relocate_end)
86 /* Src addr to copy (= __relocate_start - start + where_loaded) */
101 GETSYM(r4, __relocate_start)
102 GETSYM(r5, do_relocate)
104 sub r4,r5,r4 /* Get entry point for do_relocate in */
105 add r6,r6,r4 /* relocated section */
107 /* This will return to the relocated do_relocate */
109 b flush_instruction_cache
111 .section ".relocate_code","xa"
114 /* We have 2 cases --- start < load, or start > load
115 * This determines whether we copy from the end, or the start.
116 * Its easier to have 2 loops than to have paramaterised
119 li r6,0 /* Clear checksum */
120 mtctr r7 /* Setup for a loop */
123 mr r3,r8 /* Get the load addr */
125 cmpw cr0,r4,r3 /* If we need to copy from the end, do so */
126 bgt do_relocate_from_end
128 do_relocate_from_start:
129 1: lwz r5,0(r3) /* Load and decrement */
130 stw r5,0(r4) /* Store and decrement */
133 xor r6,r6,r5 /* Update checksum */
134 bdnz 1b /* Are we done? */
135 b do_relocate_out /* Finished */
137 do_relocate_from_end:
140 add r4,r8,r4 /* Get the physical end */
148 mtlr r3 /* Easiest way to do an absolute jump */
149 /* Some boards don't boot up with the I-cache enabled. Do that
150 * now because the decompress runs much faster that way.
151 * As a side effect, we have to ensure the data cache is not enabled
152 * so we can access the serial I/O without trouble.
154 b flush_instruction_cache
159 /* Clear all of BSS and set up stack for C calls */
170 90: mr r9,r1 /* Save old stack pointer (in case it matters) */
175 li r2,0x000F /* Mask pointer to 16-byte boundary */
181 mr r3,r8 /* Load point */
182 mr r4,r7 /* Program length */
183 mr r5,r6 /* Checksum */
184 mr r6,r11 /* Residual data */
185 mr r7,r25 /* Validated OFW interface */
189 * Make sure the kernel knows we don't have things set in
197 * Start at the begining.
199 #ifdef CONFIG_PPC_MULTIPLATFORM
202 /* tell kernel we're prep, by putting 0xdeadc0de at KERNELLOAD,
203 * and tell the kernel to start on the 4th instruction since we
204 * overwrite the first 3 sometimes (which are 'nop').
207 ori r10,r10,0xdeadc0de@l
216 .comm .stack,4096*2,4