4 * Copyright 1995 Alexandre Julliard
21 #include "selectors.h"
24 #include "stackframe.h"
27 #define DOS_GET_DRIVE(reg) ((reg) ? (reg) - 1 : DRIVE_GetCurrentDrive())
29 void CreateBPB(int drive
, BYTE
*data
, BOOL16 limited
); /* defined in int21.c */
31 static void* lastvalloced
= NULL
;
33 /* Structure for real-mode callbacks */
57 typedef struct tagRMCB
{
63 static RMCB
*FirstRMCB
= NULL
;
65 /**********************************************************************
67 * special virtualalloc, allocates lineary monoton growing memory.
68 * (the usual VirtualAlloc does not satisfy that restriction)
71 DPMI_xalloc(int len
) {
73 LPVOID oldlastv
= lastvalloced
;
79 ret
=VirtualAlloc(lastvalloced
,len
,MEM_COMMIT
|MEM_RESERVE
,PAGE_EXECUTE_READWRITE
);
81 lastvalloced
+=0x10000;
82 /* we failed to allocate one in the first round.
85 if (!xflag
&& (lastvalloced
<oldlastv
)) { /* wrapped */
86 FIXME(int31
,"failed to allocate lineary growing memory (%d bytes), using non-linear growing...\n",len
);
89 /* if we even fail to allocate something in the next
92 if ((xflag
==1) && (lastvalloced
>= oldlastv
))
94 if ((xflag
==2) && (lastvalloced
< oldlastv
)) {
95 FIXME(int31
,"failed to allocate any memory of %d bytes!\n",len
);
100 ret
=VirtualAlloc(NULL
,len
,MEM_COMMIT
|MEM_RESERVE
,PAGE_EXECUTE_READWRITE
);
101 lastvalloced
= (LPVOID
)(((DWORD
)ret
+len
+0xffff)&~0xffff);
106 DPMI_xfree(LPVOID ptr
) {
107 VirtualFree(ptr
,0,MEM_RELEASE
);
110 /* FIXME: perhaps we could grow this mapped area... */
112 DPMI_xrealloc(LPVOID ptr
,int newsize
) {
113 MEMORY_BASIC_INFORMATION mbi
;
116 newptr
= DPMI_xalloc(newsize
);
118 if (!VirtualQuery(ptr
,&mbi
,sizeof(mbi
))) {
119 FIXME(int31
,"realloc of DPMI_xallocd region %p?\n",ptr
);
122 if (mbi
.State
== MEM_FREE
) {
123 FIXME(int31
,"realloc of DPMI_xallocd region %p?\n",ptr
);
126 /* We do not shrink allocated memory. most reallocs
127 * only do grows anyway
129 if (newsize
<=mbi
.RegionSize
)
131 memcpy(newptr
,ptr
,mbi
.RegionSize
);
136 /**********************************************************************
137 * INT_GetRealModeContext
139 static void INT_GetRealModeContext( REALMODECALL
*call
, CONTEXT
*context
)
141 EAX_reg(context
) = call
->eax
;
142 EBX_reg(context
) = call
->ebx
;
143 ECX_reg(context
) = call
->ecx
;
144 EDX_reg(context
) = call
->edx
;
145 ESI_reg(context
) = call
->esi
;
146 EDI_reg(context
) = call
->edi
;
147 EBP_reg(context
) = call
->ebp
;
148 EFL_reg(context
) = call
->fl
| V86_FLAG
;
149 EIP_reg(context
) = call
->ip
;
150 ESP_reg(context
) = call
->sp
;
151 CS_reg(context
) = call
->cs
;
152 DS_reg(context
) = call
->ds
;
153 ES_reg(context
) = call
->es
;
154 FS_reg(context
) = call
->fs
;
155 GS_reg(context
) = call
->gs
;
156 (char*)V86BASE(context
) = DOSMEM_MemoryBase(0);
160 /**********************************************************************
161 * INT_SetRealModeContext
163 static void INT_SetRealModeContext( REALMODECALL
*call
, CONTEXT
*context
)
165 call
->eax
= EAX_reg(context
);
166 call
->ebx
= EBX_reg(context
);
167 call
->ecx
= ECX_reg(context
);
168 call
->edx
= EDX_reg(context
);
169 call
->esi
= ESI_reg(context
);
170 call
->edi
= EDI_reg(context
);
171 call
->ebp
= EBP_reg(context
);
172 call
->fl
= FL_reg(context
);
173 call
->ip
= IP_reg(context
);
174 call
->sp
= SP_reg(context
);
175 call
->cs
= CS_reg(context
);
176 call
->ds
= DS_reg(context
);
177 call
->es
= ES_reg(context
);
178 call
->fs
= FS_reg(context
);
179 call
->gs
= GS_reg(context
);
183 /**********************************************************************
186 * This routine does the hard work of calling a real mode procedure.
188 int DPMI_CallRMProc( CONTEXT
*context
, LPWORD stack
, int args
, int iret
)
191 THDB
*thdb
= THREAD_Current();
193 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
194 NE_MODULE
*pModule
= pTask
? NE_GetPtr( pTask
->hModule
) : NULL
;
199 GlobalUnlock16( GetCurrentTask() );
201 TRACE(int31
, "EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx\n",
202 EAX_reg(context
), EBX_reg(context
), ECX_reg(context
), EDX_reg(context
) );
203 TRACE(int31
, "ESI=%08lx EDI=%08lx ES=%04x DS=%04x CS:IP=%04x:%04x, %d WORD arguments\n",
204 ESI_reg(context
), EDI_reg(context
), ES_reg(context
), DS_reg(context
),
205 CS_reg(context
), IP_reg(context
), args
);
208 FIXME(int31
,"DPMI real-mode call using DOS VM task system, not fully tested\n");
209 if (!pModule
->lpDosTask
) {
210 TRACE(int31
,"creating VM86 task\n");
211 if (MZ_InitTask( MZ_AllocDPMITask( pModule
->self
) ) < 32) {
212 ERR(int31
,"could not setup VM86 task\n");
216 if (!SS_reg(context
)) {
217 alloc
= 1; /* allocate default stack */
218 stack16
= addr
= DOSMEM_GetBlock( pModule
->self
, 64, &(SS_reg(context
)) );
219 SP_reg(context
) = 64-2;
222 ERR(int31
,"could not allocate default stack\n");
226 stack16
= CTX_SEG_OFF_TO_LIN(context
, SS_reg(context
), ESP_reg(context
));
227 addr
= NULL
; /* avoid gcc warning */
229 SP_reg(context
) -= (args
+ (iret
?1:0)) * sizeof(WORD
);
231 stack16
= THREAD_STACK16(thdb
);
234 if (args
) memcpy(stack16
, stack
, args
*sizeof(WORD
) );
235 /* push flags if iret */
238 *stack16
= FL_reg(context
);
241 /* push return address (return to interrupt wrapper) */
242 *(--stack16
) = pModule
->lpDosTask
->dpmi_seg
;
243 *(--stack16
) = pModule
->lpDosTask
->wrap_ofs
;
244 /* push call address */
245 *(--stack16
) = CS_reg(context
);
246 *(--stack16
) = IP_reg(context
);
248 SP_reg(context
) -= 4*sizeof(WORD
);
249 /* set initial CS:IP to the wrapper's "lret" */
250 CS_reg(context
) = pModule
->lpDosTask
->dpmi_seg
;
251 IP_reg(context
) = pModule
->lpDosTask
->call_ofs
;
252 TRACE(int31
,"entering real mode...\n");
253 DOSVM_Enter( context
);
254 TRACE(int31
,"returned from real-mode call\n");
255 if (alloc
) DOSMEM_FreeBlock( pModule
->self
, addr
);
257 addr
= CTX_SEG_OFF_TO_LIN(context
, CS_reg(context
), EIP_reg(context
));
258 sel
= SELECTOR_AllocBlock( addr
, 0x10000, SEGMENT_CODE
, FALSE
, FALSE
);
259 seg_addr
= PTR_SEG_OFF_TO_SEGPTR( sel
, 0 );
261 CS_reg(context
) = HIWORD(seg_addr
);
262 IP_reg(context
) = LOWORD(seg_addr
);
263 EBP_reg(context
) = OFFSETOF( thdb
->cur_stack
)
264 + (WORD
)&((STACK16FRAME
*)0)->bp
;
265 Callbacks
->CallRegisterShortProc(context
, args
*sizeof(WORD
));
272 /**********************************************************************
275 static void INT_DoRealModeInt( CONTEXT
*context
)
277 CONTEXT realmode_ctx
;
278 FARPROC16 rm_int
= INT_GetRMHandler( BL_reg(context
) );
279 REALMODECALL
*call
= (REALMODECALL
*)PTR_SEG_OFF_TO_LIN( ES_reg(context
),
281 INT_GetRealModeContext( call
, &realmode_ctx
);
284 /* we need to check if a real-mode program has hooked the interrupt */
285 if (HIWORD(rm_int
)!=0xF000) {
286 /* yup, which means we need to switch to real mode... */
287 CS_reg(&realmode_ctx
) = HIWORD(rm_int
);
288 EIP_reg(&realmode_ctx
) = LOWORD(rm_int
);
289 if (DPMI_CallRMProc( &realmode_ctx
, NULL
, 0, TRUE
))
294 RESET_CFLAG(context
);
295 if (INT_RealModeInterrupt( BL_reg(context
), &realmode_ctx
))
297 if (EFL_reg(context
)&1) {
298 FIXME(int31
,"%02x: EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx\n",
299 BL_reg(context
), EAX_reg(&realmode_ctx
), EBX_reg(&realmode_ctx
),
300 ECX_reg(&realmode_ctx
), EDX_reg(&realmode_ctx
));
301 FIXME(int31
," ESI=%08lx EDI=%08lx DS=%04lx ES=%04lx\n",
302 ESI_reg(&realmode_ctx
), EDI_reg(&realmode_ctx
),
303 DS_reg(&realmode_ctx
), ES_reg(&realmode_ctx
) );
306 INT_SetRealModeContext( call
, &realmode_ctx
);
310 static void CallRMProcFar( CONTEXT
*context
)
312 REALMODECALL
*p
= (REALMODECALL
*)PTR_SEG_OFF_TO_LIN( ES_reg(context
), DI_reg(context
) );
314 THDB
*thdb
= THREAD_Current();
319 TRACE(int31
, "RealModeCall: EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx\n",
320 p
->eax
, p
->ebx
, p
->ecx
, p
->edx
);
321 TRACE(int31
, " ESI=%08lx EDI=%08lx ES=%04x DS=%04x CS:IP=%04x:%04x, %d WORD arguments\n",
322 p
->esi
, p
->edi
, p
->es
, p
->ds
, p
->cs
, p
->ip
, CX_reg(context
) );
324 if (!(p
->cs
) && !(p
->ip
)) { /* remove this check
325 if Int21/6501 case map function
326 has been implemented */
330 INT_GetRealModeContext(p
, &context16
);
333 addr
= DOSMEM_MapRealToLinear(MAKELONG(p
->ip
, p
->cs
));
334 sel
= SELECTOR_AllocBlock( addr
, 0x10000, SEGMENT_CODE
, FALSE
, FALSE
);
335 seg_addr
= PTR_SEG_OFF_TO_SEGPTR( sel
, 0 );
337 CS_reg(&context16
) = HIWORD(seg_addr
);
338 IP_reg(&context16
) = LOWORD(seg_addr
);
339 EBP_reg(&context16
) = OFFSETOF( thdb
->cur_stack
)
340 + (WORD
)&((STACK16FRAME
*)0)->bp
;
342 argsize
= CX_reg(context
)*sizeof(WORD
);
343 memcpy( ((LPBYTE
)THREAD_STACK16(thdb
))-argsize
,
344 (LPBYTE
)PTR_SEG_OFF_TO_LIN(SS_reg(context
), SP_reg(context
))+6, argsize
);
346 Callbacks
->CallRegisterShortProc(&context16
, argsize
);
350 DPMI_CallRMProc( &context16
, ((LPWORD
)PTR_SEG_OFF_TO_LIN(SS_reg(context
), SP_reg(context
)))+3,
351 CX_reg(context
), 0 );
353 INT_SetRealModeContext(p
, &context16
);
357 void WINAPI
RMCallbackProc( FARPROC16 pmProc
, REALMODECALL
*rmc
)
360 INT_GetRealModeContext(rmc
, &ctx
);
361 Callbacks
->CallRegisterShortProc(&ctx
, 0);
365 static void AllocRMCB( CONTEXT
*context
)
367 RMCB
*NewRMCB
= HeapAlloc(GetProcessHeap(), 0, sizeof(RMCB
));
368 REALMODECALL
*p
= (REALMODECALL
*)PTR_SEG_OFF_TO_LIN( ES_reg(context
), DI_reg(context
) );
371 FIXME(int31
, "EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx\n", p
->eax
, p
->ebx
, p
->ecx
, p
->edx
);
372 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
);
373 FIXME(int31
, " Function to call: %04x:%04x\n",
374 (WORD
)DS_reg(context
), SI_reg(context
) );
378 LPVOID RMCBmem
= DOSMEM_GetBlock(0, 20, &uParagraph
);
381 *p
++ = 0x68; /* pushl */
383 PTR_SEG_OFF_TO_LIN(ES_reg(context
), SI_reg(context
)); /* pmode proc to call */
385 *p
++ = 0x68; /* pushl */
387 PTR_SEG_OFF_TO_LIN(ES_reg(context
), DI_reg(context
));
389 *p
++ = 0x9a; /* lcall */
390 *(FARPROC16
*)p
= (FARPROC16
)RMCallbackProc
; /* FIXME ? */
394 *p
++=0xc3; /* retf */
395 NewRMCB
->address
= MAKELONG(0, uParagraph
);
396 NewRMCB
->next
= FirstRMCB
;
398 CX_reg(context
) = uParagraph
;
403 AX_reg(context
) = 0x8015; /* callback unavailable */
409 static void FreeRMCB( CONTEXT
*context
)
411 RMCB
*CurrRMCB
= FirstRMCB
;
412 RMCB
*PrevRMCB
= NULL
;
414 FIXME(int31
, "callback address: %04x:%04x\n",
415 CX_reg(context
), DX_reg(context
));
417 while (CurrRMCB
&& (CurrRMCB
->address
!= MAKELONG(DX_reg(context
), CX_reg(context
))))
420 CurrRMCB
= CurrRMCB
->next
;
425 PrevRMCB
->next
= CurrRMCB
->next
;
427 FirstRMCB
= CurrRMCB
->next
;
428 DOSMEM_FreeBlock(0, DOSMEM_MapRealToLinear(CurrRMCB
->address
));
429 HeapFree(GetProcessHeap(), 0, CurrRMCB
);
433 AX_reg(context
) = 0x8024; /* invalid callback address */
439 /* (see loader/dos/module.c, function MZ_InitDPMI) */
441 static void StartPM( CONTEXT
*context
, LPDOSTASK lpDosTask
)
443 char *base
= DOSMEM_MemoryBase(0);
444 UINT16 cs
, ss
, ds
, es
;
447 RESET_CFLAG(context
);
448 lpDosTask
->dpmi_flag
= AX_reg(context
);
449 /* our mode switch wrapper have placed the desired CS into DX */
450 cs
= SELECTOR_AllocBlock( base
+ (DWORD
)(DX_reg(context
)<<4), 0x10000, SEGMENT_CODE
, FALSE
, FALSE
);
451 ss
= SELECTOR_AllocBlock( base
+ (DWORD
)(SS_reg(context
)<<4), 0x10000, SEGMENT_DATA
, FALSE
, FALSE
);
452 ds
= SELECTOR_AllocBlock( base
+ (DWORD
)(DS_reg(context
)<<4), 0x10000, SEGMENT_DATA
, FALSE
, FALSE
);
453 es
= SELECTOR_AllocBlock( base
+ (DWORD
)(lpDosTask
->psp_seg
<<4), 0x100, SEGMENT_DATA
, FALSE
, FALSE
);
456 CS_reg(&pm_ctx
) = lpDosTask
->dpmi_sel
;
457 /* our mode switch wrapper expects the new CS in DX, and the new SS in AX */
458 AX_reg(&pm_ctx
) = ss
;
459 DX_reg(&pm_ctx
) = cs
;
460 DS_reg(&pm_ctx
) = ds
;
461 ES_reg(&pm_ctx
) = es
;
465 TRACE(int31
,"DOS program is now entering protected mode\n");
466 Callbacks
->CallRegisterShortProc(&pm_ctx
, 0);
468 /* in the current state of affairs, we won't ever actually return here... */
470 UnMapLS(PTR_SEG_OFF_TO_SEGPTR(es
,0));
471 UnMapLS(PTR_SEG_OFF_TO_SEGPTR(ds
,0));
472 UnMapLS(PTR_SEG_OFF_TO_SEGPTR(ss
,0));
473 UnMapLS(PTR_SEG_OFF_TO_SEGPTR(cs
,0));
477 /**********************************************************************
480 * Handler for int 31h (DPMI).
483 void WINAPI
INT_Int31Handler( CONTEXT
*context
)
486 * Note: For Win32s processes, the whole linear address space is
487 * shifted by 0x10000 relative to the OS linear address space.
488 * See the comment in msdos/vxd.c.
490 DWORD offset
= W32S_APPLICATION() ? W32S_OFFSET
: 0;
495 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
496 NE_MODULE
*pModule
= pTask
? NE_GetPtr( pTask
->hModule
) : NULL
;
498 GlobalUnlock16( GetCurrentTask() );
501 if (ISV86(context
) && pModule
&& pModule
->lpDosTask
) {
502 /* Called from real mode, check if it's our wrapper */
503 TRACE(int31
,"called from real mode\n");
504 if (CS_reg(context
)==pModule
->lpDosTask
->dpmi_seg
) {
505 /* This is the protected mode switch */
506 StartPM(context
,pModule
->lpDosTask
);
509 if (CS_reg(context
)==pModule
->lpDosTask
->xms_seg
) {
510 /* This is the XMS driver entry point */
511 XMS_Handler(context
);
517 RESET_CFLAG(context
);
518 switch(AX_reg(context
))
520 case 0x0000: /* Allocate LDT descriptors */
521 TRACE(int31
,"allocate LDT descriptors (%d)\n",CX_reg(context
));
522 if (!(AX_reg(context
) = AllocSelectorArray( CX_reg(context
) )))
524 TRACE(int31
,"failed\n");
525 AX_reg(context
) = 0x8011; /* descriptor unavailable */
528 TRACE(int31
,"success, array starts at 0x%04x\n",AX_reg(context
));
531 case 0x0001: /* Free LDT descriptor */
532 TRACE(int31
,"free LDT descriptor (0x%04x)\n",BX_reg(context
));
533 if (FreeSelector( BX_reg(context
) ))
535 AX_reg(context
) = 0x8022; /* invalid selector */
540 /* If a segment register contains the selector being freed, */
541 /* set it to zero. */
542 if (!((DS_reg(context
)^BX_reg(context
)) & ~3)) DS_reg(context
) = 0;
543 if (!((ES_reg(context
)^BX_reg(context
)) & ~3)) ES_reg(context
) = 0;
544 if (!((FS_reg(context
)^BX_reg(context
)) & ~3)) FS_reg(context
) = 0;
545 if (!((GS_reg(context
)^BX_reg(context
)) & ~3)) GS_reg(context
) = 0;
549 case 0x0002: /* Real mode segment to descriptor */
550 TRACE(int31
,"real mode segment to descriptor (0x%04x)\n",BX_reg(context
));
552 WORD entryPoint
= 0; /* KERNEL entry point for descriptor */
553 switch(BX_reg(context
))
555 case 0x0000: entryPoint
= 183; break; /* __0000H */
556 case 0x0040: entryPoint
= 193; break; /* __0040H */
557 case 0xa000: entryPoint
= 174; break; /* __A000H */
558 case 0xb000: entryPoint
= 181; break; /* __B000H */
559 case 0xb800: entryPoint
= 182; break; /* __B800H */
560 case 0xc000: entryPoint
= 195; break; /* __C000H */
561 case 0xd000: entryPoint
= 179; break; /* __D000H */
562 case 0xe000: entryPoint
= 190; break; /* __E000H */
563 case 0xf000: entryPoint
= 194; break; /* __F000H */
565 AX_reg(context
) = DOSMEM_AllocSelector(BX_reg(context
));
569 AX_reg(context
) = LOWORD(NE_GetEntryPoint(
570 GetModuleHandle16( "KERNEL" ),
575 case 0x0003: /* Get next selector increment */
576 TRACE(int31
,"get selector increment (__AHINCR)\n");
577 AX_reg(context
) = __AHINCR
;
580 case 0x0004: /* Lock selector (not supported) */
581 FIXME(int31
,"lock selector not supported\n");
582 AX_reg(context
) = 0; /* FIXME: is this a correct return value? */
585 case 0x0005: /* Unlock selector (not supported) */
586 FIXME(int31
,"unlock selector not supported\n");
587 AX_reg(context
) = 0; /* FIXME: is this a correct return value? */
590 case 0x0006: /* Get selector base address */
591 TRACE(int31
,"get selector base address (0x%04x)\n",BX_reg(context
));
592 if (!(dw
= GetSelectorBase( BX_reg(context
) )))
594 AX_reg(context
) = 0x8022; /* invalid selector */
600 if (pModule
&& pModule
->lpDosTask
) {
601 DWORD base
= (DWORD
)DOSMEM_MemoryBase(pModule
->self
);
602 if ((dw
>= base
) && (dw
< base
+ 0x110000)) dw
-= base
;
605 CX_reg(context
) = HIWORD(W32S_WINE2APP(dw
, offset
));
606 DX_reg(context
) = LOWORD(W32S_WINE2APP(dw
, offset
));
610 case 0x0007: /* Set selector base address */
611 TRACE(int31
, "set selector base address (0x%04x,0x%08lx)\n",
613 W32S_APP2WINE(MAKELONG(DX_reg(context
),CX_reg(context
)), offset
));
614 dw
= W32S_APP2WINE(MAKELONG(DX_reg(context
), CX_reg(context
)), offset
);
616 /* well, what else could we possibly do? */
617 if (pModule
&& pModule
->lpDosTask
) {
618 if (dw
< 0x110000) dw
+= (DWORD
)DOSMEM_MemoryBase(pModule
->self
);
621 SetSelectorBase(BX_reg(context
), dw
);
624 case 0x0008: /* Set selector limit */
625 TRACE(int31
,"set selector limit (0x%04x,0x%08lx)\n",BX_reg(context
),MAKELONG(DX_reg(context
),CX_reg(context
)));
626 dw
= MAKELONG( DX_reg(context
), CX_reg(context
) );
628 if (pModule
&& pModule
->lpDosTask
) {
629 DWORD base
= GetSelectorBase( BX_reg(context
) );
630 if ((dw
== 0xffffffff) || ((base
< 0x110000) && (base
+ dw
> 0x110000))) {
631 AX_reg(context
) = 0x8021; /* invalid value */
637 SetSelectorLimit( BX_reg(context
), dw
);
640 case 0x0009: /* Set selector access rights */
641 TRACE(int31
,"set selector access rights(0x%04x,0x%04x)\n",BX_reg(context
),CX_reg(context
));
642 SelectorAccessRights( BX_reg(context
), 1, CX_reg(context
) );
645 case 0x000a: /* Allocate selector alias */
646 TRACE(int31
,"allocate selector alias (0x%04x)\n",BX_reg(context
));
647 if (!(AX_reg(context
) = AllocCStoDSAlias( BX_reg(context
) )))
649 AX_reg(context
) = 0x8011; /* descriptor unavailable */
654 case 0x000b: /* Get descriptor */
655 TRACE(int31
,"get descriptor (0x%04x)\n",BX_reg(context
));
658 LDT_GetEntry( SELECTOR_TO_ENTRY( BX_reg(context
) ), &entry
);
659 entry
.base
= W32S_WINE2APP(entry
.base
, offset
);
661 /* FIXME: should use ES:EDI for 32-bit clients */
662 LDT_EntryToBytes( PTR_SEG_OFF_TO_LIN( ES_reg(context
),
663 DI_reg(context
) ), &entry
);
667 case 0x000c: /* Set descriptor */
668 TRACE(int31
,"set descriptor (0x%04x)\n",BX_reg(context
));
671 LDT_BytesToEntry( PTR_SEG_OFF_TO_LIN( ES_reg(context
),
672 DI_reg(context
) ), &entry
);
673 entry
.base
= W32S_APP2WINE(entry
.base
, offset
);
675 LDT_SetEntry( SELECTOR_TO_ENTRY( BX_reg(context
) ), &entry
);
679 case 0x000d: /* Allocate specific LDT descriptor */
680 FIXME(int31
,"allocate descriptor (0x%04x), stub!\n",BX_reg(context
));
681 AX_reg(context
) = 0x8011; /* descriptor unavailable */
684 case 0x0100: /* Allocate DOS memory block */
685 TRACE(int31
,"allocate DOS memory block (0x%x paragraphs)\n",BX_reg(context
));
686 dw
= GlobalDOSAlloc((DWORD
)BX_reg(context
)<<4);
688 AX_reg(context
) = HIWORD(dw
);
689 DX_reg(context
) = LOWORD(dw
);
691 AX_reg(context
) = 0x0008; /* insufficient memory */
692 BX_reg(context
) = DOSMEM_Available(0)>>4;
696 case 0x0101: /* Free DOS memory block */
697 TRACE(int31
,"free DOS memory block (0x%04x)\n",DX_reg(context
));
698 dw
= GlobalDOSFree(DX_reg(context
));
700 AX_reg(context
) = 0x0009; /* memory block address invalid */
704 case 0x0200: /* get real mode interrupt vector */
705 FIXME(int31
,"get realmode interupt vector(0x%02x) unimplemented.\n",
709 case 0x0201: /* set real mode interrupt vector */
710 FIXME(int31
, "set realmode interupt vector(0x%02x,0x%04x:0x%04x) unimplemented\n", BL_reg(context
),CX_reg(context
),DX_reg(context
));
713 case 0x0204: /* Get protected mode interrupt vector */
714 TRACE(int31
,"get protected mode interrupt handler (0x%02x), stub!\n",BL_reg(context
));
715 dw
= (DWORD
)INT_GetPMHandler( BL_reg(context
) );
716 CX_reg(context
) = HIWORD(dw
);
717 DX_reg(context
) = LOWORD(dw
);
720 case 0x0205: /* Set protected mode interrupt vector */
721 TRACE(int31
,"set protected mode interrupt handler (0x%02x,%p), stub!\n",
722 BL_reg(context
),PTR_SEG_OFF_TO_LIN(CX_reg(context
),DX_reg(context
)));
723 INT_SetPMHandler( BL_reg(context
),
724 (FARPROC16
)PTR_SEG_OFF_TO_SEGPTR( CX_reg(context
),
728 case 0x0300: /* Simulate real mode interrupt */
729 INT_DoRealModeInt( context
);
732 case 0x0301: /* Call real mode procedure with far return */
733 CallRMProcFar( context
);
736 case 0x0302: /* Call real mode procedure with interrupt return */
738 REALMODECALL
*p
= (REALMODECALL
*)PTR_SEG_OFF_TO_LIN( ES_reg(context
), DI_reg(context
) );
739 FIXME(int31
, "RealModeCallIret: EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx\n", p
->eax
, p
->ebx
, p
->ecx
, p
->edx
);
740 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
);
745 case 0x0303: /* Allocate Real Mode Callback Address */
746 AllocRMCB( context
);
749 case 0x0304: /* Free Real Mode Callback Address */
753 case 0x0400: /* Get DPMI version */
754 TRACE(int31
,"get DPMI version\n");
759 AX_reg(context
) = 0x005a; /* DPMI version 0.90 */
760 BX_reg(context
) = 0x0005; /* Flags: 32-bit, virtual memory */
761 CL_reg(context
) = si
.wProcessorLevel
;
762 DX_reg(context
) = 0x0102; /* Master/slave interrupt controller base*/
765 case 0x0500: /* Get free memory information */
766 TRACE(int31
,"get free memory information\n");
770 mmi
.dwSize
= sizeof(mmi
);
772 ptr
= (BYTE
*)PTR_SEG_OFF_TO_LIN(ES_reg(context
),DI_reg(context
));
773 /* the layout is just the same as MEMMANINFO, but without
776 memcpy(ptr
,((char*)&mmi
)+4,sizeof(mmi
)-4);
779 case 0x0501: /* Allocate memory block */
780 TRACE(int31
,"allocate memory block (%ld)\n",MAKELONG(CX_reg(context
),BX_reg(context
)));
781 if (!(ptr
= (BYTE
*)DPMI_xalloc(MAKELONG(CX_reg(context
), BX_reg(context
)))))
783 AX_reg(context
) = 0x8012; /* linear memory not available */
786 BX_reg(context
) = SI_reg(context
) = HIWORD(W32S_WINE2APP(ptr
, offset
));
787 CX_reg(context
) = DI_reg(context
) = LOWORD(W32S_WINE2APP(ptr
, offset
));
791 case 0x0502: /* Free memory block */
792 TRACE(int31
, "free memory block (0x%08lx)\n",
793 W32S_APP2WINE(MAKELONG(DI_reg(context
),SI_reg(context
)), offset
));
794 DPMI_xfree( (void *)W32S_APP2WINE(MAKELONG(DI_reg(context
),
795 SI_reg(context
)), offset
) );
798 case 0x0503: /* Resize memory block */
799 TRACE(int31
, "resize memory block (0x%08lx,%ld)\n",
800 W32S_APP2WINE(MAKELONG(DI_reg(context
),SI_reg(context
)), offset
),
801 MAKELONG(CX_reg(context
),BX_reg(context
)));
802 if (!(ptr
= (BYTE
*)DPMI_xrealloc(
803 (void *)W32S_APP2WINE(MAKELONG(DI_reg(context
),SI_reg(context
)), offset
),
804 MAKELONG(CX_reg(context
),BX_reg(context
)))))
806 AX_reg(context
) = 0x8012; /* linear memory not available */
809 BX_reg(context
) = SI_reg(context
) = HIWORD(W32S_WINE2APP(ptr
, offset
));
810 CX_reg(context
) = DI_reg(context
) = LOWORD(W32S_WINE2APP(ptr
, offset
));
814 case 0x0507: /* Modify page attributes */
815 FIXME(int31
,"modify page attributes unimplemented\n");
816 break; /* Just ignore it */
818 case 0x0600: /* Lock linear region */
819 FIXME(int31
,"lock linear region unimplemented\n");
820 break; /* Just ignore it */
822 case 0x0601: /* Unlock linear region */
823 FIXME(int31
,"unlock linear region unimplemented\n");
824 break; /* Just ignore it */
826 case 0x0602: /* Unlock real-mode region */
827 FIXME(int31
,"unlock realmode region unimplemented\n");
828 break; /* Just ignore it */
830 case 0x0603: /* Lock real-mode region */
831 FIXME(int31
,"lock realmode region unimplemented\n");
832 break; /* Just ignore it */
834 case 0x0604: /* Get page size */
835 TRACE(int31
,"get pagesize\n");
837 CX_reg(context
) = VIRTUAL_GetPageSize();
840 case 0x0702: /* Mark page as demand-paging candidate */
841 FIXME(int31
,"mark page as demand-paging candidate\n");
842 break; /* Just ignore it */
844 case 0x0703: /* Discard page contents */
845 FIXME(int31
,"discard page contents\n");
846 break; /* Just ignore it */
848 case 0x0800: /* Physical address mapping */
849 FIXME(int31
,"map real to linear (0x%08lx)\n",MAKELONG(CX_reg(context
),BX_reg(context
)));
850 if(!(ptr
=DOSMEM_MapRealToLinear(MAKELONG(CX_reg(context
),BX_reg(context
)))))
852 AX_reg(context
) = 0x8021;
857 BX_reg(context
) = HIWORD(W32S_WINE2APP(ptr
, offset
));
858 CX_reg(context
) = LOWORD(W32S_WINE2APP(ptr
, offset
));
859 RESET_CFLAG(context
);
864 INT_BARF( context
, 0x31 );
865 AX_reg(context
) = 0x8001; /* unsupported function */