Moved mode setting out of .spec file into Makefile.
[wine/gsoc_dplay.git] / dlls / kernel / kernel_main.c
blobac0fa8a7b9bf05a441cdf8b03f54059667ab490a
1 /*
2 * Kernel initialization code
4 * Copyright 2000 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "config.h"
22 #include "wine/port.h"
24 #include <assert.h>
25 #include <ctype.h>
26 #include <string.h>
27 #include <sys/stat.h>
28 #include <signal.h>
30 #include "winbase.h"
31 #include "wincon.h"
32 #include "ntddk.h"
34 #include "wine/winbase16.h"
35 #include "wine/library.h"
36 #include "file.h"
37 #include "global.h"
38 #include "miscemu.h"
39 #include "module.h"
40 #include "task.h"
41 #include "wincon.h"
42 #include "console_private.h"
44 extern void LOCALE_Init(void);
45 extern BOOL RELAY_Init(void);
47 extern int __wine_set_signal_handler(unsigned, int (*)(unsigned));
49 extern int main_create_flags;
51 /***********************************************************************
52 * KERNEL process initialisation routine
54 static BOOL process_attach(void)
56 HMODULE16 hModule;
58 /* Get the umask */
59 FILE_umask = umask(0777);
60 umask( FILE_umask );
62 /* Setup codepage info */
63 LOCALE_Init();
65 /* Initialize relay entry points */
66 if (!RELAY_Init()) return FALSE;
68 /* Initialize DOS memory */
69 if (!DOSMEM_Init(0)) return FALSE;
71 if ((hModule = LoadLibrary16( "krnl386.exe" )) < 32) return FALSE;
73 /* Initialize special KERNEL entry points */
75 /* Initialize KERNEL.178 (__WINFLAGS) with the correct flags value */
76 NE_SetEntryPoint( hModule, 178, GetWinFlags16() );
78 /* Initialize KERNEL.454/455 (__FLATCS/__FLATDS) */
79 NE_SetEntryPoint( hModule, 454, wine_get_cs() );
80 NE_SetEntryPoint( hModule, 455, wine_get_ds() );
82 /* Initialize KERNEL.THHOOK */
83 TASK_InstallTHHook(MapSL((SEGPTR)GetProcAddress16( hModule, (LPCSTR)332 )));
85 /* Initialize the real-mode selector entry points */
86 #define SET_ENTRY_POINT( num, addr ) \
87 NE_SetEntryPoint( hModule, (num), GLOBAL_CreateBlock( GMEM_FIXED, \
88 DOSMEM_MapDosToLinear(addr), 0x10000, hModule, \
89 WINE_LDT_FLAGS_DATA ))
91 SET_ENTRY_POINT( 174, 0xa0000 ); /* KERNEL.174: __A000H */
92 SET_ENTRY_POINT( 181, 0xb0000 ); /* KERNEL.181: __B000H */
93 SET_ENTRY_POINT( 182, 0xb8000 ); /* KERNEL.182: __B800H */
94 SET_ENTRY_POINT( 195, 0xc0000 ); /* KERNEL.195: __C000H */
95 SET_ENTRY_POINT( 179, 0xd0000 ); /* KERNEL.179: __D000H */
96 SET_ENTRY_POINT( 190, 0xe0000 ); /* KERNEL.190: __E000H */
97 NE_SetEntryPoint( hModule, 183, DOSMEM_0000H ); /* KERNEL.183: __0000H */
98 NE_SetEntryPoint( hModule, 173, DOSMEM_BiosSysSeg ); /* KERNEL.173: __ROMBIOS */
99 NE_SetEntryPoint( hModule, 193, DOSMEM_BiosDataSeg ); /* KERNEL.193: __0040H */
100 NE_SetEntryPoint( hModule, 194, DOSMEM_BiosSysSeg ); /* KERNEL.194: __F000H */
101 #undef SET_ENTRY_POINT
103 /* Force loading of some dlls */
104 if (LoadLibrary16( "system" ) < 32) return FALSE;
106 /* Create 16-bit task */
107 TASK_CreateMainTask();
109 /* Create the shared heap for broken win95 native dlls */
110 HeapCreate( HEAP_SHARED, 0, 0 );
112 /* finish the process initialisation for console bits, if needed */
113 __wine_set_signal_handler(SIGINT, CONSOLE_HandleCtrlC);
115 if (main_create_flags & CREATE_NEW_CONSOLE)
117 HMODULE mod = GetModuleHandleA(0);
118 if (RtlImageNtHeader(mod)->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI)
119 AllocConsole();
121 if (main_create_flags & CREATE_NEW_PROCESS_GROUP)
122 SetConsoleCtrlHandler(NULL, TRUE);
124 return TRUE;
127 /***********************************************************************
128 * KERNEL initialisation routine
130 BOOL WINAPI MAIN_KernelInit( HINSTANCE hinst, DWORD reason, LPVOID reserved )
132 switch(reason)
134 case DLL_PROCESS_ATTACH:
135 return process_attach();
136 case DLL_PROCESS_DETACH:
137 WriteOutProfiles16();
138 break;
140 return TRUE;
143 /***********************************************************************
144 * EnableDos (KERNEL.41)
145 * DisableDos (KERNEL.42)
146 * GetLastDiskChange (KERNEL.98)
147 * ValidateCodeSegments (KERNEL.100)
148 * KbdRst (KERNEL.123)
149 * EnableKernel (KERNEL.124)
150 * DisableKernel (KERNEL.125)
151 * ValidateFreeSpaces (KERNEL.200)
152 * K237 (KERNEL.237)
153 * BUNNY_351 (KERNEL.351)
154 * PIGLET_361 (KERNEL.361)
156 * Entry point for kernel functions that do nothing.
158 LONG WINAPI KERNEL_nop(void)
160 return 0;
163 /***********************************************************************
164 * SwitchToThread (KERNEL32.@)
167 BOOL WINAPI SwitchToThread(void)
169 Sleep(0);
170 return 1;