Bug fix - cdrom media emulation only moves drives if of the same type.
[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     u8 mode = GET_GLOBAL(ATA.devices[device].mode);
456
457     u16 options = 0;
458     if (type == ATA_TYPE_ATA) {
459         u8 translation = GET_GLOBAL(ATA.devices[device].translation);
460         if (translation != ATA_TRANSLATION_NONE) {
461             options |= 1<<3; // CHS translation
462             if (translation == ATA_TRANSLATION_LBA)
463                 options |= 1<<9;
464             if (translation == ATA_TRANSLATION_RECHS)
465                 options |= 3<<9;
466         }
467     } else {
468         // ATAPI
469         options |= 1<<5; // removable device
470         options |= 1<<6; // atapi device
471     }
472     options |= 1<<4; // lba translation
473     if (mode == ATA_MODE_PIO32)
474         options |= 1<<7;
475
476     SET_EBDA2(ebda_seg, dpte.iobase1, iobase1);
477     SET_EBDA2(ebda_seg, dpte.iobase2, iobase2 + ATA_CB_DC);
478     SET_EBDA2(ebda_seg, dpte.prefix, ((slave ? ATA_CB_DH_DEV1 : ATA_CB_DH_DEV0)
479                                       | ATA_CB_DH_LBA));
480     SET_EBDA2(ebda_seg, dpte.unused, 0xcb);
481     SET_EBDA2(ebda_seg, dpte.irq, irq);
482     SET_EBDA2(ebda_seg, dpte.blkcount, 1);
483     SET_EBDA2(ebda_seg, dpte.dma, 0);
484     SET_EBDA2(ebda_seg, dpte.pio, 0);
485     SET_EBDA2(ebda_seg, dpte.options, options);
486     SET_EBDA2(ebda_seg, dpte.reserved, 0);
487     SET_EBDA2(ebda_seg, dpte.revision, 0x11);
488
489     u8 sum = checksum_far(
490         ebda_seg, (void*)offsetof(struct extended_bios_data_area_s, dpte), 15);
491     SET_EBDA2(ebda_seg, dpte.checksum, -sum);
492
493     if (size < 66) {
494         disk_ret(regs, DISK_RET_SUCCESS);
495         return;
496     }
497
498     // EDD 3.x
499     SET_INT13DPT(regs, key, 0xbedd);
500     SET_INT13DPT(regs, dpi_length, 36);
501     SET_INT13DPT(regs, reserved1, 0);
502     SET_INT13DPT(regs, reserved2, 0);
503
504     SET_INT13DPT(regs, host_bus[0], 'P');
505     SET_INT13DPT(regs, host_bus[1], 'C');
506     SET_INT13DPT(regs, host_bus[2], 'I');
507     SET_INT13DPT(regs, host_bus[3], 0);
508
509     u32 bdf = GET_GLOBAL(ATA.channels[channel].pci_bdf);
510     u32 path = (pci_bdf_to_bus(bdf) | (pci_bdf_to_dev(bdf) << 8)
511                 | (pci_bdf_to_fn(bdf) << 16));
512     SET_INT13DPT(regs, iface_path, path);
513
514     SET_INT13DPT(regs, iface_type[0], 'A');
515     SET_INT13DPT(regs, iface_type[1], 'T');
516     SET_INT13DPT(regs, iface_type[2], 'A');
517     SET_INT13DPT(regs, iface_type[3], 0);
518     SET_INT13DPT(regs, iface_type[4], 0);
519     SET_INT13DPT(regs, iface_type[5], 0);
520     SET_INT13DPT(regs, iface_type[6], 0);
521     SET_INT13DPT(regs, iface_type[7], 0);
522
523     SET_INT13DPT(regs, device_path, slave);
524
525     SET_INT13DPT(regs, checksum
526                  , -checksum_far(regs->ds, (void*)(regs->si+30), 35));
527
528     disk_ret(regs, DISK_RET_SUCCESS);
529 }
530
531 // IBM/MS extended media change
532 static void
533 disk_1349(struct bregs *regs, u8 device)
534 {
535     // Always success for HD
536     disk_ret(regs, DISK_RET_SUCCESS);
537 }
538
539 static void
540 disk_134e01(struct bregs *regs, u8 device)
541 {
542     disk_ret(regs, DISK_RET_SUCCESS);
543 }
544
545 static void
546 disk_134e03(struct bregs *regs, u8 device)
547 {
548     disk_ret(regs, DISK_RET_SUCCESS);
549 }
550
551 static void
552 disk_134e04(struct bregs *regs, u8 device)
553 {
554     disk_ret(regs, DISK_RET_SUCCESS);
555 }
556
557 static void
558 disk_134e06(struct bregs *regs, u8 device)
559 {
560     disk_ret(regs, DISK_RET_SUCCESS);
561 }
562
563 static void
564 disk_134eXX(struct bregs *regs, u8 device)
565 {
566     disk_ret(regs, DISK_RET_EPARAM);
567 }
568
569 // IBM/MS set hardware configuration
570 static void
571 disk_134e(struct bregs *regs, u8 device)
572 {
573     switch (regs->al) {
574     case 0x01: disk_134e01(regs, device); break;
575     case 0x03: disk_134e03(regs, device); break;
576     case 0x04: disk_134e04(regs, device); break;
577     case 0x06: disk_134e06(regs, device); break;
578     default:   disk_134eXX(regs, device); break;
579     }
580 }
581
582 void
583 disk_13XX(struct bregs *regs, u8 device)
584 {
585     disk_ret(regs, DISK_RET_EPARAM);
586 }
587
588 void
589 disk_13(struct bregs *regs, u8 device)
590 {
591     //debug_stub(regs);
592
593     // clear completion flag
594     SET_BDA(disk_interrupt_flag, 0);
595
596     switch (regs->ah) {
597     case 0x00: disk_1300(regs, device); break;
598     case 0x01: disk_1301(regs, device); break;
599     case 0x02: disk_1302(regs, device); break;
600     case 0x03: disk_1303(regs, device); break;
601     case 0x04: disk_1304(regs, device); break;
602     case 0x05: disk_1305(regs, device); break;
603     case 0x08: disk_1308(regs, device); break;
604     case 0x09: disk_1309(regs, device); break;
605     case 0x0c: disk_130c(regs, device); break;
606     case 0x0d: disk_130d(regs, device); break;
607     case 0x10: disk_1310(regs, device); break;
608     case 0x11: disk_1311(regs, device); break;
609     case 0x14: disk_1314(regs, device); break;
610     case 0x15: disk_1315(regs, device); break;
611     case 0x41: disk_1341(regs, device); break;
612     case 0x42: disk_1342(regs, device); break;
613     case 0x43: disk_1343(regs, device); break;
614     case 0x44: disk_1344(regs, device); break;
615     case 0x45: disk_1345(regs, device); break;
616     case 0x46: disk_1346(regs, device); break;
617     case 0x47: disk_1347(regs, device); break;
618     case 0x48: disk_1348(regs, device); break;
619     case 0x49: disk_1349(regs, device); break;
620     case 0x4e: disk_134e(regs, device); break;
621     default:   disk_13XX(regs, device); break;
622     }
623 }
624
625
626 /****************************************************************
627  * Entry points
628  ****************************************************************/
629
630 static u8
631 get_device(struct bregs *regs, u8 iscd, u8 drive)
632 {
633     // basic check : device has to be defined
634     if (drive >= CONFIG_MAX_ATA_DEVICES) {
635         disk_ret(regs, DISK_RET_EPARAM);
636         return CONFIG_MAX_ATA_DEVICES;
637     }
638
639     // Get the ata channel
640     u8 device = GET_GLOBAL(ATA.idmap[iscd][drive]);
641
642     // basic check : device has to be valid
643     if (device >= CONFIG_MAX_ATA_DEVICES) {
644         disk_ret(regs, DISK_RET_EPARAM);
645         return CONFIG_MAX_ATA_DEVICES;
646     }
647
648     return device;
649 }
650
651 static void
652 handle_legacy_disk(struct bregs *regs, u8 drive)
653 {
654     if (drive < 0x80) {
655         floppy_13(regs, drive);
656         return;
657     }
658
659     if (! CONFIG_ATA) {
660         // XXX - old code had other disk access method.
661         disk_ret(regs, DISK_RET_EPARAM);
662         return;
663     }
664
665     if (drive >= 0xe0) {
666         u8 device = get_device(regs, 1, drive - 0xe0);
667         if (device >= CONFIG_MAX_ATA_DEVICES)
668             return;
669         cdrom_13(regs, device);
670         return;
671     }
672
673     u8 device = get_device(regs, 0, drive - 0x80);
674     if (device >= CONFIG_MAX_ATA_DEVICES)
675         return;
676     disk_13(regs, device);
677 }
678
679 void VISIBLE16
680 handle_40(struct bregs *regs)
681 {
682     debug_enter(regs, DEBUG_HDL_40);
683     handle_legacy_disk(regs, regs->dl);
684 }
685
686 // INT 13h Fixed Disk Services Entry Point
687 void VISIBLE16
688 handle_13(struct bregs *regs)
689 {
690     debug_enter(regs, DEBUG_HDL_13);
691     u8 drive = regs->dl;
692
693     if (CONFIG_CDROM_EMU) {
694         if (regs->ah == 0x4b) {
695             cdemu_134b(regs);
696             return;
697         }
698         u16 ebda_seg = get_ebda_seg();
699         if (GET_EBDA2(ebda_seg, cdemu.active)) {
700             u8 emudrive = GET_EBDA2(ebda_seg, cdemu.emulated_drive);
701             if (drive == emudrive) {
702                 cdemu_13(regs);
703                 return;
704             }
705             if (drive < 0xe0 && ((emudrive ^ drive) & 0x80) == 0)
706                 drive--;
707         }
708     }
709     handle_legacy_disk(regs, drive);
710 }
711
712 // record completion in BIOS task complete flag
713 void VISIBLE16
714 handle_76()
715 {
716     debug_isr(DEBUG_ISR_76);
717     SET_BDA(disk_interrupt_flag, 0xff);
718     eoi_pic2();
719 }
720
721 // Old Fixed Disk Parameter Table (newer tables are in the ebda).
722 struct fdpt_s OldFDPT VAR16FIXED(0xe401);