2 * Mach Operating System
3 * Copyright (c) 1992, 1991 Carnegie Mellon University
6 * Permission to use, copy, modify and distribute this software and its
7 * documentation is hereby granted, provided that both the copyright
8 * notice and this permission notice appear in all copies of the
9 * software, derivative works or modified versions, and any portions
10 * thereof, and that both notices appear in supporting documentation.
12 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
13 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
16 * Carnegie Mellon requests users of this software to return to
18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
19 * School of Computer Science
20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
23 * any improvements or extensions that they make and grant Carnegie Mellon
24 * the rights to redistribute these changes.
26 * from: Mach, [92/04/03 16:51:14 rvb]
27 * $FreeBSD: src/sys/i386/boot/cdboot/boot.c,v 1.3 1999/08/28 00:43:17 peter Exp $
28 * $DragonFly: src/sys/platform/pc32/boot/cdboot/Attic/boot.c,v 1.2 2003/06/17 04:28:34 dillon Exp $
33 Copyright 1988, 1989, 1990, 1991, 1992
34 by Intel Corporation, Santa Clara, California.
38 Permission to use, copy, modify, and distribute this software and
39 its documentation for any purpose and without fee is hereby
40 granted, provided that the above copyright notice appears in all
41 copies and that both the copyright notice and this permission notice
42 appear in supporting documentation, and that the name of Intel
43 not be used in advertising or publicity pertaining to distribution
44 of the software without specific, written prior permission.
46 INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
47 INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
48 IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
49 CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
50 LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
51 NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
52 WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
56 * Extensions for El Torito CD-ROM booting:
58 * Copyright © 1997 Pluto Technologies International, Inc. Boulder CO
59 * Copyright © 1997 interface business GmbH, Dresden.
60 * All rights reserved.
62 * This code was written by Jörg Wunsch, Dresden.
63 * Direct comments to <joerg_wunsch@interface-business.de>.
65 * Redistribution and use in source and binary forms, with or without
66 * modification, are permitted provided that the following conditions
68 * 1. Redistributions of source code must retain the above copyright
69 * notice, this list of conditions and the following disclaimer.
70 * 2. Redistributions in binary form must reproduce the above copyright
71 * notice, this list of conditions and the following disclaimer in the
72 * documentation and/or other materials provided with the distribution.
74 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
75 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
76 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
77 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
78 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
79 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
80 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
81 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
82 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
83 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
84 * POSSIBILITY OF SUCH DAMAGE.
87 #include <sys/param.h>
90 #include <sys/reboot.h>
91 #include <machine/bootinfo.h>
92 #ifdef PROBE_KEYBOARD_LOCK
93 #include <machine/cpufunc.h>
96 #define ouraddr (BOOTSEG << 4) /* XXX */
102 * By now, only "cd". How do we learn from the BIOS we've been booted off
103 * an ATAPI CD-ROM? Do the non-{cd,wcd} drivers implement El Torito booting
107 static struct specpacket spkt = { 0x13 };
109 static char namebuf[128];
110 static struct bootinfo bootinfo;
112 static void getbootdev(char *ptr, int *howto);
113 static void loadprog(void);
121 #ifdef PROBE_KEYBOARD
122 if (probe_keyboard()) {
124 loadflags |= RB_SERIAL;
125 printf("\nNo keyboard found.");
129 #ifdef PROBE_KEYBOARD_LOCK
130 if (!(inb(0x64) & 0x10)) {
132 loadflags |= RB_SERIAL;
133 printf("\nKeyboard locked.");
137 #ifdef FORCE_COMCONSOLE
139 loadflags |= RB_SERIAL;
140 printf("\nSerial console forced.");
143 /* Pick up the story from the Bios on geometry of disks */
147 * Do we need to defer this until we can relinguish the
151 for(ret = 0; ret < N_BIOS_GEOM; ret ++)
152 bootinfo.bi_bios_geom[ret] = get_diskinfo(ret + 0x80);
154 bootinfo.bi_basemem = memsize(0);
155 bootinfo.bi_extmem = memsize(1);
156 bootinfo.bi_memsizes_valid = 1;
160 ret = getbootspec(&spkt);
162 printf("Your BIOS int 0x13 extensions seem to be disabled.\n"
163 "It's impossible to boot a CD-ROM without them.\n"
164 "(BIOS int 0x13 fn 0x4b01 yielded error %d)\n",
170 if (devopen(sessionstart) == -1)
171 printf("Warning: cannot open default session.\n"
172 "Maybe your BIOS int 0x13 extensions are disabled?\n"
173 "You need them in order to boot a CD-ROM.\n");
178 * The El Torito specification stinks. Not only this
179 * crappy idea of `emulation booting' (and at least
180 * earlier versions of the AHA-2940 BIOS didn't
181 * implement anything else than floppy emulation
182 * booting), but note also that there's absolutely no
183 * way via the BIOS to obtain the starting LBA of your
184 * session. All you can get ahold of is the LBA of
185 * that funny emulated disk. Since this one just
186 * happens to be a file hidden inside the ISO9660
187 * filesystem, it is located at a varying offset from
188 * the start of the session. We therefore allow to
189 * specify the starting block of the session to use in
190 * the boot string, so the operator can specify the
191 * session to boot from. However, (s)he needs to know
192 * the RBA for the session from the CD-ROM TOC.
194 DPRINTF(("using session at sector %d\n", sessionstart));
197 printf("\n>> FreeBSD CD-ROM BOOT\n"
198 "Usage: [@%d]%s[-abcCdghrsv]\n"
199 "Use ? for file list or press Enter for defaults\n"
203 loadflags &= RB_SERIAL; /* clear all, but leave serial console */
204 loadflags |= RB_CDROM; /* ...and default to CD-ROM root. */
206 getbootdev(namebuf, &loadflags);
208 DPRINTF(("Selected: name=`%s', loadflags=0x%x\n",
213 DPRINTF(("openrd() = %d\n", ret));
217 printf("Can't find %s\n", name);
228 u_int32_t startaddr, addr, bootdev;
233 if (read((void *)&head, sizeof(head)) == -1 ||
235 printf("Invalid format!\n");
240 * We assume that the entry address is the same as the lowest text
241 * address and that the kernel startup code handles relocation by
242 * this address rounded down to a multiple of 16M.
244 startaddr = head.a_entry & 0x00FFFFFF;
246 printf("Booting CD-ROM [@%d]%s @ 0x%x\n", sessionstart, name, addr);
247 if(addr < 0x00100000)
250 * Bail out, instead of risking to damage the BIOS
251 * variables, the loader, or the adapter memory area.
252 * We don't support loading below 1 MB any more.
254 printf("Start address too low\n");
257 printf("text=0x%x ", head.a_text);
259 /* load the text segment */
260 seek(N_TXTOFF(head));
261 if (xread((void *)addr, head.a_text) == -1)
265 /* Pad to a page boundary. */
266 pad = (unsigned)addr & PAGE_MASK;
268 pad = PAGE_SIZE - pad;
269 pbzero((void *)addr, pad);
273 /* load the initialised data after the text */
274 printf("data=0x%x ", head.a_data);
275 if (xread((void *)addr, head.a_data) == -1)
279 /* Skip over the uninitialised data (but clear it) */
280 printf("bss=0x%x ", head.a_bss);
283 * XXX however, we should be checking that we don't load ... into
284 * nonexistent memory. A full symbol table is unlikely to fit on 4MB
287 pbzero((void *)addr, head.a_bss);
290 /* Pad to a page boundary. */
291 pad = (unsigned)addr & PAGE_MASK;
293 pad = PAGE_SIZE - pad;
296 bootinfo.bi_symtab = addr;
298 /* Copy the symbol table size */
299 pcpy(&head.a_syms, (void *)addr, sizeof(head.a_syms));
300 addr += sizeof(head.a_syms);
302 /* Load the symbol table */
303 printf("symbols=[+0x%x+0x%x+0x%x", pad, sizeof(head.a_syms),
305 if (xread((void *)addr, head.a_syms) == -1)
309 /* Load the string table size */
310 if (read((void *)&i, sizeof(int)) == -1)
312 pcpy(&i, (void *)addr, sizeof(int));
316 /* Load the string table */
317 printf("+0x%x+0x%x]\n", sizeof(int), i);
318 if (xread((void *)addr, i) == -1)
322 bootinfo.bi_esymtab = addr;
324 /* XXX what else can we say about a CD-ROM? */
325 bootdev = MAKEBOOTDEV(maj, 0, 0, 0, 0);
327 bootinfo.bi_version = BOOTINFO_VERSION;
328 bootinfo.bi_kernelname = (u_int32_t)(name + ouraddr);
329 bootinfo.bi_nfs_diskless = 0;
330 bootinfo.bi_size = sizeof(bootinfo);
331 printf("total=0x%x entry point=0x%x\n", (int)addr, (int)startaddr);
332 startprog((int)startaddr, loadflags | RB_BOOTINFO, bootdev,
333 (int)&bootinfo + ouraddr);
337 getbootdev(char *ptr, int *howto)
342 * Be paranoid and make doubly sure that the input buffer is empty.
344 if (*howto & RB_SERIAL)
351 while ((c = *ptr) != '\0') {
356 while ((c = *++ptr) != '\0') {
362 *howto |= RB_ASKNAME;
371 if (*howto & RB_SERIAL)
378 *howto |= RB_DFLTROOT;
382 *howto |= RB_VERBOSE;
387 while (*++ptr != '\0') {