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 DEFAULT_DEBUG_CHANNEL(server)
53 int __winelib = 1; /* Winelib run-time flag */
55 /***********************************************************************
56 * Main initialisation routine
58 BOOL MAIN_MainInit(void)
60 /* Set server debug level */
61 /* To fool make_debug: TRACE(server) */
62 CLIENT_SetDebug( TRACE_ON(server) );
64 /* Initialize syslevel handling */
67 /* Initialize signal handling */
68 if (!SIGNAL_Init()) return FALSE;
70 /* Initialize kernel services thread */
71 if (!SERVICE_Init()) return FALSE;
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;
106 /***********************************************************************
107 * KERNEL initialisation routine
109 BOOL WINAPI MAIN_KernelInit(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
111 static BOOL initDone = FALSE;
115 if ( initDone ) return TRUE;
118 /* Initialize special KERNEL entry points */
119 hModule = GetModuleHandle16( "KERNEL" );
124 /* Initialize KERNEL.178 (__WINFLAGS) with the correct flags value */
125 NE_SetEntryPoint( hModule, 178, GetWinFlags16() );
127 /* Initialize KERNEL.454/455 (__FLATCS/__FLATDS) */
128 GET_CS(cs); GET_DS(ds);
129 NE_SetEntryPoint( hModule, 454, cs );
130 NE_SetEntryPoint( hModule, 455, ds );
132 /* Initialize KERNEL.THHOOK */
133 TASK_InstallTHHook((THHOOK *)PTR_SEG_TO_LIN(
134 (SEGPTR)NE_GetEntryPoint( hModule, 332 )));
136 /* Initialize the real-mode selector entry points */
137 #define SET_ENTRY_POINT( num, addr ) \
138 NE_SetEntryPoint( hModule, (num), GLOBAL_CreateBlock( GMEM_FIXED, \
139 DOSMEM_MapDosToLinear(addr), 0x10000, hModule, \
140 FALSE, FALSE, FALSE, NULL ))
142 SET_ENTRY_POINT( 183, 0x00000 ); /* KERNEL.183: __0000H */
143 SET_ENTRY_POINT( 174, 0xa0000 ); /* KERNEL.174: __A000H */
144 SET_ENTRY_POINT( 181, 0xb0000 ); /* KERNEL.181: __B000H */
145 SET_ENTRY_POINT( 182, 0xb8000 ); /* KERNEL.182: __B800H */
146 SET_ENTRY_POINT( 195, 0xc0000 ); /* KERNEL.195: __C000H */
147 SET_ENTRY_POINT( 179, 0xd0000 ); /* KERNEL.179: __D000H */
148 SET_ENTRY_POINT( 190, 0xe0000 ); /* KERNEL.190: __E000H */
149 NE_SetEntryPoint( hModule, 173, DOSMEM_BiosSysSeg ); /* KERNEL.173: __ROMBIOS */
150 NE_SetEntryPoint( hModule, 193, DOSMEM_BiosDataSeg ); /* KERNEL.193: __0040H */
151 NE_SetEntryPoint( hModule, 194, DOSMEM_BiosSysSeg ); /* KERNEL.194: __F000H */
152 #undef SET_ENTRY_POINT
157 /***********************************************************************
158 * GDI initialisation routine
160 BOOL WINAPI MAIN_GdiInit(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
164 if ( GDI_HeapSel ) return TRUE;
166 /* Create GDI heap */
167 pModule = NE_GetPtr( GetModuleHandle16( "GDI" ) );
170 GDI_HeapSel = GlobalHandleToSel16( (NE_SEG_TABLE( pModule ) +
171 pModule->dgroup - 1)->hSeg );
175 GDI_HeapSel = GlobalAlloc16( GMEM_FIXED, GDI_HEAP_SIZE );
176 LocalInit16( GDI_HeapSel, 0, GDI_HEAP_SIZE-1 );
179 if (!TWEAK_Init()) return FALSE;
181 /* GDI initialisation */
182 if(!GDI_Init()) return FALSE;
185 /* PSDRV initialization */
186 if(!PSDRV_Init()) return FALSE;
191 /***********************************************************************
192 * USER initialisation routine
194 BOOL WINAPI MAIN_UserInit(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
199 if ( USER_HeapSel ) return TRUE;
201 /* Create USER heap */
202 pModule = NE_GetPtr( GetModuleHandle16( "USER" ) );
205 USER_HeapSel = GlobalHandleToSel16( (NE_SEG_TABLE( pModule ) +
206 pModule->dgroup - 1)->hSeg );
210 USER_HeapSel = GlobalAlloc16( GMEM_FIXED, 0x10000 );
211 LocalInit16( USER_HeapSel, 0, 0xffff );
214 /* Global atom table initialisation */
215 if (!ATOM_Init( USER_HeapSel )) return FALSE;
217 /* Initialize system colors and metrics*/
221 /* Create the DCEs */
224 /* Initialize timers */
225 if (!TIMER_Init()) return FALSE;
227 /* Initialize window procedures */
228 if (!WINPROC_Init()) return FALSE;
230 /* Initialize built-in window classes */
231 if (!WIDGETS_Init()) return FALSE;
233 /* Initialize dialog manager */
234 if (!DIALOG_Init()) return FALSE;
236 /* Initialize menus */
237 if (!MENU_Init()) return FALSE;
239 /* Initialize cursor/icons */
242 /* Initialize multimedia */
243 if (!MULTIMEDIA_Init()) return FALSE;
245 /* Initialize message spying */
246 if (!SPY_Init()) return FALSE;
248 /* Check wine.conf for old/bad entries */
249 if (!TWEAK_CheckConfiguration()) return FALSE;
251 /* Create system message queue */
252 queueSize = GetProfileIntA( "windows", "TypeAhead", 120 );
253 if (!QUEUE_CreateSysMsgQueue( queueSize )) return FALSE;
255 /* Set double click time */
256 SetDoubleClickTime( GetProfileIntA("windows","DoubleClickSpeed",452) );
258 /* Create task message queue for the initial task */
259 queueSize = GetProfileIntA( "windows", "DefaultQueueSize", 8 );
260 if (!SetMessageQueue( queueSize )) return FALSE;
262 /* Create desktop window */
263 if (!WIN_CreateDesktopWindow()) return FALSE;
265 /* Initialize keyboard driver */
266 KEYBOARD_Enable( keybd_event, InputKeyStateTable );
268 /* Initialize mouse driver */
269 MOUSE_Enable( mouse_event );
275 /***********************************************************************
276 * Winelib initialisation routine
278 HINSTANCE MAIN_WinelibInit( int *argc, char *argv[] )
285 /* Create the initial process */
286 if (!PROCESS_Init()) return 0;
288 /* Parse command line arguments */
289 MAIN_WineInit( argc, argv );
291 /* Main initialization */
292 if (!MAIN_MainInit()) return 0;
294 /* Initialize KERNEL */
295 if (!MAIN_KernelInit(0, 0, NULL)) return 0;
297 /* Create and switch to initial task */
298 if (!(wm = ELF_CreateDummyModule( argv[0], argv[0] )))
300 PROCESS_Current()->exe_modref = wm;
302 strcpy( ofs.szPathName, wm->modname );
303 if ((hModule = MODULE_CreateDummyModule( &ofs, NULL )) < 32) return 0;
304 pModule = (NE_MODULE *)GlobalLock16( hModule );
305 pModule->flags = NE_FFLAGS_WIN32;
306 pModule->module32 = wm->module;
308 if (!TASK_Create( THREAD_Current(), pModule, 0, 0, FALSE )) return 0;
309 TASK_StartTask( PROCESS_Current()->task );
311 /* Initialize GDI and USER */
312 if (!MAIN_GdiInit(0, 0, NULL)) return 0;
313 if (!MAIN_UserInit(0, 0, NULL)) return 0;