Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygensetupldr.c
Go to the documentation of this file.
00001 /* 00002 * FreeLoader 00003 * 00004 * Copyright (C) 2009 Aleksey Bragin <aleksey@reactos.org> 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License along 00017 * with this program; if not, write to the Free Software Foundation, Inc., 00018 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00019 */ 00020 00021 #include <freeldr.h> 00022 00023 #include <ndk/ldrtypes.h> 00024 #include <arc/setupblk.h> 00025 00026 #include <debug.h> 00027 00028 DBG_DEFAULT_CHANNEL(WINDOWS); 00029 00030 void 00031 WinLdrSetupMachineDependent(PLOADER_PARAMETER_BLOCK LoaderBlock); 00032 00033 VOID 00034 WinLdrSetProcessorContext(void); 00035 00036 // TODO: Move to .h 00037 VOID AllocateAndInitLPB(PLOADER_PARAMETER_BLOCK *OutLoaderBlock); 00038 00039 static VOID 00040 SetupLdrLoadNlsData(PLOADER_PARAMETER_BLOCK LoaderBlock, HINF InfHandle, LPCSTR SearchPath) 00041 { 00042 INFCONTEXT InfContext; 00043 BOOLEAN Status; 00044 LPCSTR AnsiName, OemName, LangName; 00045 00046 /* Get ANSI codepage file */ 00047 if (!InfFindFirstLine(InfHandle, "NLS", "AnsiCodepage", &InfContext)) 00048 { 00049 ERR("Failed to find 'NLS/AnsiCodepage'\n"); 00050 return; 00051 } 00052 if (!InfGetDataField(&InfContext, 1, &AnsiName)) 00053 { 00054 ERR("Failed to get load options\n"); 00055 return; 00056 } 00057 00058 /* Get OEM codepage file */ 00059 if (!InfFindFirstLine(InfHandle, "NLS", "OemCodepage", &InfContext)) 00060 { 00061 ERR("Failed to find 'NLS/AnsiCodepage'\n"); 00062 return; 00063 } 00064 if (!InfGetDataField(&InfContext, 1, &OemName)) 00065 { 00066 ERR("Failed to get load options\n"); 00067 return; 00068 } 00069 00070 if (!InfFindFirstLine(InfHandle, "NLS", "UnicodeCasetable", &InfContext)) 00071 { 00072 ERR("Failed to find 'NLS/AnsiCodepage'\n"); 00073 return; 00074 } 00075 if (!InfGetDataField(&InfContext, 1, &LangName)) 00076 { 00077 ERR("Failed to get load options\n"); 00078 return; 00079 } 00080 00081 Status = WinLdrLoadNLSData(LoaderBlock, SearchPath, AnsiName, OemName, LangName); 00082 TRACE("NLS data loaded with status %d\n", Status); 00083 } 00084 00085 static VOID 00086 SetupLdrScanBootDrivers(PLIST_ENTRY BootDriverListHead, HINF InfHandle, LPCSTR SearchPath) 00087 { 00088 INFCONTEXT InfContext, dirContext; 00089 BOOLEAN Status; 00090 LPCSTR Media, DriverName, dirIndex, ImagePath; 00091 WCHAR ServiceName[256]; 00092 WCHAR ImagePathW[256]; 00093 00094 /* Open inf section */ 00095 if (!InfFindFirstLine(InfHandle, "SourceDisksFiles", NULL, &InfContext)) 00096 return; 00097 00098 /* Load all listed boot drivers */ 00099 do 00100 { 00101 if (InfGetDataField(&InfContext, 7, &Media) && 00102 InfGetDataField(&InfContext, 0, &DriverName) && 00103 InfGetDataField(&InfContext, 13, &dirIndex)) 00104 { 00105 if ((strcmp(Media, "x") == 0) && 00106 InfFindFirstLine(InfHandle, "Directories", dirIndex, &dirContext) && 00107 InfGetDataField(&dirContext, 1, &ImagePath)) 00108 { 00109 /* Convert name to widechar */ 00110 swprintf(ServiceName, L"%S", DriverName); 00111 00112 /* Prepare image path */ 00113 swprintf(ImagePathW, L"%S", ImagePath); 00114 wcscat(ImagePathW, L"\\"); 00115 wcscat(ImagePathW, ServiceName); 00116 00117 /* Remove .sys extension */ 00118 ServiceName[wcslen(ServiceName) - 4] = 0; 00119 00120 /* Add it to the list */ 00121 Status = WinLdrAddDriverToList(BootDriverListHead, 00122 L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\", 00123 ImagePathW, 00124 ServiceName); 00125 00126 if (!Status) 00127 { 00128 ERR("could not add boot driver %s, %s\n", SearchPath, DriverName); 00129 return; 00130 } 00131 } 00132 } 00133 } while (InfFindNextLine(&InfContext, &InfContext)); 00134 } 00135 00136 VOID LoadReactOSSetup(VOID) 00137 { 00138 CHAR FileName[512]; 00139 CHAR BootPath[512]; 00140 LPCSTR LoadOptions, BootOptions; 00141 BOOLEAN BootFromFloppy; 00142 ULONG i, ErrorLine; 00143 HINF InfHandle; 00144 INFCONTEXT InfContext; 00145 PLOADER_PARAMETER_BLOCK LoaderBlock; 00146 PSETUP_LOADER_BLOCK SetupBlock; 00147 LPCSTR SystemPath; 00148 LPCSTR SourcePaths[] = 00149 { 00150 "\\", /* Only for floppy boot */ 00151 #if defined(_M_IX86) 00152 "\\I386\\", 00153 #elif defined(_M_MPPC) 00154 "\\PPC\\", 00155 #elif defined(_M_MRX000) 00156 "\\MIPS\\", 00157 #endif 00158 "\\reactos\\", 00159 NULL 00160 }; 00161 00162 /* Get boot path */ 00163 MachDiskGetBootPath(BootPath, sizeof(BootPath)); 00164 00165 /* And check if we booted from floppy */ 00166 BootFromFloppy = strstr(BootPath, "fdisk") != NULL; 00167 00168 /* Open 'txtsetup.sif' from any of source paths */ 00169 for (i = BootFromFloppy ? 0 : 1; ; i++) 00170 { 00171 SystemPath = SourcePaths[i]; 00172 if (!SystemPath) 00173 { 00174 ERR("Failed to open txtsetup.sif\n"); 00175 return; 00176 } 00177 sprintf(FileName, "%stxtsetup.sif", SystemPath); 00178 if (InfOpenFile (&InfHandle, FileName, &ErrorLine)) 00179 { 00180 strcat(BootPath, SystemPath); 00181 break; 00182 } 00183 } 00184 00185 TRACE("BootPath: '%s', SystemPath: '%s'\n", BootPath, SystemPath); 00186 00187 /* Get Load options - debug and non-debug */ 00188 if (!InfFindFirstLine(InfHandle, "SetupData", "OsLoadOptions", &InfContext)) 00189 { 00190 ERR("Failed to find 'SetupData/OsLoadOptions'\n"); 00191 return; 00192 } 00193 00194 if (!InfGetDataField (&InfContext, 1, &LoadOptions)) 00195 { 00196 ERR("Failed to get load options\n"); 00197 return; 00198 } 00199 00200 BootOptions = LoadOptions; 00201 00202 #if DBG 00203 /* Get debug load options and use them */ 00204 if (InfFindFirstLine(InfHandle, "SetupData", "DbgOsLoadOptions", &InfContext)) 00205 { 00206 if (InfGetDataField(&InfContext, 1, &LoadOptions)) 00207 BootOptions = LoadOptions; 00208 } 00209 #endif 00210 00211 TRACE("BootOptions: '%s'\n", BootOptions); 00212 00213 //SetupUiInitialize(); 00214 UiDrawStatusText(""); 00215 00216 /* Allocate and minimalistic-initialize LPB */ 00217 AllocateAndInitLPB(&LoaderBlock); 00218 00219 /* Allocate and initialize setup loader block */ 00220 SetupBlock = &WinLdrSystemBlock->SetupBlock; 00221 LoaderBlock->SetupLdrBlock = SetupBlock; 00222 00223 /* Set textmode setup flag */ 00224 SetupBlock->Flags = SETUPLDR_TEXT_MODE; 00225 00226 /* Load NLS data, they are in system32 */ 00227 strcpy(FileName, BootPath); 00228 strcat(FileName, "system32\\"); 00229 SetupLdrLoadNlsData(LoaderBlock, InfHandle, FileName); 00230 00231 /* Get a list of boot drivers */ 00232 SetupLdrScanBootDrivers(&LoaderBlock->BootDriverListHead, InfHandle, BootPath); 00233 00234 00235 LoadAndBootWindowsCommon(_WIN32_WINNT_WS03, 00236 LoaderBlock, 00237 BootOptions, 00238 BootPath, 00239 1); 00240 } Generated on Sat May 26 2012 04:18:05 for ReactOS by
1.7.6.1
|