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