2 * arch/alpha/boot/bootp.c
4 * Copyright (C) 1997 Jay Estabrook
6 * This file is used for creating a bootp file for the Linux/AXP kernel
8 * based significantly on the arch/alpha/boot/main.c of Linus Torvalds
10 #include <linux/kernel.h>
11 #include <linux/string.h>
12 #include <linux/utsrelease.h>
15 #include <asm/system.h>
16 #include <asm/console.h>
17 #include <asm/hwrpb.h>
18 #include <asm/pgtable.h>
25 extern unsigned long switch_to_osf_pal(unsigned long nr,
26 struct pcb_struct * pcb_va, struct pcb_struct * pcb_pa,
29 extern void move_stack(unsigned long new_stack);
31 struct hwrpb_struct *hwrpb = INIT_HWRPB;
32 static struct pcb_struct pcb_va[1];
35 * Find a physical address of a virtual object..
37 * This is easy using the virtual page table address.
41 find_pa(unsigned long *vptb, void *ptr)
43 unsigned long address = (unsigned long) ptr;
46 result = vptb[address >> 13];
49 result |= address & 0x1fff;
50 return (void *) result;
54 * This function moves into OSF/1 pal-code, and has a temporary
55 * PCB for that. The kernel proper should replace this PCB with
56 * the real one as soon as possible.
58 * The page table muckery in here depends on the fact that the boot
59 * code has the L1 page table identity-map itself in the second PTE
60 * in the L1 page table. Thus the L1-page is virtually addressable
61 * itself (through three levels) at virtual address 0x200802000.
64 #define VPTB ((unsigned long *) 0x200000000)
65 #define L1 ((unsigned long *) 0x200802000)
71 struct percpu_struct * percpu;
72 struct pcb_struct * pcb_pa;
74 /* Create the dummy PCB. */
77 pcb_va->ptbr = L1[1] >> 32;
84 pcb_pa = find_pa(VPTB, pcb_va);
88 * a1 = return address, but we give the asm the vaddr of the PCB
89 * a2 = physical addr of PCB
90 * a3 = new virtual page table pointer
91 * a4 = KSP (but the asm sets it)
93 srm_printk("Switching to OSF PAL-code .. ");
95 i = switch_to_osf_pal(2, pcb_va, pcb_pa, VPTB);
97 srm_printk("failed, code %ld\n", i);
101 percpu = (struct percpu_struct *)
102 (INIT_HWRPB->processor_offset + (unsigned long) INIT_HWRPB);
103 rev = percpu->pal_revision = percpu->palcode_avail[2];
105 srm_printk("Ok (rev %lx)\n", rev);
107 tbia(); /* do it directly in case we are SMP */
111 load(unsigned long dst, unsigned long src, unsigned long count)
113 memcpy((void *)dst, (void *)src, count);
122 __asm__ __volatile__(
125 : /* no outputs: it doesn't even return */
130 #define KERNEL_ORIGIN \
131 ((((unsigned long)&_end) + 511) & ~511)
137 * Note that this crufty stuff with static and envval
138 * and envbuf is because:
140 * 1. Frequently, the stack is short, and we don't want to overrun;
141 * 2. Frequently the stack is where we are going to copy the kernel to;
142 * 3. A certain SRM console required the GET_ENV output to stack.
143 * ??? A comment in the aboot sources indicates that the GET_ENV
144 * destination must be quadword aligned. Might this explain the
145 * behaviour, rather than requiring output to the stack, which
146 * seems rather far-fetched.
149 static char envval[256] __attribute__((aligned(8)));
150 static unsigned long initrd_start;
152 srm_printk("Linux/AXP bootp loader for Linux " UTS_RELEASE "\n");
153 if (INIT_HWRPB->pagesize != 8192) {
154 srm_printk("Expected 8kB pages, got %ldkB\n",
155 INIT_HWRPB->pagesize >> 10);
158 if (INIT_HWRPB->vptb != (unsigned long) VPTB) {
159 srm_printk("Expected vptb at %p, got %p\n",
160 VPTB, (void *)INIT_HWRPB->vptb);
165 /* The initrd must be page-aligned. See below for the
166 cause of the magic number 5. */
167 initrd_start = ((START_ADDR + 5*KERNEL_SIZE + PAGE_SIZE) |
169 #ifdef INITRD_IMAGE_SIZE
170 srm_printk("Initrd positioned at %#lx\n", initrd_start);
174 * Move the stack to a safe place to ensure it won't be
175 * overwritten by kernel image.
177 move_stack(initrd_start - PAGE_SIZE);
179 nbytes = callback_getenv(ENV_BOOTED_OSFLAGS, envval, sizeof(envval));
180 if (nbytes < 0 || nbytes >= sizeof(envval)) {
183 envval[nbytes] = '\0';
184 srm_printk("Loading the kernel...'%s'\n", envval);
186 /* NOTE: *no* callbacks or printouts from here on out!!! */
188 /* This is a hack, as some consoles seem to get virtual 20000000 (ie
189 * where the SRM console puts the kernel bootp image) memory
190 * overlapping physical memory where the kernel wants to be put,
191 * which causes real problems when attempting to copy the former to
194 * So, we first move the kernel virtual-to-physical way above where
195 * we physically want the kernel to end up, then copy it from there
196 * to its final resting place... ;-}
200 #ifdef INITRD_IMAGE_SIZE
201 load(initrd_start, KERNEL_ORIGIN+KERNEL_SIZE, INITRD_IMAGE_SIZE);
203 load(START_ADDR+(4*KERNEL_SIZE), KERNEL_ORIGIN, KERNEL_SIZE);
204 load(START_ADDR, START_ADDR+(4*KERNEL_SIZE), KERNEL_SIZE);
206 memset((char*)ZERO_PGE, 0, PAGE_SIZE);
207 strcpy((char*)ZERO_PGE, envval);
208 #ifdef INITRD_IMAGE_SIZE
209 ((long *)(ZERO_PGE+256))[0] = initrd_start;
210 ((long *)(ZERO_PGE+256))[1] = INITRD_IMAGE_SIZE;