Index: stable/12/stand/i386/libi386/bioscd.c =================================================================== --- stable/12/stand/i386/libi386/bioscd.c (revision 342615) +++ stable/12/stand/i386/libi386/bioscd.c (nonexistent) @@ -1,432 +0,0 @@ -/*- - * Copyright (c) 1998 Michael Smith - * Copyright (c) 2001 John H. Baldwin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -__FBSDID("$FreeBSD$"); - -/* - * BIOS CD device handling for CD's that have been booted off of via no - * emulation booting as defined in the El Torito standard. - * - * Ideas and algorithms from: - * - * - FreeBSD libi386/biosdisk.c - * - */ - -#include - -#include -#include - -#include - -#include -#include -#include -#include "libi386.h" - -#define BIOSCD_SECSIZE 2048 -#define BUFSIZE (1 * BIOSCD_SECSIZE) -#define MAXBCDEV 1 - -/* Major numbers for devices we frontend for. */ -#define ACDMAJOR 117 -#define CDMAJOR 15 - -#ifdef DISK_DEBUG -# define DEBUG(fmt, args...) printf("%s: " fmt "\n" , __func__ , ## args) -#else -# define DEBUG(fmt, args...) -#endif - -struct specification_packet { - u_char sp_size; - u_char sp_bootmedia; - u_char sp_drive; - u_char sp_controller; - u_int sp_lba; - u_short sp_devicespec; - u_short sp_buffersegment; - u_short sp_loadsegment; - u_short sp_sectorcount; - u_short sp_cylsec; - u_char sp_head; -}; - -/* - * List of BIOS devices, translation from disk unit number to - * BIOS unit number. - */ -static struct bcinfo { - int bc_unit; /* BIOS unit number */ - struct specification_packet bc_sp; - int bc_open; /* reference counter */ - void *bc_bcache; /* buffer cache data */ -} bcinfo [MAXBCDEV]; -static int nbcinfo = 0; - -#define BC(dev) (bcinfo[(dev)->dd.d_unit]) - -static int bc_read(int unit, daddr_t dblk, int blks, caddr_t dest); -static int bc_init(void); -static int bc_strategy(void *devdata, int flag, daddr_t dblk, - size_t size, char *buf, size_t *rsize); -static int bc_realstrategy(void *devdata, int flag, daddr_t dblk, - size_t size, char *buf, size_t *rsize); -static int bc_open(struct open_file *f, ...); -static int bc_close(struct open_file *f); -static int bc_print(int verbose); - -struct devsw bioscd = { - "cd", - DEVT_CD, - bc_init, - bc_strategy, - bc_open, - bc_close, - noioctl, - bc_print, - NULL -}; - -/* - * Translate between BIOS device numbers and our private unit numbers. - */ -int -bc_bios2unit(int biosdev) -{ - int i; - - DEBUG("looking for bios device 0x%x", biosdev); - for (i = 0; i < nbcinfo; i++) { - DEBUG("bc unit %d is BIOS device 0x%x", i, bcinfo[i].bc_unit); - if (bcinfo[i].bc_unit == biosdev) - return(i); - } - return(-1); -} - -int -bc_unit2bios(int unit) -{ - if ((unit >= 0) && (unit < nbcinfo)) - return(bcinfo[unit].bc_unit); - return(-1); -} - -/* - * We can't quiz, we have to be told what device to use, so this functoin - * doesn't do anything. Instead, the loader calls bc_add() with the BIOS - * device number to add. - */ -static int -bc_init(void) -{ - - return (0); -} - -int -bc_add(int biosdev) -{ - - if (nbcinfo >= MAXBCDEV) - return (-1); - bcinfo[nbcinfo].bc_unit = biosdev; - v86.ctl = V86_FLAGS; - v86.addr = 0x13; - v86.eax = 0x4b01; - v86.edx = biosdev; - v86.ds = VTOPSEG(&bcinfo[nbcinfo].bc_sp); - v86.esi = VTOPOFF(&bcinfo[nbcinfo].bc_sp); - v86int(); - if ((v86.eax & 0xff00) != 0) - return (-1); - - printf("BIOS CD is cd%d\n", nbcinfo); - nbcinfo++; - bcache_add_dev(nbcinfo); /* register cd device in bcache */ - return(0); -} - -/* - * Print information about disks - */ -static int -bc_print(int verbose) -{ - char line[80]; - int i, ret = 0; - - if (nbcinfo == 0) - return (0); - - printf("%s devices:", bioscd.dv_name); - if ((ret = pager_output("\n")) != 0) - return (ret); - - for (i = 0; i < nbcinfo; i++) { - snprintf(line, sizeof(line), " cd%d: Device 0x%x\n", i, - bcinfo[i].bc_sp.sp_devicespec); - if ((ret = pager_output(line)) != 0) - break; - } - return (ret); -} - -/* - * Attempt to open the disk described by (dev) for use by (f). - */ -static int -bc_open(struct open_file *f, ...) -{ - va_list ap; - struct i386_devdesc *dev; - - va_start(ap, f); - dev = va_arg(ap, struct i386_devdesc *); - va_end(ap); - if (dev->dd.d_unit >= nbcinfo) { - DEBUG("attempt to open nonexistent disk"); - return(ENXIO); - } - - BC(dev).bc_open++; - if (BC(dev).bc_bcache == NULL) - BC(dev).bc_bcache = bcache_allocate(); - return(0); -} - -static int -bc_close(struct open_file *f) -{ - struct i386_devdesc *dev; - - dev = (struct i386_devdesc *)f->f_devdata; - BC(dev).bc_open--; - if (BC(dev).bc_open == 0) { - bcache_free(BC(dev).bc_bcache); - BC(dev).bc_bcache = NULL; - } - return(0); -} - -static int -bc_strategy(void *devdata, int rw, daddr_t dblk, size_t size, - char *buf, size_t *rsize) -{ - struct bcache_devdata bcd; - struct i386_devdesc *dev; - - dev = (struct i386_devdesc *)devdata; - bcd.dv_strategy = bc_realstrategy; - bcd.dv_devdata = devdata; - bcd.dv_cache = BC(dev).bc_bcache; - - return (bcache_strategy(&bcd, rw, dblk, size, buf, rsize)); -} - -static int -bc_realstrategy(void *devdata, int rw, daddr_t dblk, size_t size, - char *buf, size_t *rsize) -{ - struct i386_devdesc *dev; - int unit; - int blks; - - if (size % BIOSCD_SECSIZE) - return (EINVAL); - - if ((rw & F_MASK) != F_READ) - return(EROFS); - dev = (struct i386_devdesc *)devdata; - unit = dev->dd.d_unit; - blks = size / BIOSCD_SECSIZE; - if (dblk % (BIOSCD_SECSIZE / DEV_BSIZE) != 0) - return (EINVAL); - dblk /= (BIOSCD_SECSIZE / DEV_BSIZE); - DEBUG("read %d from %lld to %p", blks, dblk, buf); - - if (rsize) - *rsize = 0; - if ((blks = bc_read(unit, dblk, blks, buf)) < 0) { - DEBUG("read error"); - return (EIO); - } else { - if (size / BIOSCD_SECSIZE > blks) { - if (rsize) - *rsize = blks * BIOSCD_SECSIZE; - return (0); - } - } - if (rsize) - *rsize = size; - return (0); -} - -/* return negative value for an error, otherwise blocks read */ -static int -bc_read(int unit, daddr_t dblk, int blks, caddr_t dest) -{ - u_int maxfer, resid, result, retry, x; - caddr_t bbuf, p, xp; - static struct edd_packet packet; - int biosdev; -#ifdef DISK_DEBUG - int error; -#endif - - /* Just in case some idiot actually tries to read -1 blocks... */ - if (blks < 0) - return (-1); - - /* If nothing to do, just return succcess. */ - if (blks == 0) - return (0); - - /* Decide whether we have to bounce */ - if (VTOP(dest) >> 20 != 0) { - /* - * The destination buffer is above first 1MB of - * physical memory so we have to arrange a suitable - * bounce buffer. - */ - x = V86_IO_BUFFER_SIZE / BIOSCD_SECSIZE; - x = min(x, (unsigned)blks); - bbuf = PTOV(V86_IO_BUFFER); - maxfer = x; - } else { - bbuf = NULL; - maxfer = 0; - } - - biosdev = bc_unit2bios(unit); - resid = blks; - p = dest; - - while (resid > 0) { - if (bbuf) - xp = bbuf; - else - xp = p; - x = resid; - if (maxfer > 0) - x = min(x, maxfer); - - /* - * Loop retrying the operation a couple of times. The BIOS - * may also retry. - */ - for (retry = 0; retry < 3; retry++) { - /* If retrying, reset the drive */ - if (retry > 0) { - v86.ctl = V86_FLAGS; - v86.addr = 0x13; - v86.eax = 0; - v86.edx = biosdev; - v86int(); - } - - packet.len = sizeof(struct edd_packet); - packet.count = x; - packet.off = VTOPOFF(xp); - packet.seg = VTOPSEG(xp); - packet.lba = dblk; - v86.ctl = V86_FLAGS; - v86.addr = 0x13; - v86.eax = 0x4200; - v86.edx = biosdev; - v86.ds = VTOPSEG(&packet); - v86.esi = VTOPOFF(&packet); - v86int(); - result = V86_CY(v86.efl); - if (result == 0) - break; - /* fall back to 1 sector read */ - x = 1; - } - -#ifdef DISK_DEBUG - error = (v86.eax >> 8) & 0xff; -#endif - DEBUG("%d sectors from %lld to %p (0x%x) %s", x, dblk, p, - VTOP(p), result ? "failed" : "ok"); - DEBUG("unit %d status 0x%x", unit, error); - - /* still an error? break off */ - if (result != 0) - break; - - if (bbuf != NULL) - bcopy(bbuf, p, x * BIOSCD_SECSIZE); - p += (x * BIOSCD_SECSIZE); - dblk += x; - resid -= x; - } - -/* hexdump(dest, (blks * BIOSCD_SECSIZE)); */ - - if (blks - resid == 0) - return (-1); /* read failed */ - - return (blks - resid); -} - -/* - * Return a suitable dev_t value for (dev). - */ -int -bc_getdev(struct i386_devdesc *dev) -{ - int biosdev, unit; - int major; - int rootdev; - - unit = dev->dd.d_unit; - biosdev = bc_unit2bios(unit); - DEBUG("unit %d BIOS device %d", unit, biosdev); - if (biosdev == -1) /* not a BIOS device */ - return(-1); - - /* - * XXX: Need to examine device spec here to figure out if SCSI or - * ATAPI. No idea on how to figure out device number. All we can - * really pass to the kernel is what bus and device on which bus we - * were booted from, which dev_t isn't well suited to since those - * number don't match to unit numbers very well. We may just need - * to engage in a hack where we pass -C to the boot args if we are - * the boot device. - */ - major = ACDMAJOR; - unit = 0; /* XXX */ - - /* XXX: Assume partition 'a'. */ - rootdev = MAKEBOOTDEV(major, 0, unit, 0); - DEBUG("dev is 0x%x\n", rootdev); - return(rootdev); -} Property changes on: stable/12/stand/i386/libi386/bioscd.c ___________________________________________________________________ Deleted: svn:keywords ## -1 +0,0 ## -FreeBSD=%H \ No newline at end of property Index: stable/12/stand/i386/libi386/Makefile =================================================================== --- stable/12/stand/i386/libi386/Makefile (revision 342615) +++ stable/12/stand/i386/libi386/Makefile (revision 342616) @@ -1,57 +1,57 @@ # $FreeBSD$ .include LIB= i386 -SRCS= biosacpi.c bioscd.c biosdisk.c biosmem.c biospnp.c \ +SRCS= biosacpi.c biosdisk.c biosmem.c biospnp.c \ biospci.c biossmap.c bootinfo.c bootinfo32.c bootinfo64.c \ comconsole.c devicename.c elf32_freebsd.c \ elf64_freebsd.c multiboot.c multiboot_tramp.S relocater_tramp.S \ i386_copy.c i386_module.c nullconsole.c pxe.c pxetramp.s \ smbios.c time.c vidconsole.c amd64_tramp.S spinconsole.c .PATH: ${ZFSSRC} SRCS+= devicename_stubs.c CFLAGS+= -I${ZFSSRC} BOOT_COMCONSOLE_PORT?= 0x3f8 CFLAGS+= -DCOMPORT=${BOOT_COMCONSOLE_PORT} BOOT_COMCONSOLE_SPEED?= 9600 CFLAGS+= -DCOMSPEED=${BOOT_COMCONSOLE_SPEED} .ifdef(BOOT_BIOSDISK_DEBUG) # Make the disk code more talkative CFLAGS+= -DDISK_DEBUG .endif .if !defined(BOOT_HIDE_SERIAL_NUMBERS) # Export serial numbers, UUID, and asset tag from loader. CFLAGS+= -DSMBIOS_SERIAL_NUMBERS .if defined(BOOT_LITTLE_ENDIAN_UUID) # Use little-endian UUID format as defined in SMBIOS 2.6. CFLAGS+= -DSMBIOS_LITTLE_ENDIAN_UUID .elif defined(BOOT_NETWORK_ENDIAN_UUID) # Use network-endian UUID format for backward compatibility. CFLAGS+= -DSMBIOS_NETWORK_ENDIAN_UUID .endif .endif # Include simple terminal emulation (cons25-compatible) CFLAGS+= -DTERM_EMU # XXX: make alloca() useable CFLAGS+= -Dalloca=__builtin_alloca CFLAGS+= -I${BOOTSRC}/ficl -I${BOOTSRC}/ficl/i386 \ -I${LDRSRC} -I${BOOTSRC}/i386/common \ -I${SYSDIR}/contrib/dev/acpica/include # Handle FreeBSD specific %b and %D printf format specifiers CFLAGS+= ${FORMAT_EXTENSIONS} .include # XXX: clang integrated-as doesn't grok .codeNN directives yet CFLAGS.amd64_tramp.S= ${CLANG_NO_IAS} CFLAGS.multiboot_tramp.S= ${CLANG_NO_IAS} Index: stable/12/stand/i386/libi386/biosdisk.c =================================================================== --- stable/12/stand/i386/libi386/biosdisk.c (revision 342615) +++ stable/12/stand/i386/libi386/biosdisk.c (revision 342616) @@ -1,940 +1,1260 @@ /*- * Copyright (c) 1998 Michael Smith * Copyright (c) 2012 Andrey V. Elsukov * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); /* * BIOS disk device handling. * * Ideas and algorithms from: * * - NetBSD libi386/biosdisk.c * - FreeBSD biosboot/disk.c * */ #include #include +#include #include #include #include +#include #include #include #include #include "disk.h" #include "libi386.h" #define BIOS_NUMDRIVES 0x475 #define BIOSDISK_SECSIZE 512 #define BUFSIZE (1 * BIOSDISK_SECSIZE) #define DT_ATAPI 0x10 /* disk type for ATAPI floppies */ #define WDMAJOR 0 /* major numbers for devices we frontend for */ #define WFDMAJOR 1 #define FDMAJOR 2 #define DAMAJOR 4 +#define ACDMAJOR 117 +#define CDMAJOR 15 #ifdef DISK_DEBUG #define DEBUG(fmt, args...) printf("%s: " fmt "\n", __func__, ## args) #else #define DEBUG(fmt, args...) #endif +struct specification_packet { + uint8_t sp_size; + uint8_t sp_bootmedia; + uint8_t sp_drive; + uint8_t sp_controller; + uint32_t sp_lba; + uint16_t sp_devicespec; + uint16_t sp_buffersegment; + uint16_t sp_loadsegment; + uint16_t sp_sectorcount; + uint16_t sp_cylsec; + uint8_t sp_head; +}; + /* * List of BIOS devices, translation from disk unit number to * BIOS unit number. */ -static struct bdinfo +typedef struct bdinfo { + STAILQ_ENTRY(bdinfo) bd_link; /* link in device list */ int bd_unit; /* BIOS unit number */ int bd_cyl; /* BIOS geometry */ int bd_hds; int bd_sec; int bd_flags; #define BD_MODEINT13 0x0000 #define BD_MODEEDD1 0x0001 #define BD_MODEEDD3 0x0002 #define BD_MODEEDD (BD_MODEEDD1 | BD_MODEEDD3) #define BD_MODEMASK 0x0003 #define BD_FLOPPY 0x0004 -#define BD_NO_MEDIA 0x0008 +#define BD_CDROM 0x0008 +#define BD_NO_MEDIA 0x0010 int bd_type; /* BIOS 'drive type' (floppy only) */ uint16_t bd_sectorsize; /* Sector size */ uint64_t bd_sectors; /* Disk size */ int bd_open; /* reference counter */ void *bd_bcache; /* buffer cache data */ -} bdinfo [MAXBDDEV]; -static int nbdinfo = 0; +} bdinfo_t; -#define BD(dev) (bdinfo[(dev)->dd.d_unit]) #define BD_RD 0 #define BD_WR 1 -static void bd_io_workaround(struct disk_devdesc *dev); +typedef STAILQ_HEAD(bdinfo_list, bdinfo) bdinfo_list_t; +static bdinfo_list_t fdinfo = STAILQ_HEAD_INITIALIZER(fdinfo); +static bdinfo_list_t cdinfo = STAILQ_HEAD_INITIALIZER(cdinfo); +static bdinfo_list_t hdinfo = STAILQ_HEAD_INITIALIZER(hdinfo); -static int bd_io(struct disk_devdesc *, daddr_t, int, caddr_t, int); -static int bd_int13probe(struct bdinfo *bd); +static void bd_io_workaround(bdinfo_t *); +static int bd_io(struct disk_devdesc *, bdinfo_t *, daddr_t, int, caddr_t, int); +static bool bd_int13probe(bdinfo_t *); static int bd_init(void); +static int cd_init(void); +static int fd_init(void); static int bd_strategy(void *devdata, int flag, daddr_t dblk, size_t size, char *buf, size_t *rsize); static int bd_realstrategy(void *devdata, int flag, daddr_t dblk, size_t size, char *buf, size_t *rsize); static int bd_open(struct open_file *f, ...); static int bd_close(struct open_file *f); static int bd_ioctl(struct open_file *f, u_long cmd, void *data); static int bd_print(int verbose); +static int cd_print(int verbose); +static int fd_print(int verbose); -struct devsw biosdisk = { - "disk", - DEVT_DISK, - bd_init, - bd_strategy, - bd_open, - bd_close, - bd_ioctl, - bd_print, - NULL +struct devsw biosfd = { + .dv_name = "fd", + .dv_type = DEVT_FD, + .dv_init = fd_init, + .dv_strategy = bd_strategy, + .dv_open = bd_open, + .dv_close = bd_close, + .dv_ioctl = bd_ioctl, + .dv_print = fd_print, + .dv_cleanup = NULL }; +struct devsw bioscd = { + .dv_name = "cd", + .dv_type = DEVT_CD, + .dv_init = cd_init, + .dv_strategy = bd_strategy, + .dv_open = bd_open, + .dv_close = bd_close, + .dv_ioctl = bd_ioctl, + .dv_print = cd_print, + .dv_cleanup = NULL +}; + +struct devsw bioshd = { + .dv_name = "disk", + .dv_type = DEVT_DISK, + .dv_init = bd_init, + .dv_strategy = bd_strategy, + .dv_open = bd_open, + .dv_close = bd_close, + .dv_ioctl = bd_ioctl, + .dv_print = bd_print, + .dv_cleanup = NULL +}; + +static bdinfo_list_t * +bd_get_bdinfo_list(struct devsw *dev) +{ + if (dev->dv_type == DEVT_DISK) + return (&hdinfo); + if (dev->dv_type == DEVT_CD) + return (&cdinfo); + if (dev->dv_type == DEVT_FD) + return (&fdinfo); + return (NULL); +} + +/* XXX this gets called way way too often, investigate */ +static bdinfo_t * +bd_get_bdinfo(struct devdesc *dev) +{ + bdinfo_list_t *bdi; + bdinfo_t *bd = NULL; + int unit; + + bdi = bd_get_bdinfo_list(dev->d_dev); + if (bdi == NULL) + return (bd); + + unit = 0; + STAILQ_FOREACH(bd, bdi, bd_link) { + if (unit == dev->d_unit) + return (bd); + unit++; + } + return (bd); +} + /* * Translate between BIOS device numbers and our private unit numbers. */ int bd_bios2unit(int biosdev) { - int i; + bdinfo_list_t *bdi[] = { &fdinfo, &cdinfo, &hdinfo, NULL }; + bdinfo_t *bd; + int i, unit; DEBUG("looking for bios device 0x%x", biosdev); - for (i = 0; i < nbdinfo; i++) { - DEBUG("bd unit %d is BIOS device 0x%x", i, bdinfo[i].bd_unit); - if (bdinfo[i].bd_unit == biosdev) - return (i); + for (i = 0; bdi[i] != NULL; i++) { + unit = 0; + STAILQ_FOREACH(bd, bdi[i], bd_link) { + if (bd->bd_unit == biosdev) { + DEBUG("bd unit %d is BIOS device 0x%x", unit, + bd->bd_unit); + return (unit); + } + unit++; + } } return (-1); } int -bd_unit2bios(int unit) +bd_unit2bios(struct i386_devdesc *dev) { + bdinfo_list_t *bdi; + bdinfo_t *bd; + int unit; - if ((unit >= 0) && (unit < nbdinfo)) - return (bdinfo[unit].bd_unit); + bdi = bd_get_bdinfo_list(dev->dd.d_dev); + if (bdi == NULL) + return (-1); + + unit = 0; + STAILQ_FOREACH(bd, bdi, bd_link) { + if (unit == dev->dd.d_unit) + return (bd->bd_unit); + unit++; + } return (-1); } /* * Quiz the BIOS for disk devices, save a little info about them. */ static int -bd_init(void) +fd_init(void) { - int base, unit, nfd = 0; + int unit; + bdinfo_t *bd; - /* sequence 0, 0x80 */ - for (base = 0; base <= 0x80; base += 0x80) { - for (unit = base; (nbdinfo < MAXBDDEV); unit++) { -#ifndef VIRTUALBOX - /* - * Check the BIOS equipment list for number - * of fixed disks. - */ - if (base == 0x80 && - (nfd >= *(unsigned char *)PTOV(BIOS_NUMDRIVES))) - break; -#endif - bdinfo[nbdinfo].bd_open = 0; - bdinfo[nbdinfo].bd_bcache = NULL; - bdinfo[nbdinfo].bd_unit = unit; - bdinfo[nbdinfo].bd_flags = unit < 0x80 ? BD_FLOPPY: 0; - if (!bd_int13probe(&bdinfo[nbdinfo])) - break; + for (unit = 0; unit < MAXBDDEV; unit++) { + if ((bd = calloc(1, sizeof(*bd))) == NULL) + break; + bd->bd_flags = BD_FLOPPY; + bd->bd_unit = unit; + if (!bd_int13probe(bd)) { + free(bd); + break; + } + if (bd->bd_sectors == 0) + bd->bd_flags |= BD_NO_MEDIA; - /* XXX we need "disk aliases" to make this simpler */ - printf("BIOS drive %c: is disk%d\n", (unit < 0x80) ? - ('A' + unit): ('C' + unit - 0x80), nbdinfo); - nbdinfo++; - if (base == 0x80) - nfd++; + printf("BIOS drive %c: is %s%d\n", ('A' + unit), + biosfd.dv_name, unit); + + STAILQ_INSERT_TAIL(&fdinfo, bd, bd_link); + } + + bcache_add_dev(unit); + return (0); +} + +static int +bd_init(void) +{ + int base, unit; + bdinfo_t *bd; + + base = 0x80; + for (unit = 0; unit < *(unsigned char *)PTOV(BIOS_NUMDRIVES); unit++) { + /* + * Check the BIOS equipment list for number of fixed disks. + */ + if ((bd = calloc(1, sizeof(*bd))) == NULL) + break; + bd->bd_unit = base + unit; + if (!bd_int13probe(bd)) { + free(bd); + break; } + + printf("BIOS drive %c: is %s%d\n", ('C' + unit), + bioshd.dv_name, unit); + + STAILQ_INSERT_TAIL(&hdinfo, bd, bd_link); } - bcache_add_dev(nbdinfo); + bcache_add_dev(unit); return (0); } /* + * We can't quiz, we have to be told what device to use, so this function + * doesn't do anything. Instead, the loader calls bc_add() with the BIOS + * device number to add. + */ +static int +cd_init(void) +{ + + return (0); +} + +int +bc_add(int biosdev) +{ + bdinfo_t *bd; + struct specification_packet bc_sp; + int nbcinfo = 0; + + if (!STAILQ_EMPTY(&cdinfo)) + return (-1); + + v86.ctl = V86_FLAGS; + v86.addr = 0x13; + v86.eax = 0x4b01; + v86.edx = biosdev; + v86.ds = VTOPSEG(&bc_sp); + v86.esi = VTOPOFF(&bc_sp); + v86int(); + if ((v86.eax & 0xff00) != 0) + return (-1); + + if ((bd = calloc(1, sizeof(*bd))) == NULL) + return (-1); + + bd->bd_flags = BD_CDROM; + bd->bd_unit = biosdev; + + /* + * Ignore result from bd_int13probe(), we will use local + * workaround below. + */ + (void)bd_int13probe(bd); + + if (bd->bd_cyl == 0) { + bd->bd_cyl = ((bc_sp.sp_cylsec & 0xc0) << 2) + + ((bc_sp.sp_cylsec & 0xff00) >> 8) + 1; + } + if (bd->bd_hds == 0) + bd->bd_hds = bc_sp.sp_head + 1; + if (bd->bd_sec == 0) + bd->bd_sec = bc_sp.sp_cylsec & 0x3f; + if (bd->bd_sectors == 0) + bd->bd_sectors = (uint64_t)bd->bd_cyl * bd->bd_hds * bd->bd_sec; + + /* Still no size? use 7.961GB */ + if (bd->bd_sectors == 0) + bd->bd_sectors = 4173824; + + STAILQ_INSERT_TAIL(&cdinfo, bd, bd_link); + printf("BIOS CD is cd%d\n", nbcinfo); + nbcinfo++; + bcache_add_dev(nbcinfo); /* register cd device in bcache */ + return(0); +} + +/* * Return EDD version or 0 if EDD is not supported on this drive. */ static int bd_check_extensions(int unit) { /* Determine if we can use EDD with this device. */ v86.ctl = V86_FLAGS; v86.addr = 0x13; v86.eax = 0x4100; v86.edx = unit; v86.ebx = 0x55aa; v86int(); if (V86_CY(v86.efl) || /* carry set */ (v86.ebx & 0xffff) != 0xaa55) /* signature */ return (0); /* extended disk access functions (AH=42h-44h,47h,48h) supported */ if ((v86.ecx & EDD_INTERFACE_FIXED_DISK) == 0) return (0); return ((v86.eax >> 8) & 0xff); } static void bd_reset_disk(int unit) { /* reset disk */ v86.ctl = V86_FLAGS; v86.addr = 0x13; v86.eax = 0; v86.edx = unit; v86int(); } /* * Read CHS info. Return 0 on success, error otherwise. */ static int bd_get_diskinfo_std(struct bdinfo *bd) { bzero(&v86, sizeof(v86)); v86.ctl = V86_FLAGS; v86.addr = 0x13; v86.eax = 0x800; v86.edx = bd->bd_unit; v86int(); if (V86_CY(v86.efl) && ((v86.eax & 0xff00) != 0)) return ((v86.eax & 0xff00) >> 8); /* return custom error on absurd sector number */ if ((v86.ecx & 0x3f) == 0) return (0x60); bd->bd_cyl = ((v86.ecx & 0xc0) << 2) + ((v86.ecx & 0xff00) >> 8) + 1; /* Convert max head # -> # of heads */ bd->bd_hds = ((v86.edx & 0xff00) >> 8) + 1; bd->bd_sec = v86.ecx & 0x3f; bd->bd_type = v86.ebx; bd->bd_sectors = (uint64_t)bd->bd_cyl * bd->bd_hds * bd->bd_sec; return (0); } /* * Read EDD info. Return 0 on success, error otherwise. */ static int bd_get_diskinfo_ext(struct bdinfo *bd) { struct edd_params params; uint64_t total; /* Get disk params */ bzero(¶ms, sizeof(params)); params.len = sizeof(params); v86.ctl = V86_FLAGS; v86.addr = 0x13; v86.eax = 0x4800; v86.edx = bd->bd_unit; v86.ds = VTOPSEG(¶ms); v86.esi = VTOPOFF(¶ms); v86int(); if (V86_CY(v86.efl) && ((v86.eax & 0xff00) != 0)) return ((v86.eax & 0xff00) >> 8); /* * Sector size must be a multiple of 512 bytes. * An alternate test would be to check power of 2, * powerof2(params.sector_size). * 4K is largest read buffer we can use at this time. */ if (params.sector_size >= 512 && params.sector_size <= 4096 && (params.sector_size % BIOSDISK_SECSIZE) == 0) bd->bd_sectorsize = params.sector_size; bd->bd_cyl = params.cylinders; bd->bd_hds = params.heads; bd->bd_sec = params.sectors_per_track; if (params.sectors != 0) { total = params.sectors; } else { total = (uint64_t)params.cylinders * params.heads * params.sectors_per_track; } bd->bd_sectors = total; return (0); } /* * Try to detect a device supported by the legacy int13 BIOS */ -static int -bd_int13probe(struct bdinfo *bd) +static bool +bd_int13probe(bdinfo_t *bd) { - int edd; - int ret; + int edd, ret; bd->bd_flags &= ~BD_NO_MEDIA; edd = bd_check_extensions(bd->bd_unit); if (edd == 0) bd->bd_flags |= BD_MODEINT13; else if (edd < 0x30) bd->bd_flags |= BD_MODEEDD1; else bd->bd_flags |= BD_MODEEDD3; /* Default sector size */ bd->bd_sectorsize = BIOSDISK_SECSIZE; /* * Test if the floppy device is present, so we can avoid receiving * bogus information from bd_get_diskinfo_std(). */ if (bd->bd_unit < 0x80) { /* reset disk */ bd_reset_disk(bd->bd_unit); /* Get disk type */ v86.ctl = V86_FLAGS; v86.addr = 0x13; v86.eax = 0x1500; v86.edx = bd->bd_unit; v86int(); if (V86_CY(v86.efl) || (v86.eax & 0x300) == 0) - return (0); + return (false); } ret = 1; if (edd != 0) ret = bd_get_diskinfo_ext(bd); if (ret != 0 || bd->bd_sectors == 0) ret = bd_get_diskinfo_std(bd); if (ret != 0 && bd->bd_unit < 0x80) { /* Set defaults for 1.44 floppy */ bd->bd_cyl = 80; bd->bd_hds = 2; bd->bd_sec = 18; - bd->bd_type = 4; bd->bd_sectors = 2880; /* Since we are there, there most likely is no media */ bd->bd_flags |= BD_NO_MEDIA; ret = 0; } if (ret != 0) { + /* CD is special case, bc_add() has its own fallback. */ + if ((bd->bd_flags & BD_CDROM) != 0) + return (true); + if (bd->bd_sectors != 0 && edd != 0) { bd->bd_sec = 63; bd->bd_hds = 255; bd->bd_cyl = (bd->bd_sectors + bd->bd_sec * bd->bd_hds - 1) / bd->bd_sec * bd->bd_hds; } else { + const char *dv_name; + + if ((bd->bd_flags & BD_FLOPPY) != 0) + dv_name = biosfd.dv_name; + else if ((bd->bd_flags & BD_CDROM) != 0) + dv_name = bioscd.dv_name; + else + dv_name = bioshd.dv_name; + printf("Can not get information about %s unit %#x\n", - biosdisk.dv_name, bd->bd_unit); - return (0); + dv_name, bd->bd_unit); + return (false); } } if (bd->bd_sec == 0) bd->bd_sec = 63; if (bd->bd_hds == 0) bd->bd_hds = 255; if (bd->bd_sectors == 0) bd->bd_sectors = (uint64_t)bd->bd_cyl * bd->bd_hds * bd->bd_sec; - DEBUG("unit 0x%x geometry %d/%d/%d", bd->bd_unit, bd->bd_cyl, + DEBUG("unit 0x%x geometry %d/%d/%d\n", bd->bd_unit, bd->bd_cyl, bd->bd_hds, bd->bd_sec); - return (1); + return (true); } +static int +bd_count(bdinfo_list_t *bdi) +{ + bdinfo_t *bd; + int i; + + i = 0; + STAILQ_FOREACH(bd, bdi, bd_link) + i++; + return (i); +} + /* * Print information about disks */ static int -bd_print(int verbose) +bd_print_common(struct devsw *dev, bdinfo_list_t *bdi, int verbose) { - static char line[80]; - struct disk_devdesc dev; + char line[80]; + struct disk_devdesc devd; + bdinfo_t *bd; int i, ret = 0; + char drive; - if (nbdinfo == 0) + if (STAILQ_EMPTY(bdi)) return (0); - printf("%s devices:", biosdisk.dv_name); + printf("%s devices:", dev->dv_name); if ((ret = pager_output("\n")) != 0) return (ret); - for (i = 0; i < nbdinfo; i++) { + i = -1; + STAILQ_FOREACH(bd, bdi, bd_link) { + i++; + + switch (dev->dv_type) { + case DEVT_FD: + drive = 'A'; + break; + case DEVT_CD: + drive = 'C' + bd_count(&hdinfo); + break; + default: + drive = 'C'; + break; + } + snprintf(line, sizeof(line), - " disk%d: BIOS drive %c (%s%ju X %u):\n", i, - (bdinfo[i].bd_unit < 0x80) ? ('A' + bdinfo[i].bd_unit): - ('C' + bdinfo[i].bd_unit - 0x80), - (bdinfo[i].bd_flags & BD_NO_MEDIA) == BD_NO_MEDIA ? + " %s%d: BIOS drive %c (%s%ju X %u):\n", + dev->dv_name, i, drive + i, + (bd->bd_flags & BD_NO_MEDIA) == BD_NO_MEDIA ? "no media, " : "", - (uintmax_t)bdinfo[i].bd_sectors, - bdinfo[i].bd_sectorsize); + (uintmax_t)bd->bd_sectors, + bd->bd_sectorsize); if ((ret = pager_output(line)) != 0) break; - if ((bdinfo[i].bd_flags & BD_NO_MEDIA) == BD_NO_MEDIA) + if ((bd->bd_flags & BD_NO_MEDIA) == BD_NO_MEDIA) continue; - dev.dd.d_dev = &biosdisk; - dev.dd.d_unit = i; - dev.d_slice = -1; - dev.d_partition = -1; - if (disk_open(&dev, - bdinfo[i].bd_sectorsize * bdinfo[i].bd_sectors, - bdinfo[i].bd_sectorsize) == 0) { - snprintf(line, sizeof(line), " disk%d", i); - ret = disk_print(&dev, line, verbose); - disk_close(&dev); + if (dev->dv_type != DEVT_DISK) + continue; + + devd.dd.d_dev = dev; + devd.dd.d_unit = i; + devd.d_slice = -1; + devd.d_partition = -1; + if (disk_open(&devd, + bd->bd_sectorsize * bd->bd_sectors, + bd->bd_sectorsize) == 0) { + snprintf(line, sizeof(line), " %s%d", + dev->dv_name, i); + ret = disk_print(&devd, line, verbose); + disk_close(&devd); if (ret != 0) break; } } return (ret); } +static int +fd_print(int verbose) +{ + return (bd_print_common(&biosfd, &fdinfo, verbose)); +} + +static int +bd_print(int verbose) +{ + return (bd_print_common(&bioshd, &hdinfo, verbose)); +} + +static int +cd_print(int verbose) +{ + return (bd_print_common(&bioscd, &cdinfo, verbose)); +} + /* * Read disk size from partition. * This is needed to work around buggy BIOS systems returning * wrong (truncated) disk media size. * During bd_probe() we tested if the multiplication of bd_sectors * would overflow so it should be safe to perform here. */ static uint64_t bd_disk_get_sectors(struct disk_devdesc *dev) { + bdinfo_t *bd; struct disk_devdesc disk; uint64_t size; + bd = bd_get_bdinfo(&dev->dd); + if (bd == NULL) + return (0); + disk.dd.d_dev = dev->dd.d_dev; disk.dd.d_unit = dev->dd.d_unit; disk.d_slice = -1; disk.d_partition = -1; disk.d_offset = 0; - size = BD(dev).bd_sectors * BD(dev).bd_sectorsize; - if (disk_open(&disk, size, BD(dev).bd_sectorsize) == 0) { + size = bd->bd_sectors * bd->bd_sectorsize; + if (disk_open(&disk, size, bd->bd_sectorsize) == 0) { (void) disk_ioctl(&disk, DIOCGMEDIASIZE, &size); disk_close(&disk); } - return (size / BD(dev).bd_sectorsize); + return (size / bd->bd_sectorsize); } /* * Attempt to open the disk described by (dev) for use by (f). * * Note that the philosophy here is "give them exactly what * they ask for". This is necessary because being too "smart" * about what the user might want leads to complications. * (eg. given no slice or partition value, with a disk that is * sliced - are they after the first BSD slice, or the DOS * slice before it?) */ static int bd_open(struct open_file *f, ...) { + bdinfo_t *bd; struct disk_devdesc *dev; va_list ap; int rc; va_start(ap, f); dev = va_arg(ap, struct disk_devdesc *); va_end(ap); - if (dev->dd.d_unit < 0 || dev->dd.d_unit >= nbdinfo) + bd = bd_get_bdinfo(&dev->dd); + if (bd == NULL) return (EIO); - if ((BD(dev).bd_flags & BD_NO_MEDIA) == BD_NO_MEDIA) { - if (!bd_int13probe(&BD(dev))) + if ((bd->bd_flags & BD_NO_MEDIA) == BD_NO_MEDIA) { + if (!bd_int13probe(bd)) return (EIO); - if ((BD(dev).bd_flags & BD_NO_MEDIA) == BD_NO_MEDIA) + if ((bd->bd_flags & BD_NO_MEDIA) == BD_NO_MEDIA) return (EIO); } - if (BD(dev).bd_bcache == NULL) - BD(dev).bd_bcache = bcache_allocate(); + if (bd->bd_bcache == NULL) + bd->bd_bcache = bcache_allocate(); - if (BD(dev).bd_open == 0) - BD(dev).bd_sectors = bd_disk_get_sectors(dev); - BD(dev).bd_open++; + if (bd->bd_open == 0) + bd->bd_sectors = bd_disk_get_sectors(dev); + bd->bd_open++; - rc = disk_open(dev, BD(dev).bd_sectors * BD(dev).bd_sectorsize, - BD(dev).bd_sectorsize); - if (rc != 0) { - BD(dev).bd_open--; - if (BD(dev).bd_open == 0) { - bcache_free(BD(dev).bd_bcache); - BD(dev).bd_bcache = NULL; + rc = 0; + if (dev->dd.d_dev->dv_type == DEVT_DISK) { + rc = disk_open(dev, bd->bd_sectors * bd->bd_sectorsize, + bd->bd_sectorsize); + if (rc != 0) { + bd->bd_open--; + if (bd->bd_open == 0) { + bcache_free(bd->bd_bcache); + bd->bd_bcache = NULL; + } } } return (rc); } static int bd_close(struct open_file *f) { struct disk_devdesc *dev; + bdinfo_t *bd; + int rc = 0; dev = (struct disk_devdesc *)f->f_devdata; - BD(dev).bd_open--; - if (BD(dev).bd_open == 0) { - bcache_free(BD(dev).bd_bcache); - BD(dev).bd_bcache = NULL; + bd = bd_get_bdinfo(&dev->dd); + if (bd == NULL) + return (EIO); + + bd->bd_open--; + if (bd->bd_open == 0) { + bcache_free(bd->bd_bcache); + bd->bd_bcache = NULL; } - return (disk_close(dev)); + if (dev->dd.d_dev->dv_type == DEVT_DISK) + rc = disk_close(dev); + return (rc); } static int bd_ioctl(struct open_file *f, u_long cmd, void *data) { + bdinfo_t *bd; struct disk_devdesc *dev; int rc; dev = (struct disk_devdesc *)f->f_devdata; + bd = bd_get_bdinfo(&dev->dd); + if (bd == NULL) + return (EIO); - rc = disk_ioctl(dev, cmd, data); - if (rc != ENOTTY) - return (rc); + if (dev->dd.d_dev->dv_type == DEVT_DISK) { + rc = disk_ioctl(dev, cmd, data); + if (rc != ENOTTY) + return (rc); + } switch (cmd) { case DIOCGSECTORSIZE: - *(uint32_t *)data = BD(dev).bd_sectorsize; + *(uint32_t *)data = bd->bd_sectorsize; break; case DIOCGMEDIASIZE: - *(uint64_t *)data = BD(dev).bd_sectors * BD(dev).bd_sectorsize; + *(uint64_t *)data = bd->bd_sectors * bd->bd_sectorsize; break; default: return (ENOTTY); } return (0); } static int bd_strategy(void *devdata, int rw, daddr_t dblk, size_t size, char *buf, size_t *rsize) { + bdinfo_t *bd; struct bcache_devdata bcd; struct disk_devdesc *dev; + daddr_t offset; dev = (struct disk_devdesc *)devdata; + bd = bd_get_bdinfo(&dev->dd); + if (bd == NULL) + return (EINVAL); + bcd.dv_strategy = bd_realstrategy; bcd.dv_devdata = devdata; - bcd.dv_cache = BD(dev).bd_bcache; - return (bcache_strategy(&bcd, rw, dblk + dev->d_offset, size, + bcd.dv_cache = bd->bd_bcache; + + offset = 0; + if (dev->dd.d_dev->dv_type == DEVT_DISK) { + + offset = dev->d_offset * bd->bd_sectorsize; + offset /= BIOSDISK_SECSIZE; + } + return (bcache_strategy(&bcd, rw, dblk + offset, size, buf, rsize)); } static int bd_realstrategy(void *devdata, int rw, daddr_t dblk, size_t size, char *buf, size_t *rsize) { struct disk_devdesc *dev = (struct disk_devdesc *)devdata; - uint64_t disk_blocks, offset; + bdinfo_t *bd; + uint64_t disk_blocks, offset, d_offset; size_t blks, blkoff, bsize, rest; caddr_t bbuf; int rc; - if ((BD(dev).bd_flags & BD_NO_MEDIA) == BD_NO_MEDIA) + bd = bd_get_bdinfo(&dev->dd); + if (bd == NULL || (bd->bd_flags & BD_NO_MEDIA) == BD_NO_MEDIA) return (EIO); /* * First make sure the IO size is a multiple of 512 bytes. While we do * process partial reads below, the strategy mechanism is built * assuming IO is a multiple of 512B blocks. If the request is not * a multiple of 512B blocks, it has to be some sort of bug. */ if (size == 0 || (size % BIOSDISK_SECSIZE) != 0) { printf("bd_strategy: %d bytes I/O not multiple of %d\n", size, BIOSDISK_SECSIZE); return (EIO); } DEBUG("open_disk %p", dev); offset = dblk * BIOSDISK_SECSIZE; - dblk = offset / BD(dev).bd_sectorsize; - blkoff = offset % BD(dev).bd_sectorsize; + dblk = offset / bd->bd_sectorsize; + blkoff = offset % bd->bd_sectorsize; /* * Check the value of the size argument. We do have quite small * heap (64MB), but we do not know good upper limit, so we check against * INT_MAX here. This will also protect us against possible overflows * while translating block count to bytes. */ if (size > INT_MAX) { DEBUG("too large I/O: %zu bytes", size); return (EIO); } - blks = size / BD(dev).bd_sectorsize; - if (blks == 0 || (size % BD(dev).bd_sectorsize) != 0) + blks = size / bd->bd_sectorsize; + if (blks == 0 || (size % bd->bd_sectorsize) != 0) blks++; if (dblk > dblk + blks) return (EIO); if (rsize) *rsize = 0; /* * Get disk blocks, this value is either for whole disk or for * partition. */ - if (disk_ioctl(dev, DIOCGMEDIASIZE, &disk_blocks) == 0) { - /* DIOCGMEDIASIZE does return bytes. */ - disk_blocks /= BD(dev).bd_sectorsize; - } else { - /* We should not get here. Just try to survive. */ - disk_blocks = BD(dev).bd_sectors - dev->d_offset; + d_offset = 0; + disk_blocks = 0; + if (dev->dd.d_dev->dv_type == DEVT_DISK) { + if (disk_ioctl(dev, DIOCGMEDIASIZE, &disk_blocks) == 0) { + /* DIOCGMEDIASIZE does return bytes. */ + disk_blocks /= bd->bd_sectorsize; + } + d_offset = dev->d_offset; } + if (disk_blocks == 0) + disk_blocks = bd->bd_sectors - d_offset; /* Validate source block address. */ - if (dblk < dev->d_offset || dblk >= dev->d_offset + disk_blocks) + if (dblk < d_offset || dblk >= d_offset + disk_blocks) return (EIO); /* * Truncate if we are crossing disk or partition end. */ - if (dblk + blks >= dev->d_offset + disk_blocks) { - blks = dev->d_offset + disk_blocks - dblk; - size = blks * BD(dev).bd_sectorsize; + if (dblk + blks >= d_offset + disk_blocks) { + blks = d_offset + disk_blocks - dblk; + size = blks * bd->bd_sectorsize; DEBUG("short I/O %d", blks); } - if (V86_IO_BUFFER_SIZE / BD(dev).bd_sectorsize == 0) + if (V86_IO_BUFFER_SIZE / bd->bd_sectorsize == 0) panic("BUG: Real mode buffer is too small"); bbuf = PTOV(V86_IO_BUFFER); rest = size; while (blks > 0) { - int x = min(blks, V86_IO_BUFFER_SIZE / BD(dev).bd_sectorsize); + int x = min(blks, V86_IO_BUFFER_SIZE / bd->bd_sectorsize); switch (rw & F_MASK) { case F_READ: DEBUG("read %d from %lld to %p", x, dblk, buf); - bsize = BD(dev).bd_sectorsize * x - blkoff; + bsize = bd->bd_sectorsize * x - blkoff; if (rest < bsize) bsize = rest; - if ((rc = bd_io(dev, dblk, x, bbuf, BD_RD)) != 0) + if ((rc = bd_io(dev, bd, dblk, x, bbuf, BD_RD)) != 0) return (EIO); bcopy(bbuf + blkoff, buf, bsize); break; case F_WRITE : DEBUG("write %d from %lld to %p", x, dblk, buf); if (blkoff != 0) { /* * We got offset to sector, read 1 sector to * bbuf. */ x = 1; - bsize = BD(dev).bd_sectorsize - blkoff; + bsize = bd->bd_sectorsize - blkoff; bsize = min(bsize, rest); - rc = bd_io(dev, dblk, x, bbuf, BD_RD); - } else if (rest < BD(dev).bd_sectorsize) { + rc = bd_io(dev, bd, dblk, x, bbuf, BD_RD); + } else if (rest < bd->bd_sectorsize) { /* * The remaining block is not full * sector. Read 1 sector to bbuf. */ x = 1; bsize = rest; - rc = bd_io(dev, dblk, x, bbuf, BD_RD); + rc = bd_io(dev, bd, dblk, x, bbuf, BD_RD); } else { /* We can write full sector(s). */ - bsize = BD(dev).bd_sectorsize * x; + bsize = bd->bd_sectorsize * x; } /* * Put your Data In, Put your Data out, * Put your Data In, and shake it all about */ bcopy(buf, bbuf + blkoff, bsize); - if ((rc = bd_io(dev, dblk, x, bbuf, BD_WR)) != 0) + if ((rc = bd_io(dev, bd, dblk, x, bbuf, BD_WR)) != 0) return (EIO); break; default: /* DO NOTHING */ return (EROFS); } blkoff = 0; buf += bsize; rest -= bsize; blks -= x; dblk += x; } if (rsize != NULL) *rsize = size; return (0); } static int -bd_edd_io(struct disk_devdesc *dev, daddr_t dblk, int blks, caddr_t dest, +bd_edd_io(bdinfo_t *bd, daddr_t dblk, int blks, caddr_t dest, int dowrite) { static struct edd_packet packet; packet.len = sizeof(struct edd_packet); packet.count = blks; packet.off = VTOPOFF(dest); packet.seg = VTOPSEG(dest); packet.lba = dblk; v86.ctl = V86_FLAGS; v86.addr = 0x13; /* Should we Write with verify ?? 0x4302 ? */ if (dowrite == BD_WR) v86.eax = 0x4300; else v86.eax = 0x4200; - v86.edx = BD(dev).bd_unit; + v86.edx = bd->bd_unit; v86.ds = VTOPSEG(&packet); v86.esi = VTOPOFF(&packet); v86int(); if (V86_CY(v86.efl)) return (v86.eax >> 8); return (0); } static int -bd_chs_io(struct disk_devdesc *dev, daddr_t dblk, int blks, caddr_t dest, +bd_chs_io(bdinfo_t *bd, daddr_t dblk, int blks, caddr_t dest, int dowrite) { uint32_t x, bpc, cyl, hd, sec; - bpc = BD(dev).bd_sec * BD(dev).bd_hds; /* blocks per cylinder */ + bpc = bd->bd_sec * bd->bd_hds; /* blocks per cylinder */ x = dblk; cyl = x / bpc; /* block # / blocks per cylinder */ x %= bpc; /* block offset into cylinder */ - hd = x / BD(dev).bd_sec; /* offset / blocks per track */ - sec = x % BD(dev).bd_sec; /* offset into track */ + hd = x / bd->bd_sec; /* offset / blocks per track */ + sec = x % bd->bd_sec; /* offset into track */ /* correct sector number for 1-based BIOS numbering */ sec++; if (cyl > 1023) { /* CHS doesn't support cylinders > 1023. */ return (1); } v86.ctl = V86_FLAGS; v86.addr = 0x13; if (dowrite == BD_WR) v86.eax = 0x300 | blks; else v86.eax = 0x200 | blks; v86.ecx = ((cyl & 0xff) << 8) | ((cyl & 0x300) >> 2) | sec; - v86.edx = (hd << 8) | BD(dev).bd_unit; + v86.edx = (hd << 8) | bd->bd_unit; v86.es = VTOPSEG(dest); v86.ebx = VTOPOFF(dest); v86int(); if (V86_CY(v86.efl)) return (v86.eax >> 8); return (0); } static void -bd_io_workaround(struct disk_devdesc *dev) +bd_io_workaround(bdinfo_t *bd) { uint8_t buf[8 * 1024]; - bd_edd_io(dev, 0xffffffff, 1, (caddr_t)buf, BD_RD); + bd_edd_io(bd, 0xffffffff, 1, (caddr_t)buf, BD_RD); } static int -bd_io(struct disk_devdesc *dev, daddr_t dblk, int blks, caddr_t dest, - int dowrite) +bd_io(struct disk_devdesc *dev, bdinfo_t *bd, daddr_t dblk, int blks, + caddr_t dest, int dowrite) { int result, retry; /* Just in case some idiot actually tries to read/write -1 blocks... */ if (blks < 0) return (-1); /* * Workaround for a problem with some HP ProLiant BIOS failing to work * out the boot disk after installation. hrs and kuriyama discovered * this problem with an HP ProLiant DL320e Gen 8 with a 3TB HDD, and * discovered that an int13h call seems to cause a buffer overrun in * the bios. The problem is alleviated by doing an extra read before * the buggy read. It is not immediately known whether other models * are similarly affected. * Loop retrying the operation a couple of times. The BIOS * may also retry. */ if (dowrite == BD_RD && dblk >= 0x100000000) - bd_io_workaround(dev); + bd_io_workaround(bd); for (retry = 0; retry < 3; retry++) { - if (BD(dev).bd_flags & BD_MODEEDD) - result = bd_edd_io(dev, dblk, blks, dest, dowrite); + if (bd->bd_flags & BD_MODEEDD) + result = bd_edd_io(bd, dblk, blks, dest, dowrite); else - result = bd_chs_io(dev, dblk, blks, dest, dowrite); + result = bd_chs_io(bd, dblk, blks, dest, dowrite); if (result == 0) { - if (BD(dev).bd_flags & BD_NO_MEDIA) - BD(dev).bd_flags &= ~BD_NO_MEDIA; + if (bd->bd_flags & BD_NO_MEDIA) + bd->bd_flags &= ~BD_NO_MEDIA; break; } - bd_reset_disk(BD(dev).bd_unit); + bd_reset_disk(bd->bd_unit); /* * Error codes: * 20h controller failure * 31h no media in drive (IBM/MS INT 13 extensions) * 80h no media in drive, VMWare (Fusion) * There is no reason to repeat the IO with errors above. */ if (result == 0x20 || result == 0x31 || result == 0x80) { - BD(dev).bd_flags |= BD_NO_MEDIA; + bd->bd_flags |= BD_NO_MEDIA; break; } } - if (result != 0 && (BD(dev).bd_flags & BD_NO_MEDIA) == 0) { + if (result != 0 && (bd->bd_flags & BD_NO_MEDIA) == 0) { if (dowrite == BD_WR) { printf("%s%d: Write %d sector(s) from %p (0x%x) " "to %lld: 0x%x\n", dev->dd.d_dev->dv_name, dev->dd.d_unit, blks, dest, VTOP(dest), dblk, result); } else { printf("%s%d: Read %d sector(s) from %lld to %p " "(0x%x): 0x%x\n", dev->dd.d_dev->dv_name, dev->dd.d_unit, blks, dblk, dest, VTOP(dest), result); } } return (result); } /* * Return the BIOS geometry of a given "fixed drive" in a format * suitable for the legacy bootinfo structure. Since the kernel is * expecting raw int 0x13/0x8 values for N_BIOS_GEOM drives, we * prefer to get the information directly, rather than rely on being * able to put it together from information already maintained for * different purposes and for a probably different number of drives. * * For valid drives, the geometry is expected in the format (31..0) * "000000cc cccccccc hhhhhhhh 00ssssss"; and invalid drives are * indicated by returning the geometry of a "1.2M" PC-format floppy * disk. And, incidentally, what is returned is not the geometry as * such but the highest valid cylinder, head, and sector numbers. */ uint32_t bd_getbigeom(int bunit) { v86.ctl = V86_FLAGS; v86.addr = 0x13; v86.eax = 0x800; v86.edx = 0x80 + bunit; v86int(); if (V86_CY(v86.efl)) return (0x4f010f); return (((v86.ecx & 0xc0) << 18) | ((v86.ecx & 0xff00) << 8) | (v86.edx & 0xff00) | (v86.ecx & 0x3f)); } /* * Return a suitable dev_t value for (dev). * * In the case where it looks like (dev) is a SCSI disk, we allow the number of * IDE disks to be specified in $num_ide_disks. There should be a Better Way. */ int bd_getdev(struct i386_devdesc *d) { struct disk_devdesc *dev; + bdinfo_t *bd; int biosdev; int major; int rootdev; char *nip, *cp; - int i, unit; + int i, unit, slice, partition; + /* XXX: Assume partition 'a'. */ + slice = 0; + partition = 0; + dev = (struct disk_devdesc *)d; - biosdev = bd_unit2bios(dev->dd.d_unit); + bd = bd_get_bdinfo(&dev->dd); + if (bd == NULL) + return (-1); + + biosdev = bd_unit2bios(d); DEBUG("unit %d BIOS device %d", dev->dd.d_unit, biosdev); if (biosdev == -1) /* not a BIOS device */ return (-1); - if (disk_open(dev, BD(dev).bd_sectors * BD(dev).bd_sectorsize, - BD(dev).bd_sectorsize) != 0) /* oops, not a viable device */ - return (-1); - else - disk_close(dev); + if (dev->dd.d_dev->dv_type == DEVT_DISK) { + if (disk_open(dev, bd->bd_sectors * bd->bd_sectorsize, + bd->bd_sectorsize) != 0) /* oops, not a viable device */ + return (-1); + else + disk_close(dev); + slice = dev->d_slice + 1; + partition = dev->d_partition; + } + if (biosdev < 0x80) { /* floppy (or emulated floppy) or ATAPI device */ - if (bdinfo[dev->dd.d_unit].bd_type == DT_ATAPI) { + if (bd->bd_type == DT_ATAPI) { /* is an ATAPI disk */ major = WFDMAJOR; } else { /* is a floppy disk */ major = FDMAJOR; } } else { /* assume an IDE disk */ major = WDMAJOR; } /* default root disk unit number */ unit = biosdev & 0x7f; + if (dev->dd.d_dev->dv_type == DEVT_CD) { + /* + * XXX: Need to examine device spec here to figure out if + * SCSI or ATAPI. No idea on how to figure out device number. + * All we can really pass to the kernel is what bus and device + * on which bus we were booted from, which dev_t isn't well + * suited to since those number don't match to unit numbers + * very well. We may just need to engage in a hack where + * we pass -C to the boot args if we are the boot device. + */ + major = ACDMAJOR; + unit = 0; /* XXX */ + } + /* XXX a better kludge to set the root disk unit number */ if ((nip = getenv("root_disk_unit")) != NULL) { i = strtol(nip, &cp, 0); /* check for parse error */ if ((cp != nip) && (*cp == 0)) unit = i; } - rootdev = MAKEBOOTDEV(major, dev->d_slice + 1, unit, dev->d_partition); + rootdev = MAKEBOOTDEV(major, slice, unit, partition); DEBUG("dev is 0x%x\n", rootdev); return (rootdev); } Index: stable/12/stand/i386/libi386/bootinfo32.c =================================================================== --- stable/12/stand/i386/libi386/bootinfo32.c (revision 342615) +++ stable/12/stand/i386/libi386/bootinfo32.c (revision 342616) @@ -1,283 +1,278 @@ /*- * Copyright (c) 1998 Michael Smith * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include "bootstrap.h" #include "libi386.h" #include "btxv86.h" #ifdef LOADER_GELI_SUPPORT #include "geliboot.h" #endif static struct bootinfo bi; /* * Copy module-related data into the load area, where it can be * used as a directory for loaded modules. * * Module data is presented in a self-describing format. Each datum * is preceded by a 32-bit identifier and a 32-bit size field. * * Currently, the following data are saved: * * MOD_NAME (variable) module name (string) * MOD_TYPE (variable) module type (string) * MOD_ARGS (variable) module parameters (string) * MOD_ADDR sizeof(vm_offset_t) module load address * MOD_SIZE sizeof(size_t) module size * MOD_METADATA (variable) type-specific metadata */ #define COPY32(v, a, c) { \ uint32_t x = (v); \ if (c) \ i386_copyin(&x, a, sizeof(x)); \ a += sizeof(x); \ } #define MOD_STR(t, a, s, c) { \ COPY32(t, a, c); \ COPY32(strlen(s) + 1, a, c); \ if (c) \ i386_copyin(s, a, strlen(s) + 1); \ a += roundup(strlen(s) + 1, sizeof(u_long));\ } #define MOD_NAME(a, s, c) MOD_STR(MODINFO_NAME, a, s, c) #define MOD_TYPE(a, s, c) MOD_STR(MODINFO_TYPE, a, s, c) #define MOD_ARGS(a, s, c) MOD_STR(MODINFO_ARGS, a, s, c) #define MOD_VAR(t, a, s, c) { \ COPY32(t, a, c); \ COPY32(sizeof(s), a, c); \ if (c) \ i386_copyin(&s, a, sizeof(s)); \ a += roundup(sizeof(s), sizeof(u_long)); \ } #define MOD_ADDR(a, s, c) MOD_VAR(MODINFO_ADDR, a, s, c) #define MOD_SIZE(a, s, c) MOD_VAR(MODINFO_SIZE, a, s, c) #define MOD_METADATA(a, mm, c) { \ COPY32(MODINFO_METADATA | mm->md_type, a, c); \ COPY32(mm->md_size, a, c); \ if (c) \ i386_copyin(mm->md_data, a, mm->md_size); \ a += roundup(mm->md_size, sizeof(u_long));\ } #define MOD_END(a, c) { \ COPY32(MODINFO_END, a, c); \ COPY32(0, a, c); \ } static vm_offset_t bi_copymodules32(vm_offset_t addr) { struct preloaded_file *fp; struct file_metadata *md; int c; c = addr != 0; /* start with the first module on the list, should be the kernel */ for (fp = file_findfile(NULL, NULL); fp != NULL; fp = fp->f_next) { MOD_NAME(addr, fp->f_name, c); /* this field must come first */ MOD_TYPE(addr, fp->f_type, c); if (fp->f_args) MOD_ARGS(addr, fp->f_args, c); MOD_ADDR(addr, fp->f_addr, c); MOD_SIZE(addr, fp->f_size, c); for (md = fp->f_metadata; md != NULL; md = md->md_next) if (!(md->md_type & MODINFOMD_NOCOPY)) MOD_METADATA(addr, md, c); } MOD_END(addr, c); return(addr); } /* * Load the information expected by an i386 kernel. * * - The 'boothowto' argument is constructed * - The 'bootdev' argument is constructed * - The 'bootinfo' struct is constructed, and copied into the kernel space. * - The kernel environment is copied into kernel space. * - Module metadata are formatted and placed in kernel space. */ int bi_load32(char *args, int *howtop, int *bootdevp, vm_offset_t *bip, vm_offset_t *modulep, vm_offset_t *kernendp) { struct preloaded_file *xp, *kfp; struct i386_devdesc *rootdev; struct file_metadata *md; vm_offset_t addr; vm_offset_t kernend; vm_offset_t envp; vm_offset_t size; vm_offset_t ssym, esym; char *rootdevname; int bootdevnr, i, howto; char *kernelname; const char *kernelpath; howto = bi_getboothowto(args); /* * Allow the environment variable 'rootdev' to override the supplied device * This should perhaps go to MI code and/or have $rootdev tested/set by * MI code before launching the kernel. */ rootdevname = getenv("rootdev"); i386_getdev((void **)(&rootdev), rootdevname, NULL); if (rootdev == NULL) { /* bad $rootdev/$currdev */ printf("can't determine root device\n"); return(EINVAL); } /* Try reading the /etc/fstab file to select the root device */ getrootmount(i386_fmtdev((void *)rootdev)); /* Do legacy rootdev guessing */ /* XXX - use a default bootdev of 0. Is this ok??? */ bootdevnr = 0; switch(rootdev->dd.d_dev->dv_type) { case DEVT_CD: - /* Pass in BIOS device number. */ - bi.bi_bios_dev = bc_unit2bios(rootdev->dd.d_unit); - bootdevnr = bc_getdev(rootdev); - break; - case DEVT_DISK: /* pass in the BIOS device number of the current disk */ - bi.bi_bios_dev = bd_unit2bios(rootdev->dd.d_unit); + bi.bi_bios_dev = bd_unit2bios(rootdev); bootdevnr = bd_getdev(rootdev); break; case DEVT_NET: case DEVT_ZFS: break; default: printf("WARNING - don't know how to boot from device type %d\n", rootdev->dd.d_dev->dv_type); } if (bootdevnr == -1) { printf("root device %s invalid\n", i386_fmtdev(rootdev)); return (EINVAL); } free(rootdev); /* find the last module in the chain */ addr = 0; for (xp = file_findfile(NULL, NULL); xp != NULL; xp = xp->f_next) { if (addr < (xp->f_addr + xp->f_size)) addr = xp->f_addr + xp->f_size; } /* pad to a page boundary */ addr = roundup(addr, PAGE_SIZE); /* copy our environment */ envp = addr; addr = bi_copyenv(addr); /* pad to a page boundary */ addr = roundup(addr, PAGE_SIZE); kfp = file_findfile(NULL, "elf kernel"); if (kfp == NULL) kfp = file_findfile(NULL, "elf32 kernel"); if (kfp == NULL) panic("can't find kernel file"); kernend = 0; /* fill it in later */ file_addmetadata(kfp, MODINFOMD_HOWTO, sizeof howto, &howto); file_addmetadata(kfp, MODINFOMD_ENVP, sizeof envp, &envp); file_addmetadata(kfp, MODINFOMD_KERNEND, sizeof kernend, &kernend); bios_addsmapdata(kfp); #ifdef LOADER_GELI_SUPPORT geli_export_key_metadata(kfp); #endif /* Figure out the size and location of the metadata */ *modulep = addr; size = bi_copymodules32(0); kernend = roundup(addr + size, PAGE_SIZE); *kernendp = kernend; /* patch MODINFOMD_KERNEND */ md = file_findmetadata(kfp, MODINFOMD_KERNEND); bcopy(&kernend, md->md_data, sizeof kernend); /* copy module list and metadata */ (void)bi_copymodules32(addr); ssym = esym = 0; md = file_findmetadata(kfp, MODINFOMD_SSYM); if (md != NULL) ssym = *((vm_offset_t *)&(md->md_data)); md = file_findmetadata(kfp, MODINFOMD_ESYM); if (md != NULL) esym = *((vm_offset_t *)&(md->md_data)); if (ssym == 0 || esym == 0) ssym = esym = 0; /* sanity */ /* legacy bootinfo structure */ kernelname = getenv("kernelname"); i386_getdev(NULL, kernelname, &kernelpath); bi.bi_version = BOOTINFO_VERSION; bi.bi_kernelname = 0; /* XXX char * -> kernel name */ bi.bi_nfs_diskless = 0; /* struct nfs_diskless * */ bi.bi_n_bios_used = 0; /* XXX would have to hook biosdisk driver for these */ for (i = 0; i < N_BIOS_GEOM; i++) bi.bi_bios_geom[i] = bd_getbigeom(i); bi.bi_size = sizeof(bi); bi.bi_memsizes_valid = 1; bi.bi_basemem = bios_basemem / 1024; bi.bi_extmem = bios_extmem / 1024; bi.bi_envp = envp; bi.bi_modulep = *modulep; bi.bi_kernend = kernend; bi.bi_kernelname = VTOP(kernelpath); bi.bi_symtab = ssym; /* XXX this is only the primary kernel symtab */ bi.bi_esymtab = esym; /* legacy boot arguments */ *howtop = howto | RB_BOOTINFO; *bootdevp = bootdevnr; *bip = VTOP(&bi); return(0); } Index: stable/12/stand/i386/libi386/libi386.h =================================================================== --- stable/12/stand/i386/libi386/libi386.h (revision 342615) +++ stable/12/stand/i386/libi386/libi386.h (revision 342616) @@ -1,151 +1,149 @@ /*- * Copyright (c) 1998 Michael Smith * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ /* * i386 fully-qualified device descriptor. */ struct i386_devdesc { struct devdesc dd; /* Must be first. */ union { struct { int slice; int partition; off_t offset; } biosdisk; struct { uint64_t pool_guid; uint64_t root_guid; } zfs; } d_kind; }; /* * relocater trampoline support. */ struct relocate_data { uint32_t src; uint32_t dest; uint32_t size; }; extern void relocater(void); /* * The relocater_data[] is fixed size array allocated in relocater_tramp.S */ extern struct relocate_data relocater_data[]; extern uint32_t relocater_size; extern uint16_t relocator_ip; extern uint16_t relocator_cs; extern uint16_t relocator_ds; extern uint16_t relocator_es; extern uint16_t relocator_fs; extern uint16_t relocator_gs; extern uint16_t relocator_ss; extern uint16_t relocator_sp; extern uint32_t relocator_esi; extern uint32_t relocator_eax; extern uint32_t relocator_ebx; extern uint32_t relocator_edx; extern uint32_t relocator_ebp; extern uint16_t relocator_a20_enabled; int i386_getdev(void **vdev, const char *devspec, const char **path); char *i386_fmtdev(void *vdev); int i386_setcurrdev(struct env_var *ev, int flags, const void *value); extern struct devdesc currdev; /* our current device */ #define MAXDEV 31 /* maximum number of distinct devices */ #define MAXBDDEV MAXDEV /* exported devices XXX rename? */ extern struct devsw bioscd; -extern struct devsw biosdisk; +extern struct devsw biosfd; +extern struct devsw bioshd; extern struct devsw pxedisk; extern struct fs_ops pxe_fsops; int bc_add(int biosdev); /* Register CD booted from. */ -int bc_getdev(struct i386_devdesc *dev); /* return dev_t for (dev) */ -int bc_bios2unit(int biosdev); /* xlate BIOS device -> bioscd unit */ -int bc_unit2bios(int unit); /* xlate bioscd unit -> BIOS device */ uint32_t bd_getbigeom(int bunit); /* return geometry in bootinfo format */ int bd_bios2unit(int biosdev); /* xlate BIOS device -> biosdisk unit */ -int bd_unit2bios(int unit); /* xlate biosdisk unit -> BIOS device */ +int bd_unit2bios(struct i386_devdesc *); /* xlate biosdisk -> BIOS device */ int bd_getdev(struct i386_devdesc *dev); /* return dev_t for (dev) */ ssize_t i386_copyin(const void *src, vm_offset_t dest, const size_t len); ssize_t i386_copyout(const vm_offset_t src, void *dest, const size_t len); ssize_t i386_readin(const int fd, vm_offset_t dest, const size_t len); struct preloaded_file; void bios_addsmapdata(struct preloaded_file *); void bios_getsmap(void); void bios_getmem(void); extern uint32_t bios_basemem; /* base memory in bytes */ extern uint32_t bios_extmem; /* extended memory in bytes */ extern vm_offset_t memtop; /* last address of physical memory + 1 */ extern vm_offset_t memtop_copyin; /* memtop less heap size for the cases */ /* when heap is at the top of */ /* extended memory; for other cases */ /* just the same as memtop */ extern uint32_t high_heap_size; /* extended memory region available */ extern vm_offset_t high_heap_base; /* for use as the heap */ /* * Values for width parameter to biospci_{read,write}_config */ #define BIOSPCI_8BITS 0 #define BIOSPCI_16BITS 1 #define BIOSPCI_32BITS 2 void biospci_detect(void); int biospci_find_devclass(uint32_t class, int index, uint32_t *locator); int biospci_read_config(uint32_t locator, int offset, int width, uint32_t *val); uint32_t biospci_locator(int8_t bus, uint8_t device, uint8_t function); int biospci_write_config(uint32_t locator, int offset, int width, uint32_t val); void biosacpi_detect(void); int i386_autoload(void); int bi_getboothowto(char *kargs); void bi_setboothowto(int howto); vm_offset_t bi_copyenv(vm_offset_t addr); int bi_load32(char *args, int *howtop, int *bootdevp, vm_offset_t *bip, vm_offset_t *modulep, vm_offset_t *kernend); int bi_load64(char *args, vm_offset_t addr, vm_offset_t *modulep, vm_offset_t *kernend, int add_smap); void pxe_enable(void *pxeinfo); Index: stable/12/stand/i386/loader/chain.c =================================================================== --- stable/12/stand/i386/loader/chain.c (revision 342615) +++ stable/12/stand/i386/loader/chain.c (revision 342616) @@ -1,136 +1,136 @@ /*- * Copyright 2015 Toomas Soome * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /* * Chain loader to load BIOS boot block either from MBR or PBR. * * Note the boot block location 0000:7c000 conflicts with loader, so we need to * read in to temporary space and relocate on exec, when btx is stopped. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include "bootstrap.h" #include "libi386/libi386.h" #include "btxv86.h" /* * The MBR/VBR is located in first sector of disk/partition. * Read 512B to temporary location and set up relocation. Then * exec relocator. */ #define SECTOR_SIZE (512) COMMAND_SET(chain, "chain", "chain load boot block from device", command_chain); static int command_chain(int argc, char *argv[]) { int fd, len, size = SECTOR_SIZE; struct stat st; vm_offset_t mem = 0x100000; struct i386_devdesc *rootdev; if (argc == 1) { command_errmsg = "no device or file name specified"; return (CMD_ERROR); } if (argc != 2) { command_errmsg = "invalid trailing arguments"; return (CMD_ERROR); } fd = open(argv[1], O_RDONLY); if (fd == -1) { command_errmsg = "open failed"; return (CMD_ERROR); } len = strlen(argv[1]); if (argv[1][len-1] != ':') { if (fstat(fd, &st) == -1) { command_errmsg = "stat failed"; close(fd); return (CMD_ERROR); } size = st.st_size; } else if (strncmp(argv[1], "disk", 4) != 0) { command_errmsg = "can only use disk device"; close(fd); return (CMD_ERROR); } i386_getdev((void **)(&rootdev), argv[1], NULL); if (rootdev == NULL) { command_errmsg = "can't determine root device"; close(fd); return (CMD_ERROR); } if (archsw.arch_readin(fd, mem, size) != size) { command_errmsg = "failed to read disk"; close(fd); return (CMD_ERROR); } close(fd); if (argv[1][len-1] == ':' && *((uint16_t *)PTOV(mem + DOSMAGICOFFSET)) != DOSMAGIC) { command_errmsg = "wrong magic"; return (CMD_ERROR); } relocater_data[0].src = mem; relocater_data[0].dest = 0x7C00; relocater_data[0].size = size; - relocator_edx = bd_unit2bios(rootdev->dd.d_unit); + relocator_edx = bd_unit2bios(rootdev); relocator_esi = relocater_size; relocator_ds = 0; relocator_es = 0; relocator_fs = 0; relocator_gs = 0; relocator_ss = 0; relocator_cs = 0; relocator_sp = 0x7C00; relocator_ip = 0x7C00; relocator_a20_enabled = 0; i386_copyin(relocater, 0x600, relocater_size); dev_cleanup(); __exec((void *)0x600); panic("exec returned"); return (CMD_ERROR); /* not reached */ } Index: stable/12/stand/i386/loader/conf.c =================================================================== --- stable/12/stand/i386/loader/conf.c (revision 342615) +++ stable/12/stand/i386/loader/conf.c (revision 342616) @@ -1,167 +1,168 @@ /*- * Copyright (c) 1998 Michael Smith * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include #include "libi386/libi386.h" #if defined(LOADER_ZFS_SUPPORT) #include "libzfs.h" #endif /* * We could use linker sets for some or all of these, but * then we would have to control what ended up linked into * the bootstrap. So it's easier to conditionalise things * here. * * XXX rename these arrays to be consistent and less namespace-hostile * * XXX as libi386 and biosboot merge, some of these can become linker sets. */ #if defined(LOADER_FIREWIRE_SUPPORT) extern struct devsw fwohci; #endif /* Exported for libstand */ struct devsw *devsw[] = { + &biosfd, &bioscd, - &biosdisk, + &bioshd, #if defined(LOADER_NFS_SUPPORT) || defined(LOADER_TFTP_SUPPORT) &pxedisk, #endif #if defined(LOADER_FIREWIRE_SUPPORT) &fwohci, #endif #if defined(LOADER_ZFS_SUPPORT) &zfs_dev, #endif NULL }; struct fs_ops *file_system[] = { #if defined(LOADER_ZFS_SUPPORT) &zfs_fsops, #endif #if defined(LOADER_UFS_SUPPORT) &ufs_fsops, #endif #if defined(LOADER_EXT2FS_SUPPORT) &ext2fs_fsops, #endif #if defined(LOADER_MSDOS_SUPPORT) &dosfs_fsops, #endif #if defined(LOADER_CD9660_SUPPORT) &cd9660_fsops, #endif #if defined(LOADER_NANDFS_SUPPORT) &nandfs_fsops, #endif #ifdef LOADER_NFS_SUPPORT &nfs_fsops, #endif #ifdef LOADER_TFTP_SUPPORT &tftp_fsops, #endif #ifdef LOADER_GZIP_SUPPORT &gzipfs_fsops, #endif #ifdef LOADER_BZIP2_SUPPORT &bzipfs_fsops, #endif #ifdef LOADER_SPLIT_SUPPORT &splitfs_fsops, #endif NULL }; /* Exported for i386 only */ /* * Sort formats so that those that can detect based on arguments * rather than reading the file go first. */ extern struct file_format i386_elf; extern struct file_format i386_elf_obj; extern struct file_format amd64_elf; extern struct file_format amd64_elf_obj; extern struct file_format multiboot; extern struct file_format multiboot_obj; struct file_format *file_formats[] = { &multiboot, &multiboot_obj, #ifdef LOADER_PREFER_AMD64 &amd64_elf, &amd64_elf_obj, #endif &i386_elf, &i386_elf_obj, #ifndef LOADER_PREFER_AMD64 &amd64_elf, &amd64_elf_obj, #endif NULL }; /* * Consoles * * We don't prototype these in libi386.h because they require * data structures from bootstrap.h as well. */ extern struct console vidconsole; extern struct console comconsole; #if defined(LOADER_FIREWIRE_SUPPORT) extern struct console dconsole; #endif extern struct console nullconsole; extern struct console spinconsole; struct console *consoles[] = { &vidconsole, &comconsole, #if defined(LOADER_FIREWIRE_SUPPORT) &dconsole, #endif &nullconsole, &spinconsole, NULL }; extern struct pnphandler isapnphandler; extern struct pnphandler biospnphandler; extern struct pnphandler biospcihandler; struct pnphandler *pnphandlers[] = { &biospnphandler, /* should go first, as it may set isapnp_readport */ &isapnphandler, &biospcihandler, NULL }; Index: stable/12/stand/i386/loader/main.c =================================================================== --- stable/12/stand/i386/loader/main.c (revision 342615) +++ stable/12/stand/i386/loader/main.c (revision 342616) @@ -1,408 +1,406 @@ /*- * Copyright (c) 1998 Michael Smith * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); /* * MD bootstrap main() and assorted miscellaneous * commands. */ #include #include #include #include #include #include #include #include #include #include "bootstrap.h" #include "common/bootargs.h" #include "libi386/libi386.h" #include "libi386/smbios.h" #include "btxv86.h" #ifdef LOADER_ZFS_SUPPORT #include "libzfs.h" #endif CTASSERT(sizeof(struct bootargs) == BOOTARGS_SIZE); CTASSERT(offsetof(struct bootargs, bootinfo) == BA_BOOTINFO); CTASSERT(offsetof(struct bootargs, bootflags) == BA_BOOTFLAGS); CTASSERT(offsetof(struct bootinfo, bi_size) == BI_SIZE); /* Arguments passed in from the boot1/boot2 loader */ static struct bootargs *kargs; static uint32_t initial_howto; static uint32_t initial_bootdev; static struct bootinfo *initial_bootinfo; struct arch_switch archsw; /* MI/MD interface boundary */ static void extract_currdev(void); static int isa_inb(int port); static void isa_outb(int port, int value); void exit(int code); #ifdef LOADER_GELI_SUPPORT #include "geliboot.h" struct geli_boot_args *gargs; #endif #ifdef LOADER_ZFS_SUPPORT struct zfs_boot_args *zargs; static void i386_zfs_probe(void); #endif /* XXX debugging */ extern char end[]; static void *heap_top; static void *heap_bottom; int main(void) { int i; /* Pick up arguments */ kargs = (void *)__args; initial_howto = kargs->howto; initial_bootdev = kargs->bootdev; initial_bootinfo = kargs->bootinfo ? (struct bootinfo *)PTOV(kargs->bootinfo) : NULL; /* Initialize the v86 register set to a known-good state. */ bzero(&v86, sizeof(v86)); v86.efl = PSL_RESERVED_DEFAULT | PSL_I; /* * Initialise the heap as early as possible. Once this is done, malloc() is usable. */ bios_getmem(); #if defined(LOADER_BZIP2_SUPPORT) || defined(LOADER_FIREWIRE_SUPPORT) || \ defined(LOADER_GPT_SUPPORT) || defined(LOADER_ZFS_SUPPORT) if (high_heap_size > 0) { heap_top = PTOV(high_heap_base + high_heap_size); heap_bottom = PTOV(high_heap_base); if (high_heap_base < memtop_copyin) memtop_copyin = high_heap_base; } else #endif { heap_top = (void *)PTOV(bios_basemem); heap_bottom = (void *)end; } setheap(heap_bottom, heap_top); /* * XXX Chicken-and-egg problem; we want to have console output early, but some * console attributes may depend on reading from eg. the boot device, which we * can't do yet. * * We can use printf() etc. once this is done. * If the previous boot stage has requested a serial console, prefer that. */ bi_setboothowto(initial_howto); if (initial_howto & RB_MULTIPLE) { if (initial_howto & RB_SERIAL) setenv("console", "comconsole vidconsole", 1); else setenv("console", "vidconsole comconsole", 1); } else if (initial_howto & RB_SERIAL) setenv("console", "comconsole", 1); else if (initial_howto & RB_MUTE) setenv("console", "nullconsole", 1); cons_probe(); /* * Initialise the block cache. Set the upper limit. */ bcache_init(32768, 512); /* * Special handling for PXE and CD booting. */ if (kargs->bootinfo == 0) { /* * We only want the PXE disk to try to init itself in the below * walk through devsw if we actually booted off of PXE. */ if (kargs->bootflags & KARGS_FLAGS_PXE) pxe_enable(kargs->pxeinfo ? PTOV(kargs->pxeinfo) : NULL); else if (kargs->bootflags & KARGS_FLAGS_CD) bc_add(initial_bootdev); } archsw.arch_autoload = i386_autoload; archsw.arch_getdev = i386_getdev; archsw.arch_copyin = i386_copyin; archsw.arch_copyout = i386_copyout; archsw.arch_readin = i386_readin; archsw.arch_isainb = isa_inb; archsw.arch_isaoutb = isa_outb; #ifdef LOADER_ZFS_SUPPORT archsw.arch_zfs_probe = i386_zfs_probe; #ifdef LOADER_GELI_SUPPORT if ((kargs->bootflags & KARGS_FLAGS_EXTARG) != 0) { zargs = (struct zfs_boot_args *)(kargs + 1); if (zargs != NULL && zargs->size >= offsetof(struct zfs_boot_args, gelipw)) { if (zargs->size >= offsetof(struct zfs_boot_args, keybuf_sentinel) && zargs->keybuf_sentinel == KEYBUF_SENTINEL) { geli_import_key_buffer(zargs->keybuf); } if (zargs->gelipw[0] != '\0') { setenv("kern.geom.eli.passphrase", zargs->gelipw, 1); explicit_bzero(zargs->gelipw, sizeof(zargs->gelipw)); } } } #endif /* LOADER_GELI_SUPPORT */ #else /* !LOADER_ZFS_SUPPORT */ #ifdef LOADER_GELI_SUPPORT if ((kargs->bootflags & KARGS_FLAGS_EXTARG) != 0) { gargs = (struct geli_boot_args *)(kargs + 1); if (gargs != NULL && gargs->size >= offsetof(struct geli_boot_args, gelipw)) { if (gargs->keybuf_sentinel == KEYBUF_SENTINEL) { geli_import_key_buffer(gargs->keybuf); } if (gargs->gelipw[0] != '\0') { setenv("kern.geom.eli.passphrase", gargs->gelipw, 1); explicit_bzero(gargs->gelipw, sizeof(gargs->gelipw)); } } } #endif /* LOADER_GELI_SUPPORT */ #endif /* LOADER_ZFS_SUPPORT */ /* * March through the device switch probing for things. */ for (i = 0; devsw[i] != NULL; i++) if (devsw[i]->dv_init != NULL) (devsw[i]->dv_init)(); printf("BIOS %dkB/%dkB available memory\n", bios_basemem / 1024, bios_extmem / 1024); if (initial_bootinfo != NULL) { initial_bootinfo->bi_basemem = bios_basemem / 1024; initial_bootinfo->bi_extmem = bios_extmem / 1024; } /* detect ACPI for future reference */ biosacpi_detect(); /* detect SMBIOS for future reference */ smbios_detect(NULL); /* detect PCI BIOS for future reference */ biospci_detect(); printf("\n%s", bootprog_info); extract_currdev(); /* set $currdev and $loaddev */ setenv("LINES", "24", 1); /* optional */ bios_getsmap(); interact(); /* if we ever get here, it is an error */ return (1); } /* * Set the 'current device' by (if possible) recovering the boot device as * supplied by the initial bootstrap. * * XXX should be extended for netbooting. */ static void extract_currdev(void) { struct i386_devdesc new_currdev; #ifdef LOADER_ZFS_SUPPORT char buf[20]; #endif int biosdev = -1; /* Assume we are booting from a BIOS disk by default */ - new_currdev.dd.d_dev = &biosdisk; + new_currdev.dd.d_dev = &bioshd; /* new-style boot loaders such as pxeldr and cdldr */ if (kargs->bootinfo == 0) { if ((kargs->bootflags & KARGS_FLAGS_CD) != 0) { /* we are booting from a CD with cdboot */ new_currdev.dd.d_dev = &bioscd; - new_currdev.dd.d_unit = bc_bios2unit(initial_bootdev); + new_currdev.dd.d_unit = bd_bios2unit(initial_bootdev); } else if ((kargs->bootflags & KARGS_FLAGS_PXE) != 0) { /* we are booting from pxeldr */ new_currdev.dd.d_dev = &pxedisk; new_currdev.dd.d_unit = 0; } else { /* we don't know what our boot device is */ new_currdev.d_kind.biosdisk.slice = -1; new_currdev.d_kind.biosdisk.partition = 0; biosdev = -1; } #ifdef LOADER_ZFS_SUPPORT } else if ((kargs->bootflags & KARGS_FLAGS_ZFS) != 0) { zargs = NULL; /* check for new style extended argument */ if ((kargs->bootflags & KARGS_FLAGS_EXTARG) != 0) zargs = (struct zfs_boot_args *)(kargs + 1); if (zargs != NULL && zargs->size >= offsetof(struct zfs_boot_args, primary_pool)) { /* sufficient data is provided */ new_currdev.d_kind.zfs.pool_guid = zargs->pool; new_currdev.d_kind.zfs.root_guid = zargs->root; if (zargs->size >= sizeof(*zargs) && zargs->primary_vdev != 0) { sprintf(buf, "%llu", zargs->primary_pool); setenv("vfs.zfs.boot.primary_pool", buf, 1); sprintf(buf, "%llu", zargs->primary_vdev); setenv("vfs.zfs.boot.primary_vdev", buf, 1); } } else { /* old style zfsboot block */ new_currdev.d_kind.zfs.pool_guid = kargs->zfspool; new_currdev.d_kind.zfs.root_guid = 0; } new_currdev.dd.d_dev = &zfs_dev; #endif } else if ((initial_bootdev & B_MAGICMASK) != B_DEVMAGIC) { /* The passed-in boot device is bad */ new_currdev.d_kind.biosdisk.slice = -1; new_currdev.d_kind.biosdisk.partition = 0; biosdev = -1; } else { new_currdev.d_kind.biosdisk.slice = B_SLICE(initial_bootdev) - 1; new_currdev.d_kind.biosdisk.partition = B_PARTITION(initial_bootdev); biosdev = initial_bootinfo->bi_bios_dev; /* * If we are booted by an old bootstrap, we have to guess at the BIOS * unit number. We will lose if there is more than one disk type * and we are not booting from the lowest-numbered disk type * (ie. SCSI when IDE also exists). */ if ((biosdev == 0) && (B_TYPE(initial_bootdev) != 2)) /* biosdev doesn't match major */ biosdev = 0x80 + B_UNIT(initial_bootdev); /* assume harddisk */ } /* * If we are booting off of a BIOS disk and we didn't succeed in determining * which one we booted off of, just use disk0: as a reasonable default. */ - if ((new_currdev.dd.d_dev->dv_type == biosdisk.dv_type) && + if ((new_currdev.dd.d_dev->dv_type == bioshd.dv_type) && ((new_currdev.dd.d_unit = bd_bios2unit(biosdev)) == -1)) { printf("Can't work out which disk we are booting from.\n" "Guessed BIOS device 0x%x not found by probes, defaulting to disk0:\n", biosdev); new_currdev.dd.d_unit = 0; } #ifdef LOADER_ZFS_SUPPORT if (new_currdev.dd.d_dev->dv_type == DEVT_ZFS) init_zfs_bootenv(zfs_fmtdev(&new_currdev)); #endif env_setenv("currdev", EV_VOLATILE, i386_fmtdev(&new_currdev), i386_setcurrdev, env_nounset); env_setenv("loaddev", EV_VOLATILE, i386_fmtdev(&new_currdev), env_noset, env_nounset); } COMMAND_SET(reboot, "reboot", "reboot the system", command_reboot); static int command_reboot(int argc, char *argv[]) { int i; for (i = 0; devsw[i] != NULL; ++i) if (devsw[i]->dv_cleanup != NULL) (devsw[i]->dv_cleanup)(); printf("Rebooting...\n"); delay(1000000); __exit(0); } /* provide this for panic, as it's not in the startup code */ void exit(int code) { __exit(code); } COMMAND_SET(heap, "heap", "show heap usage", command_heap); static int command_heap(int argc, char *argv[]) { mallocstats(); printf("heap base at %p, top at %p, upper limit at %p\n", heap_bottom, sbrk(0), heap_top); return(CMD_OK); } /* ISA bus access functions for PnP. */ static int isa_inb(int port) { return (inb(port)); } static void isa_outb(int port, int value) { outb(port, value); } #ifdef LOADER_ZFS_SUPPORT static void i386_zfs_probe(void) { char devname[32]; - int unit; + struct i386_devdesc dev; /* * Open all the disks we can find and see if we can reconstruct * ZFS pools from them. */ - for (unit = 0; unit < MAXBDDEV; unit++) { - if (bd_unit2bios(unit) == -1) - break; - if (bd_unit2bios(unit) < 0x80) - continue; - sprintf(devname, "disk%d:", unit); + dev.dd.d_dev = &bioshd; + for (dev.dd.d_unit = 0; bd_unit2bios(&dev) >= 0; dev.dd.d_unit++) { + snprintf(devname, sizeof(devname), "%s%d:", bioshd.dv_name, + dev.dd.d_unit); zfs_probe_dev(devname, NULL); } } #endif Index: stable/12 =================================================================== --- stable/12 (revision 342615) +++ stable/12 (revision 342616) Property changes on: stable/12 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /head:r341328