Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1 | /* |
| 2 | * BIOS interrupt 13h handler |
| 3 | */ |
| 4 | |
Alexandre Julliard | 7e50df3 | 1994-08-06 11:22:41 +0000 | [diff] [blame] | 5 | #include <stdlib.h> |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 6 | #include <unistd.h> |
| 7 | #include <sys/types.h> |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 8 | #include <sys/ioctl.h> |
| 9 | #include <fcntl.h> |
| 10 | #ifdef linux |
Marcus Meissner | 3f1ed52 | 2001-05-14 20:09:37 +0000 | [diff] [blame] | 11 | # include <linux/fd.h> |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 12 | #endif |
Alexandre Julliard | 234bc24 | 1994-12-10 13:02:28 +0000 | [diff] [blame] | 13 | #include "miscemu.h" |
Alexandre Julliard | aca0578 | 1994-10-17 18:12:41 +0000 | [diff] [blame] | 14 | /* #define DEBUG_INT */ |
Alexandre Julliard | 61fece0 | 1999-06-26 19:09:08 +0000 | [diff] [blame] | 15 | #include "debugtools.h" |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 16 | #include "drive.h" |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 17 | |
Dimitrie O. Paun | 529da54 | 2000-11-27 23:54:25 +0000 | [diff] [blame] | 18 | DEFAULT_DEBUG_CHANNEL(int); |
Patrik Stridvall | b4b9fae | 1999-04-19 14:56:29 +0000 | [diff] [blame] | 19 | |
Alexandre Julliard | e2991ea | 1995-07-29 13:09:43 +0000 | [diff] [blame] | 20 | /********************************************************************** |
Patrik Stridvall | 3ca9823 | 2001-06-20 23:03:14 +0000 | [diff] [blame] | 21 | * INT_Int13Handler (WPROCS.119) |
Alexandre Julliard | e2991ea | 1995-07-29 13:09:43 +0000 | [diff] [blame] | 22 | * |
| 23 | * Handler for int 13h (disk I/O). |
| 24 | */ |
Alexandre Julliard | 617955d | 1999-06-26 18:40:24 +0000 | [diff] [blame] | 25 | void WINAPI INT_Int13Handler( CONTEXT86 *context ) |
Alexandre Julliard | e2991ea | 1995-07-29 13:09:43 +0000 | [diff] [blame] | 26 | { |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 27 | switch(AH_reg(context)) |
Alexandre Julliard | e2991ea | 1995-07-29 13:09:43 +0000 | [diff] [blame] | 28 | { |
Alexandre Julliard | 7e50df3 | 1994-08-06 11:22:41 +0000 | [diff] [blame] | 29 | case 0x00: /* RESET DISK SYSTEM */ |
Joseph Pranevich | f217cf5 | 1998-10-24 10:35:11 +0000 | [diff] [blame] | 30 | break; /* no return ? */ |
| 31 | case 0x01: /* STATUS OF DISK SYSTEM */ |
| 32 | AL_reg(context) = 0; /* successful completion */ |
| 33 | break; |
| 34 | case 0x02: /* READ SECTORS INTO MEMORY */ |
| 35 | AL_reg(context) = 0; /* number of sectors read */ |
| 36 | AH_reg(context) = 0; /* status */ |
| 37 | break; |
| 38 | case 0x03: /* WRITE SECTORS FROM MEMORY */ |
| 39 | break; /* no return ? */ |
Alexandre Julliard | 7e50df3 | 1994-08-06 11:22:41 +0000 | [diff] [blame] | 40 | case 0x04: /* VERIFY DISK SECTOR(S) */ |
Joseph Pranevich | f217cf5 | 1998-10-24 10:35:11 +0000 | [diff] [blame] | 41 | AL_reg(context) = 0; /* number of sectors verified */ |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 42 | AH_reg(context) = 0; |
Alexandre Julliard | 7e50df3 | 1994-08-06 11:22:41 +0000 | [diff] [blame] | 43 | break; |
| 44 | |
| 45 | case 0x05: /* FORMAT TRACK */ |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 46 | case 0x06: /* FORMAT TRACK AND SET BAD SECTOR FLAGS */ |
| 47 | case 0x07: /* FORMAT DRIVE STARTING AT GIVEN TRACK */ |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 48 | /* despite what Ralf Brown says, 0x06 and 0x07 seem to |
| 49 | * set CFLAG, too (at least my BIOS does that) */ |
| 50 | AH_reg(context) = 0x0c; |
| 51 | SET_CFLAG(context); |
| 52 | break; |
Alexandre Julliard | 7e50df3 | 1994-08-06 11:22:41 +0000 | [diff] [blame] | 53 | |
Alexandre Julliard | 7e50df3 | 1994-08-06 11:22:41 +0000 | [diff] [blame] | 54 | case 0x08: /* GET DRIVE PARAMETERS */ |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 55 | if (DL_reg(context) & 0x80) { /* hard disk ? */ |
| 56 | AH_reg(context) = 0x07; |
| 57 | SET_CFLAG(context); |
| 58 | } |
| 59 | else { /* floppy disk */ |
| 60 | #ifdef linux |
| 61 | unsigned int i, nr_of_drives = 0; |
| 62 | BYTE drive_nr = DL_reg(context); |
| 63 | int floppy_fd; |
| 64 | struct floppy_drive_params floppy_parm; |
Alexandre Julliard | bf67259 | 2000-12-12 00:44:42 +0000 | [diff] [blame] | 65 | char root[] = "A:\\"; |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 66 | |
| 67 | AH_reg(context) = 0x00; /* success */ |
| 68 | |
Alexandre Julliard | bf67259 | 2000-12-12 00:44:42 +0000 | [diff] [blame] | 69 | for (i = 0; i < MAX_DOS_DRIVES; i++, root[0]++) |
| 70 | if (GetDriveTypeA(root) == DRIVE_REMOVABLE) nr_of_drives++; |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 71 | DL_reg(context) = nr_of_drives; |
| 72 | |
| 73 | if (drive_nr > 1) { /* invalid drive ? */ |
| 74 | BX_reg(context) = 0; |
| 75 | CX_reg(context) = 0; |
| 76 | DH_reg(context) = 0; |
| 77 | break; |
| 78 | } |
| 79 | |
| 80 | if ( (floppy_fd = DRIVE_OpenDevice( drive_nr, O_NONBLOCK)) == -1) |
| 81 | { |
Alexandre Julliard | 61fece0 | 1999-06-26 19:09:08 +0000 | [diff] [blame] | 82 | WARN("(GET DRIVE PARAMETERS): Can't determine floppy geometry !\n"); |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 83 | BX_reg(context) = 0; |
| 84 | CX_reg(context) = 0; |
| 85 | DH_reg(context) = 0; |
| 86 | break; |
| 87 | } |
| 88 | ioctl(floppy_fd, FDGETDRVPRM, &floppy_parm); |
| 89 | close(floppy_fd); |
| 90 | |
| 91 | BL_reg(context) = floppy_parm.cmos; |
| 92 | |
| 93 | /* CH = low eight bits of max cyl |
| 94 | CL = max sec nr (bits 5-0), |
| 95 | hi two bits of max cyl (bits 7-6) |
| 96 | DH = max head nr */ |
| 97 | DH_reg(context) = 0x01; |
| 98 | switch (BL_reg(context)) |
| 99 | { |
| 100 | case 0: /* no drive */ |
| 101 | CX_reg(context) = 0x0; |
| 102 | DX_reg(context) = 0x0; |
| 103 | break; |
| 104 | case 1: /* 360 K */ |
| 105 | CX_reg(context) = 0x2709; |
| 106 | break; |
| 107 | case 2: /* 1.2 M */ |
| 108 | CX_reg(context) = 0x4f0f; |
| 109 | break; |
| 110 | case 3: /* 720 K */ |
| 111 | CX_reg(context) = 0x4f09; |
| 112 | break; |
| 113 | case 4: /* 1.44 M */ |
| 114 | CX_reg(context) = 0x4f12; |
| 115 | break; |
| 116 | case 5: |
| 117 | case 6: /* 2.88 M */ |
| 118 | CX_reg(context) = 0x4f24; |
| 119 | break; |
| 120 | } |
Alexandre Julliard | d8fab2e | 2000-09-25 23:53:07 +0000 | [diff] [blame] | 121 | context->SegEs = 0x0000; /* FIXME: drive parameter table */ |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 122 | DI_reg(context) = 0x0000; |
| 123 | #else |
| 124 | AH_reg(context) = 0x01; |
| 125 | SET_CFLAG(context); |
| 126 | break; |
| 127 | #endif |
| 128 | } |
Alexandre Julliard | 7e50df3 | 1994-08-06 11:22:41 +0000 | [diff] [blame] | 129 | break; |
| 130 | |
| 131 | case 0x09: /* INITIALIZE CONTROLLER WITH DRIVE PARAMETERS */ |
Joseph Pranevich | f217cf5 | 1998-10-24 10:35:11 +0000 | [diff] [blame] | 132 | case 0x0a: /* FIXED DISK - READ LONG (XT,AT,XT286,PS) */ |
| 133 | case 0x0b: /* FIXED DISK - WRITE LONG (XT,AT,XT286,PS) */ |
Alexandre Julliard | 7e50df3 | 1994-08-06 11:22:41 +0000 | [diff] [blame] | 134 | case 0x0c: /* SEEK TO CYLINDER */ |
Joseph Pranevich | f217cf5 | 1998-10-24 10:35:11 +0000 | [diff] [blame] | 135 | case 0x0d: /* ALTERNATE RESET HARD DISKS */ |
Alexandre Julliard | 7e50df3 | 1994-08-06 11:22:41 +0000 | [diff] [blame] | 136 | case 0x10: /* CHECK IF DRIVE READY */ |
| 137 | case 0x11: /* RECALIBRATE DRIVE */ |
| 138 | case 0x14: /* CONTROLLER INTERNAL DIAGNOSTIC */ |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 139 | AH_reg(context) = 0; |
Alexandre Julliard | 7e50df3 | 1994-08-06 11:22:41 +0000 | [diff] [blame] | 140 | break; |
| 141 | |
Joseph Pranevich | f217cf5 | 1998-10-24 10:35:11 +0000 | [diff] [blame] | 142 | case 0x15: /* GET DISK TYPE (AT,XT2,XT286,CONV,PS) */ |
| 143 | if (DL_reg(context) & 0x80) { /* hard disk ? */ |
| 144 | AH_reg(context) = 3; /* fixed disk */ |
| 145 | SET_CFLAG(context); |
| 146 | } |
| 147 | else { /* floppy disk ? */ |
| 148 | AH_reg(context) = 2; /* floppy with change detection */ |
| 149 | SET_CFLAG(context); |
| 150 | } |
| 151 | break; |
Alexandre Julliard | 7e50df3 | 1994-08-06 11:22:41 +0000 | [diff] [blame] | 152 | case 0x0e: /* READ SECTOR BUFFER (XT only) */ |
| 153 | case 0x0f: /* WRITE SECTOR BUFFER (XT only) */ |
| 154 | case 0x12: /* CONTROLLER RAM DIAGNOSTIC (XT,PS) */ |
| 155 | case 0x13: /* DRIVE DIAGNOSTIC (XT,PS) */ |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 156 | AH_reg(context) = 0x01; |
| 157 | SET_CFLAG(context); |
Alexandre Julliard | 7e50df3 | 1994-08-06 11:22:41 +0000 | [diff] [blame] | 158 | break; |
| 159 | |
Joseph Pranevich | f217cf5 | 1998-10-24 10:35:11 +0000 | [diff] [blame] | 160 | case 0x16: /* FLOPPY - CHANGE OF DISK STATUS */ |
| 161 | AH_reg(context) = 0; /* FIXME - no change */ |
| 162 | break; |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 163 | case 0x17: /* SET DISK TYPE FOR FORMAT */ |
| 164 | if (DL_reg(context) < 4) |
| 165 | AH_reg(context) = 0x00; /* successful completion */ |
| 166 | else |
| 167 | AH_reg(context) = 0x01; /* error */ |
| 168 | break; |
Joseph Pranevich | f217cf5 | 1998-10-24 10:35:11 +0000 | [diff] [blame] | 169 | case 0x18: /* SET MEDIA TYPE FOR FORMAT */ |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 170 | if (DL_reg(context) < 4) |
| 171 | AH_reg(context) = 0x00; /* successful completion */ |
| 172 | else |
| 173 | AH_reg(context) = 0x01; /* error */ |
| 174 | break; |
Joseph Pranevich | f217cf5 | 1998-10-24 10:35:11 +0000 | [diff] [blame] | 175 | case 0x19: /* FIXED DISK - PARK HEADS */ |
Alexandre Julliard | 7e50df3 | 1994-08-06 11:22:41 +0000 | [diff] [blame] | 176 | default: |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 177 | INT_BARF( context, 0x13 ); |
Alexandre Julliard | e2991ea | 1995-07-29 13:09:43 +0000 | [diff] [blame] | 178 | } |
Alexandre Julliard | 7e50df3 | 1994-08-06 11:22:41 +0000 | [diff] [blame] | 179 | } |