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