2019-04-06 15:29:29 +03:00
|
|
|
#pragma once
|
|
|
|
|
2019-09-15 21:47:49 +03:00
|
|
|
#include <AK/LogStream.h>
|
2019-07-03 22:17:35 +03:00
|
|
|
#include <AK/Types.h>
|
|
|
|
|
2019-04-06 15:29:29 +03:00
|
|
|
class PhysicalAddress {
|
|
|
|
public:
|
2019-05-28 12:53:16 +03:00
|
|
|
PhysicalAddress() {}
|
2019-07-03 22:17:35 +03:00
|
|
|
explicit PhysicalAddress(u32 address)
|
2019-05-28 12:53:16 +03:00
|
|
|
: m_address(address)
|
|
|
|
{
|
|
|
|
}
|
2019-04-06 15:29:29 +03:00
|
|
|
|
2019-07-03 22:17:35 +03:00
|
|
|
PhysicalAddress offset(u32 o) const { return PhysicalAddress(m_address + o); }
|
|
|
|
u32 get() const { return m_address; }
|
|
|
|
void set(u32 address) { m_address = address; }
|
|
|
|
void mask(u32 m) { m_address &= m; }
|
2019-04-06 15:29:29 +03:00
|
|
|
|
|
|
|
bool is_null() const { return m_address == 0; }
|
|
|
|
|
2019-07-03 22:17:35 +03:00
|
|
|
u8* as_ptr() { return reinterpret_cast<u8*>(m_address); }
|
|
|
|
const u8* as_ptr() const { return reinterpret_cast<const u8*>(m_address); }
|
2019-04-06 15:29:29 +03:00
|
|
|
|
2019-07-03 22:17:35 +03:00
|
|
|
u32 page_base() const { return m_address & 0xfffff000; }
|
2019-04-06 15:29:29 +03:00
|
|
|
|
|
|
|
bool operator==(const PhysicalAddress& other) const { return m_address == other.m_address; }
|
2019-06-11 14:12:17 +03:00
|
|
|
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; }
|
2019-04-06 15:29:29 +03:00
|
|
|
|
|
|
|
private:
|
2019-07-03 22:17:35 +03:00
|
|
|
u32 m_address { 0 };
|
2019-04-06 15:29:29 +03:00
|
|
|
};
|
2019-09-15 21:47:49 +03:00
|
|
|
|
|
|
|
inline const LogStream& operator<<(const LogStream& stream, PhysicalAddress value)
|
|
|
|
{
|
|
|
|
return stream << 'P' << value.as_ptr();
|
|
|
|
}
|