ReactOS 0.4.16-dev-292-gbbdcc14
rosload.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING.ARM in the top level directory
3 * PROJECT: ReactOS UEFI OS Loader
4 * FILE: boot/environ/app/rosload/rosload.c
5 * PURPOSE: OS Loader Entrypoint
6 * PROGRAMMER: Alex Ionescu (alex.ionescu@reactos.org)
7 */
8
9/* INCLUDES ******************************************************************/
10
11#include "rosload.h"
12
15 _In_ PLOADER_PARAMETER_BLOCK LoaderBlock,
16 _In_ PVOID KernelEntrypoint
17 );
18
19/* DATA VARIABLES ************************************************************/
20
29
34
38
43
45
47
52
54
56
58{
59 {
62 }, // RtlBsdItemVersionNumber
63 {
64 FIELD_OFFSET(RTL_BSD_DATA, ProductType),
66 }, // RtlBsdItemProductType
67 {
68 FIELD_OFFSET(RTL_BSD_DATA, AabEnabled),
70 }, // RtlBsdItemAabEnabled
71 {
72 FIELD_OFFSET(RTL_BSD_DATA, AabTimeout),
74 }, // RtlBsdItemAabTimeout
75 {
76 FIELD_OFFSET(RTL_BSD_DATA, LastBootSucceeded),
78 }, // RtlBsdItemBootGood
79 {
80 FIELD_OFFSET(RTL_BSD_DATA, LastBootShutdown),
82 }, // RtlBsdItemBootShutdown
83 {
84 FIELD_OFFSET(RTL_BSD_DATA, SleepInProgress),
86 }, // RtlBsdSleepInProgress
87 {
88 FIELD_OFFSET(RTL_BSD_DATA, PowerTransition),
90 }, // RtlBsdPowerTransition
91 {
92 FIELD_OFFSET(RTL_BSD_DATA, BootAttemptCount),
94 }, // RtlBsdItemBootAttemptCount
95 {
96 FIELD_OFFSET(RTL_BSD_DATA, LastBootCheckpoint),
98 }, // RtlBsdItemBootCheckpoint
99 {
100 FIELD_OFFSET(RTL_BSD_DATA, LastBootId),
102 }, // RtlBsdItemBootId
103 {
104 FIELD_OFFSET(RTL_BSD_DATA, LastSuccessfulShutdownBootId),
106 }, // RtlBsdItemShutdownBootId
107 {
108 FIELD_OFFSET(RTL_BSD_DATA, LastReportedAbnormalShutdownBootId),
110 }, // RtlBsdItemReportedAbnormalShutdownBootId
111 {
112 FIELD_OFFSET(RTL_BSD_DATA, ErrorInfo),
114 }, // RtlBsdItemErrorInfo
115 {
116 FIELD_OFFSET(RTL_BSD_DATA, PowerButtonPressInfo),
118 }, // RtlBsdItemPowerButtonPressInfo
119 {
120 FIELD_OFFSET(RTL_BSD_DATA, Checksum),
122 }, // RtlBsdItemChecksum
123};
124
128
130
134
135/* FUNCTIONS *****************************************************************/
136
137VOID
140 _In_ ULONG Parameter1,
141 _In_ ULONG_PTR Parameter2,
142 _In_ ULONG_PTR Parameter3
143 )
144{
145 /* For now just do this */
146 BlStatusPrint(L"FATAL ERROR IN ROSLOAD: %lx\n", ErrorCode);
147}
148
149VOID
152 )
153{
154 /* For now just do this */
155 BlStatusPrint(L"BOOT ABORTED: %lx\n", Status);
156}
157
161 _In_ ULONG Parameter1,
162 _In_ ULONG_PTR Parameter2,
163 _In_ ULONG_PTR Parameter3,
164 _In_ ULONG_PTR Parameter4
165 )
166{
167 /* We only filter error code 4 */
168 if (ErrorCode != 4)
169 {
171 }
172
173 /* Handle error 4 as a fatal error 3 internally */
174 OslFatalErrorEx(3, Parameter1, Parameter2, Parameter3);
175 return STATUS_SUCCESS;
176}
177
178VOID
180 _In_ PWCHAR OptionString,
181 _In_ PWCHAR SanitizeString
182 )
183{
184 /* TODO */
185 return;
186}
187
188VOID
190 _In_ PBL_BCD_OPTION BcdOptions
191 )
192{
193 /* TODO */
194 return;
195}
196
199 VOID
200 )
201{
204
205 /* Assume success */
207
208 /* Remove attempts to disable integrity checks or ELAM driver load */
213
214 /* Get the command-line parameters, if any */
217 &LoadString);
218 if (NT_SUCCESS(Status))
219 {
220 /* Conver to upper case */
222
223 /* Remove the existing one */
226
227 /* Sanitize strings we don't want */
228 OslpSanitizeLoadOptionsString(LoadString, L"DISABLE_INTEGRITY_CHECKS");
229 OslpSanitizeLoadOptionsString(LoadString, L"NOINTEGRITYCHECKS");
230 OslpSanitizeLoadOptionsString(LoadString, L"DISABLEELAMDRIVERS");
231
232 /* Add the sanitized one back */
235 LoadString);
236
237 /* Free the original BCD one */
239 }
240
241 /* One more pass for secure-boot options */
243
244 /* All good */
245 return Status;
246}
247
250 VOID
251 )
252{
253 ULONG64 ForceReason;
255
256 /* Read the option */
259 &ForceReason);
260 if (NT_SUCCESS(Status) && (ForceReason < 4))
261 {
262 /* For reasons above 3, don't actually do anything */
263 if (ForceReason > 3)
264 {
265 return STATUS_SUCCESS;
266 }
267 }
268
269 /* If the option isn't there or invalid, always return success */
270 return STATUS_SUCCESS;
271}
272
273VOID
275 VOID
276 )
277{
278 /* TODO */
279 return;
280}
281
285 )
286{
287 /* Are you trying to write? */
288 if (WriteAccess)
289 {
290 /* Have we already read? */
292 {
293 /* No -- fail */
294 return STATUS_UNSUCCESSFUL;
295 }
296 }
297 else if (BsdBootStatusData)
298 {
299 /* No -- you're trying to read and we already have the data: no-op */
300 return STATUS_SUCCESS;
301 }
302
303 /* TODO */
305}
306
310 _In_ RTL_BSD_ITEM_TYPE DataClass,
313 )
314{
317
318 /* No data has been read yet, fail */
320 {
321 return STATUS_UNSUCCESSFUL;
322 }
323
324 /* Invalid data item, fail */
325 if (DataClass >= RtlBsdItemMax)
326 {
328 }
329
330 /* Capture the length and offset */
331 Length = OslpBootStatusFields[DataClass].Size;
333
334 /* Make sure it doesn't overflow past the structure we've read */
336 {
338 }
339
340 /* Make sure we have enough space */
341 if (*Size >= Length)
342 {
343 /* We do -- is this a read? */
344 if (Read)
345 {
346 /* Yes, copy into the caller's buffer */
349 Length);
350 }
351 else
352 {
353 /* It's a write, copy from caller's buffer */
355 Buffer,
356 Length);
357 }
358
359 /* Set success */
361 }
362 else
363 {
364 /* Return size needed and failure code */
365 *Size = Length;
367 }
368
369 /* All good */
370 return Status;
371}
372
375 _In_ BOOLEAN LastBootGood,
376 _In_ BOOLEAN LastBootShutdown,
377 _In_ BOOLEAN LastBootCheckpoint,
378 _In_ ULONG UpdateIncrement,
379 _In_ ULONG BootAttemptCount
380 )
381{
383 ULONG Size;
384
385 /* Capture the BSD data in our globals, if needed */
387 if (!NT_SUCCESS(Status))
388 {
389 goto Quickie;
390 }
391
392 /* Write last boot shutdown */
393 Size = sizeof(LastBootShutdown);
396 &LastBootShutdown,
397 &Size);
398 if (!NT_SUCCESS(Status))
399 {
400 goto Quickie;
401 }
402
403 /* Write last boot good */
404 Size = sizeof(LastBootGood);
407 &LastBootGood,
408 &Size);
409 if (!NT_SUCCESS(Status))
410 {
411 goto Quickie;
412 }
413
414 /* Write last boot checkpoint */
415 Size = sizeof(LastBootCheckpoint);
418 &LastBootCheckpoint,
419 &Size);
420 if (!NT_SUCCESS(Status))
421 {
422 goto Quickie;
423 }
424
425 /* Write boot attempt count */
426 Size = sizeof(BootAttemptCount);
429 &BootAttemptCount,
430 &Size);
431 if (!NT_SUCCESS(Status))
432 {
433 goto Quickie;
434 }
435
436 /* TODO: Update Boot ID*/
437
438 /* Now write the data */
440
441Quickie:
442 return Status;
443}
444
447 _Out_ PBOOLEAN LastBootGood,
448 _Out_ PBOOLEAN LastBootShutdown,
449 _Out_ PBOOLEAN LastBootCheckpoint,
450 _Out_ PULONG LastBootId,
451 _Out_ PBOOLEAN BootGood,
452 _Out_ PBOOLEAN BootShutdown
453 )
454{
456 ULONG Size;
457 ULONG64 BootStatusPolicy;
458 BOOLEAN localBootShutdown, localBootGood;
459
460 /* Capture the BSD data in our globals, if needed */
462 if (!NT_SUCCESS(Status))
463 {
464 goto Quickie;
465 }
466
467 /* Read the last boot ID */
468 Size = sizeof(*LastBootId);
470 if (!NT_SUCCESS(Status))
471 {
472 /* Set to zero if we couldn't find it */
473 *LastBootId = 0;
474 }
475
476 /* Get the boot status policy */
479 &BootStatusPolicy);
480 if (!NT_SUCCESS(Status))
481 {
482 /* Apply a default if none exists */
483 BootStatusPolicy = IgnoreShutdownFailures;
484 }
485
486 /* Check if this was a good shutdown */
487 Size = sizeof(localBootShutdown);
490 &localBootShutdown,
491 &Size);
492 if (!NT_SUCCESS(Status))
493 {
494 goto Quickie;
495 }
496
497 /* Tell the caller */
498 *BootShutdown = localBootShutdown;
499
500 /* Check if this was a good boot */
501 Size = sizeof(localBootGood);
504 &localBootGood,
505 &Size);
506 if (!NT_SUCCESS(Status))
507 {
508 goto Quickie;
509 }
510
511 /* Tell the caller*/
512 *BootGood = localBootGood;
513
514 /* TODO: Additional logic for checkpoints and such */
516
517Quickie:
518 return Status;
519}
520
523 VOID
524 )
525{
526 /* TODO */
527 return FALSE;
528}
529
532 _Out_ PULONG ReturnFlags,
533 _Out_ PBOOLEAN Jump
534 )
535{
536 PGUID AppId;
538 PBL_DEVICE_DESCRIPTOR OsDevice;
540 SIZE_T RootLength, RootLengthWithSep;
541 ULONG i;
542 ULONG64 StartPerf, EndPerf;
543 RTL_BSD_DATA_POWER_TRANSITION PowerTransitionData;
545 ULONG OsDeviceHandle;
546 BOOLEAN LastBootGood, LastBootShutdown, LastBootCheckpoint;
547 ULONG BootId;
548 BOOLEAN BootGood, BootShutdown;
549 ULONG BsdSize;
550
551 /* Initialize locals */
552 PowerBuffer = NULL;
553
554 /* Assume no flags */
555 *ReturnFlags = 0;
556
557 /* Make all registry handles invalid */
558 OslImcHiveHandle = -1;
562
563 /* Initialize memory lists */
568 {
570 }
571
572 /* Initialize the memory map descriptor buffer */
575
576 /* Initialize general pointers */
582
583 /* Initialize general variables */
587
588 /* Capture the current TSC */
589 StartPerf = BlArchGetPerformanceCounter();
590
591 /* Set our application type for SecureBoot/TPM purposes */
599
600 /* Register an error handler */
602
603 /* Get the application identifier and save it */
605 if (AppId)
606 {
608 }
609
610 /* Enable tracing */
611#ifdef BL_ETW_SUPPORT
612 TraceLoggingRegister(&TlgOslBootProviderProv);
613#endif
614
615 /* Remove dangerous BCD options */
617 if (!NT_SUCCESS(Status))
618 {
619 EfiPrintf(L"Fail here: %d\r\n", __LINE__);
620 goto Quickie;
621 }
622
623 /* Get the OS device */
626 &OsDevice,
627 0);
628 if (!NT_SUCCESS(Status))
629 {
630 EfiPrintf(L"Fail here: %d\r\n", __LINE__);
631 goto Quickie;
632 }
633
634 /* If the OS device is the boot device, use the one provided by bootlib */
635 if (OsDevice->DeviceType == BootDevice)
636 {
637 OsDevice = BlpBootDevice;
638 }
639
640 /* Save it as a global for later */
641 OslLoadDevice = OsDevice;
642
643 /* Get the system root */
646 &SystemRoot);
647 if (!NT_SUCCESS(Status))
648 {
649 EfiPrintf(L"Fail here: %d\r\n", __LINE__);
650 goto Quickie;
651 }
652
653 EfiPrintf(L"System root: %s\r\n", SystemRoot);
654
655 /* Get the system root length and make sure it's slash-terminated */
656 RootLength = wcslen(SystemRoot);
657 if (SystemRoot[RootLength - 1] == OBJ_NAME_PATH_SEPARATOR)
658 {
659 /* Perfect, set it */
661 }
662 else
663 {
664 /* Allocate a new buffer large enough to contain the slash */
665 RootLengthWithSep = RootLength + sizeof(OBJ_NAME_PATH_SEPARATOR);
666 OslSystemRoot = BlMmAllocateHeap(RootLengthWithSep * sizeof(WCHAR));
667 if (!OslSystemRoot)
668 {
669 /* Bail out if we're out of memory */
671 EfiPrintf(L"Fail here: %d\r\n", __LINE__);
672 goto Quickie;
673 }
674
675 /* Make a copy of the path, adding the separator */
677 wcscat(OslSystemRoot, L"\\");
678
679 /* Free the original one from the BCD library */
681 }
682
683 /* Initialize access to the BSD */
685
686 /* Check if we're supposed to fail on purpose */
688 if (!NT_SUCCESS(Status))
689 {
690 EfiPrintf(L"Fail here: %d\r\n", __LINE__);
691 goto Quickie;
692 }
693
694 /* Always disable VGA mode */
697 TRUE);
698 if (!NT_SUCCESS(Status))
699 {
700 EfiPrintf(L"Fail here: %d\r\n", __LINE__);
701 goto Quickie;
702 }
703
704 /* Get telemetry data from the last boot */
705 Status = OslGetBootStatusData(&LastBootGood,
706 &LastBootShutdown,
707 &LastBootCheckpoint,
708 &BootId,
709 &BootGood,
710 &BootShutdown);
711 if (!NT_SUCCESS(Status))
712 {
713 /* Assume this is the very first boot and everything went well */
714 BootId = 0;
715 LastBootGood = TRUE;
716 LastBootShutdown = TRUE;
717 LastBootCheckpoint = TRUE;
718 BootGood = TRUE;
719 BootShutdown = TRUE;
720
721 /* Set 0 boot attempts */
723 }
724
725 /* Set more attempt variables to their initial state */
728
729 /* Read the current BSD data into the global buffer */
731 if (NT_SUCCESS(Status))
732 {
733 /* Get the power transition buffer from the BSD */
734 BsdSize = sizeof(PowerTransitionData);
737 &PowerTransitionData,
738 &BsdSize);
739 if (NT_SUCCESS(Status))
740 {
741 /* Save the buffer */
742 PowerBuffer = &PowerTransitionData;
743 }
744 }
745
746 /* Check if this is VHD boot, which gets 3 boot attempts instead of 2 */
749
750 /* Check if the user wants to see the advanced menu */
752 {
753 /* The last boot failed more than the maximum */
754 if (!(LastBootGood) &&
756 {
757 /* Return failure due to boot -- launch recovery */
758 *ReturnFlags |= 8;
759
760 /* Update the attempt count and status variables */
762 OslCurrentBootCheckpoint = LastBootCheckpoint;
764 OslCurrentBootShutdown = LastBootShutdown;
765
766 /* Crash with code 15 and abort boot */
767 OslFatalErrorEx(15, 0, 0, 0);
769 EfiPrintf(L"Fail here: %d\r\n", __LINE__);
770 goto Quickie;
771 }
772
773 /* We never made it far enough, more than the maximum */
774 if (!(LastBootCheckpoint) &&
776 {
777 /* Return crash/dirty shutdown during boot attempt */
778 *ReturnFlags |= 0x10;
779
780 /* Update the attempt count and status variables */
782 OslCurrentBootSucceeded = LastBootGood;
783 OslCurrentBootShutdown = LastBootShutdown;
785
786 /* Crash with code 16 and abort boot */
787 OslFatalErrorEx(16, 0, 0, 0);
789 EfiPrintf(L"Fail here: %d\r\n", __LINE__);
790 goto Quickie;
791 }
792
793 /* We failed to shutdown cleanly, and haven't booted yet */
794 if (!(LastBootShutdown) && !(OslBootAttemptCount))
795 {
796 /* Return crash/dirty shutdown */
797 *ReturnFlags |= 0x10;
798
799 /* There's no boot attempt, so only update shutdown variables */
800 OslCurrentBootSucceeded = LastBootGood;
802 OslCurrentBootCheckpoint = LastBootCheckpoint;
803
804 /* Crash with code 16 and abort boot */
805 OslFatalErrorEx(16, 0, 0, 0);
807 EfiPrintf(L"Fail here: %d\r\n", __LINE__);
808 goto Quickie;
809 }
810 }
811
812 /* Officially increment the number of boot attempts */
814
815 /* No success yet, write to boot status file */
820 FALSE,
821 FALSE,
824
825 /* Open the OS Loader Device for Read/Write access */
828 0,
829 &OsDeviceHandle);
830 if (!NT_SUCCESS(Status))
831 {
832 EfiPrintf(L"Fail here: %d\r\n", __LINE__);
833 goto Quickie;
834 }
835
836 /* That's all for now, folks */
839
840 /* Printf perf */
841 EndPerf = BlArchGetPerformanceCounter();
842 EfiPrintf(L"Delta: %lld\r\n", EndPerf - StartPerf);
843
844Quickie:
845#if BL_BITLOCKER_SUPPORT
846 /* Destroy the RNG/AES library for BitLocker */
847 SymCryptRngAesUninstantiate();
848#endif
849
850 /* Abort the boot */
852
853 /* This is a failure path, so never do the jump */
854 *Jump = FALSE;
855
856 /* Return error code */
857 return Status;
858}
859
862 _In_ PLOADER_PARAMETER_BLOCK LoaderBlock
863 )
864{
866}
867
870 _In_ PLOADER_PARAMETER_BLOCK LoaderBlock
871 )
872{
874}
875
876VOID
878 VOID
879 )
880{
881 /* Any XCR0 bits to clear? */
883 {
884 /* Clear them */
885#if defined(_MSC_VER) && !defined(__clang__) && !defined(_M_ARM)
886 __xsetbv(0, __xgetbv(0) & ~ArchXCr0BitsToClear);
887#endif
889 }
890
891 /* Any CR4 bits to clear? */
893 {
894 /* Clear them */
895#if !defined(_M_ARM)
897#endif
899 }
900}
901
904 _In_ ULONG Phase,
905 _In_ PLOADER_PARAMETER_BLOCK LoaderBlock
906 )
907{
908 /* For phase 0, do architectural setup */
909 if (Phase == 0)
910 {
911 return OslArchpKernelSetupPhase0(LoaderBlock);
912 }
913
914 /* Nothing to do for Phase 1 */
915 if (Phase == 1)
916 {
917 return STATUS_SUCCESS;
918 }
919
920 /* Relocate the self map */
922
923 /* Zero out the HAL Heap */
926
927 /* Move shared user data in its place */
930 PAGE_SIZE);
931
932 /* Clear XCR0/CR4 CPU features that should be disabled before boot */
934
935 /* Good to go */
936 return STATUS_SUCCESS;
937}
938
941 VOID
942 )
943{
945
946 /* Is the debugger meant to be kept enabled throughout the boot phase? */
948 {
949#ifdef BL_KD_SUPPORT
950 /* No -- disable it */
951 BlBdStop();
952#endif
953 }
954
955 /* Setup Firmware for Phase 1 */
957 if (NT_SUCCESS(Status))
958 {
959 /* Setup kernel for Phase 2 */
961 if (NT_SUCCESS(Status))
962 {
963#ifdef BL_KD_SUPPORT
964 /* Stop the boot debugger */
965 BlBdStop();
966#endif
967 /* Jump to the kernel entrypoint */
969
970 /* Infinite loop if we got here */
971 for (;;);
972 }
973 }
974
975 /* Return back with the failure code */
976 return Status;
977}
978
981 _Out_ PULONG ReturnFlags
982 )
983{
985 BOOLEAN ExecuteJump;
986#if !defined(_M_ARM)
987 CPU_INFO CpuInfo;
988 BOOLEAN NxEnabled;
989 LARGE_INTEGER MiscMsr;
990
991 /* Check if the CPU supports NX */
992 BlArchCpuId(0x80000001, 0, &CpuInfo);
993 if (!(CpuInfo.Edx & 0x10000))
994 {
995 /* It doesn't, check if this is Intel */
996 EfiPrintf(L"NX disabled: %lx\r\n", CpuInfo.Edx);
998 {
999 /* Then turn off the MSR disable feature for it, enabling NX */
1001 EfiPrintf(L"NX being turned on: %llx\r\n", MiscMsr.QuadPart);
1002 MiscMsr.HighPart &= MSR_XD_ENABLE_MASK;
1005 NxEnabled = TRUE;
1006 }
1007 }
1008
1009 /* Turn on NX support with the CPU-generic MSR */
1011
1012#endif
1013
1014 /* Load the kernel */
1015 Status = OslPrepareTarget(ReturnFlags, &ExecuteJump);
1016 if (NT_SUCCESS(Status) && (ExecuteJump))
1017 {
1018 /* Jump to the kernel */
1020 }
1021
1022#if !defined(_M_ARM)
1023 /* Retore NX support */
1025
1026 /* Did we manually enable NX? */
1027 if (NxEnabled)
1028 {
1029 /* Turn it back off */
1031 MiscMsr.HighPart |= ~MSR_XD_ENABLE_MASK;
1033 }
1034
1035#endif
1036 /* Go back */
1037 return Status;
1038}
1039
1040/*++
1041 * @name OslMain
1042 *
1043 * The OslMain function implements the Windows Boot Application entrypoint for
1044 * the OS Loader.
1045 *
1046 * @param BootParameters
1047 * Pointer to the Boot Application Parameter Block.
1048 *
1049 * @return NT_SUCCESS if the image was loaded correctly, relevant error code
1050 * otherwise.
1051 *
1052 *--*/
1054NTAPI
1057 )
1058{
1059 BL_LIBRARY_PARAMETERS LibraryParameters;
1061 PBL_RETURN_ARGUMENTS ReturnArguments;
1062 PBL_APPLICATION_ENTRY AppEntry;
1063 CPU_INFO CpuInfo;
1064 ULONG Flags;
1065
1066 /* Get the return arguments structure, and set our version */
1067 ReturnArguments = (PBL_RETURN_ARGUMENTS)((ULONG_PTR)BootParameters +
1068 BootParameters->ReturnArgumentsOffset);
1069 ReturnArguments->Version = BL_RETURN_ARGUMENTS_VERSION;
1070
1071 /* Get the application entry, and validate it */
1072 AppEntry = (PBL_APPLICATION_ENTRY)((ULONG_PTR)BootParameters +
1073 BootParameters->AppEntryOffset);
1074 if (!RtlEqualMemory(AppEntry->Signature,
1076 sizeof(AppEntry->Signature)))
1077 {
1078 /* Unrecognized, bail out */
1080 goto Quickie;
1081 }
1082
1083#if !defined(_M_ARM)
1084 /* Check if CPUID 01h is supported */
1086 {
1087 /* Query CPU features */
1088 BlArchCpuId(1, 0, &CpuInfo);
1089
1090 /* Check if PAE is supported */
1091 if (CpuInfo.Edx & 0x40)
1092 {
1093 EfiPrintf(L"PAE Supported, but won't be used\r\n");
1094 }
1095 }
1096#endif
1097
1098 /* Setup the boot library parameters for this application */
1099 BlSetupDefaultParameters(&LibraryParameters);
1100 LibraryParameters.TranslationType = BlVirtual;
1103 LibraryParameters.MinimumAllocationCount = 1024;
1104 LibraryParameters.MinimumHeapSize = 2 * 1024 * 1024;
1106 LibraryParameters.FontBaseDirectory = L"\\Reactos\\Boot\\Fonts";
1107 LibraryParameters.DescriptorCount = 512;
1108
1109 /* Initialize the boot library */
1110 Status = BlInitializeLibrary(BootParameters, &LibraryParameters);
1111 if (NT_SUCCESS(Status))
1112 {
1113 /* For testing, draw the logo */
1114 OslDrawLogo();
1115
1116 /* Call the main routine */
1117 Status = OslpMain(&Flags);
1118
1119 /* Return the flags, and destroy the boot library */
1120 ReturnArguments->Flags = Flags;
1122 }
1123
1124Quickie:
1125 /* Return back to boot manager */
1126 ReturnArguments->Status = Status;
1127 return Status;
1128}
1129
unsigned char BOOLEAN
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
#define OBJ_NAME_PATH_SEPARATOR
Definition: arcname_tests.c:25
LONG NTSTATUS
Definition: precomp.h:26
@ BcdOSLoaderDevice_OSDevice
Definition: bcd.h:110
@ BcdOSLoaderInteger_BootStatusPolicy
Definition: bcd.h:159
@ BcdOSLoaderBoolean_DisableElamDrivers
Definition: bcd.h:160
@ BcdOSLoaderString_SystemRoot
Definition: bcd.h:111
@ BcdOSLoaderBoolean_DisableVgaMode
Definition: bcd.h:129
@ BcdOSLoaderInteger_ForceFailure
Definition: bcd.h:154
@ IgnoreShutdownFailures
Definition: bcd.h:213
#define BCD_IMAGE_TYPE_BOOT_APP
Definition: bcd.h:30
#define BCD_OBJECT_TYPE_APPLICATION
Definition: bcd.h:44
#define BCD_APPLICATION_TYPE_OSLOADER
Definition: bcd.h:36
@ BcdLibraryString_LoadOptionsString
Definition: bcd.h:80
@ BcdLibraryBoolean_DisableIntegrityChecks
Definition: bcd.h:88
BOOLEAN BlDeviceIsVirtualPartitionDevice(_In_ PBL_DEVICE_DESCRIPTOR InputDevice, _Outptr_ PBL_DEVICE_DESCRIPTOR *VirtualDevice)
Definition: device.c:612
#define BL_DEVICE_READ_ACCESS
Definition: bl.h:152
NTSTATUS BlInitializeLibrary(_In_ PBOOT_APPLICATION_PARAMETER_BLOCK BootAppParameters, _In_ PBL_LIBRARY_PARAMETERS LibraryParameters)
Definition: bootlib.c:355
VOID BlArchCpuId(_In_ ULONG Function, _In_ ULONG SubFunction, _Out_ PCPU_INFO Result)
Definition: util.c:924
VOID EfiPrintf(_In_ PWCHAR Format,...)
Definition: firmware.c:126
#define BL_DEVICE_WRITE_ACCESS
Definition: bl.h:153
@ BlVirtual
Definition: bl.h:231
NTSTATUS BlGetBootOptionDevice(_In_ PBL_BCD_OPTION List, _In_ ULONG Type, _Out_ PBL_DEVICE_DESCRIPTOR *Value, _In_opt_ PBL_BCD_OPTION *ExtraOptions)
Definition: bcdopt.c:321
PVOID BlMmAllocateHeap(_In_ SIZE_T Size)
Definition: heapalloc.c:569
struct _BL_RETURN_ARGUMENTS * PBL_RETURN_ARGUMENTS
struct _BL_APPLICATION_ENTRY * PBL_APPLICATION_ENTRY
NTSTATUS BlpDeviceOpen(_In_ PBL_DEVICE_DESCRIPTOR Device, _In_ ULONG Flags, _In_ ULONG Unknown, _Out_ PULONG DeviceId)
Definition: device.c:2111
BOOLEAN BlArchIsCpuIdFunctionSupported(_In_ ULONG Function)
Definition: util.c:856
PBL_DEVICE_DESCRIPTOR BlpBootDevice
Definition: bootlib.c:16
PBL_MM_RELOCATE_SELF_MAP BlMmRelocateSelfMap
Definition: arch.c:16
PBL_MM_MOVE_VIRTUAL_ADDRESS_RANGE BlMmMoveVirtualAddressRange
Definition: arch.c:17
CPU_VENDORS BlArchGetCpuVendor(VOID)
Definition: util.c:937
@ BootDevice
Definition: bl.h:251
VOID BlRemoveBootOption(_In_ PBL_BCD_OPTION List, _In_ ULONG Type)
Definition: bcdopt.c:801
PGUID BlGetApplicationIdentifier(VOID)
Definition: bootlib.c:414
FORCEINLINE VOID BlSetupDefaultParameters(_Out_ PBL_LIBRARY_PARAMETERS LibraryParameters)
Definition: bl.h:1354
ULONGLONG BlArchGetPerformanceCounter(VOID)
Definition: util.c:902
PBL_STATUS_ERROR_HANDLER BlpStatusErrorHandler
Definition: debug.c:20
VOID BlDestroyLibrary(VOID)
Definition: bootlib.c:405
#define BL_LIBRARY_FLAG_REINITIALIZE_ALL
Definition: bl.h:129
#define BL_APP_ENTRY_SIGNATURE
Definition: bl.h:53
PBL_MM_ZERO_VIRTUAL_ADDRESS_RANGE BlMmZeroVirtualAddressRange
Definition: arch.c:18
NTSTATUS BlAppendBootOptionString(_In_ PBL_LOADED_APPLICATION_ENTRY AppEntry, _In_ ULONG OptionId, _In_ PWCHAR OptionString)
Definition: bcdopt.c:689
NTSTATUS BlGetBootOptionString(_In_ PBL_BCD_OPTION List, _In_ ULONG Type, _Out_ PWCHAR *Value)
Definition: bcdopt.c:146
@ BlMemoryKernelRange
Definition: bl.h:367
BL_LOADED_APPLICATION_ENTRY BlpApplicationEntry
Definition: bootlib.c:19
#define BL_LIBRARY_FLAG_ZERO_HEAP_ALLOCATIONS_ON_FREE
Definition: bl.h:130
NTSTATUS BlMmFreeHeap(_In_ PVOID Buffer)
Definition: heapalloc.c:663
VOID BlStatusPrint(_In_ PCWCH Format,...)
Definition: debug.c:75
NTSTATUS BlAppendBootOptionBoolean(_In_ PBL_LOADED_APPLICATION_ENTRY AppEntry, _In_ ULONG OptionId, _In_ BOOLEAN Value)
Definition: bcdopt.c:625
NTSTATUS BlGetBootOptionInteger(_In_ PBL_BCD_OPTION List, _In_ ULONG Type, _Out_ PULONGLONG Value)
Definition: bcdopt.c:467
#define BL_RETURN_ARGUMENTS_VERSION
Definition: bl.h:63
Definition: bufpool.h:45
#define STATUS_NO_MEMORY
Definition: d3dkmdt.h:51
#define STATUS_NOT_IMPLEMENTED
Definition: d3dkmdt.h:42
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
static const WCHAR SystemRoot[]
Definition: reg.c:38
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
Status
Definition: gdiplustypes.h:25
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
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
PPC_QUAL void __writemsr(const unsigned long Value)
Definition: intrin_ppc.h:748
PPC_QUAL unsigned long long __readmsr()
Definition: intrin_ppc.h:741
__INTRIN_INLINE unsigned long __readcr4(void)
Definition: intrin_x86.h:1825
__INTRIN_INLINE void __writecr4(unsigned int Data)
Definition: intrin_x86.h:1799
#define RtlEqualMemory(dst, src, len)
Definition: kdvm.h:18
unsigned __int64 ULONG64
Definition: imports.h:198
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define MM_HAL_VA_END
Definition: ketypes.h:327
#define MM_HAL_VA_START
Definition: ketypes.h:326
#define MSR_EFER
Definition: ketypes.h:236
#define MSR_XD_ENABLE_MASK
Definition: ketypes.h:275
@ CPU_INTEL
Definition: ketypes.h:95
#define MSR_IA32_MISC_ENABLE
Definition: ketypes.h:246
#define MSR_NXE
Definition: ketypes.h:268
enum _RTL_BSD_ITEM_TYPE RTL_BSD_ITEM_TYPE
@ RtlBsdItemBootCheckpoint
Definition: rtltypes.h:435
@ RtlBsdPowerTransition
Definition: rtltypes.h:433
@ RtlBsdItemMax
Definition: rtltypes.h:442
@ RtlBsdItemBootShutdown
Definition: rtltypes.h:431
@ RtlBsdItemBootAttemptCount
Definition: rtltypes.h:434
@ RtlBsdItemBootGood
Definition: rtltypes.h:430
@ RtlBsdItemBootId
Definition: rtltypes.h:436
#define _Inout_
Definition: no_sal2.h:162
#define _Out_
Definition: no_sal2.h:160
#define _In_
Definition: no_sal2.h:158
#define DBG_UNREFERENCED_LOCAL_VARIABLE(L)
Definition: ntbasedef.h:327
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define STATUS_INVALID_PARAMETER_9
Definition: ntstatus.h:483
#define STATUS_REVISION_MISMATCH
Definition: ntstatus.h:325
#define L(x)
Definition: ntvdm.h:50
PBL_DEVICE_DESCRIPTOR OslLoadDevice
Definition: rosload.c:35
ULONG OslResetBootStatus
Definition: rosload.c:48
ULONG OslFreeMemoryDesctiptorsListSize
Definition: rosload.c:50
VOID OslpInitializeBootStatusDataLog(VOID)
Definition: rosload.c:274
LIST_ENTRY OslFreeMemoryDesctiptorsList
Definition: rosload.c:39
OSL_BSD_ITEM_TABLE_ENTRY OslpBootStatusFields[RtlBsdItemMax]
Definition: rosload.c:57
ULONG_PTR OslMachineHiveHandle
Definition: rosload.c:31
BOOLEAN OslImcProcessingValid
Definition: rosload.c:49
NTSTATUS OslGetBootStatusData(_Out_ PBOOLEAN LastBootGood, _Out_ PBOOLEAN LastBootShutdown, _Out_ PBOOLEAN LastBootCheckpoint, _Out_ PULONG LastBootId, _Out_ PBOOLEAN BootGood, _Out_ PBOOLEAN BootShutdown)
Definition: rosload.c:446
NTSTATUS OslArchKernelSetup(_In_ ULONG Phase, _In_ PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: rosload.c:903
ULONG_PTR OslSystemHiveHandle
Definition: rosload.c:33
NTSTATUS OslExecuteTransition(VOID)
Definition: rosload.c:940
KDESCRIPTOR OslKernelIdt
Definition: rosload.c:28
NTSTATUS NTAPI OslMain(_In_ PBOOT_APPLICATION_PARAMETER_BLOCK BootParameters)
Definition: rosload.c:1055
VOID OslpSanitizeLoadOptionsString(_In_ PWCHAR OptionString, _In_ PWCHAR SanitizeString)
Definition: rosload.c:179
PLOADER_PARAMETER_BLOCK OslLoaderBlock
Definition: rosload.c:21
LIST_ENTRY OslCoreExtensionSubGroups[2]
Definition: rosload.c:41
NTSTATUS OslSetBootStatusData(_In_ BOOLEAN LastBootGood, _In_ BOOLEAN LastBootShutdown, _In_ BOOLEAN LastBootCheckpoint, _In_ ULONG UpdateIncrement, _In_ ULONG BootAttemptCount)
Definition: rosload.c:374
PRTL_BSD_DATA BsdBootStatusData
Definition: rosload.c:55
BOOLEAN OslpAdvancedOptionsRequested(VOID)
Definition: rosload.c:522
VOID OslpSanitizeStringOptions(_In_ PBL_BCD_OPTION BcdOptions)
Definition: rosload.c:189
NTSTATUS OslpRemoveInternalApplicationOptions(VOID)
Definition: rosload.c:198
GUID OslApplicationIdentifier
Definition: rosload.c:46
NTSTATUS OslArchpKernelSetupPhase0(_In_ PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: rosload.c:869
ULONG OslBootCountUpdateRequestForAbort
Definition: rosload.c:126
ULONG_PTR OslElamHiveHandle
Definition: rosload.c:32
PVOID OslMemoryDescriptorBuffer
Definition: rosload.c:51
NTSTATUS OslArchTransferToKernel(_In_ PLOADER_PARAMETER_BLOCK LoaderBlock, _In_ PVOID KernelEntrypoint)
BcdObjectType BlpSbdiCurrentApplicationType
Definition: rosload.c:53
NTSTATUS OslpCheckForcedFailure(VOID)
Definition: rosload.c:249
NTSTATUS OslBlStatusErrorHandler(_In_ ULONG ErrorCode, _In_ ULONG Parameter1, _In_ ULONG_PTR Parameter2, _In_ ULONG_PTR Parameter3, _In_ ULONG_PTR Parameter4)
Definition: rosload.c:159
BOOLEAN OslCurrentBootCheckpoint
Definition: rosload.c:131
VOID ArchRestoreProcessorFeatures(VOID)
Definition: rosload.c:877
ULONGLONG ArchXCr0BitsToClear
Definition: rosload.c:24
ULONG OslBootCountUpdateIncrement
Definition: rosload.c:129
PCHAR OslLoadOptions
Definition: rosload.c:36
BOOLEAN OslCurrentBootShutdown
Definition: rosload.c:133
NTSTATUS OslPrepareTarget(_Out_ PULONG ReturnFlags, _Out_ PBOOLEAN Jump)
Definition: rosload.c:531
BL_BUFFER_DESCRIPTOR OslFinalMemoryMapDescriptorsBuffer
Definition: rosload.c:44
VOID OslAbortBoot(_In_ NTSTATUS Status)
Definition: rosload.c:150
BOOLEAN OslCurrentBootSucceeded
Definition: rosload.c:132
PVOID OslEntryPoint
Definition: rosload.c:22
BOOLEAN BdDebugAfterExitBootServices
Definition: rosload.c:26
KDESCRIPTOR OslKernelGdt
Definition: rosload.c:27
NTSTATUS OslFwpKernelSetupPhase1(_In_ PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: rosload.c:861
ULONG OslBootAttemptCount
Definition: rosload.c:125
VOID OslFatalErrorEx(_In_ ULONG ErrorCode, _In_ ULONG Parameter1, _In_ ULONG_PTR Parameter2, _In_ ULONG_PTR Parameter3)
Definition: rosload.c:138
ULONG_PTR OslImcHiveHandle
Definition: rosload.c:30
NTSTATUS OslpMain(_Out_ PULONG ReturnFlags)
Definition: rosload.c:980
ULONGLONG ArchCr4BitsToClear
Definition: rosload.c:25
LIST_ENTRY OslFinalMemoryMap
Definition: rosload.c:40
PWCHAR OslSystemRoot
Definition: rosload.c:37
PVOID UserSharedAddress
Definition: rosload.c:23
ULONG OslBootAttemptMaximum
Definition: rosload.c:127
LIST_ENTRY OslLoadedFirmwareDriverList
Definition: rosload.c:42
NTSTATUS OslpReadWriteBootStatusData(_In_ BOOLEAN WriteAccess)
Definition: rosload.c:283
NTSTATUS OslpGetSetBootStatusData(_In_ BOOLEAN Read, _In_ RTL_BSD_ITEM_TYPE DataClass, _Out_ PVOID Buffer, _Inout_ PULONG Size)
Definition: rosload.c:308
VOID NTAPI OslDrawLogo(VOID)
Definition: roslogo.c:9767
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
_CRTIMP wchar_t *__cdecl _wcsupr(_Inout_z_ wchar_t *_String)
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define KI_USER_SHARED_DATA
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
_In_ BOOLEAN Read
Definition: strmini.h:479
struct BcdObjectType::@106::@108::@110 Application
Definition: bl.h:855
CHAR Signature[8]
Definition: bl.h:856
DEVICE_TYPE DeviceType
Definition: bl.h:950
PWCHAR FontBaseDirectory
Definition: bl.h:764
ULONG MinimumHeapSize
Definition: bl.h:760
ULONG LibraryFlags
Definition: bl.h:757
ULONG HeapAllocationAttributes
Definition: bl.h:761
ULONG DescriptorCount
Definition: bl.h:763
ULONG MinimumAllocationCount
Definition: bl.h:759
ULONG TranslationType
Definition: bl.h:758
PBL_BCD_OPTION BcdData
Definition: bl.h:867
ULONG Version
Definition: bl.h:816
NTSTATUS Status
Definition: bl.h:817
Definition: typedefs.h:120
Definition: rosload.h:38
ULONG Offset
Definition: rosload.h:39
ULONG Size
Definition: rosload.h:40
UCHAR AabTimeout
Definition: rtltypes.h:1337
RTL_BSD_POWER_BUTTON_PRESS_INFO PowerButtonPressInfo
Definition: rtltypes.h:1349
ULONG ProductType
Definition: rtltypes.h:1335
BOOLEAN LastBootShutdown
Definition: rtltypes.h:1339
ULONG LastSuccessfulShutdownBootId
Definition: rtltypes.h:1346
RTL_BSD_DATA_ERROR_INFO ErrorInfo
Definition: rtltypes.h:1348
UCHAR BootAttemptCount
Definition: rtltypes.h:1342
UCHAR LastBootCheckpoint
Definition: rtltypes.h:1343
BOOLEAN SleepInProgress
Definition: rtltypes.h:1340
ULONG LastBootId
Definition: rtltypes.h:1345
BOOLEAN LastBootSucceeded
Definition: rtltypes.h:1338
ULONG LastReportedAbnormalShutdownBootId
Definition: rtltypes.h:1347
BOOLEAN AabEnabled
Definition: rtltypes.h:1336
UCHAR Checksum
Definition: rtltypes.h:1344
ULONG Version
Definition: rtltypes.h:1334
RTL_BSD_DATA_POWER_TRANSITION PowerTransition
Definition: rtltypes.h:1341
uint32_t * PULONG
Definition: typedefs.h:59
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
unsigned char * PBOOLEAN
Definition: typedefs.h:53
#define NTAPI
Definition: typedefs.h:36
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint16_t * PWCHAR
Definition: typedefs.h:56
uint32_t ULONG
Definition: typedefs.h:59
uint64_t ULONGLONG
Definition: typedefs.h:67
char * PCHAR
Definition: typedefs.h:51
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
ULONG Edx
Definition: ketypes.h:373
LONGLONG QuadPart
Definition: typedefs.h:114
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID _Out_ PINTERFACE _In_ USHORT _In_ USHORT Version
Definition: wdffdo.h:469
#define LoadString
Definition: winuser.h:5831
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
@ WriteAccess
Definition: iotypes.h:425
__wchar_t WCHAR
Definition: xmlstorage.h:180