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