Alexandre Julliard | 7fe09bc | 2000-06-03 04:49:40 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Kernel initialization code |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 3 | * |
| 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 Julliard | 7fe09bc | 2000-06-03 04:49:40 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
Patrik Stridvall | 33929be | 2001-07-18 21:04:23 +0000 | [diff] [blame] | 21 | #include "config.h" |
Patrik Stridvall | 9aab47e | 2002-08-28 23:42:34 +0000 | [diff] [blame] | 22 | #include "wine/port.h" |
Patrik Stridvall | 33929be | 2001-07-18 21:04:23 +0000 | [diff] [blame] | 23 | |
Alexandre Julliard | 7fe09bc | 2000-06-03 04:49:40 +0000 | [diff] [blame] | 24 | #include <assert.h> |
Andreas Mohr | 04a8eda | 2000-10-17 00:27:47 +0000 | [diff] [blame] | 25 | #include <ctype.h> |
James Juran | f4d5fef | 2001-01-26 20:43:40 +0000 | [diff] [blame] | 26 | #include <string.h> |
Francois Gouget | 34372dc | 2002-03-29 18:17:35 +0000 | [diff] [blame] | 27 | #include <sys/stat.h> |
Eric Pouech | 3d4d7e0 | 2002-07-31 18:46:09 +0000 | [diff] [blame] | 28 | #include <signal.h> |
Alexandre Julliard | 7fe09bc | 2000-06-03 04:49:40 +0000 | [diff] [blame] | 29 | |
| 30 | #include "winbase.h" |
Alexandre Julliard | 99d8b7f | 2002-07-31 19:19:36 +0000 | [diff] [blame] | 31 | #include "wincon.h" |
Patrik Stridvall | 9c1de6d | 2002-09-12 22:07:02 +0000 | [diff] [blame] | 32 | #include "winternl.h" |
Alexandre Julliard | 7fe09bc | 2000-06-03 04:49:40 +0000 | [diff] [blame] | 33 | |
Patrik Stridvall | 33929be | 2001-07-18 21:04:23 +0000 | [diff] [blame] | 34 | #include "wine/winbase16.h" |
Alexandre Julliard | 5900867 | 2002-05-16 20:32:16 +0000 | [diff] [blame] | 35 | #include "wine/library.h" |
Francois Gouget | 34372dc | 2002-03-29 18:17:35 +0000 | [diff] [blame] | 36 | #include "file.h" |
Patrik Stridvall | 33929be | 2001-07-18 21:04:23 +0000 | [diff] [blame] | 37 | #include "global.h" |
| 38 | #include "miscemu.h" |
Alexandre Julliard | 7fe09bc | 2000-06-03 04:49:40 +0000 | [diff] [blame] | 39 | #include "module.h" |
| 40 | #include "task.h" |
Eric Pouech | d7d9836 | 2002-09-04 18:41:03 +0000 | [diff] [blame] | 41 | #include "wincon.h" |
| 42 | #include "console_private.h" |
Alexandre Julliard | 7fe09bc | 2000-06-03 04:49:40 +0000 | [diff] [blame] | 43 | |
Alexandre Julliard | 66e3183 | 2002-08-15 23:18:47 +0000 | [diff] [blame] | 44 | extern void LOCALE_Init(void); |
Alexandre Julliard | 751625e | 2000-12-12 00:50:19 +0000 | [diff] [blame] | 45 | extern BOOL RELAY_Init(void); |
Martin Wilck | 6d886a5 | 2002-11-15 01:01:47 +0000 | [diff] [blame] | 46 | extern void COMPUTERNAME_Init(void); |
Alexandre Julliard | d5041fc | 2000-07-25 16:42:25 +0000 | [diff] [blame] | 47 | |
Eric Pouech | 3d4d7e0 | 2002-07-31 18:46:09 +0000 | [diff] [blame] | 48 | extern int __wine_set_signal_handler(unsigned, int (*)(unsigned)); |
Alexandre Julliard | 7fe09bc | 2000-06-03 04:49:40 +0000 | [diff] [blame] | 49 | |
Alexandre Julliard | 99d8b7f | 2002-07-31 19:19:36 +0000 | [diff] [blame] | 50 | extern int main_create_flags; |
| 51 | |
Alexandre Julliard | 7fe09bc | 2000-06-03 04:49:40 +0000 | [diff] [blame] | 52 | /*********************************************************************** |
| 53 | * KERNEL process initialisation routine |
| 54 | */ |
| 55 | static BOOL process_attach(void) |
| 56 | { |
| 57 | HMODULE16 hModule; |
| 58 | |
Francois Gouget | 34372dc | 2002-03-29 18:17:35 +0000 | [diff] [blame] | 59 | /* Get the umask */ |
| 60 | FILE_umask = umask(0777); |
| 61 | umask( FILE_umask ); |
| 62 | |
Alexandre Julliard | 6ce2570 | 2000-07-11 22:08:43 +0000 | [diff] [blame] | 63 | /* Setup codepage info */ |
Alexandre Julliard | 66e3183 | 2002-08-15 23:18:47 +0000 | [diff] [blame] | 64 | LOCALE_Init(); |
Alexandre Julliard | 6ce2570 | 2000-07-11 22:08:43 +0000 | [diff] [blame] | 65 | |
Alexandre Julliard | 751625e | 2000-12-12 00:50:19 +0000 | [diff] [blame] | 66 | /* Initialize relay entry points */ |
| 67 | if (!RELAY_Init()) return FALSE; |
| 68 | |
Alexandre Julliard | 7fe09bc | 2000-06-03 04:49:40 +0000 | [diff] [blame] | 69 | /* Initialize DOS memory */ |
| 70 | if (!DOSMEM_Init(0)) return FALSE; |
| 71 | |
Martin Wilck | 6d886a5 | 2002-11-15 01:01:47 +0000 | [diff] [blame] | 72 | /* Setup computer name */ |
| 73 | COMPUTERNAME_Init(); |
| 74 | |
Alexandre Julliard | 9842b19 | 2002-10-02 02:36:20 +0000 | [diff] [blame] | 75 | if ((hModule = LoadLibrary16( "krnl386.exe" )) >= 32) |
| 76 | { |
| 77 | /* Initialize special KERNEL entry points */ |
Alexandre Julliard | 7fe09bc | 2000-06-03 04:49:40 +0000 | [diff] [blame] | 78 | |
Alexandre Julliard | 9842b19 | 2002-10-02 02:36:20 +0000 | [diff] [blame] | 79 | /* Initialize KERNEL.178 (__WINFLAGS) with the correct flags value */ |
| 80 | NE_SetEntryPoint( hModule, 178, GetWinFlags16() ); |
Alexandre Julliard | 7fe09bc | 2000-06-03 04:49:40 +0000 | [diff] [blame] | 81 | |
Alexandre Julliard | 9842b19 | 2002-10-02 02:36:20 +0000 | [diff] [blame] | 82 | /* Initialize KERNEL.454/455 (__FLATCS/__FLATDS) */ |
| 83 | NE_SetEntryPoint( hModule, 454, wine_get_cs() ); |
| 84 | NE_SetEntryPoint( hModule, 455, wine_get_ds() ); |
Alexandre Julliard | 7fe09bc | 2000-06-03 04:49:40 +0000 | [diff] [blame] | 85 | |
Alexandre Julliard | 9842b19 | 2002-10-02 02:36:20 +0000 | [diff] [blame] | 86 | /* Initialize KERNEL.THHOOK */ |
| 87 | TASK_InstallTHHook(MapSL((SEGPTR)GetProcAddress16( hModule, (LPCSTR)332 ))); |
Alexandre Julliard | 7fe09bc | 2000-06-03 04:49:40 +0000 | [diff] [blame] | 88 | |
Alexandre Julliard | 9842b19 | 2002-10-02 02:36:20 +0000 | [diff] [blame] | 89 | /* Initialize the real-mode selector entry points */ |
Alexandre Julliard | 7fe09bc | 2000-06-03 04:49:40 +0000 | [diff] [blame] | 90 | #define SET_ENTRY_POINT( num, addr ) \ |
| 91 | NE_SetEntryPoint( hModule, (num), GLOBAL_CreateBlock( GMEM_FIXED, \ |
| 92 | DOSMEM_MapDosToLinear(addr), 0x10000, hModule, \ |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 93 | WINE_LDT_FLAGS_DATA )) |
Alexandre Julliard | 7fe09bc | 2000-06-03 04:49:40 +0000 | [diff] [blame] | 94 | |
Alexandre Julliard | 9842b19 | 2002-10-02 02:36:20 +0000 | [diff] [blame] | 95 | 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 Julliard | 7fe09bc | 2000-06-03 04:49:40 +0000 | [diff] [blame] | 105 | #undef SET_ENTRY_POINT |
Alexandre Julliard | 9842b19 | 2002-10-02 02:36:20 +0000 | [diff] [blame] | 106 | } |
Alexandre Julliard | 7fe09bc | 2000-06-03 04:49:40 +0000 | [diff] [blame] | 107 | |
| 108 | /* Force loading of some dlls */ |
Alexandre Julliard | 9842b19 | 2002-10-02 02:36:20 +0000 | [diff] [blame] | 109 | LoadLibrary16( "system" ); |
Alexandre Julliard | 7fe09bc | 2000-06-03 04:49:40 +0000 | [diff] [blame] | 110 | |
Alexandre Julliard | 973ce4a | 2000-08-25 22:02:14 +0000 | [diff] [blame] | 111 | /* Create 16-bit task */ |
Alexandre Julliard | 9ee9eff | 2001-02-28 05:29:50 +0000 | [diff] [blame] | 112 | TASK_CreateMainTask(); |
Alexandre Julliard | 973ce4a | 2000-08-25 22:02:14 +0000 | [diff] [blame] | 113 | |
Alexandre Julliard | 389b039 | 2001-03-04 01:06:07 +0000 | [diff] [blame] | 114 | /* Create the shared heap for broken win95 native dlls */ |
| 115 | HeapCreate( HEAP_SHARED, 0, 0 ); |
| 116 | |
Eric Pouech | d7d9836 | 2002-09-04 18:41:03 +0000 | [diff] [blame] | 117 | /* finish the process initialisation for console bits, if needed */ |
Eric Pouech | 3d4d7e0 | 2002-07-31 18:46:09 +0000 | [diff] [blame] | 118 | __wine_set_signal_handler(SIGINT, CONSOLE_HandleCtrlC); |
| 119 | |
Alexandre Julliard | 99d8b7f | 2002-07-31 19:19:36 +0000 | [diff] [blame] | 120 | 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 Pouech | d7d9836 | 2002-09-04 18:41:03 +0000 | [diff] [blame] | 126 | if (main_create_flags & CREATE_NEW_PROCESS_GROUP) |
| 127 | SetConsoleCtrlHandler(NULL, TRUE); |
Alexandre Julliard | 99d8b7f | 2002-07-31 19:19:36 +0000 | [diff] [blame] | 128 | |
Alexandre Julliard | 7fe09bc | 2000-06-03 04:49:40 +0000 | [diff] [blame] | 129 | return TRUE; |
| 130 | } |
| 131 | |
| 132 | /*********************************************************************** |
| 133 | * KERNEL initialisation routine |
| 134 | */ |
| 135 | BOOL WINAPI MAIN_KernelInit( HINSTANCE hinst, DWORD reason, LPVOID reserved ) |
| 136 | { |
Alexandre Julliard | 7fe09bc | 2000-06-03 04:49:40 +0000 | [diff] [blame] | 137 | switch(reason) |
| 138 | { |
| 139 | case DLL_PROCESS_ATTACH: |
Uwe Bonnes | fb2f84e | 2000-08-21 03:33:31 +0000 | [diff] [blame] | 140 | return process_attach(); |
Alexandre Julliard | 7fe09bc | 2000-06-03 04:49:40 +0000 | [diff] [blame] | 141 | case DLL_PROCESS_DETACH: |
Uwe Bonnes | fb2f84e | 2000-08-21 03:33:31 +0000 | [diff] [blame] | 142 | WriteOutProfiles16(); |
Alexandre Julliard | 7fe09bc | 2000-06-03 04:49:40 +0000 | [diff] [blame] | 143 | break; |
| 144 | } |
| 145 | return TRUE; |
| 146 | } |
Alexandre Julliard | 3850c1a | 2000-08-06 02:42:46 +0000 | [diff] [blame] | 147 | |
| 148 | /*********************************************************************** |
Patrik Stridvall | 01d5e5b | 2001-07-02 19:59:40 +0000 | [diff] [blame] | 149 | * 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 Julliard | 3850c1a | 2000-08-06 02:42:46 +0000 | [diff] [blame] | 160 | * |
| 161 | * Entry point for kernel functions that do nothing. |
| 162 | */ |
Dmitry Timoshkov | fc99ddd | 2001-05-24 19:32:00 +0000 | [diff] [blame] | 163 | LONG WINAPI KERNEL_nop(void) |
Andreas Mohr | 04a8eda | 2000-10-17 00:27:47 +0000 | [diff] [blame] | 164 | { |
Dmitry Timoshkov | fc99ddd | 2001-05-24 19:32:00 +0000 | [diff] [blame] | 165 | return 0; |
Andreas Mohr | 0bc1d27 | 2001-01-02 20:00:37 +0000 | [diff] [blame] | 166 | } |
Aric Stewart | e23c96f | 2002-08-16 01:38:20 +0000 | [diff] [blame] | 167 | |
Patrik Stridvall | d97f7cd | 2002-08-17 00:21:53 +0000 | [diff] [blame] | 168 | /*********************************************************************** |
| 169 | * SwitchToThread (KERNEL32.@) |
| 170 | */ |
| 171 | |
| 172 | BOOL WINAPI SwitchToThread(void) |
Aric Stewart | e23c96f | 2002-08-16 01:38:20 +0000 | [diff] [blame] | 173 | { |
| 174 | Sleep(0); |
| 175 | return 1; |
| 176 | } |