ReactOS  0.4.14-dev-297-g23e575c
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)
 
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)
 
VOID WinLdrInitializePhase1 (PLOADER_PARAMETER_BLOCK LoaderBlock, PCSTR Options, PCSTR SystemPath, PCSTR BootPath, USHORT VersionToBoot)
 
BOOLEAN WinLdrLoadNLSData (IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, IN PCSTR DirectoryPath, IN PCSTR AnsiFileName, IN PCSTR OemFileName, IN PCSTR LanguageFileName)
 
BOOLEAN WinLdrAddDriverToList (LIST_ENTRY *BootDriverListHead, PWSTR RegistryPath, PWSTR ImagePath, PWSTR ServiceName)
 
VOID WinLdrpDumpMemoryDescriptors (PLOADER_PARAMETER_BLOCK LoaderBlock)
 
VOID WinLdrpDumpBootDriver (PLOADER_PARAMETER_BLOCK LoaderBlock)
 
VOID WinLdrpDumpArcDisks (PLOADER_PARAMETER_BLOCK LoaderBlock)
 
ARC_STATUS LoadAndBootWindowsCommon (USHORT OperatingSystemVersion, PLOADER_PARAMETER_BLOCK LoaderBlock, PCSTR BootOptions, PCSTR BootPath, BOOLEAN Setup)
 
VOID WinLdrSetupMachineDependent (PLOADER_PARAMETER_BLOCK LoaderBlock)
 
VOID WinLdrSetProcessorContext (VOID)
 
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
 

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 }
struct _CONFIGURATION_COMPONENT_DATA * Parent
Definition: arc.h:118
struct _CONFIGURATION_COMPONENT_DATA * Child
Definition: arc.h:119
CONFIGURATION_TYPE Type
Definition: arc.h:105
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
CONFIGURATION_CLASS Class
Definition: arc.h:104
Definition: partlist.h:33
CONFIGURATION_COMPONENT ComponentEntry
Definition: arc.h:121
struct _CONFIGURATION_COMPONENT_DATA * Sibling
Definition: arc.h:120
VOID ConvertConfigToVA(PCONFIGURATION_COMPONENT_DATA Start)
Definition: conversion.c:51
FORCEINLINE PVOID PaToVa(PVOID Pa)
Definition: conversion.h:22
ACPI_PHYSICAL_ADDRESS ACPI_SIZE BOOLEAN Warn BOOLEAN Physical 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 Child
Definition: acpixf.h:722
FORCEINLINE PVOID VaToPa(PVOID Va)
Definition: conversion.h:15

Referenced by ConvertConfigToVA(), and WinLdrInitializePhase1().

◆ LoadAndBootWindowsCommon()

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

Definition at line 908 of file winldr.c.

