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