Import 2.3.9pre5
[davej-history.git] / arch / alpha / boot / bootp.c
blob90fccb766cba8d4ef9c30f05a28b16e9d86ad62c
1 /*
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
9 */
10 #include <linux/kernel.h>
11 #include <linux/string.h>
12 #include <linux/version.h>
13 #include <linux/mm.h>
15 #include <asm/system.h>
16 #include <asm/console.h>
17 #include <asm/hwrpb.h>
18 #include <asm/pgtable.h>
19 #include <asm/io.h>
21 #include <stdarg.h>
23 #include "ksize.h"
25 extern unsigned long switch_to_osf_pal(unsigned long nr,
26 struct pcb_struct * pcb_va, struct pcb_struct * pcb_pa,
27 unsigned long *vptb);
29 struct hwrpb_struct *hwrpb = INIT_HWRPB;
30 static struct pcb_struct pcb_va[1];
33 * Find a physical address of a virtual object..
35 * This is easy using the virtual page table address.
38 static inline void *
39 find_pa(unsigned long *vptb, void *ptr)
41 unsigned long address = (unsigned long) ptr;
42 unsigned long result;
44 result = vptb[address >> 13];
45 result >>= 32;
46 result <<= 13;
47 result |= address & 0x1fff;
48 return (void *) result;
52 * This function moves into OSF/1 pal-code, and has a temporary
53 * PCB for that. The kernel proper should replace this PCB with
54 * the real one as soon as possible.
56 * The page table muckery in here depends on the fact that the boot
57 * code has the L1 page table identity-map itself in the second PTE
58 * in the L1 page table. Thus the L1-page is virtually addressable
59 * itself (through three levels) at virtual address 0x200802000.
62 #define VPTB ((unsigned long *) 0x200000000)
63 #define L1 ((unsigned long *) 0x200802000)
65 void
66 pal_init(void)
68 unsigned long i, rev;
69 struct percpu_struct * percpu;
70 struct pcb_struct * pcb_pa;
72 /* Create the dummy PCB. */
73 pcb_va->ksp = 0;
74 pcb_va->usp = 0;
75 pcb_va->ptbr = L1[1] >> 32;
76 pcb_va->asn = 0;
77 pcb_va->pcc = 0;
78 pcb_va->unique = 0;
79 pcb_va->flags = 1;
80 pcb_va->res1 = 0;
81 pcb_va->res2 = 0;
82 pcb_pa = find_pa(VPTB, pcb_va);
85 * a0 = 2 (OSF)
86 * a1 = return address, but we give the asm the vaddr of the PCB
87 * a2 = physical addr of PCB
88 * a3 = new virtual page table pointer
89 * a4 = KSP (but the asm sets it)
91 srm_printk("Switching to OSF PAL-code .. ");
93 i = switch_to_osf_pal(2, pcb_va, pcb_pa, VPTB);
94 if (i) {
95 srm_printk("failed, code %ld\n", i);
96 halt();
99 percpu = (struct percpu_struct *)
100 (INIT_HWRPB->processor_offset + (unsigned long) INIT_HWRPB);
101 rev = percpu->pal_revision = percpu->palcode_avail[2];
103 srm_printk("Ok (rev %lx)\n", rev);
105 tbia(); /* do it directly in case we are SMP */
108 static inline void
109 load(unsigned long dst, unsigned long src, unsigned long count)
111 memcpy((void *)dst, (void *)src, count);
115 * Start the kernel.
117 static inline void
118 runkernel(void)
120 __asm__ __volatile__(
121 "bis %1,%1,$30\n\t"
122 "bis %0,%0,$27\n\t"
123 "jmp ($27)"
124 : /* no outputs: it doesn't even return */
125 : "r" (START_ADDR),
126 "r" (PAGE_SIZE + INIT_STACK));
129 extern char _end;
130 #define KERNEL_ORIGIN \
131 ((((unsigned long)&_end) + 511) & ~511)
133 void
134 start_kernel(void)
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.
148 static long nbytes;
149 static char envval[256] __attribute__((aligned(8)));
150 #ifdef INITRD_SIZE
151 static unsigned long initrd_start;
152 #endif
154 srm_printk("Linux/AXP bootp loader for Linux " UTS_RELEASE "\n");
155 if (INIT_HWRPB->pagesize != 8192) {
156 srm_printk("Expected 8kB pages, got %ldkB\n",
157 INIT_HWRPB->pagesize >> 10);
158 return;
160 if (INIT_HWRPB->vptb != (unsigned long) VPTB) {
161 srm_printk("Expected vptb at %p, got %p\n",
162 VPTB, (void *)INIT_HWRPB->vptb);
163 return;
165 pal_init();
167 #ifdef INITRD_SIZE
168 /* The initrd must be page-aligned. See below for the
169 cause of the magic number 5. */
170 initrd_start = ((START_ADDR + 5*KERNEL_SIZE) | (PAGE_SIZE-1)) + 1;
171 srm_printk("Initrd positioned at %#lx\n", initrd_start);
172 #endif
174 nbytes = srm_dispatch(CCB_GET_ENV, ENV_BOOTED_OSFLAGS,
175 envval, sizeof(envval));
176 if (nbytes < 0 || nbytes >= sizeof(envval)) {
177 nbytes = 0;
179 envval[nbytes] = '\0';
180 srm_printk("Loading the kernel...'%s'\n", envval);
182 /* NOTE: *no* callbacks or printouts from here on out!!! */
185 * This is a hack, as some consoles seem to get virtual 20000000
186 * (ie where the SRM console puts the kernel bootp image) memory
187 * overlapping physical 310000 memory, which causes real problems
188 * when attempting to copy the former to the latter... :-(
190 * So, we first move the kernel virtual-to-physical way above where
191 * we physically want the kernel to end up, then copy it from there
192 * to its final resting place... ;-}
194 * Sigh...
197 #ifdef INITRD_SIZE
198 load(initrd_start, KERNEL_ORIGIN+KERNEL_SIZE, INITRD_SIZE);
199 #endif
200 load(START_ADDR+(4*KERNEL_SIZE), KERNEL_ORIGIN, KERNEL_SIZE);
201 load(START_ADDR, START_ADDR+(4*KERNEL_SIZE), KERNEL_SIZE);
203 memset((char*)ZERO_PAGE(0), 0, PAGE_SIZE);
204 strcpy((char*)ZERO_PAGE(0), envval);
205 #ifdef INITRD_SIZE
206 ((long *)(ZERO_PAGE(0)+256))[0] = initrd_start;
207 ((long *)(ZERO_PAGE(0)+256))[1] = INITRD_SIZE;
208 #endif
210 runkernel();