914 {
915  PLOADER_PARAMETER_BLOCK LoaderBlockVA;
917  PLDR_DATA_TABLE_ENTRY KernelDTE;
920 
921  TRACE("LoadAndBootWindowsCommon()\n");
922 
923  ASSERT(OperatingSystemVersion != 0);
924 
925 #ifdef _M_IX86
926  /* Setup redirection support */
928 #endif
929 
930  /* Convert BootPath to SystemRoot */
931  SystemRoot = strstr(BootPath, "\\");
932 
933  /* Detect hardware */
934  UiDrawBackdrop();
935  UiDrawProgressBarCenter(20, 100, "Detecting hardware...");
936  LoaderBlock->ConfigurationRoot = MachHwDetect();
937 
938  /* Load the operating system core: the Kernel, the HAL and the Kernel Debugger Transport DLL */
939  Success = LoadWindowsCore(OperatingSystemVersion,
940  LoaderBlock,
941  BootOptions,
942  BootPath,
943  &KernelDTE);
944  if (!Success)
945  {
946  UiMessageBox("Error loading NTOS core.");
947  return ENOEXEC;
948  }
949 
950  /* Load boot drivers */
951  UiDrawBackdrop();
952  UiDrawProgressBarCenter(100, 100, "Loading boot drivers...");
953  Success = WinLdrLoadBootDrivers(LoaderBlock, BootPath);
954  TRACE("Boot drivers loading %s\n", Success ? "successful" : "failed");
955 
956  /* Cleanup ini file */
957  IniCleanup();
958 
959  /* Initialize Phase 1 - no drivers loading anymore */
960  WinLdrInitializePhase1(LoaderBlock,
961  BootOptions,
962  SystemRoot,
963  BootPath,
964  OperatingSystemVersion);
965 
966  /* Save entry-point pointer and Loader block VAs */
968  LoaderBlockVA = PaToVa(LoaderBlock);
969 
970  /* "Stop all motors", change videomode */
972 
973  /* Debugging... */
974  //DumpMemoryAllocMap();
975 
976  /* Do the machine specific initialization */
977  WinLdrSetupMachineDependent(LoaderBlock);
978 
979  /* Map pages and create memory descriptors */
980  WinLdrSetupMemoryLayout(LoaderBlock);
981 
982  /* Set processor context */
984 
985  /* Save final value of LoaderPagesSpanned */
987 
988  TRACE("Hello from paged mode, KiSystemStartup %p, LoaderBlockVA %p!\n",
989  KiSystemStartup, LoaderBlockVA);
990 
991  /* Zero KI_USER_SHARED_DATA page */
992  RtlZeroMemory((PVOID)KI_USER_SHARED_DATA, MM_PAGE_SIZE);
993 
994  WinLdrpDumpMemoryDescriptors(LoaderBlockVA);
995  WinLdrpDumpBootDriver(LoaderBlockVA);
996 #ifndef _M_AMD64
997  WinLdrpDumpArcDisks(LoaderBlockVA);
998 #endif
999 
1000  /* Pass control */
1001  (*KiSystemStartup)(LoaderBlockVA);
1002  return ESUCCESS;
1003 }
signed char * PCHAR
Definition: retypes.h:7
#define MachHwDetect()
Definition: machine.h:136
VOID(NTAPI * KERNEL_ENTRY_POINT)(PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: winldr.h:13
BOOLEAN WinLdrLoadBootDrivers(PLOADER_PARAMETER_BLOCK LoaderBlock, PCSTR BootPath)
Definition: winldr.c:303
VOID WinLdrpDumpArcDisks(PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: winldr.c:1044
Definition: arc.h:32
VOID WinLdrSetProcessorContext(void)
Definition: winldr.c:348
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
PLOADER_PARAMETER_EXTENSION Extension
Definition: arc.h:512
PCONFIGURATION_COMPONENT_DATA ConfigurationRoot
Definition: arc.h:502
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:484
void WinLdrSetupEms(IN PCHAR BootOptions)
Definition: headless.c:243
BOOLEAN WinLdrSetupMemoryLayout(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: wlmemory.c:181
PVOID EntryPoint
Definition: ntddk_ex.h:203
INIT_FUNCTION VOID NTAPI KiSystemStartup(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: kiinit.c:371
VOID UiMessageBox(PCSTR Format,...)
Definition: ui.c:320
unsigned char BOOLEAN
void WinLdrSetupMachineDependent(PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: winldr.c:379
VOID WinLdrpDumpBootDriver(PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: winldr.c:1025
ULONG_PTR LoaderPagesSpanned
Definition: arc.h:356
#define TRACE(s)
Definition: solgame.cpp:4
static const WCHAR SystemRoot[]
Definition: reg.c:38
ULONG LoaderPagesSpanned
Definition: mm.c:29
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
VOID IniCleanup(VOID)
Definition: inifile.c:235
#define KI_USER_SHARED_DATA
#define MachPrepareForReactOS()
Definition: machine.h:120
Definition: btrfs_drv.h:1780
VOID UiDrawBackdrop(VOID)
Definition: ui.c:214
VOID WinLdrpDumpMemoryDescriptors(PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: winldr.c:1006
VOID WinLdrInitializePhase1(PLOADER_PARAMETER_BLOCK LoaderBlock, PCSTR Options, PCSTR SystemRoot, PCSTR BootPath, USHORT VersionToBoot)
Definition: winldr.c:72
FORCEINLINE PVOID PaToVa(PVOID Pa)
Definition: conversion.h:22
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
Definition: arc.h:47
const char * PCSTR
Definition: typedefs.h:51
VOID UiDrawProgressBarCenter(ULONG Position, ULONG Range, PCHAR ProgressText)
Definition: ui.c:346

Referenced by LoadAndBootWindows(), and LoadReactOSSetup().

◆ MempDump()

VOID MempDump ( VOID  )

Definition at line 429 of file winldr.c.

430 {
431 }

Referenced by WinLdrSetupMemoryLayout().

◆ MempSetupPaging()

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

Definition at line 170 of file winldr.c.

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

Referenced by MempSetupPagingForRegion(), and WinLdrSetupMemoryLayout().

◆ MempUnmapPage()

VOID MempUnmapPage ( PFN_NUMBER  Page)

Definition at line 204 of file winldr.c.

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

◆ WinLdrAddDriverToList()

BOOLEAN WinLdrAddDriverToList ( LIST_ENTRY BootDriverListHead,
PWSTR  RegistryPath,
PWSTR  ImagePath,
PWSTR  ServiceName 
)

Definition at line 768 of file wlregistry.c.

772 {
773  PBOOT_DRIVER_LIST_ENTRY BootDriverEntry;
776 
777  BootDriverEntry = FrLdrHeapAlloc(sizeof(BOOT_DRIVER_LIST_ENTRY), TAG_WLDR_BDE);
778 
779  if (!BootDriverEntry)
780  return FALSE;
781 
782  // DTE will be filled during actual load of the driver
783  BootDriverEntry->LdrEntry = NULL;
784 
785  // Check - if we have a valid ImagePath, if not - we need to build it
786  // like "System32\\Drivers\\blah.sys"
787  if (ImagePath && (ImagePath[0] != 0))
788  {
789  // Just copy ImagePath to the corresponding field in the structure
790  PathLength = (USHORT)wcslen(ImagePath) * sizeof(WCHAR) + sizeof(UNICODE_NULL);
791 
792  BootDriverEntry->FilePath.Length = 0;
793  BootDriverEntry->FilePath.MaximumLength = PathLength;
795 
796  if (!BootDriverEntry->FilePath.Buffer)
797  {
798  FrLdrHeapFree(BootDriverEntry, TAG_WLDR_BDE);
799  return FALSE;
800  }
801 
802  Status = RtlAppendUnicodeToString(&BootDriverEntry->FilePath, ImagePath);
803  if (!NT_SUCCESS(Status))
804  {
805  FrLdrHeapFree(BootDriverEntry->FilePath.Buffer, TAG_WLDR_NAME);
806  FrLdrHeapFree(BootDriverEntry, TAG_WLDR_BDE);
807  return FALSE;
808  }
809  }
810  else
811  {
812  // we have to construct ImagePath ourselves
813  PathLength = (USHORT)wcslen(ServiceName)*sizeof(WCHAR) + sizeof(L"system32\\drivers\\.sys");
814  BootDriverEntry->FilePath.Length = 0;
815  BootDriverEntry->FilePath.MaximumLength = PathLength;
817 
818  if (!BootDriverEntry->FilePath.Buffer)
819  {
820  FrLdrHeapFree(BootDriverEntry, TAG_WLDR_NAME);
821  return FALSE;
822  }
823 
824  Status = RtlAppendUnicodeToString(&BootDriverEntry->FilePath, L"system32\\drivers\\");
825  if (!NT_SUCCESS(Status))
826  {
827  FrLdrHeapFree(BootDriverEntry->FilePath.Buffer, TAG_WLDR_NAME);
828  FrLdrHeapFree(BootDriverEntry, TAG_WLDR_NAME);
829  return FALSE;
830  }
831 
832  Status = RtlAppendUnicodeToString(&BootDriverEntry->FilePath, ServiceName);
833  if (!NT_SUCCESS(Status))
834  {
835  FrLdrHeapFree(BootDriverEntry->FilePath.Buffer, TAG_WLDR_NAME);
836  FrLdrHeapFree(BootDriverEntry, TAG_WLDR_NAME);
837  return FALSE;
838  }
839 
840  Status = RtlAppendUnicodeToString(&BootDriverEntry->FilePath, L".sys");
841  if (!NT_SUCCESS(Status))
842  {
843  FrLdrHeapFree(BootDriverEntry->FilePath.Buffer, TAG_WLDR_NAME);
844  FrLdrHeapFree(BootDriverEntry, TAG_WLDR_NAME);
845  return FALSE;
846  }
847  }
848 
849  // Add registry path
851  BootDriverEntry->RegistryPath.Length = 0;
852  BootDriverEntry->RegistryPath.MaximumLength = PathLength;
854  if (!BootDriverEntry->RegistryPath.Buffer)
855  return FALSE;
856 
858  if (!NT_SUCCESS(Status))
859  return FALSE;
860 
862  if (!NT_SUCCESS(Status))
863  return FALSE;
864 
865  // Insert entry into the list
866  if (!InsertInBootDriverList(BootDriverListHead, BootDriverEntry))
867  {
868  // It was already there, so delete our entry
869  if (BootDriverEntry->FilePath.Buffer) FrLdrHeapFree(BootDriverEntry->FilePath.Buffer, TAG_WLDR_NAME);
870  if (BootDriverEntry->RegistryPath.Buffer) FrLdrHeapFree(BootDriverEntry->RegistryPath.Buffer, TAG_WLDR_NAME);
871  FrLdrHeapFree(BootDriverEntry, TAG_WLDR_BDE);
872  }
873 
874  return TRUE;
875 }
#define TRUE
Definition: types.h:120
FORCEINLINE VOID FrLdrHeapFree(PVOID MemoryPointer, ULONG Tag)
Definition: mm.h:170
USHORT MaximumLength
Definition: env_spec_w32.h:370
LONG NTSTATUS
Definition: precomp.h:26
static USHORT PathLength
UNICODE_STRING FilePath
Definition: arc.h:201
Definition: arc.h:198
#define UNICODE_NULL
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
#define TAG_WLDR_NAME
Definition: winldr.h:15
#define TAG_WLDR_BDE
Definition: winldr.h:14
FORCEINLINE PVOID FrLdrHeapAlloc(SIZE_T MemorySize, ULONG Tag)
Definition: mm.h:163
LPTSTR ServiceName
Definition: ServiceMain.c:15
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static const WCHAR L[]
Definition: oid.c:1250
Status
Definition: gdiplustypes.h:24
UNICODE_STRING RegistryPath
Definition: arc.h:202
unsigned short USHORT
Definition: pedump.c:61
struct _LDR_DATA_TABLE_ENTRY * LdrEntry
Definition: arc.h:203
_In_ PUNICODE_STRING RegistryPath
Definition: wmip.h:27
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
static BOOLEAN InsertInBootDriverList(PLIST_ENTRY BootDriverListHead, PBOOT_DRIVER_LIST_ENTRY BootDriverEntry)
Definition: wlregistry.c:729

Referenced by SetupLdrScanBootDrivers(), WinLdrLoadSystemHive(), and WinLdrScanRegistry().

◆ WinLdrInitializePhase1()

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

Definition at line 72 of file winldr.c.

77 {
78  /*
79  * Examples of correct options and paths:
80  * CHAR Options[] = "/DEBUGPORT=COM1 /BAUDRATE=115200";
81  * CHAR Options[] = "/NODEBUG";
82  * CHAR SystemRoot[] = "\\WINNT\\";
83  * CHAR ArcBoot[] = "multi(0)disk(0)rdisk(0)partition(1)";
84  */
85 
86  PSTR LoadOptions, NewLoadOptions;
87  CHAR HalPath[] = "\\";
88  CHAR ArcBoot[MAX_PATH+1];
89  CHAR MiscFiles[MAX_PATH+1];
90  ULONG i;
91  ULONG_PTR PathSeparator;
93 
94  /* Construct SystemRoot and ArcBoot from SystemPath */
95  PathSeparator = strstr(BootPath, "\\") - BootPath;
96  RtlStringCbCopyNA(ArcBoot, sizeof(ArcBoot), BootPath, PathSeparator);
97 
98  TRACE("ArcBoot: '%s'\n", ArcBoot);
99  TRACE("SystemRoot: '%s'\n", SystemRoot);
100  TRACE("Options: '%s'\n", Options);
101 
102  /* Fill ARC BootDevice */
105  LoaderBlock->ArcBootDeviceName = PaToVa(LoaderBlock->ArcBootDeviceName);
106 
107 //
108 // IMPROVE!!
109 // SetupBlock->ArcSetupDeviceName must be the path to the setup **SOURCE**,
110 // and not the setup boot path. Indeed they may differ!!
111 //
112  if (LoaderBlock->SetupLdrBlock)
113  {
114  PSETUP_LOADER_BLOCK SetupBlock = LoaderBlock->SetupLdrBlock;
115 
116  /* Adjust the ARC path in the setup block - Matches ArcBoot path */
118  SetupBlock->ArcSetupDeviceName = PaToVa(SetupBlock->ArcSetupDeviceName);
119 
120  /* Convert the setup block pointer */
121  LoaderBlock->SetupLdrBlock = PaToVa(LoaderBlock->SetupLdrBlock);
122  }
123 
124  /* Fill ARC HalDevice, it matches ArcBoot path */
126  LoaderBlock->ArcHalDeviceName = PaToVa(LoaderBlock->ArcHalDeviceName);
127 
128  /* Fill SystemRoot */
131  LoaderBlock->NtBootPathName = PaToVa(LoaderBlock->NtBootPathName);
132 
133  /* Fill NtHalPathName */
135  RtlStringCbCopyA(LoaderBlock->NtHalPathName, sizeof(WinLdrSystemBlock->NtHalPathName), HalPath);
136  LoaderBlock->NtHalPathName = PaToVa(LoaderBlock->NtHalPathName);
137 
138  /* Fill LoadOptions and strip the '/' switch symbol in front of each option */
139  NewLoadOptions = LoadOptions = LoaderBlock->LoadOptions = WinLdrSystemBlock->LoadOptions;
141 
142  do
143  {
144  while (*LoadOptions == '/')
145  ++LoadOptions;
146 
147  *NewLoadOptions++ = *LoadOptions;
148  } while (*LoadOptions++);
149 
150  LoaderBlock->LoadOptions = PaToVa(LoaderBlock->LoadOptions);
151 
152  /* ARC devices */
155 
156  /* Convert ARC disk information from freeldr to a correct format */
157  for (i = 0; i < reactos_disk_count; i++)
158  {
159  PARC_DISK_SIGNATURE_EX ArcDiskSig;
160 
161  /* Allocate the ARC structure */
162  ArcDiskSig = FrLdrHeapAlloc(sizeof(ARC_DISK_SIGNATURE_EX), 'giSD');
163 
164  /* Copy the data over */
166 
167  /* Set the ARC Name pointer */
168  ArcDiskSig->DiskSignature.ArcName = PaToVa(ArcDiskSig->ArcName);
169 
170  /* Insert into the list */
172  &ArcDiskSig->DiskSignature.ListEntry);
173  }
174 
175  /* Convert all lists to Virtual address */
176 
177  /* Convert the ArcDisks list to virtual address */
179  LoaderBlock->ArcDiskInformation = PaToVa(LoaderBlock->ArcDiskInformation);
180 
181  /* Convert configuration entries to VA */
182  ConvertConfigToVA(LoaderBlock->ConfigurationRoot);
183  LoaderBlock->ConfigurationRoot = PaToVa(LoaderBlock->ConfigurationRoot);
184 
185  /* Convert all DTE into virtual addresses */
186  List_PaToVa(&LoaderBlock->LoadOrderListHead);
187 
188  /* This one will be converted right before switching to virtual paging mode */
189  //List_PaToVa(&LoaderBlock->MemoryDescriptorListHead);
190 
191  /* Convert list of boot drivers */
192  List_PaToVa(&LoaderBlock->BootDriverListHead);
193 
194  Extension = LoaderBlock->Extension;
195 
196  /* FIXME! HACK value for docking profile */
197  Extension->Profile.Status = 2;
198 
199  /* Check if FreeLdr detected a ACPI table */
200  if (AcpiPresent)
201  {
202  /* Set the pointer to something for compatibility */
203  Extension->AcpiTable = (PVOID)1;
204  // FIXME: Extension->AcpiTableSize;
205  }
206 
207 #ifdef _M_IX86
208  /* Set headless block pointer */
210  {
211  Extension->HeadlessLoaderBlock = &WinLdrSystemBlock->HeadlessLoaderBlock;
212  RtlCopyMemory(Extension->HeadlessLoaderBlock,
214  sizeof(HEADLESS_LOADER_BLOCK));
215  Extension->HeadlessLoaderBlock = PaToVa(Extension->HeadlessLoaderBlock);
216  }
217 #endif
218  /* Load drivers database */
219  RtlStringCbCopyA(MiscFiles, sizeof(MiscFiles), BootPath);
220  RtlStringCbCatA(MiscFiles, sizeof(MiscFiles), "AppPatch\\drvmain.sdb");
221  Extension->DrvDBImage = PaToVa(WinLdrLoadModule(MiscFiles,
222  &Extension->DrvDBSize,
224 
225  /* Convert the extension block pointer */
226  LoaderBlock->Extension = PaToVa(LoaderBlock->Extension);
227 
228  TRACE("WinLdrInitializePhase1() completed\n");
229 }
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
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
PSTR ArcBootDeviceName
Definition: arc.h:503
ARC_DISK_INFORMATION ArcDiskInformation
Definition: winldr.h:60
ARC_DISK_SIGNATURE_EX reactos_arc_disk_info[]
Definition: archwsup.c:21
PCHAR ArcName
Definition: arc.h:210
VOID List_PaToVa(_In_ LIST_ENTRY *ListEntry)
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
PLOADER_PARAMETER_EXTENSION Extension
Definition: arc.h:512
PCONFIGURATION_COMPONENT_DATA ConfigurationRoot
Definition: arc.h:502
char CHAR
Definition: xmlstorage.h:175
BOOLEAN WinLdrTerminalConnected
Definition: headless.c:30
HEADLESS_LOADER_BLOCK LoaderRedirectionInformation
Definition: headless.c:29
#define InsertTailList(ListHead, Entry)
enum OPTION_FLAGS Options
Definition: stats.c:44
CHAR ArcBootDeviceName[MAX_PATH+1]
Definition: winldr.h:56
uint32_t ULONG_PTR
Definition: typedefs.h:63
NTSTRSAFEAPI RtlStringCbCopyA(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCSTR pszSrc)
Definition: ntstrsafe.h:156
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
struct _SETUP_LOADER_BLOCK * SetupLdrBlock
Definition: arc.h:511
void * PVOID
Definition: retypes.h:9
FORCEINLINE PVOID FrLdrHeapAlloc(SIZE_T MemorySize, ULONG Tag)
Definition: mm.h:163
#define TRACE(s)
Definition: solgame.cpp:4
LIST_ENTRY ListEntry
Definition: arc.h:208
static const WCHAR SystemRoot[]
Definition: reg.c:38
CHAR ArcName[MAX_PATH]
Definition: winldr.h:37
#define MAX_PATH
Definition: compat.h:26
PARC_DISK_INFORMATION ArcDiskInformation
Definition: arc.h:509
LIST_ENTRY BootDriverListHead
Definition: arc.h:495
ULONG reactos_disk_count
Definition: archwsup.c:20
ARC_DISK_SIGNATURE DiskSignature
Definition: winldr.h:36
BOOLEAN AcpiPresent
Definition: macharm.c:21
CHAR LoadOptions[MAX_OPTIONS_LENGTH+1]
Definition: winldr.h:55
CHAR NtHalPathName[MAX_PATH+1]
Definition: winldr.h:59
LIST_ENTRY LoadOrderListHead
Definition: arc.h:493
PVOID WinLdrLoadModule(PCSTR ModuleName, PULONG Size, TYPE_OF_MEMORY MemoryType)
Definition: winldr.c:355
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
signed char * PSTR
Definition: retypes.h:7
VOID ConvertConfigToVA(PCONFIGURATION_COMPONENT_DATA Start)
Definition: conversion.c:51
FORCEINLINE PVOID PaToVa(PVOID Pa)
Definition: conversion.h:22
LIST_ENTRY DiskSignatureListHead
Definition: arc.h:221
PCHAR ArcSetupDeviceName
Definition: setupblk.h:112
unsigned int ULONG
Definition: retypes.h:1
CHAR NtBootPathName[MAX_PATH+1]
Definition: winldr.h:58
_Inout_opt_ PUNICODE_STRING Extension
Definition: fltkernel.h:1092
PLOADER_SYSTEM_BLOCK WinLdrSystemBlock
Definition: winldr.c:27
NTSTRSAFEAPI RtlStringCbCatA(_Inout_updates_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCSTR pszSrc)
Definition: ntstrsafe.h:625

Referenced by LoadAndBootWindowsCommon().

◆ WinLdrInitSystemHive()

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

Definition at line 123 of file wlregistry.c.

127 {
128  CHAR SearchPath[1024];
129  PCSTR HiveName;
131 
132  if (Setup)
133  {
135  HiveName = "SETUPREG.HIV";
136  }
137  else
138  {
139  // There is a simple logic here: try to load usual hive (system), if it
140  // fails, then give system.alt a try, and finally try a system.sav
141 
142  // FIXME: For now we only try system
144  RtlStringCbCatA(SearchPath, sizeof(SearchPath), "system32\\config\\");
145  HiveName = "SYSTEM";
146  }
147 
148  TRACE("WinLdrInitSystemHive: loading hive %s%s\n", SearchPath, HiveName);
149  Success = WinLdrLoadSystemHive(LoaderBlock, SearchPath, HiveName);
150 
151  /* Fail if failed... */
152  if (!Success)
153  return FALSE;
154 
155  /* Import what was loaded */
156  Success = RegImportBinaryHive(VaToPa(LoaderBlock->RegistryBase), LoaderBlock->RegistryLength);
157  if (!Success)
158  {
159  UiMessageBox("Importing binary hive failed!");
160  return FALSE;
161  }
162 
163  /* Initialize the 'CurrentControlSet' link */
165  {
166  UiMessageBox("Initializing CurrentControlSet link failed!");
167  return FALSE;
168  }
169 
170  return TRUE;
171 }
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
ACPI_PHYSICAL_ADDRESS ACPI_SIZE BOOLEAN Warn BOOLEAN Physical 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:822
BOOLEAN RegImportBinaryHive(_In_ PVOID ChunkBase, _In_ ULONG ChunkSize)
Definition: registry.c:56
char CHAR
Definition: xmlstorage.h:175
LONG RegInitCurrentControlSet(_In_ BOOLEAN LastKnownGood)
Definition: registry.c:93
#define SearchPath
Definition: winbase.h:3724
NTSTRSAFEAPI RtlStringCbCopyA(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCSTR pszSrc)
Definition: ntstrsafe.h:156
VOID UiMessageBox(PCSTR Format,...)
Definition: ui.c:320
unsigned char BOOLEAN
#define TRACE(s)
Definition: solgame.cpp:4
static const WCHAR SystemRoot[]
Definition: reg.c:38
static BOOLEAN WinLdrLoadSystemHive(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, IN PCSTR DirectoryPath, IN PCSTR HiveName)
Definition: wlregistry.c:34
FORCEINLINE PVOID VaToPa(PVOID Va)
Definition: conversion.h:15
const char * PCSTR
Definition: typedefs.h:51
NTSTRSAFEAPI RtlStringCbCatA(_Inout_updates_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCSTR pszSrc)
Definition: ntstrsafe.h:625

Referenced by LoadAndBootWindows(), and LoadReactOSSetup().

◆ WinLdrLoadModule()

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

Definition at line 355 of file winldr.c.

358 {
359  ULONG FileId;
360  PVOID PhysicalBase;
362  ULONG FileSize;
365 
366  //CHAR ProgressString[256];
367 
368  /* Inform user we are loading files */
369  //UiDrawBackdrop();
370  //RtlStringCbPrintfA(ProgressString, sizeof(ProgressString), "Loading %s...", FileName);
371  //UiDrawProgressBarCenter(1, 100, ProgressString);
372 
373  TRACE("Loading module %s\n", ModuleName);
374  *Size = 0;
375 
376  /* Open the image file */
377  Status = ArcOpen((PSTR)ModuleName, OpenReadOnly, &FileId);
378  if (Status != ESUCCESS)
379  {
380  /* In case of errors, we just return, without complaining to the user */
381  WARN("Error while opening '%s', Status: %u\n", ModuleName, Status);
382  return NULL;
383  }
384 
385  /* Retrieve its size */
387  if (Status != ESUCCESS)
388  {
389  ArcClose(FileId);
390  return NULL;
391  }
392  FileSize = FileInfo.EndingAddress.LowPart;
393  *Size = FileSize;
394 
395  /* Allocate memory */
396  PhysicalBase = MmAllocateMemoryWithType(FileSize, MemoryType);
397  if (PhysicalBase == NULL)
398  {
399  ERR("Could not allocate memory for '%s'\n", ModuleName);
400  ArcClose(FileId);
401  return NULL;
402  }
403 
404  /* Load the whole file */
405  Status = ArcRead(FileId, PhysicalBase, FileSize, &BytesRead);
406  ArcClose(FileId);
407  if (Status != ESUCCESS)
408  {
409  WARN("Error while reading '%s', Status: %u\n", ModuleName, Status);
410  return NULL;
411  }
412 
413  TRACE("Loaded %s at 0x%x with size 0x%x\n", ModuleName, PhysicalBase, FileSize);
414 
415  return PhysicalBase;
416 }
Definition: arc.h:32
#define WARN(fmt,...)
Definition: debug.h:111
ULONG ARC_STATUS
Definition: arc.h:4
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:1264
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
ARC_STATUS ArcRead(ULONG FileId, VOID *Buffer, ULONG N, ULONG *Count)
Definition: fs.c:236
PVOID MmAllocateMemoryWithType(SIZE_T MemorySize, TYPE_OF_MEMORY MemoryType)
Definition: mm.c:31
_Must_inspect_result_ _Out_ PLARGE_INTEGER FileSize
Definition: fsrtlfuncs.h:108
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
Status
Definition: gdiplustypes.h:24
#define ERR(fmt,...)
Definition: debug.h:109
signed char * PSTR
Definition: retypes.h:7
ARC_STATUS ArcClose(ULONG FileId)
Definition: fs.c:218
ARC_STATUS ArcGetFileInformation(ULONG FileId, FILEINFORMATION *Information)
Definition: fs.c:250
struct FileInfo FileInfo
ARC_STATUS ArcOpen(CHAR *Path, OPENMODE OpenMode, ULONG *FileId)
Definition: fs.c:56
unsigned int ULONG
Definition: retypes.h:1
_Must_inspect_result_ _In_ PFILE_OBJECT _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ FLT_IO_OPERATION_FLAGS _Out_opt_ PULONG BytesRead
Definition: fltkernel.h:1255

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

◆ WinLdrLoadNLSData()

BOOLEAN WinLdrLoadNLSData ( IN OUT PLOADER_PARAMETER_BLOCK  LoaderBlock,
IN PCSTR  DirectoryPath,
IN PCSTR  AnsiFileName,
IN PCSTR  OemFileName,
IN PCSTR  LanguageFileName 
)

Definition at line 301 of file wlregistry.c.

306 {
307  CHAR FileName[255];
308  ULONG FileId;
309  ULONG AnsiFileSize, OemFileSize, LanguageFileSize;
310  ULONG TotalSize;
311  PVOID NlsDataBase;
312  PVOID NlsVirtual;
313  BOOLEAN AnsiEqualsOem = FALSE;
317 
318  /* There may be a case, when OEM and ANSI page coincide */
319  if (!strcmp(AnsiFileName, OemFileName))
320  AnsiEqualsOem = TRUE;
321 
322  /* Open file with ANSI and store its size */
323  RtlStringCbCopyA(FileName, sizeof(FileName), DirectoryPath);
324  RtlStringCbCatA(FileName, sizeof(FileName), AnsiFileName);
325  Status = ArcOpen(FileName, OpenReadOnly, &FileId);
326  if (Status != ESUCCESS)
327  {
328  WARN("Error while opening '%s', Status: %u\n", FileName, Status);
329  goto Failure;
330  }
331 
333  ArcClose(FileId);
334  if (Status != ESUCCESS)
335  goto Failure;
336  AnsiFileSize = FileInfo.EndingAddress.LowPart;
337  TRACE("AnsiFileSize: %d\n", AnsiFileSize);
338 
339  /* Open OEM file and store its length */
340  if (AnsiEqualsOem)
341  {
342  OemFileSize = 0;
343  }
344  else
345  {
346  //Print(L"Loading %s...\n", Filename);
347  RtlStringCbCopyA(FileName, sizeof(FileName), DirectoryPath);
348  RtlStringCbCatA(FileName, sizeof(FileName), OemFileName);
349  Status = ArcOpen(FileName, OpenReadOnly, &FileId);
350  if (Status != ESUCCESS)
351  {
352  WARN("Error while opening '%s', Status: %u\n", FileName, Status);
353  goto Failure;
354  }
355 
357  ArcClose(FileId);
358  if (Status != ESUCCESS)
359  goto Failure;
360  OemFileSize = FileInfo.EndingAddress.LowPart;
361  }
362  TRACE("OemFileSize: %d\n", OemFileSize);
363 
364  /* And finally open the language codepage file and store its length */
365  //Print(L"Loading %s...\n", Filename);
366  RtlStringCbCopyA(FileName, sizeof(FileName), DirectoryPath);
367  RtlStringCbCatA(FileName, sizeof(FileName), LanguageFileName);
368  Status = ArcOpen(FileName, OpenReadOnly, &FileId);
369  if (Status != ESUCCESS)
370  {
371  WARN("Error while opening '%s', Status: %u\n", FileName, Status);
372  goto Failure;
373  }
374 
376  ArcClose(FileId);
377  if (Status != ESUCCESS)
378  goto Failure;
379  LanguageFileSize = FileInfo.EndingAddress.LowPart;
380  TRACE("LanguageFileSize: %d\n", LanguageFileSize);
381 
382  /* Sum up all three length, having in mind that every one of them
383  must start at a page boundary => thus round up each file to a page */
384  TotalSize = MM_SIZE_TO_PAGES(AnsiFileSize) +
385  MM_SIZE_TO_PAGES(OemFileSize) +
386  MM_SIZE_TO_PAGES(LanguageFileSize);
387 
388  /* Store it for later marking the pages as NlsData type */
389  TotalNLSSize = TotalSize;
390 
391  NlsDataBase = MmAllocateMemoryWithType(TotalSize*MM_PAGE_SIZE, LoaderNlsData);
392  if (NlsDataBase == NULL)
393  goto Failure;
394 
395  NlsVirtual = PaToVa(NlsDataBase);
396  LoaderBlock->NlsData->AnsiCodePageData = NlsVirtual;
397  LoaderBlock->NlsData->OemCodePageData = (PVOID)((ULONG_PTR)NlsVirtual +
398  (MM_SIZE_TO_PAGES(AnsiFileSize) << MM_PAGE_SHIFT));
399  LoaderBlock->NlsData->UnicodeCodePageData = (PVOID)((ULONG_PTR)NlsVirtual +
400  (MM_SIZE_TO_PAGES(AnsiFileSize) << MM_PAGE_SHIFT) +
401  (MM_SIZE_TO_PAGES(OemFileSize) << MM_PAGE_SHIFT));
402 
403  /* Ansi and OEM data are the same - just set pointers to the same area */
404  if (AnsiEqualsOem)
405  LoaderBlock->NlsData->OemCodePageData = LoaderBlock->NlsData->AnsiCodePageData;
406 
407  /* Now actually read the data into memory, starting with Ansi file */
408  RtlStringCbCopyA(FileName, sizeof(FileName), DirectoryPath);
409  RtlStringCbCatA(FileName, sizeof(FileName), AnsiFileName);
410  Status = ArcOpen(FileName, OpenReadOnly, &FileId);
411  if (Status != ESUCCESS)
412  {
413  WARN("Error while opening '%s', Status: %u\n", FileName, Status);
414  goto Failure;
415  }
416 
417  Status = ArcRead(FileId, VaToPa(LoaderBlock->NlsData->AnsiCodePageData), AnsiFileSize, &BytesRead);
418  ArcClose(FileId);
419  if (Status != ESUCCESS)
420  {
421  WARN("Error while reading '%s', Status: %u\n", FileName, Status);
422  goto Failure;
423  }
424 
425  /* OEM now, if it doesn't equal Ansi of course */
426  if (!AnsiEqualsOem)
427  {
428  RtlStringCbCopyA(FileName, sizeof(FileName), DirectoryPath);
429  RtlStringCbCatA(FileName, sizeof(FileName), OemFileName);
430  Status = ArcOpen(FileName, OpenReadOnly, &FileId);
431  if (Status != ESUCCESS)
432  {
433  WARN("Error while opening '%s', Status: %u\n", FileName, Status);
434  goto Failure;
435  }
436 
437  Status = ArcRead(FileId, VaToPa(LoaderBlock->NlsData->OemCodePageData), OemFileSize, &BytesRead);
438  ArcClose(FileId);
439  if (Status != ESUCCESS)
440  {
441  WARN("Error while reading '%s', Status: %u\n", FileName, Status);
442  goto Failure;
443  }
444  }
445 
446  /* Finally the language file */
447  RtlStringCbCopyA(FileName, sizeof(FileName), DirectoryPath);
448  RtlStringCbCatA(FileName, sizeof(FileName), LanguageFileName);
449  Status = ArcOpen(FileName, OpenReadOnly, &FileId);
450  if (Status != ESUCCESS)
451  {
452  WARN("Error while opening '%s', Status: %u\n", FileName, Status);
453  goto Failure;
454  }
455 
456  Status = ArcRead(FileId, VaToPa(LoaderBlock->NlsData->UnicodeCodePageData), LanguageFileSize, &BytesRead);
457  ArcClose(FileId);
458  if (Status != ESUCCESS)
459  {
460  WARN("Error while reading '%s', Status: %u\n", FileName, Status);
461  goto Failure;
462  }
463 
464  //
465  // THIS IS HAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACK
466  // Should go to WinLdrLoadOemHalFont(), when it will be implemented
467  //
468  LoaderBlock->OemFontFile = VaToPa(LoaderBlock->NlsData->UnicodeCodePageData);
469 
470  /* Convert NlsTables address to VA */
471  LoaderBlock->NlsData = PaToVa(LoaderBlock->NlsData);
472 
473  return TRUE;
474 
475 Failure:
476  UiMessageBox("Error reading NLS file %s", FileName);
477  return FALSE;
478 }
#define TRUE
Definition: types.h:120
Definition: arc.h:32
char CHAR
Definition: xmlstorage.h:175
#define WARN(fmt,...)
Definition: debug.h:111
ULONG ARC_STATUS
Definition: arc.h:4
uint32_t ULONG_PTR
Definition: typedefs.h:63
NTSTRSAFEAPI RtlStringCbCopyA(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCSTR pszSrc)
Definition: ntstrsafe.h:156
VOID UiMessageBox(PCSTR Format,...)
Definition: ui.c:320
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
void * PVOID
Definition: retypes.h:9
#define TRACE(s)
Definition: solgame.cpp:4
ARC_STATUS ArcRead(ULONG FileId, VOID *Buffer, ULONG N, ULONG *Count)
Definition: fs.c:236
PVOID MmAllocateMemoryWithType(SIZE_T MemorySize, TYPE_OF_MEMORY MemoryType)
Definition: mm.c:31
Status
Definition: gdiplustypes.h:24
ULONG TotalNLSSize
Definition: wlregistry.c:19
ARC_STATUS ArcClose(ULONG FileId)
Definition: fs.c:218
ARC_STATUS ArcGetFileInformation(ULONG FileId, FILEINFORMATION *Information)
Definition: fs.c:250
struct FileInfo FileInfo
FORCEINLINE PVOID PaToVa(PVOID Pa)
Definition: conversion.h:22
ARC_STATUS ArcOpen(CHAR *Path, OPENMODE OpenMode, ULONG *FileId)
Definition: fs.c:56
unsigned int ULONG
Definition: retypes.h:1
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
FORCEINLINE PVOID VaToPa(PVOID Va)
Definition: conversion.h:15
_Must_inspect_result_ _In_ PFILE_OBJECT _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ FLT_IO_OPERATION_FLAGS _Out_opt_ PULONG BytesRead
Definition: fltkernel.h:1255
NTSTRSAFEAPI RtlStringCbCatA(_Inout_updates_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCSTR pszSrc)
Definition: ntstrsafe.h:625

Referenced by SetupLdrLoadNlsData(), and WinLdrScanSystemHive().

◆ WinLdrpDumpArcDisks()

VOID WinLdrpDumpArcDisks ( PLOADER_PARAMETER_BLOCK  LoaderBlock)

Definition at line 1044 of file winldr.c.

1045 {
1046  PLIST_ENTRY NextBd;
1047  PARC_DISK_SIGNATURE ArcDisk;
1048 
1049  NextBd = LoaderBlock->ArcDiskInformation->DiskSignatureListHead.Flink;
1050 
1051  while (NextBd != &LoaderBlock->ArcDiskInformation->DiskSignatureListHead)
1052  {
1053  ArcDisk = CONTAINING_RECORD(NextBd, ARC_DISK_SIGNATURE, ListEntry);
1054 
1055  TRACE("ArcDisk %s checksum: 0x%X, signature: 0x%X\n",
1056  ArcDisk->ArcName, ArcDisk->CheckSum, ArcDisk->Signature);
1057 
1058  NextBd = ArcDisk->ListEntry.Flink;
1059  }
1060 }
PCHAR ArcName
Definition: arc.h:210
ULONG Signature
Definition: arc.h:209
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define TRACE(s)
Definition: solgame.cpp:4
LIST_ENTRY ListEntry
Definition: arc.h:208
PARC_DISK_INFORMATION ArcDiskInformation
Definition: arc.h:509
Definition: typedefs.h:117
LIST_ENTRY DiskSignatureListHead
Definition: arc.h:221
ULONG CheckSum
Definition: arc.h:211

Referenced by LoadAndBootWindowsCommon().

◆ WinLdrpDumpBootDriver()

VOID WinLdrpDumpBootDriver ( PLOADER_PARAMETER_BLOCK  LoaderBlock)

Definition at line 1025 of file winldr.c.

1026 {
1027  PLIST_ENTRY NextBd;
1028  PBOOT_DRIVER_LIST_ENTRY BootDriver;
1029 
1030  NextBd = LoaderBlock->BootDriverListHead.Flink;
1031 
1032  while (NextBd != &LoaderBlock->BootDriverListHead)
1033  {
1034  BootDriver = CONTAINING_RECORD(NextBd, BOOT_DRIVER_LIST_ENTRY, Link);
1035 
1036  TRACE("BootDriver %wZ DTE %08X RegPath: %wZ\n", &BootDriver->FilePath,
1037  BootDriver->LdrEntry, &BootDriver->RegistryPath);
1038 
1039  NextBd = BootDriver->Link.Flink;
1040  }
1041 }
UNICODE_STRING FilePath
Definition: arc.h:201
static int Link(const char **args)
Definition: vfdcmd.c:2414
Definition: arc.h:198
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define TRACE(s)
Definition: solgame.cpp:4
LIST_ENTRY BootDriverListHead
Definition: arc.h:495
Definition: typedefs.h:117
UNICODE_STRING RegistryPath
Definition: arc.h:202
struct _LDR_DATA_TABLE_ENTRY * LdrEntry
Definition: arc.h:203
LIST_ENTRY Link
Definition: arc.h:200

Referenced by LoadAndBootWindowsCommon().

◆ WinLdrpDumpMemoryDescriptors()

VOID WinLdrpDumpMemoryDescriptors ( PLOADER_PARAMETER_BLOCK  LoaderBlock)

Definition at line 1006 of file winldr.c.

1007 {
1008  PLIST_ENTRY NextMd;
1010 
1011  NextMd = LoaderBlock->MemoryDescriptorListHead.Flink;
1012 
1013  while (NextMd != &LoaderBlock->MemoryDescriptorListHead)
1014  {
1016 
1017  TRACE("BP %08X PC %04X MT %d\n", MemoryDescriptor->BasePage,
1018  MemoryDescriptor->PageCount, MemoryDescriptor->MemoryType);
1019 
1020  NextMd = MemoryDescriptor->ListEntry.Flink;
1021  }
1022 }
_Out_ PNDIS_BUFFER _In_ NDIS_HANDLE _In_ PVOID MemoryDescriptor
Definition: ndis.h:3270
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define TRACE(s)
Definition: solgame.cpp:4
Definition: typedefs.h:117
LIST_ENTRY MemoryDescriptorListHead
Definition: arc.h:494

Referenced by LoadAndBootWindowsCommon(), and WinLdrSetupMemoryLayout().

◆ WinLdrScanSystemHive()

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

Definition at line 173 of file wlregistry.c.

175 {
176  CHAR SearchPath[1024];
177  CHAR AnsiName[256], OemName[256], LangName[256];
179 
180  /* Scan registry and prepare boot drivers list */
181  WinLdrScanRegistry(&LoaderBlock->BootDriverListHead, SystemRoot);
182 
183  /* Get names of NLS files */
184  Success = WinLdrGetNLSNames(AnsiName, OemName, LangName);
185  if (!Success)
186  {
187  UiMessageBox("Getting NLS names from registry failed!");
188  return FALSE;
189  }
190 
191  TRACE("NLS data %s %s %s\n", AnsiName, OemName, LangName);
192 
193  /* Load NLS data */
195  RtlStringCbCatA(SearchPath, sizeof(SearchPath), "system32\\");
196  Success = WinLdrLoadNLSData(LoaderBlock, SearchPath, AnsiName, OemName, LangName);
197  TRACE("NLS data loading %s\n", Success ? "successful" : "failed");
198 
199  /* TODO: Load OEM HAL font */
200  // In HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\CodePage,
201  // REG_SZ value "OEMHAL"
202 
203  return TRUE;
204 }
#define TRUE
Definition: types.h:120
static VOID WinLdrScanRegistry(IN OUT PLIST_ENTRY BootDriverListHead, IN PCSTR SystemRoot)
Definition: wlregistry.c:481
char CHAR
Definition: xmlstorage.h:175
#define SearchPath
Definition: winbase.h:3724
NTSTRSAFEAPI RtlStringCbCopyA(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCSTR pszSrc)
Definition: ntstrsafe.h:156
VOID UiMessageBox(PCSTR Format,...)
Definition: ui.c:320
unsigned char BOOLEAN
static BOOLEAN WinLdrGetNLSNames(PSTR AnsiName, PSTR OemName, PSTR LangName)
Definition: wlregistry.c:211
#define TRACE(s)
Definition: solgame.cpp:4
static const WCHAR SystemRoot[]
Definition: reg.c:38
BOOLEAN WinLdrLoadNLSData(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, IN PCSTR DirectoryPath, IN PCSTR AnsiFileName, IN PCSTR OemFileName, IN PCSTR LanguageFileName)
Definition: wlregistry.c:301
IN PDCB IN POEM_STRING OemName
Definition: fatprocs.h:1294
NTSTRSAFEAPI RtlStringCbCatA(_Inout_updates_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCSTR pszSrc)
Definition: ntstrsafe.h:625

Referenced by LoadAndBootWindows().

◆ WinLdrSetProcessorContext()

VOID WinLdrSetProcessorContext ( VOID  )

Definition at line 348 of file winldr.c.

349 {
350  TRACE("WinLdrSetProcessorContext\n");
351 
352  /* Disable Interrupts */
353  _disable();
354 
355  /* Re-initialize EFLAGS */
356  __writeeflags(0);
357 
358  /* Set the new PML4 */
360 
361  /* Get kernel mode address of gdt / idt */
363 
364  /* Create gdt entries and load gdtr */
365  Amd64SetupGdt(GdtIdt, KSEG0_BASE | (TssBasePage << MM_PAGE_SHIFT));
366 
367  /* Copy old Idt and set idtr */
369 
370  /* LDT is unused */
371 // __lldt(0);
372 
373  /* Load TSR */
374  __ltr(KGDT64_SYS_TSS);
375 
376  TRACE("leave WinLdrSetProcessorContext\n");
377 }
static VOID Amd64SetupIdt(PVOID IdtBase)
Definition: winldr.c:325
static VOID Amd64SetupGdt(PVOID GdtBase, ULONG64 TssBase)
Definition: winldr.c:276
PHARDWARE_PTE PxeBase
Definition: winldr.c:22
__INTRIN_INLINE void __writecr3(unsigned int Data)
Definition: intrin_x86.h:1675
#define KSEG0_BASE
Definition: ketypes.h:273
ULONG_PTR TssBasePage
Definition: winldr.c:27
void * PVOID
Definition: retypes.h:9
#define TRACE(s)
Definition: solgame.cpp:4
unsigned __int64 ULONG64
Definition: imports.h:198
#define KGDT64_SYS_TSS
Definition: ketypes.h:77
__INTRIN_INLINE void __writeeflags(uintptr_t Value)
Definition: intrin_x86.h:1550
#define NUM_GDT
Definition: winldr.h:16
void __cdecl _disable(void)
Definition: intrin_arm.h:365
PVOID GdtIdt
Definition: winldr.c:25

Referenced by LoadAndBootWindowsCommon().

◆ WinLdrSetupMachineDependent()

VOID WinLdrSetupMachineDependent ( PLOADER_PARAMETER_BLOCK  LoaderBlock)

Definition at line 379 of file winldr.c.

380 {
381  ULONG_PTR Pcr = 0;
382  ULONG_PTR Tss = 0;
383  ULONG BlockSize, NumPages;
384 
385  LoaderBlock->u.I386.CommonDataArea = (PVOID)DbgPrint; // HACK
386  LoaderBlock->u.I386.MachineType = MACHINE_TYPE_ISA;
387 
388  /* Allocate 2 pages for PCR */
389  Pcr = (ULONG_PTR)MmAllocateMemoryWithType(2 * MM_PAGE_SIZE, LoaderStartupPcrPage);
390  PcrBasePage = Pcr >> MM_PAGE_SHIFT;
391  if (Pcr == 0)
392  {
393  UiMessageBox("Can't allocate PCR.");
394  return;
395  }
396  RtlZeroMemory((PVOID)Pcr, 2 * MM_PAGE_SIZE);
397 
398  /* Allocate TSS */
399  BlockSize = (sizeof(KTSS) + MM_PAGE_SIZE) & ~(MM_PAGE_SIZE - 1);
401  TssBasePage = Tss >> MM_PAGE_SHIFT;
402 
403  /* Allocate space for new GDT + IDT */
404  BlockSize = NUM_GDT * sizeof(KGDTENTRY) + NUM_IDT * sizeof(KIDTENTRY);
405  NumPages = (BlockSize + MM_PAGE_SIZE - 1) >> MM_PAGE_SHIFT;
406  GdtIdt = (PKGDTENTRY)MmAllocateMemoryWithType(NumPages * MM_PAGE_SIZE, LoaderMemoryData);
407  if (GdtIdt == NULL)
408  {
409  UiMessageBox("Can't allocate pages for GDT+IDT!");
410  return;
411  }
412 
413  /* Zero newly prepared GDT+IDT */
414  RtlZeroMemory(GdtIdt, NumPages << MM_PAGE_SHIFT);
415 
416  // Before we start mapping pages, create a block of memory, which will contain
417  // PDE and PTEs
418  if (MempAllocatePageTables() == FALSE)
419  {
420  // FIXME: bugcheck
421  }
422 
423  /* Map stuff like PCR, KI_USER_SHARED_DATA and Apic */
425 }
#define PKGDTENTRY
Definition: ketypes.h:438
#define KTSS
Definition: ketypes.h:920
#define DbgPrint
Definition: loader.c:25
ULONG_PTR PcrBasePage
Definition: winldr.c:26
#define KGDTENTRY
Definition: ketypes.h:437
static BOOLEAN WinLdrMapSpecialPages(VOID)
Definition: winldr.c:244
uint32_t ULONG_PTR
Definition: typedefs.h:63
VOID UiMessageBox(PCSTR Format,...)
Definition: ui.c:320
I386_LOADER_BLOCK I386
Definition: arc.h:515
smooth NULL
Definition: ftsmooth.c:416
ULONG_PTR TssBasePage
Definition: winldr.c:27
void * PVOID
Definition: retypes.h:9
ULONG MachineType
Definition: arc.h:407
#define MACHINE_TYPE_ISA
Definition: ketypes.h:52
#define NUM_IDT
Definition: winldr.h:17
PVOID MmAllocateMemoryWithType(SIZE_T MemorySize, TYPE_OF_MEMORY MemoryType)
Definition: mm.c:31
PVOID CommonDataArea
Definition: arc.h:406
#define NUM_GDT
Definition: winldr.h:16
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define ULONG_PTR
Definition: config.h:101
PVOID GdtIdt
Definition: winldr.c:25
union _LOADER_PARAMETER_BLOCK::@3274 u
static BOOLEAN MempAllocatePageTables(VOID)
Definition: winldr.c:33

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;
188  //BOOLEAN Status;
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 #if 0
233  // Always contiguously map low 1Mb of memory
234  Status = MempSetupPaging(0, 0x100, FALSE);
235  if (!Status)
236  {
237  ERR("Error during MempSetupPaging of low 1Mb\n");
238  return FALSE;
239  }
240 #endif
241 
242  /* Before creating the map, we need to map pages to kernel mode */
243  LastPageIndex = 1;
244  LastPageType = MemoryMap[1].PageAllocated;
245  for (i = 2; i < NoEntries; i++)
246  {
247  if ((MemoryMap[i].PageAllocated != LastPageType) ||
248  (i == NoEntries - 1))
249  {
250  MempSetupPagingForRegion(LastPageIndex, i - LastPageIndex, LastPageType);
251  LastPageIndex = i;
252  LastPageType = MemoryMap[i].PageAllocated;
253  }
254  }
255 
256  // Construct a good memory map from what we've got,
257  // but mark entries which the memory allocation bitmap takes
258  // as free entries (this is done in order to have the ability
259  // to place mem alloc bitmap outside lower 16Mb zone)
260  PagesCount = 1;
261  LastPageIndex = 0;
262  LastPageType = MemoryMap[0].PageAllocated;
263  for (i = 1; i < NoEntries; i++)
264  {
265  // Check if its memory map itself
266  if (i >= MemoryMapStartPage &&
267  i < (MemoryMapStartPage+MemoryMapSizeInPages))
268  {
269  // Exclude it if current page belongs to the memory map
270  MemoryMap[i].PageAllocated = LoaderFree;
271  }
272 
273  // Process entry
274  if (MemoryMap[i].PageAllocated == LastPageType &&
275  (i != NoEntries-1) )
276  {
277  PagesCount++;
278  }
279  else
280  {
281  // Add the resulting region
282  MempAddMemoryBlock(LoaderBlock, LastPageIndex, PagesCount, LastPageType);
283 
284  // Reset our counter vars
285  LastPageIndex = i;
286  LastPageType = MemoryMap[i].PageAllocated;
287  PagesCount = 1;
288  }
289  }
290 
291  // TEMP, DEBUG!
292  // adding special reserved memory zones for vmware workstation
293 #if 0
294  {
295  Mad[MadCount].BasePage = 0xfec00;
296  Mad[MadCount].PageCount = 0x10;
298  WinLdrInsertDescriptor(LoaderBlock, &Mad[MadCount]);
299  MadCount++;
300 
301  Mad[MadCount].BasePage = 0xfee00;
302  Mad[MadCount].PageCount = 0x1;
304  WinLdrInsertDescriptor(LoaderBlock, &Mad[MadCount]);
305  MadCount++;
306 
307  Mad[MadCount].BasePage = 0xfffe0;
308  Mad[MadCount].PageCount = 0x20;
310  WinLdrInsertDescriptor(LoaderBlock, &Mad[MadCount]);
311  MadCount++;
312  }
313 #endif
314 
315  /* Now we need to add high descriptors from the bios memory map */
316  for (i = 0; i < BiosMemoryMapEntryCount; i++)
317  {
318  /* Check if its higher than the lookup table */
320  {
321  /* Copy this descriptor */
322  MempAddMemoryBlock(LoaderBlock,
326  }
327  }
328 
329  TRACE("MadCount: %d\n", MadCount);
330 
331  WinLdrpDumpMemoryDescriptors(LoaderBlock); //FIXME: Delete!
332 
333  // Map our loader image, so we can continue running
334  /*Status = MempSetupPaging(OsLoaderBase >> MM_PAGE_SHIFT, OsLoaderSize >> MM_PAGE_SHIFT);
335  if (!Status)
336  {
337  UiMessageBox("Error during MempSetupPaging.");
338  return;
339  }*/
340 
341  // Fill the memory descriptor list and
342  //PrepareMemoryDescriptorList();
343  TRACE("Memory Descriptor List prepared, printing PDE\n");
344  List_PaToVa(&LoaderBlock->MemoryDescriptorListHead);
345 
346 #if DBG
347  MempDump();
348 #endif
349 
350  return TRUE;
351 }
VOID MempDump(VOID)
Definition: winldr.c:429
PFN_NUMBER MmHighestPhysicalPage
Definition: meminit.c:31
#define TRUE
Definition: types.h:120
ULONG MadCount
Definition: wlmemory.c:58
VOID List_PaToVa(_In_ LIST_ENTRY *ListEntry)
BIOS_MEMORY_MAP MemoryMap[32]
Definition: loader.c:11
TYPE_OF_MEMORY MemoryType
Definition: mm.h:38
VOID MempSetupPagingForRegion(PFN_NUMBER BasePage, PFN_NUMBER PageCount, ULONG Type)
Definition: wlmemory.c:106
BOOLEAN MempSetupPaging(IN PFN_NUMBER StartPage, IN PFN_NUMBER NumberOfPages, IN BOOLEAN KernelMapping)
Definition: winldr.c:170
MEMORY_ALLOCATION_DESCRIPTOR * Mad
Definition: wlmemory.c:57
TYPE_OF_MEMORY MemoryType
Definition: arc.h:193
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
ULONG PFN_NUMBER
Definition: ke.h:8
#define MAX_MAD_COUNT
Definition: wlmemory.c:60
VOID UiMessageBox(PCSTR Format,...)
Definition: ui.c:320
smooth NULL
Definition: ftsmooth.c:416
PFN_NUMBER BasePage
Definition: mm.h:39
ULONG BiosMemoryMapEntryCount
Definition: meminit.c:34
#define TRACE(s)
Definition: solgame.cpp:4
PPAGE_LOOKUP_TABLE_ITEM MmGetMemoryMap(PFN_NUMBER *NoEntries)
Definition: mm.c:297
VOID FrLdrHeapCleanupAll(VOID)
Definition: heap.c:248
PFREELDR_MEMORY_DESCRIPTOR BiosMemoryMap
Definition: meminit.c:33
PVOID MmAllocateMemoryWithType(SIZE_T MemorySize, TYPE_OF_MEMORY MemoryType)
Definition: mm.c:31
VOID WinLdrpDumpMemoryDescriptors(PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: winldr.c:1006
Status
Definition: gdiplustypes.h:24
VOID MempAddMemoryBlock(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, PFN_NUMBER BasePage, PFN_NUMBER PageCount, ULONG Type)
Definition: wlmemory.c:65
#define ERR(fmt,...)
Definition: debug.h:109
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
static VOID WinLdrInsertDescriptor(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, IN PMEMORY_ALLOCATION_DESCRIPTOR NewDescriptor)
Definition: wlmemory.c:356
PFN_NUMBER PageCount
Definition: mm.h:40

Referenced by LoadAndBootWindowsCommon().

Variable Documentation

◆ WinLdrSystemBlock

PLOADER_SYSTEM_BLOCK WinLdrSystemBlock

Definition at line 27 of file winldr.c.

Referenced by AllocateAndInitLPB(), LoadReactOSSetup(), and WinLdrInitializePhase1().