Index: stand/i386/libi386/biosdisk.c =================================================================== --- stand/i386/libi386/biosdisk.c +++ stand/i386/libi386/biosdisk.c @@ -66,6 +66,17 @@ #define DEBUG(fmt, args...) #endif +/* + * INT13 commands + */ +#define CMD_RESET 0x0000 +#define CMD_READ_CHS 0x0200 +#define CMD_WRITE_CHS 0x0300 +#define CMD_READ_PARAM 0x0800 +#define CMD_READ_LBA 0x4200 +#define CMD_WRITE_LBA 0x4300 +#define CMD_EXT_PARAM 0x4800 + /* * List of BIOS devices, translation from disk unit number to * BIOS unit number. @@ -123,6 +134,38 @@ NULL }; + +static void +bd_int13(uint32_t eax, uint32_t edx, uint32_t ebx) +{ + +// bzero(&v86, sizeof(v86)); XXX + v86.ctl = V86_FLAGS; + v86.addr = 0x13; + v86.eax = eax; + v86.edx = edx; + v86.ebx = ebx; + v86int(); +} + +static void +bd_int13_param(uint32_t eax, uint32_t edx, uint32_t ds, uintt32_t esi) +{ + + v86.ds = ds; + v86.esi = esi; + bd_int13(eax, edx, 0); +} + +static void +bd_int13_chs(uint32_t eax, uint32_t edx, uint32_t ecx, uint32_t es, uint32_t ebx) +{ + + v86.ecx = ecx; + v86.es = es; + bd_int13(eax, edx, ebx); +} + /* * Translate between BIOS device numbers and our private unit numbers. */ @@ -219,7 +262,7 @@ /* reset disk */ v86.ctl = V86_FLAGS; v86.addr = 0x13; - v86.eax = 0; + v86.eax = CMD_RESET; v86.edx = unit; v86int(); } @@ -230,12 +273,7 @@ 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(); + bd_int13(CMD_READ_PARAM, bd->bd_unit, 0); if (V86_CY(v86.efl) && ((v86.eax & 0xff00) != 0)) return ((v86.eax & 0xff00) >> 8); @@ -266,13 +304,9 @@ /* 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(); + bd_int13_param(CMD_EXT_PARAM, bd->bd_unit, VTOPSEG(¶ms), VTOPOFF(¶ms)); + if (!V86_CY(v86.efl)) { + uint64_t total; if (V86_CY(v86.efl) && ((v86.eax & 0xff00) != 0)) return ((v86.eax & 0xff00) >> 8); @@ -722,17 +756,9 @@ 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.ds = VTOPSEG(&packet); - v86.esi = VTOPOFF(&packet); - v86int(); + bd_int13_param(dowrite == BD_WR ? CMD_WRITE_LBA : CMD_READ_LBA, + BD(dev).bd_unit, VTOPSEG(¶ms), VTOPOFF(¶ms)); if (V86_CY(v86.efl)) return (v86.eax >> 8); return (0); @@ -759,17 +785,10 @@ 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.es = VTOPSEG(dest); - v86.ebx = VTOPOFF(dest); - v86int(); + bd_int13_chs((dowrite == BD_WR ? CMD_WRITE_CHS : CMD_READ_CHS) | blks, + (hd << 8) | BD(dev).bd_unit, + ((cyl & 0xff) << 8) | ((cyl & 0x300) >> 2) | sec, + VTOPSEG(dest), VTOPOFF(dest)); if (V86_CY(v86.efl)) return (v86.eax >> 8); return (0); @@ -868,11 +887,7 @@ bd_getbigeom(int bunit) { - v86.ctl = V86_FLAGS; - v86.addr = 0x13; - v86.eax = 0x800; - v86.edx = 0x80 + bunit; - v86int(); + bd_int13(CMD_READ_PARAM, 0x80 + bunit, 0); if (V86_CY(v86.efl)) return (0x4f010f); return (((v86.ecx & 0xc0) << 18) | ((v86.ecx & 0xff00) << 8) |