Moved the kernel 16-bit initialization to a new DllEntryPoint routine

in krnl386.
This commit is contained in:
Alexandre Julliard 2005-08-29 10:20:51 +00:00
parent 8a8c561cfa
commit 510acffe08
5 changed files with 138 additions and 93 deletions

View File

@ -79,6 +79,7 @@ C_SRCS = \
C_SRCS16 = \ C_SRCS16 = \
atom16.c \ atom16.c \
error16.c \ error16.c \
kernel16.c \
registry16.c \ registry16.c \
toolhelp16.c \ toolhelp16.c \
win87em.c win87em.c

135
dlls/kernel/kernel16.c Normal file
View File

@ -0,0 +1,135 @@
/*
* 16-bit kernel initialization code
*
* Copyright 2000 Alexandre Julliard
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "winternl.h"
#include "wownt32.h"
#include "toolhelp.h"
#include "kernel_private.h"
#include "kernel16_private.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(kernel);
/**************************************************************************
* DllEntryPoint (KERNEL.669)
*/
BOOL WINAPI KERNEL_DllEntryPoint( DWORD reasion, HINSTANCE16 inst, WORD ds,
WORD heap, DWORD reserved1, WORD reserved2 )
{
static int done;
/* the entry point can be called multiple times */
if (done) return TRUE;
done = 1;
/* Initialize 16-bit thunking entry points */
if (!WOWTHUNK_Init()) return FALSE;
/* Initialize DOS memory */
if (!DOSMEM_Init()) return FALSE;
/* Initialize special KERNEL entry points */
NE_SetEntryPoint( inst, 178, GetWinFlags16() );
NE_SetEntryPoint( inst, 454, wine_get_cs() );
NE_SetEntryPoint( inst, 455, wine_get_ds() );
NE_SetEntryPoint( inst, 183, DOSMEM_0000H ); /* KERNEL.183: __0000H */
NE_SetEntryPoint( inst, 173, DOSMEM_BiosSysSeg ); /* KERNEL.173: __ROMBIOS */
NE_SetEntryPoint( inst, 193, DOSMEM_BiosDataSeg ); /* KERNEL.193: __0040H */
NE_SetEntryPoint( inst, 194, DOSMEM_BiosSysSeg ); /* KERNEL.194: __F000H */
/* Initialize KERNEL.THHOOK */
TASK_InstallTHHook(MapSL((SEGPTR)GetProcAddress16( inst, (LPCSTR)332 )));
/* Initialize the real-mode selector entry points */
#define SET_ENTRY_POINT( num, addr ) \
NE_SetEntryPoint( inst, (num), GLOBAL_CreateBlock( GMEM_FIXED, \
DOSMEM_MapDosToLinear(addr), 0x10000, inst, \
WINE_LDT_FLAGS_DATA ))
SET_ENTRY_POINT( 174, 0xa0000 ); /* KERNEL.174: __A000H */
SET_ENTRY_POINT( 181, 0xb0000 ); /* KERNEL.181: __B000H */
SET_ENTRY_POINT( 182, 0xb8000 ); /* KERNEL.182: __B800H */
SET_ENTRY_POINT( 195, 0xc0000 ); /* KERNEL.195: __C000H */
SET_ENTRY_POINT( 179, 0xd0000 ); /* KERNEL.179: __D000H */
SET_ENTRY_POINT( 190, 0xe0000 ); /* KERNEL.190: __E000H */
#undef SET_ENTRY_POINT
/* Force loading of some dlls */
LoadLibrary16( "system.drv" );
return TRUE;
}
/***********************************************************************
* EnableDos (KERNEL.41)
* DisableDos (KERNEL.42)
* GetLastDiskChange (KERNEL.98)
* ValidateCodeSegments (KERNEL.100)
* KbdRst (KERNEL.123)
* EnableKernel (KERNEL.124)
* DisableKernel (KERNEL.125)
* ValidateFreeSpaces (KERNEL.200)
* K237 (KERNEL.237)
* BUNNY_351 (KERNEL.351)
* PIGLET_361 (KERNEL.361)
*
* Entry point for kernel functions that do nothing.
*/
LONG WINAPI KERNEL_nop(void)
{
return 0;
}
/* thunk for 16-bit CreateThread */
struct thread_args
{
FARPROC16 proc;
DWORD param;
};
static DWORD CALLBACK start_thread16( LPVOID threadArgs )
{
struct thread_args args = *(struct thread_args *)threadArgs;
HeapFree( GetProcessHeap(), 0, threadArgs );
return K32WOWCallback16( (DWORD)args.proc, args.param );
}
/***********************************************************************
* CreateThread16 (KERNEL.441)
*/
HANDLE WINAPI CreateThread16( SECURITY_ATTRIBUTES *sa, DWORD stack,
FARPROC16 start, SEGPTR param,
DWORD flags, LPDWORD id )
{
struct thread_args *args = HeapAlloc( GetProcessHeap(), 0, sizeof(*args) );
if (!args) return INVALID_HANDLE_VALUE;
args->proc = start;
args->param = param;
return CreateThread( sa, stack, start_thread16, args, flags, id );
}

