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