2 * Main initialization code
12 #include "wine/winbase16.h"
13 #include "wine/winuser16.h"
20 #include "multimedia.h"
24 #include "sysmetrics.h"
36 #include "cursoricon.h"
48 #include "cursoricon.h"
49 #include "loadorder.h"
51 int __winelib = 1; /* Winelib run-time flag */
53 /***********************************************************************
54 * Main initialisation routine
56 BOOL MAIN_MainInit(void)
58 /* Set server debug level */
59 /* To fool make_debug: TRACE(server) */
60 CLIENT_SetDebug( TRACE_ON(server) );
62 /* Initialize syslevel handling */
65 /* Initialize signal handling */
66 if (!SIGNAL_Init()) return FALSE;
68 /* Initialize kernel services thread */
69 if (!SERVICE_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 /* Initialize communications */
92 /* Initialize IO-port permissions */
95 /* registry initialisation */
98 /* Read DOS config.sys */
99 if (!DOSCONF_ReadConfig()) return FALSE;
104 /***********************************************************************
105 * KERNEL initialisation routine
107 BOOL WINAPI MAIN_KernelInit(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
109 static BOOL initDone = FALSE;
113 if ( initDone ) return TRUE;
116 /* Initialize special KERNEL entry points */
117 hModule = GetModuleHandle16( "KERNEL" );
122 /* Initialize KERNEL.178 (__WINFLAGS) with the correct flags value */
123 NE_SetEntryPoint( hModule, 178, GetWinFlags16() );
125 /* Initialize KERNEL.454/455 (__FLATCS/__FLATDS) */
126 GET_CS(cs); GET_DS(ds);
127 NE_SetEntryPoint( hModule, 454, cs );
128 NE_SetEntryPoint( hModule, 455, ds );
130 /* Initialize KERNEL.THHOOK */
131 TASK_InstallTHHook((THHOOK *)PTR_SEG_TO_LIN(
132 (SEGPTR)NE_GetEntryPoint( hModule, 332 )));
134 /* Initialize the real-mode selector entry points */
135 #define SET_ENTRY_POINT( num, addr ) \
136 NE_SetEntryPoint( hModule, (num), GLOBAL_CreateBlock( GMEM_FIXED, \
137 DOSMEM_MapDosToLinear(addr), 0x10000, hModule, \
138 FALSE, FALSE, FALSE, NULL ))
140 SET_ENTRY_POINT( 183, 0x00000 ); /* KERNEL.183: __0000H */
141 SET_ENTRY_POINT( 174, 0xa0000 ); /* KERNEL.174: __A000H */
142 SET_ENTRY_POINT( 181, 0xb0000 ); /* KERNEL.181: __B000H */
143 SET_ENTRY_POINT( 182, 0xb8000 ); /* KERNEL.182: __B800H */
144 SET_ENTRY_POINT( 195, 0xc0000 ); /* KERNEL.195: __C000H */
145 SET_ENTRY_POINT( 179, 0xd0000 ); /* KERNEL.179: __D000H */
146 SET_ENTRY_POINT( 190, 0xe0000 ); /* KERNEL.190: __E000H */
147 NE_SetEntryPoint( hModule, 173, DOSMEM_BiosSysSeg ); /* KERNEL.173: __ROMBIOS */
148 NE_SetEntryPoint( hModule, 193, DOSMEM_BiosDataSeg ); /* KERNEL.193: __0040H */
149 NE_SetEntryPoint( hModule, 194, DOSMEM_BiosSysSeg ); /* KERNEL.194: __F000H */
150 #undef SET_ENTRY_POINT
155 /***********************************************************************
156 * GDI initialisation routine
158 BOOL WINAPI MAIN_GdiInit(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
162 if ( GDI_HeapSel ) return TRUE;
164 /* Create GDI heap */
165 pModule = NE_GetPtr( GetModuleHandle16( "GDI" ) );
168 GDI_HeapSel = GlobalHandleToSel16( (NE_SEG_TABLE( pModule ) +
169 pModule->dgroup - 1)->hSeg );
173 GDI_HeapSel = GlobalAlloc16( GMEM_FIXED, GDI_HEAP_SIZE );
174 LocalInit16( GDI_HeapSel, 0, GDI_HEAP_SIZE-1 );
177 if (!TWEAK_Init()) return FALSE;
179 /* GDI initialisation */
180 if(!GDI_Init()) return FALSE;
183 /* PSDRV initialization */
184 if(!PSDRV_Init()) return FALSE;
189 /***********************************************************************
190 * USER initialisation routine
192 BOOL WINAPI MAIN_UserInit(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
197 if ( USER_HeapSel ) return TRUE;
199 /* Create USER heap */
200 pModule = NE_GetPtr( GetModuleHandle16( "USER" ) );
203 USER_HeapSel = GlobalHandleToSel16( (NE_SEG_TABLE( pModule ) +
204 pModule->dgroup - 1)->hSeg );
208 USER_HeapSel = GlobalAlloc16( GMEM_FIXED, 0x10000 );
209 LocalInit16( USER_HeapSel, 0, 0xffff );
212 /* Global atom table initialisation */
213 if (!ATOM_Init( USER_HeapSel )) return FALSE;
215 /* Initialize system colors and metrics*/
219 /* Create the DCEs */
222 /* Initialize timers */
223 if (!TIMER_Init()) return FALSE;
225 /* Initialize window procedures */
226 if (!WINPROC_Init()) return FALSE;
228 /* Initialize built-in window classes */
229 if (!WIDGETS_Init()) return FALSE;
231 /* Initialize dialog manager */
232 if (!DIALOG_Init()) return FALSE;
234 /* Initialize menus */
235 if (!MENU_Init()) return FALSE;
237 /* Initialize cursor/icons */
240 /* Initialize multimedia */
241 if (!MULTIMEDIA_Init()) return FALSE;
243 /* Initialize message spying */
244 if (!SPY_Init()) return FALSE;
246 /* Check wine.conf for old/bad entries */
247 if (!TWEAK_CheckConfiguration()) return FALSE;
249 /* Create system message queue */
250 queueSize = GetProfileIntA( "windows", "TypeAhead", 120 );
251 if (!QUEUE_CreateSysMsgQueue( queueSize )) return FALSE;
253 /* Set double click time */
254 SetDoubleClickTime( GetProfileIntA("windows","DoubleClickSpeed",452) );
256 /* Create task message queue for the initial task */
257 queueSize = GetProfileIntA( "windows", "DefaultQueueSize", 8 );
258 if (!SetMessageQueue( queueSize )) return FALSE;
260 /* Create desktop window */
261 if (!WIN_CreateDesktopWindow()) return FALSE;
263 /* Initialize keyboard driver */
264 KEYBOARD_Enable( keybd_event, InputKeyStateTable );
266 /* Initialize mouse driver */
267 MOUSE_Enable( mouse_event );
273 /***********************************************************************
274 * Winelib initialisation routine
276 HINSTANCE MAIN_WinelibInit( int *argc, char *argv[] )
283 /* Create the initial process */
284 if (!PROCESS_Init()) return 0;
286 /* Parse command line arguments */
287 MAIN_WineInit( argc, argv );
289 /* Main initialization */
290 if (!MAIN_MainInit()) return 0;
292 /* Initialize KERNEL */
293 if (!MAIN_KernelInit(0, 0, NULL)) return 0;
295 /* Create and switch to initial task */
296 if (!(wm = ELF_CreateDummyModule( argv[0], argv[0] )))
298 PROCESS_Current()->exe_modref = wm;
300 strcpy( ofs.szPathName, wm->modname );
301 if ((hModule = MODULE_CreateDummyModule( &ofs, NULL )) < 32) return 0;
302 pModule = (NE_MODULE *)GlobalLock16( hModule );
303 pModule->flags = NE_FFLAGS_WIN32;
304 pModule->module32 = wm->module;
306 if (!TASK_Create( THREAD_Current(), pModule, 0, 0, FALSE )) return 0;
307 TASK_StartTask( PROCESS_Current()->task );
309 /* Initialize GDI and USER */
310 if (!MAIN_GdiInit(0, 0, NULL)) return 0;
311 if (!MAIN_UserInit(0, 0, NULL)) return 0;