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