Fixed Win16 documentation not fixed because of a bug in winapi_check.
[wine] / dlls / kernel / kernel_main.c
1 /*
2  * Kernel initialization code
3  */
4
5 #include <assert.h>
6 #include <ctype.h>
7
8 #include "winbase.h"
9 #include "wine/winbase16.h"
10
11 #include "module.h"
12 #include "task.h"
13 #include "selectors.h"
14 #include "miscemu.h"
15 #include "global.h"
16
17 extern void CODEPAGE_Init(void);
18 extern BOOL THUNK_Init(void);
19 extern void COMM_Init(void);
20
21
22 /***********************************************************************
23  *           KERNEL process initialisation routine
24  */
25 static BOOL process_attach(void)
26 {
27     HMODULE16 hModule;
28     STARTUPINFOA startup_info;
29     UINT cmdShow = 1; /* SW_SHOWNORMAL but we don't want to include winuser.h here */
30
31     /* Setup codepage info */
32     CODEPAGE_Init();
33
34     /* Initialize thunking */
35     if (!THUNK_Init()) return FALSE;
36
37     /* Initialize DOS memory */
38     if (!DOSMEM_Init(0)) return FALSE;
39
40     if ((hModule = LoadLibrary16( "krnl386.exe" )) < 32) return FALSE;
41
42     /* Initialize special KERNEL entry points */
43
44     /* Initialize KERNEL.178 (__WINFLAGS) with the correct flags value */
45     NE_SetEntryPoint( hModule, 178, GetWinFlags16() );
46
47     /* Initialize KERNEL.454/455 (__FLATCS/__FLATDS) */
48     NE_SetEntryPoint( hModule, 454, __get_cs() );
49     NE_SetEntryPoint( hModule, 455, __get_ds() );
50
51     /* Initialize KERNEL.THHOOK */
52     TASK_InstallTHHook((THHOOK *)PTR_SEG_TO_LIN((SEGPTR)GetProcAddress16( hModule, (LPCSTR)332 )));
53
54     /* Initialize the real-mode selector entry points */
55 #define SET_ENTRY_POINT( num, addr ) \
56     NE_SetEntryPoint( hModule, (num), GLOBAL_CreateBlock( GMEM_FIXED, \
57                       DOSMEM_MapDosToLinear(addr), 0x10000, hModule, \
58                       WINE_LDT_FLAGS_DATA ))
59
60     SET_ENTRY_POINT( 174, 0xa0000 );  /* KERNEL.174: __A000H */
61     SET_ENTRY_POINT( 181, 0xb0000 );  /* KERNEL.181: __B000H */
62     SET_ENTRY_POINT( 182, 0xb8000 );  /* KERNEL.182: __B800H */
63     SET_ENTRY_POINT( 195, 0xc0000 );  /* KERNEL.195: __C000H */
64     SET_ENTRY_POINT( 179, 0xd0000 );  /* KERNEL.179: __D000H */
65     SET_ENTRY_POINT( 190, 0xe0000 );  /* KERNEL.190: __E000H */
66     NE_SetEntryPoint( hModule, 183, DOSMEM_0000H );       /* KERNEL.183: __0000H */
67     NE_SetEntryPoint( hModule, 173, DOSMEM_BiosSysSeg );  /* KERNEL.173: __ROMBIOS */
68     NE_SetEntryPoint( hModule, 193, DOSMEM_BiosDataSeg ); /* KERNEL.193: __0040H */
69     NE_SetEntryPoint( hModule, 194, DOSMEM_BiosSysSeg );  /* KERNEL.194: __F000H */
70 #undef SET_ENTRY_POINT
71
72     /* Force loading of some dlls */
73     if (LoadLibrary16( "system" ) < 32) return FALSE;
74
75     /* Initialize communications */
76     COMM_Init();
77
78     /* Read DOS config.sys */
79     if (!DOSCONF_ReadConfig()) return FALSE;
80
81     /* Create 16-bit task */
82     GetStartupInfoA( &startup_info );
83     if (startup_info.dwFlags & STARTF_USESHOWWINDOW) cmdShow = startup_info.wShowWindow;
84     if (!TASK_Create( (NE_MODULE *)GlobalLock16( MapHModuleLS(GetModuleHandleA(0)) ),
85                       cmdShow, NtCurrentTeb(), NULL, 0 ))
86         return FALSE;
87
88     return TRUE;
89 }
90
91 /***********************************************************************
92  *           KERNEL initialisation routine
93  */
94 BOOL WINAPI MAIN_KernelInit( HINSTANCE hinst, DWORD reason, LPVOID reserved )
95 {
96     switch(reason)
97     {
98     case DLL_PROCESS_ATTACH:
99         return process_attach();
100     case DLL_PROCESS_DETACH:
101         WriteOutProfiles16();
102         break;
103     }
104     return TRUE;
105 }
106
107 /***********************************************************************
108  *              KERNEL_nop
109  *
110  * Entry point for kernel functions that do nothing.
111  */
112 LONG WINAPI KERNEL_nop(void) { return 0; }
113
114
115 /***************************************************************************
116  *
117  * Win 2.x string functions now moved to USER
118  *
119  * We rather want to implement them here instead of doing Callouts
120  */
121
122 /***********************************************************************
123  *              KERNEL_AnsiNext16
124  */
125 SEGPTR WINAPI KERNEL_AnsiNext16(SEGPTR current)
126 {
127     return (*(char *)PTR_SEG_TO_LIN(current)) ? current + 1 : current;
128 }
129
130 /***********************************************************************
131  *              KERNEL_AnsiPrev16
132  */     
133 SEGPTR WINAPI KERNEL_AnsiPrev16( SEGPTR start, SEGPTR current )
134 {
135     return (current==start)?start:current-1;
136 }
137
138 /***********************************************************************
139  *              KERNEL_AnsiUpper16
140  */
141 SEGPTR WINAPI KERNEL_AnsiUpper16( SEGPTR strOrChar )
142 {
143     /* uppercase only one char if strOrChar < 0x10000 */
144     if (HIWORD(strOrChar))
145     {
146         char *s = PTR_SEG_TO_LIN(strOrChar);
147         while (*s) {
148             *s = toupper(*s);
149             s++;
150         }
151         return strOrChar;
152     }
153     else return toupper((char)strOrChar);
154 }
155
156 /***********************************************************************
157  *              KERNEL_AnsiLower16
158  */
159 SEGPTR WINAPI KERNEL_AnsiLower16( SEGPTR strOrChar )
160 {
161     /* lowercase only one char if strOrChar < 0x10000 */
162     if (HIWORD(strOrChar))
163     {
164         char *s = PTR_SEG_TO_LIN(strOrChar);
165         while (*s) {
166             *s = tolower(*s);
167             s++;
168         }
169         return strOrChar;
170     }
171     else return tolower((char)strOrChar);
172 }