diff options
| author | 2018-02-14 22:22:41 -0500 | |
|---|---|---|
| committer | 2018-02-14 22:22:41 -0500 | |
| commit | 42c062c620b8aff1bee000691f997b0cf0388d15 (patch) | |
| tree | 243e3377a9cec540c6747cc1b9cc830c732c0661 /src | |
| parent | log: Add logging category for NS services. (diff) | |
| download | yuzu-42c062c620b8aff1bee000691f997b0cf0388d15.tar.gz yuzu-42c062c620b8aff1bee000691f997b0cf0388d15.tar.xz yuzu-42c062c620b8aff1bee000691f997b0cf0388d15.zip | |
pl_u: Implement basic shared font loading from RAM dump.
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/CMakeLists.txt | 4 | ||||
| -rw-r--r-- | src/core/hle/service/ns/ns.cpp | 16 | ||||
| -rw-r--r-- | src/core/hle/service/ns/ns.h | 16 | ||||
| -rw-r--r-- | src/core/hle/service/ns/pl_u.cpp | 111 | ||||
| -rw-r--r-- | src/core/hle/service/ns/pl_u.h | 33 | ||||
| -rw-r--r-- | src/core/hle/service/service.cpp | 2 |
6 files changed, 182 insertions, 0 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index fc6cb67c7..ce68194c5 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt | |||
| @@ -124,6 +124,10 @@ add_library(core STATIC | |||
| 124 | hle/service/nifm/nifm_s.h | 124 | hle/service/nifm/nifm_s.h |
| 125 | hle/service/nifm/nifm_u.cpp | 125 | hle/service/nifm/nifm_u.cpp |
| 126 | hle/service/nifm/nifm_u.h | 126 | hle/service/nifm/nifm_u.h |
| 127 | hle/service/ns/ns.cpp | ||
| 128 | hle/service/ns/ns.h | ||
| 129 | hle/service/ns/pl_u.cpp | ||
| 130 | hle/service/ns/pl_u.h | ||
| 127 | hle/service/nvdrv/devices/nvdevice.h | 131 | hle/service/nvdrv/devices/nvdevice.h |
| 128 | hle/service/nvdrv/devices/nvdisp_disp0.cpp | 132 | hle/service/nvdrv/devices/nvdisp_disp0.cpp |
| 129 | hle/service/nvdrv/devices/nvdisp_disp0.h | 133 | hle/service/nvdrv/devices/nvdisp_disp0.h |
diff --git a/src/core/hle/service/ns/ns.cpp b/src/core/hle/service/ns/ns.cpp new file mode 100644 index 000000000..45681c50f --- /dev/null +++ b/src/core/hle/service/ns/ns.cpp | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "core/hle/service/ns/ns.h" | ||
| 6 | #include "core/hle/service/ns/pl_u.h" | ||
| 7 | |||
| 8 | namespace Service { | ||
| 9 | namespace NS { | ||
| 10 | |||
| 11 | void InstallInterfaces(SM::ServiceManager& service_manager) { | ||
| 12 | std::make_shared<PL_U>()->InstallAsService(service_manager); | ||
| 13 | } | ||
| 14 | |||
| 15 | } // namespace NS | ||
| 16 | } // namespace Service | ||
diff --git a/src/core/hle/service/ns/ns.h b/src/core/hle/service/ns/ns.h new file mode 100644 index 000000000..a4b7e3ded --- /dev/null +++ b/src/core/hle/service/ns/ns.h | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "core/hle/service/service.h" | ||
| 8 | |||
| 9 | namespace Service { | ||
| 10 | namespace NS { | ||
| 11 | |||
| 12 | /// Registers all NS services with the specified service manager. | ||
| 13 | void InstallInterfaces(SM::ServiceManager& service_manager); | ||
| 14 | |||
| 15 | } // namespace NS | ||
| 16 | } // namespace Service | ||
diff --git a/src/core/hle/service/ns/pl_u.cpp b/src/core/hle/service/ns/pl_u.cpp new file mode 100644 index 000000000..cc9d03a7c --- /dev/null +++ b/src/core/hle/service/ns/pl_u.cpp | |||
| @@ -0,0 +1,111 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "common/common_paths.h" | ||
| 6 | #include "common/file_util.h" | ||
| 7 | #include "core/hle/ipc_helpers.h" | ||
| 8 | #include "core/hle/service/ns/pl_u.h" | ||
| 9 | |||
| 10 | namespace Service { | ||
| 11 | namespace NS { | ||
| 12 | |||
| 13 | struct FontRegion { | ||
| 14 | u32 offset; | ||
| 15 | u32 size; | ||
| 16 | }; | ||
| 17 | |||
| 18 | // The below data is specific to shared font data dumped from Switch on f/w 2.2 | ||
| 19 | // Virtual address and offsets/sizes likely will vary by dump | ||
| 20 | static constexpr VAddr SHARED_FONT_MEM_VADDR{0x00000009d3016000ULL}; | ||
| 21 | static constexpr u64 SHARED_FONT_MEM_SIZE{0x1100000}; | ||
| 22 | static constexpr std::array<FontRegion, 6> SHARED_FONT_REGIONS{ | ||
| 23 | FontRegion{0x00000008, 0x001fe764}, FontRegion{0x001fe774, 0x00773e58}, | ||
| 24 | FontRegion{0x009725d4, 0x0001aca8}, FontRegion{0x0098d284, 0x00369cec}, | ||
| 25 | FontRegion{0x00cf6f78, 0x0039b858}, FontRegion{0x010927d8, 0x00019e80}, | ||
| 26 | }; | ||
| 27 | |||
| 28 | enum class LoadState : u32 { | ||
| 29 | Loading = 0, | ||
| 30 | Done = 1, | ||
| 31 | }; | ||
| 32 | |||
| 33 | PL_U::PL_U() : ServiceFramework("pl:u") { | ||
| 34 | static const FunctionInfo functions[] = { | ||
| 35 | {1, &PL_U::GetLoadState, "GetLoadState"}, | ||
| 36 | {2, &PL_U::GetSize, "GetSize"}, | ||
| 37 | {3, &PL_U::GetSharedMemoryAddressOffset, "GetSharedMemoryAddressOffset"}, | ||
| 38 | {4, &PL_U::GetSharedMemoryNativeHandle, "GetSharedMemoryNativeHandle"}}; | ||
| 39 | RegisterHandlers(functions); | ||
| 40 | |||
| 41 | // Attempt to load shared font data from disk | ||
| 42 | const std::string filepath{FileUtil::GetUserPath(D_SYSDATA_IDX) + SHARED_FONT}; | ||
| 43 | FileUtil::CreateFullPath(filepath); // Create path if not already created | ||
| 44 | FileUtil::IOFile file(filepath, "rb"); | ||
| 45 | |||
| 46 | if (file.IsOpen()) { | ||
| 47 | // Read shared font data | ||
| 48 | ASSERT(file.GetSize() == SHARED_FONT_MEM_SIZE); | ||
| 49 | shared_font = std::make_shared<std::vector<u8>>(static_cast<size_t>(file.GetSize())); | ||
| 50 | file.ReadBytes(shared_font->data(), shared_font->size()); | ||
| 51 | } else { | ||
| 52 | LOG_WARNING(Service_NS, "Unable to load shared font: %s", filepath.c_str()); | ||
| 53 | } | ||
| 54 | } | ||
| 55 | |||
| 56 | void PL_U::GetLoadState(Kernel::HLERequestContext& ctx) { | ||
| 57 | IPC::RequestParser rp{ctx}; | ||
| 58 | const u32 font_id{rp.Pop<u32>()}; | ||
| 59 | |||
| 60 | LOG_DEBUG(Service_NS, "called, font_id=%d", font_id); | ||
| 61 | IPC::ResponseBuilder rb{ctx, 3}; | ||
| 62 | rb.Push(RESULT_SUCCESS); | ||
| 63 | rb.Push<u32>(static_cast<u32>(LoadState::Done)); | ||
| 64 | } | ||
| 65 | |||
| 66 | void PL_U::GetSize(Kernel::HLERequestContext& ctx) { | ||
| 67 | IPC::RequestParser rp{ctx}; | ||
| 68 | const u32 font_id{rp.Pop<u32>()}; | ||
| 69 | |||
| 70 | LOG_DEBUG(Service_NS, "called, font_id=%d", font_id); | ||
| 71 | IPC::ResponseBuilder rb{ctx, 3}; | ||
| 72 | rb.Push(RESULT_SUCCESS); | ||
| 73 | rb.Push<u32>(SHARED_FONT_REGIONS[font_id].size); | ||
| 74 | } | ||
| 75 | |||
| 76 | void PL_U::GetSharedMemoryAddressOffset(Kernel::HLERequestContext& ctx) { | ||
| 77 | IPC::RequestParser rp{ctx}; | ||
| 78 | const u32 font_id{rp.Pop<u32>()}; | ||
| 79 | |||
| 80 | LOG_DEBUG(Service_NS, "called, font_id=%d", font_id); | ||
| 81 | IPC::ResponseBuilder rb{ctx, 3}; | ||
| 82 | rb.Push(RESULT_SUCCESS); | ||
| 83 | rb.Push<u32>(SHARED_FONT_REGIONS[font_id].offset); | ||
| 84 | } | ||
| 85 | |||
| 86 | void PL_U::GetSharedMemoryNativeHandle(Kernel::HLERequestContext& ctx) { | ||
| 87 | if (shared_font != nullptr) { | ||
| 88 | // TODO(bunnei): This is a less-than-ideal solution to load a RAM dump of the Switch shared | ||
| 89 | // font data. This (likely) relies on exact address, size, and offsets from the original | ||
| 90 | // dump. In the future, we need to replace this with a more robust solution. | ||
| 91 | |||
| 92 | // Map backing memory for the font data | ||
| 93 | Kernel::g_current_process->vm_manager.MapMemoryBlock(SHARED_FONT_MEM_VADDR, shared_font, 0, | ||
| 94 | SHARED_FONT_MEM_SIZE, | ||
| 95 | Kernel::MemoryState::Shared); | ||
| 96 | |||
| 97 | // Create shared font memory object | ||
| 98 | shared_font_mem = Kernel::SharedMemory::Create( | ||
| 99 | Kernel::g_current_process, SHARED_FONT_MEM_SIZE, Kernel::MemoryPermission::ReadWrite, | ||
| 100 | Kernel::MemoryPermission::Read, SHARED_FONT_MEM_VADDR, Kernel::MemoryRegion::BASE, | ||
| 101 | "PL_U:shared_font_mem"); | ||
| 102 | } | ||
| 103 | |||
| 104 | LOG_DEBUG(Service_NS, "called"); | ||
| 105 | IPC::ResponseBuilder rb{ctx, 2, 1}; | ||
| 106 | rb.Push(RESULT_SUCCESS); | ||
| 107 | rb.PushCopyObjects(shared_font_mem); | ||
| 108 | } | ||
| 109 | |||
| 110 | } // namespace NS | ||
| 111 | } // namespace Service | ||
diff --git a/src/core/hle/service/ns/pl_u.h b/src/core/hle/service/ns/pl_u.h new file mode 100644 index 000000000..7a4766338 --- /dev/null +++ b/src/core/hle/service/ns/pl_u.h | |||
| @@ -0,0 +1,33 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <memory> | ||
| 8 | #include "core/hle/kernel/shared_memory.h" | ||
| 9 | #include "core/hle/service/service.h" | ||
| 10 | |||
| 11 | namespace Service { | ||
| 12 | namespace NS { | ||
| 13 | |||
| 14 | class PL_U final : public ServiceFramework<PL_U> { | ||
| 15 | public: | ||
| 16 | PL_U(); | ||
| 17 | ~PL_U() = default; | ||
| 18 | |||
| 19 | private: | ||
| 20 | void GetLoadState(Kernel::HLERequestContext& ctx); | ||
| 21 | void GetSize(Kernel::HLERequestContext& ctx); | ||
| 22 | void GetSharedMemoryAddressOffset(Kernel::HLERequestContext& ctx); | ||
| 23 | void GetSharedMemoryNativeHandle(Kernel::HLERequestContext& ctx); | ||
| 24 | |||
| 25 | /// Handle to shared memory region designated for a shared font | ||
| 26 | Kernel::SharedPtr<Kernel::SharedMemory> shared_font_mem; | ||
| 27 | |||
| 28 | /// Backing memory for the shared font data | ||
| 29 | std::shared_ptr<std::vector<u8>> shared_font; | ||
| 30 | }; | ||
| 31 | |||
| 32 | } // namespace NS | ||
| 33 | } // namespace Service | ||
diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index 1dd04a12f..5e6d83729 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp | |||
| @@ -23,6 +23,7 @@ | |||
| 23 | #include "core/hle/service/hid/hid.h" | 23 | #include "core/hle/service/hid/hid.h" |
| 24 | #include "core/hle/service/lm/lm.h" | 24 | #include "core/hle/service/lm/lm.h" |
| 25 | #include "core/hle/service/nifm/nifm.h" | 25 | #include "core/hle/service/nifm/nifm.h" |
| 26 | #include "core/hle/service/ns/ns.h" | ||
| 26 | #include "core/hle/service/nvdrv/nvdrv.h" | 27 | #include "core/hle/service/nvdrv/nvdrv.h" |
| 27 | #include "core/hle/service/pctl/pctl.h" | 28 | #include "core/hle/service/pctl/pctl.h" |
| 28 | #include "core/hle/service/service.h" | 29 | #include "core/hle/service/service.h" |
| @@ -182,6 +183,7 @@ void Init() { | |||
| 182 | HID::InstallInterfaces(*SM::g_service_manager); | 183 | HID::InstallInterfaces(*SM::g_service_manager); |
| 183 | LM::InstallInterfaces(*SM::g_service_manager); | 184 | LM::InstallInterfaces(*SM::g_service_manager); |
| 184 | NIFM::InstallInterfaces(*SM::g_service_manager); | 185 | NIFM::InstallInterfaces(*SM::g_service_manager); |
| 186 | NS::InstallInterfaces(*SM::g_service_manager); | ||
| 185 | Nvidia::InstallInterfaces(*SM::g_service_manager); | 187 | Nvidia::InstallInterfaces(*SM::g_service_manager); |
| 186 | PCTL::InstallInterfaces(*SM::g_service_manager); | 188 | PCTL::InstallInterfaces(*SM::g_service_manager); |
| 187 | Sockets::InstallInterfaces(*SM::g_service_manager); | 189 | Sockets::InstallInterfaces(*SM::g_service_manager); |