4 * Copyright (C) 2009 Aleksey Bragin <aleksey@reactos.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program 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
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include <ndk/ldrtypes.h>
24 #include <arc/setupblk.h>
28 DBG_DEFAULT_CHANNEL(WINDOWS
);
29 #define TAG_BOOT_OPTIONS 'pOtB'
32 WinLdrSetupMachineDependent(PLOADER_PARAMETER_BLOCK LoaderBlock
);
35 WinLdrSetProcessorContext(void);
38 VOID
AllocateAndInitLPB(PLOADER_PARAMETER_BLOCK
*OutLoaderBlock
);
41 SetupLdrLoadNlsData(PLOADER_PARAMETER_BLOCK LoaderBlock
, HINF InfHandle
, LPCSTR SearchPath
)
43 INFCONTEXT InfContext
;
45 LPCSTR AnsiName
, OemName
, LangName
;
47 /* Get ANSI codepage file */
48 if (!InfFindFirstLine(InfHandle
, "NLS", "AnsiCodepage", &InfContext
))
50 ERR("Failed to find 'NLS/AnsiCodepage'\n");
53 if (!InfGetDataField(&InfContext
, 1, &AnsiName
))
55 ERR("Failed to get load options\n");
59 /* Get OEM codepage file */
60 if (!InfFindFirstLine(InfHandle
, "NLS", "OemCodepage", &InfContext
))
62 ERR("Failed to find 'NLS/AnsiCodepage'\n");
65 if (!InfGetDataField(&InfContext
, 1, &OemName
))
67 ERR("Failed to get load options\n");
71 if (!InfFindFirstLine(InfHandle
, "NLS", "UnicodeCasetable", &InfContext
))
73 ERR("Failed to find 'NLS/AnsiCodepage'\n");
76 if (!InfGetDataField(&InfContext
, 1, &LangName
))
78 ERR("Failed to get load options\n");
82 Success
= WinLdrLoadNLSData(LoaderBlock
, SearchPath
, AnsiName
, OemName
, LangName
);
83 TRACE("NLS data loading %s\n", Success
? "successful" : "failed");
87 SetupLdrScanBootDrivers(PLIST_ENTRY BootDriverListHead
, HINF InfHandle
, LPCSTR SearchPath
)
89 INFCONTEXT InfContext
, dirContext
;
91 LPCSTR Media
, DriverName
, dirIndex
, ImagePath
;
92 WCHAR ServiceName
[256];
93 WCHAR ImagePathW
[256];
95 /* Open inf section */
96 if (!InfFindFirstLine(InfHandle
, "SourceDisksFiles", NULL
, &InfContext
))
99 /* Load all listed boot drivers */
102 if (InfGetDataField(&InfContext
, 7, &Media
) &&
103 InfGetDataField(&InfContext
, 0, &DriverName
) &&
104 InfGetDataField(&InfContext
, 13, &dirIndex
))
106 if ((strcmp(Media
, "x") == 0) &&
107 InfFindFirstLine(InfHandle
, "Directories", dirIndex
, &dirContext
) &&
108 InfGetDataField(&dirContext
, 1, &ImagePath
))
110 /* Convert name to widechar */
111 swprintf(ServiceName
, L
"%S", DriverName
);
113 /* Prepare image path */
114 swprintf(ImagePathW
, L
"%S", ImagePath
);
115 wcscat(ImagePathW
, L
"\\");
116 wcscat(ImagePathW
, ServiceName
);
118 /* Remove .sys extension */
119 ServiceName
[wcslen(ServiceName
) - 4] = 0;
121 /* Add it to the list */
122 Success
= WinLdrAddDriverToList(BootDriverListHead
,
123 L
"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\",
128 ERR("could not add boot driver %s, %s\n", SearchPath
, DriverName
);
133 } while (InfFindNextLine(&InfContext
, &InfContext
));
137 LoadReactOSSetup(IN OperatingSystemItem
* OperatingSystem
,
138 IN USHORT OperatingSystemVersion
)
141 PCSTR SectionName
= OperatingSystem
->SystemPartition
;
142 CHAR SettingsValue
[80];
144 CHAR BootOptions2
[256];
150 BOOLEAN BootFromFloppy
;
153 INFCONTEXT InfContext
;
154 PLOADER_PARAMETER_BLOCK LoaderBlock
;
155 PSETUP_LOADER_BLOCK SetupBlock
;
157 LPCSTR SourcePaths
[] =
159 "", /* Only for floppy boot */
162 #elif defined(_M_MPPC)
164 #elif defined(_M_MRX000)
171 /* Get OS setting value */
172 SettingsValue
[0] = ANSI_NULL
;
173 IniOpenSection("Operating Systems", &SectionId
);
174 IniReadSettingByName(SectionId
, SectionName
, SettingsValue
, sizeof(SettingsValue
));
176 /* Open the operating system section specified in the .ini file */
177 HasSection
= IniOpenSection(SectionName
, &SectionId
);
180 UiDrawProgressBarCenter(1, 100, "Loading ReactOS Setup...");
182 /* Read the system path is set in the .ini file */
184 !IniReadSettingByName(SectionId
, "SystemPath", BootPath
, sizeof(BootPath
)))
187 * IMPROVE: I don't want to call MachDiskGetBootPath here as a
188 * default choice because I can call it after (see few lines below).
189 * Also doing the strcpy call as it is done in winldr.c is not
190 * really what we want. Instead I reset BootPath here so that
191 * we can build the full path using the general code from below.
193 // MachDiskGetBootPath(BootPath, sizeof(BootPath));
194 // strcpy(BootPath, SectionName);
199 * Check whether BootPath is a full path
200 * and if not, create a full boot path.
202 * See FsOpenFile for the technique used.
204 if (strrchr(BootPath
, ')') == NULL
)
206 /* Temporarily save the boot path */
207 strcpy(FileName
, BootPath
);
209 /* This is not a full path. Use the current (i.e. boot) device. */
210 MachDiskGetBootPath(BootPath
, sizeof(BootPath
));
212 /* Append a path separator if needed */
213 if (FileName
[0] != '\\' && FileName
[0] != '/')
214 strcat(BootPath
, "\\");
216 /* Append the remaining path */
217 strcat(BootPath
, FileName
);
220 /* Append a backslash if needed */
221 if ((strlen(BootPath
) == 0) || BootPath
[strlen(BootPath
) - 1] != '\\')
222 strcat(BootPath
, "\\");
224 /* Read booting options */
225 if (!HasSection
|| !IniReadSettingByName(SectionId
, "Options", BootOptions2
, sizeof(BootOptions2
)))
227 /* Get options after the title */
228 PCSTR p
= SettingsValue
;
229 while (*p
== ' ' || *p
== '"')
231 while (*p
!= '\0' && *p
!= '"')
233 strcpy(BootOptions2
, p
);
234 TRACE("BootOptions: '%s'\n", BootOptions2
);
237 /* Check if a ramdisk file was given */
238 File
= strstr(BootOptions2
, "/RDPATH=");
241 /* Copy the file name and everything else after it */
242 strcpy(FileName
, File
+ 8);
245 *strstr(FileName
, " ") = ANSI_NULL
;
247 /* Load the ramdisk */
248 if (!RamDiskLoadVirtualFile(FileName
))
250 UiMessageBox("Failed to load RAM disk file %s", FileName
);
255 TRACE("BootPath: '%s'\n", BootPath
);
257 /* And check if we booted from floppy */
258 BootFromFloppy
= strstr(BootPath
, "fdisk") != NULL
;
260 /* Open 'txtsetup.sif' from any of source paths */
261 File
= BootPath
+ strlen(BootPath
);
262 for (i
= BootFromFloppy
? 0 : 1; ; i
++)
264 SystemPath
= SourcePaths
[i
];
267 UiMessageBox("Failed to open txtsetup.sif");
270 strcpy(File
, SystemPath
);
271 strcpy(FileName
, BootPath
);
272 strcat(FileName
, "txtsetup.sif");
273 if (InfOpenFile(&InfHandle
, FileName
, &ErrorLine
))
279 TRACE("BootPath: '%s', SystemPath: '%s'\n", BootPath
, SystemPath
);
281 /* Get Load options - debug and non-debug */
282 if (!InfFindFirstLine(InfHandle
, "SetupData", "OsLoadOptions", &InfContext
))
284 ERR("Failed to find 'SetupData/OsLoadOptions'\n");
288 if (!InfGetDataField(&InfContext
, 1, &LoadOptions
))
290 ERR("Failed to get load options\n");
295 /* Get debug load options and use them */
296 if (InfFindFirstLine(InfHandle
, "SetupData", "DbgOsLoadOptions", &InfContext
))
298 LPCSTR DbgLoadOptions
;
300 if (InfGetDataField(&InfContext
, 1, &DbgLoadOptions
))
301 LoadOptions
= DbgLoadOptions
;
305 /* Copy loadoptions (original string will be freed) */
306 BootOptions
= FrLdrTempAlloc(strlen(LoadOptions
) + 1, TAG_BOOT_OPTIONS
);
307 strcpy(BootOptions
, LoadOptions
);
309 TRACE("BootOptions: '%s'\n", BootOptions
);
311 UiDrawStatusText("Setup is loading...");
313 /* Allocate and minimalistic-initialize LPB */
314 AllocateAndInitLPB(&LoaderBlock
);
316 /* Allocate and initialize setup loader block */
317 SetupBlock
= &WinLdrSystemBlock
->SetupBlock
;
318 LoaderBlock
->SetupLdrBlock
= SetupBlock
;
320 /* Set textmode setup flag */
321 SetupBlock
->Flags
= SETUPLDR_TEXT_MODE
;
323 /* Load NLS data, they are in system32 */
324 strcpy(FileName
, BootPath
);
325 strcat(FileName
, "system32\\");
326 SetupLdrLoadNlsData(LoaderBlock
, InfHandle
, FileName
);
328 /* Get a list of boot drivers */
329 SetupLdrScanBootDrivers(&LoaderBlock
->BootDriverListHead
, InfHandle
, BootPath
);
331 /* Close the inf file */
332 InfCloseFile(InfHandle
);
334 /* Load ReactOS Setup */
335 LoadAndBootWindowsCommon(_WIN32_WINNT_WS03
,