From 377ad9887cb2484d49e106193d1aa9f8eb3d430d Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Sat, 30 May 2020 02:17:34 +0300 Subject: [PATCH] Compile EBOOT.BIN on 'Create PPU Caches' --- rpcs3/Emu/System.cpp | 90 +++++++++++++++++++++++++++++++++----------- rpcs3/Emu/System.h | 1 + 2 files changed, 69 insertions(+), 22 deletions(-) diff --git a/rpcs3/Emu/System.cpp b/rpcs3/Emu/System.cpp index db5bb3d939..579ff34adb 100644 --- a/rpcs3/Emu/System.cpp +++ b/rpcs3/Emu/System.cpp @@ -950,8 +950,15 @@ game_boot_result Emulator::Load(const std::string& title_id, bool add_only, bool // Force LLVM recompiler g_cfg.core.ppu_decoder.from_default(); - // Workaround for analyser glitches - vm::falloc(0x10000, 0xf0000, vm::main); + // Force lib loading mode + g_cfg.core.lib_loading.from_string("Manually load selected libraries"); + verify(HERE), g_cfg.core.lib_loading == lib_loading_type::manual; + g_cfg.core.load_libraries.from_default(); + + // Fake arg (workaround) + argv.resize(1); + argv[0] = "/dev_bdvd/PS3_GAME/USRDIR/EBOOT.BIN"; + m_dir = "/dev_bdvd/PS3_GAME"; g_fxo->init("SPRX Loader"sv, [this] { @@ -1008,6 +1015,40 @@ game_boot_result Emulator::Load(const std::string& title_id, bool add_only, bool g_progr = "Compiling PPU modules"; + if (std::string path = m_path + "/USRDIR/EBOOT.BIN"; fs::is_file(path)) + { + // Compile EBOOT.BIN first + sys_log.notice("Trying to load EBOOT.BIN: %s", path); + + fs::file src{path}; + + src = decrypt_self(std::move(src)); + + const ppu_exec_object obj = src; + + if (obj == elf_error::ok) + { + const auto _main = g_fxo->get(); + + ppu_load_exec(obj); + + _main->path = path; + + ConfigurePPUCache(); + + ppu_initialize(*_main); + } + else + { + sys_log.error("Failed to load EBOOT.BIN '%s' (%s)", path, obj.get_error()); + } + } + else + { + // Workaround for analyser glitches + verify(HERE), vm::falloc(0x10000, 0xf0000, vm::main); + } + atomic_t fnext = 0; shared_mutex sprx_mtx; @@ -1436,26 +1477,7 @@ game_boot_result Emulator::Load(const std::string& title_id, bool add_only, bool ppu_load_exec(ppu_exec); - _main->cache = GetCacheDir(); - - if (!m_title_id.empty() && m_cat != "1P") - { - // TODO - _main->cache += Emu.GetTitleID(); - _main->cache += '/'; - } - - fmt::append(_main->cache, "ppu-%s-%s/", fmt::base57(_main->sha1), _main->path.substr(_main->path.find_last_of('/') + 1)); - - if (!fs::create_path(_main->cache)) - { - sys_log.error("Failed to create cache directory: %s (%s)", _main->cache, fs::g_tls_error); - return game_boot_result::file_creation_error; - } - else - { - sys_log.notice("Cache: %s", _main->cache); - } + ConfigurePPUCache(); g_fxo->init(); Emu.GetCallbacks().init_gs_render(); @@ -1854,6 +1876,30 @@ void Emulator::ConfigureLogs() was_silenced = silenced; } +void Emulator::ConfigurePPUCache() +{ + const auto _main = g_fxo->get(); + + _main->cache = GetCacheDir(); + + if (!m_title_id.empty() && m_cat != "1P") + { + _main->cache += Emu.GetTitleID(); + _main->cache += '/'; + } + + fmt::append(_main->cache, "ppu-%s-%s/", fmt::base57(_main->sha1), _main->path.substr(_main->path.find_last_of('/') + 1)); + + if (!fs::create_path(_main->cache)) + { + sys_log.error("Failed to create cache directory: %s (%s)", _main->cache, fs::g_tls_error); + } + else + { + sys_log.notice("Cache: %s", _main->cache); + } +} + template <> void stx::manual_fixed_typemap::init_reporter(const char* name, unsigned long long created) const noexcept { diff --git a/rpcs3/Emu/System.h b/rpcs3/Emu/System.h index ee97df392f..11d7304099 100644 --- a/rpcs3/Emu/System.h +++ b/rpcs3/Emu/System.h @@ -213,6 +213,7 @@ public: u32 GetMaxThreads() const; void ConfigureLogs(); + void ConfigurePPUCache(); private: void LimitCacheSize();