2 * Kernel initialization code
10 #include "wine/winbase16.h"
17 extern void CODEPAGE_Init(void);
18 extern BOOL RELAY_Init(void);
19 extern BOOL THUNK_Init(void);
20 extern void COMM_Init(void);
23 /***********************************************************************
24 * KERNEL process initialisation routine
26 static BOOL process_attach(void)
29 STARTUPINFOA startup_info;
30 UINT cmdShow = 1; /* SW_SHOWNORMAL but we don't want to include winuser.h here */
32 /* Setup codepage info */
35 /* Initialize relay entry points */
36 if (!RELAY_Init()) return FALSE;
38 /* Initialize thunking */
39 if (!THUNK_Init()) return FALSE;
41 /* Initialize DOS memory */
42 if (!DOSMEM_Init(0)) return FALSE;
44 if ((hModule = LoadLibrary16( "krnl386.exe" )) < 32) return FALSE;
46 /* Initialize special KERNEL entry points */
48 /* Initialize KERNEL.178 (__WINFLAGS) with the correct flags value */
49 NE_SetEntryPoint( hModule, 178, GetWinFlags16() );
51 /* Initialize KERNEL.454/455 (__FLATCS/__FLATDS) */
52 NE_SetEntryPoint( hModule, 454, __get_cs() );
53 NE_SetEntryPoint( hModule, 455, __get_ds() );
55 /* Initialize KERNEL.THHOOK */
56 TASK_InstallTHHook(MapSL((SEGPTR)GetProcAddress16( hModule, (LPCSTR)332 )));
58 /* Initialize the real-mode selector entry points */
59 #define SET_ENTRY_POINT( num, addr ) \
60 NE_SetEntryPoint( hModule, (num), GLOBAL_CreateBlock( GMEM_FIXED, \
61 DOSMEM_MapDosToLinear(addr), 0x10000, hModule, \
62 WINE_LDT_FLAGS_DATA ))
64 SET_ENTRY_POINT( 174, 0xa0000 ); /* KERNEL.174: __A000H */
65 SET_ENTRY_POINT( 181, 0xb0000 ); /* KERNEL.181: __B000H */
66 SET_ENTRY_POINT( 182, 0xb8000 ); /* KERNEL.182: __B800H */
67 SET_ENTRY_POINT( 195, 0xc0000 ); /* KERNEL.195: __C000H */
68 SET_ENTRY_POINT( 179, 0xd0000 ); /* KERNEL.179: __D000H */
69 SET_ENTRY_POINT( 190, 0xe0000 ); /* KERNEL.190: __E000H */
70 NE_SetEntryPoint( hModule, 183, DOSMEM_0000H ); /* KERNEL.183: __0000H */
71 NE_SetEntryPoint( hModule, 173, DOSMEM_BiosSysSeg ); /* KERNEL.173: __ROMBIOS */
72 NE_SetEntryPoint( hModule, 193, DOSMEM_BiosDataSeg ); /* KERNEL.193: __0040H */
73 NE_SetEntryPoint( hModule, 194, DOSMEM_BiosSysSeg ); /* KERNEL.194: __F000H */
74 #undef SET_ENTRY_POINT
76 /* Force loading of some dlls */
77 if (LoadLibrary16( "system" ) < 32) return FALSE;
79 /* Initialize communications */
82 /* Read DOS config.sys */
83 if (!DOSCONF_ReadConfig()) return FALSE;
85 /* Create 16-bit task */
86 GetStartupInfoA( &startup_info );
87 if (startup_info.dwFlags & STARTF_USESHOWWINDOW) cmdShow = startup_info.wShowWindow;
88 if (!TASK_Create( (NE_MODULE *)GlobalLock16( MapHModuleLS(GetModuleHandleA(0)) ),
89 cmdShow, NtCurrentTeb(), NULL, 0 ))
95 /***********************************************************************
96 * KERNEL initialisation routine
98 BOOL WINAPI MAIN_KernelInit( HINSTANCE hinst, DWORD reason, LPVOID reserved )
102 case DLL_PROCESS_ATTACH:
103 return process_attach();
104 case DLL_PROCESS_DETACH:
105 WriteOutProfiles16();
111 /***********************************************************************
112 * KERNEL_nop (KERNEL.361)
114 * Entry point for kernel functions that do nothing.
116 LONG WINAPI KERNEL_nop(void) { return 0; }
119 /***************************************************************************
121 * Win 2.x string functions now moved to USER
123 * We rather want to implement them here instead of doing Callouts
126 /***********************************************************************
127 * KERNEL_AnsiNext16 (KERNEL.77)
129 SEGPTR WINAPI KERNEL_AnsiNext16(SEGPTR current)
131 return (*(char *)MapSL(current)) ? current + 1 : current;
134 /***********************************************************************
135 * KERNEL_AnsiPrev16(KERNEL.78)
137 SEGPTR WINAPI KERNEL_AnsiPrev16( SEGPTR start, SEGPTR current )
139 return (current==start)?start:current-1;
142 /***********************************************************************
143 * KERNEL_AnsiUpper16 (KERNEL.79)
145 SEGPTR WINAPI KERNEL_AnsiUpper16( SEGPTR strOrChar )
147 /* uppercase only one char if strOrChar < 0x10000 */
148 if (HIWORD(strOrChar))
150 char *s = MapSL(strOrChar);
157 else return toupper((char)strOrChar);
160 /***********************************************************************
161 * KERNEL_AnsiLower16 (KERNEL.80)
163 SEGPTR WINAPI KERNEL_AnsiLower16( SEGPTR strOrChar )
165 /* lowercase only one char if strOrChar < 0x10000 */
166 if (HIWORD(strOrChar))
168 char *s = MapSL(strOrChar);
175 else return tolower((char)strOrChar);
178 /***********************************************************************
179 * KERNEL_lstrcmp16 (KERNEL.87)
181 INT16 WINAPI KERNEL_lstrcmp16( LPCSTR str1, LPCSTR str2 )
183 return (INT16)strcmp( str1, str2 );