2 * 16-bit kernel initialization code
4 * Copyright 2000 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #include "kernel_private.h"
30 #include "kernel16_private.h"
31 #include "wine/server.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(module);
36 /**************************************************************************
37 * DllEntryPoint (KERNEL.669)
39 BOOL WINAPI KERNEL_DllEntryPoint( DWORD reasion, HINSTANCE16 inst, WORD ds,
40 WORD heap, DWORD reserved1, WORD reserved2 )
44 /* the entry point can be called multiple times */
45 if (done) return TRUE;
48 /* Initialize 16-bit thunking entry points */
49 if (!WOWTHUNK_Init()) return FALSE;
51 /* Initialize DOS memory */
52 if (!DOSMEM_Init()) return FALSE;
54 /* Initialize special KERNEL entry points */
56 NE_SetEntryPoint( inst, 178, GetWinFlags16() );
58 NE_SetEntryPoint( inst, 454, wine_get_cs() );
59 NE_SetEntryPoint( inst, 455, wine_get_ds() );
61 NE_SetEntryPoint( inst, 183, DOSMEM_0000H ); /* KERNEL.183: __0000H */
62 NE_SetEntryPoint( inst, 173, DOSMEM_BiosSysSeg ); /* KERNEL.173: __ROMBIOS */
63 NE_SetEntryPoint( inst, 193, DOSMEM_BiosDataSeg ); /* KERNEL.193: __0040H */
64 NE_SetEntryPoint( inst, 194, DOSMEM_BiosSysSeg ); /* KERNEL.194: __F000H */
66 /* Initialize KERNEL.THHOOK */
67 TASK_InstallTHHook(MapSL((SEGPTR)GetProcAddress16( inst, (LPCSTR)332 )));
69 /* Initialize the real-mode selector entry points */
70 #define SET_ENTRY_POINT( num, addr ) \
71 NE_SetEntryPoint( inst, (num), GLOBAL_CreateBlock( GMEM_FIXED, \
72 DOSMEM_MapDosToLinear(addr), 0x10000, inst, \
73 WINE_LDT_FLAGS_DATA ))
75 SET_ENTRY_POINT( 174, 0xa0000 ); /* KERNEL.174: __A000H */
76 SET_ENTRY_POINT( 181, 0xb0000 ); /* KERNEL.181: __B000H */
77 SET_ENTRY_POINT( 182, 0xb8000 ); /* KERNEL.182: __B800H */
78 SET_ENTRY_POINT( 195, 0xc0000 ); /* KERNEL.195: __C000H */
79 SET_ENTRY_POINT( 179, 0xd0000 ); /* KERNEL.179: __D000H */
80 SET_ENTRY_POINT( 190, 0xe0000 ); /* KERNEL.190: __E000H */
81 #undef SET_ENTRY_POINT
83 /* Force loading of some dlls */
84 LoadLibrary16( "system.drv" );
89 /***********************************************************************
90 * EnableDos (KERNEL.41)
91 * DisableDos (KERNEL.42)
92 * GetLastDiskChange (KERNEL.98)
93 * ValidateCodeSegments (KERNEL.100)
95 * EnableKernel (KERNEL.124)
96 * DisableKernel (KERNEL.125)
97 * ValidateFreeSpaces (KERNEL.200)
99 * BUNNY_351 (KERNEL.351)
100 * PIGLET_361 (KERNEL.361)
102 * Entry point for kernel functions that do nothing.
104 LONG WINAPI KERNEL_nop(void)
110 /* thunk for 16-bit CreateThread */
117 static DWORD CALLBACK start_thread16( LPVOID threadArgs )
119 struct thread_args args = *(struct thread_args *)threadArgs;
120 HeapFree( GetProcessHeap(), 0, threadArgs );
121 return K32WOWCallback16( (DWORD)args.proc, args.param );
124 /***********************************************************************
125 * CreateThread16 (KERNEL.441)
127 HANDLE WINAPI CreateThread16( SECURITY_ATTRIBUTES *sa, DWORD stack,
128 FARPROC16 start, SEGPTR param,
129 DWORD flags, LPDWORD id )
131 struct thread_args *args = HeapAlloc( GetProcessHeap(), 0, sizeof(*args) );
132 if (!args) return INVALID_HANDLE_VALUE;
135 return CreateThread( sa, stack, start_thread16, args, flags, id );
139 /***********************************************************************
142 * user32.WaitForInputIdle releases the win16 lock, so here is a replacement.
144 static DWORD wait_input_idle( HANDLE process, DWORD timeout )
149 handles[0] = process;
150 SERVER_START_REQ( get_process_idle_event )
152 req->handle = process;
153 if (!(ret = wine_server_call_err( req ))) handles[1] = reply->event;
156 if (ret) return WAIT_FAILED; /* error */
157 if (!handles[1]) return 0; /* no event to wait on */
159 return WaitForMultipleObjects( 2, handles, FALSE, timeout );
163 /**************************************************************************
164 * WINOLDAP entry point
166 void WINAPI WINOLDAP_EntryPoint( CONTEXT86 *context )
171 PROCESS_INFORMATION info;
172 STARTUPINFOA startup;
173 DWORD count, exit_code = 1;
175 InitTask16( context );
177 TRACE( "(ds=%x es=%x fs=%x gs=%x, bx=%04x cx=%04x di=%04x si=%x)\n",
178 context->SegDs, context->SegEs, context->SegFs, context->SegGs,
179 context->Ebx, context->Ecx, context->Edi, context->Esi );
181 psp = GlobalLock16( context->SegEs );
182 len = psp->cmdLine[0];
183 cmdline = HeapAlloc( GetProcessHeap(), 0, len + 1 );
184 memcpy( cmdline, psp->cmdLine + 1, len );
187 memset( &startup, 0, sizeof(startup) );
188 startup.cb = sizeof(startup);
190 if (CreateProcessA( NULL, cmdline, NULL, NULL, FALSE,
191 0, NULL, NULL, &startup, &info ))
193 /* Give 10 seconds to the app to come up */
194 if (wait_input_idle( info.hProcess, 10000 ) == WAIT_FAILED)
195 WARN("WaitForInputIdle failed: Error %d\n", GetLastError() );
196 ReleaseThunkLock( &count );
198 WaitForSingleObject( info.hProcess, INFINITE );
199 GetExitCodeProcess( info.hProcess, &exit_code );
200 CloseHandle( info.hThread );
201 CloseHandle( info.hProcess );
204 ReleaseThunkLock( &count );
206 HeapFree( GetProcessHeap(), 0, cmdline );
207 ExitThread( exit_code );
211 /**************************************************************************
212 * WINHELP entry point
214 * FIXME: should go into winhlp32.exe, but we don't support 16-bit modules in executables yet.
216 void WINAPI WINHELP_EntryPoint( CONTEXT86 *context )
218 static const WCHAR winhlp32W[] = {'\\','w','i','n','h','l','p','3','2','.','e','x','e',0};
222 PROCESS_INFORMATION info;
223 STARTUPINFOW startup;
224 DWORD count, exit_code = 1;
226 InitTask16( context );
228 TRACE( "(ds=%x es=%x fs=%x gs=%x, bx=%04x cx=%04x di=%04x si=%x)\n",
229 context->SegDs, context->SegEs, context->SegFs, context->SegGs,
230 context->Ebx, context->Ecx, context->Edi, context->Esi );
232 psp = GlobalLock16( context->SegEs );
233 len = MultiByteToWideChar( CP_ACP, 0, (char *)psp->cmdLine + 1, psp->cmdLine[0], NULL, 0 );
234 total = (GetSystemDirectoryW( NULL, 0 ) + len + 1) * sizeof(WCHAR) + sizeof(winhlp32W);
235 cmdline = HeapAlloc( GetProcessHeap(), 0, total );
236 GetSystemDirectoryW( cmdline, total );
237 lstrcatW( cmdline, winhlp32W );
238 p = cmdline + lstrlenW(cmdline);
242 MultiByteToWideChar( CP_ACP, 0, (char *)psp->cmdLine + 1, psp->cmdLine[0], p, len );
246 memset( &startup, 0, sizeof(startup) );
247 startup.cb = sizeof(startup);
249 if (CreateProcessW( NULL, cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &startup, &info ))
251 /* Give 10 seconds to the app to come up */
252 if (wait_input_idle( info.hProcess, 10000 ) == WAIT_FAILED)
253 WARN("WaitForInputIdle failed: Error %d\n", GetLastError() );
254 ReleaseThunkLock( &count );
256 WaitForSingleObject( info.hProcess, INFINITE );
257 GetExitCodeProcess( info.hProcess, &exit_code );
258 CloseHandle( info.hThread );
259 CloseHandle( info.hProcess );
262 ReleaseThunkLock( &count );
264 HeapFree( GetProcessHeap(), 0, cmdline );
265 ExitThread( exit_code );