4 * Copyright 1995 Alexandre Julliard
21 #define DOS_GET_DRIVE(reg) ((reg) ? (reg) - 1 : DRIVE_GetCurrentDrive())
24 /* Structure for real-mode callbacks */
46 extern void do_mscdex( SIGCONTEXT
*context
);
48 /**********************************************************************
51 * Handler for int 31h (DPMI).
53 void INT_Int31Handler( SIGCONTEXT
*context
)
59 switch(AX_reg(context
))
61 case 0x0000: /* Allocate LDT descriptors */
62 if (!(AX_reg(context
) = AllocSelectorArray( CX_reg(context
) )))
64 AX_reg(context
) = 0x8011; /* descriptor unavailable */
69 case 0x0001: /* Free LDT descriptor */
70 if (FreeSelector( BX_reg(context
) ))
72 AX_reg(context
) = 0x8022; /* invalid selector */
77 /* If a segment register contains the selector being freed, */
79 if (!((DS_reg(context
)^BX_reg(context
)) & ~3)) DS_reg(context
) = 0;
80 if (!((ES_reg(context
)^BX_reg(context
)) & ~3)) ES_reg(context
) = 0;
82 if (!((FS_reg(context
)^BX_reg(context
)) & ~3)) FS_reg(context
) = 0;
85 if (!((GS_reg(context
)^BX_reg(context
)) & ~3)) GS_reg(context
) = 0;
90 case 0x0002: /* Real mode segment to descriptor */
92 WORD entryPoint
= 0; /* KERNEL entry point for descriptor */
93 switch(BX_reg(context
))
95 case 0x0000: entryPoint
= 183; break; /* __0000H */
96 case 0x0040: entryPoint
= 193; break; /* __0040H */
97 case 0xa000: entryPoint
= 174; break; /* __A000H */
98 case 0xb000: entryPoint
= 181; break; /* __B000H */
99 case 0xb800: entryPoint
= 182; break; /* __B800H */
100 case 0xc000: entryPoint
= 195; break; /* __C000H */
101 case 0xd000: entryPoint
= 179; break; /* __D000H */
102 case 0xe000: entryPoint
= 190; break; /* __E000H */
103 case 0xf000: entryPoint
= 194; break; /* __F000H */
105 AX_reg(context
) = DOSMEM_AllocSelector(BX_reg(context
));
109 AX_reg(context
) = LOWORD(MODULE_GetEntryPoint(
110 GetModuleHandle( "KERNEL" ),
115 case 0x0003: /* Get next selector increment */
116 AX_reg(context
) = __AHINCR
;
119 case 0x0004: /* Lock selector (not supported) */
120 AX_reg(context
) = 0; /* FIXME: is this a correct return value? */
123 case 0x0005: /* Unlock selector (not supported) */
124 AX_reg(context
) = 0; /* FIXME: is this a correct return value? */
127 case 0x0006: /* Get selector base address */
128 if (!(dw
= GetSelectorBase( BX_reg(context
) )))
130 AX_reg(context
) = 0x8022; /* invalid selector */
135 CX_reg(context
) = HIWORD(dw
);
136 DX_reg(context
) = LOWORD(dw
);
140 case 0x0007: /* Set selector base address */
141 SetSelectorBase( BX_reg(context
),
142 MAKELONG( DX_reg(context
), CX_reg(context
) ) );
145 case 0x0008: /* Set selector limit */
146 SetSelectorLimit( BX_reg(context
),
147 MAKELONG( DX_reg(context
), CX_reg(context
) ) );
150 case 0x0009: /* Set selector access rights */
151 SelectorAccessRights( BX_reg(context
), 1, CX_reg(context
) );
154 case 0x000a: /* Allocate selector alias */
155 if (!(AX_reg(context
) = AllocCStoDSAlias( BX_reg(context
) )))
157 AX_reg(context
) = 0x8011; /* descriptor unavailable */
162 case 0x000b: /* Get descriptor */
165 LDT_GetEntry( SELECTOR_TO_ENTRY( BX_reg(context
) ), &entry
);
166 /* FIXME: should use ES:EDI for 32-bit clients */
167 LDT_EntryToBytes( PTR_SEG_OFF_TO_LIN( ES_reg(context
),
168 DI_reg(context
) ), &entry
);
172 case 0x000c: /* Set descriptor */
175 LDT_BytesToEntry( PTR_SEG_OFF_TO_LIN( ES_reg(context
),
176 DI_reg(context
) ), &entry
);
177 LDT_GetEntry( SELECTOR_TO_ENTRY( BX_reg(context
) ), &entry
);
181 case 0x000d: /* Allocate specific LDT descriptor */
182 AX_reg(context
) = 0x8011; /* descriptor unavailable */
185 case 0x0200: /* get real mode interrupt vector */
187 "int31: get realmode interupt vector(0x%02x) unimplemented.\n",
192 case 0x0201: /* set real mode interrupt vector */
194 "int31: set realmode interupt vector(0x%02x,0x%04x:0x%04x) unimplemented\n",
195 BL_reg(context
),CX_reg(context
),DX_reg(context
)
199 case 0x0204: /* Get protected mode interrupt vector */
200 dw
= (DWORD
)INT_GetHandler( BL_reg(context
) );
201 CX_reg(context
) = HIWORD(dw
);
202 DX_reg(context
) = LOWORD(dw
);
205 case 0x0205: /* Set protected mode interrupt vector */
206 INT_SetHandler( BL_reg(context
),
207 (FARPROC16
)PTR_SEG_OFF_TO_SEGPTR( CX_reg(context
),
211 case 0x0300: /* Simulate real mode interrupt
212 * Interrupt number is in BL, flags are in BH
213 * ES:DI points to real-mode call structure
214 * Currently we just print it out and return error.
216 RESET_CFLAG(context
);
218 REALMODECALL
*p
= (REALMODECALL
*)PTR_SEG_OFF_TO_LIN( ES_reg(context
), DI_reg(context
) );
220 switch (BL_reg(context
)) {
221 case 0x2f: /* int2f */
222 switch ((p
->eax
& 0xFF00)>>8) {
225 AX_reg(context
) = p
->eax
& 0xFFFF;
226 do_mscdex( context
);
233 case 0x21: /* int21 */
234 switch ((p
->eax
& 0xFF00)>>8) {
236 switch (p
->eax
& 0xFF) {
237 case 06:{/* get collate table */
238 extern DWORD DOSMEM_CollateTable
;
240 /* ES:DI is a REALMODE pointer to 5 byte dosmem
241 * we fill that with 0x6, realmode pointer to collateTB
243 table
= DOSMEM_RealMode2Linear(MAKELONG(p
->edi
,p
->es
));
244 *(BYTE
*)table
= 0x06;
245 *(DWORD
*)(table
+1) = DOSMEM_CollateTable
;
247 CX_reg(context
) = 258;/*FIXME: size of table?*/
255 switch (p
->eax
& 0xFF) {
256 case 0x0D:{/* generic block device request */
257 BYTE
*dataptr
= DOSMEM_RealMode2Linear((p
->ds
)*0x1000+(p
->edx
& 0xFFFF));
258 int drive
= DOS_GET_DRIVE(p
->ebx
&0xFF);
260 if ((p
->ecx
& 0xFF00) != 0x0800) {
264 switch (p
->ecx
& 0xFF) {
267 char label
[12],fsname
[9],path
[4];
270 strcpy(path
,"x:\\");path
[0]=drive
+'A';
271 GetVolumeInformation32A(path
,label
,12,&serial
,NULL
,NULL
,fsname
,9);
273 memcpy(dataptr
+2,&serial
,4);
274 memcpy(dataptr
+6,label
,11);
275 memcpy(dataptr
+17,fsname
,8);
278 case 0x60: /* get device parameters */
279 /* used by defrag.exe of win95 */
280 memset(dataptr
, 0, 0x26);
282 dataptr
[6] = 0; /* media type */
284 dataptr
[1] = 0x05; /* fixed disk */
285 setword(&dataptr
[2], 0x01); /* non removable */
286 setword(&dataptr
[4], 0x300); /* # of cylinders */
288 dataptr
[1] = 0x07; /* block dev, floppy */
289 setword(&dataptr
[2], 0x02); /* removable */
290 setword(&dataptr
[4], 80); /* # of cylinders */
292 CreateBPB(drive
, &dataptr
[7]);
313 if (EFL_reg(context
)&1) {
315 "RealModeInt %02x: EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx\n"
316 " ESI=%08lx EDI=%08lx ES=%04x DS=%04x\n",
317 BL_reg(context
), p
->eax
, p
->ebx
, p
->ecx
, p
->edx
,
318 p
->esi
, p
->edi
, p
->es
, p
->ds
323 case 0x0301: /* Call real mode procedure with far return */
325 REALMODECALL
*p
= (REALMODECALL
*)PTR_SEG_OFF_TO_LIN( ES_reg(context
), DI_reg(context
) );
327 "RealModeCall: EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx\n"
328 " ESI=%08lx EDI=%08lx ES=%04x DS=%04x CS:IP=%04x:%04x\n",
329 p
->eax
, p
->ebx
, p
->ecx
, p
->edx
,
330 p
->esi
, p
->edi
, p
->es
, p
->ds
, p
->cs
, p
->ip
);
335 case 0x0302: /* Call real mode procedure with interrupt return */
337 REALMODECALL
*p
= (REALMODECALL
*)PTR_SEG_OFF_TO_LIN( ES_reg(context
), DI_reg(context
) );
339 "RealModeCallIret: EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx\n"
340 " ESI=%08lx EDI=%08lx ES=%04x DS=%04x CS:IP=%04x:%04x\n",
341 p
->eax
, p
->ebx
, p
->ecx
, p
->edx
,
342 p
->esi
, p
->edi
, p
->es
, p
->ds
, p
->cs
, p
->ip
);
347 case 0x0303: /* Allocate Real Mode Callback Address */
349 REALMODECALL
*p
= (REALMODECALL
*)PTR_SEG_OFF_TO_LIN( ES_reg(context
), DI_reg(context
) );
351 "AllocRMCB: EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx\n"
352 " ESI=%08lx EDI=%08lx ES=%04x DS=%04x CS:IP=%04x:%04x\n"
353 " Function to call: %04x:%04x\n",
354 p
->eax
, p
->ebx
, p
->ecx
, p
->edx
,
355 p
->esi
, p
->edi
, p
->es
, p
->ds
, p
->cs
, p
->ip
,
356 DS_reg(context
),SI_reg(context
)
362 case 0x0400: /* Get DPMI version */
363 AX_reg(context
) = 0x005a; /* DPMI version 0.90 */
364 BX_reg(context
) = 0x0005; /* Flags: 32-bit, virtual memory */
365 CL_reg(context
) = runtime_cpu ();
366 DX_reg(context
) = 0x0102; /* Master/slave interrupt controller base*/
369 case 0x0500: /* Get free memory information */
373 mmi
.dwSize
= sizeof(mmi
);
375 ptr
= (BYTE
*)PTR_SEG_OFF_TO_LIN(ES_reg(context
),DI_reg(context
));
376 /* the layout is just the same as MEMMANINFO, but without
379 memcpy(ptr
,((char*)&mmi
)+4,sizeof(mmi
)-4);
382 case 0x0501: /* Allocate memory block */
383 if (!(ptr
= (BYTE
*)HeapAlloc( SystemHeap
, 0,MAKELONG( CX_reg(context
),
386 AX_reg(context
) = 0x8012; /* linear memory not available */
391 BX_reg(context
) = SI_reg(context
) = HIWORD(ptr
);
392 CX_reg(context
) = DI_reg(context
) = LOWORD(ptr
);
396 case 0x0502: /* Free memory block */
397 HeapFree( SystemHeap
, 0,
398 (void *)MAKELONG( DI_reg(context
), SI_reg(context
) ) );
401 case 0x0503: /* Resize memory block */
402 if (!(ptr
= (BYTE
*)HeapReAlloc( SystemHeap
, 0,
403 (void *)MAKELONG(DI_reg(context
),SI_reg(context
)),
404 MAKELONG(CX_reg(context
),BX_reg(context
)))))
406 AX_reg(context
) = 0x8012; /* linear memory not available */
411 BX_reg(context
) = SI_reg(context
) = HIWORD(ptr
);
412 CX_reg(context
) = DI_reg(context
) = LOWORD(ptr
);
416 case 0x0600: /* Lock linear region */
417 break; /* Just ignore it */
419 case 0x0601: /* Unlock linear region */
420 break; /* Just ignore it */
422 case 0x0602: /* Unlock real-mode region */
423 break; /* Just ignore it */
425 case 0x0603: /* Lock real-mode region */
426 break; /* Just ignore it */
428 case 0x0604: /* Get page size */
430 CX_reg(context
) = 4096;
433 case 0x0702: /* Mark page as demand-paging candidate */
434 break; /* Just ignore it */
436 case 0x0703: /* Discard page contents */
437 break; /* Just ignore it */
440 INT_BARF( context
, 0x31 );
441 AX_reg(context
) = 0x8001; /* unsupported function */