4 * Copyright 1995 Alexandre Julliard
13 #include "registers.h"
17 /* #define DEBUG_INT */
21 /* Structure for real-mode callbacks */
43 /**********************************************************************
46 * Handler for int 31h (DPMI).
48 void INT_Int31Handler( struct sigcontext_struct context
)
53 RESET_CFLAG(&context
);
54 switch(AX_reg(&context
))
56 case 0x0000: /* Allocate LDT descriptors */
57 if (!(AX_reg(&context
) = AllocSelectorArray( CX_reg(&context
) )))
59 AX_reg(&context
) = 0x8011; /* descriptor unavailable */
64 case 0x0001: /* Free LDT descriptor */
65 if (FreeSelector( BX_reg(&context
) ))
67 AX_reg(&context
) = 0x8022; /* invalid selector */
72 case 0x0003: /* Get next selector increment */
73 AX_reg(&context
) = __AHINCR
;
76 case 0x0004: /* Lock selector (not supported) */
77 AX_reg(&context
) = 0; /* FIXME: is this a correct return value? */
80 case 0x0005: /* Unlock selector (not supported) */
81 AX_reg(&context
) = 0; /* FIXME: is this a correct return value? */
84 case 0x0006: /* Get selector base address */
85 if (!(dw
= GetSelectorBase( BX_reg(&context
) )))
87 AX_reg(&context
) = 0x8022; /* invalid selector */
92 CX_reg(&context
) = HIWORD(dw
);
93 DX_reg(&context
) = LOWORD(dw
);
97 case 0x0007: /* Set selector base address */
98 SetSelectorBase( BX_reg(&context
),
99 MAKELONG( DX_reg(&context
), CX_reg(&context
) ) );
102 case 0x0008: /* Set selector limit */
103 SetSelectorLimit( BX_reg(&context
),
104 MAKELONG( DX_reg(&context
), CX_reg(&context
) ) );
107 case 0x0009: /* Set selector access rights */
108 SelectorAccessRights( BX_reg(&context
), 1, CX_reg(&context
) );
110 case 0x000a: /* Allocate selector alias */
111 if (!(AX_reg(&context
) = AllocCStoDSAlias( BX_reg(&context
) )))
113 AX_reg(&context
) = 0x8011; /* descriptor unavailable */
118 case 0x000b: /* Get descriptor */
121 LDT_GetEntry( SELECTOR_TO_ENTRY( BX_reg(&context
) ), &entry
);
122 /* FIXME: should use ES:EDI for 32-bit clients */
123 LDT_EntryToBytes( PTR_SEG_OFF_TO_LIN( ES_reg(&context
),
124 DI_reg(&context
) ), &entry
);
128 case 0x000c: /* Set descriptor */
131 LDT_BytesToEntry( PTR_SEG_OFF_TO_LIN( ES_reg(&context
),
132 DI_reg(&context
) ), &entry
);
133 LDT_GetEntry( SELECTOR_TO_ENTRY( BX_reg(&context
) ), &entry
);
137 case 0x000d: /* Allocate specific LDT descriptor */
138 AX_reg(&context
) = 0x8011; /* descriptor unavailable */
142 case 0x0204: /* Get protected mode interrupt vector */
143 dw
= (DWORD
)INT_GetHandler( BL_reg(&context
) );
144 CX_reg(&context
) = HIWORD(dw
);
145 DX_reg(&context
) = LOWORD(dw
);
148 case 0x0205: /* Set protected mode interrupt vector */
149 INT_SetHandler( BL_reg(&context
),
150 (SEGPTR
)MAKELONG( DX_reg(&context
), CX_reg(&context
) ));
153 case 0x0300: /* Simulate real mode interrupt
154 * Interrupt number is in BL, flags are in BH
155 * ES:DI points to real-mode call structure
156 * Currently we just print it out and return error.
159 REALMODECALL
*p
= (REALMODECALL
*)PTR_SEG_OFF_TO_LIN( ES_reg(&context
), DI_reg(&context
) );
161 "RealModeInt %02x: EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx\n"
162 " ESI=%08lx EDI=%08lx ES=%04x DS=%04x\n",
163 BL_reg(&context
), p
->eax
, p
->ebx
, p
->ecx
, p
->edx
,
164 p
->esi
, p
->edi
, p
->es
, p
->ds
);
169 case 0x0301: /* Call real mode procedure with far return */
171 REALMODECALL
*p
= (REALMODECALL
*)PTR_SEG_OFF_TO_LIN( ES_reg(&context
), DI_reg(&context
) );
173 "RealModeCall: EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx\n"
174 " ESI=%08lx EDI=%08lx ES=%04x DS=%04x CS:IP=%04x:%04x\n",
175 p
->eax
, p
->ebx
, p
->ecx
, p
->edx
,
176 p
->esi
, p
->edi
, p
->es
, p
->ds
, p
->cs
, p
->ip
);
181 case 0x0302: /* Call real mode procedure with interrupt return */
183 REALMODECALL
*p
= (REALMODECALL
*)PTR_SEG_OFF_TO_LIN( ES_reg(&context
), DI_reg(&context
) );
185 "RealModeCallIret: EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx\n"
186 " ESI=%08lx EDI=%08lx ES=%04x DS=%04x CS:IP=%04x:%04x\n",
187 p
->eax
, p
->ebx
, p
->ecx
, p
->edx
,
188 p
->esi
, p
->edi
, p
->es
, p
->ds
, p
->cs
, p
->ip
);
193 case 0x0400: /* Get DPMI version */
194 AX_reg(&context
) = 0x005a; /* DPMI version 0.90 */
195 BX_reg(&context
) = 0x0005; /* Flags: 32-bit, virtual memory */
196 CL_reg(&context
) = runtime_cpu ();
197 DX_reg(&context
) = 0x0102; /* Master/slave interrupt controller base*/
200 case 0x0500: /* Get free memory information */
201 ptr
= (BYTE
*)PTR_SEG_OFF_TO_LIN( ES_reg(&context
), DI_reg(&context
) );
202 *(DWORD
*)ptr
= 0x00ff0000; /* Largest block available */
203 memset( ptr
+ 4, 0xff, 0x2c ); /* No other information supported */
206 case 0x0501: /* Allocate memory block */
207 if (!(ptr
= (BYTE
*)malloc( MAKELONG( CX_reg(&context
),
208 BX_reg(&context
) ) )))
210 AX_reg(&context
) = 0x8012; /* linear memory not available */
215 BX_reg(&context
) = SI_reg(&context
) = HIWORD(ptr
);
216 CX_reg(&context
) = DI_reg(&context
) = LOWORD(ptr
);
220 case 0x0502: /* Free memory block */
221 free( (void *)MAKELONG( DI_reg(&context
), SI_reg(&context
) ) );
224 case 0x0503: /* Resize memory block */
225 if (!(ptr
= (BYTE
*)realloc( (void *)MAKELONG(DI_reg(&context
),SI_reg(&context
)),
226 MAKELONG(CX_reg(&context
),BX_reg(&context
)))))
228 AX_reg(&context
) = 0x8012; /* linear memory not available */
233 BX_reg(&context
) = SI_reg(&context
) = HIWORD(ptr
);
234 CX_reg(&context
) = DI_reg(&context
) = LOWORD(ptr
);
238 case 0x0600: /* Lock linear region */
239 break; /* Just ignore it */
241 case 0x0601: /* Unlock linear region */
242 break; /* Just ignore it */
244 case 0x0604: /* Get page size */
245 BX_reg(&context
) = 0;
246 CX_reg(&context
) = 4096;
250 INT_BARF( &context
, 0x31 );
251 AX_reg(&context
) = 0x8001; /* unsupported function */