1 // 16bit code to access hard drives.
3 // Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net>
4 // Copyright (C) 2002 MandrakeSoft S.A.
6 // This file may be distributed under the terms of the GNU LGPLv3 license.
8 #include "disk.h" // floppy_13
9 #include "biosvar.h" // SET_BDA
10 #include "config.h" // CONFIG_*
11 #include "util.h" // debug_enter
12 #include "pic.h" // eoi_pic2
13 #include "bregs.h" // struct bregs
14 #include "pci.h" // pci_bdf_to_bus
15 #include "ata.h" // ATA_CB_DC
18 /****************************************************************
20 ****************************************************************/
23 __disk_ret(struct bregs *regs, u32 linecode, const char *fname)
26 if (regs->dl < EXTSTART_HD)
27 SET_BDA(floppy_last_status, code);
29 SET_BDA(disk_last_status, code);
31 __set_code_invalid(regs, linecode, fname);
33 set_code_success(regs);
37 __disk_ret_unimplemented(struct bregs *regs, u32 linecode, const char *fname)
40 if (regs->dl < EXTSTART_HD)
41 SET_BDA(floppy_last_status, code);
43 SET_BDA(disk_last_status, code);
44 __set_code_unimplemented(regs, linecode, fname);
48 __disk_stub(struct bregs *regs, int lineno, const char *fname)
50 __warn_unimplemented(regs, lineno, fname);
51 __disk_ret(regs, DISK_RET_SUCCESS | (lineno << 8), fname);
54 #define DISK_STUB(regs) \
55 __disk_stub((regs), __LINE__, __func__)
57 // Get the cylinders/heads/sectors for the given drive.
59 fillLCHS(struct drive_s *drive_g, u16 *nlc, u16 *nlh, u16 *nlspt)
62 && drive_g == GLOBALFLAT2GLOBAL(GET_GLOBAL(cdemu_drive_gf))) {
63 // Emulated drive - get info from ebda. (It's not possible to
64 // populate the geometry directly in the driveid because the
65 // geometry is only known after the bios segment is made
67 u16 ebda_seg = get_ebda_seg();
68 *nlc = GET_EBDA2(ebda_seg, cdemu.lchs.cylinders);
69 *nlh = GET_EBDA2(ebda_seg, cdemu.lchs.heads);
70 *nlspt = GET_EBDA2(ebda_seg, cdemu.lchs.spt);
73 *nlc = GET_GLOBAL(drive_g->lchs.cylinders);
74 *nlh = GET_GLOBAL(drive_g->lchs.heads);
75 *nlspt = GET_GLOBAL(drive_g->lchs.spt);
78 // Perform read/write/verify using old-style chs accesses
80 basic_access(struct bregs *regs, struct drive_s *drive_g, u16 command)
83 dop.drive_g = drive_g;
84 dop.command = command;
87 u16 cylinder = regs->ch | ((((u16)regs->cl) << 2) & 0x300);
88 u16 sector = regs->cl & 0x3f;
91 if (count > 128 || count == 0 || sector == 0) {
93 disk_ret(regs, DISK_RET_EPARAM);
99 fillLCHS(drive_g, &nlc, &nlh, &nlspt);
101 // sanity check on cyl heads, sec
102 if (cylinder >= nlc || head >= nlh || sector > nlspt) {
104 disk_ret(regs, DISK_RET_EPARAM);
108 // translate lchs to lba
109 dop.lba = (((((u32)cylinder * (u32)nlh) + (u32)head) * (u32)nlspt)
112 dop.buf_fl = MAKE_FLATPTR(regs->es, regs->bx);
114 int status = send_disk_op(&dop);
116 regs->al = dop.count;
118 disk_ret(regs, status);
121 // Perform read/write/verify using new-style "int13ext" accesses.
123 extended_access(struct bregs *regs, struct drive_s *drive_g, u16 command)
125 struct disk_op_s dop;
126 // Get lba and check.
127 dop.lba = GET_INT13EXT(regs, lba);
128 dop.command = command;
129 dop.drive_g = drive_g;
130 if (dop.lba >= GET_GLOBAL(drive_g->sectors)) {
132 disk_ret(regs, DISK_RET_EPARAM);
136 dop.buf_fl = SEGOFF_TO_FLATPTR(GET_INT13EXT(regs, data));
137 dop.count = GET_INT13EXT(regs, count);
139 int status = send_disk_op(&dop);
141 SET_INT13EXT(regs, count, dop.count);
143 disk_ret(regs, status);
147 /****************************************************************
148 * Hard Drive functions
149 ****************************************************************/
151 // disk controller reset
153 disk_1300(struct bregs *regs, struct drive_s *drive_g)
155 struct disk_op_s dop;
156 dop.drive_g = drive_g;
157 dop.command = CMD_RESET;
158 int status = send_disk_op(&dop);
159 disk_ret(regs, status);
164 disk_1301(struct bregs *regs, struct drive_s *drive_g)
167 if (regs->dl < EXTSTART_HD)
169 v = GET_BDA(floppy_last_status);
171 v = GET_BDA(disk_last_status);
174 // XXX - clear disk_last_status?
179 disk_1302(struct bregs *regs, struct drive_s *drive_g)
181 basic_access(regs, drive_g, CMD_READ);
184 // write disk sectors
186 disk_1303(struct bregs *regs, struct drive_s *drive_g)
188 basic_access(regs, drive_g, CMD_WRITE);
191 // verify disk sectors
193 disk_1304(struct bregs *regs, struct drive_s *drive_g)
195 basic_access(regs, drive_g, CMD_VERIFY);
200 disk_1305(struct bregs *regs, struct drive_s *drive_g)
205 fillLCHS(drive_g, &nlc, &nlh, &nlspt);
207 u8 num_sectors = regs->al;
210 if (head >= nlh || num_sectors == 0 || num_sectors > nlspt) {
211 disk_ret(regs, DISK_RET_EPARAM);
215 struct disk_op_s dop;
216 dop.drive_g = drive_g;
217 dop.command = CMD_FORMAT;
219 dop.count = num_sectors;
220 dop.buf_fl = MAKE_FLATPTR(regs->es, regs->bx);
221 int status = send_disk_op(&dop);
222 disk_ret(regs, status);
225 // read disk drive parameters
227 disk_1308(struct bregs *regs, struct drive_s *drive_g)
229 u16 ebda_seg = get_ebda_seg();
230 // Get logical geometry from table
232 fillLCHS(drive_g, &nlc, &nlh, &nlspt);
236 if (regs->dl < EXTSTART_HD) {
238 count = GET_GLOBAL(FloppyCount);
241 && drive_g == GLOBALFLAT2GLOBAL(GET_GLOBAL(cdemu_drive_gf)))
242 regs->bx = GET_EBDA2(ebda_seg, cdemu.media) * 2;
244 regs->bx = GET_GLOBAL(drive_g->floppy_type);
246 // set es & di to point to 11 byte diskette param table in ROM
248 regs->di = (u32)&diskette_param_table2;
249 } else if (regs->dl < EXTSTART_CD) {
251 count = GET_BDA(hdcount);
252 nlc--; // last sector reserved
254 // Not supported on CDROM
255 disk_ret(regs, DISK_RET_EPARAM);
259 if (CONFIG_CDROM_EMU && GET_EBDA2(ebda_seg, cdemu.active)) {
260 u8 emudrive = GET_EBDA2(ebda_seg, cdemu.emulated_extdrive);
261 if (((emudrive ^ regs->dl) & 0x80) == 0)
262 // Note extra drive due to emulation.
264 if (regs->dl < EXTSTART_HD && count > 2)
265 // Max of two floppy drives.
270 regs->ch = nlc & 0xff;
271 regs->cl = ((nlc >> 2) & 0xc0) | (nlspt & 0x3f);
274 disk_ret(regs, DISK_RET_SUCCESS);
278 // initialize drive parameters
280 disk_1309(struct bregs *regs, struct drive_s *drive_g)
285 // seek to specified cylinder
287 disk_130c(struct bregs *regs, struct drive_s *drive_g)
292 // alternate disk reset
294 disk_130d(struct bregs *regs, struct drive_s *drive_g)
301 disk_1310(struct bregs *regs, struct drive_s *drive_g)
303 // should look at 40:8E also???
305 struct disk_op_s dop;
306 dop.drive_g = drive_g;
307 dop.command = CMD_ISREADY;
308 int status = send_disk_op(&dop);
309 disk_ret(regs, status);
314 disk_1311(struct bregs *regs, struct drive_s *drive_g)
319 // controller internal diagnostic
321 disk_1314(struct bregs *regs, struct drive_s *drive_g)
326 // read disk drive size
328 disk_1315(struct bregs *regs, struct drive_s *drive_g)
330 disk_ret(regs, DISK_RET_SUCCESS);
331 if (regs->dl < EXTSTART_HD || regs->dl >= EXTSTART_CD) {
338 // Get logical geometry from table
340 fillLCHS(drive_g, &nlc, &nlh, &nlspt);
342 // Compute sector count seen by int13
343 u32 lba = (u32)(nlc - 1) * (u32)nlh * (u32)nlspt;
344 regs->cx = lba >> 16;
345 regs->dx = lba & 0xffff;
346 regs->ah = 3; // hard disk accessible
350 disk_1316(struct bregs *regs, struct drive_s *drive_g)
352 if (regs->dl >= EXTSTART_HD) {
354 disk_ret(regs, DISK_RET_EPARAM);
357 disk_ret(regs, DISK_RET_ECHANGED);
360 // IBM/MS installation check
362 disk_1341(struct bregs *regs, struct drive_s *drive_g)
364 regs->bx = 0xaa55; // install check
365 regs->cx = 0x0007; // ext disk access and edd, removable supported
366 disk_ret(regs, DISK_RET_SUCCESS);
367 regs->ah = 0x30; // EDD 3.0
370 // IBM/MS extended read
372 disk_1342(struct bregs *regs, struct drive_s *drive_g)
374 extended_access(regs, drive_g, CMD_READ);
377 // IBM/MS extended write
379 disk_1343(struct bregs *regs, struct drive_s *drive_g)
381 extended_access(regs, drive_g, CMD_WRITE);
386 disk_1344(struct bregs *regs, struct drive_s *drive_g)
388 extended_access(regs, drive_g, CMD_VERIFY);
393 disk_134500(struct bregs *regs, struct drive_s *drive_g)
395 u16 ebda_seg = get_ebda_seg();
396 int cdid = regs->dl - EXTSTART_CD;
397 u8 locks = GET_EBDA2(ebda_seg, cdrom_locks[cdid]);
400 disk_ret(regs, DISK_RET_ETOOMANYLOCKS);
403 SET_EBDA2(ebda_seg, cdrom_locks[cdid], locks + 1);
405 disk_ret(regs, DISK_RET_SUCCESS);
410 disk_134501(struct bregs *regs, struct drive_s *drive_g)
412 u16 ebda_seg = get_ebda_seg();
413 int cdid = regs->dl - EXTSTART_CD;
414 u8 locks = GET_EBDA2(ebda_seg, cdrom_locks[cdid]);
417 disk_ret(regs, DISK_RET_ENOTLOCKED);
421 SET_EBDA2(ebda_seg, cdrom_locks[cdid], locks);
422 regs->al = (locks ? 1 : 0);
423 disk_ret(regs, DISK_RET_SUCCESS);
428 disk_134502(struct bregs *regs, struct drive_s *drive_g)
430 int cdid = regs->dl - EXTSTART_CD;
431 u8 locks = GET_EBDA(cdrom_locks[cdid]);
432 regs->al = (locks ? 1 : 0);
433 disk_ret(regs, DISK_RET_SUCCESS);
437 disk_1345XX(struct bregs *regs, struct drive_s *drive_g)
439 disk_ret_unimplemented(regs, DISK_RET_EPARAM);
442 // IBM/MS lock/unlock drive
444 disk_1345(struct bregs *regs, struct drive_s *drive_g)
446 if (regs->dl < EXTSTART_CD) {
447 // Always success for HD
448 disk_ret(regs, DISK_RET_SUCCESS);
453 case 0x00: disk_134500(regs, drive_g); break;
454 case 0x01: disk_134501(regs, drive_g); break;
455 case 0x02: disk_134502(regs, drive_g); break;
456 default: disk_1345XX(regs, drive_g); break;
460 // IBM/MS eject media
462 disk_1346(struct bregs *regs, struct drive_s *drive_g)
464 if (regs->dl < EXTSTART_CD) {
465 // Volume Not Removable
466 disk_ret(regs, DISK_RET_ENOTREMOVABLE);
470 int cdid = regs->dl - EXTSTART_CD;
471 u8 locks = GET_EBDA(cdrom_locks[cdid]);
473 disk_ret(regs, DISK_RET_ELOCKED);
477 // FIXME should handle 0x31 no media in device
478 // FIXME should handle 0xb5 valid request failed
480 // Call removable media eject
482 memset(&br, 0, sizeof(br));
485 call16_int(0x15, &br);
487 if (br.ah || br.flags & F_CF) {
488 disk_ret(regs, DISK_RET_ELOCKED);
491 disk_ret(regs, DISK_RET_SUCCESS);
494 // IBM/MS extended seek
496 disk_1347(struct bregs *regs, struct drive_s *drive_g)
498 extended_access(regs, drive_g, CMD_SEEK);
501 // IBM/MS get drive parameters
503 disk_1348(struct bregs *regs, struct drive_s *drive_g)
505 u16 size = GET_INT13DPT(regs, size);
507 // Buffer is too small
509 disk_ret(regs, DISK_RET_EPARAM);
515 u8 type = GET_GLOBAL(drive_g->type);
516 u16 npc = GET_GLOBAL(drive_g->pchs.cylinders);
517 u16 nph = GET_GLOBAL(drive_g->pchs.heads);
518 u16 npspt = GET_GLOBAL(drive_g->pchs.spt);
519 u64 lba = GET_GLOBAL(drive_g->sectors);
520 u16 blksize = GET_GLOBAL(drive_g->blksize);
522 dprintf(DEBUG_HDL_13, "disk_1348 size=%d t=%d chs=%d,%d,%d lba=%d bs=%d\n"
523 , size, type, npc, nph, npspt, (u32)lba, blksize);
525 SET_INT13DPT(regs, size, 26);
526 if (type == DTYPE_ATAPI) {
527 // 0x74 = removable, media change, lockable, max values
528 SET_INT13DPT(regs, infos, 0x74);
529 SET_INT13DPT(regs, cylinders, 0xffffffff);
530 SET_INT13DPT(regs, heads, 0xffffffff);
531 SET_INT13DPT(regs, spt, 0xffffffff);
532 SET_INT13DPT(regs, sector_count, (u64)-1);
534 if (lba > (u64)npspt*nph*0x3fff) {
535 SET_INT13DPT(regs, infos, 0x00); // geometry is invalid
536 SET_INT13DPT(regs, cylinders, 0x3fff);
538 SET_INT13DPT(regs, infos, 0x02); // geometry is valid
539 SET_INT13DPT(regs, cylinders, (u32)npc);
541 SET_INT13DPT(regs, heads, (u32)nph);
542 SET_INT13DPT(regs, spt, (u32)npspt);
543 SET_INT13DPT(regs, sector_count, lba);
545 SET_INT13DPT(regs, blksize, blksize);
548 (type != DTYPE_ATA && type != DTYPE_ATAPI && type != DTYPE_VIRTIO)) {
549 disk_ret(regs, DISK_RET_SUCCESS);
558 SET_INT13DPT(regs, size, 30);
559 if (type == DTYPE_ATA || type == DTYPE_ATAPI) {
560 u16 ebda_seg = get_ebda_seg();
562 SET_INT13DPT(regs, dpte_segment, ebda_seg);
563 SET_INT13DPT(regs, dpte_offset
564 , offsetof(struct extended_bios_data_area_s, dpte));
567 struct atadrive_s *adrive_g = container_of(
568 drive_g, struct atadrive_s, drive);
569 struct ata_channel_s *chan_gf = GET_GLOBAL(adrive_g->chan_gf);
570 u8 slave = GET_GLOBAL(adrive_g->slave);
571 u16 iobase2 = GET_GLOBALFLAT(chan_gf->iobase2);
572 u8 irq = GET_GLOBALFLAT(chan_gf->irq);
573 iobase1 = GET_GLOBALFLAT(chan_gf->iobase1);
574 bdf = GET_GLOBALFLAT(chan_gf->pci_bdf);
578 if (type == DTYPE_ATA) {
579 u8 translation = GET_GLOBAL(drive_g->translation);
580 if (translation != TRANSLATION_NONE) {
581 options |= 1<<3; // CHS translation
582 if (translation == TRANSLATION_LBA)
584 if (translation == TRANSLATION_RECHS)
589 options |= 1<<5; // removable device
590 options |= 1<<6; // atapi device
592 options |= 1<<4; // lba translation
593 if (CONFIG_ATA_PIO32)
596 SET_EBDA2(ebda_seg, dpte.iobase1, iobase1);
597 SET_EBDA2(ebda_seg, dpte.iobase2, iobase2 + ATA_CB_DC);
598 SET_EBDA2(ebda_seg, dpte.prefix, ((slave ? ATA_CB_DH_DEV1 : ATA_CB_DH_DEV0)
600 SET_EBDA2(ebda_seg, dpte.unused, 0xcb);
601 SET_EBDA2(ebda_seg, dpte.irq, irq);
602 SET_EBDA2(ebda_seg, dpte.blkcount, 1);
603 SET_EBDA2(ebda_seg, dpte.dma, 0);
604 SET_EBDA2(ebda_seg, dpte.pio, 0);
605 SET_EBDA2(ebda_seg, dpte.options, options);
606 SET_EBDA2(ebda_seg, dpte.reserved, 0);
607 SET_EBDA2(ebda_seg, dpte.revision, 0x11);
609 u8 sum = checksum_far(
610 ebda_seg, (void*)offsetof(struct extended_bios_data_area_s, dpte), 15);
611 SET_EBDA2(ebda_seg, dpte.checksum, -sum);
613 SET_INT13DPT(regs, dpte_segment, 0);
614 SET_INT13DPT(regs, dpte_offset, 0);
615 bdf = GET_GLOBAL(drive_g->cntl_id);
621 disk_ret(regs, DISK_RET_SUCCESS);
626 SET_INT13DPT(regs, key, 0xbedd);
627 SET_INT13DPT(regs, dpi_length, 36);
628 SET_INT13DPT(regs, reserved1, 0);
629 SET_INT13DPT(regs, reserved2, 0);
632 SET_INT13DPT(regs, host_bus[0], 'P');
633 SET_INT13DPT(regs, host_bus[1], 'C');
634 SET_INT13DPT(regs, host_bus[2], 'I');
635 SET_INT13DPT(regs, host_bus[3], 0);
637 u32 path = (pci_bdf_to_bus(bdf) | (pci_bdf_to_dev(bdf) << 8)
638 | (pci_bdf_to_fn(bdf) << 16));
639 SET_INT13DPT(regs, iface_path, path);
642 SET_INT13DPT(regs, host_bus[0], 'I');
643 SET_INT13DPT(regs, host_bus[1], 'S');
644 SET_INT13DPT(regs, host_bus[2], 'A');
645 SET_INT13DPT(regs, host_bus[3], 0);
647 SET_INT13DPT(regs, iface_path, iobase1);
650 if (type != DTYPE_VIRTIO) {
651 SET_INT13DPT(regs, iface_type[0], 'A');
652 SET_INT13DPT(regs, iface_type[1], 'T');
653 SET_INT13DPT(regs, iface_type[2], 'A');
654 SET_INT13DPT(regs, iface_type[3], 0);
656 SET_INT13DPT(regs, iface_type[0], 'S');
657 SET_INT13DPT(regs, iface_type[1], 'C');
658 SET_INT13DPT(regs, iface_type[2], 'S');
659 SET_INT13DPT(regs, iface_type[3], 'I');
661 SET_INT13DPT(regs, iface_type[4], 0);
662 SET_INT13DPT(regs, iface_type[5], 0);
663 SET_INT13DPT(regs, iface_type[6], 0);
664 SET_INT13DPT(regs, iface_type[7], 0);
666 SET_INT13DPT(regs, device_path, device_path);
668 SET_INT13DPT(regs, checksum
669 , -checksum_far(regs->ds, (void*)(regs->si+30), 35));
671 disk_ret(regs, DISK_RET_SUCCESS);
674 // IBM/MS extended media change
676 disk_1349(struct bregs *regs, struct drive_s *drive_g)
678 if (regs->dl < EXTSTART_CD) {
679 // Always success for HD
680 disk_ret(regs, DISK_RET_SUCCESS);
684 // always send changed ??
685 regs->ah = DISK_RET_ECHANGED;
689 disk_134e01(struct bregs *regs, struct drive_s *drive_g)
691 disk_ret(regs, DISK_RET_SUCCESS);
695 disk_134e03(struct bregs *regs, struct drive_s *drive_g)
697 disk_ret(regs, DISK_RET_SUCCESS);
701 disk_134e04(struct bregs *regs, struct drive_s *drive_g)
703 disk_ret(regs, DISK_RET_SUCCESS);
707 disk_134e06(struct bregs *regs, struct drive_s *drive_g)
709 disk_ret(regs, DISK_RET_SUCCESS);
713 disk_134eXX(struct bregs *regs, struct drive_s *drive_g)
715 disk_ret(regs, DISK_RET_EPARAM);
718 // IBM/MS set hardware configuration
720 disk_134e(struct bregs *regs, struct drive_s *drive_g)
723 case 0x01: disk_134e01(regs, drive_g); break;
724 case 0x03: disk_134e03(regs, drive_g); break;
725 case 0x04: disk_134e04(regs, drive_g); break;
726 case 0x06: disk_134e06(regs, drive_g); break;
727 default: disk_134eXX(regs, drive_g); break;
732 disk_13XX(struct bregs *regs, struct drive_s *drive_g)
734 disk_ret_unimplemented(regs, DISK_RET_EPARAM);
738 disk_13(struct bregs *regs, struct drive_s *drive_g)
742 // clear completion flag
743 SET_BDA(disk_interrupt_flag, 0);
746 case 0x00: disk_1300(regs, drive_g); break;
747 case 0x01: disk_1301(regs, drive_g); break;
748 case 0x02: disk_1302(regs, drive_g); break;
749 case 0x03: disk_1303(regs, drive_g); break;
750 case 0x04: disk_1304(regs, drive_g); break;
751 case 0x05: disk_1305(regs, drive_g); break;
752 case 0x08: disk_1308(regs, drive_g); break;
753 case 0x09: disk_1309(regs, drive_g); break;
754 case 0x0c: disk_130c(regs, drive_g); break;
755 case 0x0d: disk_130d(regs, drive_g); break;
756 case 0x10: disk_1310(regs, drive_g); break;
757 case 0x11: disk_1311(regs, drive_g); break;
758 case 0x14: disk_1314(regs, drive_g); break;
759 case 0x15: disk_1315(regs, drive_g); break;
760 case 0x16: disk_1316(regs, drive_g); break;
761 case 0x41: disk_1341(regs, drive_g); break;
762 case 0x42: disk_1342(regs, drive_g); break;
763 case 0x43: disk_1343(regs, drive_g); break;
764 case 0x44: disk_1344(regs, drive_g); break;
765 case 0x45: disk_1345(regs, drive_g); break;
766 case 0x46: disk_1346(regs, drive_g); break;
767 case 0x47: disk_1347(regs, drive_g); break;
768 case 0x48: disk_1348(regs, drive_g); break;
769 case 0x49: disk_1349(regs, drive_g); break;
770 case 0x4e: disk_134e(regs, drive_g); break;
771 default: disk_13XX(regs, drive_g); break;
776 floppy_13(struct bregs *regs, struct drive_s *drive_g)
778 // Only limited commands are supported on floppies.
789 disk_13(regs, drive_g);
791 default: disk_13XX(regs, drive_g); break;
796 /****************************************************************
798 ****************************************************************/
801 handle_legacy_disk(struct bregs *regs, u8 extdrive)
803 if (! CONFIG_DRIVES) {
804 // XXX - support handle_1301 anyway?
805 disk_ret(regs, DISK_RET_EPARAM);
809 if (extdrive < EXTSTART_HD) {
810 struct drive_s *drive_g = getDrive(EXTTYPE_FLOPPY, extdrive);
813 floppy_13(regs, drive_g);
817 struct drive_s *drive_g;
818 if (extdrive >= EXTSTART_CD)
819 drive_g = getDrive(EXTTYPE_CD, extdrive - EXTSTART_CD);
821 drive_g = getDrive(EXTTYPE_HD, extdrive - EXTSTART_HD);
824 disk_13(regs, drive_g);
828 // XXX - support 1301/1308/1315 anyway?
829 disk_ret(regs, DISK_RET_EPARAM);
833 handle_40(struct bregs *regs)
835 debug_enter(regs, DEBUG_HDL_40);
836 handle_legacy_disk(regs, regs->dl);
839 // INT 13h Fixed Disk Services Entry Point
841 handle_13(struct bregs *regs)
843 debug_enter(regs, DEBUG_HDL_13);
844 u8 extdrive = regs->dl;
846 if (CONFIG_CDROM_EMU) {
847 if (regs->ah == 0x4b) {
851 u16 ebda_seg = get_ebda_seg();
852 if (GET_EBDA2(ebda_seg, cdemu.active)) {
853 u8 emudrive = GET_EBDA2(ebda_seg, cdemu.emulated_extdrive);
854 if (extdrive == emudrive) {
855 // Access to an emulated drive.
856 struct drive_s *cdemu_g;
857 cdemu_g = GLOBALFLAT2GLOBAL(GET_GLOBAL(cdemu_drive_gf));
858 if (regs->ah > 0x16) {
859 // Only old-style commands supported.
860 disk_13XX(regs, cdemu_g);
863 disk_13(regs, cdemu_g);
866 if (extdrive < EXTSTART_CD && ((emudrive ^ extdrive) & 0x80) == 0)
867 // Adjust id to make room for emulated drive.
871 handle_legacy_disk(regs, extdrive);
874 // record completion in BIOS task complete flag
878 debug_isr(DEBUG_ISR_76);
879 SET_BDA(disk_interrupt_flag, 0xff);
883 // Old Fixed Disk Parameter Table (newer tables are in the ebda).
884 struct fdpt_s OldFDPT VAR16FIXED(0xe401);