wine/miscemu/main.c
Eric Pouech 527eea99f8 No longer directly accessing debuggee memory.
Execution context (mode, steps...) are now linked to a thread.
Removed some X11 crst hacks.
Rewrote info/walk commands.
Removed direct debugger invocation code (and moved the rest to the new
winedbg.c file).
2000-03-08 16:44:54 +00:00

143 lines
3.7 KiB
C

/*
* Emulator initialisation code
*
*/
#include <stdlib.h>
#include <assert.h>
#include "wine/winbase16.h"
#include "callback.h"
#include "main.h"
#include "miscemu.h"
#include "module.h"
#include "options.h"
#include "process.h"
#include "thread.h"
#include "task.h"
#include "stackframe.h"
#include "wine/exception.h"
#include "debugtools.h"
static int MAIN_argc;
static char **MAIN_argv;
extern void DEBUG_StartDebugger(DWORD);
/***********************************************************************
* Main loop of initial task
*/
void MAIN_EmulatorRun( void )
{
char startProg[256], defProg[256];
int i, tasks = 0;
MSG msg;
BOOL err_msg = FALSE;
/* Load system DLLs into the initial process (and initialize them) */
if ( !LoadLibrary16("GDI.EXE" ) || !LoadLibraryA("GDI32.DLL" )
|| !LoadLibrary16("USER.EXE") || !LoadLibraryA("USER32.DLL"))
ExitProcess( 1 );
/* Get pointers to USER routines called by KERNEL */
THUNK_InitCallout();
/* Call FinalUserInit routine */
Callout.FinalUserInit16();
/* Call InitApp for initial task */
Callout.InitApp16( MapHModuleLS( 0 ) );
/* Add the Default Program if no program on the command line */
if (!MAIN_argv[1])
{
PROFILE_GetWineIniString( "programs", "Default", "",
defProg, sizeof(defProg) );
if (defProg[0]) MAIN_argv[MAIN_argc++] = defProg;
}
/* Add the Startup Program to the run list */
PROFILE_GetWineIniString( "programs", "Startup", "",
startProg, sizeof(startProg) );
if (startProg[0]) MAIN_argv[MAIN_argc++] = startProg;
/* Abort if no executable on command line */
if (MAIN_argc <= 1)
{
MAIN_Usage(MAIN_argv[0]);
ExitProcess( 1 );
}
/* Load and run executables given on command line */
for (i = 1; i < MAIN_argc; i++)
{
PROCESS_INFORMATION info;
STARTUPINFOA startup;
memset(&startup, 0, sizeof(startup));
startup.cb = sizeof(startup);
startup.dwFlags = STARTF_USESHOWWINDOW;
startup.wShowWindow = SW_SHOWNORMAL;
if (!CreateProcessA(NULL, MAIN_argv[i], NULL, NULL, FALSE, 0,
NULL, NULL, &startup, &info)) {
err_msg = TRUE;
MESSAGE("wine: can't exec '%s': ", MAIN_argv[i]);
switch (GetLastError())
{
case 2: MESSAGE("file not found\n" ); break;
case 11: MESSAGE("invalid exe file\n" ); break;
default: MESSAGE("error=%ld\n", GetLastError() ); break;
}
}
else
{
tasks++;
/* hack until wine debugger can be moved to a separate process */
DEBUG_StartDebugger(info.dwProcessId);
}
}
if (!tasks)
{
if (!err_msg) MESSAGE("wine: no executable file found.\n" );
ExitProcess( 0 );
}
/* Start message loop for desktop window */
while ( GetNumTasks16() > 1 && Callout.GetMessageA( &msg, 0, 0, 0 ) )
{
Callout.TranslateMessage( &msg );
Callout.DispatchMessageA( &msg );
}
ExitProcess( 0 );
}
/**********************************************************************
* main
*/
int main( int argc, char *argv[] )
{
NE_MODULE *pModule;
/* Initialize everything */
if (!MAIN_MainInit( &argc, argv, FALSE )) return 1;
MAIN_argc = argc; MAIN_argv = argv;
/* Create initial task */
if ( !(pModule = NE_GetPtr( GetModuleHandle16( "KERNEL" ) )) ) return 1;
if ( !TASK_Create( pModule, FALSE ) ) return 1;
/* Switch to initial task */
PostEvent16( PROCESS_Current()->task );
TASK_Reschedule();
/* Switch stacks and jump to MAIN_EmulatorRun */
CALL32_Init( &IF1632_CallLargeStack, MAIN_EmulatorRun, NtCurrentTeb()->stack_top );
MESSAGE( "main: Should never happen: returned from CALL32_Init()\n" );
return 0;
}