diff options
author | Toomas Soome <tsoome@me.com> | 2018-05-19 18:50:26 +0300 |
---|---|---|
committer | Dan McDonald <danmcd@joyent.com> | 2018-06-11 12:38:43 -0400 |
commit | 5855bf06da593dee5899b9077ff2318df7a7c068 (patch) | |
tree | c78945cd7f2b28926c3bd8864414268cfb66580d | |
parent | af7c4cb5225cc98e505e165d8fe7b59f98595bbc (diff) | |
download | illumos-joyent-5855bf06da593dee5899b9077ff2318df7a7c068.tar.gz |
9543 loader: bd_io needs a bit cleanup
Reviewed by: Igor Kozhukhov <igor@dilos.org>
Reviewed by: Yuri Pankov <yuripv@yuripv.net>
Approved by: Dan McDonald <danmcd@joyent.com>
-rw-r--r-- | usr/src/boot/Makefile.version | 2 | ||||
-rw-r--r-- | usr/src/boot/sys/boot/i386/libi386/biosdisk.c | 250 |
2 files changed, 125 insertions, 127 deletions
diff --git a/usr/src/boot/Makefile.version b/usr/src/boot/Makefile.version index 4b2bde6131..5d8a7e586f 100644 --- a/usr/src/boot/Makefile.version +++ b/usr/src/boot/Makefile.version @@ -33,4 +33,4 @@ LOADER_VERSION = 1.1 # Use date like formatting here, YYYY.MM.DD.XX, without leading zeroes. # The version is processed from left to right, the version number can only # be increased. -BOOT_VERSION = $(LOADER_VERSION)-2018.3.29.1 +BOOT_VERSION = $(LOADER_VERSION)-2018.5.19.1 diff --git a/usr/src/boot/sys/boot/i386/libi386/biosdisk.c b/usr/src/boot/sys/boot/i386/libi386/biosdisk.c index a1854f8ff6..85899d2045 100644 --- a/usr/src/boot/sys/boot/i386/libi386/biosdisk.c +++ b/usr/src/boot/sys/boot/i386/libi386/biosdisk.c @@ -49,22 +49,22 @@ #include "disk.h" #include "libi386.h" -CTASSERT(sizeof(struct i386_devdesc) >= sizeof(struct disk_devdesc)); +CTASSERT(sizeof (struct i386_devdesc) >= sizeof (struct disk_devdesc)); -#define BIOS_NUMDRIVES 0x475 -#define BIOSDISK_SECSIZE 512 -#define BUFSIZE (1 * BIOSDISK_SECSIZE) +#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 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 #ifdef DISK_DEBUG -# define DEBUG(fmt, args...) printf("%s: " fmt "\n" , __func__ , ## args) +#define DEBUG(fmt, args...) printf("%s: " fmt "\n", __func__, ## args) #else -# define DEBUG(fmt, args...) +#define DEBUG(fmt, args...) #endif /* @@ -160,7 +160,7 @@ bd_init(void) * Check the BIOS equipment list for number * of fixed disks. */ - if(base == 0x80 && + if (base == 0x80 && (nfd >= *(unsigned char *)PTOV(BIOS_NUMDRIVES))) break; #endif @@ -182,7 +182,7 @@ bd_init(void) } } bcache_add_dev(nbdinfo); - return(0); + return (0); } /* @@ -239,7 +239,7 @@ bd_int13probe(struct bdinfo *bd) if ((v86.eax & 0xff00) >= 0x3000) bd->bd_flags |= BD_MODEEDD3; /* Get disk params */ - params.len = sizeof(struct edd_params); + params.len = sizeof (struct edd_params); v86.ctl = V86_FLAGS; v86.addr = 0x13; v86.eax = 0x4800; @@ -417,7 +417,7 @@ bd_ioctl(struct open_file *f, u_long cmd, void *data) switch (cmd) { case DIOCGSECTORSIZE: - *(u_int *)data = BD(dev).bd_sectorsize; + *(uint32_t *)data = BD(dev).bd_sectorsize; break; case DIOCGMEDIASIZE: *(uint64_t *)data = BD(dev).bd_sectors * BD(dev).bd_sectorsize; @@ -592,70 +592,71 @@ static int bd_edd_io(struct disk_devdesc *dev, 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; - if (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 ? */ - v86.eax = 0x4300; - else - v86.eax = 0x4200; - v86.edx = BD(dev).bd_unit; - v86.ds = VTOPSEG(&packet); - v86.esi = VTOPOFF(&packet); - v86int(); - if (V86_CY(v86.efl)) - return (v86.eax >> 8); - return (0); + if (dowrite) + v86.eax = 0x4300; + else + v86.eax = 0x4200; + v86.edx = BD(dev).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, int dowrite) { - u_int x, bpc, cyl, hd, sec; - - bpc = BD(dev).bd_sec * BD(dev).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 */ - - /* 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) - 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.es = VTOPSEG(dest); - v86.ebx = VTOPOFF(dest); - v86int(); - if (V86_CY(v86.efl)) - return (v86.eax >> 8); - return (0); + uint32_t x, bpc, cyl, hd, sec; + + bpc = BD(dev).bd_sec * BD(dev).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 */ + + /* 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) + 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.es = VTOPSEG(dest); + v86.ebx = VTOPOFF(dest); + v86int(); + if (V86_CY(v86.efl)) + return (v86.eax >> 8); + return (0); } static int bd_io(struct disk_devdesc *dev, daddr_t dblk, int blks, caddr_t dest, int dowrite) { - u_int result, retry; + int result, retry; /* Just in case some idiot actually tries to read/write -1 blocks... */ if (blks < 0) @@ -691,21 +692,18 @@ bd_io(struct disk_devdesc *dev, daddr_t dblk, int blks, caddr_t dest, if (result != 0 && result != 0x20) { if (dowrite != 0) { printf("%s%d: Write %d sector(s) from %p (0x%x) " - "to %lld: 0x%x", dev->dd.d_dev->dv_name, + "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", dev->dd.d_dev->dv_name, + "(0x%x): 0x%x\n", dev->dd.d_dev->dv_name, dev->dd.d_unit, blks, dblk, dest, VTOP(dest), result); + } } - if (result != 0) - return (result); - } - - return(0); + return (result); } /* @@ -722,19 +720,19 @@ bd_io(struct disk_devdesc *dev, daddr_t dblk, int blks, caddr_t dest, * disk. And, incidentally, what is returned is not the geometry as * such but the highest valid cylinder, head, and sector numbers. */ -u_int32_t +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); + 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)); } /* @@ -746,49 +744,49 @@ bd_getbigeom(int bunit) int bd_getdev(struct i386_devdesc *d) { - struct disk_devdesc *dev; - int biosdev; - int major; - int rootdev; - char *nip, *cp; - int i, unit; - - dev = (struct disk_devdesc *)d; - biosdev = bd_unit2bios(dev->dd.d_unit); - 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 (biosdev < 0x80) { - /* floppy (or emulated floppy) or ATAPI device */ - if (bdinfo[dev->dd.d_unit].bd_type == DT_ATAPI) { - /* is an ATAPI disk */ - major = WFDMAJOR; + struct disk_devdesc *dev; + int biosdev; + int major; + int rootdev; + char *nip, *cp; + int i, unit; + + dev = (struct disk_devdesc *)d; + biosdev = bd_unit2bios(dev->dd.d_unit); + 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 (biosdev < 0x80) { + /* floppy (or emulated floppy) or ATAPI device */ + if (bdinfo[dev->dd.d_unit].bd_type == DT_ATAPI) { + /* is an ATAPI disk */ + major = WFDMAJOR; + } else { + /* is a floppy disk */ + major = FDMAJOR; + } } else { - /* is a floppy disk */ - major = FDMAJOR; + /* assume an IDE disk */ + major = WDMAJOR; + } + /* default root disk unit number */ + unit = biosdev & 0x7f; + + /* 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; } - } else { - /* assume an IDE disk */ - major = WDMAJOR; - } - /* default root disk unit number */ - unit = biosdev & 0x7f; - - /* 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); - DEBUG("dev is 0x%x\n", rootdev); - return(rootdev); + + rootdev = MAKEBOOTDEV(major, dev->d_slice + 1, unit, dev->d_partition); + DEBUG("dev is 0x%x\n", rootdev); + return (rootdev); } |