xref: /netbsd-src/sys/arch/i386/stand/lib/exec.c (revision 6a493d6bc668897c91594964a732d38505b70cbb)
1 /*	$NetBSD: exec.c,v 1.55 2013/11/27 18:29:45 jakllsch 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 <i386/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 void
181 fs_add(char *name)
182 {
183 	return module_add_common(name, BM_TYPE_FS);
184 }
185 
186 static void
187 module_add_common(char *name, uint8_t type)
188 {
189 	boot_module_t *bm, *bmp;
190 	size_t len;
191 	char *str;
192 
193 	while (*name == ' ' || *name == '\t')
194 		++name;
195 
196 	bm = alloc(sizeof(boot_module_t));
197 	len = strlen(name) + 1;
198 	str = alloc(len);
199 	if (bm == NULL || str == NULL) {
200 		printf("couldn't allocate module\n");
201 		return;
202 	}
203 	memcpy(str, name, len);
204 	bm->bm_path = str;
205 	bm->bm_next = NULL;
206 	bm->bm_type = type;
207 	if (boot_modules == NULL)
208 		boot_modules = bm;
209 	else {
210 		for (bmp = boot_modules; bmp->bm_next;
211 		    bmp = bmp->bm_next)
212 			;
213 		bmp->bm_next = bm;
214 	}
215 }
216 
217 void
218 userconf_add(char *cmd)
219 {
220 	userconf_command_t *uc;
221 	size_t len;
222 	char *text;
223 
224 	while (*cmd == ' ' || *cmd == '\t')
225 		++cmd;
226 
227 	uc = alloc(sizeof(*uc));
228 	if (uc == NULL) {
229 		printf("couldn't allocate command\n");
230 		return;
231 	}
232 
233 	len = strlen(cmd) + 1;
234 	text = alloc(len);
235 	if (text == NULL) {
236 		dealloc(uc, sizeof(*uc));
237 		printf("couldn't allocate command\n");
238 		return;
239 	}
240 	memcpy(text, cmd, len);
241 
242 	uc->uc_text = text;
243 	uc->uc_len = len;
244 	uc->uc_next = NULL;
245 
246 	if (userconf_commands == NULL)
247 		userconf_commands = uc;
248 	else {
249 		userconf_command_t *ucp;
250 		for (ucp = userconf_commands; ucp->uc_next != NULL;
251 		     ucp = ucp->uc_next)
252 			;
253 		ucp->uc_next = uc;
254 	}
255 }
256 
257 static int
258 common_load_kernel(const char *file, u_long *basemem, u_long *extmem,
259     physaddr_t loadaddr, int floppy, u_long marks[MARK_MAX])
260 {
261 	int fd;
262 #ifdef XMS
263 	u_long		xmsmem;
264 	physaddr_t	origaddr = loadaddr;
265 #endif
266 
267 	*extmem = getextmem();
268 	*basemem = getbasemem();
269 
270 #ifdef XMS
271 	if ((getextmem1() == 0) && (xmsmem = checkxms())) {
272 	        u_long kernsize;
273 
274 		/*
275 		 * With "CONSERVATIVE_MEMDETECT", extmem is 0 because
276 		 *  getextmem() is getextmem1(). Without, the "smart"
277 		 *  methods could fail to report all memory as well.
278 		 * xmsmem is a few kB less than the actual size, but
279 		 *  better than nothing.
280 		 */
281 		if (xmsmem > *extmem)
282 			*extmem = xmsmem;
283 		/*
284 		 * Get the size of the kernel
285 		 */
286 		marks[MARK_START] = loadaddr;
287 		if ((fd = loadfile(file, marks, COUNT_KERNEL)) == -1)
288 			return EIO;
289 		close(fd);
290 
291 		kernsize = marks[MARK_END];
292 		kernsize = (kernsize + 1023) / 1024;
293 
294 		loadaddr = xmsalloc(kernsize);
295 		if (!loadaddr)
296 			return ENOMEM;
297 	}
298 #endif
299 	marks[MARK_START] = loadaddr;
300 	if ((fd = loadfile(file, marks,
301 	    LOAD_KERNEL & ~(floppy ? LOAD_BACKWARDS : 0))) == -1)
302 		return EIO;
303 
304 	close(fd);
305 
306 	/* If the root fs type is unusual, load its module. */
307 	if (fsmod != NULL)
308 		module_add(fsmod);
309 
310 	/*
311 	 * Gather some information for the kernel. Do this after the
312 	 * "point of no return" to avoid memory leaks.
313 	 * (but before DOS might be trashed in the XMS case)
314 	 */
315 #ifdef PASS_BIOSGEOM
316 	bi_getbiosgeom();
317 #endif
318 #ifdef PASS_MEMMAP
319 	bi_getmemmap();
320 #endif
321 
322 #ifdef XMS
323 	if (loadaddr != origaddr) {
324 		/*
325 		 * We now have done our last DOS IO, so we may
326 		 * trash the OS. Copy the data from the temporary
327 		 * buffer to its real address.
328 		 */
329 		marks[MARK_START] -= loadaddr;
330 		marks[MARK_END] -= loadaddr;
331 		marks[MARK_SYM] -= loadaddr;
332 		marks[MARK_END] -= loadaddr;
333 		ppbcopy(loadaddr, origaddr, marks[MARK_END]);
334 	}
335 #endif
336 	marks[MARK_END] = (((u_long) marks[MARK_END] + sizeof(int) - 1)) &
337 	    (-sizeof(int));
338 	image_end = marks[MARK_END];
339 	kernel_loaded = true;
340 
341 	return 0;
342 }
343 
344 int
345 exec_netbsd(const char *file, physaddr_t loadaddr, int boothowto, int floppy,
346 	    void (*callback)(void))
347 {
348 	uint32_t	boot_argv[BOOT_NARGS];
349 	u_long		marks[MARK_MAX];
350 	struct btinfo_symtab btinfo_symtab;
351 	u_long		extmem;
352 	u_long		basemem;
353 
354 #ifdef	DEBUG
355 	printf("exec: file=%s loadaddr=0x%lx\n",
356 	       file ? file : "NULL", loadaddr);
357 #endif
358 
359 	BI_ALLOC(32); /* ??? */
360 
361 	BI_ADD(&btinfo_console, BTINFO_CONSOLE, sizeof(struct btinfo_console));
362 
363 	howto = boothowto;
364 
365 	if (common_load_kernel(file, &basemem, &extmem, loadaddr, floppy, marks))
366 		goto out;
367 
368 	boot_argv[0] = boothowto;
369 	boot_argv[1] = 0;
370 	boot_argv[2] = vtophys(bootinfo);	/* old cyl offset */
371 	boot_argv[3] = marks[MARK_END];
372 	boot_argv[4] = extmem;
373 	boot_argv[5] = basemem;
374 
375 	/* pull in any modules if necessary */
376 	if (boot_modules_enabled) {
377 		module_init(file);
378 		if (btinfo_modulelist) {
379 			BI_ADD(btinfo_modulelist, BTINFO_MODULELIST,
380 			    btinfo_modulelist_size);
381 		}
382 	}
383 
384 	userconf_init();
385 	if (btinfo_userconfcommands != NULL)
386 		BI_ADD(btinfo_userconfcommands, BTINFO_USERCONFCOMMANDS,
387 	btinfo_userconfcommands_size);
388 
389 #ifdef DEBUG
390 	printf("Start @ 0x%lx [%ld=0x%lx-0x%lx]...\n", marks[MARK_ENTRY],
391 	    marks[MARK_NSYM], marks[MARK_SYM], marks[MARK_END]);
392 #endif
393 
394 	btinfo_symtab.nsym = marks[MARK_NSYM];
395 	btinfo_symtab.ssym = marks[MARK_SYM];
396 	btinfo_symtab.esym = marks[MARK_END];
397 	BI_ADD(&btinfo_symtab, BTINFO_SYMTAB, sizeof(struct btinfo_symtab));
398 
399 	/* set new video mode if necessary */
400 	vbe_commit();
401 	BI_ADD(&btinfo_framebuffer, BTINFO_FRAMEBUFFER,
402 	    sizeof(struct btinfo_framebuffer));
403 
404 	if (callback != NULL)
405 		(*callback)();
406 	startprog(marks[MARK_ENTRY], BOOT_NARGS, boot_argv,
407 		  x86_trunc_page(basemem*1024));
408 	panic("exec returned");
409 
410 out:
411 	BI_FREE();
412 	bootinfo = 0;
413 	return -1;
414 }
415 
416 static void
417 extract_device(const char *path, char *buf, size_t buflen)
418 {
419 	int i;
420 
421 	if (strchr(path, ':') != NULL) {
422 		for (i = 0; i < buflen - 2 && path[i] != ':'; i++)
423 			buf[i] = path[i];
424 		buf[i++] = ':';
425 		buf[i] = '\0';
426 	} else
427 		buf[0] = '\0';
428 }
429 
430 static const char *
431 module_path(boot_module_t *bm, const char *kdev)
432 {
433 	static char buf[256];
434 	char name_buf[256], dev_buf[64];
435 	const char *name, *name2, *p;
436 
437 	name = bm->bm_path;
438 	for (name2 = name; *name2; ++name2) {
439 		if (*name2 == ' ' || *name2 == '\t') {
440 			strlcpy(name_buf, name, sizeof(name_buf));
441 			if (name2 - name < sizeof(name_buf))
442 				name_buf[name2 - name] = '\0';
443 			name = name_buf;
444 			break;
445 		}
446 	}
447 	if ((p = strchr(name, ':')) != NULL) {
448 		/* device specified, use it */
449 		if (p[1] == '/')
450 			snprintf(buf, sizeof(buf), "%s", name);
451 		else {
452 			p++;
453 			extract_device(name, dev_buf, sizeof(dev_buf));
454 			snprintf(buf, sizeof(buf), "%s%s/%s/%s.kmod",
455 			    dev_buf, module_base, p, p);
456 		}
457 	} else {
458 		/* device not specified; load from kernel device if known */
459  		if (name[0] == '/')
460 			snprintf(buf, sizeof(buf), "%s%s", kdev, name);
461 		else
462 			snprintf(buf, sizeof(buf), "%s%s/%s/%s.kmod",
463 			    kdev, module_base, name, name);
464 	}
465 
466 	return buf;
467 }
468 
469 static int
470 module_open(boot_module_t *bm, int mode, const char *kdev, bool doload)
471 {
472 	int fd;
473 	const char *path;
474 
475 	/* check the expanded path first */
476 	path = module_path(bm, kdev);
477 	fd = open(path, mode);
478 	if (fd != -1) {
479 		if ((howto & AB_SILENT) == 0 && doload)
480 			printf("Loading %s ", path);
481 	} else {
482 		/* now attempt the raw path provided */
483 		fd = open(bm->bm_path, mode);
484 		if (fd != -1 && (howto & AB_SILENT) == 0 && doload)
485 			printf("Loading %s ", bm->bm_path);
486 	}
487 	if (!doload && fd == -1) {
488 		printf("WARNING: couldn't open %s", bm->bm_path);
489 		if (strcmp(bm->bm_path, path) != 0)
490 			printf(" (%s)", path);
491 		printf("\n");
492 	}
493 	return fd;
494 }
495 
496 static void
497 module_init(const char *kernel_path)
498 {
499 	struct bi_modulelist_entry *bi;
500 	struct stat st;
501 	const char *machine;
502 	char kdev[64];
503 	char *buf;
504 	boot_module_t *bm;
505 	size_t len;
506 	off_t off;
507 	int err, fd, nfail = 0;
508 
509 	extract_device(kernel_path, kdev, sizeof(kdev));
510 
511 	switch (netbsd_elf_class) {
512 	case ELFCLASS32:
513 		machine = "i386";
514 		break;
515 	case ELFCLASS64:
516 		machine = "amd64";
517 		break;
518 	default:
519 		machine = "generic";
520 		break;
521 	}
522 	if (netbsd_version / 1000000 % 100 == 99) {
523 		/* -current */
524 		snprintf(module_base, sizeof(module_base),
525 		    "/stand/%s/%d.%d.%d/modules", machine,
526 		    netbsd_version / 100000000,
527 		    netbsd_version / 1000000 % 100,
528 		    netbsd_version / 100 % 100);
529 	} else if (netbsd_version != 0) {
530 		/* release */
531 		snprintf(module_base, sizeof(module_base),
532 		    "/stand/%s/%d.%d/modules", machine,
533 		    netbsd_version / 100000000,
534 		    netbsd_version / 1000000 % 100);
535 	}
536 
537 	/* First, see which modules are valid and calculate btinfo size */
538 	len = sizeof(struct btinfo_modulelist);
539 	for (bm = boot_modules; bm; bm = bm->bm_next) {
540 		fd = module_open(bm, 0, kdev, false);
541 		if (fd == -1) {
542 			bm->bm_len = -1;
543 			++nfail;
544 			continue;
545 		}
546 		err = fstat(fd, &st);
547 		if (err == -1 || st.st_size == -1) {
548 			printf("WARNING: couldn't stat %s\n", bm->bm_path);
549 			close(fd);
550 			bm->bm_len = -1;
551 			++nfail;
552 			continue;
553 		}
554 		bm->bm_len = st.st_size;
555 		close(fd);
556 		len += sizeof(struct bi_modulelist_entry);
557 	}
558 
559 	/* Allocate the module list */
560 	btinfo_modulelist = alloc(len);
561 	if (btinfo_modulelist == NULL) {
562 		printf("WARNING: couldn't allocate module list\n");
563 		wait_sec(MODULE_WARNING_SEC);
564 		return;
565 	}
566 	memset(btinfo_modulelist, 0, len);
567 	btinfo_modulelist_size = len;
568 
569 	/* Fill in btinfo structure */
570 	buf = (char *)btinfo_modulelist;
571 	btinfo_modulelist->num = 0;
572 	off = sizeof(struct btinfo_modulelist);
573 
574 	for (bm = boot_modules; bm; bm = bm->bm_next) {
575 		if (bm->bm_len == -1)
576 			continue;
577 		fd = module_open(bm, 0, kdev, true);
578 		if (fd == -1)
579 			continue;
580 		image_end = (image_end + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1);
581 		len = pread(fd, (void *)(uintptr_t)image_end, SSIZE_MAX);
582 		if (len < bm->bm_len) {
583 			if ((howto & AB_SILENT) != 0)
584 				printf("Loading %s ", bm->bm_path);
585 			printf(" FAILED\n");
586 		} else {
587 			btinfo_modulelist->num++;
588 			bi = (struct bi_modulelist_entry *)(buf + off);
589 			off += sizeof(struct bi_modulelist_entry);
590 			strncpy(bi->path, bm->bm_path, sizeof(bi->path) - 1);
591 			bi->base = image_end;
592 			bi->len = len;
593 			switch (bm->bm_type) {
594 			    case BM_TYPE_KMOD:
595 				bi->type = BI_MODULE_ELF;
596 				break;
597 			    case BM_TYPE_IMAGE:
598 				bi->type = BI_MODULE_IMAGE;
599 				break;
600 			    case BM_TYPE_FS:
601 				bi->type = BI_MODULE_FS;
602 				break;
603 			    case BM_TYPE_RND:
604 			    default:
605 				/* safest -- rnd checks the sha1 */
606 				bi->type = BI_MODULE_RND;
607 				break;
608 			}
609 			if ((howto & AB_SILENT) == 0)
610 				printf(" \n");
611 		}
612 		if (len > 0)
613 			image_end += len;
614 		close(fd);
615 	}
616 	btinfo_modulelist->endpa = image_end;
617 
618 	if (nfail > 0) {
619 		printf("WARNING: %d module%s failed to load\n",
620 		    nfail, nfail == 1 ? "" : "s");
621 #if notyet
622 		wait_sec(MODULE_WARNING_SEC);
623 #endif
624 	}
625 }
626 
627 static void
628 userconf_init(void)
629 {
630 	size_t count, len;
631 	userconf_command_t *uc;
632 	char *buf;
633 	off_t off;
634 
635 	/* Calculate the userconf commands list size */
636 	count = 0;
637 	for (uc = userconf_commands; uc != NULL; uc = uc->uc_next)
638 		count++;
639 	len = sizeof(*btinfo_userconfcommands) +
640 	      count * sizeof(struct bi_userconfcommand);
641 
642 	/* Allocate the userconf commands list */
643 	btinfo_userconfcommands = alloc(len);
644 	if (btinfo_userconfcommands == NULL) {
645 		printf("WARNING: couldn't allocate userconf commands list\n");
646 		return;
647 	}
648 	memset(btinfo_userconfcommands, 0, len);
649 	btinfo_userconfcommands_size = len;
650 
651 	/* Fill in btinfo structure */
652 	buf = (char *)btinfo_userconfcommands;
653 	off = sizeof(*btinfo_userconfcommands);
654 	btinfo_userconfcommands->num = 0;
655 	for (uc = userconf_commands; uc != NULL; uc = uc->uc_next) {
656 		struct bi_userconfcommand *bi;
657 		bi = (struct bi_userconfcommand *)(buf + off);
658 		strncpy(bi->text, uc->uc_text, sizeof(bi->text) - 1);
659 
660 		off += sizeof(*bi);
661 		btinfo_userconfcommands->num++;
662 	}
663 }
664 
665 int
666 exec_multiboot(const char *file, char *args)
667 {
668 	struct multiboot_info *mbi;
669 	struct multiboot_module *mbm;
670 	struct bi_modulelist_entry *bim;
671 	int		i, len;
672 	u_long		marks[MARK_MAX];
673 	u_long		extmem;
674 	u_long		basemem;
675 	char		*cmdline;
676 
677 	mbi = alloc(sizeof(struct multiboot_info));
678 	mbi->mi_flags = MULTIBOOT_INFO_HAS_MEMORY;
679 
680 	if (common_load_kernel(file, &basemem, &extmem, 0, 0, marks))
681 		goto out;
682 
683 	mbi->mi_mem_upper = extmem;
684 	mbi->mi_mem_lower = basemem;
685 
686 	if (args) {
687 		mbi->mi_flags |= MULTIBOOT_INFO_HAS_CMDLINE;
688 		len = strlen(file) + 1 + strlen(args) + 1;
689 		cmdline = alloc(len);
690 		snprintf(cmdline, len, "%s %s", file, args);
691 		mbi->mi_cmdline = (char *) vtophys(cmdline);
692 	}
693 
694 	/* pull in any modules if necessary */
695 	if (boot_modules_enabled) {
696 		module_init(file);
697 		if (btinfo_modulelist) {
698 			mbm = alloc(sizeof(struct multiboot_module) *
699 					   btinfo_modulelist->num);
700 
701 			bim = (struct bi_modulelist_entry *)
702 			  (((char *) btinfo_modulelist) +
703 			   sizeof(struct btinfo_modulelist));
704 			for (i = 0; i < btinfo_modulelist->num; i++) {
705 				mbm[i].mmo_start = bim->base;
706 				mbm[i].mmo_end = bim->base + bim->len;
707 				mbm[i].mmo_string = (char *)vtophys(bim->path);
708 				mbm[i].mmo_reserved = 0;
709 				bim++;
710 			}
711 			mbi->mi_flags |= MULTIBOOT_INFO_HAS_MODS;
712 			mbi->mi_mods_count = btinfo_modulelist->num;
713 			mbi->mi_mods_addr = vtophys(mbm);
714 		}
715 	}
716 
717 #ifdef DEBUG
718 	printf("Start @ 0x%lx [%ld=0x%lx-0x%lx]...\n", marks[MARK_ENTRY],
719 	    marks[MARK_NSYM], marks[MARK_SYM], marks[MARK_END]);
720 #endif
721 
722 
723 #if 0
724 	if (btinfo_symtab.nsym) {
725 		mbi->mi_flags |= MULTIBOOT_INFO_HAS_ELF_SYMS;
726 		mbi->mi_elfshdr_addr = marks[MARK_SYM];
727 	btinfo_symtab.nsym = marks[MARK_NSYM];
728 	btinfo_symtab.ssym = marks[MARK_SYM];
729 	btinfo_symtab.esym = marks[MARK_END];
730 #endif
731 
732 	multiboot(marks[MARK_ENTRY], vtophys(mbi),
733 		  x86_trunc_page(mbi->mi_mem_lower*1024));
734 	panic("exec returned");
735 
736 out:
737         dealloc(mbi, 0);
738 	return -1;
739 }
740 
741 void
742 x86_progress(const char *fmt, ...)
743 {
744 	va_list ap;
745 
746 	if ((howto & AB_SILENT) != 0)
747 		return;
748 	va_start(ap, fmt);
749 	vprintf(fmt, ap);
750 	va_end(ap);
751 }
752