1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-30 21:28:11 +00:00
serenity/Kernel/PhysicalAddress.h
Tom ad5d9d648b Kernel: Use PAE to allow accessing all physical memory beyond 4GB
We already use PAE for the NX bit, but this changes the PhysicalAddress
structure to be able to hold 64 bit physical addresses. This allows us
to use all the available physical memory.
2021-07-08 11:43:34 +02:00

58 lines
2.2 KiB
C++

/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Format.h>
#include <AK/Types.h>
typedef u64 PhysicalPtr;
typedef u64 PhysicalSize;
class PhysicalAddress {
public:
ALWAYS_INLINE static PhysicalPtr physical_page_base(PhysicalPtr page_address) { return page_address & ~(PhysicalPtr)0xfff; }
PhysicalAddress() = default;
explicit PhysicalAddress(PhysicalPtr address)
: m_address(address)
{
}
[[nodiscard]] PhysicalAddress offset(PhysicalPtr o) const { return PhysicalAddress(m_address + o); }
[[nodiscard]] PhysicalPtr get() const { return m_address; }
void set(PhysicalPtr address) { m_address = address; }
void mask(PhysicalPtr m) { m_address &= m; }
[[nodiscard]] bool is_null() const { return m_address == 0; }
[[nodiscard]] u8* as_ptr() { return reinterpret_cast<u8*>(m_address); }
[[nodiscard]] const u8* as_ptr() const { return reinterpret_cast<const u8*>(m_address); }
[[nodiscard]] PhysicalAddress page_base() const { return PhysicalAddress(physical_page_base(m_address)); }
[[nodiscard]] PhysicalPtr offset_in_page() const { return PhysicalAddress(m_address & 0xfff).get(); }
bool operator==(const PhysicalAddress& other) const { return m_address == other.m_address; }
bool operator!=(const PhysicalAddress& other) const { return m_address != other.m_address; }
bool operator>(const PhysicalAddress& other) const { return m_address > other.m_address; }
bool operator>=(const PhysicalAddress& other) const { return m_address >= other.m_address; }
bool operator<(const PhysicalAddress& other) const { return m_address < other.m_address; }
bool operator<=(const PhysicalAddress& other) const { return m_address <= other.m_address; }
private:
PhysicalPtr m_address { 0 };
};
template<>
struct AK::Formatter<PhysicalAddress> : AK::Formatter<FormatString> {
void format(FormatBuilder& builder, PhysicalAddress value)
{
if constexpr (sizeof(PhysicalPtr) == sizeof(u64))
return AK::Formatter<FormatString>::format(builder, "P{:016x}", value.get());
else
return AK::Formatter<FormatString>::format(builder, "P{}", value.as_ptr());
}
};