ReactOS 0.4.17-dev-116-ga4b6fe9
winldr.h File Reference
#include <arc/setupblk.h>
#include <pshpack1.h>
#include <poppack.h>
Include dependency graph for winldr.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  RSDP_DESCRIPTOR
 
struct  _ARC_DISK_SIGNATURE_EX
 

Macros

#define TAG_WLDR_DTE   'eDlW'
 
#define TAG_WLDR_BDE   'dBlW'
 
#define TAG_WLDR_NAME   'mNlW'
 
#define BOOT_LOGGING   (1 << 0)
 
#define BOOT_VGA_MODE   (1 << 1)
 
#define BOOT_DEBUGGING   (1 << 2)
 

Typedefs

typedef struct RSDP_DESCRIPTORPRSDP_DESCRIPTOR
 
typedef struct _ARC_DISK_SIGNATURE_EX ARC_DISK_SIGNATURE_EX
 
typedef struct _ARC_DISK_SIGNATURE_EXPARC_DISK_SIGNATURE_EX
 

Enumerations

enum  SAFEBOOT_MODE {
  NO_OPTION = 0 , SAFEBOOT , SAFEBOOT_NETWORK , SAFEBOOT_ALTSHELL ,
  SAFEBOOT_DSREPAIR , LKG_CONFIG
}
 

Functions

VOID MenuNTOptions (_Inout_ OperatingSystemItem *OperatingSystem)
 
VOID AppendBootTimeOptions (_Inout_z_bytecount_(BootOptionsSize) PSTR BootOptions, _In_ SIZE_T BootOptionsSize)
 
ARC_STATUS LoadAndBootWindows (IN ULONG Argc, IN PCHAR Argv[], IN PCHAR Envp[])
 
ARC_STATUS LoadReactOSSetup (IN ULONG Argc, IN PCHAR Argv[], IN PCHAR Envp[])
 
PVOID VaToPa (PVOID Va)
 
PVOID PaToVa (PVOID Pa)
 
VOID List_PaToVa (_In_ LIST_ENTRY *ListEntry)
 

Variables

enum SAFEBOOT_MODE BootOptionChoice
 
LOGICAL BootFlags
 

Macro Definition Documentation

◆ BOOT_DEBUGGING

#define BOOT_DEBUGGING   (1 << 2)

Definition at line 69 of file winldr.h.

◆ BOOT_LOGGING

#define BOOT_LOGGING   (1 << 0)

Definition at line 67 of file winldr.h.

◆ BOOT_VGA_MODE

#define BOOT_VGA_MODE   (1 << 1)

Definition at line 68 of file winldr.h.

◆ TAG_WLDR_BDE

#define TAG_WLDR_BDE   'dBlW'

Definition at line 14 of file winldr.h.

◆ TAG_WLDR_DTE

#define TAG_WLDR_DTE   'eDlW'

Definition at line 13 of file winldr.h.

◆ TAG_WLDR_NAME

#define TAG_WLDR_NAME   'mNlW'

Definition at line 15 of file winldr.h.

Typedef Documentation

◆ ARC_DISK_SIGNATURE_EX

◆ PARC_DISK_SIGNATURE_EX

◆ PRSDP_DESCRIPTOR

Enumeration Type Documentation

◆ SAFEBOOT_MODE

Enumerator
NO_OPTION 
SAFEBOOT 
SAFEBOOT_NETWORK 
SAFEBOOT_ALTSHELL 
SAFEBOOT_DSREPAIR 
LKG_CONFIG 

Definition at line 47 of file winldr.h.

48{
49 NO_OPTION = 0,
50
55
56 LKG_CONFIG, // TODO: Make it exclusive? Or allow it to be combined with SafeBoot?
57};
@ SAFEBOOT
Definition: winldr.h:51
@ LKG_CONFIG
Definition: winldr.h:56
@ SAFEBOOT_DSREPAIR
Definition: winldr.h:54
@ SAFEBOOT_NETWORK
Definition: winldr.h:52
@ SAFEBOOT_ALTSHELL
Definition: winldr.h:53
@ NO_OPTION
Definition: winldr.h:49

Function Documentation

◆ AppendBootTimeOptions()

VOID AppendBootTimeOptions ( _Inout_z_bytecount_(BootOptionsSize) PSTR  BootOptions,
_In_ SIZE_T  BootOptionsSize 
)

Definition at line 282 of file advopts.c.

