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"
50 #include "cursoricon.h"
51 #include "loadorder.h"
53 DEFAULT_DEBUG_CHANNEL(server)
55 int __winelib = 1; /* Winelib run-time flag */
57 /***********************************************************************
58 * Main initialisation routine
60 BOOL MAIN_MainInit(void)
62 /* Set server debug level */
63 CLIENT_SetDebug( TRACE_ON(server) );
65 /* Initialize syslevel handling */
68 /* Initialize signal handling */
69 if (!SIGNAL_Init()) return FALSE;
71 /* Load the configuration file */
72 if (!PROFILE_LoadWineIni()) return FALSE;
74 /* Initialize module loadorder */
75 if (!MODULE_InitLoadOrder()) return FALSE;
77 /* Initialize DOS memory */
78 if (!DOSMEM_Init(0)) return FALSE;
80 /* Initialise DOS drives */
81 if (!DRIVE_Init()) return FALSE;
83 /* Initialise DOS directories */
84 if (!DIR_Init()) return FALSE;
86 /* Initialize event handling */
87 if (!EVENT_Init()) return FALSE;
89 /* Initialise WINSOCK handling */
90 if (!WINSOCK_Init()) return FALSE;
92 /* Initialize communications */
95 /* Initialize IO-port permissions */
98 /* registry initialisation */
101 /* Read DOS config.sys */
102 if (!DOSCONF_ReadConfig()) return FALSE;
107 /***********************************************************************
108 * KERNEL initialisation routine
110 BOOL WINAPI MAIN_KernelInit(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
112 static BOOL initDone = FALSE;
116 if ( initDone ) return TRUE;
119 /* Initialize special KERNEL entry points */
120 hModule = GetModuleHandle16( "KERNEL" );
125 /* Initialize KERNEL.178 (__WINFLAGS) with the correct flags value */
126 NE_SetEntryPoint( hModule, 178, GetWinFlags16() );
128 /* Initialize KERNEL.454/455 (__FLATCS/__FLATDS) */
129 GET_CS(cs); GET_DS(ds);
130 NE_SetEntryPoint( hModule, 454, cs );
131 NE_SetEntryPoint( hModule, 455, ds );
133 /* Initialize KERNEL.THHOOK */
134 TASK_InstallTHHook((THHOOK *)PTR_SEG_TO_LIN(
135 (SEGPTR)NE_GetEntryPoint( hModule, 332 )));
137 /* Initialize the real-mode selector entry points */
138 #define SET_ENTRY_POINT( num, addr ) \
139 NE_SetEntryPoint( hModule, (num), GLOBAL_CreateBlock( GMEM_FIXED, \
140 DOSMEM_MapDosToLinear(addr), 0x10000, hModule, \
141 FALSE, FALSE, FALSE, NULL ))
143 SET_ENTRY_POINT( 183, 0x00000 ); /* KERNEL.183: __0000H */
144 SET_ENTRY_POINT( 174, 0xa0000 ); /* KERNEL.174: __A000H */
145 SET_ENTRY_POINT( 181, 0xb0000 ); /* KERNEL.181: __B000H */
146 SET_ENTRY_POINT( 182, 0xb8000 ); /* KERNEL.182: __B800H */
147 SET_ENTRY_POINT( 195, 0xc0000 ); /* KERNEL.195: __C000H */
148 SET_ENTRY_POINT( 179, 0xd0000 ); /* KERNEL.179: __D000H */
149 SET_ENTRY_POINT( 190, 0xe0000 ); /* KERNEL.190: __E000H */
150 NE_SetEntryPoint( hModule, 173, DOSMEM_BiosSysSeg ); /* KERNEL.173: __ROMBIOS */
151 NE_SetEntryPoint( hModule, 193, DOSMEM_BiosDataSeg ); /* KERNEL.193: __0040H */
152 NE_SetEntryPoint( hModule, 194, DOSMEM_BiosSysSeg ); /* KERNEL.194: __F000H */
153 #undef SET_ENTRY_POINT
158 /***********************************************************************
159 * GDI initialisation routine
161 BOOL WINAPI MAIN_GdiInit(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
165 if ( GDI_HeapSel ) return TRUE;
167 /* Create GDI heap */
168 pModule = NE_GetPtr( GetModuleHandle16( "GDI" ) );
171 GDI_HeapSel = GlobalHandleToSel16( (NE_SEG_TABLE( pModule ) +
172 pModule->dgroup - 1)->hSeg );
176 GDI_HeapSel = GlobalAlloc16( GMEM_FIXED, GDI_HEAP_SIZE );
177 LocalInit16( GDI_HeapSel, 0, GDI_HEAP_SIZE-1 );
180 if (!TWEAK_Init()) return FALSE;
182 /* GDI initialisation */
183 if(!GDI_Init()) return FALSE;
186 /* PSDRV initialization */
187 if(!PSDRV_Init()) return FALSE;
192 /***********************************************************************
193 * USER initialisation routine
195 BOOL WINAPI MAIN_UserInit(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
200 if ( USER_HeapSel ) return TRUE;
202 /* Create USER heap */
203 pModule = NE_GetPtr( GetModuleHandle16( "USER" ) );
206 USER_HeapSel = GlobalHandleToSel16( (NE_SEG_TABLE( pModule ) +
207 pModule->dgroup - 1)->hSeg );
211 USER_HeapSel = GlobalAlloc16( GMEM_FIXED, 0x10000 );
212 LocalInit16( USER_HeapSel, 0, 0xffff );
215 /* Global atom table initialisation */
216 if (!ATOM_Init( USER_HeapSel )) return FALSE;
218 /* Initialize window handling (critical section) */
221 /* Initialize system colors and metrics*/
225 /* Create the DCEs */
228 /* Initialize timers */
229 if (!TIMER_Init()) return FALSE;
231 /* Initialize window procedures */
232 if (!WINPROC_Init()) return FALSE;
234 /* Initialize built-in window classes */
235 if (!WIDGETS_Init()) return FALSE;
237 /* Initialize dialog manager */
238 if (!DIALOG_Init()) return FALSE;
240 /* Initialize menus */
241 if (!MENU_Init()) return FALSE;
243 /* Initialize cursor/icons */
246 /* Initialize message spying */
247 if (!SPY_Init()) return FALSE;
249 /* Check wine.conf for old/bad entries */
250 if (!TWEAK_CheckConfiguration()) return FALSE;
252 /* Create system message queue */
253 queueSize = GetProfileIntA( "windows", "TypeAhead", 120 );
254 if (!QUEUE_CreateSysMsgQueue( queueSize )) return FALSE;
256 /* Set double click time */
257 SetDoubleClickTime( GetProfileIntA("windows","DoubleClickSpeed",452) );
259 /* Create task message queue for the initial task */
260 queueSize = GetProfileIntA( "windows", "DefaultQueueSize", 8 );
261 if (!SetMessageQueue( queueSize )) return FALSE;
263 /* Create desktop window */
264 if (!WIN_CreateDesktopWindow()) return FALSE;
266 /* Initialize keyboard driver */
267 KEYBOARD_Enable( keybd_event, InputKeyStateTable );
269 /* Initialize mouse driver */
270 MOUSE_Enable( mouse_event );
272 /* Start processing X events */
273 UserRepaintDisable16( FALSE );
279 /***********************************************************************
280 * Winelib initialisation routine
282 HINSTANCE MAIN_WinelibInit( int *argc, char *argv[] )
289 /* Create the initial process */
290 if (!PROCESS_Init()) return 0;
292 /* Parse command line arguments */
293 MAIN_WineInit( argc, argv );
295 /* Main initialization */
296 if (!MAIN_MainInit()) return 0;
298 /* Initialize KERNEL */
299 if (!LoadLibraryA( "KERNEL32" )) return 0;
301 /* Create and switch to initial task */
302 if (!(wm = ELF_CreateDummyModule( argv[0], argv[0] )))
304 PROCESS_Current()->exe_modref = wm;
306 strcpy( ofs.szPathName, wm->modname );
307 if ((hModule = MODULE_CreateDummyModule( &ofs, NULL )) < 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, 0, 0, FALSE )) return 0;
314 /* Initialize GDI and USER */
315 if (!LoadLibraryA( "GDI32.DLL" )) return 0;
316 if (!LoadLibraryA( "USER32.DLL" )) return 0;
321 /***********************************************************************
322 * ExitKernel16 (KERNEL.2)
324 * Clean-up everything and exit the Wine process.
327 void WINAPI ExitKernel16( void )
329 /* Do the clean-up stuff */
331 WriteOutProfiles16();
332 SHELL_SaveRegistry();
334 TerminateProcess( GetCurrentProcess(), 0 );