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"
52 #include "cursoricon.h"
53 #include "loadorder.h"
55 DEFAULT_DEBUG_CHANNEL(server
)
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 /* Load the configuration file */
69 if (!PROFILE_LoadWineIni()) return FALSE
;
71 /* Initialize module loadorder */
72 if (!MODULE_InitLoadOrder()) return FALSE
;
74 /* Initialize DOS memory */
75 if (!DOSMEM_Init(0)) return FALSE
;
77 /* Initialise DOS drives */
78 if (!DRIVE_Init()) return FALSE
;
80 /* Initialise DOS directories */
81 if (!DIR_Init()) return FALSE
;
83 /* Initialize event handling */
84 if (!EVENT_Init()) return FALSE
;
86 /* Initialise WINSOCK handling */
87 if (!WINSOCK_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
153 /* Initialize relay code */
154 if (!RELAY_Init()) return FALSE
;
159 /***********************************************************************
160 * GDI initialisation routine
162 BOOL WINAPI
MAIN_GdiInit(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
166 if ( GDI_HeapSel
) return TRUE
;
168 /* Create GDI heap */
169 pModule
= NE_GetPtr( GetModuleHandle16( "GDI" ) );
172 GDI_HeapSel
= GlobalHandleToSel16( (NE_SEG_TABLE( pModule
) +
173 pModule
->dgroup
- 1)->hSeg
);
177 GDI_HeapSel
= GlobalAlloc16( GMEM_FIXED
, GDI_HEAP_SIZE
);
178 LocalInit16( GDI_HeapSel
, 0, GDI_HEAP_SIZE
-1 );
181 if (!TWEAK_Init()) return FALSE
;
183 /* GDI initialisation */
184 if(!GDI_Init()) return FALSE
;
186 /* Create the Win16 printer driver */
187 if (!WIN16DRV_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 cursor/icons */
240 /* Initialize built-in window classes */
241 if (!WIDGETS_Init()) return FALSE
;
243 /* Initialize dialog manager */
244 if (!DIALOG_Init()) return FALSE
;
246 /* Initialize menus */
247 if (!MENU_Init()) return FALSE
;
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 message queue of initial thread */
263 InitThreadInput16( 0, 0 );
265 /* Create desktop window */
266 if (!WIN_CreateDesktopWindow()) return FALSE
;
268 /* Initialize keyboard driver */
269 KEYBOARD_Enable( keybd_event
, InputKeyStateTable
);
271 /* Initialize mouse driver */
272 MOUSE_Enable( mouse_event
);
274 /* Start processing X events */
275 UserRepaintDisable16( FALSE
);
281 /***********************************************************************
282 * Winelib initialisation routine
284 HINSTANCE
MAIN_WinelibInit( int *argc
, char *argv
[] )
291 /* Create the initial process */
292 if (!PROCESS_Init()) return 0;
294 /* Parse command line arguments */
295 MAIN_WineInit( argc
, argv
);
297 /* Main initialization */
298 if (!MAIN_MainInit()) return 0;
300 /* Initialize KERNEL */
301 if (!LoadLibrary16( "KERNEL" )) return 0;
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( pModule
, FALSE
)) return 0;
317 /* Load system DLLs into the initial process (and initialize them) */
318 if ( !LoadLibrary16("GDI.EXE" ) || !LoadLibraryA("GDI32.DLL" )
319 || !LoadLibrary16("USER.EXE") || !LoadLibraryA("USER32.DLL"))
322 /* Get pointers to USER routines called by KERNEL */
328 /***********************************************************************
329 * ExitKernel16 (KERNEL.2)
331 * Clean-up everything and exit the Wine process.
334 void WINAPI
ExitKernel16( void )
336 /* Do the clean-up stuff */
338 WriteOutProfiles16();
339 SHELL_SaveRegistry();
341 TerminateProcess( GetCurrentProcess(), 0 );