2 * Emulator initialisation code
8 #include "wine/winbase16.h"
19 #include "stackframe.h"
20 #include "wine/exception.h"
21 #include "debugtools.h"
24 static char **MAIN_argv
;
26 extern int (*INSTR_IsRelay
)( const void *addr
);
28 static int is_relay_addr( const void *addr
)
30 extern char CallFrom16_Start
, CallFrom16_End
, CALLTO16_Start
, CALLTO16_End
;
32 return ((((char *)addr
>= &CallFrom16_Start
) &&
33 ((char *)addr
< &CallFrom16_End
)) ||
34 (((char *)addr
>= &CALLTO16_Start
) &&
35 ((char *)addr
< &CALLTO16_End
)));
38 /***********************************************************************
39 * Emulator initialisation
41 BOOL
MAIN_EmulatorInit(void)
43 /* Main initialization */
44 if (!MAIN_MainInit()) return FALSE
;
46 /* Initialize relay code */
47 if (!RELAY_Init()) return FALSE
;
49 /* Create the Win16 printer driver */
50 if (!WIN16DRV_Init()) return FALSE
;
56 /***********************************************************************
57 * Main loop of initial task
59 void MAIN_EmulatorRun( void )
61 extern void THUNK_InitCallout( void );
62 char startProg
[256], defProg
[256];
67 /* Load system DLLs into the initial process (and initialize them) */
68 if ( !LoadLibrary16("GDI.EXE" ) || !LoadLibraryA("GDI32.DLL" )
69 || !LoadLibrary16("USER.EXE") || !LoadLibraryA("USER32.DLL"))
72 /* Get pointers to USER routines called by KERNEL */
75 /* Call InitApp for initial task */
76 Callout
.InitApp16( MapHModuleLS( 0 ) );
78 /* Add the Default Program if no program on the command line */
81 PROFILE_GetWineIniString( "programs", "Default", "",
82 defProg
, sizeof(defProg
) );
83 if (defProg
[0]) MAIN_argv
[MAIN_argc
++] = defProg
;
86 /* Add the Startup Program to the run list */
87 PROFILE_GetWineIniString( "programs", "Startup", "",
88 startProg
, sizeof(startProg
) );
89 if (startProg
[0]) MAIN_argv
[MAIN_argc
++] = startProg
;
91 /* Abort if no executable on command line */
94 MAIN_Usage(MAIN_argv
[0]);
98 /* Load and run executables given on command line */
99 for (i
= 1; i
< MAIN_argc
; i
++)
101 if ((handle
= WinExec( MAIN_argv
[i
], SW_SHOWNORMAL
)) < 32)
103 MESSAGE("wine: can't exec '%s': ", MAIN_argv
[i
]);
106 case 2: MESSAGE("file not found\n" ); break;
107 case 11: MESSAGE("invalid exe file\n" ); break;
108 default: MESSAGE("error=%d\n", handle
); break;
116 MESSAGE("wine: no executable file found.\n" );
120 /* Start message loop for desktop window */
122 while ( GetNumTasks16() > 1 && Callout
.GetMessageA( &msg
, 0, 0, 0 ) )
124 Callout
.TranslateMessage( &msg
);
125 Callout
.DispatchMessageA( &msg
);
132 /**********************************************************************
135 int main( int argc
, char *argv
[] )
138 extern char * DEBUG_argv0
;
140 __winelib
= 0; /* First of all, clear the Winelib flag */
143 * Save this so that the internal debugger can get a hold of it if
146 DEBUG_argv0
= argv
[0];
148 /* Create the initial process */
149 if (!PROCESS_Init()) return FALSE
;
151 /* Parse command-line */
152 if (!MAIN_WineInit( &argc
, argv
)) return 1;
153 MAIN_argc
= argc
; MAIN_argv
= argv
;
155 /* Set up debugger hook */
156 INSTR_IsRelay
= is_relay_addr
;
157 EXC_SetDebugEventHook( wine_debugger
);
160 TASK_AddTaskEntryBreakpoint
= DEBUG_AddTaskEntryBreakpoint
;
162 /* Initialize everything */
163 if (!MAIN_EmulatorInit()) return 1;
165 /* Load kernel modules */
166 if (!LoadLibrary16( "KERNEL" )) return 1;
167 if (!LoadLibraryA( "KERNEL32" )) return 1;
169 /* Create initial task */
170 if ( !(pModule
= NE_GetPtr( GetModuleHandle16( "KERNEL" ) )) ) return 1;
171 if ( !TASK_Create( pModule
, FALSE
) ) return 1;
173 /* Switch to initial task */
174 PostEvent16( PROCESS_Current()->task
);
177 /* Switch stacks and jump to MAIN_EmulatorRun */
178 CALL32_Init( &IF1632_CallLargeStack
, MAIN_EmulatorRun
, NtCurrentTeb()->stack_top
);
180 MESSAGE( "main: Should never happen: returned from CALL32_Init()\n" );