Added TEB in init_thread request.
[wine/multimedia.git] / loader / main.c
blob5f75eb0ab3aaa0dc84a7974f9172113808569bb7
1 /*
2 * Main initialization code
3 */
5 #include <stdlib.h>
6 #include <sys/types.h>
7 #include <sys/stat.h>
8 #include <fcntl.h>
9 #include <unistd.h>
10 #include <string.h>
11 #include <errno.h>
12 #include "wine/winbase16.h"
13 #include "wine/winuser16.h"
14 #include "bitmap.h"
15 #include "comm.h"
16 #include "neexe.h"
17 #include "main.h"
18 #include "menu.h"
19 #include "message.h"
20 #include "dialog.h"
21 #include "drive.h"
22 #include "queue.h"
23 #include "sysmetrics.h"
24 #include "file.h"
25 #include "heap.h"
26 #include "keyboard.h"
27 #include "mouse.h"
28 #include "input.h"
29 #include "miscemu.h"
30 #include "options.h"
31 #include "process.h"
32 #include "spy.h"
33 #include "tweak.h"
34 #include "user.h"
35 #include "cursoricon.h"
36 #include "global.h"
37 #include "dce.h"
38 #include "shell.h"
39 #include "win.h"
40 #include "winproc.h"
41 #include "syslevel.h"
42 #include "services.h"
43 #include "thread.h"
44 #include "task.h"
45 #include "debug.h"
46 #include "psdrv.h"
47 #include "server.h"
48 #include "cursoricon.h"
49 #include "loadorder.h"
51 DEFAULT_DEBUG_CHANNEL(server)
53 int __winelib = 1; /* Winelib run-time flag */
55 /***********************************************************************
56 * Main initialisation routine
58 BOOL MAIN_MainInit(void)
60 /* Set server debug level */
61 /* To fool make_debug: TRACE(server) */
62 CLIENT_SetDebug( TRACE_ON(server) );
64 /* Initialize syslevel handling */
65 SYSLEVEL_Init();
67 /* Initialize signal handling */
68 if (!SIGNAL_Init()) return FALSE;
70 /* Initialize kernel services thread */
71 if (!SERVICE_Init()) return FALSE;
73 /* Load the configuration file */
74 if (!PROFILE_LoadWineIni()) return FALSE;
76 /* Initialize module loadorder */
77 if (!MODULE_InitLoadOrder()) return FALSE;
79 /* Initialize DOS memory */
80 if (!DOSMEM_Init(0)) return FALSE;
82 /* Initialise DOS drives */
83 if (!DRIVE_Init()) return FALSE;
85 /* Initialise DOS directories */
86 if (!DIR_Init()) return FALSE;
88 /* Initialize event handling */
89 if (!EVENT_Init()) return FALSE;
91 /* Initialize communications */
92 COMM_Init();
94 /* Initialize IO-port permissions */
95 IO_port_init();
97 /* registry initialisation */
98 SHELL_LoadRegistry();
100 /* Read DOS config.sys */
101 if (!DOSCONF_ReadConfig()) return FALSE;
103 return TRUE;
106 /***********************************************************************
107 * KERNEL initialisation routine
109 BOOL WINAPI MAIN_KernelInit(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
111 static BOOL initDone = FALSE;
113 HMODULE16 hModule;
115 if ( initDone ) return TRUE;
116 initDone = TRUE;
118 /* Initialize special KERNEL entry points */
119 hModule = GetModuleHandle16( "KERNEL" );
120 if ( hModule )
122 WORD cs, ds;
124 /* Initialize KERNEL.178 (__WINFLAGS) with the correct flags value */
125 NE_SetEntryPoint( hModule, 178, GetWinFlags16() );
127 /* Initialize KERNEL.454/455 (__FLATCS/__FLATDS) */
128 GET_CS(cs); GET_DS(ds);
129 NE_SetEntryPoint( hModule, 454, cs );
130 NE_SetEntryPoint( hModule, 455, ds );
132 /* Initialize KERNEL.THHOOK */
133 TASK_InstallTHHook((THHOOK *)PTR_SEG_TO_LIN(
134 (SEGPTR)NE_GetEntryPoint( hModule, 332 )));
136 /* Initialize the real-mode selector entry points */
137 #define SET_ENTRY_POINT( num, addr ) \
138 NE_SetEntryPoint( hModule, (num), GLOBAL_CreateBlock( GMEM_FIXED, \
139 DOSMEM_MapDosToLinear(addr), 0x10000, hModule, \
140 FALSE, FALSE, FALSE, NULL ))
142 SET_ENTRY_POINT( 183, 0x00000 ); /* KERNEL.183: __0000H */
143 SET_ENTRY_POINT( 174, 0xa0000 ); /* KERNEL.174: __A000H */
144 SET_ENTRY_POINT( 181, 0xb0000 ); /* KERNEL.181: __B000H */
145 SET_ENTRY_POINT( 182, 0xb8000 ); /* KERNEL.182: __B800H */
146 SET_ENTRY_POINT( 195, 0xc0000 ); /* KERNEL.195: __C000H */
147 SET_ENTRY_POINT( 179, 0xd0000 ); /* KERNEL.179: __D000H */
148 SET_ENTRY_POINT( 190, 0xe0000 ); /* KERNEL.190: __E000H */
149 NE_SetEntryPoint( hModule, 173, DOSMEM_BiosSysSeg ); /* KERNEL.173: __ROMBIOS */
150 NE_SetEntryPoint( hModule, 193, DOSMEM_BiosDataSeg ); /* KERNEL.193: __0040H */
151 NE_SetEntryPoint( hModule, 194, DOSMEM_BiosSysSeg ); /* KERNEL.194: __F000H */
152 #undef SET_ENTRY_POINT
154 return TRUE;
157 /***********************************************************************
158 * GDI initialisation routine
160 BOOL WINAPI MAIN_GdiInit(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
162 NE_MODULE *pModule;
164 if ( GDI_HeapSel ) return TRUE;
166 /* Create GDI heap */
167 pModule = NE_GetPtr( GetModuleHandle16( "GDI" ) );
168 if ( pModule )
170 GDI_HeapSel = GlobalHandleToSel16( (NE_SEG_TABLE( pModule ) +
171 pModule->dgroup - 1)->hSeg );
173 else
175 GDI_HeapSel = GlobalAlloc16( GMEM_FIXED, GDI_HEAP_SIZE );
176 LocalInit16( GDI_HeapSel, 0, GDI_HEAP_SIZE-1 );
179 if (!TWEAK_Init()) return FALSE;
181 /* GDI initialisation */
182 if(!GDI_Init()) return FALSE;
185 /* PSDRV initialization */
186 if(!PSDRV_Init()) return FALSE;
188 return TRUE;
191 /***********************************************************************
192 * USER initialisation routine
194 BOOL WINAPI MAIN_UserInit(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
196 NE_MODULE *pModule;
197 int queueSize;
199 if ( USER_HeapSel ) return TRUE;
201 /* Create USER heap */
202 pModule = NE_GetPtr( GetModuleHandle16( "USER" ) );
203 if ( pModule )
205 USER_HeapSel = GlobalHandleToSel16( (NE_SEG_TABLE( pModule ) +
206 pModule->dgroup - 1)->hSeg );
208 else
210 USER_HeapSel = GlobalAlloc16( GMEM_FIXED, 0x10000 );
211 LocalInit16( USER_HeapSel, 0, 0xffff );
214 /* Global atom table initialisation */
215 if (!ATOM_Init( USER_HeapSel )) return FALSE;
217 /* Initialize window handling (critical section) */
218 WIN_Init();
220 /* Initialize system colors and metrics*/
221 SYSMETRICS_Init();
222 SYSCOLOR_Init();
224 /* Create the DCEs */
225 DCE_Init();
227 /* Initialize timers */
228 if (!TIMER_Init()) return FALSE;
230 /* Initialize window procedures */
231 if (!WINPROC_Init()) return FALSE;
233 /* Initialize built-in window classes */
234 if (!WIDGETS_Init()) return FALSE;
236 /* Initialize dialog manager */
237 if (!DIALOG_Init()) return FALSE;
239 /* Initialize menus */
240 if (!MENU_Init()) return FALSE;
242 /* Initialize cursor/icons */
243 CURSORICON_Init();
245 /* Initialize message spying */
246 if (!SPY_Init()) return FALSE;
248 /* Check wine.conf for old/bad entries */
249 if (!TWEAK_CheckConfiguration()) return FALSE;
251 /* Create system message queue */
252 queueSize = GetProfileIntA( "windows", "TypeAhead", 120 );
253 if (!QUEUE_CreateSysMsgQueue( queueSize )) return FALSE;
255 /* Set double click time */
256 SetDoubleClickTime( GetProfileIntA("windows","DoubleClickSpeed",452) );
258 /* Create task message queue for the initial task */
259 queueSize = GetProfileIntA( "windows", "DefaultQueueSize", 8 );
260 if (!SetMessageQueue( queueSize )) return FALSE;
262 /* Create desktop window */
263 if (!WIN_CreateDesktopWindow()) return FALSE;
265 /* Initialize keyboard driver */
266 KEYBOARD_Enable( keybd_event, InputKeyStateTable );
268 /* Initialize mouse driver */
269 MOUSE_Enable( mouse_event );
271 return TRUE;
275 /***********************************************************************
276 * Winelib initialisation routine
278 HINSTANCE MAIN_WinelibInit( int *argc, char *argv[] )
280 WINE_MODREF *wm;
281 NE_MODULE *pModule;
282 OFSTRUCT ofs;
283 HMODULE16 hModule;
285 /* Create the initial process */
286 if (!PROCESS_Init()) return 0;
288 /* Parse command line arguments */
289 MAIN_WineInit( argc, argv );
291 /* Main initialization */
292 if (!MAIN_MainInit()) return 0;
294 /* Initialize KERNEL */
295 if (!LoadLibraryA( "KERNEL32" )) return 0;
297 /* Create and switch to initial task */
298 if (!(wm = ELF_CreateDummyModule( argv[0], argv[0] )))
299 return 0;
300 PROCESS_Current()->exe_modref = wm;
302 strcpy( ofs.szPathName, wm->modname );
303 if ((hModule = MODULE_CreateDummyModule( &ofs, NULL )) < 32) return 0;
304 pModule = (NE_MODULE *)GlobalLock16( hModule );
305 pModule->flags = NE_FFLAGS_WIN32;
306 pModule->module32 = wm->module;
308 if (!TASK_Create( THREAD_Current(), pModule, 0, 0, FALSE )) return 0;
309 TASK_StartTask( PROCESS_Current()->task );
311 /* Initialize GDI and USER */
312 if (!LoadLibraryA( "GDI32.DLL" )) return 0;
313 if (!LoadLibraryA( "USER32.DLL" )) return 0;
315 return wm->module;