VOID NTAPI FldrCreateSystemKey(OUT PCONFIGURATION_COMPONENT_DATA *SystemNode) { PCONFIGURATION_COMPONENT Component; /* Allocate the root */ FldrArcHwTreeRoot = FrLdrHeapAlloc(sizeof(CONFIGURATION_COMPONENT_DATA), TAG_HW_COMPONENT_DATA); if (!FldrArcHwTreeRoot) return; /* Set it up */ Component = &FldrArcHwTreeRoot->ComponentEntry; Component->Class = SystemClass; Component->Type = MaximumType; Component->ConfigurationDataLength = 0; Component->Identifier = 0; Component->IdentifierLength = 0; Component->Flags = 0; Component->Version = 0; Component->Revision = 0; Component->Key = 0; Component->AffinityMask = 0xFFFFFFFF; /* Return the node */ *SystemNode = FldrArcHwTreeRoot; }
static VOID DetectPciIrqRoutingTable(PCONFIGURATION_COMPONENT_DATA BusKey) { PCM_PARTIAL_RESOURCE_LIST PartialResourceList; PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor; PPCI_IRQ_ROUTING_TABLE Table; PCONFIGURATION_COMPONENT_DATA TableKey; ULONG Size; Table = GetPciIrqRoutingTable(); if (Table != NULL) { TRACE("Table size: %u\n", Table->TableSize); /* Set 'Configuration Data' value */ Size = FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors) + 2 * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) + Table->TableSize; PartialResourceList = FrLdrHeapAlloc(Size, TAG_HW_RESOURCE_LIST); if (PartialResourceList == NULL) { ERR("Failed to allocate resource descriptor\n"); return; } /* Initialize resource descriptor */ memset(PartialResourceList, 0, Size); PartialResourceList->Version = 1; PartialResourceList->Revision = 1; PartialResourceList->Count = 2; PartialDescriptor = &PartialResourceList->PartialDescriptors[0]; PartialDescriptor->Type = CmResourceTypeBusNumber; PartialDescriptor->ShareDisposition = CmResourceShareDeviceExclusive; PartialDescriptor->u.BusNumber.Start = 0; PartialDescriptor->u.BusNumber.Length = 1; PartialDescriptor = &PartialResourceList->PartialDescriptors[1]; PartialDescriptor->Type = CmResourceTypeDeviceSpecific; PartialDescriptor->ShareDisposition = CmResourceShareUndetermined; PartialDescriptor->u.DeviceSpecificData.DataSize = Table->TableSize; memcpy(&PartialResourceList->PartialDescriptors[2], Table, Table->TableSize); FldrCreateComponentKey(BusKey, PeripheralClass, RealModeIrqRoutingTable, 0x0, 0x0, 0xFFFFFFFF, "PCI Real-mode IRQ Routing Table", PartialResourceList, Size, &TableKey); } }
PVOID NTAPI FldrpHwHeapAlloc(IN SIZE_T Size) { PVOID Buffer; /* Allocate memory from generic bootloader heap */ Buffer = FrLdrHeapAlloc(Size, 'pHwH'); return Buffer; }
VOID NTAPI FldrCreateComponentKey(IN PCONFIGURATION_COMPONENT_DATA SystemNode, IN CONFIGURATION_CLASS Class, IN CONFIGURATION_TYPE Type, IN IDENTIFIER_FLAG Flags, IN ULONG Key, IN ULONG Affinity, IN PCHAR IdentifierString, IN PCM_PARTIAL_RESOURCE_LIST ResourceList, IN ULONG Size, OUT PCONFIGURATION_COMPONENT_DATA *ComponentKey) { PCONFIGURATION_COMPONENT_DATA ComponentData; PCONFIGURATION_COMPONENT Component; /* Allocate the node for this component */ ComponentData = FrLdrHeapAlloc(sizeof(CONFIGURATION_COMPONENT_DATA), TAG_HW_COMPONENT_DATA); if (!ComponentData) return; /* Now save our parent */ ComponentData->Parent = SystemNode; /* Link us to the parent */ if (SystemNode) FldrLinkToParent(SystemNode, ComponentData); /* Set us up */ Component = &ComponentData->ComponentEntry; Component->Class = Class; Component->Type = Type; Component->Flags = Flags; Component->Key = Key; Component->AffinityMask = Affinity; /* Set identifier */ if (IdentifierString) FldrSetIdentifier(ComponentData, IdentifierString); /* Set configuration data */ if (ResourceList) { ComponentData->ConfigurationData = ResourceList; ComponentData->ComponentEntry.ConfigurationDataLength = Size; } /* Return the child */ *ComponentKey = ComponentData; }
static VOID DetectIsaBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber) { PCM_PARTIAL_RESOURCE_LIST PartialResourceList; PCONFIGURATION_COMPONENT_DATA BusKey; ULONG Size; /* Set 'Configuration Data' value */ Size = sizeof(CM_PARTIAL_RESOURCE_LIST) - sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR); PartialResourceList = FrLdrHeapAlloc(Size, TAG_HW_RESOURCE_LIST); if (PartialResourceList == NULL) { TRACE("Failed to allocate resource descriptor\n"); return; } /* Initialize resource descriptor */ memset(PartialResourceList, 0, Size); PartialResourceList->Version = 1; PartialResourceList->Revision = 1; PartialResourceList->Count = 0; /* Create new bus key */ FldrCreateComponentKey(SystemKey, AdapterClass, MultiFunctionAdapter, 0x0, 0x0, 0xFFFFFFFF, "ISA", PartialResourceList, Size, &BusKey); /* Increment bus number */ (*BusNumber)++; /* Detect ISA/BIOS devices */ DetectBiosDisks(SystemKey, BusKey); /* FIXME: Detect more ISA devices */ }
VOID NTAPI FldrSetIdentifier(IN PCONFIGURATION_COMPONENT_DATA ComponentData, IN PCHAR IdentifierString) { SIZE_T IdentifierLength; PCONFIGURATION_COMPONENT Component = &ComponentData->ComponentEntry; PCHAR Identifier; /* Allocate memory for the identifier */ IdentifierLength = strlen(IdentifierString) + 1; Identifier = FrLdrHeapAlloc(IdentifierLength, TAG_HW_NAME); if (!Identifier) return; /* Copy the identifier */ RtlCopyMemory(Identifier, IdentifierString, IdentifierLength); /* Set component information */ Component->IdentifierLength = (ULONG)IdentifierLength; Component->Identifier = Identifier; }
VOID DetectPciBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber) { PCM_PARTIAL_RESOURCE_LIST PartialResourceList; PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor; PCI_REGISTRY_INFO BusData; PCONFIGURATION_COMPONENT_DATA BiosKey; ULONG Size; PCONFIGURATION_COMPONENT_DATA BusKey; ULONG i; /* Report the PCI BIOS */ if (FindPciBios(&BusData)) { /* Set 'Configuration Data' value */ Size = FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors); PartialResourceList = FrLdrHeapAlloc(Size, TAG_HW_RESOURCE_LIST); if (PartialResourceList == NULL) { ERR("Failed to allocate resource descriptor\n"); return; } /* Initialize resource descriptor */ memset(PartialResourceList, 0, Size); /* Create new bus key */ FldrCreateComponentKey(SystemKey, AdapterClass, MultiFunctionAdapter, 0x0, 0x0, 0xFFFFFFFF, "PCI BIOS", PartialResourceList, Size, &BiosKey); /* Increment bus number */ (*BusNumber)++; DetectPciIrqRoutingTable(BiosKey); /* Report PCI buses */ for (i = 0; i < (ULONG)BusData.NoBuses; i++) { /* Check if this is the first bus */ if (i == 0) { /* Set 'Configuration Data' value */ Size = FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors) + sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) + sizeof(PCI_REGISTRY_INFO); PartialResourceList = FrLdrHeapAlloc(Size, TAG_HW_RESOURCE_LIST); if (!PartialResourceList) { ERR("Failed to allocate resource descriptor\n"); return; } /* Initialize resource descriptor */ memset(PartialResourceList, 0, Size); PartialResourceList->Version = 1; PartialResourceList->Revision = 1; PartialResourceList->Count = 1; PartialDescriptor = &PartialResourceList->PartialDescriptors[0]; PartialDescriptor->Type = CmResourceTypeDeviceSpecific; PartialDescriptor->ShareDisposition = CmResourceShareUndetermined; PartialDescriptor->u.DeviceSpecificData.DataSize = sizeof(PCI_REGISTRY_INFO); memcpy(&PartialResourceList->PartialDescriptors[1], &BusData, sizeof(PCI_REGISTRY_INFO)); } else { /* Set 'Configuration Data' value */ Size = FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors); PartialResourceList = FrLdrHeapAlloc(Size, TAG_HW_RESOURCE_LIST); if (!PartialResourceList) { ERR("Failed to allocate resource descriptor\n"); return; } /* Initialize resource descriptor */ memset(PartialResourceList, 0, Size); } /* Create the bus key */ FldrCreateComponentKey(SystemKey, AdapterClass, MultiFunctionAdapter, 0x0, 0x0, 0xFFFFFFFF, "PCI", PartialResourceList, Size, &BusKey); /* Increment bus number */ (*BusNumber)++; } } }
BOOLEAN WinLdrAllocateDataTableEntry(IN OUT PLIST_ENTRY ModuleListHead, IN PCCH BaseDllName, IN PCCH FullDllName, IN PVOID BasePA, OUT PLDR_DATA_TABLE_ENTRY *NewEntry) { PVOID BaseVA = PaToVa(BasePA); PWSTR Buffer; PLDR_DATA_TABLE_ENTRY DataTableEntry; PIMAGE_NT_HEADERS NtHeaders; USHORT Length; TRACE("WinLdrAllocateDataTableEntry(, '%s', '%s', %p)\n", BaseDllName, FullDllName, BasePA); /* Allocate memory for a data table entry, zero-initialize it */ DataTableEntry = (PLDR_DATA_TABLE_ENTRY)FrLdrHeapAlloc(sizeof(LDR_DATA_TABLE_ENTRY), TAG_WLDR_DTE); if (DataTableEntry == NULL) return FALSE; RtlZeroMemory(DataTableEntry, sizeof(LDR_DATA_TABLE_ENTRY)); /* Get NT headers from the image */ NtHeaders = RtlImageNtHeader(BasePA); /* Initialize corresponding fields of DTE based on NT headers value */ DataTableEntry->DllBase = BaseVA; DataTableEntry->SizeOfImage = NtHeaders->OptionalHeader.SizeOfImage; DataTableEntry->EntryPoint = RVA(BaseVA, NtHeaders->OptionalHeader.AddressOfEntryPoint); DataTableEntry->SectionPointer = 0; DataTableEntry->CheckSum = NtHeaders->OptionalHeader.CheckSum; /* Initialize BaseDllName field (UNICODE_STRING) from the Ansi BaseDllName by simple conversion - copying each character */ Length = (USHORT)(strlen(BaseDllName) * sizeof(WCHAR)); Buffer = (PWSTR)FrLdrHeapAlloc(Length, TAG_WLDR_NAME); if (Buffer == NULL) { FrLdrHeapFree(DataTableEntry, TAG_WLDR_DTE); return FALSE; } RtlZeroMemory(Buffer, Length); DataTableEntry->BaseDllName.Length = Length; DataTableEntry->BaseDllName.MaximumLength = Length; DataTableEntry->BaseDllName.Buffer = PaToVa(Buffer); while (*BaseDllName != 0) { *Buffer++ = *BaseDllName++; } /* Initialize FullDllName field (UNICODE_STRING) from the Ansi FullDllName using the same method */ Length = (USHORT)(strlen(FullDllName) * sizeof(WCHAR)); Buffer = (PWSTR)FrLdrHeapAlloc(Length, TAG_WLDR_NAME); if (Buffer == NULL) { FrLdrHeapFree(DataTableEntry, TAG_WLDR_DTE); return FALSE; } RtlZeroMemory(Buffer, Length); DataTableEntry->FullDllName.Length = Length; DataTableEntry->FullDllName.MaximumLength = Length; DataTableEntry->FullDllName.Buffer = PaToVa(Buffer); while (*FullDllName != 0) { *Buffer++ = *FullDllName++; } /* Initialize what's left - LoadCount which is 1, and set Flags so that we know this entry is processed */ DataTableEntry->Flags = LDRP_ENTRY_PROCESSED; DataTableEntry->LoadCount = 1; /* Insert this DTE to a list in the LPB */ InsertTailList(ModuleListHead, &DataTableEntry->InLoadOrderLinks); TRACE("Inserting DTE %p, name='%.*S' DllBase=%p \n", DataTableEntry, DataTableEntry->BaseDllName.Length / 2, VaToPa(DataTableEntry->BaseDllName.Buffer), DataTableEntry->DllBase); /* Save pointer to a newly allocated and initialized entry */ *NewEntry = DataTableEntry; /* Return success */ return TRUE; }
BOOLEAN WinLdrAddDriverToList(LIST_ENTRY *BootDriverListHead, LPWSTR RegistryPath, LPWSTR ImagePath, LPWSTR ServiceName) { PBOOT_DRIVER_LIST_ENTRY BootDriverEntry; NTSTATUS Status; USHORT PathLength; BootDriverEntry = FrLdrHeapAlloc(sizeof(BOOT_DRIVER_LIST_ENTRY), TAG_WLDR_BDE); if (!BootDriverEntry) return FALSE; // DTE will be filled during actual load of the driver BootDriverEntry->LdrEntry = NULL; // Check - if we have a valid ImagePath, if not - we need to build it // like "System32\\Drivers\\blah.sys" if (ImagePath && (ImagePath[0] != 0)) { // Just copy ImagePath to the corresponding field in the structure PathLength = (USHORT)wcslen(ImagePath) * sizeof(WCHAR) + sizeof(UNICODE_NULL); BootDriverEntry->FilePath.Length = 0; BootDriverEntry->FilePath.MaximumLength = PathLength; BootDriverEntry->FilePath.Buffer = FrLdrHeapAlloc(PathLength, TAG_WLDR_NAME); if (!BootDriverEntry->FilePath.Buffer) { FrLdrHeapFree(BootDriverEntry, TAG_WLDR_BDE); return FALSE; } Status = RtlAppendUnicodeToString(&BootDriverEntry->FilePath, ImagePath); if (!NT_SUCCESS(Status)) { FrLdrHeapFree(BootDriverEntry->FilePath.Buffer, TAG_WLDR_NAME); FrLdrHeapFree(BootDriverEntry, TAG_WLDR_BDE); return FALSE; } } else { // we have to construct ImagePath ourselves PathLength = (USHORT)wcslen(ServiceName)*sizeof(WCHAR) + sizeof(L"system32\\drivers\\.sys"); BootDriverEntry->FilePath.Length = 0; BootDriverEntry->FilePath.MaximumLength = PathLength; BootDriverEntry->FilePath.Buffer = FrLdrHeapAlloc(PathLength, TAG_WLDR_NAME); if (!BootDriverEntry->FilePath.Buffer) { FrLdrHeapFree(BootDriverEntry, TAG_WLDR_NAME); return FALSE; } Status = RtlAppendUnicodeToString(&BootDriverEntry->FilePath, L"system32\\drivers\\"); if (!NT_SUCCESS(Status)) { FrLdrHeapFree(BootDriverEntry->FilePath.Buffer, TAG_WLDR_NAME); FrLdrHeapFree(BootDriverEntry, TAG_WLDR_NAME); return FALSE; } Status = RtlAppendUnicodeToString(&BootDriverEntry->FilePath, ServiceName); if (!NT_SUCCESS(Status)) { FrLdrHeapFree(BootDriverEntry->FilePath.Buffer, TAG_WLDR_NAME); FrLdrHeapFree(BootDriverEntry, TAG_WLDR_NAME); return FALSE; } Status = RtlAppendUnicodeToString(&BootDriverEntry->FilePath, L".sys"); if (!NT_SUCCESS(Status)) { FrLdrHeapFree(BootDriverEntry->FilePath.Buffer, TAG_WLDR_NAME); FrLdrHeapFree(BootDriverEntry, TAG_WLDR_NAME); return FALSE; } } // Add registry path PathLength = (USHORT)(wcslen(RegistryPath) + wcslen(ServiceName))*sizeof(WCHAR) + sizeof(UNICODE_NULL); BootDriverEntry->RegistryPath.Length = 0; BootDriverEntry->RegistryPath.MaximumLength = PathLength; BootDriverEntry->RegistryPath.Buffer = FrLdrHeapAlloc(PathLength, TAG_WLDR_NAME); if (!BootDriverEntry->RegistryPath.Buffer) return FALSE; Status = RtlAppendUnicodeToString(&BootDriverEntry->RegistryPath, RegistryPath); if (!NT_SUCCESS(Status)) return FALSE; Status = RtlAppendUnicodeToString(&BootDriverEntry->RegistryPath, ServiceName); if (!NT_SUCCESS(Status)) return FALSE; // Insert entry at top of the list InsertTailList(BootDriverListHead, &BootDriverEntry->Link); return TRUE; }
static VOID WinLdrScanRegistry(IN OUT PLIST_ENTRY BootDriverListHead, IN LPCSTR DirectoryPath) { LONG rc = 0; HKEY hGroupKey, hOrderKey, hServiceKey, hDriverKey; LPWSTR GroupNameBuffer; WCHAR ServiceName[256]; ULONG OrderList[128]; ULONG BufferSize; ULONG Index; ULONG TagIndex; LPWSTR GroupName; ULONG ValueSize; ULONG ValueType; ULONG StartValue; ULONG TagValue; WCHAR DriverGroup[256]; ULONG DriverGroupSize; CHAR ImagePath[256]; WCHAR TempImagePath[256]; BOOLEAN Success; /* get 'service group order' key */ rc = RegOpenKey(NULL, L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\ServiceGroupOrder", &hGroupKey); if (rc != ERROR_SUCCESS) { TRACE_CH(REACTOS, "Failed to open the 'ServiceGroupOrder' key (rc %d)\n", (int)rc); return; } /* get 'group order list' key */ rc = RegOpenKey(NULL, L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\GroupOrderList", &hOrderKey); if (rc != ERROR_SUCCESS) { TRACE_CH(REACTOS, "Failed to open the 'GroupOrderList' key (rc %d)\n", (int)rc); return; } /* enumerate drivers */ rc = RegOpenKey(NULL, L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Services", &hServiceKey); if (rc != ERROR_SUCCESS) { TRACE_CH(REACTOS, "Failed to open the 'Services' key (rc %d)\n", (int)rc); return; } /* Get the Name Group */ BufferSize = 4096; GroupNameBuffer = FrLdrHeapAlloc(BufferSize, TAG_WLDR_NAME); rc = RegQueryValue(hGroupKey, L"List", NULL, (PUCHAR)GroupNameBuffer, &BufferSize); TRACE_CH(REACTOS, "RegQueryValue(): rc %d\n", (int)rc); if (rc != ERROR_SUCCESS) return; TRACE_CH(REACTOS, "BufferSize: %d \n", (int)BufferSize); TRACE_CH(REACTOS, "GroupNameBuffer: '%S' \n", GroupNameBuffer); /* Loop through each group */ GroupName = GroupNameBuffer; while (*GroupName) { TRACE("Driver group: '%S'\n", GroupName); /* Query the Order */ BufferSize = sizeof(OrderList); rc = RegQueryValue(hOrderKey, GroupName, NULL, (PUCHAR)OrderList, &BufferSize); if (rc != ERROR_SUCCESS) OrderList[0] = 0; /* enumerate all drivers */ for (TagIndex = 1; TagIndex <= OrderList[0]; TagIndex++) { Index = 0; while (TRUE) { /* Get the Driver's Name */ ValueSize = sizeof(ServiceName); rc = RegEnumKey(hServiceKey, Index, ServiceName, &ValueSize, &hDriverKey); TRACE("RegEnumKey(): rc %d\n", (int)rc); /* Make sure it's valid, and check if we're done */ if (rc == ERROR_NO_MORE_ITEMS) break; if (rc != ERROR_SUCCESS) { FrLdrHeapFree(GroupNameBuffer, TAG_WLDR_NAME); return; } //TRACE_CH(REACTOS, "Service %d: '%S'\n", (int)Index, ServiceName); /* Read the Start Value */ ValueSize = sizeof(ULONG); rc = RegQueryValue(hDriverKey, L"Start", &ValueType, (PUCHAR)&StartValue, &ValueSize); if (rc != ERROR_SUCCESS) StartValue = (ULONG)-1; //TRACE_CH(REACTOS, " Start: %x \n", (int)StartValue); /* Read the Tag */ ValueSize = sizeof(ULONG); rc = RegQueryValue(hDriverKey, L"Tag", &ValueType, (PUCHAR)&TagValue, &ValueSize); if (rc != ERROR_SUCCESS) TagValue = (ULONG)-1; //TRACE_CH(REACTOS, " Tag: %x \n", (int)TagValue); /* Read the driver's group */ DriverGroupSize = sizeof(DriverGroup); rc = RegQueryValue(hDriverKey, L"Group", NULL, (PUCHAR)DriverGroup, &DriverGroupSize); //TRACE_CH(REACTOS, " Group: '%S' \n", DriverGroup); /* Make sure it should be started */ if ((StartValue == 0) && (TagValue == OrderList[TagIndex]) && (_wcsicmp(DriverGroup, GroupName) == 0)) { /* Get the Driver's Location */ ValueSize = sizeof(TempImagePath); rc = RegQueryValue(hDriverKey, L"ImagePath", NULL, (PUCHAR)TempImagePath, &ValueSize); /* Write the whole path if it succeeded, else prepare to fail */ if (rc != ERROR_SUCCESS) { TRACE_CH(REACTOS, "ImagePath: not found\n"); TempImagePath[0] = 0; sprintf(ImagePath, "%s\\system32\\drivers\\%S.sys", DirectoryPath, ServiceName); } else if (TempImagePath[0] != L'\\') { sprintf(ImagePath, "%s%S", DirectoryPath, TempImagePath); } else { sprintf(ImagePath, "%S", TempImagePath); TRACE_CH(REACTOS, "ImagePath: '%s'\n", ImagePath); } TRACE("Adding boot driver: '%s'\n", ImagePath); Success = WinLdrAddDriverToList(BootDriverListHead, L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\", TempImagePath, ServiceName); if (!Success) ERR("Failed to add boot driver\n"); } else { //TRACE(" Skipping driver '%S' with Start %d, Tag %d and Group '%S' (Current Tag %d, current group '%S')\n", // ServiceName, StartValue, TagValue, DriverGroup, OrderList[TagIndex], GroupName); } Index++; } } Index = 0; while (TRUE) { /* Get the Driver's Name */ ValueSize = sizeof(ServiceName); rc = RegEnumKey(hServiceKey, Index, ServiceName, &ValueSize, &hDriverKey); //TRACE_CH(REACTOS, "RegEnumKey(): rc %d\n", (int)rc); if (rc == ERROR_NO_MORE_ITEMS) break; if (rc != ERROR_SUCCESS) { FrLdrHeapFree(GroupNameBuffer, TAG_WLDR_NAME); return; } TRACE("Service %d: '%S'\n", (int)Index, ServiceName); /* Read the Start Value */ ValueSize = sizeof(ULONG); rc = RegQueryValue(hDriverKey, L"Start", &ValueType, (PUCHAR)&StartValue, &ValueSize); if (rc != ERROR_SUCCESS) StartValue = (ULONG)-1; //TRACE_CH(REACTOS, " Start: %x \n", (int)StartValue); /* Read the Tag */ ValueSize = sizeof(ULONG); rc = RegQueryValue(hDriverKey, L"Tag", &ValueType, (PUCHAR)&TagValue, &ValueSize); if (rc != ERROR_SUCCESS) TagValue = (ULONG)-1; //TRACE_CH(REACTOS, " Tag: %x \n", (int)TagValue); /* Read the driver's group */ DriverGroupSize = sizeof(DriverGroup); rc = RegQueryValue(hDriverKey, L"Group", NULL, (PUCHAR)DriverGroup, &DriverGroupSize); //TRACE_CH(REACTOS, " Group: '%S' \n", DriverGroup); for (TagIndex = 1; TagIndex <= OrderList[0]; TagIndex++) { if (TagValue == OrderList[TagIndex]) break; } if ((StartValue == 0) && (TagIndex > OrderList[0]) && (_wcsicmp(DriverGroup, GroupName) == 0)) { ValueSize = sizeof(TempImagePath); rc = RegQueryValue(hDriverKey, L"ImagePath", NULL, (PUCHAR)TempImagePath, &ValueSize); if (rc != ERROR_SUCCESS) { TRACE_CH(REACTOS, "ImagePath: not found\n"); TempImagePath[0] = 0; sprintf(ImagePath, "%ssystem32\\drivers\\%S.sys", DirectoryPath, ServiceName); } else if (TempImagePath[0] != L'\\') { sprintf(ImagePath, "%s%S", DirectoryPath, TempImagePath); } else { sprintf(ImagePath, "%S", TempImagePath); TRACE_CH(REACTOS, "ImagePath: '%s'\n", ImagePath); } TRACE(" Adding boot driver: '%s'\n", ImagePath); Success = WinLdrAddDriverToList(BootDriverListHead, L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\", TempImagePath, ServiceName); if (!Success) ERR(" Failed to add boot driver\n"); } else { //TRACE(" Skipping driver '%S' with Start %d, Tag %d and Group '%S' (Current group '%S')\n", // ServiceName, StartValue, TagValue, DriverGroup, GroupName); } Index++; } /* Move to the next group name */ GroupName = GroupName + wcslen(GroupName) + 1; } /* Free allocated memory */ FrLdrHeapFree(GroupNameBuffer, TAG_WLDR_NAME); }
// NOTE: Similar to machpc.c!PcGetHarddiskConfigurationData(), // but without extended geometry support. static PCM_PARTIAL_RESOURCE_LIST XboxGetHarddiskConfigurationData(UCHAR DriveNumber, ULONG* pSize) { PCM_PARTIAL_RESOURCE_LIST PartialResourceList; PCM_DISK_GEOMETRY_DEVICE_DATA DiskGeometry; //EXTENDED_GEOMETRY ExtGeometry; GEOMETRY Geometry; ULONG Size; // // Initialize returned size // *pSize = 0; /* Set 'Configuration Data' value */ Size = sizeof(CM_PARTIAL_RESOURCE_LIST) + sizeof(CM_DISK_GEOMETRY_DEVICE_DATA); PartialResourceList = FrLdrHeapAlloc(Size, TAG_HW_RESOURCE_LIST); if (PartialResourceList == NULL) { ERR("Failed to allocate a full resource descriptor\n"); return NULL; } memset(PartialResourceList, 0, Size); PartialResourceList->Version = 1; PartialResourceList->Revision = 1; PartialResourceList->Count = 1; PartialResourceList->PartialDescriptors[0].Type = CmResourceTypeDeviceSpecific; // PartialResourceList->PartialDescriptors[0].ShareDisposition = // PartialResourceList->PartialDescriptors[0].Flags = PartialResourceList->PartialDescriptors[0].u.DeviceSpecificData.DataSize = sizeof(CM_DISK_GEOMETRY_DEVICE_DATA); /* Get pointer to geometry data */ DiskGeometry = (PVOID)(((ULONG_PTR)PartialResourceList) + sizeof(CM_PARTIAL_RESOURCE_LIST)); /* Get the disk geometry */ //ExtGeometry.Size = sizeof(EXTENDED_GEOMETRY); if (MachDiskGetDriveGeometry(DriveNumber, &Geometry)) { DiskGeometry->BytesPerSector = Geometry.BytesPerSector; DiskGeometry->NumberOfCylinders = Geometry.Cylinders; DiskGeometry->SectorsPerTrack = Geometry.Sectors; DiskGeometry->NumberOfHeads = Geometry.Heads; } else { ERR("Reading disk geometry failed\n"); FrLdrHeapFree(PartialResourceList, TAG_HW_RESOURCE_LIST); return NULL; } TRACE("Disk %x: %u Cylinders %u Heads %u Sectors %u Bytes\n", DriveNumber, DiskGeometry->NumberOfCylinders, DiskGeometry->NumberOfHeads, DiskGeometry->SectorsPerTrack, DiskGeometry->BytesPerSector); // // Return configuration data // *pSize = Size; return PartialResourceList; }
// 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 = FrLdrHeapAlloc(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"); }
VOID DetectAcpiBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber) { PCONFIGURATION_COMPONENT_DATA BiosKey; PCM_PARTIAL_RESOURCE_LIST PartialResourceList; PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor; PRSDP_DESCRIPTOR Rsdp; PACPI_BIOS_DATA AcpiBiosData; ULONG TableSize; Rsdp = FindAcpiBios(); if (Rsdp) { /* Set up the flag in the loader block */ AcpiPresent = TRUE; /* Calculate the table size */ TableSize = PcBiosMapCount * sizeof(BIOS_MEMORY_MAP) + sizeof(ACPI_BIOS_DATA) - sizeof(BIOS_MEMORY_MAP); /* Set 'Configuration Data' value */ PartialResourceList = FrLdrHeapAlloc(sizeof(CM_PARTIAL_RESOURCE_LIST) + TableSize, TAG_HW_RESOURCE_LIST); if (PartialResourceList == NULL) { ERR("Failed to allocate resource descriptor\n"); return; } memset(PartialResourceList, 0, sizeof(CM_PARTIAL_RESOURCE_LIST) + TableSize); PartialResourceList->Version = 0; PartialResourceList->Revision = 0; PartialResourceList->Count = 1; PartialDescriptor = &PartialResourceList->PartialDescriptors[0]; PartialDescriptor->Type = CmResourceTypeDeviceSpecific; PartialDescriptor->ShareDisposition = CmResourceShareUndetermined; PartialDescriptor->u.DeviceSpecificData.DataSize = TableSize; /* Fill the table */ AcpiBiosData = (PACPI_BIOS_DATA)&PartialResourceList->PartialDescriptors[1]; AcpiBiosData->RSDTAddress.LowPart = Rsdp->rsdt_physical_address; AcpiBiosData->Count = PcBiosMapCount; memcpy(AcpiBiosData->MemoryMap, PcBiosMemoryMap, PcBiosMapCount * sizeof(BIOS_MEMORY_MAP)); TRACE("RSDT %p, data size %x\n", Rsdp->rsdt_physical_address, TableSize); /* Create new bus key */ FldrCreateComponentKey(SystemKey, AdapterClass, MultiFunctionAdapter, 0x0, 0x0, 0xFFFFFFFF, "ACPI BIOS", PartialResourceList, sizeof(CM_PARTIAL_RESOURCE_LIST) + TableSize, &BiosKey); /* Increment bus number */ (*BusNumber)++; } }