Memmap: Make the MMIO mapping a unique_ptr

This commit is contained in:
Lioncash 2016-02-14 22:22:49 -05:00
parent cafc879b7c
commit b36b10fa78
4 changed files with 34 additions and 28 deletions

View File

@ -9,6 +9,7 @@
// may be redirected here (for example to Read_U32()).
#include <cstring>
#include <memory>
#include "Common/ChunkFile.h"
#include "Common/CommonFuncs.h"
@ -58,31 +59,37 @@ u8* m_pEXRAM;
u8* m_pFakeVMEM;
// MMIO mapping object.
MMIO::Mapping* mmio_mapping;
std::unique_ptr<MMIO::Mapping> mmio_mapping;
static void InitMMIO(MMIO::Mapping* mmio)
static std::unique_ptr<MMIO::Mapping> InitMMIO()
{
CommandProcessor::RegisterMMIO(mmio, 0x0C000000);
PixelEngine::RegisterMMIO(mmio, 0x0C001000);
VideoInterface::RegisterMMIO(mmio, 0x0C002000);
ProcessorInterface::RegisterMMIO(mmio, 0x0C003000);
MemoryInterface::RegisterMMIO(mmio, 0x0C004000);
DSP::RegisterMMIO(mmio, 0x0C005000);
DVDInterface::RegisterMMIO(mmio, 0x0C006000);
SerialInterface::RegisterMMIO(mmio, 0x0C006400);
ExpansionInterface::RegisterMMIO(mmio, 0x0C006800);
AudioInterface::RegisterMMIO(mmio, 0x0C006C00);
auto mmio = std::make_unique<MMIO::Mapping>();
CommandProcessor ::RegisterMMIO(mmio.get(), 0x0C000000);
PixelEngine ::RegisterMMIO(mmio.get(), 0x0C001000);
VideoInterface ::RegisterMMIO(mmio.get(), 0x0C002000);
ProcessorInterface::RegisterMMIO(mmio.get(), 0x0C003000);
MemoryInterface ::RegisterMMIO(mmio.get(), 0x0C004000);
DSP ::RegisterMMIO(mmio.get(), 0x0C005000);
DVDInterface ::RegisterMMIO(mmio.get(), 0x0C006000);
SerialInterface ::RegisterMMIO(mmio.get(), 0x0C006400);
ExpansionInterface::RegisterMMIO(mmio.get(), 0x0C006800);
AudioInterface ::RegisterMMIO(mmio.get(), 0x0C006C00);
return mmio;
}
static void InitMMIOWii(MMIO::Mapping* mmio)
static std::unique_ptr<MMIO::Mapping> InitMMIOWii()
{
InitMMIO(mmio);
auto mmio = InitMMIO();
WII_IPCInterface::RegisterMMIO(mmio, 0x0D000000);
DVDInterface::RegisterMMIO(mmio, 0x0D006000);
SerialInterface::RegisterMMIO(mmio, 0x0D006400);
ExpansionInterface::RegisterMMIO(mmio, 0x0D006800);
AudioInterface::RegisterMMIO(mmio, 0x0D006C00);
WII_IPCInterface ::RegisterMMIO(mmio.get(), 0x0D000000);
DVDInterface ::RegisterMMIO(mmio.get(), 0x0D006000);
SerialInterface ::RegisterMMIO(mmio.get(), 0x0D006400);
ExpansionInterface::RegisterMMIO(mmio.get(), 0x0D006800);
AudioInterface ::RegisterMMIO(mmio.get(), 0x0D006C00);
return mmio;
}
bool IsInitialized()
@ -180,12 +187,10 @@ void Init()
logical_base = physical_base + 0x200000000;
#endif
mmio_mapping = new MMIO::Mapping();
if (wii)
InitMMIOWii(mmio_mapping);
mmio_mapping = InitMMIOWii();
else
InitMMIO(mmio_mapping);
mmio_mapping = InitMMIO();
INFO_LOG(MEMMAP, "Memory system initialized. RAM at %p", m_pRAM);
m_IsInitialized = true;
@ -215,7 +220,7 @@ void Shutdown()
g_arena.ReleaseSHMSegment();
physical_base = nullptr;
logical_base = nullptr;
delete mmio_mapping;
mmio_mapping.reset();
INFO_LOG(MEMMAP, "Memory system shut down.");
}

View File

@ -4,6 +4,7 @@
#pragma once
#include <memory>
#include <string>
#include "Common/CommonFuncs.h"
@ -63,7 +64,7 @@ enum
};
// MMIO mapping object.
extern MMIO::Mapping* mmio_mapping;
extern std::unique_ptr<MMIO::Mapping> mmio_mapping;
// Init and Shutdown
bool IsInitialized();

View File

@ -154,7 +154,7 @@ void JitArm64::SafeLoadToReg(u32 dest, s32 addr, s32 offsetReg, u32 flags, s32 o
}
else if (mmio_address)
{
MMIOLoadToReg(Memory::mmio_mapping, this,
MMIOLoadToReg(Memory::mmio_mapping.get(), this,
regs_in_use, fprs_in_use, dest_reg,
mmio_address, flags);
}
@ -350,7 +350,7 @@ void JitArm64::SafeStoreFromReg(s32 dest, u32 value, s32 regOffset, u32 flags, s
}
else if (mmio_address && !(flags & BackPatchInfo::FLAG_REVERSE))
{
MMIOWriteRegToAddr(Memory::mmio_mapping, this,
MMIOWriteRegToAddr(Memory::mmio_mapping.get(), this,
regs_in_use, fprs_in_use, RS,
mmio_address, flags);
}

View File

@ -264,7 +264,7 @@ void EmuCodeBlock::SafeLoadToReg(X64Reg reg_value, const Gen::OpArg & opAddress,
u32 mmioAddress = PowerPC::IsOptimizableMMIOAccess(address, accessSize);
if (accessSize != 64 && mmioAddress)
{
MMIOLoadToReg(Memory::mmio_mapping, reg_value, registersInUse,
MMIOLoadToReg(Memory::mmio_mapping.get(), reg_value, registersInUse,
mmioAddress, accessSize, signExtend);
return;
}