diff options
author | yuzubot <[email protected]> | 2024-03-04 13:02:54 +0000 |
---|---|---|
committer | yuzubot <[email protected]> | 2024-03-04 13:02:54 +0000 |
commit | 537296095ab24eddcb196b5ef98004f91de9c8c2 (patch) | |
tree | e75e9e2441dc3f8657cc42f2daaae08737949c2b /src/core/core.cpp | |
parent | 2ddac7b02b660bbc7bdfe4fef240699df6d52e64 (diff) | |
download | yuzu-mainline-537296095ab24eddcb196b5ef98004f91de9c8c2.tar.gz yuzu-mainline-537296095ab24eddcb196b5ef98004f91de9c8c2.zip |
Diffstat (limited to 'src/core/core.cpp')
-rw-r--r-- | src/core/core.cpp | 112 |
1 files changed, 29 insertions, 83 deletions
diff --git a/src/core/core.cpp b/src/core/core.cpp index dc515bc82..e1c8b41ee 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -3,7 +3,6 @@ #include <array> #include <atomic> -#include <exception> #include <memory> #include <utility> @@ -20,7 +19,6 @@ #include "core/cpu_manager.h" #include "core/debugger/debugger.h" #include "core/device_memory.h" -#include "core/file_sys/bis_factory.h" #include "core/file_sys/fs_filesystem.h" #include "core/file_sys/patch_manager.h" #include "core/file_sys/registered_cache.h" @@ -38,6 +36,7 @@ #include "core/hle/service/acc/profile_manager.h" #include "core/hle/service/am/applet_manager.h" #include "core/hle/service/am/frontend/applets.h" +#include "core/hle/service/am/process_creation.h" #include "core/hle/service/apm/apm_controller.h" #include "core/hle/service/filesystem/filesystem.h" #include "core/hle/service/glue/glue_manager.h" @@ -72,30 +71,6 @@ MICROPROFILE_DEFINE(ARM_CPU3, "ARM", "CPU 3", MP_RGB(255, 64, 64)); namespace Core { -namespace { - -FileSys::StorageId GetStorageIdForFrontendSlot( - std::optional<FileSys::ContentProviderUnionSlot> slot) { - if (!slot.has_value()) { - return FileSys::StorageId::None; - } - - switch (*slot) { - case FileSys::ContentProviderUnionSlot::UserNAND: - return FileSys::StorageId::NandUser; - case FileSys::ContentProviderUnionSlot::SysNAND: - return FileSys::StorageId::NandSystem; - case FileSys::ContentProviderUnionSlot::SDMC: - return FileSys::StorageId::SdCard; - case FileSys::ContentProviderUnionSlot::FrontendManual: - return FileSys::StorageId::Host; - default: - return FileSys::StorageId::None; - } -} - -} // Anonymous namespace - FileSys::VirtualFile GetGameFileFromPath(const FileSys::VirtualFilesystem& vfs, const std::string& path) { // To account for split 00+01+etc files. @@ -297,9 +272,6 @@ struct System::Impl { } SystemResultStatus SetupForApplicationProcess(System& system, Frontend::EmuWindow& emu_window) { - /// Reset all glue registrations - arp_manager.ResetAll(); - telemetry_session = std::make_unique<Core::TelemetrySession>(); host1x_core = std::make_unique<Tegra::Host1x::Host1x>(system); @@ -335,8 +307,24 @@ struct System::Impl { SystemResultStatus Load(System& system, Frontend::EmuWindow& emu_window, const std::string& filepath, Service::AM::FrontendAppletParameters& params) { - app_loader = Loader::GetLoader(system, GetGameFileFromPath(virtual_filesystem, filepath), - params.program_id, params.program_index); + InitializeKernel(system); + + const auto file = GetGameFileFromPath(virtual_filesystem, filepath); + + // Create the application process + Loader::ResultStatus load_result{}; + std::vector<u8> control; + auto process = + Service::AM::CreateApplicationProcess(control, app_loader, load_result, system, file, + params.program_id, params.program_index); + + if (load_result != Loader::ResultStatus::Success) { + LOG_CRITICAL(Core, "Failed to load ROM (Error {})!", load_result); + ShutdownMainProcess(); + + return static_cast<SystemResultStatus>( + static_cast<u32>(SystemResultStatus::ErrorLoader) + static_cast<u32>(load_result)); + } if (!app_loader) { LOG_CRITICAL(Core, "Failed to obtain loader for {}!", filepath); @@ -344,7 +332,7 @@ struct System::Impl { } if (app_loader->ReadProgramId(params.program_id) != Loader::ResultStatus::Success) { - LOG_ERROR(Core, "Failed to find title id for ROM!"); + LOG_ERROR(Core, "Failed to find program id for ROM!"); } std::string name = "Unknown program"; @@ -352,23 +340,10 @@ struct System::Impl { LOG_ERROR(Core, "Failed to read title for ROM!"); } - LOG_INFO(Core, "Loading {} ({})", name, params.program_id); + LOG_INFO(Core, "Loading {} ({:016X}) ...", name, params.program_id); - InitializeKernel(system); - - // Create the application process. - auto main_process = Kernel::KProcess::Create(system.Kernel()); - Kernel::KProcess::Register(system.Kernel(), main_process); - kernel.AppendNewProcess(main_process); - kernel.MakeApplicationProcess(main_process); - const auto [load_result, load_parameters] = app_loader->Load(*main_process, system); - if (load_result != Loader::ResultStatus::Success) { - LOG_CRITICAL(Core, "Failed to load ROM (Error {})!", load_result); - ShutdownMainProcess(); - - return static_cast<SystemResultStatus>( - static_cast<u32>(SystemResultStatus::ErrorLoader) + static_cast<u32>(load_result)); - } + // Make the process created be the application + kernel.MakeApplicationProcess(process->GetHandle()); // Set up the rest of the system. SystemResultStatus init_result{SetupForApplicationProcess(system, emu_window)}; @@ -379,7 +354,6 @@ struct System::Impl { return init_result; } - AddGlueRegistrationForProcess(*app_loader, *main_process); telemetry_session->AddInitialInfo(*app_loader, fs_controller, *content_provider); // Initialize cheat engine @@ -387,14 +361,9 @@ struct System::Impl { cheat_engine->Initialize(); } - // Register with applet manager. - applet_manager.CreateAndInsertByFrontendAppletParameters(main_process->GetProcessId(), - params); - - // All threads are started, begin main process execution, now that we're in the clear. - main_process->Run(load_parameters->main_thread_priority, - load_parameters->main_thread_stack_size); - main_process->Close(); + // Register with applet manager + // All threads are started, begin main process execution, now that we're in the clear + applet_manager.CreateAndInsertByFrontendAppletParameters(std::move(process), params); if (Settings::values.gamecard_inserted) { if (Settings::values.gamecard_current_game) { @@ -461,7 +430,6 @@ struct System::Impl { kernel.SuspendEmulation(true); kernel.CloseServices(); kernel.ShutdownCores(); - applet_manager.Reset(); services.reset(); service_manager.reset(); fs_controller.Reset(); @@ -484,6 +452,9 @@ struct System::Impl { room_member->SendGameInfo(game_info); } + // Reset all glue registrations + arp_manager.ResetAll(); + LOG_DEBUG(Core, "Shutdown OK"); } @@ -501,31 +472,6 @@ struct System::Impl { return app_loader->ReadTitle(out); } - void AddGlueRegistrationForProcess(Loader::AppLoader& loader, Kernel::KProcess& process) { - std::vector<u8> nacp_data; - FileSys::NACP nacp; - if (loader.ReadControlData(nacp) == Loader::ResultStatus::Success) { - nacp_data = nacp.GetRawBytes(); - } else { - nacp_data.resize(sizeof(FileSys::RawNACP)); - } - - Service::Glue::ApplicationLaunchProperty launch{}; - launch.title_id = process.GetProgramId(); - - FileSys::PatchManager pm{launch.title_id, fs_controller, *content_provider}; - launch.version = pm.GetGameVersion().value_or(0); - - // TODO(DarkLordZach): When FSController/Game Card Support is added, if - // current_process_game_card use correct StorageId - launch.base_game_storage_id = GetStorageIdForFrontendSlot(content_provider->GetSlotForEntry( - launch.title_id, FileSys::ContentRecordType::Program)); - launch.update_storage_id = GetStorageIdForFrontendSlot(content_provider->GetSlotForEntry( - FileSys::GetUpdateTitleID(launch.title_id), FileSys::ContentRecordType::Program)); - - arp_manager.Register(launch.title_id, launch, std::move(nacp_data)); - } - void SetStatus(SystemResultStatus new_status, const char* details = nullptr) { status = new_status; if (details) { |