Setup the initial thread %fs from a constructor.
[wine.git] / miscemu / main.c
blobf4550c44e0919df432897dce8bc291d1f9c8c694
1 /*
2 * Emulator initialisation code
4 */
6 #include <stdlib.h>
7 #include <assert.h>
8 #include "wine/winbase16.h"
9 #include "callback.h"
10 #include "main.h"
11 #include "miscemu.h"
12 #include "module.h"
13 #include "options.h"
14 #include "process.h"
15 #include "thread.h"
16 #include "task.h"
17 #include "stackframe.h"
18 #include "wine/exception.h"
19 #include "debugtools.h"
21 static BOOL exec_program( LPCSTR cmdline )
23 HINSTANCE handle = WinExec( cmdline, SW_SHOWNORMAL );
24 if (handle < 32)
26 MESSAGE( "%s: can't exec '%s': ", argv0, cmdline );
27 switch (handle)
29 case 2: MESSAGE("file not found\n" ); break;
30 case 11: MESSAGE("invalid exe file\n" ); break;
31 default: MESSAGE("error=%d\n", handle ); break;
34 return (handle >= 32);
37 /***********************************************************************
38 * Main loop of initial task
40 void MAIN_EmulatorRun( void )
42 char startProg[256], defProg[256];
43 int i, tasks = 0;
44 MSG msg;
45 char szGraphicsDriver[MAX_PATH];
47 if (PROFILE_GetWineIniString( "Wine", "GraphicsDriver",
48 "x11drv", szGraphicsDriver, sizeof(szGraphicsDriver)))
50 if (!LoadLibraryA( szGraphicsDriver )) ExitProcess(1);
53 /* Load system DLLs into the initial process (and initialize them) */
54 if ( !LoadLibrary16("GDI.EXE" ) || !LoadLibraryA("GDI32.DLL" )
55 || !LoadLibrary16("USER.EXE") || !LoadLibraryA("USER32.DLL"))
56 ExitProcess( 1 );
58 /* Get pointers to USER routines called by KERNEL */
59 THUNK_InitCallout();
61 /* Call FinalUserInit routine */
62 Callout.FinalUserInit16();
64 /* Call InitApp for initial task */
65 Callout.InitApp16( MapHModuleLS( 0 ) );
67 /* Add the Startup Program to the run list */
68 PROFILE_GetWineIniString( "programs", "Startup", "",
69 startProg, sizeof(startProg) );
70 if (startProg[0]) tasks += exec_program( startProg );
72 /* Add the Default Program if no program on the command line */
73 if (!Options.argv[1])
75 PROFILE_GetWineIniString( "programs", "Default", "",
76 defProg, sizeof(defProg) );
77 if (defProg[0]) tasks += exec_program( defProg );
78 else if (!tasks && !startProg[0]) OPTIONS_Usage();
80 else
82 /* Load and run executables given on command line */
83 for (i = 1; Options.argv[i]; i++)
85 tasks += exec_program( Options.argv[i] );
88 if (!tasks) ExitProcess( 0 );
90 /* Start message loop for desktop window */
92 while ( GetNumTasks16() > 1 && Callout.GetMessageA( &msg, 0, 0, 0 ) )
94 Callout.TranslateMessage( &msg );
95 Callout.DispatchMessageA( &msg );
98 ExitProcess( 0 );
102 /**********************************************************************
103 * main
105 int main( int argc, char *argv[] )
107 NE_MODULE *pModule;
109 /* Initialize everything */
110 if (!MAIN_MainInit( argc, argv, FALSE )) return 1;
112 if (!THREAD_InitStack( NtCurrentTeb(), 0, TRUE )) return 1;
113 SIGNAL_Init(); /* reinitialize signal stack */
115 /* Initialize KERNEL */
116 if (!LoadLibraryA( "KERNEL32" )) return FALSE;
118 /* Create initial task */
119 if ( !(pModule = NE_GetPtr( GetModuleHandle16( "KERNEL" ) )) ) return 1;
120 if ( !TASK_Create( pModule, FALSE ) ) return 1;
122 /* Switch to initial task */
123 PostEvent16( PROCESS_Current()->task );
124 TASK_Reschedule();
126 /* Switch stacks and jump to MAIN_EmulatorRun */
127 CALL32_Init( &IF1632_CallLargeStack, MAIN_EmulatorRun, NtCurrentTeb()->stack_top );
129 MESSAGE( "main: Should never happen: returned from CALL32_Init()\n" );
130 return 0;