ReactOS 0.4.16-dev-303-g11d5cb8
winldr.h File Reference
#include <arc/setupblk.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  _LOADER_SYSTEM_BLOCK
 

Macros

#define NUM_GDT   128
 
#define NUM_IDT   0x100
 
#define MAX_OPTIONS_LENGTH   255
 

Typedefs

typedef VOID(NTAPIKERNEL_ENTRY_POINT) (PLOADER_PARAMETER_BLOCK LoaderBlock)
 
typedef struct _LOADER_SYSTEM_BLOCK LOADER_SYSTEM_BLOCK
 
typedef struct _LOADER_SYSTEM_BLOCKPLOADER_SYSTEM_BLOCK
 

Functions

VOID ConvertConfigToVA (PCONFIGURATION_COMPONENT_DATA Start)
 
FORCEINLINE VOID UiResetForSOS (VOID)
 
VOID NtLdrOutputLoadMsg (_In_ PCSTR FileName, _In_opt_ PCSTR Description)
 
PVOID WinLdrLoadModule (PCSTR ModuleName, PULONG Size, TYPE_OF_MEMORY MemoryType)
 
BOOLEAN WinLdrSetupMemoryLayout (IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock)
 
BOOLEAN WinLdrInitSystemHive (IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, IN PCSTR SystemRoot, IN BOOLEAN Setup)
 
BOOLEAN WinLdrScanSystemHive (IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, IN PCSTR SystemRoot)
 
BOOLEAN WinLdrLoadNLSData (_Inout_ PLOADER_PARAMETER_BLOCK LoaderBlock, _In_ PCSTR DirectoryPath, _In_ PCUNICODE_STRING AnsiFileName, _In_ PCUNICODE_STRING OemFileName, _In_ PCUNICODE_STRING LangFileName, _In_ PCUNICODE_STRING OemHalFileName)
 
BOOLEAN WinLdrAddDriverToList (_Inout_ PLIST_ENTRY DriverListHead, _In_ BOOLEAN InsertAtHead, _In_ PCWSTR DriverName, _In_opt_ PCWSTR ImagePath, _In_opt_ PCWSTR GroupName, _In_ ULONG ErrorControl, _In_ ULONG Tag)
 Inserts the specified driver entry into the driver list, or updates an existing entry with new ImagePath, ErrorControl, Group and Tag values.
 
VOID WinLdrInitializePhase1 (PLOADER_PARAMETER_BLOCK LoaderBlock, PCSTR Options, PCSTR SystemPath, PCSTR BootPath, USHORT VersionToBoot)
 
VOID WinLdrpDumpMemoryDescriptors (PLOADER_PARAMETER_BLOCK LoaderBlock)
 
VOID WinLdrpDumpBootDriver (PLOADER_PARAMETER_BLOCK LoaderBlock)
 
VOID WinLdrpDumpArcDisks (PLOADER_PARAMETER_BLOCK LoaderBlock)
 
ARC_STATUS LoadAndBootWindowsCommon (IN USHORT OperatingSystemVersion, IN PLOADER_PARAMETER_BLOCK LoaderBlock, IN PCSTR BootOptions, IN PCSTR BootPath)
 
VOID WinLdrSetupMachineDependent (PLOADER_PARAMETER_BLOCK LoaderBlock)
 
VOID WinLdrSetProcessorContext (_In_ USHORT OperatingSystemVersion)
 
BOOLEAN MempSetupPaging (IN PFN_NUMBER StartPage, IN PFN_NUMBER NumberOfPages, IN BOOLEAN KernelMapping)
 
VOID MempUnmapPage (PFN_NUMBER Page)
 
VOID MempDump (VOID)
 

Variables

PLOADER_SYSTEM_BLOCK WinLdrSystemBlock
 
PCWSTR BootFileSystem
 
BOOLEAN SosEnabled
 

Macro Definition Documentation

◆ MAX_OPTIONS_LENGTH

#define MAX_OPTIONS_LENGTH   255

Definition at line 44 of file winldr.h.

◆ NUM_GDT

#define NUM_GDT   128

Definition at line 16 of file winldr.h.

◆ NUM_IDT

#define NUM_IDT   0x100

Definition at line 17 of file winldr.h.

Typedef Documentation

◆ KERNEL_ENTRY_POINT

typedef VOID(NTAPI * KERNEL_ENTRY_POINT) (PLOADER_PARAMETER_BLOCK LoaderBlock)

Definition at line 13 of file winldr.h.

◆ LOADER_SYSTEM_BLOCK

◆ PLOADER_SYSTEM_BLOCK

Function Documentation

◆ ConvertConfigToVA()

VOID ConvertConfigToVA ( PCONFIGURATION_COMPONENT_DATA  Start)

Definition at line 51 of file conversion.c.

52{
55
56 TRACE("ConvertConfigToVA(Start 0x%X)\n", Start);
57 Child = Start;
58
59 while (Child != NULL)
60 {
61 if (Child->ConfigurationData)
62 Child->ConfigurationData = PaToVa(Child->ConfigurationData);
63
64 if (Child->Child)
65 Child->Child = PaToVa(Child->Child);
66
67 if (Child->Parent)
68 Child->Parent = PaToVa(Child->Parent);
69
70 if (Child->Sibling)
71 Child->Sibling = PaToVa(Child->Sibling);
72
73 if (Child->ComponentEntry.Identifier)
74 Child->ComponentEntry.Identifier = PaToVa(Child->ComponentEntry.Identifier);
75
76 TRACE("Device 0x%X class %d type %d id '%s', parent %p\n", Child,
77 Child->ComponentEntry.Class, Child->ComponentEntry.Type, VaToPa(Child->ComponentEntry.Identifier), Child->Parent);
78
79 // Go through siblings list
80 Sibling = VaToPa(Child->Sibling);
81 while (Sibling != NULL)
82 {
83 if (Sibling->ConfigurationData)
84 Sibling->ConfigurationData = PaToVa(Sibling->ConfigurationData);
85
86 if (Sibling->Child)
87 Sibling->Child = PaToVa(Sibling->Child);
88
89 if (Sibling->Parent)
90 Sibling->Parent = PaToVa(Sibling->Parent);
91
92 if (Sibling->Sibling)
93 Sibling->Sibling = PaToVa(Sibling->Sibling);
94
95 if (Sibling->ComponentEntry.Identifier)
97
98 TRACE("Device 0x%X class %d type %d id '%s', parent %p\n", Sibling,
99 Sibling->ComponentEntry.Class, Sibling->ComponentEntry.Type, VaToPa(Sibling->ComponentEntry.Identifier), Sibling->Parent);
100
101 // Recurse into the Child tree
102 if (VaToPa(Sibling->Child) != NULL)
103 ConvertConfigToVA(VaToPa(Sibling->Child));
104
105 Sibling = VaToPa(Sibling->Sibling);
106 }
107
108 // Go to the next child
109 Child = VaToPa(Child->Child);
110 }
111}
VOID ConvertConfigToVA(PCONFIGURATION_COMPONENT_DATA Start)
Definition: conversion.c:51
FORCEINLINE PVOID VaToPa(PVOID Va)
Definition: conversion.h:15
FORCEINLINE PVOID PaToVa(PVOID Pa)
Definition: conversion.h:22
#define NULL
Definition: types.h:112
return pTarget Start()
#define TRACE(s)
Definition: solgame.cpp:4
CONFIGURATION_COMPONENT ComponentEntry
Definition: arc.h:168
struct _CONFIGURATION_COMPONENT_DATA * Sibling
Definition: arc.h:167
struct _CONFIGURATION_COMPONENT_DATA * Child
Definition: arc.h:166
struct _CONFIGURATION_COMPONENT_DATA * Parent
Definition: arc.h:165
CONFIGURATION_TYPE Type
Definition: arc.h:152
CONFIGURATION_CLASS Class
Definition: arc.h:151
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFDEVICE Child
Definition: wdffdo.h:536

Referenced by ConvertConfigToVA(), and WinLdrInitializePhase1().

◆ LoadAndBootWindowsCommon()

ARC_STATUS LoadAndBootWindowsCommon ( IN USHORT  OperatingSystemVersion,
IN PLOADER_PARAMETER_BLOCK  LoaderBlock,
IN PCSTR  BootOptions,
IN PCSTR  BootPath 
)

Definition at line 1173 of file winldr.c.

