1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * arch/alpha/boot/bootpz.c
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Copyright (C) 1997 Jay Estabrook
6*4882a593Smuzhiyun *
7*4882a593Smuzhiyun * This file is used for creating a compressed BOOTP file for the
8*4882a593Smuzhiyun * Linux/AXP kernel
9*4882a593Smuzhiyun *
10*4882a593Smuzhiyun * based significantly on the arch/alpha/boot/main.c of Linus Torvalds
11*4882a593Smuzhiyun * and the decompression code from MILO.
12*4882a593Smuzhiyun */
13*4882a593Smuzhiyun #include <linux/kernel.h>
14*4882a593Smuzhiyun #include <linux/slab.h>
15*4882a593Smuzhiyun #include <linux/string.h>
16*4882a593Smuzhiyun #include <generated/utsrelease.h>
17*4882a593Smuzhiyun #include <linux/mm.h>
18*4882a593Smuzhiyun
19*4882a593Smuzhiyun #include <asm/console.h>
20*4882a593Smuzhiyun #include <asm/hwrpb.h>
21*4882a593Smuzhiyun #include <asm/io.h>
22*4882a593Smuzhiyun
23*4882a593Smuzhiyun #include <stdarg.h>
24*4882a593Smuzhiyun
25*4882a593Smuzhiyun #include "kzsize.h"
26*4882a593Smuzhiyun
27*4882a593Smuzhiyun /* FIXME FIXME FIXME */
28*4882a593Smuzhiyun #define MALLOC_AREA_SIZE 0x200000 /* 2MB for now */
29*4882a593Smuzhiyun /* FIXME FIXME FIXME */
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun
32*4882a593Smuzhiyun /*
33*4882a593Smuzhiyun WARNING NOTE
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun It is very possible that turning on additional messages may cause
36*4882a593Smuzhiyun kernel image corruption due to stack usage to do the printing.
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun */
39*4882a593Smuzhiyun
40*4882a593Smuzhiyun #undef DEBUG_CHECK_RANGE
41*4882a593Smuzhiyun #undef DEBUG_ADDRESSES
42*4882a593Smuzhiyun #undef DEBUG_LAST_STEPS
43*4882a593Smuzhiyun
44*4882a593Smuzhiyun extern unsigned long switch_to_osf_pal(unsigned long nr,
45*4882a593Smuzhiyun struct pcb_struct * pcb_va, struct pcb_struct * pcb_pa,
46*4882a593Smuzhiyun unsigned long *vptb);
47*4882a593Smuzhiyun
48*4882a593Smuzhiyun extern int decompress_kernel(void* destination, void *source,
49*4882a593Smuzhiyun size_t ksize, size_t kzsize);
50*4882a593Smuzhiyun
51*4882a593Smuzhiyun extern void move_stack(unsigned long new_stack);
52*4882a593Smuzhiyun
53*4882a593Smuzhiyun struct hwrpb_struct *hwrpb = INIT_HWRPB;
54*4882a593Smuzhiyun static struct pcb_struct pcb_va[1];
55*4882a593Smuzhiyun
56*4882a593Smuzhiyun /*
57*4882a593Smuzhiyun * Find a physical address of a virtual object..
58*4882a593Smuzhiyun *
59*4882a593Smuzhiyun * This is easy using the virtual page table address.
60*4882a593Smuzhiyun */
61*4882a593Smuzhiyun #define VPTB ((unsigned long *) 0x200000000)
62*4882a593Smuzhiyun
63*4882a593Smuzhiyun static inline unsigned long
find_pa(unsigned long address)64*4882a593Smuzhiyun find_pa(unsigned long address)
65*4882a593Smuzhiyun {
66*4882a593Smuzhiyun unsigned long result;
67*4882a593Smuzhiyun
68*4882a593Smuzhiyun result = VPTB[address >> 13];
69*4882a593Smuzhiyun result >>= 32;
70*4882a593Smuzhiyun result <<= 13;
71*4882a593Smuzhiyun result |= address & 0x1fff;
72*4882a593Smuzhiyun return result;
73*4882a593Smuzhiyun }
74*4882a593Smuzhiyun
75*4882a593Smuzhiyun int
check_range(unsigned long vstart,unsigned long vend,unsigned long kstart,unsigned long kend)76*4882a593Smuzhiyun check_range(unsigned long vstart, unsigned long vend,
77*4882a593Smuzhiyun unsigned long kstart, unsigned long kend)
78*4882a593Smuzhiyun {
79*4882a593Smuzhiyun unsigned long vaddr, kaddr;
80*4882a593Smuzhiyun
81*4882a593Smuzhiyun #ifdef DEBUG_CHECK_RANGE
82*4882a593Smuzhiyun srm_printk("check_range: V[0x%lx:0x%lx] K[0x%lx:0x%lx]\n",
83*4882a593Smuzhiyun vstart, vend, kstart, kend);
84*4882a593Smuzhiyun #endif
85*4882a593Smuzhiyun /* do some range checking for detecting an overlap... */
86*4882a593Smuzhiyun for (vaddr = vstart; vaddr <= vend; vaddr += PAGE_SIZE)
87*4882a593Smuzhiyun {
88*4882a593Smuzhiyun kaddr = (find_pa(vaddr) | PAGE_OFFSET);
89*4882a593Smuzhiyun if (kaddr >= kstart && kaddr <= kend)
90*4882a593Smuzhiyun {
91*4882a593Smuzhiyun #ifdef DEBUG_CHECK_RANGE
92*4882a593Smuzhiyun srm_printk("OVERLAP: vaddr 0x%lx kaddr 0x%lx"
93*4882a593Smuzhiyun " [0x%lx:0x%lx]\n",
94*4882a593Smuzhiyun vaddr, kaddr, kstart, kend);
95*4882a593Smuzhiyun #endif
96*4882a593Smuzhiyun return 1;
97*4882a593Smuzhiyun }
98*4882a593Smuzhiyun }
99*4882a593Smuzhiyun return 0;
100*4882a593Smuzhiyun }
101*4882a593Smuzhiyun
102*4882a593Smuzhiyun /*
103*4882a593Smuzhiyun * This function moves into OSF/1 pal-code, and has a temporary
104*4882a593Smuzhiyun * PCB for that. The kernel proper should replace this PCB with
105*4882a593Smuzhiyun * the real one as soon as possible.
106*4882a593Smuzhiyun *
107*4882a593Smuzhiyun * The page table muckery in here depends on the fact that the boot
108*4882a593Smuzhiyun * code has the L1 page table identity-map itself in the second PTE
109*4882a593Smuzhiyun * in the L1 page table. Thus the L1-page is virtually addressable
110*4882a593Smuzhiyun * itself (through three levels) at virtual address 0x200802000.
111*4882a593Smuzhiyun */
112*4882a593Smuzhiyun
113*4882a593Smuzhiyun #define L1 ((unsigned long *) 0x200802000)
114*4882a593Smuzhiyun
115*4882a593Smuzhiyun void
pal_init(void)116*4882a593Smuzhiyun pal_init(void)
117*4882a593Smuzhiyun {
118*4882a593Smuzhiyun unsigned long i, rev;
119*4882a593Smuzhiyun struct percpu_struct * percpu;
120*4882a593Smuzhiyun struct pcb_struct * pcb_pa;
121*4882a593Smuzhiyun
122*4882a593Smuzhiyun /* Create the dummy PCB. */
123*4882a593Smuzhiyun pcb_va->ksp = 0;
124*4882a593Smuzhiyun pcb_va->usp = 0;
125*4882a593Smuzhiyun pcb_va->ptbr = L1[1] >> 32;
126*4882a593Smuzhiyun pcb_va->asn = 0;
127*4882a593Smuzhiyun pcb_va->pcc = 0;
128*4882a593Smuzhiyun pcb_va->unique = 0;
129*4882a593Smuzhiyun pcb_va->flags = 1;
130*4882a593Smuzhiyun pcb_va->res1 = 0;
131*4882a593Smuzhiyun pcb_va->res2 = 0;
132*4882a593Smuzhiyun pcb_pa = (struct pcb_struct *)find_pa((unsigned long)pcb_va);
133*4882a593Smuzhiyun
134*4882a593Smuzhiyun /*
135*4882a593Smuzhiyun * a0 = 2 (OSF)
136*4882a593Smuzhiyun * a1 = return address, but we give the asm the vaddr of the PCB
137*4882a593Smuzhiyun * a2 = physical addr of PCB
138*4882a593Smuzhiyun * a3 = new virtual page table pointer
139*4882a593Smuzhiyun * a4 = KSP (but the asm sets it)
140*4882a593Smuzhiyun */
141*4882a593Smuzhiyun srm_printk("Switching to OSF PAL-code... ");
142*4882a593Smuzhiyun
143*4882a593Smuzhiyun i = switch_to_osf_pal(2, pcb_va, pcb_pa, VPTB);
144*4882a593Smuzhiyun if (i) {
145*4882a593Smuzhiyun srm_printk("failed, code %ld\n", i);
146*4882a593Smuzhiyun __halt();
147*4882a593Smuzhiyun }
148*4882a593Smuzhiyun
149*4882a593Smuzhiyun percpu = (struct percpu_struct *)
150*4882a593Smuzhiyun (INIT_HWRPB->processor_offset + (unsigned long) INIT_HWRPB);
151*4882a593Smuzhiyun rev = percpu->pal_revision = percpu->palcode_avail[2];
152*4882a593Smuzhiyun
153*4882a593Smuzhiyun srm_printk("OK (rev %lx)\n", rev);
154*4882a593Smuzhiyun
155*4882a593Smuzhiyun tbia(); /* do it directly in case we are SMP */
156*4882a593Smuzhiyun }
157*4882a593Smuzhiyun
158*4882a593Smuzhiyun /*
159*4882a593Smuzhiyun * Start the kernel.
160*4882a593Smuzhiyun */
161*4882a593Smuzhiyun static inline void
runkernel(void)162*4882a593Smuzhiyun runkernel(void)
163*4882a593Smuzhiyun {
164*4882a593Smuzhiyun __asm__ __volatile__(
165*4882a593Smuzhiyun "bis %0,%0,$27\n\t"
166*4882a593Smuzhiyun "jmp ($27)"
167*4882a593Smuzhiyun : /* no outputs: it doesn't even return */
168*4882a593Smuzhiyun : "r" (START_ADDR));
169*4882a593Smuzhiyun }
170*4882a593Smuzhiyun
171*4882a593Smuzhiyun /* Must record the SP (it is virtual) on entry, so we can make sure
172*4882a593Smuzhiyun not to overwrite it during movement or decompression. */
173*4882a593Smuzhiyun unsigned long SP_on_entry;
174*4882a593Smuzhiyun
175*4882a593Smuzhiyun /* Calculate the kernel image address based on the end of the BOOTP
176*4882a593Smuzhiyun bootstrapper (ie this program).
177*4882a593Smuzhiyun */
178*4882a593Smuzhiyun extern char _end;
179*4882a593Smuzhiyun #define KERNEL_ORIGIN \
180*4882a593Smuzhiyun ((((unsigned long)&_end) + 511) & ~511)
181*4882a593Smuzhiyun
182*4882a593Smuzhiyun /* Round address to next higher page boundary. */
183*4882a593Smuzhiyun #define NEXT_PAGE(a) (((a) | (PAGE_SIZE - 1)) + 1)
184*4882a593Smuzhiyun
185*4882a593Smuzhiyun #ifdef INITRD_IMAGE_SIZE
186*4882a593Smuzhiyun # define REAL_INITRD_SIZE INITRD_IMAGE_SIZE
187*4882a593Smuzhiyun #else
188*4882a593Smuzhiyun # define REAL_INITRD_SIZE 0
189*4882a593Smuzhiyun #endif
190*4882a593Smuzhiyun
191*4882a593Smuzhiyun /* Defines from include/asm-alpha/system.h
192*4882a593Smuzhiyun
193*4882a593Smuzhiyun BOOT_ADDR Virtual address at which the consoles loads
194*4882a593Smuzhiyun the BOOTP image.
195*4882a593Smuzhiyun
196*4882a593Smuzhiyun KERNEL_START KSEG address at which the kernel is built to run,
197*4882a593Smuzhiyun which includes some initial data pages before the
198*4882a593Smuzhiyun code.
199*4882a593Smuzhiyun
200*4882a593Smuzhiyun START_ADDR KSEG address of the entry point of kernel code.
201*4882a593Smuzhiyun
202*4882a593Smuzhiyun ZERO_PGE KSEG address of page full of zeroes, but
203*4882a593Smuzhiyun upon entry to kerne cvan be expected
204*4882a593Smuzhiyun to hold the parameter list and possible
205*4882a593Smuzhiyun INTRD information.
206*4882a593Smuzhiyun
207*4882a593Smuzhiyun These are used in the local defines below.
208*4882a593Smuzhiyun */
209*4882a593Smuzhiyun
210*4882a593Smuzhiyun
211*4882a593Smuzhiyun /* Virtual addresses for the BOOTP image. Note that this includes the
212*4882a593Smuzhiyun bootstrapper code as well as the compressed kernel image, and
213*4882a593Smuzhiyun possibly the INITRD image.
214*4882a593Smuzhiyun
215*4882a593Smuzhiyun Oh, and do NOT forget the STACK, which appears to be placed virtually
216*4882a593Smuzhiyun beyond the end of the loaded image.
217*4882a593Smuzhiyun */
218*4882a593Smuzhiyun #define V_BOOT_IMAGE_START BOOT_ADDR
219*4882a593Smuzhiyun #define V_BOOT_IMAGE_END SP_on_entry
220*4882a593Smuzhiyun
221*4882a593Smuzhiyun /* Virtual addresses for just the bootstrapper part of the BOOTP image. */
222*4882a593Smuzhiyun #define V_BOOTSTRAPPER_START BOOT_ADDR
223*4882a593Smuzhiyun #define V_BOOTSTRAPPER_END KERNEL_ORIGIN
224*4882a593Smuzhiyun
225*4882a593Smuzhiyun /* Virtual addresses for just the data part of the BOOTP
226*4882a593Smuzhiyun image. This may also include the INITRD image, but always
227*4882a593Smuzhiyun includes the STACK.
228*4882a593Smuzhiyun */
229*4882a593Smuzhiyun #define V_DATA_START KERNEL_ORIGIN
230*4882a593Smuzhiyun #define V_INITRD_START (KERNEL_ORIGIN + KERNEL_Z_SIZE)
231*4882a593Smuzhiyun #define V_INTRD_END (V_INITRD_START + REAL_INITRD_SIZE)
232*4882a593Smuzhiyun #define V_DATA_END V_BOOT_IMAGE_END
233*4882a593Smuzhiyun
234*4882a593Smuzhiyun /* KSEG addresses for the uncompressed kernel.
235*4882a593Smuzhiyun
236*4882a593Smuzhiyun Note that the end address includes workspace for the decompression.
237*4882a593Smuzhiyun Note also that the DATA_START address is ZERO_PGE, to which we write
238*4882a593Smuzhiyun just before jumping to the kernel image at START_ADDR.
239*4882a593Smuzhiyun */
240*4882a593Smuzhiyun #define K_KERNEL_DATA_START ZERO_PGE
241*4882a593Smuzhiyun #define K_KERNEL_IMAGE_START START_ADDR
242*4882a593Smuzhiyun #define K_KERNEL_IMAGE_END (START_ADDR + KERNEL_SIZE)
243*4882a593Smuzhiyun
244*4882a593Smuzhiyun /* Define to where we may have to decompress the kernel image, before
245*4882a593Smuzhiyun we move it to the final position, in case of overlap. This will be
246*4882a593Smuzhiyun above the final position of the kernel.
247*4882a593Smuzhiyun
248*4882a593Smuzhiyun Regardless of overlap, we move the INITRD image to the end of this
249*4882a593Smuzhiyun copy area, because there needs to be a buffer area after the kernel
250*4882a593Smuzhiyun for "bootmem" anyway.
251*4882a593Smuzhiyun */
252*4882a593Smuzhiyun #define K_COPY_IMAGE_START NEXT_PAGE(K_KERNEL_IMAGE_END)
253*4882a593Smuzhiyun /* Reserve one page below INITRD for the new stack. */
254*4882a593Smuzhiyun #define K_INITRD_START \
255*4882a593Smuzhiyun NEXT_PAGE(K_COPY_IMAGE_START + KERNEL_SIZE + PAGE_SIZE)
256*4882a593Smuzhiyun #define K_COPY_IMAGE_END \
257*4882a593Smuzhiyun (K_INITRD_START + REAL_INITRD_SIZE + MALLOC_AREA_SIZE)
258*4882a593Smuzhiyun #define K_COPY_IMAGE_SIZE \
259*4882a593Smuzhiyun NEXT_PAGE(K_COPY_IMAGE_END - K_COPY_IMAGE_START)
260*4882a593Smuzhiyun
261*4882a593Smuzhiyun void
start_kernel(void)262*4882a593Smuzhiyun start_kernel(void)
263*4882a593Smuzhiyun {
264*4882a593Smuzhiyun int must_move = 0;
265*4882a593Smuzhiyun
266*4882a593Smuzhiyun /* Initialize these for the decompression-in-place situation,
267*4882a593Smuzhiyun which is the smallest amount of work and most likely to
268*4882a593Smuzhiyun occur when using the normal START_ADDR of the kernel
269*4882a593Smuzhiyun (currently set to 16MB, to clear all console code.
270*4882a593Smuzhiyun */
271*4882a593Smuzhiyun unsigned long uncompressed_image_start = K_KERNEL_IMAGE_START;
272*4882a593Smuzhiyun unsigned long uncompressed_image_end = K_KERNEL_IMAGE_END;
273*4882a593Smuzhiyun
274*4882a593Smuzhiyun unsigned long initrd_image_start = K_INITRD_START;
275*4882a593Smuzhiyun
276*4882a593Smuzhiyun /*
277*4882a593Smuzhiyun * Note that this crufty stuff with static and envval
278*4882a593Smuzhiyun * and envbuf is because:
279*4882a593Smuzhiyun *
280*4882a593Smuzhiyun * 1. Frequently, the stack is short, and we don't want to overrun;
281*4882a593Smuzhiyun * 2. Frequently the stack is where we are going to copy the kernel to;
282*4882a593Smuzhiyun * 3. A certain SRM console required the GET_ENV output to stack.
283*4882a593Smuzhiyun * ??? A comment in the aboot sources indicates that the GET_ENV
284*4882a593Smuzhiyun * destination must be quadword aligned. Might this explain the
285*4882a593Smuzhiyun * behaviour, rather than requiring output to the stack, which
286*4882a593Smuzhiyun * seems rather far-fetched.
287*4882a593Smuzhiyun */
288*4882a593Smuzhiyun static long nbytes;
289*4882a593Smuzhiyun static char envval[256] __attribute__((aligned(8)));
290*4882a593Smuzhiyun register unsigned long asm_sp asm("30");
291*4882a593Smuzhiyun
292*4882a593Smuzhiyun SP_on_entry = asm_sp;
293*4882a593Smuzhiyun
294*4882a593Smuzhiyun srm_printk("Linux/Alpha BOOTPZ Loader for Linux " UTS_RELEASE "\n");
295*4882a593Smuzhiyun
296*4882a593Smuzhiyun /* Validity check the HWRPB. */
297*4882a593Smuzhiyun if (INIT_HWRPB->pagesize != 8192) {
298*4882a593Smuzhiyun srm_printk("Expected 8kB pages, got %ldkB\n",
299*4882a593Smuzhiyun INIT_HWRPB->pagesize >> 10);
300*4882a593Smuzhiyun return;
301*4882a593Smuzhiyun }
302*4882a593Smuzhiyun if (INIT_HWRPB->vptb != (unsigned long) VPTB) {
303*4882a593Smuzhiyun srm_printk("Expected vptb at %p, got %p\n",
304*4882a593Smuzhiyun VPTB, (void *)INIT_HWRPB->vptb);
305*4882a593Smuzhiyun return;
306*4882a593Smuzhiyun }
307*4882a593Smuzhiyun
308*4882a593Smuzhiyun /* PALcode (re)initialization. */
309*4882a593Smuzhiyun pal_init();
310*4882a593Smuzhiyun
311*4882a593Smuzhiyun /* Get the parameter list from the console environment variable. */
312*4882a593Smuzhiyun nbytes = callback_getenv(ENV_BOOTED_OSFLAGS, envval, sizeof(envval));
313*4882a593Smuzhiyun if (nbytes < 0 || nbytes >= sizeof(envval)) {
314*4882a593Smuzhiyun nbytes = 0;
315*4882a593Smuzhiyun }
316*4882a593Smuzhiyun envval[nbytes] = '\0';
317*4882a593Smuzhiyun
318*4882a593Smuzhiyun #ifdef DEBUG_ADDRESSES
319*4882a593Smuzhiyun srm_printk("START_ADDR 0x%lx\n", START_ADDR);
320*4882a593Smuzhiyun srm_printk("KERNEL_ORIGIN 0x%lx\n", KERNEL_ORIGIN);
321*4882a593Smuzhiyun srm_printk("KERNEL_SIZE 0x%x\n", KERNEL_SIZE);
322*4882a593Smuzhiyun srm_printk("KERNEL_Z_SIZE 0x%x\n", KERNEL_Z_SIZE);
323*4882a593Smuzhiyun #endif
324*4882a593Smuzhiyun
325*4882a593Smuzhiyun /* Since all the SRM consoles load the BOOTP image at virtual
326*4882a593Smuzhiyun * 0x20000000, we have to ensure that the physical memory
327*4882a593Smuzhiyun * pages occupied by that image do NOT overlap the physical
328*4882a593Smuzhiyun * address range where the kernel wants to be run. This
329*4882a593Smuzhiyun * causes real problems when attempting to cdecompress the
330*4882a593Smuzhiyun * former into the latter... :-(
331*4882a593Smuzhiyun *
332*4882a593Smuzhiyun * So, we may have to decompress/move the kernel/INITRD image
333*4882a593Smuzhiyun * virtual-to-physical someplace else first before moving
334*4882a593Smuzhiyun * kernel /INITRD to their final resting places... ;-}
335*4882a593Smuzhiyun *
336*4882a593Smuzhiyun * Sigh...
337*4882a593Smuzhiyun */
338*4882a593Smuzhiyun
339*4882a593Smuzhiyun /* First, check to see if the range of addresses occupied by
340*4882a593Smuzhiyun the bootstrapper part of the BOOTP image include any of the
341*4882a593Smuzhiyun physical pages into which the kernel will be placed for
342*4882a593Smuzhiyun execution.
343*4882a593Smuzhiyun
344*4882a593Smuzhiyun We only need check on the final kernel image range, since we
345*4882a593Smuzhiyun will put the INITRD someplace that we can be sure is not
346*4882a593Smuzhiyun in conflict.
347*4882a593Smuzhiyun */
348*4882a593Smuzhiyun if (check_range(V_BOOTSTRAPPER_START, V_BOOTSTRAPPER_END,
349*4882a593Smuzhiyun K_KERNEL_DATA_START, K_KERNEL_IMAGE_END))
350*4882a593Smuzhiyun {
351*4882a593Smuzhiyun srm_printk("FATAL ERROR: overlap of bootstrapper code\n");
352*4882a593Smuzhiyun __halt();
353*4882a593Smuzhiyun }
354*4882a593Smuzhiyun
355*4882a593Smuzhiyun /* Next, check to see if the range of addresses occupied by
356*4882a593Smuzhiyun the compressed kernel/INITRD/stack portion of the BOOTP
357*4882a593Smuzhiyun image include any of the physical pages into which the
358*4882a593Smuzhiyun decompressed kernel or the INITRD will be placed for
359*4882a593Smuzhiyun execution.
360*4882a593Smuzhiyun */
361*4882a593Smuzhiyun if (check_range(V_DATA_START, V_DATA_END,
362*4882a593Smuzhiyun K_KERNEL_IMAGE_START, K_COPY_IMAGE_END))
363*4882a593Smuzhiyun {
364*4882a593Smuzhiyun #ifdef DEBUG_ADDRESSES
365*4882a593Smuzhiyun srm_printk("OVERLAP: cannot decompress in place\n");
366*4882a593Smuzhiyun #endif
367*4882a593Smuzhiyun uncompressed_image_start = K_COPY_IMAGE_START;
368*4882a593Smuzhiyun uncompressed_image_end = K_COPY_IMAGE_END;
369*4882a593Smuzhiyun must_move = 1;
370*4882a593Smuzhiyun
371*4882a593Smuzhiyun /* Finally, check to see if the range of addresses
372*4882a593Smuzhiyun occupied by the compressed kernel/INITRD part of
373*4882a593Smuzhiyun the BOOTP image include any of the physical pages
374*4882a593Smuzhiyun into which that part is to be copied for
375*4882a593Smuzhiyun decompression.
376*4882a593Smuzhiyun */
377*4882a593Smuzhiyun while (check_range(V_DATA_START, V_DATA_END,
378*4882a593Smuzhiyun uncompressed_image_start,
379*4882a593Smuzhiyun uncompressed_image_end))
380*4882a593Smuzhiyun {
381*4882a593Smuzhiyun #if 0
382*4882a593Smuzhiyun uncompressed_image_start += K_COPY_IMAGE_SIZE;
383*4882a593Smuzhiyun uncompressed_image_end += K_COPY_IMAGE_SIZE;
384*4882a593Smuzhiyun initrd_image_start += K_COPY_IMAGE_SIZE;
385*4882a593Smuzhiyun #else
386*4882a593Smuzhiyun /* Keep as close as possible to end of BOOTP image. */
387*4882a593Smuzhiyun uncompressed_image_start += PAGE_SIZE;
388*4882a593Smuzhiyun uncompressed_image_end += PAGE_SIZE;
389*4882a593Smuzhiyun initrd_image_start += PAGE_SIZE;
390*4882a593Smuzhiyun #endif
391*4882a593Smuzhiyun }
392*4882a593Smuzhiyun }
393*4882a593Smuzhiyun
394*4882a593Smuzhiyun srm_printk("Starting to load the kernel with args '%s'\n", envval);
395*4882a593Smuzhiyun
396*4882a593Smuzhiyun #ifdef DEBUG_ADDRESSES
397*4882a593Smuzhiyun srm_printk("Decompressing the kernel...\n"
398*4882a593Smuzhiyun "...from 0x%lx to 0x%lx size 0x%x\n",
399*4882a593Smuzhiyun V_DATA_START,
400*4882a593Smuzhiyun uncompressed_image_start,
401*4882a593Smuzhiyun KERNEL_SIZE);
402*4882a593Smuzhiyun #endif
403*4882a593Smuzhiyun decompress_kernel((void *)uncompressed_image_start,
404*4882a593Smuzhiyun (void *)V_DATA_START,
405*4882a593Smuzhiyun KERNEL_SIZE, KERNEL_Z_SIZE);
406*4882a593Smuzhiyun
407*4882a593Smuzhiyun /*
408*4882a593Smuzhiyun * Now, move things to their final positions, if/as required.
409*4882a593Smuzhiyun */
410*4882a593Smuzhiyun
411*4882a593Smuzhiyun #ifdef INITRD_IMAGE_SIZE
412*4882a593Smuzhiyun
413*4882a593Smuzhiyun /* First, we always move the INITRD image, if present. */
414*4882a593Smuzhiyun #ifdef DEBUG_ADDRESSES
415*4882a593Smuzhiyun srm_printk("Moving the INITRD image...\n"
416*4882a593Smuzhiyun " from 0x%lx to 0x%lx size 0x%x\n",
417*4882a593Smuzhiyun V_INITRD_START,
418*4882a593Smuzhiyun initrd_image_start,
419*4882a593Smuzhiyun INITRD_IMAGE_SIZE);
420*4882a593Smuzhiyun #endif
421*4882a593Smuzhiyun memcpy((void *)initrd_image_start, (void *)V_INITRD_START,
422*4882a593Smuzhiyun INITRD_IMAGE_SIZE);
423*4882a593Smuzhiyun
424*4882a593Smuzhiyun #endif /* INITRD_IMAGE_SIZE */
425*4882a593Smuzhiyun
426*4882a593Smuzhiyun /* Next, we may have to move the uncompressed kernel to the
427*4882a593Smuzhiyun final destination.
428*4882a593Smuzhiyun */
429*4882a593Smuzhiyun if (must_move) {
430*4882a593Smuzhiyun #ifdef DEBUG_ADDRESSES
431*4882a593Smuzhiyun srm_printk("Moving the uncompressed kernel...\n"
432*4882a593Smuzhiyun "...from 0x%lx to 0x%lx size 0x%x\n",
433*4882a593Smuzhiyun uncompressed_image_start,
434*4882a593Smuzhiyun K_KERNEL_IMAGE_START,
435*4882a593Smuzhiyun (unsigned)KERNEL_SIZE);
436*4882a593Smuzhiyun #endif
437*4882a593Smuzhiyun /*
438*4882a593Smuzhiyun * Move the stack to a safe place to ensure it won't be
439*4882a593Smuzhiyun * overwritten by kernel image.
440*4882a593Smuzhiyun */
441*4882a593Smuzhiyun move_stack(initrd_image_start - PAGE_SIZE);
442*4882a593Smuzhiyun
443*4882a593Smuzhiyun memcpy((void *)K_KERNEL_IMAGE_START,
444*4882a593Smuzhiyun (void *)uncompressed_image_start, KERNEL_SIZE);
445*4882a593Smuzhiyun }
446*4882a593Smuzhiyun
447*4882a593Smuzhiyun /* Clear the zero page, then move the argument list in. */
448*4882a593Smuzhiyun #ifdef DEBUG_LAST_STEPS
449*4882a593Smuzhiyun srm_printk("Preparing ZERO_PGE...\n");
450*4882a593Smuzhiyun #endif
451*4882a593Smuzhiyun memset((char*)ZERO_PGE, 0, PAGE_SIZE);
452*4882a593Smuzhiyun strcpy((char*)ZERO_PGE, envval);
453*4882a593Smuzhiyun
454*4882a593Smuzhiyun #ifdef INITRD_IMAGE_SIZE
455*4882a593Smuzhiyun
456*4882a593Smuzhiyun #ifdef DEBUG_LAST_STEPS
457*4882a593Smuzhiyun srm_printk("Preparing INITRD info...\n");
458*4882a593Smuzhiyun #endif
459*4882a593Smuzhiyun /* Finally, set the INITRD paramenters for the kernel. */
460*4882a593Smuzhiyun ((long *)(ZERO_PGE+256))[0] = initrd_image_start;
461*4882a593Smuzhiyun ((long *)(ZERO_PGE+256))[1] = INITRD_IMAGE_SIZE;
462*4882a593Smuzhiyun
463*4882a593Smuzhiyun #endif /* INITRD_IMAGE_SIZE */
464*4882a593Smuzhiyun
465*4882a593Smuzhiyun #ifdef DEBUG_LAST_STEPS
466*4882a593Smuzhiyun srm_printk("Doing 'runkernel()'...\n");
467*4882a593Smuzhiyun #endif
468*4882a593Smuzhiyun runkernel();
469*4882a593Smuzhiyun }
470*4882a593Smuzhiyun
471*4882a593Smuzhiyun /* dummy function, should never be called. */
__kmalloc(size_t size,gfp_t flags)472*4882a593Smuzhiyun void *__kmalloc(size_t size, gfp_t flags)
473*4882a593Smuzhiyun {
474*4882a593Smuzhiyun return (void *)NULL;
475*4882a593Smuzhiyun }
476