Don't 'autodetect' ATA PIO32 mode - use compile def instead.
[seabios.git] / src / disk.c
1 // 16bit code to access hard drives.
2 //
3 // Copyright (C) 2008  Kevin O'Connor <kevin@koconnor.net>
4 // Copyright (C) 2002  MandrakeSoft S.A.
5 //
6 // This file may be distributed under the terms of the GNU LGPLv3 license.
7
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 "atabits.h" // ATA_CB_STAT
16
17
18 /****************************************************************
19  * Helper functions
20  ****************************************************************/
21
22 void
23 __disk_ret(struct bregs *regs, u32 linecode, const char *fname)
24 {
25     u8 code = linecode;
26     SET_BDA(disk_last_status, code);
27     if (code)
28         __set_code_fail(regs, linecode, fname);
29     else
30         set_code_success(regs);
31 }
32
33 static void
34 __disk_stub(struct bregs *regs, int lineno, const char *fname)
35 {
36     __debug_stub(regs, lineno, fname);
37     __disk_ret(regs, DISK_RET_SUCCESS | (lineno << 8), fname);
38 }
39
40 #define DISK_STUB(regs)                         \
41     __disk_stub((regs), __LINE__, __func__)
42
43 static int
44 __send_disk_op(struct disk_op_s *op_far, u16 op_seg)
45 {
46     struct disk_op_s dop;
47     memcpy_far(GET_SEG(SS), &dop
48                , op_seg, op_far
49                , sizeof(dop));
50
51     dprintf(DEBUG_HDL_13, "disk_op d=%d lba=%d buf=%p count=%d cmd=%d\n"
52             , dop.driveid, (u32)dop.lba, dop.buf_fl
53             , dop.count, dop.command);
54
55     irq_enable();
56
57     int status;
58     if (dop.command == CMD_CDEMU_READ)
59         status = cdrom_read_512(&dop);
60     else if (dop.command == CMD_CDROM_READ)
61         status = cdrom_read(&dop);
62     else
63         status = ata_cmd_data(&dop);
64
65     irq_disable();
66
67     return status;
68 }
69
70 static int
71 send_disk_op(struct disk_op_s *op)
72 {
73     if (! CONFIG_ATA)
74         return -1;
75
76     return stack_hop((u32)op, GET_SEG(SS), 0, __send_disk_op);
77 }
78
79 static void
80 basic_access(struct bregs *regs, u8 device, u16 command)
81 {
82     struct disk_op_s dop;
83     dop.lba = 0;
84     dop.driveid = device;
85     u8 type = GET_GLOBAL(ATA.devices[device].type);
86     u16 nlc, nlh, nlspt;
87     if (type == ATA_TYPE_ATA) {
88         nlc   = GET_GLOBAL(ATA.devices[device].lchs.cylinders);
89         nlh   = GET_GLOBAL(ATA.devices[device].lchs.heads);
90         nlspt = GET_GLOBAL(ATA.devices[device].lchs.spt);
91         dop.command = command;
92     } else {
93         // Must be cd emulation.
94         u16 ebda_seg = get_ebda_seg();
95         nlc   = GET_EBDA2(ebda_seg, cdemu.cylinders);
96         nlh   = GET_EBDA2(ebda_seg, cdemu.heads);
97         nlspt = GET_EBDA2(ebda_seg, cdemu.spt);
98         dop.lba = GET_EBDA2(ebda_seg, cdemu.ilba) * 4;
99         dop.command = CMD_CDEMU_READ;
100     }
101
102     dop.count       = regs->al;
103     u16 cylinder    = regs->ch | ((((u16) regs->cl) << 2) & 0x300);
104     u16 sector      = regs->cl & 0x3f;
105     u16 head        = regs->dh;
106
107     if (dop.count > 128 || dop.count == 0 || sector == 0) {
108         dprintf(1, "int13_harddisk: function %02x, parameter out of range!\n"
109                 , regs->ah);
110         disk_ret(regs, DISK_RET_EPARAM);
111         return;
112     }
113
114     // sanity check on cyl heads, sec
115     if (cylinder >= nlc || head >= nlh || sector > nlspt) {
116         dprintf(1, "int13_harddisk: function %02x, parameters out of"
117                 " range %04x/%04x/%04x!\n"
118                 , regs->ah, cylinder, head, sector);
119         disk_ret(regs, DISK_RET_EPARAM);
120         return;
121     }
122
123     if (!command) {
124         // If verify or seek
125         disk_ret(regs, DISK_RET_SUCCESS);
126         return;
127     }
128
129     // translate lchs to lba
130     dop.lba += (((((u32)cylinder * (u32)nlh) + (u32)head) * (u32)nlspt)
131                 + (u32)sector - 1);
132
133     u16 segment = regs->es;
134     u16 offset  = regs->bx;
135     dop.buf_fl = MAKE_FLATPTR(segment, offset);
136
137     int status = send_disk_op(&dop);
138
139     // Set nb of sector transferred
140     regs->al = GET_EBDA(sector_count);
141
142     if (status != 0) {
143         dprintf(1, "int13_harddisk: function %02x, error %d!\n"
144                 , regs->ah, status);
145         disk_ret(regs, DISK_RET_EBADTRACK);
146         return;
147     }
148     disk_ret(regs, DISK_RET_SUCCESS);
149 }
150
151 static void
152 extended_access(struct bregs *regs, u8 device, u16 command)
153 {
154     struct disk_op_s dop;
155     // Get lba and check.
156     dop.lba = GET_INT13EXT(regs, lba);
157     dop.command = command;
158     dop.driveid = device;
159     u8 type = GET_GLOBAL(ATA.devices[device].type);
160     if (type == ATA_TYPE_ATA) {
161         if (dop.lba >= GET_GLOBAL(ATA.devices[device].sectors)) {
162             dprintf(1, "int13_harddisk: function %02x. LBA out of range\n"
163                     , regs->ah);
164             disk_ret(regs, DISK_RET_EPARAM);
165             return;
166         }
167     } else {
168         dop.command = CMD_CDROM_READ;
169     }
170
171     if (!command) {
172         // If verify or seek
173         disk_ret(regs, DISK_RET_SUCCESS);
174         return;
175     }
176
177     u16 segment = GET_INT13EXT(regs, segment);
178     u16 offset = GET_INT13EXT(regs, offset);
179     dop.buf_fl = MAKE_FLATPTR(segment, offset);
180     dop.count = GET_INT13EXT(regs, count);
181
182     int status = send_disk_op(&dop);
183
184     SET_INT13EXT(regs, count, GET_EBDA(sector_count));
185
186     if (status != 0) {
187         dprintf(1, "int13_harddisk: function %02x, error %d!\n"
188                 , regs->ah, status);
189         disk_ret(regs, DISK_RET_EBADTRACK);
190         return;
191     }
192     disk_ret(regs, DISK_RET_SUCCESS);
193 }
194
195
196 /****************************************************************
197  * Hard Drive functions
198  ****************************************************************/
199
200 // disk controller reset
201 static void
202 disk_1300(struct bregs *regs, u8 device)
203 {
204     ata_reset(device);
205 }
206
207 // read disk status
208 static void
209 disk_1301(struct bregs *regs, u8 device)
210 {
211     u8 v = GET_BDA(disk_last_status);
212     regs->ah = v;
213     set_cf(regs, v);
214     // XXX - clear disk_last_status?
215 }
216
217 // read disk sectors
218 static void
219 disk_1302(struct bregs *regs, u8 device)
220 {
221     basic_access(regs, device, ATA_CMD_READ_SECTORS);
222 }
223
224 // write disk sectors
225 static void
226 disk_1303(struct bregs *regs, u8 device)
227 {
228     basic_access(regs, device, ATA_CMD_WRITE_SECTORS);
229 }
230
231 // verify disk sectors
232 static void
233 disk_1304(struct bregs *regs, u8 device)
234 {
235     basic_access(regs, device, 0);
236     // FIXME verify
237 }
238
239 // format disk track
240 static void
241 disk_1305(struct bregs *regs, u8 device)
242 {
243     DISK_STUB(regs);
244 }
245
246 // read disk drive parameters
247 static void
248 disk_1308(struct bregs *regs, u8 device)
249 {
250     // Get logical geometry from table
251     u16 nlc = GET_GLOBAL(ATA.devices[device].lchs.cylinders);
252     u16 nlh = GET_GLOBAL(ATA.devices[device].lchs.heads);
253     u16 nlspt = GET_GLOBAL(ATA.devices[device].lchs.spt);
254     u16 count = GET_BDA(hdcount);
255
256     nlc = nlc - 2; /* 0 based , last sector not used */
257     regs->al = 0;
258     regs->ch = nlc & 0xff;
259     regs->cl = ((nlc >> 2) & 0xc0) | (nlspt & 0x3f);
260     regs->dh = nlh - 1;
261     regs->dl = count; /* FIXME returns 0, 1, or n hard drives */
262
263     // FIXME should set ES & DI
264     disk_ret(regs, DISK_RET_SUCCESS);
265 }
266
267 // initialize drive parameters
268 static void
269 disk_1309(struct bregs *regs, u8 device)
270 {
271     DISK_STUB(regs);
272 }
273
274 // seek to specified cylinder
275 static void
276 disk_130c(struct bregs *regs, u8 device)
277 {
278     DISK_STUB(regs);
279 }
280
281 // alternate disk reset
282 static void
283 disk_130d(struct bregs *regs, u8 device)
284 {
285     DISK_STUB(regs);
286 }
287
288 // check drive ready
289 static void
290 disk_1310(struct bregs *regs, u8 device)
291 {
292     // should look at 40:8E also???
293
294     // Read the status from controller
295     u8 status = inb(GET_GLOBAL(ATA.channels[device/2].iobase1) + ATA_CB_STAT);
296     if ( (status & ( ATA_CB_STAT_BSY | ATA_CB_STAT_RDY )) == ATA_CB_STAT_RDY )
297         disk_ret(regs, DISK_RET_SUCCESS);
298     else
299         disk_ret(regs, DISK_RET_ENOTREADY);
300 }
301
302 // recalibrate
303 static void
304 disk_1311(struct bregs *regs, u8 device)
305 {
306     DISK_STUB(regs);
307 }
308
309 // controller internal diagnostic
310 static void
311 disk_1314(struct bregs *regs, u8 device)
312 {
313     DISK_STUB(regs);
314 }
315
316 // read disk drive size
317 static void
318 disk_1315(struct bregs *regs, u8 device)
319 {
320     // Get logical geometry from table
321     u16 nlc   = GET_GLOBAL(ATA.devices[device].lchs.cylinders);
322     u16 nlh   = GET_GLOBAL(ATA.devices[device].lchs.heads);
323     u16 nlspt = GET_GLOBAL(ATA.devices[device].lchs.spt);
324
325     // Compute sector count seen by int13
326     u32 lba = (u32)(nlc - 1) * (u32)nlh * (u32)nlspt;
327     regs->cx = lba >> 16;
328     regs->dx = lba & 0xffff;
329
330     disk_ret(regs, DISK_RET_SUCCESS);
331     regs->ah = 3; // hard disk accessible
332 }
333
334 // IBM/MS installation check
335 static void
336 disk_1341(struct bregs *regs, u8 device)
337 {
338     regs->bx = 0xaa55;  // install check
339     regs->cx = 0x0007;  // ext disk access and edd, removable supported
340     disk_ret(regs, DISK_RET_SUCCESS);
341     regs->ah = 0x30;    // EDD 3.0
342 }
343
344 // IBM/MS extended read
345 static void
346 disk_1342(struct bregs *regs, u8 device)
347 {
348     extended_access(regs, device, ATA_CMD_READ_SECTORS);
349 }
350
351 // IBM/MS extended write
352 static void
353 disk_1343(struct bregs *regs, u8 device)
354 {
355     extended_access(regs, device, ATA_CMD_WRITE_SECTORS);
356 }
357
358 // IBM/MS verify
359 static void
360 disk_1344(struct bregs *regs, u8 device)
361 {
362     extended_access(regs, device, 0);
363 }
364
365 // IBM/MS lock/unlock drive
366 static void
367 disk_1345(struct bregs *regs, u8 device)
368 {
369     // Always success for HD
370     disk_ret(regs, DISK_RET_SUCCESS);
371 }
372
373 // IBM/MS eject media
374 static void
375 disk_1346(struct bregs *regs, u8 device)
376 {
377     // Volume Not Removable
378     disk_ret(regs, DISK_RET_ENOTREMOVABLE);
379 }
380
381 // IBM/MS extended seek
382 static void
383 disk_1347(struct bregs *regs, u8 device)
384 {
385     extended_access(regs, device, 0);
386 }
387
388 // IBM/MS get drive parameters
389 static void
390 disk_1348(struct bregs *regs, u8 device)
391 {
392     u16 size = GET_INT13DPT(regs, size);
393
394     // Buffer is too small
395     if (size < 26) {
396         disk_ret(regs, DISK_RET_EPARAM);
397         return;
398     }
399
400     // EDD 1.x
401
402     u8  type    = GET_GLOBAL(ATA.devices[device].type);
403     u16 npc     = GET_GLOBAL(ATA.devices[device].pchs.cylinders);
404     u16 nph     = GET_GLOBAL(ATA.devices[device].pchs.heads);
405     u16 npspt   = GET_GLOBAL(ATA.devices[device].pchs.spt);
406     u64 lba     = GET_GLOBAL(ATA.devices[device].sectors);
407     u16 blksize = GET_GLOBAL(ATA.devices[device].blksize);
408
409     dprintf(DEBUG_HDL_13, "disk_1348 size=%d t=%d chs=%d,%d,%d lba=%d bs=%d\n"
410             , size, type, npc, nph, npspt, (u32)lba, blksize);
411
412     SET_INT13DPT(regs, size, 26);
413     if (type == ATA_TYPE_ATA) {
414         if (lba > (u64)npspt*nph*0x3fff) {
415             SET_INT13DPT(regs, infos, 0x00); // geometry is invalid
416             SET_INT13DPT(regs, cylinders, 0x3fff);
417         } else {
418             SET_INT13DPT(regs, infos, 0x02); // geometry is valid
419             SET_INT13DPT(regs, cylinders, (u32)npc);
420         }
421         SET_INT13DPT(regs, heads, (u32)nph);
422         SET_INT13DPT(regs, spt, (u32)npspt);
423         SET_INT13DPT(regs, sector_count, lba);
424     } else {
425         // ATAPI
426         // 0x74 = removable, media change, lockable, max values
427         SET_INT13DPT(regs, infos, 0x74);
428         SET_INT13DPT(regs, cylinders, 0xffffffff);
429         SET_INT13DPT(regs, heads, 0xffffffff);
430         SET_INT13DPT(regs, spt, 0xffffffff);
431         SET_INT13DPT(regs, sector_count, (u64)-1);
432     }
433     SET_INT13DPT(regs, blksize, blksize);
434
435     if (size < 30) {
436         disk_ret(regs, DISK_RET_SUCCESS);
437         return;
438     }
439
440     // EDD 2.x
441
442     u16 ebda_seg = get_ebda_seg();
443     SET_INT13DPT(regs, size, 30);
444
445     SET_INT13DPT(regs, dpte_segment, ebda_seg);
446     SET_INT13DPT(regs, dpte_offset
447                  , offsetof(struct extended_bios_data_area_s, dpte));
448
449     // Fill in dpte
450     u8 channel = device / 2;
451     u8 slave = device % 2;
452     u16 iobase1 = GET_GLOBAL(ATA.channels[channel].iobase1);
453     u16 iobase2 = GET_GLOBAL(ATA.channels[channel].iobase2);
454     u8 irq = GET_GLOBAL(ATA.channels[channel].irq);
455
456     u16 options = 0;
457     if (type == ATA_TYPE_ATA) {
458         u8 translation = GET_GLOBAL(ATA.devices[device].translation);
459         if (translation != ATA_TRANSLATION_NONE) {
460             options |= 1<<3; // CHS translation
461             if (translation == ATA_TRANSLATION_LBA)
462                 options |= 1<<9;
463             if (translation == ATA_TRANSLATION_RECHS)
464                 options |= 3<<9;
465         }
466     } else {
467         // ATAPI
468         options |= 1<<5; // removable device
469         options |= 1<<6; // atapi device
470     }
471     options |= 1<<4; // lba translation
472     if (CONFIG_ATA_PIO32)
473         options |= 1<<7;
474
475     SET_EBDA2(ebda_seg, dpte.iobase1, iobase1);
476     SET_EBDA2(ebda_seg, dpte.iobase2, iobase2 + ATA_CB_DC);
477     SET_EBDA2(ebda_seg, dpte.prefix, ((slave ? ATA_CB_DH_DEV1 : ATA_CB_DH_DEV0)
478                                       | ATA_CB_DH_LBA));
479     SET_EBDA2(ebda_seg, dpte.unused, 0xcb);
480     SET_EBDA2(ebda_seg, dpte.irq, irq);
481     SET_EBDA2(ebda_seg, dpte.blkcount, 1);
482     SET_EBDA2(ebda_seg, dpte.dma, 0);
483     SET_EBDA2(ebda_seg, dpte.pio, 0);
484     SET_EBDA2(ebda_seg, dpte.options, options);
485     SET_EBDA2(ebda_seg, dpte.reserved, 0);
486     SET_EBDA2(ebda_seg, dpte.revision, 0x11);
487
488     u8 sum = checksum_far(
489         ebda_seg, (void*)offsetof(struct extended_bios_data_area_s, dpte), 15);
490     SET_EBDA2(ebda_seg, dpte.checksum, -sum);
491
492     if (size < 66) {
493         disk_ret(regs, DISK_RET_SUCCESS);
494         return;
495     }
496
497     // EDD 3.x
498     SET_INT13DPT(regs, key, 0xbedd);
499     SET_INT13DPT(regs, dpi_length, 36);
500     SET_INT13DPT(regs, reserved1, 0);
501     SET_INT13DPT(regs, reserved2, 0);
502
503     SET_INT13DPT(regs, host_bus[0], 'P');
504     SET_INT13DPT(regs, host_bus[1], 'C');
505     SET_INT13DPT(regs, host_bus[2], 'I');
506     SET_INT13DPT(regs, host_bus[3], 0);
507
508     u32 bdf = GET_GLOBAL(ATA.channels[channel].pci_bdf);
509     u32 path = (pci_bdf_to_bus(bdf) | (pci_bdf_to_dev(bdf) << 8)
510                 | (pci_bdf_to_fn(bdf) << 16));
511     SET_INT13DPT(regs, iface_path, path);
512
513     SET_INT13DPT(regs, iface_type[0], 'A');
514     SET_INT13DPT(regs, iface_type[1], 'T');
515     SET_INT13DPT(regs, iface_type[2], 'A');
516     SET_INT13DPT(regs, iface_type[3], 0);
517     SET_INT13DPT(regs, iface_type[4], 0);
518     SET_INT13DPT(regs, iface_type[5], 0);
519     SET_INT13DPT(regs, iface_type[6], 0);
520     SET_INT13DPT(regs, iface_type[7], 0);
521
522     SET_INT13DPT(regs, device_path, slave);
523
524     SET_INT13DPT(regs, checksum
525                  , -checksum_far(regs->ds, (void*)(regs->si+30), 35));
526
527     disk_ret(regs, DISK_RET_SUCCESS);
528 }
529
530 // IBM/MS extended media change
531 static void
532 disk_1349(struct bregs *regs, u8 device)
533 {
534     // Always success for HD
535     disk_ret(regs, DISK_RET_SUCCESS);
536 }
537
538 static void
539 disk_134e01(struct bregs *regs, u8 device)
540 {
541     disk_ret(regs, DISK_RET_SUCCESS);
542 }
543
544 static void
545 disk_134e03(struct bregs *regs, u8 device)
546 {
547     disk_ret(regs, DISK_RET_SUCCESS);
548 }
549
550 static void
551 disk_134e04(struct bregs *regs, u8 device)
552 {
553     disk_ret(regs, DISK_RET_SUCCESS);
554 }
555
556 static void
557 disk_134e06(struct bregs *regs, u8 device)
558 {
559     disk_ret(regs, DISK_RET_SUCCESS);
560 }
561
562 static void
563 disk_134eXX(struct bregs *regs, u8 device)
564 {
565     disk_ret(regs, DISK_RET_EPARAM);
566 }
567
568 // IBM/MS set hardware configuration
569 static void
570 disk_134e(struct bregs *regs, u8 device)
571 {
572     switch (regs->al) {
573     case 0x01: disk_134e01(regs, device); break;
574     case 0x03: disk_134e03(regs, device); break;
575     case 0x04: disk_134e04(regs, device); break;
576     case 0x06: disk_134e06(regs, device); break;
577     default:   disk_134eXX(regs, device); break;
578     }
579 }
580
581 void
582 disk_13XX(struct bregs *regs, u8 device)
583 {
584     disk_ret(regs, DISK_RET_EPARAM);
585 }
586
587 void
588 disk_13(struct bregs *regs, u8 device)
589 {
590     //debug_stub(regs);
591
592     // clear completion flag
593     SET_BDA(disk_interrupt_flag, 0);
594
595     switch (regs->ah) {
596     case 0x00: disk_1300(regs, device); break;
597     case 0x01: disk_1301(regs, device); break;
598     case 0x02: disk_1302(regs, device); break;
599     case 0x03: disk_1303(regs, device); break;
600     case 0x04: disk_1304(regs, device); break;
601     case 0x05: disk_1305(regs, device); break;
602     case 0x08: disk_1308(regs, device); break;
603     case 0x09: disk_1309(regs, device); break;
604     case 0x0c: disk_130c(regs, device); break;
605     case 0x0d: disk_130d(regs, device); break;
606     case 0x10: disk_1310(regs, device); break;
607     case 0x11: disk_1311(regs, device); break;
608     case 0x14: disk_1314(regs, device); break;
609     case 0x15: disk_1315(regs, device); break;
610     case 0x41: disk_1341(regs, device); break;
611     case 0x42: disk_1342(regs, device); break;
612     case 0x43: disk_1343(regs, device); break;
613     case 0x44: disk_1344(regs, device); break;
614     case 0x45: disk_1345(regs, device); break;
615     case 0x46: disk_1346(regs, device); break;
616     case 0x47: disk_1347(regs, device); break;
617     case 0x48: disk_1348(regs, device); break;
618     case 0x49: disk_1349(regs, device); break;
619     case 0x4e: disk_134e(regs, device); break;
620     default:   disk_13XX(regs, device); break;
621     }
622 }
623
624
625 /****************************************************************
626  * Entry points
627  ****************************************************************/
628
629 static u8
630 get_device(struct bregs *regs, u8 iscd, u8 drive)
631 {
632     // basic check : device has to be defined
633     if (drive >= CONFIG_MAX_ATA_DEVICES) {
634         disk_ret(regs, DISK_RET_EPARAM);
635         return CONFIG_MAX_ATA_DEVICES;
636     }
637
638     // Get the ata channel
639     u8 device = GET_GLOBAL(ATA.idmap[iscd][drive]);
640
641     // basic check : device has to be valid
642     if (device >= CONFIG_MAX_ATA_DEVICES) {
643         disk_ret(regs, DISK_RET_EPARAM);
644         return CONFIG_MAX_ATA_DEVICES;
645     }
646
647     return device;
648 }
649
650 static void
651 handle_legacy_disk(struct bregs *regs, u8 drive)
652 {
653     if (drive < 0x80) {
654         floppy_13(regs, drive);
655         return;
656     }
657
658     if (! CONFIG_ATA) {
659         // XXX - old code had other disk access method.
660         disk_ret(regs, DISK_RET_EPARAM);
661         return;
662     }
663
664     if (drive >= 0xe0) {
665         u8 device = get_device(regs, 1, drive - 0xe0);
666         if (device >= CONFIG_MAX_ATA_DEVICES)
667             return;
668         cdrom_13(regs, device);
669         return;
670     }
671
672     u8 device = get_device(regs, 0, drive - 0x80);
673     if (device >= CONFIG_MAX_ATA_DEVICES)
674         return;
675     disk_13(regs, device);
676 }
677
678 void VISIBLE16
679 handle_40(struct bregs *regs)
680 {
681     debug_enter(regs, DEBUG_HDL_40);
682     handle_legacy_disk(regs, regs->dl);
683 }
684
685 // INT 13h Fixed Disk Services Entry Point
686 void VISIBLE16
687 handle_13(struct bregs *regs)
688 {
689     debug_enter(regs, DEBUG_HDL_13);
690     u8 drive = regs->dl;
691
692     if (CONFIG_CDROM_EMU) {
693         if (regs->ah == 0x4b) {
694             cdemu_134b(regs);
695             return;
696         }
697         u16 ebda_seg = get_ebda_seg();
698         if (GET_EBDA2(ebda_seg, cdemu.active)) {
699             u8 emudrive = GET_EBDA2(ebda_seg, cdemu.emulated_drive);
700             if (drive == emudrive) {
701                 cdemu_13(regs);
702                 return;
703             }
704             if (drive < 0xe0 && ((emudrive ^ drive) & 0x80) == 0)
705                 drive--;
706         }
707     }
708     handle_legacy_disk(regs, drive);
709 }
710
711 // record completion in BIOS task complete flag
712 void VISIBLE16
713 handle_76()
714 {
715     debug_isr(DEBUG_ISR_76);
716     SET_BDA(disk_interrupt_flag, 0xff);
717     eoi_pic2();
718 }
719
720 // Old Fixed Disk Parameter Table (newer tables are in the ebda).
721 struct fdpt_s OldFDPT VAR16FIXED(0xe401);