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( CONTEXT
*context
);
48 /**********************************************************************
51 * Handler for int 31h (DPMI).
53 void INT_Int31Handler( CONTEXT
*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;
81 if (!((FS_reg(context
)^BX_reg(context
)) & ~3)) FS_reg(context
) = 0;
82 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 AX_reg(context
) = DOSMEM_AllocSelector(BX_reg(context
));
105 AX_reg(context
) = LOWORD(MODULE_GetEntryPoint(
106 GetModuleHandle( "KERNEL" ),
111 case 0x0003: /* Get next selector increment */
112 AX_reg(context
) = __AHINCR
;
115 case 0x0004: /* Lock selector (not supported) */
116 AX_reg(context
) = 0; /* FIXME: is this a correct return value? */
119 case 0x0005: /* Unlock selector (not supported) */
120 AX_reg(context
) = 0; /* FIXME: is this a correct return value? */
123 case 0x0006: /* Get selector base address */
124 if (!(dw
= GetSelectorBase( BX_reg(context
) )))
126 AX_reg(context
) = 0x8022; /* invalid selector */
131 CX_reg(context
) = HIWORD(dw
);
132 DX_reg(context
) = LOWORD(dw
);
136 case 0x0007: /* Set selector base address */
137 SetSelectorBase( BX_reg(context
),
138 MAKELONG( DX_reg(context
), CX_reg(context
) ) );
141 case 0x0008: /* Set selector limit */
142 SetSelectorLimit( BX_reg(context
),
143 MAKELONG( DX_reg(context
), CX_reg(context
) ) );
146 case 0x0009: /* Set selector access rights */
147 SelectorAccessRights( BX_reg(context
), 1, CX_reg(context
) );
150 case 0x000a: /* Allocate selector alias */
151 if (!(AX_reg(context
) = AllocCStoDSAlias( BX_reg(context
) )))
153 AX_reg(context
) = 0x8011; /* descriptor unavailable */
158 case 0x000b: /* Get descriptor */
161 LDT_GetEntry( SELECTOR_TO_ENTRY( BX_reg(context
) ), &entry
);
162 /* FIXME: should use ES:EDI for 32-bit clients */
163 LDT_EntryToBytes( PTR_SEG_OFF_TO_LIN( ES_reg(context
),
164 DI_reg(context
) ), &entry
);
168 case 0x000c: /* Set descriptor */
171 LDT_BytesToEntry( PTR_SEG_OFF_TO_LIN( ES_reg(context
),
172 DI_reg(context
) ), &entry
);
173 LDT_GetEntry( SELECTOR_TO_ENTRY( BX_reg(context
) ), &entry
);
177 case 0x000d: /* Allocate specific LDT descriptor */
178 AX_reg(context
) = 0x8011; /* descriptor unavailable */
181 case 0x0200: /* get real mode interrupt vector */
183 "int31: get realmode interupt vector(0x%02x) unimplemented.\n",
188 case 0x0201: /* set real mode interrupt vector */
190 "int31: set realmode interupt vector(0x%02x,0x%04x:0x%04x) unimplemented\n",
191 BL_reg(context
),CX_reg(context
),DX_reg(context
)
195 case 0x0204: /* Get protected mode interrupt vector */
196 dw
= (DWORD
)INT_GetHandler( BL_reg(context
) );
197 CX_reg(context
) = HIWORD(dw
);
198 DX_reg(context
) = LOWORD(dw
);
201 case 0x0205: /* Set protected mode interrupt vector */
202 INT_SetHandler( BL_reg(context
),
203 (FARPROC16
)PTR_SEG_OFF_TO_SEGPTR( CX_reg(context
),
207 case 0x0300: /* Simulate real mode interrupt
208 * Interrupt number is in BL, flags are in BH
209 * ES:DI points to real-mode call structure
210 * Currently we just print it out and return error.
212 RESET_CFLAG(context
);
214 REALMODECALL
*p
= (REALMODECALL
*)PTR_SEG_OFF_TO_LIN( ES_reg(context
), DI_reg(context
) );
216 switch (BL_reg(context
)) {
217 case 0x2f: /* int2f */
218 switch ((p
->eax
& 0xFF00)>>8) {
221 AX_reg(context
) = p
->eax
& 0xFFFF;
222 do_mscdex( context
);
229 case 0x21: /* int21 */
230 switch ((p
->eax
& 0xFF00)>>8) {
232 switch (p
->eax
& 0xFF) {
233 case 06:{/* get collate table */
235 /* ES:DI is a REALMODE pointer to 5 byte dosmem
236 * we fill that with 0x6, realmode pointer to collateTB
238 table
= DOSMEM_RealMode2Linear(MAKELONG(p
->edi
,p
->es
));
239 *(BYTE
*)table
= 0x06;
240 *(DWORD
*)(table
+1) = DOSMEM_CollateTable
;
242 CX_reg(context
) = 258;/*FIXME: size of table?*/
250 switch (p
->eax
& 0xFF) {
251 case 0x0D:{/* generic block device request */
252 BYTE
*dataptr
= DOSMEM_RealMode2Linear((p
->ds
)*0x1000+(p
->edx
& 0xFFFF));
253 int drive
= DOS_GET_DRIVE(p
->ebx
&0xFF);
255 if ((p
->ecx
& 0xFF00) != 0x0800) {
259 switch (p
->ecx
& 0xFF) {
262 char label
[12],fsname
[9],path
[4];
265 strcpy(path
,"x:\\");path
[0]=drive
+'A';
266 GetVolumeInformation32A(path
,label
,12,&serial
,NULL
,NULL
,fsname
,9);
268 memcpy(dataptr
+2,&serial
,4);
269 memcpy(dataptr
+6,label
,11);
270 memcpy(dataptr
+17,fsname
,8);
273 case 0x60: /* get device parameters */
274 /* used by defrag.exe of win95 */
275 memset(dataptr
, 0, 0x26);
277 dataptr
[6] = 0; /* media type */
279 dataptr
[1] = 0x05; /* fixed disk */
280 setword(&dataptr
[2], 0x01); /* non removable */
281 setword(&dataptr
[4], 0x300); /* # of cylinders */
283 dataptr
[1] = 0x07; /* block dev, floppy */
284 setword(&dataptr
[2], 0x02); /* removable */
285 setword(&dataptr
[4], 80); /* # of cylinders */
287 CreateBPB(drive
, &dataptr
[7]);
308 if (EFL_reg(context
)&1) {
310 "RealModeInt %02x: EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx\n"
311 " ESI=%08lx EDI=%08lx ES=%04x DS=%04x\n",
312 BL_reg(context
), p
->eax
, p
->ebx
, p
->ecx
, p
->edx
,
313 p
->esi
, p
->edi
, p
->es
, p
->ds
318 case 0x0301: /* Call real mode procedure with far return */
320 REALMODECALL
*p
= (REALMODECALL
*)PTR_SEG_OFF_TO_LIN( ES_reg(context
), DI_reg(context
) );
322 "RealModeCall: EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx\n"
323 " ESI=%08lx EDI=%08lx ES=%04x DS=%04x CS:IP=%04x:%04x\n",
324 p
->eax
, p
->ebx
, p
->ecx
, p
->edx
,
325 p
->esi
, p
->edi
, p
->es
, p
->ds
, p
->cs
, p
->ip
);
330 case 0x0302: /* Call real mode procedure with interrupt return */
332 REALMODECALL
*p
= (REALMODECALL
*)PTR_SEG_OFF_TO_LIN( ES_reg(context
), DI_reg(context
) );
334 "RealModeCallIret: EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx\n"
335 " ESI=%08lx EDI=%08lx ES=%04x DS=%04x CS:IP=%04x:%04x\n",
336 p
->eax
, p
->ebx
, p
->ecx
, p
->edx
,
337 p
->esi
, p
->edi
, p
->es
, p
->ds
, p
->cs
, p
->ip
);
342 case 0x0303: /* Allocate Real Mode Callback Address */
344 REALMODECALL
*p
= (REALMODECALL
*)PTR_SEG_OFF_TO_LIN( ES_reg(context
), DI_reg(context
) );
346 "AllocRMCB: EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx\n"
347 " ESI=%08lx EDI=%08lx ES=%04x DS=%04x CS:IP=%04x:%04x\n"
348 " Function to call: %04x:%04x\n",
349 p
->eax
, p
->ebx
, p
->ecx
, p
->edx
,
350 p
->esi
, p
->edi
, p
->es
, p
->ds
, p
->cs
, p
->ip
,
351 (WORD
)DS_reg(context
), SI_reg(context
) );
356 case 0x0400: /* Get DPMI version */
357 AX_reg(context
) = 0x005a; /* DPMI version 0.90 */
358 BX_reg(context
) = 0x0005; /* Flags: 32-bit, virtual memory */
359 CL_reg(context
) = runtime_cpu ();
360 DX_reg(context
) = 0x0102; /* Master/slave interrupt controller base*/
363 case 0x0500: /* Get free memory information */
367 mmi
.dwSize
= sizeof(mmi
);
369 ptr
= (BYTE
*)PTR_SEG_OFF_TO_LIN(ES_reg(context
),DI_reg(context
));
370 /* the layout is just the same as MEMMANINFO, but without
373 memcpy(ptr
,((char*)&mmi
)+4,sizeof(mmi
)-4);
376 case 0x0501: /* Allocate memory block */
377 if (!(ptr
= (BYTE
*)HeapAlloc( SystemHeap
, 0,MAKELONG( CX_reg(context
),
380 AX_reg(context
) = 0x8012; /* linear memory not available */
385 BX_reg(context
) = SI_reg(context
) = HIWORD(ptr
);
386 CX_reg(context
) = DI_reg(context
) = LOWORD(ptr
);
390 case 0x0502: /* Free memory block */
391 HeapFree( SystemHeap
, 0,
392 (void *)MAKELONG( DI_reg(context
), SI_reg(context
) ) );
395 case 0x0503: /* Resize memory block */
396 if (!(ptr
= (BYTE
*)HeapReAlloc( SystemHeap
, 0,
397 (void *)MAKELONG(DI_reg(context
),SI_reg(context
)),
398 MAKELONG(CX_reg(context
),BX_reg(context
)))))
400 AX_reg(context
) = 0x8012; /* linear memory not available */
405 BX_reg(context
) = SI_reg(context
) = HIWORD(ptr
);
406 CX_reg(context
) = DI_reg(context
) = LOWORD(ptr
);
410 case 0x0600: /* Lock linear region */
411 break; /* Just ignore it */
413 case 0x0601: /* Unlock linear region */
414 break; /* Just ignore it */
416 case 0x0602: /* Unlock real-mode region */
417 break; /* Just ignore it */
419 case 0x0603: /* Lock real-mode region */
420 break; /* Just ignore it */
422 case 0x0604: /* Get page size */
424 CX_reg(context
) = 4096;
427 case 0x0702: /* Mark page as demand-paging candidate */
428 break; /* Just ignore it */
430 case 0x0703: /* Discard page contents */
431 break; /* Just ignore it */
434 INT_BARF( context
, 0x31 );
435 AX_reg(context
) = 0x8001; /* unsupported function */