__disk_ret(struct bregs *regs, u32 linecode, const char *fname)
{
u8 code = linecode;
- SET_BDA(disk_last_status, code);
+ if (regs->dl < EXTSTART_HD)
+ SET_BDA(floppy_last_status, code);
+ else
+ SET_BDA(disk_last_status, code);
if (code)
- __set_code_fail(regs, linecode, fname);
+ __set_code_invalid(regs, linecode, fname);
else
set_code_success(regs);
}
+void
+__disk_ret_unimplemented(struct bregs *regs, u32 linecode, const char *fname)
+{
+ u8 code = linecode;
+ if (regs->dl < EXTSTART_HD)
+ SET_BDA(floppy_last_status, code);
+ else
+ SET_BDA(disk_last_status, code);
+ __set_code_unimplemented(regs, linecode, fname);
+}
+
static void
__disk_stub(struct bregs *regs, int lineno, const char *fname)
{
- __debug_stub(regs, lineno, fname);
+ __warn_unimplemented(regs, lineno, fname);
__disk_ret(regs, DISK_RET_SUCCESS | (lineno << 8), fname);
}
#define DISK_STUB(regs) \
__disk_stub((regs), __LINE__, __func__)
-// Execute a "disk_op_s" request - this runs on a stack in the ebda.
-static int
-__send_disk_op(struct disk_op_s *op_far, u16 op_seg)
+// Get the cylinders/heads/sectors for the given drive.
+static void
+fillLCHS(struct drive_s *drive_g, u16 *nlc, u16 *nlh, u16 *nlspt)
{
- struct disk_op_s dop;
- memcpy_far(GET_SEG(SS), &dop
- , op_seg, op_far
- , sizeof(dop));
-
- dprintf(DEBUG_HDL_13, "disk_op d=%d lba=%d buf=%p count=%d cmd=%d\n"
- , dop.driveid, (u32)dop.lba, dop.buf_fl
- , dop.count, dop.command);
-
- irq_enable();
-
- int status = 0;
- u8 type = GET_GLOBAL(Drives.drives[dop.driveid].type);
- if (type == DTYPE_ATA)
- status = process_ata_op(&dop);
- else if (type == DTYPE_ATAPI)
- status = process_atapi_op(&dop);
-
- irq_disable();
-
- // Update count with total sectors transferred.
- SET_FARVAR(op_seg, op_far->count, dop.count);
-
- if (status)
- dprintf(1, "disk_op cmd %d error %d!\n", dop.command, status);
-
- return status;
+ if (CONFIG_CDROM_EMU
+ && drive_g == GLOBALFLAT2GLOBAL(GET_GLOBAL(cdemu_drive_gf))) {
+ // Emulated drive - get info from ebda. (It's not possible to
+ // populate the geometry directly in the driveid because the
+ // geometry is only known after the bios segment is made
+ // read-only).
+ u16 ebda_seg = get_ebda_seg();
+ *nlc = GET_EBDA2(ebda_seg, cdemu.lchs.cylinders);
+ *nlh = GET_EBDA2(ebda_seg, cdemu.lchs.heads);
+ *nlspt = GET_EBDA2(ebda_seg, cdemu.lchs.spt);
+ return;
+ }
+ *nlc = GET_GLOBAL(drive_g->lchs.cylinders);
+ *nlh = GET_GLOBAL(drive_g->lchs.heads);
+ *nlspt = GET_GLOBAL(drive_g->lchs.spt);
}
-// Execute a "disk_op_s" request by jumping to a stack in the ebda.
-static int
-send_disk_op(struct disk_op_s *op)
+// Perform read/write/verify using old-style chs accesses
+static void
+basic_access(struct bregs *regs, struct drive_s *drive_g, u16 command)
{
- if (! CONFIG_DRIVES)
- return -1;
-
- return stack_hop((u32)op, GET_SEG(SS), 0, __send_disk_op);
-}
+ struct disk_op_s dop;
+ dop.drive_g = drive_g;
+ dop.command = command;
-// Obtain the requested disk lba from an old-style chs request.
-static int
-legacy_lba(struct bregs *regs, u16 lchs_seg, struct chs_s *lchs_far)
-{
u8 count = regs->al;
u16 cylinder = regs->ch | ((((u16)regs->cl) << 2) & 0x300);
u16 sector = regs->cl & 0x3f;
u16 head = regs->dh;
if (count > 128 || count == 0 || sector == 0) {
- dprintf(1, "int13_harddisk: function %02x, parameter out of range!\n"
- , regs->ah);
+ warn_invalid(regs);
disk_ret(regs, DISK_RET_EPARAM);
- return -1;
+ return;
}
+ dop.count = count;
- u16 nlc = GET_FARVAR(lchs_seg, lchs_far->cylinders);
- u16 nlh = GET_FARVAR(lchs_seg, lchs_far->heads);
- u16 nlspt = GET_FARVAR(lchs_seg, lchs_far->spt);
+ u16 nlc, nlh, nlspt;
+ fillLCHS(drive_g, &nlc, &nlh, &nlspt);
// sanity check on cyl heads, sec
if (cylinder >= nlc || head >= nlh || sector > nlspt) {
- dprintf(1, "int13_harddisk: function %02x, parameters out of"
- " range %04x/%04x/%04x!\n"
- , regs->ah, cylinder, head, sector);
+ warn_invalid(regs);
disk_ret(regs, DISK_RET_EPARAM);
- return -1;
+ return;
}
// translate lchs to lba
- return (((((u32)cylinder * (u32)nlh) + (u32)head) * (u32)nlspt)
- + (u32)sector - 1);
-}
+ dop.lba = (((((u32)cylinder * (u32)nlh) + (u32)head) * (u32)nlspt)
+ + (u32)sector - 1);
-// Perform read/write/verify using old-style chs accesses
-static void
-basic_access(struct bregs *regs, u8 device, u16 command)
-{
- struct disk_op_s dop;
- dop.driveid = device;
- dop.command = command;
- int lba = legacy_lba(regs, get_global_seg(), &Drives.drives[device].lchs);
- if (lba < 0)
- return;
- dop.lba = lba;
- dop.count = regs->al;
dop.buf_fl = MAKE_FLATPTR(regs->es, regs->bx);
int status = send_disk_op(&dop);
regs->al = dop.count;
- if (status) {
- disk_ret(regs, DISK_RET_EBADTRACK);
- return;
- }
- disk_ret(regs, DISK_RET_SUCCESS);
-}
-
-// Perform cdemu read/verify
-void
-cdemu_access(struct bregs *regs, u8 device, u16 command)
-{
- struct disk_op_s dop;
- dop.driveid = device;
- dop.command = command;
- u16 ebda_seg = get_ebda_seg();
- int vlba = legacy_lba(
- regs, ebda_seg
- , (void*)offsetof(struct extended_bios_data_area_s, cdemu.lchs));
- if (vlba < 0)
- return;
- dop.lba = GET_EBDA2(ebda_seg, cdemu.ilba) + vlba / 4;
- u8 count = regs->al;
- u8 *cdbuf_far = (void*)offsetof(struct extended_bios_data_area_s, cdemu_buf);
- u8 *dest_far = (void*)(regs->bx+0);
- regs->al = 0;
-
- if (vlba & 3) {
- dop.count = 1;
- dop.buf_fl = MAKE_FLATPTR(ebda_seg, cdbuf_far);
- int status = send_disk_op(&dop);
- if (status)
- goto fail;
- u8 thiscount = 4 - (vlba & 3);
- if (thiscount > count)
- thiscount = count;
- count -= thiscount;
- memcpy_far(regs->es, dest_far
- , ebda_seg, cdbuf_far + (vlba & 3) * 512
- , thiscount * 512);
- dest_far += thiscount * 512;
- regs->al += thiscount;
- dop.lba++;
- }
-
- if (count > 3) {
- dop.count = count / 4;
- dop.buf_fl = MAKE_FLATPTR(regs->es, dest_far);
- int status = send_disk_op(&dop);
- regs->al += dop.count * 4;
- if (status)
- goto fail;
- u8 thiscount = count & ~3;
- count &= 3;
- dest_far += thiscount * 512;
- dop.lba += thiscount / 4;
- }
-
- if (count) {
- dop.count = 1;
- dop.buf_fl = MAKE_FLATPTR(ebda_seg, cdbuf_far);
- int status = send_disk_op(&dop);
- if (status)
- goto fail;
- u8 thiscount = count;
- memcpy_far(regs->es, dest_far, ebda_seg, cdbuf_far, thiscount * 512);
- regs->al += thiscount;
- }
-
- disk_ret(regs, DISK_RET_SUCCESS);
- return;
-fail:
- disk_ret(regs, DISK_RET_EBADTRACK);
+ disk_ret(regs, status);
}
// Perform read/write/verify using new-style "int13ext" accesses.
static void
-extended_access(struct bregs *regs, u8 device, u16 command)
+extended_access(struct bregs *regs, struct drive_s *drive_g, u16 command)
{
struct disk_op_s dop;
// Get lba and check.
dop.lba = GET_INT13EXT(regs, lba);
dop.command = command;
- dop.driveid = device;
- if (dop.lba >= GET_GLOBAL(Drives.drives[device].sectors)) {
- dprintf(1, "int13_harddisk: function %02x. LBA out of range\n"
- , regs->ah);
+ dop.drive_g = drive_g;
+ if (dop.lba >= GET_GLOBAL(drive_g->sectors)) {
+ warn_invalid(regs);
disk_ret(regs, DISK_RET_EPARAM);
return;
}
- u16 segment = GET_INT13EXT(regs, segment);
- u16 offset = GET_INT13EXT(regs, offset);
- dop.buf_fl = MAKE_FLATPTR(segment, offset);
+ dop.buf_fl = SEGOFF_TO_FLATPTR(GET_INT13EXT(regs, data));
dop.count = GET_INT13EXT(regs, count);
int status = send_disk_op(&dop);
SET_INT13EXT(regs, count, dop.count);
- if (status) {
- disk_ret(regs, DISK_RET_EBADTRACK);
- return;
- }
- disk_ret(regs, DISK_RET_SUCCESS);
+ disk_ret(regs, status);
}
// disk controller reset
static void
-disk_1300(struct bregs *regs, u8 device)
+disk_1300(struct bregs *regs, struct drive_s *drive_g)
{
struct disk_op_s dop;
- dop.driveid = device;
+ dop.drive_g = drive_g;
dop.command = CMD_RESET;
- send_disk_op(&dop);
+ int status = send_disk_op(&dop);
+ disk_ret(regs, status);
}
// read disk status
static void
-disk_1301(struct bregs *regs, u8 device)
+disk_1301(struct bregs *regs, struct drive_s *drive_g)
{
- u8 v = GET_BDA(disk_last_status);
+ u8 v;
+ if (regs->dl < EXTSTART_HD)
+ // Floppy
+ v = GET_BDA(floppy_last_status);
+ else
+ v = GET_BDA(disk_last_status);
regs->ah = v;
set_cf(regs, v);
// XXX - clear disk_last_status?
// read disk sectors
static void
-disk_1302(struct bregs *regs, u8 device)
+disk_1302(struct bregs *regs, struct drive_s *drive_g)
{
- basic_access(regs, device, CMD_READ);
+ basic_access(regs, drive_g, CMD_READ);
}
// write disk sectors
static void
-disk_1303(struct bregs *regs, u8 device)
+disk_1303(struct bregs *regs, struct drive_s *drive_g)
{
- basic_access(regs, device, CMD_WRITE);
+ basic_access(regs, drive_g, CMD_WRITE);
}
// verify disk sectors
static void
-disk_1304(struct bregs *regs, u8 device)
+disk_1304(struct bregs *regs, struct drive_s *drive_g)
{
- basic_access(regs, device, CMD_VERIFY);
- // FIXME verify
+ basic_access(regs, drive_g, CMD_VERIFY);
}
// format disk track
static void
-disk_1305(struct bregs *regs, u8 device)
+disk_1305(struct bregs *regs, struct drive_s *drive_g)
{
- DISK_STUB(regs);
+ debug_stub(regs);
+
+ u16 nlc, nlh, nlspt;
+ fillLCHS(drive_g, &nlc, &nlh, &nlspt);
+
+ u8 num_sectors = regs->al;
+ u8 head = regs->dh;
+
+ if (head >= nlh || num_sectors == 0 || num_sectors > nlspt) {
+ disk_ret(regs, DISK_RET_EPARAM);
+ return;
+ }
+
+ struct disk_op_s dop;
+ dop.drive_g = drive_g;
+ dop.command = CMD_FORMAT;
+ dop.lba = head;
+ dop.count = num_sectors;
+ dop.buf_fl = MAKE_FLATPTR(regs->es, regs->bx);
+ int status = send_disk_op(&dop);
+ disk_ret(regs, status);
}
// read disk drive parameters
static void
-disk_1308(struct bregs *regs, u8 device)
+disk_1308(struct bregs *regs, struct drive_s *drive_g)
{
+ u16 ebda_seg = get_ebda_seg();
// Get logical geometry from table
- u16 nlc = GET_GLOBAL(Drives.drives[device].lchs.cylinders);
- u16 nlh = GET_GLOBAL(Drives.drives[device].lchs.heads);
- u16 nlspt = GET_GLOBAL(Drives.drives[device].lchs.spt);
- u16 count = GET_BDA(hdcount);
+ u16 nlc, nlh, nlspt;
+ fillLCHS(drive_g, &nlc, &nlh, &nlspt);
+ nlc--;
+ nlh--;
+ u8 count;
+ if (regs->dl < EXTSTART_HD) {
+ // Floppy
+ count = GET_GLOBAL(Drives.floppycount);
+
+ if (CONFIG_CDROM_EMU
+ && drive_g == GLOBALFLAT2GLOBAL(GET_GLOBAL(cdemu_drive_gf)))
+ regs->bx = GET_EBDA2(ebda_seg, cdemu.media) * 2;
+ else
+ regs->bx = GET_GLOBAL(drive_g->floppy_type);
+
+ // set es & di to point to 11 byte diskette param table in ROM
+ regs->es = SEG_BIOS;
+ regs->di = (u32)&diskette_param_table2;
+ } else if (regs->dl < EXTSTART_CD) {
+ // Hard drive
+ count = GET_BDA(hdcount);
+ nlc--; // last sector reserved
+ } else {
+ // Not supported on CDROM
+ disk_ret(regs, DISK_RET_EPARAM);
+ return;
+ }
+
+ if (CONFIG_CDROM_EMU && GET_EBDA2(ebda_seg, cdemu.active)) {
+ u8 emudrive = GET_EBDA2(ebda_seg, cdemu.emulated_extdrive);
+ if (((emudrive ^ regs->dl) & 0x80) == 0)
+ // Note extra drive due to emulation.
+ count++;
+ if (regs->dl < EXTSTART_HD && count > 2)
+ // Max of two floppy drives.
+ count = 2;
+ }
- nlc = nlc - 2; /* 0 based , last sector not used */
regs->al = 0;
regs->ch = nlc & 0xff;
regs->cl = ((nlc >> 2) & 0xc0) | (nlspt & 0x3f);
- regs->dh = nlh - 1;
- regs->dl = count; /* FIXME returns 0, 1, or n hard drives */
+ regs->dh = nlh;
- // FIXME should set ES & DI
disk_ret(regs, DISK_RET_SUCCESS);
+ regs->dl = count;
}
// initialize drive parameters
static void
-disk_1309(struct bregs *regs, u8 device)
+disk_1309(struct bregs *regs, struct drive_s *drive_g)
{
DISK_STUB(regs);
}
// seek to specified cylinder
static void
-disk_130c(struct bregs *regs, u8 device)
+disk_130c(struct bregs *regs, struct drive_s *drive_g)
{
DISK_STUB(regs);
}
// alternate disk reset
static void
-disk_130d(struct bregs *regs, u8 device)
+disk_130d(struct bregs *regs, struct drive_s *drive_g)
{
DISK_STUB(regs);
}
// check drive ready
static void
-disk_1310(struct bregs *regs, u8 device)
+disk_1310(struct bregs *regs, struct drive_s *drive_g)
{
// should look at 40:8E also???
struct disk_op_s dop;
- dop.driveid = device;
+ dop.drive_g = drive_g;
dop.command = CMD_ISREADY;
int status = send_disk_op(&dop);
- if (status)
- disk_ret(regs, DISK_RET_ENOTREADY);
- else
- disk_ret(regs, DISK_RET_SUCCESS);
+ disk_ret(regs, status);
}
// recalibrate
static void
-disk_1311(struct bregs *regs, u8 device)
+disk_1311(struct bregs *regs, struct drive_s *drive_g)
{
DISK_STUB(regs);
}
// controller internal diagnostic
static void
-disk_1314(struct bregs *regs, u8 device)
+disk_1314(struct bregs *regs, struct drive_s *drive_g)
{
DISK_STUB(regs);
}
// read disk drive size
static void
-disk_1315(struct bregs *regs, u8 device)
+disk_1315(struct bregs *regs, struct drive_s *drive_g)
{
+ disk_ret(regs, DISK_RET_SUCCESS);
+ if (regs->dl < EXTSTART_HD || regs->dl >= EXTSTART_CD) {
+ // Floppy or cdrom
+ regs->ah = 1;
+ return;
+ }
+ // Hard drive
+
// Get logical geometry from table
- u16 nlc = GET_GLOBAL(Drives.drives[device].lchs.cylinders);
- u16 nlh = GET_GLOBAL(Drives.drives[device].lchs.heads);
- u16 nlspt = GET_GLOBAL(Drives.drives[device].lchs.spt);
+ u16 nlc, nlh, nlspt;
+ fillLCHS(drive_g, &nlc, &nlh, &nlspt);
// Compute sector count seen by int13
u32 lba = (u32)(nlc - 1) * (u32)nlh * (u32)nlspt;
regs->cx = lba >> 16;
regs->dx = lba & 0xffff;
-
- disk_ret(regs, DISK_RET_SUCCESS);
regs->ah = 3; // hard disk accessible
}
+static void
+disk_1316(struct bregs *regs, struct drive_s *drive_g)
+{
+ if (regs->dl >= EXTSTART_HD) {
+ // Hard drive
+ disk_ret(regs, DISK_RET_EPARAM);
+ return;
+ }
+ disk_ret(regs, DISK_RET_ECHANGED);
+}
+
// IBM/MS installation check
static void
-disk_1341(struct bregs *regs, u8 device)
+disk_1341(struct bregs *regs, struct drive_s *drive_g)
{
regs->bx = 0xaa55; // install check
regs->cx = 0x0007; // ext disk access and edd, removable supported
// IBM/MS extended read
static void
-disk_1342(struct bregs *regs, u8 device)
+disk_1342(struct bregs *regs, struct drive_s *drive_g)
{
- extended_access(regs, device, CMD_READ);
+ extended_access(regs, drive_g, CMD_READ);
}
// IBM/MS extended write
static void
-disk_1343(struct bregs *regs, u8 device)
+disk_1343(struct bregs *regs, struct drive_s *drive_g)
{
- extended_access(regs, device, CMD_WRITE);
+ extended_access(regs, drive_g, CMD_WRITE);
}
// IBM/MS verify
static void
-disk_1344(struct bregs *regs, u8 device)
+disk_1344(struct bregs *regs, struct drive_s *drive_g)
{
- extended_access(regs, device, CMD_VERIFY);
+ extended_access(regs, drive_g, CMD_VERIFY);
}
-// IBM/MS lock/unlock drive
+// lock
static void
-disk_1345(struct bregs *regs, u8 device)
+disk_134500(struct bregs *regs, struct drive_s *drive_g)
{
- // Always success for HD
+ u16 ebda_seg = get_ebda_seg();
+ int cdid = regs->dl - EXTSTART_CD;
+ u8 locks = GET_EBDA2(ebda_seg, cdrom_locks[cdid]);
+ if (locks == 0xff) {
+ regs->al = 1;
+ disk_ret(regs, DISK_RET_ETOOMANYLOCKS);
+ return;
+ }
+ SET_EBDA2(ebda_seg, cdrom_locks[cdid], locks + 1);
+ regs->al = 1;
disk_ret(regs, DISK_RET_SUCCESS);
}
+// unlock
+static void
+disk_134501(struct bregs *regs, struct drive_s *drive_g)
+{
+ u16 ebda_seg = get_ebda_seg();
+ int cdid = regs->dl - EXTSTART_CD;
+ u8 locks = GET_EBDA2(ebda_seg, cdrom_locks[cdid]);
+ if (locks == 0x00) {
+ regs->al = 0;
+ disk_ret(regs, DISK_RET_ENOTLOCKED);
+ return;
+ }
+ locks--;
+ SET_EBDA2(ebda_seg, cdrom_locks[cdid], locks);
+ regs->al = (locks ? 1 : 0);
+ disk_ret(regs, DISK_RET_SUCCESS);
+}
+
+// status
+static void
+disk_134502(struct bregs *regs, struct drive_s *drive_g)
+{
+ int cdid = regs->dl - EXTSTART_CD;
+ u8 locks = GET_EBDA(cdrom_locks[cdid]);
+ regs->al = (locks ? 1 : 0);
+ disk_ret(regs, DISK_RET_SUCCESS);
+}
+
+static void
+disk_1345XX(struct bregs *regs, struct drive_s *drive_g)
+{
+ disk_ret_unimplemented(regs, DISK_RET_EPARAM);
+}
+
+// IBM/MS lock/unlock drive
+static void
+disk_1345(struct bregs *regs, struct drive_s *drive_g)
+{
+ if (regs->dl < EXTSTART_CD) {
+ // Always success for HD
+ disk_ret(regs, DISK_RET_SUCCESS);
+ return;
+ }
+
+ switch (regs->al) {
+ case 0x00: disk_134500(regs, drive_g); break;
+ case 0x01: disk_134501(regs, drive_g); break;
+ case 0x02: disk_134502(regs, drive_g); break;
+ default: disk_1345XX(regs, drive_g); break;
+ }
+}
+
// IBM/MS eject media
static void
-disk_1346(struct bregs *regs, u8 device)
+disk_1346(struct bregs *regs, struct drive_s *drive_g)
{
- // Volume Not Removable
- disk_ret(regs, DISK_RET_ENOTREMOVABLE);
+ if (regs->dl < EXTSTART_CD) {
+ // Volume Not Removable
+ disk_ret(regs, DISK_RET_ENOTREMOVABLE);
+ return;
+ }
+
+ int cdid = regs->dl - EXTSTART_CD;
+ u8 locks = GET_EBDA(cdrom_locks[cdid]);
+ if (locks != 0) {
+ disk_ret(regs, DISK_RET_ELOCKED);
+ return;
+ }
+
+ // FIXME should handle 0x31 no media in device
+ // FIXME should handle 0xb5 valid request failed
+
+ // Call removable media eject
+ struct bregs br;
+ memset(&br, 0, sizeof(br));
+ br.ah = 0x52;
+ br.dl = regs->dl;
+ call16_int(0x15, &br);
+
+ if (br.ah || br.flags & F_CF) {
+ disk_ret(regs, DISK_RET_ELOCKED);
+ return;
+ }
+ disk_ret(regs, DISK_RET_SUCCESS);
}
// IBM/MS extended seek
static void
-disk_1347(struct bregs *regs, u8 device)
+disk_1347(struct bregs *regs, struct drive_s *drive_g)
{
- extended_access(regs, device, CMD_SEEK);
+ extended_access(regs, drive_g, CMD_SEEK);
}
// IBM/MS get drive parameters
static void
-disk_1348(struct bregs *regs, u8 device)
+disk_1348(struct bregs *regs, struct drive_s *drive_g)
{
u16 size = GET_INT13DPT(regs, size);
// EDD 1.x
- u8 type = GET_GLOBAL(Drives.drives[device].type);
- u16 npc = GET_GLOBAL(Drives.drives[device].pchs.cylinders);
- u16 nph = GET_GLOBAL(Drives.drives[device].pchs.heads);
- u16 npspt = GET_GLOBAL(Drives.drives[device].pchs.spt);
- u64 lba = GET_GLOBAL(Drives.drives[device].sectors);
- u16 blksize = GET_GLOBAL(Drives.drives[device].blksize);
+ u8 type = GET_GLOBAL(drive_g->type);
+ u16 npc = GET_GLOBAL(drive_g->pchs.cylinders);
+ u16 nph = GET_GLOBAL(drive_g->pchs.heads);
+ u16 npspt = GET_GLOBAL(drive_g->pchs.spt);
+ u64 lba = GET_GLOBAL(drive_g->sectors);
+ u16 blksize = GET_GLOBAL(drive_g->blksize);
dprintf(DEBUG_HDL_13, "disk_1348 size=%d t=%d chs=%d,%d,%d lba=%d bs=%d\n"
, size, type, npc, nph, npspt, (u32)lba, blksize);
, offsetof(struct extended_bios_data_area_s, dpte));
// Fill in dpte
- u8 ataid = GET_GLOBAL(Drives.drives[device].cntl_id);
- u8 channel = ataid / 2;
- u8 slave = ataid % 2;
- u16 iobase1 = GET_GLOBAL(ATA_channels[channel].iobase1);
- u16 iobase2 = GET_GLOBAL(ATA_channels[channel].iobase2);
- u8 irq = GET_GLOBAL(ATA_channels[channel].irq);
+ struct atadrive_s *adrive_g = container_of(
+ drive_g, struct atadrive_s, drive);
+ struct ata_channel_s *chan_gf = GET_GLOBAL(adrive_g->chan_gf);
+ u8 slave = GET_GLOBAL(adrive_g->slave);
+ u16 iobase1 = GET_GLOBALFLAT(chan_gf->iobase1);
+ u16 iobase2 = GET_GLOBALFLAT(chan_gf->iobase2);
+ u8 irq = GET_GLOBALFLAT(chan_gf->irq);
u16 options = 0;
if (type == DTYPE_ATA) {
- u8 translation = GET_GLOBAL(Drives.drives[device].translation);
+ u8 translation = GET_GLOBAL(drive_g->translation);
if (translation != TRANSLATION_NONE) {
options |= 1<<3; // CHS translation
if (translation == TRANSLATION_LBA)
SET_INT13DPT(regs, reserved1, 0);
SET_INT13DPT(regs, reserved2, 0);
- SET_INT13DPT(regs, host_bus[0], 'P');
- SET_INT13DPT(regs, host_bus[1], 'C');
- SET_INT13DPT(regs, host_bus[2], 'I');
- SET_INT13DPT(regs, host_bus[3], 0);
+ int bdf = GET_GLOBALFLAT(chan_gf->pci_bdf);
+ if (bdf != -1) {
+ SET_INT13DPT(regs, host_bus[0], 'P');
+ SET_INT13DPT(regs, host_bus[1], 'C');
+ SET_INT13DPT(regs, host_bus[2], 'I');
+ SET_INT13DPT(regs, host_bus[3], 0);
- u32 bdf = GET_GLOBAL(ATA_channels[channel].pci_bdf);
- u32 path = (pci_bdf_to_bus(bdf) | (pci_bdf_to_dev(bdf) << 8)
- | (pci_bdf_to_fn(bdf) << 16));
- SET_INT13DPT(regs, iface_path, path);
+ u32 path = (pci_bdf_to_bus(bdf) | (pci_bdf_to_dev(bdf) << 8)
+ | (pci_bdf_to_fn(bdf) << 16));
+ SET_INT13DPT(regs, iface_path, path);
+ } else {
+ // ISA
+ SET_INT13DPT(regs, host_bus[0], 'I');
+ SET_INT13DPT(regs, host_bus[1], 'S');
+ SET_INT13DPT(regs, host_bus[2], 'A');
+ SET_INT13DPT(regs, host_bus[3], 0);
+
+ SET_INT13DPT(regs, iface_path, iobase1);
+ }
SET_INT13DPT(regs, iface_type[0], 'A');
SET_INT13DPT(regs, iface_type[1], 'T');
// IBM/MS extended media change
static void
-disk_1349(struct bregs *regs, u8 device)
+disk_1349(struct bregs *regs, struct drive_s *drive_g)
{
- // Always success for HD
- disk_ret(regs, DISK_RET_SUCCESS);
+ if (regs->dl < EXTSTART_CD) {
+ // Always success for HD
+ disk_ret(regs, DISK_RET_SUCCESS);
+ return;
+ }
+ set_invalid(regs);
+ // always send changed ??
+ regs->ah = DISK_RET_ECHANGED;
}
static void
-disk_134e01(struct bregs *regs, u8 device)
+disk_134e01(struct bregs *regs, struct drive_s *drive_g)
{
disk_ret(regs, DISK_RET_SUCCESS);
}
static void
-disk_134e03(struct bregs *regs, u8 device)
+disk_134e03(struct bregs *regs, struct drive_s *drive_g)
{
disk_ret(regs, DISK_RET_SUCCESS);
}
static void
-disk_134e04(struct bregs *regs, u8 device)
+disk_134e04(struct bregs *regs, struct drive_s *drive_g)
{
disk_ret(regs, DISK_RET_SUCCESS);
}
static void
-disk_134e06(struct bregs *regs, u8 device)
+disk_134e06(struct bregs *regs, struct drive_s *drive_g)
{
disk_ret(regs, DISK_RET_SUCCESS);
}
static void
-disk_134eXX(struct bregs *regs, u8 device)
+disk_134eXX(struct bregs *regs, struct drive_s *drive_g)
{
disk_ret(regs, DISK_RET_EPARAM);
}
// IBM/MS set hardware configuration
static void
-disk_134e(struct bregs *regs, u8 device)
+disk_134e(struct bregs *regs, struct drive_s *drive_g)
{
switch (regs->al) {
- case 0x01: disk_134e01(regs, device); break;
- case 0x03: disk_134e03(regs, device); break;
- case 0x04: disk_134e04(regs, device); break;
- case 0x06: disk_134e06(regs, device); break;
- default: disk_134eXX(regs, device); break;
+ case 0x01: disk_134e01(regs, drive_g); break;
+ case 0x03: disk_134e03(regs, drive_g); break;
+ case 0x04: disk_134e04(regs, drive_g); break;
+ case 0x06: disk_134e06(regs, drive_g); break;
+ default: disk_134eXX(regs, drive_g); break;
}
}
-void
-disk_13XX(struct bregs *regs, u8 device)
+static void
+disk_13XX(struct bregs *regs, struct drive_s *drive_g)
{
- disk_ret(regs, DISK_RET_EPARAM);
+ disk_ret_unimplemented(regs, DISK_RET_EPARAM);
}
-void
-disk_13(struct bregs *regs, u8 device)
+static void
+disk_13(struct bregs *regs, struct drive_s *drive_g)
{
//debug_stub(regs);
SET_BDA(disk_interrupt_flag, 0);
switch (regs->ah) {
- case 0x00: disk_1300(regs, device); break;
- case 0x01: disk_1301(regs, device); break;
- case 0x02: disk_1302(regs, device); break;
- case 0x03: disk_1303(regs, device); break;
- case 0x04: disk_1304(regs, device); break;
- case 0x05: disk_1305(regs, device); break;
- case 0x08: disk_1308(regs, device); break;
- case 0x09: disk_1309(regs, device); break;
- case 0x0c: disk_130c(regs, device); break;
- case 0x0d: disk_130d(regs, device); break;
- case 0x10: disk_1310(regs, device); break;
- case 0x11: disk_1311(regs, device); break;
- case 0x14: disk_1314(regs, device); break;
- case 0x15: disk_1315(regs, device); break;
- case 0x41: disk_1341(regs, device); break;
- case 0x42: disk_1342(regs, device); break;
- case 0x43: disk_1343(regs, device); break;
- case 0x44: disk_1344(regs, device); break;
- case 0x45: disk_1345(regs, device); break;
- case 0x46: disk_1346(regs, device); break;
- case 0x47: disk_1347(regs, device); break;
- case 0x48: disk_1348(regs, device); break;
- case 0x49: disk_1349(regs, device); break;
- case 0x4e: disk_134e(regs, device); break;
- default: disk_13XX(regs, device); break;
+ case 0x00: disk_1300(regs, drive_g); break;
+ case 0x01: disk_1301(regs, drive_g); break;
+ case 0x02: disk_1302(regs, drive_g); break;
+ case 0x03: disk_1303(regs, drive_g); break;
+ case 0x04: disk_1304(regs, drive_g); break;
+ case 0x05: disk_1305(regs, drive_g); break;
+ case 0x08: disk_1308(regs, drive_g); break;
+ case 0x09: disk_1309(regs, drive_g); break;
+ case 0x0c: disk_130c(regs, drive_g); break;
+ case 0x0d: disk_130d(regs, drive_g); break;
+ case 0x10: disk_1310(regs, drive_g); break;
+ case 0x11: disk_1311(regs, drive_g); break;
+ case 0x14: disk_1314(regs, drive_g); break;
+ case 0x15: disk_1315(regs, drive_g); break;
+ case 0x16: disk_1316(regs, drive_g); break;
+ case 0x41: disk_1341(regs, drive_g); break;
+ case 0x42: disk_1342(regs, drive_g); break;
+ case 0x43: disk_1343(regs, drive_g); break;
+ case 0x44: disk_1344(regs, drive_g); break;
+ case 0x45: disk_1345(regs, drive_g); break;
+ case 0x46: disk_1346(regs, drive_g); break;
+ case 0x47: disk_1347(regs, drive_g); break;
+ case 0x48: disk_1348(regs, drive_g); break;
+ case 0x49: disk_1349(regs, drive_g); break;
+ case 0x4e: disk_134e(regs, drive_g); break;
+ default: disk_13XX(regs, drive_g); break;
}
}
-
-/****************************************************************
- * Entry points
- ****************************************************************/
-
-static int
-get_device(struct bregs *regs, u8 iscd, u8 drive)
+static void
+floppy_13(struct bregs *regs, struct drive_s *drive_g)
{
- // basic check : device has to be defined
- if (drive >= ARRAY_SIZE(Drives.idmap[0])) {
- disk_ret(regs, DISK_RET_EPARAM);
- return -1;
+ // Only limited commands are supported on floppies.
+ switch (regs->ah) {
+ case 0x00:
+ case 0x01:
+ case 0x02:
+ case 0x03:
+ case 0x04:
+ case 0x05:
+ case 0x08:
+ case 0x15:
+ case 0x16:
+ disk_13(regs, drive_g);
+ break;
+ default: disk_13XX(regs, drive_g); break;
}
+}
- // Get the ata channel
- u8 driveid = GET_GLOBAL(Drives.idmap[iscd][drive]);
- // basic check : device has to be valid
- if (driveid >= ARRAY_SIZE(Drives.drives)) {
- disk_ret(regs, DISK_RET_EPARAM);
- return -1;
- }
-
- return driveid;
-}
+/****************************************************************
+ * Entry points
+ ****************************************************************/
static void
-handle_legacy_disk(struct bregs *regs, u8 drive)
+handle_legacy_disk(struct bregs *regs, u8 extdrive)
{
- if (drive < 0x80) {
- floppy_13(regs, drive);
- return;
- }
-
if (! CONFIG_DRIVES) {
- // XXX - old code had other disk access method.
+ // XXX - support handle_1301 anyway?
disk_ret(regs, DISK_RET_EPARAM);
return;
}
- if (drive >= 0xe0) {
- int driveid = get_device(regs, 1, drive - 0xe0);
- if (driveid < 0)
- return;
- cdrom_13(regs, driveid);
+ if (extdrive < EXTSTART_HD) {
+ struct drive_s *drive_g = getDrive(EXTTYPE_FLOPPY, extdrive);
+ if (!drive_g)
+ goto fail;
+ floppy_13(regs, drive_g);
return;
}
- int driveid = get_device(regs, 0, drive - 0x80);
- if (driveid < 0)
- return;
- disk_13(regs, driveid);
+ struct drive_s *drive_g;
+ if (extdrive >= EXTSTART_CD)
+ drive_g = getDrive(EXTTYPE_CD, extdrive - EXTSTART_CD);
+ else
+ drive_g = getDrive(EXTTYPE_HD, extdrive - EXTSTART_HD);
+ if (!drive_g)
+ goto fail;
+ disk_13(regs, drive_g);
+ return;
+
+fail:
+ // XXX - support 1301/1308/1315 anyway?
+ disk_ret(regs, DISK_RET_EPARAM);
}
void VISIBLE16
handle_13(struct bregs *regs)
{
debug_enter(regs, DEBUG_HDL_13);
- u8 drive = regs->dl;
+ u8 extdrive = regs->dl;
if (CONFIG_CDROM_EMU) {
if (regs->ah == 0x4b) {
}
u16 ebda_seg = get_ebda_seg();
if (GET_EBDA2(ebda_seg, cdemu.active)) {
- u8 emudrive = GET_EBDA2(ebda_seg, cdemu.emulated_drive);
- if (drive == emudrive) {
- cdemu_13(regs);
+ u8 emudrive = GET_EBDA2(ebda_seg, cdemu.emulated_extdrive);
+ if (extdrive == emudrive) {
+ // Access to an emulated drive.
+ struct drive_s *cdemu_g;
+ cdemu_g = GLOBALFLAT2GLOBAL(GET_GLOBAL(cdemu_drive_gf));
+ if (regs->ah > 0x16) {
+ // Only old-style commands supported.
+ disk_13XX(regs, cdemu_g);
+ return;
+ }
+ disk_13(regs, cdemu_g);
return;
}
- if (drive < 0xe0 && ((emudrive ^ drive) & 0x80) == 0)
- drive--;
+ if (extdrive < EXTSTART_CD && ((emudrive ^ extdrive) & 0x80) == 0)
+ // Adjust id to make room for emulated drive.
+ extdrive--;
}
}
- handle_legacy_disk(regs, drive);
+ handle_legacy_disk(regs, extdrive);
}
// record completion in BIOS task complete flag
void VISIBLE16
-handle_76()
+handle_76(void)
{
debug_isr(DEBUG_ISR_76);
SET_BDA(disk_interrupt_flag, 0xff);