krnl386: Remove support for running DOS executables.
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
a87b55d92e
commit
5e0fd3403e
|
@ -9,7 +9,6 @@ C_SRCS = \
|
||||||
dma.c \
|
dma.c \
|
||||||
dosaspi.c \
|
dosaspi.c \
|
||||||
dosdev.c \
|
dosdev.c \
|
||||||
dosexe.c \
|
|
||||||
dosmem.c \
|
dosmem.c \
|
||||||
dosvm.c \
|
dosvm.c \
|
||||||
error.c \
|
error.c \
|
||||||
|
|
|
@ -1,796 +0,0 @@
|
||||||
/*
|
|
||||||
* DOS (MZ) loader
|
|
||||||
*
|
|
||||||
* Copyright 1998 Ove Kåven
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
||||||
*
|
|
||||||
* Note: This code hasn't been completely cleaned up yet.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
#include "wine/port.h"
|
|
||||||
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <signal.h>
|
|
||||||
#ifdef HAVE_UNISTD_H
|
|
||||||
# include <unistd.h>
|
|
||||||
#endif
|
|
||||||
#include <sys/types.h>
|
|
||||||
#ifdef HAVE_SYS_STAT_H
|
|
||||||
# include <sys/stat.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_SYS_TIME_H
|
|
||||||
# include <sys/time.h>
|
|
||||||
#endif
|
|
||||||
#include "windef.h"
|
|
||||||
#include "winbase.h"
|
|
||||||
#include "wine/winbase16.h"
|
|
||||||
#include "wingdi.h"
|
|
||||||
#include "winuser.h"
|
|
||||||
#include "winerror.h"
|
|
||||||
#include "wine/debug.h"
|
|
||||||
#include "kernel16_private.h"
|
|
||||||
#include "dosexe.h"
|
|
||||||
#include "vga.h"
|
|
||||||
|
|
||||||
WINE_DEFAULT_DEBUG_CHANNEL(module);
|
|
||||||
|
|
||||||
static BOOL DOSVM_isdosexe;
|
|
||||||
|
|
||||||
/**********************************************************************
|
|
||||||
* DOSVM_IsWin16
|
|
||||||
*
|
|
||||||
* Return TRUE if we are in Windows process.
|
|
||||||
*/
|
|
||||||
BOOL DOSVM_IsWin16(void)
|
|
||||||
{
|
|
||||||
return !DOSVM_isdosexe;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**********************************************************************
|
|
||||||
* DOSVM_Exit
|
|
||||||
*/
|
|
||||||
void DOSVM_Exit( WORD retval )
|
|
||||||
{
|
|
||||||
DWORD count;
|
|
||||||
|
|
||||||
ReleaseThunkLock( &count );
|
|
||||||
ExitThread( retval );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef MZ_SUPPORTED
|
|
||||||
|
|
||||||
#define BIOS_DATA_SEGMENT 0x40
|
|
||||||
#define PSP_SIZE 0x10
|
|
||||||
|
|
||||||
#define SEG16(ptr,seg) ((LPVOID)((BYTE*)ptr+((DWORD)(seg)<<4)))
|
|
||||||
#define SEGPTR16(ptr,segptr) ((LPVOID)((BYTE*)ptr+((DWORD)SELECTOROF(segptr)<<4)+OFFSETOF(segptr)))
|
|
||||||
|
|
||||||
/* structures for EXEC */
|
|
||||||
|
|
||||||
#include "pshpack1.h"
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
WORD env_seg;
|
|
||||||
DWORD cmdline;
|
|
||||||
DWORD fcb1;
|
|
||||||
DWORD fcb2;
|
|
||||||
WORD init_sp;
|
|
||||||
WORD init_ss;
|
|
||||||
WORD init_ip;
|
|
||||||
WORD init_cs;
|
|
||||||
} ExecBlock;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
WORD load_seg;
|
|
||||||
WORD rel_seg;
|
|
||||||
} OverlayBlock;
|
|
||||||
|
|
||||||
#include "poppack.h"
|
|
||||||
|
|
||||||
/* global variables */
|
|
||||||
|
|
||||||
pid_t dosvm_pid;
|
|
||||||
|
|
||||||
static WORD init_cs,init_ip,init_ss,init_sp;
|
|
||||||
static HANDLE dosvm_thread, loop_thread;
|
|
||||||
static DWORD dosvm_tid, loop_tid;
|
|
||||||
|
|
||||||
static DWORD MZ_Launch( LPCSTR cmdtail, int length );
|
|
||||||
static BOOL MZ_InitTask(void);
|
|
||||||
|
|
||||||
static void MZ_CreatePSP( LPVOID lpPSP, WORD env, WORD par )
|
|
||||||
{
|
|
||||||
PDB16*psp=lpPSP;
|
|
||||||
|
|
||||||
psp->int20=0x20CD; /* int 20 */
|
|
||||||
/* some programs use this to calculate how much memory they need */
|
|
||||||
psp->nextParagraph=0x9FFF; /* FIXME: use a real value */
|
|
||||||
/* FIXME: dispatcher */
|
|
||||||
psp->savedint22 = DOSVM_GetRMHandler(0x22);
|
|
||||||
psp->savedint23 = DOSVM_GetRMHandler(0x23);
|
|
||||||
psp->savedint24 = DOSVM_GetRMHandler(0x24);
|
|
||||||
psp->parentPSP=par;
|
|
||||||
psp->environment=env;
|
|
||||||
/* FIXME: more PSP stuff */
|
|
||||||
}
|
|
||||||
|
|
||||||
static void MZ_FillPSP( LPVOID lpPSP, LPCSTR cmdtail, int length )
|
|
||||||
{
|
|
||||||
PDB16 *psp = lpPSP;
|
|
||||||
|
|
||||||
if(length > 127)
|
|
||||||
{
|
|
||||||
WARN( "Command tail truncated! (length %d)\n", length );
|
|
||||||
length = 126;
|
|
||||||
}
|
|
||||||
|
|
||||||
psp->cmdLine[0] = length;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Length of exactly 127 bytes means that full command line is
|
|
||||||
* stored in environment variable CMDLINE and PSP contains
|
|
||||||
* command tail truncated to 126 bytes.
|
|
||||||
*/
|
|
||||||
if(length == 127)
|
|
||||||
length = 126;
|
|
||||||
|
|
||||||
if(length > 0)
|
|
||||||
memmove(psp->cmdLine+1, cmdtail, length);
|
|
||||||
|
|
||||||
psp->cmdLine[length+1] = '\r';
|
|
||||||
|
|
||||||
/* FIXME: more PSP stuff */
|
|
||||||
}
|
|
||||||
|
|
||||||
static WORD MZ_InitEnvironment( LPCSTR env, LPCSTR name )
|
|
||||||
{
|
|
||||||
unsigned sz=0;
|
|
||||||
unsigned i=0;
|
|
||||||
WORD seg;
|
|
||||||
LPSTR envblk;
|
|
||||||
|
|
||||||
if (env) {
|
|
||||||
/* get size of environment block */
|
|
||||||
while (env[sz++]) sz+=strlen(env+sz)+1;
|
|
||||||
} else sz++;
|
|
||||||
/* allocate it */
|
|
||||||
envblk=DOSMEM_AllocBlock(sz+sizeof(WORD)+strlen(name)+1,&seg);
|
|
||||||
/* fill it */
|
|
||||||
if (env) {
|
|
||||||
memcpy(envblk,env,sz);
|
|
||||||
} else envblk[0]=0;
|
|
||||||
/* DOS environment variables are uppercase */
|
|
||||||
while (envblk[i]){
|
|
||||||
while (envblk[i] != '='){
|
|
||||||
if (envblk[i]>='a' && envblk[i] <= 'z'){
|
|
||||||
envblk[i] -= 32;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
i += strlen(envblk+i) + 1;
|
|
||||||
}
|
|
||||||
/* DOS 3.x: the block contains 1 additional string */
|
|
||||||
*(WORD*)(envblk+sz)=1;
|
|
||||||
/* being the program name itself */
|
|
||||||
strcpy(envblk+sz+sizeof(WORD),name);
|
|
||||||
return seg;
|
|
||||||
}
|
|
||||||
|
|
||||||
static BOOL MZ_InitMemory(void)
|
|
||||||
{
|
|
||||||
/* initialize the memory */
|
|
||||||
TRACE("Initializing DOS memory structures\n");
|
|
||||||
DOSMEM_MapDosLayout();
|
|
||||||
DOSDEV_InstallDOSDevices();
|
|
||||||
MSCDEX_InstallCDROM();
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static BOOL MZ_DoLoadImage( HANDLE hFile, LPCSTR filename, OverlayBlock *oblk, WORD par_env_seg )
|
|
||||||
{
|
|
||||||
IMAGE_DOS_HEADER mz_header;
|
|
||||||
DWORD image_start,image_size,min_size,max_size,avail;
|
|
||||||
BYTE*psp_start,*load_start;
|
|
||||||
LPSTR oldenv = 0;
|
|
||||||
int x, old_com=0, alloc;
|
|
||||||
SEGPTR reloc;
|
|
||||||
WORD env_seg, load_seg, rel_seg, oldpsp_seg;
|
|
||||||
DWORD len;
|
|
||||||
|
|
||||||
if (DOSVM_psp) {
|
|
||||||
/* DOS process already running, inherit from it */
|
|
||||||
PDB16* par_psp;
|
|
||||||
alloc=0;
|
|
||||||
oldpsp_seg = DOSVM_psp;
|
|
||||||
if( !par_env_seg) {
|
|
||||||
par_psp = (PDB16*)((DWORD)DOSVM_psp << 4);
|
|
||||||
oldenv = (LPSTR)((DWORD)par_psp->environment << 4);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
/* allocate new DOS process, inheriting from Wine environment */
|
|
||||||
alloc=1;
|
|
||||||
oldpsp_seg = 0;
|
|
||||||
if( !par_env_seg)
|
|
||||||
oldenv = GetEnvironmentStringsA();
|
|
||||||
}
|
|
||||||
|
|
||||||
SetFilePointer(hFile,0,NULL,FILE_BEGIN);
|
|
||||||
if ( !ReadFile(hFile,&mz_header,sizeof(mz_header),&len,NULL)
|
|
||||||
|| len != sizeof(mz_header)
|
|
||||||
|| mz_header.e_magic != IMAGE_DOS_SIGNATURE) {
|
|
||||||
const char *p = strrchr( filename, '.' );
|
|
||||||
if (!p || strcasecmp( p, ".com" )) /* check for .COM extension */
|
|
||||||
{
|
|
||||||
SetLastError(ERROR_BAD_FORMAT);
|
|
||||||
goto load_error;
|
|
||||||
}
|
|
||||||
old_com=1; /* assume .COM file */
|
|
||||||
image_start=0;
|
|
||||||
image_size=GetFileSize(hFile,NULL);
|
|
||||||
min_size=0x10000; max_size=0x100000;
|
|
||||||
mz_header.e_crlc=0;
|
|
||||||
mz_header.e_ss=0; mz_header.e_sp=0xFFFE;
|
|
||||||
mz_header.e_cs=0; mz_header.e_ip=0x100;
|
|
||||||
} else {
|
|
||||||
/* calculate load size */
|
|
||||||
image_start=mz_header.e_cparhdr<<4;
|
|
||||||
image_size=mz_header.e_cp<<9; /* pages are 512 bytes */
|
|
||||||
/* From Ralf Brown Interrupt List: If the word at offset 02h is 4, it should
|
|
||||||
* be treated as 00h, since pre-1.10 versions of the MS linker set it that
|
|
||||||
* way. */
|
|
||||||
if ((mz_header.e_cblp!=0)&&(mz_header.e_cblp!=4)) image_size-=512-mz_header.e_cblp;
|
|
||||||
image_size-=image_start;
|
|
||||||
min_size=image_size+((DWORD)mz_header.e_minalloc<<4)+(PSP_SIZE<<4);
|
|
||||||
max_size=image_size+((DWORD)mz_header.e_maxalloc<<4)+(PSP_SIZE<<4);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (alloc) MZ_InitMemory();
|
|
||||||
|
|
||||||
if (oblk) {
|
|
||||||
/* load overlay into preallocated memory */
|
|
||||||
load_seg=oblk->load_seg;
|
|
||||||
rel_seg=oblk->rel_seg;
|
|
||||||
load_start=(LPBYTE)((DWORD)load_seg<<4);
|
|
||||||
} else {
|
|
||||||
/* allocate environment block */
|
|
||||||
if( par_env_seg)
|
|
||||||
env_seg = par_env_seg;
|
|
||||||
else
|
|
||||||
env_seg=MZ_InitEnvironment(oldenv, filename);
|
|
||||||
if (alloc)
|
|
||||||
FreeEnvironmentStringsA( oldenv);
|
|
||||||
|
|
||||||
/* allocate memory for the executable */
|
|
||||||
TRACE("Allocating DOS memory (min=%d, max=%d)\n",min_size,max_size);
|
|
||||||
avail=DOSMEM_Available();
|
|
||||||
if (avail<min_size) {
|
|
||||||
ERR("insufficient DOS memory\n");
|
|
||||||
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
||||||
goto load_error;
|
|
||||||
}
|
|
||||||
if (avail>max_size) avail=max_size;
|
|
||||||
psp_start=DOSMEM_AllocBlock(avail,&DOSVM_psp);
|
|
||||||
if (!psp_start) {
|
|
||||||
ERR("error allocating DOS memory\n");
|
|
||||||
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
||||||
goto load_error;
|
|
||||||
}
|
|
||||||
load_seg=DOSVM_psp+(old_com?0:PSP_SIZE);
|
|
||||||
rel_seg=load_seg;
|
|
||||||
load_start=psp_start+(PSP_SIZE<<4);
|
|
||||||
MZ_CreatePSP(psp_start, env_seg, oldpsp_seg);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* load executable image */
|
|
||||||
TRACE("loading DOS %s image, %08x bytes\n",old_com?"COM":"EXE",image_size);
|
|
||||||
SetFilePointer(hFile,image_start,NULL,FILE_BEGIN);
|
|
||||||
if (!ReadFile(hFile,load_start,image_size,&len,NULL) || len != image_size) {
|
|
||||||
/* check if this is due to the workaround for the pre-1.10 MS linker and we
|
|
||||||
really had only 4 bytes on the last page */
|
|
||||||
if (mz_header.e_cblp != 4 || image_size - len != 512 - 4) {
|
|
||||||
SetLastError(ERROR_BAD_FORMAT);
|
|
||||||
goto load_error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mz_header.e_crlc) {
|
|
||||||
/* load relocation table */
|
|
||||||
TRACE("loading DOS EXE relocation table, %d entries\n",mz_header.e_crlc);
|
|
||||||
/* FIXME: is this too slow without read buffering? */
|
|
||||||
SetFilePointer(hFile,mz_header.e_lfarlc,NULL,FILE_BEGIN);
|
|
||||||
for (x=0; x<mz_header.e_crlc; x++) {
|
|
||||||
if (!ReadFile(hFile,&reloc,sizeof(reloc),&len,NULL) || len != sizeof(reloc)) {
|
|
||||||
SetLastError(ERROR_BAD_FORMAT);
|
|
||||||
goto load_error;
|
|
||||||
}
|
|
||||||
*(WORD*)SEGPTR16(load_start,reloc)+=rel_seg;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!oblk) {
|
|
||||||
init_cs = load_seg+mz_header.e_cs;
|
|
||||||
init_ip = mz_header.e_ip;
|
|
||||||
init_ss = load_seg+mz_header.e_ss;
|
|
||||||
init_sp = mz_header.e_sp;
|
|
||||||
if (old_com){
|
|
||||||
/* .COM files exit with ret. Make sure they jump to psp start (=int 20) */
|
|
||||||
WORD* stack = PTR_REAL_TO_LIN(init_ss, init_sp);
|
|
||||||
*stack = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
TRACE("entry point: %04x:%04x\n",init_cs,init_ip);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (alloc && !MZ_InitTask()) {
|
|
||||||
SetLastError(ERROR_GEN_FAILURE);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
load_error:
|
|
||||||
DOSVM_psp = oldpsp_seg;
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/***********************************************************************
|
|
||||||
* __wine_load_dos_exe (KERNEL.@)
|
|
||||||
*
|
|
||||||
* Called from WineVDM when a new real-mode DOS process is started.
|
|
||||||
* Loads DOS program into memory and executes the program.
|
|
||||||
*/
|
|
||||||
void __wine_load_dos_exe( LPCSTR filename, LPCSTR cmdline )
|
|
||||||
{
|
|
||||||
char dos_cmdtail[126];
|
|
||||||
int dos_length = 0;
|
|
||||||
|
|
||||||
HANDLE hFile = CreateFileA( filename, GENERIC_READ, FILE_SHARE_READ,
|
|
||||||
NULL, OPEN_EXISTING, 0, 0 );
|
|
||||||
if (hFile == INVALID_HANDLE_VALUE) return;
|
|
||||||
DOSVM_isdosexe = TRUE;
|
|
||||||
DOSMEM_InitDosMemory();
|
|
||||||
|
|
||||||
if(cmdline && *cmdline)
|
|
||||||
{
|
|
||||||
dos_length = strlen(cmdline);
|
|
||||||
memmove( dos_cmdtail + 1, cmdline,
|
|
||||||
(dos_length < 125) ? dos_length : 125 );
|
|
||||||
|
|
||||||
/* Non-empty command tail always starts with at least one space. */
|
|
||||||
dos_cmdtail[0] = ' ';
|
|
||||||
dos_length++;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* If command tail is longer than 126 characters,
|
|
||||||
* set tail length to 127 and fill CMDLINE environment variable
|
|
||||||
* with full command line (this includes filename).
|
|
||||||
*/
|
|
||||||
if (dos_length > 126)
|
|
||||||
{
|
|
||||||
char *cmd = HeapAlloc( GetProcessHeap(), 0,
|
|
||||||
dos_length + strlen(filename) + 4 );
|
|
||||||
char *ptr = cmd;
|
|
||||||
|
|
||||||
if (!cmd)
|
|
||||||
return;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Append filename. If path includes spaces, quote the path.
|
|
||||||
*/
|
|
||||||
if (strchr(filename, ' '))
|
|
||||||
{
|
|
||||||
*ptr++ = '\"';
|
|
||||||
strcpy( ptr, filename );
|
|
||||||
ptr += strlen(filename);
|
|
||||||
*ptr++ = '\"';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
strcpy( ptr, filename );
|
|
||||||
ptr += strlen(filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Append command tail.
|
|
||||||
*/
|
|
||||||
if (cmdline[0] != ' ')
|
|
||||||
*ptr++ = ' ';
|
|
||||||
strcpy( ptr, cmdline );
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Set environment variable. This will be passed to
|
|
||||||
* new DOS process.
|
|
||||||
*/
|
|
||||||
if (!SetEnvironmentVariableA( "CMDLINE", cmd ))
|
|
||||||
{
|
|
||||||
HeapFree(GetProcessHeap(), 0, cmd );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
HeapFree(GetProcessHeap(), 0, cmd );
|
|
||||||
dos_length = 127;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
AllocConsole();
|
|
||||||
|
|
||||||
if (MZ_DoLoadImage( hFile, filename, NULL, 0 ))
|
|
||||||
{
|
|
||||||
DWORD err = MZ_Launch( dos_cmdtail, dos_length );
|
|
||||||
/* if we get back here it failed */
|
|
||||||
SetLastError( err );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/***********************************************************************
|
|
||||||
* MZ_Exec
|
|
||||||
*
|
|
||||||
* this may only be called from existing DOS processes
|
|
||||||
*/
|
|
||||||
BOOL MZ_Exec( CONTEXT *context, LPCSTR filename, BYTE func, LPVOID paramblk )
|
|
||||||
{
|
|
||||||
DWORD binType;
|
|
||||||
STARTUPINFOA st;
|
|
||||||
PROCESS_INFORMATION pe;
|
|
||||||
HANDLE hFile;
|
|
||||||
|
|
||||||
BOOL ret = FALSE;
|
|
||||||
|
|
||||||
if(!GetBinaryTypeA(filename, &binType)) /* determine what kind of binary this is */
|
|
||||||
{
|
|
||||||
return FALSE; /* binary is not an executable */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* handle non-dos executables */
|
|
||||||
if(binType != SCS_DOS_BINARY)
|
|
||||||
{
|
|
||||||
if(func == 0) /* load and execute */
|
|
||||||
{
|
|
||||||
LPSTR fullCmdLine;
|
|
||||||
WORD fullCmdLength;
|
|
||||||
LPBYTE psp_start = (LPBYTE)((DWORD)DOSVM_psp << 4);
|
|
||||||
PDB16 *psp = (PDB16 *)psp_start;
|
|
||||||
ExecBlock *blk = paramblk;
|
|
||||||
LPBYTE cmdline = PTR_REAL_TO_LIN(SELECTOROF(blk->cmdline),OFFSETOF(blk->cmdline));
|
|
||||||
LPBYTE envblock = PTR_REAL_TO_LIN(psp->environment, 0);
|
|
||||||
int cmdLength = cmdline[0];
|
|
||||||
|
|
||||||
/*
|
|
||||||
* If cmdLength is 127, command tail is truncated and environment
|
|
||||||
* variable CMDLINE should contain full command line
|
|
||||||
* (this includes filename).
|
|
||||||
*/
|
|
||||||
if (cmdLength == 127)
|
|
||||||
{
|
|
||||||
FIXME( "CMDLINE argument passing is unimplemented.\n" );
|
|
||||||
cmdLength = 126; /* FIXME */
|
|
||||||
}
|
|
||||||
|
|
||||||
fullCmdLength = (strlen(filename) + 1) + cmdLength + 1; /* filename + space + cmdline + terminating null character */
|
|
||||||
|
|
||||||
fullCmdLine = HeapAlloc(GetProcessHeap(), 0, fullCmdLength);
|
|
||||||
if(!fullCmdLine) return FALSE; /* return false on memory alloc failure */
|
|
||||||
|
|
||||||
/* build the full command line from the executable file and the command line being passed in */
|
|
||||||
snprintf(fullCmdLine, fullCmdLength, "%s ", filename); /* start off with the executable filename and a space */
|
|
||||||
memcpy(fullCmdLine + strlen(fullCmdLine), cmdline + 1, cmdLength); /* append cmdline onto the end */
|
|
||||||
fullCmdLine[fullCmdLength - 1] = 0; /* null terminate string */
|
|
||||||
|
|
||||||
ZeroMemory (&st, sizeof(STARTUPINFOA));
|
|
||||||
st.cb = sizeof(STARTUPINFOA);
|
|
||||||
ret = CreateProcessA (NULL, fullCmdLine, NULL, NULL, TRUE, 0, envblock, NULL, &st, &pe);
|
|
||||||
|
|
||||||
/* wait for the app to finish and clean up PROCESS_INFORMATION handles */
|
|
||||||
if(ret)
|
|
||||||
{
|
|
||||||
WaitForSingleObject(pe.hProcess, INFINITE); /* wait here until the child process is complete */
|
|
||||||
CloseHandle(pe.hProcess);
|
|
||||||
CloseHandle(pe.hThread);
|
|
||||||
}
|
|
||||||
|
|
||||||
HeapFree(GetProcessHeap(), 0, fullCmdLine); /* free the memory we allocated */
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
FIXME("EXEC type of %d not implemented for non-dos executables\n", func);
|
|
||||||
ret = FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
} /* if(binType != SCS_DOS_BINARY) */
|
|
||||||
|
|
||||||
|
|
||||||
/* handle dos executables */
|
|
||||||
|
|
||||||
hFile = CreateFileA( filename, GENERIC_READ, FILE_SHARE_READ,
|
|
||||||
NULL, OPEN_EXISTING, 0, 0);
|
|
||||||
if (hFile == INVALID_HANDLE_VALUE) return FALSE;
|
|
||||||
|
|
||||||
switch (func) {
|
|
||||||
case 0: /* load and execute */
|
|
||||||
case 1: /* load but don't execute */
|
|
||||||
{
|
|
||||||
/* save current process's return SS:SP now */
|
|
||||||
LPBYTE psp_start = (LPBYTE)((DWORD)DOSVM_psp << 4);
|
|
||||||
PDB16 *psp = (PDB16 *)psp_start;
|
|
||||||
psp->saveStack = (DWORD)MAKESEGPTR(context->SegSs, LOWORD(context->Esp));
|
|
||||||
}
|
|
||||||
ret = MZ_DoLoadImage( hFile, filename, NULL, ((ExecBlock *)paramblk)->env_seg );
|
|
||||||
if (ret) {
|
|
||||||
/* MZ_LoadImage created a new PSP and loaded new values into it,
|
|
||||||
* let's work on the new values now */
|
|
||||||
LPBYTE psp_start = (LPBYTE)((DWORD)DOSVM_psp << 4);
|
|
||||||
ExecBlock *blk = paramblk;
|
|
||||||
LPBYTE cmdline = PTR_REAL_TO_LIN(SELECTOROF(blk->cmdline),OFFSETOF(blk->cmdline));
|
|
||||||
|
|
||||||
/* First character contains the length of the command line. */
|
|
||||||
MZ_FillPSP(psp_start, (LPSTR)cmdline + 1, cmdline[0]);
|
|
||||||
|
|
||||||
/* the lame MS-DOS engineers decided that the return address should be in int22 */
|
|
||||||
DOSVM_SetRMHandler(0x22, (FARPROC16)MAKESEGPTR(context->SegCs, LOWORD(context->Eip)));
|
|
||||||
if (func) {
|
|
||||||
/* don't execute, just return startup state */
|
|
||||||
/*
|
|
||||||
* From Ralph Brown:
|
|
||||||
* For function 01h, the AX value to be passed to the child program
|
|
||||||
* is put on top of the child's stack
|
|
||||||
*/
|
|
||||||
LPBYTE stack;
|
|
||||||
init_sp -= 2;
|
|
||||||
stack = CTX_SEG_OFF_TO_LIN(context, init_ss, init_sp);
|
|
||||||
/* FIXME: push AX correctly */
|
|
||||||
stack[0] = 0x00; /* push AL */
|
|
||||||
stack[1] = 0x00; /* push AH */
|
|
||||||
|
|
||||||
blk->init_cs = init_cs;
|
|
||||||
blk->init_ip = init_ip;
|
|
||||||
blk->init_ss = init_ss;
|
|
||||||
blk->init_sp = init_sp;
|
|
||||||
} else {
|
|
||||||
/* execute by making us return to new process */
|
|
||||||
context->SegCs = init_cs;
|
|
||||||
context->Eip = init_ip;
|
|
||||||
context->SegSs = init_ss;
|
|
||||||
context->Esp = init_sp;
|
|
||||||
context->SegDs = DOSVM_psp;
|
|
||||||
context->SegEs = DOSVM_psp;
|
|
||||||
context->Eax = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 3: /* load overlay */
|
|
||||||
{
|
|
||||||
OverlayBlock *blk = paramblk;
|
|
||||||
ret = MZ_DoLoadImage( hFile, filename, blk, 0);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
FIXME("EXEC load type %d not implemented\n", func);
|
|
||||||
SetLastError(ERROR_INVALID_FUNCTION);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
CloseHandle(hFile);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/***********************************************************************
|
|
||||||
* MZ_AllocDPMITask
|
|
||||||
*/
|
|
||||||
void MZ_AllocDPMITask( void )
|
|
||||||
{
|
|
||||||
MZ_InitMemory();
|
|
||||||
MZ_InitTask();
|
|
||||||
}
|
|
||||||
|
|
||||||
/***********************************************************************
|
|
||||||
* MZ_RunInThread
|
|
||||||
*/
|
|
||||||
void MZ_RunInThread( PAPCFUNC proc, ULONG_PTR arg )
|
|
||||||
{
|
|
||||||
if (loop_thread) {
|
|
||||||
DOS_SPC spc;
|
|
||||||
HANDLE event;
|
|
||||||
|
|
||||||
spc.proc = proc;
|
|
||||||
spc.arg = arg;
|
|
||||||
event = CreateEventW(NULL, TRUE, FALSE, NULL);
|
|
||||||
PostThreadMessageA(loop_tid, WM_USER, (WPARAM)event, (LPARAM)&spc);
|
|
||||||
WaitForSingleObject(event, INFINITE);
|
|
||||||
CloseHandle(event);
|
|
||||||
} else
|
|
||||||
proc(arg);
|
|
||||||
}
|
|
||||||
|
|
||||||
static DWORD WINAPI MZ_DOSVM( LPVOID lpExtra )
|
|
||||||
{
|
|
||||||
CONTEXT context;
|
|
||||||
INT ret;
|
|
||||||
|
|
||||||
dosvm_pid = getpid();
|
|
||||||
|
|
||||||
memset( &context, 0, sizeof(context) );
|
|
||||||
context.SegCs = init_cs;
|
|
||||||
context.Eip = init_ip;
|
|
||||||
context.SegSs = init_ss;
|
|
||||||
context.Esp = init_sp;
|
|
||||||
context.SegDs = DOSVM_psp;
|
|
||||||
context.SegEs = DOSVM_psp;
|
|
||||||
context.EFlags = V86_FLAG | VIF_MASK;
|
|
||||||
DOSVM_SetTimer(0x10000);
|
|
||||||
ret = DOSVM_Enter( &context );
|
|
||||||
if (ret == -1) ret = GetLastError();
|
|
||||||
dosvm_pid = 0;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static BOOL MZ_InitTask(void)
|
|
||||||
{
|
|
||||||
if (!DuplicateHandle(GetCurrentProcess(), GetCurrentThread(),
|
|
||||||
GetCurrentProcess(), &loop_thread,
|
|
||||||
0, FALSE, DUPLICATE_SAME_ACCESS))
|
|
||||||
return FALSE;
|
|
||||||
dosvm_thread = CreateThread(NULL, 0, MZ_DOSVM, NULL, CREATE_SUSPENDED, &dosvm_tid);
|
|
||||||
if (!dosvm_thread) {
|
|
||||||
CloseHandle(loop_thread);
|
|
||||||
loop_thread = 0;
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
loop_tid = GetCurrentThreadId();
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static DWORD MZ_Launch( LPCSTR cmdtail, int length )
|
|
||||||
{
|
|
||||||
TDB *pTask = GlobalLock16( GetCurrentTask() );
|
|
||||||
BYTE *psp_start = PTR_REAL_TO_LIN( DOSVM_psp, 0 );
|
|
||||||
DWORD rv;
|
|
||||||
SYSLEVEL *lock;
|
|
||||||
MSG msg;
|
|
||||||
|
|
||||||
MZ_FillPSP(psp_start, cmdtail, length);
|
|
||||||
pTask->flags |= TDBF_WINOLDAP;
|
|
||||||
|
|
||||||
/* DTA is set to PSP:0080h when a program is started. */
|
|
||||||
pTask->dta = MAKESEGPTR( DOSVM_psp, 0x80 );
|
|
||||||
|
|
||||||
GetpWin16Lock( &lock );
|
|
||||||
_LeaveSysLevel( lock );
|
|
||||||
|
|
||||||
/* force the message queue to be created */
|
|
||||||
PeekMessageW(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);
|
|
||||||
|
|
||||||
ResumeThread(dosvm_thread);
|
|
||||||
rv = DOSVM_Loop(dosvm_thread);
|
|
||||||
|
|
||||||
CloseHandle(dosvm_thread);
|
|
||||||
dosvm_thread = 0; dosvm_tid = 0;
|
|
||||||
CloseHandle(loop_thread);
|
|
||||||
loop_thread = 0; loop_tid = 0;
|
|
||||||
if (rv) return rv;
|
|
||||||
|
|
||||||
VGA_Clean();
|
|
||||||
ExitProcess(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/***********************************************************************
|
|
||||||
* MZ_Exit
|
|
||||||
*/
|
|
||||||
void MZ_Exit( CONTEXT *context, BOOL cs_psp, WORD retval )
|
|
||||||
{
|
|
||||||
if (DOSVM_psp) {
|
|
||||||
WORD psp_seg = cs_psp ? context->SegCs : DOSVM_psp;
|
|
||||||
LPBYTE psp_start = (LPBYTE)((DWORD)psp_seg << 4);
|
|
||||||
PDB16 *psp = (PDB16 *)psp_start;
|
|
||||||
WORD parpsp = psp->parentPSP; /* check for parent DOS process */
|
|
||||||
if (parpsp) {
|
|
||||||
/* retrieve parent's return address */
|
|
||||||
FARPROC16 retaddr = DOSVM_GetRMHandler(0x22);
|
|
||||||
/* restore interrupts */
|
|
||||||
DOSVM_SetRMHandler(0x22, psp->savedint22);
|
|
||||||
DOSVM_SetRMHandler(0x23, psp->savedint23);
|
|
||||||
DOSVM_SetRMHandler(0x24, psp->savedint24);
|
|
||||||
/* FIXME: deallocate file handles etc */
|
|
||||||
/* free process's associated memory
|
|
||||||
* FIXME: walk memory and deallocate all blocks owned by process */
|
|
||||||
DOSMEM_FreeBlock( PTR_REAL_TO_LIN(psp->environment,0) );
|
|
||||||
DOSMEM_FreeBlock( PTR_REAL_TO_LIN(DOSVM_psp,0) );
|
|
||||||
/* switch to parent's PSP */
|
|
||||||
DOSVM_psp = parpsp;
|
|
||||||
psp_start = (LPBYTE)((DWORD)parpsp << 4);
|
|
||||||
psp = (PDB16 *)psp_start;
|
|
||||||
/* now return to parent */
|
|
||||||
DOSVM_retval = retval;
|
|
||||||
context->SegCs = SELECTOROF(retaddr);
|
|
||||||
context->Eip = OFFSETOF(retaddr);
|
|
||||||
context->SegSs = SELECTOROF(psp->saveStack);
|
|
||||||
context->Esp = OFFSETOF(psp->saveStack);
|
|
||||||
return;
|
|
||||||
} else
|
|
||||||
TRACE("killing DOS task\n");
|
|
||||||
}
|
|
||||||
DOSVM_Exit( retval );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/***********************************************************************
|
|
||||||
* MZ_Current
|
|
||||||
*/
|
|
||||||
BOOL MZ_Current( void )
|
|
||||||
{
|
|
||||||
return (dosvm_pid != 0); /* FIXME: do a better check */
|
|
||||||
}
|
|
||||||
|
|
||||||
#else /* !MZ_SUPPORTED */
|
|
||||||
|
|
||||||
/***********************************************************************
|
|
||||||
* __wine_load_dos_exe (KERNEL.@)
|
|
||||||
*/
|
|
||||||
void __wine_load_dos_exe( LPCSTR filename, LPCSTR cmdline )
|
|
||||||
{
|
|
||||||
SetLastError( ERROR_NOT_SUPPORTED );
|
|
||||||
}
|
|
||||||
|
|
||||||
/***********************************************************************
|
|
||||||
* MZ_Exec
|
|
||||||
*/
|
|
||||||
BOOL MZ_Exec( CONTEXT *context, LPCSTR filename, BYTE func, LPVOID paramblk )
|
|
||||||
{
|
|
||||||
/* can't happen */
|
|
||||||
SetLastError(ERROR_BAD_FORMAT);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/***********************************************************************
|
|
||||||
* MZ_AllocDPMITask
|
|
||||||
*/
|
|
||||||
void MZ_AllocDPMITask( void )
|
|
||||||
{
|
|
||||||
FIXME("Actual real-mode calls not supported on this platform!\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
/***********************************************************************
|
|
||||||
* MZ_RunInThread
|
|
||||||
*/
|
|
||||||
void MZ_RunInThread( PAPCFUNC proc, ULONG_PTR arg )
|
|
||||||
{
|
|
||||||
proc(arg);
|
|
||||||
}
|
|
||||||
|
|
||||||
/***********************************************************************
|
|
||||||
* MZ_Exit
|
|
||||||
*/
|
|
||||||
void MZ_Exit( CONTEXT *context, BOOL cs_psp, WORD retval )
|
|
||||||
{
|
|
||||||
DOSVM_Exit( retval );
|
|
||||||
}
|
|
||||||
|
|
||||||
/***********************************************************************
|
|
||||||
* MZ_Current
|
|
||||||
*/
|
|
||||||
BOOL MZ_Current( void )
|
|
||||||
{
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* !MZ_SUPPORTED */
|
|
|
@ -33,15 +33,6 @@
|
||||||
|
|
||||||
#define MAX_DOS_DRIVES 26
|
#define MAX_DOS_DRIVES 26
|
||||||
|
|
||||||
struct _DOSEVENT;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
PAPCFUNC proc;
|
|
||||||
ULONG_PTR arg;
|
|
||||||
} DOS_SPC;
|
|
||||||
|
|
||||||
extern pid_t dosvm_pid DECLSPEC_HIDDEN;
|
|
||||||
|
|
||||||
/* amount of space reserved for relay stack */
|
/* amount of space reserved for relay stack */
|
||||||
#define DOSVM_RELAY_DATA_SIZE 4096
|
#define DOSVM_RELAY_DATA_SIZE 4096
|
||||||
|
|
||||||
|
@ -78,10 +69,6 @@ extern WORD DOSVM_psp DECLSPEC_HIDDEN; /* psp of current DOS task */
|
||||||
extern WORD DOSVM_retval DECLSPEC_HIDDEN; /* return value of previous DOS task */
|
extern WORD DOSVM_retval DECLSPEC_HIDDEN; /* return value of previous DOS task */
|
||||||
extern struct DPMI_segments *DOSVM_dpmi_segments DECLSPEC_HIDDEN;
|
extern struct DPMI_segments *DOSVM_dpmi_segments DECLSPEC_HIDDEN;
|
||||||
|
|
||||||
#if defined(linux) && defined(__i386__) && defined(HAVE_SYS_VM86_H)
|
|
||||||
# define MZ_SUPPORTED
|
|
||||||
#endif /* linux-i386 */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Declare some CONTEXT.EFlags bits.
|
* Declare some CONTEXT.EFlags bits.
|
||||||
* IF_MASK is only pushed into real mode stack.
|
* IF_MASK is only pushed into real mode stack.
|
||||||
|
@ -333,19 +320,11 @@ typedef struct
|
||||||
RMCBPROC interrupt;
|
RMCBPROC interrupt;
|
||||||
} WINEDEV;
|
} WINEDEV;
|
||||||
|
|
||||||
/* dosexe.c */
|
|
||||||
extern BOOL MZ_Exec( CONTEXT *context, LPCSTR filename, BYTE func, LPVOID paramblk ) DECLSPEC_HIDDEN;
|
|
||||||
extern void MZ_Exit( CONTEXT *context, BOOL cs_psp, WORD retval ) DECLSPEC_HIDDEN;
|
|
||||||
extern BOOL MZ_Current( void ) DECLSPEC_HIDDEN;
|
|
||||||
extern void MZ_AllocDPMITask( void ) DECLSPEC_HIDDEN;
|
|
||||||
extern void MZ_RunInThread( PAPCFUNC proc, ULONG_PTR arg ) DECLSPEC_HIDDEN;
|
|
||||||
extern BOOL DOSVM_IsWin16(void) DECLSPEC_HIDDEN;
|
|
||||||
extern void DOSVM_Exit( WORD retval ) DECLSPEC_HIDDEN;
|
|
||||||
|
|
||||||
/* dosvm.c */
|
/* dosvm.c */
|
||||||
extern void DOSVM_SendQueuedEvents( CONTEXT * ) DECLSPEC_HIDDEN;
|
extern void DOSVM_SendQueuedEvents( CONTEXT * ) DECLSPEC_HIDDEN;
|
||||||
extern void WINAPI DOSVM_AcknowledgeIRQ( CONTEXT * ) DECLSPEC_HIDDEN;
|
extern void WINAPI DOSVM_AcknowledgeIRQ( CONTEXT * ) DECLSPEC_HIDDEN;
|
||||||
extern INT DOSVM_Enter( CONTEXT *context ) DECLSPEC_HIDDEN;
|
extern INT DOSVM_Enter( CONTEXT *context ) DECLSPEC_HIDDEN;
|
||||||
|
extern void DOSVM_Exit( WORD retval ) DECLSPEC_HIDDEN;
|
||||||
extern void DOSVM_Wait( CONTEXT * ) DECLSPEC_HIDDEN;
|
extern void DOSVM_Wait( CONTEXT * ) DECLSPEC_HIDDEN;
|
||||||
extern DWORD DOSVM_Loop( HANDLE hThread ) DECLSPEC_HIDDEN;
|
extern DWORD DOSVM_Loop( HANDLE hThread ) DECLSPEC_HIDDEN;
|
||||||
extern void DOSVM_QueueEvent( INT irq, INT priority, DOSRELAY relay, LPVOID data ) DECLSPEC_HIDDEN;
|
extern void DOSVM_QueueEvent( INT irq, INT priority, DOSRELAY relay, LPVOID data ) DECLSPEC_HIDDEN;
|
||||||
|
@ -442,7 +421,6 @@ extern void EMS_Ioctl_Handler(CONTEXT*) DECLSPEC_HIDDEN;
|
||||||
extern void __wine_call_int_handler( CONTEXT *, BYTE ) DECLSPEC_HIDDEN;
|
extern void __wine_call_int_handler( CONTEXT *, BYTE ) DECLSPEC_HIDDEN;
|
||||||
extern void DOSVM_CallBuiltinHandler( CONTEXT *, BYTE ) DECLSPEC_HIDDEN;
|
extern void DOSVM_CallBuiltinHandler( CONTEXT *, BYTE ) DECLSPEC_HIDDEN;
|
||||||
extern BOOL DOSVM_EmulateInterruptPM( CONTEXT *, BYTE ) DECLSPEC_HIDDEN;
|
extern BOOL DOSVM_EmulateInterruptPM( CONTEXT *, BYTE ) DECLSPEC_HIDDEN;
|
||||||
extern BOOL DOSVM_EmulateInterruptRM( CONTEXT *, BYTE ) DECLSPEC_HIDDEN;
|
|
||||||
extern FARPROC16 DOSVM_GetPMHandler16( BYTE ) DECLSPEC_HIDDEN;
|
extern FARPROC16 DOSVM_GetPMHandler16( BYTE ) DECLSPEC_HIDDEN;
|
||||||
extern FARPROC48 DOSVM_GetPMHandler48( BYTE ) DECLSPEC_HIDDEN;
|
extern FARPROC48 DOSVM_GetPMHandler48( BYTE ) DECLSPEC_HIDDEN;
|
||||||
extern FARPROC16 DOSVM_GetRMHandler( BYTE ) DECLSPEC_HIDDEN;
|
extern FARPROC16 DOSVM_GetRMHandler( BYTE ) DECLSPEC_HIDDEN;
|
||||||
|
|
|
@ -55,10 +55,6 @@
|
||||||
#include "excpt.h"
|
#include "excpt.h"
|
||||||
|
|
||||||
WINE_DEFAULT_DEBUG_CHANNEL(int);
|
WINE_DEFAULT_DEBUG_CHANNEL(int);
|
||||||
#ifdef MZ_SUPPORTED
|
|
||||||
WINE_DECLARE_DEBUG_CHANNEL(module);
|
|
||||||
WINE_DECLARE_DEBUG_CHANNEL(relay);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
WORD DOSVM_psp = 0;
|
WORD DOSVM_psp = 0;
|
||||||
WORD DOSVM_retval = 0;
|
WORD DOSVM_retval = 0;
|
||||||
|
@ -250,422 +246,12 @@ void DOSVM_SendQueuedEvents( CONTEXT *context )
|
||||||
get_vm86_teb_info()->vm86_pending = 0;
|
get_vm86_teb_info()->vm86_pending = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef MZ_SUPPORTED
|
|
||||||
|
|
||||||
if (DOSVM_HasPendingEvents())
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* Interrupts disabled, but there are still
|
|
||||||
* pending events, make sure that pending flag is turned on.
|
|
||||||
*/
|
|
||||||
TRACE( "Another event is pending, setting VIP flag.\n" );
|
|
||||||
get_vm86_teb_info()->vm86_pending |= VIP_MASK;
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
FIXME("No DOS .exe file support on this platform (yet)\n");
|
FIXME("No DOS .exe file support on this platform (yet)\n");
|
||||||
|
|
||||||
#endif /* MZ_SUPPORTED */
|
|
||||||
|
|
||||||
LeaveCriticalSection(&qcrit);
|
LeaveCriticalSection(&qcrit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef MZ_SUPPORTED
|
|
||||||
/***********************************************************************
|
|
||||||
* DOSVM_QueueEvent
|
|
||||||
*/
|
|
||||||
void DOSVM_QueueEvent( INT irq, INT priority, DOSRELAY relay, LPVOID data)
|
|
||||||
{
|
|
||||||
LPDOSEVENT event, cur, prev;
|
|
||||||
BOOL old_pending;
|
|
||||||
|
|
||||||
if (MZ_Current()) {
|
|
||||||
event = HeapAlloc(GetProcessHeap(), 0, sizeof(DOSEVENT));
|
|
||||||
if (!event) {
|
|
||||||
ERR("out of memory allocating event entry\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
event->irq = irq; event->priority = priority;
|
|
||||||
event->relay = relay; event->data = data;
|
|
||||||
|
|
||||||
EnterCriticalSection(&qcrit);
|
|
||||||
old_pending = DOSVM_HasPendingEvents();
|
|
||||||
|
|
||||||
/* insert event into linked list, in order *after*
|
|
||||||
* all earlier events of higher or equal priority */
|
|
||||||
cur = pending_event; prev = NULL;
|
|
||||||
while (cur && cur->priority<=priority) {
|
|
||||||
prev = cur;
|
|
||||||
cur = cur->next;
|
|
||||||
}
|
|
||||||
event->next = cur;
|
|
||||||
if (prev) prev->next = event;
|
|
||||||
else pending_event = event;
|
|
||||||
|
|
||||||
if (!old_pending && DOSVM_HasPendingEvents()) {
|
|
||||||
TRACE("new event queued, signalling (time=%d)\n", GetTickCount());
|
|
||||||
|
|
||||||
/* Alert VM86 thread about the new event. */
|
|
||||||
kill(dosvm_pid,SIGUSR2);
|
|
||||||
|
|
||||||
/* Wake up DOSVM_Wait so that it can serve pending events. */
|
|
||||||
SetEvent(event_notifier);
|
|
||||||
} else {
|
|
||||||
TRACE("new event queued (time=%d)\n", GetTickCount());
|
|
||||||
}
|
|
||||||
|
|
||||||
LeaveCriticalSection(&qcrit);
|
|
||||||
} else {
|
|
||||||
/* DOS subsystem not running */
|
|
||||||
/* (this probably means that we're running a win16 app
|
|
||||||
* which uses DPMI to thunk down to DOS services) */
|
|
||||||
if (irq<0) {
|
|
||||||
/* callback event, perform it with dummy context */
|
|
||||||
CONTEXT context;
|
|
||||||
memset(&context,0,sizeof(context));
|
|
||||||
(*relay)(&context,data);
|
|
||||||
} else {
|
|
||||||
ERR("IRQ without DOS task: should not happen\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void DOSVM_ProcessConsole(void)
|
|
||||||
{
|
|
||||||
INPUT_RECORD msg;
|
|
||||||
DWORD res;
|
|
||||||
BYTE scan, ascii;
|
|
||||||
|
|
||||||
if (ReadConsoleInputA(GetStdHandle(STD_INPUT_HANDLE),&msg,1,&res)) {
|
|
||||||
switch (msg.EventType) {
|
|
||||||
case KEY_EVENT:
|
|
||||||
scan = msg.Event.KeyEvent.wVirtualScanCode;
|
|
||||||
ascii = msg.Event.KeyEvent.uChar.AsciiChar;
|
|
||||||
TRACE("scan %02x, ascii %02x\n", scan, ascii);
|
|
||||||
|
|
||||||
/* set the "break" (release) flag if key released */
|
|
||||||
if (!msg.Event.KeyEvent.bKeyDown) scan |= 0x80;
|
|
||||||
|
|
||||||
/* check whether extended bit is set,
|
|
||||||
* and if so, queue the extension prefix */
|
|
||||||
if (msg.Event.KeyEvent.dwControlKeyState & ENHANCED_KEY) {
|
|
||||||
DOSVM_Int09SendScan(0xE0,0);
|
|
||||||
}
|
|
||||||
DOSVM_Int09SendScan(scan, ascii);
|
|
||||||
break;
|
|
||||||
case MOUSE_EVENT:
|
|
||||||
DOSVM_Int33Console(&msg.Event.MouseEvent);
|
|
||||||
break;
|
|
||||||
case WINDOW_BUFFER_SIZE_EVENT:
|
|
||||||
FIXME("unhandled WINDOW_BUFFER_SIZE_EVENT.\n");
|
|
||||||
break;
|
|
||||||
case MENU_EVENT:
|
|
||||||
FIXME("unhandled MENU_EVENT.\n");
|
|
||||||
break;
|
|
||||||
case FOCUS_EVENT:
|
|
||||||
FIXME("unhandled FOCUS_EVENT.\n");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
FIXME("unknown console event: %d\n", msg.EventType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void DOSVM_ProcessMessage(MSG *msg)
|
|
||||||
{
|
|
||||||
BYTE scan = 0;
|
|
||||||
|
|
||||||
TRACE("got message %04x, wparam=%08lx, lparam=%08lx\n",msg->message,msg->wParam,msg->lParam);
|
|
||||||
if ((msg->message>=WM_MOUSEFIRST)&&
|
|
||||||
(msg->message<=WM_MOUSELAST)) {
|
|
||||||
DOSVM_Int33Message(msg->message,msg->wParam,msg->lParam);
|
|
||||||
} else {
|
|
||||||
switch (msg->message) {
|
|
||||||
case WM_KEYUP:
|
|
||||||
scan = 0x80;
|
|
||||||
case WM_KEYDOWN:
|
|
||||||
scan |= (msg->lParam >> 16) & 0x7f;
|
|
||||||
|
|
||||||
/* check whether extended bit is set,
|
|
||||||
* and if so, queue the extension prefix */
|
|
||||||
if (msg->lParam & 0x1000000) {
|
|
||||||
/* FIXME: some keys (function keys) have
|
|
||||||
* extended bit set even when they shouldn't,
|
|
||||||
* should check for them */
|
|
||||||
DOSVM_Int09SendScan(0xE0,0);
|
|
||||||
}
|
|
||||||
DOSVM_Int09SendScan(scan,0);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/***********************************************************************
|
|
||||||
* DOSVM_Wait
|
|
||||||
*
|
|
||||||
* Wait for asynchronous events. This routine temporarily enables
|
|
||||||
* interrupts and waits until some asynchronous event has been
|
|
||||||
* processed.
|
|
||||||
*/
|
|
||||||
void DOSVM_Wait( CONTEXT *waitctx )
|
|
||||||
{
|
|
||||||
if (DOSVM_HasPendingEvents())
|
|
||||||
{
|
|
||||||
CONTEXT context = *waitctx;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* If DOSVM_Wait is called from protected mode we emulate
|
|
||||||
* interrupt reflection and convert context into real mode context.
|
|
||||||
* This is actually the correct thing to do as long as DOSVM_Wait
|
|
||||||
* is only called from those interrupt functions that DPMI reflects
|
|
||||||
* to real mode.
|
|
||||||
*
|
|
||||||
* FIXME: Need to think about where to place real mode stack.
|
|
||||||
* FIXME: If DOSVM_Wait calls are nested stack gets corrupted.
|
|
||||||
* Can this really happen?
|
|
||||||
*/
|
|
||||||
if (!ISV86(&context))
|
|
||||||
{
|
|
||||||
context.EFlags |= V86_FLAG;
|
|
||||||
context.SegSs = 0xffff;
|
|
||||||
context.Esp = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
context.EFlags |= VIF_MASK;
|
|
||||||
context.SegCs = 0;
|
|
||||||
context.Eip = 0;
|
|
||||||
|
|
||||||
DOSVM_SendQueuedEvents(&context);
|
|
||||||
|
|
||||||
if(context.SegCs || context.Eip)
|
|
||||||
DPMI_CallRMProc( &context, NULL, 0, TRUE );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
HANDLE objs[2];
|
|
||||||
int objc = DOSVM_IsWin16() ? 2 : 1;
|
|
||||||
DWORD waitret;
|
|
||||||
|
|
||||||
objs[0] = event_notifier;
|
|
||||||
objs[1] = GetStdHandle(STD_INPUT_HANDLE);
|
|
||||||
|
|
||||||
waitret = MsgWaitForMultipleObjects( objc, objs, FALSE,
|
|
||||||
INFINITE, QS_ALLINPUT );
|
|
||||||
|
|
||||||
if (waitret == WAIT_OBJECT_0)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* New pending event has been queued, we ignore it
|
|
||||||
* here because it will be processed on next call to
|
|
||||||
* DOSVM_Wait.
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
else if (objc == 2 && waitret == WAIT_OBJECT_0 + 1)
|
|
||||||
{
|
|
||||||
DOSVM_ProcessConsole();
|
|
||||||
}
|
|
||||||
else if (waitret == WAIT_OBJECT_0 + objc)
|
|
||||||
{
|
|
||||||
MSG msg;
|
|
||||||
while (PeekMessageA(&msg,0,0,0,PM_REMOVE|PM_NOYIELD))
|
|
||||||
{
|
|
||||||
/* got a message */
|
|
||||||
DOSVM_ProcessMessage(&msg);
|
|
||||||
/* we don't need a TranslateMessage here */
|
|
||||||
DispatchMessageA(&msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ERR_(module)( "dosvm wait error=%d\n", GetLastError() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DWORD DOSVM_Loop( HANDLE hThread )
|
|
||||||
{
|
|
||||||
HANDLE objs[2];
|
|
||||||
int count = 0;
|
|
||||||
MSG msg;
|
|
||||||
DWORD waitret;
|
|
||||||
|
|
||||||
objs[count++] = hThread;
|
|
||||||
if (GetConsoleMode( GetStdHandle(STD_INPUT_HANDLE), NULL ))
|
|
||||||
objs[count++] = GetStdHandle(STD_INPUT_HANDLE);
|
|
||||||
|
|
||||||
for(;;) {
|
|
||||||
TRACE_(int)("waiting for action\n");
|
|
||||||
waitret = MsgWaitForMultipleObjects(count, objs, FALSE, INFINITE, QS_ALLINPUT);
|
|
||||||
if (waitret == WAIT_OBJECT_0) {
|
|
||||||
DWORD rv;
|
|
||||||
if(!GetExitCodeThread(hThread, &rv)) {
|
|
||||||
ERR("Failed to get thread exit code!\n");
|
|
||||||
rv = 0;
|
|
||||||
}
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
else if (waitret == WAIT_OBJECT_0 + count) {
|
|
||||||
while (PeekMessageA(&msg,0,0,0,PM_REMOVE)) {
|
|
||||||
if (msg.hwnd) {
|
|
||||||
/* it's a window message */
|
|
||||||
DOSVM_ProcessMessage(&msg);
|
|
||||||
DispatchMessageA(&msg);
|
|
||||||
} else {
|
|
||||||
/* it's a thread message */
|
|
||||||
switch (msg.message) {
|
|
||||||
case WM_QUIT:
|
|
||||||
/* stop this madness!! */
|
|
||||||
return 0;
|
|
||||||
case WM_USER:
|
|
||||||
/* run passed procedure in this thread */
|
|
||||||
/* (sort of like APC, but we signal the completion) */
|
|
||||||
{
|
|
||||||
DOS_SPC *spc = (DOS_SPC *)msg.lParam;
|
|
||||||
TRACE_(int)("calling %p with arg %08lx\n", spc->proc, spc->arg);
|
|
||||||
(spc->proc)(spc->arg);
|
|
||||||
TRACE_(int)("done, signalling event %lx\n", msg.wParam);
|
|
||||||
SetEvent( (HANDLE)msg.wParam );
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
DispatchMessageA(&msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (waitret == WAIT_OBJECT_0 + 1)
|
|
||||||
{
|
|
||||||
DOSVM_ProcessConsole();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ERR_(int)("MsgWaitForMultipleObjects returned unexpected value.\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static LONG WINAPI exception_handler(EXCEPTION_POINTERS *eptr)
|
|
||||||
{
|
|
||||||
EXCEPTION_RECORD *rec = eptr->ExceptionRecord;
|
|
||||||
CONTEXT *context = eptr->ContextRecord;
|
|
||||||
int arg = rec->ExceptionInformation[0];
|
|
||||||
BOOL ret;
|
|
||||||
|
|
||||||
switch(rec->ExceptionCode) {
|
|
||||||
case EXCEPTION_VM86_INTx:
|
|
||||||
TRACE_(relay)("\1Call DOS int 0x%02x ret=%04x:%04x\n"
|
|
||||||
" eax=%08x ebx=%08x ecx=%08x edx=%08x esi=%08x edi=%08x\n"
|
|
||||||
" ebp=%08x esp=%08x ds=%04x es=%04x fs=%04x gs=%04x flags=%08x\n",
|
|
||||||
arg, context->SegCs, context->Eip,
|
|
||||||
context->Eax, context->Ebx, context->Ecx, context->Edx, context->Esi, context->Edi,
|
|
||||||
context->Ebp, context->Esp, context->SegDs, context->SegEs, context->SegFs, context->SegGs,
|
|
||||||
context->EFlags );
|
|
||||||
ret = DOSVM_EmulateInterruptRM( context, arg );
|
|
||||||
TRACE_(relay)("\1Ret DOS int 0x%02x ret=%04x:%04x\n"
|
|
||||||
" eax=%08x ebx=%08x ecx=%08x edx=%08x esi=%08x edi=%08x\n"
|
|
||||||
" ebp=%08x esp=%08x ds=%04x es=%04x fs=%04x gs=%04x flags=%08x\n",
|
|
||||||
arg, context->SegCs, context->Eip,
|
|
||||||
context->Eax, context->Ebx, context->Ecx, context->Edx, context->Esi, context->Edi,
|
|
||||||
context->Ebp, context->Esp, context->SegDs, context->SegEs,
|
|
||||||
context->SegFs, context->SegGs, context->EFlags );
|
|
||||||
return ret ? EXCEPTION_CONTINUE_EXECUTION : EXCEPTION_EXECUTE_HANDLER;
|
|
||||||
|
|
||||||
case EXCEPTION_VM86_STI:
|
|
||||||
/* case EXCEPTION_VM86_PICRETURN: */
|
|
||||||
if (!ISV86(context))
|
|
||||||
ERR( "Protected mode STI caught by real mode handler!\n" );
|
|
||||||
DOSVM_SendQueuedEvents(context);
|
|
||||||
return EXCEPTION_CONTINUE_EXECUTION;
|
|
||||||
|
|
||||||
case EXCEPTION_SINGLE_STEP:
|
|
||||||
ret = DOSVM_EmulateInterruptRM( context, 1 );
|
|
||||||
return ret ? EXCEPTION_CONTINUE_EXECUTION : EXCEPTION_EXECUTE_HANDLER;
|
|
||||||
|
|
||||||
case EXCEPTION_BREAKPOINT:
|
|
||||||
ret = DOSVM_EmulateInterruptRM( context, 3 );
|
|
||||||
return ret ? EXCEPTION_CONTINUE_EXECUTION : EXCEPTION_EXECUTE_HANDLER;
|
|
||||||
|
|
||||||
}
|
|
||||||
return EXCEPTION_CONTINUE_SEARCH;
|
|
||||||
}
|
|
||||||
|
|
||||||
INT DOSVM_Enter( CONTEXT *context )
|
|
||||||
{
|
|
||||||
INT ret = 0;
|
|
||||||
if (!ISV86(context))
|
|
||||||
ERR( "Called with protected mode context!\n" );
|
|
||||||
|
|
||||||
__TRY
|
|
||||||
{
|
|
||||||
if (!WOWCallback16Ex( 0, WCB16_REGS, 0, NULL, (DWORD *)context )) ret = -1;
|
|
||||||
TRACE_(module)( "ret %d err %u\n", ret, GetLastError() );
|
|
||||||
}
|
|
||||||
__EXCEPT(exception_handler)
|
|
||||||
{
|
|
||||||
TRACE_(module)( "leaving vm86 mode\n" );
|
|
||||||
}
|
|
||||||
__ENDTRY
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/***********************************************************************
|
|
||||||
* DOSVM_PIC_ioport_out
|
|
||||||
*/
|
|
||||||
void DOSVM_PIC_ioport_out( WORD port, BYTE val)
|
|
||||||
{
|
|
||||||
if (port != 0x20)
|
|
||||||
{
|
|
||||||
FIXME( "Unsupported PIC port %04x\n", port );
|
|
||||||
}
|
|
||||||
else if (val == 0x20 || (val >= 0x60 && val <= 0x67))
|
|
||||||
{
|
|
||||||
EnterCriticalSection(&qcrit);
|
|
||||||
|
|
||||||
if (!current_event)
|
|
||||||
{
|
|
||||||
WARN( "%s without active IRQ\n",
|
|
||||||
val == 0x20 ? "EOI" : "Specific EOI" );
|
|
||||||
}
|
|
||||||
else if (val != 0x20 && val - 0x60 != current_event->irq)
|
|
||||||
{
|
|
||||||
WARN( "Specific EOI but current IRQ %d is not %d\n",
|
|
||||||
current_event->irq, val - 0x60 );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LPDOSEVENT event = current_event;
|
|
||||||
|
|
||||||
TRACE( "Received %s for current IRQ %d, clearing event\n",
|
|
||||||
val == 0x20 ? "EOI" : "Specific EOI", event->irq );
|
|
||||||
|
|
||||||
current_event = event->next;
|
|
||||||
if (event->relay)
|
|
||||||
(*event->relay)(NULL,event->data);
|
|
||||||
HeapFree(GetProcessHeap(), 0, event);
|
|
||||||
|
|
||||||
if (DOSVM_HasPendingEvents())
|
|
||||||
{
|
|
||||||
TRACE( "Another event pending, setting pending flag\n" );
|
|
||||||
get_vm86_teb_info()->vm86_pending |= VIP_MASK;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LeaveCriticalSection(&qcrit);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
FIXME( "Unrecognized PIC command %02x\n", val );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#else /* !MZ_SUPPORTED */
|
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* DOSVM_Enter
|
* DOSVM_Enter
|
||||||
*/
|
*/
|
||||||
|
@ -675,6 +261,17 @@ INT DOSVM_Enter( CONTEXT *context )
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**********************************************************************
|
||||||
|
* DOSVM_Exit
|
||||||
|
*/
|
||||||
|
void DOSVM_Exit( WORD retval )
|
||||||
|
{
|
||||||
|
DWORD count;
|
||||||
|
|
||||||
|
ReleaseThunkLock( &count );
|
||||||
|
ExitThread( retval );
|
||||||
|
}
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* DOSVM_Wait
|
* DOSVM_Wait
|
||||||
*/
|
*/
|
||||||
|
@ -700,8 +297,6 @@ void DOSVM_QueueEvent( INT irq, INT priority, DOSRELAY relay, LPVOID data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* MZ_SUPPORTED */
|
|
||||||
|
|
||||||
|
|
||||||
/**********************************************************************
|
/**********************************************************************
|
||||||
* DOSVM_AcknowledgeIRQ
|
* DOSVM_AcknowledgeIRQ
|
||||||
|
|
|
@ -583,7 +583,7 @@ static WORD INT21_GetHeapSelector( CONTEXT *context )
|
||||||
{
|
{
|
||||||
INT21_HEAP *heap = INT21_GetHeapPointer();
|
INT21_HEAP *heap = INT21_GetHeapPointer();
|
||||||
|
|
||||||
if (!ISV86(context) && DOSVM_IsWin16())
|
if (!ISV86(context))
|
||||||
return heap->misc_selector;
|
return heap->misc_selector;
|
||||||
else
|
else
|
||||||
return heap->misc_segment;
|
return heap->misc_segment;
|
||||||
|
@ -2377,7 +2377,7 @@ static void INT21_GetPSP( CONTEXT *context )
|
||||||
* FIXME: should we return the original DOS PSP upon
|
* FIXME: should we return the original DOS PSP upon
|
||||||
* Windows startup ?
|
* Windows startup ?
|
||||||
*/
|
*/
|
||||||
if (!ISV86(context) && DOSVM_IsWin16())
|
if (!ISV86(context))
|
||||||
SET_BX( context, LOWORD(GetCurrentPDB16()) );
|
SET_BX( context, LOWORD(GetCurrentPDB16()) );
|
||||||
else
|
else
|
||||||
SET_BX( context, DOSVM_psp );
|
SET_BX( context, DOSVM_psp );
|
||||||
|
@ -4170,12 +4170,7 @@ void WINAPI DOSVM_Int21Handler( CONTEXT *context )
|
||||||
{
|
{
|
||||||
case 0x00: /* TERMINATE PROGRAM */
|
case 0x00: /* TERMINATE PROGRAM */
|
||||||
TRACE("TERMINATE PROGRAM\n");
|
TRACE("TERMINATE PROGRAM\n");
|
||||||
if (DOSVM_IsWin16())
|
DOSVM_Exit( 0 );
|
||||||
DOSVM_Exit( 0 );
|
|
||||||
else if(ISV86(context))
|
|
||||||
MZ_Exit( context, FALSE, 0 );
|
|
||||||
else
|
|
||||||
ERR( "Called from DOS protected mode\n" );
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
|
case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
|
||||||
|
@ -4266,13 +4261,7 @@ void WINAPI DOSVM_Int21Handler( CONTEXT *context )
|
||||||
*/
|
*/
|
||||||
while (*p != '$') p++;
|
while (*p != '$') p++;
|
||||||
|
|
||||||
if (DOSVM_IsWin16())
|
WriteFile( DosFileHandleToWin32Handle(1), data, p - data, &w, NULL );
|
||||||
WriteFile( DosFileHandleToWin32Handle(1),
|
|
||||||
data, p - data, &w, NULL );
|
|
||||||
else
|
|
||||||
for(; data != p; data++)
|
|
||||||
DOSVM_PutChar( *data );
|
|
||||||
|
|
||||||
SET_AL( context, '$' ); /* yes, '$' (0x24) gets returned in AL */
|
SET_AL( context, '$' ); /* yes, '$' (0x24) gets returned in AL */
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -4458,7 +4447,7 @@ void WINAPI DOSVM_Int21Handler( CONTEXT *context )
|
||||||
TRACE("SET INTERRUPT VECTOR 0x%02x\n",AL_reg(context));
|
TRACE("SET INTERRUPT VECTOR 0x%02x\n",AL_reg(context));
|
||||||
{
|
{
|
||||||
FARPROC16 ptr = (FARPROC16)MAKESEGPTR( context->SegDs, DX_reg(context) );
|
FARPROC16 ptr = (FARPROC16)MAKESEGPTR( context->SegDs, DX_reg(context) );
|
||||||
if (!ISV86(context) && DOSVM_IsWin16())
|
if (!ISV86(context))
|
||||||
DOSVM_SetPMHandler16( AL_reg(context), ptr );
|
DOSVM_SetPMHandler16( AL_reg(context), ptr );
|
||||||
else
|
else
|
||||||
DOSVM_SetRMHandler( AL_reg(context), ptr );
|
DOSVM_SetRMHandler( AL_reg(context), ptr );
|
||||||
|
@ -4655,7 +4644,7 @@ void WINAPI DOSVM_Int21Handler( CONTEXT *context )
|
||||||
TRACE("GET INTERRUPT VECTOR 0x%02x\n",AL_reg(context));
|
TRACE("GET INTERRUPT VECTOR 0x%02x\n",AL_reg(context));
|
||||||
{
|
{
|
||||||
FARPROC16 addr;
|
FARPROC16 addr;
|
||||||
if (!ISV86(context) && DOSVM_IsWin16())
|
if (!ISV86(context))
|
||||||
addr = DOSVM_GetPMHandler16( AL_reg(context) );
|
addr = DOSVM_GetPMHandler16( AL_reg(context) );
|
||||||
else
|
else
|
||||||
addr = DOSVM_GetRMHandler( AL_reg(context) );
|
addr = DOSVM_GetRMHandler( AL_reg(context) );
|
||||||
|
@ -4784,13 +4773,8 @@ void WINAPI DOSVM_Int21Handler( CONTEXT *context )
|
||||||
context->Edx );
|
context->Edx );
|
||||||
|
|
||||||
/* Some programs pass a count larger than the allocated buffer */
|
/* Some programs pass a count larger than the allocated buffer */
|
||||||
if (DOSVM_IsWin16())
|
DWORD maxcount = GetSelectorLimit16( context->SegDs ) - DX_reg(context) + 1;
|
||||||
{
|
if (count > maxcount) count = maxcount;
|
||||||
DWORD maxcount = GetSelectorLimit16( context->SegDs )
|
|
||||||
- DX_reg(context) + 1;
|
|
||||||
if (count > maxcount)
|
|
||||||
count = maxcount;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* FIXME: Reading from console (BX=1) in DOS mode
|
* FIXME: Reading from console (BX=1) in DOS mode
|
||||||
|
@ -4798,13 +4782,7 @@ void WINAPI DOSVM_Int21Handler( CONTEXT *context )
|
||||||
*/
|
*/
|
||||||
|
|
||||||
RESET_CFLAG(context); /* set if error */
|
RESET_CFLAG(context); /* set if error */
|
||||||
if (!DOSVM_IsWin16() && BX_reg(context) == 0)
|
if (ReadFile( DosFileHandleToWin32Handle(BX_reg(context)), buffer, count, &result, NULL ))
|
||||||
{
|
|
||||||
result = INT21_BufferedInput( context, buffer, count );
|
|
||||||
SET_AX( context, (WORD)result );
|
|
||||||
}
|
|
||||||
else if (ReadFile( DosFileHandleToWin32Handle(BX_reg(context)),
|
|
||||||
buffer, count, &result, NULL ))
|
|
||||||
SET_AX( context, (WORD)result );
|
SET_AX( context, (WORD)result );
|
||||||
else
|
else
|
||||||
bSetDOSExtendedError = TRUE;
|
bSetDOSExtendedError = TRUE;
|
||||||
|
@ -4817,27 +4795,14 @@ void WINAPI DOSVM_Int21Handler( CONTEXT *context )
|
||||||
BX_reg(context), CX_reg(context) );
|
BX_reg(context), CX_reg(context) );
|
||||||
{
|
{
|
||||||
char *ptr = CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
|
char *ptr = CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
|
||||||
|
HFILE handle = (HFILE)DosFileHandleToWin32Handle(BX_reg(context));
|
||||||
if (!DOSVM_IsWin16() &&
|
LONG result = _hwrite( handle, ptr, CX_reg(context) );
|
||||||
(BX_reg(context) == 1 || BX_reg(context) == 2))
|
if (result == HFILE_ERROR)
|
||||||
{
|
bSetDOSExtendedError = TRUE;
|
||||||
int i;
|
|
||||||
for(i=0; i<CX_reg(context); i++)
|
|
||||||
DOSVM_PutChar(ptr[i]);
|
|
||||||
SET_AX(context, CX_reg(context));
|
|
||||||
RESET_CFLAG(context);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
HFILE handle = (HFILE)DosFileHandleToWin32Handle(BX_reg(context));
|
SET_AX( context, (WORD)result );
|
||||||
LONG result = _hwrite( handle, ptr, CX_reg(context) );
|
RESET_CFLAG(context);
|
||||||
if (result == HFILE_ERROR)
|
|
||||||
bSetDOSExtendedError = TRUE;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
SET_AX( context, (WORD)result );
|
|
||||||
RESET_CFLAG(context);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -4938,7 +4903,7 @@ void WINAPI DOSVM_Int21Handler( CONTEXT *context )
|
||||||
WORD selector = 0;
|
WORD selector = 0;
|
||||||
DWORD bytes = (DWORD)BX_reg(context) << 4;
|
DWORD bytes = (DWORD)BX_reg(context) << 4;
|
||||||
|
|
||||||
if (!ISV86(context) && DOSVM_IsWin16())
|
if (!ISV86(context))
|
||||||
{
|
{
|
||||||
DWORD rv = GlobalDOSAlloc16( bytes );
|
DWORD rv = GlobalDOSAlloc16( bytes );
|
||||||
selector = LOWORD( rv );
|
selector = LOWORD( rv );
|
||||||
|
@ -4965,7 +4930,7 @@ void WINAPI DOSVM_Int21Handler( CONTEXT *context )
|
||||||
{
|
{
|
||||||
BOOL ok;
|
BOOL ok;
|
||||||
|
|
||||||
if (!ISV86(context) && DOSVM_IsWin16())
|
if (!ISV86(context))
|
||||||
{
|
{
|
||||||
ok = !GlobalDOSFree16( context->SegEs );
|
ok = !GlobalDOSFree16( context->SegEs );
|
||||||
|
|
||||||
|
@ -4991,7 +4956,7 @@ void WINAPI DOSVM_Int21Handler( CONTEXT *context )
|
||||||
{
|
{
|
||||||
DWORD newsize = (DWORD)BX_reg(context) << 4;
|
DWORD newsize = (DWORD)BX_reg(context) << 4;
|
||||||
|
|
||||||
if (!ISV86(context) && DOSVM_IsWin16())
|
if (!ISV86(context))
|
||||||
{
|
{
|
||||||
FIXME( "Resize memory block - unsupported under Win16\n" );
|
FIXME( "Resize memory block - unsupported under Win16\n" );
|
||||||
SET_CFLAG(context);
|
SET_CFLAG(context);
|
||||||
|
@ -5020,42 +4985,23 @@ void WINAPI DOSVM_Int21Handler( CONTEXT *context )
|
||||||
case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
|
case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
|
||||||
{
|
{
|
||||||
char *program = CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
|
char *program = CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
|
||||||
BYTE *paramblk = CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Ebx);
|
HINSTANCE16 instance;
|
||||||
|
|
||||||
TRACE( "EXEC %s\n", program );
|
TRACE( "EXEC %s\n", program );
|
||||||
|
|
||||||
RESET_CFLAG(context);
|
RESET_CFLAG(context);
|
||||||
if (DOSVM_IsWin16())
|
instance = WinExec16( program, SW_NORMAL );
|
||||||
|
if (instance < 32)
|
||||||
{
|
{
|
||||||
HINSTANCE16 instance = WinExec16( program, SW_NORMAL );
|
SET_CFLAG( context );
|
||||||
if (instance < 32)
|
SET_AX( context, instance );
|
||||||
{
|
|
||||||
SET_CFLAG( context );
|
|
||||||
SET_AX( context, instance );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!MZ_Exec( context, program, AL_reg(context), paramblk))
|
|
||||||
bSetDOSExtendedError = TRUE;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
|
case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
|
||||||
TRACE( "EXIT with return code %d\n", AL_reg(context) );
|
TRACE( "EXIT with return code %d\n", AL_reg(context) );
|
||||||
if (DOSVM_IsWin16())
|
DOSVM_Exit( AL_reg(context) );
|
||||||
DOSVM_Exit( AL_reg(context) );
|
|
||||||
else if(ISV86(context))
|
|
||||||
MZ_Exit( context, FALSE, AL_reg(context) );
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* Exit from DPMI.
|
|
||||||
*/
|
|
||||||
ULONG_PTR rv = AL_reg(context);
|
|
||||||
RaiseException( EXCEPTION_VM86_INTx, 0, 1, &rv );
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x4d: /* GET RETURN CODE */
|
case 0x4d: /* GET RETURN CODE */
|
||||||
|
@ -5092,7 +5038,7 @@ void WINAPI DOSVM_Int21Handler( CONTEXT *context )
|
||||||
|
|
||||||
case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
|
case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
|
||||||
{
|
{
|
||||||
SEGPTR ptr = DOSDEV_GetLOL( ISV86(context) || !DOSVM_IsWin16() );
|
SEGPTR ptr = DOSDEV_GetLOL( ISV86(context) );
|
||||||
context->SegEs = SELECTOROF(ptr);
|
context->SegEs = SELECTOROF(ptr);
|
||||||
SET_BX( context, OFFSETOF(ptr) );
|
SET_BX( context, OFFSETOF(ptr) );
|
||||||
}
|
}
|
||||||
|
|
|
@ -482,11 +482,10 @@ callrmproc_again:
|
||||||
while (CurrRMCB && (HIWORD(CurrRMCB->address) != context->SegCs))
|
while (CurrRMCB && (HIWORD(CurrRMCB->address) != context->SegCs))
|
||||||
CurrRMCB = CurrRMCB->next;
|
CurrRMCB = CurrRMCB->next;
|
||||||
|
|
||||||
if (!CurrRMCB && !MZ_Current())
|
if (!CurrRMCB)
|
||||||
{
|
{
|
||||||
FIXME("DPMI real-mode call using DOS VM task system, not fully tested!\n");
|
FIXME("DPMI real-mode call using DOS VM task system, not fully tested!\n");
|
||||||
TRACE("creating VM86 task\n");
|
return 0;
|
||||||
MZ_AllocDPMITask();
|
|
||||||
}
|
}
|
||||||
if (!already) {
|
if (!already) {
|
||||||
if (!context->SegSs) {
|
if (!context->SegSs) {
|
||||||
|
@ -1069,8 +1068,7 @@ void WINAPI DOSVM_Int31Handler( CONTEXT *context )
|
||||||
TRACE( "set selector base address (0x%04x,0x%08x)\n", sel, base );
|
TRACE( "set selector base address (0x%04x,0x%08x)\n", sel, base );
|
||||||
|
|
||||||
/* check if Win16 app wants to access lower 64K of DOS memory */
|
/* check if Win16 app wants to access lower 64K of DOS memory */
|
||||||
if (base < 0x10000 && DOSVM_IsWin16())
|
if (base < 0x10000) DOSMEM_MapDosLayout();
|
||||||
DOSMEM_MapDosLayout();
|
|
||||||
|
|
||||||
SetSelectorBase( sel, base );
|
SetSelectorBase( sel, base );
|
||||||
}
|
}
|
||||||
|
|
|
@ -436,70 +436,6 @@ void DOSVM_HardwareInterruptPM( CONTEXT *context, BYTE intnum )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**********************************************************************
|
|
||||||
* DOSVM_EmulateInterruptRM
|
|
||||||
*
|
|
||||||
* Emulate software interrupt in real mode.
|
|
||||||
* Called from VM86 emulation when intXX opcode is executed.
|
|
||||||
*
|
|
||||||
* Either calls directly builtin handler or pushes interrupt frame to
|
|
||||||
* stack and changes instruction pointer to interrupt handler.
|
|
||||||
*
|
|
||||||
* Returns FALSE if this interrupt was caused by return
|
|
||||||
* from real mode wrapper.
|
|
||||||
*/
|
|
||||||
BOOL DOSVM_EmulateInterruptRM( CONTEXT *context, BYTE intnum )
|
|
||||||
{
|
|
||||||
TRACE_(relay)("\1Call DOS int 0x%02x ret=%04x:%08x\n"
|
|
||||||
" eax=%08x ebx=%08x ecx=%08x edx=%08x\n"
|
|
||||||
" esi=%08x edi=%08x ebp=%08x esp=%08x\n"
|
|
||||||
" ds=%04x es=%04x fs=%04x gs=%04x ss=%04x flags=%08x\n",
|
|
||||||
intnum, context->SegCs, context->Eip,
|
|
||||||
context->Eax, context->Ebx, context->Ecx, context->Edx,
|
|
||||||
context->Esi, context->Edi, context->Ebp, context->Esp,
|
|
||||||
context->SegDs, context->SegEs, context->SegFs, context->SegGs,
|
|
||||||
context->SegSs, context->EFlags );
|
|
||||||
|
|
||||||
/* check for our real-mode hooks */
|
|
||||||
if (intnum == 0x31)
|
|
||||||
{
|
|
||||||
/* is this exit from real-mode wrapper */
|
|
||||||
if (context->SegCs == DOSVM_dpmi_segments->wrap_seg)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
if (DOSVM_CheckWrappers( context ))
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* check if the call is from our fake BIOS interrupt stubs */
|
|
||||||
if (context->SegCs==0xf000)
|
|
||||||
{
|
|
||||||
/* Restore original flags stored into the stack by the caller. */
|
|
||||||
WORD *stack = CTX_SEG_OFF_TO_LIN(context,
|
|
||||||
context->SegSs, context->Esp);
|
|
||||||
context->EFlags = (DWORD)MAKELONG( stack[2], HIWORD(context->EFlags) );
|
|
||||||
|
|
||||||
if (intnum != context->Eip / DOSVM_STUB_RM)
|
|
||||||
WARN( "interrupt stub has been modified "
|
|
||||||
"(interrupt is %02x, interrupt stub is %02x)\n",
|
|
||||||
intnum, context->Eip/DOSVM_STUB_RM );
|
|
||||||
|
|
||||||
TRACE( "builtin interrupt %02x has been branched to\n", intnum );
|
|
||||||
|
|
||||||
DOSVM_CallBuiltinHandler( context, intnum );
|
|
||||||
|
|
||||||
/* Real mode stubs use IRET so we must put flags back into stack. */
|
|
||||||
stack[2] = LOWORD(context->EFlags);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DOSVM_HardwareInterruptRM( context, intnum );
|
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**********************************************************************
|
/**********************************************************************
|
||||||
* DOSVM_HardwareInterruptRM
|
* DOSVM_HardwareInterruptRM
|
||||||
*
|
*
|
||||||
|
@ -963,12 +899,7 @@ static void WINAPI DOSVM_Int1aHandler( CONTEXT *context )
|
||||||
*/
|
*/
|
||||||
static void WINAPI DOSVM_Int20Handler( CONTEXT *context )
|
static void WINAPI DOSVM_Int20Handler( CONTEXT *context )
|
||||||
{
|
{
|
||||||
if (DOSVM_IsWin16())
|
DOSVM_Exit( 0 );
|
||||||
DOSVM_Exit( 0 );
|
|
||||||
else if(ISV86(context))
|
|
||||||
MZ_Exit( context, TRUE, 0 );
|
|
||||||
else
|
|
||||||
ERR( "Called from DOS protected mode\n" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -739,7 +739,6 @@
|
||||||
|
|
||||||
# DOS support
|
# DOS support
|
||||||
@ cdecl -arch=win32 __wine_call_int_handler(ptr long)
|
@ cdecl -arch=win32 __wine_call_int_handler(ptr long)
|
||||||
@ cdecl -arch=win32 __wine_load_dos_exe(str str)
|
|
||||||
|
|
||||||
# VxDs
|
# VxDs
|
||||||
@ cdecl -arch=win32 -private __wine_vxd_open(wstr long ptr)
|
@ cdecl -arch=win32 -private __wine_vxd_open(wstr long ptr)
|
||||||
|
|
|
@ -21,137 +21,15 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include "dosexe.h"
|
#include "dosexe.h"
|
||||||
#include "wine/debug.h"
|
|
||||||
#include "wingdi.h"
|
#include "wingdi.h"
|
||||||
#include "winuser.h"
|
#include "winuser.h"
|
||||||
|
|
||||||
WINE_DEFAULT_DEBUG_CHANNEL(int);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* FIXME: Use QueryPerformanceCounter for
|
|
||||||
* more precise GetTimer implementation.
|
|
||||||
* FIXME: Use QueryPerformanceCounter (or GetTimer implementation)
|
|
||||||
* in timer tick routine to compensate for lost ticks.
|
|
||||||
* This should also make it possible to
|
|
||||||
* emulate really fast timers.
|
|
||||||
* FIXME: Support special timer modes in addition to periodic mode.
|
|
||||||
* FIXME: Use timeSetEvent, NtSetEvent or timer thread for more precise
|
|
||||||
* timing.
|
|
||||||
* FIXME: Move Win16 timer emulation code here.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* The PC clocks ticks at 1193180 Hz. */
|
|
||||||
#define TIMER_FREQ 1193180
|
|
||||||
|
|
||||||
/* How many timer IRQs can be pending at any time. */
|
|
||||||
#define TIMER_MAX_PENDING 20
|
|
||||||
|
|
||||||
/* Unique system timer identifier. */
|
|
||||||
static UINT_PTR TIMER_id = 0;
|
|
||||||
|
|
||||||
/* Time when timer IRQ was last queued. */
|
|
||||||
static DWORD TIMER_stamp = 0;
|
|
||||||
|
|
||||||
/* Timer ticks between timer IRQs. */
|
|
||||||
static UINT TIMER_ticks = 0;
|
|
||||||
|
|
||||||
/* Number of pending timer IRQs. */
|
|
||||||
static LONG TIMER_pending = 0;
|
|
||||||
|
|
||||||
/* Number of milliseconds between IRQs. */
|
|
||||||
static DWORD TIMER_millis = 0;
|
|
||||||
|
|
||||||
/***********************************************************************
|
|
||||||
* TIMER_Relay
|
|
||||||
*
|
|
||||||
* Decrement the number of pending IRQs after IRQ handler has been
|
|
||||||
* called. This function will be called even if application has its
|
|
||||||
* own IRQ handler that does not jump to builtin IRQ handler.
|
|
||||||
*/
|
|
||||||
static void TIMER_Relay( CONTEXT *context, void *data )
|
|
||||||
{
|
|
||||||
InterlockedDecrement( &TIMER_pending );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/***********************************************************************
|
|
||||||
* TIMER_TimerProc
|
|
||||||
*/
|
|
||||||
static void CALLBACK TIMER_TimerProc( HWND hwnd,
|
|
||||||
UINT uMsg,
|
|
||||||
UINT_PTR idEvent,
|
|
||||||
DWORD dwTime )
|
|
||||||
{
|
|
||||||
LONG pending = InterlockedIncrement( &TIMER_pending );
|
|
||||||
DWORD delta = (dwTime >= TIMER_stamp) ?
|
|
||||||
(dwTime - TIMER_stamp) : (0xffffffff - (TIMER_stamp - dwTime));
|
|
||||||
|
|
||||||
if (pending >= TIMER_MAX_PENDING)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (delta >= 60000)
|
|
||||||
{
|
|
||||||
ERR( "DOS timer has been stuck for 60 seconds...\n" );
|
|
||||||
TIMER_stamp = dwTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
InterlockedDecrement( &TIMER_pending );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DWORD i;
|
|
||||||
|
|
||||||
/* Calculate the number of valid timer interrupts we can generate */
|
|
||||||
DWORD count = delta / TIMER_millis;
|
|
||||||
|
|
||||||
/* Forward the timestamp with the time used */
|
|
||||||
TIMER_stamp += (count * TIMER_millis);
|
|
||||||
|
|
||||||
/* Generate interrupts */
|
|
||||||
for(i=0;i<count;i++)
|
|
||||||
{
|
|
||||||
DOSVM_QueueEvent( 0, DOS_PRIORITY_REALTIME, TIMER_Relay, NULL );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/***********************************************************************
|
|
||||||
* TIMER_DoSetTimer
|
|
||||||
*/
|
|
||||||
static void WINAPI TIMER_DoSetTimer( ULONG_PTR arg )
|
|
||||||
{
|
|
||||||
INT millis = MulDiv( arg, 1000, TIMER_FREQ );
|
|
||||||
|
|
||||||
/* sanity check - too fast timer */
|
|
||||||
if (millis < 1)
|
|
||||||
millis = 1;
|
|
||||||
|
|
||||||
TRACE_(int)( "setting timer tick delay to %d ms\n", millis );
|
|
||||||
|
|
||||||
if (TIMER_id)
|
|
||||||
KillTimer( NULL, TIMER_id );
|
|
||||||
|
|
||||||
TIMER_id = SetTimer( NULL, 0, millis, TIMER_TimerProc );
|
|
||||||
TIMER_stamp = GetTickCount();
|
|
||||||
TIMER_ticks = arg;
|
|
||||||
|
|
||||||
/* Remember number of milliseconds to wait */
|
|
||||||
TIMER_millis = millis;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* DOSVM_SetTimer
|
* DOSVM_SetTimer
|
||||||
*/
|
*/
|
||||||
void DOSVM_SetTimer( UINT ticks )
|
void DOSVM_SetTimer( UINT ticks )
|
||||||
{
|
{
|
||||||
/* PIT interprets zero as a maximum length delay. */
|
|
||||||
if (ticks == 0)
|
|
||||||
ticks = 0x10000;
|
|
||||||
|
|
||||||
if (!DOSVM_IsWin16())
|
|
||||||
MZ_RunInThread( TIMER_DoSetTimer, ticks );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -764,7 +764,7 @@ static void VGA_SyncWindow( BOOL target_is_fb )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void WINAPI VGA_DoExit(ULONG_PTR arg)
|
static void VGA_DoExit(ULONG_PTR arg)
|
||||||
{
|
{
|
||||||
VGA_DeinstallTimer();
|
VGA_DeinstallTimer();
|
||||||
IDirectDrawSurface_SetPalette(lpddsurf,NULL);
|
IDirectDrawSurface_SetPalette(lpddsurf,NULL);
|
||||||
|
@ -776,10 +776,9 @@ static void WINAPI VGA_DoExit(ULONG_PTR arg)
|
||||||
lpddraw=NULL;
|
lpddraw=NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void WINAPI VGA_DoSetMode(ULONG_PTR arg)
|
static void VGA_DoSetMode( ModeSet *par )
|
||||||
{
|
{
|
||||||
HRESULT res;
|
HRESULT res;
|
||||||
ModeSet *par = (ModeSet *)arg;
|
|
||||||
par->ret = FALSE;
|
par->ret = FALSE;
|
||||||
|
|
||||||
if (lpddraw) VGA_DoExit(0);
|
if (lpddraw) VGA_DoExit(0);
|
||||||
|
@ -950,7 +949,7 @@ static BOOL VGA_SetGraphicMode(WORD mode)
|
||||||
|
|
||||||
par.Depth = (vga_fb_depth < 8) ? 8 : vga_fb_depth;
|
par.Depth = (vga_fb_depth < 8) ? 8 : vga_fb_depth;
|
||||||
|
|
||||||
MZ_RunInThread(VGA_DoSetMode, (ULONG_PTR)&par);
|
VGA_DoSetMode( &par );
|
||||||
return par.ret;
|
return par.ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -995,7 +994,7 @@ BOOL VGA_GetMode(unsigned *Height, unsigned *Width, unsigned *Depth)
|
||||||
|
|
||||||
static void VGA_Exit(void)
|
static void VGA_Exit(void)
|
||||||
{
|
{
|
||||||
if (lpddraw) MZ_RunInThread(VGA_DoExit, 0);
|
if (lpddraw) VGA_DoExit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VGA_SetPalette(PALETTEENTRY*pal,int start,int len)
|
void VGA_SetPalette(PALETTEENTRY*pal,int start,int len)
|
||||||
|
@ -1109,7 +1108,7 @@ int VGA_GetWindowStart(void)
|
||||||
*
|
*
|
||||||
* Callback for VGA_ShowMouse.
|
* Callback for VGA_ShowMouse.
|
||||||
*/
|
*/
|
||||||
static void WINAPI VGA_DoShowMouse( ULONG_PTR show )
|
static void VGA_DoShowMouse( BOOL show )
|
||||||
{
|
{
|
||||||
INT rv;
|
INT rv;
|
||||||
|
|
||||||
|
@ -1130,8 +1129,7 @@ static void WINAPI VGA_DoShowMouse( ULONG_PTR show )
|
||||||
*/
|
*/
|
||||||
void VGA_ShowMouse( BOOL show )
|
void VGA_ShowMouse( BOOL show )
|
||||||
{
|
{
|
||||||
if (lpddraw)
|
if (lpddraw) VGA_DoShowMouse( show );
|
||||||
MZ_RunInThread( VGA_DoShowMouse, (ULONG_PTR)show );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -275,27 +275,6 @@ static DWORD call16_handler( EXCEPTION_RECORD *record, EXCEPTION_REGISTRATION_RE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************
|
|
||||||
* vm86_handler
|
|
||||||
*
|
|
||||||
* Handler for exceptions occurring in vm86 code.
|
|
||||||
*/
|
|
||||||
static DWORD vm86_handler( EXCEPTION_RECORD *record, EXCEPTION_REGISTRATION_RECORD *frame,
|
|
||||||
CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **pdispatcher )
|
|
||||||
{
|
|
||||||
if (record->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND))
|
|
||||||
return ExceptionContinueSearch;
|
|
||||||
|
|
||||||
if (record->ExceptionCode == EXCEPTION_ACCESS_VIOLATION ||
|
|
||||||
record->ExceptionCode == EXCEPTION_PRIV_INSTRUCTION)
|
|
||||||
{
|
|
||||||
return __wine_emulate_instruction( record, context );
|
|
||||||
}
|
|
||||||
|
|
||||||
return ExceptionContinueSearch;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 32-bit WOW routines (in WOW32, but actually forwarded to KERNEL32)
|
* 32-bit WOW routines (in WOW32, but actually forwarded to KERNEL32)
|
||||||
*/
|
*/
|
||||||
|
@ -549,60 +528,41 @@ BOOL WINAPI K32WOWCallback16Ex( DWORD vpfn16, DWORD dwFlags,
|
||||||
SYSLEVEL_CheckNotLevel( 2 );
|
SYSLEVEL_CheckNotLevel( 2 );
|
||||||
}
|
}
|
||||||
|
|
||||||
if (context->EFlags & 0x00020000) /* v86 mode */
|
assert( !(context->EFlags & 0x00020000) ); /* vm86 mode no longer supported */
|
||||||
|
|
||||||
|
/* push return address */
|
||||||
|
if (dwFlags & WCB16_REGS_LONG)
|
||||||
{
|
{
|
||||||
EXCEPTION_REGISTRATION_RECORD frame;
|
stack -= sizeof(DWORD);
|
||||||
frame.Handler = vm86_handler;
|
*((DWORD *)stack) = HIWORD(call16_ret_addr);
|
||||||
errno = 0;
|
stack -= sizeof(DWORD);
|
||||||
__wine_push_frame( &frame );
|
*((DWORD *)stack) = LOWORD(call16_ret_addr);
|
||||||
__wine_enter_vm86( context );
|
cbArgs += 2 * sizeof(DWORD);
|
||||||
__wine_pop_frame( &frame );
|
|
||||||
if (errno != 0) /* enter_vm86 will fail with ENOSYS on x64 kernels */
|
|
||||||
{
|
|
||||||
WARN("__wine_enter_vm86 failed (errno=%d)\n", errno);
|
|
||||||
if (errno == ENOSYS)
|
|
||||||
SetLastError(ERROR_NOT_SUPPORTED);
|
|
||||||
else
|
|
||||||
SetLastError(ERROR_GEN_FAILURE);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* push return address */
|
stack -= sizeof(SEGPTR);
|
||||||
if (dwFlags & WCB16_REGS_LONG)
|
*((SEGPTR *)stack) = call16_ret_addr;
|
||||||
{
|
cbArgs += sizeof(SEGPTR);
|
||||||
stack -= sizeof(DWORD);
|
|
||||||
*((DWORD *)stack) = HIWORD(call16_ret_addr);
|
|
||||||
stack -= sizeof(DWORD);
|
|
||||||
*((DWORD *)stack) = LOWORD(call16_ret_addr);
|
|
||||||
cbArgs += 2 * sizeof(DWORD);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
stack -= sizeof(SEGPTR);
|
|
||||||
*((SEGPTR *)stack) = call16_ret_addr;
|
|
||||||
cbArgs += sizeof(SEGPTR);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Start call by checking for pending events.
|
|
||||||
* Note that wine_call_to_16_regs overwrites context stack
|
|
||||||
* pointer so we may modify it here without a problem.
|
|
||||||
*/
|
|
||||||
if (get_vm86_teb_info()->dpmi_vif)
|
|
||||||
{
|
|
||||||
context->SegSs = wine_get_ds();
|
|
||||||
context->Esp = (DWORD)stack;
|
|
||||||
insert_event_check( context );
|
|
||||||
cbArgs += (DWORD)stack - context->Esp;
|
|
||||||
}
|
|
||||||
|
|
||||||
_EnterWin16Lock();
|
|
||||||
wine_call_to_16_regs( context, cbArgs, call16_handler );
|
|
||||||
_LeaveWin16Lock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Start call by checking for pending events.
|
||||||
|
* Note that wine_call_to_16_regs overwrites context stack
|
||||||
|
* pointer so we may modify it here without a problem.
|
||||||
|
*/
|
||||||
|
if (get_vm86_teb_info()->dpmi_vif)
|
||||||
|
{
|
||||||
|
context->SegSs = wine_get_ds();
|
||||||
|
context->Esp = (DWORD)stack;
|
||||||
|
insert_event_check( context );
|
||||||
|
cbArgs += (DWORD)stack - context->Esp;
|
||||||
|
}
|
||||||
|
|
||||||
|
_EnterWin16Lock();
|
||||||
|
wine_call_to_16_regs( context, cbArgs, call16_handler );
|
||||||
|
_LeaveWin16Lock();
|
||||||
|
|
||||||
if (TRACE_ON(relay))
|
if (TRACE_ON(relay))
|
||||||
{
|
{
|
||||||
TRACE_(relay)( "\1RetFrom16() ss:sp=%04x:%04x ax=%04x bx=%04x cx=%04x dx=%04x bp=%04x sp=%04x\n",
|
TRACE_(relay)( "\1RetFrom16() ss:sp=%04x:%04x ax=%04x bx=%04x cx=%04x dx=%04x bp=%04x sp=%04x\n",
|
||||||
|
|
Loading…
Reference in New Issue