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