Compare commits
2 Commits
437b19a0f5
...
75197cc8b5
Author | SHA1 | Date | |
---|---|---|---|
75197cc8b5 | |||
6fc91eb58c |
@ -63,6 +63,11 @@ BlpFwInitialize (
|
|||||||
IN PBOOT_FIRMWARE_DATA FirmwareData
|
IN PBOOT_FIRMWARE_DATA FirmwareData
|
||||||
);
|
);
|
||||||
|
|
||||||
|
NTSTATUS
|
||||||
|
BlpMmInitializeConstraints (
|
||||||
|
VOID
|
||||||
|
);
|
||||||
|
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
BlpMmInitialize (
|
BlpMmInitialize (
|
||||||
IN PBOOT_MEMORY_INFO MemoryInfo,
|
IN PBOOT_MEMORY_INFO MemoryInfo,
|
||||||
|
@ -18,7 +18,8 @@ Abstract:
|
|||||||
|
|
||||||
#include "bootlib.h"
|
#include "bootlib.h"
|
||||||
|
|
||||||
#define MDL_OPERATION_FLAGS_TRUNCATE 0x02
|
#define MDL_OPERATION_FLAGS_TRUNCATE 0x00000002
|
||||||
|
#define MDL_OPERATION_FLAGS_PHYSICAL 0x40000000
|
||||||
|
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
MmFwGetMemoryMap (
|
MmFwGetMemoryMap (
|
||||||
@ -52,6 +53,15 @@ MmMdRemoveDescriptorFromList (
|
|||||||
IN PMEMORY_DESCRIPTOR Descriptor
|
IN PMEMORY_DESCRIPTOR Descriptor
|
||||||
);
|
);
|
||||||
|
|
||||||
|
NTSTATUS
|
||||||
|
MmMdRemoveRegionFromMdlEx (
|
||||||
|
IN PMEMORY_DESCRIPTOR_LIST Mdl,
|
||||||
|
IN ULONGLONG FirstPage,
|
||||||
|
IN ULONGLONG PageCount,
|
||||||
|
IN ULONG Flags,
|
||||||
|
OUT PMEMORY_DESCRIPTOR_LIST Unused
|
||||||
|
);
|
||||||
|
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
MmMdFreeDescriptor (
|
MmMdFreeDescriptor (
|
||||||
IN PMEMORY_DESCRIPTOR Descriptor
|
IN PMEMORY_DESCRIPTOR Descriptor
|
||||||
|
@ -17,6 +17,36 @@ Abstract:
|
|||||||
#include "bootlib.h"
|
#include "bootlib.h"
|
||||||
#include "mm.h"
|
#include "mm.h"
|
||||||
|
|
||||||
|
NTSTATUS
|
||||||
|
BlpMmInitializeConstraints (
|
||||||
|
VOID
|
||||||
|
)
|
||||||
|
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
Initializes physical address constraints.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
None.
|
||||||
|
|
||||||
|
Return Value:
|
||||||
|
|
||||||
|
STATUS_SUCCESS if successful,
|
||||||
|
|
||||||
|
|
||||||
|
--*/
|
||||||
|
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// TODO: Implement this.
|
||||||
|
//
|
||||||
|
|
||||||
|
return STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
BlpMmInitialize (
|
BlpMmInitialize (
|
||||||
IN PBOOT_MEMORY_INFO MemoryInfo,
|
IN PBOOT_MEMORY_INFO MemoryInfo,
|
||||||
|
@ -347,9 +347,9 @@ Routine Description:
|
|||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
|
|
||||||
Mdl - the MDL to remove Descriptor from.
|
Mdl - MDL to remove Descriptor from.
|
||||||
|
|
||||||
Descriptor - the descriptor to remove from Mdl.
|
Descriptor - Descriptor to remove from Mdl.
|
||||||
|
|
||||||
Return Value:
|
Return Value:
|
||||||
|
|
||||||
@ -386,6 +386,67 @@ Return Value:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NTSTATUS
|
||||||
|
MmMdRemoveRegionFromMdlEx (
|
||||||
|
IN PMEMORY_DESCRIPTOR_LIST Mdl,
|
||||||
|
IN ULONGLONG FirstPage,
|
||||||
|
IN ULONGLONG PageCount,
|
||||||
|
IN ULONG Flags,
|
||||||
|
OUT PMEMORY_DESCRIPTOR_LIST Unused
|
||||||
|
)
|
||||||
|
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
Removes a region from a MDL.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
Mdl - MDL to remove the region from.
|
||||||
|
|
||||||
|
FirstPage - The first page in the region.
|
||||||
|
|
||||||
|
PageCount - The number of pages in the region.
|
||||||
|
|
||||||
|
Flags - MDL_OPERATION_FLAGS_*.
|
||||||
|
|
||||||
|
Unused - Unused.
|
||||||
|
|
||||||
|
Return Value:
|
||||||
|
|
||||||
|
None.
|
||||||
|
|
||||||
|
--*/
|
||||||
|
|
||||||
|
{
|
||||||
|
ULONGLONG RemoveEnd, DescriptorEnd;
|
||||||
|
PLIST_ENTRY Entry;
|
||||||
|
PMEMORY_DESCRIPTOR Descriptor;
|
||||||
|
MEMORY_DESCRIPTOR RemovedDescriptor;
|
||||||
|
|
||||||
|
(VOID)Flags;
|
||||||
|
(VOID)Unused;
|
||||||
|
|
||||||
|
RemoveEnd = FirstPage + PageCount;
|
||||||
|
Entry = Mdl->Head->Flink;
|
||||||
|
while (Entry != Mdl->Head) {
|
||||||
|
Descriptor = (PMEMORY_DESCRIPTOR)Entry;
|
||||||
|
DescriptorEnd = Descriptor->FirstPage + Descriptor->PageCount;
|
||||||
|
|
||||||
|
RtlCopyMemory(&RemovedDescriptor, Descriptor, sizeof(MEMORY_DESCRIPTOR));
|
||||||
|
|
||||||
|
// if (FirstPage <= Descriptor->FirstPage && Descriptor->FirstPage < RemoveEnd) {
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// TODO: Finish this function.
|
||||||
|
//
|
||||||
|
|
||||||
|
return STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
MmMdFreeDescriptor (
|
MmMdFreeDescriptor (
|
||||||
IN PMEMORY_DESCRIPTOR Descriptor
|
IN PMEMORY_DESCRIPTOR Descriptor
|
||||||
|
@ -79,44 +79,78 @@ Arguments:
|
|||||||
Return Value:
|
Return Value:
|
||||||
|
|
||||||
STATUS_SUCCESS if successful,
|
STATUS_SUCCESS if successful,
|
||||||
|
STATUS_INVALID_PARAMETER if regions in MemoryInfo could not be removed.
|
||||||
|
STATUS_NO_MEMORY if a new descriptor cannot be allocated.
|
||||||
|
|
||||||
--*/
|
--*/
|
||||||
|
|
||||||
{
|
{
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
|
PMEMORY_DESCRIPTOR Descriptor, NewDescriptor;
|
||||||
|
|
||||||
(VOID)MemoryInfo;
|
(VOID)MemoryInfo;
|
||||||
|
|
||||||
DebugPrint(L"Initializing page allocator...\r\n");
|
DebugPrint(L"Initializing page allocator...\r\n");
|
||||||
|
|
||||||
//
|
|
||||||
// Initialize page allocator settings.
|
|
||||||
//
|
|
||||||
PapMinimumAllocationCount = MinimumAllocation;
|
PapMinimumAllocationCount = MinimumAllocation;
|
||||||
PapMinimumPhysicalPage = 1;
|
PapMinimumPhysicalPage = 1;
|
||||||
PapMaximumPhysicalPage = MAXULONGLONG >> PAGE_SHIFT;
|
PapMaximumPhysicalPage = MAXULONGLONG >> PAGE_SHIFT;
|
||||||
DebugPrintf(L"Maximum physical page: %x %x\r\n", HIDWORD(PapMaximumPhysicalPage), LODWORD(PapMaximumPhysicalPage));
|
|
||||||
|
|
||||||
//
|
|
||||||
// Initialize MDLs.
|
|
||||||
//
|
|
||||||
InitializeMdl(&MmMdlFwAllocationTracker);
|
InitializeMdl(&MmMdlFwAllocationTracker);
|
||||||
InitializeMdl(&MmMdlBadMemory);
|
InitializeMdl(&MmMdlBadMemory);
|
||||||
InitializeMdl(&MmMdlTruncatedMemory);
|
InitializeMdl(&MmMdlTruncatedMemory);
|
||||||
InitializeMdl(&MmMdlPersistentMemory);
|
InitializeMdl(&MmMdlPersistentMemory);
|
||||||
InitializeMdl(&MmMdlReservedAllocated);;
|
InitializeMdl(&MmMdlReservedAllocated);
|
||||||
InitializeMdl(&MmMdlMappedAllocated);
|
InitializeMdl(&MmMdlMappedAllocated);
|
||||||
InitializeMdl(&MmMdlMappedUnallocated);
|
InitializeMdl(&MmMdlMappedUnallocated);
|
||||||
InitializeMdl(&MmMdlUnmappedAllocated);
|
InitializeMdl(&MmMdlUnmappedAllocated);
|
||||||
InitializeMdl(&MmMdlUnmappedUnallocated);
|
InitializeMdl(&MmMdlUnmappedUnallocated);
|
||||||
|
|
||||||
//
|
|
||||||
// Get the firmware memory map.
|
|
||||||
//
|
|
||||||
Status = MmFwGetMemoryMap(&MmMdlUnmappedUnallocated, 0x03);
|
Status = MmFwGetMemoryMap(&MmMdlUnmappedUnallocated, 0x03);
|
||||||
if (!NT_SUCCESS(Status)) {
|
if (!NT_SUCCESS(Status)) {
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Remove regions described in MemoryInfo from the
|
||||||
|
// MDL the memory manager will use for allocation.
|
||||||
|
//
|
||||||
|
Descriptor = (PMEMORY_DESCRIPTOR)((PUCHAR)MemoryInfo + MemoryInfo->MdlOffset);
|
||||||
|
for (ULONG DescriptorCount = MemoryInfo->DescriptorCount; DescriptorCount > 0; DescriptorCount--) {
|
||||||
|
//
|
||||||
|
// Remove from the usable MDL.
|
||||||
|
//
|
||||||
|
Status = MmMdRemoveRegionFromMdlEx(&MmMdlUnmappedUnallocated, Descriptor->FirstPage, Descriptor->PageCount, MDL_OPERATION_FLAGS_PHYSICAL, NULL);
|
||||||
|
if (!NT_SUCCESS(Status)) {
|
||||||
|
return STATUS_INVALID_PARAMETER;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// ... and add to the reserved MDL.
|
||||||
|
//
|
||||||
|
NewDescriptor = MmMdInitDescriptor(
|
||||||
|
Descriptor->FirstPage,
|
||||||
|
Descriptor->MappedFirstPage,
|
||||||
|
Descriptor->PageCount,
|
||||||
|
Descriptor->Attributes,
|
||||||
|
Descriptor->Type
|
||||||
|
);
|
||||||
|
if (NewDescriptor == NULL) {
|
||||||
|
return STATUS_NO_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
Status = MmMdAddDescriptorToList(&MmMdlReservedAllocated, NewDescriptor, 0x00);
|
||||||
|
if (!NT_SUCCESS(Status)) {
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
Descriptor = (PMEMORY_DESCRIPTOR)((PUCHAR)Descriptor + MemoryInfo->DescriptorSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
Status = BlpMmInitializeConstraints();
|
||||||
|
if (!NT_SUCCESS(Status)) {
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ Return Value:
|
|||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
ConsolePrint(L"-------- Alcyone EFI Boot Manager --------\r\n");
|
ConsolePrint(L"> Alcyone EFI Boot Manager\r\n");
|
||||||
ConsolePrintf(L"Image base: %x %x\r\nImage size: %x\r\n", HIDWORD((ULONG_PTR)InputParameters->ImageBase), LODWORD((ULONG_PTR)InputParameters->ImageBase), InputParameters->ImageSize);
|
ConsolePrintf(L"Image base: %x %x\r\nImage size: %x\r\n", HIDWORD((ULONG_PTR)InputParameters->ImageBase), LODWORD((ULONG_PTR)InputParameters->ImageBase), InputParameters->ImageSize);
|
||||||
|
|
||||||
DebugPrint(L"Initializing boot library...\r\n");
|
DebugPrint(L"Initializing boot library...\r\n");
|
||||||
|
@ -25,6 +25,7 @@ Abstract:
|
|||||||
#define STATUS_UNSUCCESSFUL ((NTSTATUS) 0xC0000001L)
|
#define STATUS_UNSUCCESSFUL ((NTSTATUS) 0xC0000001L)
|
||||||
#define STATUS_NOT_IMPLEMENTED ((NTSTATUS) 0xC0000002L)
|
#define STATUS_NOT_IMPLEMENTED ((NTSTATUS) 0xC0000002L)
|
||||||
#define STATUS_INVALID_PARAMETER ((NTSTATUS) 0xC000000DL)
|
#define STATUS_INVALID_PARAMETER ((NTSTATUS) 0xC000000DL)
|
||||||
|
#define STATUS_NO_MEMORY ((NTSTATUS) 0xC0000017L)
|
||||||
#define STATUS_ACCESS_DENIED ((NTSTATUS) 0xC0000022L)
|
#define STATUS_ACCESS_DENIED ((NTSTATUS) 0xC0000022L)
|
||||||
#define STATUS_BUFFER_TOO_SMALL ((NTSTATUS) 0xC0000023L)
|
#define STATUS_BUFFER_TOO_SMALL ((NTSTATUS) 0xC0000023L)
|
||||||
#define STATUS_DISK_CORRUPT_ERROR ((NTSTATUS) 0xC0000032L)
|
#define STATUS_DISK_CORRUPT_ERROR ((NTSTATUS) 0xC0000032L)
|
||||||
|
Loading…
Reference in New Issue
Block a user