diff options
Diffstat (limited to '')
-rw-r--r-- | src/core/arm/arm_interface.h | 4 | ||||
-rw-r--r-- | src/core/arm/dynarmic/arm_dynarmic.cpp | 8 | ||||
-rw-r--r-- | src/core/arm/dynarmic/arm_dynarmic.h | 2 | ||||
-rw-r--r-- | src/core/arm/unicorn/arm_unicorn.cpp | 10 | ||||
-rw-r--r-- | src/core/arm/unicorn/arm_unicorn.h | 2 | ||||
-rw-r--r-- | src/core/file_sys/errors.h | 16 | ||||
-rw-r--r-- | src/core/file_sys/vfs.cpp | 2 | ||||
-rw-r--r-- | src/core/file_sys/vfs.h | 27 | ||||
-rw-r--r-- | src/core/file_sys/vfs_offset.cpp | 5 | ||||
-rw-r--r-- | src/core/file_sys/vfs_offset.h | 2 | ||||
-rw-r--r-- | src/core/hle/kernel/scheduler.cpp | 3 | ||||
-rw-r--r-- | src/core/hle/kernel/thread.cpp | 1 | ||||
-rw-r--r-- | src/core/hle/kernel/thread.h | 9 | ||||
-rw-r--r-- | src/core/loader/deconstructed_rom_directory.cpp | 7 |
14 files changed, 64 insertions, 34 deletions
diff --git a/src/core/arm/arm_interface.h b/src/core/arm/arm_interface.h index a8273bb1c..b0d7ced7f 100644 --- a/src/core/arm/arm_interface.h +++ b/src/core/arm/arm_interface.h @@ -101,6 +101,10 @@ public: virtual void SetTlsAddress(VAddr address) = 0; + virtual u64 GetTPIDR_EL0() const = 0; + + virtual void SetTPIDR_EL0(u64 value) = 0; + /** * Saves the current CPU context * @param ctx Thread context to save diff --git a/src/core/arm/dynarmic/arm_dynarmic.cpp b/src/core/arm/dynarmic/arm_dynarmic.cpp index 4417c6da4..5d7efc9b6 100644 --- a/src/core/arm/dynarmic/arm_dynarmic.cpp +++ b/src/core/arm/dynarmic/arm_dynarmic.cpp @@ -196,6 +196,14 @@ void ARM_Dynarmic::SetTlsAddress(u64 address) { cb->tpidrro_el0 = address; } +u64 ARM_Dynarmic::GetTPIDR_EL0() const { + return cb->tpidr_el0; +} + +void ARM_Dynarmic::SetTPIDR_EL0(u64 value) { + cb->tpidr_el0 = value; +} + void ARM_Dynarmic::SaveContext(ARM_Interface::ThreadContext& ctx) { ctx.cpu_registers = jit->GetRegisters(); ctx.sp = jit->GetSP(); diff --git a/src/core/arm/dynarmic/arm_dynarmic.h b/src/core/arm/dynarmic/arm_dynarmic.h index ed724c3f1..a9891ac4f 100644 --- a/src/core/arm/dynarmic/arm_dynarmic.h +++ b/src/core/arm/dynarmic/arm_dynarmic.h @@ -34,6 +34,8 @@ public: void SetCPSR(u32 cpsr) override; VAddr GetTlsAddress() const override; void SetTlsAddress(VAddr address) override; + void SetTPIDR_EL0(u64 value) override; + u64 GetTPIDR_EL0() const override; void SaveContext(ThreadContext& ctx) override; void LoadContext(const ThreadContext& ctx) override; diff --git a/src/core/arm/unicorn/arm_unicorn.cpp b/src/core/arm/unicorn/arm_unicorn.cpp index b7afd9ed8..4c11f35a4 100644 --- a/src/core/arm/unicorn/arm_unicorn.cpp +++ b/src/core/arm/unicorn/arm_unicorn.cpp @@ -169,6 +169,16 @@ void ARM_Unicorn::SetTlsAddress(VAddr base) { CHECKED(uc_reg_write(uc, UC_ARM64_REG_TPIDRRO_EL0, &base)); } +u64 ARM_Unicorn::GetTPIDR_EL0() const { + u64 value{}; + CHECKED(uc_reg_read(uc, UC_ARM64_REG_TPIDR_EL0, &value)); + return value; +} + +void ARM_Unicorn::SetTPIDR_EL0(u64 value) { + CHECKED(uc_reg_write(uc, UC_ARM64_REG_TPIDR_EL0, &value)); +} + void ARM_Unicorn::Run() { if (GDBStub::IsServerEnabled()) { ExecuteInstructions(std::max(4000000, 0)); diff --git a/src/core/arm/unicorn/arm_unicorn.h b/src/core/arm/unicorn/arm_unicorn.h index a78a0acf2..af7943352 100644 --- a/src/core/arm/unicorn/arm_unicorn.h +++ b/src/core/arm/unicorn/arm_unicorn.h @@ -28,6 +28,8 @@ public: void SetCPSR(u32 cpsr) override; VAddr GetTlsAddress() const override; void SetTlsAddress(VAddr address) override; + void SetTPIDR_EL0(u64 value) override; + u64 GetTPIDR_EL0() const override; void SaveContext(ThreadContext& ctx) override; void LoadContext(const ThreadContext& ctx) override; void PrepareReschedule() override; diff --git a/src/core/file_sys/errors.h b/src/core/file_sys/errors.h index a152dbd33..fea0593c7 100644 --- a/src/core/file_sys/errors.h +++ b/src/core/file_sys/errors.h @@ -20,13 +20,13 @@ enum { constexpr ResultCode ERROR_PATH_NOT_FOUND(ErrorModule::FS, ErrCodes::NotFound); // TODO(bunnei): Replace these with correct errors for Switch OS -constexpr ResultCode ERROR_INVALID_PATH(ResultCode(-1)); -constexpr ResultCode ERROR_UNSUPPORTED_OPEN_FLAGS(ResultCode(-1)); -constexpr ResultCode ERROR_INVALID_OPEN_FLAGS(ResultCode(-1)); -constexpr ResultCode ERROR_FILE_NOT_FOUND(ResultCode(-1)); -constexpr ResultCode ERROR_UNEXPECTED_FILE_OR_DIRECTORY(ResultCode(-1)); -constexpr ResultCode ERROR_DIRECTORY_ALREADY_EXISTS(ResultCode(-1)); -constexpr ResultCode ERROR_FILE_ALREADY_EXISTS(ResultCode(-1)); -constexpr ResultCode ERROR_DIRECTORY_NOT_EMPTY(ResultCode(-1)); +constexpr ResultCode ERROR_INVALID_PATH(-1); +constexpr ResultCode ERROR_UNSUPPORTED_OPEN_FLAGS(-1); +constexpr ResultCode ERROR_INVALID_OPEN_FLAGS(-1); +constexpr ResultCode ERROR_FILE_NOT_FOUND(-1); +constexpr ResultCode ERROR_UNEXPECTED_FILE_OR_DIRECTORY(-1); +constexpr ResultCode ERROR_DIRECTORY_ALREADY_EXISTS(-1); +constexpr ResultCode ERROR_FILE_ALREADY_EXISTS(-1); +constexpr ResultCode ERROR_DIRECTORY_NOT_EMPTY(-1); } // namespace FileSys diff --git a/src/core/file_sys/vfs.cpp b/src/core/file_sys/vfs.cpp index 16c8ad90b..3f690f12a 100644 --- a/src/core/file_sys/vfs.cpp +++ b/src/core/file_sys/vfs.cpp @@ -42,7 +42,7 @@ bool VfsFile::WriteByte(u8 data, size_t offset) { return Write(&data, 1, offset) == 1; } -size_t VfsFile::WriteBytes(std::vector<u8> data, size_t offset) { +size_t VfsFile::WriteBytes(const std::vector<u8>& data, size_t offset) { return Write(data.data(), data.size(), offset); } diff --git a/src/core/file_sys/vfs.h b/src/core/file_sys/vfs.h index a5213e0cc..db3c77eac 100644 --- a/src/core/file_sys/vfs.h +++ b/src/core/file_sys/vfs.h @@ -59,8 +59,7 @@ struct VfsFile : NonCopyable { // Returns the number of bytes (sizeof(T)*number_elements) read successfully. template <typename T> size_t ReadArray(T* data, size_t number_elements, size_t offset = 0) const { - static_assert(std::is_trivially_copyable<T>::value, - "Data type must be trivially copyable."); + static_assert(std::is_trivially_copyable_v<T>, "Data type must be trivially copyable."); return Read(reinterpret_cast<u8*>(data), number_elements * sizeof(T), offset); } @@ -69,8 +68,7 @@ struct VfsFile : NonCopyable { // Returns the number of bytes read successfully. template <typename T> size_t ReadBytes(T* data, size_t size, size_t offset = 0) const { - static_assert(std::is_trivially_copyable<T>::value, - "Data type must be trivially copyable."); + static_assert(std::is_trivially_copyable_v<T>, "Data type must be trivially copyable."); return Read(reinterpret_cast<u8*>(data), size, offset); } @@ -78,8 +76,7 @@ struct VfsFile : NonCopyable { // Returns the number of bytes read successfully (sizeof(T)). template <typename T> size_t ReadObject(T* data, size_t offset = 0) const { - static_assert(std::is_trivially_copyable<T>::value, - "Data type must be trivially copyable."); + static_assert(std::is_trivially_copyable_v<T>, "Data type must be trivially copyable."); return Read(reinterpret_cast<u8*>(data), sizeof(T), offset); } @@ -88,33 +85,29 @@ struct VfsFile : NonCopyable { virtual bool WriteByte(u8 data, size_t offset = 0); // Writes a vector of bytes to offset in file and returns the number of bytes successfully // written. - virtual size_t WriteBytes(std::vector<u8> data, size_t offset = 0); + virtual size_t WriteBytes(const std::vector<u8>& data, size_t offset = 0); // Writes an array of type T, size number_elements to offset in file. // Returns the number of bytes (sizeof(T)*number_elements) written successfully. template <typename T> - size_t WriteArray(T* data, size_t number_elements, size_t offset = 0) { - static_assert(std::is_trivially_copyable<T>::value, - "Data type must be trivially copyable."); - + size_t WriteArray(const T* data, size_t number_elements, size_t offset = 0) { + static_assert(std::is_trivially_copyable_v<T>, "Data type must be trivially copyable."); return Write(data, number_elements * sizeof(T), offset); } // Writes size bytes starting at memory location data to offset in file. // Returns the number of bytes written successfully. template <typename T> - size_t WriteBytes(T* data, size_t size, size_t offset = 0) { - static_assert(std::is_trivially_copyable<T>::value, - "Data type must be trivially copyable."); - return Write(reinterpret_cast<u8*>(data), size, offset); + size_t WriteBytes(const T* data, size_t size, size_t offset = 0) { + static_assert(std::is_trivially_copyable_v<T>, "Data type must be trivially copyable."); + return Write(reinterpret_cast<const u8*>(data), size, offset); } // Writes one object of type T to offset in file. // Returns the number of bytes written successfully (sizeof(T)). template <typename T> size_t WriteObject(const T& data, size_t offset = 0) { - static_assert(std::is_trivially_copyable<T>::value, - "Data type must be trivially copyable."); + static_assert(std::is_trivially_copyable_v<T>, "Data type must be trivially copyable."); return Write(&data, sizeof(T), offset); } diff --git a/src/core/file_sys/vfs_offset.cpp b/src/core/file_sys/vfs_offset.cpp index 31fdd9aa1..217e02235 100644 --- a/src/core/file_sys/vfs_offset.cpp +++ b/src/core/file_sys/vfs_offset.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include <algorithm> #include <utility> #include "core/file_sys/vfs_offset.h" @@ -75,7 +76,7 @@ bool OffsetVfsFile::WriteByte(u8 data, size_t r_offset) { return false; } -size_t OffsetVfsFile::WriteBytes(std::vector<u8> data, size_t r_offset) { +size_t OffsetVfsFile::WriteBytes(const std::vector<u8>& data, size_t r_offset) { return file->Write(data.data(), TrimToFit(data.size(), r_offset), offset + r_offset); } @@ -88,7 +89,7 @@ size_t OffsetVfsFile::GetOffset() const { } size_t OffsetVfsFile::TrimToFit(size_t r_size, size_t r_offset) const { - return std::max<size_t>(std::min<size_t>(size - r_offset, r_size), 0); + return std::clamp(r_size, size_t{0}, size - r_offset); } } // namespace FileSys diff --git a/src/core/file_sys/vfs_offset.h b/src/core/file_sys/vfs_offset.h index 2e16e47eb..ded4827f5 100644 --- a/src/core/file_sys/vfs_offset.h +++ b/src/core/file_sys/vfs_offset.h @@ -28,7 +28,7 @@ struct OffsetVfsFile : public VfsFile { std::vector<u8> ReadBytes(size_t size, size_t offset) const override; std::vector<u8> ReadAllBytes() const override; bool WriteByte(u8 data, size_t offset) override; - size_t WriteBytes(std::vector<u8> data, size_t offset) override; + size_t WriteBytes(const std::vector<u8>& data, size_t offset) override; bool Rename(const std::string& name) override; diff --git a/src/core/hle/kernel/scheduler.cpp b/src/core/hle/kernel/scheduler.cpp index f7e25cbf5..e307eec98 100644 --- a/src/core/hle/kernel/scheduler.cpp +++ b/src/core/hle/kernel/scheduler.cpp @@ -56,6 +56,8 @@ void Scheduler::SwitchContext(Thread* new_thread) { if (previous_thread) { previous_thread->last_running_ticks = CoreTiming::GetTicks(); cpu_core->SaveContext(previous_thread->context); + // Save the TPIDR_EL0 system register in case it was modified. + previous_thread->tpidr_el0 = cpu_core->GetTPIDR_EL0(); if (previous_thread->status == ThreadStatus::Running) { // This is only the case when a reschedule is triggered without the current thread @@ -87,6 +89,7 @@ void Scheduler::SwitchContext(Thread* new_thread) { cpu_core->LoadContext(new_thread->context); cpu_core->SetTlsAddress(new_thread->GetTLSAddress()); + cpu_core->SetTPIDR_EL0(new_thread->GetTPIDR_EL0()); cpu_core->ClearExclusiveState(); } else { current_thread = nullptr; diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index 53f2e861e..cd85c4b7c 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp @@ -312,6 +312,7 @@ ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point, thread->status = ThreadStatus::Dormant; thread->entry_point = entry_point; thread->stack_top = stack_top; + thread->tpidr_el0 = 0; thread->nominal_priority = thread->current_priority = priority; thread->last_running_ticks = CoreTiming::GetTicks(); thread->processor_id = processor_id; diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h index 47881ec20..6218960d2 100644 --- a/src/core/hle/kernel/thread.h +++ b/src/core/hle/kernel/thread.h @@ -183,6 +183,14 @@ public: } /* + * Returns the value of the TPIDR_EL0 Read/Write system register for this thread. + * @returns The value of the TPIDR_EL0 register. + */ + u64 GetTPIDR_EL0() const { + return tpidr_el0; + } + + /* * Returns the address of the current thread's command buffer, located in the TLS. * @returns VAddr of the thread's command buffer. */ @@ -213,6 +221,7 @@ public: s32 processor_id; VAddr tls_address; ///< Virtual address of the Thread Local Storage of the thread + u64 tpidr_el0; ///< TPIDR_EL0 read/write system register. SharedPtr<Process> owner_process; ///< Process that owns this thread diff --git a/src/core/loader/deconstructed_rom_directory.cpp b/src/core/loader/deconstructed_rom_directory.cpp index 19b8667ba..394963a69 100644 --- a/src/core/loader/deconstructed_rom_directory.cpp +++ b/src/core/loader/deconstructed_rom_directory.cpp @@ -83,16 +83,13 @@ ResultStatus AppLoader_DeconstructedRomDirectory::Load( VAddr next_load_addr{Memory::PROCESS_IMAGE_VADDR}; for (const auto& module : {"rtld", "main", "subsdk0", "subsdk1", "subsdk2", "subsdk3", "subsdk4", "subsdk5", "subsdk6", "subsdk7", "sdk"}) { - const VAddr load_addr = next_load_addr; const FileSys::VirtualFile module_file = dir->GetFile(module); - if (module_file != nullptr) + if (module_file != nullptr) { + const VAddr load_addr = next_load_addr; next_load_addr = AppLoader_NSO::LoadModule(module_file, load_addr); - if (next_load_addr) { LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", module, load_addr); // Register module with GDBStub GDBStub::RegisterModule(module, load_addr, next_load_addr - 1, false); - } else { - next_load_addr = load_addr; } } |