VirtualBox

source: vbox/trunk/src/VBox/Devices/PC/BIOS/disk.c

Last change on this file was 104194, checked in by vboxsync, 4 weeks ago

BIOS: Run INITIALIZE DRIVE PARAMETERS after resetting drives in the unusual case where logical geometry does not match physical.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 21.7 KB
Line 
1/* $Id: disk.c 104194 2024-04-05 14:39:02Z vboxsync $ */
2/** @file
3 * PC BIOS - ???
4 */
5
6/*
7 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 * --------------------------------------------------------------------
27 *
28 * This code is based on:
29 *
30 * ROM BIOS for use with Bochs/Plex86/QEMU emulation environment
31 *
32 * Copyright (C) 2002 MandrakeSoft S.A.
33 *
34 * MandrakeSoft S.A.
35 * 43, rue d'Aboukir
36 * 75002 Paris - France
37 * http://www.linux-mandrake.com/
38 * http://www.mandrakesoft.com/
39 *
40 * This library is free software; you can redistribute it and/or
41 * modify it under the terms of the GNU Lesser General Public
42 * License as published by the Free Software Foundation; either
43 * version 2 of the License, or (at your option) any later version.
44 *
45 * This library is distributed in the hope that it will be useful,
46 * but WITHOUT ANY WARRANTY; without even the implied warranty of
47 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
48 * Lesser General Public License for more details.
49 *
50 * You should have received a copy of the GNU Lesser General Public
51 * License along with this library; if not, write to the Free Software
52 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
53 *
54 */
55
56/*
57 * Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
58 * other than GPL or LGPL is available it will apply instead, Oracle elects to use only
59 * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
60 * a choice of LGPL license versions is made available with the language indicating
61 * that LGPLv2 or any later version may be used, or where a choice of which version
62 * of the LGPL is applied is otherwise unspecified.
63 */
64
65
66#include <stdint.h>
67#include "biosint.h"
68#include "inlines.h"
69#include "ebda.h"
70#include "ata.h"
71
72
73#if DEBUG_INT13_HD
74# define BX_DEBUG_INT13_HD(...) BX_DEBUG(__VA_ARGS__)
75#else
76# define BX_DEBUG_INT13_HD(...)
77#endif
78
79/* Generic disk read/write routine signature. */
80typedef int __fastcall (* dsk_rw_func)(bio_dsk_t __far *bios_dsk);
81
82/* Controller specific disk access routines. Declared as a union to reduce
83 * the need for conditionals when choosing between read/write functions.
84 * Note that we get away with using near pointers, which is nice.
85 */
86typedef union {
87 struct {
88 dsk_rw_func read;
89 dsk_rw_func write;
90 } s;
91 dsk_rw_func a[2];
92} dsk_acc_t;
93
94/* Pointers to HW specific disk access routines. */
95dsk_acc_t dskacc[DSKTYP_CNT] = {
96 [DSK_TYPE_ATA] = { ata_read_sectors, ata_write_sectors },
97#ifdef VBOX_WITH_AHCI
98 [DSK_TYPE_AHCI] = { ahci_read_sectors, ahci_write_sectors },
99#endif
100#ifdef VBOX_WITH_SCSI
101 [DSK_TYPE_SCSI] = { scsi_read_sectors, scsi_write_sectors },
102#endif
103};
104
105
106/// @todo put in a header
107#define AX r.gr.u.r16.ax
108#define BX r.gr.u.r16.bx
109#define CX r.gr.u.r16.cx
110#define DX r.gr.u.r16.dx
111#define SI r.gr.u.r16.si
112#define DI r.gr.u.r16.di
113#define BP r.gr.u.r16.bp
114#define ELDX r.gr.u.r16.sp
115#define DS r.ds
116#define ES r.es
117#define FLAGS r.ra.flags.u.r16.flags
118
119
120/*
121 * Build translated CHS geometry given a disk size in sectors. Based on
122 * Phoenix EDD 3.0. This is used as a fallback to generate sane logical
123 * geometry in case none was provided in CMOS.
124 */
125void set_geom_lba(chs_t __far *lgeo, uint64_t nsectors64)
126{
127 uint32_t limit = 8257536; /* 1024 * 128 * 63 */
128 uint32_t nsectors;
129 unsigned heads = 255;
130 int i;
131
132 nsectors = (nsectors64 >> 32) ? 0xFFFFFFFFL : (uint32_t)nsectors64;
133 /* Start with ~4GB limit, go down to 504MB. */
134 for (i = 0; i < 4; ++i) {
135 if (nsectors <= limit)
136 heads = (heads + 1) / 2;
137 limit /= 2;
138 }
139
140 lgeo->cylinders = nsectors / (heads * 63UL);
141 if (lgeo->cylinders > 1024)
142 lgeo->cylinders = 1024;
143 lgeo->heads = heads;
144 lgeo->spt = 63; /* Always 63 sectors per track, the maximum. */
145}
146
147int edd_fill_dpt(dpt_t __far *dpt, bio_dsk_t __far *bios_dsk, uint8_t device)
148{
149 uint16_t ebda_seg = read_word(0x0040,0x000E);
150
151 /* Check if buffer is large enough. */
152 if (dpt->size < 0x1a)
153 return -1;
154
155 /* Fill in EDD 1.x table. */
156 if (dpt->size >= 0x1a) {
157 uint64_t lba;
158
159 dpt->size = 0x1a;
160 dpt->blksize = bios_dsk->devices[device].blksize;
161
162 if (bios_dsk->devices[device].device == DSK_DEVICE_CDROM) {
163 dpt->infos = 0x74; /* Removable, media change, lockable, max values */
164 dpt->cylinders = 0xffffffff;
165 dpt->heads = 0xffffffff;
166 dpt->spt = 0xffffffff;
167 dpt->sector_count1 = 0xffffffff;
168 dpt->sector_count2 = 0xffffffff;
169 } else {
170 dpt->infos = 0x02; // geometry is valid
171 dpt->cylinders = bios_dsk->devices[device].pchs.cylinders;
172 dpt->heads = bios_dsk->devices[device].pchs.heads;
173 dpt->spt = bios_dsk->devices[device].pchs.spt;
174 lba = bios_dsk->devices[device].sectors;
175 dpt->sector_count1 = lba;
176 dpt->sector_count2 = lba >> 32;
177 }
178 }
179
180 /* Fill in EDD 2.x table. */
181 if (dpt->size >= 0x1e) {
182 uint8_t channel, irq, mode, checksum, i, xlation;
183 uint16_t iobase1, iobase2, options;
184
185 dpt->size = 0x1e;
186 dpt->dpte_segment = ebda_seg;
187 dpt->dpte_offset = (uint16_t)&EbdaData->bdisk.dpte;
188
189 // Fill in dpte
190 channel = device / 2;
191 iobase1 = bios_dsk->channels[channel].iobase1;
192 iobase2 = bios_dsk->channels[channel].iobase2;
193 irq = bios_dsk->channels[channel].irq;
194 mode = bios_dsk->devices[device].mode;
195 xlation = bios_dsk->devices[device].translation;
196
197 options = (xlation == GEO_TRANSLATION_NONE ? 0 : 1 << 3); /* CHS translation */
198 options |= (1 << 4); /* LBA translation */
199 if (bios_dsk->devices[device].device == DSK_DEVICE_CDROM) {
200 options |= (1 << 5); /* Removable device */
201 options |= (1 << 6); /* ATAPI device */
202 }
203#if VBOX_BIOS_CPU >= 80386
204 options |= (mode == ATA_MODE_PIO32 ? 1 : 0 << 7);
205#endif
206 options |= (xlation == GEO_TRANSLATION_LBA ? 1 : 0 << 9);
207 options |= (xlation == GEO_TRANSLATION_RECHS ? 3 : 0 << 9);
208
209 bios_dsk->dpte.iobase1 = iobase1;
210 bios_dsk->dpte.iobase2 = iobase2;
211 bios_dsk->dpte.prefix = (0xe | (device % 2)) << 4;
212 bios_dsk->dpte.unused = 0xcb;
213 bios_dsk->dpte.irq = irq;
214 bios_dsk->dpte.blkcount = 1;
215 bios_dsk->dpte.dma = 0;
216 bios_dsk->dpte.pio = 0;
217 bios_dsk->dpte.options = options;
218 bios_dsk->dpte.reserved = 0;
219 bios_dsk->dpte.revision = 0x11;
220
221 checksum = 0;
222 for (i = 0; i < 15; ++i)
223 checksum += read_byte(ebda_seg, (uint16_t)&EbdaData->bdisk.dpte + i);
224 checksum = -checksum;
225 bios_dsk->dpte.checksum = checksum;
226 }
227
228 /* Fill in EDD 3.x table. */
229 if (dpt->size >= 0x42) {
230 uint8_t channel, iface, checksum, i;
231 uint16_t iobase1;
232
233 channel = device / 2;
234 iface = bios_dsk->channels[channel].iface;
235 iobase1 = bios_dsk->channels[channel].iobase1;
236
237 dpt->size = 0x42;
238 dpt->key = 0xbedd;
239 dpt->dpi_length = 0x24;
240 dpt->reserved1 = 0;
241 dpt->reserved2 = 0;
242
243 if (iface == ATA_IFACE_ISA) {
244 dpt->host_bus[0] = 'I';
245 dpt->host_bus[1] = 'S';
246 dpt->host_bus[2] = 'A';
247 dpt->host_bus[3] = ' ';
248 }
249 else {
250 // FIXME PCI
251 }
252 dpt->iface_type[0] = 'A';
253 dpt->iface_type[1] = 'T';
254 dpt->iface_type[2] = 'A';
255 dpt->iface_type[3] = ' ';
256 dpt->iface_type[4] = ' ';
257 dpt->iface_type[5] = ' ';
258 dpt->iface_type[6] = ' ';
259 dpt->iface_type[7] = ' ';
260
261 if (iface == ATA_IFACE_ISA) {
262 ((uint16_t __far *)dpt->iface_path)[0] = iobase1;
263 ((uint16_t __far *)dpt->iface_path)[1] = 0;
264 ((uint32_t __far *)dpt->iface_path)[1] = 0;
265 }
266 else {
267 // FIXME PCI
268 }
269 ((uint16_t __far *)dpt->device_path)[0] = device & 1; // device % 2; @todo: correct?
270 ((uint16_t __far *)dpt->device_path)[1] = 0;
271 ((uint32_t __far *)dpt->device_path)[1] = 0;
272
273 checksum = 0;
274 for (i = 30; i < 64; i++)
275 checksum += ((uint8_t __far *)dpt)[i];
276 checksum = -checksum;
277 dpt->checksum = checksum;
278 }
279 return 0;
280}
281
282void BIOSCALL int13_harddisk(disk_regs_t r)
283{
284 uint32_t lba;
285 uint16_t cylinder, head, sector;
286 uint16_t nlc, nlh, nlspt;
287 uint16_t count;
288 uint8_t device, status;
289 bio_dsk_t __far *bios_dsk;
290
291 BX_DEBUG_INT13_HD("%s: AX=%04x BX=%04x CX=%04x DX=%04x ES=%04x\n", __func__, AX, BX, CX, DX, ES);
292
293 SET_IF(); /* INT 13h always returns with interrupts enabled. */
294
295 bios_dsk = read_word(0x0040,0x000E) :> &EbdaData->bdisk;
296 write_byte(0x0040, 0x008e, 0); // clear completion flag
297
298 // basic check : device has to be defined
299 if ( (GET_ELDL() < 0x80) || (GET_ELDL() >= 0x80 + BX_MAX_STORAGE_DEVICES) ) {
300 BX_DEBUG("%s: function %02x, ELDL out of range %02x\n", __func__, GET_AH(), GET_ELDL());
301 goto int13_fail;
302 }
303
304 // Get the ata channel
305 device = bios_dsk->hdidmap[GET_ELDL()-0x80];
306
307 // basic check : device has to be valid
308 if (device >= BX_MAX_STORAGE_DEVICES) {
309 BX_DEBUG("%s: function %02x, unmapped device for ELDL=%02x\n", __func__, GET_AH(), GET_ELDL());
310 goto int13_fail;
311 }
312
313 switch (GET_AH()) {
314
315 case 0x00: /* disk controller reset */
316 /* For ATA drives only. NB: This resets both drives on a channel. */
317 if (VBOX_IS_ATA_DEVICE(device))
318 ata_reset(device);
319 goto int13_success;
320 break;
321
322 case 0x01: /* read disk status */
323 status = read_byte(0x0040, 0x0074);
324 SET_AH(status);
325 SET_DISK_RET_STATUS(0);
326 /* set CF if error status read */
327 if (status) goto int13_fail_nostatus;
328 else goto int13_success_noah;
329 break;
330
331 case 0x02: // read disk sectors
332 case 0x03: // write disk sectors
333 case 0x04: // verify disk sectors
334
335 count = GET_AL();
336 cylinder = GET_CH();
337 cylinder |= ( ((uint16_t) GET_CL()) << 2) & 0x300;
338 sector = (GET_CL() & 0x3f);
339 head = GET_DH();
340
341 /* Segment and offset are in ES:BX. */
342 if ( (count > 128) || (count == 0) ) {
343 BX_INFO("%s: function %02x, count out of range!\n", __func__, GET_AH());
344 goto int13_fail;
345 }
346
347 /* Get the logical CHS geometry. */
348 nlc = bios_dsk->devices[device].lchs.cylinders;
349 nlh = bios_dsk->devices[device].lchs.heads;
350 nlspt = bios_dsk->devices[device].lchs.spt;
351
352 /* Sanity check the geometry. */
353 if( (cylinder >= nlc) || (head >= nlh) || (sector > nlspt )) {
354 BX_INFO("%s: function %02x, disk %02x, parameters out of range %04x/%04x/%04x!\n", __func__, GET_AH(), GET_DL(), cylinder, head, sector);
355 goto int13_fail;
356 }
357
358 // FIXME verify
359 if ( GET_AH() == 0x04 )
360 goto int13_success;
361
362 /* If required, translate LCHS to LBA and execute command. */
363 /// @todo The IS_SCSI_DEVICE check should be redundant...
364 if (( (bios_dsk->devices[device].pchs.heads != nlh) || (bios_dsk->devices[device].pchs.spt != nlspt)) || VBOX_IS_SCSI_DEVICE(device)) {
365 lba = ((((uint32_t)cylinder * (uint32_t)nlh) + (uint32_t)head) * (uint32_t)nlspt) + (uint32_t)sector - 1;
366 sector = 0; // this forces the command to be lba
367 BX_DEBUG_INT13_HD("%s: %d sectors from lba %lu @ %04x:%04x\n", __func__,
368 count, lba, ES, BX);
369 } else {
370 BX_DEBUG_INT13_HD("%s: %d sectors from C/H/S %u/%u/%u @ %04x:%04x\n", __func__,
371 count, cylinder, head, sector, ES, BX);
372 }
373
374
375 /* Clear the count of transferred sectors/bytes. */
376 bios_dsk->drqp.trsfsectors = 0;
377 bios_dsk->drqp.trsfbytes = 0;
378
379 /* Pass request information to low level disk code. */
380 bios_dsk->drqp.lba = lba;
381 bios_dsk->drqp.buffer = MK_FP(ES, BX);
382 bios_dsk->drqp.nsect = count;
383 bios_dsk->drqp.sect_sz = 512; /// @todo device specific?
384 bios_dsk->drqp.cylinder = cylinder;
385 bios_dsk->drqp.head = head;
386 bios_dsk->drqp.sector = sector;
387 bios_dsk->drqp.dev_id = device;
388
389 status = dskacc[bios_dsk->devices[device].type].a[GET_AH() - 0x02](bios_dsk);
390
391 // Set nb of sector transferred
392 SET_AL(bios_dsk->drqp.trsfsectors);
393
394 if (status != 0) {
395 BX_INFO("%s: function %02x, error %02x !\n", __func__, GET_AH(), status);
396 SET_AH(0x0c);
397 goto int13_fail_noah;
398 }
399
400 goto int13_success;
401 break;
402
403 case 0x05: /* format disk track */
404 BX_INFO("format disk track called\n");
405 goto int13_success;
406 break;
407
408 case 0x08: /* read disk drive parameters */
409
410 /* Get the logical geometry from internal table. */
411 nlc = bios_dsk->devices[device].lchs.cylinders;
412 nlh = bios_dsk->devices[device].lchs.heads;
413 nlspt = bios_dsk->devices[device].lchs.spt;
414
415 count = bios_dsk->hdcount;
416 /* Maximum cylinder number is just one less than the number of cylinders. */
417 /* To make Windows 3.1x WDCTRL.386 happy, we'd have to subtract 2, not 1,
418 * to account for a diagnostic cylinder.
419 */
420 nlc = nlc - 1; /* 0 based , last sector not used */
421 SET_AL(0);
422 SET_CH(nlc & 0xff);
423 SET_CL(((nlc >> 2) & 0xc0) | (nlspt & 0x3f));
424 SET_DH(nlh - 1);
425 SET_DL(count); /* FIXME returns 0, 1, or n hard drives */
426
427 // FIXME should set ES & DI
428 /// @todo Actually, the above comment is nonsense.
429
430 goto int13_success;
431 break;
432
433 case 0x10: /* check drive ready */
434 // should look at 40:8E also???
435
436#ifdef VBOX_WITH_SCSI
437 /* SCSI drives are always "ready". */
438 if (!VBOX_IS_SCSI_DEVICE(device)) {
439#endif
440 // Read the status from controller
441 status = inb(bios_dsk->channels[device/2].iobase1 + ATA_CB_STAT);
442 if ( (status & ( ATA_CB_STAT_BSY | ATA_CB_STAT_RDY )) == ATA_CB_STAT_RDY ) {
443 goto int13_success;
444 } else {
445 SET_AH(0xAA);
446 goto int13_fail_noah;
447 }
448#ifdef VBOX_WITH_SCSI
449 } else /* It's not an ATA drive. */
450 goto int13_success;
451#endif
452 break;
453
454 case 0x15: /* read disk drive size */
455
456 /* Get the physical geometry from internal table. */
457 cylinder = bios_dsk->devices[device].pchs.cylinders;
458 head = bios_dsk->devices[device].pchs.heads;
459 sector = bios_dsk->devices[device].pchs.spt;
460
461 /* Calculate sector count seen by old style INT 13h. */
462 lba = (uint32_t)cylinder * head * sector;
463 CX = lba >> 16;
464 DX = lba & 0xffff;
465
466 SET_AH(3); // hard disk accessible
467 goto int13_success_noah;
468 break;
469
470 case 0x09: /* initialize drive parameters */
471 case 0x0c: /* seek to specified cylinder */
472 case 0x0d: /* alternate disk reset */
473 case 0x11: /* recalibrate */
474 case 0x14: /* controller internal diagnostic */
475 BX_INFO("%s: function %02xh unimplemented, returns success\n", __func__, GET_AH());
476 goto int13_success;
477 break;
478
479 case 0x0a: /* read disk sectors with ECC */
480 case 0x0b: /* write disk sectors with ECC */
481 case 0x18: // set media type for format
482 default:
483 BX_INFO("%s: function %02xh unsupported, returns fail\n", __func__, GET_AH());
484 goto int13_fail;
485 break;
486 }
487
488int13_fail:
489 SET_AH(0x01); // defaults to invalid function in AH or invalid parameter
490int13_fail_noah:
491 SET_DISK_RET_STATUS(GET_AH());
492int13_fail_nostatus:
493 SET_CF(); // error occurred
494 return;
495
496int13_success:
497 SET_AH(0x00); // no error
498int13_success_noah:
499 SET_DISK_RET_STATUS(0x00);
500 CLEAR_CF(); // no error
501 return;
502}
503
504void BIOSCALL int13_harddisk_ext(disk_regs_t r)
505{
506 uint64_t lba;
507 uint16_t segment, offset;
508 uint8_t device, status;
509 uint16_t count;
510 uint8_t type;
511 bio_dsk_t __far *bios_dsk;
512 int13ext_t __far *i13_ext;
513#if 0
514 uint16_t ebda_seg = read_word(0x0040,0x000E);
515 uint16_t npc, nph, npspt;
516 uint16_t size;
517 dpt_t __far *dpt;
518#endif
519
520 bios_dsk = read_word(0x0040,0x000E) :> &EbdaData->bdisk;
521
522 BX_DEBUG_INT13_HD("%s: AX=%04x BX=%04x CX=%04x DX=%04x ES=%04x DS=%04x SI=%04x\n",
523 __func__, AX, BX, CX, DX, ES, DS, SI);
524
525 write_byte(0x0040, 0x008e, 0); // clear completion flag
526
527 // basic check : device has to be defined
528 if ( (GET_ELDL() < 0x80) || (GET_ELDL() >= 0x80 + BX_MAX_STORAGE_DEVICES) ) {
529 BX_DEBUG("%s: function %02x, ELDL out of range %02x\n", __func__, GET_AH(), GET_ELDL());
530 goto int13x_fail;
531 }
532
533 // Get the ata channel
534 device = bios_dsk->hdidmap[GET_ELDL()-0x80];
535
536 // basic check : device has to be valid
537 if (device >= BX_MAX_STORAGE_DEVICES) {
538 BX_DEBUG("%s: function %02x, unmapped device for ELDL=%02x\n", __func__, GET_AH(), GET_ELDL());
539 goto int13x_fail;
540 }
541
542 switch (GET_AH()) {
543 case 0x41: // IBM/MS installation check
544 BX=0xaa55; // install check
545 SET_AH(0x30); // EDD 3.0
546 CX=0x0007; // ext disk access and edd, removable supported
547 goto int13x_success_noah;
548 break;
549
550 case 0x42: // IBM/MS extended read
551 case 0x43: // IBM/MS extended write
552 case 0x44: // IBM/MS verify
553 case 0x47: // IBM/MS extended seek
554
555 /* Get a pointer to the extended structure. */
556 i13_ext = DS :> (int13ext_t *)SI;
557
558 count = i13_ext->count;
559 segment = i13_ext->segment;
560 offset = i13_ext->offset;
561
562 // Get 64 bits lba and check
563 lba = i13_ext->lba2;
564 lba <<= 32;
565 lba |= i13_ext->lba1;
566
567 BX_DEBUG_INT13_HD("%s: %d sectors from LBA 0x%llx @ %04x:%04x\n", __func__,
568 count, lba, segment, offset);
569
570 type = bios_dsk->devices[device].type;
571 if (lba >= bios_dsk->devices[device].sectors) {
572 BX_INFO("%s: function %02x. LBA out of range\n", __func__, GET_AH());
573 goto int13x_fail;
574 }
575
576 /* Don't bother with seek or verify. */
577 if (( GET_AH() == 0x44 ) || ( GET_AH() == 0x47 ))
578 goto int13x_success;
579
580 /* Clear the count of transferred sectors/bytes. */
581 bios_dsk->drqp.trsfsectors = 0;
582 bios_dsk->drqp.trsfbytes = 0;
583
584 /* Pass request information to low level disk code. */
585 bios_dsk->drqp.lba = lba;
586 bios_dsk->drqp.buffer = MK_FP(segment, offset);
587 bios_dsk->drqp.nsect = count;
588 bios_dsk->drqp.sect_sz = 512; /// @todo device specific?
589 bios_dsk->drqp.sector = 0; /* Indicate LBA. */
590 bios_dsk->drqp.dev_id = device;
591
592 /* Execute the read or write command. */
593 status = dskacc[type].a[GET_AH() - 0x42](bios_dsk);
594 count = bios_dsk->drqp.trsfsectors;
595 i13_ext->count = count;
596
597 if (status != 0) {
598 BX_INFO("%s: function %02x, error %02x !\n", __func__, GET_AH(), status);
599 SET_AH(0x0c);
600 goto int13x_fail_noah;
601 }
602
603 goto int13x_success;
604 break;
605
606 case 0x45: // IBM/MS lock/unlock drive
607 case 0x49: // IBM/MS extended media change
608 goto int13x_success; // Always success for HD
609 break;
610
611 case 0x46: // IBM/MS eject media
612 SET_AH(0xb2); // Volume Not Removable
613 goto int13x_fail_noah; // Always fail for HD
614 break;
615
616 case 0x48: // IBM/MS get drive parameters
617 if (edd_fill_dpt(DS :> (dpt_t *)SI, bios_dsk, device))
618 goto int13x_fail;
619 else
620 goto int13x_success;
621 break;
622
623 case 0x4e: // // IBM/MS set hardware configuration
624 // DMA, prefetch, PIO maximum not supported
625 switch (GET_AL()) {
626 case 0x01:
627 case 0x03:
628 case 0x04:
629 case 0x06:
630 goto int13x_success;
631 break;
632 default :
633 goto int13x_fail;
634 }
635 break;
636
637 case 0x50: // IBM/MS send packet command
638 default:
639 BX_INFO("%s: function %02xh unsupported, returns fail\n", __func__, GET_AH());
640 goto int13x_fail;
641 break;
642 }
643
644int13x_fail:
645 SET_AH(0x01); // defaults to invalid function in AH or invalid parameter
646int13x_fail_noah:
647 SET_DISK_RET_STATUS(GET_AH());
648 SET_CF(); // error occurred
649 return;
650
651int13x_success:
652 SET_AH(0x00); // no error
653int13x_success_noah:
654 SET_DISK_RET_STATUS(0x00);
655 CLEAR_CF(); // no error
656 return;
657}
658
659/* Avoid saving general registers already saved by caller (PUSHA). */
660#pragma aux int13_harddisk modify [di si cx dx bx];
661#pragma aux int13_harddisk_ext modify [di si cx dx bx];
662
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use