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.
24 #include <ndk/ldrtypes.h>
25 #include <arc/setupblk.h>
29 DBG_DEFAULT_CHANNEL(WINDOWS
);
30 #define TAG_BOOT_OPTIONS 'pOtB'
33 VOID
AllocateAndInitLPB(PLOADER_PARAMETER_BLOCK
*OutLoaderBlock
);
36 SetupLdrLoadNlsData(PLOADER_PARAMETER_BLOCK LoaderBlock
, HINF InfHandle
, LPCSTR SearchPath
)
38 INFCONTEXT InfContext
;
39 LPCSTR AnsiName
, OemName
, LangName
;
41 /* Get ANSI codepage file */
42 if (!InfFindFirstLine(InfHandle
, "NLS", "AnsiCodepage", &InfContext
))
44 ERR("Failed to find 'NLS/AnsiCodepage'\n");
47 if (!InfGetDataField(&InfContext
, 1, &AnsiName
))
49 ERR("Failed to get load options\n");
53 /* Get OEM codepage file */
54 if (!InfFindFirstLine(InfHandle
, "NLS", "OemCodepage", &InfContext
))
56 ERR("Failed to find 'NLS/AnsiCodepage'\n");
59 if (!InfGetDataField(&InfContext
, 1, &OemName
))
61 ERR("Failed to get load options\n");
65 if (!InfFindFirstLine(InfHandle
, "NLS", "UnicodeCasetable", &InfContext
))
67 ERR("Failed to find 'NLS/AnsiCodepage'\n");
70 if (!InfGetDataField(&InfContext
, 1, &LangName
))
72 ERR("Failed to get load options\n");
76 TRACE("NLS data %s %s %s\n", AnsiName
, OemName
, LangName
);
80 BOOLEAN Success
= WinLdrLoadNLSData(LoaderBlock
, SearchPath
, AnsiName
, OemName
, LangName
);
81 TRACE("NLS data loading %s\n", Success
? "successful" : "failed");
84 WinLdrLoadNLSData(LoaderBlock
, SearchPath
, AnsiName
, OemName
, LangName
);
87 /* TODO: Load OEM HAL font */
92 SetupLdrScanBootDrivers(PLIST_ENTRY BootDriverListHead
, HINF InfHandle
, LPCSTR SearchPath
)
94 INFCONTEXT InfContext
, dirContext
;
96 LPCSTR Media
, DriverName
, dirIndex
, ImagePath
;
97 WCHAR ServiceName
[256];
98 WCHAR ImagePathW
[256];
100 /* Open inf section */
101 if (!InfFindFirstLine(InfHandle
, "SourceDisksFiles", NULL
, &InfContext
))
104 /* Load all listed boot drivers */
107 if (InfGetDataField(&InfContext
, 7, &Media
) &&
108 InfGetDataField(&InfContext
, 0, &DriverName
) &&
109 InfGetDataField(&InfContext
, 13, &dirIndex
))
111 if ((strcmp(Media
, "x") == 0) &&
112 InfFindFirstLine(InfHandle
, "Directories", dirIndex
, &dirContext
) &&
113 InfGetDataField(&dirContext
, 1, &ImagePath
))
115 /* Convert name to widechar */
116 swprintf(ServiceName
, L
"%S", DriverName
);
118 /* Prepare image path */
119 swprintf(ImagePathW
, L
"%S", ImagePath
);
120 wcscat(ImagePathW
, L
"\\");
121 wcscat(ImagePathW
, ServiceName
);
123 /* Remove .sys extension */
124 ServiceName
[wcslen(ServiceName
) - 4] = 0;
126 /* Add it to the list */
127 Success
= WinLdrAddDriverToList(BootDriverListHead
,
128 L
"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\",
133 ERR("could not add boot driver %s, %s\n", SearchPath
, DriverName
);
138 } while (InfFindNextLine(&InfContext
, &InfContext
));
142 /* SETUP STARTER **************************************************************/
145 LoadReactOSSetup(IN OperatingSystemItem
* OperatingSystem
,
146 IN USHORT OperatingSystemVersion
)
149 PCSTR SectionName
= OperatingSystem
->SystemPartition
;
150 CHAR SettingsValue
[80];
152 CHAR BootOptions2
[256];
158 BOOLEAN BootFromFloppy
;
162 INFCONTEXT InfContext
;
163 PLOADER_PARAMETER_BLOCK LoaderBlock
;
164 PSETUP_LOADER_BLOCK SetupBlock
;
166 LPCSTR SourcePaths
[] =
168 "", /* Only for floppy boot */
171 #elif defined(_M_MPPC)
173 #elif defined(_M_MRX000)
180 UiDrawStatusText("Setup is loading...");
182 /* Get OS setting value */
183 SettingsValue
[0] = ANSI_NULL
;
184 IniOpenSection("Operating Systems", &SectionId
);
185 IniReadSettingByName(SectionId
, SectionName
, SettingsValue
, sizeof(SettingsValue
));
187 /* Open the operating system section specified in the .ini file */
188 HasSection
= IniOpenSection(SectionName
, &SectionId
);
191 UiDrawProgressBarCenter(1, 100, "Loading ReactOS Setup...");
193 /* Read the system path is set in the .ini file */
195 !IniReadSettingByName(SectionId
, "SystemPath", BootPath
, sizeof(BootPath
)))
198 * IMPROVE: I don't want to call MachDiskGetBootPath here as a
199 * default choice because I can call it after (see few lines below).
200 * Also doing the strcpy call as it is done in winldr.c is not
201 * really what we want. Instead I reset BootPath here so that
202 * we can build the full path using the general code from below.
204 // MachDiskGetBootPath(BootPath, sizeof(BootPath));
205 // strcpy(BootPath, SectionName);
210 * Check whether BootPath is a full path
211 * and if not, create a full boot path.
213 * See FsOpenFile for the technique used.
215 if (strrchr(BootPath
, ')') == NULL
)
217 /* Temporarily save the boot path */
218 strcpy(FileName
, BootPath
);
220 /* This is not a full path. Use the current (i.e. boot) device. */
221 MachDiskGetBootPath(BootPath
, sizeof(BootPath
));
223 /* Append a path separator if needed */
224 if (FileName
[0] != '\\' && FileName
[0] != '/')
225 strcat(BootPath
, "\\");
227 /* Append the remaining path */
228 strcat(BootPath
, FileName
);
231 /* Append a backslash if needed */
232 if ((strlen(BootPath
) == 0) || BootPath
[strlen(BootPath
) - 1] != '\\')
233 strcat(BootPath
, "\\");
235 /* Read booting options */
236 if (!HasSection
|| !IniReadSettingByName(SectionId
, "Options", BootOptions2
, sizeof(BootOptions2
)))
238 /* Get options after the title */
239 PCSTR p
= SettingsValue
;
240 while (*p
== ' ' || *p
== '"')
242 while (*p
!= '\0' && *p
!= '"')
244 strcpy(BootOptions2
, p
);
245 TRACE("BootOptions: '%s'\n", BootOptions2
);
248 /* Check if a ramdisk file was given */
249 File
= strstr(BootOptions2
, "/RDPATH=");
252 /* Copy the file name and everything else after it */
253 strcpy(FileName
, File
+ 8);
256 *strstr(FileName
, " ") = ANSI_NULL
;
258 /* Load the ramdisk */
259 if (!RamDiskLoadVirtualFile(FileName
))
261 UiMessageBox("Failed to load RAM disk file %s", FileName
);
266 TRACE("BootPath: '%s'\n", BootPath
);
268 /* And check if we booted from floppy */
269 BootFromFloppy
= strstr(BootPath
, "fdisk") != NULL
;
271 /* Open 'txtsetup.sif' from any of source paths */
272 File
= BootPath
+ strlen(BootPath
);
273 for (i
= BootFromFloppy
? 0 : 1; ; i
++)
275 SystemPath
= SourcePaths
[i
];
278 UiMessageBox("Failed to open txtsetup.sif");
281 strcpy(File
, SystemPath
);
282 strcpy(FileName
, BootPath
);
283 strcat(FileName
, "txtsetup.sif");
284 if (InfOpenFile(&InfHandle
, FileName
, &ErrorLine
))
290 TRACE("BootPath: '%s', SystemPath: '%s'\n", BootPath
, SystemPath
);
292 /* Get Load options - debug and non-debug */
293 if (!InfFindFirstLine(InfHandle
, "SetupData", "OsLoadOptions", &InfContext
))
295 ERR("Failed to find 'SetupData/OsLoadOptions'\n");
299 if (!InfGetDataField(&InfContext
, 1, &LoadOptions
))
301 ERR("Failed to get load options\n");
306 /* Get debug load options and use them */
307 if (InfFindFirstLine(InfHandle
, "SetupData", "DbgOsLoadOptions", &InfContext
))
309 LPCSTR DbgLoadOptions
;
311 if (InfGetDataField(&InfContext
, 1, &DbgLoadOptions
))
312 LoadOptions
= DbgLoadOptions
;
316 /* Copy loadoptions (original string will be freed) */
317 BootOptions
= FrLdrTempAlloc(strlen(LoadOptions
) + 1, TAG_BOOT_OPTIONS
);
318 strcpy(BootOptions
, LoadOptions
);
320 TRACE("BootOptions: '%s'\n", BootOptions
);
322 /* Allocate and minimalist-initialize LPB */
323 AllocateAndInitLPB(&LoaderBlock
);
325 /* Allocate and initialize setup loader block */
326 SetupBlock
= &WinLdrSystemBlock
->SetupBlock
;
327 LoaderBlock
->SetupLdrBlock
= SetupBlock
;
329 /* Set textmode setup flag */
330 SetupBlock
->Flags
= SETUPLDR_TEXT_MODE
;
332 /* Load the system hive "setupreg.hiv" for setup */
334 UiDrawProgressBarCenter(15, 100, "Loading setup system hive...");
335 Success
= WinLdrInitSystemHive(LoaderBlock
, BootPath
, TRUE
);
336 TRACE("Setup SYSTEM hive %s\n", (Success
? "loaded" : "not loaded"));
337 /* Bail out if failure */
341 /* Load NLS data, they are in the System32 directory of the installation medium */
342 strcpy(FileName
, BootPath
);
343 strcat(FileName
, "system32\\");
344 SetupLdrLoadNlsData(LoaderBlock
, InfHandle
, FileName
);
346 // UiDrawStatusText("Press F6 if you need to install a 3rd-party SCSI or RAID driver...");
348 /* Get a list of boot drivers */
349 SetupLdrScanBootDrivers(&LoaderBlock
->BootDriverListHead
, InfHandle
, BootPath
);
351 /* Close the inf file */
352 InfCloseFile(InfHandle
);
354 UiDrawStatusText("The Setup program is starting...");
356 /* Load ReactOS Setup */
357 LoadAndBootWindowsCommon(_WIN32_WINNT_WS03
,