Misc: Purge unused code and report startup error to host
This commit is contained in:
@ -174,21 +174,18 @@ static constexpr size_t TOTAL_SIZE = LUT_OFFSET + LUT_SIZE;
|
||||
#define FIXUP_WORD_WRITE_VALUE(size, offset, value) \
|
||||
((size == MemoryAccessSize::Word) ? (value) : ((value) << (((offset) & 3u) * 8)))
|
||||
|
||||
bool Bus::AllocateMemory()
|
||||
bool Bus::AllocateMemory(Error* error)
|
||||
{
|
||||
Error error;
|
||||
s_shmem_handle =
|
||||
MemMap::CreateSharedMemory(MemMap::GetFileMappingName("duckstation").c_str(), MemoryMap::TOTAL_SIZE, &error);
|
||||
MemMap::CreateSharedMemory(MemMap::GetFileMappingName("duckstation").c_str(), MemoryMap::TOTAL_SIZE, error);
|
||||
if (!s_shmem_handle)
|
||||
{
|
||||
#ifndef __linux__
|
||||
error.AddSuffix("\nYou may need to close some programs to free up additional memory.");
|
||||
Error::AddSuffix(error, "\nYou may need to close some programs to free up additional memory.");
|
||||
#else
|
||||
error.AddSuffix(
|
||||
"\nYou may need to close some programs to free up additional memory, or increase the size of /dev/shm.");
|
||||
Error::AddSuffix(
|
||||
error, "\nYou may need to close some programs to free up additional memory, or increase the size of /dev/shm.");
|
||||
#endif
|
||||
|
||||
Host::ReportFatalError("Memory Allocation Failed", error.GetDescription());
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -198,7 +195,7 @@ bool Bus::AllocateMemory()
|
||||
MemoryMap::RAM_SIZE, PageProtect::ReadWrite));
|
||||
if (!g_ram || !g_unprotected_ram)
|
||||
{
|
||||
Host::ReportFatalError("Memory Allocation Failed", "Failed to map memory for RAM");
|
||||
Error::SetStringView(error, "Failed to map memory for RAM");
|
||||
ReleaseMemory();
|
||||
return false;
|
||||
}
|
||||
@ -209,7 +206,7 @@ bool Bus::AllocateMemory()
|
||||
MemoryMap::BIOS_SIZE, PageProtect::ReadWrite));
|
||||
if (!g_bios)
|
||||
{
|
||||
Host::ReportFatalError("Memory Allocation Failed", "Failed to map memory for BIOS");
|
||||
Error::SetStringView(error, "Failed to map memory for BIOS");
|
||||
ReleaseMemory();
|
||||
return false;
|
||||
}
|
||||
@ -220,7 +217,7 @@ bool Bus::AllocateMemory()
|
||||
MemoryMap::LUT_SIZE, PageProtect::ReadWrite));
|
||||
if (!g_memory_handlers)
|
||||
{
|
||||
Host::ReportFatalError("Memory Allocation Failed", "Failed to map memory for LUTs");
|
||||
Error::SetStringView(error, "Failed to map memory for LUTs");
|
||||
ReleaseMemory();
|
||||
return false;
|
||||
}
|
||||
@ -232,8 +229,7 @@ bool Bus::AllocateMemory()
|
||||
#ifdef ENABLE_MMAP_FASTMEM
|
||||
if (!s_fastmem_arena.Create(FASTMEM_ARENA_SIZE))
|
||||
{
|
||||
// TODO: maybe make this non-fatal?
|
||||
Host::ReportFatalError("Memory Allocation Failed", "Failed to create fastmem arena");
|
||||
Error::SetStringView(error, "Failed to create fastmem arena");
|
||||
ReleaseMemory();
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -14,6 +14,8 @@
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
class Error;
|
||||
|
||||
class StateWrapper;
|
||||
|
||||
namespace Bus {
|
||||
@ -109,7 +111,7 @@ enum : u32
|
||||
static constexpr size_t FASTMEM_ARENA_SIZE = UINT64_C(0x100000000);
|
||||
#endif
|
||||
|
||||
bool AllocateMemory();
|
||||
bool AllocateMemory(Error* error);
|
||||
void ReleaseMemory();
|
||||
|
||||
bool Initialize();
|
||||
|
||||
@ -172,12 +172,6 @@ std::optional<u32> Controller::GetBindIndex(ControllerType type, std::string_vie
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
Controller::VibrationCapabilities Controller::GetControllerVibrationCapabilities(std::string_view type)
|
||||
{
|
||||
const ControllerInfo* info = GetControllerInfo(type);
|
||||
return info ? info->vibration_caps : VibrationCapabilities::NoVibration;
|
||||
}
|
||||
|
||||
std::tuple<u32, u32> Controller::ConvertPadToPortAndSlot(u32 index)
|
||||
{
|
||||
if (index > 4) // [5,6,7]
|
||||
|
||||
@ -104,9 +104,6 @@ public:
|
||||
/// Gets the integer code for an axis in the specified controller type.
|
||||
static std::optional<u32> GetBindIndex(ControllerType type, std::string_view bind_name);
|
||||
|
||||
/// Returns the vibration configuration for the specified controller type.
|
||||
static VibrationCapabilities GetControllerVibrationCapabilities(std::string_view type);
|
||||
|
||||
/// Returns general information for the specified controller type.
|
||||
static const ControllerInfo* GetControllerInfo(ControllerType type);
|
||||
static const ControllerInfo* GetControllerInfo(std::string_view name);
|
||||
|
||||
@ -72,8 +72,6 @@ static void SetRegAccess(InstructionInfo* inst, Reg reg, bool write);
|
||||
static void AddBlockToPageList(Block* block);
|
||||
static void RemoveBlockFromPageList(Block* block);
|
||||
|
||||
static Common::PageFaultHandler::HandlerResult ExceptionHandler(void* exception_pc, void* fault_address, bool is_write);
|
||||
|
||||
static Block* CreateCachedInterpreterBlock(u32 pc);
|
||||
[[noreturn]] static void ExecuteCachedInterpreter();
|
||||
template<PGXPMode pgxp_mode>
|
||||
@ -99,8 +97,7 @@ static void UnlinkBlockExits(Block* block);
|
||||
static void ClearASMFunctions();
|
||||
static void CompileASMFunctions();
|
||||
static bool CompileBlock(Block* block);
|
||||
static Common::PageFaultHandler::HandlerResult HandleFastmemException(void* exception_pc, void* fault_address,
|
||||
bool is_write);
|
||||
static PageFaultHandler::HandlerResult HandleFastmemException(void* exception_pc, void* fault_address, bool is_write);
|
||||
static void BackpatchLoadStore(void* host_pc, const LoadstoreBackpatchInfo& info);
|
||||
static void RemoveBackpatchInfoForRange(const void* host_code, u32 size);
|
||||
|
||||
@ -165,7 +162,7 @@ bool CPU::CodeCache::IsUsingFastmem()
|
||||
return IsUsingAnyRecompiler() && g_settings.cpu_fastmem_mode != CPUFastmemMode::Disabled;
|
||||
}
|
||||
|
||||
bool CPU::CodeCache::ProcessStartup()
|
||||
bool CPU::CodeCache::ProcessStartup(Error* error)
|
||||
{
|
||||
AllocateLUTs();
|
||||
|
||||
@ -178,24 +175,19 @@ bool CPU::CodeCache::ProcessStartup()
|
||||
#endif
|
||||
if (!has_buffer && !s_code_buffer.Allocate(RECOMPILER_CODE_CACHE_SIZE, RECOMPILER_FAR_CODE_CACHE_SIZE))
|
||||
{
|
||||
Host::ReportFatalError("Error", "Failed to initialize code space");
|
||||
Error::SetStringView(error, "Failed to initialize code space");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!Common::PageFaultHandler::InstallHandler(ExceptionHandler))
|
||||
{
|
||||
Host::ReportFatalError("Error", "Failed to install page fault handler");
|
||||
if (!PageFaultHandler::Install(error))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CPU::CodeCache::ProcessShutdown()
|
||||
{
|
||||
Common::PageFaultHandler::RemoveHandler(ExceptionHandler);
|
||||
|
||||
#ifdef ENABLE_RECOMPILER_SUPPORT
|
||||
s_code_buffer.Destroy();
|
||||
#endif
|
||||
@ -747,8 +739,8 @@ void CPU::CodeCache::ClearBlocks()
|
||||
std::memset(s_lut_block_pointers.get(), 0, sizeof(Block*) * GetLUTSlotCount(false));
|
||||
}
|
||||
|
||||
Common::PageFaultHandler::HandlerResult CPU::CodeCache::ExceptionHandler(void* exception_pc, void* fault_address,
|
||||
bool is_write)
|
||||
PageFaultHandler::HandlerResult PageFaultHandler::HandlePageFault(void* exception_pc, void* fault_address,
|
||||
bool is_write)
|
||||
{
|
||||
if (static_cast<const u8*>(fault_address) >= Bus::g_ram &&
|
||||
static_cast<const u8*>(fault_address) < (Bus::g_ram + Bus::RAM_8MB_SIZE))
|
||||
@ -759,14 +751,14 @@ Common::PageFaultHandler::HandlerResult CPU::CodeCache::ExceptionHandler(void* e
|
||||
const u32 page_index = Bus::GetRAMCodePageIndex(guest_address);
|
||||
Log_DevFmt("Page fault on protected RAM @ 0x{:08X} (page #{}), invalidating code cache.", guest_address,
|
||||
page_index);
|
||||
InvalidateBlocksWithPageIndex(page_index);
|
||||
return Common::PageFaultHandler::HandlerResult::ContinueExecution;
|
||||
CPU::CodeCache::InvalidateBlocksWithPageIndex(page_index);
|
||||
return PageFaultHandler::HandlerResult::ContinueExecution;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_RECOMPILER_SUPPORT
|
||||
return HandleFastmemException(exception_pc, fault_address, is_write);
|
||||
return CPU::CodeCache::HandleFastmemException(exception_pc, fault_address, is_write);
|
||||
#else
|
||||
return Common::PageFaultHandler::HandlerResult::ExecuteNextHandler;
|
||||
return PageFaultHandler::HandlerResult::ExecuteNextHandler;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -1593,8 +1585,8 @@ void CPU::CodeCache::AddLoadStoreInfo(void* code_address, u32 code_size, u32 gue
|
||||
s_fastmem_backpatch_info.emplace(code_address, info);
|
||||
}
|
||||
|
||||
Common::PageFaultHandler::HandlerResult CPU::CodeCache::HandleFastmemException(void* exception_pc, void* fault_address,
|
||||
bool is_write)
|
||||
PageFaultHandler::HandlerResult CPU::CodeCache::HandleFastmemException(void* exception_pc, void* fault_address,
|
||||
bool is_write)
|
||||
{
|
||||
// TODO: Catch general RAM writes, not just fastmem
|
||||
PhysicalMemoryAddress guest_address;
|
||||
@ -1606,7 +1598,7 @@ Common::PageFaultHandler::HandlerResult CPU::CodeCache::HandleFastmemException(v
|
||||
(static_cast<u8*>(fault_address) - static_cast<u8*>(g_state.fastmem_base)) >=
|
||||
static_cast<ptrdiff_t>(Bus::FASTMEM_ARENA_SIZE))
|
||||
{
|
||||
return Common::PageFaultHandler::HandlerResult::ExecuteNextHandler;
|
||||
return PageFaultHandler::HandlerResult::ExecuteNextHandler;
|
||||
}
|
||||
|
||||
guest_address = static_cast<PhysicalMemoryAddress>(
|
||||
@ -1618,7 +1610,7 @@ Common::PageFaultHandler::HandlerResult CPU::CodeCache::HandleFastmemException(v
|
||||
{
|
||||
Log_DevFmt("Ignoring fault due to RAM write @ 0x{:08X}", guest_address);
|
||||
InvalidateBlocksWithPageIndex(Bus::GetRAMCodePageIndex(guest_address));
|
||||
return Common::PageFaultHandler::HandlerResult::ContinueExecution;
|
||||
return PageFaultHandler::HandlerResult::ContinueExecution;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -1635,7 +1627,7 @@ Common::PageFaultHandler::HandlerResult CPU::CodeCache::HandleFastmemException(v
|
||||
if (iter == s_fastmem_backpatch_info.end())
|
||||
{
|
||||
Log_ErrorFmt("No backpatch info found for {}", exception_pc);
|
||||
return Common::PageFaultHandler::HandlerResult::ExecuteNextHandler;
|
||||
return PageFaultHandler::HandlerResult::ExecuteNextHandler;
|
||||
}
|
||||
|
||||
LoadstoreBackpatchInfo& info = iter->second;
|
||||
@ -1670,7 +1662,7 @@ Common::PageFaultHandler::HandlerResult CPU::CodeCache::HandleFastmemException(v
|
||||
// and store the pc in the faulting list, so that we don't emit another fastmem loadstore
|
||||
s_fastmem_faulting_pcs.insert(info.guest_pc);
|
||||
s_fastmem_backpatch_info.erase(iter);
|
||||
return Common::PageFaultHandler::HandlerResult::ContinueExecution;
|
||||
return PageFaultHandler::HandlerResult::ContinueExecution;
|
||||
}
|
||||
|
||||
bool CPU::CodeCache::HasPreviouslyFaultedOnPC(u32 guest_pc)
|
||||
|
||||
@ -6,6 +6,8 @@
|
||||
#include "bus.h"
|
||||
#include "cpu_types.h"
|
||||
|
||||
class Error;
|
||||
|
||||
namespace CPU::CodeCache {
|
||||
|
||||
/// Returns true if any recompiler is in use.
|
||||
@ -15,7 +17,7 @@ bool IsUsingAnyRecompiler();
|
||||
bool IsUsingFastmem();
|
||||
|
||||
/// Allocates resources, call once at startup.
|
||||
bool ProcessStartup();
|
||||
bool ProcessStartup(Error* error);
|
||||
|
||||
/// Frees resources, call once at shutdown.
|
||||
void ProcessShutdown();
|
||||
|
||||
@ -254,7 +254,7 @@ static TinyString GetTimestampStringForFileName()
|
||||
return TinyString::from_format("{:%Y-%m-%d-%H-%M-%S}", fmt::localtime(std::time(nullptr)));
|
||||
}
|
||||
|
||||
bool System::Internal::CPUThreadInitialize()
|
||||
bool System::Internal::CPUThreadInitialize(Error* error)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
// On Win32, we have a bunch of things which use COM (e.g. SDL, Cubeb, etc).
|
||||
@ -263,15 +263,15 @@ bool System::Internal::CPUThreadInitialize()
|
||||
HRESULT hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
Host::ReportErrorAsync("Error", fmt::format("CoInitializeEx() failed: {:08X}", static_cast<unsigned>(hr)));
|
||||
Error::SetHResult(error, "CoInitializeEx() failed: ", hr);
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!Bus::AllocateMemory())
|
||||
if (!Bus::AllocateMemory(error))
|
||||
return false;
|
||||
|
||||
if (!CPU::CodeCache::ProcessStartup())
|
||||
if (!CPU::CodeCache::ProcessStartup(error))
|
||||
return false;
|
||||
|
||||
// This will call back to Host::LoadSettings() -> ReloadSources().
|
||||
|
||||
@ -490,7 +490,7 @@ void UpdateDiscordPresence(bool update_session_time);
|
||||
|
||||
namespace Internal {
|
||||
/// Called on process startup.
|
||||
bool CPUThreadInitialize();
|
||||
bool CPUThreadInitialize(Error* error);
|
||||
|
||||
/// Called on process shutdown.
|
||||
void CPUThreadShutdown();
|
||||
|
||||
Reference in New Issue
Block a user