Compare commits
2 Commits
75197cc8b5
...
4c32340803
Author | SHA1 | Date | |
---|---|---|---|
4c32340803 | |||
a32d72be1e |
@ -53,6 +53,13 @@ MmMdRemoveDescriptorFromList (
|
|||||||
IN PMEMORY_DESCRIPTOR Descriptor
|
IN PMEMORY_DESCRIPTOR Descriptor
|
||||||
);
|
);
|
||||||
|
|
||||||
|
PMEMORY_DESCRIPTOR
|
||||||
|
MmMdFindDescriptorFromMdl (
|
||||||
|
IN PMEMORY_DESCRIPTOR_LIST Mdl,
|
||||||
|
IN ULONGLONG Page,
|
||||||
|
IN ULONG Flags
|
||||||
|
);
|
||||||
|
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
MmMdRemoveRegionFromMdlEx (
|
MmMdRemoveRegionFromMdlEx (
|
||||||
IN PMEMORY_DESCRIPTOR_LIST Mdl,
|
IN PMEMORY_DESCRIPTOR_LIST Mdl,
|
||||||
|
@ -206,6 +206,9 @@ Return Value:
|
|||||||
}
|
}
|
||||||
BootDevice->Size = sizeof(BOOT_DEVICE);
|
BootDevice->Size = sizeof(BOOT_DEVICE);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Memory map devices are treated as ramdisks.
|
||||||
|
//
|
||||||
if (DevicePathType(EfiDevicePath) == HARDWARE_DEVICE_PATH && DevicePathSubType(EfiDevicePath) == HW_MEMMAP_DP) {
|
if (DevicePathType(EfiDevicePath) == HARDWARE_DEVICE_PATH && DevicePathSubType(EfiDevicePath) == HW_MEMMAP_DP) {
|
||||||
MemmapNode = (MEMMAP_DEVICE_PATH *)EfiDevicePath;
|
MemmapNode = (MEMMAP_DEVICE_PATH *)EfiDevicePath;
|
||||||
BlockDevice = &BootDevice->Block;
|
BlockDevice = &BootDevice->Block;
|
||||||
@ -218,7 +221,7 @@ Return Value:
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// TODO: Only media devices and ramdisks are currently supported.
|
// TODO: Support more devices than just HDD/CD-ROM and ramdisks.
|
||||||
//
|
//
|
||||||
DeviceNode = EfiInitpGetDeviceNode(EfiDevicePath);
|
DeviceNode = EfiInitpGetDeviceNode(EfiDevicePath);
|
||||||
if (DevicePathType(DeviceNode) != MEDIA_DEVICE_PATH) {
|
if (DevicePathType(DeviceNode) != MEDIA_DEVICE_PATH) {
|
||||||
@ -547,7 +550,7 @@ Return Value:
|
|||||||
|
|
||||||
//
|
//
|
||||||
// Convert the EFI file path into a boot file path option.
|
// Convert the EFI file path into a boot file path option.
|
||||||
// TODO: UDP/PXE are not supported.
|
// TODO: Support UDP/PXE boot.
|
||||||
//
|
//
|
||||||
PrevOption = Option;
|
PrevOption = Option;
|
||||||
Option = (PBOOT_APPLICATION_OPTION)((PUCHAR)&Entry->Options + OptionsSize);
|
Option = (PBOOT_APPLICATION_OPTION)((PUCHAR)&Entry->Options + OptionsSize);
|
||||||
@ -561,7 +564,7 @@ Return Value:
|
|||||||
BufferRemaining -= Size;
|
BufferRemaining -= Size;
|
||||||
|
|
||||||
//
|
//
|
||||||
// TODO: Additional options in LoadOptions are not parsed.
|
// TODO: Parse additional options from LoadOptions.
|
||||||
//
|
//
|
||||||
PrevOption = Option;
|
PrevOption = Option;
|
||||||
Option = (PBOOT_APPLICATION_OPTION)((PUCHAR)&Entry->Options + OptionsSize);
|
Option = (PBOOT_APPLICATION_OPTION)((PUCHAR)&Entry->Options + OptionsSize);
|
||||||
|
@ -302,17 +302,18 @@ Return Value:
|
|||||||
|
|
||||||
{
|
{
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
UINTN EfiMapSize;
|
|
||||||
UINTN EfiMapKey;
|
|
||||||
UINTN EfiDescriptorSize;
|
|
||||||
UINT32 EfiDescriptorVersion;
|
|
||||||
UINTN PageCount, EfiPageCount;
|
|
||||||
EFI_PHYSICAL_ADDRESS EfiBuffer;
|
EFI_PHYSICAL_ADDRESS EfiBuffer;
|
||||||
EFI_MEMORY_DESCRIPTOR *EfiMap;
|
EFI_MEMORY_DESCRIPTOR *EfiMap;
|
||||||
BOOLEAN IsRamdisk;
|
UINTN EfiMapKey;
|
||||||
MEMORY_TYPE MemoryType;
|
UINTN EfiMapSize, EfiDescriptorSize;
|
||||||
|
UINT32 EfiDescriptorVersion;
|
||||||
UINT64 EfiStartPage, EfiEndPage;
|
UINT64 EfiStartPage, EfiEndPage;
|
||||||
|
UINTN EfiPageCount;
|
||||||
|
ULONGLONG NtStartPage;
|
||||||
|
ULONG NtPageCount;
|
||||||
|
BOOLEAN IsRamdisk;
|
||||||
UINT64 EfiRamdiskStartPage, EfiRamdiskEndPage;
|
UINT64 EfiRamdiskStartPage, EfiRamdiskEndPage;
|
||||||
|
MEMORY_TYPE MemoryType;
|
||||||
PMEMORY_DESCRIPTOR NtDescriptor;
|
PMEMORY_DESCRIPTOR NtDescriptor;
|
||||||
|
|
||||||
(VOID)Flags;
|
(VOID)Flags;
|
||||||
@ -347,8 +348,8 @@ Return Value:
|
|||||||
}
|
}
|
||||||
|
|
||||||
EfiMapSize += 4 * EfiDescriptorSize;
|
EfiMapSize += 4 * EfiDescriptorSize;
|
||||||
PageCount = (ALIGN_UP(EfiMapSize, PAGE_SIZE) >> PAGE_SHIFT) + 1;
|
NtPageCount = (ALIGN_UP(EfiMapSize, PAGE_SIZE) >> PAGE_SHIFT) + 1;
|
||||||
EfiPageCount = EFI_PAGE(PageCount);
|
EfiPageCount = EFI_PAGE(NtPageCount);
|
||||||
Status = EfiAllocatePages(AllocateAnyPages, EfiLoaderData, EfiPageCount, &EfiBuffer);
|
Status = EfiAllocatePages(AllocateAnyPages, EfiLoaderData, EfiPageCount, &EfiBuffer);
|
||||||
if (!NT_SUCCESS(Status)) {
|
if (!NT_SUCCESS(Status)) {
|
||||||
DebugPrint(L"MmFwGetMemoryMap(): EfiAllocatePages() failed\r\n");
|
DebugPrint(L"MmFwGetMemoryMap(): EfiAllocatePages() failed\r\n");
|
||||||
@ -572,9 +573,55 @@ Return Value:
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// TODO: Account for possible MDL changes due to EfiFreePages(EfiBuffer).
|
// The following code is to free the buffer and
|
||||||
|
// also mark the freed memory as free in the MDL.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
Status = EfiFreePages(EfiBuffer, EfiPageCount);
|
||||||
|
if (!NT_SUCCESS(Status)) {
|
||||||
|
Status = STATUS_SUCCESS;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
EfiBuffer = 0;
|
||||||
|
|
||||||
|
EfiStartPage = EfiBuffer >> EFI_PAGE_SHIFT;
|
||||||
|
EfiEndPage = ALIGN_UP(EfiStartPage + EfiPageCount, EFI_PAGE(1));
|
||||||
|
NtStartPage = NT_PAGE(EfiStartPage);
|
||||||
|
NtPageCount = NT_PAGE(EfiEndPage) - NtStartPage;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Find the current descriptor.
|
||||||
|
//
|
||||||
|
NtDescriptor = MmMdFindDescriptorFromMdl(Mdl, NtStartPage, MDL_OPERATION_FLAGS_PHYSICAL);
|
||||||
|
if (NtDescriptor == NULL) {
|
||||||
|
Status = STATUS_UNSUCCESSFUL;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Create a new free descriptor, with the same
|
||||||
|
// attributes as the current one.
|
||||||
|
//
|
||||||
|
NtDescriptor = MmMdInitDescriptor(NtStartPage, 0, NtPageCount, NtDescriptor->Attributes, MEMORY_TYPE_FREE);
|
||||||
|
if (NtDescriptor == NULL) {
|
||||||
|
Status = STATUS_INSUFFICIENT_RESOURCES;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Remove the current descriptor.
|
||||||
|
//
|
||||||
|
Status = MmMdRemoveRegionFromMdlEx(Mdl, NtStartPage, NtPageCount, MDL_OPERATION_FLAGS_PHYSICAL, 0);
|
||||||
|
if (!NT_SUCCESS(Status)) {
|
||||||
|
MmMdFreeDescriptor(NtDescriptor);
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Add the new descriptor to the MDL.
|
||||||
|
//
|
||||||
|
Status = MmMdAddDescriptorToList(Mdl, NtDescriptor, 0x01);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
if (EfiBuffer) {
|
if (EfiBuffer) {
|
||||||
EfiFreePages(EfiBuffer, EfiPageCount);
|
EfiFreePages(EfiBuffer, EfiPageCount);
|
||||||
|
@ -41,7 +41,7 @@ Return Value:
|
|||||||
|
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// TODO: Implement this.
|
// TODO: Implement this routine.
|
||||||
//
|
//
|
||||||
|
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
|
@ -83,7 +83,7 @@ Return Value:
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// TODO: Incomplete.
|
// TODO: Implement the rest of this routine.
|
||||||
//
|
//
|
||||||
ConsolePrint(L"MmMdpHasPrecedence() is incomplete\r\n");
|
ConsolePrint(L"MmMdpHasPrecedence() is incomplete\r\n");
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -386,6 +386,45 @@ Return Value:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PMEMORY_DESCRIPTOR
|
||||||
|
MmMdFindDescriptorFromMdl (
|
||||||
|
IN PMEMORY_DESCRIPTOR_LIST Mdl,
|
||||||
|
IN ULONGLONG Page,
|
||||||
|
IN ULONG Flags
|
||||||
|
)
|
||||||
|
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
Searches an MDL for the descriptor containing a page.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
Mdl - The MDL to search.
|
||||||
|
|
||||||
|
Page - The page to search for.
|
||||||
|
|
||||||
|
Flags - MDL_OPERATION_FLAGS_*
|
||||||
|
MDL_OPERATION_FLAGS_PHYSICAL if Page is physical.
|
||||||
|
MDL_OPERATION_FLAGS_VIRTUAL if Page is virtual.
|
||||||
|
|
||||||
|
Return Value:
|
||||||
|
|
||||||
|
Pointer to the descriptor if successful.
|
||||||
|
NULL if an error occurs.
|
||||||
|
|
||||||
|
--*/
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// TODO: Implement this routine.
|
||||||
|
//
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
MmMdRemoveRegionFromMdlEx (
|
MmMdRemoveRegionFromMdlEx (
|
||||||
IN PMEMORY_DESCRIPTOR_LIST Mdl,
|
IN PMEMORY_DESCRIPTOR_LIST Mdl,
|
||||||
@ -441,7 +480,7 @@ Return Value:
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// TODO: Finish this function.
|
// TODO: Implement the rest of this routine.
|
||||||
//
|
//
|
||||||
|
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
@ -490,7 +529,7 @@ Return Value:
|
|||||||
|
|
||||||
//
|
//
|
||||||
// Free the descriptor from the heap.
|
// Free the descriptor from the heap.
|
||||||
// TODO: Use BlMmFreeHeap()
|
// TODO: Use BlMmFreeHeap().
|
||||||
//
|
//
|
||||||
ConsolePrint(L"MmMdFreeDescriptor(): need BlMmFreeHeap() to free descriptor\r\n");
|
ConsolePrint(L"MmMdFreeDescriptor(): need BlMmFreeHeap() to free descriptor\r\n");
|
||||||
return STATUS_NOT_IMPLEMENTED;
|
return STATUS_NOT_IMPLEMENTED;
|
||||||
@ -565,6 +604,7 @@ Return Value:
|
|||||||
PMEMORY_DESCRIPTOR Descriptor;
|
PMEMORY_DESCRIPTOR Descriptor;
|
||||||
|
|
||||||
if (MmGlobalMemoryDescriptorsUsed >= MmGlobalMemoryDescriptorCount) {
|
if (MmGlobalMemoryDescriptorsUsed >= MmGlobalMemoryDescriptorCount) {
|
||||||
|
DebugPrint(L"MmMdInitDescriptor(): No free descriptors available\r\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user