4 * Copyright 1995 Alexandre Julliard
20 #define DOS_GET_DRIVE(reg) ((reg) ? (reg) - 1 : DRIVE_GetCurrentDrive())
23 /* Structure for real-mode callbacks */
45 extern void do_mscdex( SIGCONTEXT *context );
47 /**********************************************************************
50 * Handler for int 31h (DPMI).
52 void INT_Int31Handler( SIGCONTEXT *context )
58 switch(AX_reg(context))
60 case 0x0000: /* Allocate LDT descriptors */
61 if (!(AX_reg(context) = AllocSelectorArray( CX_reg(context) )))
63 AX_reg(context) = 0x8011; /* descriptor unavailable */
68 case 0x0001: /* Free LDT descriptor */
69 if (FreeSelector( BX_reg(context) ))
71 AX_reg(context) = 0x8022; /* invalid selector */
76 /* If a segment register contains the selector being freed, */
78 if (!((DS_reg(context)^BX_reg(context)) & ~3)) DS_reg(context) = 0;
79 if (!((ES_reg(context)^BX_reg(context)) & ~3)) ES_reg(context) = 0;
81 if (!((FS_reg(context)^BX_reg(context)) & ~3)) FS_reg(context) = 0;
84 if (!((GS_reg(context)^BX_reg(context)) & ~3)) GS_reg(context) = 0;
89 case 0x0002: /* Real mode segment to descriptor */
91 WORD entryPoint = 0; /* KERNEL entry point for descriptor */
92 switch(BX_reg(context))
94 case 0x0000: entryPoint = 183; break; /* __0000H */
95 case 0x0040: entryPoint = 193; break; /* __0040H */
96 case 0xa000: entryPoint = 174; break; /* __A000H */
97 case 0xb000: entryPoint = 181; break; /* __B000H */
98 case 0xb800: entryPoint = 182; break; /* __B800H */
99 case 0xc000: entryPoint = 195; break; /* __C000H */
100 case 0xd000: entryPoint = 179; break; /* __D000H */
101 case 0xe000: entryPoint = 190; break; /* __E000H */
102 case 0xf000: entryPoint = 194; break; /* __F000H */
104 AX_reg(context) = DOSMEM_AllocSelector(BX_reg(context));
108 AX_reg(context) = LOWORD(MODULE_GetEntryPoint(
109 GetModuleHandle( "KERNEL" ),
114 case 0x0003: /* Get next selector increment */
115 AX_reg(context) = __AHINCR;
118 case 0x0004: /* Lock selector (not supported) */
119 AX_reg(context) = 0; /* FIXME: is this a correct return value? */
122 case 0x0005: /* Unlock selector (not supported) */
123 AX_reg(context) = 0; /* FIXME: is this a correct return value? */
126 case 0x0006: /* Get selector base address */
127 if (!(dw = GetSelectorBase( BX_reg(context) )))
129 AX_reg(context) = 0x8022; /* invalid selector */
134 CX_reg(context) = HIWORD(dw);
135 DX_reg(context) = LOWORD(dw);
139 case 0x0007: /* Set selector base address */
140 SetSelectorBase( BX_reg(context),
141 MAKELONG( DX_reg(context), CX_reg(context) ) );
144 case 0x0008: /* Set selector limit */
145 SetSelectorLimit( BX_reg(context),
146 MAKELONG( DX_reg(context), CX_reg(context) ) );
149 case 0x0009: /* Set selector access rights */
150 SelectorAccessRights( BX_reg(context), 1, CX_reg(context) );
153 case 0x000a: /* Allocate selector alias */
154 if (!(AX_reg(context) = AllocCStoDSAlias( BX_reg(context) )))
156 AX_reg(context) = 0x8011; /* descriptor unavailable */
161 case 0x000b: /* Get descriptor */
164 LDT_GetEntry( SELECTOR_TO_ENTRY( BX_reg(context) ), &entry );
165 /* FIXME: should use ES:EDI for 32-bit clients */
166 LDT_EntryToBytes( PTR_SEG_OFF_TO_LIN( ES_reg(context),
167 DI_reg(context) ), &entry );
171 case 0x000c: /* Set descriptor */
174 LDT_BytesToEntry( PTR_SEG_OFF_TO_LIN( ES_reg(context),
175 DI_reg(context) ), &entry );
176 LDT_GetEntry( SELECTOR_TO_ENTRY( BX_reg(context) ), &entry );
180 case 0x000d: /* Allocate specific LDT descriptor */
181 AX_reg(context) = 0x8011; /* descriptor unavailable */
185 case 0x0204: /* Get protected mode interrupt vector */
186 dw = (DWORD)INT_GetHandler( BL_reg(context) );
187 CX_reg(context) = HIWORD(dw);
188 DX_reg(context) = LOWORD(dw);
191 case 0x0205: /* Set protected mode interrupt vector */
192 INT_SetHandler( BL_reg(context),
193 (FARPROC16)PTR_SEG_OFF_TO_SEGPTR( CX_reg(context),
197 case 0x0300: /* Simulate real mode interrupt
198 * Interrupt number is in BL, flags are in BH
199 * ES:DI points to real-mode call structure
200 * Currently we just print it out and return error.
202 RESET_CFLAG(context);
204 REALMODECALL *p = (REALMODECALL *)PTR_SEG_OFF_TO_LIN( ES_reg(context), DI_reg(context) );
206 switch (BL_reg(context)) {
207 case 0x2f: /* int2f */
208 switch ((p->eax & 0xFF00)>>8) {
211 AX_reg(context) = p->eax & 0xFFFF;
212 do_mscdex( context );
219 case 0x21: /* int21 */
220 switch ((p->eax & 0xFF00)>>8) {
222 switch (p->eax & 0xFF) {
223 case 06:{/* get collate table */
224 extern DWORD DOSMEM_CollateTable;
226 /* ES:DI is a REALMODE pointer to 5 byte dosmem
227 * we fill that with 0x6, realmode pointer to collateTB
229 table = DOSMEM_RealMode2Linear(MAKELONG(p->edi,p->es));
230 *(BYTE*)table = 0x06;
231 *(DWORD*)(table+1) = DOSMEM_CollateTable;
233 CX_reg(context) = 258;/*FIXME: size of table?*/
241 switch (p->eax & 0xFF) {
242 case 0x0D:{/* generic block device request */
243 BYTE *dataptr = DOSMEM_RealMode2Linear((p->ds)*0x1000+(p->edx & 0xFFFF));
244 int drive = DOS_GET_DRIVE(p->ebx&0xFF);
246 if ((p->ecx & 0xFF00) != 0x0800) {
250 switch (p->ecx & 0xFF) {
253 char label[12],fsname[9],path[4];
256 strcpy(path,"x:\\");path[0]=drive+'A';
257 GetVolumeInformation32A(path,label,12,&serial,NULL,NULL,fsname,9);
259 memcpy(dataptr+2,&serial,4);
260 memcpy(dataptr+6,label ,11);
261 memcpy(dataptr+17,fsname,8);
264 case 0x60: /* get device parameters */
265 /* used by defrag.exe of win95 */
266 memset(dataptr, 0, 0x26);
268 dataptr[6] = 0; /* media type */
270 dataptr[1] = 0x05; /* fixed disk */
271 setword(&dataptr[2], 0x01); /* non removable */
272 setword(&dataptr[4], 0x300); /* # of cylinders */
274 dataptr[1] = 0x07; /* block dev, floppy */
275 setword(&dataptr[2], 0x02); /* removable */
276 setword(&dataptr[4], 80); /* # of cylinders */
278 CreateBPB(drive, &dataptr[7]);
299 if (EFL_reg(context)&1) {
301 "RealModeInt %02x: EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx\n"
302 " ESI=%08lx EDI=%08lx ES=%04x DS=%04x\n",
303 BL_reg(context), p->eax, p->ebx, p->ecx, p->edx,
304 p->esi, p->edi, p->es, p->ds
309 case 0x0301: /* Call real mode procedure with far return */
311 REALMODECALL *p = (REALMODECALL *)PTR_SEG_OFF_TO_LIN( ES_reg(context), DI_reg(context) );
313 "RealModeCall: EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx\n"
314 " ESI=%08lx EDI=%08lx ES=%04x DS=%04x CS:IP=%04x:%04x\n",
315 p->eax, p->ebx, p->ecx, p->edx,
316 p->esi, p->edi, p->es, p->ds, p->cs, p->ip );
321 case 0x0302: /* Call real mode procedure with interrupt return */
323 REALMODECALL *p = (REALMODECALL *)PTR_SEG_OFF_TO_LIN( ES_reg(context), DI_reg(context) );
325 "RealModeCallIret: EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx\n"
326 " ESI=%08lx EDI=%08lx ES=%04x DS=%04x CS:IP=%04x:%04x\n",
327 p->eax, p->ebx, p->ecx, p->edx,
328 p->esi, p->edi, p->es, p->ds, p->cs, p->ip );
333 case 0x0303: /* Allocate Real Mode Callback Address */
335 REALMODECALL *p = (REALMODECALL *)PTR_SEG_OFF_TO_LIN( ES_reg(context), DI_reg(context) );
337 "AllocRMCB: EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx\n"
338 " ESI=%08lx EDI=%08lx ES=%04x DS=%04x CS:IP=%04x:%04x\n"
339 " Function to call: %04x:%04x\n",
340 p->eax, p->ebx, p->ecx, p->edx,
341 p->esi, p->edi, p->es, p->ds, p->cs, p->ip,
342 DS_reg(context),SI_reg(context)
348 case 0x0400: /* Get DPMI version */
349 AX_reg(context) = 0x005a; /* DPMI version 0.90 */
350 BX_reg(context) = 0x0005; /* Flags: 32-bit, virtual memory */
351 CL_reg(context) = runtime_cpu ();
352 DX_reg(context) = 0x0102; /* Master/slave interrupt controller base*/
355 case 0x0500: /* Get free memory information */
356 ptr = (BYTE *)PTR_SEG_OFF_TO_LIN( ES_reg(context), DI_reg(context) );
357 *(DWORD *)ptr = 0x00ff0000; /* Largest block available */
358 memset( ptr + 4, 0xff, 0x2c ); /* No other information supported */
361 case 0x0501: /* Allocate memory block */
362 if (!(ptr = (BYTE *)HeapAlloc( SystemHeap, 0,MAKELONG( CX_reg(context),
365 AX_reg(context) = 0x8012; /* linear memory not available */
370 BX_reg(context) = SI_reg(context) = HIWORD(ptr);
371 CX_reg(context) = DI_reg(context) = LOWORD(ptr);
375 case 0x0502: /* Free memory block */
376 HeapFree( SystemHeap, 0,
377 (void *)MAKELONG( DI_reg(context), SI_reg(context) ) );
380 case 0x0503: /* Resize memory block */
381 if (!(ptr = (BYTE *)HeapReAlloc( SystemHeap, 0,
382 (void *)MAKELONG(DI_reg(context),SI_reg(context)),
383 MAKELONG(CX_reg(context),BX_reg(context)))))
385 AX_reg(context) = 0x8012; /* linear memory not available */
390 BX_reg(context) = SI_reg(context) = HIWORD(ptr);
391 CX_reg(context) = DI_reg(context) = LOWORD(ptr);
395 case 0x0600: /* Lock linear region */
396 break; /* Just ignore it */
398 case 0x0601: /* Unlock linear region */
399 break; /* Just ignore it */
401 case 0x0602: /* Unlock real-mode region */
402 break; /* Just ignore it */
404 case 0x0603: /* Lock real-mode region */
405 break; /* Just ignore it */
407 case 0x0604: /* Get page size */
409 CX_reg(context) = 4096;
412 case 0x0702: /* Mark page as demand-paging candidate */
413 break; /* Just ignore it */
415 case 0x0703: /* Discard page contents */
416 break; /* Just ignore it */
419 INT_BARF( context, 0x31 );
420 AX_reg(context) = 0x8001; /* unsupported function */