2 * Main initialization code
15 #include "wine/winbase16.h"
16 #include "wine/winuser16.h"
26 #include "sysmetrics.h"
39 #include "cursoricon.h"
48 #include "selectors.h"
51 #include "debugtools.h"
56 #include "loadorder.h"
58 DEFAULT_DEBUG_CHANNEL(server
)
60 /***********************************************************************
61 * Main initialisation routine
63 BOOL
MAIN_MainInit( int argc
, char *argv
[], BOOL win32
)
65 /* store the program name */
68 /* Create the initial process */
69 if (!PROCESS_Init( win32
)) return 0;
71 /* Initialize syslevel handling */
74 /* Parse command line arguments */
75 MAIN_WineInit( argc
, argv
);
77 /* Load the configuration file */
78 if (!PROFILE_LoadWineIni()) return FALSE
;
80 /* Initialise DOS drives */
81 if (!DRIVE_Init()) return FALSE
;
83 /* Initialise DOS directories */
84 if (!DIR_Init()) return FALSE
;
86 /* Registry initialisation */
89 /* Global boot finished, the rest is process-local */
90 CLIENT_BootDone( TRACE_ON(server
) );
92 /* Initialize module loadorder */
93 if (!MODULE_InitLoadOrder()) return FALSE
;
95 /* Initialize DOS memory */
96 if (!DOSMEM_Init(0)) return FALSE
;
98 /* Initialize communications */
101 /* Initialize IO-port permissions */
104 /* Read DOS config.sys */
105 if (!DOSCONF_ReadConfig()) return FALSE
;
107 /* Initialize KERNEL */
108 if (!LoadLibrary16( "KRNL386.EXE" )) return FALSE
;
109 if (!LoadLibraryA( "KERNEL32" )) return FALSE
;
111 if (!LoadLibraryA( "x11drv" )) return FALSE
;
113 /* Initialize event handling */
114 if (!EVENT_Init()) return FALSE
;
116 SHELL_InitRegistrySaving();
121 /***********************************************************************
122 * KERNEL initialisation routine
124 BOOL WINAPI
MAIN_KernelInit(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
126 static BOOL initDone
= FALSE
;
130 if ( initDone
) return TRUE
;
133 /* Initialize special KERNEL entry points */
134 hModule
= GetModuleHandle16( "KERNEL" );
137 /* Initialize KERNEL.178 (__WINFLAGS) with the correct flags value */
138 NE_SetEntryPoint( hModule
, 178, GetWinFlags16() );
140 /* Initialize KERNEL.454/455 (__FLATCS/__FLATDS) */
141 NE_SetEntryPoint( hModule
, 454, __get_cs() );
142 NE_SetEntryPoint( hModule
, 455, __get_ds() );
144 /* Initialize KERNEL.THHOOK */
145 TASK_InstallTHHook((THHOOK
*)PTR_SEG_TO_LIN(
146 (SEGPTR
)NE_GetEntryPoint( hModule
, 332 )));
148 /* Initialize the real-mode selector entry points */
149 #define SET_ENTRY_POINT( num, addr ) \
150 NE_SetEntryPoint( hModule, (num), GLOBAL_CreateBlock( GMEM_FIXED, \
151 DOSMEM_MapDosToLinear(addr), 0x10000, hModule, \
152 FALSE, FALSE, FALSE, NULL ))
154 SET_ENTRY_POINT( 183, 0x00000 ); /* KERNEL.183: __0000H */
155 SET_ENTRY_POINT( 174, 0xa0000 ); /* KERNEL.174: __A000H */
156 SET_ENTRY_POINT( 181, 0xb0000 ); /* KERNEL.181: __B000H */
157 SET_ENTRY_POINT( 182, 0xb8000 ); /* KERNEL.182: __B800H */
158 SET_ENTRY_POINT( 195, 0xc0000 ); /* KERNEL.195: __C000H */
159 SET_ENTRY_POINT( 179, 0xd0000 ); /* KERNEL.179: __D000H */
160 SET_ENTRY_POINT( 190, 0xe0000 ); /* KERNEL.190: __E000H */
161 NE_SetEntryPoint( hModule
, 173, DOSMEM_BiosSysSeg
); /* KERNEL.173: __ROMBIOS */
162 NE_SetEntryPoint( hModule
, 193, DOSMEM_BiosDataSeg
); /* KERNEL.193: __0040H */
163 NE_SetEntryPoint( hModule
, 194, DOSMEM_BiosSysSeg
); /* KERNEL.194: __F000H */
164 #undef SET_ENTRY_POINT
167 /* Initialize relay code */
168 if (!RELAY_Init()) return FALSE
;
174 /***********************************************************************
175 * Winelib initialisation routine
177 HINSTANCE
MAIN_WinelibInit( int *argc
, char *argv
[] )
183 /* Main initialization */
184 if (!MAIN_MainInit( *argc
, argv
, TRUE
)) return 0;
185 *argc
= Options
.argc
;
187 /* Load WineLib EXE module */
188 if ( (hModule
= BUILTIN32_LoadExeModule()) < 32 ) return 0;
189 pModule
= (NE_MODULE
*)GlobalLock16( hModule
);
191 /* Create initial task */
192 if (!TASK_Create( pModule
, FALSE
)) return 0;
194 /* Create 32-bit MODREF */
195 if ( !PE_CreateModule( pModule
->module32
, NE_MODULE_NAME(pModule
), 0, FALSE
) )
198 /* Increment EXE refcount */
199 curr
= PROCESS_Current();
200 assert( curr
->exe_modref
);
201 curr
->exe_modref
->refCount
++;
203 /* Load system DLLs into the initial process (and initialize them) */
204 if ( !LoadLibrary16("GDI.EXE" ) || !LoadLibraryA("GDI32.DLL" )
205 || !LoadLibrary16("USER.EXE") || !LoadLibraryA("USER32.DLL"))
208 /* attach the imported DLLs */
209 if ( !MODULE_DllProcessAttach( curr
->exe_modref
, NULL
) )
212 /* Get pointers to USER routines called by KERNEL */
215 return pModule
->module32
;
218 /***********************************************************************
219 * ExitKernel16 (KERNEL.2)
221 * Clean-up everything and exit the Wine process.
224 void WINAPI
ExitKernel16( void )
226 /* Do the clean-up stuff */
228 WriteOutProfiles16();
229 SHELL_SaveRegistry();
231 TerminateProcess( GetCurrentProcess(), 0 );