smallnet.c revision 1.1 1 1.1 simonb /* $NetBSD: smallnet.c,v 1.1 1999/05/13 08:38:05 simonb Exp $ */
2 1.1 simonb
3 1.1 simonb /*-
4 1.1 simonb * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 1.1 simonb * All rights reserved.
6 1.1 simonb *
7 1.1 simonb * This code is derived from software contributed to The NetBSD Foundation
8 1.1 simonb * by Simon Burge.
9 1.1 simonb *
10 1.1 simonb * Redistribution and use in source and binary forms, with or without
11 1.1 simonb * modification, are permitted provided that the following conditions
12 1.1 simonb * are met:
13 1.1 simonb * 1. Redistributions of source code must retain the above copyright
14 1.1 simonb * notice, this list of conditions and the following disclaimer.
15 1.1 simonb * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 simonb * notice, this list of conditions and the following disclaimer in the
17 1.1 simonb * documentation and/or other materials provided with the distribution.
18 1.1 simonb * 3. All advertising materials mentioning features or use of this software
19 1.1 simonb * must display the following acknowledgement:
20 1.1 simonb * This product includes software developed by the NetBSD
21 1.1 simonb * Foundation, Inc. and its contributors.
22 1.1 simonb * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 simonb * contributors may be used to endorse or promote products derived
24 1.1 simonb * from this software without specific prior written permission.
25 1.1 simonb *
26 1.1 simonb * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 simonb * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 simonb * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 simonb * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 simonb * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 simonb * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 simonb * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 simonb * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 simonb * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 simonb * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 simonb * POSSIBILITY OF SUCH DAMAGE.
37 1.1 simonb */
38 1.1 simonb
39 1.1 simonb #include <stand.h>
40 1.1 simonb #include <sys/param.h>
41 1.1 simonb #include <sys/exec_elf.h>
42 1.1 simonb #include <machine/dec_prom.h>
43 1.1 simonb #include <lib/libz/zlib.h>
44 1.1 simonb #include <lib/libkern/libkern.h>
45 1.1 simonb
46 1.1 simonb #include "common.h"
47 1.1 simonb #include "bootinfo.h"
48 1.1 simonb
49 1.1 simonb
50 1.1 simonb typedef void (*entrypt) __P((int, char **, int, const void *));
51 1.1 simonb
52 1.1 simonb int main __P((int, char **));
53 1.1 simonb
54 1.1 simonb /*
55 1.1 simonb * These variables and array will be patched to contain a kernel image
56 1.1 simonb * and some information about the kernel.
57 1.1 simonb */
58 1.1 simonb
59 1.1 simonb int maxkernel_size = KERNELSIZE;
60 1.1 simonb entrypt kernel_entry = 0 /* (entrypt)0x80030000 */ /* XXX XXX XXX */;
61 1.1 simonb u_long kernel_loadaddr = 0 /* 0x80030000 */ /* XXX XXX XXX */;
62 1.1 simonb int kernel_size = 0 /* 387321 */ /* XXX XXX XXX */;
63 1.1 simonb char kernel_image[KERNELSIZE] = "|This is the kernel image!\n";
64 1.1 simonb
65 1.1 simonb
66 1.1 simonb /*
67 1.1 simonb * This gets arguments from the PROM, calls other routines to open
68 1.1 simonb * and load the secondary boot loader called boot, and then transfers
69 1.1 simonb * execution to that program.
70 1.1 simonb *
71 1.1 simonb * Argv[0] should be something like "rz(0,0,0)netbsd" on a DECstation 3100.
72 1.1 simonb * Argv[0,1] should be something like "boot 5/rz0/netbsd" on a DECstation 5000.
73 1.1 simonb * The argument "-a" means netbsd should do an automatic reboot.
74 1.1 simonb */
75 1.1 simonb int
76 1.1 simonb main(argc, argv)
77 1.1 simonb int argc;
78 1.1 simonb char **argv;
79 1.1 simonb {
80 1.1 simonb int ret;
81 1.1 simonb char *name;
82 1.1 simonb uLongf destlen;
83 1.1 simonb struct btinfo_bootpath bi_bpath;
84 1.1 simonb
85 1.1 simonb printf("NetBSD/pmax " NETBSD_VERS " " BOOT_TYPE_NAME
86 1.1 simonb " Bootstrap, Revision %s\n", bootprog_rev);
87 1.1 simonb printf("(%s, %s)\n", bootprog_maker, bootprog_date);
88 1.1 simonb
89 1.1 simonb /* initialise bootinfo structure early */
90 1.1 simonb bi_init(BOOTINFO_ADDR);
91 1.1 simonb
92 1.1 simonb /* check for DS5000 boot */
93 1.1 simonb if (strcmp(argv[0], "boot") == 0) {
94 1.1 simonb argc--;
95 1.1 simonb argv++;
96 1.1 simonb }
97 1.1 simonb name = *argv;
98 1.1 simonb
99 1.1 simonb strncpy(bi_bpath.bootpath, name, BTINFO_BOOTPATH_LEN);
100 1.1 simonb bi_add(&bi_bpath, BTINFO_BOOTPATH, sizeof(bi_bpath));
101 1.1 simonb
102 1.1 simonb destlen = RELOC - kernel_loadaddr;
103 1.1 simonb printf("\n");
104 1.1 simonb printf("Decompressing %d bytes to 0x%lx\n", kernel_size,
105 1.1 simonb kernel_loadaddr);
106 1.1 simonb ret = uncompress((Bytef *)kernel_loadaddr, &destlen, kernel_image,
107 1.1 simonb kernel_size);
108 1.1 simonb if (ret != Z_OK) {
109 1.1 simonb printf("Error decompressing kernel\n");
110 1.1 simonb printf("libz error %d\n", ret);
111 1.1 simonb return (1);
112 1.1 simonb }
113 1.1 simonb
114 1.1 simonb if (callv == &callvec)
115 1.1 simonb kernel_entry(argc, argv, 0, 0);
116 1.1 simonb else
117 1.1 simonb kernel_entry(argc, argv, DEC_PROM_MAGIC, callv);
118 1.1 simonb return (1);
119 1.1 simonb }
120