Cleaned up a bit, removed todos for OpenThread, avoid TerminateThread
[wine] / dlls / kernel / kernel_main.c
1 /*
2  * Kernel initialization code
3  *
4  * Copyright 2000 Alexandre Julliard
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "config.h"
22
23 #include <assert.h>
24 #include <ctype.h>
25 #include <string.h>
26 #include <sys/stat.h>
27
28 #include "winbase.h"
29
30 #include "wine/winbase16.h"
31 #include "file.h"
32 #include "global.h"
33 #include "miscemu.h"
34 #include "module.h"
35 #include "task.h"
36
37 extern void CODEPAGE_Init(void);
38 extern BOOL RELAY_Init(void);
39
40
41 /***********************************************************************
42  *           KERNEL process initialisation routine
43  */
44 static BOOL process_attach(void)
45 {
46     HMODULE16 hModule;
47
48     /* Get the umask */
49     FILE_umask = umask(0777);
50     umask( FILE_umask );
51
52     /* Setup codepage info */
53     CODEPAGE_Init();
54
55     /* Initialize relay entry points */
56     if (!RELAY_Init()) return FALSE;
57
58     /* Initialize DOS memory */
59     if (!DOSMEM_Init(0)) return FALSE;
60
61     if ((hModule = LoadLibrary16( "krnl386.exe" )) < 32) return FALSE;
62
63     /* Initialize special KERNEL entry points */
64
65     /* Initialize KERNEL.178 (__WINFLAGS) with the correct flags value */
66     NE_SetEntryPoint( hModule, 178, GetWinFlags16() );
67
68     /* Initialize KERNEL.454/455 (__FLATCS/__FLATDS) */
69     NE_SetEntryPoint( hModule, 454, __get_cs() );
70     NE_SetEntryPoint( hModule, 455, __get_ds() );
71
72     /* Initialize KERNEL.THHOOK */
73     TASK_InstallTHHook(MapSL((SEGPTR)GetProcAddress16( hModule, (LPCSTR)332 )));
74
75     /* Initialize the real-mode selector entry points */
76 #define SET_ENTRY_POINT( num, addr ) \
77     NE_SetEntryPoint( hModule, (num), GLOBAL_CreateBlock( GMEM_FIXED, \
78                       DOSMEM_MapDosToLinear(addr), 0x10000, hModule, \
79                       WINE_LDT_FLAGS_DATA ))
80
81     SET_ENTRY_POINT( 174, 0xa0000 );  /* KERNEL.174: __A000H */
82     SET_ENTRY_POINT( 181, 0xb0000 );  /* KERNEL.181: __B000H */
83     SET_ENTRY_POINT( 182, 0xb8000 );  /* KERNEL.182: __B800H */
84     SET_ENTRY_POINT( 195, 0xc0000 );  /* KERNEL.195: __C000H */
85     SET_ENTRY_POINT( 179, 0xd0000 );  /* KERNEL.179: __D000H */
86     SET_ENTRY_POINT( 190, 0xe0000 );  /* KERNEL.190: __E000H */
87     NE_SetEntryPoint( hModule, 183, DOSMEM_0000H );       /* KERNEL.183: __0000H */
88     NE_SetEntryPoint( hModule, 173, DOSMEM_BiosSysSeg );  /* KERNEL.173: __ROMBIOS */
89     NE_SetEntryPoint( hModule, 193, DOSMEM_BiosDataSeg ); /* KERNEL.193: __0040H */
90     NE_SetEntryPoint( hModule, 194, DOSMEM_BiosSysSeg );  /* KERNEL.194: __F000H */
91 #undef SET_ENTRY_POINT
92
93     /* Force loading of some dlls */
94     if (LoadLibrary16( "system" ) < 32) return FALSE;
95
96     /* Create 16-bit task */
97     TASK_CreateMainTask();
98
99     /* Create the shared heap for broken win95 native dlls */
100     HeapCreate( HEAP_SHARED, 0, 0 );
101
102     return TRUE;
103 }
104
105 /***********************************************************************
106  *           KERNEL initialisation routine
107  */
108 BOOL WINAPI MAIN_KernelInit( HINSTANCE hinst, DWORD reason, LPVOID reserved )
109 {
110     switch(reason)
111     {
112     case DLL_PROCESS_ATTACH:
113         return process_attach();
114     case DLL_PROCESS_DETACH:
115         WriteOutProfiles16();
116         break;
117     }
118     return TRUE;
119 }
120
121 /***********************************************************************
122  *              EnableDos (KERNEL.41)
123  *              DisableDos (KERNEL.42)
124  *              GetLastDiskChange (KERNEL.98)
125  *              ValidateCodeSegments (KERNEL.100)
126  *              KbdRst (KERNEL.123)
127  *              EnableKernel (KERNEL.124)
128  *              DisableKernel (KERNEL.125)
129  *              ValidateFreeSpaces (KERNEL.200)
130  *              K237 (KERNEL.237)
131  *              BUNNY_351 (KERNEL.351)
132  *              PIGLET_361 (KERNEL.361)
133  *
134  * Entry point for kernel functions that do nothing.
135  */
136 LONG WINAPI KERNEL_nop(void)
137 {
138     return 0;
139 }