Files
SpeedBreakerProject--speedb…/runtime/kernel/memory.h
T
2026-10-08 13:25:54 +00:00

54 lines
1.3 KiB
C

// Adapted from Unleashed Recompiled (https://github.com/hedge-dev/UnleashedRecomp),
// GPL-3.0-or-later. Modified for SpeedBreaker.
#pragma once
#ifndef _WIN32
#define MEM_COMMIT 0x00001000
#define MEM_RESERVE 0x00002000
#endif
struct Memory
{
uint8_t* base{};
Memory();
bool MapPhysicalMirrors();
// Physical offset of the 0xE0000000 window: 0x1000 on hardware, 0 on
// hosts whose page size can't express it (see memory.cpp).
uint32_t eWindowShift = 0;
bool IsInMemoryRange(const void* host) const noexcept
{
return host >= base && host < (base + PPC_MEMORY_SIZE);
}
void* Translate(size_t offset) const noexcept
{
if (offset)
assert(offset < PPC_MEMORY_SIZE);
return base + offset;
}
uint32_t MapVirtual(const void* host) const noexcept
{
if (host)
assert(IsInMemoryRange(host));
return static_cast<uint32_t>(static_cast<const uint8_t*>(host) - base);
}
PPCFunc* FindFunction(uint32_t guest) const noexcept
{
return PPC_LOOKUP_FUNC(base, guest);
}
void InsertFunction(uint32_t guest, PPCFunc* host)
{
PPC_LOOKUP_FUNC(base, guest) = host;
}
};
extern "C" void* MmGetHostAddress(uint32_t ptr);
extern Memory g_memory;