2 * Main initialization code
19 #include "multimedia.h"
23 #include "sysmetrics.h"
47 int __winelib
= 1; /* Winelib run-time flag */
49 /***********************************************************************
50 * Main initialisation routine
52 BOOL32
MAIN_MainInit(void)
54 /* Set server debug level */
55 /* To fool make_debug: TRACE(server) */
56 CLIENT_SetDebug( TRACE_ON(server
) );
58 /* Initialize syslevel handling */
61 /* Initialize signal handling */
62 if (!SIGNAL_Init()) return FALSE
;
64 /* Load the configuration file */
65 if (!PROFILE_LoadWineIni()) return FALSE
;
67 /* Initialize DOS memory */
68 if (!DOSMEM_Init(0)) return FALSE
;
70 /* Initialise DOS drives */
71 if (!DRIVE_Init()) return FALSE
;
73 /* Initialise DOS directories */
74 if (!DIR_Init()) return FALSE
;
76 /* Initialize event handling */
77 if (!EVENT_Init()) return FALSE
;
79 /* Initialize communications */
82 /* Initialize IO-port permissions */
85 /* registry initialisation */
88 /* Read DOS config.sys */
89 if (!DOSCONF_ReadConfig()) return FALSE
;
94 /***********************************************************************
95 * KERNEL initialisation routine
97 BOOL32 WINAPI
MAIN_KernelInit(HINSTANCE32 hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
99 static BOOL32 initDone
= FALSE
;
103 if ( initDone
) return TRUE
;
106 /* Initialize special KERNEL entry points */
107 hModule
= GetModuleHandle16( "KERNEL" );
112 /* Initialize KERNEL.178 (__WINFLAGS) with the correct flags value */
113 NE_SetEntryPoint( hModule
, 178, GetWinFlags() );
115 /* Initialize KERNEL.454/455 (__FLATCS/__FLATDS) */
116 GET_CS(cs
); GET_DS(ds
);
117 NE_SetEntryPoint( hModule
, 454, cs
);
118 NE_SetEntryPoint( hModule
, 455, ds
);
120 /* Initialize KERNEL.THHOOK */
121 TASK_InstallTHHook((THHOOK
*)PTR_SEG_TO_LIN(
122 (SEGPTR
)NE_GetEntryPoint( hModule
, 332 )));
124 /* Initialize the real-mode selector entry points */
125 #define SET_ENTRY_POINT( num, addr ) \
126 NE_SetEntryPoint( hModule, (num), GLOBAL_CreateBlock( GMEM_FIXED, \
127 DOSMEM_MapDosToLinear(addr), 0x10000, hModule, \
128 FALSE, FALSE, FALSE, NULL ))
130 SET_ENTRY_POINT( 183, 0x00000 ); /* KERNEL.183: __0000H */
131 SET_ENTRY_POINT( 174, 0xa0000 ); /* KERNEL.174: __A000H */
132 SET_ENTRY_POINT( 181, 0xb0000 ); /* KERNEL.181: __B000H */
133 SET_ENTRY_POINT( 182, 0xb8000 ); /* KERNEL.182: __B800H */
134 SET_ENTRY_POINT( 195, 0xc0000 ); /* KERNEL.195: __C000H */
135 SET_ENTRY_POINT( 179, 0xd0000 ); /* KERNEL.179: __D000H */
136 SET_ENTRY_POINT( 190, 0xe0000 ); /* KERNEL.190: __E000H */
137 NE_SetEntryPoint( hModule
, 173, DOSMEM_BiosSysSeg
); /* KERNEL.173: __ROMBIOS */
138 NE_SetEntryPoint( hModule
, 193, DOSMEM_BiosDataSeg
); /* KERNEL.193: __0040H */
139 NE_SetEntryPoint( hModule
, 194, DOSMEM_BiosSysSeg
); /* KERNEL.194: __F000H */
140 #undef SET_ENTRY_POINT
146 /***********************************************************************
147 * GDI initialisation routine
149 BOOL32 WINAPI
MAIN_GdiInit(HINSTANCE32 hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
153 if ( GDI_HeapSel
) return TRUE
;
155 /* Create GDI heap */
156 pModule
= NE_GetPtr( GetModuleHandle16( "GDI" ) );
159 GDI_HeapSel
= GlobalHandleToSel( (NE_SEG_TABLE( pModule
) +
160 pModule
->dgroup
- 1)->hSeg
);
164 GDI_HeapSel
= GlobalAlloc16( GMEM_FIXED
, GDI_HEAP_SIZE
);
165 LocalInit( GDI_HeapSel
, 0, GDI_HEAP_SIZE
-1 );
168 if (!TWEAK_Init()) return FALSE
;
170 /* GDI initialisation */
171 if(!GDI_Init()) return FALSE
;
174 /* PSDRV initialization */
175 if(!PSDRV_Init()) return FALSE
;
180 /***********************************************************************
181 * USER initialisation routine
183 BOOL32 WINAPI
MAIN_UserInit(HINSTANCE32 hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
188 if ( USER_HeapSel
) return TRUE
;
190 /* Create USER heap */
191 pModule
= NE_GetPtr( GetModuleHandle16( "USER" ) );
194 USER_HeapSel
= GlobalHandleToSel( (NE_SEG_TABLE( pModule
) +
195 pModule
->dgroup
- 1)->hSeg
);
199 USER_HeapSel
= GlobalAlloc16( GMEM_FIXED
, 0x10000 );
200 LocalInit( USER_HeapSel
, 0, 0xffff );
203 /* Global atom table initialisation */
204 if (!ATOM_Init( USER_HeapSel
)) return FALSE
;
206 /* Initialize system colors and metrics*/
210 /* Create the DCEs */
213 /* Initialize window procedures */
214 if (!WINPROC_Init()) return FALSE
;
216 /* Initialize built-in window classes */
217 if (!WIDGETS_Init()) return FALSE
;
219 /* Initialize dialog manager */
220 if (!DIALOG_Init()) return FALSE
;
222 /* Initialize menus */
223 if (!MENU_Init()) return FALSE
;
225 /* Initialize multimedia */
226 if (!MULTIMEDIA_Init()) return FALSE
;
228 /* Initialize message spying */
229 if (!SPY_Init()) return FALSE
;
231 /* Check wine.conf for old/bad entries */
232 if (!TWEAK_CheckConfiguration()) return FALSE
;
234 /* Create system message queue */
235 queueSize
= GetProfileInt32A( "windows", "TypeAhead", 120 );
236 if (!QUEUE_CreateSysMsgQueue( queueSize
)) return FALSE
;
238 /* Set double click time */
239 SetDoubleClickTime32( GetProfileInt32A("windows","DoubleClickSpeed",452) );
241 /* Create task message queue for the initial task */
242 queueSize
= GetProfileInt32A( "windows", "DefaultQueueSize", 8 );
243 if (!SetMessageQueue32( queueSize
)) return FALSE
;
245 /* Create desktop window */
246 if (!WIN_CreateDesktopWindow()) return FALSE
;
248 /* Install default USER Signal Handler */
249 SetTaskSignalProc( 0, (FARPROC16
)USER_SignalProc
);
251 /* Initialize keyboard driver */
252 KEYBOARD_Enable( keybd_event
, InputKeyStateTable
);
254 /* Initialize mouse driver */
255 MOUSE_Enable( mouse_event
);
261 /***********************************************************************
262 * Winelib initialisation routine
264 HINSTANCE32
MAIN_WinelibInit( int *argc
, char *argv
[] )
270 HINSTANCE16 hInstance
;
272 /* Create the initial process */
273 if (!PROCESS_Init()) return 0;
275 /* Parse command line arguments */
276 MAIN_WineInit( argc
, argv
);
278 /* Main initialization */
279 if (!MAIN_MainInit()) return 0;
281 /* Initialize KERNEL */
282 if (!MAIN_KernelInit(0, 0, NULL
)) return 0;
284 /* Create and switch to initial task */
285 if (!(wm
= ELF_CreateDummyModule( argv
[0], argv
[0], PROCESS_Current() )))
287 PROCESS_Current()->exe_modref
= wm
;
289 strcpy( ofs
.szPathName
, wm
->modname
);
290 if ((hModule
= MODULE_CreateDummyModule( &ofs
, NULL
)) < 32) return 0;
291 pModule
= (NE_MODULE
*)GlobalLock16( hModule
);
292 pModule
->flags
= NE_FFLAGS_WIN32
;
293 pModule
->module32
= wm
->module
;
295 hInstance
= NE_CreateInstance( pModule
, NULL
, TRUE
);
296 PROCESS_Current()->task
= TASK_Create( THREAD_Current(), pModule
, hInstance
, 0, FALSE
);
298 TASK_StartTask( PROCESS_Current()->task
);
300 /* Initialize GDI and USER */
301 if (!MAIN_GdiInit(0, 0, NULL
)) return 0;
302 if (!MAIN_UserInit(0, 0, NULL
)) return 0;