aboutsummaryrefslogtreecommitdiffstats
path: root/arch/alpha/boot
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /arch/alpha/boot
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'arch/alpha/boot')
-rw-r--r--arch/alpha/boot/Makefile116
-rw-r--r--arch/alpha/boot/bootloader.lds24
-rw-r--r--arch/alpha/boot/bootp.c214
-rw-r--r--arch/alpha/boot/bootpz.c469
-rw-r--r--arch/alpha/boot/head.S123
-rw-r--r--arch/alpha/boot/main.c191
-rw-r--r--arch/alpha/boot/misc.c207
-rw-r--r--arch/alpha/boot/tools/mkbb.c151
-rw-r--r--arch/alpha/boot/tools/objstrip.c281
9 files changed, 1776 insertions, 0 deletions
diff --git a/arch/alpha/boot/Makefile b/arch/alpha/boot/Makefile
new file mode 100644
index 000000000000..e1ae14cd2b4e
--- /dev/null
+++ b/arch/alpha/boot/Makefile
@@ -0,0 +1,116 @@
1#
2# arch/alpha/boot/Makefile
3#
4# This file is subject to the terms and conditions of the GNU General Public
5# License. See the file "COPYING" in the main directory of this archive
6# for more details.
7#
8# Copyright (C) 1994 by Linus Torvalds
9#
10
11hostprogs-y := tools/mkbb tools/objstrip
12targets := vmlinux.gz vmlinux \
13 vmlinux.nh tools/lxboot tools/bootlx tools/bootph \
14 tools/bootpzh bootloader bootpheader bootpzheader
15OBJSTRIP := $(obj)/tools/objstrip
16
17# SRM bootable image. Copy to offset 512 of a partition.
18$(obj)/bootimage: $(addprefix $(obj)/tools/,mkbb lxboot bootlx) $(obj)/vmlinux.nh
19 ( cat $(obj)/tools/lxboot $(obj)/tools/bootlx $(obj)/vmlinux.nh ) > $@
20 $(obj)/tools/mkbb $@ $(obj)/tools/lxboot
21 @echo ' Bootimage $@ is ready'
22
23# BOOTP bootable image. Define INITRD during make to append initrd image.
24$(obj)/bootpfile: $(obj)/tools/bootph $(obj)/vmlinux.nh
25 cat $(obj)/tools/bootph $(obj)/vmlinux.nh > $@
26ifdef INITRD
27 cat $(INITRD) >> $@
28endif
29
30# Compressed kernel BOOTP bootable image.
31# Define INITRD during make to append initrd image.
32$(obj)/bootpzfile: $(obj)/tools/bootpzh $(obj)/vmlinux.nh.gz
33 cat $(obj)/tools/bootpzh $(obj)/vmlinux.nh.gz > $@
34ifdef INITRD
35 cat $(INITRD) >> $@
36endif
37
38# Compressed kernel image
39$(obj)/vmlinux.gz: $(obj)/vmlinux FORCE
40 $(call if_changed,gzip)
41 @echo ' Kernel $@ is ready'
42
43$(obj)/main.o: $(obj)/ksize.h
44$(obj)/bootp.o: $(obj)/ksize.h
45$(obj)/bootpz.o: $(obj)/kzsize.h
46
47$(obj)/ksize.h: $(obj)/vmlinux.nh FORCE
48 echo "#define KERNEL_SIZE `ls -l $(obj)/vmlinux.nh | awk '{print $$5}'`" > $@T
49ifdef INITRD
50 [ -f $(INITRD) ] || exit 1
51 echo "#define INITRD_IMAGE_SIZE `ls -l $(INITRD) | awk '{print $$5}'`" >> $@T
52endif
53 cmp -s $@T $@ || mv -f $@T $@
54 rm -f $@T
55
56$(obj)/kzsize.h: $(obj)/vmlinux.nh.gz FORCE
57 echo "#define KERNEL_SIZE `ls -l $(obj)/vmlinux.nh | awk '{print $$5}'`" > $@T
58 echo "#define KERNEL_Z_SIZE `ls -l $(obj)/vmlinux.nh.gz | awk '{print $$5}'`" >> $@T
59ifdef INITRD
60 [ -f $(INITRD) ] || exit 1
61 echo "#define INITRD_IMAGE_SIZE `ls -l $(INITRD) | awk '{print $$5}'`" >> $@T
62endif
63 cmp -s $@T $@ || mv -f $@T $@
64 rm -f $@T
65
66quiet_cmd_strip = STRIP $@
67 cmd_strip = $(STRIP) -o $@ $<
68
69$(obj)/vmlinux: vmlinux FORCE
70 $(call if_changed,strip)
71
72quiet_cmd_objstrip = OBJSTRIP $@
73 cmd_objstrip = $(OBJSTRIP) $(OSFLAGS_$(@F)) $< $@
74
75OSFLAGS_vmlinux.nh := -v
76OSFLAGS_lxboot := -p
77OSFLAGS_bootlx := -vb
78OSFLAGS_bootph := -vb
79OSFLAGS_bootpzh := -vb
80
81$(obj)/vmlinux.nh: vmlinux $(OBJSTRIP) FORCE
82 $(call if_changed,objstrip)
83
84$(obj)/vmlinux.nh.gz: $(obj)/vmlinux.nh FORCE
85 $(call if_changed,gzip)
86
87$(obj)/tools/lxboot: $(obj)/bootloader $(OBJSTRIP) FORCE
88 $(call if_changed,objstrip)
89
90$(obj)/tools/bootlx: $(obj)/bootloader $(OBJSTRIP) FORCE
91 $(call if_changed,objstrip)
92
93$(obj)/tools/bootph: $(obj)/bootpheader $(OBJSTRIP) FORCE
94 $(call if_changed,objstrip)
95
96$(obj)/tools/bootpzh: $(obj)/bootpzheader $(OBJSTRIP) FORCE
97 $(call if_changed,objstrip)
98
99LDFLAGS_bootloader := -static -uvsprintf -T #-N -relax
100LDFLAGS_bootpheader := -static -uvsprintf -T #-N -relax
101LDFLAGS_bootpzheader := -static -uvsprintf -T #-N -relax
102
103OBJ_bootlx := $(obj)/head.o $(obj)/main.o
104OBJ_bootph := $(obj)/head.o $(obj)/bootp.o
105OBJ_bootpzh := $(obj)/head.o $(obj)/bootpz.o $(obj)/misc.o
106
107$(obj)/bootloader: $(obj)/bootloader.lds $(OBJ_bootlx) FORCE
108 $(call if_changed,ld)
109
110$(obj)/bootpheader: $(obj)/bootloader.lds $(OBJ_bootph) $(LIBS_Y) FORCE
111 $(call if_changed,ld)
112
113$(obj)/bootpzheader: $(obj)/bootloader.lds $(OBJ_bootpzh) $(LIBS_Y) FORCE
114 $(call if_changed,ld)
115
116$(obj)/misc.o: lib/inflate.c
diff --git a/arch/alpha/boot/bootloader.lds b/arch/alpha/boot/bootloader.lds
new file mode 100644
index 000000000000..31c081ce1d50
--- /dev/null
+++ b/arch/alpha/boot/bootloader.lds
@@ -0,0 +1,24 @@
1OUTPUT_FORMAT("elf64-alpha")
2ENTRY(__start)
3printk = srm_printk;
4SECTIONS
5{
6 . = 0x20000000;
7 .text : { *(.text) }
8 _etext = .;
9 PROVIDE (etext = .);
10 .rodata : { *(.rodata) *(.rodata.*) }
11 .data : { *(.data) CONSTRUCTORS }
12 .got : { *(.got) }
13 .sdata : { *(.sdata) }
14 _edata = .;
15 PROVIDE (edata = .);
16 .sbss : { *(.sbss) *(.scommon) }
17 .bss : { *(.bss) *(COMMON) }
18 _end = . ;
19 PROVIDE (end = .);
20
21 .mdebug 0 : { *(.mdebug) }
22 .note 0 : { *(.note) }
23 .comment 0 : { *(.comment) }
24}
diff --git a/arch/alpha/boot/bootp.c b/arch/alpha/boot/bootp.c
new file mode 100644
index 000000000000..ec53c28e33de
--- /dev/null
+++ b/arch/alpha/boot/bootp.c
@@ -0,0 +1,214 @@
1/*
2 * arch/alpha/boot/bootp.c
3 *
4 * Copyright (C) 1997 Jay Estabrook
5 *
6 * This file is used for creating a bootp file for the Linux/AXP kernel
7 *
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>
14
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>
20
21#include <stdarg.h>
22
23#include "ksize.h"
24
25extern unsigned long switch_to_osf_pal(unsigned long nr,
26 struct pcb_struct * pcb_va, struct pcb_struct * pcb_pa,
27 unsigned long *vptb);
28
29extern void move_stack(unsigned long new_stack);
30
31struct hwrpb_struct *hwrpb = INIT_HWRPB;
32static struct pcb_struct pcb_va[1];
33
34/*
35 * Find a physical address of a virtual object..
36 *
37 * This is easy using the virtual page table address.
38 */
39
40static inline void *
41find_pa(unsigned long *vptb, void *ptr)
42{
43 unsigned long address = (unsigned long) ptr;
44 unsigned long result;
45
46 result = vptb[address >> 13];
47 result >>= 32;
48 result <<= 13;
49 result |= address & 0x1fff;
50 return (void *) result;
51}
52
53/*
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.
57 *
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.
62 */
63
64#define VPTB ((unsigned long *) 0x200000000)
65#define L1 ((unsigned long *) 0x200802000)
66
67void
68pal_init(void)
69{
70 unsigned long i, rev;
71 struct percpu_struct * percpu;
72 struct pcb_struct * pcb_pa;
73
74 /* Create the dummy PCB. */
75 pcb_va->ksp = 0;
76 pcb_va->usp = 0;
77 pcb_va->ptbr = L1[1] >> 32;
78 pcb_va->asn = 0;
79 pcb_va->pcc = 0;
80 pcb_va->unique = 0;
81 pcb_va->flags = 1;
82 pcb_va->res1 = 0;
83 pcb_va->res2 = 0;
84 pcb_pa = find_pa(VPTB, pcb_va);
85
86 /*
87 * a0 = 2 (OSF)
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)
92 */
93 srm_printk("Switching to OSF PAL-code .. ");
94
95 i = switch_to_osf_pal(2, pcb_va, pcb_pa, VPTB);
96 if (i) {
97 srm_printk("failed, code %ld\n", i);
98 __halt();
99 }
100
101 percpu = (struct percpu_struct *)
102 (INIT_HWRPB->processor_offset + (unsigned long) INIT_HWRPB);
103 rev = percpu->pal_revision = percpu->palcode_avail[2];
104
105 srm_printk("Ok (rev %lx)\n", rev);
106
107 tbia(); /* do it directly in case we are SMP */
108}
109
110static inline void
111load(unsigned long dst, unsigned long src, unsigned long count)
112{
113 memcpy((void *)dst, (void *)src, count);
114}
115
116/*
117 * Start the kernel.
118 */
119static inline void
120runkernel(void)
121{
122 __asm__ __volatile__(
123 "bis %0,%0,$27\n\t"
124 "jmp ($27)"
125 : /* no outputs: it doesn't even return */
126 : "r" (START_ADDR));
127}
128
129extern char _end;
130#define KERNEL_ORIGIN \
131 ((((unsigned long)&_end) + 511) & ~511)
132
133void
134start_kernel(void)
135{
136 /*
137 * Note that this crufty stuff with static and envval
138 * and envbuf is because:
139 *
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.
147 */
148 static long nbytes;
149 static char envval[256] __attribute__((aligned(8)));
150 static unsigned long initrd_start;
151
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);
156 return;
157 }
158 if (INIT_HWRPB->vptb != (unsigned long) VPTB) {
159 srm_printk("Expected vptb at %p, got %p\n",
160 VPTB, (void *)INIT_HWRPB->vptb);
161 return;
162 }
163 pal_init();
164
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) |
168 (PAGE_SIZE-1)) + 1;
169#ifdef INITRD_IMAGE_SIZE
170 srm_printk("Initrd positioned at %#lx\n", initrd_start);
171#endif
172
173 /*
174 * Move the stack to a safe place to ensure it won't be
175 * overwritten by kernel image.
176 */
177 move_stack(initrd_start - PAGE_SIZE);
178
179 nbytes = callback_getenv(ENV_BOOTED_OSFLAGS, envval, sizeof(envval));
180 if (nbytes < 0 || nbytes >= sizeof(envval)) {
181 nbytes = 0;
182 }
183 envval[nbytes] = '\0';
184 srm_printk("Loading the kernel...'%s'\n", envval);
185
186 /* NOTE: *no* callbacks or printouts from here on out!!! */
187
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
192 * the latter... :-(
193 *
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... ;-}
197 *
198 * Sigh... */
199
200#ifdef INITRD_IMAGE_SIZE
201 load(initrd_start, KERNEL_ORIGIN+KERNEL_SIZE, INITRD_IMAGE_SIZE);
202#endif
203 load(START_ADDR+(4*KERNEL_SIZE), KERNEL_ORIGIN, KERNEL_SIZE);
204 load(START_ADDR, START_ADDR+(4*KERNEL_SIZE), KERNEL_SIZE);
205
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;
211#endif
212
213 runkernel();
214}
diff --git a/arch/alpha/boot/bootpz.c b/arch/alpha/boot/bootpz.c
new file mode 100644
index 000000000000..a6657f2cf9bd
--- /dev/null
+++ b/arch/alpha/boot/bootpz.c
@@ -0,0 +1,469 @@
1/*
2 * arch/alpha/boot/bootpz.c
3 *
4 * Copyright (C) 1997 Jay Estabrook
5 *
6 * This file is used for creating a compressed BOOTP file for the
7 * Linux/AXP kernel
8 *
9 * based significantly on the arch/alpha/boot/main.c of Linus Torvalds
10 * and the decompression code from MILO.
11 */
12#include <linux/kernel.h>
13#include <linux/string.h>
14#include <linux/version.h>
15#include <linux/mm.h>
16
17#include <asm/system.h>
18#include <asm/console.h>
19#include <asm/hwrpb.h>
20#include <asm/pgtable.h>
21#include <asm/io.h>
22
23#include <stdarg.h>
24
25#include "kzsize.h"
26
27/* FIXME FIXME FIXME */
28#define MALLOC_AREA_SIZE 0x200000 /* 2MB for now */
29/* FIXME FIXME FIXME */
30
31
32/*
33 WARNING NOTE
34
35 It is very possible that turning on additional messages may cause
36 kernel image corruption due to stack usage to do the printing.
37
38*/
39
40#undef DEBUG_CHECK_RANGE
41#undef DEBUG_ADDRESSES
42#undef DEBUG_LAST_STEPS
43
44extern unsigned long switch_to_osf_pal(unsigned long nr,
45 struct pcb_struct * pcb_va, struct pcb_struct * pcb_pa,
46 unsigned long *vptb);
47
48extern int decompress_kernel(void* destination, void *source,
49 size_t ksize, size_t kzsize);
50
51extern void move_stack(unsigned long new_stack);
52
53struct hwrpb_struct *hwrpb = INIT_HWRPB;
54static struct pcb_struct pcb_va[1];
55
56/*
57 * Find a physical address of a virtual object..
58 *
59 * This is easy using the virtual page table address.
60 */
61#define VPTB ((unsigned long *) 0x200000000)
62
63static inline unsigned long
64find_pa(unsigned long address)
65{
66 unsigned long result;
67
68 result = VPTB[address >> 13];
69 result >>= 32;
70 result <<= 13;
71 result |= address & 0x1fff;
72 return result;
73}
74
75int
76check_range(unsigned long vstart, unsigned long vend,
77 unsigned long kstart, unsigned long kend)
78{
79 unsigned long vaddr, kaddr;
80
81#ifdef DEBUG_CHECK_RANGE
82 srm_printk("check_range: V[0x%lx:0x%lx] K[0x%lx:0x%lx]\n",
83 vstart, vend, kstart, kend);
84#endif
85 /* do some range checking for detecting an overlap... */
86 for (vaddr = vstart; vaddr <= vend; vaddr += PAGE_SIZE)
87 {
88 kaddr = (find_pa(vaddr) | PAGE_OFFSET);
89 if (kaddr >= kstart && kaddr <= kend)
90 {
91#ifdef DEBUG_CHECK_RANGE
92 srm_printk("OVERLAP: vaddr 0x%lx kaddr 0x%lx"
93 " [0x%lx:0x%lx]\n",
94 vaddr, kaddr, kstart, kend);
95#endif
96 return 1;
97 }
98 }
99 return 0;
100}
101
102/*
103 * This function moves into OSF/1 pal-code, and has a temporary
104 * PCB for that. The kernel proper should replace this PCB with
105 * the real one as soon as possible.
106 *
107 * The page table muckery in here depends on the fact that the boot
108 * code has the L1 page table identity-map itself in the second PTE
109 * in the L1 page table. Thus the L1-page is virtually addressable
110 * itself (through three levels) at virtual address 0x200802000.
111 */
112
113#define L1 ((unsigned long *) 0x200802000)
114
115void
116pal_init(void)
117{
118 unsigned long i, rev;
119 struct percpu_struct * percpu;
120 struct pcb_struct * pcb_pa;
121
122 /* Create the dummy PCB. */
123 pcb_va->ksp = 0;
124 pcb_va->usp = 0;
125 pcb_va->ptbr = L1[1] >> 32;
126 pcb_va->asn = 0;
127 pcb_va->pcc = 0;
128 pcb_va->unique = 0;
129 pcb_va->flags = 1;
130 pcb_va->res1 = 0;
131 pcb_va->res2 = 0;
132 pcb_pa = (struct pcb_struct *)find_pa((unsigned long)pcb_va);
133
134 /*
135 * a0 = 2 (OSF)
136 * a1 = return address, but we give the asm the vaddr of the PCB
137 * a2 = physical addr of PCB
138 * a3 = new virtual page table pointer
139 * a4 = KSP (but the asm sets it)
140 */
141 srm_printk("Switching to OSF PAL-code... ");
142
143 i = switch_to_osf_pal(2, pcb_va, pcb_pa, VPTB);
144 if (i) {
145 srm_printk("failed, code %ld\n", i);
146 __halt();
147 }
148
149 percpu = (struct percpu_struct *)
150 (INIT_HWRPB->processor_offset + (unsigned long) INIT_HWRPB);
151 rev = percpu->pal_revision = percpu->palcode_avail[2];
152
153 srm_printk("OK (rev %lx)\n", rev);
154
155 tbia(); /* do it directly in case we are SMP */
156}
157
158/*
159 * Start the kernel.
160 */
161static inline void
162runkernel(void)
163{
164 __asm__ __volatile__(
165 "bis %0,%0,$27\n\t"
166 "jmp ($27)"
167 : /* no outputs: it doesn't even return */
168 : "r" (START_ADDR));
169}
170
171/* Must record the SP (it is virtual) on entry, so we can make sure
172 not to overwrite it during movement or decompression. */
173unsigned long SP_on_entry;
174
175/* Calculate the kernel image address based on the end of the BOOTP
176 bootstrapper (ie this program).
177*/
178extern char _end;
179#define KERNEL_ORIGIN \
180 ((((unsigned long)&_end) + 511) & ~511)
181
182/* Round address to next higher page boundary. */
183#define NEXT_PAGE(a) (((a) | (PAGE_SIZE - 1)) + 1)
184
185#ifdef INITRD_IMAGE_SIZE
186# define REAL_INITRD_SIZE INITRD_IMAGE_SIZE
187#else
188# define REAL_INITRD_SIZE 0
189#endif
190
191/* Defines from include/asm-alpha/system.h
192
193 BOOT_ADDR Virtual address at which the consoles loads
194 the BOOTP image.
195
196 KERNEL_START KSEG address at which the kernel is built to run,
197 which includes some initial data pages before the
198 code.
199
200 START_ADDR KSEG address of the entry point of kernel code.
201
202 ZERO_PGE KSEG address of page full of zeroes, but
203 upon entry to kerne cvan be expected
204 to hold the parameter list and possible
205 INTRD information.
206
207 These are used in the local defines below.
208*/
209
210
211/* Virtual addresses for the BOOTP image. Note that this includes the
212 bootstrapper code as well as the compressed kernel image, and
213 possibly the INITRD image.
214
215 Oh, and do NOT forget the STACK, which appears to be placed virtually
216 beyond the end of the loaded image.
217*/
218#define V_BOOT_IMAGE_START BOOT_ADDR
219#define V_BOOT_IMAGE_END SP_on_entry
220
221/* Virtual addresses for just the bootstrapper part of the BOOTP image. */
222#define V_BOOTSTRAPPER_START BOOT_ADDR
223#define V_BOOTSTRAPPER_END KERNEL_ORIGIN
224
225/* Virtual addresses for just the data part of the BOOTP
226 image. This may also include the INITRD image, but always
227 includes the STACK.
228*/
229#define V_DATA_START KERNEL_ORIGIN
230#define V_INITRD_START (KERNEL_ORIGIN + KERNEL_Z_SIZE)
231#define V_INTRD_END (V_INITRD_START + REAL_INITRD_SIZE)
232#define V_DATA_END V_BOOT_IMAGE_END
233
234/* KSEG addresses for the uncompressed kernel.
235
236 Note that the end address includes workspace for the decompression.
237 Note also that the DATA_START address is ZERO_PGE, to which we write
238 just before jumping to the kernel image at START_ADDR.
239 */
240#define K_KERNEL_DATA_START ZERO_PGE
241#define K_KERNEL_IMAGE_START START_ADDR
242#define K_KERNEL_IMAGE_END (START_ADDR + KERNEL_SIZE)
243
244/* Define to where we may have to decompress the kernel image, before
245 we move it to the final position, in case of overlap. This will be
246 above the final position of the kernel.
247
248 Regardless of overlap, we move the INITRD image to the end of this
249 copy area, because there needs to be a buffer area after the kernel
250 for "bootmem" anyway.
251*/
252#define K_COPY_IMAGE_START NEXT_PAGE(K_KERNEL_IMAGE_END)
253/* Reserve one page below INITRD for the new stack. */
254#define K_INITRD_START \
255 NEXT_PAGE(K_COPY_IMAGE_START + KERNEL_SIZE + PAGE_SIZE)
256#define K_COPY_IMAGE_END \
257 (K_INITRD_START + REAL_INITRD_SIZE + MALLOC_AREA_SIZE)
258#define K_COPY_IMAGE_SIZE \
259 NEXT_PAGE(K_COPY_IMAGE_END - K_COPY_IMAGE_START)
260
261void
262start_kernel(void)
263{
264 int must_move = 0;
265
266 /* Initialize these for the decompression-in-place situation,
267 which is the smallest amount of work and most likely to
268 occur when using the normal START_ADDR of the kernel
269 (currently set to 16MB, to clear all console code.
270 */
271 unsigned long uncompressed_image_start = K_KERNEL_IMAGE_START;
272 unsigned long uncompressed_image_end = K_KERNEL_IMAGE_END;
273
274 unsigned long initrd_image_start = K_INITRD_START;
275
276 /*
277 * Note that this crufty stuff with static and envval
278 * and envbuf is because:
279 *
280 * 1. Frequently, the stack is short, and we don't want to overrun;
281 * 2. Frequently the stack is where we are going to copy the kernel to;
282 * 3. A certain SRM console required the GET_ENV output to stack.
283 * ??? A comment in the aboot sources indicates that the GET_ENV
284 * destination must be quadword aligned. Might this explain the
285 * behaviour, rather than requiring output to the stack, which
286 * seems rather far-fetched.
287 */
288 static long nbytes;
289 static char envval[256] __attribute__((aligned(8)));
290 register unsigned long asm_sp asm("30");
291
292 SP_on_entry = asm_sp;
293
294 srm_printk("Linux/Alpha BOOTPZ Loader for Linux " UTS_RELEASE "\n");
295
296 /* Validity check the HWRPB. */
297 if (INIT_HWRPB->pagesize != 8192) {
298 srm_printk("Expected 8kB pages, got %ldkB\n",
299 INIT_HWRPB->pagesize >> 10);
300 return;
301 }
302 if (INIT_HWRPB->vptb != (unsigned long) VPTB) {
303 srm_printk("Expected vptb at %p, got %p\n",
304 VPTB, (void *)INIT_HWRPB->vptb);
305 return;
306 }
307
308 /* PALcode (re)initialization. */
309 pal_init();
310
311 /* Get the parameter list from the console environment variable. */
312 nbytes = callback_getenv(ENV_BOOTED_OSFLAGS, envval, sizeof(envval));
313 if (nbytes < 0 || nbytes >= sizeof(envval)) {
314 nbytes = 0;
315 }
316 envval[nbytes] = '\0';
317
318#ifdef DEBUG_ADDRESSES
319 srm_printk("START_ADDR 0x%lx\n", START_ADDR);
320 srm_printk("KERNEL_ORIGIN 0x%lx\n", KERNEL_ORIGIN);
321 srm_printk("KERNEL_SIZE 0x%x\n", KERNEL_SIZE);
322 srm_printk("KERNEL_Z_SIZE 0x%x\n", KERNEL_Z_SIZE);
323#endif
324
325 /* Since all the SRM consoles load the BOOTP image at virtual
326 * 0x20000000, we have to ensure that the physical memory
327 * pages occupied by that image do NOT overlap the physical
328 * address range where the kernel wants to be run. This
329 * causes real problems when attempting to cdecompress the
330 * former into the latter... :-(
331 *
332 * So, we may have to decompress/move the kernel/INITRD image
333 * virtual-to-physical someplace else first before moving
334 * kernel /INITRD to their final resting places... ;-}
335 *
336 * Sigh...
337 */
338
339 /* First, check to see if the range of addresses occupied by
340 the bootstrapper part of the BOOTP image include any of the
341 physical pages into which the kernel will be placed for
342 execution.
343
344 We only need check on the final kernel image range, since we
345 will put the INITRD someplace that we can be sure is not
346 in conflict.
347 */
348 if (check_range(V_BOOTSTRAPPER_START, V_BOOTSTRAPPER_END,
349 K_KERNEL_DATA_START, K_KERNEL_IMAGE_END))
350 {
351 srm_printk("FATAL ERROR: overlap of bootstrapper code\n");
352 __halt();
353 }
354
355 /* Next, check to see if the range of addresses occupied by
356 the compressed kernel/INITRD/stack portion of the BOOTP
357 image include any of the physical pages into which the
358 decompressed kernel or the INITRD will be placed for
359 execution.
360 */
361 if (check_range(V_DATA_START, V_DATA_END,
362 K_KERNEL_IMAGE_START, K_COPY_IMAGE_END))
363 {
364#ifdef DEBUG_ADDRESSES
365 srm_printk("OVERLAP: cannot decompress in place\n");
366#endif
367 uncompressed_image_start = K_COPY_IMAGE_START;
368 uncompressed_image_end = K_COPY_IMAGE_END;
369 must_move = 1;
370
371 /* Finally, check to see if the range of addresses
372 occupied by the compressed kernel/INITRD part of
373 the BOOTP image include any of the physical pages
374 into which that part is to be copied for
375 decompression.
376 */
377 while (check_range(V_DATA_START, V_DATA_END,
378 uncompressed_image_start,
379 uncompressed_image_end))
380 {
381#if 0
382 uncompressed_image_start += K_COPY_IMAGE_SIZE;
383 uncompressed_image_end += K_COPY_IMAGE_SIZE;
384 initrd_image_start += K_COPY_IMAGE_SIZE;
385#else
386 /* Keep as close as possible to end of BOOTP image. */
387 uncompressed_image_start += PAGE_SIZE;
388 uncompressed_image_end += PAGE_SIZE;
389 initrd_image_start += PAGE_SIZE;
390#endif
391 }
392 }
393
394 srm_printk("Starting to load the kernel with args '%s'\n", envval);
395
396#ifdef DEBUG_ADDRESSES
397 srm_printk("Decompressing the kernel...\n"
398 "...from 0x%lx to 0x%lx size 0x%x\n",
399 V_DATA_START,
400 uncompressed_image_start,
401 KERNEL_SIZE);
402#endif
403 decompress_kernel((void *)uncompressed_image_start,
404 (void *)V_DATA_START,
405 KERNEL_SIZE, KERNEL_Z_SIZE);
406
407 /*
408 * Now, move things to their final positions, if/as required.
409 */
410
411#ifdef INITRD_IMAGE_SIZE
412
413 /* First, we always move the INITRD image, if present. */
414#ifdef DEBUG_ADDRESSES
415 srm_printk("Moving the INITRD image...\n"
416 " from 0x%lx to 0x%lx size 0x%x\n",
417 V_INITRD_START,
418 initrd_image_start,
419 INITRD_IMAGE_SIZE);
420#endif
421 memcpy((void *)initrd_image_start, (void *)V_INITRD_START,
422 INITRD_IMAGE_SIZE);
423
424#endif /* INITRD_IMAGE_SIZE */
425
426 /* Next, we may have to move the uncompressed kernel to the
427 final destination.
428 */
429 if (must_move) {
430#ifdef DEBUG_ADDRESSES
431 srm_printk("Moving the uncompressed kernel...\n"
432 "...from 0x%lx to 0x%lx size 0x%x\n",
433 uncompressed_image_start,
434 K_KERNEL_IMAGE_START,
435 (unsigned)KERNEL_SIZE);
436#endif
437 /*
438 * Move the stack to a safe place to ensure it won't be
439 * overwritten by kernel image.
440 */
441 move_stack(initrd_image_start - PAGE_SIZE);
442
443 memcpy((void *)K_KERNEL_IMAGE_START,
444 (void *)uncompressed_image_start, KERNEL_SIZE);
445 }
446
447 /* Clear the zero page, then move the argument list in. */
448#ifdef DEBUG_LAST_STEPS
449 srm_printk("Preparing ZERO_PGE...\n");
450#endif
451 memset((char*)ZERO_PGE, 0, PAGE_SIZE);
452 strcpy((char*)ZERO_PGE, envval);
453
454#ifdef INITRD_IMAGE_SIZE
455
456#ifdef DEBUG_LAST_STEPS
457 srm_printk("Preparing INITRD info...\n");
458#endif
459 /* Finally, set the INITRD paramenters for the kernel. */
460 ((long *)(ZERO_PGE+256))[0] = initrd_image_start;
461 ((long *)(ZERO_PGE+256))[1] = INITRD_IMAGE_SIZE;
462
463#endif /* INITRD_IMAGE_SIZE */
464
465#ifdef DEBUG_LAST_STEPS
466 srm_printk("Doing 'runkernel()'...\n");
467#endif
468 runkernel();
469}
diff --git a/arch/alpha/boot/head.S b/arch/alpha/boot/head.S
new file mode 100644
index 000000000000..f3d98089b3dc
--- /dev/null
+++ b/arch/alpha/boot/head.S
@@ -0,0 +1,123 @@
1/*
2 * arch/alpha/boot/head.S
3 *
4 * initial bootloader stuff..
5 */
6
7#include <asm/system.h>
8
9 .set noreorder
10 .globl __start
11 .ent __start
12__start:
13 br $29,2f
142: ldgp $29,0($29)
15 jsr $26,start_kernel
16 call_pal PAL_halt
17 .end __start
18
19 .align 5
20 .globl wrent
21 .ent wrent
22wrent:
23 .prologue 0
24 call_pal PAL_wrent
25 ret ($26)
26 .end wrent
27
28 .align 5
29 .globl wrkgp
30 .ent wrkgp
31wrkgp:
32 .prologue 0
33 call_pal PAL_wrkgp
34 ret ($26)
35 .end wrkgp
36
37 .align 5
38 .globl switch_to_osf_pal
39 .ent switch_to_osf_pal
40switch_to_osf_pal:
41 subq $30,128,$30
42 .frame $30,128,$26
43 stq $26,0($30)
44 stq $1,8($30)
45 stq $2,16($30)
46 stq $3,24($30)
47 stq $4,32($30)
48 stq $5,40($30)
49 stq $6,48($30)
50 stq $7,56($30)
51 stq $8,64($30)
52 stq $9,72($30)
53 stq $10,80($30)
54 stq $11,88($30)
55 stq $12,96($30)
56 stq $13,104($30)
57 stq $14,112($30)
58 stq $15,120($30)
59 .prologue 0
60
61 stq $30,0($17) /* save KSP in PCB */
62
63 bis $30,$30,$20 /* a4 = KSP */
64 br $17,1f
65
66 ldq $26,0($30)
67 ldq $1,8($30)
68 ldq $2,16($30)
69 ldq $3,24($30)
70 ldq $4,32($30)
71 ldq $5,40($30)
72 ldq $6,48($30)
73 ldq $7,56($30)
74 ldq $8,64($30)
75 ldq $9,72($30)
76 ldq $10,80($30)
77 ldq $11,88($30)
78 ldq $12,96($30)
79 ldq $13,104($30)
80 ldq $14,112($30)
81 ldq $15,120($30)
82 addq $30,128,$30
83 ret ($26)
841: call_pal PAL_swppal
85 .end switch_to_osf_pal
86
87 .align 3
88 .globl tbi
89 .ent tbi
90tbi:
91 .prologue 0
92 call_pal PAL_tbi
93 ret ($26)
94 .end tbi
95
96 .align 3
97 .globl halt
98 .ent halt
99halt:
100 .prologue 0
101 call_pal PAL_halt
102 .end halt
103
104/* $16 - new stack page */
105 .align 3
106 .globl move_stack
107 .ent move_stack
108move_stack:
109 .prologue 0
110 lda $0, 0x1fff($31)
111 and $0, $30, $1 /* Stack offset */
112 or $1, $16, $16 /* New stack pointer */
113 mov $30, $1
114 mov $16, $2
1151: ldq $3, 0($1) /* Move the stack */
116 addq $1, 8, $1
117 stq $3, 0($2)
118 and $0, $1, $4
119 addq $2, 8, $2
120 bne $4, 1b
121 mov $16, $30
122 ret ($26)
123 .end move_stack
diff --git a/arch/alpha/boot/main.c b/arch/alpha/boot/main.c
new file mode 100644
index 000000000000..78c9b0b6eea7
--- /dev/null
+++ b/arch/alpha/boot/main.c
@@ -0,0 +1,191 @@
1/*
2 * arch/alpha/boot/main.c
3 *
4 * Copyright (C) 1994, 1995 Linus Torvalds
5 *
6 * This file is the bootloader for the Linux/AXP kernel
7 */
8#include <linux/kernel.h>
9#include <linux/string.h>
10#include <linux/version.h>
11#include <linux/mm.h>
12
13#include <asm/system.h>
14#include <asm/console.h>
15#include <asm/hwrpb.h>
16#include <asm/pgtable.h>
17
18#include <stdarg.h>
19
20#include "ksize.h"
21
22extern int vsprintf(char *, const char *, va_list);
23extern unsigned long switch_to_osf_pal(unsigned long nr,
24 struct pcb_struct * pcb_va, struct pcb_struct * pcb_pa,
25 unsigned long *vptb);
26struct hwrpb_struct *hwrpb = INIT_HWRPB;
27static struct pcb_struct pcb_va[1];
28
29/*
30 * Find a physical address of a virtual object..
31 *
32 * This is easy using the virtual page table address.
33 */
34
35static inline void *
36find_pa(unsigned long *vptb, void *ptr)
37{
38 unsigned long address = (unsigned long) ptr;
39 unsigned long result;
40
41 result = vptb[address >> 13];
42 result >>= 32;
43 result <<= 13;
44 result |= address & 0x1fff;
45 return (void *) result;
46}
47
48/*
49 * This function moves into OSF/1 pal-code, and has a temporary
50 * PCB for that. The kernel proper should replace this PCB with
51 * the real one as soon as possible.
52 *
53 * The page table muckery in here depends on the fact that the boot
54 * code has the L1 page table identity-map itself in the second PTE
55 * in the L1 page table. Thus the L1-page is virtually addressable
56 * itself (through three levels) at virtual address 0x200802000.
57 */
58
59#define VPTB ((unsigned long *) 0x200000000)
60#define L1 ((unsigned long *) 0x200802000)
61
62void
63pal_init(void)
64{
65 unsigned long i, rev;
66 struct percpu_struct * percpu;
67 struct pcb_struct * pcb_pa;
68
69 /* Create the dummy PCB. */
70 pcb_va->ksp = 0;
71 pcb_va->usp = 0;
72 pcb_va->ptbr = L1[1] >> 32;
73 pcb_va->asn = 0;
74 pcb_va->pcc = 0;
75 pcb_va->unique = 0;
76 pcb_va->flags = 1;
77 pcb_va->res1 = 0;
78 pcb_va->res2 = 0;
79 pcb_pa = find_pa(VPTB, pcb_va);
80
81 /*
82 * a0 = 2 (OSF)
83 * a1 = return address, but we give the asm the vaddr of the PCB
84 * a2 = physical addr of PCB
85 * a3 = new virtual page table pointer
86 * a4 = KSP (but the asm sets it)
87 */
88 srm_printk("Switching to OSF PAL-code .. ");
89
90 i = switch_to_osf_pal(2, pcb_va, pcb_pa, VPTB);
91 if (i) {
92 srm_printk("failed, code %ld\n", i);
93 __halt();
94 }
95
96 percpu = (struct percpu_struct *)
97 (INIT_HWRPB->processor_offset + (unsigned long) INIT_HWRPB);
98 rev = percpu->pal_revision = percpu->palcode_avail[2];
99
100 srm_printk("Ok (rev %lx)\n", rev);
101
102 tbia(); /* do it directly in case we are SMP */
103}
104
105static inline long openboot(void)
106{
107 char bootdev[256];
108 long result;
109
110 result = callback_getenv(ENV_BOOTED_DEV, bootdev, 255);
111 if (result < 0)
112 return result;
113 return callback_open(bootdev, result & 255);
114}
115
116static inline long close(long dev)
117{
118 return callback_close(dev);
119}
120
121static inline long load(long dev, unsigned long addr, unsigned long count)
122{
123 char bootfile[256];
124 extern char _end;
125 long result, boot_size = &_end - (char *) BOOT_ADDR;
126
127 result = callback_getenv(ENV_BOOTED_FILE, bootfile, 255);
128 if (result < 0)
129 return result;
130 result &= 255;
131 bootfile[result] = '\0';
132 if (result)
133 srm_printk("Boot file specification (%s) not implemented\n",
134 bootfile);
135 return callback_read(dev, count, addr, boot_size/512 + 1);
136}
137
138/*
139 * Start the kernel.
140 */
141static void runkernel(void)
142{
143 __asm__ __volatile__(
144 "bis %1,%1,$30\n\t"
145 "bis %0,%0,$26\n\t"
146 "ret ($26)"
147 : /* no outputs: it doesn't even return */
148 : "r" (START_ADDR),
149 "r" (PAGE_SIZE + INIT_STACK));
150}
151
152void start_kernel(void)
153{
154 long i;
155 long dev;
156 int nbytes;
157 char envval[256];
158
159 srm_printk("Linux/AXP bootloader for Linux " UTS_RELEASE "\n");
160 if (INIT_HWRPB->pagesize != 8192) {
161 srm_printk("Expected 8kB pages, got %ldkB\n", INIT_HWRPB->pagesize >> 10);
162 return;
163 }
164 pal_init();
165 dev = openboot();
166 if (dev < 0) {
167 srm_printk("Unable to open boot device: %016lx\n", dev);
168 return;
169 }
170 dev &= 0xffffffff;
171 srm_printk("Loading vmlinux ...");
172 i = load(dev, START_ADDR, KERNEL_SIZE);
173 close(dev);
174 if (i != KERNEL_SIZE) {
175 srm_printk("Failed (%lx)\n", i);
176 return;
177 }
178
179 nbytes = callback_getenv(ENV_BOOTED_OSFLAGS, envval, sizeof(envval));
180 if (nbytes < 0) {
181 nbytes = 0;
182 }
183 envval[nbytes] = '\0';
184 strcpy((char*)ZERO_PGE, envval);
185
186 srm_printk(" Ok\nNow booting the kernel\n");
187 runkernel();
188 for (i = 0 ; i < 0x100000000 ; i++)
189 /* nothing */;
190 __halt();
191}
diff --git a/arch/alpha/boot/misc.c b/arch/alpha/boot/misc.c
new file mode 100644
index 000000000000..1d65adf5691e
--- /dev/null
+++ b/arch/alpha/boot/misc.c
@@ -0,0 +1,207 @@
1/*
2 * misc.c
3 *
4 * This is a collection of several routines from gzip-1.0.3
5 * adapted for Linux.
6 *
7 * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
8 *
9 * Modified for ARM Linux by Russell King
10 *
11 * Nicolas Pitre <nico@visuaide.com> 1999/04/14 :
12 * For this code to run directly from Flash, all constant variables must
13 * be marked with 'const' and all other variables initialized at run-time
14 * only. This way all non constant variables will end up in the bss segment,
15 * which should point to addresses in RAM and cleared to 0 on start.
16 * This allows for a much quicker boot time.
17 *
18 * Modified for Alpha, from the ARM version, by Jay Estabrook 2003.
19 */
20
21#include <linux/kernel.h>
22
23#include <asm/uaccess.h>
24
25#define memzero(s,n) memset ((s),0,(n))
26#define puts srm_printk
27extern long srm_printk(const char *, ...)
28 __attribute__ ((format (printf, 1, 2)));
29
30/*
31 * gzip delarations
32 */
33#define OF(args) args
34#define STATIC static
35
36typedef unsigned char uch;
37typedef unsigned short ush;
38typedef unsigned long ulg;
39
40#define WSIZE 0x8000 /* Window size must be at least 32k, */
41 /* and a power of two */
42
43static uch *inbuf; /* input buffer */
44static uch *window; /* Sliding window buffer */
45
46static unsigned insize; /* valid bytes in inbuf */
47static unsigned inptr; /* index of next byte to be processed in inbuf */
48static unsigned outcnt; /* bytes in output buffer */
49
50/* gzip flag byte */
51#define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */
52#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
53#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
54#define ORIG_NAME 0x08 /* bit 3 set: original file name present */
55#define COMMENT 0x10 /* bit 4 set: file comment present */
56#define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
57#define RESERVED 0xC0 /* bit 6,7: reserved */
58
59#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
60
61/* Diagnostic functions */
62#ifdef DEBUG
63# define Assert(cond,msg) {if(!(cond)) error(msg);}
64# define Trace(x) fprintf x
65# define Tracev(x) {if (verbose) fprintf x ;}
66# define Tracevv(x) {if (verbose>1) fprintf x ;}
67# define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
68# define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
69#else
70# define Assert(cond,msg)
71# define Trace(x)
72# define Tracev(x)
73# define Tracevv(x)
74# define Tracec(c,x)
75# define Tracecv(c,x)
76#endif
77
78static int fill_inbuf(void);
79static void flush_window(void);
80static void error(char *m);
81static void gzip_mark(void **);
82static void gzip_release(void **);
83
84static char *input_data;
85static int input_data_size;
86
87static uch *output_data;
88static ulg output_ptr;
89static ulg bytes_out;
90
91static void *malloc(int size);
92static void free(void *where);
93static void error(char *m);
94static void gzip_mark(void **);
95static void gzip_release(void **);
96
97extern int end;
98static ulg free_mem_ptr;
99static ulg free_mem_ptr_end;
100
101#define HEAP_SIZE 0x2000
102
103#include "../../../lib/inflate.c"
104
105static void *malloc(int size)
106{
107 void *p;
108
109 if (size <0) error("Malloc error");
110 if (free_mem_ptr <= 0) error("Memory error");
111
112 free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */
113
114 p = (void *)free_mem_ptr;
115 free_mem_ptr += size;
116
117 if (free_mem_ptr >= free_mem_ptr_end)
118 error("Out of memory");
119 return p;
120}
121
122static void free(void *where)
123{ /* gzip_mark & gzip_release do the free */
124}
125
126static void gzip_mark(void **ptr)
127{
128 *ptr = (void *) free_mem_ptr;
129}
130
131static void gzip_release(void **ptr)
132{
133 free_mem_ptr = (long) *ptr;
134}
135
136/* ===========================================================================
137 * Fill the input buffer. This is called only when the buffer is empty
138 * and at least one byte is really needed.
139 */
140int fill_inbuf(void)
141{
142 if (insize != 0)
143 error("ran out of input data");
144
145 inbuf = input_data;
146 insize = input_data_size;
147
148 inptr = 1;
149 return inbuf[0];
150}
151
152/* ===========================================================================
153 * Write the output window window[0..outcnt-1] and update crc and bytes_out.
154 * (Used for the decompressed data only.)
155 */
156void flush_window(void)
157{
158 ulg c = crc;
159 unsigned n;
160 uch *in, *out, ch;
161
162 in = window;
163 out = &output_data[output_ptr];
164 for (n = 0; n < outcnt; n++) {
165 ch = *out++ = *in++;
166 c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
167 }
168 crc = c;
169 bytes_out += (ulg)outcnt;
170 output_ptr += (ulg)outcnt;
171 outcnt = 0;
172/* puts("."); */
173}
174
175static void error(char *x)
176{
177 puts("\n\n");
178 puts(x);
179 puts("\n\n -- System halted");
180
181 while(1); /* Halt */
182}
183
184unsigned int
185decompress_kernel(void *output_start,
186 void *input_start,
187 size_t ksize,
188 size_t kzsize)
189{
190 output_data = (uch *)output_start;
191 input_data = (uch *)input_start;
192 input_data_size = kzsize; /* use compressed size */
193
194 /* FIXME FIXME FIXME */
195 free_mem_ptr = (ulg)output_start + ksize;
196 free_mem_ptr_end = (ulg)output_start + ksize + 0x200000;
197 /* FIXME FIXME FIXME */
198
199 /* put in temp area to reduce initial footprint */
200 window = malloc(WSIZE);
201
202 makecrc();
203/* puts("Uncompressing Linux..."); */
204 gunzip();
205/* puts(" done, booting the kernel.\n"); */
206 return output_ptr;
207}
diff --git a/arch/alpha/boot/tools/mkbb.c b/arch/alpha/boot/tools/mkbb.c
new file mode 100644
index 000000000000..23c7190b047c
--- /dev/null
+++ b/arch/alpha/boot/tools/mkbb.c
@@ -0,0 +1,151 @@
1/* This utility makes a bootblock suitable for the SRM console/miniloader */
2
3/* Usage:
4 * mkbb <device> <lxboot>
5 *
6 * Where <device> is the name of the device to install the bootblock on,
7 * and <lxboot> is the name of a bootblock to merge in. This bootblock
8 * contains the offset and size of the bootloader. It must be exactly
9 * 512 bytes long.
10 */
11
12#include <fcntl.h>
13#include <unistd.h>
14#include <stdio.h>
15
16/* Minimal definition of disklabel, so we don't have to include
17 * asm/disklabel.h (confuses make)
18 */
19#ifndef MAXPARTITIONS
20#define MAXPARTITIONS 8 /* max. # of partitions */
21#endif
22
23#ifndef u8
24#define u8 unsigned char
25#endif
26
27#ifndef u16
28#define u16 unsigned short
29#endif
30
31#ifndef u32
32#define u32 unsigned int
33#endif
34
35struct disklabel {
36 u32 d_magic; /* must be DISKLABELMAGIC */
37 u16 d_type, d_subtype;
38 u8 d_typename[16];
39 u8 d_packname[16];
40 u32 d_secsize;
41 u32 d_nsectors;
42 u32 d_ntracks;
43 u32 d_ncylinders;
44 u32 d_secpercyl;
45 u32 d_secprtunit;
46 u16 d_sparespertrack;
47 u16 d_sparespercyl;
48 u32 d_acylinders;
49 u16 d_rpm, d_interleave, d_trackskew, d_cylskew;
50 u32 d_headswitch, d_trkseek, d_flags;
51 u32 d_drivedata[5];
52 u32 d_spare[5];
53 u32 d_magic2; /* must be DISKLABELMAGIC */
54 u16 d_checksum;
55 u16 d_npartitions;
56 u32 d_bbsize, d_sbsize;
57 struct d_partition {
58 u32 p_size;
59 u32 p_offset;
60 u32 p_fsize;
61 u8 p_fstype;
62 u8 p_frag;
63 u16 p_cpg;
64 } d_partitions[MAXPARTITIONS];
65};
66
67
68typedef union __bootblock {
69 struct {
70 char __pad1[64];
71 struct disklabel __label;
72 } __u1;
73 struct {
74 unsigned long __pad2[63];
75 unsigned long __checksum;
76 } __u2;
77 char bootblock_bytes[512];
78 unsigned long bootblock_quadwords[64];
79} bootblock;
80
81#define bootblock_label __u1.__label
82#define bootblock_checksum __u2.__checksum
83
84main(int argc, char ** argv)
85{
86 bootblock bootblock_from_disk;
87 bootblock bootloader_image;
88 int dev, fd;
89 int i;
90 int nread;
91
92 /* Make sure of the arg count */
93 if(argc != 3) {
94 fprintf(stderr, "Usage: %s device lxboot\n", argv[0]);
95 exit(0);
96 }
97
98 /* First, open the device and make sure it's accessible */
99 dev = open(argv[1], O_RDWR);
100 if(dev < 0) {
101 perror(argv[1]);
102 exit(0);
103 }
104
105 /* Now open the lxboot and make sure it's reasonable */
106 fd = open(argv[2], O_RDONLY);
107 if(fd < 0) {
108 perror(argv[2]);
109 close(dev);
110 exit(0);
111 }
112
113 /* Read in the lxboot */
114 nread = read(fd, &bootloader_image, sizeof(bootblock));
115 if(nread != sizeof(bootblock)) {
116 perror("lxboot read");
117 fprintf(stderr, "expected %d, got %d\n", sizeof(bootblock), nread);
118 exit(0);
119 }
120
121 /* Read in the bootblock from disk. */
122 nread = read(dev, &bootblock_from_disk, sizeof(bootblock));
123 if(nread != sizeof(bootblock)) {
124 perror("bootblock read");
125 fprintf(stderr, "expected %d, got %d\n", sizeof(bootblock), nread);
126 exit(0);
127 }
128
129 /* Swap the bootblock's disklabel into the bootloader */
130 bootloader_image.bootblock_label = bootblock_from_disk.bootblock_label;
131
132 /* Calculate the bootblock checksum */
133 bootloader_image.bootblock_checksum = 0;
134 for(i = 0; i < 63; i++) {
135 bootloader_image.bootblock_checksum +=
136 bootloader_image.bootblock_quadwords[i];
137 }
138
139 /* Write the whole thing out! */
140 lseek(dev, 0L, SEEK_SET);
141 if(write(dev, &bootloader_image, sizeof(bootblock)) != sizeof(bootblock)) {
142 perror("bootblock write");
143 exit(0);
144 }
145
146 close(fd);
147 close(dev);
148 exit(0);
149}
150
151
diff --git a/arch/alpha/boot/tools/objstrip.c b/arch/alpha/boot/tools/objstrip.c
new file mode 100644
index 000000000000..67beb1b45e4f
--- /dev/null
+++ b/arch/alpha/boot/tools/objstrip.c
@@ -0,0 +1,281 @@
1/*
2 * arch/alpha/boot/tools/objstrip.c
3 *
4 * Strip the object file headers/trailers from an executable (ELF or ECOFF).
5 *
6 * Copyright (C) 1996 David Mosberger-Tang.
7 */
8/*
9 * Converts an ECOFF or ELF object file into a bootable file. The
10 * object file must be a OMAGIC file (i.e., data and bss follow immediately
11 * behind the text). See DEC "Assembly Language Programmer's Guide"
12 * documentation for details. The SRM boot process is documented in
13 * the Alpha AXP Architecture Reference Manual, Second Edition by
14 * Richard L. Sites and Richard T. Witek.
15 */
16#include <stdio.h>
17#include <string.h>
18#include <stdlib.h>
19#include <unistd.h>
20
21#include <sys/fcntl.h>
22#include <sys/stat.h>
23#include <sys/types.h>
24
25#include <linux/a.out.h>
26#include <linux/coff.h>
27#include <linux/param.h>
28#include <linux/string.h>
29#ifdef __ELF__
30# include <linux/elf.h>
31#endif
32
33/* bootfile size must be multiple of BLOCK_SIZE: */
34#define BLOCK_SIZE 512
35
36const char * prog_name;
37
38
39void
40usage (void)
41{
42 fprintf(stderr,
43 "usage: %s [-v] -p file primary\n"
44 " %s [-vb] file [secondary]\n", prog_name, prog_name);
45 exit(1);
46}
47
48
49int
50main (int argc, char *argv[])
51{
52 size_t nwritten, tocopy, n, mem_size, fil_size, pad = 0;
53 int fd, ofd, i, j, verbose = 0, primary = 0;
54 char buf[8192], *inname;
55 struct exec * aout; /* includes file & aout header */
56 long offset;
57#ifdef __ELF__
58 struct elfhdr *elf;
59 struct elf_phdr *elf_phdr; /* program header */
60 unsigned long long e_entry;
61#endif
62
63 prog_name = argv[0];
64
65 for (i = 1; i < argc && argv[i][0] == '-'; ++i) {
66 for (j = 1; argv[i][j]; ++j) {
67 switch (argv[i][j]) {
68 case 'v':
69 verbose = ~verbose;
70 break;
71
72 case 'b':
73 pad = BLOCK_SIZE;
74 break;
75
76 case 'p':
77 primary = 1; /* make primary bootblock */
78 break;
79 }
80 }
81 }
82
83 if (i >= argc) {
84 usage();
85 }
86 inname = argv[i++];
87
88 fd = open(inname, O_RDONLY);
89 if (fd == -1) {
90 perror("open");
91 exit(1);
92 }
93
94 ofd = 1;
95 if (i < argc) {
96 ofd = open(argv[i++], O_WRONLY | O_CREAT | O_TRUNC, 0666);
97 if (fd == -1) {
98 perror("open");
99 exit(1);
100 }
101 }
102
103 if (primary) {
104 /* generate bootblock for primary loader */
105
106 unsigned long bb[64], sum = 0;
107 struct stat st;
108 off_t size;
109 int i;
110
111 if (ofd == 1) {
112 usage();
113 }
114
115 if (fstat(fd, &st) == -1) {
116 perror("fstat");
117 exit(1);
118 }
119
120 size = (st.st_size + BLOCK_SIZE - 1) & ~(BLOCK_SIZE - 1);
121 memset(bb, 0, sizeof(bb));
122 strcpy((char *) bb, "Linux SRM bootblock");
123 bb[60] = size / BLOCK_SIZE; /* count */
124 bb[61] = 1; /* starting sector # */
125 bb[62] = 0; /* flags---must be 0 */
126 for (i = 0; i < 63; ++i) {
127 sum += bb[i];
128 }
129 bb[63] = sum;
130 if (write(ofd, bb, sizeof(bb)) != sizeof(bb)) {
131 perror("boot-block write");
132 exit(1);
133 }
134 printf("%lu\n", size);
135 return 0;
136 }
137
138 /* read and inspect exec header: */
139
140 if (read(fd, buf, sizeof(buf)) < 0) {
141 perror("read");
142 exit(1);
143 }
144
145#ifdef __ELF__
146 elf = (struct elfhdr *) buf;
147
148 if (elf->e_ident[0] == 0x7f && strncmp(elf->e_ident + 1, "ELF", 3) == 0) {
149 if (elf->e_type != ET_EXEC) {
150 fprintf(stderr, "%s: %s is not an ELF executable\n",
151 prog_name, inname);
152 exit(1);
153 }
154 if (!elf_check_arch(elf)) {
155 fprintf(stderr, "%s: is not for this processor (e_machine=%d)\n",
156 prog_name, elf->e_machine);
157 exit(1);
158 }
159 if (elf->e_phnum != 1) {
160 fprintf(stderr,
161 "%s: %d program headers (forgot to link with -N?)\n",
162 prog_name, elf->e_phnum);
163 }
164
165 e_entry = elf->e_entry;
166
167 lseek(fd, elf->e_phoff, SEEK_SET);
168 if (read(fd, buf, sizeof(*elf_phdr)) != sizeof(*elf_phdr)) {
169 perror("read");
170 exit(1);
171 }
172
173 elf_phdr = (struct elf_phdr *) buf;
174 offset = elf_phdr->p_offset;
175 mem_size = elf_phdr->p_memsz;
176 fil_size = elf_phdr->p_filesz;
177
178 /* work around ELF bug: */
179 if (elf_phdr->p_vaddr < e_entry) {
180 unsigned long delta = e_entry - elf_phdr->p_vaddr;
181 offset += delta;
182 mem_size -= delta;
183 fil_size -= delta;
184 elf_phdr->p_vaddr += delta;
185 }
186
187 if (verbose) {
188 fprintf(stderr, "%s: extracting %#016lx-%#016lx (at %lx)\n",
189 prog_name, (long) elf_phdr->p_vaddr,
190 elf_phdr->p_vaddr + fil_size, offset);
191 }
192 } else
193#endif
194 {
195 aout = (struct exec *) buf;
196
197 if (!(aout->fh.f_flags & COFF_F_EXEC)) {
198 fprintf(stderr, "%s: %s is not in executable format\n",
199 prog_name, inname);
200 exit(1);
201 }
202
203 if (aout->fh.f_opthdr != sizeof(aout->ah)) {
204 fprintf(stderr, "%s: %s has unexpected optional header size\n",
205 prog_name, inname);
206 exit(1);
207 }
208
209 if (N_MAGIC(*aout) != OMAGIC) {
210 fprintf(stderr, "%s: %s is not an OMAGIC file\n",
211 prog_name, inname);
212 exit(1);
213 }
214 offset = N_TXTOFF(*aout);
215 fil_size = aout->ah.tsize + aout->ah.dsize;
216 mem_size = fil_size + aout->ah.bsize;
217
218 if (verbose) {
219 fprintf(stderr, "%s: extracting %#016lx-%#016lx (at %lx)\n",
220 prog_name, aout->ah.text_start,
221 aout->ah.text_start + fil_size, offset);
222 }
223 }
224
225 if (lseek(fd, offset, SEEK_SET) != offset) {
226 perror("lseek");
227 exit(1);
228 }
229
230 if (verbose) {
231 fprintf(stderr, "%s: copying %lu byte from %s\n",
232 prog_name, (unsigned long) fil_size, inname);
233 }
234
235 tocopy = fil_size;
236 while (tocopy > 0) {
237 n = tocopy;
238 if (n > sizeof(buf)) {
239 n = sizeof(buf);
240 }
241 tocopy -= n;
242 if ((size_t) read(fd, buf, n) != n) {
243 perror("read");
244 exit(1);
245 }
246 do {
247 nwritten = write(ofd, buf, n);
248 if ((ssize_t) nwritten == -1) {
249 perror("write");
250 exit(1);
251 }
252 n -= nwritten;
253 } while (n > 0);
254 }
255
256 if (pad) {
257 mem_size = ((mem_size + pad - 1) / pad) * pad;
258 }
259
260 tocopy = mem_size - fil_size;
261 if (tocopy > 0) {
262 fprintf(stderr,
263 "%s: zero-filling bss and aligning to %lu with %lu bytes\n",
264 prog_name, pad, (unsigned long) tocopy);
265
266 memset(buf, 0x00, sizeof(buf));
267 do {
268 n = tocopy;
269 if (n > sizeof(buf)) {
270 n = sizeof(buf);
271 }
272 nwritten = write(ofd, buf, n);
273 if ((ssize_t) nwritten == -1) {
274 perror("write");
275 exit(1);
276 }
277 tocopy -= nwritten;
278 } while (tocopy > 0);
279 }
280 return 0;
281}