// Init "phase 1" VOID WinLdrInitializePhase1(PLOADER_PARAMETER_BLOCK LoaderBlock, LPCSTR Options, LPCSTR SystemRoot, LPCSTR BootPath, USHORT VersionToBoot) { /* Examples of correct options and paths */ //CHAR Options[] = "/DEBUGPORT=COM1 /BAUDRATE=115200"; //CHAR Options[] = "/NODEBUG"; //CHAR SystemRoot[] = "\\WINNT\\"; //CHAR ArcBoot[] = "multi(0)disk(0)rdisk(0)partition(1)"; LPSTR LoadOptions, NewLoadOptions; CHAR HalPath[] = "\\"; CHAR ArcBoot[256]; CHAR MiscFiles[256]; ULONG i; ULONG_PTR PathSeparator; PLOADER_PARAMETER_EXTENSION Extension; /* Construct SystemRoot and ArcBoot from SystemPath */ PathSeparator = strstr(BootPath, "\\") - BootPath; strncpy(ArcBoot, BootPath, PathSeparator); ArcBoot[PathSeparator] = 0; TRACE("ArcBoot: %s\n", ArcBoot); TRACE("SystemRoot: %s\n", SystemRoot); TRACE("Options: %s\n", Options); /* Fill Arc BootDevice */ LoaderBlock->ArcBootDeviceName = WinLdrSystemBlock->ArcBootDeviceName; strncpy(LoaderBlock->ArcBootDeviceName, ArcBoot, MAX_PATH); LoaderBlock->ArcBootDeviceName = PaToVa(LoaderBlock->ArcBootDeviceName); /* Fill Arc HalDevice, it matches ArcBoot path */ LoaderBlock->ArcHalDeviceName = WinLdrSystemBlock->ArcBootDeviceName; LoaderBlock->ArcHalDeviceName = PaToVa(LoaderBlock->ArcHalDeviceName); /* Fill SystemRoot */ LoaderBlock->NtBootPathName = WinLdrSystemBlock->NtBootPathName; strncpy(LoaderBlock->NtBootPathName, SystemRoot, MAX_PATH); LoaderBlock->NtBootPathName = PaToVa(LoaderBlock->NtBootPathName); /* Fill NtHalPathName */ LoaderBlock->NtHalPathName = WinLdrSystemBlock->NtHalPathName; strncpy(LoaderBlock->NtHalPathName, HalPath, MAX_PATH); LoaderBlock->NtHalPathName = PaToVa(LoaderBlock->NtHalPathName); /* Fill LoadOptions and strip the '/' commutator symbol in front of each option */ NewLoadOptions = LoadOptions = LoaderBlock->LoadOptions = WinLdrSystemBlock->LoadOptions; strncpy(LoaderBlock->LoadOptions, Options, MAX_OPTIONS_LENGTH); do { while (*LoadOptions == '/') ++LoadOptions; *NewLoadOptions++ = *LoadOptions; } while (*LoadOptions++); LoaderBlock->LoadOptions = PaToVa(LoaderBlock->LoadOptions); /* Arc devices */ LoaderBlock->ArcDiskInformation = &WinLdrSystemBlock->ArcDiskInformation; InitializeListHead(&LoaderBlock->ArcDiskInformation->DiskSignatureListHead); /* Convert ARC disk information from freeldr to a correct format */ for (i = 0; i < reactos_disk_count; i++) { PARC_DISK_SIGNATURE_EX ArcDiskSig; /* Allocate the ARC structure */ ArcDiskSig = HeapAllocate(FrLdrDefaultHeap, sizeof(ARC_DISK_SIGNATURE_EX), 'giSD'); /* Copy the data over */ ArcDiskSig->DiskSignature.Signature = reactos_arc_disk_info[i].Signature; ArcDiskSig->DiskSignature.CheckSum = reactos_arc_disk_info[i].CheckSum; /* Copy the ARC Name */ strncpy(ArcDiskSig->ArcName, reactos_arc_disk_info[i].ArcName, MAX_PATH); ArcDiskSig->DiskSignature.ArcName = PaToVa(ArcDiskSig->ArcName); /* Mark partition table as valid */ ArcDiskSig->DiskSignature.ValidPartitionTable = TRUE; /* Insert into the list */ InsertTailList(&LoaderBlock->ArcDiskInformation->DiskSignatureListHead, &ArcDiskSig->DiskSignature.ListEntry); } /* Convert all list's to Virtual address */ /* Convert the ArcDisks list to virtual address */ List_PaToVa(&LoaderBlock->ArcDiskInformation->DiskSignatureListHead); LoaderBlock->ArcDiskInformation = PaToVa(LoaderBlock->ArcDiskInformation); /* Convert configuration entries to VA */ ConvertConfigToVA(LoaderBlock->ConfigurationRoot); LoaderBlock->ConfigurationRoot = PaToVa(LoaderBlock->ConfigurationRoot); /* Convert all DTE into virtual addresses */ List_PaToVa(&LoaderBlock->LoadOrderListHead); /* this one will be converted right before switching to virtual paging mode */ //List_PaToVa(&LoaderBlock->MemoryDescriptorListHead); /* Convert list of boot drivers */ List_PaToVa(&LoaderBlock->BootDriverListHead); /* Initialize Extension now */ Extension = &WinLdrSystemBlock->Extension; Extension->Size = sizeof(LOADER_PARAMETER_EXTENSION); Extension->MajorVersion = (VersionToBoot & 0xFF00) >> 8; Extension->MinorVersion = VersionToBoot & 0xFF; Extension->Profile.Status = 2; /* Check if ACPI is present */ if (AcpiPresent) { /* See KiRosFrldrLpbToNtLpb for details */ Extension->AcpiTable = (PVOID)1; } #ifdef _M_IX86 /* Set headless block pointer */ if (WinLdrTerminalConnected) { Extension->HeadlessLoaderBlock = &WinLdrSystemBlock->HeadlessLoaderBlock; RtlCopyMemory(Extension->HeadlessLoaderBlock, &LoaderRedirectionInformation, sizeof(HEADLESS_LOADER_BLOCK)); Extension->HeadlessLoaderBlock = PaToVa(Extension->HeadlessLoaderBlock); } #endif /* Load drivers database */ strcpy(MiscFiles, BootPath); strcat(MiscFiles, "AppPatch\\drvmain.sdb"); Extension->DrvDBImage = PaToVa(WinLdrLoadModule(MiscFiles, &Extension->DrvDBSize, LoaderRegistryData)); /* Convert extension and setup block pointers */ LoaderBlock->Extension = PaToVa(Extension); if (LoaderBlock->SetupLdrBlock) LoaderBlock->SetupLdrBlock = PaToVa(LoaderBlock->SetupLdrBlock); TRACE("WinLdrInitializePhase1() completed\n"); }
// This function converts only Child->Child, and calls itself for each Sibling VOID ConvertConfigToVA(PCONFIGURATION_COMPONENT_DATA Start) { PCONFIGURATION_COMPONENT_DATA Child; PCONFIGURATION_COMPONENT_DATA Sibling; TRACE("ConvertConfigToVA(Start 0x%X)\n", Start); Child = Start; while (Child != NULL) { if (Child->ConfigurationData) Child->ConfigurationData = PaToVa(Child->ConfigurationData); if (Child->Child) Child->Child = PaToVa(Child->Child); if (Child->Parent) Child->Parent = PaToVa(Child->Parent); if (Child->Sibling) Child->Sibling = PaToVa(Child->Sibling); if (Child->ComponentEntry.Identifier) Child->ComponentEntry.Identifier = PaToVa(Child->ComponentEntry.Identifier); TRACE("Device 0x%X class %d type %d id '%s', parent %p\n", Child, Child->ComponentEntry.Class, Child->ComponentEntry.Type, VaToPa(Child->ComponentEntry.Identifier), Child->Parent); // Go through siblings list Sibling = VaToPa(Child->Sibling); while (Sibling != NULL) { if (Sibling->ConfigurationData) Sibling->ConfigurationData = PaToVa(Sibling->ConfigurationData); if (Sibling->Child) Sibling->Child = PaToVa(Sibling->Child); if (Sibling->Parent) Sibling->Parent = PaToVa(Sibling->Parent); if (Sibling->Sibling) Sibling->Sibling = PaToVa(Sibling->Sibling); if (Sibling->ComponentEntry.Identifier) Sibling->ComponentEntry.Identifier = PaToVa(Sibling->ComponentEntry.Identifier); TRACE("Device 0x%X class %d type %d id '%s', parent %p\n", Sibling, Sibling->ComponentEntry.Class, Sibling->ComponentEntry.Type, VaToPa(Sibling->ComponentEntry.Identifier), Sibling->Parent); // Recurse into the Child tree if (VaToPa(Sibling->Child) != NULL) ConvertConfigToVA(VaToPa(Sibling->Child)); Sibling = VaToPa(Sibling->Sibling); } // Go to the next child Child = VaToPa(Child->Child); } }