Started BlpMmDestroy(), MmMdDestroy(), MmPaDestroy(), EfiSetWatchdogTimer(), EfiOpenProtocol(), EfiConInExSetState(), and BlDestroyLibrary(). Completed BlpFwInitialize(). Improved InitializeLibrary().
162 lines
2.6 KiB
C
162 lines
2.6 KiB
C
/*++
|
|
|
|
Copyright (c) 2024, Quinn Stephens.
|
|
Provided under the BSD 3-Clause license.
|
|
|
|
Module Name:
|
|
|
|
mm.c
|
|
|
|
Abstract:
|
|
|
|
Provides boot library memory manager routines.
|
|
|
|
--*/
|
|
|
|
#include <ntrtl.h>
|
|
#include "bootlib.h"
|
|
#include "mm.h"
|
|
|
|
ULONG MmTranslationType;
|
|
|
|
NTSTATUS
|
|
BlpMmDestroy (
|
|
IN ULONG Stage
|
|
)
|
|
|
|
/*++
|
|
|
|
Routine Description:
|
|
|
|
Cleans up after any actions performed by the memory manager.
|
|
After calling this, the memory manager can no longer be used.
|
|
|
|
Arguments:
|
|
|
|
Stage - Which stage of cleanup to perform.
|
|
Stage 0: Unknown.
|
|
Stage 1: Destroy all MM modules.
|
|
|
|
Return Value:
|
|
|
|
STATUS_SUCCESS if successful.
|
|
|
|
--*/
|
|
|
|
{
|
|
NTSTATUS Status, ExitStatus;
|
|
|
|
ExitStatus = STATUS_SUCCESS;
|
|
if (Stage == 1) {
|
|
Status = MmMdDestroy();
|
|
if (!NT_SUCCESS(Status)) {
|
|
ExitStatus = Status;
|
|
}
|
|
|
|
Status = MmPaDestroy(0);
|
|
if (!NT_SUCCESS(Status)) {
|
|
ExitStatus = Status;
|
|
}
|
|
|
|
Status = MmPaDestroy(1);
|
|
if (!NT_SUCCESS(Status)) {
|
|
ExitStatus = Status;
|
|
}
|
|
}
|
|
|
|
return ExitStatus;
|
|
}
|
|
|
|
NTSTATUS
|
|
BlpMmInitializeConstraints (
|
|
VOID
|
|
)
|
|
|
|
/*++
|
|
|
|
Routine Description:
|
|
|
|
Initializes physical address constraints.
|
|
|
|
Arguments:
|
|
|
|
None.
|
|
|
|
Return Value:
|
|
|
|
STATUS_SUCCESS if successful.
|
|
|
|
--*/
|
|
|
|
{
|
|
//
|
|
// TODO: Implement this routine.
|
|
//
|
|
|
|
return STATUS_SUCCESS;
|
|
}
|
|
|
|
NTSTATUS
|
|
BlpMmInitialize (
|
|
IN PBOOT_MEMORY_INFO MemoryInfo,
|
|
IN ULONG TranslationType,
|
|
IN PBOOT_LIBRARY_PARAMETERS LibraryParameters
|
|
)
|
|
|
|
/*++
|
|
|
|
Routine Description:
|
|
|
|
Initializes the boot memory manager.
|
|
|
|
Arguments:
|
|
|
|
MemoryInfo - Pointer to the memory info.
|
|
|
|
TranslationType - The current translation type.
|
|
|
|
LibraryParameters - Pointer to the library parameters.
|
|
|
|
Return Value:
|
|
|
|
STATUS_SUCCESS if successful,
|
|
STATUS_INVALID_PARAMETER if TranslationType is invalid,
|
|
Other NTSTATUS value if an error occurs.
|
|
|
|
--*/
|
|
|
|
{
|
|
NTSTATUS Status;
|
|
|
|
//
|
|
// Check TranslationType.
|
|
//
|
|
if (
|
|
TranslationType > TRANSLATION_TYPE_MAX
|
|
|| LibraryParameters->TranslationType > TRANSLATION_TYPE_MAX
|
|
) {
|
|
DebugPrint(L"BlpMmInitialize(): TranslationType is invalid\r\n");
|
|
return STATUS_INVALID_PARAMETER;
|
|
}
|
|
|
|
//
|
|
// Initialize memory descriptor manager.
|
|
//
|
|
MmMdInitialize(0, LibraryParameters);
|
|
|
|
//
|
|
// Initialize page allocator.
|
|
//
|
|
Status = MmPaInitialize(MemoryInfo, LibraryParameters->MinimumPageAllocation);
|
|
if (!NT_SUCCESS(Status)) {
|
|
return Status;
|
|
}
|
|
|
|
MmTranslationType = LibraryParameters->TranslationType;
|
|
|
|
//
|
|
// TODO: Finish this routine.
|
|
//
|
|
|
|
return STATUS_SUCCESS;
|
|
} |