ReactOS  0.4.15-dev-3453-gff89651
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 (IN USHORT OperatingSystemVersion, IN PLOADER_PARAMETER_BLOCK LoaderBlock, IN PCSTR BootOptions, IN PCSTR BootPath)
 
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
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFDEVICE Child
Definition: wdffdo.h:533
struct _CONFIGURATION_COMPONENT_DATA * Child
Definition: arc.h:119
CONFIGURATION_TYPE Type
Definition: arc.h:105
#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
#define NULL
Definition: types.h:112
VOID ConvertConfigToVA(PCONFIGURATION_COMPONENT_DATA Start)
Definition: conversion.c:51
FORCEINLINE PVOID PaToVa(PVOID Pa)
Definition: conversion.h:22
FORCEINLINE PVOID VaToPa(PVOID Va)
Definition: conversion.h:15

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 955 of file winldr.c.

960 {
961  PLOADER_PARAMETER_BLOCK LoaderBlockVA;
963  PLDR_DATA_TABLE_ENTRY KernelDTE;
966 
967  TRACE("LoadAndBootWindowsCommon()\n");
968 
969  ASSERT(OperatingSystemVersion != 0);
970 
971 #ifdef _M_IX86
972  /* Setup redirection support */
974 #endif
975 
976  /* Convert BootPath to SystemRoot */
977  SystemRoot = strstr(BootPath, "\\");
978 
979  /* Detect hardware */
980  UiDrawBackdrop();
981  UiDrawProgressBarCenter(20, 100, "Detecting hardware...");
982  LoaderBlock->ConfigurationRoot = MachHwDetect();
983 
984  /* Load the operating system core: the Kernel, the HAL and the Kernel Debugger Transport DLL */
985  Success = LoadWindowsCore(OperatingSystemVersion,
986  LoaderBlock,
987  BootOptions,
988  BootPath,
989  &KernelDTE);
990  if (!Success)
991  {
992  UiMessageBox("Error loading NTOS core.");
993  return ENOEXEC;
994  }
995 
996  /* Load boot drivers */
997  UiDrawBackdrop();
998  UiDrawProgressBarCenter(100, 100, "Loading boot drivers...");
999  Success = WinLdrLoadBootDrivers(LoaderBlock, BootPath);
1000  TRACE("Boot drivers loading %s\n", Success ? "successful" : "failed");
1001 
1002  /* Cleanup ini file */
1003  IniCleanup();
1004 
1005  /* Initialize Phase 1 - no drivers loading anymore */
1006  WinLdrInitializePhase1(LoaderBlock,
1007  BootOptions,
1008  SystemRoot,
1009  BootPath,
1010  OperatingSystemVersion);
1011 
1012  /* Save entry-point pointer and Loader block VAs */
1014  LoaderBlockVA = PaToVa(LoaderBlock);
1015 
1016  /* "Stop all motors", change videomode */
1018 
1019  /* Debugging... */
1020  //DumpMemoryAllocMap();
1021 
1022  /* Do the machine specific initialization */
1023  WinLdrSetupMachineDependent(LoaderBlock);
1024 
1025  /* Map pages and create memory descriptors */
1026  WinLdrSetupMemoryLayout(LoaderBlock);
1027 
1028  /* Set processor context */
1030 
1031  /* Save final value of LoaderPagesSpanned */
1032  LoaderBlock->Extension->LoaderPagesSpanned = LoaderPagesSpanned;
1033 
1034  TRACE("Hello from paged mode, KiSystemStartup %p, LoaderBlockVA %p!\n",
1035  KiSystemStartup, LoaderBlockVA);
1036 
1037  /* Zero KI_USER_SHARED_DATA page */
1038  RtlZeroMemory((PVOID)KI_USER_SHARED_DATA, MM_PAGE_SIZE);
1039 
1040  WinLdrpDumpMemoryDescriptors(LoaderBlockVA);
1041  WinLdrpDumpBootDriver(LoaderBlockVA);
1042 #ifndef _M_AMD64
1043  WinLdrpDumpArcDisks(LoaderBlockVA);
1044 #endif
1045 
1046  /* Pass control */
1047  (*KiSystemStartup)(LoaderBlockVA);
1048 
1049  UNREACHABLE; // return ESUCCESS;
1050 }
#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:319
VOID WinLdrpDumpArcDisks(PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: winldr.c:1091
VOID WinLdrSetProcessorContext(void)
Definition: winldr.c:348
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
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:501
BOOLEAN WinLdrSetupMemoryLayout(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: wlmemory.c:181
PVOID EntryPoint
Definition: ntddk_ex.h:203
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:1072
#define TRACE(s)
Definition: solgame.cpp:4
#define ASSERT(a)
Definition: mode.c:44
static const WCHAR SystemRoot[]
Definition: reg.c:38
ULONG LoaderPagesSpanned
Definition: mm.c:29
VOID IniCleanup(VOID)
Definition: inifile.c:235
#define KI_USER_SHARED_DATA
#define MachPrepareForReactOS()
Definition: machine.h:120
Definition: btrfs_drv.h:1922
VOID UiDrawBackdrop(VOID)
Definition: ui.c:214
VOID WinLdrpDumpMemoryDescriptors(PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: winldr.c:1053
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:82
DECLSPEC_NORETURN VOID NTAPI KiSystemStartup(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: kiinit.c:372
FORCEINLINE PVOID PaToVa(PVOID Pa)
Definition: conversion.h:22
#define UNREACHABLE
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
Definition: arc.h:47
const char * PCSTR
Definition: typedefs.h:52
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 FALSE
Definition: types.h:117
#define KSEG0_BASE
Definition: ketypes.h:277
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:110

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 784 of file wlregistry.c.

788 {
789  PBOOT_DRIVER_LIST_ENTRY BootDriverEntry;
792 
793  BootDriverEntry = FrLdrHeapAlloc(sizeof(BOOT_DRIVER_LIST_ENTRY), TAG_WLDR_BDE);
794  if (!BootDriverEntry)
795  return FALSE;
796 
797  // DTE will be filled during actual load of the driver
798  BootDriverEntry->LdrEntry = NULL;
799 
800  // Check - if we have a valid ImagePath, if not - we need to build it
801  // like "System32\\Drivers\\blah.sys"
802  if (ImagePath && (ImagePath[0] != 0))
803  {
804  // Just copy ImagePath to the corresponding field in the structure
805  PathLength = (USHORT)wcslen(ImagePath) * sizeof(WCHAR) + sizeof(UNICODE_NULL);
806 
807  BootDriverEntry->FilePath.Length = 0;
808  BootDriverEntry->FilePath.MaximumLength = PathLength;
810  if (!BootDriverEntry->FilePath.Buffer)
811  {
812  FrLdrHeapFree(BootDriverEntry, TAG_WLDR_BDE);
813  return FALSE;
814  }
815 
816  Status = RtlAppendUnicodeToString(&BootDriverEntry->FilePath, ImagePath);
817  if (!NT_SUCCESS(Status))
818  {
819  FrLdrHeapFree(BootDriverEntry->FilePath.Buffer, TAG_WLDR_NAME);
820  FrLdrHeapFree(BootDriverEntry, TAG_WLDR_BDE);
821  return FALSE;
822  }
823  }
824  else
825  {
826  // we have to construct ImagePath ourselves
827  PathLength = (USHORT)wcslen(ServiceName)*sizeof(WCHAR) + sizeof(L"system32\\drivers\\.sys");
828  BootDriverEntry->FilePath.Length = 0;
829  BootDriverEntry->FilePath.MaximumLength = PathLength;
831  if (!BootDriverEntry->FilePath.Buffer)
832  {
833  FrLdrHeapFree(BootDriverEntry, TAG_WLDR_BDE);
834  return FALSE;
835  }
836 
837  Status = RtlAppendUnicodeToString(&BootDriverEntry->FilePath, L"system32\\drivers\\");
838  if (!NT_SUCCESS(Status))
839  {
840  FrLdrHeapFree(BootDriverEntry->FilePath.Buffer, TAG_WLDR_NAME);
841  FrLdrHeapFree(BootDriverEntry, TAG_WLDR_BDE);
842  return FALSE;
843  }
844 
845  Status = RtlAppendUnicodeToString(&BootDriverEntry->FilePath, ServiceName);
846  if (!NT_SUCCESS(Status))
847  {
848  FrLdrHeapFree(BootDriverEntry->FilePath.Buffer, TAG_WLDR_NAME);
849  FrLdrHeapFree(BootDriverEntry, TAG_WLDR_BDE);
850  return FALSE;
851  }
852 
853  Status = RtlAppendUnicodeToString(&BootDriverEntry->FilePath, L".sys");
854  if (!NT_SUCCESS(Status))
855  {
856  FrLdrHeapFree(BootDriverEntry->FilePath.Buffer, TAG_WLDR_NAME);
857  FrLdrHeapFree(BootDriverEntry, TAG_WLDR_BDE);
858  return FALSE;
859  }
860  }
861 
862  // Add registry path
864  BootDriverEntry->RegistryPath.Length = 0;
865  BootDriverEntry->RegistryPath.MaximumLength = PathLength;
867  if (!BootDriverEntry->RegistryPath.Buffer)
868  {
869  FrLdrHeapFree(BootDriverEntry->FilePath.Buffer, TAG_WLDR_NAME);
870  FrLdrHeapFree(BootDriverEntry, TAG_WLDR_BDE);
871  return FALSE;
872  }
873 
875  if (!NT_SUCCESS(Status))
876  {
877  FrLdrHeapFree(BootDriverEntry->RegistryPath.Buffer, TAG_WLDR_NAME);
878  FrLdrHeapFree(BootDriverEntry->FilePath.Buffer, TAG_WLDR_NAME);
879  FrLdrHeapFree(BootDriverEntry, TAG_WLDR_BDE);
880  return FALSE;
881  }
882 
884  if (!NT_SUCCESS(Status))
885  {
886  FrLdrHeapFree(BootDriverEntry->RegistryPath.Buffer, TAG_WLDR_NAME);
887  FrLdrHeapFree(BootDriverEntry->FilePath.Buffer, TAG_WLDR_NAME);
888  FrLdrHeapFree(BootDriverEntry, TAG_WLDR_BDE);
889  return FALSE;
890  }
891 
892  // Insert entry into the list
893  if (!InsertInBootDriverList(BootDriverListHead, BootDriverEntry))
894  {
895  // It was already there, so delete our entry
896  FrLdrHeapFree(BootDriverEntry->RegistryPath.Buffer, TAG_WLDR_NAME);
897  FrLdrHeapFree(BootDriverEntry->FilePath.Buffer, TAG_WLDR_NAME);
898  FrLdrHeapFree(BootDriverEntry, TAG_WLDR_BDE);
899  }
900 
901  return TRUE;
902 }
FORCEINLINE VOID FrLdrHeapFree(PVOID MemoryPointer, ULONG Tag)
Definition: mm.h:181
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:213
static USHORT PathLength
UNICODE_STRING FilePath
Definition: arc.h:201
Definition: arc.h:198
#define L(x)
Definition: ntvdm.h:50
#define FALSE
Definition: types.h:117
#define UNICODE_NULL
Status
Definition: gdiplustypes.h:24
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:174
LPTSTR ServiceName
Definition: ServiceMain.c:15
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
UNICODE_STRING RegistryPath
Definition: arc.h:202
unsigned short USHORT
Definition: pedump.c:61
struct _LDR_DATA_TABLE_ENTRY * LdrEntry
Definition: arc.h:203
#define NULL
Definition: types.h:112
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
static BOOLEAN InsertInBootDriverList(PLIST_ENTRY BootDriverListHead, PBOOT_DRIVER_LIST_ENTRY BootDriverEntry)
Definition: wlregistry.c:745

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

◆ WinLdrInitializePhase1()

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

Definition at line 82 of file winldr.c.

87 {
88  /*
89  * Examples of correct options and paths:
90  * CHAR Options[] = "/DEBUGPORT=COM1 /BAUDRATE=115200";
91  * CHAR Options[] = "/NODEBUG";
92  * CHAR SystemRoot[] = "\\WINNT\\";
93  * CHAR ArcBoot[] = "multi(0)disk(0)rdisk(0)partition(1)";
94  */
95 
96  PSTR LoadOptions, NewLoadOptions;
97  CHAR HalPath[] = "\\";
98  CHAR ArcBoot[MAX_PATH+1];
99  CHAR MiscFiles[MAX_PATH+1];
100  ULONG i;
101  ULONG_PTR PathSeparator;
103 
104  /* Construct SystemRoot and ArcBoot from SystemPath */
105  PathSeparator = strstr(BootPath, "\\") - BootPath;
106  RtlStringCbCopyNA(ArcBoot, sizeof(ArcBoot), BootPath, PathSeparator);
107 
108  TRACE("ArcBoot: '%s'\n", ArcBoot);
109  TRACE("SystemRoot: '%s'\n", SystemRoot);
110  TRACE("Options: '%s'\n", Options);
111 
112  /* Fill ARC BootDevice */
115  LoaderBlock->ArcBootDeviceName = PaToVa(LoaderBlock->ArcBootDeviceName);
116 
117 //
118 // IMPROVE!!
119 // SetupBlock->ArcSetupDeviceName must be the path to the setup **SOURCE**,
120 // and not the setup boot path. Indeed they may differ!!
121 //
122  if (LoaderBlock->SetupLdrBlock)
123  {
124  PSETUP_LOADER_BLOCK SetupBlock = LoaderBlock->SetupLdrBlock;
125 
126  /* Adjust the ARC path in the setup block - Matches ArcBoot path */
128  SetupBlock->ArcSetupDeviceName = PaToVa(SetupBlock->ArcSetupDeviceName);
129 
130  /* Convert the setup block pointer */
131  LoaderBlock->SetupLdrBlock = PaToVa(LoaderBlock->SetupLdrBlock);
132  }
133 
134  /* Fill ARC HalDevice, it matches ArcBoot path */
136  LoaderBlock->ArcHalDeviceName = PaToVa(LoaderBlock->ArcHalDeviceName);
137 
138  /* Fill SystemRoot */
141  LoaderBlock->NtBootPathName = PaToVa(LoaderBlock->NtBootPathName);
142 
143  /* Fill NtHalPathName */
145  RtlStringCbCopyA(LoaderBlock->NtHalPathName, sizeof(WinLdrSystemBlock->NtHalPathName), HalPath);
146  LoaderBlock->NtHalPathName = PaToVa(LoaderBlock->NtHalPathName);
147 
148  /* Fill LoadOptions and strip the '/' switch symbol in front of each option */
149  NewLoadOptions = LoadOptions = LoaderBlock->LoadOptions = WinLdrSystemBlock->LoadOptions;
151 
152  do
153  {
154  while (*LoadOptions == '/')
155  ++LoadOptions;
156 
157  *NewLoadOptions++ = *LoadOptions;
158  } while (*LoadOptions++);
159 
160  LoaderBlock->LoadOptions = PaToVa(LoaderBlock->LoadOptions);
161 
162  /* ARC devices */
165 
166  /* Convert ARC disk information from freeldr to a correct format */
167  for (i = 0; i < reactos_disk_count; i++)
168  {
169  PARC_DISK_SIGNATURE_EX ArcDiskSig;
170 
171  /* Allocate the ARC structure */
172  ArcDiskSig = FrLdrHeapAlloc(sizeof(ARC_DISK_SIGNATURE_EX), 'giSD');
173  if (!ArcDiskSig)
174  {
175  ERR("Failed to allocate ARC structure! Ignoring remaining ARC disks. (i = %lu, DiskCount = %lu)\n",
177  break;
178  }
179 
180  /* Copy the data over */
182 
183  /* Set the ARC Name pointer */
184  ArcDiskSig->DiskSignature.ArcName = PaToVa(ArcDiskSig->ArcName);
185 
186  /* Insert into the list */
188  &ArcDiskSig->DiskSignature.ListEntry);
189  }
190 
191  /* Convert all lists to Virtual address */
192 
193  /* Convert the ArcDisks list to virtual address */
195  LoaderBlock->ArcDiskInformation = PaToVa(LoaderBlock->ArcDiskInformation);
196 
197  /* Convert configuration entries to VA */
198  ConvertConfigToVA(LoaderBlock->ConfigurationRoot);
199  LoaderBlock->ConfigurationRoot = PaToVa(LoaderBlock->ConfigurationRoot);
200 
201  /* Convert all DTE into virtual addresses */
202  List_PaToVa(&LoaderBlock->LoadOrderListHead);
203 
204  /* This one will be converted right before switching to virtual paging mode */
205  //List_PaToVa(&LoaderBlock->MemoryDescriptorListHead);
206 
207  /* Convert list of boot drivers */
208  List_PaToVa(&LoaderBlock->BootDriverListHead);
209 
210  Extension = LoaderBlock->Extension;
211 
212  /* FIXME! HACK value for docking profile */
213  Extension->Profile.Status = 2;
214 
215  /* Check if FreeLdr detected a ACPI table */
216  if (AcpiPresent)
217  {
218  /* Set the pointer to something for compatibility */
219  Extension->AcpiTable = (PVOID)1;
220  // FIXME: Extension->AcpiTableSize;
221  }
222 
223 #ifdef _M_IX86
224  /* Set headless block pointer */
226  {
227  Extension->HeadlessLoaderBlock = &WinLdrSystemBlock->HeadlessLoaderBlock;
228  RtlCopyMemory(Extension->HeadlessLoaderBlock,
230  sizeof(HEADLESS_LOADER_BLOCK));
231  Extension->HeadlessLoaderBlock = PaToVa(Extension->HeadlessLoaderBlock);
232  }
233 #endif
234  /* Load drivers database */
235  RtlStringCbCopyA(MiscFiles, sizeof(MiscFiles), BootPath);
236  RtlStringCbCatA(MiscFiles, sizeof(MiscFiles), "AppPatch\\drvmain.sdb");
237  Extension->DrvDBImage = PaToVa(WinLdrLoadModule(MiscFiles,
238  &Extension->DrvDBSize,
240 
241  /* Convert the extension block pointer */
242  LoaderBlock->Extension = PaToVa(LoaderBlock->Extension);
243 
244  TRACE("WinLdrInitializePhase1() completed\n");
245 }
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
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:31
HEADLESS_LOADER_BLOCK LoaderRedirectionInformation
Definition: headless.c:30
#define InsertTailList(ListHead, Entry)
CHAR ArcBootDeviceName[MAX_PATH+1]
Definition: winldr.h:56
uint32_t ULONG_PTR
Definition: typedefs.h:65
NTSTRSAFEAPI RtlStringCbCopyA(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCSTR pszSrc)
Definition: ntstrsafe.h:156
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:174
#define TRACE(s)
Definition: solgame.cpp:4
_In_ PWDFDEVICE_INIT _In_ PWDF_REMOVE_LOCK_OPTIONS Options
Definition: wdfdevice.h:3531
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:34
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
#define ERR(fmt,...)
Definition: debug.h:110
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
PVOID WinLdrLoadModule(PCSTR ModuleName, PULONG Size, TYPE_OF_MEMORY MemoryType)
Definition: winldr.c:371
#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
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
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:28
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 121 of file wlregistry.c.

125 {
126  CHAR SearchPath[1024];
127  PCSTR HiveName;
129 
130  if (Setup)
131  {
133  HiveName = "SETUPREG.HIV";
134  }
135  else
136  {
137  // There is a simple logic here: try to load usual hive (system), if it
138  // fails, then give system.alt a try, and finally try a system.sav
139 
140  // FIXME: For now we only try system
142  RtlStringCbCatA(SearchPath, sizeof(SearchPath), "system32\\config\\");
143  HiveName = "SYSTEM";
144  }
145 
146  TRACE("WinLdrInitSystemHive: loading hive %s%s\n", SearchPath, HiveName);
147  Success = WinLdrLoadSystemHive(LoaderBlock, SearchPath, HiveName);
148  if (!Success)
149  {
150  UiMessageBox("Could not load %s hive!", HiveName);
151  return FALSE;
152  }
153 
154  /* Import what was loaded */
155  Success = RegImportBinaryHive(VaToPa(LoaderBlock->RegistryBase), LoaderBlock->RegistryLength);
156  if (!Success)
157  {
158  UiMessageBox("Importing binary hive failed!");
159  return FALSE;
160  }
161 
162  /* Initialize the 'CurrentControlSet' link */
164  {
165  UiMessageBox("Initializing CurrentControlSet link failed!");
166  return FALSE;
167  }
168 
169  return TRUE;
170 }
#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:828
#define TRUE
Definition: types.h:120
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:94
#define SearchPath
Definition: winbase.h:3756
NTSTRSAFEAPI RtlStringCbCopyA(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCSTR pszSrc)
Definition: ntstrsafe.h:156
#define FALSE
Definition: types.h:117
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:52
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 371 of file winldr.c.

374 {
375  ULONG FileId;
376  PVOID PhysicalBase;
378  ULONG FileSize;
381 
382  //CHAR ProgressString[256];
383 
384  /* Inform user we are loading files */
385  //UiDrawBackdrop();
386  //RtlStringCbPrintfA(ProgressString, sizeof(ProgressString), "Loading %s...", FileName);
387  //UiDrawProgressBarCenter(1, 100, ProgressString);
388 
389  TRACE("Loading module %s\n", ModuleName);
390  *Size = 0;
391 
392  /* Open the image file */
393  Status = ArcOpen((PSTR)ModuleName, OpenReadOnly, &FileId);
394  if (Status != ESUCCESS)
395  {
396  /* In case of errors, we just return, without complaining to the user */
397  WARN("Error while opening '%s', Status: %u\n", ModuleName, Status);
398  return NULL;
399  }
400 
401  /* Retrieve its size */
403  if (Status != ESUCCESS)
404  {
405  ArcClose(FileId);
406  return NULL;
407  }
408  FileSize = FileInfo.EndingAddress.LowPart;
409  *Size = FileSize;
410 
411  /* Allocate memory */
412  PhysicalBase = MmAllocateMemoryWithType(FileSize, MemoryType);
413  if (PhysicalBase == NULL)
414  {
415  ERR("Could not allocate memory for '%s'\n", ModuleName);
416  ArcClose(FileId);
417  return NULL;
418  }
419 
420  /* Load the whole file */
421  Status = ArcRead(FileId, PhysicalBase, FileSize, &BytesRead);
422  ArcClose(FileId);
423  if (Status != ESUCCESS)
424  {
425  WARN("Error while reading '%s', Status: %u\n", ModuleName, Status);
426  return NULL;
427  }
428 
429  TRACE("Loaded %s at 0x%x with size 0x%x\n", ModuleName, PhysicalBase, FileSize);
430 
431  return PhysicalBase;
432 }
Definition: arc.h:32
#define WARN(fmt,...)
Definition: debug.h:112
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
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:1274
_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:859
Status
Definition: gdiplustypes.h:24
#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
#define ERR(fmt,...)
Definition: debug.h:110
signed char * PSTR
Definition: retypes.h:7
#define NULL
Definition: types.h:112
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

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 309 of file wlregistry.c.

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

1092 {
1093  PLIST_ENTRY NextBd;
1094  PARC_DISK_SIGNATURE ArcDisk;
1095 
1096  NextBd = LoaderBlock->ArcDiskInformation->DiskSignatureListHead.Flink;
1097 
1098  while (NextBd != &LoaderBlock->ArcDiskInformation->DiskSignatureListHead)
1099  {
1100  ArcDisk = CONTAINING_RECORD(NextBd, ARC_DISK_SIGNATURE, ListEntry);
1101 
1102  TRACE("ArcDisk %s checksum: 0x%X, signature: 0x%X\n",
1103  ArcDisk->ArcName, ArcDisk->CheckSum, ArcDisk->Signature);
1104 
1105  NextBd = ArcDisk->ListEntry.Flink;
1106  }
1107 }
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:121
#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:119
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 1072 of file winldr.c.

1073 {
1074  PLIST_ENTRY NextBd;
1075  PBOOT_DRIVER_LIST_ENTRY BootDriver;
1076 
1077  NextBd = LoaderBlock->BootDriverListHead.Flink;
1078 
1079  while (NextBd != &LoaderBlock->BootDriverListHead)
1080  {
1081  BootDriver = CONTAINING_RECORD(NextBd, BOOT_DRIVER_LIST_ENTRY, Link);
1082 
1083  TRACE("BootDriver %wZ DTE %08X RegPath: %wZ\n", &BootDriver->FilePath,
1084  BootDriver->LdrEntry, &BootDriver->RegistryPath);
1085 
1086  NextBd = BootDriver->Link.Flink;
1087  }
1088 }
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:121
#define TRACE(s)
Definition: solgame.cpp:4
LIST_ENTRY BootDriverListHead
Definition: arc.h:495
Definition: typedefs.h:119
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 1053 of file winldr.c.

1054 {
1055  PLIST_ENTRY NextMd;
1057 
1058  NextMd = LoaderBlock->MemoryDescriptorListHead.Flink;
1059 
1060  while (NextMd != &LoaderBlock->MemoryDescriptorListHead)
1061  {
1063 
1064  TRACE("BP %08X PC %04X MT %d\n", MemoryDescriptor->BasePage,
1065  MemoryDescriptor->PageCount, MemoryDescriptor->MemoryType);
1066 
1067  NextMd = MemoryDescriptor->ListEntry.Flink;
1068  }
1069 }
_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:1331
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:121
#define TRACE(s)
Definition: solgame.cpp:4
Definition: typedefs.h:119
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 172 of file wlregistry.c.

174 {
175  CHAR SearchPath[1024];
176  CHAR AnsiName[256], OemName[256], LangName[256];
178 
179  /* Scan registry and prepare boot drivers list */
180  WinLdrScanRegistry(&LoaderBlock->BootDriverListHead, SystemRoot);
181 
182  /* Get names of NLS files */
183  Success = WinLdrGetNLSNames(AnsiName, OemName, LangName);
184  if (!Success)
185  {
186  UiMessageBox("Getting NLS names from registry failed!");
187  return FALSE;
188  }
189 
190  TRACE("NLS data %s %s %s\n", AnsiName, OemName, LangName);
191 
192  /* Load NLS data */
194  RtlStringCbCatA(SearchPath, sizeof(SearchPath), "system32\\");
195  Success = WinLdrLoadNLSData(LoaderBlock, SearchPath, AnsiName, OemName, LangName);
196  TRACE("NLS data loading %s\n", Success ? "successful" : "failed");
197 
198  /* TODO: Load OEM HAL font */
199  // In HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\CodePage,
200  // REG_SZ value "OEMHAL"
201 
202  return TRUE;
203 }
static VOID WinLdrScanRegistry(IN OUT PLIST_ENTRY BootDriverListHead, IN PCSTR SystemRoot)
Definition: wlregistry.c:489
#define TRUE
Definition: types.h:120
char CHAR
Definition: xmlstorage.h:175
#define SearchPath
Definition: winbase.h:3756
NTSTRSAFEAPI RtlStringCbCopyA(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCSTR pszSrc)
Definition: ntstrsafe.h:156
#define FALSE
Definition: types.h:117
VOID UiMessageBox(PCSTR Format,...)
Definition: ui.c:320
unsigned char BOOLEAN
static BOOLEAN WinLdrGetNLSNames(PSTR AnsiName, PSTR OemName, PSTR LangName)
Definition: wlregistry.c:210
#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:309
IN PDCB IN POEM_STRING OemName
Definition: fatprocs.h:1303
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:1795
#define KSEG0_BASE
Definition: ketypes.h:277
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:1670
#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:442
#define KTSS
Definition: ketypes.h:924
#define DbgPrint
Definition: hal.h:12
ULONG_PTR PcrBasePage
Definition: winldr.c:26
#define KGDTENTRY
Definition: ketypes.h:441
static BOOLEAN WinLdrMapSpecialPages(VOID)
Definition: winldr.c:244
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define FALSE
Definition: types.h:117
VOID UiMessageBox(PCSTR Format,...)
Definition: ui.c:320
I386_LOADER_BLOCK I386
Definition: arc.h:515
ULONG_PTR TssBasePage
Definition: winldr.c:27
void * PVOID
Definition: retypes.h:9
ULONG MachineType
Definition: arc.h:407
union _LOADER_PARAMETER_BLOCK::@3290 u
#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
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define ULONG_PTR
Definition: config.h:101
PVOID GdtIdt
Definition: winldr.c:25
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
ULONG MadCount
Definition: wlmemory.c:58
#define TRUE
Definition: types.h:120
VOID List_PaToVa(_In_ LIST_ENTRY *ListEntry)
BIOS_MEMORY_MAP MemoryMap[32]
Definition: loader.c:11
TYPE_OF_MEMORY MemoryType
Definition: mm.h:43
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
ULONG PFN_NUMBER
Definition: ke.h:9
#define FALSE
Definition: types.h:117
#define MAX_MAD_COUNT
Definition: wlmemory.c:60
VOID UiMessageBox(PCSTR Format,...)
Definition: ui.c:320
PFN_NUMBER BasePage
Definition: mm.h:44
ULONG BiosMemoryMapEntryCount
Definition: meminit.c:34
Status
Definition: gdiplustypes.h:24
#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:1053
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:110
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
#define NULL
Definition: types.h:112
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:45

Referenced by LoadAndBootWindowsCommon().

Variable Documentation

◆ WinLdrSystemBlock

PLOADER_SYSTEM_BLOCK WinLdrSystemBlock

Definition at line 28 of file winldr.c.

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