blob: c549e1fee47b6bd3780bb7e01d82cb77463cd040 [file] [log] [blame]
Alexandre Julliard7fe09bc2000-06-03 04:49:40 +00001/*
2 * Kernel initialization code
Alexandre Julliard0799c1a2002-03-09 23:29:33 +00003 *
4 * Copyright 2000 Alexandre Julliard
5 *
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.
10 *
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.
15 *
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Alexandre Julliard7fe09bc2000-06-03 04:49:40 +000019 */
20
Patrik Stridvall33929be2001-07-18 21:04:23 +000021#include "config.h"
Patrik Stridvall9aab47e2002-08-28 23:42:34 +000022#include "wine/port.h"
Patrik Stridvall33929be2001-07-18 21:04:23 +000023
Alexandre Julliard7fe09bc2000-06-03 04:49:40 +000024#include <assert.h>
Andreas Mohr04a8eda2000-10-17 00:27:47 +000025#include <ctype.h>
James Juranf4d5fef2001-01-26 20:43:40 +000026#include <string.h>
Francois Gouget34372dc2002-03-29 18:17:35 +000027#include <sys/stat.h>
Eric Pouech3d4d7e02002-07-31 18:46:09 +000028#include <signal.h>
Alexandre Julliard7fe09bc2000-06-03 04:49:40 +000029
30#include "winbase.h"
Alexandre Julliard99d8b7f2002-07-31 19:19:36 +000031#include "wincon.h"
Patrik Stridvall9c1de6d2002-09-12 22:07:02 +000032#include "winternl.h"
Alexandre Julliard7fe09bc2000-06-03 04:49:40 +000033
Patrik Stridvall33929be2001-07-18 21:04:23 +000034#include "wine/winbase16.h"
Alexandre Julliard59008672002-05-16 20:32:16 +000035#include "wine/library.h"
Francois Gouget34372dc2002-03-29 18:17:35 +000036#include "file.h"
Patrik Stridvall33929be2001-07-18 21:04:23 +000037#include "global.h"
38#include "miscemu.h"
Alexandre Julliard7fe09bc2000-06-03 04:49:40 +000039#include "module.h"
40#include "task.h"
Eric Pouechd7d98362002-09-04 18:41:03 +000041#include "wincon.h"
42#include "console_private.h"
Alexandre Julliard7fe09bc2000-06-03 04:49:40 +000043
Alexandre Julliard66e31832002-08-15 23:18:47 +000044extern void LOCALE_Init(void);
Alexandre Julliard751625e2000-12-12 00:50:19 +000045extern BOOL RELAY_Init(void);
Martin Wilck6d886a52002-11-15 01:01:47 +000046extern void COMPUTERNAME_Init(void);
Alexandre Julliardd5041fc2000-07-25 16:42:25 +000047
Eric Pouech3d4d7e02002-07-31 18:46:09 +000048extern int __wine_set_signal_handler(unsigned, int (*)(unsigned));
Alexandre Julliard7fe09bc2000-06-03 04:49:40 +000049
Alexandre Julliard99d8b7f2002-07-31 19:19:36 +000050extern int main_create_flags;
51
Alexandre Julliard7fe09bc2000-06-03 04:49:40 +000052/***********************************************************************
53 * KERNEL process initialisation routine
54 */
55static BOOL process_attach(void)
56{
57 HMODULE16 hModule;
58
Francois Gouget34372dc2002-03-29 18:17:35 +000059 /* Get the umask */
60 FILE_umask = umask(0777);
61 umask( FILE_umask );
62
Alexandre Julliard6ce25702000-07-11 22:08:43 +000063 /* Setup codepage info */
Alexandre Julliard66e31832002-08-15 23:18:47 +000064 LOCALE_Init();
Alexandre Julliard6ce25702000-07-11 22:08:43 +000065
Alexandre Julliard751625e2000-12-12 00:50:19 +000066 /* Initialize relay entry points */
67 if (!RELAY_Init()) return FALSE;
68
Alexandre Julliard7fe09bc2000-06-03 04:49:40 +000069 /* Initialize DOS memory */
70 if (!DOSMEM_Init(0)) return FALSE;
71
Martin Wilck6d886a52002-11-15 01:01:47 +000072 /* Setup computer name */
73 COMPUTERNAME_Init();
74
Alexandre Julliard9842b192002-10-02 02:36:20 +000075 if ((hModule = LoadLibrary16( "krnl386.exe" )) >= 32)
76 {
77 /* Initialize special KERNEL entry points */
Alexandre Julliard7fe09bc2000-06-03 04:49:40 +000078
Alexandre Julliard9842b192002-10-02 02:36:20 +000079 /* Initialize KERNEL.178 (__WINFLAGS) with the correct flags value */
80 NE_SetEntryPoint( hModule, 178, GetWinFlags16() );
Alexandre Julliard7fe09bc2000-06-03 04:49:40 +000081
Alexandre Julliard9842b192002-10-02 02:36:20 +000082 /* Initialize KERNEL.454/455 (__FLATCS/__FLATDS) */
83 NE_SetEntryPoint( hModule, 454, wine_get_cs() );
84 NE_SetEntryPoint( hModule, 455, wine_get_ds() );
Alexandre Julliard7fe09bc2000-06-03 04:49:40 +000085
Alexandre Julliard9842b192002-10-02 02:36:20 +000086 /* Initialize KERNEL.THHOOK */
87 TASK_InstallTHHook(MapSL((SEGPTR)GetProcAddress16( hModule, (LPCSTR)332 )));
Alexandre Julliard7fe09bc2000-06-03 04:49:40 +000088
Alexandre Julliard9842b192002-10-02 02:36:20 +000089 /* Initialize the real-mode selector entry points */
Alexandre Julliard7fe09bc2000-06-03 04:49:40 +000090#define SET_ENTRY_POINT( num, addr ) \
91 NE_SetEntryPoint( hModule, (num), GLOBAL_CreateBlock( GMEM_FIXED, \
92 DOSMEM_MapDosToLinear(addr), 0x10000, hModule, \
Alexandre Julliard914406f2000-11-14 01:54:49 +000093 WINE_LDT_FLAGS_DATA ))
Alexandre Julliard7fe09bc2000-06-03 04:49:40 +000094
Alexandre Julliard9842b192002-10-02 02:36:20 +000095 SET_ENTRY_POINT( 174, 0xa0000 ); /* KERNEL.174: __A000H */
96 SET_ENTRY_POINT( 181, 0xb0000 ); /* KERNEL.181: __B000H */
97 SET_ENTRY_POINT( 182, 0xb8000 ); /* KERNEL.182: __B800H */
98 SET_ENTRY_POINT( 195, 0xc0000 ); /* KERNEL.195: __C000H */
99 SET_ENTRY_POINT( 179, 0xd0000 ); /* KERNEL.179: __D000H */
100 SET_ENTRY_POINT( 190, 0xe0000 ); /* KERNEL.190: __E000H */
101 NE_SetEntryPoint( hModule, 183, DOSMEM_0000H ); /* KERNEL.183: __0000H */
102 NE_SetEntryPoint( hModule, 173, DOSMEM_BiosSysSeg ); /* KERNEL.173: __ROMBIOS */
103 NE_SetEntryPoint( hModule, 193, DOSMEM_BiosDataSeg ); /* KERNEL.193: __0040H */
104 NE_SetEntryPoint( hModule, 194, DOSMEM_BiosSysSeg ); /* KERNEL.194: __F000H */
Alexandre Julliard7fe09bc2000-06-03 04:49:40 +0000105#undef SET_ENTRY_POINT
Alexandre Julliard9842b192002-10-02 02:36:20 +0000106 }
Alexandre Julliard7fe09bc2000-06-03 04:49:40 +0000107
108 /* Force loading of some dlls */
Alexandre Julliard9842b192002-10-02 02:36:20 +0000109 LoadLibrary16( "system" );
Alexandre Julliard7fe09bc2000-06-03 04:49:40 +0000110
Alexandre Julliard973ce4a2000-08-25 22:02:14 +0000111 /* Create 16-bit task */
Alexandre Julliard9ee9eff2001-02-28 05:29:50 +0000112 TASK_CreateMainTask();
Alexandre Julliard973ce4a2000-08-25 22:02:14 +0000113
Alexandre Julliard389b0392001-03-04 01:06:07 +0000114 /* Create the shared heap for broken win95 native dlls */
115 HeapCreate( HEAP_SHARED, 0, 0 );
116
Eric Pouechd7d98362002-09-04 18:41:03 +0000117 /* finish the process initialisation for console bits, if needed */
Eric Pouech3d4d7e02002-07-31 18:46:09 +0000118 __wine_set_signal_handler(SIGINT, CONSOLE_HandleCtrlC);
119
Alexandre Julliard99d8b7f2002-07-31 19:19:36 +0000120 if (main_create_flags & CREATE_NEW_CONSOLE)
121 {
122 HMODULE mod = GetModuleHandleA(0);
123 if (RtlImageNtHeader(mod)->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI)
124 AllocConsole();
125 }
Eric Pouechd7d98362002-09-04 18:41:03 +0000126 if (main_create_flags & CREATE_NEW_PROCESS_GROUP)
127 SetConsoleCtrlHandler(NULL, TRUE);
Alexandre Julliard99d8b7f2002-07-31 19:19:36 +0000128
Alexandre Julliard7fe09bc2000-06-03 04:49:40 +0000129 return TRUE;
130}
131
132/***********************************************************************
133 * KERNEL initialisation routine
134 */
135BOOL WINAPI MAIN_KernelInit( HINSTANCE hinst, DWORD reason, LPVOID reserved )
136{
Alexandre Julliard7fe09bc2000-06-03 04:49:40 +0000137 switch(reason)
138 {
139 case DLL_PROCESS_ATTACH:
Uwe Bonnesfb2f84e2000-08-21 03:33:31 +0000140 return process_attach();
Alexandre Julliard7fe09bc2000-06-03 04:49:40 +0000141 case DLL_PROCESS_DETACH:
Uwe Bonnesfb2f84e2000-08-21 03:33:31 +0000142 WriteOutProfiles16();
Alexandre Julliard7fe09bc2000-06-03 04:49:40 +0000143 break;
144 }
145 return TRUE;
146}
Alexandre Julliard3850c1a2000-08-06 02:42:46 +0000147
148/***********************************************************************
Patrik Stridvall01d5e5b2001-07-02 19:59:40 +0000149 * EnableDos (KERNEL.41)
150 * DisableDos (KERNEL.42)
151 * GetLastDiskChange (KERNEL.98)
152 * ValidateCodeSegments (KERNEL.100)
153 * KbdRst (KERNEL.123)
154 * EnableKernel (KERNEL.124)
155 * DisableKernel (KERNEL.125)
156 * ValidateFreeSpaces (KERNEL.200)
157 * K237 (KERNEL.237)
158 * BUNNY_351 (KERNEL.351)
159 * PIGLET_361 (KERNEL.361)
Alexandre Julliard3850c1a2000-08-06 02:42:46 +0000160 *
161 * Entry point for kernel functions that do nothing.
162 */
Dmitry Timoshkovfc99ddd2001-05-24 19:32:00 +0000163LONG WINAPI KERNEL_nop(void)
Andreas Mohr04a8eda2000-10-17 00:27:47 +0000164{
Dmitry Timoshkovfc99ddd2001-05-24 19:32:00 +0000165 return 0;
Andreas Mohr0bc1d272001-01-02 20:00:37 +0000166}
Aric Stewarte23c96f2002-08-16 01:38:20 +0000167
Patrik Stridvalld97f7cd2002-08-17 00:21:53 +0000168/***********************************************************************
169 * SwitchToThread (KERNEL32.@)
170 */
171
172BOOL WINAPI SwitchToThread(void)
Aric Stewarte23c96f2002-08-16 01:38:20 +0000173{
174 Sleep(0);
175 return 1;
176}