xref: /netbsd-src/sys/arch/pmax/stand/smallnet/smallnet.c (revision 404fbe5fb94ca1e054339640cabb2801ce52dd30)
1 /*	$NetBSD: smallnet.c,v 1.5 2008/04/28 20:23:31 martin 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) __P((int, char **, int, const void *));
46 
47 int main __P((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
71 main(argc, argv)
72 	int argc;
73 	char **argv;
74 {
75 	int ret;
76 	char *name;
77 	uLongf destlen;
78 	struct btinfo_bootpath bi_bpath;
79 
80 	printf("NetBSD/pmax " NETBSD_VERS " " BOOT_TYPE_NAME
81 	    " Bootstrap, Revision %s\n", bootprog_rev);
82 	printf("(%s, %s)\n", bootprog_maker, bootprog_date);
83 
84 	/* initialise bootinfo structure early */
85 	bi_init(BOOTINFO_ADDR);
86 
87 	/* check for DS5000 boot */
88 	if (strcmp(argv[0], "boot") == 0) {
89 		argc--;
90 		argv++;
91 	}
92 	name = *argv;
93 
94 	strncpy(bi_bpath.bootpath, name, BTINFO_BOOTPATH_LEN);
95 	bi_add(&bi_bpath, BTINFO_BOOTPATH, sizeof(bi_bpath));
96 
97 	destlen = RELOC - kernel_loadaddr;
98 	printf("\n");
99 	printf("Decompressing %d bytes to 0x%lx\n", kernel_size,
100 	    kernel_loadaddr);
101 	ret = uncompress((Bytef *)kernel_loadaddr, &destlen, kernel_image,
102 	    kernel_size);
103 	if (ret != Z_OK) {
104 		printf("Error decompressing kernel\n");
105 		printf("libz error %d\n", ret);
106 		return (1);
107 	}
108 
109 	if (callv == &callvec)
110 		kernel_entry(argc, argv, 0, 0);
111 	else
112 		kernel_entry(argc, argv, DEC_PROM_MAGIC, callv);
113 	return (1);
114 }
115