blob: fe2e2c3165d7e8c2c05c3ac1aaab3f89eb9e5370 [file] [log] [blame]
Kevin O'Connorf076a3e2008-02-25 22:25:15 -05001// 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//
Kevin O'Connorb1b7c2a2009-01-15 20:52:58 -05006// This file may be distributed under the terms of the GNU LGPLv3 license.
Kevin O'Connorf076a3e2008-02-25 22:25:15 -05007
Kevin O'Connor9521e262008-07-04 13:04:29 -04008#include "biosvar.h" // SET_BDA
Kevin O'Connor9521e262008-07-04 13:04:29 -04009#include "bregs.h" // struct bregs
Kevin O'Connor2d2fa312013-09-14 21:55:26 -040010#include "config.h" // CONFIG_*
Kevin O'Connor5d369d82013-09-02 20:48:46 -040011#include "hw/ata.h" // ATA_CB_DC
Kevin O'Connor2d2fa312013-09-14 21:55:26 -040012#include "hw/pic.h" // pic_eoi2
13#include "output.h" // debug_enter
Kevin O'Connor3df600b2013-09-14 19:28:55 -040014#include "stacks.h" // call16_int
Kevin O'Connor135f3f62013-09-14 23:57:26 -040015#include "std/disk.h" // DISK_RET_SUCCESS
Kevin O'Connorfa9c66a2013-09-14 19:10:40 -040016#include "string.h" // memset
Kevin O'Connor135f3f62013-09-14 23:57:26 -040017#include "util.h" // CDRom_locks
Kevin O'Connor3491e8b2008-02-29 00:22:27 -050018
Kevin O'Connorb74102d2008-03-03 21:57:30 -050019
20/****************************************************************
Kevin O'Connorc029a912014-05-10 15:51:40 -040021 * Return status functions
Kevin O'Connorb74102d2008-03-03 21:57:30 -050022 ****************************************************************/
23
Kevin O'Connor567e4e32008-04-05 11:37:51 -040024static void
Kevin O'Connorc029a912014-05-10 15:51:40 -040025__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
38static 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
49static void
Kevin O'Connor05600342009-01-02 13:10:58 -050050__disk_stub(struct bregs *regs, int lineno, const char *fname)
Kevin O'Connor567e4e32008-04-05 11:37:51 -040051{
Kevin O'Connordfefeb52009-12-13 13:04:17 -050052 __warn_unimplemented(regs, lineno, fname);
Kevin O'Connor05600342009-01-02 13:10:58 -050053 __disk_ret(regs, DISK_RET_SUCCESS | (lineno << 8), fname);
Kevin O'Connor567e4e32008-04-05 11:37:51 -040054}
55
Kevin O'Connorc029a912014-05-10 15:51:40 -040056#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__)
Kevin O'Connor05600342009-01-02 13:10:58 -050060#define DISK_STUB(regs) \
61 __disk_stub((regs), __LINE__, __func__)
Kevin O'Connore43df9e2008-03-01 22:16:32 -050062
Kevin O'Connorc029a912014-05-10 15:51:40 -040063
64/****************************************************************
65 * Helper functions
66 ****************************************************************/
67
Kevin O'Connor5c99b6c2009-12-30 12:36:22 -050068// Get the cylinders/heads/sectors for the given drive.
Kevin O'Connor48365582012-05-27 10:45:32 -040069static struct chs_s
Kevin O'Connor1902c942013-10-26 11:48:06 -040070getLCHS(struct drive_s *drive_gf)
Kevin O'Connore43df9e2008-03-01 22:16:32 -050071{
Kevin O'Connor48365582012-05-27 10:45:32 -040072 struct chs_s res = { };
Kevin O'Connor1902c942013-10-26 11:48:06 -040073 if (CONFIG_CDROM_EMU && drive_gf == GET_GLOBAL(cdemu_drive_gf)) {
Kevin O'Connord3140832012-05-13 22:46:12 -040074 // Emulated drive - get info from CDEmu. (It's not possible to
Kevin O'Connor36c93a52009-09-12 19:35:04 -040075 // populate the geometry directly in the driveid because the
76 // geometry is only known after the bios segment is made
77 // read-only).
Kevin O'Connor02f76762014-05-10 01:20:46 -040078 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;
Kevin O'Connor48365582012-05-27 10:45:32 -040082 return res;
Kevin O'Connor0cdac0e2008-03-29 12:45:53 -040083 }
Kevin O'Connor1902c942013-10-26 11:48:06 -040084 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);
Kevin O'Connor48365582012-05-27 10:45:32 -040087 return res;
Kevin O'Connor1625a752009-08-09 13:08:21 -040088}
89
90// Perform read/write/verify using old-style chs accesses
Kevin O'Connorecf9b7d2012-03-25 10:21:27 -040091static void noinline
Kevin O'Connor1902c942013-10-26 11:48:06 -040092basic_access(struct bregs *regs, struct drive_s *drive_gf, u16 command)
Kevin O'Connor1625a752009-08-09 13:08:21 -040093{
94 struct disk_op_s dop;
Kevin O'Connor1902c942013-10-26 11:48:06 -040095 dop.drive_gf = drive_gf;
Kevin O'Connor1625a752009-08-09 13:08:21 -040096 dop.command = command;
Kevin O'Connor36c93a52009-09-12 19:35:04 -040097
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) {
Kevin O'Connorcfdc13f2010-02-14 13:07:54 -0500104 warn_invalid(regs);
Kevin O'Connor36c93a52009-09-12 19:35:04 -0400105 disk_ret(regs, DISK_RET_EPARAM);
Kevin O'Connor1625a752009-08-09 13:08:21 -0400106 return;
Kevin O'Connor36c93a52009-09-12 19:35:04 -0400107 }
108 dop.count = count;
109
Kevin O'Connor1902c942013-10-26 11:48:06 -0400110 struct chs_s chs = getLCHS(drive_gf);
Kevin O'Connor8ab9a342013-09-28 23:34:49 -0400111 u16 nlc=chs.cylinder, nlh=chs.head, nls=chs.sector;
Kevin O'Connor36c93a52009-09-12 19:35:04 -0400112
113 // sanity check on cyl heads, sec
Kevin O'Connor8ab9a342013-09-28 23:34:49 -0400114 if (cylinder >= nlc || head >= nlh || sector > nls) {
Kevin O'Connorcfdc13f2010-02-14 13:07:54 -0500115 warn_invalid(regs);
Kevin O'Connor36c93a52009-09-12 19:35:04 -0400116 disk_ret(regs, DISK_RET_EPARAM);
117 return;
118 }
119
120 // translate lchs to lba
Kevin O'Connor8ab9a342013-09-28 23:34:49 -0400121 dop.lba = (((((u32)cylinder * (u32)nlh) + (u32)head) * (u32)nls)
Kevin O'Connor36c93a52009-09-12 19:35:04 -0400122 + (u32)sector - 1);
123
Kevin O'Connorb68ac712009-08-09 17:25:19 -0400124 dop.buf_fl = MAKE_FLATPTR(regs->es, regs->bx);
Kevin O'Connoraa2590c2008-03-22 23:13:24 -0400125
Kevin O'Connor4524bf72008-12-31 00:31:03 -0500126 int status = send_disk_op(&dop);
Kevin O'Connor74799df2008-03-12 20:49:07 -0400127
Kevin O'Connor1625a752009-08-09 13:08:21 -0400128 regs->al = dop.count;
Kevin O'Connore43df9e2008-03-01 22:16:32 -0500129
Kevin O'Connor126eac62009-08-16 13:32:24 -0400130 disk_ret(regs, status);
Kevin O'Connor941d3e42008-03-04 19:45:04 -0500131}
132
Kevin O'Connor1625a752009-08-09 13:08:21 -0400133// Perform read/write/verify using new-style "int13ext" accesses.
Kevin O'Connorecf9b7d2012-03-25 10:21:27 -0400134static void noinline
Kevin O'Connor1902c942013-10-26 11:48:06 -0400135extended_access(struct bregs *regs, struct drive_s *drive_gf, u16 command)
Kevin O'Connore43df9e2008-03-01 22:16:32 -0500136{
Kevin O'Connor4524bf72008-12-31 00:31:03 -0500137 struct disk_op_s dop;
Kevin O'Connorcd8dcbe2012-05-24 22:52:39 -0400138 struct int13ext_s *param_far = (struct int13ext_s*)(regs->si+0);
Kevin O'Connor1bb3b5c2008-05-14 00:43:13 -0400139 // Get lba and check.
Kevin O'Connorcd8dcbe2012-05-24 22:52:39 -0400140 dop.lba = GET_FARVAR(regs->ds, param_far->lba);
Kevin O'Connor4524bf72008-12-31 00:31:03 -0500141 dop.command = command;
Kevin O'Connor1902c942013-10-26 11:48:06 -0400142 dop.drive_gf = drive_gf;
143 if (dop.lba >= GET_GLOBALFLAT(drive_gf->sectors)) {
Kevin O'Connorcfdc13f2010-02-14 13:07:54 -0500144 warn_invalid(regs);
Kevin O'Connor3f6c2782009-08-09 19:17:11 -0400145 disk_ret(regs, DISK_RET_EPARAM);
146 return;
Kevin O'Connore43df9e2008-03-01 22:16:32 -0500147 }
148
Kevin O'Connorcd8dcbe2012-05-24 22:52:39 -0400149 dop.buf_fl = SEGOFF_TO_FLATPTR(GET_FARVAR(regs->ds, param_far->data));
150 dop.count = GET_FARVAR(regs->ds, param_far->count);
Kevin O'Connorb50488b2012-02-11 09:38:44 -0500151 if (! dop.count) {
152 // Nothing to do.
153 disk_ret(regs, DISK_RET_SUCCESS);
154 return;
155 }
Kevin O'Connoraa2590c2008-03-22 23:13:24 -0400156
Kevin O'Connor4524bf72008-12-31 00:31:03 -0500157 int status = send_disk_op(&dop);
Kevin O'Connor74799df2008-03-12 20:49:07 -0400158
Kevin O'Connorcd8dcbe2012-05-24 22:52:39 -0400159 SET_FARVAR(regs->ds, param_far->count, dop.count);
Kevin O'Connore43df9e2008-03-01 22:16:32 -0500160
Kevin O'Connor126eac62009-08-16 13:32:24 -0400161 disk_ret(regs, status);
Kevin O'Connore43df9e2008-03-01 22:16:32 -0500162}
163
Kevin O'Connorb74102d2008-03-03 21:57:30 -0500164
165/****************************************************************
166 * Hard Drive functions
167 ****************************************************************/
168
Kevin O'Connor3491e8b2008-02-29 00:22:27 -0500169// disk controller reset
170static void
Kevin O'Connor1902c942013-10-26 11:48:06 -0400171disk_1300(struct bregs *regs, struct drive_s *drive_gf)
Kevin O'Connor3491e8b2008-02-29 00:22:27 -0500172{
Kevin O'Connor3f6c2782009-08-09 19:17:11 -0400173 struct disk_op_s dop;
Kevin O'Connor1902c942013-10-26 11:48:06 -0400174 dop.drive_gf = drive_gf;
Kevin O'Connor3f6c2782009-08-09 19:17:11 -0400175 dop.command = CMD_RESET;
Kevin O'Connor126eac62009-08-16 13:32:24 -0400176 int status = send_disk_op(&dop);
177 disk_ret(regs, status);
Kevin O'Connor3491e8b2008-02-29 00:22:27 -0500178}
179
180// read disk status
181static void
Kevin O'Connor1902c942013-10-26 11:48:06 -0400182disk_1301(struct bregs *regs, struct drive_s *drive_gf)
Kevin O'Connor3491e8b2008-02-29 00:22:27 -0500183{
Kevin O'Connor48410fd2009-08-16 14:13:36 -0400184 u8 v;
Kevin O'Connor51cfbe72009-08-18 22:38:49 -0400185 if (regs->dl < EXTSTART_HD)
Kevin O'Connor48410fd2009-08-16 14:13:36 -0400186 // Floppy
187 v = GET_BDA(floppy_last_status);
188 else
189 v = GET_BDA(disk_last_status);
Kevin O'Connorfad2da82008-03-22 20:37:44 -0400190 regs->ah = v;
191 set_cf(regs, v);
192 // XXX - clear disk_last_status?
Kevin O'Connor3491e8b2008-02-29 00:22:27 -0500193}
194
Kevin O'Connore43df9e2008-03-01 22:16:32 -0500195// read disk sectors
Kevin O'Connor3491e8b2008-02-29 00:22:27 -0500196static void
Kevin O'Connor1902c942013-10-26 11:48:06 -0400197disk_1302(struct bregs *regs, struct drive_s *drive_gf)
Kevin O'Connor3491e8b2008-02-29 00:22:27 -0500198{
Kevin O'Connor1902c942013-10-26 11:48:06 -0400199 basic_access(regs, drive_gf, CMD_READ);
Kevin O'Connor3491e8b2008-02-29 00:22:27 -0500200}
201
Kevin O'Connore43df9e2008-03-01 22:16:32 -0500202// write disk sectors
Kevin O'Connor3491e8b2008-02-29 00:22:27 -0500203static void
Kevin O'Connor1902c942013-10-26 11:48:06 -0400204disk_1303(struct bregs *regs, struct drive_s *drive_gf)
Kevin O'Connor3491e8b2008-02-29 00:22:27 -0500205{
Kevin O'Connor1902c942013-10-26 11:48:06 -0400206 basic_access(regs, drive_gf, CMD_WRITE);
Kevin O'Connor3491e8b2008-02-29 00:22:27 -0500207}
208
Kevin O'Connore43df9e2008-03-01 22:16:32 -0500209// verify disk sectors
Kevin O'Connor3491e8b2008-02-29 00:22:27 -0500210static void
Kevin O'Connor1902c942013-10-26 11:48:06 -0400211disk_1304(struct bregs *regs, struct drive_s *drive_gf)
Kevin O'Connor3491e8b2008-02-29 00:22:27 -0500212{
Kevin O'Connor1902c942013-10-26 11:48:06 -0400213 basic_access(regs, drive_gf, CMD_VERIFY);
Kevin O'Connor3491e8b2008-02-29 00:22:27 -0500214}
215
Kevin O'Connor3491e8b2008-02-29 00:22:27 -0500216// format disk track
Kevin O'Connorecf9b7d2012-03-25 10:21:27 -0400217static void noinline
Kevin O'Connor1902c942013-10-26 11:48:06 -0400218disk_1305(struct bregs *regs, struct drive_s *drive_gf)
Kevin O'Connor3491e8b2008-02-29 00:22:27 -0500219{
Kevin O'Connor4d9d4002009-11-25 19:35:01 -0500220 debug_stub(regs);
Kevin O'Connoraf5aabb2009-08-16 18:48:38 -0400221
Kevin O'Connor1902c942013-10-26 11:48:06 -0400222 struct chs_s chs = getLCHS(drive_gf);
Kevin O'Connorb84899e2013-12-11 19:15:45 -0500223 u16 nlc=chs.cylinder, nlh=chs.head, nls=chs.sector;
Kevin O'Connoraf5aabb2009-08-16 18:48:38 -0400224
Kevin O'Connorb84899e2013-12-11 19:15:45 -0500225 u8 count = regs->al;
226 u8 cylinder = regs->ch;
227 u8 head = regs->dh;
Kevin O'Connoraf5aabb2009-08-16 18:48:38 -0400228
Kevin O'Connorb84899e2013-12-11 19:15:45 -0500229 if (cylinder >= nlc || head >= nlh || count == 0 || count > nls) {
Kevin O'Connoraf5aabb2009-08-16 18:48:38 -0400230 disk_ret(regs, DISK_RET_EPARAM);
231 return;
232 }
233
234 struct disk_op_s dop;
Kevin O'Connor1902c942013-10-26 11:48:06 -0400235 dop.drive_gf = drive_gf;
Kevin O'Connoraf5aabb2009-08-16 18:48:38 -0400236 dop.command = CMD_FORMAT;
Kevin O'Connorb84899e2013-12-11 19:15:45 -0500237 dop.lba = (((u32)cylinder * (u32)nlh) + (u32)head) * (u32)nls;
238 dop.count = count;
Kevin O'Connoraf5aabb2009-08-16 18:48:38 -0400239 dop.buf_fl = MAKE_FLATPTR(regs->es, regs->bx);
240 int status = send_disk_op(&dop);
241 disk_ret(regs, status);
Kevin O'Connor3491e8b2008-02-29 00:22:27 -0500242}
243
244// read disk drive parameters
Kevin O'Connorecf9b7d2012-03-25 10:21:27 -0400245static void noinline
Kevin O'Connor1902c942013-10-26 11:48:06 -0400246disk_1308(struct bregs *regs, struct drive_s *drive_gf)
Kevin O'Connor3491e8b2008-02-29 00:22:27 -0500247{
248 // Get logical geometry from table
Kevin O'Connor1902c942013-10-26 11:48:06 -0400249 struct chs_s chs = getLCHS(drive_gf);
Kevin O'Connor8ab9a342013-09-28 23:34:49 -0400250 u16 nlc=chs.cylinder, nlh=chs.head, nls=chs.sector;
Kevin O'Connor36c93a52009-09-12 19:35:04 -0400251 nlc--;
252 nlh--;
Kevin O'Connor48410fd2009-08-16 14:13:36 -0400253 u8 count;
Kevin O'Connor51cfbe72009-08-18 22:38:49 -0400254 if (regs->dl < EXTSTART_HD) {
Kevin O'Connor48410fd2009-08-16 14:13:36 -0400255 // Floppy
Kevin O'Connora0842f82010-12-29 11:05:46 -0500256 count = GET_GLOBAL(FloppyCount);
Kevin O'Connor3491e8b2008-02-29 00:22:27 -0500257
Kevin O'Connor1902c942013-10-26 11:48:06 -0400258 if (CONFIG_CDROM_EMU && drive_gf == GET_GLOBAL(cdemu_drive_gf))
Kevin O'Connord3140832012-05-13 22:46:12 -0400259 regs->bx = GET_LOW(CDEmu.media) * 2;
Kevin O'Connor36c93a52009-09-12 19:35:04 -0400260 else
Kevin O'Connor1902c942013-10-26 11:48:06 -0400261 regs->bx = GET_GLOBALFLAT(drive_gf->floppy_type);
Kevin O'Connor48410fd2009-08-16 14:13:36 -0400262
263 // set es & di to point to 11 byte diskette param table in ROM
264 regs->es = SEG_BIOS;
265 regs->di = (u32)&diskette_param_table2;
Kevin O'Connor51cfbe72009-08-18 22:38:49 -0400266 } else if (regs->dl < EXTSTART_CD) {
Kevin O'Connor48410fd2009-08-16 14:13:36 -0400267 // Hard drive
268 count = GET_BDA(hdcount);
269 nlc--; // last sector reserved
Kevin O'Connor51cfbe72009-08-18 22:38:49 -0400270 } else {
271 // Not supported on CDROM
272 disk_ret(regs, DISK_RET_EPARAM);
273 return;
Kevin O'Connor48410fd2009-08-16 14:13:36 -0400274 }
275
Kevin O'Connor02f76762014-05-10 01:20:46 -0400276 if (CONFIG_CDROM_EMU && GET_LOW(CDEmu.media)) {
277 u8 emudrive = GET_LOW(CDEmu.emulated_drive);
Kevin O'Connor36c93a52009-09-12 19:35:04 -0400278 if (((emudrive ^ regs->dl) & 0x80) == 0)
279 // Note extra drive due to emulation.
280 count++;
281 if (regs->dl < EXTSTART_HD && count > 2)
282 // Max of two floppy drives.
283 count = 2;
284 }
285
Kevin O'Connor3491e8b2008-02-29 00:22:27 -0500286 regs->al = 0;
287 regs->ch = nlc & 0xff;
Kevin O'Connor8ab9a342013-09-28 23:34:49 -0400288 regs->cl = ((nlc >> 2) & 0xc0) | (nls & 0x3f);
Kevin O'Connor48410fd2009-08-16 14:13:36 -0400289 regs->dh = nlh;
Kevin O'Connor3491e8b2008-02-29 00:22:27 -0500290
Kevin O'Connor3491e8b2008-02-29 00:22:27 -0500291 disk_ret(regs, DISK_RET_SUCCESS);
Kevin O'Connor48410fd2009-08-16 14:13:36 -0400292 regs->dl = count;
Kevin O'Connor3491e8b2008-02-29 00:22:27 -0500293}
294
Kevin O'Connore43df9e2008-03-01 22:16:32 -0500295// initialize drive parameters
296static void
Kevin O'Connor1902c942013-10-26 11:48:06 -0400297disk_1309(struct bregs *regs, struct drive_s *drive_gf)
Kevin O'Connore43df9e2008-03-01 22:16:32 -0500298{
299 DISK_STUB(regs);
300}
301
302// seek to specified cylinder
303static void
Kevin O'Connor1902c942013-10-26 11:48:06 -0400304disk_130c(struct bregs *regs, struct drive_s *drive_gf)
Kevin O'Connore43df9e2008-03-01 22:16:32 -0500305{
306 DISK_STUB(regs);
307}
308
309// alternate disk reset
310static void
Kevin O'Connor1902c942013-10-26 11:48:06 -0400311disk_130d(struct bregs *regs, struct drive_s *drive_gf)
Kevin O'Connore43df9e2008-03-01 22:16:32 -0500312{
313 DISK_STUB(regs);
314}
315
Kevin O'Connor3491e8b2008-02-29 00:22:27 -0500316// check drive ready
317static void
Kevin O'Connor1902c942013-10-26 11:48:06 -0400318disk_1310(struct bregs *regs, struct drive_s *drive_gf)
Kevin O'Connor3491e8b2008-02-29 00:22:27 -0500319{
320 // should look at 40:8E also???
321
Kevin O'Connor42337662009-08-10 00:06:37 -0400322 struct disk_op_s dop;
Kevin O'Connor1902c942013-10-26 11:48:06 -0400323 dop.drive_gf = drive_gf;
Kevin O'Connor42337662009-08-10 00:06:37 -0400324 dop.command = CMD_ISREADY;
325 int status = send_disk_op(&dop);
Kevin O'Connor126eac62009-08-16 13:32:24 -0400326 disk_ret(regs, status);
Kevin O'Connor3491e8b2008-02-29 00:22:27 -0500327}
328
Kevin O'Connore43df9e2008-03-01 22:16:32 -0500329// recalibrate
330static void
Kevin O'Connor1902c942013-10-26 11:48:06 -0400331disk_1311(struct bregs *regs, struct drive_s *drive_gf)
Kevin O'Connore43df9e2008-03-01 22:16:32 -0500332{
333 DISK_STUB(regs);
334}
335
336// controller internal diagnostic
337static void
Kevin O'Connor1902c942013-10-26 11:48:06 -0400338disk_1314(struct bregs *regs, struct drive_s *drive_gf)
Kevin O'Connore43df9e2008-03-01 22:16:32 -0500339{
340 DISK_STUB(regs);
341}
342
Kevin O'Connor3491e8b2008-02-29 00:22:27 -0500343// read disk drive size
Kevin O'Connorecf9b7d2012-03-25 10:21:27 -0400344static void noinline
Kevin O'Connor1902c942013-10-26 11:48:06 -0400345disk_1315(struct bregs *regs, struct drive_s *drive_gf)
Kevin O'Connor3491e8b2008-02-29 00:22:27 -0500346{
Kevin O'Connor48410fd2009-08-16 14:13:36 -0400347 disk_ret(regs, DISK_RET_SUCCESS);
Kevin O'Connor51cfbe72009-08-18 22:38:49 -0400348 if (regs->dl < EXTSTART_HD || regs->dl >= EXTSTART_CD) {
349 // Floppy or cdrom
Kevin O'Connor48410fd2009-08-16 14:13:36 -0400350 regs->ah = 1;
351 return;
352 }
353 // Hard drive
354
Kevin O'Connor3491e8b2008-02-29 00:22:27 -0500355 // Get logical geometry from table
Kevin O'Connor1902c942013-10-26 11:48:06 -0400356 struct chs_s chs = getLCHS(drive_gf);
Kevin O'Connor8ab9a342013-09-28 23:34:49 -0400357 u16 nlc=chs.cylinder, nlh=chs.head, nls=chs.sector;
Kevin O'Connor3491e8b2008-02-29 00:22:27 -0500358
359 // Compute sector count seen by int13
Kevin O'Connor8ab9a342013-09-28 23:34:49 -0400360 u32 lba = (u32)(nlc - 1) * (u32)nlh * (u32)nls;
Kevin O'Connor3491e8b2008-02-29 00:22:27 -0500361 regs->cx = lba >> 16;
362 regs->dx = lba & 0xffff;
Kevin O'Connor3491e8b2008-02-29 00:22:27 -0500363 regs->ah = 3; // hard disk accessible
364}
365
Kevin O'Connor48410fd2009-08-16 14:13:36 -0400366static void
Kevin O'Connor1902c942013-10-26 11:48:06 -0400367disk_1316(struct bregs *regs, struct drive_s *drive_gf)
Kevin O'Connor48410fd2009-08-16 14:13:36 -0400368{
Kevin O'Connor51cfbe72009-08-18 22:38:49 -0400369 if (regs->dl >= EXTSTART_HD) {
Kevin O'Connor48410fd2009-08-16 14:13:36 -0400370 // Hard drive
371 disk_ret(regs, DISK_RET_EPARAM);
372 return;
373 }
374 disk_ret(regs, DISK_RET_ECHANGED);
375}
376
Kevin O'Connore43df9e2008-03-01 22:16:32 -0500377// IBM/MS installation check
378static void
Kevin O'Connor1902c942013-10-26 11:48:06 -0400379disk_1341(struct bregs *regs, struct drive_s *drive_gf)
Kevin O'Connore43df9e2008-03-01 22:16:32 -0500380{
381 regs->bx = 0xaa55; // install check
382 regs->cx = 0x0007; // ext disk access and edd, removable supported
383 disk_ret(regs, DISK_RET_SUCCESS);
384 regs->ah = 0x30; // EDD 3.0
385}
386
387// IBM/MS extended read
388static void
Kevin O'Connor1902c942013-10-26 11:48:06 -0400389disk_1342(struct bregs *regs, struct drive_s *drive_gf)
Kevin O'Connore43df9e2008-03-01 22:16:32 -0500390{
Kevin O'Connor1902c942013-10-26 11:48:06 -0400391 extended_access(regs, drive_gf, CMD_READ);
Kevin O'Connore43df9e2008-03-01 22:16:32 -0500392}
393
394// IBM/MS extended write
395static void
Kevin O'Connor1902c942013-10-26 11:48:06 -0400396disk_1343(struct bregs *regs, struct drive_s *drive_gf)
Kevin O'Connore43df9e2008-03-01 22:16:32 -0500397{
Kevin O'Connor1902c942013-10-26 11:48:06 -0400398 extended_access(regs, drive_gf, CMD_WRITE);
Kevin O'Connore43df9e2008-03-01 22:16:32 -0500399}
400
401// IBM/MS verify
402static void
Kevin O'Connor1902c942013-10-26 11:48:06 -0400403disk_1344(struct bregs *regs, struct drive_s *drive_gf)
Kevin O'Connore43df9e2008-03-01 22:16:32 -0500404{
Kevin O'Connor1902c942013-10-26 11:48:06 -0400405 extended_access(regs, drive_gf, CMD_VERIFY);
Kevin O'Connore43df9e2008-03-01 22:16:32 -0500406}
407
Kevin O'Connor51cfbe72009-08-18 22:38:49 -0400408// lock
409static void
Kevin O'Connor1902c942013-10-26 11:48:06 -0400410disk_134500(struct bregs *regs, struct drive_s *drive_gf)
Kevin O'Connor51cfbe72009-08-18 22:38:49 -0400411{
Kevin O'Connor77d227b2009-10-22 21:48:39 -0400412 int cdid = regs->dl - EXTSTART_CD;
Kevin O'Connord3140832012-05-13 22:46:12 -0400413 u8 locks = GET_LOW(CDRom_locks[cdid]);
Kevin O'Connor51cfbe72009-08-18 22:38:49 -0400414 if (locks == 0xff) {
415 regs->al = 1;
416 disk_ret(regs, DISK_RET_ETOOMANYLOCKS);
417 return;
418 }
Kevin O'Connord3140832012-05-13 22:46:12 -0400419 SET_LOW(CDRom_locks[cdid], locks + 1);
Kevin O'Connor51cfbe72009-08-18 22:38:49 -0400420 regs->al = 1;
421 disk_ret(regs, DISK_RET_SUCCESS);
422}
423
424// unlock
425static void
Kevin O'Connor1902c942013-10-26 11:48:06 -0400426disk_134501(struct bregs *regs, struct drive_s *drive_gf)
Kevin O'Connor51cfbe72009-08-18 22:38:49 -0400427{
Kevin O'Connor77d227b2009-10-22 21:48:39 -0400428 int cdid = regs->dl - EXTSTART_CD;
Kevin O'Connord3140832012-05-13 22:46:12 -0400429 u8 locks = GET_LOW(CDRom_locks[cdid]);
Kevin O'Connor51cfbe72009-08-18 22:38:49 -0400430 if (locks == 0x00) {
431 regs->al = 0;
432 disk_ret(regs, DISK_RET_ENOTLOCKED);
433 return;
434 }
435 locks--;
Kevin O'Connord3140832012-05-13 22:46:12 -0400436 SET_LOW(CDRom_locks[cdid], locks);
Kevin O'Connor51cfbe72009-08-18 22:38:49 -0400437 regs->al = (locks ? 1 : 0);
438 disk_ret(regs, DISK_RET_SUCCESS);
439}
440
441// status
442static void
Kevin O'Connor1902c942013-10-26 11:48:06 -0400443disk_134502(struct bregs *regs, struct drive_s *drive_gf)
Kevin O'Connor51cfbe72009-08-18 22:38:49 -0400444{
Kevin O'Connor77d227b2009-10-22 21:48:39 -0400445 int cdid = regs->dl - EXTSTART_CD;
Kevin O'Connord3140832012-05-13 22:46:12 -0400446 u8 locks = GET_LOW(CDRom_locks[cdid]);
Kevin O'Connor51cfbe72009-08-18 22:38:49 -0400447 regs->al = (locks ? 1 : 0);
448 disk_ret(regs, DISK_RET_SUCCESS);
449}
450
451static void
Kevin O'Connor1902c942013-10-26 11:48:06 -0400452disk_1345XX(struct bregs *regs, struct drive_s *drive_gf)
Kevin O'Connor51cfbe72009-08-18 22:38:49 -0400453{
Kevin O'Connordfefeb52009-12-13 13:04:17 -0500454 disk_ret_unimplemented(regs, DISK_RET_EPARAM);
Kevin O'Connor51cfbe72009-08-18 22:38:49 -0400455}
456
Kevin O'Connore43df9e2008-03-01 22:16:32 -0500457// IBM/MS lock/unlock drive
458static void
Kevin O'Connor1902c942013-10-26 11:48:06 -0400459disk_1345(struct bregs *regs, struct drive_s *drive_gf)
Kevin O'Connore43df9e2008-03-01 22:16:32 -0500460{
Kevin O'Connor51cfbe72009-08-18 22:38:49 -0400461 if (regs->dl < EXTSTART_CD) {
462 // Always success for HD
463 disk_ret(regs, DISK_RET_SUCCESS);
464 return;
465 }
466
467 switch (regs->al) {
Kevin O'Connor1902c942013-10-26 11:48:06 -0400468 case 0x00: disk_134500(regs, drive_gf); break;
469 case 0x01: disk_134501(regs, drive_gf); break;
470 case 0x02: disk_134502(regs, drive_gf); break;
471 default: disk_1345XX(regs, drive_gf); break;
Kevin O'Connor51cfbe72009-08-18 22:38:49 -0400472 }
Kevin O'Connore43df9e2008-03-01 22:16:32 -0500473}
474
475// IBM/MS eject media
Kevin O'Connorecf9b7d2012-03-25 10:21:27 -0400476static void noinline
Kevin O'Connor1902c942013-10-26 11:48:06 -0400477disk_1346(struct bregs *regs, struct drive_s *drive_gf)
Kevin O'Connore43df9e2008-03-01 22:16:32 -0500478{
Kevin O'Connor51cfbe72009-08-18 22:38:49 -0400479 if (regs->dl < EXTSTART_CD) {
480 // Volume Not Removable
481 disk_ret(regs, DISK_RET_ENOTREMOVABLE);
482 return;
483 }
484
Kevin O'Connor77d227b2009-10-22 21:48:39 -0400485 int cdid = regs->dl - EXTSTART_CD;
Kevin O'Connord3140832012-05-13 22:46:12 -0400486 u8 locks = GET_LOW(CDRom_locks[cdid]);
Kevin O'Connor51cfbe72009-08-18 22:38:49 -0400487 if (locks != 0) {
488 disk_ret(regs, DISK_RET_ELOCKED);
489 return;
490 }
491
492 // FIXME should handle 0x31 no media in device
493 // FIXME should handle 0xb5 valid request failed
494
495 // Call removable media eject
496 struct bregs br;
497 memset(&br, 0, sizeof(br));
498 br.ah = 0x52;
Kevin O'Connor74152702010-03-20 17:53:40 -0400499 br.dl = regs->dl;
Kevin O'Connor51cfbe72009-08-18 22:38:49 -0400500 call16_int(0x15, &br);
501
502 if (br.ah || br.flags & F_CF) {
503 disk_ret(regs, DISK_RET_ELOCKED);
504 return;
505 }
506 disk_ret(regs, DISK_RET_SUCCESS);
Kevin O'Connore43df9e2008-03-01 22:16:32 -0500507}
508
509// IBM/MS extended seek
510static void
Kevin O'Connor1902c942013-10-26 11:48:06 -0400511disk_1347(struct bregs *regs, struct drive_s *drive_gf)
Kevin O'Connore43df9e2008-03-01 22:16:32 -0500512{
Kevin O'Connor1902c942013-10-26 11:48:06 -0400513 extended_access(regs, drive_gf, CMD_SEEK);
Kevin O'Connore43df9e2008-03-01 22:16:32 -0500514}
515
516// IBM/MS get drive parameters
Kevin O'Connor39ca4982014-05-10 11:42:22 -0400517static void
Kevin O'Connor1902c942013-10-26 11:48:06 -0400518disk_1348(struct bregs *regs, struct drive_s *drive_gf)
Kevin O'Connore43df9e2008-03-01 22:16:32 -0500519{
Kevin O'Connor39ca4982014-05-10 11:42:22 -0400520 int ret = fill_edd(regs->ds, (void*)(regs->si+0), drive_gf);
521 disk_ret(regs, ret);
Kevin O'Connore43df9e2008-03-01 22:16:32 -0500522}
523
524// IBM/MS extended media change
525static void
Kevin O'Connor1902c942013-10-26 11:48:06 -0400526disk_1349(struct bregs *regs, struct drive_s *drive_gf)
Kevin O'Connore43df9e2008-03-01 22:16:32 -0500527{
Kevin O'Connor51cfbe72009-08-18 22:38:49 -0400528 if (regs->dl < EXTSTART_CD) {
529 // Always success for HD
530 disk_ret(regs, DISK_RET_SUCCESS);
531 return;
532 }
Kevin O'Connordfefeb52009-12-13 13:04:17 -0500533 set_invalid(regs);
Kevin O'Connor51cfbe72009-08-18 22:38:49 -0400534 // always send changed ??
535 regs->ah = DISK_RET_ECHANGED;
Kevin O'Connore43df9e2008-03-01 22:16:32 -0500536}
537
538static void
Kevin O'Connor1902c942013-10-26 11:48:06 -0400539disk_134e01(struct bregs *regs, struct drive_s *drive_gf)
Kevin O'Connore43df9e2008-03-01 22:16:32 -0500540{
541 disk_ret(regs, DISK_RET_SUCCESS);
542}
543
544static void
Kevin O'Connor1902c942013-10-26 11:48:06 -0400545disk_134e03(struct bregs *regs, struct drive_s *drive_gf)
Kevin O'Connore43df9e2008-03-01 22:16:32 -0500546{
547 disk_ret(regs, DISK_RET_SUCCESS);
548}
549
550static void
Kevin O'Connor1902c942013-10-26 11:48:06 -0400551disk_134e04(struct bregs *regs, struct drive_s *drive_gf)
Kevin O'Connore43df9e2008-03-01 22:16:32 -0500552{
553 disk_ret(regs, DISK_RET_SUCCESS);
554}
555
556static void
Kevin O'Connor1902c942013-10-26 11:48:06 -0400557disk_134e06(struct bregs *regs, struct drive_s *drive_gf)
Kevin O'Connore43df9e2008-03-01 22:16:32 -0500558{
559 disk_ret(regs, DISK_RET_SUCCESS);
560}
561
562static void
Kevin O'Connor1902c942013-10-26 11:48:06 -0400563disk_134eXX(struct bregs *regs, struct drive_s *drive_gf)
Kevin O'Connore43df9e2008-03-01 22:16:32 -0500564{
Kevin O'Connore43df9e2008-03-01 22:16:32 -0500565 disk_ret(regs, DISK_RET_EPARAM);
566}
567
568// IBM/MS set hardware configuration
569static void
Kevin O'Connor1902c942013-10-26 11:48:06 -0400570disk_134e(struct bregs *regs, struct drive_s *drive_gf)
Kevin O'Connore43df9e2008-03-01 22:16:32 -0500571{
572 switch (regs->al) {
Kevin O'Connor1902c942013-10-26 11:48:06 -0400573 case 0x01: disk_134e01(regs, drive_gf); break;
574 case 0x03: disk_134e03(regs, drive_gf); break;
575 case 0x04: disk_134e04(regs, drive_gf); break;
576 case 0x06: disk_134e06(regs, drive_gf); break;
577 default: disk_134eXX(regs, drive_gf); break;
Kevin O'Connore43df9e2008-03-01 22:16:32 -0500578 }
579}
580
Kevin O'Connor36c93a52009-09-12 19:35:04 -0400581static void
Kevin O'Connor1902c942013-10-26 11:48:06 -0400582disk_13XX(struct bregs *regs, struct drive_s *drive_gf)
Kevin O'Connor3491e8b2008-02-29 00:22:27 -0500583{
Kevin O'Connordfefeb52009-12-13 13:04:17 -0500584 disk_ret_unimplemented(regs, DISK_RET_EPARAM);
Kevin O'Connor3491e8b2008-02-29 00:22:27 -0500585}
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500586
Kevin O'Connor36c93a52009-09-12 19:35:04 -0400587static void
Kevin O'Connor1902c942013-10-26 11:48:06 -0400588disk_13(struct bregs *regs, struct drive_s *drive_gf)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500589{
Kevin O'Connor15aee2e2008-03-01 13:34:04 -0500590 //debug_stub(regs);
Kevin O'Connor3491e8b2008-02-29 00:22:27 -0500591
592 // clear completion flag
593 SET_BDA(disk_interrupt_flag, 0);
594
Kevin O'Connor3491e8b2008-02-29 00:22:27 -0500595 switch (regs->ah) {
Kevin O'Connor1902c942013-10-26 11:48:06 -0400596 case 0x00: disk_1300(regs, drive_gf); break;
597 case 0x01: disk_1301(regs, drive_gf); break;
598 case 0x02: disk_1302(regs, drive_gf); break;
599 case 0x03: disk_1303(regs, drive_gf); break;
600 case 0x04: disk_1304(regs, drive_gf); break;
601 case 0x05: disk_1305(regs, drive_gf); break;
602 case 0x08: disk_1308(regs, drive_gf); break;
603 case 0x09: disk_1309(regs, drive_gf); break;
604 case 0x0c: disk_130c(regs, drive_gf); break;
605 case 0x0d: disk_130d(regs, drive_gf); break;
606 case 0x10: disk_1310(regs, drive_gf); break;
607 case 0x11: disk_1311(regs, drive_gf); break;
608 case 0x14: disk_1314(regs, drive_gf); break;
609 case 0x15: disk_1315(regs, drive_gf); break;
610 case 0x16: disk_1316(regs, drive_gf); break;
611 case 0x41: disk_1341(regs, drive_gf); break;
612 case 0x42: disk_1342(regs, drive_gf); break;
613 case 0x43: disk_1343(regs, drive_gf); break;
614 case 0x44: disk_1344(regs, drive_gf); break;
615 case 0x45: disk_1345(regs, drive_gf); break;
616 case 0x46: disk_1346(regs, drive_gf); break;
617 case 0x47: disk_1347(regs, drive_gf); break;
618 case 0x48: disk_1348(regs, drive_gf); break;
619 case 0x49: disk_1349(regs, drive_gf); break;
620 case 0x4e: disk_134e(regs, drive_gf); break;
621 default: disk_13XX(regs, drive_gf); break;
Kevin O'Connor3491e8b2008-02-29 00:22:27 -0500622 }
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500623}
624
Kevin O'Connoraf5aabb2009-08-16 18:48:38 -0400625static void
Kevin O'Connor1902c942013-10-26 11:48:06 -0400626floppy_13(struct bregs *regs, struct drive_s *drive_gf)
Kevin O'Connoraf5aabb2009-08-16 18:48:38 -0400627{
628 // Only limited commands are supported on floppies.
629 switch (regs->ah) {
630 case 0x00:
631 case 0x01:
632 case 0x02:
633 case 0x03:
634 case 0x04:
635 case 0x05:
636 case 0x08:
637 case 0x15:
638 case 0x16:
Kevin O'Connor1902c942013-10-26 11:48:06 -0400639 disk_13(regs, drive_gf);
Kevin O'Connoraf5aabb2009-08-16 18:48:38 -0400640 break;
Kevin O'Connor1902c942013-10-26 11:48:06 -0400641 default: disk_13XX(regs, drive_gf); break;
Kevin O'Connoraf5aabb2009-08-16 18:48:38 -0400642 }
643}
644
Kevin O'Connorc029a912014-05-10 15:51:40 -0400645// ElTorito - Terminate disk emu
646static void
647cdemu_134b(struct bregs *regs)
648{
649 memcpy_far(regs->ds, (void*)(regs->si+0), SEG_LOW, &CDEmu, sizeof(CDEmu));
650
651 // If we have to terminate emulation
652 if (regs->al == 0x00) {
653 // FIXME ElTorito Various. Should be handled accordingly to spec
654 SET_LOW(CDEmu.media, 0x00); // bye bye
655
656 // XXX - update floppy/hd count.
657 }
658
659 disk_ret(regs, DISK_RET_SUCCESS);
660}
661
Kevin O'Connorb74102d2008-03-03 21:57:30 -0500662
663/****************************************************************
Kevin O'Connorb74102d2008-03-03 21:57:30 -0500664 * Entry points
665 ****************************************************************/
666
Kevin O'Connore43df9e2008-03-01 22:16:32 -0500667static void
Kevin O'Connor707298a2009-08-11 22:27:51 -0400668handle_legacy_disk(struct bregs *regs, u8 extdrive)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500669{
Kevin O'Connorc892b132009-08-11 21:59:37 -0400670 if (! CONFIG_DRIVES) {
Kevin O'Connor0a0e42e2009-08-16 12:09:44 -0400671 // XXX - support handle_1301 anyway?
Kevin O'Connore43df9e2008-03-01 22:16:32 -0500672 disk_ret(regs, DISK_RET_EPARAM);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500673 return;
674 }
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500675
Kevin O'Connor51cfbe72009-08-18 22:38:49 -0400676 if (extdrive < EXTSTART_HD) {
Kevin O'Connor1902c942013-10-26 11:48:06 -0400677 struct drive_s *drive_gf = getDrive(EXTTYPE_FLOPPY, extdrive);
678 if (!drive_gf)
Kevin O'Connor0a0e42e2009-08-16 12:09:44 -0400679 goto fail;
Kevin O'Connor1902c942013-10-26 11:48:06 -0400680 floppy_13(regs, drive_gf);
Kevin O'Connor0a0e42e2009-08-16 12:09:44 -0400681 return;
682 }
683
Kevin O'Connor1902c942013-10-26 11:48:06 -0400684 struct drive_s *drive_gf;
Kevin O'Connor51cfbe72009-08-18 22:38:49 -0400685 if (extdrive >= EXTSTART_CD)
Kevin O'Connor1902c942013-10-26 11:48:06 -0400686 drive_gf = getDrive(EXTTYPE_CD, extdrive - EXTSTART_CD);
Kevin O'Connor51cfbe72009-08-18 22:38:49 -0400687 else
Kevin O'Connor1902c942013-10-26 11:48:06 -0400688 drive_gf = getDrive(EXTTYPE_HD, extdrive - EXTSTART_HD);
689 if (!drive_gf)
Kevin O'Connor0a0e42e2009-08-16 12:09:44 -0400690 goto fail;
Kevin O'Connor1902c942013-10-26 11:48:06 -0400691 disk_13(regs, drive_gf);
Kevin O'Connor0a0e42e2009-08-16 12:09:44 -0400692 return;
693
694fail:
695 // XXX - support 1301/1308/1315 anyway?
696 disk_ret(regs, DISK_RET_EPARAM);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500697}
698
Kevin O'Connor19786762008-03-05 21:09:59 -0500699void VISIBLE16
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500700handle_40(struct bregs *regs)
701{
Kevin O'Connor15c1f222008-06-12 22:59:43 -0400702 debug_enter(regs, DEBUG_HDL_40);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500703 handle_legacy_disk(regs, regs->dl);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500704}
705
706// INT 13h Fixed Disk Services Entry Point
Kevin O'Connor19786762008-03-05 21:09:59 -0500707void VISIBLE16
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500708handle_13(struct bregs *regs)
709{
Kevin O'Connor15c1f222008-06-12 22:59:43 -0400710 debug_enter(regs, DEBUG_HDL_13);
Kevin O'Connor707298a2009-08-11 22:27:51 -0400711 u8 extdrive = regs->dl;
Kevin O'Connor941d3e42008-03-04 19:45:04 -0500712
Kevin O'Connordfa16502008-03-22 20:13:08 -0400713 if (CONFIG_CDROM_EMU) {
Kevin O'Connor941d3e42008-03-04 19:45:04 -0500714 if (regs->ah == 0x4b) {
715 cdemu_134b(regs);
Kevin O'Connor6c781222008-03-09 12:19:23 -0400716 return;
Kevin O'Connor941d3e42008-03-04 19:45:04 -0500717 }
Kevin O'Connor02f76762014-05-10 01:20:46 -0400718 if (GET_LOW(CDEmu.media)) {
719 u8 emudrive = GET_LOW(CDEmu.emulated_drive);
Kevin O'Connor707298a2009-08-11 22:27:51 -0400720 if (extdrive == emudrive) {
Kevin O'Connor77d227b2009-10-22 21:48:39 -0400721 // Access to an emulated drive.
Kevin O'Connor1902c942013-10-26 11:48:06 -0400722 struct drive_s *cdemu_gf = GET_GLOBAL(cdemu_drive_gf);
Kevin O'Connor36c93a52009-09-12 19:35:04 -0400723 if (regs->ah > 0x16) {
724 // Only old-style commands supported.
Kevin O'Connor1902c942013-10-26 11:48:06 -0400725 disk_13XX(regs, cdemu_gf);
Kevin O'Connor36c93a52009-09-12 19:35:04 -0400726 return;
727 }
Kevin O'Connor1902c942013-10-26 11:48:06 -0400728 disk_13(regs, cdemu_gf);
Kevin O'Connor6c781222008-03-09 12:19:23 -0400729 return;
Kevin O'Connor941d3e42008-03-04 19:45:04 -0500730 }
Kevin O'Connor51cfbe72009-08-18 22:38:49 -0400731 if (extdrive < EXTSTART_CD && ((emudrive ^ extdrive) & 0x80) == 0)
Kevin O'Connor77d227b2009-10-22 21:48:39 -0400732 // Adjust id to make room for emulated drive.
Kevin O'Connor707298a2009-08-11 22:27:51 -0400733 extdrive--;
Kevin O'Connor941d3e42008-03-04 19:45:04 -0500734 }
735 }
Kevin O'Connor707298a2009-08-11 22:27:51 -0400736 handle_legacy_disk(regs, extdrive);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500737}
738
739// record completion in BIOS task complete flag
Kevin O'Connor19786762008-03-05 21:09:59 -0500740void VISIBLE16
Kevin O'Connor1297e5d2012-06-02 20:30:58 -0400741handle_76(void)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500742{
Kevin O'Connor1297e5d2012-06-02 20:30:58 -0400743 debug_isr(DEBUG_ISR_76);
Kevin O'Connored128492008-03-11 11:14:59 -0400744 SET_BDA(disk_interrupt_flag, 0xff);
Kevin O'Connoraa7c2342013-07-14 15:07:21 -0400745 pic_eoi2();
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500746}