2 * Main initialization code
12 #include "wine/winbase16.h"
13 #include "wine/winuser16.h"
23 #include "sysmetrics.h"
36 #include "cursoricon.h"
47 #include "debugtools.h"
52 #include "loadorder.h"
54 DEFAULT_DEBUG_CHANNEL(server
)
56 /***********************************************************************
57 * Main initialisation routine
59 BOOL
MAIN_MainInit( int *argc
, char *argv
[] )
61 /* store the program name */
64 /* Create the initial process */
65 if (!PROCESS_Init()) return 0;
67 /* Initialize syslevel handling */
70 /* Parse command line arguments */
71 MAIN_WineInit( argc
, argv
);
73 /* Load the configuration file */
74 if (!PROFILE_LoadWineIni()) return FALSE
;
76 /* Initialise DOS drives */
77 if (!DRIVE_Init()) return FALSE
;
79 /* Initialise DOS directories */
80 if (!DIR_Init()) return FALSE
;
82 /* Registry initialisation */
85 /* Global boot finished, the rest is process-local */
86 CLIENT_BootDone( TRACE_ON(server
) );
88 /* Initialize module loadorder */
89 if (!MODULE_InitLoadOrder()) return FALSE
;
91 /* Initialize DOS memory */
92 if (!DOSMEM_Init(0)) return FALSE
;
94 /* Initialize event handling */
95 if (!EVENT_Init()) return FALSE
;
97 /* Initialize communications */
100 /* Initialize IO-port permissions */
103 /* Read DOS config.sys */
104 if (!DOSCONF_ReadConfig()) return FALSE
;
106 /* Initialize KERNEL */
107 if (!LoadLibrary16( "KRNL386.EXE" )) return FALSE
;
108 if (!LoadLibraryA( "KERNEL32" )) return FALSE
;
113 /***********************************************************************
114 * KERNEL initialisation routine
116 BOOL WINAPI
MAIN_KernelInit(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
118 static BOOL initDone
= FALSE
;
122 if ( initDone
) return TRUE
;
125 /* Initialize special KERNEL entry points */
126 hModule
= GetModuleHandle16( "KERNEL" );
131 /* Initialize KERNEL.178 (__WINFLAGS) with the correct flags value */
132 NE_SetEntryPoint( hModule
, 178, GetWinFlags16() );
134 /* Initialize KERNEL.454/455 (__FLATCS/__FLATDS) */
135 GET_CS(cs
); GET_DS(ds
);
136 NE_SetEntryPoint( hModule
, 454, cs
);
137 NE_SetEntryPoint( hModule
, 455, ds
);
139 /* Initialize KERNEL.THHOOK */
140 TASK_InstallTHHook((THHOOK
*)PTR_SEG_TO_LIN(
141 (SEGPTR
)NE_GetEntryPoint( hModule
, 332 )));
143 /* Initialize the real-mode selector entry points */
144 #define SET_ENTRY_POINT( num, addr ) \
145 NE_SetEntryPoint( hModule, (num), GLOBAL_CreateBlock( GMEM_FIXED, \
146 DOSMEM_MapDosToLinear(addr), 0x10000, hModule, \
147 FALSE, FALSE, FALSE, NULL ))
149 SET_ENTRY_POINT( 183, 0x00000 ); /* KERNEL.183: __0000H */
150 SET_ENTRY_POINT( 174, 0xa0000 ); /* KERNEL.174: __A000H */
151 SET_ENTRY_POINT( 181, 0xb0000 ); /* KERNEL.181: __B000H */
152 SET_ENTRY_POINT( 182, 0xb8000 ); /* KERNEL.182: __B800H */
153 SET_ENTRY_POINT( 195, 0xc0000 ); /* KERNEL.195: __C000H */
154 SET_ENTRY_POINT( 179, 0xd0000 ); /* KERNEL.179: __D000H */
155 SET_ENTRY_POINT( 190, 0xe0000 ); /* KERNEL.190: __E000H */
156 NE_SetEntryPoint( hModule
, 173, DOSMEM_BiosSysSeg
); /* KERNEL.173: __ROMBIOS */
157 NE_SetEntryPoint( hModule
, 193, DOSMEM_BiosDataSeg
); /* KERNEL.193: __0040H */
158 NE_SetEntryPoint( hModule
, 194, DOSMEM_BiosSysSeg
); /* KERNEL.194: __F000H */
159 #undef SET_ENTRY_POINT
162 /* Initialize relay code */
163 if (!RELAY_Init()) return FALSE
;
168 /***********************************************************************
169 * GDI initialisation routine
171 BOOL WINAPI
MAIN_GdiInit(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
175 if ( GDI_HeapSel
) return TRUE
;
177 /* Create GDI heap */
178 pModule
= NE_GetPtr( GetModuleHandle16( "GDI" ) );
181 GDI_HeapSel
= GlobalHandleToSel16( (NE_SEG_TABLE( pModule
) +
182 pModule
->dgroup
- 1)->hSeg
);
186 GDI_HeapSel
= GlobalAlloc16( GMEM_FIXED
, GDI_HEAP_SIZE
);
187 LocalInit16( GDI_HeapSel
, 0, GDI_HEAP_SIZE
-1 );
190 if (!TWEAK_Init()) return FALSE
;
192 /* GDI initialisation */
193 if(!GDI_Init()) return FALSE
;
195 /* Create the Win16 printer driver */
196 if (!WIN16DRV_Init()) return FALSE
;
198 /* PSDRV initialization */
199 if(!PSDRV_Init()) return FALSE
;
204 /***********************************************************************
205 * USER initialisation routine
207 BOOL WINAPI
MAIN_UserInit(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
212 if ( USER_HeapSel
) return TRUE
;
214 /* Create USER heap */
215 pModule
= NE_GetPtr( GetModuleHandle16( "USER" ) );
218 USER_HeapSel
= GlobalHandleToSel16( (NE_SEG_TABLE( pModule
) +
219 pModule
->dgroup
- 1)->hSeg
);
223 USER_HeapSel
= GlobalAlloc16( GMEM_FIXED
, 0x10000 );
224 LocalInit16( USER_HeapSel
, 0, 0xffff );
227 /* Global atom table initialisation */
228 if (!ATOM_Init( USER_HeapSel
)) return FALSE
;
230 /* Initialize window handling (critical section) */
233 /* Initialize system colors and metrics*/
237 /* Create the DCEs */
240 /* Initialize timers */
241 if (!TIMER_Init()) return FALSE
;
243 /* Initialize window procedures */
244 if (!WINPROC_Init()) return FALSE
;
246 /* Initialize cursor/icons */
249 /* Initialize built-in window classes */
250 if (!WIDGETS_Init()) return FALSE
;
252 /* Initialize dialog manager */
253 if (!DIALOG_Init()) return FALSE
;
255 /* Initialize menus */
256 if (!MENU_Init()) return FALSE
;
258 /* Initialize message spying */
259 if (!SPY_Init()) return FALSE
;
261 /* Check wine.conf for old/bad entries */
262 if (!TWEAK_CheckConfiguration()) return FALSE
;
264 /* Create system message queue */
265 queueSize
= GetProfileIntA( "windows", "TypeAhead", 120 );
266 if (!QUEUE_CreateSysMsgQueue( queueSize
)) return FALSE
;
268 /* Set double click time */
269 SetDoubleClickTime( GetProfileIntA("windows","DoubleClickSpeed",452) );
271 /* Create message queue of initial thread */
272 InitThreadInput16( 0, 0 );
274 /* Create desktop window */
275 if (!WIN_CreateDesktopWindow()) return FALSE
;
277 /* Initialize keyboard driver */
278 KEYBOARD_Enable( keybd_event
, InputKeyStateTable
);
280 /* Initialize mouse driver */
281 MOUSE_Enable( mouse_event
);
283 /* Start processing X events */
284 UserRepaintDisable16( FALSE
);
290 /***********************************************************************
291 * Winelib initialisation routine
293 HINSTANCE
MAIN_WinelibInit( int *argc
, char *argv
[] )
299 /* Main initialization */
300 if (!MAIN_MainInit( argc
, argv
)) return 0;
302 /* Create and switch to initial task */
303 if (!(wm
= ELF_CreateDummyModule( argv
[0], argv
[0] )))
305 PROCESS_Current()->exe_modref
= wm
;
307 if ((hModule
= MODULE_CreateDummyModule( wm
->filename
, 0 )) < 32) return 0;
308 pModule
= (NE_MODULE
*)GlobalLock16( hModule
);
309 pModule
->flags
= NE_FFLAGS_WIN32
;
310 pModule
->module32
= wm
->module
;
312 if (!TASK_Create( pModule
, FALSE
)) return 0;
314 /* Load system DLLs into the initial process (and initialize them) */
315 if ( !LoadLibrary16("GDI.EXE" ) || !LoadLibraryA("GDI32.DLL" )
316 || !LoadLibrary16("USER.EXE") || !LoadLibraryA("USER32.DLL"))
319 /* Get pointers to USER routines called by KERNEL */
325 /***********************************************************************
326 * ExitKernel16 (KERNEL.2)
328 * Clean-up everything and exit the Wine process.
331 void WINAPI
ExitKernel16( void )
333 /* Do the clean-up stuff */
335 WriteOutProfiles16();
336 SHELL_SaveRegistry();
338 TerminateProcess( GetCurrentProcess(), 0 );