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 /* Create the initial process */
62 if (!PROCESS_Init()) return 0;
64 /* Initialize syslevel handling */
67 /* Parse command line arguments */
68 MAIN_WineInit( argc
, argv
);
70 /* Set server debug level */
71 CLIENT_SetDebug( TRACE_ON(server
) );
73 /* Load the configuration file */
74 if (!PROFILE_LoadWineIni()) return FALSE
;
76 /* Initialize module loadorder */
77 if (!MODULE_InitLoadOrder()) return FALSE
;
79 /* Initialize DOS memory */
80 if (!DOSMEM_Init(0)) return FALSE
;
82 /* Initialise DOS drives */
83 if (!DRIVE_Init()) return FALSE
;
85 /* Initialise DOS directories */
86 if (!DIR_Init()) return FALSE
;
88 /* Initialize event handling */
89 if (!EVENT_Init()) return FALSE
;
91 /* Initialize communications */
94 /* Initialize IO-port permissions */
97 /* registry initialisation */
100 /* Read DOS config.sys */
101 if (!DOSCONF_ReadConfig()) return FALSE
;
103 /* Initialize KERNEL */
104 if (!LoadLibrary16( "KRNL386.EXE" )) return FALSE
;
105 if (!LoadLibraryA( "KERNEL32" )) return FALSE
;
110 /***********************************************************************
111 * KERNEL initialisation routine
113 BOOL WINAPI
MAIN_KernelInit(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
115 static BOOL initDone
= FALSE
;
119 if ( initDone
) return TRUE
;
122 /* Initialize special KERNEL entry points */
123 hModule
= GetModuleHandle16( "KERNEL" );
128 /* Initialize KERNEL.178 (__WINFLAGS) with the correct flags value */
129 NE_SetEntryPoint( hModule
, 178, GetWinFlags16() );
131 /* Initialize KERNEL.454/455 (__FLATCS/__FLATDS) */
132 GET_CS(cs
); GET_DS(ds
);
133 NE_SetEntryPoint( hModule
, 454, cs
);
134 NE_SetEntryPoint( hModule
, 455, ds
);
136 /* Initialize KERNEL.THHOOK */
137 TASK_InstallTHHook((THHOOK
*)PTR_SEG_TO_LIN(
138 (SEGPTR
)NE_GetEntryPoint( hModule
, 332 )));
140 /* Initialize the real-mode selector entry points */
141 #define SET_ENTRY_POINT( num, addr ) \
142 NE_SetEntryPoint( hModule, (num), GLOBAL_CreateBlock( GMEM_FIXED, \
143 DOSMEM_MapDosToLinear(addr), 0x10000, hModule, \
144 FALSE, FALSE, FALSE, NULL ))
146 SET_ENTRY_POINT( 183, 0x00000 ); /* KERNEL.183: __0000H */
147 SET_ENTRY_POINT( 174, 0xa0000 ); /* KERNEL.174: __A000H */
148 SET_ENTRY_POINT( 181, 0xb0000 ); /* KERNEL.181: __B000H */
149 SET_ENTRY_POINT( 182, 0xb8000 ); /* KERNEL.182: __B800H */
150 SET_ENTRY_POINT( 195, 0xc0000 ); /* KERNEL.195: __C000H */
151 SET_ENTRY_POINT( 179, 0xd0000 ); /* KERNEL.179: __D000H */
152 SET_ENTRY_POINT( 190, 0xe0000 ); /* KERNEL.190: __E000H */
153 NE_SetEntryPoint( hModule
, 173, DOSMEM_BiosSysSeg
); /* KERNEL.173: __ROMBIOS */
154 NE_SetEntryPoint( hModule
, 193, DOSMEM_BiosDataSeg
); /* KERNEL.193: __0040H */
155 NE_SetEntryPoint( hModule
, 194, DOSMEM_BiosSysSeg
); /* KERNEL.194: __F000H */
156 #undef SET_ENTRY_POINT
159 /* Initialize relay code */
160 if (!RELAY_Init()) return FALSE
;
165 /***********************************************************************
166 * GDI initialisation routine
168 BOOL WINAPI
MAIN_GdiInit(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
172 if ( GDI_HeapSel
) return TRUE
;
174 /* Create GDI heap */
175 pModule
= NE_GetPtr( GetModuleHandle16( "GDI" ) );
178 GDI_HeapSel
= GlobalHandleToSel16( (NE_SEG_TABLE( pModule
) +
179 pModule
->dgroup
- 1)->hSeg
);
183 GDI_HeapSel
= GlobalAlloc16( GMEM_FIXED
, GDI_HEAP_SIZE
);
184 LocalInit16( GDI_HeapSel
, 0, GDI_HEAP_SIZE
-1 );
187 if (!TWEAK_Init()) return FALSE
;
189 /* GDI initialisation */
190 if(!GDI_Init()) return FALSE
;
192 /* Create the Win16 printer driver */
193 if (!WIN16DRV_Init()) return FALSE
;
195 /* PSDRV initialization */
196 if(!PSDRV_Init()) return FALSE
;
201 /***********************************************************************
202 * USER initialisation routine
204 BOOL WINAPI
MAIN_UserInit(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
209 if ( USER_HeapSel
) return TRUE
;
211 /* Create USER heap */
212 pModule
= NE_GetPtr( GetModuleHandle16( "USER" ) );
215 USER_HeapSel
= GlobalHandleToSel16( (NE_SEG_TABLE( pModule
) +
216 pModule
->dgroup
- 1)->hSeg
);
220 USER_HeapSel
= GlobalAlloc16( GMEM_FIXED
, 0x10000 );
221 LocalInit16( USER_HeapSel
, 0, 0xffff );
224 /* Global atom table initialisation */
225 if (!ATOM_Init( USER_HeapSel
)) return FALSE
;
227 /* Initialize window handling (critical section) */
230 /* Initialize system colors and metrics*/
234 /* Create the DCEs */
237 /* Initialize timers */
238 if (!TIMER_Init()) return FALSE
;
240 /* Initialize window procedures */
241 if (!WINPROC_Init()) return FALSE
;
243 /* Initialize cursor/icons */
246 /* Initialize built-in window classes */
247 if (!WIDGETS_Init()) return FALSE
;
249 /* Initialize dialog manager */
250 if (!DIALOG_Init()) return FALSE
;
252 /* Initialize menus */
253 if (!MENU_Init()) return FALSE
;
255 /* Initialize message spying */
256 if (!SPY_Init()) return FALSE
;
258 /* Check wine.conf for old/bad entries */
259 if (!TWEAK_CheckConfiguration()) return FALSE
;
261 /* Create system message queue */
262 queueSize
= GetProfileIntA( "windows", "TypeAhead", 120 );
263 if (!QUEUE_CreateSysMsgQueue( queueSize
)) return FALSE
;
265 /* Set double click time */
266 SetDoubleClickTime( GetProfileIntA("windows","DoubleClickSpeed",452) );
268 /* Create message queue of initial thread */
269 InitThreadInput16( 0, 0 );
271 /* Create desktop window */
272 if (!WIN_CreateDesktopWindow()) return FALSE
;
274 /* Initialize keyboard driver */
275 KEYBOARD_Enable( keybd_event
, InputKeyStateTable
);
277 /* Initialize mouse driver */
278 MOUSE_Enable( mouse_event
);
280 /* Start processing X events */
281 UserRepaintDisable16( FALSE
);
287 /***********************************************************************
288 * Winelib initialisation routine
290 HINSTANCE
MAIN_WinelibInit( int *argc
, char *argv
[] )
297 /* Main initialization */
298 if (!MAIN_MainInit( argc
, argv
)) return 0;
300 /* Create and switch to initial task */
301 if (!(wm
= ELF_CreateDummyModule( argv
[0], argv
[0] )))
303 PROCESS_Current()->exe_modref
= wm
;
305 strcpy( ofs
.szPathName
, wm
->modname
);
306 if ((hModule
= MODULE_CreateDummyModule( &ofs
, NULL
, 0 )) < 32) return 0;
307 pModule
= (NE_MODULE
*)GlobalLock16( hModule
);
308 pModule
->flags
= NE_FFLAGS_WIN32
;
309 pModule
->module32
= wm
->module
;
311 if (!TASK_Create( pModule
, FALSE
)) return 0;
313 /* Load system DLLs into the initial process (and initialize them) */
314 if ( !LoadLibrary16("GDI.EXE" ) || !LoadLibraryA("GDI32.DLL" )
315 || !LoadLibrary16("USER.EXE") || !LoadLibraryA("USER32.DLL"))
318 /* Get pointers to USER routines called by KERNEL */
324 /***********************************************************************
325 * ExitKernel16 (KERNEL.2)
327 * Clean-up everything and exit the Wine process.
330 void WINAPI
ExitKernel16( void )
332 /* Do the clean-up stuff */
334 WriteOutProfiles16();
335 SHELL_SaveRegistry();
337 TerminateProcess( GetCurrentProcess(), 0 );