4 * Copyright 1995 Alexandre Julliard
16 /* #define DEBUG_INT */
20 /* Structure for real-mode callbacks */
42 extern void do_mscdex( SIGCONTEXT
*context
);
44 /**********************************************************************
47 * Handler for int 31h (DPMI).
49 void INT_Int31Handler( SIGCONTEXT
*context
)
55 switch(AX_reg(context
))
57 case 0x0000: /* Allocate LDT descriptors */
58 if (!(AX_reg(context
) = AllocSelectorArray( CX_reg(context
) )))
60 AX_reg(context
) = 0x8011; /* descriptor unavailable */
65 case 0x0001: /* Free LDT descriptor */
66 if (FreeSelector( BX_reg(context
) ))
68 AX_reg(context
) = 0x8022; /* invalid selector */
73 /* If a segment register contains the selector being freed, */
75 if (!((DS_reg(context
)^BX_reg(context
)) & ~3)) DS_reg(context
) = 0;
76 if (!((ES_reg(context
)^BX_reg(context
)) & ~3)) ES_reg(context
) = 0;
78 if (!((FS_reg(context
)^BX_reg(context
)) & ~3)) FS_reg(context
) = 0;
81 if (!((GS_reg(context
)^BX_reg(context
)) & ~3)) GS_reg(context
) = 0;
86 case 0x0002: /* Real mode segment to descriptor */
88 WORD entryPoint
= 0; /* KERNEL entry point for descriptor */
89 switch(BX_reg(context
))
91 case 0x0000: entryPoint
= 183; break; /* __0000H */
92 case 0x0040: entryPoint
= 193; break; /* __0040H */
93 case 0xa000: entryPoint
= 174; break; /* __A000H */
94 case 0xb000: entryPoint
= 181; break; /* __B000H */
95 case 0xb800: entryPoint
= 182; break; /* __B800H */
96 case 0xc000: entryPoint
= 195; break; /* __C000H */
97 case 0xd000: entryPoint
= 179; break; /* __D000H */
98 case 0xe000: entryPoint
= 190; break; /* __E000H */
99 case 0xf000: entryPoint
= 194; break; /* __F000H */
101 fprintf( stderr
, "DPMI: real-mode seg to descriptor %04x not possible\n",
103 AX_reg(context
) = 0x8011;
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.
203 REALMODECALL
*p
= (REALMODECALL
*)PTR_SEG_OFF_TO_LIN( ES_reg(context
), DI_reg(context
) );
205 "RealModeInt %02x: EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx\n"
206 " ESI=%08lx EDI=%08lx ES=%04x DS=%04x\n",
207 BL_reg(context
), p
->eax
, p
->ebx
, p
->ecx
, p
->edx
,
208 p
->esi
, p
->edi
, p
->es
, p
->ds
);
210 /* Compton's 1995 encyclopedia does its MSCDEX calls through
211 * this interrupt. Why? Who knows...
213 if ((BL_reg(context
) == 0x2f) && ((p
->eax
& 0xFF00) == 0x1500))
215 do_mscdex( context
);
222 case 0x0301: /* Call real mode procedure with far return */
224 REALMODECALL
*p
= (REALMODECALL
*)PTR_SEG_OFF_TO_LIN( ES_reg(context
), DI_reg(context
) );
226 "RealModeCall: EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx\n"
227 " ESI=%08lx EDI=%08lx ES=%04x DS=%04x CS:IP=%04x:%04x\n",
228 p
->eax
, p
->ebx
, p
->ecx
, p
->edx
,
229 p
->esi
, p
->edi
, p
->es
, p
->ds
, p
->cs
, p
->ip
);
234 case 0x0302: /* Call real mode procedure with interrupt return */
236 REALMODECALL
*p
= (REALMODECALL
*)PTR_SEG_OFF_TO_LIN( ES_reg(context
), DI_reg(context
) );
238 "RealModeCallIret: EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx\n"
239 " ESI=%08lx EDI=%08lx ES=%04x DS=%04x CS:IP=%04x:%04x\n",
240 p
->eax
, p
->ebx
, p
->ecx
, p
->edx
,
241 p
->esi
, p
->edi
, p
->es
, p
->ds
, p
->cs
, p
->ip
);
246 case 0x0400: /* Get DPMI version */
247 AX_reg(context
) = 0x005a; /* DPMI version 0.90 */
248 BX_reg(context
) = 0x0005; /* Flags: 32-bit, virtual memory */
249 CL_reg(context
) = runtime_cpu ();
250 DX_reg(context
) = 0x0102; /* Master/slave interrupt controller base*/
253 case 0x0500: /* Get free memory information */
254 ptr
= (BYTE
*)PTR_SEG_OFF_TO_LIN( ES_reg(context
), DI_reg(context
) );
255 *(DWORD
*)ptr
= 0x00ff0000; /* Largest block available */
256 memset( ptr
+ 4, 0xff, 0x2c ); /* No other information supported */
259 case 0x0501: /* Allocate memory block */
260 if (!(ptr
= (BYTE
*)HeapAlloc( SystemHeap
, 0,MAKELONG( CX_reg(context
),
263 AX_reg(context
) = 0x8012; /* linear memory not available */
268 BX_reg(context
) = SI_reg(context
) = HIWORD(ptr
);
269 CX_reg(context
) = DI_reg(context
) = LOWORD(ptr
);
273 case 0x0502: /* Free memory block */
274 HeapFree( SystemHeap
, 0,
275 (void *)MAKELONG( DI_reg(context
), SI_reg(context
) ) );
278 case 0x0503: /* Resize memory block */
279 if (!(ptr
= (BYTE
*)HeapReAlloc( SystemHeap
, 0,
280 (void *)MAKELONG(DI_reg(context
),SI_reg(context
)),
281 MAKELONG(CX_reg(context
),BX_reg(context
)))))
283 AX_reg(context
) = 0x8012; /* linear memory not available */
288 BX_reg(context
) = SI_reg(context
) = HIWORD(ptr
);
289 CX_reg(context
) = DI_reg(context
) = LOWORD(ptr
);
293 case 0x0600: /* Lock linear region */
294 break; /* Just ignore it */
296 case 0x0601: /* Unlock linear region */
297 break; /* Just ignore it */
299 case 0x0602: /* Unlock real-mode region */
300 break; /* Just ignore it */
302 case 0x0603: /* Lock real-mode region */
303 break; /* Just ignore it */
305 case 0x0604: /* Get page size */
307 CX_reg(context
) = 4096;
310 case 0x0702: /* Mark page as demand-paging candidate */
311 break; /* Just ignore it */
313 case 0x0703: /* Discard page contents */
314 break; /* Just ignore it */
317 INT_BARF( context
, 0x31 );
318 AX_reg(context
) = 0x8001; /* unsupported function */