// SPDX-License-Identifier: MPL-2.0 // Copyright © 2023 Skyline Team and Contributors (https://github.com/skyline-emu/) #pragma once #include #include "hle/kernel/k_process.h" namespace Core::Memory { constexpr std::size_t YUZU_PAGEBITS = 12; constexpr u64 YUZU_PAGESIZE = 1ULL << YUZU_PAGEBITS; constexpr u64 YUZU_PAGEMASK = YUZU_PAGESIZE - 1; /// Central class that handles all memory operations and state. class Memory { public: u8* GetPointer(VAddr vaddr) { return reinterpret_cast(vaddr); } template T* GetPointer(VAddr vaddr) { return reinterpret_cast(GetPointer(vaddr)); } const u8* GetPointer(VAddr vaddr) const { return reinterpret_cast(vaddr); } template const T* GetPointer(VAddr vaddr) const { return reinterpret_cast(GetPointer(vaddr)); } void Write32(VAddr addr, u32 data) { *GetPointer(addr) = data; } void ReadBlockUnsafe(VAddr src_addr, void* dest_buffer, std::size_t size) { std::memcpy(dest_buffer, GetPointer(src_addr), size); } void WriteBlockUnsafe(VAddr dest_addr, const void* src_buffer, std::size_t size) { std::memcpy(GetPointer(dest_addr), src_buffer, size); } void ZeroBlock(KernelShim::KProcess &proc, VAddr dest_addr, std::size_t size) { std::memset(GetPointer(dest_addr), 0, size); } }; }