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 <linux/config.h>
17 #include <asm/cache.h>
18 #include <asm/ppc_asm.h>
20 #define GETSYM(reg, sym) \
21 lis reg, sym@h; ori reg, reg, sym@l
24 /* We get called from the early initialization code.
25 * Register 3 has the address where we were loaded,
26 * Register 4 contains any residual data passed from the
31 /* Save r3, r4 for later.
32 * The r8/r11 are legacy registers so I don't have to
33 * rewrite the code below :-).
38 /* compute the size of the whole image in words. */
42 addi r5,r5,3 /* round up */
43 sub r5,r5,r4 /* end - start */
45 mr r7,r5 /* Save for later use. */
48 * Check if we need to relocate ourselves to the link addr or were
49 * we loaded there to begin with.
52 beq start_ldr /* If 0, we don't need to relocate */
54 /* Move this code somewhere safe. This is max(load + size, end)
61 add r6,r8,r6 /* r6 == phys(load + size) */
70 /* Ensure alignment --- this code is precautionary */
75 /* Find physical address and size of do_relocate */
76 GETSYM(r5, __relocate_start)
77 GETSYM(r4, __relocate_end)
84 /* Src addr to copy (= __relocate_start - start + where_loaded) */
99 GETSYM(r4, __relocate_start)
100 GETSYM(r5, do_relocate)
102 sub r4,r5,r4 /* Get entry point for do_relocate in */
103 add r6,r6,r4 /* relocated section */
105 /* This will return to the relocated do_relocate */
107 b flush_instruction_cache
109 .section ".relocate_code","xa"
112 /* We have 2 cases --- start < load, or start > load
113 * This determines whether we copy from the end, or the start.
114 * Its easier to have 2 loops than to have paramaterised
117 li r6,0 /* Clear checksum */
118 mtctr r7 /* Setup for a loop */
121 mr r3,r8 /* Get the load addr */
123 cmpw cr0,r4,r3 /* If we need to copy from the end, do so */
124 bgt do_relocate_from_end
126 do_relocate_from_start:
127 1: lwz r5,0(r3) /* Load and decrement */
128 stw r5,0(r4) /* Store and decrement */
131 xor r6,r6,r5 /* Update checksum */
132 bdnz 1b /* Are we done? */
133 b do_relocate_out /* Finished */
135 do_relocate_from_end:
138 add r4,r8,r4 /* Get the physical end */
146 mtlr r3 /* Easiest way to do an absolute jump */
147 /* Some boards don't boot up with the I-cache enabled. Do that
148 * now because the decompress runs much faster that way.
149 * As a side effect, we have to ensure the data cache is not enabled
150 * so we can access the serial I/O without trouble.
152 b flush_instruction_cache
157 /* Clear all of BSS and set up stack for C calls */
168 90: mr r9,r1 /* Save old stack pointer (in case it matters) */
173 li r2,0x000F /* Mask pointer to 16-byte boundary */
179 mr r3,r8 /* Load point */
180 mr r4,r7 /* Program length */
181 mr r5,r6 /* Checksum */
182 mr r6,r11 /* Residual data */
183 mr r7,r25 /* Validated OFW interface */
187 * Make sure the kernel knows we don't have things set in
195 * Start at the begining.
197 #ifdef CONFIG_PPC_PREP
200 /* tell kernel we're prep, by putting 0xdeadc0de at KERNELLOAD,
201 * and tell the kernel to start on the 4th instruction since we
202 * overwrite the first 3 sometimes (which are 'nop').
205 ori r10,r10,0xdeadc0de@l
214 .comm .stack,4096*2,4