exec.c revision 1.50 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
304 /*
305 * Gather some information for the kernel. Do this after the
306 * "point of no return" to avoid memory leaks.
307 * (but before DOS might be trashed in the XMS case)
308 */
309 #ifdef PASS_BIOSGEOM
310 bi_getbiosgeom();
311 #endif
312 #ifdef PASS_MEMMAP
313 bi_getmemmap();
314 #endif
315
316 #ifdef XMS
317 if (loadaddr != origaddr) {
318 /*
319 * We now have done our last DOS IO, so we may
320 * trash the OS. Copy the data from the temporary
321 * buffer to its real address.
322 */
323 marks[MARK_START] -= loadaddr;
324 marks[MARK_END] -= loadaddr;
325 marks[MARK_SYM] -= loadaddr;
326 marks[MARK_END] -= loadaddr;
327 ppbcopy(loadaddr, origaddr, marks[MARK_END]);
328 }
329 #endif
330 marks[MARK_END] = (((u_long) marks[MARK_END] + sizeof(int) - 1)) &
331 (-sizeof(int));
332 image_end = marks[MARK_END];
333 kernel_loaded = true;
334
335 return 0;
336 }
337
338 int
339 exec_netbsd(const char *file, physaddr_t loadaddr, int boothowto, int floppy,
340 void (*callback)(void))
341 {
342 u_long boot_argv[BOOT_NARGS];
343 u_long marks[MARK_MAX];
344 struct btinfo_symtab btinfo_symtab;
345 u_long extmem;
346 u_long basemem;
347
348 #ifdef DEBUG
349 printf("exec: file=%s loadaddr=0x%lx\n",
350 file ? file : "NULL", loadaddr);
351 #endif
352
353 BI_ALLOC(32); /* ??? */
354
355 BI_ADD(&btinfo_console, BTINFO_CONSOLE, sizeof(struct btinfo_console));
356
357 howto = boothowto;
358
359 if (common_load_kernel(file, &basemem, &extmem, loadaddr, floppy, marks))
360 goto out;
361
362 boot_argv[0] = boothowto;
363 boot_argv[1] = 0;
364 boot_argv[2] = vtophys(bootinfo); /* old cyl offset */
365 boot_argv[3] = marks[MARK_END];
366 boot_argv[4] = extmem;
367 boot_argv[5] = basemem;
368
369 /* pull in any modules if necessary */
370 if (boot_modules_enabled) {
371 module_init(file);
372 if (btinfo_modulelist) {
373 BI_ADD(btinfo_modulelist, BTINFO_MODULELIST,
374 btinfo_modulelist_size);
375 }
376 }
377
378 userconf_init();
379 if (btinfo_userconfcommands != NULL)
380 BI_ADD(btinfo_userconfcommands, BTINFO_USERCONFCOMMANDS,
381 btinfo_userconfcommands_size);
382
383 #ifdef DEBUG
384 printf("Start @ 0x%lx [%ld=0x%lx-0x%lx]...\n", marks[MARK_ENTRY],
385 marks[MARK_NSYM], marks[MARK_SYM], marks[MARK_END]);
386 #endif
387
388 btinfo_symtab.nsym = marks[MARK_NSYM];
389 btinfo_symtab.ssym = marks[MARK_SYM];
390 btinfo_symtab.esym = marks[MARK_END];
391 BI_ADD(&btinfo_symtab, BTINFO_SYMTAB, sizeof(struct btinfo_symtab));
392
393 /* set new video mode if necessary */
394 vbe_commit();
395 BI_ADD(&btinfo_framebuffer, BTINFO_FRAMEBUFFER,
396 sizeof(struct btinfo_framebuffer));
397
398 if (callback != NULL)
399 (*callback)();
400 startprog(marks[MARK_ENTRY], BOOT_NARGS, boot_argv,
401 x86_trunc_page(basemem*1024));
402 panic("exec returned");
403
404 out:
405 BI_FREE();
406 bootinfo = 0;
407 return -1;
408 }
409
410 static void
411 extract_device(const char *path, char *buf, size_t buflen)
412 {
413 int i;
414
415 if (strchr(path, ':') != NULL) {
416 for (i = 0; i < buflen - 2 && path[i] != ':'; i++)
417 buf[i] = path[i];
418 buf[i++] = ':';
419 buf[i] = '\0';
420 } else
421 buf[0] = '\0';
422 }
423
424 static const char *
425 module_path(boot_module_t *bm, const char *kdev)
426 {
427 static char buf[256];
428 char name_buf[256], dev_buf[64];
429 const char *name, *name2, *p;
430
431 name = bm->bm_path;
432 for (name2 = name; *name2; ++name2) {
433 if (*name2 == ' ' || *name2 == '\t') {
434 strlcpy(name_buf, name, sizeof(name_buf));
435 if (name2 - name < sizeof(name_buf))
436 name_buf[name2 - name] = '\0';
437 name = name_buf;
438 break;
439 }
440 }
441 if ((p = strchr(name, ':')) != NULL) {
442 /* device specified, use it */
443 if (p[1] == '/')
444 snprintf(buf, sizeof(buf), "%s", name);
445 else {
446 p++;
447 extract_device(name, dev_buf, sizeof(dev_buf));
448 snprintf(buf, sizeof(buf), "%s%s/%s/%s.kmod",
449 dev_buf, module_base, p, p);
450 }
451 } else {
452 /* device not specified; load from kernel device if known */
453 if (name[0] == '/')
454 snprintf(buf, sizeof(buf), "%s%s", kdev, name);
455 else
456 snprintf(buf, sizeof(buf), "%s%s/%s/%s.kmod",
457 kdev, module_base, name, name);
458 }
459
460 return buf;
461 }
462
463 static int
464 module_open(boot_module_t *bm, int mode, const char *kdev, bool doload)
465 {
466 int fd;
467 const char *path;
468
469 /* check the expanded path first */
470 path = module_path(bm, kdev);
471 fd = open(path, mode);
472 if (fd != -1) {
473 if ((howto & AB_SILENT) == 0 && doload)
474 printf("Loading %s ", path);
475 } else {
476 /* now attempt the raw path provided */
477 fd = open(bm->bm_path, mode);
478 if (fd != -1 && (howto & AB_SILENT) == 0 && doload)
479 printf("Loading %s ", bm->bm_path);
480 }
481 if (!doload && fd == -1) {
482 printf("WARNING: couldn't open %s", bm->bm_path);
483 if (strcmp(bm->bm_path, path) != 0)
484 printf(" (%s)", path);
485 printf("\n");
486 }
487 return fd;
488 }
489
490 static void
491 module_init(const char *kernel_path)
492 {
493 struct bi_modulelist_entry *bi;
494 struct stat st;
495 const char *machine;
496 char kdev[64];
497 char *buf;
498 boot_module_t *bm;
499 size_t len;
500 off_t off;
501 int err, fd, nfail = 0;
502
503 extract_device(kernel_path, kdev, sizeof(kdev));
504
505 switch (netbsd_elf_class) {
506 case ELFCLASS32:
507 machine = "i386";
508 break;
509 case ELFCLASS64:
510 machine = "amd64";
511 break;
512 default:
513 machine = "generic";
514 break;
515 }
516 if (netbsd_version / 1000000 % 100 == 99) {
517 /* -current */
518 snprintf(module_base, sizeof(module_base),
519 "/stand/%s/%d.%d.%d/modules", machine,
520 netbsd_version / 100000000,
521 netbsd_version / 1000000 % 100,
522 netbsd_version / 100 % 100);
523 } else if (netbsd_version != 0) {
524 /* release */
525 snprintf(module_base, sizeof(module_base),
526 "/stand/%s/%d.%d/modules", machine,
527 netbsd_version / 100000000,
528 netbsd_version / 1000000 % 100);
529 }
530
531 /* First, see which modules are valid and calculate btinfo size */
532 len = sizeof(struct btinfo_modulelist);
533 for (bm = boot_modules; bm; bm = bm->bm_next) {
534 fd = module_open(bm, 0, kdev, false);
535 if (fd == -1) {
536 bm->bm_len = -1;
537 ++nfail;
538 continue;
539 }
540 err = fstat(fd, &st);
541 if (err == -1 || st.st_size == -1) {
542 printf("WARNING: couldn't stat %s\n", bm->bm_path);
543 close(fd);
544 bm->bm_len = -1;
545 ++nfail;
546 continue;
547 }
548 bm->bm_len = st.st_size;
549 close(fd);
550 len += sizeof(struct bi_modulelist_entry);
551 }
552
553 /* Allocate the module list */
554 btinfo_modulelist = alloc(len);
555 if (btinfo_modulelist == NULL) {
556 printf("WARNING: couldn't allocate module list\n");
557 wait_sec(MODULE_WARNING_SEC);
558 return;
559 }
560 memset(btinfo_modulelist, 0, len);
561 btinfo_modulelist_size = len;
562
563 /* Fill in btinfo structure */
564 buf = (char *)btinfo_modulelist;
565 btinfo_modulelist->num = 0;
566 off = sizeof(struct btinfo_modulelist);
567
568 for (bm = boot_modules; bm; bm = bm->bm_next) {
569 if (bm->bm_len == -1)
570 continue;
571 fd = module_open(bm, 0, kdev, true);
572 if (fd == -1)
573 continue;
574 image_end = (image_end + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1);
575 len = pread(fd, (void *)image_end, SSIZE_MAX);
576 if (len < bm->bm_len) {
577 if ((howto & AB_SILENT) != 0)
578 printf("Loading %s ", bm->bm_path);
579 printf(" FAILED\n");
580 } else {
581 btinfo_modulelist->num++;
582 bi = (struct bi_modulelist_entry *)(buf + off);
583 off += sizeof(struct bi_modulelist_entry);
584 strncpy(bi->path, bm->bm_path, sizeof(bi->path) - 1);
585 bi->base = image_end;
586 bi->len = len;
587 switch (bm->bm_type) {
588 case BM_TYPE_KMOD:
589 bi->type = BI_MODULE_ELF;
590 break;
591 case BM_TYPE_IMAGE:
592 bi->type = BI_MODULE_IMAGE;
593 break;
594 case BM_TYPE_RND:
595 default:
596 /* safest -- rnd checks the sha1 */
597 bi->type = BI_MODULE_RND;
598 break;
599 }
600 if ((howto & AB_SILENT) == 0)
601 printf(" \n");
602 }
603 if (len > 0)
604 image_end += len;
605 close(fd);
606 }
607 btinfo_modulelist->endpa = image_end;
608
609 if (nfail > 0) {
610 printf("WARNING: %d module%s failed to load\n",
611 nfail, nfail == 1 ? "" : "s");
612 #if notyet
613 wait_sec(MODULE_WARNING_SEC);
614 #endif
615 }
616 }
617
618 static void
619 userconf_init(void)
620 {
621 size_t count, len;
622 userconf_command_t *uc;
623 char *buf;
624 off_t off;
625
626 /* Calculate the userconf commands list size */
627 count = 0;
628 for (uc = userconf_commands; uc != NULL; uc = uc->uc_next)
629 count++;
630 len = sizeof(btinfo_userconfcommands) +
631 count * sizeof(struct bi_userconfcommand);
632
633 /* Allocate the userconf commands list */
634 btinfo_userconfcommands = alloc(len);
635 if (btinfo_userconfcommands == NULL) {
636 printf("WARNING: couldn't allocate userconf commands list\n");
637 return;
638 }
639 memset(btinfo_userconfcommands, 0, len);
640 btinfo_userconfcommands_size = len;
641
642 /* Fill in btinfo structure */
643 buf = (char *)btinfo_userconfcommands;
644 off = sizeof(*btinfo_userconfcommands);
645 btinfo_userconfcommands->num = 0;
646 for (uc = userconf_commands; uc != NULL; uc = uc->uc_next) {
647 struct bi_userconfcommand *bi;
648 bi = (struct bi_userconfcommand *)(buf + off);
649 strncpy(bi->text, uc->uc_text, sizeof(bi->text) - 1);
650
651 off += sizeof(*bi);
652 btinfo_userconfcommands->num++;
653 }
654 }
655
656 int
657 exec_multiboot(const char *file, char *args)
658 {
659 struct multiboot_info *mbi;
660 struct multiboot_module *mbm;
661 struct bi_modulelist_entry *bim;
662 int i, len;
663 u_long marks[MARK_MAX];
664 u_long extmem;
665 u_long basemem;
666 char *cmdline;
667
668 mbi = alloc(sizeof(struct multiboot_info));
669 mbi->mi_flags = MULTIBOOT_INFO_HAS_MEMORY;
670
671 if (common_load_kernel(file, &basemem, &extmem, 0, 0, marks))
672 goto out;
673
674 mbi->mi_mem_upper = extmem;
675 mbi->mi_mem_lower = basemem;
676
677 if (args) {
678 mbi->mi_flags |= MULTIBOOT_INFO_HAS_CMDLINE;
679 len = strlen(file) + 1 + strlen(args) + 1;
680 cmdline = alloc(len);
681 snprintf(cmdline, len, "%s %s", file, args);
682 mbi->mi_cmdline = (char *) vtophys(cmdline);
683 }
684
685 /* pull in any modules if necessary */
686 if (boot_modules_enabled) {
687 module_init(file);
688 if (btinfo_modulelist) {
689 mbm = alloc(sizeof(struct multiboot_module) *
690 btinfo_modulelist->num);
691
692 bim = (struct bi_modulelist_entry *)
693 (((char *) btinfo_modulelist) +
694 sizeof(struct btinfo_modulelist));
695 for (i = 0; i < btinfo_modulelist->num; i++) {
696 mbm[i].mmo_start = bim->base;
697 mbm[i].mmo_end = bim->base + bim->len;
698 mbm[i].mmo_string = (char *)vtophys(bim->path);
699 mbm[i].mmo_reserved = 0;
700 bim++;
701 }
702 mbi->mi_flags |= MULTIBOOT_INFO_HAS_MODS;
703 mbi->mi_mods_count = btinfo_modulelist->num;
704 mbi->mi_mods_addr = vtophys(mbm);
705 }
706 }
707
708 #ifdef DEBUG
709 printf("Start @ 0x%lx [%ld=0x%lx-0x%lx]...\n", marks[MARK_ENTRY],
710 marks[MARK_NSYM], marks[MARK_SYM], marks[MARK_END]);
711 #endif
712
713
714 #if 0
715 if (btinfo_symtab.nsym) {
716 mbi->mi_flags |= MULTIBOOT_INFO_HAS_ELF_SYMS;
717 mbi->mi_elfshdr_addr = marks[MARK_SYM];
718 btinfo_symtab.nsym = marks[MARK_NSYM];
719 btinfo_symtab.ssym = marks[MARK_SYM];
720 btinfo_symtab.esym = marks[MARK_END];
721 #endif
722
723 multiboot(marks[MARK_ENTRY], vtophys(mbi),
724 x86_trunc_page(mbi->mi_mem_lower*1024));
725 panic("exec returned");
726
727 out:
728 dealloc(mbi, 0);
729 return -1;
730 }
731
732 void
733 x86_progress(const char *fmt, ...)
734 {
735 va_list ap;
736
737 if ((howto & AB_SILENT) != 0)
738 return;
739 va_start(ap, fmt);
740 vprintf(fmt, ap);
741 va_end(ap);
742 }
743