286{
287 /* NOTE: Keep in sync with the 'enum SAFEBOOT_MODE' in winldr.h */
288 static const PCSTR OptionsStr[] =
289 {
290 /* NO_OPTION */ NULL,
291 /* SAFEBOOT */ "SAFEBOOT:MINIMAL SOS NOGUIBOOT",
292 /* SAFEBOOT_NETWORK */ "SAFEBOOT:NETWORK SOS NOGUIBOOT",
293 /* SAFEBOOT_ALTSHELL */ "SAFEBOOT:MINIMAL(ALTERNATESHELL) SOS NOGUIBOOT",
294 /* SAFEBOOT_DSREPAIR */ "SAFEBOOT:DSREPAIR SOS",
295 /* LKG_CONFIG */ NULL,
296 };
297
298 PCSTR OptionsToAdd[2] = {NULL};
299 PCSTR OptionsToRemove[2] = {NULL};
300
301 if (BootOptionsSize < sizeof(CHAR))
302 return;
303
304#if DBG && defined(_M_IX86) // x86 *ONLY*: HAL/Kernel auto-detection override
305 if ((HALAutoDetectMode != BOOT_AUTODETECT) && (HALAutoDetectMode <= BOOT_ACPI_SMP))
306 {
307 static const PCSTR AutoDetectOptions[] =
308 {
309 /* BOOT_AUTODETECT */ NULL,
310 /* BOOT_ACPI_APIC */ "HAL=halaacpi.dll",
311 /* BOOT_ACPI_SMP */ "HAL=halmacpi.dll KERNEL=ntkrnlmp.exe",
312 };
313 PCSTR OptionsToRemove[] = {"/HAL=/KERNEL=", "/DETECTHAL", NULL};
314
315 OptionsToAdd[0] = AutoDetectOptions[HALAutoDetectMode];
316 NtLdrUpdateOptions(BootOptions, BootOptionsSize, FALSE,
317 OptionsToAdd, OptionsToRemove);
318 }
319#endif
320
321 switch (BootOptionChoice)
322 {
323 case SAFEBOOT:
324 case SAFEBOOT_NETWORK:
327 {
329
330 /* SAFEBOOT(:) options are self-excluding */
331 OptionsToAdd[0] = OptionsStr[BootOptionChoice];
332 OptionsToRemove[0] = "/SAFEBOOT/SAFEBOOT:";
333 NtLdrUpdateOptions(BootOptions, BootOptionsSize, TRUE,
334 OptionsToAdd, OptionsToRemove);
335 break;
336 }
337
338 case LKG_CONFIG:
339 DbgPrint("Last known good configuration is not yet supported!\n");
340 break;
341
342 default:
343 break;
344 }
345
347 NtLdrAddOptions(BootOptions, BootOptionsSize, TRUE, "BOOTLOG");
348
350 NtLdrAddOptions(BootOptions, BootOptionsSize, TRUE, "BASEVIDEO");
351
353 {
354 /* Remove NODEBUG if present, since we want to have debugging enabled */
355 OptionsToAdd[0] = "DEBUG";
356 OptionsToRemove[0] = "NODEBUG";
357 NtLdrUpdateOptions(BootOptions, BootOptionsSize, TRUE,
358 OptionsToAdd, OptionsToRemove);
359 }
360}
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
enum SAFEBOOT_MODE BootOptionChoice
Definition: advopts.c:82
LOGICAL BootFlags
Definition: advopts.c:86
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define DbgPrint
Definition: hal.h:12
#define BOOT_DEBUGGING
Definition: winldr.h:69
#define BOOT_LOGGING
Definition: winldr.h:67
#define BOOT_VGA_MODE
Definition: winldr.h:68
#define ASSERT(a)
Definition: mode.c:44
VOID NtLdrUpdateOptions(_Inout_updates_z_(BufferSize) PSTR LoadOptions, _In_ ULONG BufferSize, _In_ BOOLEAN Append, _In_opt_ PCSTR OptionsToAdd[], _In_opt_ PCSTR OptionsToRemove[])
Updates the options in the buffer pointed by LoadOptions, of maximum size BufferSize,...
Definition: ntldropts.c:244
VOID NtLdrAddOptions(_Inout_updates_z_(BufferSize) PSTR Options, _In_ ULONG BufferSize, _In_ BOOLEAN Append, _In_opt_ PCSTR NewOptions)
Appends or prepends new options to the ones originally contained in the buffer pointed by Options,...
Definition: ntldropts.c:141
char CHAR
Definition: pedump.c:57
const char * PCSTR
Definition: typedefs.h:52

Referenced by LoadAndBootWindows(), and LoadReactOSSetup().

◆ List_PaToVa()

VOID List_PaToVa ( _In_ LIST_ENTRY ListEntry)

◆ LoadAndBootWindows()

ARC_STATUS LoadAndBootWindows ( IN ULONG  Argc,
IN PCHAR  Argv[],
IN PCHAR  Envp[] 
)

Definition at line 1179 of file winldr.c.

