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