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, untested!\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;
221 ERR(int31
,"could not allocate default stack\n");
225 stack16
= CTX_SEG_OFF_TO_LIN(context
, SS_reg(context
), SP_reg(context
));
226 addr
= NULL
; /* avoid gcc warning */
228 SP_reg(context
) -= args
*sizeof(WORD
) + (iret
?1:0);
230 stack16
= THREAD_STACK16(thdb
);
233 if (args
) memcpy(stack16
, stack
, args
*sizeof(WORD
) );
234 /* push flags if iret */
237 *stack16
= FL_reg(context
);
240 /* push return address (return to interrupt wrapper) */
241 *(--stack16
) = pModule
->lpDosTask
->dpmi_seg
;
242 *(--stack16
) = pModule
->lpDosTask
->wrap_ofs
;
243 /* push call address */
244 *(--stack16
) = CS_reg(context
);
245 *(--stack16
) = IP_reg(context
);
247 SP_reg(context
) -= 4*sizeof(WORD
);
248 /* set initial CS:IP to the wrapper's "lret" */
249 CS_reg(context
) = pModule
->lpDosTask
->dpmi_seg
;
250 IP_reg(context
) = pModule
->lpDosTask
->call_ofs
;
251 TRACE(int31
,"entering real mode...\n");
252 DOSVM_Enter( context
);
253 TRACE(int31
,"returned from real-mode call\n");
254 if (alloc
) DOSMEM_FreeBlock( pModule
->self
, addr
);
256 addr
= CTX_SEG_OFF_TO_LIN(context
, CS_reg(context
), IP_reg(context
));
257 sel
= SELECTOR_AllocBlock( addr
, 0x10000, SEGMENT_CODE
, FALSE
, FALSE
);
258 seg_addr
= PTR_SEG_OFF_TO_SEGPTR( sel
, 0 );
260 CS_reg(context
) = HIWORD(seg_addr
);
261 IP_reg(context
) = LOWORD(seg_addr
);
262 EBP_reg(context
) = OFFSETOF( thdb
->cur_stack
)
263 + (WORD
)&((STACK16FRAME
*)0)->bp
;
264 Callbacks
->CallRegisterShortProc(context
, args
*sizeof(WORD
));
271 /**********************************************************************
274 static void INT_DoRealModeInt( CONTEXT
*context
)
276 CONTEXT realmode_ctx
;
277 FARPROC16 rm_int
= INT_GetRMHandler( BL_reg(context
) );
278 REALMODECALL
*call
= (REALMODECALL
*)PTR_SEG_OFF_TO_LIN( ES_reg(context
),
280 INT_GetRealModeContext( call
, &realmode_ctx
);
283 /* we need to check if a real-mode program has hooked the interrupt */
284 if (HIWORD(rm_int
)!=0xF000) {
285 /* yup, which means we need to switch to real mode... */
286 CS_reg(&realmode_ctx
) = HIWORD(rm_int
);
287 EIP_reg(&realmode_ctx
) = LOWORD(rm_int
);
288 if (DPMI_CallRMProc( &realmode_ctx
, NULL
, 0, TRUE
))
293 RESET_CFLAG(context
);
294 if (INT_RealModeInterrupt( BL_reg(context
), &realmode_ctx
))
296 if (EFL_reg(context
)&1) {
297 FIXME(int31
,"%02x: EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx\n",
298 BL_reg(context
), EAX_reg(&realmode_ctx
), EBX_reg(&realmode_ctx
),
299 ECX_reg(&realmode_ctx
), EDX_reg(&realmode_ctx
));
300 FIXME(int31
," ESI=%08lx EDI=%08lx DS=%04lx ES=%04lx\n",
301 ESI_reg(&realmode_ctx
), EDI_reg(&realmode_ctx
),
302 DS_reg(&realmode_ctx
), ES_reg(&realmode_ctx
) );
305 INT_SetRealModeContext( call
, &realmode_ctx
);
309 static void CallRMProcFar( CONTEXT
*context
)
311 REALMODECALL
*p
= (REALMODECALL
*)PTR_SEG_OFF_TO_LIN( ES_reg(context
), DI_reg(context
) );
313 THDB
*thdb
= THREAD_Current();
318 TRACE(int31
, "RealModeCall: EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx\n",
319 p
->eax
, p
->ebx
, p
->ecx
, p
->edx
);
320 TRACE(int31
, " ESI=%08lx EDI=%08lx ES=%04x DS=%04x CS:IP=%04x:%04x, %d WORD arguments\n",
321 p
->esi
, p
->edi
, p
->es
, p
->ds
, p
->cs
, p
->ip
, CX_reg(context
) );
323 if (!(p
->cs
) && !(p
->ip
)) { /* remove this check
324 if Int21/6501 case map function
325 has been implemented */
329 INT_GetRealModeContext(p
, &context16
);
332 addr
= DOSMEM_MapRealToLinear(MAKELONG(p
->ip
, p
->cs
));
333 sel
= SELECTOR_AllocBlock( addr
, 0x10000, SEGMENT_CODE
, FALSE
, FALSE
);
334 seg_addr
= PTR_SEG_OFF_TO_SEGPTR( sel
, 0 );
336 CS_reg(&context16
) = HIWORD(seg_addr
);
337 IP_reg(&context16
) = LOWORD(seg_addr
);
338 EBP_reg(&context16
) = OFFSETOF( thdb
->cur_stack
)
339 + (WORD
)&((STACK16FRAME
*)0)->bp
;
341 argsize
= CX_reg(context
)*sizeof(WORD
);
342 memcpy( ((LPBYTE
)THREAD_STACK16(thdb
))-argsize
,
343 (LPBYTE
)PTR_SEG_OFF_TO_LIN(SS_reg(context
), SP_reg(context
))+6, argsize
);
345 Callbacks
->CallRegisterShortProc(&context16
, argsize
);
349 DPMI_CallRMProc( &context16
, ((LPWORD
)PTR_SEG_OFF_TO_LIN(SS_reg(context
), SP_reg(context
)))+3,
350 CX_reg(context
), 0 );
352 INT_SetRealModeContext(p
, &context16
);
356 void WINAPI
RMCallbackProc( FARPROC16 pmProc
, REALMODECALL
*rmc
)
359 INT_GetRealModeContext(rmc
, &ctx
);
360 Callbacks
->CallRegisterShortProc(&ctx
, 0);
364 static void AllocRMCB( CONTEXT
*context
)
366 RMCB
*NewRMCB
= HeapAlloc(GetProcessHeap(), 0, sizeof(RMCB
));
367 REALMODECALL
*p
= (REALMODECALL
*)PTR_SEG_OFF_TO_LIN( ES_reg(context
), DI_reg(context
) );
370 FIXME(int31
, "EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx\n", p
->eax
, p
->ebx
, p
->ecx
, p
->edx
);
371 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
);
372 FIXME(int31
, " Function to call: %04x:%04x\n",
373 (WORD
)DS_reg(context
), SI_reg(context
) );
377 LPVOID RMCBmem
= DOSMEM_GetBlock(0, 20, &uParagraph
);
380 *p
++ = 0x68; /* pushl */
382 PTR_SEG_OFF_TO_LIN(ES_reg(context
), SI_reg(context
)); /* pmode proc to call */
384 *p
++ = 0x68; /* pushl */
386 PTR_SEG_OFF_TO_LIN(ES_reg(context
), DI_reg(context
));
388 *p
++ = 0x9a; /* lcall */
389 *(FARPROC16
*)p
= (FARPROC16
)RMCallbackProc
; /* FIXME ? */
393 *p
++=0xc3; /* retf */
394 NewRMCB
->address
= MAKELONG(0, uParagraph
);
395 NewRMCB
->next
= FirstRMCB
;
397 CX_reg(context
) = uParagraph
;
402 AX_reg(context
) = 0x8015; /* callback unavailable */
408 static void FreeRMCB( CONTEXT
*context
)
410 RMCB
*CurrRMCB
= FirstRMCB
;
411 RMCB
*PrevRMCB
= NULL
;
413 FIXME(int31
, "callback address: %04x:%04x\n",
414 CX_reg(context
), DX_reg(context
));
416 while (CurrRMCB
&& (CurrRMCB
->address
!= MAKELONG(DX_reg(context
), CX_reg(context
))))
419 CurrRMCB
= CurrRMCB
->next
;
424 PrevRMCB
->next
= CurrRMCB
->next
;
426 FirstRMCB
= CurrRMCB
->next
;
427 DOSMEM_FreeBlock(0, DOSMEM_MapRealToLinear(CurrRMCB
->address
));
428 HeapFree(GetProcessHeap(), 0, CurrRMCB
);
432 AX_reg(context
) = 0x8024; /* invalid callback address */
438 /* (see loader/dos/module.c, function MZ_InitDPMI) */
440 static void StartPM( CONTEXT
*context
, LPDOSTASK lpDosTask
)
442 char *base
= DOSMEM_MemoryBase(0);
443 UINT16 cs
, ss
, ds
, es
;
446 RESET_CFLAG(context
);
447 lpDosTask
->dpmi_flag
= AX_reg(context
);
448 /* our mode switch wrapper have placed the desired CS into DX */
449 cs
= SELECTOR_AllocBlock( base
+ (DWORD
)(DX_reg(context
)<<4), 0x10000, SEGMENT_CODE
, FALSE
, FALSE
);
450 ss
= SELECTOR_AllocBlock( base
+ (DWORD
)(SS_reg(context
)<<4), 0x10000, SEGMENT_DATA
, FALSE
, FALSE
);
451 ds
= SELECTOR_AllocBlock( base
+ (DWORD
)(DS_reg(context
)<<4), 0x10000, SEGMENT_DATA
, FALSE
, FALSE
);
452 es
= SELECTOR_AllocBlock( base
+ (DWORD
)(lpDosTask
->psp_seg
<<4), 0x100, SEGMENT_DATA
, FALSE
, FALSE
);
455 CS_reg(&pm_ctx
) = lpDosTask
->dpmi_sel
;
456 /* our mode switch wrapper expects the new CS in DX, and the new SS in AX */
457 AX_reg(&pm_ctx
) = ss
;
458 DX_reg(&pm_ctx
) = cs
;
459 DS_reg(&pm_ctx
) = ds
;
460 ES_reg(&pm_ctx
) = es
;
464 TRACE(int31
,"DOS program is now entering protected mode\n");
465 Callbacks
->CallRegisterShortProc(&pm_ctx
, 0);
467 /* in the current state of affairs, we won't ever actually return here... */
469 UnMapLS(PTR_SEG_OFF_TO_SEGPTR(es
,0));
470 UnMapLS(PTR_SEG_OFF_TO_SEGPTR(ds
,0));
471 UnMapLS(PTR_SEG_OFF_TO_SEGPTR(ss
,0));
472 UnMapLS(PTR_SEG_OFF_TO_SEGPTR(cs
,0));
476 /**********************************************************************
479 * Handler for int 31h (DPMI).
482 void WINAPI
INT_Int31Handler( CONTEXT
*context
)
485 * Note: For Win32s processes, the whole linear address space is
486 * shifted by 0x10000 relative to the OS linear address space.
487 * See the comment in msdos/vxd.c.
489 DWORD offset
= PROCESS_Current()->flags
& PDB32_WIN32S_PROC
? 0x10000 : 0;
490 #define AppToWine(addr) ((addr)? ((DWORD)(addr)) + offset : 0)
491 #define WineToApp(addr) ((addr)? ((DWORD)(addr)) - offset : 0)
496 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
497 NE_MODULE
*pModule
= pTask
? NE_GetPtr( pTask
->hModule
) : NULL
;
499 GlobalUnlock16( GetCurrentTask() );
502 if (ISV86(context
) && pModule
&& pModule
->lpDosTask
) {
503 /* Called from real mode, check if it's our wrapper */
504 TRACE(int31
,"called from real mode\n");
505 if (CS_reg(context
)==pModule
->lpDosTask
->dpmi_seg
) {
506 /* This is the protected mode switch */
507 StartPM(context
,pModule
->lpDosTask
);
510 if (CS_reg(context
)==pModule
->lpDosTask
->xms_seg
) {
511 /* This is the XMS driver entry point */
512 XMS_Handler(context
);
518 RESET_CFLAG(context
);
519 switch(AX_reg(context
))
521 case 0x0000: /* Allocate LDT descriptors */
522 TRACE(int31
,"allocate LDT descriptors (%d)\n",CX_reg(context
));
523 if (!(AX_reg(context
) = AllocSelectorArray( CX_reg(context
) )))
525 TRACE(int31
,"failed\n");
526 AX_reg(context
) = 0x8011; /* descriptor unavailable */
529 TRACE(int31
,"success, array starts at 0x%04x\n",AX_reg(context
));
532 case 0x0001: /* Free LDT descriptor */
533 TRACE(int31
,"free LDT descriptor (0x%04x)\n",BX_reg(context
));
534 if (FreeSelector( BX_reg(context
) ))
536 AX_reg(context
) = 0x8022; /* invalid selector */
541 /* If a segment register contains the selector being freed, */
542 /* set it to zero. */
543 if (!((DS_reg(context
)^BX_reg(context
)) & ~3)) DS_reg(context
) = 0;
544 if (!((ES_reg(context
)^BX_reg(context
)) & ~3)) ES_reg(context
) = 0;
545 if (!((FS_reg(context
)^BX_reg(context
)) & ~3)) FS_reg(context
) = 0;
546 if (!((GS_reg(context
)^BX_reg(context
)) & ~3)) GS_reg(context
) = 0;
550 case 0x0002: /* Real mode segment to descriptor */
551 TRACE(int31
,"real mode segment to descriptor (0x%04x)\n",BX_reg(context
));
553 WORD entryPoint
= 0; /* KERNEL entry point for descriptor */
554 switch(BX_reg(context
))
556 case 0x0000: entryPoint
= 183; break; /* __0000H */
557 case 0x0040: entryPoint
= 193; break; /* __0040H */
558 case 0xa000: entryPoint
= 174; break; /* __A000H */
559 case 0xb000: entryPoint
= 181; break; /* __B000H */
560 case 0xb800: entryPoint
= 182; break; /* __B800H */
561 case 0xc000: entryPoint
= 195; break; /* __C000H */
562 case 0xd000: entryPoint
= 179; break; /* __D000H */
563 case 0xe000: entryPoint
= 190; break; /* __E000H */
564 case 0xf000: entryPoint
= 194; break; /* __F000H */
566 AX_reg(context
) = DOSMEM_AllocSelector(BX_reg(context
));
570 AX_reg(context
) = LOWORD(NE_GetEntryPoint(
571 GetModuleHandle16( "KERNEL" ),
576 case 0x0003: /* Get next selector increment */
577 TRACE(int31
,"get selector increment (__AHINCR)\n");
578 AX_reg(context
) = __AHINCR
;
581 case 0x0004: /* Lock selector (not supported) */
582 FIXME(int31
,"lock selector not supported\n");
583 AX_reg(context
) = 0; /* FIXME: is this a correct return value? */
586 case 0x0005: /* Unlock selector (not supported) */
587 FIXME(int31
,"unlock selector not supported\n");
588 AX_reg(context
) = 0; /* FIXME: is this a correct return value? */
591 case 0x0006: /* Get selector base address */
592 TRACE(int31
,"get selector base address (0x%04x)\n",BX_reg(context
));
593 if (!(dw
= GetSelectorBase( BX_reg(context
) )))
595 AX_reg(context
) = 0x8022; /* invalid selector */
601 if (pModule
&& pModule
->lpDosTask
) {
602 DWORD base
= (DWORD
)DOSMEM_MemoryBase(pModule
->self
);
603 if ((dw
>= base
) && (dw
< base
+ 0x110000)) dw
-= base
;
606 CX_reg(context
) = HIWORD(WineToApp(dw
));
607 DX_reg(context
) = LOWORD(WineToApp(dw
));
611 case 0x0007: /* Set selector base address */
612 TRACE(int31
, "set selector base address (0x%04x,0x%08lx)\n",
614 AppToWine(MAKELONG(DX_reg(context
),CX_reg(context
))));
615 dw
= AppToWine(MAKELONG(DX_reg(context
), CX_reg(context
)));
617 /* well, what else could we possibly do? */
618 if (pModule
&& pModule
->lpDosTask
) {
619 if (dw
< 0x110000) dw
+= (DWORD
)DOSMEM_MemoryBase(pModule
->self
);
622 SetSelectorBase(BX_reg(context
), dw
);
625 case 0x0008: /* Set selector limit */
626 TRACE(int31
,"set selector limit (0x%04x,0x%08lx)\n",BX_reg(context
),MAKELONG(DX_reg(context
),CX_reg(context
)));
627 dw
= MAKELONG( DX_reg(context
), CX_reg(context
) );
629 if (pModule
&& pModule
->lpDosTask
) {
630 DWORD base
= GetSelectorBase( BX_reg(context
) );
631 if ((dw
== 0xffffffff) || ((base
< 0x110000) && (base
+ dw
> 0x110000))) {
632 AX_reg(context
) = 0x8021; /* invalid value */
638 SetSelectorLimit( BX_reg(context
), dw
);
641 case 0x0009: /* Set selector access rights */
642 TRACE(int31
,"set selector access rights(0x%04x,0x%04x)\n",BX_reg(context
),CX_reg(context
));
643 SelectorAccessRights( BX_reg(context
), 1, CX_reg(context
) );
646 case 0x000a: /* Allocate selector alias */
647 TRACE(int31
,"allocate selector alias (0x%04x)\n",BX_reg(context
));
648 if (!(AX_reg(context
) = AllocCStoDSAlias( BX_reg(context
) )))
650 AX_reg(context
) = 0x8011; /* descriptor unavailable */
655 case 0x000b: /* Get descriptor */
656 TRACE(int31
,"get descriptor (0x%04x)\n",BX_reg(context
));
659 LDT_GetEntry( SELECTOR_TO_ENTRY( BX_reg(context
) ), &entry
);
660 entry
.base
= WineToApp(entry
.base
);
662 /* FIXME: should use ES:EDI for 32-bit clients */
663 LDT_EntryToBytes( PTR_SEG_OFF_TO_LIN( ES_reg(context
),
664 DI_reg(context
) ), &entry
);
668 case 0x000c: /* Set descriptor */
669 TRACE(int31
,"set descriptor (0x%04x)\n",BX_reg(context
));
672 LDT_BytesToEntry( PTR_SEG_OFF_TO_LIN( ES_reg(context
),
673 DI_reg(context
) ), &entry
);
674 entry
.base
= AppToWine(entry
.base
);
676 LDT_SetEntry( SELECTOR_TO_ENTRY( BX_reg(context
) ), &entry
);
680 case 0x000d: /* Allocate specific LDT descriptor */
681 FIXME(int31
,"allocate descriptor (0x%04x), stub!\n",BX_reg(context
));
682 AX_reg(context
) = 0x8011; /* descriptor unavailable */
685 case 0x0100: /* Allocate DOS memory block */
686 TRACE(int31
,"allocate DOS memory block (0x%x paragraphs)\n",BX_reg(context
));
687 dw
= GlobalDOSAlloc((DWORD
)BX_reg(context
)<<4);
689 AX_reg(context
) = HIWORD(dw
);
690 DX_reg(context
) = LOWORD(dw
);
692 AX_reg(context
) = 0x0008; /* insufficient memory */
693 BX_reg(context
) = DOSMEM_Available(0)>>4;
697 case 0x0101: /* Free DOS memory block */
698 TRACE(int31
,"free DOS memory block (0x%04x)\n",DX_reg(context
));
699 dw
= GlobalDOSFree(DX_reg(context
));
701 AX_reg(context
) = 0x0009; /* memory block address invalid */
705 case 0x0200: /* get real mode interrupt vector */
706 FIXME(int31
,"get realmode interupt vector(0x%02x) unimplemented.\n",
710 case 0x0201: /* set real mode interrupt vector */
711 FIXME(int31
, "set realmode interupt vector(0x%02x,0x%04x:0x%04x) unimplemented\n", BL_reg(context
),CX_reg(context
),DX_reg(context
));
714 case 0x0204: /* Get protected mode interrupt vector */
715 TRACE(int31
,"get protected mode interrupt handler (0x%02x), stub!\n",BL_reg(context
));
716 dw
= (DWORD
)INT_GetPMHandler( BL_reg(context
) );
717 CX_reg(context
) = HIWORD(dw
);
718 DX_reg(context
) = LOWORD(dw
);
721 case 0x0205: /* Set protected mode interrupt vector */
722 TRACE(int31
,"set protected mode interrupt handler (0x%02x,%p), stub!\n",
723 BL_reg(context
),PTR_SEG_OFF_TO_LIN(CX_reg(context
),DX_reg(context
)));
724 INT_SetPMHandler( BL_reg(context
),
725 (FARPROC16
)PTR_SEG_OFF_TO_SEGPTR( CX_reg(context
),
729 case 0x0300: /* Simulate real mode interrupt */
730 INT_DoRealModeInt( context
);
733 case 0x0301: /* Call real mode procedure with far return */
734 CallRMProcFar( context
);
737 case 0x0302: /* Call real mode procedure with interrupt return */
739 REALMODECALL
*p
= (REALMODECALL
*)PTR_SEG_OFF_TO_LIN( ES_reg(context
), DI_reg(context
) );
740 FIXME(int31
, "RealModeCallIret: EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx\n", p
->eax
, p
->ebx
, p
->ecx
, p
->edx
);
741 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
);
746 case 0x0303: /* Allocate Real Mode Callback Address */
747 AllocRMCB( context
);
750 case 0x0304: /* Free Real Mode Callback Address */
754 case 0x0400: /* Get DPMI version */
755 TRACE(int31
,"get DPMI version\n");
760 AX_reg(context
) = 0x005a; /* DPMI version 0.90 */
761 BX_reg(context
) = 0x0005; /* Flags: 32-bit, virtual memory */
762 CL_reg(context
) = si
.wProcessorLevel
;
763 DX_reg(context
) = 0x0102; /* Master/slave interrupt controller base*/
766 case 0x0500: /* Get free memory information */
767 TRACE(int31
,"get free memory information\n");
771 mmi
.dwSize
= sizeof(mmi
);
773 ptr
= (BYTE
*)PTR_SEG_OFF_TO_LIN(ES_reg(context
),DI_reg(context
));
774 /* the layout is just the same as MEMMANINFO, but without
777 memcpy(ptr
,((char*)&mmi
)+4,sizeof(mmi
)-4);
780 case 0x0501: /* Allocate memory block */
781 TRACE(int31
,"allocate memory block (%ld)\n",MAKELONG(CX_reg(context
),BX_reg(context
)));
782 if (!(ptr
= (BYTE
*)DPMI_xalloc(MAKELONG(CX_reg(context
), BX_reg(context
)))))
784 AX_reg(context
) = 0x8012; /* linear memory not available */
787 BX_reg(context
) = SI_reg(context
) = HIWORD(WineToApp(ptr
));
788 CX_reg(context
) = DI_reg(context
) = LOWORD(WineToApp(ptr
));
792 case 0x0502: /* Free memory block */
793 TRACE(int31
, "free memory block (0x%08lx)\n",
794 AppToWine(MAKELONG(DI_reg(context
),SI_reg(context
))));
795 DPMI_xfree( (void *)AppToWine(MAKELONG(DI_reg(context
),
799 case 0x0503: /* Resize memory block */
800 TRACE(int31
, "resize memory block (0x%08lx,%ld)\n",
801 AppToWine(MAKELONG(DI_reg(context
),SI_reg(context
))),
802 MAKELONG(CX_reg(context
),BX_reg(context
)));
803 if (!(ptr
= (BYTE
*)DPMI_xrealloc(
804 (void *)AppToWine(MAKELONG(DI_reg(context
),SI_reg(context
))),
805 MAKELONG(CX_reg(context
),BX_reg(context
)))))
807 AX_reg(context
) = 0x8012; /* linear memory not available */
810 BX_reg(context
) = SI_reg(context
) = HIWORD(WineToApp(ptr
));
811 CX_reg(context
) = DI_reg(context
) = LOWORD(WineToApp(ptr
));
815 case 0x0507: /* Modify page attributes */
816 FIXME(int31
,"modify page attributes unimplemented\n");
817 break; /* Just ignore it */
819 case 0x0600: /* Lock linear region */
820 FIXME(int31
,"lock linear region unimplemented\n");
821 break; /* Just ignore it */
823 case 0x0601: /* Unlock linear region */
824 FIXME(int31
,"unlock linear region unimplemented\n");
825 break; /* Just ignore it */
827 case 0x0602: /* Unlock real-mode region */
828 FIXME(int31
,"unlock realmode region unimplemented\n");
829 break; /* Just ignore it */
831 case 0x0603: /* Lock real-mode region */
832 FIXME(int31
,"lock realmode region unimplemented\n");
833 break; /* Just ignore it */
835 case 0x0604: /* Get page size */
836 TRACE(int31
,"get pagesize\n");
838 CX_reg(context
) = VIRTUAL_GetPageSize();
841 case 0x0702: /* Mark page as demand-paging candidate */
842 FIXME(int31
,"mark page as demand-paging candidate\n");
843 break; /* Just ignore it */
845 case 0x0703: /* Discard page contents */
846 FIXME(int31
,"discard page contents\n");
847 break; /* Just ignore it */
849 case 0x0800: /* Physical address mapping */
850 FIXME(int31
,"map real to linear (0x%08lx)\n",MAKELONG(CX_reg(context
),BX_reg(context
)));
851 if(!(ptr
=DOSMEM_MapRealToLinear(MAKELONG(CX_reg(context
),BX_reg(context
)))))
853 AX_reg(context
) = 0x8021;
858 BX_reg(context
) = HIWORD(WineToApp(ptr
));
859 CX_reg(context
) = LOWORD(WineToApp(ptr
));
860 RESET_CFLAG(context
);
865 INT_BARF( context
, 0x31 );
866 AX_reg(context
) = 0x8001; /* unsupported function */