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
| 0x00020000; /* V86 */
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 static void INT_DoRealModeInt( CONTEXT
*context
)
188 CONTEXT realmode_ctx
;
189 REALMODECALL
*call
= (REALMODECALL
*)PTR_SEG_OFF_TO_LIN( ES_reg(context
),
191 INT_GetRealModeContext( call
, &realmode_ctx
);
193 RESET_CFLAG(context
);
194 if (INT_RealModeInterrupt( BL_reg(context
), &realmode_ctx
))
196 if (EFL_reg(context
)&1) {
197 FIXME(int31
,"%02x: EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx\n",
198 BL_reg(context
), EAX_reg(&realmode_ctx
), EBX_reg(&realmode_ctx
),
199 ECX_reg(&realmode_ctx
), EDX_reg(&realmode_ctx
));
200 FIXME(int31
," ESI=%08lx EDI=%08lx DS=%04lx ES=%04lx\n",
201 ESI_reg(&realmode_ctx
), EDI_reg(&realmode_ctx
),
202 DS_reg(&realmode_ctx
), ES_reg(&realmode_ctx
) );
204 INT_SetRealModeContext( call
, &realmode_ctx
);
208 static void CallRMProcFar( CONTEXT
*context
)
210 REALMODECALL
*p
= (REALMODECALL
*)PTR_SEG_OFF_TO_LIN( ES_reg(context
), DI_reg(context
) );
212 THDB
*thdb
= THREAD_Current();
217 TRACE(int31
, "RealModeCall: EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx\n",
218 p
->eax
, p
->ebx
, p
->ecx
, p
->edx
);
219 TRACE(int31
, " ESI=%08lx EDI=%08lx ES=%04x DS=%04x CS:IP=%04x:%04x, %d WORD arguments\n",
220 p
->esi
, p
->edi
, p
->es
, p
->ds
, p
->cs
, p
->ip
, CX_reg(context
) );
222 if (!(p
->cs
) && !(p
->ip
)) { /* remove this check
223 if Int21/6501 case map function
224 has been implemented */
228 INT_GetRealModeContext(p
, &context16
);
230 addr
= DOSMEM_MapRealToLinear(MAKELONG(p
->ip
, p
->cs
));
231 sel
= SELECTOR_AllocBlock( addr
, 0x10000, SEGMENT_CODE
, FALSE
, FALSE
);
232 seg_addr
= PTR_SEG_OFF_TO_SEGPTR( sel
, 0 );
234 CS_reg(&context16
) = HIWORD(seg_addr
);
235 IP_reg(&context16
) = LOWORD(seg_addr
);
236 EBP_reg(&context16
) = OFFSETOF( thdb
->cur_stack
)
237 + (WORD
)&((STACK16FRAME
*)0)->bp
;
239 argsize
= CX_reg(context
)*sizeof(WORD
);
240 memcpy( ((LPBYTE
)THREAD_STACK16(thdb
))-argsize
,
241 (LPBYTE
)PTR_SEG_OFF_TO_LIN(SS_reg(context
), SP_reg(context
))+6, argsize
);
243 Callbacks
->CallRegisterShortProc(&context16
, argsize
);
246 INT_SetRealModeContext(p
, &context16
);
250 void WINAPI
RMCallbackProc( FARPROC16 pmProc
, REALMODECALL
*rmc
)
253 INT_GetRealModeContext(rmc
, &ctx
);
254 Callbacks
->CallRegisterShortProc(&ctx
, 0);
258 static void AllocRMCB( CONTEXT
*context
)
260 RMCB
*NewRMCB
= HeapAlloc(GetProcessHeap(), 0, sizeof(RMCB
));
261 REALMODECALL
*p
= (REALMODECALL
*)PTR_SEG_OFF_TO_LIN( ES_reg(context
), DI_reg(context
) );
264 FIXME(int31
, "EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx\n", p
->eax
, p
->ebx
, p
->ecx
, p
->edx
);
265 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
);
266 FIXME(int31
, " Function to call: %04x:%04x\n",
267 (WORD
)DS_reg(context
), SI_reg(context
) );
271 LPVOID RMCBmem
= DOSMEM_GetBlock(0, 20, &uParagraph
);
274 *p
++ = 0x68; /* pushl */
276 PTR_SEG_OFF_TO_LIN(ES_reg(context
), SI_reg(context
)); /* pmode proc to call */
278 *p
++ = 0x68; /* pushl */
280 PTR_SEG_OFF_TO_LIN(ES_reg(context
), DI_reg(context
));
282 *p
++ = 0x9a; /* lcall */
283 *(FARPROC16
*)p
= (FARPROC16
)RMCallbackProc
; /* FIXME ? */
287 *p
++=0xc3; /* retf */
288 NewRMCB
->address
= MAKELONG(0, uParagraph
);
289 NewRMCB
->next
= FirstRMCB
;
291 CX_reg(context
) = uParagraph
;
296 AX_reg(context
) = 0x8015; /* callback unavailable */
302 static void FreeRMCB( CONTEXT
*context
)
304 RMCB
*CurrRMCB
= FirstRMCB
;
305 RMCB
*PrevRMCB
= NULL
;
307 FIXME(int31
, "callback address: %04x:%04x\n",
308 CX_reg(context
), DX_reg(context
));
310 while (CurrRMCB
&& (CurrRMCB
->address
!= MAKELONG(DX_reg(context
), CX_reg(context
))))
313 CurrRMCB
= CurrRMCB
->next
;
318 PrevRMCB
->next
= CurrRMCB
->next
;
320 FirstRMCB
= CurrRMCB
->next
;
321 DOSMEM_FreeBlock(0, DOSMEM_MapRealToLinear(CurrRMCB
->address
));
322 HeapFree(GetProcessHeap(), 0, CurrRMCB
);
326 AX_reg(context
) = 0x8024; /* invalid callback address */
332 /* (see loader/dos/module.c, function MZ_InitDPMI) */
334 static void StartPM( CONTEXT
*context
, LPDOSTASK lpDosTask
)
336 char *base
= DOSMEM_MemoryBase(0);
337 UINT16 cs
, ss
, ds
, es
;
340 RESET_CFLAG(context
);
341 lpDosTask
->dpmi_flag
= AX_reg(context
);
342 /* our mode switch wrapper have placed the desired CS into DX */
343 cs
= SELECTOR_AllocBlock( base
+ (DWORD
)(DX_reg(context
)<<4), 0x10000, SEGMENT_CODE
, FALSE
, FALSE
);
344 ss
= SELECTOR_AllocBlock( base
+ (DWORD
)(SS_reg(context
)<<4), 0x10000, SEGMENT_DATA
, FALSE
, FALSE
);
345 ds
= SELECTOR_AllocBlock( base
+ (DWORD
)(DS_reg(context
)<<4), 0x10000, SEGMENT_DATA
, FALSE
, FALSE
);
346 es
= SELECTOR_AllocBlock( base
+ (DWORD
)(lpDosTask
->psp_seg
<<4), 0x100, SEGMENT_DATA
, FALSE
, FALSE
);
349 CS_reg(&pm_ctx
) = lpDosTask
->dpmi_sel
;
350 /* our mode switch wrapper expects the new CS in DX, and the new SS in AX */
351 AX_reg(&pm_ctx
) = ss
;
352 DX_reg(&pm_ctx
) = cs
;
353 DS_reg(&pm_ctx
) = ds
;
354 ES_reg(&pm_ctx
) = es
;
358 TRACE(int31
,"DOS program is now entering protected mode\n");
359 Callbacks
->CallRegisterShortProc(&pm_ctx
, 0);
361 /* in the current state of affairs, we won't ever actually return here... */
363 UnMapLS(PTR_SEG_OFF_TO_SEGPTR(es
,0));
364 UnMapLS(PTR_SEG_OFF_TO_SEGPTR(ds
,0));
365 UnMapLS(PTR_SEG_OFF_TO_SEGPTR(ss
,0));
366 UnMapLS(PTR_SEG_OFF_TO_SEGPTR(cs
,0));
370 /**********************************************************************
373 * Handler for int 31h (DPMI).
376 void WINAPI
INT_Int31Handler( CONTEXT
*context
)
379 * Note: For Win32s processes, the whole linear address space is
380 * shifted by 0x10000 relative to the OS linear address space.
381 * See the comment in msdos/vxd.c.
383 DWORD offset
= PROCESS_Current()->flags
& PDB32_WIN32S_PROC
? 0x10000 : 0;
384 #define AppToWine(addr) ((addr)? ((DWORD)(addr)) + offset : 0)
385 #define WineToApp(addr) ((addr)? ((DWORD)(addr)) - offset : 0)
390 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
391 NE_MODULE
*pModule
= pTask
? NE_GetPtr( pTask
->hModule
) : NULL
;
393 GlobalUnlock16( GetCurrentTask() );
396 if (ISV86(context
) && pModule
&& pModule
->lpDosTask
) {
397 /* Called from real mode, check if it's our wrapper */
398 TRACE(int31
,"called from real mode\n");
399 if (CS_reg(context
)==pModule
->lpDosTask
->dpmi_seg
) {
400 /* This is the protected mode switch */
401 StartPM(context
,pModule
->lpDosTask
);
404 if (CS_reg(context
)==pModule
->lpDosTask
->xms_seg
) {
405 /* This is the XMS driver entry point */
406 XMS_Handler(context
);
412 RESET_CFLAG(context
);
413 switch(AX_reg(context
))
415 case 0x0000: /* Allocate LDT descriptors */
416 TRACE(int31
,"allocate LDT descriptors (%d)\n",CX_reg(context
));
417 if (!(AX_reg(context
) = AllocSelectorArray( CX_reg(context
) )))
419 TRACE(int31
,"failed\n");
420 AX_reg(context
) = 0x8011; /* descriptor unavailable */
423 TRACE(int31
,"success, array starts at 0x%04x\n",AX_reg(context
));
426 case 0x0001: /* Free LDT descriptor */
427 TRACE(int31
,"free LDT descriptor (0x%04x)\n",BX_reg(context
));
428 if (FreeSelector( BX_reg(context
) ))
430 AX_reg(context
) = 0x8022; /* invalid selector */
435 /* If a segment register contains the selector being freed, */
436 /* set it to zero. */
437 if (!((DS_reg(context
)^BX_reg(context
)) & ~3)) DS_reg(context
) = 0;
438 if (!((ES_reg(context
)^BX_reg(context
)) & ~3)) ES_reg(context
) = 0;
439 if (!((FS_reg(context
)^BX_reg(context
)) & ~3)) FS_reg(context
) = 0;
440 if (!((GS_reg(context
)^BX_reg(context
)) & ~3)) GS_reg(context
) = 0;
444 case 0x0002: /* Real mode segment to descriptor */
445 TRACE(int31
,"real mode segment to descriptor (0x%04x)\n",BX_reg(context
));
447 WORD entryPoint
= 0; /* KERNEL entry point for descriptor */
448 switch(BX_reg(context
))
450 case 0x0000: entryPoint
= 183; break; /* __0000H */
451 case 0x0040: entryPoint
= 193; break; /* __0040H */
452 case 0xa000: entryPoint
= 174; break; /* __A000H */
453 case 0xb000: entryPoint
= 181; break; /* __B000H */
454 case 0xb800: entryPoint
= 182; break; /* __B800H */
455 case 0xc000: entryPoint
= 195; break; /* __C000H */
456 case 0xd000: entryPoint
= 179; break; /* __D000H */
457 case 0xe000: entryPoint
= 190; break; /* __E000H */
458 case 0xf000: entryPoint
= 194; break; /* __F000H */
460 AX_reg(context
) = DOSMEM_AllocSelector(BX_reg(context
));
464 AX_reg(context
) = LOWORD(NE_GetEntryPoint(
465 GetModuleHandle16( "KERNEL" ),
470 case 0x0003: /* Get next selector increment */
471 TRACE(int31
,"get selector increment (__AHINCR)\n");
472 AX_reg(context
) = __AHINCR
;
475 case 0x0004: /* Lock selector (not supported) */
476 FIXME(int31
,"lock selector not supported\n");
477 AX_reg(context
) = 0; /* FIXME: is this a correct return value? */
480 case 0x0005: /* Unlock selector (not supported) */
481 FIXME(int31
,"unlock selector not supported\n");
482 AX_reg(context
) = 0; /* FIXME: is this a correct return value? */
485 case 0x0006: /* Get selector base address */
486 TRACE(int31
,"get selector base address (0x%04x)\n",BX_reg(context
));
487 if (!(dw
= GetSelectorBase( BX_reg(context
) )))
489 AX_reg(context
) = 0x8022; /* invalid selector */
495 if (pModule
&& pModule
->lpDosTask
) {
496 DWORD base
= (DWORD
)DOSMEM_MemoryBase(pModule
->self
);
497 if ((dw
>= base
) && (dw
< base
+ 0x110000)) dw
-= base
;
500 CX_reg(context
) = HIWORD(WineToApp(dw
));
501 DX_reg(context
) = LOWORD(WineToApp(dw
));
505 case 0x0007: /* Set selector base address */
506 TRACE(int31
, "set selector base address (0x%04x,0x%08lx)\n",
508 AppToWine(MAKELONG(DX_reg(context
),CX_reg(context
))));
509 dw
= AppToWine(MAKELONG(DX_reg(context
), CX_reg(context
)));
511 /* well, what else could we possibly do? */
512 if (pModule
&& pModule
->lpDosTask
) {
513 if (dw
< 0x110000) dw
+= (DWORD
)DOSMEM_MemoryBase(pModule
->self
);
516 SetSelectorBase(BX_reg(context
), dw
);
519 case 0x0008: /* Set selector limit */
520 TRACE(int31
,"set selector limit (0x%04x,0x%08lx)\n",BX_reg(context
),MAKELONG(DX_reg(context
),CX_reg(context
)));
521 dw
= MAKELONG( DX_reg(context
), CX_reg(context
) );
523 if (pModule
&& pModule
->lpDosTask
) {
524 DWORD base
= GetSelectorBase( BX_reg(context
) );
525 if ((dw
== 0xffffffff) || ((base
< 0x110000) && (base
+ dw
> 0x110000))) {
526 AX_reg(context
) = 0x8021; /* invalid value */
532 SetSelectorLimit( BX_reg(context
), dw
);
535 case 0x0009: /* Set selector access rights */
536 TRACE(int31
,"set selector access rights(0x%04x,0x%04x)\n",BX_reg(context
),CX_reg(context
));
537 SelectorAccessRights( BX_reg(context
), 1, CX_reg(context
) );
540 case 0x000a: /* Allocate selector alias */
541 TRACE(int31
,"allocate selector alias (0x%04x)\n",BX_reg(context
));
542 if (!(AX_reg(context
) = AllocCStoDSAlias( BX_reg(context
) )))
544 AX_reg(context
) = 0x8011; /* descriptor unavailable */
549 case 0x000b: /* Get descriptor */
550 TRACE(int31
,"get descriptor (0x%04x)\n",BX_reg(context
));
553 LDT_GetEntry( SELECTOR_TO_ENTRY( BX_reg(context
) ), &entry
);
554 entry
.base
= WineToApp(entry
.base
);
556 /* FIXME: should use ES:EDI for 32-bit clients */
557 LDT_EntryToBytes( PTR_SEG_OFF_TO_LIN( ES_reg(context
),
558 DI_reg(context
) ), &entry
);
562 case 0x000c: /* Set descriptor */
563 TRACE(int31
,"set descriptor (0x%04x)\n",BX_reg(context
));
566 LDT_BytesToEntry( PTR_SEG_OFF_TO_LIN( ES_reg(context
),
567 DI_reg(context
) ), &entry
);
568 entry
.base
= AppToWine(entry
.base
);
570 LDT_SetEntry( SELECTOR_TO_ENTRY( BX_reg(context
) ), &entry
);
574 case 0x000d: /* Allocate specific LDT descriptor */
575 FIXME(int31
,"allocate descriptor (0x%04x), stub!\n",BX_reg(context
));
576 AX_reg(context
) = 0x8011; /* descriptor unavailable */
579 case 0x0100: /* Allocate DOS memory block */
580 TRACE(int31
,"allocate DOS memory block (0x%x paragraphs)\n",BX_reg(context
));
581 dw
= GlobalDOSAlloc((DWORD
)BX_reg(context
)<<4);
583 AX_reg(context
) = HIWORD(dw
);
584 DX_reg(context
) = LOWORD(dw
);
586 AX_reg(context
) = 0x0008; /* insufficient memory */
587 BX_reg(context
) = DOSMEM_Available(0)>>4;
591 case 0x0101: /* Free DOS memory block */
592 TRACE(int31
,"free DOS memory block (0x%04x)\n",DX_reg(context
));
593 dw
= GlobalDOSFree(DX_reg(context
));
595 AX_reg(context
) = 0x0009; /* memory block address invalid */
599 case 0x0200: /* get real mode interrupt vector */
600 FIXME(int31
,"get realmode interupt vector(0x%02x) unimplemented.\n",
604 case 0x0201: /* set real mode interrupt vector */
605 FIXME(int31
, "set realmode interupt vector(0x%02x,0x%04x:0x%04x) unimplemented\n", BL_reg(context
),CX_reg(context
),DX_reg(context
));
608 case 0x0204: /* Get protected mode interrupt vector */
609 TRACE(int31
,"get protected mode interrupt handler (0x%02x), stub!\n",BL_reg(context
));
610 dw
= (DWORD
)INT_GetPMHandler( BL_reg(context
) );
611 CX_reg(context
) = HIWORD(dw
);
612 DX_reg(context
) = LOWORD(dw
);
615 case 0x0205: /* Set protected mode interrupt vector */
616 TRACE(int31
,"set protected mode interrupt handler (0x%02x,%p), stub!\n",
617 BL_reg(context
),PTR_SEG_OFF_TO_LIN(CX_reg(context
),DX_reg(context
)));
618 INT_SetPMHandler( BL_reg(context
),
619 (FARPROC16
)PTR_SEG_OFF_TO_SEGPTR( CX_reg(context
),
623 case 0x0300: /* Simulate real mode interrupt */
624 INT_DoRealModeInt( context
);
627 case 0x0301: /* Call real mode procedure with far return */
628 CallRMProcFar( context
);
631 case 0x0302: /* Call real mode procedure with interrupt return */
633 REALMODECALL
*p
= (REALMODECALL
*)PTR_SEG_OFF_TO_LIN( ES_reg(context
), DI_reg(context
) );
634 FIXME(int31
, "RealModeCallIret: EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx\n", p
->eax
, p
->ebx
, p
->ecx
, p
->edx
);
635 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
);
640 case 0x0303: /* Allocate Real Mode Callback Address */
641 AllocRMCB( context
);
644 case 0x0304: /* Free Real Mode Callback Address */
648 case 0x0400: /* Get DPMI version */
649 TRACE(int31
,"get DPMI version\n");
654 AX_reg(context
) = 0x005a; /* DPMI version 0.90 */
655 BX_reg(context
) = 0x0005; /* Flags: 32-bit, virtual memory */
656 CL_reg(context
) = si
.wProcessorLevel
;
657 DX_reg(context
) = 0x0102; /* Master/slave interrupt controller base*/
660 case 0x0500: /* Get free memory information */
661 TRACE(int31
,"get free memory information\n");
665 mmi
.dwSize
= sizeof(mmi
);
667 ptr
= (BYTE
*)PTR_SEG_OFF_TO_LIN(ES_reg(context
),DI_reg(context
));
668 /* the layout is just the same as MEMMANINFO, but without
671 memcpy(ptr
,((char*)&mmi
)+4,sizeof(mmi
)-4);
674 case 0x0501: /* Allocate memory block */
675 TRACE(int31
,"allocate memory block (%ld)\n",MAKELONG(CX_reg(context
),BX_reg(context
)));
676 if (!(ptr
= (BYTE
*)DPMI_xalloc(MAKELONG(CX_reg(context
), BX_reg(context
)))))
678 AX_reg(context
) = 0x8012; /* linear memory not available */
681 BX_reg(context
) = SI_reg(context
) = HIWORD(WineToApp(ptr
));
682 CX_reg(context
) = DI_reg(context
) = LOWORD(WineToApp(ptr
));
686 case 0x0502: /* Free memory block */
687 TRACE(int31
, "free memory block (0x%08lx)\n",
688 AppToWine(MAKELONG(DI_reg(context
),SI_reg(context
))));
689 DPMI_xfree( (void *)AppToWine(MAKELONG(DI_reg(context
),
693 case 0x0503: /* Resize memory block */
694 TRACE(int31
, "resize memory block (0x%08lx,%ld)\n",
695 AppToWine(MAKELONG(DI_reg(context
),SI_reg(context
))),
696 MAKELONG(CX_reg(context
),BX_reg(context
)));
697 if (!(ptr
= (BYTE
*)DPMI_xrealloc(
698 (void *)AppToWine(MAKELONG(DI_reg(context
),SI_reg(context
))),
699 MAKELONG(CX_reg(context
),BX_reg(context
)))))
701 AX_reg(context
) = 0x8012; /* linear memory not available */
704 BX_reg(context
) = SI_reg(context
) = HIWORD(WineToApp(ptr
));
705 CX_reg(context
) = DI_reg(context
) = LOWORD(WineToApp(ptr
));
709 case 0x0507: /* Modify page attributes */
710 FIXME(int31
,"modify page attributes unimplemented\n");
711 break; /* Just ignore it */
713 case 0x0600: /* Lock linear region */
714 FIXME(int31
,"lock linear region unimplemented\n");
715 break; /* Just ignore it */
717 case 0x0601: /* Unlock linear region */
718 FIXME(int31
,"unlock linear region unimplemented\n");
719 break; /* Just ignore it */
721 case 0x0602: /* Unlock real-mode region */
722 FIXME(int31
,"unlock realmode region unimplemented\n");
723 break; /* Just ignore it */
725 case 0x0603: /* Lock real-mode region */
726 FIXME(int31
,"lock realmode region unimplemented\n");
727 break; /* Just ignore it */
729 case 0x0604: /* Get page size */
730 TRACE(int31
,"get pagesize\n");
732 CX_reg(context
) = VIRTUAL_GetPageSize();
735 case 0x0702: /* Mark page as demand-paging candidate */
736 FIXME(int31
,"mark page as demand-paging candidate\n");
737 break; /* Just ignore it */
739 case 0x0703: /* Discard page contents */
740 FIXME(int31
,"discard page contents\n");
741 break; /* Just ignore it */
743 case 0x0800: /* Physical address mapping */
744 FIXME(int31
,"map real to linear (0x%08lx)\n",MAKELONG(CX_reg(context
),BX_reg(context
)));
745 if(!(ptr
=DOSMEM_MapRealToLinear(MAKELONG(CX_reg(context
),BX_reg(context
)))))
747 AX_reg(context
) = 0x8021;
752 BX_reg(context
) = HIWORD(WineToApp(ptr
));
753 CX_reg(context
) = LOWORD(WineToApp(ptr
));
754 RESET_CFLAG(context
);
759 INT_BARF( context
, 0x31 );
760 AX_reg(context
) = 0x8001; /* unsupported function */