2 * Main initialization code
12 #include "wine/winbase16.h"
13 #include "wine/winuser16.h"
23 #include "sysmetrics.h"
36 #include "cursoricon.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 /* Initialize kernel services thread */
72 if (!SERVICE_Init()) return FALSE
;
74 /* Load the configuration file */
75 if (!PROFILE_LoadWineIni()) return FALSE
;
77 /* Initialize module loadorder */
78 if (!MODULE_InitLoadOrder()) return FALSE
;
80 /* Initialize DOS memory */
81 if (!DOSMEM_Init(0)) return FALSE
;
83 /* Initialise DOS drives */
84 if (!DRIVE_Init()) return FALSE
;
86 /* Initialise DOS directories */
87 if (!DIR_Init()) return FALSE
;
89 /* Initialize event handling */
90 if (!EVENT_Init()) return FALSE
;
92 /* Initialise WINSOCK handling */
93 if (!WINSOCK_Init()) return FALSE
;
95 /* Initialize communications */
98 /* Initialize IO-port permissions */
101 /* registry initialisation */
102 SHELL_LoadRegistry();
104 /* Read DOS config.sys */
105 if (!DOSCONF_ReadConfig()) 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
161 /***********************************************************************
162 * GDI initialisation routine
164 BOOL WINAPI
MAIN_GdiInit(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
168 if ( GDI_HeapSel
) return TRUE
;
170 /* Create GDI heap */
171 pModule
= NE_GetPtr( GetModuleHandle16( "GDI" ) );
174 GDI_HeapSel
= GlobalHandleToSel16( (NE_SEG_TABLE( pModule
) +
175 pModule
->dgroup
- 1)->hSeg
);
179 GDI_HeapSel
= GlobalAlloc16( GMEM_FIXED
, GDI_HEAP_SIZE
);
180 LocalInit16( GDI_HeapSel
, 0, GDI_HEAP_SIZE
-1 );
183 if (!TWEAK_Init()) return FALSE
;
185 /* GDI initialisation */
186 if(!GDI_Init()) return FALSE
;
189 /* PSDRV initialization */
190 if(!PSDRV_Init()) return FALSE
;
195 /***********************************************************************
196 * USER initialisation routine
198 BOOL WINAPI
MAIN_UserInit(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
203 if ( USER_HeapSel
) return TRUE
;
205 /* Create USER heap */
206 pModule
= NE_GetPtr( GetModuleHandle16( "USER" ) );
209 USER_HeapSel
= GlobalHandleToSel16( (NE_SEG_TABLE( pModule
) +
210 pModule
->dgroup
- 1)->hSeg
);
214 USER_HeapSel
= GlobalAlloc16( GMEM_FIXED
, 0x10000 );
215 LocalInit16( USER_HeapSel
, 0, 0xffff );
218 /* Global atom table initialisation */
219 if (!ATOM_Init( USER_HeapSel
)) return FALSE
;
221 /* Initialize window handling (critical section) */
224 /* Initialize system colors and metrics*/
228 /* Create the DCEs */
231 /* Initialize timers */
232 if (!TIMER_Init()) return FALSE
;
234 /* Initialize window procedures */
235 if (!WINPROC_Init()) return FALSE
;
237 /* Initialize built-in window classes */
238 if (!WIDGETS_Init()) return FALSE
;
240 /* Initialize dialog manager */
241 if (!DIALOG_Init()) return FALSE
;
243 /* Initialize menus */
244 if (!MENU_Init()) return FALSE
;
246 /* Initialize cursor/icons */
249 /* Initialize message spying */
250 if (!SPY_Init()) return FALSE
;
252 /* Check wine.conf for old/bad entries */
253 if (!TWEAK_CheckConfiguration()) return FALSE
;
255 /* Create system message queue */
256 queueSize
= GetProfileIntA( "windows", "TypeAhead", 120 );
257 if (!QUEUE_CreateSysMsgQueue( queueSize
)) return FALSE
;
259 /* Set double click time */
260 SetDoubleClickTime( GetProfileIntA("windows","DoubleClickSpeed",452) );
262 /* Create task message queue for the initial task */
263 queueSize
= GetProfileIntA( "windows", "DefaultQueueSize", 8 );
264 if (!SetMessageQueue( queueSize
)) return FALSE
;
266 /* Create desktop window */
267 if (!WIN_CreateDesktopWindow()) return FALSE
;
269 /* Initialize keyboard driver */
270 KEYBOARD_Enable( keybd_event
, InputKeyStateTable
);
272 /* Initialize mouse driver */
273 MOUSE_Enable( mouse_event
);
275 /* Start processing X events */
276 UserRepaintDisable16( FALSE
);
282 /***********************************************************************
283 * Winelib initialisation routine
285 HINSTANCE
MAIN_WinelibInit( int *argc
, char *argv
[] )
292 /* Create the initial process */
293 if (!PROCESS_Init()) return 0;
295 /* Parse command line arguments */
296 MAIN_WineInit( argc
, argv
);
298 /* Main initialization */
299 if (!MAIN_MainInit()) return 0;
301 /* Initialize KERNEL */
302 if (!LoadLibraryA( "KERNEL32" )) return 0;
304 /* Create and switch to initial task */
305 if (!(wm
= ELF_CreateDummyModule( argv
[0], argv
[0] )))
307 PROCESS_Current()->exe_modref
= wm
;
309 strcpy( ofs
.szPathName
, wm
->modname
);
310 if ((hModule
= MODULE_CreateDummyModule( &ofs
, NULL
)) < 32) return 0;
311 pModule
= (NE_MODULE
*)GlobalLock16( hModule
);
312 pModule
->flags
= NE_FFLAGS_WIN32
;
313 pModule
->module32
= wm
->module
;
315 if (!TASK_Create( THREAD_Current(), pModule
, 0, 0, FALSE
)) return 0;
316 TASK_StartTask( PROCESS_Current()->task
);
318 /* Initialize GDI and USER */
319 if (!LoadLibraryA( "GDI32.DLL" )) return 0;
320 if (!LoadLibraryA( "USER32.DLL" )) return 0;
325 /***********************************************************************
326 * ExitKernel16 (KERNEL.2)
328 * Clean-up everything and exit the Wine process.
331 void WINAPI
ExitKernel16( void )
333 /* Do the clean-up stuff */
335 WriteOutProfiles16();
336 SHELL_SaveRegistry();