Home | History | Annotate | Line # | Download | only in lib
exec.c revision 1.17.2.2
      1  1.17.2.2  jdolecek /*	$NetBSD: exec.c,v 1.17.2.2 2001/06/01 23:26:32 jdolecek Exp $	 */
      2  1.17.2.2  jdolecek 
      3  1.17.2.2  jdolecek /*
      4  1.17.2.2  jdolecek  * Copyright (c) 1982, 1986, 1990, 1993
      5  1.17.2.2  jdolecek  *	The Regents of the University of California.  All rights reserved.
      6  1.17.2.2  jdolecek  * Copyright (c) 1996
      7  1.17.2.2  jdolecek  *	Matthias Drochner.  All rights reserved.
      8  1.17.2.2  jdolecek  * Copyright (c) 1996
      9  1.17.2.2  jdolecek  * 	Perry E. Metzger.  All rights reserved.
     10  1.17.2.2  jdolecek  * Copyright (c) 1997
     11  1.17.2.2  jdolecek  * 	Martin Husemann.  All rights reserved.
     12  1.17.2.2  jdolecek  *
     13  1.17.2.2  jdolecek  * Redistribution and use in source and binary forms, with or without
     14  1.17.2.2  jdolecek  * modification, are permitted provided that the following conditions
     15  1.17.2.2  jdolecek  * are met:
     16  1.17.2.2  jdolecek  * 1. Redistributions of source code must retain the above copyright
     17  1.17.2.2  jdolecek  *    notice, this list of conditions and the following disclaimer.
     18  1.17.2.2  jdolecek  * 2. Redistributions in binary form must reproduce the above copyright
     19  1.17.2.2  jdolecek  *    notice, this list of conditions and the following disclaimer in the
     20  1.17.2.2  jdolecek  *    documentation and/or other materials provided with the distribution.
     21  1.17.2.2  jdolecek  * 3. All advertising materials mentioning features or use of this software
     22  1.17.2.2  jdolecek  *    must display the following acknowledgement:
     23  1.17.2.2  jdolecek  *	This product includes software developed by the University of
     24  1.17.2.2  jdolecek  *	California, Berkeley and its contributors.
     25  1.17.2.2  jdolecek  * 4. Neither the name of the University nor the names of its contributors
     26  1.17.2.2  jdolecek  *    may be used to endorse or promote products derived from this software
     27  1.17.2.2  jdolecek  *    without specific prior written permission.
     28  1.17.2.2  jdolecek  *
     29  1.17.2.2  jdolecek  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     30  1.17.2.2  jdolecek  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     31  1.17.2.2  jdolecek  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     32  1.17.2.2  jdolecek  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     33  1.17.2.2  jdolecek  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     34  1.17.2.2  jdolecek  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     35  1.17.2.2  jdolecek  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     36  1.17.2.2  jdolecek  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     37  1.17.2.2  jdolecek  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     38  1.17.2.2  jdolecek  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     39  1.17.2.2  jdolecek  * SUCH DAMAGE.
     40  1.17.2.2  jdolecek  *
     41  1.17.2.2  jdolecek  * 	@(#)boot.c	8.1 (Berkeley) 6/10/93
     42  1.17.2.2  jdolecek  */
     43  1.17.2.2  jdolecek 
     44  1.17.2.2  jdolecek /*
     45  1.17.2.2  jdolecek  * starts NetBSD a.out kernel
     46  1.17.2.2  jdolecek  * needs lowlevel startup from startprog.S
     47  1.17.2.2  jdolecek  * This is a special version of exec.c to support use of XMS.
     48  1.17.2.2  jdolecek  */
     49  1.17.2.2  jdolecek 
     50  1.17.2.2  jdolecek #include <sys/param.h>
     51  1.17.2.2  jdolecek #include <sys/reboot.h>
     52  1.17.2.2  jdolecek 
     53  1.17.2.2  jdolecek #include <lib/libsa/stand.h>
     54  1.17.2.2  jdolecek 
     55  1.17.2.2  jdolecek #include "loadfile.h"
     56  1.17.2.2  jdolecek #include "libi386.h"
     57  1.17.2.2  jdolecek #include "bootinfo.h"
     58  1.17.2.2  jdolecek #ifdef SUPPORT_PS2
     59  1.17.2.2  jdolecek #include "biosmca.h"
     60  1.17.2.2  jdolecek #endif
     61  1.17.2.2  jdolecek 
     62  1.17.2.2  jdolecek #define BOOT_NARGS	6
     63  1.17.2.2  jdolecek 
     64  1.17.2.2  jdolecek extern struct btinfo_console btinfo_console;
     65  1.17.2.2  jdolecek 
     66  1.17.2.2  jdolecek int
     67  1.17.2.2  jdolecek exec_netbsd(file, loadaddr, boothowto)
     68  1.17.2.2  jdolecek 	const char     *file;
     69  1.17.2.2  jdolecek 	physaddr_t      loadaddr;
     70  1.17.2.2  jdolecek 	int             boothowto;
     71  1.17.2.2  jdolecek {
     72  1.17.2.2  jdolecek 	u_long          boot_argv[BOOT_NARGS];
     73  1.17.2.2  jdolecek 	int		fd;
     74  1.17.2.2  jdolecek 	u_long		marks[MARK_MAX];
     75  1.17.2.2  jdolecek 	struct btinfo_symtab btinfo_symtab;
     76  1.17.2.2  jdolecek 	u_long		extmem;
     77  1.17.2.2  jdolecek 	u_long		basemem;
     78  1.17.2.2  jdolecek #ifdef XMS
     79  1.17.2.2  jdolecek 	u_long		xmsmem;
     80  1.17.2.2  jdolecek 	physaddr_t	origaddr = loadaddr;
     81  1.17.2.2  jdolecek #endif
     82  1.17.2.2  jdolecek 
     83  1.17.2.2  jdolecek #ifdef	DEBUG
     84  1.17.2.2  jdolecek 	printf("exec: file=%s loadaddr=0x%lx\n",
     85  1.17.2.2  jdolecek 	       file ? file : "NULL", loadaddr);
     86  1.17.2.2  jdolecek #endif
     87  1.17.2.2  jdolecek 
     88  1.17.2.2  jdolecek 	BI_ALLOC(6); /* ??? */
     89  1.17.2.2  jdolecek 
     90  1.17.2.2  jdolecek 	BI_ADD(&btinfo_console, BTINFO_CONSOLE, sizeof(struct btinfo_console));
     91  1.17.2.2  jdolecek 
     92  1.17.2.2  jdolecek 	extmem = getextmem();
     93  1.17.2.2  jdolecek 	basemem = getbasemem();
     94  1.17.2.2  jdolecek 
     95  1.17.2.2  jdolecek #ifdef XMS
     96  1.17.2.2  jdolecek 	if ((getextmem1() == 0) && (xmsmem = checkxms())) {
     97  1.17.2.2  jdolecek 	        u_long kernsize;
     98  1.17.2.2  jdolecek 
     99  1.17.2.2  jdolecek 		/*
    100  1.17.2.2  jdolecek 		 * With "CONSERVATIVE_MEMDETECT", extmem is 0 because
    101  1.17.2.2  jdolecek 		 *  getextmem() is getextmem1(). Without, the "smart"
    102  1.17.2.2  jdolecek 		 *  methods could fail to report all memory as well.
    103  1.17.2.2  jdolecek 		 * xmsmem is a few kB less than the actual size, but
    104  1.17.2.2  jdolecek 		 *  better than nothing.
    105  1.17.2.2  jdolecek 		 */
    106  1.17.2.2  jdolecek 		if (xmsmem > extmem)
    107  1.17.2.2  jdolecek 			extmem = xmsmem;
    108  1.17.2.2  jdolecek 		/*
    109  1.17.2.2  jdolecek 		 * Get the size of the kernel
    110  1.17.2.2  jdolecek 		 */
    111  1.17.2.2  jdolecek 		marks[MARK_START] = loadaddr;
    112  1.17.2.2  jdolecek 		if ((fd = loadfile(file, marks, COUNT_KERNEL)) == -1)
    113  1.17.2.2  jdolecek 			goto out;
    114  1.17.2.2  jdolecek 		close(fd);
    115  1.17.2.2  jdolecek 
    116  1.17.2.2  jdolecek 		kernsize = marks[MARK_END];
    117  1.17.2.2  jdolecek 		kernsize = (kernsize + 1023) / 1024;
    118  1.17.2.2  jdolecek 
    119  1.17.2.2  jdolecek 		loadaddr = xmsalloc(kernsize);
    120  1.17.2.2  jdolecek 		if (!loadaddr)
    121  1.17.2.2  jdolecek 			return(ENOMEM);
    122  1.17.2.2  jdolecek 	}
    123  1.17.2.2  jdolecek #endif
    124  1.17.2.2  jdolecek 	marks[MARK_START] = loadaddr;
    125  1.17.2.2  jdolecek 	if ((fd = loadfile(file, marks, LOAD_KERNEL)) == -1)
    126  1.17.2.2  jdolecek 		goto out;
    127  1.17.2.2  jdolecek 
    128  1.17.2.2  jdolecek 	boot_argv[0] = boothowto;
    129  1.17.2.2  jdolecek 	boot_argv[1] = 0;
    130  1.17.2.2  jdolecek 	boot_argv[2] = vtophys(bootinfo);	/* old cyl offset */
    131  1.17.2.2  jdolecek 	/* argv[3] below */
    132  1.17.2.2  jdolecek 	boot_argv[4] = extmem;
    133  1.17.2.2  jdolecek 	boot_argv[5] = basemem;
    134  1.17.2.2  jdolecek 
    135  1.17.2.2  jdolecek 	close(fd);
    136  1.17.2.2  jdolecek 
    137  1.17.2.2  jdolecek 	/*
    138  1.17.2.2  jdolecek 	 * Gather some information for the kernel. Do this after the
    139  1.17.2.2  jdolecek 	 * "point of no return" to avoid memory leaks.
    140  1.17.2.2  jdolecek 	 * (but before DOS might be trashed in the XMS case)
    141  1.17.2.2  jdolecek 	 */
    142  1.17.2.2  jdolecek #ifdef PASS_BIOSGEOM
    143  1.17.2.2  jdolecek 	bi_getbiosgeom();
    144  1.17.2.2  jdolecek #endif
    145  1.17.2.2  jdolecek #ifdef PASS_MEMMAP
    146  1.17.2.2  jdolecek 	bi_getmemmap();
    147  1.17.2.2  jdolecek #endif
    148  1.17.2.2  jdolecek 
    149  1.17.2.2  jdolecek #ifdef XMS
    150  1.17.2.2  jdolecek 	if (loadaddr != origaddr) {
    151  1.17.2.2  jdolecek 		/*
    152  1.17.2.2  jdolecek 		 * We now have done our last DOS IO, so we may
    153  1.17.2.2  jdolecek 		 * trash the OS. Copy the data from the temporary
    154  1.17.2.2  jdolecek 		 * buffer to its real adress.
    155  1.17.2.2  jdolecek 		 */
    156  1.17.2.2  jdolecek 		marks[MARK_START] -= loadaddr;
    157  1.17.2.2  jdolecek 		marks[MARK_END] -= loadaddr;
    158  1.17.2.2  jdolecek 		marks[MARK_SYM] -= loadaddr;
    159  1.17.2.2  jdolecek 		marks[MARK_END] -= loadaddr;
    160  1.17.2.2  jdolecek 		ppbcopy(loadaddr, origaddr, marks[MARK_END]);
    161  1.17.2.2  jdolecek 	}
    162  1.17.2.2  jdolecek #endif
    163  1.17.2.2  jdolecek 	marks[MARK_END] = (((u_long) marks[MARK_END] + sizeof(int) - 1)) &
    164  1.17.2.2  jdolecek 	    (-sizeof(int));
    165  1.17.2.2  jdolecek 
    166  1.17.2.2  jdolecek 	boot_argv[3] = marks[MARK_END];
    167  1.17.2.2  jdolecek 
    168  1.17.2.2  jdolecek 
    169  1.17.2.2  jdolecek #ifdef DEBUG
    170  1.17.2.2  jdolecek 	printf("Start @ 0x%lx [%ld=0x%lx-0x%lx]...\n", marks[MARK_ENTRY],
    171  1.17.2.2  jdolecek 	    marks[MARK_NSYM], marks[MARK_SYM], marks[MARK_END]);
    172  1.17.2.2  jdolecek #endif
    173  1.17.2.2  jdolecek 
    174  1.17.2.2  jdolecek 	btinfo_symtab.nsym = marks[MARK_NSYM];
    175  1.17.2.2  jdolecek 	btinfo_symtab.ssym = marks[MARK_SYM];
    176  1.17.2.2  jdolecek 	btinfo_symtab.esym = marks[MARK_END];
    177  1.17.2.2  jdolecek 	BI_ADD(&btinfo_symtab, BTINFO_SYMTAB, sizeof(struct btinfo_symtab));
    178  1.17.2.2  jdolecek 
    179  1.17.2.2  jdolecek 	startprog(marks[MARK_ENTRY], BOOT_NARGS, boot_argv,
    180  1.17.2.2  jdolecek 		i386_trunc_page(basemem*1024));
    181  1.17.2.2  jdolecek 	panic("exec returned");
    182  1.17.2.2  jdolecek 
    183  1.17.2.2  jdolecek out:
    184  1.17.2.2  jdolecek 	BI_FREE();
    185  1.17.2.2  jdolecek 	bootinfo = 0;
    186  1.17.2.2  jdolecek 	return (-1);
    187  1.17.2.2  jdolecek }
    188