4 * Copyright 1995 Alexandre Julliard
20 #define DOS_GET_DRIVE(reg) ((reg) ? (reg) - 1 : DRIVE_GetCurrentDrive())
22 void CreateBPB(int drive
, BYTE
*data
); /* defined in int21.c */
25 /* Structure for real-mode callbacks */
49 /**********************************************************************
50 * INT_GetRealModeContext
52 static void INT_GetRealModeContext( REALMODECALL
*call
, CONTEXT
*context
)
54 EAX_reg(context
) = call
->eax
;
55 EBX_reg(context
) = call
->ebx
;
56 ECX_reg(context
) = call
->ecx
;
57 EDX_reg(context
) = call
->edx
;
58 ESI_reg(context
) = call
->esi
;
59 EDI_reg(context
) = call
->edi
;
60 EBP_reg(context
) = call
->ebp
;
61 EFL_reg(context
) = call
->fl
;
62 EIP_reg(context
) = call
->ip
;
63 ESP_reg(context
) = call
->sp
;
64 CS_reg(context
) = call
->cs
;
65 DS_reg(context
) = call
->ds
;
66 ES_reg(context
) = call
->es
;
67 FS_reg(context
) = call
->fs
;
68 GS_reg(context
) = call
->gs
;
72 /**********************************************************************
73 * INT_SetRealModeContext
75 static void INT_SetRealModeContext( REALMODECALL
*call
, CONTEXT
*context
)
77 call
->eax
= EAX_reg(context
);
78 call
->ebx
= EBX_reg(context
);
79 call
->ecx
= ECX_reg(context
);
80 call
->edx
= EDX_reg(context
);
81 call
->esi
= ESI_reg(context
);
82 call
->edi
= EDI_reg(context
);
83 call
->ebp
= EBP_reg(context
);
84 call
->fl
= FL_reg(context
);
85 call
->ip
= IP_reg(context
);
86 call
->sp
= SP_reg(context
);
87 call
->cs
= CS_reg(context
);
88 call
->ds
= DS_reg(context
);
89 call
->es
= ES_reg(context
);
90 call
->fs
= FS_reg(context
);
91 call
->gs
= GS_reg(context
);
95 /**********************************************************************
98 static void INT_DoRealModeInt( CONTEXT
*context
)
100 CONTEXT realmode_ctx
;
101 REALMODECALL
*call
= (REALMODECALL
*)PTR_SEG_OFF_TO_LIN( ES_reg(context
),
103 INT_GetRealModeContext( call
, &realmode_ctx
);
105 RESET_CFLAG(context
);
106 switch (BL_reg(context
))
108 case 0x2f: /* int2f */
109 switch (AH_reg(&realmode_ctx
))
113 do_mscdex( &realmode_ctx
);
120 case 0x21: /* int21 */
121 switch (AH_reg(&realmode_ctx
))
124 ES_reg(&realmode_ctx
) = 0;
125 EBX_reg(&realmode_ctx
) = 0;
128 switch (AL_reg(&realmode_ctx
))
131 {/* get collate table */
132 /* ES:DI is a REALMODE pointer to 5 byte dosmem
133 * we fill that with 0x6, realmode pointer to collateTB
135 char *table
= DOSMEM_MapRealToLinear(
136 MAKELONG(EDI_reg(&realmode_ctx
),ES_reg(&realmode_ctx
)));
137 *(BYTE
*)table
= 0x06;
138 *(DWORD
*)(table
+1) = DOSMEM_CollateTable
;
139 CX_reg(&realmode_ctx
) = 258;/*FIXME: size of table?*/
148 switch (AL_reg(&realmode_ctx
))
151 {/* generic block device request */
152 BYTE
*dataptr
= DOSMEM_MapRealToLinear(
153 MAKELONG(EDX_reg(&realmode_ctx
),DS_reg(&realmode_ctx
)));
154 int drive
= DOS_GET_DRIVE(BL_reg(&realmode_ctx
));
155 if (CH_reg(&realmode_ctx
) != 0x08)
160 switch (CL_reg(&realmode_ctx
))
164 char label
[12],fsname
[9],path
[4];
167 strcpy(path
,"x:\\");path
[0]=drive
+'A';
168 GetVolumeInformation32A(path
,label
,12,&serial
,NULL
,NULL
,fsname
,9);
170 memcpy(dataptr
+2,&serial
,4);
171 memcpy(dataptr
+6,label
,11);
172 memcpy(dataptr
+17,fsname
,8);
175 case 0x60: /* get device parameters */
176 /* used by defrag.exe of win95 */
177 memset(dataptr
, 0, 0x26);
179 dataptr
[6] = 0; /* media type */
182 dataptr
[1] = 0x05; /* fixed disk */
183 setword(&dataptr
[2], 0x01); /* non removable */
184 setword(&dataptr
[4], 0x300); /* # of cylinders */
188 dataptr
[1] = 0x07; /* block dev, floppy */
189 setword(&dataptr
[2], 0x02); /* removable */
190 setword(&dataptr
[4], 80); /* # of cylinders */
192 CreateBPB(drive
, &dataptr
[7]);
215 if (EFL_reg(context
)&1)
216 FIXME(int31
,"%02x: EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx\n",
217 BL_reg(context
), EAX_reg(&realmode_ctx
), EBX_reg(&realmode_ctx
),
218 ECX_reg(&realmode_ctx
), EDX_reg(&realmode_ctx
));
219 FIXME(int31
," ESI=%08lx EDI=%08lx DS=%04lx ES=%04lx\n",
220 ESI_reg(&realmode_ctx
), EDI_reg(&realmode_ctx
),
221 DS_reg(&realmode_ctx
), ES_reg(&realmode_ctx
) );
222 INT_SetRealModeContext( call
, &realmode_ctx
);
226 /**********************************************************************
229 * Handler for int 31h (DPMI).
231 void WINAPI
INT_Int31Handler( CONTEXT
*context
)
236 RESET_CFLAG(context
);
237 switch(AX_reg(context
))
239 case 0x0000: /* Allocate LDT descriptors */
240 if (!(AX_reg(context
) = AllocSelectorArray( CX_reg(context
) )))
242 AX_reg(context
) = 0x8011; /* descriptor unavailable */
247 case 0x0001: /* Free LDT descriptor */
248 if (FreeSelector( BX_reg(context
) ))
250 AX_reg(context
) = 0x8022; /* invalid selector */
255 /* If a segment register contains the selector being freed, */
256 /* set it to zero. */
257 if (!((DS_reg(context
)^BX_reg(context
)) & ~3)) DS_reg(context
) = 0;
258 if (!((ES_reg(context
)^BX_reg(context
)) & ~3)) ES_reg(context
) = 0;
259 if (!((FS_reg(context
)^BX_reg(context
)) & ~3)) FS_reg(context
) = 0;
260 if (!((GS_reg(context
)^BX_reg(context
)) & ~3)) GS_reg(context
) = 0;
264 case 0x0002: /* Real mode segment to descriptor */
266 WORD entryPoint
= 0; /* KERNEL entry point for descriptor */
267 switch(BX_reg(context
))
269 case 0x0000: entryPoint
= 183; break; /* __0000H */
270 case 0x0040: entryPoint
= 193; break; /* __0040H */
271 case 0xa000: entryPoint
= 174; break; /* __A000H */
272 case 0xb000: entryPoint
= 181; break; /* __B000H */
273 case 0xb800: entryPoint
= 182; break; /* __B800H */
274 case 0xc000: entryPoint
= 195; break; /* __C000H */
275 case 0xd000: entryPoint
= 179; break; /* __D000H */
276 case 0xe000: entryPoint
= 190; break; /* __E000H */
277 case 0xf000: entryPoint
= 194; break; /* __F000H */
279 AX_reg(context
) = DOSMEM_AllocSelector(BX_reg(context
));
283 AX_reg(context
) = LOWORD(MODULE_GetEntryPoint(
284 GetModuleHandle16( "KERNEL" ),
289 case 0x0003: /* Get next selector increment */
290 AX_reg(context
) = __AHINCR
;
293 case 0x0004: /* Lock selector (not supported) */
294 AX_reg(context
) = 0; /* FIXME: is this a correct return value? */
297 case 0x0005: /* Unlock selector (not supported) */
298 AX_reg(context
) = 0; /* FIXME: is this a correct return value? */
301 case 0x0006: /* Get selector base address */
302 if (!(dw
= GetSelectorBase( BX_reg(context
) )))
304 AX_reg(context
) = 0x8022; /* invalid selector */
309 CX_reg(context
) = HIWORD(dw
);
310 DX_reg(context
) = LOWORD(dw
);
314 case 0x0007: /* Set selector base address */
315 SetSelectorBase( BX_reg(context
),
316 MAKELONG( DX_reg(context
), CX_reg(context
) ) );
319 case 0x0008: /* Set selector limit */
320 SetSelectorLimit( BX_reg(context
),
321 MAKELONG( DX_reg(context
), CX_reg(context
) ) );
324 case 0x0009: /* Set selector access rights */
325 SelectorAccessRights( BX_reg(context
), 1, CX_reg(context
) );
328 case 0x000a: /* Allocate selector alias */
329 if (!(AX_reg(context
) = AllocCStoDSAlias( BX_reg(context
) )))
331 AX_reg(context
) = 0x8011; /* descriptor unavailable */
336 case 0x000b: /* Get descriptor */
339 LDT_GetEntry( SELECTOR_TO_ENTRY( BX_reg(context
) ), &entry
);
340 /* FIXME: should use ES:EDI for 32-bit clients */
341 LDT_EntryToBytes( PTR_SEG_OFF_TO_LIN( ES_reg(context
),
342 DI_reg(context
) ), &entry
);
346 case 0x000c: /* Set descriptor */
349 LDT_BytesToEntry( PTR_SEG_OFF_TO_LIN( ES_reg(context
),
350 DI_reg(context
) ), &entry
);
351 LDT_SetEntry( SELECTOR_TO_ENTRY( BX_reg(context
) ), &entry
);
355 case 0x000d: /* Allocate specific LDT descriptor */
356 AX_reg(context
) = 0x8011; /* descriptor unavailable */
359 case 0x0200: /* get real mode interrupt vector */
360 FIXME(int31
,"get realmode interupt vector(0x%02x) unimplemented.\n",
364 case 0x0201: /* set real mode interrupt vector */
365 FIXME(int31
, "set realmode interupt vector(0x%02x,0x%04x:0x%04x) unimplemented\n", BL_reg(context
),CX_reg(context
),DX_reg(context
));
368 case 0x0204: /* Get protected mode interrupt vector */
369 dw
= (DWORD
)INT_GetHandler( BL_reg(context
) );
370 CX_reg(context
) = HIWORD(dw
);
371 DX_reg(context
) = LOWORD(dw
);
374 case 0x0205: /* Set protected mode interrupt vector */
375 INT_SetHandler( BL_reg(context
),
376 (FARPROC16
)PTR_SEG_OFF_TO_SEGPTR( CX_reg(context
),
380 case 0x0300: /* Simulate real mode interrupt */
381 INT_DoRealModeInt( context
);
384 case 0x0301: /* Call real mode procedure with far return */
386 REALMODECALL
*p
= (REALMODECALL
*)PTR_SEG_OFF_TO_LIN( ES_reg(context
), DI_reg(context
) );
387 FIXME(int31
, "RealModeCall: EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx\n",
388 p
->eax
, p
->ebx
, p
->ecx
, p
->edx
);
389 FIXME(int31
, " ESI=%08lx EDI=%08lx ES=%04x DS=%04x CS:IP=%04x:%04x\n",
390 p
->esi
, p
->edi
, p
->es
, p
->ds
, p
->cs
, p
->ip
);
395 case 0x0302: /* Call real mode procedure with interrupt return */
397 REALMODECALL
*p
= (REALMODECALL
*)PTR_SEG_OFF_TO_LIN( ES_reg(context
), DI_reg(context
) );
398 FIXME(int31
, "RealModeCallIret: EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx\n", p
->eax
, p
->ebx
, p
->ecx
, p
->edx
);
399 FIXME(int31
, " ESI=%08lx EDI=%08lx ES=%04x DS=%04x CS:IP=%04x:%04x\n", p
->esi
, p
->edi
, p
->es
, p
->ds
, p
->cs
, p
->ip
);
404 case 0x0303: /* Allocate Real Mode Callback Address */
406 REALMODECALL
*p
= (REALMODECALL
*)PTR_SEG_OFF_TO_LIN( ES_reg(context
), DI_reg(context
) );
407 FIXME(int31
, "AllocRMCB: EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx\n", p
->eax
, p
->ebx
, p
->ecx
, p
->edx
);
408 FIXME(int31
, " ESI=%08lx EDI=%08lx ES=%04x DS=%04x CS:IP=%04x:%04x\n", p
->esi
, p
->edi
, p
->es
, p
->ds
, p
->cs
, p
->ip
);
409 FIXME(int31
, " Function to call: %04x:%04x\n",
410 (WORD
)DS_reg(context
), SI_reg(context
) );
415 case 0x0304: /* Free Real Mode Callback Address */
417 FIXME(int31
, "FreeRMCB: callback address: %04x:%04x\n",
418 CX_reg(context
), DX_reg(context
));
423 case 0x0400: /* Get DPMI version */
428 AX_reg(context
) = 0x005a; /* DPMI version 0.90 */
429 BX_reg(context
) = 0x0005; /* Flags: 32-bit, virtual memory */
430 CL_reg(context
) = si
.wProcessorLevel
;
431 DX_reg(context
) = 0x0102; /* Master/slave interrupt controller base*/
434 case 0x0500: /* Get free memory information */
438 mmi
.dwSize
= sizeof(mmi
);
440 ptr
= (BYTE
*)PTR_SEG_OFF_TO_LIN(ES_reg(context
),DI_reg(context
));
441 /* the layout is just the same as MEMMANINFO, but without
444 memcpy(ptr
,((char*)&mmi
)+4,sizeof(mmi
)-4);
447 case 0x0501: /* Allocate memory block */
448 if (!(ptr
= (BYTE
*)VirtualAlloc(NULL
, MAKELONG(CX_reg(context
), BX_reg(context
)), MEM_COMMIT
, PAGE_EXECUTE_READWRITE
)))
450 AX_reg(context
) = 0x8012; /* linear memory not available */
455 BX_reg(context
) = SI_reg(context
) = HIWORD(ptr
);
456 CX_reg(context
) = DI_reg(context
) = LOWORD(ptr
);
460 case 0x0502: /* Free memory block */
461 VirtualFree((void *)MAKELONG(DI_reg(context
), SI_reg(context
)), 0, MEM_RELEASE
);
464 case 0x0503: /* Resize memory block */
465 if (!(ptr
= (BYTE
*)HeapReAlloc( GetProcessHeap(), 0,
466 (void *)MAKELONG(DI_reg(context
),SI_reg(context
)),
467 MAKELONG(CX_reg(context
),BX_reg(context
)))))
469 AX_reg(context
) = 0x8012; /* linear memory not available */
474 BX_reg(context
) = SI_reg(context
) = HIWORD(ptr
);
475 CX_reg(context
) = DI_reg(context
) = LOWORD(ptr
);
479 case 0x0600: /* Lock linear region */
480 break; /* Just ignore it */
482 case 0x0601: /* Unlock linear region */
483 break; /* Just ignore it */
485 case 0x0602: /* Unlock real-mode region */
486 break; /* Just ignore it */
488 case 0x0603: /* Lock real-mode region */
489 break; /* Just ignore it */
491 case 0x0604: /* Get page size */
493 CX_reg(context
) = 4096;
496 case 0x0702: /* Mark page as demand-paging candidate */
497 break; /* Just ignore it */
499 case 0x0703: /* Discard page contents */
500 break; /* Just ignore it */
502 case 0x0800: /* Physical address mapping */
503 if(!(ptr
=DOSMEM_MapRealToLinear(MAKELONG(CX_reg(context
),BX_reg(context
)))))
505 AX_reg(context
) = 0x8021;
510 BX_reg(context
) = HIWORD(ptr
);
511 CX_reg(context
) = LOWORD(ptr
);
512 RESET_CFLAG(context
);
517 INT_BARF( context
, 0x31 );
518 AX_reg(context
) = 0x8001; /* unsupported function */