1183{
1185 PCSTR ArgValue;
1190 USHORT OperatingSystemVersion;
1191 PLOADER_PARAMETER_BLOCK LoaderBlock;
1192 CHAR BootPath[MAX_PATH];
1194 CHAR BootOptions[MAX_OPTIONS_LENGTH+1];
1195
1196 /* Retrieve the (mandatory) boot type */
1197 ArgValue = GetArgumentValue(Argc, Argv, "BootType");
1198 if (!ArgValue || !*ArgValue)
1199 {
1200 ERR("No 'BootType' value, aborting!\n");
1201 return EINVAL;
1202 }
1203
1204 /* Convert it to an OS version */
1205 if (_stricmp(ArgValue, "Windows") == 0 ||
1206 _stricmp(ArgValue, "Windows2003") == 0)
1207 {
1208 OperatingSystemVersion = _WIN32_WINNT_WS03;
1209 }
1210 else if (_stricmp(ArgValue, "WindowsNT40") == 0)
1211 {
1212 OperatingSystemVersion = _WIN32_WINNT_NT4;
1213 }
1214 else if (_stricmp(ArgValue, "WindowsVista") == 0)
1215 {
1216 OperatingSystemVersion = _WIN32_WINNT_VISTA;
1217 }
1218 else
1219 {
1220 ERR("Unknown 'BootType' value '%s', aborting!\n", ArgValue);
1221 return EINVAL;
1222 }
1223
1224 /* Retrieve the (mandatory) system partition */
1225 SystemPartition = GetArgumentValue(Argc, Argv, "SystemPartition");
1227 {
1228 ERR("No 'SystemPartition' specified, aborting!\n");
1229 return EINVAL;
1230 }
1231
1232 /* Let the user know we started loading */
1234 UiDrawStatusText("Loading...");
1235 UiDrawProgressBarCenter("Loading NT...");
1236
1237 /* Retrieve the system path */
1238 *BootPath = ANSI_NULL;
1239 ArgValue = GetArgumentValue(Argc, Argv, "SystemPath");
1240 if (ArgValue)
1241 RtlStringCbCopyA(BootPath, sizeof(BootPath), ArgValue);
1242
1243 /*
1244 * Check whether BootPath is a full path
1245 * and if not, create a full boot path.
1246 *
1247 * See FsOpenFile for the technique used.
1248 */
1249 if (strrchr(BootPath, ')') == NULL)
1250 {
1251 /* Temporarily save the boot path */
1252 RtlStringCbCopyA(FilePath, sizeof(FilePath), BootPath);
1253
1254 /* This is not a full path: prepend the SystemPartition */
1255 RtlStringCbCopyA(BootPath, sizeof(BootPath), SystemPartition);
1256
1257 /* Append a path separator if needed */
1258 if (*FilePath != '\\' && *FilePath != '/')
1259 RtlStringCbCatA(BootPath, sizeof(BootPath), "\\");
1260
1261 /* Append the remaining path */
1262 RtlStringCbCatA(BootPath, sizeof(BootPath), FilePath);
1263 }
1264
1265 /* Append a path separator if needed */
1266 if (!*BootPath || BootPath[strlen(BootPath) - 1] != '\\')
1267 RtlStringCbCatA(BootPath, sizeof(BootPath), "\\");
1268
1269 TRACE("BootPath: '%s'\n", BootPath);
1270
1271 /* Retrieve the boot options */
1272 *BootOptions = ANSI_NULL;
1273 ArgValue = GetArgumentValue(Argc, Argv, "Options");
1274 if (ArgValue && *ArgValue)
1275 RtlStringCbCopyA(BootOptions, sizeof(BootOptions), ArgValue);
1276 TRACE("BootOptions(1): '%s'\n", BootOptions);
1277
1278 /*
1279 * Set the "HAL=" and "KERNEL=" options if needed.
1280 * If already present on the standard "Options=" option line, they take
1281 * precedence over those passed via the separate "Hal=" and "Kernel="
1282 * options.
1283 */
1284 if (!NtLdrGetOption(BootOptions, "HAL="))
1285 {
1286 /*
1287 * Not found in the options, try to retrieve the
1288 * separate value and append it to the options.
1289 */
1290 ArgValue = GetArgumentValue(Argc, Argv, "Hal");
1291 if (ArgValue && *ArgValue)
1292 {
1293 RtlStringCbCatA(BootOptions, sizeof(BootOptions), " /HAL=");
1294 RtlStringCbCatA(BootOptions, sizeof(BootOptions), ArgValue);
1295 }
1296 }
1297 if (!NtLdrGetOption(BootOptions, "KERNEL="))
1298 {
1299 /*
1300 * Not found in the options, try to retrieve the
1301 * separate value and append it to the options.
1302 */
1303 ArgValue = GetArgumentValue(Argc, Argv, "Kernel");
1304 if (ArgValue && *ArgValue)
1305 {
1306 RtlStringCbCatA(BootOptions, sizeof(BootOptions), " /KERNEL=");
1307 RtlStringCbCatA(BootOptions, sizeof(BootOptions), ArgValue);
1308 }
1309 }
1310
1311 /* Append boot-time options */
1312 AppendBootTimeOptions(BootOptions, sizeof(BootOptions));
1313
1314 /* Post-process the boot options */
1315 NtLdrNormalizeOptions(BootOptions);
1316 TRACE("BootOptions(2): '%s'\n", BootOptions);
1317
1318 /* Check if a RAM disk file was given */
1319 FileName = NtLdrGetOptionEx(BootOptions, "RDPATH=", &FileNameLength);
1320 if (FileName && (FileNameLength >= 7))
1321 {
1322 /* Load the RAM disk */
1324 if (Status != ESUCCESS)
1325 {
1326 FileName += 7; FileNameLength -= 7;
1327 UiMessageBox("Failed to load RAM disk file '%.*s'",
1329 return Status;
1330 }
1331 }
1332
1333 /* Handle the SOS option */
1334 SosEnabled = !!NtLdrGetOption(BootOptions, "SOS");
1335 if (SosEnabled)
1336 UiResetForSOS();
1337
1338 /* Allocate and minimally-initialize the Loader Parameter Block */
1339 AllocateAndInitLPB(OperatingSystemVersion, &LoaderBlock);
1340
1341 /* Load the system hive */
1342 UiUpdateProgressBar(15, "Loading system hive...");
1343 Success = WinLdrInitSystemHive(LoaderBlock, BootPath, FALSE);
1344 TRACE("SYSTEM hive %s\n", (Success ? "loaded" : "not loaded"));
1345 /* Bail out if failure */
1346 if (!Success)
1347 return ENOEXEC;
1348
1349 /* Fixup the version number using data from the registry */
1350 if (OperatingSystemVersion == 0)
1351 OperatingSystemVersion = WinLdrDetectVersion();
1352 LoaderBlock->Extension->MajorVersion = (OperatingSystemVersion & 0xFF00) >> 8;
1353 LoaderBlock->Extension->MinorVersion = (OperatingSystemVersion & 0xFF);
1354
1355 /* Load NLS data, OEM font, and prepare boot drivers list */
1356 Success = WinLdrScanSystemHive(LoaderBlock, BootPath);
1357 TRACE("SYSTEM hive %s\n", (Success ? "scanned" : "not scanned"));
1358 /* Bail out if failure */
1359 if (!Success)
1360 return ENOEXEC;
1361
1362 /* Load the Firmware Errata file */
1363 Success = WinLdrInitErrataInf(LoaderBlock, OperatingSystemVersion, BootPath);
1364 TRACE("Firmware Errata file %s\n", (Success ? "loaded" : "not loaded"));
1365 /* Not necessarily fatal if not found - carry on going */
1366
1367 /* Finish loading */
1368 return LoadAndBootWindowsCommon(OperatingSystemVersion,
1369 LoaderBlock,
1370 BootOptions,
1372 BootPath);
1373}
PCWSTR FilePath
unsigned char BOOLEAN
Definition: actypes.h:127
PSTR GetArgumentValue(_In_ ULONG Argc, _In_ PCHAR Argv[], _In_ PCSTR ArgumentName)
Definition: arcsupp.c:42
PPARTENTRY SystemPartition
Definition: reactos.c:33
#define ERR(fmt,...)
Definition: precomp.h:57
ARC_STATUS RamDiskInitialize(IN BOOLEAN InitRamDisk, IN PCSTR LoadOptions OPTIONAL, IN PCSTR DefaultPath OPTIONAL)
Definition: ramdisk.c:229
VOID UiDrawBackdrop(ULONG DrawHeight)
Definition: ui.c:233
VOID UiUpdateProgressBar(_In_ ULONG Percentage, _In_opt_ PCSTR ProgressText)
Definition: ui.c:454
ULONG UiGetScreenHeight(VOID)
Definition: ui.c:655
VOID UiDrawProgressBarCenter(_In_ PCSTR ProgressText)
Definition: ui.c:487
VOID UiDrawStatusText(PCSTR StatusText)
Definition: ui.c:286
VOID UiResetForSOS(VOID)
Definition: ui.c:639
VOID UiMessageBox(_In_ PCSTR Format,...)
Definition: ui.c:359
#define _stricmp
Definition: cat.c:22
#define MAX_PATH
Definition: compat.h:34
#define EINVAL
Definition: errno.h:44
#define ENOEXEC
Definition: errno.h:31
_ACRTIMP size_t __cdecl strlen(const char *)
Definition: string.c:1592
_ACRTIMP char *__cdecl strrchr(const char *, int)
Definition: string.c:3298
@ Success
Definition: eventcreate.c:712
struct _FileName FileName
Definition: fatprocs.h:897
_Must_inspect_result_ _In_ PFILE_OBJECT _In_opt_ HANDLE _In_ ULONG FileNameLength
Definition: fltkernel.h:1129
Status
Definition: gdiplustypes.h:25
VOID AppendBootTimeOptions(_Inout_z_bytecount_(BootOptionsSize) PSTR BootOptions, _In_ SIZE_T BootOptionsSize)
Definition: advopts.c:282
#define ANSI_NULL
#define MAX_OPTIONS_LENGTH
Definition: winldr.h:44
BOOLEAN WinLdrInitSystemHive(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, IN PCSTR SystemRoot, IN BOOLEAN Setup)
Definition: wlregistry.c:125
BOOLEAN WinLdrScanSystemHive(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, IN PCSTR SystemRoot)
Definition: wlregistry.c:231
PCSTR NtLdrGetOptionEx(_In_ PCSTR Options, _In_ PCSTR OptionName, _Out_opt_ PULONG OptionLength)
Definition: ntldropts.c:117
PCSTR NtLdrGetOption(_In_ PCSTR Options, _In_ PCSTR OptionName)
Definition: ntldropts.c:128
NTSTRSAFEAPI RtlStringCbCatA(_Inout_updates_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCSTR pszSrc)
Definition: ntstrsafe.h:625
NTSTRSAFEAPI RtlStringCbCopyA(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCSTR pszSrc)
Definition: ntstrsafe.h:156
unsigned short USHORT
Definition: pedump.c:61
@ ESUCCESS
Definition: arc.h:32
ULONG ARC_STATUS
Definition: arc.h:4
#define _WIN32_WINNT_WS03
Definition: sdkddkver.h:23
#define _WIN32_WINNT_NT4
Definition: sdkddkver.h:20
#define _WIN32_WINNT_VISTA
Definition: sdkddkver.h:25
#define TRACE(s)
Definition: solgame.cpp:4
PLOADER_PARAMETER_EXTENSION Extension
Definition: arc.h:857
uint32_t ULONG
Definition: typedefs.h:59
VOID NtLdrNormalizeOptions(_Inout_ PSTR LoadOptions)
Normalize in-place the NT boot options by removing any leading '/', normalizing TABs to spaces,...
Definition: winldr.c:1151
USHORT WinLdrDetectVersion(VOID)
Definition: winldr.c:507
static BOOLEAN WinLdrInitErrataInf(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, IN USHORT OperatingSystemVersion, IN PCSTR SystemRoot)
Definition: winldr.c:1086
ARC_STATUS LoadAndBootWindowsCommon(_In_ USHORT OperatingSystemVersion, _In_ PLOADER_PARAMETER_BLOCK LoaderBlock, _In_ PCSTR BootOptions, _In_ PCSTR SystemPartition, _In_ PCSTR BootPath)
Definition: winldr.c:1376
BOOLEAN SosEnabled
Definition: winldr.c:34
VOID AllocateAndInitLPB(IN USHORT VersionToBoot, OUT PLOADER_PARAMETER_BLOCK *OutLoaderBlock)
Definition: winldr.c:80

◆ LoadReactOSSetup()

ARC_STATUS LoadReactOSSetup ( IN ULONG  Argc,
IN PCHAR  Argv[],
IN PCHAR  Envp[] 
)

Definition at line 381 of file setupldr.c.

385{
387 PCSTR ArgValue;
389 PCSTR SystemPath;
392 BOOLEAN BootFromFloppy;
394 HINF InfHandle;
395 INFCONTEXT InfContext;
396 ULONG i, ErrorLine;
397 PLOADER_PARAMETER_BLOCK LoaderBlock;
398 PSETUP_LOADER_BLOCK SetupBlock;
399 CHAR BootPath[MAX_PATH];
401 CHAR UserBootOptions[MAX_OPTIONS_LENGTH+1];
402 PCSTR BootOptions;
403
404 static PCSTR SourcePaths[] =
405 {
406 "", /* Keep first to optimize TXTSETUP.SIF search on floppy boot */
407#if defined(_M_IX86)
408 "I386\\",
409#elif defined(_M_AMD64)
410 "AMD64\\",
411#elif defined(_M_ARM)
412 "ARM\\",
413#elif defined(_M_ARM64)
414 "ARM64\\",
415#elif defined(_M_MPPC)
416 "PPC\\",
417#elif defined(_M_MRX000)
418 "MIPS\\",
419#endif
420 "reactos\\",
421 };
422
423 /* Retrieve the (mandatory) boot type */
424 ArgValue = GetArgumentValue(Argc, Argv, "BootType");
425 if (!ArgValue || !*ArgValue)
426 {
427 ERR("No 'BootType' value, aborting!\n");
428 return EINVAL;
429 }
430 if (_stricmp(ArgValue, "ReactOSSetup") != 0)
431 {
432 ERR("Unknown 'BootType' value '%s', aborting!\n", ArgValue);
433 return EINVAL;
434 }
435
436 /* Retrieve the (mandatory) system partition */
437 SystemPartition = GetArgumentValue(Argc, Argv, "SystemPartition");
439 {
440 ERR("No 'SystemPartition' specified, aborting!\n");
441 return EINVAL;
442 }
443
444 /* Let the user know we started loading */
446 UiDrawStatusText("Setup is loading...");
447 UiDrawProgressBarCenter("Loading ReactOS Setup...");
448
449 /* Retrieve the system path */
450 *BootPath = ANSI_NULL;
451 ArgValue = GetArgumentValue(Argc, Argv, "SystemPath");
452 if (ArgValue)
453 {
454 RtlStringCbCopyA(BootPath, sizeof(BootPath), ArgValue);
455 }
456 else
457 {
458 /*
459 * IMPROVE: I don't want to use the SystemPartition here as a
460 * default choice because I can do it after (see few lines below).
461 * Instead I reset BootPath here so that we can build the full path
462 * using the general code from below.
463 */
464 // RtlStringCbCopyA(BootPath, sizeof(BootPath), SystemPartition);
465 *BootPath = ANSI_NULL;
466 }
467
468 /*
469 * Check whether BootPath is a full path
470 * and if not, create a full boot path.
471 *
472 * See FsOpenFile for the technique used.
473 */
474 if (strrchr(BootPath, ')') == NULL)
475 {
476 /* Temporarily save the boot path */
477 RtlStringCbCopyA(FilePath, sizeof(FilePath), BootPath);
478
479 /* This is not a full path: prepend the SystemPartition */
480 RtlStringCbCopyA(BootPath, sizeof(BootPath), SystemPartition);
481
482 /* Append a path separator if needed */
483 if (*FilePath != '\\' && *FilePath != '/')
484 RtlStringCbCatA(BootPath, sizeof(BootPath), "\\");
485
486 /* Append the remaining path */
487 RtlStringCbCatA(BootPath, sizeof(BootPath), FilePath);
488 }
489
490 /* Append a path separator if needed */
491 if (!*BootPath || BootPath[strlen(BootPath) - 1] != '\\')
492 RtlStringCbCatA(BootPath, sizeof(BootPath), "\\");
493
494 TRACE("BootPath: '%s'\n", BootPath);
495
496 /*
497 * Retrieve the boot options. Any options present here will supplement or
498 * override those that will be specified in TXTSETUP.SIF's OsLoadOptions.
499 */
500 BootOptions = GetArgumentValue(Argc, Argv, "Options");
501 if (!BootOptions)
502 BootOptions = "";
503 TRACE("BootOptions(1): '%s'\n", BootOptions);
504
505 /* Check if a RAM disk file was given */
506 FileName = (PSTR)NtLdrGetOptionEx(BootOptions, "RDPATH=", &FileNameLength);
507 if (FileName && (FileNameLength >= 7))
508 {
509 /* Load the RAM disk */
511 if (Status != ESUCCESS)
512 {
513 FileName += 7; FileNameLength -= 7;
514 UiMessageBox("Failed to load RAM disk file '%.*s'",
516 return Status;
517 }
518 }
519
520 /* Check if we booted from floppy */
521 BootFromFloppy = !!strstr(BootPath, ")fdisk(");
522 // FIXME: Use for implementing disk tag check when booting using multiple floppies.
523 DBG_UNREFERENCED_LOCAL_VARIABLE(BootFromFloppy);
524
525 /* Open 'TXTSETUP.SIF' from any of the source paths */
526 FileName = BootPath + strlen(BootPath);
527 for (i = 0;; ++i)
528 {
529 if (i >= RTL_NUMBER_OF(SourcePaths))
530 {
531 UiMessageBox("Failed to open txtsetup.sif");
532 return ENOENT;
533 }
534 SystemPath = SourcePaths[i];
535
536 /* Adjust the tentative BootPath */
537 FileNameLength = (ULONG)(sizeof(BootPath) - (FileName - BootPath)*sizeof(CHAR));
539
540 /* Try to open TXTSETUP.SIF from this BootPath */
541 RtlStringCbCopyA(FilePath, sizeof(FilePath), BootPath);
542 RtlStringCbCatA(FilePath, sizeof(FilePath), "txtsetup.sif");
543 if (InfOpenFile(&InfHandle, FilePath, &ErrorLine))
544 {
545 /* Found and opened: TXTSETUP.SIF is in the correct BootPath */
546 break;
547 }
548 else
549 {
550 if (ErrorLine != -1)
551 UiMessageBox("Error in %s at line %lu", FilePath, ErrorLine);
552 }
553 }
554
555 TRACE("BootPath: '%s', SystemPath: '%s'\n", BootPath, SystemPath);
556
557 // UseLocalSif = NtLdrGetOption(BootOptions, "USELOCALSIF");
558 if (NtLdrGetOption(BootOptions, "SIFOPTIONSOVERRIDE"))
559 {
560 PCSTR OptionsToRemove[2] = {"SIFOPTIONSOVERRIDE", NULL};
561
562 /* Do not use any load options from TXTSETUP.SIF, but
563 * use instead those passed from the command line. */
564 RtlStringCbCopyA(UserBootOptions, sizeof(UserBootOptions), BootOptions);
565
566 /* Remove the private switch from the options */
567 NtLdrUpdateOptions(UserBootOptions,
568 sizeof(UserBootOptions),
569 FALSE,
570 NULL,
571 OptionsToRemove);
572 }
573 else // if (!*BootOptions || NtLdrGetOption(BootOptions, "SIFOPTIONSADD"))
574 {
575 PCSTR LoadOptions = NULL;
576 PCSTR DbgLoadOptions = NULL;
577 PSTR ExtraOptions, HigherPriorityOptions;
578 PSTR OptionsToAdd[3];
579 PSTR OptionsToRemove[4];
580
581 /* Load the options from TXTSETUP.SIF */
582 if (InfFindFirstLine(InfHandle, "SetupData", "OsLoadOptions", &InfContext))
583 {
584 if (!InfGetDataField(&InfContext, 1, &LoadOptions))
585 WARN("Failed to get load options\n");
586 }
587
588#if !DBG
589 /* Non-debug mode: get the debug load options only if /DEBUG was specified
590 * in the Argv command-line options (was e.g. added to the options when
591 * the user selected "Debugging Mode" in the advanced boot menu). */
592 if (NtLdrGetOption(BootOptions, "DEBUG") ||
593 NtLdrGetOption(BootOptions, "DEBUG="))
594 {
595#else
596 /* Debug mode: always get the debug load options */
597#endif
598 if (InfFindFirstLine(InfHandle, "SetupData", "SetupDebugOptions", &InfContext))
599 {
600 if (!InfGetDataField(&InfContext, 1, &DbgLoadOptions))
601 WARN("Failed to get debug load options\n");
602 }
603 /* If none was found, default to enabling debugging */
604 if (!DbgLoadOptions)
605 DbgLoadOptions = "DEBUG";
606#if !DBG
607 }
608#endif
609
610 /* Initialize the load options with those from TXTSETUP.SIF */
611 *UserBootOptions = ANSI_NULL;
612 if (LoadOptions && *LoadOptions)
613 RtlStringCbCopyA(UserBootOptions, sizeof(UserBootOptions), LoadOptions);
614
615 /* Merge the debug load options if any */
616 if (DbgLoadOptions)
617 {
618 RtlZeroMemory(OptionsToAdd, sizeof(OptionsToAdd));
619 RtlZeroMemory(OptionsToRemove, sizeof(OptionsToRemove));
620
621 /*
622 * Retrieve any option patterns that we should remove from the
623 * SIF load options because they are of higher precedence than
624 * those specified in the debug load options to be added.
625 * Also always remove NODEBUG (even if the debug load options
626 * do not contain explicitly the DEBUG option), since we want
627 * to have debugging enabled if possible.
628 */
629 OptionsToRemove[0] = "NODEBUG";
630 NtLdrGetHigherPriorityOptions(DbgLoadOptions,
632 &HigherPriorityOptions);
633 OptionsToAdd[1] = (ExtraOptions ? ExtraOptions : "");
634 OptionsToRemove[1] = (HigherPriorityOptions ? HigherPriorityOptions : "");
635
636 /*
637 * Prepend the debug load options, so that in case it contains
638 * redundant options with respect to the SIF load options, the
639 * former can take precedence over the latter.
640 */
641 OptionsToAdd[0] = (PSTR)DbgLoadOptions;
642 OptionsToRemove[2] = (PSTR)DbgLoadOptions;
643 NtLdrUpdateOptions(UserBootOptions,
644 sizeof(UserBootOptions),
645 FALSE,
646 (PCSTR*)OptionsToAdd,
647 (PCSTR*)OptionsToRemove);
648
649 if (ExtraOptions)
651 if (HigherPriorityOptions)
652 FrLdrHeapFree(HigherPriorityOptions, TAG_BOOT_OPTIONS);
653 }
654
655 RtlZeroMemory(OptionsToAdd, sizeof(OptionsToAdd));
656 RtlZeroMemory(OptionsToRemove, sizeof(OptionsToRemove));
657
658 /*
659 * Retrieve any option patterns that we should remove from the
660 * SIF load options because they are of higher precedence than
661 * those specified in the options to be added.
662 */
665 &HigherPriorityOptions);
666 OptionsToAdd[1] = (ExtraOptions ? ExtraOptions : "");
667 OptionsToRemove[0] = (HigherPriorityOptions ? HigherPriorityOptions : "");
668
669 /* Finally, prepend the user-specified options that
670 * take precedence over those from TXTSETUP.SIF. */
671 OptionsToAdd[0] = (PSTR)BootOptions;
672 OptionsToRemove[1] = (PSTR)BootOptions;
673 NtLdrUpdateOptions(UserBootOptions,
674 sizeof(UserBootOptions),
675 FALSE,
676 (PCSTR*)OptionsToAdd,
677 (PCSTR*)OptionsToRemove);
678
679 if (ExtraOptions)
681 if (HigherPriorityOptions)
682 FrLdrHeapFree(HigherPriorityOptions, TAG_BOOT_OPTIONS);
683 }
684
685 /* Append boot-time options */
686 AppendBootTimeOptions(UserBootOptions, sizeof(UserBootOptions));
687
688 /* Post-process the boot options */
689 NtLdrNormalizeOptions(UserBootOptions);
690 BootOptions = UserBootOptions;
691 TRACE("BootOptions(2): '%s'\n", BootOptions);
692
693 /* Handle the SOS option */
694 SosEnabled = !!NtLdrGetOption(BootOptions, "SOS");
695 if (SosEnabled)
697
698 /* Allocate and minimally-initialize the Loader Parameter Block */
700
701 /* Allocate and initialize the setup loader block */
702 SetupBlock = &WinLdrSystemBlock->SetupBlock;
703 LoaderBlock->SetupLdrBlock = SetupBlock;
704
705 /* Set textmode setup flag */
706 SetupBlock->Flags = SETUPLDR_TEXT_MODE;
707
708 /* Load the "setupreg.hiv" setup system hive */
709 UiUpdateProgressBar(15, "Loading setup system hive...");
710 Success = WinLdrInitSystemHive(LoaderBlock, BootPath, TRUE);
711 TRACE("Setup SYSTEM hive %s\n", (Success ? "loaded" : "not loaded"));
712 /* Bail out if failure */
713 if (!Success)
714 return ENOEXEC;
715
716 /* Load NLS data, they are in the System32 directory of the installation medium */
717 RtlStringCbCopyA(FilePath, sizeof(FilePath), BootPath);
718 RtlStringCbCatA(FilePath, sizeof(FilePath), "system32\\");
719 SetupLdrLoadNlsData(LoaderBlock, InfHandle, FilePath);
720
721 /* Load the Firmware Errata file from the installation medium */
722 Success = SetupLdrInitErrataInf(LoaderBlock, InfHandle, BootPath);
723 TRACE("Firmware Errata file %s\n", (Success ? "loaded" : "not loaded"));
724 /* Not necessarily fatal if not found - carry on going */
725
726 // UiDrawStatusText("Press F6 if you need to install a 3rd-party SCSI or RAID driver...");
727
728 /* Get a list of boot drivers */
729 SetupLdrScanBootDrivers(&LoaderBlock->BootDriverListHead, InfHandle, BootPath);
730
731 /* Close the inf file */
732 InfCloseFile(InfHandle);
733
734 UiDrawStatusText("The Setup program is starting...");
735
736 /* Finish loading */
738 LoaderBlock,
739 BootOptions,
741 BootPath);
742}
#define WARN(fmt,...)
Definition: precomp.h:61
VOID FrLdrHeapFree(PVOID MemoryPointer, ULONG Tag)
Definition: heap.c:539
#define ENOENT
Definition: errno.h:25
_ACRTIMP char *__cdecl strstr(const char *, const char *)
Definition: string.c:3415
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
BOOLEAN InfFindFirstLine(HINF InfHandle, PCSTR Section, PCSTR Key, PINFCONTEXT Context)
Definition: inffile.c:1050
BOOLEAN InfOpenFile(PHINF InfHandle, PCSTR FileName, PULONG ErrorLine)
Definition: inffile.c:918
#define DBG_UNREFERENCED_LOCAL_VARIABLE(L)
Definition: ntbasedef.h:331
#define SETUPLDR_TEXT_MODE
Definition: setupblk.h:7
static VOID SetupLdrLoadNlsData(_Inout_ PLOADER_PARAMETER_BLOCK LoaderBlock, _In_ HINF InfHandle, _In_ PCSTR SearchPath)
Definition: setupldr.c:36
static VOID SetupLdrScanBootDrivers(_Inout_ PLIST_ENTRY BootDriverListHead, _In_ HINF InfHandle, _In_ PCSTR SearchPath)
Definition: setupldr.c:149
PCSTR ExtraOptions
Definition: setupldr.c:242
VOID NtLdrGetHigherPriorityOptions(IN PCSTR BootOptions, OUT PSTR *ExtraOptions, OUT PSTR *HigherPriorityOptions)
Definition: setupldr.c:271
#define TAG_BOOT_OPTIONS
Definition: setupldr.c:268
static BOOLEAN SetupLdrInitErrataInf(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, IN HINF InfHandle, IN PCSTR SystemRoot)
Definition: setupldr.c:108
VOID AllocateAndInitLPB(IN USHORT VersionToBoot, OUT PLOADER_PARAMETER_BLOCK *OutLoaderBlock)
Definition: winldr.c:80
LIST_ENTRY BootDriverListHead
Definition: arc.h:822
SETUP_LOADER_BLOCK SetupBlock
Definition: winldr.h:50
char * PSTR
Definition: typedefs.h:51
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
BOOLEAN InfGetDataField(PINFCONTEXT Context, ULONG FieldIndex, PWCHAR *Data)
Definition: infrosget.c:127
VOID InfCloseFile(HINF InfHandle)
Definition: inffile.c:1028
PLOADER_SYSTEM_BLOCK WinLdrSystemBlock
Definition: winldr.c:30

◆ MenuNTOptions()

VOID MenuNTOptions ( _Inout_ OperatingSystemItem OperatingSystem)

◆ PaToVa()

◆ VaToPa()

Variable Documentation

◆ BootFlags

LOGICAL BootFlags
extern

Definition at line 86 of file advopts.c.

Referenced by AppendBootTimeOptions(), GetBootOptionsDescription(), and MenuNTOptions().

◆ BootOptionChoice

enum SAFEBOOT_MODE BootOptionChoice
extern

Definition at line 82 of file advopts.c.

Referenced by AppendBootTimeOptions(), GetBootOptionsDescription(), and MenuNTOptions().