From 7fe09bce8645779fe34fa7dcfd76af169d998545 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Sat, 3 Jun 2000 04:49:40 +0000 Subject: [PATCH] Moved kernel initialization to kernel_main.c --- dlls/kernel/Makefile.in | 3 ++ dlls/kernel/kernel_main.c | 91 +++++++++++++++++++++++++++++++++++++++ dlls/ttydrv/ttydrv_main.c | 3 ++ dlls/x11drv/x11drv_main.c | 3 ++ if1632/relay.c | 24 +++++------ loader/main.c | 70 ------------------------------ scheduler/process.c | 23 +++++----- 7 files changed, 122 insertions(+), 95 deletions(-) create mode 100644 dlls/kernel/kernel_main.c diff --git a/dlls/kernel/Makefile.in b/dlls/kernel/Makefile.in index 25038822d5e..8a7ce36c105 100644 --- a/dlls/kernel/Makefile.in +++ b/dlls/kernel/Makefile.in @@ -15,6 +15,9 @@ SPEC_SRCS = \ toolhelp.spec \ wprocs.spec +C_SRCS = \ + kernel_main.c + @MAKE_DLL_RULES@ ### Dependencies: diff --git a/dlls/kernel/kernel_main.c b/dlls/kernel/kernel_main.c new file mode 100644 index 00000000000..258bad59464 --- /dev/null +++ b/dlls/kernel/kernel_main.c @@ -0,0 +1,91 @@ +/* + * Kernel initialization code + */ + +#include + +#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; +} diff --git a/dlls/ttydrv/ttydrv_main.c b/dlls/ttydrv/ttydrv_main.c index 966e6a515f2..4141dc55fdb 100644 --- a/dlls/ttydrv/ttydrv_main.c +++ b/dlls/ttydrv/ttydrv_main.c @@ -87,6 +87,9 @@ static void process_attach(void) MONITOR_PrimaryMonitor.depth = 1; TTYDRV_GDI_Initialize(); + + /* load display.dll */ + LoadLibrary16( "display" ); } diff --git a/dlls/x11drv/x11drv_main.c b/dlls/x11drv/x11drv_main.c index 89144928a27..43094467ae3 100644 --- a/dlls/x11drv/x11drv_main.c +++ b/dlls/x11drv/x11drv_main.c @@ -311,6 +311,9 @@ static void process_attach(void) /* initialize event handling */ X11DRV_EVENT_Init(); + + /* load display.dll */ + LoadLibrary16( "display" ); } diff --git a/if1632/relay.c b/if1632/relay.c index 7076d2eb94f..f66c5c145b5 100644 --- a/if1632/relay.c +++ b/if1632/relay.c @@ -8,10 +8,10 @@ #include #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; + extern SEGPTR CallTo16_RetAddr; + extern SEGPTR CALL32_CBClient_RetAddr; + extern SEGPTR 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 ); + 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(); } diff --git a/loader/main.c b/loader/main.c index aef6a57e52a..ea1a70769f6 100644 --- a/loader/main.c +++ b/loader/main.c @@ -12,20 +12,13 @@ #include #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; } diff --git a/scheduler/process.c b/scheduler/process.c index d08dea33fe9..c189b9ca557 100644 --- a/scheduler/process.c +++ b/scheduler/process.c @@ -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;