diff options
Diffstat (limited to 'src/core')
25 files changed, 520 insertions, 230 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index a355eaca6..e1f21a764 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -12,6 +12,8 @@ add_library(core STATIC core_timing.h core_timing_util.cpp core_timing_util.h + cpu_core_manager.cpp + cpu_core_manager.h crypto/aes_util.cpp crypto/aes_util.h crypto/encryption_layer.cpp @@ -156,6 +158,8 @@ add_library(core STATIC hle/service/am/applets/applets.h hle/service/am/applets/software_keyboard.cpp hle/service/am/applets/software_keyboard.h + hle/service/am/applets/stub_applet.cpp + hle/service/am/applets/stub_applet.h hle/service/am/idle.cpp hle/service/am/idle.h hle/service/am/omm.cpp diff --git a/src/core/core.cpp b/src/core/core.cpp index 6c72fdf4a..795fabc65 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -14,6 +14,7 @@ #include "core/core.h" #include "core/core_cpu.h" #include "core/core_timing.h" +#include "core/cpu_core_manager.h" #include "core/file_sys/mode.h" #include "core/file_sys/vfs_concat.h" #include "core/file_sys/vfs_real.h" @@ -28,7 +29,6 @@ #include "core/hle/service/sm/sm.h" #include "core/loader/loader.h" #include "core/perf_stats.h" -#include "core/settings.h" #include "core/telemetry_session.h" #include "frontend/applets/software_keyboard.h" #include "video_core/debug_utils/debug_utils.h" @@ -71,64 +71,22 @@ FileSys::VirtualFile GetGameFileFromPath(const FileSys::VirtualFilesystem& vfs, return vfs->OpenFile(path, FileSys::Mode::Read); } - -/// Runs a CPU core while the system is powered on -void RunCpuCore(Cpu& cpu_state) { - while (Core::System::GetInstance().IsPoweredOn()) { - cpu_state.RunLoop(true); - } -} } // Anonymous namespace struct System::Impl { Cpu& CurrentCpuCore() { - if (Settings::values.use_multi_core) { - const auto& search = thread_to_cpu.find(std::this_thread::get_id()); - ASSERT(search != thread_to_cpu.end()); - ASSERT(search->second); - return *search->second; - } - - // Otherwise, use single-threaded mode active_core variable - return *cpu_cores[active_core]; + return cpu_core_manager.GetCurrentCore(); } ResultStatus RunLoop(bool tight_loop) { status = ResultStatus::Success; - // Update thread_to_cpu in case Core 0 is run from a different host thread - thread_to_cpu[std::this_thread::get_id()] = cpu_cores[0].get(); - - if (GDBStub::IsServerEnabled()) { - GDBStub::HandlePacket(); - - // If the loop is halted and we want to step, use a tiny (1) number of instructions to - // execute. Otherwise, get out of the loop function. - if (GDBStub::GetCpuHaltFlag()) { - if (GDBStub::GetCpuStepFlag()) { - tight_loop = false; - } else { - return ResultStatus::Success; - } - } - } - - for (active_core = 0; active_core < NUM_CPU_CORES; ++active_core) { - cpu_cores[active_core]->RunLoop(tight_loop); - if (Settings::values.use_multi_core) { - // Cores 1-3 are run on other threads in this mode - break; - } - } - - if (GDBStub::IsServerEnabled()) { - GDBStub::SetCpuStepFlag(false); - } + cpu_core_manager.RunLoop(tight_loop); return status; } - ResultStatus Init(Frontend::EmuWindow& emu_window) { + ResultStatus Init(System& system, Frontend::EmuWindow& emu_window) { LOG_DEBUG(HW_Memory, "initialized OK"); CoreTiming::Init(); @@ -145,12 +103,6 @@ struct System::Impl { auto main_process = Kernel::Process::Create(kernel, "main"); kernel.MakeCurrentProcess(main_process.get()); - cpu_barrier = std::make_unique<CpuBarrier>(); - cpu_exclusive_monitor = Cpu::MakeExclusiveMonitor(cpu_cores.size()); - for (std::size_t index = 0; index < cpu_cores.size(); ++index) { - cpu_cores[index] = std::make_unique<Cpu>(*cpu_exclusive_monitor, *cpu_barrier, index); - } - telemetry_session = std::make_unique<Core::TelemetrySession>(); service_manager = std::make_shared<Service::SM::ServiceManager>(); @@ -164,17 +116,8 @@ struct System::Impl { gpu_core = std::make_unique<Tegra::GPU>(renderer->Rasterizer()); - // Create threads for CPU cores 1-3, and build thread_to_cpu map - // CPU core 0 is run on the main thread - thread_to_cpu[std::this_thread::get_id()] = cpu_cores[0].get(); - if (Settings::values.use_multi_core) { - for (std::size_t index = 0; index < cpu_core_threads.size(); ++index) { - cpu_core_threads[index] = - std::make_unique<std::thread>(RunCpuCore, std::ref(*cpu_cores[index + 1])); - thread_to_cpu[cpu_core_threads[index]->get_id()] = cpu_cores[index + 1].get(); - } - } - + cpu_core_manager.Initialize(system); + is_powered_on = true; LOG_DEBUG(Core, "Initialized OK"); // Reset counters and set time origin to current frame @@ -184,7 +127,8 @@ struct System::Impl { return ResultStatus::Success; } - ResultStatus Load(Frontend::EmuWindow& emu_window, const std::string& filepath) { + ResultStatus Load(System& system, Frontend::EmuWindow& emu_window, + const std::string& filepath) { app_loader = Loader::GetLoader(GetGameFileFromPath(virtual_filesystem, filepath)); if (!app_loader) { @@ -201,7 +145,7 @@ struct System::Impl { return ResultStatus::ErrorSystemMode; } - ResultStatus init_result{Init(emu_window)}; + ResultStatus init_result{Init(system, emu_window)}; if (init_result != ResultStatus::Success) { LOG_CRITICAL(Core, "Failed to initialize system (Error {})!", static_cast<int>(init_result)); @@ -231,6 +175,8 @@ struct System::Impl { Telemetry().AddField(Telemetry::FieldType::Performance, "Shutdown_Frametime", perf_results.frametime * 1000.0); + is_powered_on = false; + // Shutdown emulation session renderer.reset(); GDBStub::Shutdown(); @@ -240,19 +186,7 @@ struct System::Impl { gpu_core.reset(); // Close all CPU/threading state - cpu_barrier->NotifyEnd(); - if (Settings::values.use_multi_core) { - for (auto& thread : cpu_core_threads) { - thread->join(); - thread.reset(); - } - } - thread_to_cpu.clear(); - for (auto& cpu_core : cpu_cores) { - cpu_core.reset(); - } - cpu_exclusive_monitor.reset(); - cpu_barrier.reset(); + cpu_core_manager.Shutdown(); // Shutdown kernel and core timing kernel.Shutdown(); @@ -289,11 +223,8 @@ struct System::Impl { std::unique_ptr<VideoCore::RendererBase> renderer; std::unique_ptr<Tegra::GPU> gpu_core; std::shared_ptr<Tegra::DebugContext> debug_context; - std::unique_ptr<ExclusiveMonitor> cpu_exclusive_monitor; - std::unique_ptr<CpuBarrier> cpu_barrier; - std::array<std::unique_ptr<Cpu>, NUM_CPU_CORES> cpu_cores; - std::array<std::unique_ptr<std::thread>, NUM_CPU_CORES - 1> cpu_core_threads; - std::size_t active_core{}; ///< Active core, only used in single thread mode + CpuCoreManager cpu_core_manager; + bool is_powered_on = false; /// Frontend applets std::unique_ptr<Core::Frontend::SoftwareKeyboardApplet> software_keyboard; @@ -307,9 +238,6 @@ struct System::Impl { ResultStatus status = ResultStatus::Success; std::string status_details = ""; - /// Map of guest threads to CPU cores - std::map<std::thread::id, Cpu*> thread_to_cpu; - Core::PerfStats perf_stats; Core::FrameLimiter frame_limiter; }; @@ -334,17 +262,15 @@ System::ResultStatus System::SingleStep() { } void System::InvalidateCpuInstructionCaches() { - for (auto& cpu : impl->cpu_cores) { - cpu->ArmInterface().ClearInstructionCache(); - } + impl->cpu_core_manager.InvalidateAllInstructionCaches(); } System::ResultStatus System::Load(Frontend::EmuWindow& emu_window, const std::string& filepath) { - return impl->Load(emu_window, filepath); + return impl->Load(*this, emu_window, filepath); } bool System::IsPoweredOn() const { - return impl->cpu_barrier && impl->cpu_barrier->IsAlive(); + return impl->is_powered_on; } void System::PrepareReschedule() { @@ -408,21 +334,20 @@ const ARM_Interface& System::ArmInterface(std::size_t core_index) const { } Cpu& System::CpuCore(std::size_t core_index) { - ASSERT(core_index < NUM_CPU_CORES); - return *impl->cpu_cores[core_index]; + return impl->cpu_core_manager.GetCore(core_index); } const Cpu& System::CpuCore(std::size_t core_index) const { ASSERT(core_index < NUM_CPU_CORES); - return *impl->cpu_cores[core_index]; + return impl->cpu_core_manager.GetCore(core_index); } ExclusiveMonitor& System::Monitor() { - return *impl->cpu_exclusive_monitor; + return impl->cpu_core_manager.GetExclusiveMonitor(); } const ExclusiveMonitor& System::Monitor() const { - return *impl->cpu_exclusive_monitor; + return impl->cpu_core_manager.GetExclusiveMonitor(); } Tegra::GPU& System::GPU() { @@ -506,7 +431,7 @@ const Core::Frontend::SoftwareKeyboardApplet& System::GetSoftwareKeyboard() cons } System::ResultStatus System::Init(Frontend::EmuWindow& emu_window) { - return impl->Init(emu_window); + return impl->Init(*this, emu_window); } void System::Shutdown() { diff --git a/src/core/cpu_core_manager.cpp b/src/core/cpu_core_manager.cpp new file mode 100644 index 000000000..769a6fefa --- /dev/null +++ b/src/core/cpu_core_manager.cpp @@ -0,0 +1,142 @@ +// Copyright 2018 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include "common/assert.h" +#include "core/arm/exclusive_monitor.h" +#include "core/core.h" +#include "core/core_cpu.h" +#include "core/cpu_core_manager.h" +#include "core/gdbstub/gdbstub.h" +#include "core/settings.h" + +namespace Core { +namespace { +void RunCpuCore(const System& system, Cpu& cpu_state) { + while (system.IsPoweredOn()) { + cpu_state.RunLoop(true); + } +} +} // Anonymous namespace + +CpuCoreManager::CpuCoreManager() = default; +CpuCoreManager::~CpuCoreManager() = default; + +void CpuCoreManager::Initialize(System& system) { + barrier = std::make_unique<CpuBarrier>(); + exclusive_monitor = Cpu::MakeExclusiveMonitor(cores.size()); + + for (std::size_t index = 0; index < cores.size(); ++index) { + cores[index] = std::make_unique<Cpu>(*exclusive_monitor, *barrier, index); + } + + // Create threads for CPU cores 1-3, and build thread_to_cpu map + // CPU core 0 is run on the main thread + thread_to_cpu[std::this_thread::get_id()] = cores[0].get(); + if (!Settings::values.use_multi_core) { + return; + } + + for (std::size_t index = 0; index < core_threads.size(); ++index) { + core_threads[index] = std::make_unique<std::thread>(RunCpuCore, std::cref(system), + std::ref(*cores[index + 1])); + thread_to_cpu[core_threads[index]->get_id()] = cores[index + 1].get(); + } +} + +void CpuCoreManager::Shutdown() { + barrier->NotifyEnd(); + if (Settings::values.use_multi_core) { + for (auto& thread : core_threads) { + thread->join(); + thread.reset(); + } + } + + thread_to_cpu.clear(); + for (auto& cpu_core : cores) { + cpu_core.reset(); + } + + exclusive_monitor.reset(); + barrier.reset(); +} + +Cpu& CpuCoreManager::GetCore(std::size_t index) { + return *cores.at(index); +} + +const Cpu& CpuCoreManager::GetCore(std::size_t index) const { + return *cores.at(index); +} + +ExclusiveMonitor& CpuCoreManager::GetExclusiveMonitor() { + return *exclusive_monitor; +} + +const ExclusiveMonitor& CpuCoreManager::GetExclusiveMonitor() const { + return *exclusive_monitor; +} + +Cpu& CpuCoreManager::GetCurrentCore() { + if (Settings::values.use_multi_core) { + const auto& search = thread_to_cpu.find(std::this_thread::get_id()); + ASSERT(search != thread_to_cpu.end()); + ASSERT(search->second); + return *search->second; + } + + // Otherwise, use single-threaded mode active_core variable + return *cores[active_core]; +} + +const Cpu& CpuCoreManager::GetCurrentCore() const { + if (Settings::values.use_multi_core) { + const auto& search = thread_to_cpu.find(std::this_thread::get_id()); + ASSERT(search != thread_to_cpu.end()); + ASSERT(search->second); + return *search->second; + } + + // Otherwise, use single-threaded mode active_core variable + return *cores[active_core]; +} + +void CpuCoreManager::RunLoop(bool tight_loop) { + // Update thread_to_cpu in case Core 0 is run from a different host thread + thread_to_cpu[std::this_thread::get_id()] = cores[0].get(); + + if (GDBStub::IsServerEnabled()) { + GDBStub::HandlePacket(); + + // If the loop is halted and we want to step, use a tiny (1) number of instructions to + // execute. Otherwise, get out of the loop function. + if (GDBStub::GetCpuHaltFlag()) { + if (GDBStub::GetCpuStepFlag()) { + tight_loop = false; + } else { + return; + } + } + } + + for (active_core = 0; active_core < NUM_CPU_CORES; ++active_core) { + cores[active_core]->RunLoop(tight_loop); + if (Settings::values.use_multi_core) { + // Cores 1-3 are run on other threads in this mode + break; + } + } + + if (GDBStub::IsServerEnabled()) { + GDBStub::SetCpuStepFlag(false); + } +} + +void CpuCoreManager::InvalidateAllInstructionCaches() { + for (auto& cpu : cores) { + cpu->ArmInterface().ClearInstructionCache(); + } +} + +} // namespace Core diff --git a/src/core/cpu_core_manager.h b/src/core/cpu_core_manager.h new file mode 100644 index 000000000..a4d70ec56 --- /dev/null +++ b/src/core/cpu_core_manager.h @@ -0,0 +1,59 @@ +// Copyright 2018 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include <array> +#include <map> +#include <memory> +#include <thread> + +namespace Core { + +class Cpu; +class CpuBarrier; +class ExclusiveMonitor; +class System; + +class CpuCoreManager { +public: + CpuCoreManager(); + CpuCoreManager(const CpuCoreManager&) = delete; + CpuCoreManager(CpuCoreManager&&) = delete; + + ~CpuCoreManager(); + + CpuCoreManager& operator=(const CpuCoreManager&) = delete; + CpuCoreManager& operator=(CpuCoreManager&&) = delete; + + void Initialize(System& system); + void Shutdown(); + + Cpu& GetCore(std::size_t index); + const Cpu& GetCore(std::size_t index) const; + + Cpu& GetCurrentCore(); + const Cpu& GetCurrentCore() const; + + ExclusiveMonitor& GetExclusiveMonitor(); + const ExclusiveMonitor& GetExclusiveMonitor() const; + + void RunLoop(bool tight_loop); + + void InvalidateAllInstructionCaches(); + +private: + static constexpr std::size_t NUM_CPU_CORES = 4; + + std::unique_ptr<ExclusiveMonitor> exclusive_monitor; + std::unique_ptr<CpuBarrier> barrier; + std::array<std::unique_ptr<Cpu>, NUM_CPU_CORES> cores; + std::array<std::unique_ptr<std::thread>, NUM_CPU_CORES - 1> core_threads; + std::size_t active_core{}; ///< Active core, only used in single thread mode + + /// Map of guest threads to CPU cores + std::map<std::thread::id, Cpu*> thread_to_cpu; +}; + +} // namespace Core diff --git a/src/core/file_sys/card_image.h b/src/core/file_sys/card_image.h index 25f5914b6..a350496f7 100644 --- a/src/core/file_sys/card_image.h +++ b/src/core/file_sys/card_image.h @@ -32,7 +32,18 @@ enum class GamecardSize : u8 { }; struct GamecardInfo { - std::array<u8, 0x70> data; + u64_le firmware_version; + u32_le access_control_flags; + u32_le read_wait_time1; + u32_le read_wait_time2; + u32_le write_wait_time1; + u32_le write_wait_time2; + u32_le firmware_mode; + u32_le cup_version; + std::array<u8, 4> reserved1; + u64_le update_partition_hash; + u64_le cup_id; + std::array<u8, 0x38> reserved2; }; static_assert(sizeof(GamecardInfo) == 0x70, "GamecardInfo has incorrect size."); diff --git a/src/core/hle/kernel/handle_table.cpp b/src/core/hle/kernel/handle_table.cpp index 5ee5c05e3..1bf79b692 100644 --- a/src/core/hle/kernel/handle_table.cpp +++ b/src/core/hle/kernel/handle_table.cpp @@ -12,12 +12,23 @@ #include "core/hle/kernel/thread.h" namespace Kernel { +namespace { +constexpr u16 GetSlot(Handle handle) { + return handle >> 15; +} + +constexpr u16 GetGeneration(Handle handle) { + return handle & 0x7FFF; +} +} // Anonymous namespace HandleTable::HandleTable() { next_generation = 1; Clear(); } +HandleTable::~HandleTable() = default; + ResultVal<Handle> HandleTable::Create(SharedPtr<Object> obj) { DEBUG_ASSERT(obj != nullptr); diff --git a/src/core/hle/kernel/handle_table.h b/src/core/hle/kernel/handle_table.h index 9e2f33e8a..e3f3e3fb8 100644 --- a/src/core/hle/kernel/handle_table.h +++ b/src/core/hle/kernel/handle_table.h @@ -43,6 +43,7 @@ enum KernelHandle : Handle { class HandleTable final : NonCopyable { public: HandleTable(); + ~HandleTable(); /** * Allocates a handle for the given object. @@ -89,18 +90,8 @@ public: void Clear(); private: - /** - * This is the maximum limit of handles allowed per process in CTR-OS. It can be further - * reduced by ExHeader values, but this is not emulated here. - */ - static const std::size_t MAX_COUNT = 4096; - - static u16 GetSlot(Handle handle) { - return handle >> 15; - } - static u16 GetGeneration(Handle handle) { - return handle & 0x7FFF; - } + /// This is the maximum limit of handles allowed per process in Horizon + static constexpr std::size_t MAX_COUNT = 1024; /// Stores the Object referenced by the handle or null if the slot is empty. std::array<SharedPtr<Object>, MAX_COUNT> objects; diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp index 1412257a0..7ca538401 100644 --- a/src/core/hle/kernel/process.cpp +++ b/src/core/hle/kernel/process.cpp @@ -4,6 +4,7 @@ #include <algorithm> #include <memory> +#include <random> #include "common/assert.h" #include "common/logging/log.h" #include "core/core.h" diff --git a/src/core/hle/kernel/process.h b/src/core/hle/kernel/process.h index 230e395ff..ada845c7f 100644 --- a/src/core/hle/kernel/process.h +++ b/src/core/hle/kernel/process.h @@ -8,7 +8,6 @@ #include <bitset> #include <cstddef> #include <memory> -#include <random> #include <string> #include <vector> #include <boost/container/static_vector.hpp> diff --git a/src/core/hle/kernel/shared_memory.cpp b/src/core/hle/kernel/shared_memory.cpp index a016a86b6..0494581f5 100644 --- a/src/core/hle/kernel/shared_memory.cpp +++ b/src/core/hle/kernel/shared_memory.cpp @@ -61,7 +61,7 @@ SharedPtr<SharedMemory> SharedMemory::Create(KernelCore& kernel, SharedPtr<Proce } SharedPtr<SharedMemory> SharedMemory::CreateForApplet( - KernelCore& kernel, std::shared_ptr<std::vector<u8>> heap_block, u32 offset, u32 size, + KernelCore& kernel, std::shared_ptr<std::vector<u8>> heap_block, std::size_t offset, u64 size, MemoryPermission permissions, MemoryPermission other_permissions, std::string name) { SharedPtr<SharedMemory> shared_memory(new SharedMemory(kernel)); @@ -78,10 +78,10 @@ SharedPtr<SharedMemory> SharedMemory::CreateForApplet( return shared_memory; } -ResultCode SharedMemory::Map(Process* target_process, VAddr address, MemoryPermission permissions, +ResultCode SharedMemory::Map(Process& target_process, VAddr address, MemoryPermission permissions, MemoryPermission other_permissions) { const MemoryPermission own_other_permissions = - target_process == owner_process ? this->permissions : this->other_permissions; + &target_process == owner_process ? this->permissions : this->other_permissions; // Automatically allocated memory blocks can only be mapped with other_permissions = DontCare if (base_address == 0 && other_permissions != MemoryPermission::DontCare) { @@ -106,7 +106,7 @@ ResultCode SharedMemory::Map(Process* target_process, VAddr address, MemoryPermi VAddr target_address = address; // Map the memory block into the target process - auto result = target_process->VMManager().MapMemoryBlock( + auto result = target_process.VMManager().MapMemoryBlock( target_address, backing_block, backing_block_offset, size, MemoryState::Shared); if (result.Failed()) { LOG_ERROR( @@ -116,14 +116,14 @@ ResultCode SharedMemory::Map(Process* target_process, VAddr address, MemoryPermi return result.Code(); } - return target_process->VMManager().ReprotectRange(target_address, size, - ConvertPermissions(permissions)); + return target_process.VMManager().ReprotectRange(target_address, size, + ConvertPermissions(permissions)); } -ResultCode SharedMemory::Unmap(Process* target_process, VAddr address) { +ResultCode SharedMemory::Unmap(Process& target_process, VAddr address) { // TODO(Subv): Verify what happens if the application tries to unmap an address that is not // mapped to a SharedMemory. - return target_process->VMManager().UnmapRange(address, size); + return target_process.VMManager().UnmapRange(address, size); } VMAPermission SharedMemory::ConvertPermissions(MemoryPermission permission) { @@ -132,7 +132,11 @@ VMAPermission SharedMemory::ConvertPermissions(MemoryPermission permission) { return static_cast<VMAPermission>(masked_permissions); } -u8* SharedMemory::GetPointer(u32 offset) { +u8* SharedMemory::GetPointer(std::size_t offset) { + return backing_block->data() + backing_block_offset + offset; +} + +const u8* SharedMemory::GetPointer(std::size_t offset) const { return backing_block->data() + backing_block_offset + offset; } diff --git a/src/core/hle/kernel/shared_memory.h b/src/core/hle/kernel/shared_memory.h index 2c06bb7ce..0b48db699 100644 --- a/src/core/hle/kernel/shared_memory.h +++ b/src/core/hle/kernel/shared_memory.h @@ -64,7 +64,7 @@ public: */ static SharedPtr<SharedMemory> CreateForApplet(KernelCore& kernel, std::shared_ptr<std::vector<u8>> heap_block, - u32 offset, u32 size, + std::size_t offset, u64 size, MemoryPermission permissions, MemoryPermission other_permissions, std::string name = "Unknown Applet"); @@ -81,6 +81,11 @@ public: return HANDLE_TYPE; } + /// Gets the size of the underlying memory block in bytes. + u64 GetSize() const { + return size; + } + /** * Converts the specified MemoryPermission into the equivalent VMAPermission. * @param permission The MemoryPermission to convert. @@ -94,44 +99,51 @@ public: * @param permissions Memory block map permissions (specified by SVC field) * @param other_permissions Memory block map other permissions (specified by SVC field) */ - ResultCode Map(Process* target_process, VAddr address, MemoryPermission permissions, + ResultCode Map(Process& target_process, VAddr address, MemoryPermission permissions, MemoryPermission other_permissions); /** * Unmaps a shared memory block from the specified address in system memory - * @param target_process Process from which to umap the memory block. + * @param target_process Process from which to unmap the memory block. * @param address Address in system memory where the shared memory block is mapped * @return Result code of the unmap operation */ - ResultCode Unmap(Process* target_process, VAddr address); + ResultCode Unmap(Process& target_process, VAddr address); /** * Gets a pointer to the shared memory block * @param offset Offset from the start of the shared memory block to get pointer - * @return Pointer to the shared memory block from the specified offset + * @return A pointer to the shared memory block from the specified offset */ - u8* GetPointer(u32 offset = 0); + u8* GetPointer(std::size_t offset = 0); + + /** + * Gets a constant pointer to the shared memory block + * @param offset Offset from the start of the shared memory block to get pointer + * @return A constant pointer to the shared memory block from the specified offset + */ + const u8* GetPointer(std::size_t offset = 0) const; + +private: + explicit SharedMemory(KernelCore& kernel); + ~SharedMemory() override; - /// Process that created this shared memory block. - SharedPtr<Process> owner_process; - /// Address of shared memory block in the owner process if specified. - VAddr base_address; /// Backing memory for this shared memory block. std::shared_ptr<std::vector<u8>> backing_block; /// Offset into the backing block for this shared memory. - std::size_t backing_block_offset; + std::size_t backing_block_offset = 0; /// Size of the memory block. Page-aligned. - u64 size; + u64 size = 0; /// Permission restrictions applied to the process which created the block. - MemoryPermission permissions; + MemoryPermission permissions{}; /// Permission restrictions applied to other processes mapping the block. - MemoryPermission other_permissions; + MemoryPermission other_permissions{}; + /// Process that created this shared memory block. + SharedPtr<Process> owner_process; + /// Address of shared memory block in the owner process if specified. + VAddr base_address = 0; /// Name of shared memory object. std::string name; - -private: - explicit SharedMemory(KernelCore& kernel); - ~SharedMemory() override; }; } // namespace Kernel diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 51c367de7..b8b6b4d49 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp @@ -789,7 +789,7 @@ static ResultCode MapSharedMemory(Handle shared_memory_handle, VAddr addr, u64 s return ERR_INVALID_MEMORY_RANGE; } - return shared_memory->Map(current_process, addr, permissions_type, MemoryPermission::DontCare); + return shared_memory->Map(*current_process, addr, permissions_type, MemoryPermission::DontCare); } static ResultCode UnmapSharedMemory(Handle shared_memory_handle, VAddr addr, u64 size) { @@ -819,7 +819,7 @@ static ResultCode UnmapSharedMemory(Handle shared_memory_handle, VAddr addr, u64 return ERR_INVALID_MEMORY_RANGE; } - return shared_memory->Unmap(current_process, addr); + return shared_memory->Unmap(*current_process, addr); } /// Query process memory diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index fd14af1e7..f4127701f 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp @@ -6,8 +6,6 @@ #include <cinttypes> #include <cstring> #include <stack> -#include "applets/applets.h" -#include "applets/software_keyboard.h" #include "audio_core/audio_renderer.h" #include "core/core.h" #include "core/hle/ipc_helpers.h" @@ -18,6 +16,9 @@ #include "core/hle/service/am/am.h" #include "core/hle/service/am/applet_ae.h" #include "core/hle/service/am/applet_oe.h" +#include "core/hle/service/am/applets/applets.h" +#include "core/hle/service/am/applets/software_keyboard.h" +#include "core/hle/service/am/applets/stub_applet.h" #include "core/hle/service/am/idle.h" #include "core/hle/service/am/omm.h" #include "core/hle/service/am/spsm.h" @@ -532,8 +533,7 @@ void ICommonStateGetter::GetPerformanceMode(Kernel::HLERequestContext& ctx) { class ILibraryAppletAccessor final : public ServiceFramework<ILibraryAppletAccessor> { public: explicit ILibraryAppletAccessor(std::shared_ptr<Applets::Applet> applet) - : ServiceFramework("ILibraryAppletAccessor"), applet(std::move(applet)), - broker(std::make_shared<Applets::AppletDataBroker>()) { + : ServiceFramework("ILibraryAppletAccessor"), applet(std::move(applet)) { // clang-format off static const FunctionInfo functions[] = { {0, &ILibraryAppletAccessor::GetAppletStateChangedEvent, "GetAppletStateChangedEvent"}, @@ -562,7 +562,7 @@ public: private: void GetAppletStateChangedEvent(Kernel::HLERequestContext& ctx) { - const auto event = broker->GetStateChangedEvent(); + const auto event = applet->GetBroker().GetStateChangedEvent(); event->Signal(); IPC::ResponseBuilder rb{ctx, 2, 1}; @@ -590,7 +590,7 @@ private: void Start(Kernel::HLERequestContext& ctx) { ASSERT(applet != nullptr); - applet->Initialize(broker); + applet->Initialize(); applet->Execute(); IPC::ResponseBuilder rb{ctx, 2}; @@ -601,7 +601,7 @@ private: void PushInData(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - broker->PushNormalDataFromGame(*rp.PopIpcInterface<IStorage>()); + applet->GetBroker().PushNormalDataFromGame(*rp.PopIpcInterface<IStorage>()); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(RESULT_SUCCESS); @@ -612,7 +612,7 @@ private: void PopOutData(Kernel::HLERequestContext& ctx) { IPC::ResponseBuilder rb{ctx, 2, 0, 1}; - const auto storage = broker->PopNormalDataToGame(); + const auto storage = applet->GetBroker().PopNormalDataToGame(); if (storage == nullptr) { rb.Push(ERR_NO_DATA_IN_CHANNEL); return; @@ -626,7 +626,7 @@ private: void PushInteractiveInData(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - broker->PushInteractiveDataFromGame(*rp.PopIpcInterface<IStorage>()); + applet->GetBroker().PushInteractiveDataFromGame(*rp.PopIpcInterface<IStorage>()); ASSERT(applet->IsInitialized()); applet->ExecuteInteractive(); @@ -641,7 +641,7 @@ private: void PopInteractiveOutData(Kernel::HLERequestContext& ctx) { IPC::ResponseBuilder rb{ctx, 2, 0, 1}; - const auto storage = broker->PopInteractiveDataToGame(); + const auto storage = applet->GetBroker().PopInteractiveDataToGame(); if (storage == nullptr) { rb.Push(ERR_NO_DATA_IN_CHANNEL); return; @@ -656,7 +656,7 @@ private: void GetPopOutDataEvent(Kernel::HLERequestContext& ctx) { IPC::ResponseBuilder rb{ctx, 2, 1}; rb.Push(RESULT_SUCCESS); - rb.PushCopyObjects(broker->GetNormalDataEvent()); + rb.PushCopyObjects(applet->GetBroker().GetNormalDataEvent()); LOG_DEBUG(Service_AM, "called"); } @@ -664,13 +664,12 @@ private: void GetPopInteractiveOutDataEvent(Kernel::HLERequestContext& ctx) { IPC::ResponseBuilder rb{ctx, 2, 1}; rb.Push(RESULT_SUCCESS); - rb.PushCopyObjects(broker->GetInteractiveDataEvent()); + rb.PushCopyObjects(applet->GetBroker().GetInteractiveDataEvent()); LOG_DEBUG(Service_AM, "called"); } std::shared_ptr<Applets::Applet> applet; - std::shared_ptr<Applets::AppletDataBroker> broker; }; void IStorage::Open(Kernel::HLERequestContext& ctx) { @@ -763,8 +762,9 @@ static std::shared_ptr<Applets::Applet> GetAppletFromId(AppletId id) { case AppletId::SoftwareKeyboard: return std::make_shared<Applets::SoftwareKeyboard>(); default: - UNREACHABLE_MSG("Unimplemented AppletId [{:08X}]!", static_cast<u32>(id)); - return nullptr; + LOG_ERROR(Service_AM, "Unimplemented AppletId [{:08X}]! -- Falling back to stub!", + static_cast<u32>(id)); + return std::make_shared<Applets::StubApplet>(); } } @@ -820,8 +820,8 @@ void ILibraryAppletCreator::CreateTransferMemoryStorage(Kernel::HLERequestContex return; } - const auto mem_begin = shared_mem->backing_block->begin() + shared_mem->backing_block_offset; - const auto mem_end = mem_begin + shared_mem->size; + const u8* mem_begin = shared_mem->GetPointer(); + const u8* mem_end = mem_begin + shared_mem->GetSize(); std::vector<u8> memory{mem_begin, mem_end}; IPC::ResponseBuilder rb{ctx, 2, 0, 1}; diff --git a/src/core/hle/service/am/applets/applets.cpp b/src/core/hle/service/am/applets/applets.cpp index 8adb81823..becbadd06 100644 --- a/src/core/hle/service/am/applets/applets.cpp +++ b/src/core/hle/service/am/applets/applets.cpp @@ -98,10 +98,8 @@ Applet::Applet() = default; Applet::~Applet() = default; -void Applet::Initialize(std::shared_ptr<AppletDataBroker> broker_) { - broker = std::move(broker_); - - const auto common = broker->PopNormalDataToApplet(); +void Applet::Initialize() { + const auto common = broker.PopNormalDataToApplet(); ASSERT(common != nullptr); const auto common_data = common->GetData(); diff --git a/src/core/hle/service/am/applets/applets.h b/src/core/hle/service/am/applets/applets.h index 136445649..f65ea119c 100644 --- a/src/core/hle/service/am/applets/applets.h +++ b/src/core/hle/service/am/applets/applets.h @@ -4,14 +4,17 @@ #pragma once -#include <functional> #include <memory> #include <queue> #include "common/swap.h" -#include "core/hle/kernel/event.h" +#include "core/hle/kernel/kernel.h" union ResultCode; +namespace Kernel { +class Event; +} + namespace Service::AM { class IStorage; @@ -43,19 +46,26 @@ public: private: // Queues are named from applet's perspective - std::queue<std::unique_ptr<IStorage>> - in_channel; // PopNormalDataToApplet and PushNormalDataFromGame - std::queue<std::unique_ptr<IStorage>> - out_channel; // PopNormalDataToGame and PushNormalDataFromApplet - std::queue<std::unique_ptr<IStorage>> - in_interactive_channel; // PopInteractiveDataToApplet and PushInteractiveDataFromGame - std::queue<std::unique_ptr<IStorage>> - out_interactive_channel; // PopInteractiveDataToGame and PushInteractiveDataFromApplet + + // PopNormalDataToApplet and PushNormalDataFromGame + std::queue<std::unique_ptr<IStorage>> in_channel; + + // PopNormalDataToGame and PushNormalDataFromApplet + std::queue<std::unique_ptr<IStorage>> out_channel; + + // PopInteractiveDataToApplet and PushInteractiveDataFromGame + std::queue<std::unique_ptr<IStorage>> in_interactive_channel; + + // PopInteractiveDataToGame and PushInteractiveDataFromApplet + std::queue<std::unique_ptr<IStorage>> out_interactive_channel; Kernel::SharedPtr<Kernel::Event> state_changed_event; - Kernel::SharedPtr<Kernel::Event> pop_out_data_event; // Signaled on PushNormalDataFromApplet - Kernel::SharedPtr<Kernel::Event> - pop_interactive_out_data_event; // Signaled on PushInteractiveDataFromApplet + + // Signaled on PushNormalDataFromApplet + Kernel::SharedPtr<Kernel::Event> pop_out_data_event; + + // Signaled on PushInteractiveDataFromApplet + Kernel::SharedPtr<Kernel::Event> pop_interactive_out_data_event; }; class Applet { @@ -63,7 +73,7 @@ public: Applet(); virtual ~Applet(); - virtual void Initialize(std::shared_ptr<AppletDataBroker> broker); + virtual void Initialize(); virtual bool TransactionComplete() const = 0; virtual ResultCode GetStatus() const = 0; @@ -74,6 +84,14 @@ public: return initialized; } + AppletDataBroker& GetBroker() { + return broker; + } + + const AppletDataBroker& GetBroker() const { + return broker; + } + protected: struct CommonArguments { u32_le arguments_version; @@ -85,8 +103,8 @@ protected: }; static_assert(sizeof(CommonArguments) == 0x20, "CommonArguments has incorrect size."); - CommonArguments common_args; - std::shared_ptr<AppletDataBroker> broker; + CommonArguments common_args{}; + AppletDataBroker broker; bool initialized = false; }; diff --git a/src/core/hle/service/am/applets/software_keyboard.cpp b/src/core/hle/service/am/applets/software_keyboard.cpp index c4b76a515..981bdec51 100644 --- a/src/core/hle/service/am/applets/software_keyboard.cpp +++ b/src/core/hle/service/am/applets/software_keyboard.cpp @@ -42,21 +42,21 @@ SoftwareKeyboard::SoftwareKeyboard() = default; SoftwareKeyboard::~SoftwareKeyboard() = default; -void SoftwareKeyboard::Initialize(std::shared_ptr<AppletDataBroker> broker_) { +void SoftwareKeyboard::Initialize() { complete = false; initial_text.clear(); final_data.clear(); - Applet::Initialize(std::move(broker_)); + Applet::Initialize(); - const auto keyboard_config_storage = broker->PopNormalDataToApplet(); + const auto keyboard_config_storage = broker.PopNormalDataToApplet(); ASSERT(keyboard_config_storage != nullptr); const auto& keyboard_config = keyboard_config_storage->GetData(); ASSERT(keyboard_config.size() >= sizeof(KeyboardConfig)); std::memcpy(&config, keyboard_config.data(), sizeof(KeyboardConfig)); - const auto work_buffer_storage = broker->PopNormalDataToApplet(); + const auto work_buffer_storage = broker.PopNormalDataToApplet(); ASSERT(work_buffer_storage != nullptr); const auto& work_buffer = work_buffer_storage->GetData(); @@ -81,7 +81,7 @@ void SoftwareKeyboard::ExecuteInteractive() { if (complete) return; - const auto storage = broker->PopInteractiveDataToApplet(); + const auto storage = broker.PopInteractiveDataToApplet(); ASSERT(storage != nullptr); const auto data = storage->GetData(); const auto status = static_cast<bool>(data[0]); @@ -95,13 +95,13 @@ void SoftwareKeyboard::ExecuteInteractive() { std::memcpy(string.data(), data.data() + 4, string.size() * 2); frontend.SendTextCheckDialog( Common::UTF16StringFromFixedZeroTerminatedBuffer(string.data(), string.size()), - [this] { broker->SignalStateChanged(); }); + [this] { broker.SignalStateChanged(); }); } } void SoftwareKeyboard::Execute() { if (complete) { - broker->PushNormalDataFromApplet(IStorage{final_data}); + broker.PushNormalDataFromApplet(IStorage{final_data}); return; } @@ -145,17 +145,17 @@ void SoftwareKeyboard::WriteText(std::optional<std::u16string> text) { final_data = output_main; if (complete) { - broker->PushNormalDataFromApplet(IStorage{output_main}); + broker.PushNormalDataFromApplet(IStorage{output_main}); } else { - broker->PushInteractiveDataFromApplet(IStorage{output_sub}); + broker.PushInteractiveDataFromApplet(IStorage{output_sub}); } - broker->SignalStateChanged(); + broker.SignalStateChanged(); } else { output_main[0] = 1; complete = true; - broker->PushNormalDataFromApplet(IStorage{output_main}); - broker->SignalStateChanged(); + broker.PushNormalDataFromApplet(IStorage{output_main}); + broker.SignalStateChanged(); } } } // namespace Service::AM::Applets diff --git a/src/core/hle/service/am/applets/software_keyboard.h b/src/core/hle/service/am/applets/software_keyboard.h index 16e1fff66..efd5753a1 100644 --- a/src/core/hle/service/am/applets/software_keyboard.h +++ b/src/core/hle/service/am/applets/software_keyboard.h @@ -4,7 +4,12 @@ #pragma once +#include <array> +#include <string> +#include <vector> + #include "common/common_funcs.h" +#include "common/swap.h" #include "core/hle/service/am/am.h" #include "core/hle/service/am/applets/applets.h" @@ -50,7 +55,7 @@ public: SoftwareKeyboard(); ~SoftwareKeyboard() override; - void Initialize(std::shared_ptr<AppletDataBroker> broker) override; + void Initialize() override; bool TransactionComplete() const override; ResultCode GetStatus() const override; diff --git a/src/core/hle/service/am/applets/stub_applet.cpp b/src/core/hle/service/am/applets/stub_applet.cpp new file mode 100644 index 000000000..ed166b87d --- /dev/null +++ b/src/core/hle/service/am/applets/stub_applet.cpp @@ -0,0 +1,70 @@ +// Copyright 2018 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include <string> + +#include "common/hex_util.h" +#include "common/logging/log.h" +#include "core/hle/result.h" +#include "core/hle/service/am/am.h" +#include "core/hle/service/am/applets/stub_applet.h" + +namespace Service::AM::Applets { + +static void LogCurrentStorage(AppletDataBroker& broker, std::string prefix) { + std::unique_ptr<IStorage> storage = broker.PopNormalDataToApplet(); + for (; storage != nullptr; storage = broker.PopNormalDataToApplet()) { + const auto data = storage->GetData(); + LOG_INFO(Service_AM, + "called (STUBBED), during {} recieved normal data with size={:08X}, data={}", + prefix, data.size(), Common::HexVectorToString(data)); + } + + storage = broker.PopInteractiveDataToApplet(); + for (; storage != nullptr; storage = broker.PopInteractiveDataToApplet()) { + const auto data = storage->GetData(); + LOG_INFO(Service_AM, + "called (STUBBED), during {} recieved interactive data with size={:08X}, data={}", + prefix, data.size(), Common::HexVectorToString(data)); + } +} + +StubApplet::StubApplet() = default; + +StubApplet::~StubApplet() = default; + +void StubApplet::Initialize() { + LOG_WARNING(Service_AM, "called (STUBBED)"); + Applet::Initialize(); + LogCurrentStorage(broker, "Initialize"); +} + +bool StubApplet::TransactionComplete() const { + LOG_WARNING(Service_AM, "called (STUBBED)"); + return true; +} + +ResultCode StubApplet::GetStatus() const { + LOG_WARNING(Service_AM, "called (STUBBED)"); + return RESULT_SUCCESS; +} + +void StubApplet::ExecuteInteractive() { + LOG_WARNING(Service_AM, "called (STUBBED)"); + LogCurrentStorage(broker, "ExecuteInteractive"); + + broker.PushNormalDataFromApplet(IStorage{std::vector<u8>(0x1000)}); + broker.PushInteractiveDataFromApplet(IStorage{std::vector<u8>(0x1000)}); + broker.SignalStateChanged(); +} + +void StubApplet::Execute() { + LOG_WARNING(Service_AM, "called (STUBBED)"); + LogCurrentStorage(broker, "Execute"); + + broker.PushNormalDataFromApplet(IStorage{std::vector<u8>(0x1000)}); + broker.PushInteractiveDataFromApplet(IStorage{std::vector<u8>(0x1000)}); + broker.SignalStateChanged(); +} +} // namespace Service::AM::Applets diff --git a/src/core/hle/service/am/applets/stub_applet.h b/src/core/hle/service/am/applets/stub_applet.h new file mode 100644 index 000000000..7d8dc968d --- /dev/null +++ b/src/core/hle/service/am/applets/stub_applet.h @@ -0,0 +1,24 @@ +// Copyright 2018 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include "core/hle/service/am/applets/applets.h" + +namespace Service::AM::Applets { + +class StubApplet final : public Applet { +public: + StubApplet(); + ~StubApplet() override; + + void Initialize() override; + + bool TransactionComplete() const override; + ResultCode GetStatus() const override; + void ExecuteInteractive() override; + void Execute() override; +}; + +} // namespace Service::AM::Applets diff --git a/src/core/hle/service/audio/audout_u.cpp b/src/core/hle/service/audio/audout_u.cpp index ff1edefbb..23e1f1165 100644 --- a/src/core/hle/service/audio/audout_u.cpp +++ b/src/core/hle/service/audio/audout_u.cpp @@ -44,8 +44,10 @@ enum class AudioState : u32 { class IAudioOut final : public ServiceFramework<IAudioOut> { public: - IAudioOut(AudoutParams audio_params, AudioCore::AudioOut& audio_core) - : ServiceFramework("IAudioOut"), audio_core(audio_core), audio_params(audio_params) { + IAudioOut(AudoutParams audio_params, AudioCore::AudioOut& audio_core, std::string&& device_name, + std::string&& unique_name) + : ServiceFramework("IAudioOut"), audio_core(audio_core), audio_params(audio_params), + device_name(std::move(device_name)) { static const FunctionInfo functions[] = { {0, &IAudioOut::GetAudioOutState, "GetAudioOutState"}, @@ -69,7 +71,7 @@ public: Kernel::Event::Create(kernel, Kernel::ResetType::Sticky, "IAudioOutBufferReleased"); stream = audio_core.OpenStream(audio_params.sample_rate, audio_params.channel_count, - "IAudioOut", [=]() { buffer_event->Signal(); }); + std::move(unique_name), [=]() { buffer_event->Signal(); }); } private: @@ -177,6 +179,7 @@ private: AudioCore::AudioOut& audio_core; AudioCore::StreamPtr stream; + std::string device_name; AudoutParams audio_params{}; @@ -199,7 +202,15 @@ void AudOutU::ListAudioOutsImpl(Kernel::HLERequestContext& ctx) { void AudOutU::OpenAudioOutImpl(Kernel::HLERequestContext& ctx) { LOG_DEBUG(Service_Audio, "called"); - ctx.WriteBuffer(DefaultDevice); + const auto device_name_data{ctx.ReadBuffer()}; + std::string device_name; + if (device_name_data[0] != '\0') { + device_name.assign(device_name_data.begin(), device_name_data.end()); + } else { + device_name.assign(DefaultDevice.begin(), DefaultDevice.end()); + } + ctx.WriteBuffer(device_name); + IPC::RequestParser rp{ctx}; auto params{rp.PopRaw<AudoutParams>()}; if (params.channel_count <= 2) { @@ -212,10 +223,9 @@ void AudOutU::OpenAudioOutImpl(Kernel::HLERequestContext& ctx) { params.sample_rate = DefaultSampleRate; } - // TODO(bunnei): Support more than one IAudioOut interface. When we add this, ListAudioOutsImpl - // will likely need to be updated as well. - ASSERT_MSG(!audio_out_interface, "Unimplemented"); - audio_out_interface = std::make_shared<IAudioOut>(params, *audio_core); + std::string unique_name{fmt::format("{}-{}", device_name, audio_out_interfaces.size())}; + auto audio_out_interface = std::make_shared<IAudioOut>( + params, *audio_core, std::move(device_name), std::move(unique_name)); IPC::ResponseBuilder rb{ctx, 6, 0, 1}; rb.Push(RESULT_SUCCESS); @@ -224,6 +234,8 @@ void AudOutU::OpenAudioOutImpl(Kernel::HLERequestContext& ctx) { rb.Push<u32>(static_cast<u32>(AudioCore::Codec::PcmFormat::Int16)); rb.Push<u32>(static_cast<u32>(AudioState::Stopped)); rb.PushIpcInterface<Audio::IAudioOut>(audio_out_interface); + + audio_out_interfaces.push_back(std::move(audio_out_interface)); } AudOutU::AudOutU() : ServiceFramework("audout:u") { diff --git a/src/core/hle/service/audio/audout_u.h b/src/core/hle/service/audio/audout_u.h index dcaf64708..aed4c43b2 100644 --- a/src/core/hle/service/audio/audout_u.h +++ b/src/core/hle/service/audio/audout_u.h @@ -4,6 +4,7 @@ #pragma once +#include <vector> #include "core/hle/service/service.h" namespace AudioCore { @@ -24,7 +25,7 @@ public: ~AudOutU() override; private: - std::shared_ptr<IAudioOut> audio_out_interface; + std::vector<std::shared_ptr<IAudioOut>> audio_out_interfaces; std::unique_ptr<AudioCore::AudioOut> audio_core; void ListAudioOutsImpl(Kernel::HLERequestContext& ctx); diff --git a/src/core/hle/service/hid/controllers/debug_pad.cpp b/src/core/hle/service/hid/controllers/debug_pad.cpp index e76c83aee..c22357d8c 100644 --- a/src/core/hle/service/hid/controllers/debug_pad.cpp +++ b/src/core/hle/service/hid/controllers/debug_pad.cpp @@ -71,8 +71,9 @@ void Controller_DebugPad::OnUpdate(u8* data, std::size_t size) { void Controller_DebugPad::OnLoadInputDevices() { std::transform(Settings::values.debug_pad_buttons.begin(), - Settings::values.debug_pad_buttons.end(), buttons.begin(), - Input::CreateDevice<Input::ButtonDevice>); + Settings::values.debug_pad_buttons.begin() + + Settings::NativeButton::NUM_BUTTONS_HID, + buttons.begin(), Input::CreateDevice<Input::ButtonDevice>); std::transform(Settings::values.debug_pad_analogs.begin(), Settings::values.debug_pad_analogs.end(), analogs.begin(), Input::CreateDevice<Input::AnalogDevice>); diff --git a/src/core/hle/service/ldr/ldr.cpp b/src/core/hle/service/ldr/ldr.cpp index b43f1f054..7a9d0d0dd 100644 --- a/src/core/hle/service/ldr/ldr.cpp +++ b/src/core/hle/service/ldr/ldr.cpp @@ -16,35 +16,18 @@ namespace Service::LDR { -namespace ErrCodes { -enum { - InvalidMemoryState = 51, - InvalidNRO = 52, - InvalidNRR = 53, - MissingNRRHash = 54, - MaximumNRO = 55, - MaximumNRR = 56, - AlreadyLoaded = 57, - InvalidAlignment = 81, - InvalidSize = 82, - InvalidNROAddress = 84, - InvalidNRRAddress = 85, - NotInitialized = 87, -}; -} - -constexpr ResultCode ERROR_INVALID_MEMORY_STATE(ErrorModule::Loader, ErrCodes::InvalidMemoryState); -constexpr ResultCode ERROR_INVALID_NRO(ErrorModule::Loader, ErrCodes::InvalidNRO); -constexpr ResultCode ERROR_INVALID_NRR(ErrorModule::Loader, ErrCodes::InvalidNRR); -constexpr ResultCode ERROR_MISSING_NRR_HASH(ErrorModule::Loader, ErrCodes::MissingNRRHash); -constexpr ResultCode ERROR_MAXIMUM_NRO(ErrorModule::Loader, ErrCodes::MaximumNRO); -constexpr ResultCode ERROR_MAXIMUM_NRR(ErrorModule::Loader, ErrCodes::MaximumNRR); -constexpr ResultCode ERROR_ALREADY_LOADED(ErrorModule::Loader, ErrCodes::AlreadyLoaded); -constexpr ResultCode ERROR_INVALID_ALIGNMENT(ErrorModule::Loader, ErrCodes::InvalidAlignment); -constexpr ResultCode ERROR_INVALID_SIZE(ErrorModule::Loader, ErrCodes::InvalidSize); -constexpr ResultCode ERROR_INVALID_NRO_ADDRESS(ErrorModule::Loader, ErrCodes::InvalidNROAddress); -constexpr ResultCode ERROR_INVALID_NRR_ADDRESS(ErrorModule::Loader, ErrCodes::InvalidNRRAddress); -constexpr ResultCode ERROR_NOT_INITIALIZED(ErrorModule::Loader, ErrCodes::NotInitialized); +constexpr ResultCode ERROR_INVALID_MEMORY_STATE{ErrorModule::Loader, 51}; +constexpr ResultCode ERROR_INVALID_NRO{ErrorModule::Loader, 52}; +constexpr ResultCode ERROR_INVALID_NRR{ErrorModule::Loader, 53}; +constexpr ResultCode ERROR_MISSING_NRR_HASH{ErrorModule::Loader, 54}; +constexpr ResultCode ERROR_MAXIMUM_NRO{ErrorModule::Loader, 55}; +constexpr ResultCode ERROR_MAXIMUM_NRR{ErrorModule::Loader, 56}; +constexpr ResultCode ERROR_ALREADY_LOADED{ErrorModule::Loader, 57}; +constexpr ResultCode ERROR_INVALID_ALIGNMENT{ErrorModule::Loader, 81}; +constexpr ResultCode ERROR_INVALID_SIZE{ErrorModule::Loader, 82}; +constexpr ResultCode ERROR_INVALID_NRO_ADDRESS{ErrorModule::Loader, 84}; +constexpr ResultCode ERROR_INVALID_NRR_ADDRESS{ErrorModule::Loader, 85}; +constexpr ResultCode ERROR_NOT_INITIALIZED{ErrorModule::Loader, 87}; constexpr u64 MAXIMUM_LOADED_RO = 0x40; diff --git a/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.cpp b/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.cpp index 7a88ae029..792d26e52 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.cpp +++ b/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.cpp @@ -5,6 +5,8 @@ #include <cstring> #include "common/assert.h" #include "common/logging/log.h" +#include "core/core_timing.h" +#include "core/core_timing_util.h" #include "core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.h" namespace Service::Nvidia::Devices { @@ -33,6 +35,8 @@ u32 nvhost_ctrl_gpu::ioctl(Ioctl command, const std::vector<u8>& input, std::vec return ZBCQueryTable(input, output); case IoctlCommand::IocFlushL2: return FlushL2(input, output); + case IoctlCommand::IocGetGpuTime: + return GetGpuTime(input, output); } UNIMPLEMENTED_MSG("Unimplemented ioctl"); return 0; @@ -169,4 +173,13 @@ u32 nvhost_ctrl_gpu::FlushL2(const std::vector<u8>& input, std::vector<u8>& outp return 0; } +u32 nvhost_ctrl_gpu::GetGpuTime(const std::vector<u8>& input, std::vector<u8>& output) { + LOG_DEBUG(Service_NVDRV, "called"); + IoctlGetGpuTime params{}; + std::memcpy(¶ms, input.data(), input.size()); + params.gpu_time = CoreTiming::cyclesToNs(CoreTiming::GetTicks()); + std::memcpy(output.data(), ¶ms, output.size()); + return 0; +} + } // namespace Service::Nvidia::Devices diff --git a/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.h b/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.h index 3bbf028ad..240435eea 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.h +++ b/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.h @@ -156,6 +156,11 @@ private: }; static_assert(sizeof(IoctlFlushL2) == 8, "IoctlFlushL2 is incorrect size"); + struct IoctlGetGpuTime { + u64_le gpu_time; + }; + static_assert(sizeof(IoctlGetGpuTime) == 8, "IoctlGetGpuTime is incorrect size"); + u32 GetCharacteristics(const std::vector<u8>& input, std::vector<u8>& output); u32 GetTPCMasks(const std::vector<u8>& input, std::vector<u8>& output); u32 GetActiveSlotMask(const std::vector<u8>& input, std::vector<u8>& output); @@ -164,6 +169,7 @@ private: u32 ZBCSetTable(const std::vector<u8>& input, std::vector<u8>& output); u32 ZBCQueryTable(const std::vector<u8>& input, std::vector<u8>& output); u32 FlushL2(const std::vector<u8>& input, std::vector<u8>& output); + u32 GetGpuTime(const std::vector<u8>& input, std::vector<u8>& output); }; } // namespace Service::Nvidia::Devices |