2 * Main initialization code
13 #include "wine/winbase16.h"
14 #include "wine/winuser16.h"
24 #include "sysmetrics.h"
37 #include "cursoricon.h"
48 #include "debugtools.h"
53 #include "loadorder.h"
55 DEFAULT_DEBUG_CHANNEL(server
)
57 /***********************************************************************
58 * Main initialisation routine
60 BOOL
MAIN_MainInit( int *argc
, char *argv
[], BOOL win32
)
62 /* store the program name */
65 /* Create the initial process */
66 if (!PROCESS_Init( win32
)) return 0;
68 /* Initialize syslevel handling */
71 /* Parse command line arguments */
72 MAIN_WineInit( argc
, argv
);
74 /* Load the configuration file */
75 if (!PROFILE_LoadWineIni()) return FALSE
;
77 /* Initialise DOS drives */
78 if (!DRIVE_Init()) return FALSE
;
80 /* Initialise DOS directories */
81 if (!DIR_Init()) return FALSE
;
83 /* Registry initialisation */
86 /* Global boot finished, the rest is process-local */
87 CLIENT_BootDone( TRACE_ON(server
) );
89 /* Initialize module loadorder */
90 if (!MODULE_InitLoadOrder()) return FALSE
;
92 /* Initialize DOS memory */
93 if (!DOSMEM_Init(0)) return FALSE
;
95 /* Initialize event handling */
96 if (!EVENT_Init()) 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
;
114 /***********************************************************************
115 * KERNEL initialisation routine
117 BOOL WINAPI
MAIN_KernelInit(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
119 static BOOL initDone
= FALSE
;
123 if ( initDone
) return TRUE
;
126 /* Initialize special KERNEL entry points */
127 hModule
= GetModuleHandle16( "KERNEL" );
132 /* Initialize KERNEL.178 (__WINFLAGS) with the correct flags value */
133 NE_SetEntryPoint( hModule
, 178, GetWinFlags16() );
135 /* Initialize KERNEL.454/455 (__FLATCS/__FLATDS) */
136 GET_CS(cs
); GET_DS(ds
);
137 NE_SetEntryPoint( hModule
, 454, cs
);
138 NE_SetEntryPoint( hModule
, 455, ds
);
140 /* Initialize KERNEL.THHOOK */
141 TASK_InstallTHHook((THHOOK
*)PTR_SEG_TO_LIN(
142 (SEGPTR
)NE_GetEntryPoint( hModule
, 332 )));
144 /* Initialize the real-mode selector entry points */
145 #define SET_ENTRY_POINT( num, addr ) \
146 NE_SetEntryPoint( hModule, (num), GLOBAL_CreateBlock( GMEM_FIXED, \
147 DOSMEM_MapDosToLinear(addr), 0x10000, hModule, \
148 FALSE, FALSE, FALSE, NULL ))
150 SET_ENTRY_POINT( 183, 0x00000 ); /* KERNEL.183: __0000H */
151 SET_ENTRY_POINT( 174, 0xa0000 ); /* KERNEL.174: __A000H */
152 SET_ENTRY_POINT( 181, 0xb0000 ); /* KERNEL.181: __B000H */
153 SET_ENTRY_POINT( 182, 0xb8000 ); /* KERNEL.182: __B800H */
154 SET_ENTRY_POINT( 195, 0xc0000 ); /* KERNEL.195: __C000H */
155 SET_ENTRY_POINT( 179, 0xd0000 ); /* KERNEL.179: __D000H */
156 SET_ENTRY_POINT( 190, 0xe0000 ); /* KERNEL.190: __E000H */
157 NE_SetEntryPoint( hModule
, 173, DOSMEM_BiosSysSeg
); /* KERNEL.173: __ROMBIOS */
158 NE_SetEntryPoint( hModule
, 193, DOSMEM_BiosDataSeg
); /* KERNEL.193: __0040H */
159 NE_SetEntryPoint( hModule
, 194, DOSMEM_BiosSysSeg
); /* KERNEL.194: __F000H */
160 #undef SET_ENTRY_POINT
163 /* Initialize relay code */
164 if (!RELAY_Init()) return FALSE
;
169 /***********************************************************************
170 * GDI initialisation routine
172 BOOL WINAPI
MAIN_GdiInit(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
176 if ( GDI_HeapSel
) return TRUE
;
178 /* Create GDI heap */
179 pModule
= NE_GetPtr( GetModuleHandle16( "GDI" ) );
182 GDI_HeapSel
= GlobalHandleToSel16( (NE_SEG_TABLE( pModule
) +
183 pModule
->dgroup
- 1)->hSeg
);
187 GDI_HeapSel
= GlobalAlloc16( GMEM_FIXED
, GDI_HEAP_SIZE
);
188 LocalInit16( GDI_HeapSel
, 0, GDI_HEAP_SIZE
-1 );
191 if (!TWEAK_Init()) return FALSE
;
193 /* GDI initialisation */
194 if(!GDI_Init()) return FALSE
;
196 /* Create the Win16 printer driver */
197 if (!WIN16DRV_Init()) return FALSE
;
199 /* PSDRV initialization */
200 if(!PSDRV_Init()) return FALSE
;
205 /***********************************************************************
206 * USER initialisation routine
208 BOOL WINAPI
MAIN_UserInit(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
213 if ( USER_HeapSel
) return TRUE
;
215 /* Create USER heap */
216 pModule
= NE_GetPtr( GetModuleHandle16( "USER" ) );
219 USER_HeapSel
= GlobalHandleToSel16( (NE_SEG_TABLE( pModule
) +
220 pModule
->dgroup
- 1)->hSeg
);
224 USER_HeapSel
= GlobalAlloc16( GMEM_FIXED
, 0x10000 );
225 LocalInit16( USER_HeapSel
, 0, 0xffff );
228 /* Global atom table initialisation */
229 if (!ATOM_Init( USER_HeapSel
)) return FALSE
;
231 /* Initialize window handling (critical section) */
234 /* Initialize system colors and metrics*/
238 /* Create the DCEs */
241 /* Initialize timers */
242 if (!TIMER_Init()) return FALSE
;
244 /* Initialize window procedures */
245 if (!WINPROC_Init()) return FALSE
;
247 /* Initialize cursor/icons */
250 /* Initialize built-in window classes */
251 if (!WIDGETS_Init()) return FALSE
;
253 /* Initialize dialog manager */
254 if (!DIALOG_Init()) return FALSE
;
256 /* Initialize menus */
257 if (!MENU_Init()) return FALSE
;
259 /* Initialize message spying */
260 if (!SPY_Init()) return FALSE
;
262 /* Check wine.conf for old/bad entries */
263 if (!TWEAK_CheckConfiguration()) return FALSE
;
265 /* Create system message queue */
266 queueSize
= GetProfileIntA( "windows", "TypeAhead", 120 );
267 if (!QUEUE_CreateSysMsgQueue( queueSize
)) return FALSE
;
269 /* Set double click time */
270 SetDoubleClickTime( GetProfileIntA("windows","DoubleClickSpeed",452) );
272 /* Create message queue of initial thread */
273 InitThreadInput16( 0, 0 );
275 /* Create desktop window */
276 if (!WIN_CreateDesktopWindow()) return FALSE
;
278 /* Initialize keyboard driver */
279 KEYBOARD_Enable( keybd_event
, InputKeyStateTable
);
281 /* Initialize mouse driver */
282 MOUSE_Enable( mouse_event
);
284 /* Start processing X events */
285 UserRepaintDisable16( FALSE
);
291 /***********************************************************************
292 * Winelib initialisation routine
294 HINSTANCE
MAIN_WinelibInit( int *argc
, char *argv
[] )
299 /* Main initialization */
300 if (!MAIN_MainInit( argc
, argv
, TRUE
)) return 0;
302 /* Load WineLib EXE module */
303 if ( (hModule
= BUILTIN32_LoadExeModule()) < 32 ) return 0;
304 pModule
= (NE_MODULE
*)GlobalLock16( hModule
);
306 /* Create initial task */
307 if (!TASK_Create( pModule
, FALSE
)) return 0;
309 /* Create 32-bit MODREF */
310 if ( !PE_CreateModule( pModule
->module32
, NE_MODULE_NAME(pModule
), 0, FALSE
) )
313 /* Increment EXE refcount */
314 assert( PROCESS_Current()->exe_modref
);
315 PROCESS_Current()->exe_modref
->refCount
++;
317 /* Load system DLLs into the initial process (and initialize them) */
318 if ( !LoadLibrary16("GDI.EXE" ) || !LoadLibraryA("GDI32.DLL" )
319 || !LoadLibrary16("USER.EXE") || !LoadLibraryA("USER32.DLL"))
322 /* Get pointers to USER routines called by KERNEL */
325 return pModule
->module32
;
328 /***********************************************************************
329 * ExitKernel16 (KERNEL.2)
331 * Clean-up everything and exit the Wine process.
334 void WINAPI
ExitKernel16( void )
336 /* Do the clean-up stuff */
338 WriteOutProfiles16();
339 SHELL_SaveRegistry();
341 TerminateProcess( GetCurrentProcess(), 0 );