Home | History | Annotate | Line # | Download | only in lib
exec.c revision 1.7
      1  1.7  christos /*	$NetBSD: exec.c,v 1.7 1999/01/28 22:45:06 christos Exp $	 */
      2  1.1     perry 
      3  1.1     perry /*
      4  1.1     perry  * Copyright (c) 1982, 1986, 1990, 1993
      5  1.1     perry  *	The Regents of the University of California.  All rights reserved.
      6  1.1     perry  * Copyright (c) 1996
      7  1.1     perry  *	Matthias Drochner.  All rights reserved.
      8  1.1     perry  * Copyright (c) 1996
      9  1.1     perry  * 	Perry E. Metzger.  All rights reserved.
     10  1.1     perry  *
     11  1.1     perry  * Redistribution and use in source and binary forms, with or without
     12  1.1     perry  * modification, are permitted provided that the following conditions
     13  1.1     perry  * are met:
     14  1.1     perry  * 1. Redistributions of source code must retain the above copyright
     15  1.1     perry  *    notice, this list of conditions and the following disclaimer.
     16  1.1     perry  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.1     perry  *    notice, this list of conditions and the following disclaimer in the
     18  1.1     perry  *    documentation and/or other materials provided with the distribution.
     19  1.1     perry  * 3. All advertising materials mentioning features or use of this software
     20  1.1     perry  *    must display the following acknowledgement:
     21  1.1     perry  *	This product includes software developed by the University of
     22  1.1     perry  *	California, Berkeley and its contributors.
     23  1.1     perry  * 4. Neither the name of the University nor the names of its contributors
     24  1.1     perry  *    may be used to endorse or promote products derived from this software
     25  1.1     perry  *    without specific prior written permission.
     26  1.1     perry  *
     27  1.1     perry  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     28  1.1     perry  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     29  1.1     perry  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     30  1.1     perry  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     31  1.1     perry  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     32  1.1     perry  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     33  1.1     perry  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     34  1.1     perry  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     35  1.1     perry  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     36  1.1     perry  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     37  1.1     perry  * SUCH DAMAGE.
     38  1.1     perry  *
     39  1.1     perry  * 	@(#)boot.c	8.1 (Berkeley) 6/10/93
     40  1.1     perry  */
     41  1.1     perry 
     42  1.2   thorpej /*
     43  1.2   thorpej  * starts NetBSD a.out kernel needs lowlevel startup from startprog.S
     44  1.1     perry  */
     45  1.1     perry #include <sys/param.h>
     46  1.1     perry #include <sys/reboot.h>
     47  1.1     perry #ifdef COMPAT_OLDBOOT
     48  1.1     perry #include <sys/disklabel.h>
     49  1.1     perry #endif
     50  1.1     perry 
     51  1.1     perry #include <lib/libsa/stand.h>
     52  1.4  drochner 
     53  1.6  christos #include "loadfile.h"
     54  1.1     perry #include "libi386.h"
     55  1.4  drochner #include "bootinfo.h"
     56  1.1     perry 
     57  1.1     perry #ifdef COMPAT_OLDBOOT
     58  1.1     perry static int
     59  1.1     perry dev2major(devname, major)
     60  1.2   thorpej 	char           *devname;
     61  1.2   thorpej 	int            *major;
     62  1.1     perry {
     63  1.2   thorpej 	static char    *devices[] = {"wd", "", "fd", "", "sd"};
     64  1.1     perry #define NUMDEVICES (sizeof(devices)/sizeof(char *))
     65  1.2   thorpej 	int             i;
     66  1.1     perry 
     67  1.2   thorpej 	for (i = 0; i < NUMDEVICES; i++)
     68  1.2   thorpej 		if (!strcmp(devname, devices[i])) {
     69  1.2   thorpej 			*major = i;
     70  1.2   thorpej 			return (0);
     71  1.2   thorpej 		}
     72  1.2   thorpej 	return (-1);
     73  1.1     perry }
     74  1.1     perry #endif
     75  1.6  christos #define BOOT_NARGS	6
     76  1.1     perry 
     77  1.4  drochner extern struct btinfo_console btinfo_console;
     78  1.4  drochner 
     79  1.2   thorpej int
     80  1.4  drochner exec_netbsd(file, loadaddr, boothowto)
     81  1.2   thorpej 	const char     *file;
     82  1.2   thorpej 	physaddr_t      loadaddr;
     83  1.2   thorpej 	int             boothowto;
     84  1.1     perry {
     85  1.6  christos 	u_long          boot_argv[BOOT_NARGS];
     86  1.6  christos 	int		fd;
     87  1.1     perry #ifdef COMPAT_OLDBOOT
     88  1.2   thorpej 	char           *fsname, *devname;
     89  1.2   thorpej 	int             unit, part;
     90  1.2   thorpej 	const char     *filename;
     91  1.2   thorpej 	int             bootdevnr;
     92  1.7  christos 	u_long		marks[MARK_MAX];
     93  1.6  christos 	struct btinfo_symtab btinfo_symtab;
     94  1.1     perry #endif
     95  1.1     perry 
     96  1.1     perry #ifdef	DEBUG
     97  1.1     perry 	printf("exec: file=%s loadaddr=0x%lx\n", file, loadaddr);
     98  1.1     perry #endif
     99  1.4  drochner 
    100  1.6  christos 	BI_ALLOC(6); /* ??? */
    101  1.4  drochner 
    102  1.4  drochner 	BI_ADD(&btinfo_console, BTINFO_CONSOLE, sizeof(struct btinfo_console));
    103  1.4  drochner 
    104  1.7  christos 	marks[MARK_START] = loadaddr;
    105  1.7  christos 	if ((fd = loadfile(file, marks, LOAD_ALL)) == -1)
    106  1.4  drochner 		goto out;
    107  1.1     perry 
    108  1.7  christos 	marks[MARK_END] = (((u_long) marks[MARK_END] + sizeof(int) - 1)) &
    109  1.6  christos 	    (-sizeof(int));
    110  1.1     perry 
    111  1.7  christos 	btinfo_symtab.nsym = marks[MARK_NSYM];
    112  1.7  christos 	btinfo_symtab.ssym = marks[MARK_SYM];
    113  1.7  christos 	btinfo_symtab.esym = marks[MARK_END];
    114  1.6  christos 	BI_ADD(&btinfo_symtab, BTINFO_SYMTAB, sizeof(struct btinfo_symtab));
    115  1.1     perry 
    116  1.1     perry 	boot_argv[0] = boothowto;
    117  1.1     perry 
    118  1.1     perry #ifdef COMPAT_OLDBOOT
    119  1.1     perry 	/* prepare boot device information for kernel */
    120  1.2   thorpej 	if (parsebootfile(file, &fsname, &devname, &unit, &part, &filename)
    121  1.2   thorpej 	    || strcmp(fsname, "ufs"))
    122  1.2   thorpej 		bootdevnr = 0;	/* XXX error out if parse error??? */
    123  1.1     perry 	else {
    124  1.2   thorpej 		int             major;
    125  1.1     perry 
    126  1.3   thorpej 		if (strcmp(devname, "hd") == 0) {
    127  1.2   thorpej 			/* generic BIOS disk, have to guess type */
    128  1.6  christos 			struct open_file *f = &files[fd];	/* XXX */
    129  1.2   thorpej 
    130  1.2   thorpej 			if (biosdisk_gettype(f) == DTYPE_SCSI)
    131  1.2   thorpej 				devname = "sd";
    132  1.2   thorpej 			else
    133  1.2   thorpej 				devname = "wd";
    134  1.3   thorpej 
    135  1.3   thorpej 			/*
    136  1.3   thorpej 			 * The old boot block performed the following
    137  1.3   thorpej 			 * conversion:
    138  1.3   thorpej 			 *
    139  1.3   thorpej 			 *	hdN -> Xd0
    140  1.3   thorpej 			 *
    141  1.3   thorpej 			 * where X is the type specified by the label.
    142  1.3   thorpej 			 * We mimmick that here, for lack of any better
    143  1.3   thorpej 			 * way of doing things.
    144  1.3   thorpej 			 */
    145  1.3   thorpej 			unit = 0;
    146  1.2   thorpej 		}
    147  1.3   thorpej 
    148  1.2   thorpej 		if (dev2major(devname, &major))
    149  1.2   thorpej 			bootdevnr = 0;	/* XXX error out??? */
    150  1.1     perry 		else
    151  1.2   thorpej 			bootdevnr = MAKEBOOTDEV(major, 0, 0, unit, part);
    152  1.1     perry 	}
    153  1.1     perry 
    154  1.1     perry 	boot_argv[1] = bootdevnr;
    155  1.5  drochner #else
    156  1.5  drochner 	boot_argv[1] = 0;
    157  1.5  drochner #endif
    158  1.4  drochner #ifdef PASS_BIOSGEOM
    159  1.4  drochner 	bi_getbiosgeom();
    160  1.4  drochner #endif
    161  1.5  drochner 	boot_argv[2] = vtophys(bootinfo);	/* old cyl offset */
    162  1.7  christos 	boot_argv[3] = marks[MARK_END];
    163  1.1     perry 	boot_argv[4] = getextmem();
    164  1.1     perry 	boot_argv[5] = getbasemem();
    165  1.1     perry 
    166  1.6  christos 	close(fd);
    167  1.1     perry 
    168  1.1     perry #ifdef DEBUG
    169  1.7  christos 	printf("Start @ 0x%lx [%ld=0x%lx-0x%lx]...\n", marks[MARK_START],
    170  1.7  christos 	    marks[MARK_NSYM], marks[MARK_SYM], marks[MARK_END]);
    171  1.1     perry #endif
    172  1.1     perry 
    173  1.7  christos 	startprog(marks[MARK_START], BOOT_NARGS, boot_argv, 0x90000);
    174  1.1     perry 	panic("exec returned");
    175  1.1     perry 
    176  1.4  drochner out:
    177  1.4  drochner 	BI_FREE();
    178  1.4  drochner 	bootinfo = 0;
    179  1.2   thorpej 	return (-1);
    180  1.1     perry }
    181