2 * BIOS interrupt 13h handler
4 * Copyright 1997 Andreas Mohr
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include <sys/types.h>
29 #ifdef HAVE_SYS_IOCTL_H
30 # include <sys/ioctl.h>
34 #ifdef HAVE_LINUX_COMPILER_H
35 #include <linux/compiler.h>
37 # include <linux/fd.h>
41 #include "wine/server.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(int);
48 * Status of last int13 operation.
50 static BYTE INT13_last_status
;
53 /**********************************************************************
56 * Write status to AH register and set carry flag on error (AH != 0).
58 * Despite what Ralf Brown says, at least functions 0x06 and 0x07
59 * seem to set carry, too.
61 static void INT13_SetStatus( CONTEXT
*context
, BYTE status
)
63 INT13_last_status
= status
;
65 SET_AH( context
, status
);
70 RESET_CFLAG( context
);
74 /**********************************************************************
75 * INT13_ReadFloppyParams
77 * Read floppy disk parameters.
79 static void INT13_ReadFloppyParams( CONTEXT
*context
)
82 static const BYTE floppy_params
[2][13] =
84 { 0xaf, 0x02, 0x25, 0x02, 0x12, 0x1b, 0xff, 0x6c, 0xf6, 0x0f, 0x08 },
85 { 0xaf, 0x02, 0x25, 0x02, 0x12, 0x1b, 0xff, 0x6c, 0xf6, 0x0f, 0x08 }
88 static const DWORD drive_type_info
[7]={
99 unsigned int nr_of_drives
= 0;
100 BYTE drive_nr
= DL_reg( context
);
103 struct floppy_drive_params floppy_parm
;
104 WCHAR root
[] = {'A',':','\\',0}, drive_root
[] = {'\\','\\','.','\\','A',':',0};
107 TRACE("in [ EDX=%08x ]\n", context
->Edx
);
109 SET_AL( context
, 0 );
110 SET_BX( context
, 0 );
111 SET_CX( context
, 0 );
112 SET_DH( context
, 0 );
114 for (i
= 0; i
< MAX_DOS_DRIVES
; i
++, root
[0]++)
115 if (GetDriveTypeW(root
) == DRIVE_REMOVABLE
) nr_of_drives
++;
116 SET_DL( context
, nr_of_drives
);
119 /* invalid drive ? */
120 INT13_SetStatus( context
, 0x07 ); /* drive parameter activity failed */
124 drive_root
[4] = 'A' + drive_nr
;
125 h
= CreateFileW(drive_root
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
,
126 FILE_FLAG_BACKUP_SEMANTICS
, NULL
);
127 if (h
== INVALID_HANDLE_VALUE
||
128 wine_server_handle_to_fd(h
, FILE_READ_DATA
, &floppy_fd
, NULL
))
130 WARN("Can't determine floppy geometry !\n");
131 INT13_SetStatus( context
, 0x07 ); /* drive parameter activity failed */
134 r
= ioctl(floppy_fd
, FDGETDRVPRM
, &floppy_parm
);
135 wine_server_release_fd( h
, floppy_fd
);
140 INT13_SetStatus( context
, 0x07 ); /* drive parameter activity failed */
144 SET_BL( context
, floppy_parm
.cmos
);
147 * CH = low eight bits of max cyl
148 * CL = max sec nr (bits 5-0),
149 * hi two bits of max cyl (bits 7-6)
152 if(BL_reg( context
) && BL_reg( context
) < 7)
154 SET_DH( context
, 0x01 );
155 SET_CX( context
, drive_type_info
[BL_reg( context
)] );
158 context
->Edi
= (DWORD
)floppy_params
[drive_nr
];
162 ERR("Get floppy params failed for drive %d\n", drive_nr
);
163 INT13_SetStatus( context
, 0x07 ); /* drive parameter activity failed */
167 TRACE("out [ EAX=%08x EBX=%08x ECX=%08x EDX=%08x EDI=%08x ]\n",
168 context
->Eax
, context
->Ebx
, context
->Ecx
, context
->Edx
, context
->Edi
);
170 INT13_SetStatus( context
, 0x00 ); /* success */
172 /* FIXME: Word exits quietly if we return with no error. Why? */
173 FIXME("Returned ERROR!\n");
174 SET_CFLAG( context
);
177 INT13_SetStatus( context
, 0x01 ); /* invalid function */
182 /**********************************************************************
185 * Handler for int 13h (disk I/O).
187 void WINAPI
DOSVM_Int13Handler( CONTEXT
*context
)
189 TRACE( "AH=%02x\n", AH_reg( context
) );
191 switch( AH_reg( context
) )
193 case 0x00: /* RESET DISK SYSTEM */
194 INT13_SetStatus( context
, 0x00 ); /* success */
197 case 0x01: /* STATUS OF DISK SYSTEM */
198 INT13_SetStatus( context
, INT13_last_status
);
201 case 0x02: /* READ SECTORS INTO MEMORY */
202 SET_AL( context
, 0 ); /* number of sectors transferred */
203 INT13_SetStatus( context
, 0x00 ); /* success */
206 case 0x03: /* WRITE SECTORS FROM MEMORY */
207 SET_AL( context
, 0 ); /* number of sectors transferred */
208 INT13_SetStatus( context
, 0x00 ); /* success */
211 case 0x04: /* VERIFY DISK SECTOR(S) */
212 SET_AL( context
, 0 ); /* number of sectors verified */
213 INT13_SetStatus( context
, 0x00 ); /* success */
216 case 0x05: /* FORMAT TRACK */
217 case 0x06: /* FORMAT TRACK AND SET BAD SECTOR FLAGS */
218 case 0x07: /* FORMAT DRIVE STARTING AT GIVEN TRACK */
219 INT13_SetStatus( context
, 0x0c ); /* unsupported track or invalid media */
222 case 0x08: /* GET DRIVE PARAMETERS */
223 if (DL_reg( context
) & 0x80)
226 INT13_SetStatus( context
, 0x07 ); /* drive parameter activity failed */
231 INT13_ReadFloppyParams( context
);
235 case 0x09: /* INITIALIZE CONTROLLER WITH DRIVE PARAMETERS */
236 case 0x0a: /* FIXED DISK - READ LONG */
237 case 0x0b: /* FIXED DISK - WRITE LONG */
238 case 0x0c: /* SEEK TO CYLINDER */
239 case 0x0d: /* ALTERNATE RESET HARD DISK */
240 INT13_SetStatus( context
, 0x00 ); /* success */
243 case 0x0e: /* READ SECTOR BUFFER */
244 case 0x0f: /* WRITE SECTOR BUFFER */
245 INT13_SetStatus( context
, 0x01 ); /* invalid function */
248 case 0x10: /* CHECK IF DRIVE READY */
249 case 0x11: /* RECALIBRATE DRIVE */
250 INT13_SetStatus( context
, 0x00 ); /* success */
253 case 0x12: /* CONTROLLER RAM DIAGNOSTIC */
254 case 0x13: /* DRIVE DIAGNOSTIC */
255 INT13_SetStatus( context
, 0x01 ); /* invalid function */
258 case 0x14: /* CONTROLLER INTERNAL DIAGNOSTIC */
259 INT13_SetStatus( context
, 0x00 ); /* success */
262 case 0x15: /* GET DISK TYPE */
263 if (DL_reg( context
) & 0x80)
266 INT13_SetStatus( context
, 0x00 ); /* success */
267 /* type is fixed disk, overwrites status */
268 SET_AH( context
, 0x03 );
273 INT13_SetStatus( context
, 0x00 ); /* success */
274 /* type is floppy with change detection, overwrites status */
275 SET_AH( context
, 0x02 );
279 case 0x16: /* FLOPPY - CHANGE OF DISK STATUS */
280 INT13_SetStatus( context
, 0x00 ); /* success */
283 case 0x17: /* SET DISK TYPE FOR FORMAT */
284 if (DL_reg( context
) < 4)
285 INT13_SetStatus( context
, 0x00 ); /* successful completion */
287 INT13_SetStatus( context
, 0x01 ); /* error */
290 case 0x18: /* SET MEDIA TYPE FOR FORMAT */
291 if (DL_reg( context
) < 4)
292 INT13_SetStatus( context
, 0x00 ); /* success */
294 INT13_SetStatus( context
, 0x01 ); /* error */
297 case 0x19: /* FIXED DISK - PARK HEADS */
298 INT13_SetStatus( context
, 0x00 ); /* success */
302 INT_BARF( context
, 0x13 );
303 INT13_SetStatus( context
, 0x01 ); /* invalid function */