4 * Copyright 1995 Alexandre Julliard
14 #include "registers.h"
18 /* #define DEBUG_INT */
22 /* Structure for real-mode callbacks */
44 extern void do_mscdex(struct sigcontext_struct
*context
);
46 /**********************************************************************
49 * Handler for int 31h (DPMI).
51 void INT_Int31Handler( struct sigcontext_struct context
)
56 RESET_CFLAG(&context
);
57 switch(AX_reg(&context
))
59 case 0x0000: /* Allocate LDT descriptors */
60 if (!(AX_reg(&context
) = AllocSelectorArray( CX_reg(&context
) )))
62 AX_reg(&context
) = 0x8011; /* descriptor unavailable */
67 case 0x0001: /* Free LDT descriptor */
68 if (FreeSelector( BX_reg(&context
) ))
70 AX_reg(&context
) = 0x8022; /* invalid selector */
75 case 0x0002: /* Real mode segment to descriptor */
77 WORD entryPoint
= 0; /* KERNEL entry point for descriptor */
78 switch(BX_reg(&context
))
80 case 0x0000: entryPoint
= 183; break; /* __0000H */
81 case 0x0040: entryPoint
= 193; break; /* __0040H */
82 case 0xa000: entryPoint
= 174; break; /* __A000H */
83 case 0xb000: entryPoint
= 181; break; /* __B000H */
84 case 0xb800: entryPoint
= 182; break; /* __B800H */
85 case 0xc000: entryPoint
= 195; break; /* __C000H */
86 case 0xd000: entryPoint
= 179; break; /* __D000H */
87 case 0xe000: entryPoint
= 190; break; /* __E000H */
88 case 0xf000: entryPoint
= 194; break; /* __F000H */
90 fprintf( stderr
, "DPMI: real-mode seg to descriptor %04x not possible\n",
92 AX_reg(&context
) = 0x8011;
97 AX_reg(&context
) = LOWORD(MODULE_GetEntryPoint(
98 GetModuleHandle( "KERNEL" ),
103 case 0x0003: /* Get next selector increment */
104 AX_reg(&context
) = __AHINCR
;
107 case 0x0004: /* Lock selector (not supported) */
108 AX_reg(&context
) = 0; /* FIXME: is this a correct return value? */
111 case 0x0005: /* Unlock selector (not supported) */
112 AX_reg(&context
) = 0; /* FIXME: is this a correct return value? */
115 case 0x0006: /* Get selector base address */
116 if (!(dw
= GetSelectorBase( BX_reg(&context
) )))
118 AX_reg(&context
) = 0x8022; /* invalid selector */
123 CX_reg(&context
) = HIWORD(dw
);
124 DX_reg(&context
) = LOWORD(dw
);
128 case 0x0007: /* Set selector base address */
129 SetSelectorBase( BX_reg(&context
),
130 MAKELONG( DX_reg(&context
), CX_reg(&context
) ) );
133 case 0x0008: /* Set selector limit */
134 SetSelectorLimit( BX_reg(&context
),
135 MAKELONG( DX_reg(&context
), CX_reg(&context
) ) );
138 case 0x0009: /* Set selector access rights */
139 SelectorAccessRights( BX_reg(&context
), 1, CX_reg(&context
) );
141 case 0x000a: /* Allocate selector alias */
142 if (!(AX_reg(&context
) = AllocCStoDSAlias( BX_reg(&context
) )))
144 AX_reg(&context
) = 0x8011; /* descriptor unavailable */
149 case 0x000b: /* Get descriptor */
152 LDT_GetEntry( SELECTOR_TO_ENTRY( BX_reg(&context
) ), &entry
);
153 /* FIXME: should use ES:EDI for 32-bit clients */
154 LDT_EntryToBytes( PTR_SEG_OFF_TO_LIN( ES_reg(&context
),
155 DI_reg(&context
) ), &entry
);
159 case 0x000c: /* Set descriptor */
162 LDT_BytesToEntry( PTR_SEG_OFF_TO_LIN( ES_reg(&context
),
163 DI_reg(&context
) ), &entry
);
164 LDT_GetEntry( SELECTOR_TO_ENTRY( BX_reg(&context
) ), &entry
);
168 case 0x000d: /* Allocate specific LDT descriptor */
169 AX_reg(&context
) = 0x8011; /* descriptor unavailable */
173 case 0x0204: /* Get protected mode interrupt vector */
174 dw
= (DWORD
)INT_GetHandler( BL_reg(&context
) );
175 CX_reg(&context
) = HIWORD(dw
);
176 DX_reg(&context
) = LOWORD(dw
);
179 case 0x0205: /* Set protected mode interrupt vector */
180 INT_SetHandler( BL_reg(&context
),
181 PTR_SEG_OFF_TO_SEGPTR(CX_reg(&context
),DX_reg(&context
)));
184 case 0x0300: /* Simulate real mode interrupt
185 * Interrupt number is in BL, flags are in BH
186 * ES:DI points to real-mode call structure
187 * Currently we just print it out and return error.
190 REALMODECALL
*p
= (REALMODECALL
*)PTR_SEG_OFF_TO_LIN( ES_reg(&context
), DI_reg(&context
) );
192 "RealModeInt %02x: EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx\n"
193 " ESI=%08lx EDI=%08lx ES=%04x DS=%04x\n",
194 BL_reg(&context
), p
->eax
, p
->ebx
, p
->ecx
, p
->edx
,
195 p
->esi
, p
->edi
, p
->es
, p
->ds
);
197 /* Compton's 1995 encyclopedia does its MSCDEX calls through
198 * this interrupt. Why? Who knows...
200 if ((BL_reg(&context
) == 0x2f) && ((p
->eax
& 0xFF00) == 0x1500))
202 struct sigcontext_struct context2
;
203 EAX_reg(&context2
) = p
->eax
;
204 EBX_reg(&context2
) = p
->ebx
;
205 ECX_reg(&context2
) = p
->ecx
;
206 EDX_reg(&context2
) = p
->edx
;
207 ES_reg(&context2
) = p
->es
;
208 do_mscdex(&context2
);
209 p
->eax
= EAX_reg(&context2
);
210 p
->ebx
= EBX_reg(&context2
);
211 p
->ecx
= ECX_reg(&context2
);
212 p
->edx
= EDX_reg(&context2
);
214 else SET_CFLAG(&context
);
218 case 0x0301: /* Call real mode procedure with far return */
220 REALMODECALL
*p
= (REALMODECALL
*)PTR_SEG_OFF_TO_LIN( ES_reg(&context
), DI_reg(&context
) );
222 "RealModeCall: EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx\n"
223 " ESI=%08lx EDI=%08lx ES=%04x DS=%04x CS:IP=%04x:%04x\n",
224 p
->eax
, p
->ebx
, p
->ecx
, p
->edx
,
225 p
->esi
, p
->edi
, p
->es
, p
->ds
, p
->cs
, p
->ip
);
230 case 0x0302: /* Call real mode procedure with interrupt return */
232 REALMODECALL
*p
= (REALMODECALL
*)PTR_SEG_OFF_TO_LIN( ES_reg(&context
), DI_reg(&context
) );
234 "RealModeCallIret: EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx\n"
235 " ESI=%08lx EDI=%08lx ES=%04x DS=%04x CS:IP=%04x:%04x\n",
236 p
->eax
, p
->ebx
, p
->ecx
, p
->edx
,
237 p
->esi
, p
->edi
, p
->es
, p
->ds
, p
->cs
, p
->ip
);
242 case 0x0400: /* Get DPMI version */
243 AX_reg(&context
) = 0x005a; /* DPMI version 0.90 */
244 BX_reg(&context
) = 0x0005; /* Flags: 32-bit, virtual memory */
245 CL_reg(&context
) = runtime_cpu ();
246 DX_reg(&context
) = 0x0102; /* Master/slave interrupt controller base*/
249 case 0x0500: /* Get free memory information */
250 ptr
= (BYTE
*)PTR_SEG_OFF_TO_LIN( ES_reg(&context
), DI_reg(&context
) );
251 *(DWORD
*)ptr
= 0x00ff0000; /* Largest block available */
252 memset( ptr
+ 4, 0xff, 0x2c ); /* No other information supported */
255 case 0x0501: /* Allocate memory block */
256 if (!(ptr
= (BYTE
*)malloc( MAKELONG( CX_reg(&context
),
257 BX_reg(&context
) ) )))
259 AX_reg(&context
) = 0x8012; /* linear memory not available */
264 BX_reg(&context
) = SI_reg(&context
) = HIWORD(ptr
);
265 CX_reg(&context
) = DI_reg(&context
) = LOWORD(ptr
);
269 case 0x0502: /* Free memory block */
270 free( (void *)MAKELONG( DI_reg(&context
), SI_reg(&context
) ) );
273 case 0x0503: /* Resize memory block */
274 if (!(ptr
= (BYTE
*)realloc( (void *)MAKELONG(DI_reg(&context
),SI_reg(&context
)),
275 MAKELONG(CX_reg(&context
),BX_reg(&context
)))))
277 AX_reg(&context
) = 0x8012; /* linear memory not available */
282 BX_reg(&context
) = SI_reg(&context
) = HIWORD(ptr
);
283 CX_reg(&context
) = DI_reg(&context
) = LOWORD(ptr
);
287 case 0x0600: /* Lock linear region */
288 break; /* Just ignore it */
290 case 0x0601: /* Unlock linear region */
291 break; /* Just ignore it */
293 case 0x0602: /* Unlock real-mode region */
294 break; /* Just ignore it */
296 case 0x0603: /* Lock real-mode region */
297 break; /* Just ignore it */
299 case 0x0604: /* Get page size */
300 BX_reg(&context
) = 0;
301 CX_reg(&context
) = 4096;
304 case 0x0702: /* Mark page as demand-paging candidate */
305 break; /* Just ignore it */
307 case 0x0703: /* Discard page contents */
308 break; /* Just ignore it */
311 INT_BARF( &context
, 0x31 );
312 AX_reg(&context
) = 0x8001; /* unsupported function */