Bugfixes, shellview uses DPA's now, IShellView_GetItemObject implemented.
[wine/multimedia.git] / msdos / dpmi.c
blob913d832d858f87008f4461693254308340503e3e
1 /*
2 * DPMI 0.9 emulation
4 * Copyright 1995 Alexandre Julliard
5 */
7 #include <unistd.h>
8 #include <string.h>
9 #include "windows.h"
10 #include "heap.h"
11 #include "global.h"
12 #include "ldt.h"
13 #include "module.h"
14 #include "miscemu.h"
15 #include "drive.h"
16 #include "msdos.h"
17 #include "task.h"
18 #include "dosexe.h"
19 #include "toolhelp.h"
20 #include "debug.h"
21 #include "selectors.h"
22 #include "thread.h"
23 #include "process.h"
24 #include "stackframe.h"
25 #include "callback.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 */
34 typedef struct
36 DWORD edi;
37 DWORD esi;
38 DWORD ebp;
39 DWORD reserved;
40 DWORD ebx;
41 DWORD edx;
42 DWORD ecx;
43 DWORD eax;
44 WORD fl;
45 WORD es;
46 WORD ds;
47 WORD fs;
48 WORD gs;
49 WORD ip;
50 WORD cs;
51 WORD sp;
52 WORD ss;
53 } REALMODECALL;
57 typedef struct tagRMCB {
58 DWORD address;
59 struct tagRMCB *next;
61 } RMCB;
63 static RMCB *FirstRMCB = NULL;
65 /**********************************************************************
66 * DPMI_xalloc
67 * special virtualalloc, allocates lineary monoton growing memory.
68 * (the usual VirtualAlloc does not satisfy that restriction)
70 static LPVOID
71 DPMI_xalloc(int len) {
72 LPVOID ret;
73 LPVOID oldlastv = lastvalloced;
75 if (lastvalloced) {
76 int xflag = 0;
77 ret = NULL;
78 while (!ret) {
79 ret=VirtualAlloc(lastvalloced,len,MEM_COMMIT|MEM_RESERVE,PAGE_EXECUTE_READWRITE);
80 if (!ret)
81 lastvalloced+=0x10000;
82 /* we failed to allocate one in the first round.
83 * try non-linear
85 if (!xflag && (lastvalloced<oldlastv)) { /* wrapped */
86 FIXME(int31,"failed to allocate lineary growing memory (%d bytes), using non-linear growing...\n",len);
87 xflag++;
89 /* if we even fail to allocate something in the next
90 * round, return NULL
92 if ((xflag==1) && (lastvalloced >= oldlastv))
93 xflag++;
94 if ((xflag==2) && (lastvalloced < oldlastv)) {
95 FIXME(int31,"failed to allocate any memory of %d bytes!\n",len);
96 return NULL;
99 } else
100 ret=VirtualAlloc(NULL,len,MEM_COMMIT|MEM_RESERVE,PAGE_EXECUTE_READWRITE);
101 lastvalloced = (LPVOID)(((DWORD)ret+len+0xffff)&~0xffff);
102 return ret;
105 static void
106 DPMI_xfree(LPVOID ptr) {
107 VirtualFree(ptr,0,MEM_RELEASE);
110 /* FIXME: perhaps we could grow this mapped area... */
111 static LPVOID
112 DPMI_xrealloc(LPVOID ptr,int newsize) {
113 MEMORY_BASIC_INFORMATION mbi;
114 LPVOID newptr;
116 newptr = DPMI_xalloc(newsize);
117 if (ptr) {
118 if (!VirtualQuery(ptr,&mbi,sizeof(mbi))) {
119 FIXME(int31,"realloc of DPMI_xallocd region %p?\n",ptr);
120 return NULL;
122 if (mbi.State == MEM_FREE) {
123 FIXME(int31,"realloc of DPMI_xallocd region %p?\n",ptr);
124 return NULL;
126 /* We do not shrink allocated memory. most reallocs
127 * only do grows anyway
129 if (newsize<=mbi.RegionSize)
130 return ptr;
131 memcpy(newptr,ptr,mbi.RegionSize);
132 DPMI_xfree(ptr);
134 return newptr;
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 /**********************************************************************
184 * INT_DoRealModeInt
186 static void INT_DoRealModeInt( CONTEXT *context )
188 CONTEXT realmode_ctx;
189 REALMODECALL *call = (REALMODECALL *)PTR_SEG_OFF_TO_LIN( ES_reg(context),
190 DI_reg(context) );
191 INT_GetRealModeContext( call, &realmode_ctx );
193 RESET_CFLAG(context);
194 if (INT_RealModeInterrupt( BL_reg(context), &realmode_ctx ))
195 SET_CFLAG(context);
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) );
211 CONTEXT context16;
212 THDB *thdb = THREAD_Current();
213 WORD argsize, sel;
214 LPVOID addr;
215 SEGPTR seg_addr;
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 */
225 SET_CFLAG(context);
226 return;
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);
245 UnMapLS(seg_addr);
246 INT_SetRealModeContext(p, &context16);
250 void WINAPI RMCallbackProc( FARPROC16 pmProc, REALMODECALL *rmc )
252 CONTEXT ctx;
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) );
262 UINT16 uParagraph;
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) );
269 if (NewRMCB)
271 LPVOID RMCBmem = DOSMEM_GetBlock(0, 20, &uParagraph);
272 LPBYTE p = RMCBmem;
274 *p++ = 0x68; /* pushl */
275 *(FARPROC16 *)p =
276 PTR_SEG_OFF_TO_LIN(ES_reg(context), SI_reg(context)); /* pmode proc to call */
277 p+=4;
278 *p++ = 0x68; /* pushl */
279 *(LPVOID *)p =
280 PTR_SEG_OFF_TO_LIN(ES_reg(context), DI_reg(context));
281 p+=4;
282 *p++ = 0x9a; /* lcall */
283 *(FARPROC16 *)p = (FARPROC16)RMCallbackProc; /* FIXME ? */
284 p+=4;
285 GET_CS(*(WORD *)p);
286 p+=2;
287 *p++=0xc3; /* retf */
288 NewRMCB->address = MAKELONG(0, uParagraph);
289 NewRMCB->next = FirstRMCB;
290 FirstRMCB = NewRMCB;
291 CX_reg(context) = uParagraph;
292 DX_reg(context) = 0;
294 else
296 AX_reg(context) = 0x8015; /* callback unavailable */
297 SET_CFLAG(context);
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))))
312 PrevRMCB = CurrRMCB;
313 CurrRMCB = CurrRMCB->next;
315 if (CurrRMCB)
317 if (PrevRMCB)
318 PrevRMCB->next = CurrRMCB->next;
319 else
320 FirstRMCB = CurrRMCB->next;
321 DOSMEM_FreeBlock(0, DOSMEM_MapRealToLinear(CurrRMCB->address));
322 HeapFree(GetProcessHeap(), 0, CurrRMCB);
324 else
326 AX_reg(context) = 0x8024; /* invalid callback address */
327 SET_CFLAG(context);
331 #ifdef MZ_SUPPORTED
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;
338 CONTEXT pm_ctx;
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 );
348 pm_ctx = *context;
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;
355 FS_reg(&pm_ctx) = 0;
356 GS_reg(&pm_ctx) = 0;
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));
368 #endif
370 /**********************************************************************
371 * INT_Int31Handler
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)
387 DWORD dw;
388 BYTE *ptr;
390 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
391 NE_MODULE *pModule = pTask ? NE_GetPtr( pTask->hModule ) : NULL;
393 GlobalUnlock16( GetCurrentTask() );
395 #ifdef MZ_SUPPORTED
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);
402 return;
403 } else
404 if (CS_reg(context)==pModule->lpDosTask->xms_seg) {
405 /* This is the XMS driver entry point */
406 XMS_Handler(context);
407 return;
410 #endif
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 */
421 SET_CFLAG(context);
423 TRACE(int31,"success, array starts at 0x%04x\n",AX_reg(context));
424 break;
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 */
431 SET_CFLAG(context);
433 else
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;
442 break;
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 */
459 default:
460 AX_reg(context) = DOSMEM_AllocSelector(BX_reg(context));
461 break;
463 if (entryPoint)
464 AX_reg(context) = LOWORD(NE_GetEntryPoint(
465 GetModuleHandle16( "KERNEL" ),
466 entryPoint ));
468 break;
470 case 0x0003: /* Get next selector increment */
471 TRACE(int31,"get selector increment (__AHINCR)\n");
472 AX_reg(context) = __AHINCR;
473 break;
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? */
478 break;
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? */
483 break;
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 */
490 SET_CFLAG(context);
492 else
494 #ifdef MZ_SUPPORTED
495 if (pModule && pModule->lpDosTask) {
496 DWORD base = (DWORD)DOSMEM_MemoryBase(pModule->self);
497 if ((dw >= base) && (dw < base + 0x110000)) dw -= base;
499 #endif
500 CX_reg(context) = HIWORD(WineToApp(dw));
501 DX_reg(context) = LOWORD(WineToApp(dw));
503 break;
505 case 0x0007: /* Set selector base address */
506 TRACE(int31, "set selector base address (0x%04x,0x%08lx)\n",
507 BX_reg(context),
508 AppToWine(MAKELONG(DX_reg(context),CX_reg(context))));
509 dw = AppToWine(MAKELONG(DX_reg(context), CX_reg(context)));
510 #ifdef MZ_SUPPORTED
511 /* well, what else could we possibly do? */
512 if (pModule && pModule->lpDosTask) {
513 if (dw < 0x110000) dw += (DWORD)DOSMEM_MemoryBase(pModule->self);
515 #endif
516 SetSelectorBase(BX_reg(context), dw);
517 break;
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) );
522 #ifdef MZ_SUPPORTED
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 */
527 SET_CFLAG(context);
528 break;
531 #endif
532 SetSelectorLimit( BX_reg(context), dw );
533 break;
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) );
538 break;
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 */
545 SET_CFLAG(context);
547 break;
549 case 0x000b: /* Get descriptor */
550 TRACE(int31,"get descriptor (0x%04x)\n",BX_reg(context));
552 ldt_entry entry;
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 );
560 break;
562 case 0x000c: /* Set descriptor */
563 TRACE(int31,"set descriptor (0x%04x)\n",BX_reg(context));
565 ldt_entry entry;
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 );
572 break;
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 */
577 SET_CFLAG(context);
578 break;
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);
582 if (dw) {
583 AX_reg(context) = HIWORD(dw);
584 DX_reg(context) = LOWORD(dw);
585 } else {
586 AX_reg(context) = 0x0008; /* insufficient memory */
587 BX_reg(context) = DOSMEM_Available(0)>>4;
588 SET_CFLAG(context);
590 break;
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));
594 if (!dw) {
595 AX_reg(context) = 0x0009; /* memory block address invalid */
596 SET_CFLAG(context);
598 break;
599 case 0x0200: /* get real mode interrupt vector */
600 FIXME(int31,"get realmode interupt vector(0x%02x) unimplemented.\n",
601 BL_reg(context));
602 SET_CFLAG(context);
603 break;
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));
606 SET_CFLAG(context);
607 break;
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);
613 break;
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),
620 DX_reg(context) ));
621 break;
623 case 0x0300: /* Simulate real mode interrupt */
624 INT_DoRealModeInt( context );
625 break;
627 case 0x0301: /* Call real mode procedure with far return */
628 CallRMProcFar( context );
629 break;
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 );
636 SET_CFLAG(context);
638 break;
640 case 0x0303: /* Allocate Real Mode Callback Address */
641 AllocRMCB( context );
642 break;
644 case 0x0304: /* Free Real Mode Callback Address */
645 FreeRMCB( context );
646 break;
648 case 0x0400: /* Get DPMI version */
649 TRACE(int31,"get DPMI version\n");
651 SYSTEM_INFO si;
653 GetSystemInfo(&si);
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*/
658 break;
660 case 0x0500: /* Get free memory information */
661 TRACE(int31,"get free memory information\n");
663 MEMMANINFO mmi;
665 mmi.dwSize = sizeof(mmi);
666 MemManInfo(&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
669 * the dwSize entry.
671 memcpy(ptr,((char*)&mmi)+4,sizeof(mmi)-4);
672 break;
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 */
679 SET_CFLAG(context);
680 } else {
681 BX_reg(context) = SI_reg(context) = HIWORD(WineToApp(ptr));
682 CX_reg(context) = DI_reg(context) = LOWORD(WineToApp(ptr));
684 break;
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),
690 SI_reg(context))) );
691 break;
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 */
702 SET_CFLAG(context);
703 } else {
704 BX_reg(context) = SI_reg(context) = HIWORD(WineToApp(ptr));
705 CX_reg(context) = DI_reg(context) = LOWORD(WineToApp(ptr));
707 break;
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");
731 BX_reg(context) = 0;
732 CX_reg(context) = VIRTUAL_GetPageSize();
733 break;
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;
748 SET_CFLAG(context);
750 else
752 BX_reg(context) = HIWORD(WineToApp(ptr));
753 CX_reg(context) = LOWORD(WineToApp(ptr));
754 RESET_CFLAG(context);
756 break;
758 default:
759 INT_BARF( context, 0x31 );
760 AX_reg(context) = 0x8001; /* unsupported function */
761 SET_CFLAG(context);
762 break;
765 #undef AppToWine
766 #undef WineToApp