mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-07 22:55:40 +12:00
Fix fastmem (again)
This commit is contained in:
parent
7dd82a3c9a
commit
080df1b3f8
3 changed files with 21 additions and 37 deletions
|
@ -152,8 +152,11 @@ private:
|
||||||
static constexpr size_t FASTMEM_FCRAM_OFFSET = 0; // Offset of FCRAM in the fastmem arena
|
static constexpr size_t FASTMEM_FCRAM_OFFSET = 0; // Offset of FCRAM in the fastmem arena
|
||||||
static constexpr size_t FASTMEM_DSP_RAM_OFFSET = FASTMEM_FCRAM_OFFSET + FCRAM_SIZE; // Offset of DSP RAM
|
static constexpr size_t FASTMEM_DSP_RAM_OFFSET = FASTMEM_FCRAM_OFFSET + FCRAM_SIZE; // Offset of DSP RAM
|
||||||
|
|
||||||
#ifdef PANDA3DS_HARDWARE_FASTMEM
|
static constexpr size_t FASTMEM_BACKING_SIZE = FCRAM_SIZE + DSP_RAM_SIZE;
|
||||||
std::unique_ptr<Common::HostMemory> arena;
|
// Total size of the virtual address space we will occupy (4GB)
|
||||||
|
static constexpr size_t FASTMEM_VIRTUAL_SIZE = 4_GB;
|
||||||
|
|
||||||
|
Common::HostMemory* arena;
|
||||||
|
|
||||||
void addFastmemView(u32 guestVaddr, size_t arenaOffset, size_t size, bool w, bool x = false) {
|
void addFastmemView(u32 guestVaddr, size_t arenaOffset, size_t size, bool w, bool x = false) {
|
||||||
if (useFastmem) {
|
if (useFastmem) {
|
||||||
|
@ -169,10 +172,6 @@ private:
|
||||||
arena->Map(guestVaddr, arenaOffset, size, perms, false);
|
arena->Map(guestVaddr, arenaOffset, size, perms, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
void resetFastmemViews() {}
|
|
||||||
void addFastmemView(u32 guestVaddr, size_t arenaOffset, size_t size, bool r, bool w, bool x = false) {}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
std::bitset<FCRAM_PAGE_COUNT> usedFCRAMPages;
|
std::bitset<FCRAM_PAGE_COUNT> usedFCRAMPages;
|
||||||
std::optional<u32> findPaddr(u32 size);
|
std::optional<u32> findPaddr(u32 size);
|
||||||
|
@ -334,11 +333,6 @@ private:
|
||||||
Regions getConsoleRegion();
|
Regions getConsoleRegion();
|
||||||
void copySharedFont(u8* ptr, u32 vaddr);
|
void copySharedFont(u8* ptr, u32 vaddr);
|
||||||
|
|
||||||
#ifdef PANDA3DS_HARDWARE_FASTMEM
|
|
||||||
bool isFastmemEnabled() { return useFastmem; }
|
bool isFastmemEnabled() { return useFastmem; }
|
||||||
u8* getFastmemArenaBase() { return arena->VirtualBasePointer(); }
|
u8* getFastmemArenaBase() { return arena->VirtualBasePointer(); }
|
||||||
#else
|
|
||||||
bool isFastmemEnabled() { return false; }
|
|
||||||
u8* getFastmemArenaBase() { return nullptr; }
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -15,35 +15,16 @@ CMRC_DECLARE(ConsoleFonts);
|
||||||
using namespace KernelMemoryTypes;
|
using namespace KernelMemoryTypes;
|
||||||
|
|
||||||
Memory::Memory(const EmulatorConfig& config) : config(config) {
|
Memory::Memory(const EmulatorConfig& config) : config(config) {
|
||||||
fcram = new uint8_t[FCRAM_SIZE]();
|
arena = new Common::HostMemory(FASTMEM_BACKING_SIZE, FASTMEM_VIRTUAL_SIZE);
|
||||||
|
|
||||||
readTable.resize(totalPageCount, 0);
|
readTable.resize(totalPageCount, 0);
|
||||||
writeTable.resize(totalPageCount, 0);
|
writeTable.resize(totalPageCount, 0);
|
||||||
memoryInfo.reserve(32); // Pre-allocate some room for memory allocation info to avoid dynamic allocs
|
memoryInfo.reserve(32); // Pre-allocate some room for memory allocation info to avoid dynamic allocs
|
||||||
|
|
||||||
#ifdef PANDA3DS_HARDWARE_FASTMEM
|
fcram = arena->BackingBasePointer() + FASTMEM_FCRAM_OFFSET;
|
||||||
u8* arenaFcram = nullptr;
|
// arenaDSPRam = arena->BackingBasePointer() + FASTMEM_DSP_RAM_OFFSET;
|
||||||
u8* arenaDSPRam = nullptr;
|
|
||||||
|
|
||||||
constexpr size_t BACKING_SIZE = FCRAM_SIZE + DSP_RAM_SIZE;
|
useFastmem = arena->VirtualBasePointer() != nullptr;
|
||||||
constexpr size_t VIRTUAL_SIZE = 4_GB; // Total size of the virtual address space we will occupy (4GB)
|
|
||||||
|
|
||||||
try {
|
|
||||||
arena.reset(new Common::HostMemory(BACKING_SIZE, VIRTUAL_SIZE));
|
|
||||||
arenaFcram = arena->BackingBasePointer() + FASTMEM_FCRAM_OFFSET;
|
|
||||||
// arenaDSPRam = arena->VirtualBasePointer() + FASTMEM_DSP_RAM_OFFSET;
|
|
||||||
|
|
||||||
useFastmem = true;
|
|
||||||
delete[] fcram;
|
|
||||||
|
|
||||||
fcram = arenaFcram;
|
|
||||||
} catch (...) {
|
|
||||||
useFastmem = false;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
useFastmem = false;
|
|
||||||
fastmemArenaBase = nullptr;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Memory::reset() {
|
void Memory::reset() {
|
||||||
|
@ -98,7 +79,9 @@ void Memory::reset() {
|
||||||
readTable[i + initialPage] = pointer;
|
readTable[i + initialPage] = pointer;
|
||||||
writeTable[i + initialPage] = pointer;
|
writeTable[i + initialPage] = pointer;
|
||||||
}
|
}
|
||||||
// addFastmemView(VirtualAddrs::DSPMemStart, FASTMEM_DSP_RAM_OFFSET, DSP_RAM_SIZE, true, false); // Allocate RW mapping for DSP RAM
|
|
||||||
|
// Allocate RW mapping for DSP RAM
|
||||||
|
// addFastmemView(VirtualAddrs::DSPMemStart, FASTMEM_DSP_RAM_OFFSET, DSP_RAM_SIZE, true, false);
|
||||||
|
|
||||||
// Later adjusted based on ROM header when possible
|
// Later adjusted based on ROM header when possible
|
||||||
region = Regions::USA;
|
region = Regions::USA;
|
||||||
|
@ -514,6 +497,10 @@ void Memory::mirrorMapping(u32 destAddress, u32 sourceAddress, u32 size) {
|
||||||
|
|
||||||
const u32 pageCount = size / pageSize; // How many pages we need to mirror
|
const u32 pageCount = size / pageSize; // How many pages we need to mirror
|
||||||
for (u32 i = 0; i < pageCount; i++) {
|
for (u32 i = 0; i < pageCount; i++) {
|
||||||
|
if (useFastmem) {
|
||||||
|
Helpers::panic("Unimplemented: Mirror mapping with fastmem enabled");
|
||||||
|
}
|
||||||
|
|
||||||
// Redo the shift here to "properly" handle wrapping around the address space instead of reading OoB
|
// Redo the shift here to "properly" handle wrapping around the address space instead of reading OoB
|
||||||
const u32 sourcePage = sourceAddress / pageSize;
|
const u32 sourcePage = sourceAddress / pageSize;
|
||||||
const u32 destPage = destAddress / pageSize;
|
const u32 destPage = destAddress / pageSize;
|
||||||
|
|
7
third_party/host_memory/host_memory.cpp
vendored
7
third_party/host_memory/host_memory.cpp
vendored
|
@ -1,6 +1,9 @@
|
||||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
// Copyright 2008 Dolphin Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#if defined(_M_ARM64) || defined(__aarch64__)
|
#if defined(_M_ARM64) || defined(__aarch64__)
|
||||||
#define ARCHITECTURE_arm64
|
#define ARCHITECTURE_arm64
|
||||||
#endif
|
#endif
|
||||||
|
@ -59,7 +62,7 @@ namespace Common {
|
||||||
constexpr size_t PageAlignment = 0x1000;
|
constexpr size_t PageAlignment = 0x1000;
|
||||||
constexpr size_t HugePageSize = 0x200000;
|
constexpr size_t HugePageSize = 0x200000;
|
||||||
|
|
||||||
#ifdef _WIN32
|
#if defined(_WIN32) && defined(PANDA3DS_HARDWARE_FASTMEM)
|
||||||
|
|
||||||
// Manually imported for MinGW compatibility
|
// Manually imported for MinGW compatibility
|
||||||
#ifndef MEM_RESERVE_PLACEHOLDER
|
#ifndef MEM_RESERVE_PLACEHOLDER
|
||||||
|
@ -365,7 +368,7 @@ namespace Common {
|
||||||
std::unordered_map<size_t, size_t> placeholder_host_pointers; ///< Placeholder backing offset
|
std::unordered_map<size_t, size_t> placeholder_host_pointers; ///< Placeholder backing offset
|
||||||
};
|
};
|
||||||
|
|
||||||
#elif defined(__linux__) || defined(__FreeBSD__) // ^^^ Windows ^^^ vvv Linux vvv
|
#elif (defined(__linux__) || defined(__FreeBSD__)) && defined(PANDA3DS_HARDWARE_FASTMEM) // ^^^ Windows ^^^ vvv Linux vvv
|
||||||
|
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
#define ASHMEM_DEVICE "/dev/ashmem"
|
#define ASHMEM_DEVICE "/dev/ashmem"
|
||||||
|
|
Loading…
Add table
Reference in a new issue