Annotation of src/sys/arch/i386/stand/lib/exec.c, Revision 1.16
1.16 ! jdolecek 1: /* $NetBSD: exec.c,v 1.15 2000/02/22 07:45:04 dbj Exp $ */
1.1 perry 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.
1.8 christos 10: * Copyright (c) 1997
11: * Martin Husemann. All rights reserved.
1.1 perry 12: *
13: * Redistribution and use in source and binary forms, with or without
14: * modification, are permitted provided that the following conditions
15: * are met:
16: * 1. Redistributions of source code must retain the above copyright
17: * notice, this list of conditions and the following disclaimer.
18: * 2. Redistributions in binary form must reproduce the above copyright
19: * notice, this list of conditions and the following disclaimer in the
20: * documentation and/or other materials provided with the distribution.
21: * 3. All advertising materials mentioning features or use of this software
22: * must display the following acknowledgement:
23: * This product includes software developed by the University of
24: * California, Berkeley and its contributors.
25: * 4. Neither the name of the University nor the names of its contributors
26: * may be used to endorse or promote products derived from this software
27: * without specific prior written permission.
28: *
29: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39: * SUCH DAMAGE.
40: *
41: * @(#)boot.c 8.1 (Berkeley) 6/10/93
42: */
43:
1.2 thorpej 44: /*
1.8 christos 45: * starts NetBSD a.out kernel
46: * needs lowlevel startup from startprog.S
47: * This is a special version of exec.c to support use of XMS.
1.1 perry 48: */
1.8 christos 49:
1.1 perry 50: #include <sys/param.h>
51: #include <sys/reboot.h>
52: #ifdef COMPAT_OLDBOOT
53: #include <sys/disklabel.h>
54: #endif
55:
56: #include <lib/libsa/stand.h>
1.4 drochner 57:
1.6 christos 58: #include "loadfile.h"
1.1 perry 59: #include "libi386.h"
1.4 drochner 60: #include "bootinfo.h"
1.16 ! jdolecek 61: #ifdef SUPPORT_PS2
! 62: #include "biosmca.h"
! 63: #endif
1.1 perry 64:
65: #ifdef COMPAT_OLDBOOT
1.11 drochner 66: static int dev2major __P((char *, int *));
67:
1.1 perry 68: static int
69: dev2major(devname, major)
1.2 thorpej 70: char *devname;
71: int *major;
1.1 perry 72: {
1.16 ! jdolecek 73: static const struct {
! 74: const char *name;
! 75: int maj;
! 76: } devices[] = {
! 77: { "wd", 0 },
! 78: { "fd", 2 },
! 79: { "sd", 4 },
! 80: #ifdef SUPPORT_PS2
! 81: { "ed", 20 },
! 82: #endif
! 83: };
! 84: #define NUMDEVICES (sizeof(devices)/sizeof(devices[0]))
1.2 thorpej 85: int i;
1.1 perry 86:
1.2 thorpej 87: for (i = 0; i < NUMDEVICES; i++)
1.16 ! jdolecek 88: if (!strcmp(devname, devices[i].name)) {
! 89: *major = devices[i].maj;
1.2 thorpej 90: return (0);
91: }
92: return (-1);
1.1 perry 93: }
94: #endif
1.6 christos 95: #define BOOT_NARGS 6
1.1 perry 96:
1.4 drochner 97: extern struct btinfo_console btinfo_console;
98:
1.2 thorpej 99: int
1.4 drochner 100: exec_netbsd(file, loadaddr, boothowto)
1.2 thorpej 101: const char *file;
102: physaddr_t loadaddr;
103: int boothowto;
1.1 perry 104: {
1.6 christos 105: u_long boot_argv[BOOT_NARGS];
106: int fd;
1.8 christos 107: u_long marks[MARK_MAX];
108: struct btinfo_symtab btinfo_symtab;
109: u_long extmem;
1.15 dbj 110: u_long basemem;
1.8 christos 111: #ifdef XMS
112: u_long xmsmem;
113: physaddr_t origaddr = loadaddr;
114: #endif
115:
1.1 perry 116: #ifdef COMPAT_OLDBOOT
1.2 thorpej 117: char *fsname, *devname;
118: int unit, part;
119: const char *filename;
120: int bootdevnr;
1.1 perry 121: #endif
122:
123: #ifdef DEBUG
1.13 drochner 124: printf("exec: file=%s loadaddr=0x%lx\n",
125: file ? file : "NULL", loadaddr);
1.1 perry 126: #endif
1.4 drochner 127:
1.6 christos 128: BI_ALLOC(6); /* ??? */
1.4 drochner 129:
130: BI_ADD(&btinfo_console, BTINFO_CONSOLE, sizeof(struct btinfo_console));
131:
1.8 christos 132: extmem = getextmem();
1.15 dbj 133: basemem = getbasemem();
1.8 christos 134:
135: #ifdef XMS
136: if ((getextmem1() == 0) && (xmsmem = checkxms())) {
137: u_long kernsize;
138:
139: /*
140: * With "CONSERVATIVE_MEMDETECT", extmem is 0 because
141: * getextmem() is getextmem1(). Without, the "smart"
142: * methods could fail to report all memory as well.
143: * xmsmem is a few kB less than the actual size, but
144: * better than nothing.
145: */
146: if (xmsmem > extmem)
147: extmem = xmsmem;
148: /*
149: * Get the size of the kernel
150: */
151: marks[MARK_START] = loadaddr;
1.12 christos 152: if ((fd = loadfile(file, marks, COUNT_KERNEL)) == -1)
1.8 christos 153: goto out;
154: close(fd);
155:
156: kernsize = marks[MARK_END];
157: kernsize = (kernsize + 1023) / 1024;
158:
159: loadaddr = xmsalloc(kernsize);
160: if (!loadaddr)
161: return(ENOMEM);
162: }
163: #endif
1.7 christos 164: marks[MARK_START] = loadaddr;
1.12 christos 165: if ((fd = loadfile(file, marks, LOAD_KERNEL)) == -1)
1.4 drochner 166: goto out;
1.1 perry 167:
168: boot_argv[0] = boothowto;
169:
170: #ifdef COMPAT_OLDBOOT
171: /* prepare boot device information for kernel */
1.2 thorpej 172: if (parsebootfile(file, &fsname, &devname, &unit, &part, &filename)
173: || strcmp(fsname, "ufs"))
174: bootdevnr = 0; /* XXX error out if parse error??? */
1.1 perry 175: else {
1.2 thorpej 176: int major;
1.1 perry 177:
1.3 thorpej 178: if (strcmp(devname, "hd") == 0) {
1.2 thorpej 179: /* generic BIOS disk, have to guess type */
1.6 christos 180: struct open_file *f = &files[fd]; /* XXX */
1.2 thorpej 181:
1.16 ! jdolecek 182: switch (biosdisk_gettype(f)) {
! 183: case DTYPE_SCSI:
1.2 thorpej 184: devname = "sd";
1.16 ! jdolecek 185: break;
! 186: #ifdef SUPPORT_PS2
! 187: case DTYPE_ESDI:
! 188: if (biosmca_ps2model) {
! 189: devname = "ed";
! 190: break;
! 191: }
! 192: #endif
! 193: default:
1.2 thorpej 194: devname = "wd";
1.16 ! jdolecek 195: break;
! 196: }
1.3 thorpej 197:
198: /*
199: * The old boot block performed the following
200: * conversion:
201: *
202: * hdN -> Xd0
203: *
204: * where X is the type specified by the label.
205: * We mimmick that here, for lack of any better
206: * way of doing things.
207: */
208: unit = 0;
1.2 thorpej 209: }
1.3 thorpej 210:
1.2 thorpej 211: if (dev2major(devname, &major))
212: bootdevnr = 0; /* XXX error out??? */
1.1 perry 213: else
1.2 thorpej 214: bootdevnr = MAKEBOOTDEV(major, 0, 0, unit, part);
1.1 perry 215: }
216:
217: boot_argv[1] = bootdevnr;
1.5 drochner 218: #else
219: boot_argv[1] = 0;
220: #endif
1.8 christos 221: boot_argv[2] = vtophys(bootinfo); /* old cyl offset */
222: /* argv[3] below */
223: boot_argv[4] = extmem;
1.15 dbj 224: boot_argv[5] = basemem;
1.8 christos 225:
226: close(fd);
1.10 drochner 227:
228: /*
229: * Gather some information for the kernel. Do this after the
230: * "point of no return" to avoid memory leaks.
231: * (but before DOS might be trashed in the XMS case)
232: */
233: #ifdef PASS_BIOSGEOM
234: bi_getbiosgeom();
235: #endif
236: #ifdef PASS_MEMMAP
237: bi_getmemmap();
238: #endif
1.8 christos 239:
240: #ifdef XMS
241: if (loadaddr != origaddr) {
242: /*
1.14 ross 243: * We now have done our last DOS IO, so we may
1.8 christos 244: * trash the OS. Copy the data from the temporary
245: * buffer to its real adress.
246: */
247: marks[MARK_START] -= loadaddr;
248: marks[MARK_END] -= loadaddr;
249: marks[MARK_SYM] -= loadaddr;
250: marks[MARK_END] -= loadaddr;
251: ppbcopy(loadaddr, origaddr, marks[MARK_END]);
252: }
253: #endif
254: marks[MARK_END] = (((u_long) marks[MARK_END] + sizeof(int) - 1)) &
255: (-sizeof(int));
256:
1.7 christos 257: boot_argv[3] = marks[MARK_END];
1.1 perry 258:
259:
260: #ifdef DEBUG
1.8 christos 261: printf("Start @ 0x%lx [%ld=0x%lx-0x%lx]...\n", marks[MARK_ENTRY],
1.7 christos 262: marks[MARK_NSYM], marks[MARK_SYM], marks[MARK_END]);
1.1 perry 263: #endif
264:
1.8 christos 265: btinfo_symtab.nsym = marks[MARK_NSYM];
266: btinfo_symtab.ssym = marks[MARK_SYM];
267: btinfo_symtab.esym = marks[MARK_END];
268: BI_ADD(&btinfo_symtab, BTINFO_SYMTAB, sizeof(struct btinfo_symtab));
269:
1.15 dbj 270: startprog(marks[MARK_ENTRY], BOOT_NARGS, boot_argv,
271: i386_trunc_page(basemem*1024));
1.1 perry 272: panic("exec returned");
273:
1.4 drochner 274: out:
275: BI_FREE();
276: bootinfo = 0;
1.2 thorpej 277: return (-1);
1.1 perry 278: }
CVSweb <webmaster@jp.NetBSD.org>