diff options
Diffstat (limited to 'src/core')
80 files changed, 657 insertions, 171 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 4cdfffecb..7153c4f3f 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -1,7 +1,5 @@ add_library(core STATIC arm/arm_interface.h - arm/dynarmic/arm_dynarmic.cpp - arm/dynarmic/arm_dynarmic.h arm/unicorn/arm_unicorn.cpp arm/unicorn/arm_unicorn.h core.cpp @@ -124,6 +122,8 @@ add_library(core STATIC hle/service/pctl/pctl_a.h hle/service/service.cpp hle/service/service.h + hle/service/set/set.cpp + hle/service/set/set.h hle/service/sm/controller.cpp hle/service/sm/controller.h hle/service/sm/sm.cpp @@ -135,6 +135,10 @@ add_library(core STATIC hle/service/sockets/sockets.h hle/service/time/time.cpp hle/service/time/time.h + hle/service/time/time_s.cpp + hle/service/time/time_s.h + hle/service/time/time_u.cpp + hle/service/time/time_u.h hle/service/vi/vi.cpp hle/service/vi/vi.h hle/service/vi/vi_m.cpp @@ -145,6 +149,8 @@ add_library(core STATIC hw/hw.h hw/lcd.cpp hw/lcd.h + loader/deconstructed_rom_directory.cpp + loader/deconstructed_rom_directory.h loader/elf.cpp loader/elf.h loader/linker.cpp @@ -172,5 +178,13 @@ add_library(core STATIC create_target_directory_groups(core) -target_link_libraries(core PUBLIC common PRIVATE dynarmic video_core) +target_link_libraries(core PUBLIC common PRIVATE video_core) target_link_libraries(core PUBLIC Boost::boost PRIVATE fmt lz4_static unicorn) + +if (ARCHITECTURE_x86_64) + target_sources(core PRIVATE + arm/dynarmic/arm_dynarmic.cpp + arm/dynarmic/arm_dynarmic.h + ) + target_link_libraries(core PRIVATE dynarmic) +endif() diff --git a/src/core/arm/dynarmic/arm_dynarmic.cpp b/src/core/arm/dynarmic/arm_dynarmic.cpp index 2ad48dcc7..72c54f984 100644 --- a/src/core/arm/dynarmic/arm_dynarmic.cpp +++ b/src/core/arm/dynarmic/arm_dynarmic.cpp @@ -46,7 +46,7 @@ public: ARM_Interface::ThreadContext ctx; parent.SaveContext(ctx); parent.inner_unicorn.LoadContext(ctx); - parent.inner_unicorn.ExecuteInstructions(num_instructions); + parent.inner_unicorn.ExecuteInstructions(static_cast<int>(num_instructions)); parent.inner_unicorn.SaveContext(ctx); parent.LoadContext(ctx); num_interpreted_instructions += num_instructions; @@ -163,9 +163,9 @@ void ARM_Dynarmic::LoadContext(const ARM_Interface::ThreadContext& ctx) { jit.SetRegisters(ctx.cpu_registers); jit.SetSP(ctx.sp); jit.SetPC(ctx.pc); - jit.SetPstate(ctx.cpsr); + jit.SetPstate(static_cast<u32>(ctx.cpsr)); jit.SetVectors(ctx.fpu_registers); - jit.SetFpcr(ctx.fpscr); + jit.SetFpcr(static_cast<u32>(ctx.fpscr)); cb->tpidrr0_el0 = ctx.tls_address; } diff --git a/src/core/core.cpp b/src/core/core.cpp index ae1eb2430..0ba44b111 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -5,7 +5,9 @@ #include <memory> #include <utility> #include "common/logging/log.h" +#ifdef ARCHITECTURE_x86_64 #include "core/arm/dynarmic/arm_dynarmic.h" +#endif #include "core/arm/unicorn/arm_unicorn.h" #include "core/core.h" #include "core/core_timing.h" @@ -144,7 +146,12 @@ System::ResultStatus System::Init(EmuWindow* emu_window, u32 system_mode) { break; case Settings::CpuCore::Dynarmic: default: +#ifdef ARCHITECTURE_x86_64 cpu_core = std::make_unique<ARM_Dynarmic>(); +#else + cpu_core = std::make_unique<ARM_Unicorn>(); + LOG_WARNING(Core, "CPU JIT requested, but Dynarmic not available"); +#endif break; } diff --git a/src/core/core_timing.cpp b/src/core/core_timing.cpp index a0656f0a8..9e1bf2d0e 100644 --- a/src/core/core_timing.cpp +++ b/src/core/core_timing.cpp @@ -122,7 +122,7 @@ u64 GetTicks() { } void AddTicks(u64 ticks) { - downcount -= ticks; + downcount -= static_cast<int>(ticks); } u64 GetIdleTicks() { @@ -208,7 +208,7 @@ void Advance() { Event evt = std::move(event_queue.front()); std::pop_heap(event_queue.begin(), event_queue.end(), std::greater<Event>()); event_queue.pop_back(); - evt.type->callback(evt.userdata, global_timer - evt.time); + evt.type->callback(evt.userdata, static_cast<int>(global_timer - evt.time)); } is_global_timer_sane = false; diff --git a/src/core/file_sys/archive_backend.cpp b/src/core/file_sys/archive_backend.cpp index 87a240d7a..fc472b44f 100644 --- a/src/core/file_sys/archive_backend.cpp +++ b/src/core/file_sys/archive_backend.cpp @@ -119,4 +119,4 @@ std::vector<u8> Path::AsBinary() const { return {}; } } -} +} // namespace FileSys diff --git a/src/core/gdbstub/gdbstub.cpp b/src/core/gdbstub/gdbstub.cpp index 05c872d89..2f3ccb689 100644 --- a/src/core/gdbstub/gdbstub.cpp +++ b/src/core/gdbstub/gdbstub.cpp @@ -183,11 +183,11 @@ static u8 NibbleToHex(u8 n) { } /** -* Converts input hex string characters into an array of equivalent of u8 bytes. -* -* @param src Pointer to array of output hex string characters. -* @param len Length of src array. -*/ + * Converts input hex string characters into an array of equivalent of u8 bytes. + * + * @param src Pointer to array of output hex string characters. + * @param len Length of src array. + */ static u32 HexToInt(const u8* src, size_t len) { u32 output = 0; while (len-- > 0) { @@ -299,17 +299,17 @@ static std::map<u32, Breakpoint>& GetBreakpointList(BreakpointType type) { static void RemoveBreakpoint(BreakpointType type, PAddr addr) { std::map<u32, Breakpoint>& p = GetBreakpointList(type); - auto bp = p.find(addr); + auto bp = p.find(static_cast<u32>(addr)); if (bp != p.end()) { LOG_DEBUG(Debug_GDBStub, "gdb: removed a breakpoint: %08x bytes at %08x of type %d\n", bp->second.len, bp->second.addr, type); - p.erase(addr); + p.erase(static_cast<u32>(addr)); } } BreakpointAddress GetNextBreakpointFromAddress(PAddr addr, BreakpointType type) { std::map<u32, Breakpoint>& p = GetBreakpointList(type); - auto next_breakpoint = p.lower_bound(addr); + auto next_breakpoint = p.lower_bound(static_cast<u32>(addr)); BreakpointAddress breakpoint; if (next_breakpoint != p.end()) { @@ -330,7 +330,7 @@ bool CheckBreakpoint(PAddr addr, BreakpointType type) { std::map<u32, Breakpoint>& p = GetBreakpointList(type); - auto bp = p.find(addr); + auto bp = p.find(static_cast<u32>(addr)); if (bp != p.end()) { u32 len = bp->second.len; @@ -452,7 +452,8 @@ static void SendSignal(u32 signal) { std::string buffer = Common::StringFromFormat("T%02x%02x:%08x;%02x:%08x;", latest_signal, 15, - htonl(Core::CPU().GetPC()), 13, htonl(Core::CPU().GetReg(13))); + htonl(static_cast<u_long>(Core::CPU().GetPC())), 13, + htonl(static_cast<u_long>(Core::CPU().GetReg(13)))); LOG_DEBUG(Debug_GDBStub, "Response: %s", buffer.c_str()); SendReply(buffer.c_str()); } @@ -539,7 +540,7 @@ static void ReadRegister() { } if (id <= R15_REGISTER) { - IntToGdbHex(reply, Core::CPU().GetReg(id)); + IntToGdbHex(reply, static_cast<u32>(Core::CPU().GetReg(static_cast<u64>(id)))); } else if (id == CPSR_REGISTER) { IntToGdbHex(reply, Core::CPU().GetCPSR()); } else if (id > CPSR_REGISTER && id < FPSCR_REGISTER) { @@ -563,7 +564,7 @@ static void ReadRegisters() { u8* bufptr = buffer; for (int reg = 0; reg <= R15_REGISTER; reg++) { - IntToGdbHex(bufptr + reg * CHAR_BIT, Core::CPU().GetReg(reg)); + IntToGdbHex(bufptr + reg * CHAR_BIT, static_cast<u32>(Core::CPU().GetReg(reg))); } bufptr += (16 * CHAR_BIT); @@ -1034,4 +1035,4 @@ bool GetCpuStepFlag() { void SetCpuStepFlag(bool is_step) { step_loop = is_step; } -}; +}; // namespace GDBStub diff --git a/src/core/gdbstub/gdbstub.h b/src/core/gdbstub/gdbstub.h index 8f12c6a1d..201fca095 100644 --- a/src/core/gdbstub/gdbstub.h +++ b/src/core/gdbstub/gdbstub.h @@ -91,4 +91,4 @@ bool GetCpuStepFlag(); * @param is_step */ void SetCpuStepFlag(bool is_step); -} +} // namespace GDBStub diff --git a/src/core/hle/config_mem.cpp b/src/core/hle/config_mem.cpp index e386ccdc6..038af7909 100644 --- a/src/core/hle/config_mem.cpp +++ b/src/core/hle/config_mem.cpp @@ -28,4 +28,4 @@ void Init() { config_mem.firm_ctr_sdk_ver = 0x0000F297; } -} // namespace +} // namespace ConfigMem diff --git a/src/core/hle/config_mem.h b/src/core/hle/config_mem.h index 42fa6d789..1840d1760 100644 --- a/src/core/hle/config_mem.h +++ b/src/core/hle/config_mem.h @@ -53,4 +53,4 @@ extern ConfigMemDef config_mem; void Init(); -} // namespace +} // namespace ConfigMem diff --git a/src/core/hle/kernel/address_arbiter.h b/src/core/hle/kernel/address_arbiter.h index 1d24401b1..f902ddf2d 100644 --- a/src/core/hle/kernel/address_arbiter.h +++ b/src/core/hle/kernel/address_arbiter.h @@ -57,4 +57,4 @@ private: ~AddressArbiter() override; }; -} // namespace FileSys +} // namespace Kernel diff --git a/src/core/hle/kernel/client_port.cpp b/src/core/hle/kernel/client_port.cpp index ce5d94e99..fb2b6f7a3 100644 --- a/src/core/hle/kernel/client_port.cpp +++ b/src/core/hle/kernel/client_port.cpp @@ -39,4 +39,4 @@ ResultVal<SharedPtr<ClientSession>> ClientPort::Connect() { return MakeResult(std::get<SharedPtr<ClientSession>>(sessions)); } -} // namespace +} // namespace Kernel diff --git a/src/core/hle/kernel/client_port.h b/src/core/hle/kernel/client_port.h index 8f7d6ac44..a829aeb6d 100644 --- a/src/core/hle/kernel/client_port.h +++ b/src/core/hle/kernel/client_port.h @@ -47,4 +47,4 @@ private: ~ClientPort() override; }; -} // namespace +} // namespace Kernel diff --git a/src/core/hle/kernel/client_session.cpp b/src/core/hle/kernel/client_session.cpp index 646a5cc64..72773d8b1 100644 --- a/src/core/hle/kernel/client_session.cpp +++ b/src/core/hle/kernel/client_session.cpp @@ -48,4 +48,4 @@ ResultCode ClientSession::SendSyncRequest(SharedPtr<Thread> thread) { return server->HandleSyncRequest(std::move(thread)); } -} // namespace +} // namespace Kernel diff --git a/src/core/hle/kernel/client_session.h b/src/core/hle/kernel/client_session.h index 671174ec4..d6ab4f893 100644 --- a/src/core/hle/kernel/client_session.h +++ b/src/core/hle/kernel/client_session.h @@ -45,4 +45,4 @@ private: ~ClientSession() override; }; -} // namespace +} // namespace Kernel diff --git a/src/core/hle/kernel/condition_variable.cpp b/src/core/hle/kernel/condition_variable.cpp index 5942eae61..561666384 100644 --- a/src/core/hle/kernel/condition_variable.cpp +++ b/src/core/hle/kernel/condition_variable.cpp @@ -43,7 +43,7 @@ void ConditionVariable::Acquire(Thread* thread) { ResultCode ConditionVariable::Release(s32 target) { if (target == -1) { // When -1, wake up all waiting threads - SetAvailableCount(GetWaitingThreads().size()); + SetAvailableCount(static_cast<s32>(GetWaitingThreads().size())); WakeupAllWaitingThreads(); } else { // Otherwise, wake up just a single thread diff --git a/src/core/hle/kernel/condition_variable.h b/src/core/hle/kernel/condition_variable.h index 0610a284f..0d54031cb 100644 --- a/src/core/hle/kernel/condition_variable.h +++ b/src/core/hle/kernel/condition_variable.h @@ -4,8 +4,8 @@ #pragma once -#include <queue> #include <string> +#include <queue> #include "common/common_types.h" #include "core/hle/kernel/kernel.h" #include "core/hle/kernel/wait_object.h" diff --git a/src/core/hle/kernel/event.cpp b/src/core/hle/kernel/event.cpp index 23f9df0d6..9cae2369f 100644 --- a/src/core/hle/kernel/event.cpp +++ b/src/core/hle/kernel/event.cpp @@ -52,4 +52,4 @@ void Event::WakeupAllWaitingThreads() { signaled = false; } -} // namespace +} // namespace Kernel diff --git a/src/core/hle/kernel/event.h b/src/core/hle/kernel/event.h index cc41abb85..e5c924a75 100644 --- a/src/core/hle/kernel/event.h +++ b/src/core/hle/kernel/event.h @@ -49,4 +49,4 @@ private: ~Event() override; }; -} // namespace +} // namespace Kernel diff --git a/src/core/hle/kernel/handle_table.cpp b/src/core/hle/kernel/handle_table.cpp index 12506e64c..74d3d0514 100644 --- a/src/core/hle/kernel/handle_table.cpp +++ b/src/core/hle/kernel/handle_table.cpp @@ -104,4 +104,4 @@ void HandleTable::Clear() { next_free_slot = 0; } -} // namespace +} // namespace Kernel diff --git a/src/core/hle/kernel/handle_table.h b/src/core/hle/kernel/handle_table.h index dba5573a8..935cc22b5 100644 --- a/src/core/hle/kernel/handle_table.h +++ b/src/core/hle/kernel/handle_table.h @@ -130,4 +130,4 @@ private: extern HandleTable g_handle_table; -} // namespace +} // namespace Kernel diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp index 73bb6a8be..ecf32c18a 100644 --- a/src/core/hle/kernel/hle_ipc.cpp +++ b/src/core/hle/kernel/hle_ipc.cpp @@ -99,9 +99,8 @@ void HLERequestContext::ParseCommandBuffer(u32_le* src_cmdbuf, bool incoming) { data_payload_offset = rp.GetCurrentOffset(); - if (domain_message_header && - domain_message_header->command == - IPC::DomainMessageHeader::CommandType::CloseVirtualHandle) { + if (domain_message_header && domain_message_header->command == + IPC::DomainMessageHeader::CommandType::CloseVirtualHandle) { // CloseVirtualHandle command does not have SFC* or any data return; } @@ -210,7 +209,7 @@ ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(u32_le* dst_cmdbuf, P for (auto& object : domain_objects) { request_handlers.emplace_back(object); - dst_cmdbuf[domain_offset++] = request_handlers.size(); + dst_cmdbuf[domain_offset++] = static_cast<u32_le>(request_handlers.size()); } } return RESULT_SUCCESS; diff --git a/src/core/hle/kernel/resource_limit.cpp b/src/core/hle/kernel/resource_limit.cpp index 517dc47a8..0149a3ed6 100644 --- a/src/core/hle/kernel/resource_limit.cpp +++ b/src/core/hle/kernel/resource_limit.cpp @@ -151,4 +151,4 @@ void ResourceLimitsInit() { void ResourceLimitsShutdown() {} -} // namespace +} // namespace Kernel diff --git a/src/core/hle/kernel/resource_limit.h b/src/core/hle/kernel/resource_limit.h index 42874eb8d..1a0ca11f1 100644 --- a/src/core/hle/kernel/resource_limit.h +++ b/src/core/hle/kernel/resource_limit.h @@ -123,4 +123,4 @@ void ResourceLimitsInit(); // Destroys the resource limits void ResourceLimitsShutdown(); -} // namespace +} // namespace Kernel diff --git a/src/core/hle/kernel/server_port.cpp b/src/core/hle/kernel/server_port.cpp index 49a9cdfa3..0b7061403 100644 --- a/src/core/hle/kernel/server_port.cpp +++ b/src/core/hle/kernel/server_port.cpp @@ -50,4 +50,4 @@ std::tuple<SharedPtr<ServerPort>, SharedPtr<ClientPort>> ServerPort::CreatePortP return std::make_tuple(std::move(server_port), std::move(client_port)); } -} // namespace +} // namespace Kernel diff --git a/src/core/hle/kernel/server_port.h b/src/core/hle/kernel/server_port.h index 6fe7c7f2f..9ef4ecc35 100644 --- a/src/core/hle/kernel/server_port.h +++ b/src/core/hle/kernel/server_port.h @@ -72,4 +72,4 @@ private: ~ServerPort() override; }; -} // namespace +} // namespace Kernel diff --git a/src/core/hle/kernel/server_session.h b/src/core/hle/kernel/server_session.h index f4360ddf3..6ff4ef8c1 100644 --- a/src/core/hle/kernel/server_session.h +++ b/src/core/hle/kernel/server_session.h @@ -113,4 +113,4 @@ private: * in the command buffer. */ ResultCode TranslateHLERequest(ServerSession* server_session); -} +} // namespace Kernel diff --git a/src/core/hle/kernel/session.cpp b/src/core/hle/kernel/session.cpp index 8a2a7e3fd..642914744 100644 --- a/src/core/hle/kernel/session.cpp +++ b/src/core/hle/kernel/session.cpp @@ -9,4 +9,4 @@ namespace Kernel { Session::Session() {} Session::~Session() {} -} +} // namespace Kernel diff --git a/src/core/hle/kernel/session.h b/src/core/hle/kernel/session.h index 2cf319e99..e69b034a7 100644 --- a/src/core/hle/kernel/session.h +++ b/src/core/hle/kernel/session.h @@ -24,4 +24,4 @@ public: ServerSession* server = nullptr; ///< The server endpoint of the session. SharedPtr<ClientPort> port; ///< The port that this session is associated with (optional). }; -} +} // namespace Kernel diff --git a/src/core/hle/kernel/shared_memory.h b/src/core/hle/kernel/shared_memory.h index 93a6f2182..e948819c0 100644 --- a/src/core/hle/kernel/shared_memory.h +++ b/src/core/hle/kernel/shared_memory.h @@ -98,10 +98,10 @@ public: 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 - */ + * 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 + */ u8* GetPointer(u32 offset = 0); /// Process that created this shared memory block. @@ -129,4 +129,4 @@ private: ~SharedMemory() override; }; -} // namespace +} // namespace Kernel diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 45da842ef..516309036 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp @@ -255,8 +255,9 @@ static ResultCode CancelSynchronization(Handle thread_handle) { /// Attempts to locks a mutex, creating it if it does not already exist static ResultCode ArbitrateLock(Handle holding_thread_handle, VAddr mutex_addr, Handle requesting_thread_handle) { - LOG_TRACE(Kernel_SVC, "called holding_thread_handle=0x%08X, mutex_addr=0x%llx, " - "requesting_current_thread_handle=0x%08X", + LOG_TRACE(Kernel_SVC, + "called holding_thread_handle=0x%08X, mutex_addr=0x%llx, " + "requesting_current_thread_handle=0x%08X", holding_thread_handle, mutex_addr, requesting_thread_handle); SharedPtr<Thread> holding_thread = g_handle_table.Get<Thread>(holding_thread_handle); @@ -314,7 +315,7 @@ static ResultCode GetInfo(u64* result, u64 info_id, u64 handle, u64 info_sub_id) *result = g_current_process->allowed_thread_priority_mask; break; case GetInfoType::MapRegionBaseAddr: - *result = vm_manager.GetAddressSpaceBaseAddr(); + *result = vm_manager.GetMapRegionBaseAddr(); break; case GetInfoType::MapRegionSize: *result = vm_manager.GetAddressSpaceSize(); @@ -546,8 +547,9 @@ static ResultCode CreateThread(Handle* out_handle, VAddr entry_point, u64 arg, V Core::System::GetInstance().PrepareReschedule(); - LOG_TRACE(Kernel_SVC, "called entrypoint=0x%08X (%s), arg=0x%08X, stacktop=0x%08X, " - "threadpriority=0x%08X, processorid=0x%08X : created handle=0x%08X", + LOG_TRACE(Kernel_SVC, + "called entrypoint=0x%08X (%s), arg=0x%08X, stacktop=0x%08X, " + "threadpriority=0x%08X, processorid=0x%08X : created handle=0x%08X", entry_point, name.c_str(), arg, stack_top, priority, processor_id, *out_handle); return RESULT_SUCCESS; @@ -737,6 +739,18 @@ static ResultCode SetThreadCoreMask(u64, u64, u64) { return RESULT_SUCCESS; } +static ResultCode CreateSharedMemory(Handle* handle, u64 sz, u32 local_permissions, + u32 remote_permissions) { + LOG_TRACE(Kernel_SVC, "called, sz=0x%llx, localPerms=0x%08x, remotePerms=0x%08x", sz, + local_permissions, remote_permissions); + auto sharedMemHandle = SharedMemory::Create( + g_handle_table.Get<Process>(KernelHandle::CurrentProcess), sz, + (Kernel::MemoryPermission)local_permissions, (Kernel::MemoryPermission)remote_permissions); + + CASCADE_RESULT(*handle, g_handle_table.Create(sharedMemHandle)); + return RESULT_SUCCESS; +} + namespace { struct FunctionDef { using Func = void(); @@ -828,7 +842,7 @@ static const FunctionDef SVC_Table[] = { {0x4D, nullptr, "SleepSystem"}, {0x4E, nullptr, "ReadWriteRegister"}, {0x4F, nullptr, "SetProcessActivity"}, - {0x50, nullptr, "CreateSharedMemory"}, + {0x50, SvcWrap<CreateSharedMemory>, "CreateSharedMemory"}, {0x51, nullptr, "MapTransferMemory"}, {0x52, nullptr, "UnmapTransferMemory"}, {0x53, nullptr, "CreateInterruptEvent"}, diff --git a/src/core/hle/kernel/svc.h b/src/core/hle/kernel/svc.h index 42cc41da3..bc471d01e 100644 --- a/src/core/hle/kernel/svc.h +++ b/src/core/hle/kernel/svc.h @@ -14,7 +14,11 @@ struct MemoryInfo { u32 type; u32 attributes; u32 permission; + u32 device_refcount; + u32 ipc_refcount; + INSERT_PADDING_WORDS(1); }; +static_assert(sizeof(MemoryInfo) == 0x28, "MemoryInfo has incorrect size."); struct PageInfo { u64 flags; diff --git a/src/core/hle/kernel/svc_wrap.h b/src/core/hle/kernel/svc_wrap.h index fd7054bbd..7a165d8dc 100644 --- a/src/core/hle/kernel/svc_wrap.h +++ b/src/core/hle/kernel/svc_wrap.h @@ -145,6 +145,15 @@ void SvcWrap() { FuncReturn(retval); } +template <ResultCode func(Handle*, u64, u32, u32)> +void SvcWrap() { + u32 param_1 = 0; + u32 retval = + func(¶m_1, PARAM(1), (u32)(PARAM(2) & 0xFFFFFFFF), (u32)(PARAM(3) & 0xFFFFFFFF)).raw; + Core::CPU().SetReg(1, param_1); + FuncReturn(retval); +} + //////////////////////////////////////////////////////////////////////////////////////////////////// // Function wrappers that return type u32 diff --git a/src/core/hle/kernel/timer.cpp b/src/core/hle/kernel/timer.cpp index a93a6c87a..8da745634 100644 --- a/src/core/hle/kernel/timer.cpp +++ b/src/core/hle/kernel/timer.cpp @@ -111,4 +111,4 @@ void TimersInit() { void TimersShutdown() {} -} // namespace +} // namespace Kernel diff --git a/src/core/hle/kernel/timer.h b/src/core/hle/kernel/timer.h index 82552372d..82d19cefc 100644 --- a/src/core/hle/kernel/timer.h +++ b/src/core/hle/kernel/timer.h @@ -76,4 +76,4 @@ void TimersInit(); /// Tears down the timer variables void TimersShutdown(); -} // namespace +} // namespace Kernel diff --git a/src/core/hle/kernel/vm_manager.cpp b/src/core/hle/kernel/vm_manager.cpp index bf261699e..93662a45e 100644 --- a/src/core/hle/kernel/vm_manager.cpp +++ b/src/core/hle/kernel/vm_manager.cpp @@ -375,6 +375,11 @@ u64 VMManager::GetAddressSpaceSize() { return MAX_ADDRESS; } +VAddr VMManager::GetMapRegionBaseAddr() { + LOG_WARNING(Kernel, "(STUBBED) called"); + return Memory::HEAP_VADDR; +} + VAddr VMManager::GetNewMapRegionBaseAddr() { LOG_WARNING(Kernel, "(STUBBED) called"); return 0x8000000; diff --git a/src/core/hle/kernel/vm_manager.h b/src/core/hle/kernel/vm_manager.h index 7a7fee54a..b17385c7c 100644 --- a/src/core/hle/kernel/vm_manager.h +++ b/src/core/hle/kernel/vm_manager.h @@ -192,6 +192,9 @@ public: /// Gets the total address space address size, used by svcGetInfo u64 GetAddressSpaceSize(); + /// Gets the map region base address, used by svcGetInfo + VAddr GetMapRegionBaseAddr(); + /// Gets the base address for a new memory region, used by svcGetInfo VAddr GetNewMapRegionBaseAddr(); diff --git a/src/core/hle/service/acc/acc_u0.cpp b/src/core/hle/service/acc/acc_u0.cpp index 147f4e62e..7f0192fd3 100644 --- a/src/core/hle/service/acc/acc_u0.cpp +++ b/src/core/hle/service/acc/acc_u0.cpp @@ -9,15 +9,76 @@ namespace Service { namespace Account { +class IProfile final : public ServiceFramework<IProfile> { +public: + IProfile() : ServiceFramework("IProfile") { + static const FunctionInfo functions[] = { + {1, &IProfile::GetBase, "GetBase"}, + }; + RegisterHandlers(functions); + } + +private: + void GetBase(Kernel::HLERequestContext& ctx) { + LOG_WARNING(Service, "(STUBBED) called"); + ProfileBase profile_base{}; + IPC::RequestBuilder rb{ctx, 16}; + rb.Push(RESULT_SUCCESS); + rb.PushRaw(profile_base); + } +}; + +class IManagerForApplication final : public ServiceFramework<IManagerForApplication> { +public: + IManagerForApplication() : ServiceFramework("IProfile") { + static const FunctionInfo functions[] = { + {0, &IManagerForApplication::CheckAvailability, "CheckAvailability"}, + }; + RegisterHandlers(functions); + } + +private: + void CheckAvailability(Kernel::HLERequestContext& ctx) { + LOG_WARNING(Service, "(STUBBED) called"); + IPC::RequestBuilder rb{ctx, 3}; + rb.Push(RESULT_SUCCESS); + rb.Push(true); // TODO: Check when this is supposed to return true and when not + } +}; + +void ACC_U0::GetUserExistence(Kernel::HLERequestContext& ctx) { + LOG_WARNING(Service, "(STUBBED) called"); + IPC::RequestBuilder rb{ctx, 3}; + rb.Push(RESULT_SUCCESS); + rb.Push(true); // TODO: Check when this is supposed to return true and when not +} + +void ACC_U0::GetProfile(Kernel::HLERequestContext& ctx) { + IPC::RequestBuilder rb{ctx, 2, 0, 0, 1}; + rb.Push(RESULT_SUCCESS); + rb.PushIpcInterface<IProfile>(); + LOG_DEBUG(Service, "called"); +} + void ACC_U0::InitializeApplicationInfo(Kernel::HLERequestContext& ctx) { LOG_WARNING(Service, "(STUBBED) called"); IPC::RequestBuilder rb{ctx, 2}; rb.Push(RESULT_SUCCESS); } +void ACC_U0::GetBaasAccountManagerForApplication(Kernel::HLERequestContext& ctx) { + IPC::RequestBuilder rb{ctx, 2, 0, 0, 1}; + rb.Push(RESULT_SUCCESS); + rb.PushIpcInterface<IManagerForApplication>(); + LOG_DEBUG(Service, "called"); +} + ACC_U0::ACC_U0() : ServiceFramework("acc:u0") { static const FunctionInfo functions[] = { + {1, &ACC_U0::GetUserExistence, "GetUserExistence"}, + {5, &ACC_U0::GetProfile, "GetProfile"}, {100, &ACC_U0::InitializeApplicationInfo, "InitializeApplicationInfo"}, + {101, &ACC_U0::GetBaasAccountManagerForApplication, "GetBaasAccountManagerForApplication"}, }; RegisterHandlers(functions); } diff --git a/src/core/hle/service/acc/acc_u0.h b/src/core/hle/service/acc/acc_u0.h index ac243d5b8..51676e859 100644 --- a/src/core/hle/service/acc/acc_u0.h +++ b/src/core/hle/service/acc/acc_u0.h @@ -9,13 +9,28 @@ namespace Service { namespace Account { +// TODO: RE this structure +struct UserData { + INSERT_PADDING_BYTES(0x80); +}; +static_assert(sizeof(UserData) == 0x80, "UserData structure has incorrect size"); + +// TODO: RE this structure +struct ProfileBase { + INSERT_PADDING_BYTES(0x38); +}; +static_assert(sizeof(ProfileBase) == 0x38, "ProfileBase structure has incorrect size"); + class ACC_U0 final : public ServiceFramework<ACC_U0> { public: ACC_U0(); ~ACC_U0() = default; private: + void GetUserExistence(Kernel::HLERequestContext& ctx); + void GetProfile(Kernel::HLERequestContext& ctx); void InitializeApplicationInfo(Kernel::HLERequestContext& ctx); + void GetBaasAccountManagerForApplication(Kernel::HLERequestContext& ctx); }; } // namespace Account diff --git a/src/core/hle/service/am/applet_oe.cpp b/src/core/hle/service/am/applet_oe.cpp index 0d7f9c03d..b4a6ad232 100644 --- a/src/core/hle/service/am/applet_oe.cpp +++ b/src/core/hle/service/am/applet_oe.cpp @@ -55,6 +55,8 @@ class ISelfController final : public ServiceFramework<ISelfController> { public: ISelfController() : ServiceFramework("ISelfController") { static const FunctionInfo functions[] = { + {1, &ISelfController::LockExit, "LockExit"}, + {2, &ISelfController::UnlockExit, "UnlockExit"}, {11, &ISelfController::SetOperationModeChangedNotification, "SetOperationModeChangedNotification"}, {12, &ISelfController::SetPerformanceModeChangedNotification, @@ -128,6 +130,20 @@ private: LOG_WARNING(Service, "(STUBBED) called enabled=%u", static_cast<u32>(enabled)); } + + void LockExit(Kernel::HLERequestContext& ctx) { + IPC::RequestBuilder rb{ctx, 2}; + rb.Push(RESULT_SUCCESS); + + LOG_WARNING(Service, "(STUBBED) called"); + } + + void UnlockExit(Kernel::HLERequestContext& ctx) { + IPC::RequestBuilder rb{ctx, 2}; + rb.Push(RESULT_SUCCESS); + + LOG_WARNING(Service, "(STUBBED) called"); + } }; class ICommonStateGetter final : public ServiceFramework<ICommonStateGetter> { @@ -271,6 +287,7 @@ public: IApplicationFunctions() : ServiceFramework("IApplicationFunctions") { static const FunctionInfo functions[] = { {1, &IApplicationFunctions::PopLaunchParameter, "PopLaunchParameter"}, + {21, &IApplicationFunctions::GetDesiredLanguage, "GetDesiredLanguage"}, {22, &IApplicationFunctions::SetTerminateResult, "SetTerminateResult"}, {66, &IApplicationFunctions::InitializeGamePlayRecording, "InitializeGamePlayRecording"}, @@ -314,6 +331,13 @@ private: LOG_WARNING(Service, "(STUBBED) called, result=0x%08X", result); } + void GetDesiredLanguage(Kernel::HLERequestContext& ctx) { + IPC::RequestBuilder rb{ctx, 4}; + rb.Push(RESULT_SUCCESS); + rb.Push<u64>(SystemLanguage::English); + LOG_WARNING(Service, "(STUBBED) called"); + } + void InitializeGamePlayRecording(Kernel::HLERequestContext& ctx) { IPC::RequestBuilder rb{ctx, 2}; rb.Push(RESULT_SUCCESS); diff --git a/src/core/hle/service/am/applet_oe.h b/src/core/hle/service/am/applet_oe.h index beb75bf2a..6ee5b0e9f 100644 --- a/src/core/hle/service/am/applet_oe.h +++ b/src/core/hle/service/am/applet_oe.h @@ -10,6 +10,12 @@ namespace Service { namespace AM { +// TODO: Add more languages +enum SystemLanguage { + Japanese = 0, + English = 1, +}; + class AppletOE final : public ServiceFramework<AppletOE> { public: AppletOE(); diff --git a/src/core/hle/service/apm/apm.cpp b/src/core/hle/service/apm/apm.cpp index 66d94ff52..bf7e12288 100644 --- a/src/core/hle/service/apm/apm.cpp +++ b/src/core/hle/service/apm/apm.cpp @@ -51,7 +51,8 @@ private: APM::APM() : ServiceFramework("apm") { static const FunctionInfo functions[] = { - {0x00000000, &APM::OpenSession, "OpenSession"}, {0x00000001, nullptr, "GetPerformanceMode"}, + {0x00000000, &APM::OpenSession, "OpenSession"}, + {0x00000001, nullptr, "GetPerformanceMode"}, }; RegisterHandlers(functions); } diff --git a/src/core/hle/service/nvdrv/interface.cpp b/src/core/hle/service/nvdrv/interface.cpp index 848615fa7..417455200 100644 --- a/src/core/hle/service/nvdrv/interface.cpp +++ b/src/core/hle/service/nvdrv/interface.cpp @@ -67,6 +67,17 @@ void NVDRV::Initialize(Kernel::HLERequestContext& ctx) { rb.Push<u32>(0); } +void NVDRV::SetClientPID(Kernel::HLERequestContext& ctx) { + IPC::RequestParser rp{ctx}; + u64 pid = rp.Pop<u64>(); + u64 unk = rp.Pop<u64>(); + + LOG_WARNING(Service, "(STUBBED) called, pid=0x%llx, unk=0x%llx", pid, unk); + + IPC::RequestBuilder rb{ctx, 2}; + rb.Push(RESULT_SUCCESS); +} + NVDRV::NVDRV(std::shared_ptr<Module> nvdrv, const char* name) : ServiceFramework(name), nvdrv(std::move(nvdrv)) { static const FunctionInfo functions[] = { @@ -74,6 +85,7 @@ NVDRV::NVDRV(std::shared_ptr<Module> nvdrv, const char* name) {1, &NVDRV::Ioctl, "Ioctl"}, {2, &NVDRV::Close, "Close"}, {3, &NVDRV::Initialize, "Initialize"}, + {8, &NVDRV::SetClientPID, "SetClientPID"}, }; RegisterHandlers(functions); } diff --git a/src/core/hle/service/nvdrv/interface.h b/src/core/hle/service/nvdrv/interface.h index 1b9aa9938..2283f358e 100644 --- a/src/core/hle/service/nvdrv/interface.h +++ b/src/core/hle/service/nvdrv/interface.h @@ -22,6 +22,7 @@ private: void Ioctl(Kernel::HLERequestContext& ctx); void Close(Kernel::HLERequestContext& ctx); void Initialize(Kernel::HLERequestContext& ctx); + void SetClientPID(Kernel::HLERequestContext& ctx); std::shared_ptr<Module> nvdrv; }; diff --git a/src/core/hle/service/nvdrv/nvdrv.cpp b/src/core/hle/service/nvdrv/nvdrv.cpp index 9b73886bb..9d3013c16 100644 --- a/src/core/hle/service/nvdrv/nvdrv.cpp +++ b/src/core/hle/service/nvdrv/nvdrv.cpp @@ -7,8 +7,8 @@ #include "core/hle/service/nvdrv/devices/nvdisp_disp0.h" #include "core/hle/service/nvdrv/devices/nvhost_as_gpu.h" #include "core/hle/service/nvdrv/devices/nvmap.h" -#include "core/hle/service/nvdrv/nvdrv.h" #include "core/hle/service/nvdrv/interface.h" +#include "core/hle/service/nvdrv/nvdrv.h" namespace Service { namespace Nvidia { diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index 9a49d9e9c..19213a2f4 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp @@ -24,6 +24,7 @@ #include "core/hle/service/nvdrv/nvdrv.h" #include "core/hle/service/pctl/pctl.h" #include "core/hle/service/service.h" +#include "core/hle/service/set/set.h" #include "core/hle/service/sm/controller.h" #include "core/hle/service/sm/sm.h" #include "core/hle/service/sockets/sockets.h" @@ -178,6 +179,7 @@ void Init() { Sockets::InstallInterfaces(*SM::g_service_manager); Time::InstallInterfaces(*SM::g_service_manager); VI::InstallInterfaces(*SM::g_service_manager); + Set::InstallInterfaces(*SM::g_service_manager); LOG_DEBUG(Service, "initialized OK"); } diff --git a/src/core/hle/service/service.h b/src/core/hle/service/service.h index 8e1c5b399..9c2e826da 100644 --- a/src/core/hle/service/service.h +++ b/src/core/hle/service/service.h @@ -21,7 +21,7 @@ class ClientPort; class ServerPort; class ServerSession; class HLERequestContext; -} +} // namespace Kernel namespace Service { @@ -189,4 +189,4 @@ extern std::unordered_map<std::string, Kernel::SharedPtr<Kernel::ClientPort>> g_ /// Adds a port to the named port table void AddNamedPort(std::string name, Kernel::SharedPtr<Kernel::ClientPort> port); -} // namespace +} // namespace Service diff --git a/src/core/hle/service/set/set.cpp b/src/core/hle/service/set/set.cpp new file mode 100644 index 000000000..3715acd74 --- /dev/null +++ b/src/core/hle/service/set/set.cpp @@ -0,0 +1,42 @@ +// Copyright 2018 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include <chrono> +#include "common/logging/log.h" +#include "core/hle/ipc_helpers.h" +#include "core/hle/kernel/client_port.h" +#include "core/hle/kernel/client_session.h" +#include "core/hle/service/set/set.h" + +namespace Service { +namespace Set { + +void SET::GetAvailableLanguageCodes(Kernel::HLERequestContext& ctx) { + constexpr std::array<u8, 13> lang_codes{}; + + const auto& output_buffer = ctx.BufferDescriptorC()[0]; + + Memory::WriteBlock(output_buffer.Address(), lang_codes.data(), lang_codes.size()); + + IPC::RequestBuilder rb{ctx, 4}; + + rb.Push(RESULT_SUCCESS); + rb.Push(static_cast<u64>(lang_codes.size())); + + LOG_WARNING(Service, "(STUBBED) called"); +} + +SET::SET(const char* name) : ServiceFramework(name) { + static const FunctionInfo functions[] = { + {1, &SET::GetAvailableLanguageCodes, "GetAvailableLanguageCodes"}, + }; + RegisterHandlers(functions); +} + +void InstallInterfaces(SM::ServiceManager& service_manager) { + std::make_shared<SET>("set")->InstallAsService(service_manager); +} + +} // namespace Set +} // namespace Service diff --git a/src/core/hle/service/set/set.h b/src/core/hle/service/set/set.h new file mode 100644 index 000000000..61e957946 --- /dev/null +++ b/src/core/hle/service/set/set.h @@ -0,0 +1,25 @@ +// 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/service.h" + +namespace Service { +namespace Set { + +class SET final : public ServiceFramework<SET> { +public: + explicit SET(const char* name); + ~SET() = default; + +private: + void GetAvailableLanguageCodes(Kernel::HLERequestContext& ctx); +}; + +/// Registers all Set services with the specified service manager. +void InstallInterfaces(SM::ServiceManager& service_manager); + +} // namespace Set +} // namespace Service diff --git a/src/core/hle/service/sm/sm.cpp b/src/core/hle/service/sm/sm.cpp index f3bffac54..c4078f02f 100644 --- a/src/core/hle/service/sm/sm.cpp +++ b/src/core/hle/service/sm/sm.cpp @@ -103,6 +103,7 @@ void SM::GetService(Kernel::HLERequestContext& ctx) { rb.Push(client_port.Code()); LOG_ERROR(Service_SM, "called service=%s -> error 0x%08X", name.c_str(), client_port.Code().raw); + UNIMPLEMENTED(); return; } diff --git a/src/core/hle/service/time/time.cpp b/src/core/hle/service/time/time.cpp index 674b59509..9fed89246 100644 --- a/src/core/hle/service/time/time.cpp +++ b/src/core/hle/service/time/time.cpp @@ -8,6 +8,8 @@ #include "core/hle/kernel/client_port.h" #include "core/hle/kernel/client_session.h" #include "core/hle/service/time/time.h" +#include "core/hle/service/time/time_s.h" +#include "core/hle/service/time/time_u.h" namespace Service { namespace Time { @@ -43,6 +45,7 @@ public: ITimeZoneService() : ServiceFramework("ITimeZoneService") { static const FunctionInfo functions[] = { {0, &ITimeZoneService::GetDeviceLocationName, "GetDeviceLocationName"}, + {2, &ITimeZoneService::GetTotalLocationNameCount, "GetTotalLocationNameCount"}, {101, &ITimeZoneService::ToCalendarTimeWithMyRule, "ToCalendarTimeWithMyRule"}, }; RegisterHandlers(functions); @@ -51,28 +54,35 @@ public: private: void GetDeviceLocationName(Kernel::HLERequestContext& ctx) { LOG_WARNING(Service, "(STUBBED) called"); - LocationName name{}; - IPC::RequestBuilder rb{ctx, 11}; + LocationName location_name{}; + IPC::RequestBuilder rb{ctx, (sizeof(LocationName) / 4) + 2}; rb.Push(RESULT_SUCCESS); - rb.PushRaw(name); + rb.PushRaw(location_name); + } + + void GetTotalLocationNameCount(Kernel::HLERequestContext& ctx) { + LOG_WARNING(Service, "(STUBBED) called"); + IPC::RequestBuilder rb{ctx, 3}; + rb.Push(RESULT_SUCCESS); + rb.Push<u32>(0); } void ToCalendarTimeWithMyRule(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - u64 posixTime = rp.Pop<u64>(); + u64 posix_time = rp.Pop<u64>(); - LOG_WARNING(Service, "(STUBBED) called, posixTime=0x%016llX", posixTime); + LOG_WARNING(Service, "(STUBBED) called, posix_time=0x%016llX", posix_time); - CalendarTime calendarTime{2018, 1, 1, 0, 0, 0}; - CalendarAdditionalInfo additionalInfo{}; + CalendarTime calendar_time{2018, 1, 1, 0, 0, 0}; + CalendarAdditionalInfo additional_info{}; IPC::RequestBuilder rb{ctx, 10}; rb.Push(RESULT_SUCCESS); - rb.PushRaw(calendarTime); - rb.PushRaw(additionalInfo); + rb.PushRaw(calendar_time); + rb.PushRaw(additional_info); } }; -void TIME::GetStandardUserSystemClock(Kernel::HLERequestContext& ctx) { +void Module::Interface::GetStandardUserSystemClock(Kernel::HLERequestContext& ctx) { auto client_port = std::make_shared<ISystemClock>()->CreatePort(); auto session = client_port->Connect(); if (session.Succeeded()) { @@ -86,7 +96,7 @@ void TIME::GetStandardUserSystemClock(Kernel::HLERequestContext& ctx) { } } -void TIME::GetStandardNetworkSystemClock(Kernel::HLERequestContext& ctx) { +void Module::Interface::GetStandardNetworkSystemClock(Kernel::HLERequestContext& ctx) { auto client_port = std::make_shared<ISystemClock>()->CreatePort(); auto session = client_port->Connect(); if (session.Succeeded()) { @@ -100,7 +110,7 @@ void TIME::GetStandardNetworkSystemClock(Kernel::HLERequestContext& ctx) { } } -void TIME::GetStandardSteadyClock(Kernel::HLERequestContext& ctx) { +void Module::Interface::GetStandardSteadyClock(Kernel::HLERequestContext& ctx) { auto client_port = std::make_shared<ISteadyClock>()->CreatePort(); auto session = client_port->Connect(); if (session.Succeeded()) { @@ -114,28 +124,20 @@ void TIME::GetStandardSteadyClock(Kernel::HLERequestContext& ctx) { } } -void TIME::GetTimeZoneService(Kernel::HLERequestContext& ctx) { +void Module::Interface::GetTimeZoneService(Kernel::HLERequestContext& ctx) { IPC::RequestBuilder rb{ctx, 2, 0, 0, 1}; rb.Push(RESULT_SUCCESS); rb.PushIpcInterface<ITimeZoneService>(); LOG_DEBUG(Service, "called"); } -TIME::TIME(const char* name) : ServiceFramework(name) { - static const FunctionInfo functions[] = { - {0x00000000, &TIME::GetStandardUserSystemClock, "GetStandardUserSystemClock"}, - {0x00000001, &TIME::GetStandardNetworkSystemClock, "GetStandardNetworkSystemClock"}, - {0x00000002, &TIME::GetStandardSteadyClock, "GetStandardSteadyClock"}, - {0x00000003, &TIME::GetTimeZoneService, "GetTimeZoneService"}, - }; - RegisterHandlers(functions); -} +Module::Interface::Interface(std::shared_ptr<Module> time, const char* name) + : ServiceFramework(name), time(std::move(time)) {} void InstallInterfaces(SM::ServiceManager& service_manager) { - std::make_shared<TIME>("time:a")->InstallAsService(service_manager); - std::make_shared<TIME>("time:r")->InstallAsService(service_manager); - std::make_shared<TIME>("time:s")->InstallAsService(service_manager); - std::make_shared<TIME>("time:u")->InstallAsService(service_manager); + auto time = std::make_shared<Module>(); + std::make_shared<TIME_S>(time)->InstallAsService(service_manager); + std::make_shared<TIME_U>(time)->InstallAsService(service_manager); } } // namespace Time diff --git a/src/core/hle/service/time/time.h b/src/core/hle/service/time/time.h index 5f332d057..399f474d6 100644 --- a/src/core/hle/service/time/time.h +++ b/src/core/hle/service/time/time.h @@ -13,7 +13,7 @@ namespace Time { struct LocationName { INSERT_PADDING_BYTES(0x24); }; -static_assert(sizeof(LocationName) == 0x24, "LocationName structure has incorrect size"); +static_assert(sizeof(LocationName) == 0x24, "LocationName is incorrect size"); struct CalendarTime { u16_le year; @@ -33,16 +33,20 @@ struct CalendarAdditionalInfo { static_assert(sizeof(CalendarAdditionalInfo) == 0x18, "CalendarAdditionalInfo structure has incorrect size"); -class TIME final : public ServiceFramework<TIME> { +class Module final { public: - explicit TIME(const char* name); - ~TIME() = default; - -private: - void GetStandardUserSystemClock(Kernel::HLERequestContext& ctx); - void GetStandardNetworkSystemClock(Kernel::HLERequestContext& ctx); - void GetStandardSteadyClock(Kernel::HLERequestContext& ctx); - void GetTimeZoneService(Kernel::HLERequestContext& ctx); + class Interface : public ServiceFramework<Interface> { + public: + Interface(std::shared_ptr<Module> time, const char* name); + + void GetStandardUserSystemClock(Kernel::HLERequestContext& ctx); + void GetStandardNetworkSystemClock(Kernel::HLERequestContext& ctx); + void GetStandardSteadyClock(Kernel::HLERequestContext& ctx); + void GetTimeZoneService(Kernel::HLERequestContext& ctx); + + protected: + std::shared_ptr<Module> time; + }; }; /// Registers all Time services with the specified service manager. diff --git a/src/core/hle/service/time/time_s.cpp b/src/core/hle/service/time/time_s.cpp new file mode 100644 index 000000000..1634d3300 --- /dev/null +++ b/src/core/hle/service/time/time_s.cpp @@ -0,0 +1,18 @@ +// Copyright 2018 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include "core/hle/service/time/time_s.h" + +namespace Service { +namespace Time { + +TIME_S::TIME_S(std::shared_ptr<Module> time) : Module::Interface(std::move(time), "time:s") { + static const FunctionInfo functions[] = { + {0, &TIME_S::GetStandardUserSystemClock, "GetStandardUserSystemClock"}, + }; + RegisterHandlers(functions); +} + +} // namespace Time +} // namespace Service diff --git a/src/core/hle/service/time/time_s.h b/src/core/hle/service/time/time_s.h new file mode 100644 index 000000000..abc2a8c5a --- /dev/null +++ b/src/core/hle/service/time/time_s.h @@ -0,0 +1,18 @@ +// 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/time/time.h" + +namespace Service { +namespace Time { + +class TIME_S final : public Module::Interface { +public: + explicit TIME_S(std::shared_ptr<Module> time); +}; + +} // namespace Time +} // namespace Service diff --git a/src/core/hle/service/time/time_u.cpp b/src/core/hle/service/time/time_u.cpp new file mode 100644 index 000000000..ae4f78adf --- /dev/null +++ b/src/core/hle/service/time/time_u.cpp @@ -0,0 +1,21 @@ +// Copyright 2018 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include "core/hle/service/time/time_u.h" + +namespace Service { +namespace Time { + +TIME_U::TIME_U(std::shared_ptr<Module> time) : Module::Interface(std::move(time), "time:u") { + static const FunctionInfo functions[] = { + {0, &TIME_U::GetStandardUserSystemClock, "GetStandardUserSystemClock"}, + {1, &TIME_U::GetStandardNetworkSystemClock, "GetStandardNetworkSystemClock"}, + {2, &TIME_U::GetStandardSteadyClock, "GetStandardSteadyClock"}, + {3, &TIME_U::GetTimeZoneService, "GetTimeZoneService"}, + }; + RegisterHandlers(functions); +} + +} // namespace Time +} // namespace Service diff --git a/src/core/hle/service/time/time_u.h b/src/core/hle/service/time/time_u.h new file mode 100644 index 000000000..f99d25057 --- /dev/null +++ b/src/core/hle/service/time/time_u.h @@ -0,0 +1,18 @@ +// 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/time/time.h" + +namespace Service { +namespace Time { + +class TIME_U final : public Module::Interface { +public: + explicit TIME_U(std::shared_ptr<Module> time); +}; + +} // namespace Time +} // namespace Service diff --git a/src/core/hle/service/vi/vi.cpp b/src/core/hle/service/vi/vi.cpp index 108a635d7..c624e734e 100644 --- a/src/core/hle/service/vi/vi.cpp +++ b/src/core/hle/service/vi/vi.cpp @@ -95,7 +95,7 @@ public: Header header{}; header.data_offset = sizeof(Header); - header.data_size = write_index - sizeof(Header); + header.data_size = static_cast<u32_le>(write_index - sizeof(Header)); std::memcpy(buffer.data(), &header, sizeof(Header)); return buffer; @@ -138,7 +138,7 @@ private: u32_le process_id; u32_le id; INSERT_PADDING_BYTES(0xC); - std::array<u8, 8> dspdrv = {'d', 's', 'p', 'd', 'r', 'v'}; + std::array<u8, 8> dispdrv = {'d', 'i', 's', 'p', 'd', 'r', 'v', '\0'}; INSERT_PADDING_BYTES(8); }; static_assert(sizeof(Data) == 0x28, "ParcelData has wrong size"); diff --git a/src/core/hle/shared_page.cpp b/src/core/hle/shared_page.cpp index 9ce8af961..bba4a0715 100644 --- a/src/core/hle/shared_page.cpp +++ b/src/core/hle/shared_page.cpp @@ -82,4 +82,4 @@ void Init() { CoreTiming::ScheduleEvent(0, update_time_event); } -} // namespace +} // namespace SharedPage diff --git a/src/core/hle/shared_page.h b/src/core/hle/shared_page.h index 864695ae1..a58259888 100644 --- a/src/core/hle/shared_page.h +++ b/src/core/hle/shared_page.h @@ -66,4 +66,4 @@ extern SharedPageDef shared_page; void Init(); -} // namespace +} // namespace SharedPage diff --git a/src/core/hw/hw.cpp b/src/core/hw/hw.cpp index a751b1d62..0db604c76 100644 --- a/src/core/hw/hw.cpp +++ b/src/core/hw/hw.cpp @@ -91,4 +91,4 @@ void Shutdown() { LCD::Shutdown(); LOG_DEBUG(HW, "shutdown OK"); } -} +} // namespace HW diff --git a/src/core/hw/hw.h b/src/core/hw/hw.h index a3c5d2ea3..5890d2b5c 100644 --- a/src/core/hw/hw.h +++ b/src/core/hw/hw.h @@ -47,4 +47,4 @@ void Init(); /// Shutdown hardware void Shutdown(); -} // namespace +} // namespace HW diff --git a/src/core/hw/lcd.cpp b/src/core/hw/lcd.cpp index 763ac1c4d..690079b65 100644 --- a/src/core/hw/lcd.cpp +++ b/src/core/hw/lcd.cpp @@ -64,4 +64,4 @@ void Shutdown() { LOG_DEBUG(HW_LCD, "shutdown OK"); } -} // namespace +} // namespace LCD diff --git a/src/core/hw/lcd.h b/src/core/hw/lcd.h index 191fd44af..d2db9700f 100644 --- a/src/core/hw/lcd.h +++ b/src/core/hw/lcd.h @@ -83,4 +83,4 @@ void Init(); /// Shutdown hardware void Shutdown(); -} // namespace +} // namespace LCD diff --git a/src/core/loader/deconstructed_rom_directory.cpp b/src/core/loader/deconstructed_rom_directory.cpp new file mode 100644 index 000000000..4bee5fb86 --- /dev/null +++ b/src/core/loader/deconstructed_rom_directory.cpp @@ -0,0 +1,105 @@ +// Copyright 2018 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include "common/common_funcs.h" +#include "common/common_paths.h" +#include "common/file_util.h" +#include "common/logging/log.h" +#include "common/string_util.h" +#include "core/hle/kernel/process.h" +#include "core/hle/kernel/resource_limit.h" +#include "core/loader/deconstructed_rom_directory.h" +#include "core/loader/nso.h" +#include "core/memory.h" + +namespace Loader { + +AppLoader_DeconstructedRomDirectory::AppLoader_DeconstructedRomDirectory(FileUtil::IOFile&& file, + std::string filepath) + : AppLoader(std::move(file)), filepath(std::move(filepath)) {} + +FileType AppLoader_DeconstructedRomDirectory::IdentifyType(FileUtil::IOFile& file, + const std::string& filepath) { + bool is_main_found{}; + bool is_rtld_found{}; + bool is_sdk_found{}; + + const auto callback = [&](unsigned* num_entries_out, const std::string& directory, + const std::string& virtual_name) -> bool { + // Skip directories + std::string physical_name = directory + virtual_name; + if (FileUtil::IsDirectory(physical_name)) { + return true; + } + + // Verify filename + if (Common::ToLower(virtual_name) == "main") { + is_main_found = true; + } else if (Common::ToLower(virtual_name) == "rtld") { + is_rtld_found = true; + } else if (Common::ToLower(virtual_name) == "sdk") { + is_sdk_found = true; + } else { + // Contrinue searching + return true; + } + + // Verify file is an NSO + FileUtil::IOFile file(physical_name, "rb"); + if (AppLoader_NSO::IdentifyType(file, physical_name) != FileType::NSO) { + return false; + } + + // We are done if we've found and verified all required NSOs + return !(is_main_found && is_rtld_found && is_sdk_found); + }; + + // Search the directory recursively, looking for the required modules + const std::string directory = filepath.substr(0, filepath.find_last_of("/\\")) + DIR_SEP; + FileUtil::ForeachDirectoryEntry(nullptr, directory, callback); + + if (is_main_found && is_rtld_found && is_sdk_found) { + return FileType::DeconstructedRomDirectory; + } + + return FileType::Error; +} + +ResultStatus AppLoader_DeconstructedRomDirectory::Load( + Kernel::SharedPtr<Kernel::Process>& process) { + if (is_loaded) { + return ResultStatus::ErrorAlreadyLoaded; + } + if (!file.IsOpen()) { + return ResultStatus::Error; + } + + process = Kernel::Process::Create("main"); + + // Load NSO modules + VAddr next_load_addr{Memory::PROCESS_IMAGE_VADDR}; + for (const auto& module : {"rtld", "main", "subsdk0", "subsdk1", "subsdk2", "subsdk3", + "subsdk4", "subsdk5", "subsdk6", "subsdk7", "sdk"}) { + const std::string path = + filepath.substr(0, filepath.find_last_of("/\\")) + DIR_SEP + module; + const VAddr load_addr = next_load_addr; + next_load_addr = AppLoader_NSO::LoadModule(path, load_addr); + if (next_load_addr) { + LOG_DEBUG(Loader, "loaded module %s @ 0x%llx", module, load_addr); + } else { + next_load_addr = load_addr; + } + } + + process->svc_access_mask.set(); + process->address_mappings = default_address_mappings; + process->resource_limit = + Kernel::ResourceLimit::GetForCategory(Kernel::ResourceLimitCategory::APPLICATION); + process->Run(Memory::PROCESS_IMAGE_VADDR, 48, Kernel::DEFAULT_STACK_SIZE); + + is_loaded = true; + return ResultStatus::Success; +} + +} // namespace Loader diff --git a/src/core/loader/deconstructed_rom_directory.h b/src/core/loader/deconstructed_rom_directory.h new file mode 100644 index 000000000..162541d54 --- /dev/null +++ b/src/core/loader/deconstructed_rom_directory.h @@ -0,0 +1,42 @@ +// Copyright 2018 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include <string> +#include "common/common_types.h" +#include "core/hle/kernel/kernel.h" +#include "core/loader/loader.h" + +namespace Loader { + +/** + * This class loads a "deconstructed ROM directory", which are the typical format we see for Switch + * game dumps. The path should be a "main" NSO, which must be in a directory that contains the other + * standard ExeFS NSOs (e.g. rtld, sdk, etc.). It will automatically find and load these. + * Furthermore, it will look for the first .istorage file (optionally) and use this for the RomFS. + */ +class AppLoader_DeconstructedRomDirectory final : public AppLoader { +public: + AppLoader_DeconstructedRomDirectory(FileUtil::IOFile&& file, std::string filepath); + + /** + * Returns the type of the file + * @param file FileUtil::IOFile open file + * @param filepath Path of the file that we are opening. + * @return FileType found, or FileType::Error if this loader doesn't know it + */ + static FileType IdentifyType(FileUtil::IOFile& file, const std::string& filepath); + + FileType GetFileType() override { + return IdentifyType(file, filepath); + } + + ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override; + +private: + std::string filepath; +}; + +} // namespace Loader diff --git a/src/core/loader/elf.cpp b/src/core/loader/elf.cpp index 9ba913dbe..b87320656 100644 --- a/src/core/loader/elf.cpp +++ b/src/core/loader/elf.cpp @@ -323,8 +323,9 @@ SharedPtr<CodeSet> ElfReader::LoadInto(u32 vaddr) { } if (codeset_segment->size != 0) { - LOG_ERROR(Loader, "ELF has more than one segment of the same type. Skipping extra " - "segment (id %i)", + LOG_ERROR(Loader, + "ELF has more than one segment of the same type. Skipping extra " + "segment (id %i)", i); continue; } @@ -364,7 +365,10 @@ SectionID ElfReader::GetSectionByName(const char* name, int firstSection) const namespace Loader { -FileType AppLoader_ELF::IdentifyType(FileUtil::IOFile& file) { +AppLoader_ELF::AppLoader_ELF(FileUtil::IOFile&& file, std::string filename) + : AppLoader(std::move(file)), filename(std::move(filename)) {} + +FileType AppLoader_ELF::IdentifyType(FileUtil::IOFile& file, const std::string&) { static constexpr u16 ELF_MACHINE_ARM{0x28}; u32 magic = 0; diff --git a/src/core/loader/elf.h b/src/core/loader/elf.h index 113da5917..ee741a789 100644 --- a/src/core/loader/elf.h +++ b/src/core/loader/elf.h @@ -16,18 +16,18 @@ namespace Loader { /// Loads an ELF/AXF file class AppLoader_ELF final : public AppLoader { public: - AppLoader_ELF(FileUtil::IOFile&& file, std::string filename) - : AppLoader(std::move(file)), filename(std::move(filename)) {} + AppLoader_ELF(FileUtil::IOFile&& file, std::string filename); /** * Returns the type of the file * @param file FileUtil::IOFile open file + * @param filepath Path of the file that we are opening. * @return FileType found, or FileType::Error if this loader doesn't know it */ - static FileType IdentifyType(FileUtil::IOFile& file); + static FileType IdentifyType(FileUtil::IOFile& file, const std::string& filepath); FileType GetFileType() override { - return IdentifyType(file); + return IdentifyType(file, filename); } ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override; diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp index 92defd381..2ec08506d 100644 --- a/src/core/loader/loader.cpp +++ b/src/core/loader/loader.cpp @@ -1,4 +1,4 @@ -// Copyright 2014 Citra Emulator Project +// Copyright 2018 yuzu emulator team // Licensed under GPLv2 or any later version // Refer to the license.txt file included. @@ -7,12 +7,11 @@ #include "common/logging/log.h" #include "common/string_util.h" #include "core/hle/kernel/process.h" +#include "core/loader/deconstructed_rom_directory.h" #include "core/loader/elf.h" #include "core/loader/nro.h" #include "core/loader/nso.h" -//////////////////////////////////////////////////////////////////////////////////////////////////// - namespace Loader { const std::initializer_list<Kernel::AddressMapping> default_address_mappings = { @@ -21,14 +20,15 @@ const std::initializer_list<Kernel::AddressMapping> default_address_mappings = { {0x1F000000, 0x600000, false}, // entire VRAM }; -FileType IdentifyFile(FileUtil::IOFile& file) { +FileType IdentifyFile(FileUtil::IOFile& file, const std::string& filepath) { FileType type; #define CHECK_TYPE(loader) \ - type = AppLoader_##loader::IdentifyType(file); \ + type = AppLoader_##loader::IdentifyType(file, filepath); \ if (FileType::Error != type) \ return type; + CHECK_TYPE(DeconstructedRomDirectory) CHECK_TYPE(ELF) CHECK_TYPE(NSO) CHECK_TYPE(NRO) @@ -45,13 +45,13 @@ FileType IdentifyFile(const std::string& file_name) { return FileType::Unknown; } - return IdentifyFile(file); + return IdentifyFile(file, file_name); } FileType GuessFromExtension(const std::string& extension_) { std::string extension = Common::ToLower(extension_); - if (extension == ".elf" || extension == ".axf") + if (extension == ".elf") return FileType::ELF; else if (extension == ".nro") return FileType::NRO; @@ -69,6 +69,8 @@ const char* GetFileTypeString(FileType type) { return "NRO"; case FileType::NSO: return "NSO"; + case FileType::DeconstructedRomDirectory: + return "Directory"; case FileType::Error: case FileType::Unknown: break; @@ -102,6 +104,10 @@ static std::unique_ptr<AppLoader> GetFileLoader(FileUtil::IOFile&& file, FileTyp case FileType::NRO: return std::make_unique<AppLoader_NRO>(std::move(file), filepath); + // NX deconstructed ROM directory. + case FileType::DeconstructedRomDirectory: + return std::make_unique<AppLoader_DeconstructedRomDirectory>(std::move(file), filepath); + default: return nullptr; } @@ -117,7 +123,7 @@ std::unique_ptr<AppLoader> GetLoader(const std::string& filename) { std::string filename_filename, filename_extension; Common::SplitPath(filename, nullptr, &filename_filename, &filename_extension); - FileType type = IdentifyFile(file); + FileType type = IdentifyFile(file, filename); FileType filename_type = GuessFromExtension(filename_extension); if (type != filename_type) { diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h index dd6bb4e64..dd44ee9a6 100644 --- a/src/core/loader/loader.h +++ b/src/core/loader/loader.h @@ -1,4 +1,4 @@ -// Copyright 2014 Citra Emulator Project +// Copyright 2018 yuzu emulator team // Licensed under GPLv2 or any later version // Refer to the license.txt file included. @@ -20,9 +20,6 @@ struct AddressMapping; class Process; } // namespace Kernel -//////////////////////////////////////////////////////////////////////////////////////////////////// -// Loader namespace - namespace Loader { /// File types supported by CTR @@ -32,14 +29,16 @@ enum class FileType { ELF, NSO, NRO, + DeconstructedRomDirectory, }; /** * Identifies the type of a bootable file based on the magic value in its header. * @param file open file + * @param filepath Path of the file that we are opening. * @return FileType of file */ -FileType IdentifyFile(FileUtil::IOFile& file); +FileType IdentifyFile(FileUtil::IOFile& file, const std::string& filepath); /** * Identifies the type of a bootable file based on the magic value in its header. diff --git a/src/core/loader/nro.cpp b/src/core/loader/nro.cpp index 0fbd38b46..6f8a2f21e 100644 --- a/src/core/loader/nro.cpp +++ b/src/core/loader/nro.cpp @@ -5,6 +5,7 @@ #include <vector> #include "common/common_funcs.h" +#include "common/file_util.h" #include "common/logging/log.h" #include "common/swap.h" #include "core/hle/kernel/process.h" @@ -45,7 +46,10 @@ struct ModHeader { }; static_assert(sizeof(ModHeader) == 0x1c, "ModHeader has incorrect size."); -FileType AppLoader_NRO::IdentifyType(FileUtil::IOFile& file) { +AppLoader_NRO::AppLoader_NRO(FileUtil::IOFile&& file, std::string filepath) + : AppLoader(std::move(file)), filepath(std::move(filepath)) {} + +FileType AppLoader_NRO::IdentifyType(FileUtil::IOFile& file, const std::string&) { // Read NSO header NroHeader nro_header{}; file.Seek(0, SEEK_SET); diff --git a/src/core/loader/nro.h b/src/core/loader/nro.h index e20fa1555..599adb253 100644 --- a/src/core/loader/nro.h +++ b/src/core/loader/nro.h @@ -4,10 +4,8 @@ #pragma once -#include <map> #include <string> #include "common/common_types.h" -#include "common/file_util.h" #include "core/hle/kernel/kernel.h" #include "core/loader/linker.h" #include "core/loader/loader.h" @@ -17,18 +15,18 @@ namespace Loader { /// Loads an NRO file class AppLoader_NRO final : public AppLoader, Linker { public: - AppLoader_NRO(FileUtil::IOFile&& file, std::string filepath) - : AppLoader(std::move(file)), filepath(std::move(filepath)) {} + AppLoader_NRO(FileUtil::IOFile&& file, std::string filepath); /** * Returns the type of the file * @param file FileUtil::IOFile open file + * @param filepath Path of the file that we are opening. * @return FileType found, or FileType::Error if this loader doesn't know it */ - static FileType IdentifyType(FileUtil::IOFile& file); + static FileType IdentifyType(FileUtil::IOFile& file, const std::string& filepath); FileType GetFileType() override { - return IdentifyType(file); + return IdentifyType(file, filepath); } ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override; diff --git a/src/core/loader/nso.cpp b/src/core/loader/nso.cpp index ef769dd91..3ccbbb824 100644 --- a/src/core/loader/nso.cpp +++ b/src/core/loader/nso.cpp @@ -4,8 +4,8 @@ #include <vector> #include <lz4.h> - #include "common/common_funcs.h" +#include "common/file_util.h" #include "common/logging/log.h" #include "common/swap.h" #include "core/hle/kernel/process.h" @@ -47,7 +47,10 @@ struct ModHeader { }; static_assert(sizeof(ModHeader) == 0x1c, "ModHeader has incorrect size."); -FileType AppLoader_NSO::IdentifyType(FileUtil::IOFile& file) { +AppLoader_NSO::AppLoader_NSO(FileUtil::IOFile&& file, std::string filepath) + : AppLoader(std::move(file)), filepath(std::move(filepath)) {} + +FileType AppLoader_NSO::IdentifyType(FileUtil::IOFile& file, const std::string&) { u32 magic = 0; file.Seek(0, SEEK_SET); if (1 != file.ReadArray<u32>(&magic, 1)) { @@ -88,7 +91,7 @@ static constexpr u32 PageAlignSize(u32 size) { return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK; } -VAddr AppLoader_NSO::LoadNso(const std::string& path, VAddr load_base) { +VAddr AppLoader_NSO::LoadModule(const std::string& path, VAddr load_base) { FileUtil::IOFile file(path, "rb"); if (!file.IsOpen()) { return {}; @@ -153,21 +156,9 @@ ResultStatus AppLoader_NSO::Load(Kernel::SharedPtr<Kernel::Process>& process) { process = Kernel::Process::Create("main"); - // Load NSO modules - VAddr next_load_addr{Memory::PROCESS_IMAGE_VADDR}; - for (const auto& module : - {"rtld", "sdk", "subsdk0", "subsdk1", "subsdk2", "subsdk3", "subsdk4"}) { - const std::string path = filepath.substr(0, filepath.find_last_of("/\\")) + "/" + module; - const VAddr load_addr = next_load_addr; - next_load_addr = LoadNso(path, load_addr); - if (next_load_addr) { - LOG_DEBUG(Loader, "loaded module %s @ 0x%llx", module, load_addr); - } else { - next_load_addr = load_addr; - } - } - // Load "main" module - LoadNso(filepath, next_load_addr); + // Load module + LoadModule(filepath, Memory::PROCESS_IMAGE_VADDR); + LOG_DEBUG(Loader, "loaded module %s @ 0x%llx", filepath.c_str(), Memory::PROCESS_IMAGE_VADDR); process->svc_access_mask.set(); process->address_mappings = default_address_mappings; diff --git a/src/core/loader/nso.h b/src/core/loader/nso.h index a24bcdc24..1ae30a824 100644 --- a/src/core/loader/nso.h +++ b/src/core/loader/nso.h @@ -4,10 +4,8 @@ #pragma once -#include <map> #include <string> #include "common/common_types.h" -#include "common/file_util.h" #include "core/hle/kernel/kernel.h" #include "core/loader/linker.h" #include "core/loader/loader.h" @@ -17,25 +15,25 @@ namespace Loader { /// Loads an NSO file class AppLoader_NSO final : public AppLoader, Linker { public: - AppLoader_NSO(FileUtil::IOFile&& file, std::string filepath) - : AppLoader(std::move(file)), filepath(std::move(filepath)) {} + AppLoader_NSO(FileUtil::IOFile&& file, std::string filepath); /** * Returns the type of the file * @param file FileUtil::IOFile open file + * @param filepath Path of the file that we are opening. * @return FileType found, or FileType::Error if this loader doesn't know it */ - static FileType IdentifyType(FileUtil::IOFile& file); + static FileType IdentifyType(FileUtil::IOFile& file, const std::string& filepath); FileType GetFileType() override { - return IdentifyType(file); + return IdentifyType(file, filepath); } + static VAddr LoadModule(const std::string& path, VAddr load_base); + ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override; private: - VAddr LoadNso(const std::string& path, VAddr load_base); - std::string filepath; }; diff --git a/src/core/memory.cpp b/src/core/memory.cpp index 74a598852..a3d2d4951 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp @@ -219,6 +219,9 @@ void Write(const VAddr vaddr, const T data) { bool IsValidVirtualAddress(const Kernel::Process& process, const VAddr vaddr) { auto& page_table = process.vm_manager.page_table; + if ((vaddr >> PAGE_BITS) >= PAGE_TABLE_NUM_ENTRIES) + return false; + const u8* page_pointer = page_table.pointers[vaddr >> PAGE_BITS]; if (page_pointer) return true; diff --git a/src/core/memory_setup.h b/src/core/memory_setup.h index ff4dcc936..6f82a131e 100644 --- a/src/core/memory_setup.h +++ b/src/core/memory_setup.h @@ -29,4 +29,4 @@ void MapMemoryRegion(PageTable& page_table, VAddr base, u64 size, u8* target); void MapIoRegion(PageTable& page_table, VAddr base, u64 size, MMIORegionPointer mmio_handler); void UnmapRegion(PageTable& page_table, VAddr base, u64 size); -} +} // namespace Memory diff --git a/src/core/mmio.h b/src/core/mmio.h index f45126da8..5e3cc01af 100644 --- a/src/core/mmio.h +++ b/src/core/mmio.h @@ -35,4 +35,4 @@ public: }; using MMIORegionPointer = std::shared_ptr<MMIORegion>; -}; +}; // namespace Memory diff --git a/src/core/settings.h b/src/core/settings.h index 56fb189ae..6f8cd0f03 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -100,7 +100,8 @@ enum Values { }; static const std::array<const char*, NumAnalogs> mapping = {{ - "lstick", "rstick", + "lstick", + "rstick", }}; } // namespace NativeAnalog diff --git a/src/core/telemetry_session.cpp b/src/core/telemetry_session.cpp index a613889f0..bea05a09b 100644 --- a/src/core/telemetry_session.cpp +++ b/src/core/telemetry_session.cpp @@ -7,13 +7,16 @@ #include "common/assert.h" #include "common/file_util.h" #include "common/scm_rev.h" +#ifdef ARCHITECTURE_x86_64 #include "common/x64/cpu_detect.h" +#endif #include "core/core.h" #include "core/settings.h" #include "core/telemetry_session.h" namespace Core { +#ifdef ARCHITECTURE_x86_64 static const char* CpuVendorToStr(Common::CPUVendor vendor) { switch (vendor) { case Common::CPUVendor::INTEL: @@ -25,6 +28,7 @@ static const char* CpuVendorToStr(Common::CPUVendor vendor) { } UNREACHABLE(); } +#endif static u64 GenerateTelemetryId() { u64 telemetry_id{}; @@ -113,7 +117,8 @@ TelemetrySession::TelemetrySession() { AddField(Telemetry::FieldType::App, "BuildDate", Common::g_build_date); AddField(Telemetry::FieldType::App, "BuildName", Common::g_build_name); - // Log user system information +// Log user system information +#ifdef ARCHITECTURE_x86_64 AddField(Telemetry::FieldType::UserSystem, "CPU_Model", Common::GetCPUCaps().cpu_string); AddField(Telemetry::FieldType::UserSystem, "CPU_BrandString", Common::GetCPUCaps().brand_string); @@ -135,6 +140,9 @@ TelemetrySession::TelemetrySession() { Common::GetCPUCaps().sse4_1); AddField(Telemetry::FieldType::UserSystem, "CPU_Extension_x64_SSE42", Common::GetCPUCaps().sse4_2); +#else + AddField(Telemetry::FieldType::UserSystem, "CPU_Model", "Other"); +#endif #ifdef __APPLE__ AddField(Telemetry::FieldType::UserSystem, "OsPlatform", "Apple"); #elif defined(_WIN32) diff --git a/src/core/tracer/citrace.h b/src/core/tracer/citrace.h index 215f86359..21fdc127a 100644 --- a/src/core/tracer/citrace.h +++ b/src/core/tracer/citrace.h @@ -97,4 +97,4 @@ struct CTStreamElement { }; #pragma pack() -} +} // namespace CiTrace diff --git a/src/core/tracer/recorder.cpp b/src/core/tracer/recorder.cpp index 55b3b5efc..f3b0d6a8f 100644 --- a/src/core/tracer/recorder.cpp +++ b/src/core/tracer/recorder.cpp @@ -205,4 +205,4 @@ template void Recorder::RegisterWritten(u32, u8); template void Recorder::RegisterWritten(u32, u16); template void Recorder::RegisterWritten(u32, u32); template void Recorder::RegisterWritten(u32, u64); -} +} // namespace CiTrace diff --git a/src/core/tracer/recorder.h b/src/core/tracer/recorder.h index 39e6ec4fd..629c2f6d2 100644 --- a/src/core/tracer/recorder.h +++ b/src/core/tracer/recorder.h @@ -63,9 +63,9 @@ private: CTStreamElement data; /** - * Extra data to store along "core" data. - * This is e.g. used for data used in MemoryUpdates. - */ + * Extra data to store along "core" data. + * This is e.g. used for data used in MemoryUpdates. + */ std::vector<u8> extra_data; /// Optional CRC hash (e.g. for hashing memory regions) @@ -84,4 +84,4 @@ private: std::unordered_map<boost::crc_32_type::value_type /*hash*/, u32 /*file_offset*/> memory_regions; }; -} // namespace +} // namespace CiTrace |