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