These changes are the raw update to qemu-2.6.
[kvmfornfv.git] / qemu / roms / seabios / 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 "biosvar.h" // SET_BDA
9 #include "bregs.h" // struct bregs
10 #include "config.h" // CONFIG_*
11 #include "hw/ata.h" // ATA_CB_DC
12 #include "hw/pic.h" // pic_eoi2
13 #include "output.h" // debug_enter
14 #include "stacks.h" // call16_int
15 #include "std/disk.h" // DISK_RET_SUCCESS
16 #include "string.h" // memset
17 #include "util.h" // CDRom_locks
18
19
20 /****************************************************************
21  * Return status functions
22  ****************************************************************/
23
24 static void
25 __disk_ret(struct bregs *regs, u32 linecode, const char *fname)
26 {
27     u8 code = linecode;
28     if (regs->dl < EXTSTART_HD)
29         SET_BDA(floppy_last_status, code);
30     else
31         SET_BDA(disk_last_status, code);
32     if (code)
33         __set_code_invalid(regs, linecode, fname);
34     else
35         set_code_success(regs);
36 }
37
38 static void
39 __disk_ret_unimplemented(struct bregs *regs, u32 linecode, const char *fname)
40 {
41     u8 code = linecode;
42     if (regs->dl < EXTSTART_HD)
43         SET_BDA(floppy_last_status, code);
44     else
45         SET_BDA(disk_last_status, code);
46     __set_code_unimplemented(regs, linecode, fname);
47 }
48
49 static void
50 __disk_stub(struct bregs *regs, int lineno, const char *fname)
51 {
52     __warn_unimplemented(regs, lineno, fname);
53     __disk_ret(regs, DISK_RET_SUCCESS | (lineno << 8), fname);
54 }
55
56 #define disk_ret(regs, code) \
57     __disk_ret((regs), (code) | (__LINE__ << 8), __func__)
58 #define disk_ret_unimplemented(regs, code) \
59     __disk_ret_unimplemented((regs), (code) | (__LINE__ << 8), __func__)
60 #define DISK_STUB(regs)                         \
61     __disk_stub((regs), __LINE__, __func__)
62
63
64 /****************************************************************
65  * Helper functions
66  ****************************************************************/
67
68 // Get the cylinders/heads/sectors for the given drive.
69 static struct chs_s
70 getLCHS(struct drive_s *drive_gf)
71 {
72     struct chs_s res = { };
73     if (CONFIG_CDROM_EMU && drive_gf == GET_GLOBAL(cdemu_drive_gf)) {
74         // Emulated drive - get info from CDEmu.  (It's not possible to
75         // populate the geometry directly in the driveid because the
76         // geometry is only known after the bios segment is made
77         // read-only).
78         u8 sptcyl = GET_LOW(CDEmu.chs.sptcyl);
79         res.cylinder = GET_LOW(CDEmu.chs.cyllow) + ((sptcyl << 2) & 0x300) + 1;
80         res.head = GET_LOW(CDEmu.chs.heads) + 1;
81         res.sector = sptcyl & 0x3f;
82         return res;
83     }
84     res.cylinder = GET_GLOBALFLAT(drive_gf->lchs.cylinder);
85     res.head = GET_GLOBALFLAT(drive_gf->lchs.head);
86     res.sector = GET_GLOBALFLAT(drive_gf->lchs.sector);
87     return res;
88 }
89
90 // Perform read/write/verify using old-style chs accesses
91 static void noinline
92 basic_access(struct bregs *regs, struct drive_s *drive_gf, u16 command)
93 {
94     struct disk_op_s dop;
95     dop.drive_gf = drive_gf;
96     dop.command = command;
97
98     u8 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 (count > 128 || count == 0 || sector == 0) {
104         warn_invalid(regs);
105         disk_ret(regs, DISK_RET_EPARAM);
106         return;
107     }
108     dop.count = count;
109
110     struct chs_s chs = getLCHS(drive_gf);
111     u16 nlc=chs.cylinder, nlh=chs.head, nls=chs.sector;
112
113     // sanity check on cyl heads, sec
114     if (cylinder >= nlc || head >= nlh || sector > nls) {
115         warn_invalid(regs);
116         disk_ret(regs, DISK_RET_EPARAM);
117         return;
118     }
119
120     // translate lchs to lba
121     dop.lba = (((((u32)cylinder * (u32)nlh) + (u32)head) * (u32)nls)
122                + (u32)sector - 1);
123
124     dop.buf_fl = MAKE_FLATPTR(regs->es, regs->bx);
125
126     int status = send_disk_op(&dop);
127
128     regs->al = dop.count;
129
130     disk_ret(regs, status);
131 }
132
133 // Perform read/write/verify using new-style "int13ext" accesses.
134 static void noinline
135 extended_access(struct bregs *regs, struct drive_s *drive_gf, u16 command)
136 {
137     struct disk_op_s dop;
138     struct int13ext_s *param_far = (struct int13ext_s*)(regs->si+0);
139     // Get lba and check.
140     dop.lba = GET_FARVAR(regs->ds, param_far->lba);
141     dop.command = command;
142     dop.drive_gf = drive_gf;
143     if (dop.lba >= GET_GLOBALFLAT(drive_gf->sectors)) {
144         warn_invalid(regs);
145         disk_ret(regs, DISK_RET_EPARAM);
146         return;
147     }
148
149     dop.buf_fl = SEGOFF_TO_FLATPTR(GET_FARVAR(regs->ds, param_far->data));
150     dop.count = GET_FARVAR(regs->ds, param_far->count);
151     if (! dop.count) {
152         // Nothing to do.
153         disk_ret(regs, DISK_RET_SUCCESS);
154         return;
155     }
156
157     int status = send_disk_op(&dop);
158
159     SET_FARVAR(regs->ds, param_far->count, dop.count);
160
161     disk_ret(regs, status);
162 }
163
164
165 /****************************************************************
166  * Hard Drive functions
167  ****************************************************************/
168
169 // disk controller reset
170 static void
171 disk_1300(struct bregs *regs, struct drive_s *drive_gf)
172 {
173     struct disk_op_s dop;
174     dop.drive_gf = drive_gf;
175     dop.command = CMD_RESET;
176     dop.count = 0;
177     int status = send_disk_op(&dop);
178     disk_ret(regs, status);
179 }
180
181 // read disk status
182 static void
183 disk_1301(struct bregs *regs, struct drive_s *drive_gf)
184 {
185     u8 v;
186     if (regs->dl < EXTSTART_HD)
187         // Floppy
188         v = GET_BDA(floppy_last_status);
189     else
190         v = GET_BDA(disk_last_status);
191     regs->ah = v;
192     set_cf(regs, v);
193     // XXX - clear disk_last_status?
194 }
195
196 // read disk sectors
197 static void
198 disk_1302(struct bregs *regs, struct drive_s *drive_gf)
199 {
200     basic_access(regs, drive_gf, CMD_READ);
201 }
202
203 // write disk sectors
204 static void
205 disk_1303(struct bregs *regs, struct drive_s *drive_gf)
206 {
207     basic_access(regs, drive_gf, CMD_WRITE);
208 }
209
210 // verify disk sectors
211 static void
212 disk_1304(struct bregs *regs, struct drive_s *drive_gf)
213 {
214     basic_access(regs, drive_gf, CMD_VERIFY);
215 }
216
217 // format disk track
218 static void noinline
219 disk_1305(struct bregs *regs, struct drive_s *drive_gf)
220 {
221     debug_stub(regs);
222
223     struct chs_s chs = getLCHS(drive_gf);
224     u16 nlc=chs.cylinder, nlh=chs.head, nls=chs.sector;
225
226     u8 count = regs->al;
227     u8 cylinder = regs->ch;
228     u8 head = regs->dh;
229
230     if (cylinder >= nlc || head >= nlh || count == 0 || count > nls) {
231         disk_ret(regs, DISK_RET_EPARAM);
232         return;
233     }
234
235     struct disk_op_s dop;
236     dop.drive_gf = drive_gf;
237     dop.command = CMD_FORMAT;
238     dop.lba = (((u32)cylinder * (u32)nlh) + (u32)head) * (u32)nls;
239     dop.count = count;
240     dop.buf_fl = MAKE_FLATPTR(regs->es, regs->bx);
241     int status = send_disk_op(&dop);
242     disk_ret(regs, status);
243 }
244
245 // read disk drive parameters
246 static void noinline
247 disk_1308(struct bregs *regs, struct drive_s *drive_gf)
248 {
249     // Get logical geometry from table
250     struct chs_s chs = getLCHS(drive_gf);
251     u16 nlc=chs.cylinder, nlh=chs.head, nls=chs.sector;
252     nlc--;
253     nlh--;
254     u8 count;
255     if (regs->dl < EXTSTART_HD) {
256         // Floppy
257         count = GET_GLOBAL(FloppyCount);
258
259         if (CONFIG_CDROM_EMU && drive_gf == GET_GLOBAL(cdemu_drive_gf))
260             regs->bx = GET_LOW(CDEmu.media) * 2;
261         else
262             regs->bx = GET_GLOBALFLAT(drive_gf->floppy_type);
263
264         // set es & di to point to 11 byte diskette param table in ROM
265         regs->es = SEG_BIOS;
266         regs->di = (u32)&diskette_param_table2;
267     } else if (regs->dl < EXTSTART_CD) {
268         // Hard drive
269         count = GET_BDA(hdcount);
270         nlc--;  // last sector reserved
271     } else {
272         // Not supported on CDROM
273         disk_ret(regs, DISK_RET_EPARAM);
274         return;
275     }
276
277     if (CONFIG_CDROM_EMU && GET_LOW(CDEmu.media)) {
278         u8 emudrive = GET_LOW(CDEmu.emulated_drive);
279         if (((emudrive ^ regs->dl) & 0x80) == 0)
280             // Note extra drive due to emulation.
281             count++;
282         if (regs->dl < EXTSTART_HD && count > 2)
283             // Max of two floppy drives.
284             count = 2;
285     }
286
287     regs->al = 0;
288     regs->ch = nlc & 0xff;
289     regs->cl = ((nlc >> 2) & 0xc0) | (nls & 0x3f);
290     regs->dh = nlh;
291
292     disk_ret(regs, DISK_RET_SUCCESS);
293     regs->dl = count;
294 }
295
296 // initialize drive parameters
297 static void
298 disk_1309(struct bregs *regs, struct drive_s *drive_gf)
299 {
300     DISK_STUB(regs);
301 }
302
303 // seek to specified cylinder
304 static void
305 disk_130c(struct bregs *regs, struct drive_s *drive_gf)
306 {
307     DISK_STUB(regs);
308 }
309
310 // alternate disk reset
311 static void
312 disk_130d(struct bregs *regs, struct drive_s *drive_gf)
313 {
314     DISK_STUB(regs);
315 }
316
317 // check drive ready
318 static void
319 disk_1310(struct bregs *regs, struct drive_s *drive_gf)
320 {
321     // should look at 40:8E also???
322
323     struct disk_op_s dop;
324     dop.drive_gf = drive_gf;
325     dop.command = CMD_ISREADY;
326     dop.count = 0;
327     int status = send_disk_op(&dop);
328     disk_ret(regs, status);
329 }
330
331 // recalibrate
332 static void
333 disk_1311(struct bregs *regs, struct drive_s *drive_gf)
334 {
335     DISK_STUB(regs);
336 }
337
338 // controller internal diagnostic
339 static void
340 disk_1314(struct bregs *regs, struct drive_s *drive_gf)
341 {
342     DISK_STUB(regs);
343 }
344
345 // read disk drive size
346 static void noinline
347 disk_1315(struct bregs *regs, struct drive_s *drive_gf)
348 {
349     disk_ret(regs, DISK_RET_SUCCESS);
350     if (regs->dl < EXTSTART_HD || regs->dl >= EXTSTART_CD) {
351         // Floppy or cdrom
352         regs->ah = 1;
353         return;
354     }
355     // Hard drive
356
357     // Get logical geometry from table
358     struct chs_s chs = getLCHS(drive_gf);
359     u16 nlc=chs.cylinder, nlh=chs.head, nls=chs.sector;
360
361     // Compute sector count seen by int13
362     u32 lba = (u32)(nlc - 1) * (u32)nlh * (u32)nls;
363     regs->cx = lba >> 16;
364     regs->dx = lba & 0xffff;
365     regs->ah = 3; // hard disk accessible
366 }
367
368 static void
369 disk_1316(struct bregs *regs, struct drive_s *drive_gf)
370 {
371     if (regs->dl >= EXTSTART_HD) {
372         // Hard drive
373         disk_ret(regs, DISK_RET_EPARAM);
374         return;
375     }
376     disk_ret(regs, DISK_RET_ECHANGED);
377 }
378
379 // IBM/MS installation check
380 static void
381 disk_1341(struct bregs *regs, struct drive_s *drive_gf)
382 {
383     regs->bx = 0xaa55;  // install check
384     regs->cx = 0x0007;  // ext disk access and edd, removable supported
385     disk_ret(regs, DISK_RET_SUCCESS);
386     regs->ah = 0x30;    // EDD 3.0
387 }
388
389 // IBM/MS extended read
390 static void
391 disk_1342(struct bregs *regs, struct drive_s *drive_gf)
392 {
393     extended_access(regs, drive_gf, CMD_READ);
394 }
395
396 // IBM/MS extended write
397 static void
398 disk_1343(struct bregs *regs, struct drive_s *drive_gf)
399 {
400     extended_access(regs, drive_gf, CMD_WRITE);
401 }
402
403 // IBM/MS verify
404 static void
405 disk_1344(struct bregs *regs, struct drive_s *drive_gf)
406 {
407     extended_access(regs, drive_gf, CMD_VERIFY);
408 }
409
410 // Locks for removable devices
411 u8 CDRom_locks[BUILD_MAX_EXTDRIVE] VARLOW;
412
413 // lock
414 static void
415 disk_134500(struct bregs *regs, struct drive_s *drive_gf)
416 {
417     int cdid = regs->dl - EXTSTART_CD;
418     u8 locks = GET_LOW(CDRom_locks[cdid]);
419     if (locks == 0xff) {
420         regs->al = 1;
421         disk_ret(regs, DISK_RET_ETOOMANYLOCKS);
422         return;
423     }
424     SET_LOW(CDRom_locks[cdid], locks + 1);
425     regs->al = 1;
426     disk_ret(regs, DISK_RET_SUCCESS);
427 }
428
429 // unlock
430 static void
431 disk_134501(struct bregs *regs, struct drive_s *drive_gf)
432 {
433     int cdid = regs->dl - EXTSTART_CD;
434     u8 locks = GET_LOW(CDRom_locks[cdid]);
435     if (locks == 0x00) {
436         regs->al = 0;
437         disk_ret(regs, DISK_RET_ENOTLOCKED);
438         return;
439     }
440     locks--;
441     SET_LOW(CDRom_locks[cdid], locks);
442     regs->al = (locks ? 1 : 0);
443     disk_ret(regs, DISK_RET_SUCCESS);
444 }
445
446 // status
447 static void
448 disk_134502(struct bregs *regs, struct drive_s *drive_gf)
449 {
450     int cdid = regs->dl - EXTSTART_CD;
451     u8 locks = GET_LOW(CDRom_locks[cdid]);
452     regs->al = (locks ? 1 : 0);
453     disk_ret(regs, DISK_RET_SUCCESS);
454 }
455
456 static void
457 disk_1345XX(struct bregs *regs, struct drive_s *drive_gf)
458 {
459     disk_ret_unimplemented(regs, DISK_RET_EPARAM);
460 }
461
462 // IBM/MS lock/unlock drive
463 static void
464 disk_1345(struct bregs *regs, struct drive_s *drive_gf)
465 {
466     if (regs->dl < EXTSTART_CD) {
467         // Always success for HD
468         disk_ret(regs, DISK_RET_SUCCESS);
469         return;
470     }
471
472     switch (regs->al) {
473     case 0x00: disk_134500(regs, drive_gf); break;
474     case 0x01: disk_134501(regs, drive_gf); break;
475     case 0x02: disk_134502(regs, drive_gf); break;
476     default:   disk_1345XX(regs, drive_gf); break;
477     }
478 }
479
480 // IBM/MS eject media
481 static void noinline
482 disk_1346(struct bregs *regs, struct drive_s *drive_gf)
483 {
484     if (regs->dl < EXTSTART_CD) {
485         // Volume Not Removable
486         disk_ret(regs, DISK_RET_ENOTREMOVABLE);
487         return;
488     }
489
490     int cdid = regs->dl - EXTSTART_CD;
491     u8 locks = GET_LOW(CDRom_locks[cdid]);
492     if (locks != 0) {
493         disk_ret(regs, DISK_RET_ELOCKED);
494         return;
495     }
496
497     // FIXME should handle 0x31 no media in device
498     // FIXME should handle 0xb5 valid request failed
499
500     // Call removable media eject
501     struct bregs br;
502     memset(&br, 0, sizeof(br));
503     br.ah = 0x52;
504     br.dl = regs->dl;
505     call16_int(0x15, &br);
506
507     if (br.ah || br.flags & F_CF) {
508         disk_ret(regs, DISK_RET_ELOCKED);
509         return;
510     }
511     disk_ret(regs, DISK_RET_SUCCESS);
512 }
513
514 // IBM/MS extended seek
515 static void
516 disk_1347(struct bregs *regs, struct drive_s *drive_gf)
517 {
518     extended_access(regs, drive_gf, CMD_SEEK);
519 }
520
521 // IBM/MS get drive parameters
522 static void
523 disk_1348(struct bregs *regs, struct drive_s *drive_gf)
524 {
525     int ret = fill_edd(SEGOFF(regs->ds, regs->si), drive_gf);
526     disk_ret(regs, ret);
527 }
528
529 // IBM/MS extended media change
530 static void
531 disk_1349(struct bregs *regs, struct drive_s *drive_gf)
532 {
533     if (regs->dl < EXTSTART_CD) {
534         // Always success for HD
535         disk_ret(regs, DISK_RET_SUCCESS);
536         return;
537     }
538     set_invalid(regs);
539     // always send changed ??
540     regs->ah = DISK_RET_ECHANGED;
541 }
542
543 static void
544 disk_134e01(struct bregs *regs, struct drive_s *drive_gf)
545 {
546     disk_ret(regs, DISK_RET_SUCCESS);
547 }
548
549 static void
550 disk_134e03(struct bregs *regs, struct drive_s *drive_gf)
551 {
552     disk_ret(regs, DISK_RET_SUCCESS);
553 }
554
555 static void
556 disk_134e04(struct bregs *regs, struct drive_s *drive_gf)
557 {
558     disk_ret(regs, DISK_RET_SUCCESS);
559 }
560
561 static void
562 disk_134e06(struct bregs *regs, struct drive_s *drive_gf)
563 {
564     disk_ret(regs, DISK_RET_SUCCESS);
565 }
566
567 static void
568 disk_134eXX(struct bregs *regs, struct drive_s *drive_gf)
569 {
570     disk_ret(regs, DISK_RET_EPARAM);
571 }
572
573 // IBM/MS set hardware configuration
574 static void
575 disk_134e(struct bregs *regs, struct drive_s *drive_gf)
576 {
577     switch (regs->al) {
578     case 0x01: disk_134e01(regs, drive_gf); break;
579     case 0x03: disk_134e03(regs, drive_gf); break;
580     case 0x04: disk_134e04(regs, drive_gf); break;
581     case 0x06: disk_134e06(regs, drive_gf); break;
582     default:   disk_134eXX(regs, drive_gf); break;
583     }
584 }
585
586 static void
587 disk_13XX(struct bregs *regs, struct drive_s *drive_gf)
588 {
589     disk_ret_unimplemented(regs, DISK_RET_EPARAM);
590 }
591
592 static void
593 disk_13(struct bregs *regs, struct drive_s *drive_gf)
594 {
595     //debug_stub(regs);
596
597     // clear completion flag
598     SET_BDA(disk_interrupt_flag, 0);
599
600     switch (regs->ah) {
601     case 0x00: disk_1300(regs, drive_gf); break;
602     case 0x01: disk_1301(regs, drive_gf); break;
603     case 0x02: disk_1302(regs, drive_gf); break;
604     case 0x03: disk_1303(regs, drive_gf); break;
605     case 0x04: disk_1304(regs, drive_gf); break;
606     case 0x05: disk_1305(regs, drive_gf); break;
607     case 0x08: disk_1308(regs, drive_gf); break;
608     case 0x09: disk_1309(regs, drive_gf); break;
609     case 0x0c: disk_130c(regs, drive_gf); break;
610     case 0x0d: disk_130d(regs, drive_gf); break;
611     case 0x10: disk_1310(regs, drive_gf); break;
612     case 0x11: disk_1311(regs, drive_gf); break;
613     case 0x14: disk_1314(regs, drive_gf); break;
614     case 0x15: disk_1315(regs, drive_gf); break;
615     case 0x16: disk_1316(regs, drive_gf); break;
616     case 0x41: disk_1341(regs, drive_gf); break;
617     case 0x42: disk_1342(regs, drive_gf); break;
618     case 0x43: disk_1343(regs, drive_gf); break;
619     case 0x44: disk_1344(regs, drive_gf); break;
620     case 0x45: disk_1345(regs, drive_gf); break;
621     case 0x46: disk_1346(regs, drive_gf); break;
622     case 0x47: disk_1347(regs, drive_gf); break;
623     case 0x48: disk_1348(regs, drive_gf); break;
624     case 0x49: disk_1349(regs, drive_gf); break;
625     case 0x4e: disk_134e(regs, drive_gf); break;
626     default:   disk_13XX(regs, drive_gf); break;
627     }
628 }
629
630 static void
631 floppy_13(struct bregs *regs, struct drive_s *drive_gf)
632 {
633     // Only limited commands are supported on floppies.
634     switch (regs->ah) {
635     case 0x00:
636     case 0x01:
637     case 0x02:
638     case 0x03:
639     case 0x04:
640     case 0x05:
641     case 0x08:
642     case 0x15:
643     case 0x16:
644         disk_13(regs, drive_gf);
645         break;
646     default:   disk_13XX(regs, drive_gf); break;
647     }
648 }
649
650 // ElTorito - Terminate disk emu
651 static void
652 cdemu_134b(struct bregs *regs)
653 {
654     memcpy_far(regs->ds, (void*)(regs->si+0), SEG_LOW, &CDEmu, sizeof(CDEmu));
655
656     // If we have to terminate emulation
657     if (regs->al == 0x00) {
658         // FIXME ElTorito Various. Should be handled accordingly to spec
659         SET_LOW(CDEmu.media, 0x00); // bye bye
660
661         // XXX - update floppy/hd count.
662     }
663
664     disk_ret(regs, DISK_RET_SUCCESS);
665 }
666
667
668 /****************************************************************
669  * Entry points
670  ****************************************************************/
671
672 static void
673 handle_legacy_disk(struct bregs *regs, u8 extdrive)
674 {
675     if (! CONFIG_DRIVES) {
676         // XXX - support handle_1301 anyway?
677         disk_ret(regs, DISK_RET_EPARAM);
678         return;
679     }
680
681     if (extdrive < EXTSTART_HD) {
682         struct drive_s *drive_gf = getDrive(EXTTYPE_FLOPPY, extdrive);
683         if (!drive_gf)
684             goto fail;
685         floppy_13(regs, drive_gf);
686         return;
687     }
688
689     struct drive_s *drive_gf;
690     if (extdrive >= EXTSTART_CD)
691         drive_gf = getDrive(EXTTYPE_CD, extdrive - EXTSTART_CD);
692     else
693         drive_gf = getDrive(EXTTYPE_HD, extdrive - EXTSTART_HD);
694     if (!drive_gf)
695         goto fail;
696     disk_13(regs, drive_gf);
697     return;
698
699 fail:
700     // XXX - support 1301/1308/1315 anyway?
701     disk_ret(regs, DISK_RET_EPARAM);
702 }
703
704 void VISIBLE16
705 handle_40(struct bregs *regs)
706 {
707     debug_enter(regs, DEBUG_HDL_40);
708     handle_legacy_disk(regs, regs->dl);
709 }
710
711 // INT 13h Fixed Disk Services Entry Point
712 void VISIBLE16
713 handle_13(struct bregs *regs)
714 {
715     debug_enter(regs, DEBUG_HDL_13);
716     u8 extdrive = regs->dl;
717
718     if (CONFIG_CDROM_EMU) {
719         if (regs->ah == 0x4b) {
720             cdemu_134b(regs);
721             return;
722         }
723         if (GET_LOW(CDEmu.media)) {
724             u8 emudrive = GET_LOW(CDEmu.emulated_drive);
725             if (extdrive == emudrive) {
726                 // Access to an emulated drive.
727                 struct drive_s *cdemu_gf = GET_GLOBAL(cdemu_drive_gf);
728                 if (regs->ah > 0x16) {
729                     // Only old-style commands supported.
730                     disk_13XX(regs, cdemu_gf);
731                     return;
732                 }
733                 disk_13(regs, cdemu_gf);
734                 return;
735             }
736             if (extdrive < EXTSTART_CD && ((emudrive ^ extdrive) & 0x80) == 0)
737                 // Adjust id to make room for emulated drive.
738                 extdrive--;
739         }
740     }
741     handle_legacy_disk(regs, extdrive);
742 }
743
744 // record completion in BIOS task complete flag
745 void VISIBLE16
746 handle_76(void)
747 {
748     debug_isr(DEBUG_ISR_76);
749     SET_BDA(disk_interrupt_flag, 0xff);
750     pic_eoi2();
751 }