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