1998-10-11 12:16:56 +00:00
|
|
|
/*
|
|
|
|
* XMS v2+ emulation
|
|
|
|
*
|
2008-10-18 17:21:31 +00:00
|
|
|
* Copyright 1998 Ove Kåven
|
1998-10-11 12:16:56 +00:00
|
|
|
*
|
2002-03-09 23:29:33 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 12:49:52 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-03-09 23:29:33 +00:00
|
|
|
*
|
|
|
|
* Note: This XMS emulation is hooked through the DPMI interrupt.
|
1998-10-11 12:16:56 +00:00
|
|
|
*/
|
|
|
|
|
2002-08-17 00:43:16 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
2003-09-05 23:08:26 +00:00
|
|
|
#include <stdarg.h>
|
1998-10-11 12:16:56 +00:00
|
|
|
#include <string.h>
|
2003-09-05 23:08:26 +00:00
|
|
|
#include "windef.h"
|
1999-02-24 13:05:13 +00:00
|
|
|
#include "winbase.h"
|
2000-09-26 22:20:14 +00:00
|
|
|
#include "wine/winbase16.h"
|
2003-11-15 00:13:20 +00:00
|
|
|
#include "dosexe.h"
|
2002-03-09 23:29:33 +00:00
|
|
|
#include "wine/debug.h"
|
1998-10-11 12:16:56 +00:00
|
|
|
|
2002-03-09 23:29:33 +00:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(int31);
|
1999-04-19 14:56:29 +00:00
|
|
|
|
2004-01-09 22:18:49 +00:00
|
|
|
#include "pshpack1.h"
|
|
|
|
|
1998-10-11 12:16:56 +00:00
|
|
|
typedef struct {
|
|
|
|
WORD Handle;
|
|
|
|
DWORD Offset;
|
2004-01-09 22:18:49 +00:00
|
|
|
} MOVEOFS;
|
1998-10-11 12:16:56 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
DWORD Length;
|
|
|
|
MOVEOFS Source;
|
|
|
|
MOVEOFS Dest;
|
2004-01-09 22:18:49 +00:00
|
|
|
} MOVESTRUCT;
|
|
|
|
|
|
|
|
#include "poppack.h"
|
1998-10-11 12:16:56 +00:00
|
|
|
|
|
|
|
static BYTE * XMS_Offset( MOVEOFS *ofs )
|
|
|
|
{
|
|
|
|
if (ofs->Handle) return (BYTE*)GlobalLock16(ofs->Handle)+ofs->Offset;
|
2009-03-04 09:41:06 +00:00
|
|
|
else return PTR_REAL_TO_LIN(SELECTOROF(ofs->Offset),OFFSETOF(ofs->Offset));
|
1998-10-11 12:16:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* XMS_Handler
|
|
|
|
*/
|
|
|
|
|
1999-06-26 18:40:24 +00:00
|
|
|
void WINAPI XMS_Handler( CONTEXT86 *context )
|
1998-10-11 12:16:56 +00:00
|
|
|
{
|
|
|
|
switch(AH_reg(context))
|
|
|
|
{
|
|
|
|
case 0x00: /* Get XMS version number */
|
1999-06-26 19:09:08 +00:00
|
|
|
TRACE("get XMS version number\n");
|
2002-08-31 18:47:00 +00:00
|
|
|
SET_AX( context, 0x0200 ); /* 2.0 */
|
|
|
|
SET_BX( context, 0x0000 ); /* internal revision */
|
|
|
|
SET_DX( context, 0x0001 ); /* HMA exists */
|
1998-10-11 12:16:56 +00:00
|
|
|
break;
|
|
|
|
case 0x08: /* Query Free Extended Memory */
|
|
|
|
{
|
2002-08-30 00:03:25 +00:00
|
|
|
MEMORYSTATUS status;
|
1998-10-11 12:16:56 +00:00
|
|
|
|
1999-06-26 19:09:08 +00:00
|
|
|
TRACE("query free extended memory\n");
|
2002-08-30 00:03:25 +00:00
|
|
|
GlobalMemoryStatus( &status );
|
2002-08-31 18:47:00 +00:00
|
|
|
SET_DX( context, status.dwAvailVirtual >> 10 );
|
|
|
|
SET_AX( context, status.dwAvailVirtual >> 10 );
|
1999-06-26 19:09:08 +00:00
|
|
|
TRACE("returning largest %dK, total %dK\n", AX_reg(context), DX_reg(context));
|
1998-10-11 12:16:56 +00:00
|
|
|
}
|
1999-01-30 13:41:57 +00:00
|
|
|
break;
|
1998-10-11 12:16:56 +00:00
|
|
|
case 0x09: /* Allocate Extended Memory Block */
|
1999-06-26 19:09:08 +00:00
|
|
|
TRACE("allocate extended memory block (%dK)\n",
|
1998-10-11 12:16:56 +00:00
|
|
|
DX_reg(context));
|
2002-08-31 18:47:00 +00:00
|
|
|
SET_DX( context, GlobalAlloc16(GMEM_MOVEABLE, (DWORD)DX_reg(context)<<10) );
|
|
|
|
SET_AX( context, DX_reg(context) ? 1 : 0 );
|
|
|
|
if (!DX_reg(context)) SET_BL( context, 0xA0 ); /* out of memory */
|
1998-10-11 12:16:56 +00:00
|
|
|
break;
|
|
|
|
case 0x0a: /* Free Extended Memory Block */
|
1999-06-26 19:09:08 +00:00
|
|
|
TRACE("free extended memory block %04x\n",DX_reg(context));
|
2002-04-29 17:12:29 +00:00
|
|
|
if(!DX_reg(context) || GlobalFree16(DX_reg(context))) {
|
2002-08-31 18:47:00 +00:00
|
|
|
SET_AX( context, 0 ); /* failure */
|
|
|
|
SET_BL( context, 0xa2 ); /* invalid handle */
|
2002-04-29 17:12:29 +00:00
|
|
|
} else
|
2002-08-31 18:47:00 +00:00
|
|
|
SET_AX( context, 1 ); /* success */
|
1998-10-11 12:16:56 +00:00
|
|
|
break;
|
|
|
|
case 0x0b: /* Move Extended Memory Block */
|
|
|
|
{
|
|
|
|
MOVESTRUCT*move=CTX_SEG_OFF_TO_LIN(context,
|
2000-09-25 23:53:07 +00:00
|
|
|
context->SegDs,context->Esi);
|
1998-10-11 12:16:56 +00:00
|
|
|
BYTE*src,*dst;
|
1999-06-26 19:09:08 +00:00
|
|
|
TRACE("move extended memory block\n");
|
1998-10-11 12:16:56 +00:00
|
|
|
src=XMS_Offset(&move->Source);
|
|
|
|
dst=XMS_Offset(&move->Dest);
|
|
|
|
memcpy(dst,src,move->Length);
|
|
|
|
if (move->Source.Handle) GlobalUnlock16(move->Source.Handle);
|
|
|
|
if (move->Dest.Handle) GlobalUnlock16(move->Dest.Handle);
|
|
|
|
break;
|
|
|
|
}
|
2002-11-04 22:35:36 +00:00
|
|
|
case 0x88: /* Query Any Free Extended Memory */
|
|
|
|
{
|
|
|
|
MEMORYSTATUS status;
|
|
|
|
SYSTEM_INFO info;
|
|
|
|
|
|
|
|
TRACE("query any free extended memory\n");
|
|
|
|
|
|
|
|
GlobalMemoryStatus( &status );
|
|
|
|
GetSystemInfo( &info );
|
|
|
|
context->Eax = status.dwAvailVirtual >> 10;
|
|
|
|
context->Edx = status.dwAvailVirtual >> 10;
|
|
|
|
context->Ecx = (DWORD)info.lpMaximumApplicationAddress;
|
|
|
|
SET_BL( context, 0 ); /* No errors. */
|
|
|
|
|
2006-10-03 12:04:49 +00:00
|
|
|
TRACE("returning largest %dK, total %dK, highest 0x%x\n",
|
2002-11-04 22:35:36 +00:00
|
|
|
context->Eax, context->Edx, context->Ecx);
|
|
|
|
}
|
|
|
|
break;
|
1998-10-11 12:16:56 +00:00
|
|
|
default:
|
|
|
|
INT_BARF( context, 0x31 );
|
2002-08-31 18:47:00 +00:00
|
|
|
SET_AX( context, 0x0000 ); /* failure */
|
|
|
|
SET_BL( context, 0x80 ); /* function not implemented */
|
1998-10-11 12:16:56 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|