2 * Main initialization code
12 #include "wine/winbase16.h"
13 #include "wine/winuser16.h"
20 #include "multimedia.h"
24 #include "sysmetrics.h"
37 #include "cursoricon.h"
49 int __winelib = 1; /* Winelib run-time flag */
51 /***********************************************************************
52 * Main initialisation routine
54 BOOL MAIN_MainInit(void)
56 /* Set server debug level */
57 /* To fool make_debug: TRACE(server) */
58 CLIENT_SetDebug( TRACE_ON(server) );
60 /* Initialize syslevel handling */
63 /* Initialize signal handling */
64 if (!SIGNAL_Init()) return FALSE;
66 /* Load the configuration file */
67 if (!PROFILE_LoadWineIni()) return FALSE;
69 /* Initialize DOS memory */
70 if (!DOSMEM_Init(0)) return FALSE;
72 /* Initialise DOS drives */
73 if (!DRIVE_Init()) return FALSE;
75 /* Initialise DOS directories */
76 if (!DIR_Init()) return FALSE;
78 /* Initialize event handling */
79 if (!EVENT_Init()) return FALSE;
81 /* Initialize communications */
84 /* Initialize IO-port permissions */
87 /* registry initialisation */
90 /* Read DOS config.sys */
91 if (!DOSCONF_ReadConfig()) return FALSE;
96 /***********************************************************************
97 * KERNEL initialisation routine
99 BOOL WINAPI MAIN_KernelInit(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
101 static BOOL initDone = FALSE;
105 if ( initDone ) return TRUE;
108 /* Initialize special KERNEL entry points */
109 hModule = GetModuleHandle16( "KERNEL" );
114 /* Initialize KERNEL.178 (__WINFLAGS) with the correct flags value */
115 NE_SetEntryPoint( hModule, 178, GetWinFlags16() );
117 /* Initialize KERNEL.454/455 (__FLATCS/__FLATDS) */
118 GET_CS(cs); GET_DS(ds);
119 NE_SetEntryPoint( hModule, 454, cs );
120 NE_SetEntryPoint( hModule, 455, ds );
122 /* Initialize KERNEL.THHOOK */
123 TASK_InstallTHHook((THHOOK *)PTR_SEG_TO_LIN(
124 (SEGPTR)NE_GetEntryPoint( hModule, 332 )));
126 /* Initialize the real-mode selector entry points */
127 #define SET_ENTRY_POINT( num, addr ) \
128 NE_SetEntryPoint( hModule, (num), GLOBAL_CreateBlock( GMEM_FIXED, \
129 DOSMEM_MapDosToLinear(addr), 0x10000, hModule, \
130 FALSE, FALSE, FALSE, NULL ))
132 SET_ENTRY_POINT( 183, 0x00000 ); /* KERNEL.183: __0000H */
133 SET_ENTRY_POINT( 174, 0xa0000 ); /* KERNEL.174: __A000H */
134 SET_ENTRY_POINT( 181, 0xb0000 ); /* KERNEL.181: __B000H */
135 SET_ENTRY_POINT( 182, 0xb8000 ); /* KERNEL.182: __B800H */
136 SET_ENTRY_POINT( 195, 0xc0000 ); /* KERNEL.195: __C000H */
137 SET_ENTRY_POINT( 179, 0xd0000 ); /* KERNEL.179: __D000H */
138 SET_ENTRY_POINT( 190, 0xe0000 ); /* KERNEL.190: __E000H */
139 NE_SetEntryPoint( hModule, 173, DOSMEM_BiosSysSeg ); /* KERNEL.173: __ROMBIOS */
140 NE_SetEntryPoint( hModule, 193, DOSMEM_BiosDataSeg ); /* KERNEL.193: __0040H */
141 NE_SetEntryPoint( hModule, 194, DOSMEM_BiosSysSeg ); /* KERNEL.194: __F000H */
142 #undef SET_ENTRY_POINT
147 /***********************************************************************
148 * GDI initialisation routine
150 BOOL WINAPI MAIN_GdiInit(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
154 if ( GDI_HeapSel ) return TRUE;
156 /* Create GDI heap */
157 pModule = NE_GetPtr( GetModuleHandle16( "GDI" ) );
160 GDI_HeapSel = GlobalHandleToSel16( (NE_SEG_TABLE( pModule ) +
161 pModule->dgroup - 1)->hSeg );
165 GDI_HeapSel = GlobalAlloc16( GMEM_FIXED, GDI_HEAP_SIZE );
166 LocalInit16( GDI_HeapSel, 0, GDI_HEAP_SIZE-1 );
169 if (!TWEAK_Init()) return FALSE;
171 /* GDI initialisation */
172 if(!GDI_Init()) return FALSE;
175 /* PSDRV initialization */
176 if(!PSDRV_Init()) return FALSE;
181 /***********************************************************************
182 * USER initialisation routine
184 BOOL WINAPI MAIN_UserInit(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
189 if ( USER_HeapSel ) return TRUE;
191 /* Create USER heap */
192 pModule = NE_GetPtr( GetModuleHandle16( "USER" ) );
195 USER_HeapSel = GlobalHandleToSel16( (NE_SEG_TABLE( pModule ) +
196 pModule->dgroup - 1)->hSeg );
200 USER_HeapSel = GlobalAlloc16( GMEM_FIXED, 0x10000 );
201 LocalInit16( USER_HeapSel, 0, 0xffff );
204 /* Global atom table initialisation */
205 if (!ATOM_Init( USER_HeapSel )) return FALSE;
207 /* Initialize system colors and metrics*/
211 /* Create the DCEs */
214 /* Initialize window procedures */
215 if (!WINPROC_Init()) return FALSE;
217 /* Initialize built-in window classes */
218 if (!WIDGETS_Init()) return FALSE;
220 /* Initialize dialog manager */
221 if (!DIALOG_Init()) return FALSE;
223 /* Initialize menus */
224 if (!MENU_Init()) return FALSE;
226 /* Initialize cursor/icons */
229 /* Initialize multimedia */
230 if (!MULTIMEDIA_Init()) return FALSE;
232 /* Initialize message spying */
233 if (!SPY_Init()) return FALSE;
235 /* Check wine.conf for old/bad entries */
236 if (!TWEAK_CheckConfiguration()) return FALSE;
238 /* Create system message queue */
239 queueSize = GetProfileIntA( "windows", "TypeAhead", 120 );
240 if (!QUEUE_CreateSysMsgQueue( queueSize )) return FALSE;
242 /* Set double click time */
243 SetDoubleClickTime( GetProfileIntA("windows","DoubleClickSpeed",452) );
245 /* Create task message queue for the initial task */
246 queueSize = GetProfileIntA( "windows", "DefaultQueueSize", 8 );
247 if (!SetMessageQueue( queueSize )) return FALSE;
249 /* Create desktop window */
250 if (!WIN_CreateDesktopWindow()) return FALSE;
252 /* Install default USER Signal Handler */
253 SetTaskSignalProc( 0, (FARPROC16)USER_SignalProc );
255 /* Initialize keyboard driver */
256 KEYBOARD_Enable( keybd_event, InputKeyStateTable );
258 /* Initialize mouse driver */
259 MOUSE_Enable( mouse_event );
265 /***********************************************************************
266 * Winelib initialisation routine
268 HINSTANCE MAIN_WinelibInit( int *argc, char *argv[] )
275 /* Create the initial process */
276 if (!PROCESS_Init()) return 0;
278 /* Parse command line arguments */
279 MAIN_WineInit( argc, argv );
281 /* Main initialization */
282 if (!MAIN_MainInit()) return 0;
284 /* Initialize KERNEL */
285 if (!MAIN_KernelInit(0, 0, NULL)) return 0;
287 /* Create and switch to initial task */
288 if (!(wm = ELF_CreateDummyModule( argv[0], argv[0] )))
290 PROCESS_Current()->exe_modref = wm;
292 strcpy( ofs.szPathName, wm->modname );
293 if ((hModule = MODULE_CreateDummyModule( &ofs, NULL )) < 32) return 0;
294 pModule = (NE_MODULE *)GlobalLock16( hModule );
295 pModule->flags = NE_FFLAGS_WIN32;
296 pModule->module32 = wm->module;
298 if (!TASK_Create( THREAD_Current(), pModule, 0, 0, FALSE )) return 0;
299 TASK_StartTask( PROCESS_Current()->task );
301 /* Initialize GDI and USER */
302 if (!MAIN_GdiInit(0, 0, NULL)) return 0;
303 if (!MAIN_UserInit(0, 0, NULL)) return 0;