xref: /netbsd-src/sys/arch/pmax/stand/smallnet/smallnet.c (revision b1c86f5f087524e68db12794ee9c3e3da1ab17a0)
1 /*	$NetBSD: smallnet.c,v 1.7 2009/03/14 15:36:12 dsl 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
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 	printf("(%s, %s)\n", bootprog_maker, bootprog_date);
81 
82 	/* initialise bootinfo structure early */
83 	bi_init(BOOTINFO_ADDR);
84 
85 	/* check for DS5000 boot */
86 	if (strcmp(argv[0], "boot") == 0) {
87 		argc--;
88 		argv++;
89 	}
90 	name = *argv;
91 
92 	strncpy(bi_bpath.bootpath, name, BTINFO_BOOTPATH_LEN);
93 	bi_add(&bi_bpath, BTINFO_BOOTPATH, sizeof(bi_bpath));
94 
95 	destlen = RELOC - kernel_loadaddr;
96 	printf("\n");
97 	printf("Decompressing %d bytes to 0x%lx\n", kernel_size,
98 	    kernel_loadaddr);
99 	ret = uncompress((Bytef *)kernel_loadaddr, &destlen, kernel_image,
100 	    kernel_size);
101 	if (ret != Z_OK) {
102 		printf("Error decompressing kernel\n");
103 		printf("libz error %d\n", ret);
104 		return (1);
105 	}
106 
107 	if (callv == &callvec)
108 		kernel_entry(argc, argv, 0, 0);
109 	else
110 		kernel_entry(argc, argv, DEC_PROM_MAGIC, callv);
111 	return (1);
112 }
113