67 lines
1.9 KiB
C++
67 lines
1.9 KiB
C++
|
|
#pragma once
|
|
|
|
#if !defined(BOOT_HPP_INCLUDED)
|
|
#define BOOT_HPP_INCLUDED 1
|
|
|
|
#include <efi.h>
|
|
|
|
class EfiMemoryMapIterator
|
|
{
|
|
private:
|
|
EFI_MEMORY_DESCRIPTOR* mDescriptor;
|
|
UINTN mDescriptorSize;
|
|
public:
|
|
EfiMemoryMapIterator(EFI_MEMORY_DESCRIPTOR* descriptor, UINTN descriptorSize) noexcept : mDescriptor(descriptor), mDescriptorSize(descriptorSize) {}
|
|
EfiMemoryMapIterator(const EfiMemoryMapIterator&) noexcept = default;
|
|
|
|
EfiMemoryMapIterator& operator=(const EfiMemoryMapIterator&) noexcept = default;
|
|
|
|
bool operator==(const EfiMemoryMapIterator& other) const noexcept
|
|
{
|
|
return mDescriptor == other.mDescriptor && mDescriptorSize == other.mDescriptorSize;
|
|
}
|
|
bool operator!=(const EfiMemoryMapIterator& other) const noexcept
|
|
{
|
|
return !(*this == other);
|
|
}
|
|
|
|
EFI_MEMORY_DESCRIPTOR& operator*() const noexcept { return *mDescriptor; }
|
|
EfiMemoryMapIterator& operator++() noexcept
|
|
{
|
|
mDescriptor = reinterpret_cast<EFI_MEMORY_DESCRIPTOR*>(reinterpret_cast<UINT64>(mDescriptor) + mDescriptorSize);
|
|
return *this;
|
|
}
|
|
EfiMemoryMapIterator operator++(int) noexcept
|
|
{
|
|
EfiMemoryMapIterator copy(*this);
|
|
++(*this);
|
|
return copy;
|
|
}
|
|
};
|
|
|
|
struct EfiMemoryMap
|
|
{
|
|
UINTN mapSize = 0;
|
|
EFI_MEMORY_DESCRIPTOR* map = nullptr;
|
|
UINTN mapKey = 0;
|
|
UINTN descriptorSize = 0;
|
|
UINT32 descriptorVersion = 0;
|
|
|
|
EfiMemoryMapIterator begin() const noexcept
|
|
{
|
|
return EfiMemoryMapIterator(map, descriptorSize);
|
|
}
|
|
EfiMemoryMapIterator end() const noexcept
|
|
{
|
|
// just in case
|
|
const UINTN totalMapSize = (mapSize / descriptorSize) * descriptorSize;
|
|
return EfiMemoryMapIterator(
|
|
reinterpret_cast<EFI_MEMORY_DESCRIPTOR*>(reinterpret_cast<UINT64>(map) + totalMapSize),
|
|
descriptorSize
|
|
);
|
|
}
|
|
};
|
|
|
|
#endif // BOOT_HPP_INCLUDED
|