4 * Copyright 1998 Ove Kåven
6 * This XMS emulation is hooked through the DPMI interrupt.
17 #include "selectors.h"
19 DEFAULT_DEBUG_CHANNEL(int31
)
24 } WINE_PACKED MOVEOFS
;
30 } WINE_PACKED MOVESTRUCT
;
32 static BYTE
* XMS_Offset( MOVEOFS
*ofs
)
34 if (ofs
->Handle
) return (BYTE
*)GlobalLock16(ofs
->Handle
)+ofs
->Offset
;
35 else return (BYTE
*)DOSMEM_MapRealToLinear(ofs
->Offset
);
38 /**********************************************************************
42 void WINAPI
XMS_Handler( CONTEXT
*context
)
44 switch(AH_reg(context
))
46 case 0x00: /* Get XMS version number */
47 TRACE(int31
, "get XMS version number\n");
48 AX_reg(context
) = 0x0200; /* 2.0 */
49 BX_reg(context
) = 0x0000; /* internal revision */
50 DX_reg(context
) = 0x0001; /* HMA exists */
52 case 0x08: /* Query Free Extended Memory */
56 TRACE(int31
, "query free extended memory\n");
57 mmi
.dwSize
= sizeof(mmi
);
59 AX_reg(context
) = mmi
.dwLargestFreeBlock
>> 10;
60 DX_reg(context
) = (mmi
.dwFreePages
* VIRTUAL_GetPageSize()) >> 10;
61 TRACE(int31
, "returning largest %dK, total %dK\n", AX_reg(context
), DX_reg(context
));
64 case 0x09: /* Allocate Extended Memory Block */
65 TRACE(int31
, "allocate extended memory block (%dK)\n",
67 DX_reg(context
) = GlobalAlloc16(GMEM_MOVEABLE
,
68 (DWORD
)DX_reg(context
)<<10);
69 AX_reg(context
) = DX_reg(context
) ? 1 : 0;
70 if (!DX_reg(context
)) BL_reg(context
) = 0xA0; /* out of memory */
72 case 0x0a: /* Free Extended Memory Block */
73 TRACE(int31
, "free extended memory block %04x\n",DX_reg(context
));
74 GlobalFree16(DX_reg(context
));
76 case 0x0b: /* Move Extended Memory Block */
78 MOVESTRUCT
*move
=CTX_SEG_OFF_TO_LIN(context
,
79 DS_reg(context
),ESI_reg(context
));
81 TRACE(int31
, "move extended memory block\n");
82 src
=XMS_Offset(&move
->Source
);
83 dst
=XMS_Offset(&move
->Dest
);
84 memcpy(dst
,src
,move
->Length
);
85 if (move
->Source
.Handle
) GlobalUnlock16(move
->Source
.Handle
);
86 if (move
->Dest
.Handle
) GlobalUnlock16(move
->Dest
.Handle
);
90 INT_BARF( context
, 0x31 );
91 AX_reg(context
) = 0x0000; /* failure */
92 BL_reg(context
) = 0x80; /* function not implemented */