Commit 7fe09bce authored by Alexandre Julliard's avatar Alexandre Julliard

Moved kernel initialization to kernel_main.c

parent 2d8cf500
......@@ -15,6 +15,9 @@ SPEC_SRCS = \
toolhelp.spec \
wprocs.spec
C_SRCS = \
kernel_main.c
@MAKE_DLL_RULES@
### Dependencies:
/*
* Kernel initialization code
*/
#include <assert.h>
#include "winbase.h"
#include "wine/winbase16.h"
#include "neexe.h"
#include "module.h"
#include "task.h"
#include "comm.h"
#include "selectors.h"
#include "miscemu.h"
#include "global.h"
/***********************************************************************
* KERNEL process initialisation routine
*/
static BOOL process_attach(void)
{
HMODULE16 hModule;
/* Initialize DOS memory */
if (!DOSMEM_Init(0)) return FALSE;
if ((hModule = LoadLibrary16( "krnl386.exe" )) < 32) 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, __get_cs() );
NE_SetEntryPoint( hModule, 455, __get_ds() );
/* Initialize KERNEL.THHOOK */
TASK_InstallTHHook((THHOOK *)PTR_SEG_TO_LIN((SEGPTR)NE_GetEntryPoint( hModule, 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, \
FALSE, FALSE, FALSE, NULL ))
SET_ENTRY_POINT( 183, 0x00000 ); /* KERNEL.183: __0000H */
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, 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 */
if (LoadLibrary16( "system" ) < 32) return FALSE;
if (LoadLibrary16( "wprocs" ) < 32) return FALSE;
/* Initialize communications */
COMM_Init();
/* Read DOS config.sys */
if (!DOSCONF_ReadConfig()) return FALSE;
return TRUE;
}
/***********************************************************************
* KERNEL initialisation routine
*/
BOOL WINAPI MAIN_KernelInit( HINSTANCE hinst, DWORD reason, LPVOID reserved )
{
static int process_count;
switch(reason)
{
case DLL_PROCESS_ATTACH:
if (!process_count++) return process_attach();
break;
case DLL_PROCESS_DETACH:
--process_count;
break;
}
return TRUE;
}
......@@ -87,6 +87,9 @@ static void process_attach(void)
MONITOR_PrimaryMonitor.depth = 1;
TTYDRV_GDI_Initialize();
/* load display.dll */
LoadLibrary16( "display" );
}
......
......@@ -311,6 +311,9 @@ static void process_attach(void)
/* initialize event handling */
X11DRV_EVENT_Init();
/* load display.dll */
LoadLibrary16( "display" );
}
......
......@@ -8,10 +8,10 @@
#include <string.h>
#include "wine/winbase16.h"
#include "winnt.h"
#include "global.h"
#include "heap.h"
#include "module.h"
#include "stackframe.h"
#include "selectors.h"
#include "builtin16.h"
#include "task.h"
#include "syslevel.h"
......@@ -35,29 +35,25 @@ BOOL RELAY_Init(void)
extern void CallTo16_Ret();
extern void CALL32_CBClient_Ret();
extern void CALL32_CBClientEx_Ret();
extern DWORD CallTo16_RetAddr;
extern DWORD CALL32_CBClient_RetAddr;
extern DWORD CALL32_CBClientEx_RetAddr;
codesel = GLOBAL_CreateBlock( GMEM_FIXED, (void *)Call16_Ret_Start,
(int)Call16_Ret_End - (int)Call16_Ret_Start,
GetModuleHandle16( "KERNEL" ),
TRUE, TRUE, FALSE, NULL );
extern SEGPTR CallTo16_RetAddr;
extern SEGPTR CALL32_CBClient_RetAddr;
extern SEGPTR CALL32_CBClientEx_RetAddr;
codesel = SELECTOR_AllocBlock( (void *)Call16_Ret_Start,
(char *)Call16_Ret_End - (char *)Call16_Ret_Start,
SEGMENT_CODE, TRUE, FALSE );
if (!codesel) return FALSE;
/* Patch the return addresses for CallTo16 routines */
CallTo16_RetAddr =
MAKELONG( (int)CallTo16_Ret -(int)Call16_Ret_Start, codesel );
PTR_SEG_OFF_TO_SEGPTR( codesel, (char*)CallTo16_Ret - (char*)Call16_Ret_Start );
CALL32_CBClient_RetAddr =
MAKELONG( (int)CALL32_CBClient_Ret -(int)Call16_Ret_Start, codesel );
PTR_SEG_OFF_TO_SEGPTR( codesel, (char*)CALL32_CBClient_Ret - (char*)Call16_Ret_Start );
CALL32_CBClientEx_RetAddr =
MAKELONG( (int)CALL32_CBClientEx_Ret -(int)Call16_Ret_Start, codesel );
PTR_SEG_OFF_TO_SEGPTR( codesel, (char*)CALL32_CBClientEx_Ret - (char*)Call16_Ret_Start );
#endif
/* Create built-in modules */
if (!BUILTIN_Init()) return FALSE;
/* Initialize thunking */
return THUNK_Init();
}
......
......@@ -12,20 +12,13 @@
#include <errno.h>
#include "windef.h"
#include "wine/winbase16.h"
#include "comm.h"
#include "neexe.h"
#include "main.h"
#include "drive.h"
#include "file.h"
#include "miscemu.h"
#include "options.h"
#include "process.h"
#include "global.h"
#include "shell.h"
#include "selectors.h"
#include "task.h"
#include "debugtools.h"
#include "win16drv.h"
#include "server.h"
#include "loadorder.h"
......@@ -64,72 +57,9 @@ BOOL MAIN_MainInit( char *argv[] )
/* Initialize module loadorder */
if (!MODULE_InitLoadOrder()) return FALSE;
return TRUE;
}
/***********************************************************************
* KERNEL initialisation routine
*/
BOOL WINAPI MAIN_KernelInit(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
static BOOL initDone = FALSE;
HMODULE16 hModule;
if ( initDone ) return TRUE;
initDone = TRUE;
/* Initialize DOS memory */
if (!DOSMEM_Init(0)) return FALSE;
if (!LoadLibrary16( "KRNL386.EXE" )) return FALSE;
/* Initialize special KERNEL entry points */
hModule = GetModuleHandle16( "KERNEL" );
if ( hModule )
{
/* Initialize KERNEL.178 (__WINFLAGS) with the correct flags value */
NE_SetEntryPoint( hModule, 178, GetWinFlags16() );
/* Initialize KERNEL.454/455 (__FLATCS/__FLATDS) */
NE_SetEntryPoint( hModule, 454, __get_cs() );
NE_SetEntryPoint( hModule, 455, __get_ds() );
/* Initialize KERNEL.THHOOK */
TASK_InstallTHHook((THHOOK *)PTR_SEG_TO_LIN(
(SEGPTR)NE_GetEntryPoint( hModule, 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, \
FALSE, FALSE, FALSE, NULL ))
SET_ENTRY_POINT( 183, 0x00000 ); /* KERNEL.183: __0000H */
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, 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
}
/* Initialize relay code */
if (!RELAY_Init()) return FALSE;
/* Initialize communications */
COMM_Init();
/* Initialize IO-port permissions */
IO_port_init();
/* Read DOS config.sys */
if (!DOSCONF_ReadConfig()) return FALSE;
return TRUE;
}
......
......@@ -243,8 +243,6 @@ static int load_system_dlls(void)
{
char driver[MAX_PATH];
if (!LoadLibraryA( "KERNEL32" )) return 0;
PROFILE_GetWineIniString( "Wine", "GraphicsDriver", "x11drv", driver, sizeof(driver) );
if (!LoadLibraryA( driver ))
{
......@@ -340,6 +338,18 @@ static void start_process(void)
entry = (LPTHREAD_START_ROUTINE)RVA_PTR( module, OptionalHeader.AddressOfEntryPoint );
console_app = (PE_HEADER(module)->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI);
if (console_app) pdb->flags |= PDB32_CONSOLE_PROC;
/* Signal the parent process to continue */
req->module = (void *)module;
req->entry = entry;
req->gui = !console_app;
server_call( REQ_INIT_PROCESS_DONE );
debugged = req->debugged;
/* Load KERNEL (necessary for TASK_Create) */
if (!LoadLibraryA( "KERNEL32" )) goto error;
/* Create 16-bit dummy module */
if ((hModule16 = MODULE_CreateDummyModule( pdb->exe_modref->filename, module )) < 32)
ExitProcess( hModule16 );
......@@ -350,15 +360,6 @@ static void start_process(void)
NtCurrentTeb(), NULL, 0 ))
goto error;
if (console_app) pdb->flags |= PDB32_CONSOLE_PROC;
/* Signal the parent process to continue */
req->module = (void *)module;
req->entry = entry;
req->gui = !console_app;
server_call( REQ_INIT_PROCESS_DONE );
debugged = req->debugged;
/* Load the system dlls */
if (!load_system_dlls()) goto error;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment