ReactOS  0.4.13-dev-259-g5ca9c9c
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  {
61  sizeof(&BsdBootStatusData->Version)
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),
101  sizeof(&BsdBootStatusData->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),
113  sizeof(&BsdBootStatusData->ErrorInfo)
114  }, // RtlBsdItemErrorInfo
115  {
116  FIELD_OFFSET(RTL_BSD_DATA, PowerButtonPressInfo),
118  }, // RtlBsdItemPowerButtonPressInfo
119  {
120  FIELD_OFFSET(RTL_BSD_DATA, Checksum),
121  sizeof(&BsdBootStatusData->Checksum)
122  }, // RtlBsdItemChecksum
123 };
124 
128 
130 
134 
135 /* FUNCTIONS *****************************************************************/
136 
137 VOID
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 
149 VOID
152  )
153 {
154  /* For now just do this */
155  BlStatusPrint(L"BOOT ABORTED: %lx\n", Status);
156 }
157 
158 NTSTATUS
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  {
170  return STATUS_NOT_IMPLEMENTED;
171  }
172 
173  /* Handle error 4 as a fatal error 3 internally */
174  OslFatalErrorEx(3, Parameter1, Parameter2, Parameter3);
175  return STATUS_SUCCESS;
176 }
177 
178 VOID
180  _In_ PWCHAR OptionString,
181  _In_ PWCHAR SanitizeString
182  )
183 {
184  /* TODO */
185  return;
186 }
187 
188 VOID
190  _In_ PBL_BCD_OPTION BcdOptions
191  )
192 {
193  /* TODO */
194  return;
195 }
196 
197 NTSTATUS
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 
248 NTSTATUS
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 
273 VOID
275  VOID
276  )
277 {
278  /* TODO */
279  return;
280 }
281 
282 NTSTATUS
285  )
286 {
287  /* Are you trying to write? */
288  if (WriteAccess)
289  {
290  /* Have we already read? */
291  if (!BsdBootStatusData)
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 */
304  return STATUS_NOT_IMPLEMENTED;
305 }
306 
307 NTSTATUS
309  _In_ BOOLEAN Read,
310  _In_ RTL_BSD_ITEM_TYPE DataClass,
313  )
314 {
317 
318  /* No data has been read yet, fail */
319  if (!BsdBootStatusData)
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;
332  Offset = OslpBootStatusFields[DataClass].Offset;
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 
373 NTSTATUS
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 
441 Quickie:
442  return Status;
443 }
444 
445 NTSTATUS
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 
517 Quickie:
518  return Status;
519 }
520 
521 BOOLEAN
523  VOID
524  )
525 {
526  /* TODO */
527  return FALSE;
528 }
529 
530 NTSTATUS
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;
544  PRTL_BSD_DATA_POWER_TRANSITION PowerBuffer;
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;
560  OslElamHiveHandle = -1;
561  OslSystemHiveHandle = -1;
562 
563  /* Initialize memory lists */
567  for (i = 0; i < RTL_NUMBER_OF(OslCoreExtensionSubGroups); i++)
568  {
570  }
571 
572  /* Initialize the memory map descriptor buffer */
575 
576  /* Initialize general pointers */
582 
583  /* Initialize general variables */
584  OslResetBootStatus = 0;
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 */
604  AppId = BlGetApplicationIdentifier();
605  if (AppId)
606  {
607  OslApplicationIdentifier = *AppId;
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 */
838  DBG_UNREFERENCED_LOCAL_VARIABLE(PowerBuffer);
839 
840  /* Printf perf */
841  EndPerf = BlArchGetPerformanceCounter();
842  EfiPrintf(L"Delta: %lld\r\n", EndPerf - StartPerf);
843 
844 Quickie:
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 
860 NTSTATUS
862  _In_ PLOADER_PARAMETER_BLOCK LoaderBlock
863  )
864 {
865  return STATUS_NOT_IMPLEMENTED;
866 }
867 
868 NTSTATUS
870  _In_ PLOADER_PARAMETER_BLOCK LoaderBlock
871  )
872 {
873  return STATUS_NOT_IMPLEMENTED;
874 }
875 
876 VOID
878  VOID
879  )
880 {
881  /* Any XCR0 bits to clear? */
883  {
884  /* Clear them */
885 #if defined(_MSC_VER) && !defined(__clang__)
886  __xsetbv(0, __xgetbv(0) & ~ArchXCr0BitsToClear);
887 #endif
889  }
890 
891  /* Any CR4 bits to clear? */
892  if (ArchCr4BitsToClear)
893  {
894  /* Clear them */
896  ArchCr4BitsToClear = 0;
897  }
898 }
899 
900 NTSTATUS
902  _In_ ULONG Phase,
903  _In_ PLOADER_PARAMETER_BLOCK LoaderBlock
904  )
905 {
906  /* For phase 0, do architectural setup */
907  if (Phase == 0)
908  {
909  return OslArchpKernelSetupPhase0(LoaderBlock);
910  }
911 
912  /* Nothing to do for Phase 1 */
913  if (Phase == 1)
914  {
915  return STATUS_SUCCESS;
916  }
917 
918  /* Relocate the self map */
920 
921  /* Zero out the HAL Heap */
924 
925  /* Move shared user data in its place */
928  PAGE_SIZE);
929 
930  /* Clear XCR0/CR4 CPU features that should be disabled before boot */
932 
933  /* Good to go */
934  return STATUS_SUCCESS;
935 }
936 
937 NTSTATUS
939  VOID
940  )
941 {
943 
944  /* Is the debugger meant to be kept enabled throughout the boot phase? */
946  {
947 #ifdef BL_KD_SUPPORT
948  /* No -- disable it */
949  BlBdStop();
950 #endif
951  }
952 
953  /* Setup Firmware for Phase 1 */
955  if (NT_SUCCESS(Status))
956  {
957  /* Setup kernel for Phase 2 */
959  if (NT_SUCCESS(Status))
960  {
961 #ifdef BL_KD_SUPPORT
962  /* Stop the boot debugger */
963  BlBdStop();
964 #endif
965  /* Jump to the kernel entrypoint */
967 
968  /* Infinite loop if we got here */
969  for (;;);
970  }
971  }
972 
973  /* Return back with the failure code */
974  return Status;
975 }
976 
977 NTSTATUS
979  _Out_ PULONG ReturnFlags
980  )
981 {
982  CPU_INFO CpuInfo;
983  BOOLEAN NxEnabled;
985  BOOLEAN ExecuteJump;
986  LARGE_INTEGER MiscMsr;
987 
988  /* Check if the CPU supports NX */
989  BlArchCpuId(0x80000001, 0, &CpuInfo);
990  if (!(CpuInfo.Edx & 0x10000))
991  {
992  /* It doesn't, check if this is Intel */
993  EfiPrintf(L"NX disabled: %lx\r\n", CpuInfo.Edx);
994  if (BlArchGetCpuVendor() == CPU_INTEL)
995  {
996  /* Then turn off the MSR disable feature for it, enabling NX */
998  EfiPrintf(L"NX being turned on: %llx\r\n", MiscMsr.QuadPart);
999  MiscMsr.HighPart &= MSR_XD_ENABLE_MASK;
1002  NxEnabled = TRUE;
1003  }
1004  }
1005 
1006  /* Turn on NX support with the CPU-generic MSR */
1008 
1009  /* Load the kernel */
1010  Status = OslPrepareTarget(ReturnFlags, &ExecuteJump);
1011  if (NT_SUCCESS(Status) && (ExecuteJump))
1012  {
1013  /* Jump to the kernel */
1015  }
1016 
1017  /* Retore NX support */
1019 
1020  /* Did we manually enable NX? */
1021  if (NxEnabled)
1022  {
1023  /* Turn it back off */
1025  MiscMsr.HighPart |= ~MSR_XD_ENABLE_MASK;
1027  }
1028 
1029  /* Go back */
1030  return Status;
1031 }
1032 
1033 /*++
1034  * @name OslMain
1035  *
1036  * The OslMain function implements the Windows Boot Application entrypoint for
1037  * the OS Loader.
1038  *
1039  * @param BootParameters
1040  * Pointer to the Boot Application Parameter Block.
1041  *
1042  * @return NT_SUCCESS if the image was loaded correctly, relevant error code
1043  * otherwise.
1044  *
1045  *--*/
1046 NTSTATUS
1047 NTAPI
1050  )
1051 {
1052  BL_LIBRARY_PARAMETERS LibraryParameters;
1053  NTSTATUS Status;
1054  PBL_RETURN_ARGUMENTS ReturnArguments;
1055  PBL_APPLICATION_ENTRY AppEntry;
1056  CPU_INFO CpuInfo;
1057  ULONG Flags;
1058 
1059  /* Get the return arguments structure, and set our version */
1060  ReturnArguments = (PBL_RETURN_ARGUMENTS)((ULONG_PTR)BootParameters +
1061  BootParameters->ReturnArgumentsOffset);
1062  ReturnArguments->Version = BL_RETURN_ARGUMENTS_VERSION;
1063 
1064  /* Get the application entry, and validate it */
1065  AppEntry = (PBL_APPLICATION_ENTRY)((ULONG_PTR)BootParameters +
1066  BootParameters->AppEntryOffset);
1067  if (!RtlEqualMemory(AppEntry->Signature,
1069  sizeof(AppEntry->Signature)))
1070  {
1071  /* Unrecognized, bail out */
1073  goto Quickie;
1074  }
1075 
1076  /* Check if CPUID 01h is supported */
1078  {
1079  /* Query CPU features */
1080  BlArchCpuId(1, 0, &CpuInfo);
1081 
1082  /* Check if PAE is supported */
1083  if (CpuInfo.Edx & 0x40)
1084  {
1085  EfiPrintf(L"PAE Supported, but won't be used\r\n");
1086  }
1087  }
1088 
1089  /* Setup the boot library parameters for this application */
1090  BlSetupDefaultParameters(&LibraryParameters);
1091  LibraryParameters.TranslationType = BlVirtual;
1094  LibraryParameters.MinimumAllocationCount = 1024;
1095  LibraryParameters.MinimumHeapSize = 2 * 1024 * 1024;
1096  LibraryParameters.HeapAllocationAttributes = BlMemoryKernelRange;
1097  LibraryParameters.FontBaseDirectory = L"\\Reactos\\Boot\\Fonts";
1098  LibraryParameters.DescriptorCount = 512;
1099 
1100  /* Initialize the boot library */
1101  Status = BlInitializeLibrary(BootParameters, &LibraryParameters);
1102  if (NT_SUCCESS(Status))
1103  {
1104  /* For testing, draw the logo */
1105  OslDrawLogo();
1106 
1107  /* Call the main routine */
1108  Status = OslpMain(&Flags);
1109 
1110  /* Return the flags, and destroy the boot library */
1111  ReturnArguments->Flags = Flags;
1112  BlDestroyLibrary();
1113  }
1114 
1115 Quickie:
1116  /* Return back to boot manager */
1117  ReturnArguments->Status = Status;
1118  return Status;
1119 }
1120 
ULONG_PTR OslSystemHiveHandle
Definition: rosload.c:33
UCHAR BootAttemptCount
Definition: rtltypes.h:1336
#define STATUS_REVISION_MISMATCH
Definition: ntstatus.h:311
signed char * PCHAR
Definition: retypes.h:7
ULONG OslResetBootStatus
Definition: rosload.c:48
PBL_DEVICE_DESCRIPTOR BlpBootDevice
Definition: bootlib.c:16
__INTRIN_INLINE void __writecr4(unsigned int Data)
Definition: intrin_x86.h:1680
_In_ BOOLEAN Read
Definition: strmini.h:479
#define MM_HAL_VA_START
Definition: ketypes.h:256
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
ULONG OslBootCountUpdateIncrement
Definition: rosload.c:129
IN PVOID IN PVOID IN USHORT Version
Definition: pci.h:359
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
VOID BlDestroyLibrary(VOID)
Definition: bootlib.c:405
BOOLEAN LastBootShutdown
Definition: rtltypes.h:1333
ULONG HeapAllocationAttributes
Definition: bl.h:762
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define MM_HAL_VA_END
Definition: ketypes.h:257
#define BL_DEVICE_WRITE_ACCESS
Definition: bl.h:154
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
ULONG Version
Definition: bl.h:817
LIST_ENTRY OslLoadedFirmwareDriverList
Definition: rosload.c:42
PBL_MM_RELOCATE_SELF_MAP BlMmRelocateSelfMap
Definition: arch.c:16
Definition: bl.h:252
OSL_BSD_ITEM_TABLE_ENTRY OslpBootStatusFields[RtlBsdItemMax]
Definition: rosload.c:57
LONG NTSTATUS
Definition: precomp.h:26
LIST_ENTRY OslCoreExtensionSubGroups[2]
Definition: rosload.c:41
#define STATUS_INVALID_PARAMETER_9
Definition: ntstatus.h:469
NTSTATUS NTAPI OslMain(_In_ PBOOT_APPLICATION_PARAMETER_BLOCK BootParameters)
Definition: rosload.c:1048
VOID BlRemoveBootOption(_In_ PBL_BCD_OPTION List, _In_ ULONG Type)
Definition: bcdopt.c:801
CHAR Signature[8]
Definition: bl.h:857
UCHAR Checksum
Definition: rtltypes.h:1338
VOID NTAPI OslDrawLogo(VOID)
Definition: roslogo.c:9767
ULONG LastReportedAbnormalShutdownBootId
Definition: rtltypes.h:1341
PVOID OslMemoryDescriptorBuffer
Definition: rosload.c:51
uint16_t * PWCHAR
Definition: typedefs.h:54
BOOLEAN OslpAdvancedOptionsRequested(VOID)
Definition: rosload.c:522
VOID OslpInitializeBootStatusDataLog(VOID)
Definition: rosload.c:274
ULONG Version
Definition: rtltypes.h:1328
NTSTATUS BlMmFreeHeap(_In_ PVOID Buffer)
Definition: heapalloc.c:663
BOOLEAN OslCurrentBootCheckpoint
Definition: rosload.c:131
NTSTATUS BlGetBootOptionInteger(_In_ PBL_BCD_OPTION List, _In_ ULONG Type, _Out_ PULONGLONG Value)
Definition: bcdopt.c:467
BOOLEAN OslImcProcessingValid
Definition: rosload.c:49
PLOADER_PARAMETER_BLOCK OslLoaderBlock
Definition: rosload.c:21
#define BL_APP_ENTRY_SIGNATURE
Definition: bl.h:54
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:64
BL_LOADED_APPLICATION_ENTRY BlpApplicationEntry
Definition: bootlib.c:19
uint32_t ULONG_PTR
Definition: typedefs.h:63
Definition: bl.h:232
#define MSR_IA32_MISC_ENABLE
Definition: ketypes.h:192
RTL_BSD_DATA_ERROR_INFO ErrorInfo
Definition: rtltypes.h:1342
PBL_MM_ZERO_VIRTUAL_ADDRESS_RANGE BlMmZeroVirtualAddressRange
Definition: arch.c:18
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define MSR_XD_ENABLE_MASK
Definition: ketypes.h:221
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
VOID OslAbortBoot(_In_ NTSTATUS Status)
Definition: rosload.c:150
Definition: bl.h:855
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
PBL_DEVICE_DESCRIPTOR OslLoadDevice
Definition: rosload.c:35
#define BCD_OBJECT_TYPE_APPLICATION
Definition: bcd.h:44
#define OBJ_NAME_PATH_SEPARATOR
Definition: arcname_tests.c:25
NTSTATUS OslpReadWriteBootStatusData(_In_ BOOLEAN WriteAccess)
Definition: rosload.c:283
PBL_BCD_OPTION BcdData
Definition: bl.h:868
ULONG LibraryFlags
Definition: bl.h:758
BOOLEAN OslCurrentBootSucceeded
Definition: rosload.c:132
BOOLEAN SleepInProgress
Definition: rtltypes.h:1334
BOOLEAN BlDeviceIsVirtualPartitionDevice(_In_ PBL_DEVICE_DESCRIPTOR InputDevice, _Outptr_ PBL_DEVICE_DESCRIPTOR *VirtualDevice)
Definition: device.c:612
KDESCRIPTOR OslKernelIdt
Definition: rosload.c:28
VOID OslpSanitizeStringOptions(_In_ PBL_BCD_OPTION BcdOptions)
Definition: rosload.c:189
unsigned char BOOLEAN
DEVICE_TYPE DeviceType
Definition: bl.h:951
smooth NULL
Definition: ftsmooth.c:416
PPC_QUAL unsigned long long __readmsr()
Definition: intrin_ppc.h:741
LIST_ENTRY OslFreeMemoryDesctiptorsList
Definition: rosload.c:39
PVOID BlMmAllocateHeap(_In_ SIZE_T Size)
Definition: heapalloc.c:569
ULONG OslBootCountUpdateRequestForAbort
Definition: rosload.c:126
#define _Out_
Definition: no_sal2.h:323
enum _RTL_BSD_ITEM_TYPE RTL_BSD_ITEM_TYPE
ULONGLONG ArchCr4BitsToClear
Definition: rosload.c:25
Definition: bufpool.h:45
_CRTIMP wchar_t *__cdecl _wcsupr(_Inout_z_ wchar_t *_String)
NTSTATUS OslArchpKernelSetupPhase0(_In_ PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: rosload.c:869
NTSTATUS OslArchKernelSetup(_In_ ULONG Phase, _In_ PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: rosload.c:901
UCHAR LastBootCheckpoint
Definition: rtltypes.h:1337
BOOLEAN BlArchIsCpuIdFunctionSupported(_In_ ULONG Function)
Definition: util.c:856
ULONG_PTR OslImcHiveHandle
Definition: rosload.c:30
NTSTATUS OslFwpKernelSetupPhase1(_In_ PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: rosload.c:861
#define DBG_UNREFERENCED_LOCAL_VARIABLE(L)
Definition: ntbasedef.h:326
BcdObjectType BlpSbdiCurrentApplicationType
Definition: rosload.c:53
NTSYSAPI ULONG NTAPI RtlEqualMemory(CONST VOID *Source1, CONST VOID *Source2, ULONG Length)
static const WCHAR SystemRoot[]
Definition: reg.c:38
BOOLEAN OslCurrentBootShutdown
Definition: rosload.c:133
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ULONG_PTR OslMachineHiveHandle
Definition: rosload.c:31
uint64_t ULONGLONG
Definition: typedefs.h:65
PRTL_BSD_DATA BsdBootStatusData
Definition: rosload.c:55
#define BCD_IMAGE_TYPE_BOOT_APP
Definition: bcd.h:30
NTSTATUS BlInitializeLibrary(_In_ PBOOT_APPLICATION_PARAMETER_BLOCK BootAppParameters, _In_ PBL_LIBRARY_PARAMETERS LibraryParameters)
Definition: bootlib.c:355
RTL_BSD_POWER_BUTTON_PRESS_INFO PowerButtonPressInfo
Definition: rtltypes.h:1343
PWCHAR OslSystemRoot
Definition: rosload.c:37
BOOLEAN AabEnabled
Definition: rtltypes.h:1330
ULONG Size
Definition: rosload.h:40
VOID ArchRestoreProcessorFeatures(VOID)
Definition: rosload.c:877
#define _Inout_
Definition: no_sal2.h:244
FORCEINLINE VOID BlSetupDefaultParameters(_Out_ PBL_LIBRARY_PARAMETERS LibraryParameters)
Definition: bl.h:1355
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define BL_LIBRARY_FLAG_ZERO_HEAP_ALLOCATIONS_ON_FREE
Definition: bl.h:131
PGUID BlGetApplicationIdentifier(VOID)
Definition: bootlib.c:414
ULONG Offset
Definition: rosload.h:39
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
PVOID UserSharedAddress
Definition: rosload.c:23
VOID OslpSanitizeLoadOptionsString(_In_ PWCHAR OptionString, _In_ PWCHAR SanitizeString)
Definition: rosload.c:179
unsigned __int64 ULONG64
Definition: imports.h:198
NTSTATUS OslSetBootStatusData(_In_ BOOLEAN LastBootGood, _In_ BOOLEAN LastBootShutdown, _In_ BOOLEAN LastBootCheckpoint, _In_ ULONG UpdateIncrement, _In_ ULONG BootAttemptCount)
Definition: rosload.c:374
char * PBOOLEAN
Definition: retypes.h:11
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
ULONG MinimumHeapSize
Definition: bl.h:761
static const WCHAR L[]
Definition: oid.c:1250
NTSTATUS BlGetBootOptionString(_In_ PBL_BCD_OPTION List, _In_ ULONG Type, _Out_ PWCHAR *Value)
Definition: bcdopt.c:146
CPU_VENDORS BlArchGetCpuVendor(VOID)
Definition: util.c:937
LIST_ENTRY OslFinalMemoryMap
Definition: rosload.c:40
BOOLEAN BdDebugAfterExitBootServices
Definition: rosload.c:26
#define KI_USER_SHARED_DATA
VOID OslFatalErrorEx(_In_ ULONG ErrorCode, _In_ ULONG Parameter1, _In_ ULONG_PTR Parameter2, _In_ ULONG_PTR Parameter3)
Definition: rosload.c:138
PCHAR OslLoadOptions
Definition: rosload.c:36
#define PAGE_SIZE
Definition: env_spec_w32.h:49
Definition: typedefs.h:117
BOOLEAN LastBootSucceeded
Definition: rtltypes.h:1332
ULONG_PTR OslElamHiveHandle
Definition: rosload.c:32
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
__INTRIN_INLINE unsigned long __readcr4(void)
Definition: intrin_x86.h:1713
NTSTATUS BlAppendBootOptionString(_In_ PBL_LOADED_APPLICATION_ENTRY AppEntry, _In_ ULONG OptionId, _In_ PWCHAR OptionString)
Definition: bcdopt.c:689
NTSTATUS OslExecuteTransition(VOID)
Definition: rosload.c:938
#define MSR_EFER
Definition: ketypes.h:182
PPC_QUAL void __writemsr(const unsigned long Value)
Definition: intrin_ppc.h:748
Status
Definition: gdiplustypes.h:24
ULONG TranslationType
Definition: bl.h:759
#define _In_
Definition: no_sal2.h:204
#define BL_DEVICE_READ_ACCESS
Definition: bl.h:153
ULONG_PTR SIZE_T
Definition: typedefs.h:78
NTSTATUS OslpRemoveInternalApplicationOptions(VOID)
Definition: rosload.c:198
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
GUID OslApplicationIdentifier
Definition: rosload.c:46
UCHAR AabTimeout
Definition: rtltypes.h:1331
NTSTATUS OslArchTransferToKernel(_In_ PLOADER_PARAMETER_BLOCK LoaderBlock, _In_ PVOID KernelEntrypoint)
PVOID OslEntryPoint
Definition: rosload.c:22
NTSTATUS OslGetBootStatusData(_Out_ PBOOLEAN LastBootGood, _Out_ PBOOLEAN LastBootShutdown, _Out_ PBOOLEAN LastBootCheckpoint, _Out_ PULONG LastBootId, _Out_ PBOOLEAN BootGood, _Out_ PBOOLEAN BootShutdown)
Definition: rosload.c:446
ULONG LastSuccessfulShutdownBootId
Definition: rtltypes.h:1340
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
ULONG OslBootAttemptCount
Definition: rosload.c:125
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
ULONG OslFreeMemoryDesctiptorsListSize
Definition: rosload.c:50
RTL_BSD_DATA_POWER_TRANSITION PowerTransition
Definition: rtltypes.h:1335
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
unsigned int * PULONG
Definition: retypes.h:1
VOID EfiPrintf(_In_ PWCHAR Format,...)
Definition: firmware.c:126
ULONG OslBootAttemptMaximum
Definition: rosload.c:127
NTSTATUS OslpCheckForcedFailure(VOID)
Definition: rosload.c:249
#define BL_LIBRARY_FLAG_REINITIALIZE_ALL
Definition: bl.h:130
struct BcdObjectType::@102::@104::@106 Application
BL_BUFFER_DESCRIPTOR OslFinalMemoryMapDescriptorsBuffer
Definition: rosload.c:44
KDESCRIPTOR OslKernelGdt
Definition: rosload.c:27
ULONGLONG BlArchGetPerformanceCounter(VOID)
Definition: util.c:902
Definition: rosload.h:37
VOID BlStatusPrint(_In_ PCWCH Format,...)
Definition: debug.c:75
ULONG MinimumAllocationCount
Definition: bl.h:760
NTSTATUS OslpGetSetBootStatusData(_In_ BOOLEAN Read, _In_ RTL_BSD_ITEM_TYPE DataClass, _Out_ PVOID Buffer, _Inout_ PULONG Size)
Definition: rosload.c:308
ULONG LastBootId
Definition: rtltypes.h:1339
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
struct _BL_APPLICATION_ENTRY * PBL_APPLICATION_ENTRY
ULONG ProductType
Definition: rtltypes.h:1329
VOID BlArchCpuId(_In_ ULONG Function, _In_ ULONG SubFunction, _Out_ PCPU_INFO Result)
Definition: util.c:924
#define BCD_APPLICATION_TYPE_OSLOADER
Definition: bcd.h:36
#define BL_RETURN_ARGUMENTS_VERSION
Definition: bl.h:64
NTSTATUS BlpDeviceOpen(_In_ PBL_DEVICE_DESCRIPTOR Device, _In_ ULONG Flags, _In_ ULONG Unknown, _Out_ PULONG DeviceId)
Definition: device.c:2111
NTSTATUS OslBlStatusErrorHandler(_In_ ULONG ErrorCode, _In_ ULONG Parameter1, _In_ ULONG_PTR Parameter2, _In_ ULONG_PTR Parameter3, _In_ ULONG_PTR Parameter4)
Definition: rosload.c:159
NTSTATUS OslPrepareTarget(_Out_ PULONG ReturnFlags, _Out_ PBOOLEAN Jump)
Definition: rosload.c:531
ULONG Edx
Definition: ketypes.h:299
return STATUS_SUCCESS
Definition: btrfs.c:2745
PWCHAR FontBaseDirectory
Definition: bl.h:765
#define MSR_NXE
Definition: ketypes.h:214
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define LoadString
Definition: winuser.h:5685
NTSTATUS Status
Definition: bl.h:818
ULONG DescriptorCount
Definition: bl.h:764
NTSTATUS OslpMain(_Out_ PULONG ReturnFlags)
Definition: rosload.c:978
ULONGLONG ArchXCr0BitsToClear
Definition: rosload.c:24
NTSTATUS BlAppendBootOptionBoolean(_In_ PBL_LOADED_APPLICATION_ENTRY AppEntry, _In_ ULONG OptionId, _In_ BOOLEAN Value)
Definition: bcdopt.c:625
LONGLONG QuadPart
Definition: typedefs.h:112
PBL_MM_MOVE_VIRTUAL_ADDRESS_RANGE BlMmMoveVirtualAddressRange
Definition: arch.c:17
PBL_STATUS_ERROR_HANDLER BlpStatusErrorHandler
Definition: debug.c:20
struct _BL_RETURN_ARGUMENTS * PBL_RETURN_ARGUMENTS