1178{
1179 PLOADER_PARAMETER_BLOCK LoaderBlockVA;
1181 PLDR_DATA_TABLE_ENTRY KernelDTE;
1184
1185 TRACE("LoadAndBootWindowsCommon()\n");
1186
1187 ASSERT(OperatingSystemVersion != 0);
1188
1189#ifdef _M_IX86
1190 /* Setup redirection support */
1192#endif
1193
1194 /* Convert BootPath to SystemRoot */
1195 SystemRoot = strstr(BootPath, "\\");
1196
1197 /* Detect hardware */
1198 UiUpdateProgressBar(20, "Detecting hardware...");
1199 LoaderBlock->ConfigurationRoot = MachHwDetect(BootOptions);
1200
1201 /* Initialize the PE loader import-DLL callback, so that we can obtain
1202 * feedback (for example during SOS) on the PE images that get loaded. */
1204
1205 /* Load the operating system core: the Kernel, the HAL and the Kernel Debugger Transport DLL */
1206 Success = LoadWindowsCore(OperatingSystemVersion,
1207 LoaderBlock,
1209 BootPath,
1210 &KernelDTE);
1211 if (!Success)
1212 {
1213 /* Reset the PE loader import-DLL callback */
1215
1216 UiMessageBox("Error loading NTOS core.");
1217 return ENOEXEC;
1218 }
1219
1220 /* Cleanup INI file */
1221 IniCleanup();
1222
1223/****
1224 **** WE HAVE NOW REACHED THE POINT OF NO RETURN !!
1225 ****/
1226
1227 UiSetProgressBarSubset(40, 90); // NTOS goes from 25 to 75%
1228
1229 /* Load boot drivers */
1230 UiSetProgressBarText("Loading boot drivers...");
1231 Success = WinLdrLoadBootDrivers(LoaderBlock, BootPath);
1232 TRACE("Boot drivers loading %s\n", Success ? "successful" : "failed");
1233
1234 UiSetProgressBarSubset(0, 100);
1235
1236 /* Reset the PE loader import-DLL callback */
1238
1239 /* Initialize Phase 1 - no drivers loading anymore */
1240 WinLdrInitializePhase1(LoaderBlock,
1242 SystemRoot,
1243 BootPath,
1244 OperatingSystemVersion);
1245
1247
1248 /* Save entry-point pointer and Loader block VAs */
1250 LoaderBlockVA = PaToVa(LoaderBlock);
1251
1252 /* "Stop all motors", change videomode */
1254
1255 /* Debugging... */
1256 //DumpMemoryAllocMap();
1257
1258 /* Do the machine specific initialization */
1259 WinLdrSetupMachineDependent(LoaderBlock);
1260
1261 /* Map pages and create memory descriptors */
1262 WinLdrSetupMemoryLayout(LoaderBlock);
1263
1264 /* Set processor context */
1265 WinLdrSetProcessorContext(OperatingSystemVersion);
1266
1267 /* Save final value of LoaderPagesSpanned */
1268 LoaderBlock->Extension->LoaderPagesSpanned = LoaderPagesSpanned;
1269
1270 TRACE("Hello from paged mode, KiSystemStartup %p, LoaderBlockVA %p!\n",
1271 KiSystemStartup, LoaderBlockVA);
1272
1273 /* Zero KI_USER_SHARED_DATA page */
1274 RtlZeroMemory((PVOID)KI_USER_SHARED_DATA, MM_PAGE_SIZE);
1275
1276 WinLdrpDumpMemoryDescriptors(LoaderBlockVA);
1277 WinLdrpDumpBootDriver(LoaderBlockVA);
1278#ifndef _M_AMD64
1279 WinLdrpDumpArcDisks(LoaderBlockVA);
1280#endif
1281
1282 /* Pass control */
1283 (*KiSystemStartup)(LoaderBlockVA);
1284
1285 UNREACHABLE; // return ESUCCESS;
1286}
unsigned char BOOLEAN
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
VOID WinLdrSetProcessorContext(_In_ USHORT OperatingSystemVersion)
Definition: winldr.c:342
void WinLdrSetupMachineDependent(PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: winldr.c:374
@ BootOptions
Definition: bl.h:898
#define MachHwDetect(Options)
Definition: machine.h:136
#define MachPrepareForReactOS()
Definition: machine.h:120
VOID UiSetProgressBarText(_In_ PCSTR ProgressText)
Definition: ui.c:476
VOID UiUpdateProgressBar(_In_ ULONG Percentage, _In_opt_ PCSTR ProgressText)
Definition: ui.c:454
VOID UiSetProgressBarSubset(_In_ ULONG Floor, _In_ ULONG Ceiling)
Definition: ui.c:439
VOID UiMessageBox(_In_ PCSTR Format,...)
Definition: ui.c:359
static const WCHAR SystemRoot[]
Definition: reg.c:38
#define ENOEXEC
Definition: errno.h:14
@ Success
Definition: eventcreate.c:712
VOID IniCleanup(VOID)
Definition: inifile.c:238
#define ASSERT(a)
Definition: mode.c:44
#define UNREACHABLE
VOID(NTAPI * KERNEL_ENTRY_POINT)(PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: winldr.h:13
BOOLEAN WinLdrSetupMemoryLayout(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: wlmemory.c:181
DECLSPEC_NORETURN VOID NTAPI KiSystemStartup(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: kiinit.c:476
PELDR_IMPORTDLL_LOAD_CALLBACK PeLdrImportDllLoadCallback
Definition: peloader.c:30
#define KI_USER_SHARED_DATA
Definition: btrfs_drv.h:1876
PVOID EntryPoint
Definition: ntddk_ex.h:203
const char * PCSTR
Definition: typedefs.h:52
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
static BOOLEAN LoadWindowsCore(IN USHORT OperatingSystemVersion, IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, IN PCSTR BootOptions, IN PCSTR BootPath, IN OUT PLDR_DATA_TABLE_ENTRY *KernelDTE)
Definition: winldr.c:622
BOOLEAN WinLdrLoadBootDrivers(PLOADER_PARAMETER_BLOCK LoaderBlock, PCSTR BootPath)
Definition: winldr.c:380
VOID WinLdrpDumpArcDisks(PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: winldr.c:1327
VOID WinLdrSetupEms(IN PCSTR BootOptions)
Definition: headless.c:302
VOID WinLdrInitializePhase1(PLOADER_PARAMETER_BLOCK LoaderBlock, PCSTR Options, PCSTR SystemRoot, PCSTR BootPath, USHORT VersionToBoot)
Definition: winldr.c:117
VOID WinLdrpDumpMemoryDescriptors(PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: winldr.c:1289
VOID WinLdrpDumpBootDriver(PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: winldr.c:1308
ULONG LoaderPagesSpanned
Definition: mm.c:29
static VOID NTAPI NtLdrImportDllLoadCallback(_In_ PCSTR FileName)
Definition: winldr.c:47

Referenced by LoadAndBootWindows(), and LoadReactOSSetup().

◆ MempDump()

VOID MempDump ( VOID  )

Definition at line 424 of file winldr.c.

425{
426}

Referenced by WinLdrSetupMemoryLayout().

◆ MempSetupPaging()

BOOLEAN MempSetupPaging ( IN PFN_NUMBER  StartPage,
IN PFN_NUMBER  NumberOfPages,
IN BOOLEAN  KernelMapping 
)

Definition at line 171 of file winldr.c.

174{
175 TRACE(">>> MempSetupPaging(0x%lx, %ld, %p)\n",
176 StartPage, NumberOfPages, StartPage * PAGE_SIZE + KSEG0_BASE);
177
178 /* Identity mapping */
181 NumberOfPages) != NumberOfPages)
182 {
183 ERR("Failed to map pages %ld, %ld\n",
184 StartPage, NumberOfPages);
185 return FALSE;
186 }
187
188 /* Kernel mapping */
189 if (KernelMapping)
190 {
193 NumberOfPages) != NumberOfPages)
194 {
195 ERR("Failed to map pages %ld, %ld\n",
196 StartPage, NumberOfPages);
197 return FALSE;
198 }
199 }
200
201 return TRUE;
202}
static PFN_NUMBER MempMapRangeOfPages(ULONG64 VirtualAddress, ULONG64 PhysicalAddress, PFN_NUMBER cPages)
Definition: winldr.c:152
#define ERR(fmt,...)
Definition: precomp.h:57
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define KSEG0_BASE
Definition: ketypes.h:343
int WINAPI StartPage(_In_ HDC)

Referenced by MempSetupPagingForRegion(), and WinLdrSetupMemoryLayout().

◆ MempUnmapPage()

VOID MempUnmapPage ( PFN_NUMBER  Page)

Definition at line 205 of file winldr.c.

206{
207 // TRACE(">>> MempUnmapPage\n");
208}

◆ NtLdrOutputLoadMsg()

VOID NtLdrOutputLoadMsg ( _In_ PCSTR  FileName,
_In_opt_ PCSTR  Description 
)

Definition at line 54 of file winldr.c.

57{
58 if (SosEnabled)
59 {
60 printf(" %s\n", FileName);
61 TRACE("Loading: %s\n", FileName);
62 }
63 else
64 {
65 /* Inform the user we load a file */
66 CHAR ProgressString[256];
67
68 RtlStringCbPrintfA(ProgressString, sizeof(ProgressString),
69 "Loading %s...",
71 // UiSetProgressBarText(ProgressString);
72 // UiIndicateProgress();
73 UiDrawStatusText(ProgressString);
74 }
75}
VOID UiDrawStatusText(PCSTR StatusText)
Definition: ui.c:286
static const WCHAR Description[]
Definition: oid.c:1266
#define printf
Definition: freeldr.h:97
NTSTRSAFEVAPI RtlStringCbPrintfA(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ _Printf_format_string_ NTSTRSAFE_PCSTR pszFormat,...)
Definition: ntstrsafe.h:1148
BOOLEAN SosEnabled
Definition: winldr.c:33
char CHAR
Definition: xmlstorage.h:175

Referenced by LoadModule(), NtLdrImportDllLoadCallback(), WinLdrLoadDeviceDriver(), WinLdrLoadModule(), WinLdrLoadNLSData(), and WinLdrLoadSystemHive().

◆ UiResetForSOS()

FORCEINLINE VOID UiResetForSOS ( VOID  )

Definition at line 84 of file winldr.h.

85{
86#ifdef _M_ARM
87 /* Re-initialize the UI */
89#else
90 /* Reset the UI and switch to MiniTui */
94#endif
95 /* Disable the progress bar */
97}
UI_PROGRESS_BAR UiProgressBar
Definition: ui.c:62
UIVTBL UiVtbl
Definition: ui.c:64
BOOLEAN UiInitialize(BOOLEAN ShowUi)
Definition: ui.c:92
const UIVTBL MiniTuiVtbl
Definition: minitui.c:237
BOOLEAN Show
Definition: ui.h:136
BOOLEAN(* Initialize)(VOID)
Definition: ui.h:250
VOID(* UnInitialize)(VOID)
Definition: ui.h:251

Referenced by LoadAndBootWindows(), and LoadReactOSSetup().

◆ WinLdrAddDriverToList()

BOOLEAN WinLdrAddDriverToList ( _Inout_ PLIST_ENTRY  DriverListHead,
_In_ BOOLEAN  InsertAtHead,
_In_ PCWSTR  DriverName,
_In_opt_ PCWSTR  ImagePath,
_In_opt_ PCWSTR  GroupName,
_In_ ULONG  ErrorControl,
_In_ ULONG  Tag 
)

Inserts the specified driver entry into the driver list, or updates an existing entry with new ImagePath, ErrorControl, Group and Tag values.

Parameters
[in,out]DriverListHeadThe driver list where to insert the driver entry.
[in]InsertAtHeadWhether to insert the driver at the head (TRUE) or at the tail (FALSE) of the driver list.
[in]DriverNameThe driver's name.
[in]ImagePathOptional path the the driver's image. If none is specified, a default path is constructed out of the driver's name.
[in]GroupNameOptional driver group name.
[in]ErrorControl
[in]TagThe ErrorControl and group Tag values for the driver.
Returns
TRUE if the driver has been inserted into the list or updated, FALSE if not.

Definition at line 645 of file wlregistry.c.

653{
654 PBOOT_DRIVER_NODE DriverNode;
656 BOOLEAN AlreadyInserted;
658 UNICODE_STRING DriverNameU;
661 UNICODE_STRING RegistryString = {0};
662 UNICODE_STRING GroupString = {0};
663
664 /* Check whether the driver is already in the list */
665 RtlInitUnicodeString(&DriverNameU, DriverName);
666 AlreadyInserted = CmpIsDriverInList(DriverListHead,
667 &DriverNameU,
668 &DriverNode);
669 if (AlreadyInserted)
670 {
671 /* If so, we have obtained its node */
672 ASSERT(DriverNode);
673 DriverEntry = &DriverNode->ListEntry;
674 }
675 else
676 {
677 /* Allocate a driver node and initialize it */
678 DriverNode = CmpAllocate(sizeof(BOOT_DRIVER_NODE), FALSE, TAG_CM);
679 if (!DriverNode)
680 return FALSE;
681
682 RtlZeroMemory(DriverNode, sizeof(BOOT_DRIVER_NODE));
683 DriverEntry = &DriverNode->ListEntry;
684
685 /* Driver Name */
686 RtlInitEmptyUnicodeString(&DriverNode->Name,
687 CmpAllocate(DriverNameU.Length, FALSE, TAG_CM),
688 DriverNameU.Length);
689 if (!DriverNode->Name.Buffer)
690 goto Failure;
691
692 if (!NT_SUCCESS(RtlAppendUnicodeStringToString(&DriverNode->Name, &DriverNameU)))
693 goto Failure;
694 }
695
696 /* Check whether we have a valid ImagePath. If not, we need
697 * to build it like "System32\\Drivers\\blah.sys" */
698 if (ImagePath && *ImagePath)
699 {
700 /* Just copy ImagePath to the corresponding field in the structure */
701 PathLength = (USHORT)(wcslen(ImagePath)) * sizeof(WCHAR);
702 RtlInitEmptyUnicodeString(&FilePath,
704 PathLength);
705 if (!FilePath.Buffer)
706 goto Failure;
707
709 goto Failure;
710 }
711 else
712 {
713 /* We have to construct ImagePath ourselves */
714 PathLength = DriverNode->Name.Length + sizeof(L"system32\\drivers\\.sys");
715 RtlInitEmptyUnicodeString(&FilePath,
717 PathLength);
718 if (!FilePath.Buffer)
719 goto Failure;
720
721 if (!NT_SUCCESS(RtlAppendUnicodeToString(&FilePath, L"system32\\drivers\\")) ||
724 {
725 goto Failure;
726 }
727 }
728
729 /* Registry path */
731 L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\");
732 PathLength = RegistryPath.Length + DriverNode->Name.Length;
733 RtlInitEmptyUnicodeString(&RegistryString,
735 PathLength);
736 if (!RegistryString.Buffer)
737 goto Failure;
738
739 if (!NT_SUCCESS(RtlAppendUnicodeStringToString(&RegistryString, &RegistryPath)) ||
740 !NT_SUCCESS(RtlAppendUnicodeStringToString(&RegistryString, &DriverNode->Name)))
741 {
742 goto Failure;
743 }
744
745 /* Group */
746 if (GroupName && *GroupName)
747 {
748 /*
749 * NOTE: Here we can use our own allocator as we alone maintain the
750 * group string. This is different from the other allocated strings,
751 * where we instead need to use the same (hive) allocator as the
752 * one used by CmpAddDriverToList(), for interoperability purposes.
753 */
754 RtlCreateUnicodeString(&GroupString, GroupName);
755 if (!GroupString.Buffer)
756 goto Failure;
757 }
758 else
759 {
760 RtlInitEmptyUnicodeString(&GroupString, NULL, 0);
761 }
762
763 /* Set or replace the driver node's file path */
764 if (DriverEntry->FilePath.Buffer)
765 {
766 CmpFree(DriverEntry->FilePath.Buffer,
767 DriverEntry->FilePath.MaximumLength);
768 }
769 DriverEntry->FilePath = FilePath;
770 FilePath.Buffer = NULL;
771
772 /* Set or replace the driver node's registry path */
773 if (DriverEntry->RegistryPath.Buffer)
774 {
775 CmpFree(DriverEntry->RegistryPath.Buffer,
776 DriverEntry->RegistryPath.MaximumLength);
777 }
778 DriverEntry->RegistryPath = RegistryString;
779 RegistryString.Buffer = NULL;
780
781 /* Set or replace the driver node's group */
782 if (DriverNode->Group.Buffer)
783 {
784 /*
785 * If the buffer is inside the registry hive's memory, this means that
786 * it has been set by CmpAddDriverToList() to point to some data within
787 * the hive; thus we should not free the buffer but just replace it.
788 * Otherwise, this is a buffer previously allocated by ourselves, that
789 * we can free.
790 *
791 * NOTE: This function does not have an explicit LoaderBlock input
792 * parameter pointer, since it does not need it, except for this
793 * very place. So instead, use the global WinLdrSystemBlock pointer.
794 */
795 PLOADER_PARAMETER_BLOCK LoaderBlock =
797
798 if (!LoaderBlock || !LoaderBlock->RegistryBase || !LoaderBlock->RegistryLength ||
799 ((ULONG_PTR)DriverNode->Group.Buffer <
800 (ULONG_PTR)VaToPa(LoaderBlock->RegistryBase)) ||
801 ((ULONG_PTR)DriverNode->Group.Buffer >=
802 (ULONG_PTR)VaToPa(LoaderBlock->RegistryBase) + LoaderBlock->RegistryLength))
803 {
804 RtlFreeUnicodeString(&DriverNode->Group);
805 }
806 }
807 DriverNode->Group = GroupString;
808 GroupString.Buffer = NULL;
809
810 /* ErrorControl and Tag */
811 DriverNode->ErrorControl = ErrorControl;
812 DriverNode->Tag = Tag;
813
814 /* Insert the entry into the list if it does not exist there already */
815 if (!AlreadyInserted)
816 {
817 if (InsertAtHead)
818 InsertHeadList(DriverListHead, &DriverEntry->Link);
819 else
820 InsertTailList(DriverListHead, &DriverEntry->Link);
821 }
822
823 return TRUE;
824
825Failure:
826 if (GroupString.Buffer)
827 RtlFreeUnicodeString(&GroupString);
828 if (RegistryString.Buffer)
829 CmpFree(RegistryString.Buffer, RegistryString.MaximumLength);
830 if (FilePath.Buffer)
831 CmpFree(FilePath.Buffer, FilePath.MaximumLength);
832
833 /* If it does not exist in the list already, free the allocated
834 * driver node, otherwise keep the original one in place. */
835 if (!AlreadyInserted)
836 {
837 if (DriverEntry->RegistryPath.Buffer)
838 {
839 CmpFree(DriverEntry->RegistryPath.Buffer,
840 DriverEntry->RegistryPath.MaximumLength);
841 }
842 if (DriverEntry->FilePath.Buffer)
843 {
844 CmpFree(DriverEntry->FilePath.Buffer,
845 DriverEntry->FilePath.MaximumLength);
846 }
847 if (DriverNode->Name.Buffer)
848 {
849 CmpFree(DriverNode->Name.Buffer,
850 DriverNode->Name.MaximumLength);
851 }
852 CmpFree(DriverNode, sizeof(BOOT_DRIVER_NODE));
853 }
854
855 return FALSE;
856}
static USHORT PathLength
PCWSTR FilePath
PVOID NTAPI CmpAllocate(_In_ SIZE_T Size, _In_ BOOLEAN Paged, _In_ ULONG Tag)
Definition: bootreg.c:90
VOID NTAPI CmpFree(_In_ PVOID Ptr, _In_ ULONG Quota)
Definition: bootreg.c:105
#define TAG_CM
Definition: cmlib.h:212
NTSYSAPI BOOLEAN NTAPI RtlCreateUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
DRIVER_INITIALIZE DriverEntry
Definition: condrv.c:21
#define ULONG_PTR
Definition: config.h:101
#define InsertTailList(ListHead, Entry)
#define InsertHeadList(ListHead, Entry)
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define TAG_WLDR_NAME
Definition: winldr.h:15
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define L(x)
Definition: ntvdm.h:50
unsigned short USHORT
Definition: pedump.c:61
Definition: arc.h:246
UNICODE_STRING Group
Definition: cmboot.h:16
BOOT_DRIVER_LIST_ENTRY ListEntry
Definition: cmboot.h:15
ULONG ErrorControl
Definition: cmboot.h:19
UNICODE_STRING Name
Definition: cmboot.h:17
ULONG RegistryLength
Definition: arc.h:547
LOADER_PARAMETER_BLOCK LoaderBlock
Definition: winldr.h:48
USHORT MaximumLength
Definition: env_spec_w32.h:370
uint32_t ULONG_PTR
Definition: typedefs.h:65
_Must_inspect_result_ _In_ WDFDEVICE _In_ BOOLEAN _In_opt_ PVOID Tag
Definition: wdfdevice.h:4065
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:215
PLOADER_SYSTEM_BLOCK WinLdrSystemBlock
Definition: winldr.c:29
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by SetupLdrScanBootDrivers().

◆ WinLdrInitializePhase1()

VOID WinLdrInitializePhase1 ( PLOADER_PARAMETER_BLOCK  LoaderBlock,
PCSTR  Options,
PCSTR  SystemPath,
PCSTR  BootPath,
USHORT  VersionToBoot 
)

Definition at line 117 of file winldr.c.

122{
123 /*
124 * Examples of correct options and paths:
125 * CHAR Options[] = "/DEBUGPORT=COM1 /BAUDRATE=115200";
126 * CHAR Options[] = "/NODEBUG";
127 * CHAR SystemRoot[] = "\\WINNT\\";
128 * CHAR ArcBoot[] = "multi(0)disk(0)rdisk(0)partition(1)";
129 */
130
131 PSTR LoadOptions, NewLoadOptions;
132 CHAR HalPath[] = "\\";
133 CHAR ArcBoot[MAX_PATH+1];
134 CHAR MiscFiles[MAX_PATH+1];
135 ULONG i;
136 ULONG_PTR PathSeparator;
138
139 /* Construct SystemRoot and ArcBoot from SystemPath */
140 PathSeparator = strstr(BootPath, "\\") - BootPath;
141 RtlStringCbCopyNA(ArcBoot, sizeof(ArcBoot), BootPath, PathSeparator);
142
143 TRACE("ArcBoot: '%s'\n", ArcBoot);
144 TRACE("SystemRoot: '%s'\n", SystemRoot);
145 TRACE("Options: '%s'\n", Options);
146
147 /* Fill ARC BootDevice */
150 LoaderBlock->ArcBootDeviceName = PaToVa(LoaderBlock->ArcBootDeviceName);
151
152//
153// IMPROVE!!
154// SetupBlock->ArcSetupDeviceName must be the path to the setup **SOURCE**,
155// and not the setup boot path. Indeed they may differ!!
156//
157 if (LoaderBlock->SetupLdrBlock)
158 {
159 PSETUP_LOADER_BLOCK SetupBlock = LoaderBlock->SetupLdrBlock;
160
161 /* Adjust the ARC path in the setup block - Matches ArcBoot path */
163 SetupBlock->ArcSetupDeviceName = PaToVa(SetupBlock->ArcSetupDeviceName);
164
165 /* Convert the setup block pointer */
166 LoaderBlock->SetupLdrBlock = PaToVa(LoaderBlock->SetupLdrBlock);
167 }
168
169 /* Fill ARC HalDevice, it matches ArcBoot path */
171 LoaderBlock->ArcHalDeviceName = PaToVa(LoaderBlock->ArcHalDeviceName);
172
173 /* Fill SystemRoot */
176 LoaderBlock->NtBootPathName = PaToVa(LoaderBlock->NtBootPathName);
177
178 /* Fill NtHalPathName */
180 RtlStringCbCopyA(LoaderBlock->NtHalPathName, sizeof(WinLdrSystemBlock->NtHalPathName), HalPath);
181 LoaderBlock->NtHalPathName = PaToVa(LoaderBlock->NtHalPathName);
182
183 /* Fill LoadOptions and strip the '/' switch symbol in front of each option */
184 NewLoadOptions = LoadOptions = LoaderBlock->LoadOptions = WinLdrSystemBlock->LoadOptions;
186
187 do
188 {
189 while (*LoadOptions == '/')
190 ++LoadOptions;
191
192 *NewLoadOptions++ = *LoadOptions;
193 } while (*LoadOptions++);
194
195 LoaderBlock->LoadOptions = PaToVa(LoaderBlock->LoadOptions);
196
197 /* ARC devices */
200
201 /* Convert ARC disk information from freeldr to a correct format */
202 for (i = 0; i < reactos_disk_count; i++)
203 {
204 PARC_DISK_SIGNATURE_EX ArcDiskSig;
205
206 /* Allocate the ARC structure */
207 ArcDiskSig = FrLdrHeapAlloc(sizeof(ARC_DISK_SIGNATURE_EX), 'giSD');
208 if (!ArcDiskSig)
209 {
210 ERR("Failed to allocate ARC structure! Ignoring remaining ARC disks. (i = %lu, DiskCount = %lu)\n",
212 break;
213 }
214
215 /* Copy the data over */
217
218 /* Set the ARC Name pointer */
219 ArcDiskSig->DiskSignature.ArcName = PaToVa(ArcDiskSig->ArcName);
220
221 /* Insert into the list */
223 &ArcDiskSig->DiskSignature.ListEntry);
224 }
225
226 /* Convert all lists to Virtual address */
227
228 /* Convert the ArcDisks list to virtual address */
230 LoaderBlock->ArcDiskInformation = PaToVa(LoaderBlock->ArcDiskInformation);
231
232 /* Convert configuration entries to VA */
234 LoaderBlock->ConfigurationRoot = PaToVa(LoaderBlock->ConfigurationRoot);
235
236 /* Convert all DTE into virtual addresses */
237 List_PaToVa(&LoaderBlock->LoadOrderListHead);
238
239 /* This one will be converted right before switching to virtual paging mode */
240 //List_PaToVa(&LoaderBlock->MemoryDescriptorListHead);
241
242 /* Convert list of boot drivers */
243 List_PaToVa(&LoaderBlock->BootDriverListHead);
244
245 Extension = LoaderBlock->Extension;
246
247 /* FIXME! HACK value for docking profile */
248 Extension->Profile.Status = 2;
249
250 /* Check if FreeLdr detected a ACPI table */
251 if (AcpiPresent)
252 {
253 /* Set the pointer to something for compatibility */
254 Extension->AcpiTable = (PVOID)1;
255 // FIXME: Extension->AcpiTableSize;
256 }
257
258 if (VersionToBoot >= _WIN32_WINNT_VISTA)
259 {
260 Extension->BootViaWinload = 1;
261 Extension->LoaderPerformanceData = PaToVa(&WinLdrSystemBlock->LoaderPerformanceData);
262
263 InitializeListHead(&Extension->BootApplicationPersistentData);
264 List_PaToVa(&Extension->BootApplicationPersistentData);
265 }
266
267#ifdef _M_IX86
268 /* Set headless block pointer */
270 {
271 Extension->HeadlessLoaderBlock = &WinLdrSystemBlock->HeadlessLoaderBlock;
272 RtlCopyMemory(Extension->HeadlessLoaderBlock,
274 sizeof(HEADLESS_LOADER_BLOCK));
275 Extension->HeadlessLoaderBlock = PaToVa(Extension->HeadlessLoaderBlock);
276 }
277#endif
278 /* Load drivers database */
279 RtlStringCbCopyA(MiscFiles, sizeof(MiscFiles), BootPath);
280 RtlStringCbCatA(MiscFiles, sizeof(MiscFiles), "AppPatch\\drvmain.sdb");
281 Extension->DrvDBImage = PaToVa(WinLdrLoadModule(MiscFiles,
282 &Extension->DrvDBSize,
284
285 /* Convert the extension block pointer */
286 LoaderBlock->Extension = PaToVa(LoaderBlock->Extension);
287
288 TRACE("WinLdrInitializePhase1() completed\n");
289}
FORCEINLINE PVOID FrLdrHeapAlloc(SIZE_T MemorySize, ULONG Tag)
Definition: mm.h:174
#define MAX_PATH
Definition: compat.h:34
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
_Inout_opt_ PUNICODE_STRING Extension
Definition: fltkernel.h:1092
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 List_PaToVa(_In_ LIST_ENTRY *ListEntry)
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 RtlStringCbCopyNA(_Out_writes_bytes_(cbDest) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_reads_bytes_(cbToCopy) STRSAFE_LPCSTR pszSrc, _In_ size_t cbToCopy)
Definition: ntstrsafe.h:395
NTSTRSAFEAPI RtlStringCbCopyA(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCSTR pszSrc)
Definition: ntstrsafe.h:156
@ LoaderRegistryData
Definition: arc.h:193
#define _WIN32_WINNT_VISTA
Definition: sdkddkver.h:25
LIST_ENTRY DiskSignatureListHead
Definition: arc.h:268
CHAR ArcName[MAX_PATH]
Definition: winldr.h:37
ARC_DISK_SIGNATURE DiskSignature
Definition: winldr.h:36
LIST_ENTRY ListEntry
Definition: arc.h:255
PCHAR ArcName
Definition: arc.h:257
LIST_ENTRY BootDriverListHead
Definition: arc.h:542
PCONFIGURATION_COMPONENT_DATA ConfigurationRoot
Definition: arc.h:549
LIST_ENTRY LoadOrderListHead
Definition: arc.h:540
PARC_DISK_INFORMATION ArcDiskInformation
Definition: arc.h:556
PSTR ArcBootDeviceName
Definition: arc.h:550
PLOADER_PARAMETER_EXTENSION Extension
Definition: arc.h:559
struct _SETUP_LOADER_BLOCK * SetupLdrBlock
Definition: arc.h:558
CHAR NtHalPathName[MAX_PATH+1]
Definition: winldr.h:59
ARC_DISK_INFORMATION ArcDiskInformation
Definition: winldr.h:60
CHAR NtBootPathName[MAX_PATH+1]
Definition: winldr.h:58
CHAR ArcBootDeviceName[MAX_PATH+1]
Definition: winldr.h:56
LOADER_PERFORMANCE_DATA LoaderPerformanceData
Definition: winldr.h:61
CHAR LoadOptions[MAX_OPTIONS_LENGTH+1]
Definition: winldr.h:55
PCHAR ArcSetupDeviceName
Definition: setupblk.h:112
char * PSTR
Definition: typedefs.h:51
void * PVOID
Definition: typedefs.h:50
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG
Definition: typedefs.h:59
_In_ PWDFDEVICE_INIT _In_ PWDF_REMOVE_LOCK_OPTIONS Options
Definition: wdfdevice.h:3534
ARC_DISK_SIGNATURE_EX reactos_arc_disk_info[]
Definition: archwsup.c:69
BOOLEAN AcpiPresent
Definition: macharm.c:22
PVOID WinLdrLoadModule(PCSTR ModuleName, PULONG Size, TYPE_OF_MEMORY MemoryType)
Definition: winldr.c:441
ULONG reactos_disk_count
Definition: archwsup.c:68
HEADLESS_LOADER_BLOCK LoaderRedirectionInformation
Definition: headless.c:30
BOOLEAN WinLdrTerminalConnected
Definition: headless.c:31

Referenced by LoadAndBootWindowsCommon().

◆ WinLdrInitSystemHive()

BOOLEAN WinLdrInitSystemHive ( IN OUT PLOADER_PARAMETER_BLOCK  LoaderBlock,
IN PCSTR  SystemRoot,
IN BOOLEAN  Setup 
)

Definition at line 125 of file wlregistry.c.

129{
130 CHAR SearchPath[1024];
131 PVOID ChunkBase;
132 PCSTR HiveName;
135
136 /* Load the corresponding text-mode setup system hive or the standard hive */
137 if (Setup)
138 {
140 HiveName = "SETUPREG.HIV";
141 }
142 else
143 {
145 RtlStringCbCatA(SearchPath, sizeof(SearchPath), "system32\\config\\");
146 HiveName = "SYSTEM";
147 }
148
149 TRACE("WinLdrInitSystemHive: loading hive %s%s\n", SearchPath, HiveName);
150 Success = WinLdrLoadSystemHive(LoaderBlock, SearchPath, HiveName, &Reason);
151 if (!Success)
152 {
153 /* Check whether the SYSTEM hive does not exist or is too corrupt to be read */
154 if (Reason == CorruptHive || Reason == NoHive)
155 {
156 /* Try loading the alternate hive, the main hive should be recovered later */
157 goto LoadAlternateHive;
158 }
159
160 /* We are failing for other reason, bail out */
161 UiMessageBox("Could not load %s hive!", HiveName);
162 return FALSE;
163 }
164
165 /* Import what was loaded */
166 Success = RegImportBinaryHive(VaToPa(LoaderBlock->RegistryBase), LoaderBlock->RegistryLength, SearchPath, FALSE);
167 if (!Success)
168 {
169 /*
170 * Importing of the SYSTEM hive failed. The scenarios that would
171 * have made this possible are the following:
172 *
173 * 1. The primary hive is corrupt beyond repair (such as when
174 * core FS structures are total toast);
175 *
176 * 2. Repairing the hive could with a LOG could not recover it
177 * to the fullest. This is the case when the hive and LOG have
178 * diverged too much, or are mismatched, or the containing healthy
179 * data in the LOG was not marked as dirty that could be copied
180 * into the primary hive;
181 *
182 * 3. LOG is bad (e.g. corrupt dirty vector);
183 *
184 * 4. LOG does not physically exist on the backing storage.
185 *
186 * 5. SYSTEM hive does not physically exist or it is a 0 bytes file
187 * (the latter case still counts as corruption).
188 *
189 * With the hope to boot the system, load the mirror counterpart
190 * of the main hive, the alternate. The kernel should be able to recover
191 * the main hive later on as soon as it starts writing to it.
192 */
193LoadAlternateHive:
194 HiveName = "SYSTEM.ALT";
195 Success = WinLdrLoadSystemHive(LoaderBlock, SearchPath, HiveName, &Reason);
196 if (!Success)
197 {
198 UiMessageBox("Could not load %s hive!", HiveName);
199 return FALSE;
200 }
201
202 /* Retry importing it again */
203 Success = RegImportBinaryHive(VaToPa(LoaderBlock->RegistryBase), LoaderBlock->RegistryLength, SearchPath, TRUE);
204 if (!Success)
205 {
206 UiMessageBox("Importing binary hive failed!");
207 return FALSE;
208 }
209
210 /*
211 * Acknowledge the kernel we recovered the SYSTEM hive
212 * on our side by loading the alternate variant of the hive.
213 */
214 WARN("SYSTEM hive does not exist or is corrupt and SYSTEM.ALT has been loaded!\n");
215 ChunkBase = VaToPa(LoaderBlock->RegistryBase);
216 ((PHBASE_BLOCK)ChunkBase)->BootRecover = HBOOT_BOOT_RECOVERED_BY_ALTERNATE_HIVE;
217 }
218
219 // FIXME: Load SYSTEM.SAV if GUI setup installation is still in progress
220
221 /* Initialize the 'CurrentControlSet' link */
223 {
224 UiMessageBox("Initializing CurrentControlSet link failed!");
225 return FALSE;
226 }
227
228 return TRUE;
229}
ACPI_PHYSICAL_ADDRESS ACPI_SIZE BOOLEAN Warn UINT32 *TableIdx UINT32 ACPI_TABLE_HEADER *OutTableHeader ACPI_TABLE_HEADER **OutTable ACPI_HANDLE UINT32 ACPI_WALK_CALLBACK ACPI_WALK_CALLBACK void void **ReturnValue UINT32 ACPI_BUFFER *RetPathPtr ACPI_OBJECT_HANDLER void *Data ACPI_OBJECT_HANDLER void **Data ACPI_STRING ACPI_OBJECT_LIST ACPI_BUFFER *ReturnObjectBuffer ACPI_DEVICE_INFO **ReturnBuffer ACPI_HANDLE ACPI_HANDLE ACPI_HANDLE *OutHandle ACPI_HANDLE *OutHandle void *Context void *Context ACPI_EVENT_HANDLER Handler UINT32 UINT32 ACPI_GPE_HANDLER void *Context UINT32 ACPI_NOTIFY_HANDLER void *Context ACPI_ADR_SPACE_TYPE ACPI_ADR_SPACE_HANDLER ACPI_ADR_SPACE_SETUP Setup
Definition: acpixf.h:834
#define WARN(fmt,...)
Definition: precomp.h:61
BOOLEAN RegInitCurrentControlSet(_In_ BOOLEAN LastKnownGood)
Definition: registry.c:525
BOOLEAN RegImportBinaryHive(_In_ PVOID ChunkBase, _In_ ULONG ChunkSize, _In_ PCSTR SearchPath, _In_ BOOLEAN LoadAlternate)
Imports the SYSTEM binary hive from the registry base chunk that's been provided by the loader block.
Definition: registry.c:449
#define HBOOT_BOOT_RECOVERED_BY_ALTERNATE_HIVE
Definition: hivedata.h:96
struct _HBASE_BLOCK * PHBASE_BLOCK
PVOID PVOID PWCHAR PVOID USHORT PULONG Reason
Definition: env.c:47
#define SearchPath
Definition: winbase.h:3925
static BOOLEAN WinLdrLoadSystemHive(_Inout_ PLOADER_PARAMETER_BLOCK LoaderBlock, _In_ PCSTR DirectoryPath, _In_ PCSTR HiveName, _Out_ PBAD_HIVE_REASON Reason)
Definition: wlregistry.c:45
enum _BAD_HIVE_REASON BAD_HIVE_REASON
@ CorruptHive
Definition: wlregistry.c:37
@ NoHive
Definition: wlregistry.c:38

Referenced by LoadAndBootWindows(), and LoadReactOSSetup().

◆ WinLdrLoadModule()

PVOID WinLdrLoadModule ( PCSTR  ModuleName,
PULONG  Size,
TYPE_OF_MEMORY  MemoryType 
)

Definition at line 441 of file winldr.c.

444{
445 ULONG FileId;
446 PVOID PhysicalBase;
451
452 *Size = 0;
453
454 /* Open the image file */
457 if (Status != ESUCCESS)
458 {
459 /* In case of errors, we just return, without complaining to the user */
460 WARN("Error while opening '%s', Status: %u\n", ModuleName, Status);
461 return NULL;
462 }
463
464 /* Retrieve its size */
466 if (Status != ESUCCESS)
467 {
468 ArcClose(FileId);
469 return NULL;
470 }
471 FileSize = FileInfo.EndingAddress.LowPart;
472 *Size = FileSize;
473
474 /* Allocate memory */
475 PhysicalBase = MmAllocateMemoryWithType(FileSize, MemoryType);
476 if (PhysicalBase == NULL)
477 {
478 ERR("Could not allocate memory for '%s'\n", ModuleName);
479 ArcClose(FileId);
480 return NULL;
481 }
482
483 /* Load the whole file */
484 Status = ArcRead(FileId, PhysicalBase, FileSize, &BytesRead);
485 ArcClose(FileId);
486 if (Status != ESUCCESS)
487 {
488 WARN("Error while reading '%s', Status: %u\n", ModuleName, Status);
489 return NULL;
490 }
491
492 TRACE("Loaded %s at 0x%x with size 0x%x\n", ModuleName, PhysicalBase, FileSize);
493
494 return PhysicalBase;
495}
ACPI_BUFFER *RetBuffer ACPI_BUFFER *RetBuffer char ACPI_WALK_RESOURCE_CALLBACK void *Context ACPI_BUFFER *RetBuffer UINT16 ACPI_RESOURCE **ResourcePtr ACPI_GENERIC_ADDRESS *Reg UINT32 *ReturnValue UINT8 UINT8 *Slp_TypB ACPI_PHYSICAL_ADDRESS PhysicalAddress64 UINT32 UINT32 *TimeElapsed UINT32 ACPI_STATUS const char UINT32 ACPI_STATUS const char UINT32 const char const char * ModuleName
Definition: acpixf.h:1280
ARC_STATUS ArcGetFileInformation(ULONG FileId, FILEINFORMATION *Information)
Definition: fs.c:462
ARC_STATUS ArcOpen(CHAR *Path, OPENMODE OpenMode, ULONG *FileId)
Definition: fs.c:219
ARC_STATUS ArcClose(_In_ ULONG FileId)
Definition: fs.c:409
ARC_STATUS ArcRead(ULONG FileId, VOID *Buffer, ULONG N, ULONG *Count)
Definition: fs.c:448
PVOID MmAllocateMemoryWithType(SIZE_T MemorySize, TYPE_OF_MEMORY MemoryType)
Definition: mm.c:31
_Must_inspect_result_ _Out_ PLARGE_INTEGER FileSize
Definition: fsrtlfuncs.h:108
Status
Definition: gdiplustypes.h:25
@ ESUCCESS
Definition: arc.h:32
ULONG ARC_STATUS
Definition: arc.h:4
@ OpenReadOnly
Definition: arc.h:65
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesRead
Definition: wdfiotarget.h:870
VOID NtLdrOutputLoadMsg(_In_ PCSTR FileName, _In_opt_ PCSTR Description)
Definition: winldr.c:54

Referenced by SetupLdrInitErrataInf(), WinLdrInitErrataInf(), and WinLdrInitializePhase1().

◆ WinLdrLoadNLSData()

BOOLEAN WinLdrLoadNLSData ( _Inout_ PLOADER_PARAMETER_BLOCK  LoaderBlock,
_In_ PCSTR  DirectoryPath,
_In_ PCUNICODE_STRING  AnsiFileName,
_In_ PCUNICODE_STRING  OemFileName,
_In_ PCUNICODE_STRING  LangFileName,
_In_ PCUNICODE_STRING  OemHalFileName 
)

Definition at line 406 of file wlregistry.c.

413{
416 ULONG AnsiFileId = -1, OemFileId = -1, LangFileId = -1;
417 ULONG AnsiFileSize, OemFileSize, LangFileSize;
418 ULONG TotalSize;
420 PVOID NlsDataBase, NlsVirtual;
421 BOOLEAN AnsiEqualsOem = FALSE;
423
424 /* There may be a case, where OEM and ANSI pages coincide */
425 if (RtlCompareUnicodeString(AnsiFileName, OemFileName, TRUE) == 0)
426 AnsiEqualsOem = TRUE;
427
428 /* Open file with ANSI and store its size */
429 RtlStringCbPrintfA(FileName, sizeof(FileName), "%s%wZ",
430 DirectoryPath, AnsiFileName);
431 Status = ArcOpen(FileName, OpenReadOnly, &AnsiFileId);
432 if (Status != ESUCCESS)
433 {
434 WARN("Error while opening '%s', Status: %u\n", FileName, Status);
435 goto Quit;
436 }
437
438 Status = ArcGetFileInformation(AnsiFileId, &FileInfo);
439 if (Status != ESUCCESS)
440 goto Quit;
441 AnsiFileSize = FileInfo.EndingAddress.LowPart;
442 TRACE("AnsiFileSize: %d\n", AnsiFileSize);
443
444 /* Open OEM file and store its length */
445 if (AnsiEqualsOem)
446 {
447 OemFileSize = 0;
448 }
449 else
450 {
451 RtlStringCbPrintfA(FileName, sizeof(FileName), "%s%wZ",
452 DirectoryPath, OemFileName);
453 Status = ArcOpen(FileName, OpenReadOnly, &OemFileId);
454 if (Status != ESUCCESS)
455 {
456 WARN("Error while opening '%s', Status: %u\n", FileName, Status);
457 goto Quit;
458 }
459
461 if (Status != ESUCCESS)
462 goto Quit;
463 OemFileSize = FileInfo.EndingAddress.LowPart;
464 }
465 TRACE("OemFileSize: %d\n", OemFileSize);
466
467 /* Finally open the language codepage file and store its length */
468 RtlStringCbPrintfA(FileName, sizeof(FileName), "%s%wZ",
469 DirectoryPath, LangFileName);
470 Status = ArcOpen(FileName, OpenReadOnly, &LangFileId);
471 if (Status != ESUCCESS)
472 {
473 WARN("Error while opening '%s', Status: %u\n", FileName, Status);
474 goto Quit;
475 }
476
477 Status = ArcGetFileInformation(LangFileId, &FileInfo);
478 if (Status != ESUCCESS)
479 goto Quit;
480 LangFileSize = FileInfo.EndingAddress.LowPart;
481 TRACE("LangFileSize: %d\n", LangFileSize);
482
483 //
484 // TODO: The OEMHAL file.
485 //
486
487 /* Sum up all three length, having in mind that every one of them
488 must start at a page boundary => thus round up each file to a page */
489 TotalSize = MM_SIZE_TO_PAGES(AnsiFileSize) +
490 MM_SIZE_TO_PAGES(OemFileSize) +
491 MM_SIZE_TO_PAGES(LangFileSize);
492
493 /* Store it for later marking the pages as NlsData type */
494 TotalNLSSize = TotalSize;
495
496 NlsDataBase = MmAllocateMemoryWithType(TotalSize*MM_PAGE_SIZE, LoaderNlsData);
497 if (NlsDataBase == NULL)
498 goto Quit;
499
500 NlsVirtual = PaToVa(NlsDataBase);
501 LoaderBlock->NlsData->AnsiCodePageData = NlsVirtual;
502
503 LoaderBlock->NlsData->OemCodePageData =
504 (PVOID)((ULONG_PTR)NlsVirtual +
505 (MM_SIZE_TO_PAGES(AnsiFileSize) << MM_PAGE_SHIFT));
506
507 LoaderBlock->NlsData->UnicodeCodePageData =
508 (PVOID)((ULONG_PTR)NlsVirtual +
509 (MM_SIZE_TO_PAGES(AnsiFileSize) << MM_PAGE_SHIFT) +
510 (MM_SIZE_TO_PAGES(OemFileSize) << MM_PAGE_SHIFT));
511
512 /* ANSI and OEM data are the same - just set pointers to the same area */
513 if (AnsiEqualsOem)
514 LoaderBlock->NlsData->OemCodePageData = LoaderBlock->NlsData->AnsiCodePageData;
515
516 /* Now actually read the data into memory, starting with the ANSI file */
517 RtlStringCbPrintfA(FileName, sizeof(FileName), "%s%wZ",
518 DirectoryPath, AnsiFileName);
520 Status = ArcRead(AnsiFileId,
521 VaToPa(LoaderBlock->NlsData->AnsiCodePageData),
522 AnsiFileSize, &BytesRead);
523 if (Status != ESUCCESS)
524 {
525 WARN("Error while reading '%s', Status: %u\n", FileName, Status);
526 goto Quit;
527 }
528
529 /* OEM now, if it isn't the same as the ANSI one */
530 if (!AnsiEqualsOem)
531 {
532 RtlStringCbPrintfA(FileName, sizeof(FileName), "%s%wZ",
533 DirectoryPath, OemFileName);
535 Status = ArcRead(OemFileId,
536 VaToPa(LoaderBlock->NlsData->OemCodePageData),
537 OemFileSize, &BytesRead);
538 if (Status != ESUCCESS)
539 {
540 WARN("Error while reading '%s', Status: %u\n", FileName, Status);
541 goto Quit;
542 }
543 }
544
545 /* Finally the language file */
546 RtlStringCbPrintfA(FileName, sizeof(FileName), "%s%wZ",
547 DirectoryPath, LangFileName);
549 Status = ArcRead(LangFileId,
550 VaToPa(LoaderBlock->NlsData->UnicodeCodePageData),
551 LangFileSize, &BytesRead);
552 if (Status != ESUCCESS)
553 {
554 WARN("Error while reading '%s', Status: %u\n", FileName, Status);
555 goto Quit;
556 }
557
558 //
559 // THIS IS a HACK and should be replaced by actually loading the OEMHAL file!
560 //
561 LoaderBlock->OemFontFile = VaToPa(LoaderBlock->NlsData->UnicodeCodePageData);
562
563 /* Convert NlsTables address to VA */
564 LoaderBlock->NlsData = PaToVa(LoaderBlock->NlsData);
565
566Quit:
567 if (LangFileId != -1)
568 ArcClose(LangFileId);
569 if (OemFileId != -1)
570 ArcClose(OemFileId);
571 if (AnsiFileId != -1)
572 ArcClose(AnsiFileId);
573
574 if (Status != ESUCCESS)
575 UiMessageBox("Error reading NLS file %s", FileName);
576
577 return (Status == ESUCCESS);
578}
ULONG RtlCompareUnicodeString(PUNICODE_STRING s1, PUNICODE_STRING s2, BOOLEAN UpCase)
Definition: string_lib.cpp:31
@ LoaderNlsData
Definition: arc.h:195
ULONG TotalNLSSize
Definition: wlregistry.c:20

Referenced by SetupLdrLoadNlsData(), and WinLdrScanSystemHive().

◆ WinLdrpDumpArcDisks()

VOID WinLdrpDumpArcDisks ( PLOADER_PARAMETER_BLOCK  LoaderBlock)

Definition at line 1327 of file winldr.c.

1328{
1329 PLIST_ENTRY NextBd;
1330 PARC_DISK_SIGNATURE ArcDisk;
1331
1332 NextBd = LoaderBlock->ArcDiskInformation->DiskSignatureListHead.Flink;
1333
1334 while (NextBd != &LoaderBlock->ArcDiskInformation->DiskSignatureListHead)
1335 {
1336 ArcDisk = CONTAINING_RECORD(NextBd, ARC_DISK_SIGNATURE, ListEntry);
1337
1338 TRACE("ArcDisk %s checksum: 0x%X, signature: 0x%X\n",
1339 ArcDisk->ArcName, ArcDisk->CheckSum, ArcDisk->Signature);
1340
1341 NextBd = ArcDisk->ListEntry.Flink;
1342 }
1343}
ULONG CheckSum
Definition: arc.h:258
ULONG Signature
Definition: arc.h:256
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

Referenced by LoadAndBootWindowsCommon().

◆ WinLdrpDumpBootDriver()

VOID WinLdrpDumpBootDriver ( PLOADER_PARAMETER_BLOCK  LoaderBlock)

Definition at line 1308 of file winldr.c.

1309{
1310 PLIST_ENTRY NextBd;
1311 PBOOT_DRIVER_LIST_ENTRY BootDriver;
1312
1313 NextBd = LoaderBlock->BootDriverListHead.Flink;
1314
1315 while (NextBd != &LoaderBlock->BootDriverListHead)
1316 {
1317 BootDriver = CONTAINING_RECORD(NextBd, BOOT_DRIVER_LIST_ENTRY, Link);
1318
1319 TRACE("BootDriver %wZ DTE %08X RegPath: %wZ\n", &BootDriver->FilePath,
1320 BootDriver->LdrEntry, &BootDriver->RegistryPath);
1321
1322 NextBd = BootDriver->Link.Flink;
1323 }
1324}
LIST_ENTRY Link
Definition: arc.h:247
UNICODE_STRING RegistryPath
Definition: arc.h:249
UNICODE_STRING FilePath
Definition: arc.h:248
struct _LDR_DATA_TABLE_ENTRY * LdrEntry
Definition: arc.h:250
static int Link(const char **args)
Definition: vfdcmd.c:2414

Referenced by LoadAndBootWindowsCommon().

◆ WinLdrpDumpMemoryDescriptors()

VOID WinLdrpDumpMemoryDescriptors ( PLOADER_PARAMETER_BLOCK  LoaderBlock)

Definition at line 1289 of file winldr.c.

1290{
1291 PLIST_ENTRY NextMd;
1293
1294 NextMd = LoaderBlock->MemoryDescriptorListHead.Flink;
1295
1296 while (NextMd != &LoaderBlock->MemoryDescriptorListHead)
1297 {
1299
1300 TRACE("BP %08X PC %04X MT %d\n", MemoryDescriptor->BasePage,
1301 MemoryDescriptor->PageCount, MemoryDescriptor->MemoryType);
1302
1303 NextMd = MemoryDescriptor->ListEntry.Flink;
1304 }
1305}
LIST_ENTRY MemoryDescriptorListHead
Definition: arc.h:541
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_opt_ WDFREQUEST _In_opt_ PWDF_REQUEST_SEND_OPTIONS _In_ PWDF_USB_CONTROL_SETUP_PACKET _In_opt_ PWDF_MEMORY_DESCRIPTOR MemoryDescriptor
Definition: wdfusb.h:1339

Referenced by LoadAndBootWindowsCommon(), and WinLdrSetupMemoryLayout().

◆ WinLdrScanSystemHive()

BOOLEAN WinLdrScanSystemHive ( IN OUT PLOADER_PARAMETER_BLOCK  LoaderBlock,
IN PCSTR  SystemRoot 
)

Definition at line 231 of file wlregistry.c.

233{
237 DECLARE_UNICODE_STRING_SIZE(LangFileName, MAX_PATH); // CaseTable
238 DECLARE_UNICODE_STRING_SIZE(OemHalFileName, MAX_PATH);
239 CHAR SearchPath[1024];
240
241 /* Scan registry and prepare boot drivers list */
242 Success = WinLdrScanRegistry(&LoaderBlock->BootDriverListHead);
243 if (!Success)
244 {
245 UiMessageBox("Failed to load boot drivers!");
246 return FALSE;
247 }
248
249 /* Get names of NLS files */
251 &AnsiFileName,
252 &OemFileName,
253 &LangFileName,
254 &OemHalFileName);
255 if (!Success)
256 {
257 UiMessageBox("Getting NLS names from registry failed!");
258 return FALSE;
259 }
260
261 TRACE("NLS data: '%wZ' '%wZ' '%wZ' '%wZ'\n",
262 &AnsiFileName, &OemFileName, &LangFileName, &OemHalFileName);
263
264 /* Load NLS data */
266 RtlStringCbCatA(SearchPath, sizeof(SearchPath), "system32\\");
267 Success = WinLdrLoadNLSData(LoaderBlock,
269 &AnsiFileName,
270 &OemFileName,
271 &LangFileName,
272 &OemHalFileName);
273 TRACE("NLS data loading %s\n", Success ? "successful" : "failed");
274
275 return TRUE;
276}
HKEY CurrentControlSetKey
Definition: registry.c:34
#define DECLARE_UNICODE_STRING_SIZE(_var, _size)
Definition: wdfcore.h:155
BOOLEAN WinLdrLoadNLSData(_Inout_ PLOADER_PARAMETER_BLOCK LoaderBlock, _In_ PCSTR DirectoryPath, _In_ PCUNICODE_STRING AnsiFileName, _In_ PCUNICODE_STRING OemFileName, _In_ PCUNICODE_STRING LangFileName, _In_ PCUNICODE_STRING OemHalFileName)
Definition: wlregistry.c:406
static BOOLEAN WinLdrGetNLSNames(_In_ HKEY ControlSet, _Inout_ PUNICODE_STRING AnsiFileName, _Inout_ PUNICODE_STRING OemFileName, _Inout_ PUNICODE_STRING LangFileName, _Inout_ PUNICODE_STRING OemHalFileName)
Definition: wlregistry.c:283
static BOOLEAN WinLdrScanRegistry(IN OUT PLIST_ENTRY BootDriverListHead)
Definition: wlregistry.c:581

Referenced by LoadAndBootWindows().

◆ WinLdrSetProcessorContext()

VOID WinLdrSetProcessorContext ( _In_ USHORT  OperatingSystemVersion)

Definition at line 342 of file winldr.c.

344{
345 TRACE("WinLdrSetProcessorContext\n");
346
347 /* Disable Interrupts */
348 _disable();
349
350 /* Re-initialize EFLAGS */
351 __writeeflags(0);
352
353 /* Set the new PML4 */
355
356 /* Get kernel mode address of gdt / idt */
358
359 /* Create gdt entries and load gdtr */
360 Amd64SetupGdt(GdtIdt, KSEG0_BASE | (TssBasePage << MM_PAGE_SHIFT));
361
362 /* Copy old Idt and set idtr */
364
365 /* LDT is unused */
366// __lldt(0);
367
368 /* Load TSR */
369 __ltr(KGDT64_SYS_TSS);
370
371 TRACE("leave WinLdrSetProcessorContext\n");
372}
PVOID GdtIdt
Definition: winldr.c:26
ULONG_PTR TssBasePage
Definition: winldr.c:28
PHARDWARE_PTE PxeBase
Definition: winldr.c:23
static VOID Amd64SetupGdt(PVOID GdtBase, ULONG64 TssBase)
Definition: winldr.c:270
static VOID Amd64SetupIdt(PVOID IdtBase)
Definition: winldr.c:319
void __cdecl _disable(void)
Definition: intrin_arm.h:365
__INTRIN_INLINE void __writeeflags(uintptr_t Value)
Definition: intrin_x86.h:1669
__INTRIN_INLINE void __writecr3(unsigned int Data)
Definition: intrin_x86.h:1794
unsigned __int64 ULONG64
Definition: imports.h:198
#define KGDT64_SYS_TSS
Definition: ketypes.h:127
#define NUM_GDT
Definition: winldr.h:16

Referenced by LoadAndBootWindowsCommon().

◆ WinLdrSetupMachineDependent()

VOID WinLdrSetupMachineDependent ( PLOADER_PARAMETER_BLOCK  LoaderBlock)

Definition at line 374 of file winldr.c.

375{
376 PVOID SharedUserDataAddress = NULL;
377 ULONG_PTR Tss = 0;
378 ULONG BlockSize, NumPages;
379
380 LoaderBlock->u.I386.CommonDataArea = (PVOID)DbgPrint; // HACK
381 LoaderBlock->u.I386.MachineType = MACHINE_TYPE_ISA;
382
383 /* Allocate 1 page for SharedUserData */
384 SharedUserDataAddress = MmAllocateMemoryWithType(MM_PAGE_SIZE, LoaderStartupPcrPage);
385 SharedUserDataPfn = (ULONG_PTR)SharedUserDataAddress >> MM_PAGE_SHIFT;
386 if (SharedUserDataAddress == NULL)
387 {
388 UiMessageBox("Can't allocate SharedUserData page.");
389 return;
390 }
391 RtlZeroMemory(SharedUserDataAddress, MM_PAGE_SIZE);
392
393 /* Allocate TSS */
394 BlockSize = (sizeof(KTSS) + MM_PAGE_SIZE) & ~(MM_PAGE_SIZE - 1);
396 TssBasePage = Tss >> MM_PAGE_SHIFT;
397
398 /* Allocate space for new GDT + IDT */
399 BlockSize = NUM_GDT * sizeof(KGDTENTRY) + NUM_IDT * sizeof(KIDTENTRY);
400 NumPages = (BlockSize + MM_PAGE_SIZE - 1) >> MM_PAGE_SHIFT;
401 GdtIdt = (PKGDTENTRY)MmAllocateMemoryWithType(NumPages * MM_PAGE_SIZE, LoaderMemoryData);
402 if (GdtIdt == NULL)
403 {
404 UiMessageBox("Can't allocate pages for GDT+IDT!");
405 return;
406 }
407
408 /* Zero newly prepared GDT+IDT */
409 RtlZeroMemory(GdtIdt, NumPages << MM_PAGE_SHIFT);
410
411 // Before we start mapping pages, create a block of memory, which will contain
412 // PDE and PTEs
414 {
415 // FIXME: bugcheck
416 }
417
418 /* Map KI_USER_SHARED_DATA, Apic and HAL space */
420}
static BOOLEAN MempAllocatePageTables(VOID)
Definition: winldr.c:34
PFN_NUMBER SharedUserDataPfn
Definition: winldr.c:27
static BOOLEAN WinLdrMapSpecialPages(void)
Definition: winldr.c:320
#define DbgPrint
Definition: hal.h:12
#define KTSS
Definition: ketypes.h:995
#define PKGDTENTRY
Definition: ketypes.h:512
#define KGDTENTRY
Definition: ketypes.h:511
#define MACHINE_TYPE_ISA
Definition: ketypes.h:102
#define NUM_IDT
Definition: winldr.h:17
@ LoaderMemoryData
Definition: arc.h:194
@ LoaderStartupPcrPage
Definition: arc.h:191
ULONG MachineType
Definition: arc.h:454
PVOID CommonDataArea
Definition: arc.h:453
union _LOADER_PARAMETER_BLOCK::@3373 u
I386_LOADER_BLOCK I386
Definition: arc.h:562

Referenced by LoadAndBootWindowsCommon().

◆ WinLdrSetupMemoryLayout()

BOOLEAN WinLdrSetupMemoryLayout ( IN OUT PLOADER_PARAMETER_BLOCK  LoaderBlock)

Definition at line 181 of file wlmemory.c.

182{
183 PFN_NUMBER i, PagesCount, MemoryMapSizeInPages, NoEntries;
184 PFN_NUMBER LastPageIndex, MemoryMapStartPage;
186 ULONG LastPageType;
187 //PKTSS Tss;
189
190 /* Cleanup heap */
192
193 //
194 // Creating a suitable memory map for Windows can be tricky, so let's
195 // give a few advices:
196 // 1) One must not map the whole available memory pages to PDE!
197 // Map only what's needed - 16Mb, 24Mb, 32Mb max I think,
198 // thus occupying 4, 6 or 8 PDE entries for identical mapping,
199 // the same quantity for KSEG0_BASE mapping, one more entry for
200 // hyperspace and one more entry for HAL physical pages mapping.
201 // 2) Memory descriptors must map *the whole* physical memory
202 // showing any memory above 16/24/32 as FirmwareTemporary
203 //
204 // 3) Overall memory blocks count must not exceed 30 (?? why?)
205 //
206
207 //
208 // During MmInitMachineDependent, the kernel zeroes PDE at the following address
209 // 0xC0300000 - 0xC03007FC
210 //
211 // Then it finds the best place for non-paged pool:
212 // StartPde C0300F70, EndPde C0300FF8, NumberOfPages C13, NextPhysPage 3AD
213 //
214
215 // Allocate memory for memory allocation descriptors
218
219 // Setup an entry for each descriptor
220 MemoryMap = MmGetMemoryMap(&NoEntries);
221 if (MemoryMap == NULL)
222 {
223 UiMessageBox("Can not retrieve the current memory map.");
224 return FALSE;
225 }
226
227 // Calculate parameters of the memory map
228 MemoryMapStartPage = (ULONG_PTR)MemoryMap >> MM_PAGE_SHIFT;
229 MemoryMapSizeInPages = (NoEntries * sizeof(PAGE_LOOKUP_TABLE_ITEM) + MM_PAGE_SIZE - 1) / MM_PAGE_SIZE;
230
231 TRACE("Got memory map with %d entries\n", NoEntries);
232
233 // Always map first page of memory
235 if (!Status)
236 {
237 ERR("Error during MempSetupPaging of first page\n");
238 return FALSE;
239 }
240
241 /* Before creating the map, we need to map pages to kernel mode */
242 LastPageIndex = 1;
243 LastPageType = MemoryMap[1].PageAllocated;
244 for (i = 2; i < NoEntries; i++)
245 {
246 if ((MemoryMap[i].PageAllocated != LastPageType) ||
247 (i == NoEntries - 1))
248 {
249 MempSetupPagingForRegion(LastPageIndex, i - LastPageIndex, LastPageType);
250 LastPageIndex = i;
251 LastPageType = MemoryMap[i].PageAllocated;
252 }
253 }
254
255 // Construct a good memory map from what we've got,
256 // but mark entries which the memory allocation bitmap takes
257 // as free entries (this is done in order to have the ability
258 // to place mem alloc bitmap outside lower 16Mb zone)
259 PagesCount = 1;
260 LastPageIndex = 0;
261 LastPageType = MemoryMap[0].PageAllocated;
262 for (i = 1; i < NoEntries; i++)
263 {
264 // Check if its memory map itself
265 if (i >= MemoryMapStartPage &&
266 i < (MemoryMapStartPage+MemoryMapSizeInPages))
267 {
268 // Exclude it if current page belongs to the memory map
269 MemoryMap[i].PageAllocated = LoaderFree;
270 }
271
272 // Process entry
273 if (MemoryMap[i].PageAllocated == LastPageType &&
274 (i != NoEntries-1) )
275 {
276 PagesCount++;
277 }
278 else
279 {
280 // Add the resulting region
281 MempAddMemoryBlock(LoaderBlock, LastPageIndex, PagesCount, LastPageType);
282
283 // Reset our counter vars
284 LastPageIndex = i;
285 LastPageType = MemoryMap[i].PageAllocated;
286 PagesCount = 1;
287 }
288 }
289
290 // TEMP, DEBUG!
291 // adding special reserved memory zones for vmware workstation
292#if 0
293 {
294 Mad[MadCount].BasePage = 0xfec00;
295 Mad[MadCount].PageCount = 0x10;
297 WinLdrInsertDescriptor(LoaderBlock, &Mad[MadCount]);
298 MadCount++;
299
300 Mad[MadCount].BasePage = 0xfee00;
301 Mad[MadCount].PageCount = 0x1;
303 WinLdrInsertDescriptor(LoaderBlock, &Mad[MadCount]);
304 MadCount++;
305
306 Mad[MadCount].BasePage = 0xfffe0;
307 Mad[MadCount].PageCount = 0x20;
309 WinLdrInsertDescriptor(LoaderBlock, &Mad[MadCount]);
310 MadCount++;
311 }
312#endif
313
314 /* Now we need to add high descriptors from the bios memory map */
315 for (i = 0; i < BiosMemoryMapEntryCount; i++)
316 {
317 /* Check if its higher than the lookup table */
319 {
320 /* Copy this descriptor */
321 MempAddMemoryBlock(LoaderBlock,
325 }
326 }
327
328 TRACE("MadCount: %d\n", MadCount);
329
330 WinLdrpDumpMemoryDescriptors(LoaderBlock); //FIXME: Delete!
331
332 // Map our loader image, so we can continue running
333 /*Status = MempSetupPaging(OsLoaderBase >> MM_PAGE_SHIFT, OsLoaderSize >> MM_PAGE_SHIFT);
334 if (!Status)
335 {
336 UiMessageBox("Error during MempSetupPaging.");
337 return;
338 }*/
339
340 // Fill the memory descriptor list and
341 //PrepareMemoryDescriptorList();
342 TRACE("Memory Descriptor List prepared, printing PDE\n");
343 List_PaToVa(&LoaderBlock->MemoryDescriptorListHead);
344
345#if DBG
346 MempDump();
347#endif
348
349 return TRUE;
350}
BOOLEAN MempSetupPaging(IN PFN_NUMBER StartPage, IN PFN_NUMBER NumberOfPages, IN BOOLEAN KernelMapping)
Definition: winldr.c:171
VOID MempDump(VOID)
Definition: winldr.c:424
BIOS_MEMORY_MAP MemoryMap[32]
Definition: loader.c:11
PPAGE_LOOKUP_TABLE_ITEM MmGetMemoryMap(PFN_NUMBER *NoEntries)
Definition: mm.c:297
VOID FrLdrHeapCleanupAll(VOID)
Definition: heap.c:249
@ LoaderFree
Definition: arc.h:176
@ LoaderSpecialMemory
Definition: arc.h:196
ULONG PFN_NUMBER
Definition: ke.h:9
TYPE_OF_MEMORY MemoryType
Definition: mm.h:43
PFN_NUMBER PageCount
Definition: mm.h:45
PFN_NUMBER BasePage
Definition: mm.h:44
TYPE_OF_MEMORY MemoryType
Definition: arc.h:240
#define MAX_MAD_COUNT
Definition: wlmemory.c:60
MEMORY_ALLOCATION_DESCRIPTOR * Mad
Definition: wlmemory.c:57
PFREELDR_MEMORY_DESCRIPTOR BiosMemoryMap
Definition: meminit.c:33
PFN_NUMBER MmHighestPhysicalPage
Definition: meminit.c:31
static VOID WinLdrInsertDescriptor(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, IN PMEMORY_ALLOCATION_DESCRIPTOR NewDescriptor)
Definition: wlmemory.c:355
VOID MempSetupPagingForRegion(PFN_NUMBER BasePage, PFN_NUMBER PageCount, ULONG Type)
Definition: wlmemory.c:106
VOID MempAddMemoryBlock(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, PFN_NUMBER BasePage, PFN_NUMBER PageCount, ULONG Type)
Definition: wlmemory.c:65
ULONG BiosMemoryMapEntryCount
Definition: meminit.c:34
ULONG MadCount
Definition: wlmemory.c:58

Referenced by LoadAndBootWindowsCommon().

Variable Documentation

◆ BootFileSystem

PCWSTR BootFileSystem
extern

◆ SosEnabled

◆ WinLdrSystemBlock

PLOADER_SYSTEM_BLOCK WinLdrSystemBlock
extern