View File

@ -107,7 +107,6 @@ static void thread_detach(void)
*/ */
static BOOL process_attach(void) static BOOL process_attach(void)
{ {
HMODULE16 hModule;
SYSTEM_INFO si; SYSTEM_INFO si;
SYSTEM_TIMEOFDAY_INFORMATION sti; SYSTEM_TIMEOFDAY_INFORMATION sti;
@ -127,48 +126,6 @@ static BOOL process_attach(void)
/* copy process information from ntdll */ /* copy process information from ntdll */
ENV_CopyStartupInformation(); ENV_CopyStartupInformation();
if ((hModule = LoadLibrary16( "krnl386.exe" )) >= 32)
{
/* Initialize 16-bit thunking entry points */
if (!WOWTHUNK_Init()) return FALSE;
/* Initialize DOS memory */
if (!DOSMEM_Init()) return FALSE;
/* Initialize special KERNEL entry points */
/* Initialize KERNEL.178 (__WINFLAGS) with the correct flags value */
NE_SetEntryPoint( hModule, 178, GetWinFlags16() );
/* Initialize KERNEL.454/455 (__FLATCS/__FLATDS) */
NE_SetEntryPoint( hModule, 454, wine_get_cs() );
NE_SetEntryPoint( hModule, 455, wine_get_ds() );
/* Initialize KERNEL.THHOOK */
TASK_InstallTHHook(MapSL((SEGPTR)GetProcAddress16( hModule, (LPCSTR)332 )));
/* Initialize the real-mode selector entry points */
#define SET_ENTRY_POINT( num, addr ) \
NE_SetEntryPoint( hModule, (num), GLOBAL_CreateBlock( GMEM_FIXED, \
DOSMEM_MapDosToLinear(addr), 0x10000, hModule, \
WINE_LDT_FLAGS_DATA ))
SET_ENTRY_POINT( 174, 0xa0000 ); /* KERNEL.174: __A000H */
SET_ENTRY_POINT( 181, 0xb0000 ); /* KERNEL.181: __B000H */
SET_ENTRY_POINT( 182, 0xb8000 ); /* KERNEL.182: __B800H */
SET_ENTRY_POINT( 195, 0xc0000 ); /* KERNEL.195: __C000H */
SET_ENTRY_POINT( 179, 0xd0000 ); /* KERNEL.179: __D000H */
SET_ENTRY_POINT( 190, 0xe0000 ); /* KERNEL.190: __E000H */
NE_SetEntryPoint( hModule, 183, DOSMEM_0000H ); /* KERNEL.183: __0000H */
NE_SetEntryPoint( hModule, 173, DOSMEM_BiosSysSeg ); /* KERNEL.173: __ROMBIOS */
NE_SetEntryPoint( hModule, 193, DOSMEM_BiosDataSeg ); /* KERNEL.193: __0040H */
NE_SetEntryPoint( hModule, 194, DOSMEM_BiosSysSeg ); /* KERNEL.194: __F000H */
#undef SET_ENTRY_POINT
/* Force loading of some dlls */
LoadLibrary16( "system.drv" );
}
#ifdef __i386__ #ifdef __i386__
if (GetVersion() & 0x80000000) if (GetVersion() & 0x80000000)
{ {
@ -203,6 +160,7 @@ static BOOL process_attach(void)
SetConsoleCtrlHandler(NULL, TRUE); SetConsoleCtrlHandler(NULL, TRUE);
/* Create 16-bit task */ /* Create 16-bit task */
LoadLibrary16( "krnl386.exe" );
thread_attach(); thread_attach();
TASK_CreateMainTask(); TASK_CreateMainTask();
return TRUE; return TRUE;
@ -230,26 +188,6 @@ BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved )
return TRUE; return TRUE;
} }
/***********************************************************************
* EnableDos (KERNEL.41)
* DisableDos (KERNEL.42)
* GetLastDiskChange (KERNEL.98)
* ValidateCodeSegments (KERNEL.100)
* KbdRst (KERNEL.123)
* EnableKernel (KERNEL.124)
* DisableKernel (KERNEL.125)
* ValidateFreeSpaces (KERNEL.200)
* K237 (KERNEL.237)
* BUNNY_351 (KERNEL.351)
* PIGLET_361 (KERNEL.361)
*
* Entry point for kernel functions that do nothing.
*/
LONG WINAPI KERNEL_nop(void)
{
return 0;
}
/*********************************************************************** /***********************************************************************
* MulDiv (KERNEL32.@) * MulDiv (KERNEL32.@)
* RETURNS * RETURNS

View File

@ -513,7 +513,7 @@
666 pascal UTGlue16(ptr long ptr long) UTGlue16 666 pascal UTGlue16(ptr long ptr long) UTGlue16
667 pascal EntryAddrProc(word word) EntryAddrProc16 667 pascal EntryAddrProc(word word) EntryAddrProc16
668 pascal MyAlloc(word word word) MyAlloc16 668 pascal MyAlloc(word word word) MyAlloc16
669 pascal -ret16 DllEntryPoint(long word word word long word) KERNEL_DllEntryPoint
# 700-704 are Win95 only # 700-704 are Win95 only

View File

@ -56,20 +56,6 @@ DWORD WINAPI FreeLibrary32W16(DWORD);
#define CPEX_DEST_STDCALL 0x00000000L #define CPEX_DEST_STDCALL 0x00000000L
#define CPEX_DEST_CDECL 0x80000000L #define CPEX_DEST_CDECL 0x80000000L
/* thunk for 16-bit CreateThread */
struct thread_args
{
FARPROC16 proc;
DWORD param;
};
static DWORD CALLBACK start_thread16( LPVOID threadArgs )
{
struct thread_args args = *(struct thread_args *)threadArgs;
HeapFree( GetProcessHeap(), 0, threadArgs );
return K32WOWCallback16( (DWORD)args.proc, args.param );
}
#ifdef __i386__ #ifdef __i386__
@ -941,18 +927,3 @@ DWORD WINAPIV WOW16Call(WORD x, WORD y, WORD z, VA_LIST16 args)
DPRINTF(") calling address was 0x%08lx\n",calladdr); DPRINTF(") calling address was 0x%08lx\n",calladdr);
return 0; return 0;
} }
/***********************************************************************
* CreateThread16 (KERNEL.441)
*/
HANDLE WINAPI CreateThread16( SECURITY_ATTRIBUTES *sa, DWORD stack,
FARPROC16 start, SEGPTR param,
DWORD flags, LPDWORD id )
{
struct thread_args *args = HeapAlloc( GetProcessHeap(), 0, sizeof(*args) );
if (!args) return INVALID_HANDLE_VALUE;
args->proc = start;
args->param = param;
return CreateThread( sa, stack, start_thread16, args, flags, id );
}