VirtualBox

source: vbox/trunk/src/VBox/Devices/PC/BIOS-new/disk.c@ 38699

Last change on this file since 38699 was 38699, checked in by vboxsync, 13 years ago

Converted system BIOS to Watcom C.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use