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