exec.c revision 1.6
1/* $NetBSD: exec.c,v 1.6 1999/01/28 20:21:24 christos Exp $ */ 2 3/* 4 * Copyright (c) 1982, 1986, 1990, 1993 5 * The Regents of the University of California. All rights reserved. 6 * Copyright (c) 1996 7 * Matthias Drochner. All rights reserved. 8 * Copyright (c) 1996 9 * Perry E. Metzger. All rights reserved. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. All advertising materials mentioning features or use of this software 20 * must display the following acknowledgement: 21 * This product includes software developed by the University of 22 * California, Berkeley and its contributors. 23 * 4. Neither the name of the University nor the names of its contributors 24 * may be used to endorse or promote products derived from this software 25 * without specific prior written permission. 26 * 27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 * SUCH DAMAGE. 38 * 39 * @(#)boot.c 8.1 (Berkeley) 6/10/93 40 */ 41 42/* 43 * starts NetBSD a.out kernel needs lowlevel startup from startprog.S 44 */ 45#include <sys/param.h> 46#include <sys/reboot.h> 47#ifdef COMPAT_OLDBOOT 48#include <sys/disklabel.h> 49#endif 50 51#include <lib/libsa/stand.h> 52 53#include "loadfile.h" 54#include "libi386.h" 55#include "bootinfo.h" 56 57#ifdef COMPAT_OLDBOOT 58static int 59dev2major(devname, major) 60 char *devname; 61 int *major; 62{ 63 static char *devices[] = {"wd", "", "fd", "", "sd"}; 64#define NUMDEVICES (sizeof(devices)/sizeof(char *)) 65 int i; 66 67 for (i = 0; i < NUMDEVICES; i++) 68 if (!strcmp(devname, devices[i])) { 69 *major = i; 70 return (0); 71 } 72 return (-1); 73} 74#endif 75#define BOOT_NARGS 6 76 77extern struct btinfo_console btinfo_console; 78 79int 80exec_netbsd(file, loadaddr, boothowto) 81 const char *file; 82 physaddr_t loadaddr; 83 int boothowto; 84{ 85 u_long boot_argv[BOOT_NARGS]; 86 int fd; 87#ifdef COMPAT_OLDBOOT 88 char *fsname, *devname; 89 int unit, part; 90 const char *filename; 91 int bootdevnr; 92 u_long marks[LOAD_MAX]; 93 struct btinfo_symtab btinfo_symtab; 94#endif 95 96#ifdef DEBUG 97 printf("exec: file=%s loadaddr=0x%lx\n", file, loadaddr); 98#endif 99 100 BI_ALLOC(6); /* ??? */ 101 102 BI_ADD(&btinfo_console, BTINFO_CONSOLE, sizeof(struct btinfo_console)); 103 104 marks[LOAD_START] = loadaddr; 105 if ((fd = loadfile(file, marks)) == -1) 106 goto out; 107 108 marks[LOAD_END] = (((u_long) marks[LOAD_END] + sizeof(int) - 1)) & 109 (-sizeof(int)); 110 111 btinfo_symtab.nsym = marks[LOAD_NSYM]; 112 btinfo_symtab.ssym = marks[LOAD_SYM]; 113 btinfo_symtab.esym = marks[LOAD_END]; 114 BI_ADD(&btinfo_symtab, BTINFO_SYMTAB, sizeof(struct btinfo_symtab)); 115 116 boot_argv[0] = boothowto; 117 118#ifdef COMPAT_OLDBOOT 119 /* prepare boot device information for kernel */ 120 if (parsebootfile(file, &fsname, &devname, &unit, &part, &filename) 121 || strcmp(fsname, "ufs")) 122 bootdevnr = 0; /* XXX error out if parse error??? */ 123 else { 124 int major; 125 126 if (strcmp(devname, "hd") == 0) { 127 /* generic BIOS disk, have to guess type */ 128 struct open_file *f = &files[fd]; /* XXX */ 129 130 if (biosdisk_gettype(f) == DTYPE_SCSI) 131 devname = "sd"; 132 else 133 devname = "wd"; 134 135 /* 136 * The old boot block performed the following 137 * conversion: 138 * 139 * hdN -> Xd0 140 * 141 * where X is the type specified by the label. 142 * We mimmick that here, for lack of any better 143 * way of doing things. 144 */ 145 unit = 0; 146 } 147 148 if (dev2major(devname, &major)) 149 bootdevnr = 0; /* XXX error out??? */ 150 else 151 bootdevnr = MAKEBOOTDEV(major, 0, 0, unit, part); 152 } 153 154 boot_argv[1] = bootdevnr; 155#else 156 boot_argv[1] = 0; 157#endif 158#ifdef PASS_BIOSGEOM 159 bi_getbiosgeom(); 160#endif 161 boot_argv[2] = vtophys(bootinfo); /* old cyl offset */ 162 boot_argv[3] = marks[LOAD_END]; 163 boot_argv[4] = getextmem(); 164 boot_argv[5] = getbasemem(); 165 166 close(fd); 167 168#ifdef DEBUG 169 printf("Start @ 0x%lx [%ld=0x%lx-0x%lx]...\n", marks[LOAD_START], 170 marks[LOAD_NSYM], marks[LOAD_SYM], marks[LOAD_END]); 171#endif 172 173 startprog(marks[LOAD_START], BOOT_NARGS, boot_argv, 0x90000); 174 panic("exec returned"); 175 176out: 177 BI_FREE(); 178 bootinfo = 0; 179 return (-1); 180} 181