1 /* $OpenBSD: exec_i386.c,v 1.42 2015/09/18 13:30:56 miod Exp $ */ 2 3 /* 4 * Copyright (c) 1997-1998 Michael Shalayeff 5 * Copyright (c) 1997 Tobias Weingartner 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 */ 30 31 #include <sys/param.h> 32 #include <sys/disklabel.h> 33 #include <dev/cons.h> 34 #include <lib/libsa/loadfile.h> 35 #include <machine/biosvar.h> 36 #include <stand/boot/bootarg.h> 37 38 #include "disk.h" 39 #include "libsa.h" 40 41 #ifdef SOFTRAID 42 #include <dev/softraidvar.h> 43 #include "softraid.h" 44 #endif 45 46 #ifdef EFIBOOT 47 #include "efiboot.h" 48 #endif 49 50 typedef void (*startfuncp)(int, int, int, int, int, int, int, int) 51 __attribute__ ((noreturn)); 52 53 char *bootmac = NULL; 54 55 void 56 run_loadfile(u_long *marks, int howto) 57 { 58 u_long entry; 59 #ifdef EXEC_DEBUG 60 extern int debug; 61 #endif 62 dev_t bootdev = bootdev_dip->bootdev; 63 size_t ac = BOOTARG_LEN; 64 caddr_t av = (caddr_t)BOOTARG_OFF; 65 bios_consdev_t cd; 66 extern int com_speed; /* from bioscons.c */ 67 extern int com_addr; 68 bios_ddb_t ddb; 69 extern int db_console; 70 bios_bootduid_t bootduid; 71 #ifdef SOFTRAID 72 bios_bootsr_t bootsr; 73 struct sr_boot_volume *bv; 74 #endif 75 76 #ifdef EFIBOOT 77 if ((av = alloc(ac)) == NULL) 78 panic("alloc for bootarg"); 79 efi_makebootargs(); 80 #endif 81 if (sa_cleanup != NULL) 82 (*sa_cleanup)(); 83 84 cd.consdev = cn_tab->cn_dev; 85 cd.conspeed = com_speed; 86 cd.consaddr = com_addr; 87 cd.consfreq = 0; 88 addbootarg(BOOTARG_CONSDEV, sizeof(cd), &cd); 89 90 if (bootmac != NULL) 91 addbootarg(BOOTARG_BOOTMAC, sizeof(bios_bootmac_t), bootmac); 92 93 if (db_console != -1) { 94 ddb.db_console = db_console; 95 addbootarg(BOOTARG_DDB, sizeof(ddb), &ddb); 96 } 97 98 bcopy(bootdev_dip->disklabel.d_uid, &bootduid.duid, sizeof(bootduid)); 99 addbootarg(BOOTARG_BOOTDUID, sizeof(bootduid), &bootduid); 100 101 #ifdef SOFTRAID 102 if (bootdev_dip->sr_vol != NULL) { 103 bv = bootdev_dip->sr_vol; 104 bzero(&bootsr, sizeof(bootsr)); 105 bcopy(&bv->sbv_uuid, &bootsr.uuid, sizeof(bootsr.uuid)); 106 if (bv->sbv_maskkey != NULL) 107 bcopy(bv->sbv_maskkey, &bootsr.maskkey, 108 sizeof(bootsr.maskkey)); 109 addbootarg(BOOTARG_BOOTSR, sizeof(bios_bootsr_t), &bootsr); 110 explicit_bzero(&bootsr, sizeof(bootsr)); 111 } 112 113 sr_clear_keys(); 114 #endif 115 116 /* Pass memory map to the kernel */ 117 mem_pass(); 118 119 #ifdef __amd64__ 120 /* 121 * This code may be used both for 64bit and 32bit. Make sure the 122 * bootarg is 32bit always on even on amd64. 123 */ 124 makebootargs32(av, &ac); 125 #else 126 makebootargs(av, &ac); 127 #endif 128 129 entry = marks[MARK_ENTRY] & 0x0fffffff; 130 131 printf("entry point at 0x%x\n", (int)entry); 132 133 #if defined(EFIBOOT) 134 efi_cleanup(); 135 #endif 136 #if defined(EFIBOOT) && defined(__amd64__) 137 (*run_i386)((u_long)run_i386, entry, howto, bootdev, BOOTARG_APIVER, 138 marks[MARK_END], extmem, cnvmem, ac, (intptr_t)av); 139 #else 140 /* stack and the gung is ok at this point, so, no need for asm setup */ 141 (*(startfuncp)entry)(howto, bootdev, BOOTARG_APIVER, marks[MARK_END], 142 extmem, cnvmem, ac, (int)av); 143 /* not reached */ 144 #endif 145 } 146