2 * Main initialization code
12 #include "wine/winbase16.h"
13 #include "wine/winuser16.h"
23 #include "sysmetrics.h"
35 #include "cursoricon.h"
47 #include "cursoricon.h"
48 #include "loadorder.h"
50 DEFAULT_DEBUG_CHANNEL(server
)
52 int __winelib
= 1; /* Winelib run-time flag */
54 /***********************************************************************
55 * Main initialisation routine
57 BOOL
MAIN_MainInit(void)
59 /* Set server debug level */
60 /* To fool make_debug: TRACE(server) */
61 CLIENT_SetDebug( TRACE_ON(server
) );
63 /* Initialize syslevel handling */
66 /* Initialize signal handling */
67 if (!SIGNAL_Init()) return FALSE
;
69 /* Initialize kernel services thread */
70 if (!SERVICE_Init()) return FALSE
;
72 /* Load the configuration file */
73 if (!PROFILE_LoadWineIni()) return FALSE
;
75 /* Initialize module loadorder */
76 if (!MODULE_InitLoadOrder()) return FALSE
;
78 /* Initialize DOS memory */
79 if (!DOSMEM_Init(0)) return FALSE
;
81 /* Initialise DOS drives */
82 if (!DRIVE_Init()) return FALSE
;
84 /* Initialise DOS directories */
85 if (!DIR_Init()) return FALSE
;
87 /* Initialize event handling */
88 if (!EVENT_Init()) return FALSE
;
90 /* Initialize communications */
93 /* Initialize IO-port permissions */
96 /* registry initialisation */
99 /* Read DOS config.sys */
100 if (!DOSCONF_ReadConfig()) return FALSE
;
105 /***********************************************************************
106 * KERNEL initialisation routine
108 BOOL WINAPI
MAIN_KernelInit(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
110 static BOOL initDone
= FALSE
;
114 if ( initDone
) return TRUE
;
117 /* Initialize special KERNEL entry points */
118 hModule
= GetModuleHandle16( "KERNEL" );
123 /* Initialize KERNEL.178 (__WINFLAGS) with the correct flags value */
124 NE_SetEntryPoint( hModule
, 178, GetWinFlags16() );
126 /* Initialize KERNEL.454/455 (__FLATCS/__FLATDS) */
127 GET_CS(cs
); GET_DS(ds
);
128 NE_SetEntryPoint( hModule
, 454, cs
);
129 NE_SetEntryPoint( hModule
, 455, ds
);
131 /* Initialize KERNEL.THHOOK */
132 TASK_InstallTHHook((THHOOK
*)PTR_SEG_TO_LIN(
133 (SEGPTR
)NE_GetEntryPoint( hModule
, 332 )));
135 /* Initialize the real-mode selector entry points */
136 #define SET_ENTRY_POINT( num, addr ) \
137 NE_SetEntryPoint( hModule, (num), GLOBAL_CreateBlock( GMEM_FIXED, \
138 DOSMEM_MapDosToLinear(addr), 0x10000, hModule, \
139 FALSE, FALSE, FALSE, NULL ))
141 SET_ENTRY_POINT( 183, 0x00000 ); /* KERNEL.183: __0000H */
142 SET_ENTRY_POINT( 174, 0xa0000 ); /* KERNEL.174: __A000H */
143 SET_ENTRY_POINT( 181, 0xb0000 ); /* KERNEL.181: __B000H */
144 SET_ENTRY_POINT( 182, 0xb8000 ); /* KERNEL.182: __B800H */
145 SET_ENTRY_POINT( 195, 0xc0000 ); /* KERNEL.195: __C000H */
146 SET_ENTRY_POINT( 179, 0xd0000 ); /* KERNEL.179: __D000H */
147 SET_ENTRY_POINT( 190, 0xe0000 ); /* KERNEL.190: __E000H */
148 NE_SetEntryPoint( hModule
, 173, DOSMEM_BiosSysSeg
); /* KERNEL.173: __ROMBIOS */
149 NE_SetEntryPoint( hModule
, 193, DOSMEM_BiosDataSeg
); /* KERNEL.193: __0040H */
150 NE_SetEntryPoint( hModule
, 194, DOSMEM_BiosSysSeg
); /* KERNEL.194: __F000H */
151 #undef SET_ENTRY_POINT
156 /***********************************************************************
157 * GDI initialisation routine
159 BOOL WINAPI
MAIN_GdiInit(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
163 if ( GDI_HeapSel
) return TRUE
;
165 /* Create GDI heap */
166 pModule
= NE_GetPtr( GetModuleHandle16( "GDI" ) );
169 GDI_HeapSel
= GlobalHandleToSel16( (NE_SEG_TABLE( pModule
) +
170 pModule
->dgroup
- 1)->hSeg
);
174 GDI_HeapSel
= GlobalAlloc16( GMEM_FIXED
, GDI_HEAP_SIZE
);
175 LocalInit16( GDI_HeapSel
, 0, GDI_HEAP_SIZE
-1 );
178 if (!TWEAK_Init()) return FALSE
;
180 /* GDI initialisation */
181 if(!GDI_Init()) return FALSE
;
184 /* PSDRV initialization */
185 if(!PSDRV_Init()) return FALSE
;
190 /***********************************************************************
191 * USER initialisation routine
193 BOOL WINAPI
MAIN_UserInit(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
198 if ( USER_HeapSel
) return TRUE
;
200 /* Create USER heap */
201 pModule
= NE_GetPtr( GetModuleHandle16( "USER" ) );
204 USER_HeapSel
= GlobalHandleToSel16( (NE_SEG_TABLE( pModule
) +
205 pModule
->dgroup
- 1)->hSeg
);
209 USER_HeapSel
= GlobalAlloc16( GMEM_FIXED
, 0x10000 );
210 LocalInit16( USER_HeapSel
, 0, 0xffff );
213 /* Global atom table initialisation */
214 if (!ATOM_Init( USER_HeapSel
)) return FALSE
;
216 /* Initialize system colors and metrics*/
220 /* Create the DCEs */
223 /* Initialize timers */
224 if (!TIMER_Init()) return FALSE
;
226 /* Initialize window procedures */
227 if (!WINPROC_Init()) return FALSE
;
229 /* Initialize built-in window classes */
230 if (!WIDGETS_Init()) return FALSE
;
232 /* Initialize dialog manager */
233 if (!DIALOG_Init()) return FALSE
;
235 /* Initialize menus */
236 if (!MENU_Init()) return FALSE
;
238 /* Initialize cursor/icons */
241 /* Initialize message spying */
242 if (!SPY_Init()) return FALSE
;
244 /* Check wine.conf for old/bad entries */
245 if (!TWEAK_CheckConfiguration()) return FALSE
;
247 /* Create system message queue */
248 queueSize
= GetProfileIntA( "windows", "TypeAhead", 120 );
249 if (!QUEUE_CreateSysMsgQueue( queueSize
)) return FALSE
;
251 /* Set double click time */
252 SetDoubleClickTime( GetProfileIntA("windows","DoubleClickSpeed",452) );
254 /* Create task message queue for the initial task */
255 queueSize
= GetProfileIntA( "windows", "DefaultQueueSize", 8 );
256 if (!SetMessageQueue( queueSize
)) return FALSE
;
258 /* Create desktop window */
259 if (!WIN_CreateDesktopWindow()) return FALSE
;
261 /* Initialize keyboard driver */
262 KEYBOARD_Enable( keybd_event
, InputKeyStateTable
);
264 /* Initialize mouse driver */
265 MOUSE_Enable( mouse_event
);
271 /***********************************************************************
272 * Winelib initialisation routine
274 HINSTANCE
MAIN_WinelibInit( int *argc
, char *argv
[] )
281 /* Create the initial process */
282 if (!PROCESS_Init()) return 0;
284 /* Parse command line arguments */
285 MAIN_WineInit( argc
, argv
);
287 /* Main initialization */
288 if (!MAIN_MainInit()) return 0;
290 /* Initialize KERNEL */
291 if (!LoadLibraryA( "KERNEL32" )) return 0;
293 /* Create and switch to initial task */
294 if (!(wm
= ELF_CreateDummyModule( argv
[0], argv
[0] )))
296 PROCESS_Current()->exe_modref
= wm
;
298 strcpy( ofs
.szPathName
, wm
->modname
);
299 if ((hModule
= MODULE_CreateDummyModule( &ofs
, NULL
)) < 32) return 0;
300 pModule
= (NE_MODULE
*)GlobalLock16( hModule
);
301 pModule
->flags
= NE_FFLAGS_WIN32
;
302 pModule
->module32
= wm
->module
;
304 if (!TASK_Create( THREAD_Current(), pModule
, 0, 0, FALSE
)) return 0;
305 TASK_StartTask( PROCESS_Current()->task
);
307 /* Initialize GDI and USER */
308 if (!LoadLibraryA( "GDI32.DLL" )) return 0;
309 if (!LoadLibraryA( "USER32.DLL" )) return 0;