VirtualBox

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

Last change on this file since 78571 was 78571, checked in by vboxsync, 6 years ago

DevACPI: First check input, then take a lock.

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette