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( int *argc
, char *argv
[] )
62 /* Create the initial process */
63 if (!PROCESS_Init()) return 0;
65 /* Set server debug level */
66 CLIENT_SetDebug( TRACE_ON(server
) );
68 /* Initialize syslevel handling */
71 /* Parse command line arguments */
72 MAIN_WineInit( argc
, argv
);
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 /* Initialize communications */
95 /* Initialize IO-port permissions */
98 /* registry initialisation */
101 /* Read DOS config.sys */
102 if (!DOSCONF_ReadConfig()) return FALSE
;
104 /* Initialize KERNEL */
105 if (!LoadLibrary16( "KRNL386.EXE" )) return FALSE
;
106 if (!LoadLibraryA( "KERNEL32" )) return FALSE
;
111 /***********************************************************************
112 * KERNEL initialisation routine
114 BOOL WINAPI
MAIN_KernelInit(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
116 static BOOL initDone
= FALSE
;
120 if ( initDone
) return TRUE
;
123 /* Initialize special KERNEL entry points */
124 hModule
= GetModuleHandle16( "KERNEL" );
129 /* Initialize KERNEL.178 (__WINFLAGS) with the correct flags value */
130 NE_SetEntryPoint( hModule
, 178, GetWinFlags16() );
132 /* Initialize KERNEL.454/455 (__FLATCS/__FLATDS) */
133 GET_CS(cs
); GET_DS(ds
);
134 NE_SetEntryPoint( hModule
, 454, cs
);
135 NE_SetEntryPoint( hModule
, 455, ds
);
137 /* Initialize KERNEL.THHOOK */
138 TASK_InstallTHHook((THHOOK
*)PTR_SEG_TO_LIN(
139 (SEGPTR
)NE_GetEntryPoint( hModule
, 332 )));
141 /* Initialize the real-mode selector entry points */
142 #define SET_ENTRY_POINT( num, addr ) \
143 NE_SetEntryPoint( hModule, (num), GLOBAL_CreateBlock( GMEM_FIXED, \
144 DOSMEM_MapDosToLinear(addr), 0x10000, hModule, \
145 FALSE, FALSE, FALSE, NULL ))
147 SET_ENTRY_POINT( 183, 0x00000 ); /* KERNEL.183: __0000H */
148 SET_ENTRY_POINT( 174, 0xa0000 ); /* KERNEL.174: __A000H */
149 SET_ENTRY_POINT( 181, 0xb0000 ); /* KERNEL.181: __B000H */
150 SET_ENTRY_POINT( 182, 0xb8000 ); /* KERNEL.182: __B800H */
151 SET_ENTRY_POINT( 195, 0xc0000 ); /* KERNEL.195: __C000H */
152 SET_ENTRY_POINT( 179, 0xd0000 ); /* KERNEL.179: __D000H */
153 SET_ENTRY_POINT( 190, 0xe0000 ); /* KERNEL.190: __E000H */
154 NE_SetEntryPoint( hModule
, 173, DOSMEM_BiosSysSeg
); /* KERNEL.173: __ROMBIOS */
155 NE_SetEntryPoint( hModule
, 193, DOSMEM_BiosDataSeg
); /* KERNEL.193: __0040H */
156 NE_SetEntryPoint( hModule
, 194, DOSMEM_BiosSysSeg
); /* KERNEL.194: __F000H */
157 #undef SET_ENTRY_POINT
160 /* Initialize relay code */
161 if (!RELAY_Init()) return FALSE
;
166 /***********************************************************************
167 * GDI initialisation routine
169 BOOL WINAPI
MAIN_GdiInit(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
173 if ( GDI_HeapSel
) return TRUE
;
175 /* Create GDI heap */
176 pModule
= NE_GetPtr( GetModuleHandle16( "GDI" ) );
179 GDI_HeapSel
= GlobalHandleToSel16( (NE_SEG_TABLE( pModule
) +
180 pModule
->dgroup
- 1)->hSeg
);
184 GDI_HeapSel
= GlobalAlloc16( GMEM_FIXED
, GDI_HEAP_SIZE
);
185 LocalInit16( GDI_HeapSel
, 0, GDI_HEAP_SIZE
-1 );
188 if (!TWEAK_Init()) return FALSE
;
190 /* GDI initialisation */
191 if(!GDI_Init()) return FALSE
;
193 /* Create the Win16 printer driver */
194 if (!WIN16DRV_Init()) return FALSE
;
196 /* PSDRV initialization */
197 if(!PSDRV_Init()) return FALSE
;
202 /***********************************************************************
203 * USER initialisation routine
205 BOOL WINAPI
MAIN_UserInit(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
210 if ( USER_HeapSel
) return TRUE
;
212 /* Create USER heap */
213 pModule
= NE_GetPtr( GetModuleHandle16( "USER" ) );
216 USER_HeapSel
= GlobalHandleToSel16( (NE_SEG_TABLE( pModule
) +
217 pModule
->dgroup
- 1)->hSeg
);
221 USER_HeapSel
= GlobalAlloc16( GMEM_FIXED
, 0x10000 );
222 LocalInit16( USER_HeapSel
, 0, 0xffff );
225 /* Global atom table initialisation */
226 if (!ATOM_Init( USER_HeapSel
)) return FALSE
;
228 /* Initialize window handling (critical section) */
231 /* Initialize system colors and metrics*/
235 /* Create the DCEs */
238 /* Initialize timers */
239 if (!TIMER_Init()) return FALSE
;
241 /* Initialize window procedures */
242 if (!WINPROC_Init()) return FALSE
;
244 /* Initialize cursor/icons */
247 /* Initialize built-in window classes */
248 if (!WIDGETS_Init()) return FALSE
;
250 /* Initialize dialog manager */
251 if (!DIALOG_Init()) return FALSE
;
253 /* Initialize menus */
254 if (!MENU_Init()) return FALSE
;
256 /* Initialize message spying */
257 if (!SPY_Init()) return FALSE
;
259 /* Check wine.conf for old/bad entries */
260 if (!TWEAK_CheckConfiguration()) return FALSE
;
262 /* Create system message queue */
263 queueSize
= GetProfileIntA( "windows", "TypeAhead", 120 );
264 if (!QUEUE_CreateSysMsgQueue( queueSize
)) return FALSE
;
266 /* Set double click time */
267 SetDoubleClickTime( GetProfileIntA("windows","DoubleClickSpeed",452) );
269 /* Create message queue of initial thread */
270 InitThreadInput16( 0, 0 );
272 /* Create desktop window */
273 if (!WIN_CreateDesktopWindow()) return FALSE
;
275 /* Initialize keyboard driver */
276 KEYBOARD_Enable( keybd_event
, InputKeyStateTable
);
278 /* Initialize mouse driver */
279 MOUSE_Enable( mouse_event
);
281 /* Start processing X events */
282 UserRepaintDisable16( FALSE
);
288 /***********************************************************************
289 * Winelib initialisation routine
291 HINSTANCE
MAIN_WinelibInit( int *argc
, char *argv
[] )
298 /* Main initialization */
299 if (!MAIN_MainInit( argc
, argv
)) return 0;
301 /* Create and switch to initial task */
302 if (!(wm
= ELF_CreateDummyModule( argv
[0], argv
[0] )))
304 PROCESS_Current()->exe_modref
= wm
;
306 strcpy( ofs
.szPathName
, wm
->modname
);
307 if ((hModule
= MODULE_CreateDummyModule( &ofs
, NULL
)) < 32) return 0;
308 pModule
= (NE_MODULE
*)GlobalLock16( hModule
);
309 pModule
->flags
= NE_FFLAGS_WIN32
;
310 pModule
->module32
= wm
->module
;
312 if (!TASK_Create( pModule
, FALSE
)) return 0;
314 /* Load system DLLs into the initial process (and initialize them) */
315 if ( !LoadLibrary16("GDI.EXE" ) || !LoadLibraryA("GDI32.DLL" )
316 || !LoadLibrary16("USER.EXE") || !LoadLibraryA("USER32.DLL"))
319 /* Get pointers to USER routines called by KERNEL */
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();
338 TerminateProcess( GetCurrentProcess(), 0 );