Added RtlAllocateAndInitializeSid entry.
[wine] / msdos / int13.c
1 /*
2  * BIOS interrupt 13h handler
3  */
4
5 #include <stdlib.h>
6 #include <unistd.h>
7 #include <sys/types.h>
8 #include <sys/stat.h>
9 #include <sys/ioctl.h>
10 #include <fcntl.h>
11 #ifdef linux
12 #include <linux/fd.h>
13 #endif
14 #include "miscemu.h"
15 /* #define DEBUG_INT */
16 #include "debug.h"
17 #include "drive.h"
18
19 /**********************************************************************
20  *          INT_Int13Handler
21  *
22  * Handler for int 13h (disk I/O).
23  */
24 void WINAPI INT_Int13Handler( CONTEXT *context )
25 {
26     switch(AH_reg(context))
27     {
28         case 0x00:                            /* RESET DISK SYSTEM     */
29         case 0x04:                            /* VERIFY DISK SECTOR(S) */
30                 AH_reg(context) = 0;
31                 break;
32                
33         case 0x05:                                     /* FORMAT TRACK */
34         case 0x06:             /* FORMAT TRACK AND SET BAD SECTOR FLAGS */
35         case 0x07:             /* FORMAT DRIVE STARTING AT GIVEN TRACK  */
36             /* despite what Ralf Brown says, 0x06 and 0x07 seem to
37              * set CFLAG, too (at least my BIOS does that) */
38             AH_reg(context) = 0x0c;
39             SET_CFLAG(context);
40             break;
41
42         case 0x08:                              /* GET DRIVE PARAMETERS  */
43                 if (DL_reg(context) & 0x80) { /* hard disk ? */
44                         AH_reg(context) = 0x07;
45                         SET_CFLAG(context);
46                 }
47                 else { /* floppy disk */
48 #ifdef linux
49                         unsigned int i, nr_of_drives = 0;                       
50                         BYTE drive_nr = DL_reg(context);
51                         int floppy_fd;
52                         struct floppy_drive_params floppy_parm;
53
54                         AH_reg(context) = 0x00; /* success */
55
56                         for (i = 0; i < MAX_DOS_DRIVES; i++)
57                         if (DRIVE_GetType(i) == TYPE_FLOPPY) nr_of_drives++;
58                         DL_reg(context) = nr_of_drives;
59
60                         if (drive_nr > 1) { /* invalid drive ? */
61                                 BX_reg(context) = 0;
62                                 CX_reg(context) = 0;
63                                 DH_reg(context) = 0;
64                                 break;
65                         }
66
67                         if ( (floppy_fd = DRIVE_OpenDevice( drive_nr, O_NONBLOCK)) == -1)
68                         {
69                                 WARN(int, "(GET DRIVE PARAMETERS): Can't determine floppy geometry !\n");
70                                 BX_reg(context) = 0;
71                                 CX_reg(context) = 0;
72                                 DH_reg(context) = 0;
73                                 break;
74                         }
75                         ioctl(floppy_fd, FDGETDRVPRM, &floppy_parm);
76                         close(floppy_fd);
77
78                         BL_reg(context) = floppy_parm.cmos;
79
80                         /* CH = low eight bits of max cyl
81                            CL = max sec nr (bits 5-0),
82                            hi two bits of max cyl (bits 7-6)
83                            DH = max head nr */ 
84                         DH_reg(context) = 0x01;
85                         switch (BL_reg(context))
86                         {
87                             case 0: /* no drive */
88                                 CX_reg(context) = 0x0;
89                                 DX_reg(context) = 0x0;
90                                 break;
91                             case 1: /* 360 K */
92                                 CX_reg(context) = 0x2709;
93                                 break;
94                             case 2: /* 1.2 M */
95                                 CX_reg(context) = 0x4f0f;
96                                 break;
97                             case 3: /* 720 K */
98                                 CX_reg(context) = 0x4f09;
99                                 break;
100                             case 4: /* 1.44 M */
101                                 CX_reg(context) = 0x4f12;
102                                 break;
103                             case 5:
104                             case 6: /* 2.88 M */
105                                 CX_reg(context) = 0x4f24;
106                                 break;
107                         }
108                         ES_reg(context) = 0x0000; /* FIXME: drive parameter table */
109                         DI_reg(context) = 0x0000;
110 #else
111                         AH_reg(context) = 0x01;
112                         SET_CFLAG(context);
113                         break;
114 #endif
115                 }
116                 break;
117
118         case 0x09:         /* INITIALIZE CONTROLLER WITH DRIVE PARAMETERS */
119         case 0x0c:         /* SEEK TO CYLINDER                            */
120         case 0x0d:         /* RESET HARD DISKS                            */
121         case 0x10:         /* CHECK IF DRIVE READY                        */
122         case 0x11:         /* RECALIBRATE DRIVE                           */
123         case 0x14:         /* CONTROLLER INTERNAL DIAGNOSTIC              */
124                 AH_reg(context) = 0;
125                 break;
126
127         case 0x0e:                    /* READ SECTOR BUFFER (XT only)      */
128         case 0x0f:                    /* WRITE SECTOR BUFFER (XT only)     */
129         case 0x12:                    /* CONTROLLER RAM DIAGNOSTIC (XT,PS) */
130         case 0x13:                    /* DRIVE DIAGNOSTIC (XT,PS)          */
131                 AH_reg(context) = 0x01;
132                 SET_CFLAG(context);
133                 break;
134
135         case 0x17:         /* SET DISK TYPE FOR FORMAT */
136                 if (DL_reg(context) < 4)
137                     AH_reg(context) = 0x00; /* successful completion */
138                 else
139                     AH_reg(context) = 0x01; /* error */
140                 break;
141         case 0x18:
142                 if (DL_reg(context) < 4)
143                     AH_reg(context) = 0x00; /* successful completion */
144                 else
145                     AH_reg(context) = 0x01; /* error */
146                 break;
147         default:
148                 INT_BARF( context, 0x13 );
149     }
150 }