Can Bootloaders use custom UEFI MemoryTypes?

1

I am writing a boot loader for a hobby OS, which targets UEFI. In order to pass some information from the boot loader to the kernel, I make a few memory allocations using BootServices->AllocatePages(). I wanted to create a distinction within the memory map between the traditional EfiLoaderCode, the EfiLoaderData, and this extra information (info about the memory layout, as well as some files loaded via UEFI). Essentially, I'm looking to differentiate these regions within the memory map.

The UEFI 2.8 Specification, in section 7.2, under the MemoryType parameter of AllocatePages(), it states that

MemoryType values in the range 0x80000000..0xFFFFFFFF are reserved for use by UEFI OS loaders that are provided by operating system vendors.

And under the errors this function can return, the only reason it would fail due to the MemoryType would be,

EFI_INVALID_PARAMETER | MemoryType is in the range EfiMaxMemoryType..0x6FFFFFFF. EFI_INVALID_PARAMETER | MemoryType is EfiPersistentMemory.

It is my interpretation that the boot loader/kernel implementer (me in this situation), thus can use their own values within this range, which will be assigned to the allocated pages and these pages will be tagged with this custom type in the memory map acquired from BootServices->GetMemoryMap().

Under this assumption, I allocated memory by calling

err = BootServices->AllocatePages(AllocateAnyPages, 0x80000001, pages, &ret);

and which returns without error. However, when I later attempt to call BootServices->ExitBootServices(), the function never returns and the system hangs. When I call the above allocation with a type parameter of EfiLoaderData instead of 0x80000001, this call does not hang.

Is there some sort of registration process I need to go through to use my own custom MemoryType values, or is my understanding of the specification wrong?

bootloader
uefi
asked on Stack Overflow May 6, 2021 by brenden • edited May 6, 2021 by brenden

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0