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