Home | History | Annotate | Line # | Download | only in lib
exec.c revision 1.61.2.3
      1  1.61.2.3  pgoyette /*	$NetBSD: exec.c,v 1.61.2.3 2017/04/26 02:53:03 pgoyette Exp $	 */
      2      1.23        ad 
      3  1.61.2.1  pgoyette /*
      4      1.40        ad  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
      5      1.23        ad  * All rights reserved.
      6      1.23        ad  *
      7      1.23        ad  * Redistribution and use in source and binary forms, with or without
      8      1.23        ad  * modification, are permitted provided that the following conditions
      9      1.23        ad  * are met:
     10      1.23        ad  * 1. Redistributions of source code must retain the above copyright
     11      1.23        ad  *    notice, this list of conditions and the following disclaimer.
     12      1.23        ad  * 2. Redistributions in binary form must reproduce the above copyright
     13      1.23        ad  *    notice, this list of conditions and the following disclaimer in the
     14      1.23        ad  *    documentation and/or other materials provided with the distribution.
     15      1.23        ad  *
     16      1.23        ad  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17      1.23        ad  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18      1.23        ad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19      1.23        ad  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20      1.23        ad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21      1.23        ad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22      1.23        ad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23      1.23        ad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24      1.23        ad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25      1.23        ad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26      1.23        ad  * POSSIBILITY OF SUCH DAMAGE.
     27      1.23        ad  */
     28       1.1     perry 
     29       1.1     perry /*
     30       1.1     perry  * Copyright (c) 1982, 1986, 1990, 1993
     31       1.1     perry  *	The Regents of the University of California.  All rights reserved.
     32      1.19       agc  *
     33      1.19       agc  * Redistribution and use in source and binary forms, with or without
     34      1.19       agc  * modification, are permitted provided that the following conditions
     35      1.19       agc  * are met:
     36      1.19       agc  * 1. Redistributions of source code must retain the above copyright
     37      1.19       agc  *    notice, this list of conditions and the following disclaimer.
     38      1.19       agc  * 2. Redistributions in binary form must reproduce the above copyright
     39      1.19       agc  *    notice, this list of conditions and the following disclaimer in the
     40      1.19       agc  *    documentation and/or other materials provided with the distribution.
     41      1.19       agc  * 3. Neither the name of the University nor the names of its contributors
     42      1.19       agc  *    may be used to endorse or promote products derived from this software
     43      1.19       agc  *    without specific prior written permission.
     44      1.19       agc  *
     45      1.19       agc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     46      1.19       agc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     47      1.19       agc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     48      1.19       agc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     49      1.19       agc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     50      1.19       agc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     51      1.19       agc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     52      1.19       agc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     53      1.19       agc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     54      1.19       agc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     55      1.19       agc  * SUCH DAMAGE.
     56      1.19       agc  *
     57      1.19       agc  * 	@(#)boot.c	8.1 (Berkeley) 6/10/93
     58      1.19       agc  */
     59      1.19       agc 
     60      1.19       agc /*
     61       1.1     perry  * Copyright (c) 1996
     62       1.1     perry  *	Matthias Drochner.  All rights reserved.
     63       1.1     perry  * Copyright (c) 1996
     64       1.1     perry  * 	Perry E. Metzger.  All rights reserved.
     65       1.1     perry  *
     66       1.1     perry  * Redistribution and use in source and binary forms, with or without
     67       1.1     perry  * modification, are permitted provided that the following conditions
     68       1.1     perry  * are met:
     69       1.1     perry  * 1. Redistributions of source code must retain the above copyright
     70       1.1     perry  *    notice, this list of conditions and the following disclaimer.
     71       1.1     perry  * 2. Redistributions in binary form must reproduce the above copyright
     72       1.1     perry  *    notice, this list of conditions and the following disclaimer in the
     73       1.1     perry  *    documentation and/or other materials provided with the distribution.
     74       1.1     perry  *
     75       1.1     perry  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     76       1.1     perry  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     77       1.1     perry  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     78       1.1     perry  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     79       1.1     perry  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     80       1.1     perry  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     81       1.1     perry  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     82       1.1     perry  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     83       1.1     perry  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     84       1.1     perry  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     85       1.1     perry  * SUCH DAMAGE.
     86       1.1     perry  *
     87       1.1     perry  * 	@(#)boot.c	8.1 (Berkeley) 6/10/93
     88       1.1     perry  */
     89       1.1     perry 
     90       1.2   thorpej /*
     91  1.61.2.1  pgoyette  * Starts a NetBSD ELF kernel. The low level startup is done in startprog.S.
     92       1.8  christos  * This is a special version of exec.c to support use of XMS.
     93       1.1     perry  */
     94       1.8  christos 
     95       1.1     perry #include <sys/param.h>
     96       1.1     perry #include <sys/reboot.h>
     97      1.40        ad #include <sys/reboot.h>
     98       1.1     perry 
     99      1.53  jakllsch #include <i386/multiboot.h>
    100      1.33     joerg 
    101       1.1     perry #include <lib/libsa/stand.h>
    102      1.23        ad #include <lib/libkern/libkern.h>
    103       1.4  drochner 
    104       1.6  christos #include "loadfile.h"
    105       1.1     perry #include "libi386.h"
    106       1.4  drochner #include "bootinfo.h"
    107      1.23        ad #include "bootmod.h"
    108      1.42  jmcneill #include "vbe.h"
    109      1.16  jdolecek #ifdef SUPPORT_PS2
    110      1.16  jdolecek #include "biosmca.h"
    111      1.16  jdolecek #endif
    112  1.61.2.2  pgoyette #ifdef EFIBOOT
    113  1.61.2.2  pgoyette #include "efiboot.h"
    114  1.61.2.2  pgoyette #undef DEBUG	/* XXX */
    115  1.61.2.2  pgoyette #endif
    116       1.1     perry 
    117       1.6  christos #define BOOT_NARGS	6
    118       1.1     perry 
    119      1.23        ad #ifndef	PAGE_SIZE
    120      1.23        ad #define	PAGE_SIZE	4096
    121      1.23        ad #endif
    122      1.23        ad 
    123      1.43   tsutsui #define MODULE_WARNING_SEC	5
    124      1.41  jmcneill 
    125       1.4  drochner extern struct btinfo_console btinfo_console;
    126       1.4  drochner 
    127      1.23        ad boot_module_t *boot_modules;
    128      1.23        ad bool boot_modules_enabled = true;
    129      1.23        ad bool kernel_loaded;
    130      1.23        ad 
    131      1.47  uebayasi typedef struct userconf_command {
    132      1.47  uebayasi 	char *uc_text;
    133      1.47  uebayasi 	size_t uc_len;
    134      1.47  uebayasi 	struct userconf_command *uc_next;
    135      1.47  uebayasi } userconf_command_t;
    136      1.47  uebayasi userconf_command_t *userconf_commands = NULL;
    137      1.47  uebayasi 
    138      1.39  jmcneill static struct btinfo_framebuffer btinfo_framebuffer;
    139      1.39  jmcneill 
    140      1.23        ad static struct btinfo_modulelist *btinfo_modulelist;
    141      1.23        ad static size_t btinfo_modulelist_size;
    142      1.23        ad static uint32_t image_end;
    143      1.26        ad static char module_base[64] = "/";
    144      1.40        ad static int howto;
    145      1.23        ad 
    146      1.47  uebayasi static struct btinfo_userconfcommands *btinfo_userconfcommands = NULL;
    147      1.47  uebayasi static size_t btinfo_userconfcommands_size = 0;
    148      1.47  uebayasi 
    149      1.41  jmcneill static void	module_init(const char *);
    150      1.57  jakllsch static void	module_add_common(const char *, uint8_t);
    151      1.23        ad 
    152      1.47  uebayasi static void	userconf_init(void);
    153      1.47  uebayasi 
    154  1.61.2.2  pgoyette static void	extract_device(const char *, char *, size_t);
    155  1.61.2.2  pgoyette static void	module_base_path(char *, size_t);
    156  1.61.2.2  pgoyette static int	module_open(boot_module_t *, int, const char *, const char *,
    157  1.61.2.2  pgoyette 		    bool);
    158  1.61.2.2  pgoyette 
    159      1.34        ad void
    160      1.39  jmcneill framebuffer_configure(struct btinfo_framebuffer *fb)
    161      1.39  jmcneill {
    162      1.39  jmcneill 	if (fb)
    163      1.39  jmcneill 		btinfo_framebuffer = *fb;
    164      1.39  jmcneill 	else {
    165      1.39  jmcneill 		btinfo_framebuffer.physaddr = 0;
    166      1.39  jmcneill 		btinfo_framebuffer.flags = 0;
    167      1.39  jmcneill 	}
    168      1.39  jmcneill }
    169      1.39  jmcneill 
    170      1.39  jmcneill void
    171      1.34        ad module_add(char *name)
    172      1.34        ad {
    173      1.46  jmcneill 	return module_add_common(name, BM_TYPE_KMOD);
    174      1.46  jmcneill }
    175      1.46  jmcneill 
    176      1.46  jmcneill void
    177      1.46  jmcneill splash_add(char *name)
    178      1.46  jmcneill {
    179      1.46  jmcneill 	return module_add_common(name, BM_TYPE_IMAGE);
    180      1.46  jmcneill }
    181      1.46  jmcneill 
    182      1.49       tls void
    183      1.49       tls rnd_add(char *name)
    184      1.49       tls {
    185      1.49       tls 	return module_add_common(name, BM_TYPE_RND);
    186      1.49       tls }
    187      1.49       tls 
    188      1.51  jmcneill void
    189      1.51  jmcneill fs_add(char *name)
    190      1.51  jmcneill {
    191      1.51  jmcneill 	return module_add_common(name, BM_TYPE_FS);
    192      1.51  jmcneill }
    193      1.51  jmcneill 
    194      1.46  jmcneill static void
    195      1.57  jakllsch module_add_common(const char *name, uint8_t type)
    196      1.46  jmcneill {
    197      1.34        ad 	boot_module_t *bm, *bmp;
    198      1.34        ad 	size_t len;
    199      1.34        ad 	char *str;
    200      1.34        ad 
    201      1.35        ad 	while (*name == ' ' || *name == '\t')
    202      1.35        ad 		++name;
    203      1.35        ad 
    204  1.61.2.2  pgoyette 	for (bm = boot_modules; bm != NULL; bm = bm->bm_next)
    205  1.61.2.2  pgoyette 		if (bm->bm_type == type && strcmp(bm->bm_path, name) == 0)
    206  1.61.2.2  pgoyette 			return;
    207  1.61.2.2  pgoyette 
    208      1.34        ad 	bm = alloc(sizeof(boot_module_t));
    209      1.34        ad 	len = strlen(name) + 1;
    210      1.34        ad 	str = alloc(len);
    211      1.34        ad 	if (bm == NULL || str == NULL) {
    212      1.34        ad 		printf("couldn't allocate module\n");
    213      1.34        ad 		return;
    214      1.34        ad 	}
    215      1.34        ad 	memcpy(str, name, len);
    216      1.34        ad 	bm->bm_path = str;
    217      1.34        ad 	bm->bm_next = NULL;
    218      1.46  jmcneill 	bm->bm_type = type;
    219      1.34        ad 	if (boot_modules == NULL)
    220      1.34        ad 		boot_modules = bm;
    221      1.34        ad 	else {
    222      1.34        ad 		for (bmp = boot_modules; bmp->bm_next;
    223      1.34        ad 		    bmp = bmp->bm_next)
    224      1.34        ad 			;
    225      1.34        ad 		bmp->bm_next = bm;
    226      1.34        ad 	}
    227      1.34        ad }
    228      1.34        ad 
    229      1.47  uebayasi void
    230      1.47  uebayasi userconf_add(char *cmd)
    231      1.47  uebayasi {
    232      1.47  uebayasi 	userconf_command_t *uc;
    233      1.47  uebayasi 	size_t len;
    234      1.47  uebayasi 	char *text;
    235      1.47  uebayasi 
    236      1.47  uebayasi 	while (*cmd == ' ' || *cmd == '\t')
    237      1.47  uebayasi 		++cmd;
    238      1.47  uebayasi 
    239      1.47  uebayasi 	uc = alloc(sizeof(*uc));
    240      1.47  uebayasi 	if (uc == NULL) {
    241      1.47  uebayasi 		printf("couldn't allocate command\n");
    242      1.47  uebayasi 		return;
    243      1.47  uebayasi 	}
    244      1.47  uebayasi 
    245      1.47  uebayasi 	len = strlen(cmd) + 1;
    246      1.47  uebayasi 	text = alloc(len);
    247      1.47  uebayasi 	if (text == NULL) {
    248      1.47  uebayasi 		dealloc(uc, sizeof(*uc));
    249      1.47  uebayasi 		printf("couldn't allocate command\n");
    250      1.47  uebayasi 		return;
    251      1.47  uebayasi 	}
    252      1.47  uebayasi 	memcpy(text, cmd, len);
    253      1.47  uebayasi 
    254      1.47  uebayasi 	uc->uc_text = text;
    255      1.47  uebayasi 	uc->uc_len = len;
    256      1.47  uebayasi 	uc->uc_next = NULL;
    257      1.47  uebayasi 
    258      1.47  uebayasi 	if (userconf_commands == NULL)
    259      1.47  uebayasi 		userconf_commands = uc;
    260      1.47  uebayasi 	else {
    261      1.47  uebayasi 		userconf_command_t *ucp;
    262      1.47  uebayasi 		for (ucp = userconf_commands; ucp->uc_next != NULL;
    263      1.47  uebayasi 		     ucp = ucp->uc_next)
    264      1.47  uebayasi 			;
    265      1.47  uebayasi 		ucp->uc_next = uc;
    266      1.47  uebayasi 	}
    267      1.47  uebayasi }
    268      1.47  uebayasi 
    269      1.32     joerg static int
    270      1.32     joerg common_load_kernel(const char *file, u_long *basemem, u_long *extmem,
    271      1.32     joerg     physaddr_t loadaddr, int floppy, u_long marks[MARK_MAX])
    272       1.1     perry {
    273      1.32     joerg 	int fd;
    274       1.8  christos #ifdef XMS
    275  1.61.2.1  pgoyette 	u_long xmsmem;
    276  1.61.2.1  pgoyette 	physaddr_t origaddr = loadaddr;
    277       1.8  christos #endif
    278       1.8  christos 
    279      1.32     joerg 	*extmem = getextmem();
    280      1.32     joerg 	*basemem = getbasemem();
    281       1.8  christos 
    282       1.8  christos #ifdef XMS
    283       1.8  christos 	if ((getextmem1() == 0) && (xmsmem = checkxms())) {
    284  1.61.2.1  pgoyette 		u_long kernsize;
    285       1.8  christos 
    286       1.8  christos 		/*
    287       1.8  christos 		 * With "CONSERVATIVE_MEMDETECT", extmem is 0 because
    288  1.61.2.1  pgoyette 		 * getextmem() is getextmem1(). Without, the "smart"
    289  1.61.2.1  pgoyette 		 * methods could fail to report all memory as well.
    290       1.8  christos 		 * xmsmem is a few kB less than the actual size, but
    291  1.61.2.1  pgoyette 		 * better than nothing.
    292       1.8  christos 		 */
    293      1.32     joerg 		if (xmsmem > *extmem)
    294      1.32     joerg 			*extmem = xmsmem;
    295      1.21  junyoung 		/*
    296       1.8  christos 		 * Get the size of the kernel
    297       1.8  christos 		 */
    298       1.8  christos 		marks[MARK_START] = loadaddr;
    299      1.12  christos 		if ((fd = loadfile(file, marks, COUNT_KERNEL)) == -1)
    300      1.32     joerg 			return EIO;
    301       1.8  christos 		close(fd);
    302       1.8  christos 
    303       1.8  christos 		kernsize = marks[MARK_END];
    304       1.8  christos 		kernsize = (kernsize + 1023) / 1024;
    305       1.8  christos 
    306       1.8  christos 		loadaddr = xmsalloc(kernsize);
    307       1.8  christos 		if (!loadaddr)
    308      1.21  junyoung 			return ENOMEM;
    309       1.8  christos 	}
    310       1.8  christos #endif
    311       1.7  christos 	marks[MARK_START] = loadaddr;
    312      1.29  christos 	if ((fd = loadfile(file, marks,
    313      1.44  christos 	    LOAD_KERNEL & ~(floppy ? LOAD_BACKWARDS : 0))) == -1)
    314      1.32     joerg 		return EIO;
    315       1.1     perry 
    316       1.8  christos 	close(fd);
    317      1.10  drochner 
    318      1.50       dsl 	/* If the root fs type is unusual, load its module. */
    319      1.50       dsl 	if (fsmod != NULL)
    320      1.57  jakllsch 		module_add_common(fsmod, BM_TYPE_KMOD);
    321      1.34        ad 
    322      1.10  drochner 	/*
    323      1.10  drochner 	 * Gather some information for the kernel. Do this after the
    324      1.10  drochner 	 * "point of no return" to avoid memory leaks.
    325      1.10  drochner 	 * (but before DOS might be trashed in the XMS case)
    326      1.10  drochner 	 */
    327      1.10  drochner #ifdef PASS_BIOSGEOM
    328      1.10  drochner 	bi_getbiosgeom();
    329      1.10  drochner #endif
    330      1.10  drochner #ifdef PASS_MEMMAP
    331      1.10  drochner 	bi_getmemmap();
    332      1.10  drochner #endif
    333       1.8  christos 
    334       1.8  christos #ifdef XMS
    335       1.8  christos 	if (loadaddr != origaddr) {
    336       1.8  christos 		/*
    337      1.14      ross 		 * We now have done our last DOS IO, so we may
    338       1.8  christos 		 * trash the OS. Copy the data from the temporary
    339      1.20       wiz 		 * buffer to its real address.
    340       1.8  christos 		 */
    341       1.8  christos 		marks[MARK_START] -= loadaddr;
    342       1.8  christos 		marks[MARK_END] -= loadaddr;
    343       1.8  christos 		marks[MARK_SYM] -= loadaddr;
    344       1.8  christos 		marks[MARK_END] -= loadaddr;
    345       1.8  christos 		ppbcopy(loadaddr, origaddr, marks[MARK_END]);
    346       1.8  christos 	}
    347       1.8  christos #endif
    348       1.8  christos 	marks[MARK_END] = (((u_long) marks[MARK_END] + sizeof(int) - 1)) &
    349       1.8  christos 	    (-sizeof(int));
    350      1.23        ad 	image_end = marks[MARK_END];
    351      1.23        ad 	kernel_loaded = true;
    352       1.1     perry 
    353      1.32     joerg 	return 0;
    354      1.32     joerg }
    355      1.32     joerg 
    356      1.32     joerg int
    357      1.40        ad exec_netbsd(const char *file, physaddr_t loadaddr, int boothowto, int floppy,
    358  1.61.2.1  pgoyette     void (*callback)(void))
    359      1.32     joerg {
    360  1.61.2.1  pgoyette 	uint32_t boot_argv[BOOT_NARGS];
    361  1.61.2.1  pgoyette 	u_long marks[MARK_MAX];
    362      1.32     joerg 	struct btinfo_symtab btinfo_symtab;
    363  1.61.2.1  pgoyette 	u_long extmem;
    364  1.61.2.1  pgoyette 	u_long basemem;
    365  1.61.2.2  pgoyette 	int error;
    366  1.61.2.2  pgoyette #ifdef EFIBOOT
    367  1.61.2.2  pgoyette 	int i;
    368  1.61.2.2  pgoyette #endif
    369      1.32     joerg 
    370      1.32     joerg #ifdef	DEBUG
    371  1.61.2.1  pgoyette 	printf("exec: file=%s loadaddr=0x%lx\n", file ? file : "NULL",
    372  1.61.2.1  pgoyette 	    loadaddr);
    373      1.32     joerg #endif
    374      1.32     joerg 
    375      1.61      maxv 	BI_ALLOC(BTINFO_MAX);
    376      1.32     joerg 
    377      1.32     joerg 	BI_ADD(&btinfo_console, BTINFO_CONSOLE, sizeof(struct btinfo_console));
    378      1.32     joerg 
    379      1.40        ad 	howto = boothowto;
    380      1.40        ad 
    381      1.56  jakllsch 	memset(marks, 0, sizeof(marks));
    382      1.56  jakllsch 
    383  1.61.2.2  pgoyette 	error = common_load_kernel(file, &basemem, &extmem, loadaddr, floppy,
    384  1.61.2.2  pgoyette 	    marks);
    385  1.61.2.2  pgoyette 	if (error) {
    386  1.61.2.2  pgoyette 		errno = error;
    387      1.32     joerg 		goto out;
    388  1.61.2.2  pgoyette 	}
    389  1.61.2.2  pgoyette #ifdef EFIBOOT
    390  1.61.2.2  pgoyette 	/* adjust to the real load address */
    391  1.61.2.2  pgoyette 	marks[MARK_START] -= efi_loadaddr;
    392  1.61.2.2  pgoyette 	marks[MARK_ENTRY] -= efi_loadaddr;
    393  1.61.2.2  pgoyette 	marks[MARK_DATA] -= efi_loadaddr;
    394  1.61.2.2  pgoyette 	/* MARK_NSYM */
    395  1.61.2.2  pgoyette 	marks[MARK_SYM] -= efi_loadaddr;
    396  1.61.2.2  pgoyette 	marks[MARK_END] -= efi_loadaddr;
    397  1.61.2.2  pgoyette #endif
    398      1.32     joerg 
    399      1.31     joerg 	boot_argv[0] = boothowto;
    400      1.31     joerg 	boot_argv[1] = 0;
    401      1.31     joerg 	boot_argv[2] = vtophys(bootinfo);	/* old cyl offset */
    402      1.31     joerg 	boot_argv[3] = marks[MARK_END];
    403      1.31     joerg 	boot_argv[4] = extmem;
    404      1.31     joerg 	boot_argv[5] = basemem;
    405      1.31     joerg 
    406      1.23        ad 	/* pull in any modules if necessary */
    407      1.23        ad 	if (boot_modules_enabled) {
    408      1.41  jmcneill 		module_init(file);
    409      1.23        ad 		if (btinfo_modulelist) {
    410  1.61.2.2  pgoyette #ifdef EFIBOOT
    411  1.61.2.2  pgoyette 			/* convert module loaded address to paddr */
    412  1.61.2.2  pgoyette 			struct bi_modulelist_entry *bim;
    413  1.61.2.2  pgoyette 			bim = (void *)(btinfo_modulelist + 1);
    414  1.61.2.2  pgoyette 			for (i = 0; i < btinfo_modulelist->num; i++, bim++)
    415  1.61.2.2  pgoyette 				bim->base -= efi_loadaddr;
    416  1.61.2.2  pgoyette 			btinfo_modulelist->endpa -= efi_loadaddr;
    417  1.61.2.2  pgoyette #endif
    418      1.23        ad 			BI_ADD(btinfo_modulelist, BTINFO_MODULELIST,
    419      1.23        ad 			    btinfo_modulelist_size);
    420      1.23        ad 		}
    421      1.23        ad 	}
    422       1.1     perry 
    423      1.47  uebayasi 	userconf_init();
    424      1.47  uebayasi 	if (btinfo_userconfcommands != NULL)
    425      1.47  uebayasi 		BI_ADD(btinfo_userconfcommands, BTINFO_USERCONFCOMMANDS,
    426      1.58  jakllsch 		    btinfo_userconfcommands_size);
    427      1.47  uebayasi 
    428       1.1     perry #ifdef DEBUG
    429       1.8  christos 	printf("Start @ 0x%lx [%ld=0x%lx-0x%lx]...\n", marks[MARK_ENTRY],
    430       1.7  christos 	    marks[MARK_NSYM], marks[MARK_SYM], marks[MARK_END]);
    431       1.1     perry #endif
    432       1.1     perry 
    433       1.8  christos 	btinfo_symtab.nsym = marks[MARK_NSYM];
    434       1.8  christos 	btinfo_symtab.ssym = marks[MARK_SYM];
    435       1.8  christos 	btinfo_symtab.esym = marks[MARK_END];
    436       1.8  christos 	BI_ADD(&btinfo_symtab, BTINFO_SYMTAB, sizeof(struct btinfo_symtab));
    437       1.8  christos 
    438      1.42  jmcneill 	/* set new video mode if necessary */
    439      1.42  jmcneill 	vbe_commit();
    440      1.42  jmcneill 	BI_ADD(&btinfo_framebuffer, BTINFO_FRAMEBUFFER,
    441      1.42  jmcneill 	    sizeof(struct btinfo_framebuffer));
    442      1.42  jmcneill 
    443      1.40        ad 	if (callback != NULL)
    444      1.40        ad 		(*callback)();
    445  1.61.2.2  pgoyette #ifdef EFIBOOT
    446  1.61.2.2  pgoyette 	/* Copy bootinfo to safe arena. */
    447  1.61.2.2  pgoyette 	for (i = 0; i < bootinfo->nentries; i++) {
    448  1.61.2.2  pgoyette 		struct btinfo_common *bi = (void *)(u_long)bootinfo->entry[i];
    449  1.61.2.2  pgoyette 		char *p = alloc(bi->len);
    450  1.61.2.2  pgoyette 		memcpy(p, bi, bi->len);
    451  1.61.2.2  pgoyette 		bootinfo->entry[i] = vtophys(p);
    452  1.61.2.2  pgoyette 	}
    453  1.61.2.2  pgoyette 
    454  1.61.2.2  pgoyette 	efi_kernel_start = marks[MARK_START];
    455  1.61.2.2  pgoyette 	efi_kernel_size = image_end - efi_loadaddr - efi_kernel_start;
    456  1.61.2.2  pgoyette #endif
    457      1.15       dbj 	startprog(marks[MARK_ENTRY], BOOT_NARGS, boot_argv,
    458  1.61.2.1  pgoyette 	    x86_trunc_page(basemem * 1024));
    459       1.1     perry 	panic("exec returned");
    460       1.1     perry 
    461       1.4  drochner out:
    462       1.4  drochner 	BI_FREE();
    463      1.60      maxv 	bootinfo = NULL;
    464      1.21  junyoung 	return -1;
    465       1.1     perry }
    466      1.23        ad 
    467  1.61.2.2  pgoyette int
    468  1.61.2.2  pgoyette count_netbsd(const char *file, u_long *rsz)
    469  1.61.2.2  pgoyette {
    470  1.61.2.2  pgoyette 	u_long marks[MARK_MAX];
    471  1.61.2.2  pgoyette 	char kdev[64];
    472  1.61.2.3  pgoyette 	char base_path[64] = "/";
    473  1.61.2.2  pgoyette 	struct stat st;
    474  1.61.2.2  pgoyette 	boot_module_t *bm;
    475  1.61.2.2  pgoyette 	u_long sz;
    476  1.61.2.2  pgoyette 	int err, fd;
    477  1.61.2.2  pgoyette 
    478  1.61.2.3  pgoyette 	howto = AB_SILENT;
    479  1.61.2.3  pgoyette 
    480  1.61.2.2  pgoyette 	memset(marks, 0, sizeof(marks));
    481  1.61.2.3  pgoyette 	if ((fd = loadfile(file, marks, COUNT_KERNEL | LOAD_NOTE)) == -1)
    482  1.61.2.2  pgoyette 		return -1;
    483  1.61.2.2  pgoyette 	close(fd);
    484  1.61.2.2  pgoyette 	marks[MARK_END] = (((u_long) marks[MARK_END] + sizeof(int) - 1)) &
    485  1.61.2.2  pgoyette 	    (-sizeof(int));
    486  1.61.2.2  pgoyette 	sz = marks[MARK_END];
    487  1.61.2.2  pgoyette 
    488  1.61.2.2  pgoyette 	/* The modules must be allocated after the kernel */
    489  1.61.2.2  pgoyette 	if (boot_modules_enabled) {
    490  1.61.2.2  pgoyette 		extract_device(file, kdev, sizeof(kdev));
    491  1.61.2.2  pgoyette 		module_base_path(base_path, sizeof(base_path));
    492  1.61.2.2  pgoyette 
    493  1.61.2.2  pgoyette 		/* If the root fs type is unusual, load its module. */
    494  1.61.2.2  pgoyette 		if (fsmod != NULL)
    495  1.61.2.3  pgoyette 			module_add_common(fsmod, BM_TYPE_KMOD);
    496  1.61.2.2  pgoyette 
    497  1.61.2.2  pgoyette 		for (bm = boot_modules; bm; bm = bm->bm_next) {
    498  1.61.2.2  pgoyette 			fd = module_open(bm, 0, kdev, base_path, false);
    499  1.61.2.2  pgoyette 			if (fd == -1)
    500  1.61.2.2  pgoyette 				continue;
    501  1.61.2.3  pgoyette 			sz = (sz + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1);
    502  1.61.2.2  pgoyette 			err = fstat(fd, &st);
    503  1.61.2.2  pgoyette 			if (err == -1 || st.st_size == -1) {
    504  1.61.2.2  pgoyette 				close(fd);
    505  1.61.2.2  pgoyette 				continue;
    506  1.61.2.2  pgoyette 			}
    507  1.61.2.2  pgoyette 			sz += st.st_size;
    508  1.61.2.2  pgoyette 			close(fd);
    509  1.61.2.2  pgoyette 		}
    510  1.61.2.2  pgoyette 	}
    511  1.61.2.2  pgoyette 
    512  1.61.2.2  pgoyette 	*rsz = sz;
    513  1.61.2.2  pgoyette 	return 0;
    514  1.61.2.2  pgoyette }
    515  1.61.2.2  pgoyette 
    516      1.41  jmcneill static void
    517      1.41  jmcneill extract_device(const char *path, char *buf, size_t buflen)
    518      1.41  jmcneill {
    519      1.59  jakllsch 	size_t i;
    520      1.41  jmcneill 
    521      1.41  jmcneill 	if (strchr(path, ':') != NULL) {
    522      1.41  jmcneill 		for (i = 0; i < buflen - 2 && path[i] != ':'; i++)
    523      1.41  jmcneill 			buf[i] = path[i];
    524      1.41  jmcneill 		buf[i++] = ':';
    525      1.41  jmcneill 		buf[i] = '\0';
    526      1.41  jmcneill 	} else
    527      1.41  jmcneill 		buf[0] = '\0';
    528      1.41  jmcneill }
    529      1.41  jmcneill 
    530      1.26        ad static const char *
    531  1.61.2.2  pgoyette module_path(boot_module_t *bm, const char *kdev, const char *base_path)
    532      1.26        ad {
    533      1.26        ad 	static char buf[256];
    534      1.41  jmcneill 	char name_buf[256], dev_buf[64];
    535      1.41  jmcneill 	const char *name, *name2, *p;
    536      1.26        ad 
    537      1.26        ad 	name = bm->bm_path;
    538      1.33     joerg 	for (name2 = name; *name2; ++name2) {
    539      1.33     joerg 		if (*name2 == ' ' || *name2 == '\t') {
    540      1.33     joerg 			strlcpy(name_buf, name, sizeof(name_buf));
    541      1.59  jakllsch 			if ((uintptr_t)name2 - (uintptr_t)name < sizeof(name_buf))
    542      1.33     joerg 				name_buf[name2 - name] = '\0';
    543      1.33     joerg 			name = name_buf;
    544      1.33     joerg 			break;
    545      1.33     joerg 		}
    546      1.33     joerg 	}
    547      1.41  jmcneill 	if ((p = strchr(name, ':')) != NULL) {
    548      1.41  jmcneill 		/* device specified, use it */
    549      1.41  jmcneill 		if (p[1] == '/')
    550      1.41  jmcneill 			snprintf(buf, sizeof(buf), "%s", name);
    551      1.41  jmcneill 		else {
    552      1.41  jmcneill 			p++;
    553      1.41  jmcneill 			extract_device(name, dev_buf, sizeof(dev_buf));
    554      1.41  jmcneill 			snprintf(buf, sizeof(buf), "%s%s/%s/%s.kmod",
    555  1.61.2.2  pgoyette 			    dev_buf, base_path, p, p);
    556      1.41  jmcneill 		}
    557      1.41  jmcneill 	} else {
    558      1.41  jmcneill 		/* device not specified; load from kernel device if known */
    559      1.58  jakllsch 		if (name[0] == '/')
    560      1.41  jmcneill 			snprintf(buf, sizeof(buf), "%s%s", kdev, name);
    561      1.41  jmcneill 		else
    562      1.41  jmcneill 			snprintf(buf, sizeof(buf), "%s%s/%s/%s.kmod",
    563  1.61.2.2  pgoyette 			    kdev, base_path, name, name);
    564      1.41  jmcneill 	}
    565      1.33     joerg 
    566      1.26        ad 	return buf;
    567      1.26        ad }
    568      1.26        ad 
    569      1.36  christos static int
    570  1.61.2.2  pgoyette module_open(boot_module_t *bm, int mode, const char *kdev,
    571  1.61.2.2  pgoyette     const char *base_path, bool doload)
    572      1.28     chris {
    573      1.28     chris 	int fd;
    574      1.28     chris 	const char *path;
    575      1.36  christos 
    576      1.28     chris 	/* check the expanded path first */
    577  1.61.2.2  pgoyette 	path = module_path(bm, kdev, base_path);
    578      1.28     chris 	fd = open(path, mode);
    579      1.41  jmcneill 	if (fd != -1) {
    580      1.41  jmcneill 		if ((howto & AB_SILENT) == 0 && doload)
    581      1.41  jmcneill 			printf("Loading %s ", path);
    582      1.41  jmcneill 	} else {
    583      1.28     chris 		/* now attempt the raw path provided */
    584      1.28     chris 		fd = open(bm->bm_path, mode);
    585      1.41  jmcneill 		if (fd != -1 && (howto & AB_SILENT) == 0 && doload)
    586      1.41  jmcneill 			printf("Loading %s ", bm->bm_path);
    587      1.41  jmcneill 	}
    588      1.41  jmcneill 	if (!doload && fd == -1) {
    589      1.41  jmcneill 		printf("WARNING: couldn't open %s", bm->bm_path);
    590      1.41  jmcneill 		if (strcmp(bm->bm_path, path) != 0)
    591      1.41  jmcneill 			printf(" (%s)", path);
    592      1.41  jmcneill 		printf("\n");
    593      1.28     chris 	}
    594      1.28     chris 	return fd;
    595      1.28     chris }
    596      1.28     chris 
    597      1.23        ad static void
    598  1.61.2.2  pgoyette module_base_path(char *buf, size_t bufsize)
    599      1.23        ad {
    600      1.30     joerg 	const char *machine;
    601      1.23        ad 
    602      1.30     joerg 	switch (netbsd_elf_class) {
    603      1.30     joerg 	case ELFCLASS32:
    604      1.30     joerg 		machine = "i386";
    605      1.30     joerg 		break;
    606      1.30     joerg 	case ELFCLASS64:
    607      1.30     joerg 		machine = "amd64";
    608      1.30     joerg 		break;
    609      1.30     joerg 	default:
    610      1.30     joerg 		machine = "generic";
    611      1.30     joerg 		break;
    612      1.30     joerg 	}
    613      1.30     joerg 	if (netbsd_version / 1000000 % 100 == 99) {
    614      1.30     joerg 		/* -current */
    615  1.61.2.2  pgoyette 		snprintf(buf, bufsize,
    616      1.38     rmind 		    "/stand/%s/%d.%d.%d/modules", machine,
    617      1.30     joerg 		    netbsd_version / 100000000,
    618      1.30     joerg 		    netbsd_version / 1000000 % 100,
    619      1.30     joerg 		    netbsd_version / 100 % 100);
    620      1.30     joerg 	} else if (netbsd_version != 0) {
    621      1.30     joerg 		/* release */
    622  1.61.2.2  pgoyette 		snprintf(buf, bufsize,
    623      1.38     rmind 		    "/stand/%s/%d.%d/modules", machine,
    624      1.30     joerg 		    netbsd_version / 100000000,
    625      1.30     joerg 		    netbsd_version / 1000000 % 100);
    626      1.30     joerg 	}
    627  1.61.2.2  pgoyette }
    628  1.61.2.2  pgoyette 
    629  1.61.2.2  pgoyette static void
    630  1.61.2.2  pgoyette module_init(const char *kernel_path)
    631  1.61.2.2  pgoyette {
    632  1.61.2.2  pgoyette 	struct bi_modulelist_entry *bi;
    633  1.61.2.2  pgoyette 	struct stat st;
    634  1.61.2.2  pgoyette 	char kdev[64];
    635  1.61.2.2  pgoyette 	char *buf;
    636  1.61.2.2  pgoyette 	boot_module_t *bm;
    637  1.61.2.2  pgoyette 	ssize_t len;
    638  1.61.2.2  pgoyette 	off_t off;
    639  1.61.2.2  pgoyette 	int err, fd, nfail = 0;
    640  1.61.2.2  pgoyette 
    641  1.61.2.2  pgoyette 	extract_device(kernel_path, kdev, sizeof(kdev));
    642  1.61.2.2  pgoyette 	module_base_path(module_base, sizeof(module_base));
    643      1.30     joerg 
    644      1.23        ad 	/* First, see which modules are valid and calculate btinfo size */
    645      1.23        ad 	len = sizeof(struct btinfo_modulelist);
    646      1.23        ad 	for (bm = boot_modules; bm; bm = bm->bm_next) {
    647  1.61.2.2  pgoyette 		fd = module_open(bm, 0, kdev, module_base, false);
    648      1.23        ad 		if (fd == -1) {
    649      1.23        ad 			bm->bm_len = -1;
    650      1.41  jmcneill 			++nfail;
    651      1.23        ad 			continue;
    652      1.23        ad 		}
    653      1.23        ad 		err = fstat(fd, &st);
    654      1.24        ad 		if (err == -1 || st.st_size == -1) {
    655      1.28     chris 			printf("WARNING: couldn't stat %s\n", bm->bm_path);
    656      1.23        ad 			close(fd);
    657      1.23        ad 			bm->bm_len = -1;
    658      1.41  jmcneill 			++nfail;
    659      1.23        ad 			continue;
    660      1.23        ad 		}
    661      1.23        ad 		bm->bm_len = st.st_size;
    662      1.23        ad 		close(fd);
    663      1.23        ad 		len += sizeof(struct bi_modulelist_entry);
    664      1.23        ad 	}
    665      1.23        ad 
    666      1.23        ad 	/* Allocate the module list */
    667      1.23        ad 	btinfo_modulelist = alloc(len);
    668      1.23        ad 	if (btinfo_modulelist == NULL) {
    669      1.23        ad 		printf("WARNING: couldn't allocate module list\n");
    670      1.43   tsutsui 		wait_sec(MODULE_WARNING_SEC);
    671      1.23        ad 		return;
    672      1.23        ad 	}
    673      1.23        ad 	memset(btinfo_modulelist, 0, len);
    674      1.23        ad 	btinfo_modulelist_size = len;
    675      1.23        ad 
    676      1.23        ad 	/* Fill in btinfo structure */
    677      1.23        ad 	buf = (char *)btinfo_modulelist;
    678      1.23        ad 	btinfo_modulelist->num = 0;
    679      1.23        ad 	off = sizeof(struct btinfo_modulelist);
    680      1.23        ad 
    681      1.23        ad 	for (bm = boot_modules; bm; bm = bm->bm_next) {
    682      1.23        ad 		if (bm->bm_len == -1)
    683      1.23        ad 			continue;
    684  1.61.2.2  pgoyette 		fd = module_open(bm, 0, kdev, module_base, true);
    685      1.41  jmcneill 		if (fd == -1)
    686      1.23        ad 			continue;
    687      1.24        ad 		image_end = (image_end + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1);
    688      1.52  jakllsch 		len = pread(fd, (void *)(uintptr_t)image_end, SSIZE_MAX);
    689      1.24        ad 		if (len < bm->bm_len) {
    690      1.40        ad 			if ((howto & AB_SILENT) != 0)
    691      1.40        ad 				printf("Loading %s ", bm->bm_path);
    692      1.23        ad 			printf(" FAILED\n");
    693      1.23        ad 		} else {
    694      1.23        ad 			btinfo_modulelist->num++;
    695      1.23        ad 			bi = (struct bi_modulelist_entry *)(buf + off);
    696      1.23        ad 			off += sizeof(struct bi_modulelist_entry);
    697      1.23        ad 			strncpy(bi->path, bm->bm_path, sizeof(bi->path) - 1);
    698      1.24        ad 			bi->base = image_end;
    699      1.24        ad 			bi->len = len;
    700      1.49       tls 			switch (bm->bm_type) {
    701      1.49       tls 			    case BM_TYPE_KMOD:
    702      1.49       tls 				bi->type = BI_MODULE_ELF;
    703      1.49       tls 				break;
    704      1.49       tls 			    case BM_TYPE_IMAGE:
    705      1.49       tls 				bi->type = BI_MODULE_IMAGE;
    706      1.49       tls 				break;
    707      1.51  jmcneill 			    case BM_TYPE_FS:
    708      1.51  jmcneill 				bi->type = BI_MODULE_FS;
    709      1.51  jmcneill 				break;
    710      1.49       tls 			    case BM_TYPE_RND:
    711      1.49       tls 			    default:
    712      1.49       tls 				/* safest -- rnd checks the sha1 */
    713      1.49       tls 				bi->type = BI_MODULE_RND;
    714      1.49       tls 				break;
    715      1.49       tls 			}
    716      1.40        ad 			if ((howto & AB_SILENT) == 0)
    717      1.40        ad 				printf(" \n");
    718      1.23        ad 		}
    719      1.24        ad 		if (len > 0)
    720      1.24        ad 			image_end += len;
    721      1.23        ad 		close(fd);
    722      1.23        ad 	}
    723      1.23        ad 	btinfo_modulelist->endpa = image_end;
    724      1.41  jmcneill 
    725      1.41  jmcneill 	if (nfail > 0) {
    726      1.41  jmcneill 		printf("WARNING: %d module%s failed to load\n",
    727      1.41  jmcneill 		    nfail, nfail == 1 ? "" : "s");
    728      1.41  jmcneill #if notyet
    729      1.43   tsutsui 		wait_sec(MODULE_WARNING_SEC);
    730      1.41  jmcneill #endif
    731      1.41  jmcneill 	}
    732      1.23        ad }
    733      1.33     joerg 
    734      1.47  uebayasi static void
    735      1.47  uebayasi userconf_init(void)
    736      1.47  uebayasi {
    737      1.47  uebayasi 	size_t count, len;
    738      1.47  uebayasi 	userconf_command_t *uc;
    739      1.47  uebayasi 	char *buf;
    740      1.47  uebayasi 	off_t off;
    741      1.47  uebayasi 
    742      1.47  uebayasi 	/* Calculate the userconf commands list size */
    743      1.47  uebayasi 	count = 0;
    744      1.47  uebayasi 	for (uc = userconf_commands; uc != NULL; uc = uc->uc_next)
    745      1.47  uebayasi 		count++;
    746      1.55  jakllsch 	len = sizeof(*btinfo_userconfcommands) +
    747      1.47  uebayasi 	      count * sizeof(struct bi_userconfcommand);
    748      1.47  uebayasi 
    749      1.47  uebayasi 	/* Allocate the userconf commands list */
    750      1.47  uebayasi 	btinfo_userconfcommands = alloc(len);
    751      1.47  uebayasi 	if (btinfo_userconfcommands == NULL) {
    752      1.47  uebayasi 		printf("WARNING: couldn't allocate userconf commands list\n");
    753      1.47  uebayasi 		return;
    754      1.47  uebayasi 	}
    755      1.47  uebayasi 	memset(btinfo_userconfcommands, 0, len);
    756      1.47  uebayasi 	btinfo_userconfcommands_size = len;
    757      1.47  uebayasi 
    758      1.47  uebayasi 	/* Fill in btinfo structure */
    759      1.47  uebayasi 	buf = (char *)btinfo_userconfcommands;
    760      1.47  uebayasi 	off = sizeof(*btinfo_userconfcommands);
    761      1.47  uebayasi 	btinfo_userconfcommands->num = 0;
    762      1.47  uebayasi 	for (uc = userconf_commands; uc != NULL; uc = uc->uc_next) {
    763      1.47  uebayasi 		struct bi_userconfcommand *bi;
    764      1.47  uebayasi 		bi = (struct bi_userconfcommand *)(buf + off);
    765      1.47  uebayasi 		strncpy(bi->text, uc->uc_text, sizeof(bi->text) - 1);
    766      1.47  uebayasi 
    767      1.47  uebayasi 		off += sizeof(*bi);
    768      1.47  uebayasi 		btinfo_userconfcommands->num++;
    769      1.47  uebayasi 	}
    770      1.47  uebayasi }
    771      1.47  uebayasi 
    772      1.33     joerg int
    773      1.33     joerg exec_multiboot(const char *file, char *args)
    774      1.33     joerg {
    775      1.33     joerg 	struct multiboot_info *mbi;
    776      1.33     joerg 	struct multiboot_module *mbm;
    777      1.33     joerg 	struct bi_modulelist_entry *bim;
    778  1.61.2.1  pgoyette 	int i, len;
    779  1.61.2.1  pgoyette 	u_long marks[MARK_MAX];
    780  1.61.2.1  pgoyette 	u_long extmem;
    781  1.61.2.1  pgoyette 	u_long basemem;
    782  1.61.2.1  pgoyette 	char *cmdline;
    783      1.33     joerg 
    784      1.33     joerg 	mbi = alloc(sizeof(struct multiboot_info));
    785      1.33     joerg 	mbi->mi_flags = MULTIBOOT_INFO_HAS_MEMORY;
    786      1.33     joerg 
    787      1.33     joerg 	if (common_load_kernel(file, &basemem, &extmem, 0, 0, marks))
    788      1.33     joerg 		goto out;
    789      1.33     joerg 
    790      1.33     joerg 	mbi->mi_mem_upper = extmem;
    791      1.33     joerg 	mbi->mi_mem_lower = basemem;
    792      1.33     joerg 
    793      1.33     joerg 	if (args) {
    794      1.33     joerg 		mbi->mi_flags |= MULTIBOOT_INFO_HAS_CMDLINE;
    795      1.33     joerg 		len = strlen(file) + 1 + strlen(args) + 1;
    796      1.33     joerg 		cmdline = alloc(len);
    797      1.33     joerg 		snprintf(cmdline, len, "%s %s", file, args);
    798      1.33     joerg 		mbi->mi_cmdline = (char *) vtophys(cmdline);
    799      1.33     joerg 	}
    800      1.33     joerg 
    801      1.33     joerg 	/* pull in any modules if necessary */
    802      1.33     joerg 	if (boot_modules_enabled) {
    803      1.41  jmcneill 		module_init(file);
    804      1.33     joerg 		if (btinfo_modulelist) {
    805      1.33     joerg 			mbm = alloc(sizeof(struct multiboot_module) *
    806      1.33     joerg 					   btinfo_modulelist->num);
    807      1.33     joerg 
    808      1.33     joerg 			bim = (struct bi_modulelist_entry *)
    809      1.33     joerg 			  (((char *) btinfo_modulelist) +
    810      1.33     joerg 			   sizeof(struct btinfo_modulelist));
    811      1.33     joerg 			for (i = 0; i < btinfo_modulelist->num; i++) {
    812      1.33     joerg 				mbm[i].mmo_start = bim->base;
    813      1.33     joerg 				mbm[i].mmo_end = bim->base + bim->len;
    814      1.33     joerg 				mbm[i].mmo_string = (char *)vtophys(bim->path);
    815      1.33     joerg 				mbm[i].mmo_reserved = 0;
    816      1.33     joerg 				bim++;
    817      1.33     joerg 			}
    818      1.33     joerg 			mbi->mi_flags |= MULTIBOOT_INFO_HAS_MODS;
    819      1.33     joerg 			mbi->mi_mods_count = btinfo_modulelist->num;
    820      1.33     joerg 			mbi->mi_mods_addr = vtophys(mbm);
    821      1.33     joerg 		}
    822      1.33     joerg 	}
    823      1.33     joerg 
    824      1.33     joerg #ifdef DEBUG
    825      1.33     joerg 	printf("Start @ 0x%lx [%ld=0x%lx-0x%lx]...\n", marks[MARK_ENTRY],
    826      1.33     joerg 	    marks[MARK_NSYM], marks[MARK_SYM], marks[MARK_END]);
    827      1.33     joerg #endif
    828      1.33     joerg 
    829      1.33     joerg #if 0
    830      1.33     joerg 	if (btinfo_symtab.nsym) {
    831      1.33     joerg 		mbi->mi_flags |= MULTIBOOT_INFO_HAS_ELF_SYMS;
    832      1.33     joerg 		mbi->mi_elfshdr_addr = marks[MARK_SYM];
    833      1.33     joerg 	btinfo_symtab.nsym = marks[MARK_NSYM];
    834      1.33     joerg 	btinfo_symtab.ssym = marks[MARK_SYM];
    835      1.33     joerg 	btinfo_symtab.esym = marks[MARK_END];
    836      1.33     joerg #endif
    837      1.33     joerg 
    838      1.33     joerg 	multiboot(marks[MARK_ENTRY], vtophys(mbi),
    839  1.61.2.1  pgoyette 	    x86_trunc_page(mbi->mi_mem_lower * 1024));
    840      1.33     joerg 	panic("exec returned");
    841      1.33     joerg 
    842      1.33     joerg out:
    843  1.61.2.1  pgoyette 	dealloc(mbi, 0);
    844      1.33     joerg 	return -1;
    845      1.33     joerg }
    846      1.40        ad 
    847      1.40        ad void
    848      1.40        ad x86_progress(const char *fmt, ...)
    849      1.40        ad {
    850      1.40        ad 	va_list ap;
    851      1.40        ad 
    852      1.40        ad 	if ((howto & AB_SILENT) != 0)
    853      1.40        ad 		return;
    854      1.40        ad 	va_start(ap, fmt);
    855      1.40        ad 	vprintf(fmt, ap);
    856      1.40        ad 	va_end(ap);
    857      1.40        ad }
    858