From fb70c9683c088233810abe298d587eaf671f6041 Mon Sep 17 00:00:00 2001 From: Lectem Date: Fri, 30 Dec 2016 15:54:40 +0100 Subject: [PATCH] move push out of class body and add u8 u16 bool specializations --- src/core/hle/ipc.h | 7 +- src/core/hle/ipc_helpers.h | 152 +++++++++++++++++++++---------- src/core/hle/service/ptm/ptm.cpp | 2 +- src/core/hle/service/y2r_u.cpp | 8 +- 4 files changed, 114 insertions(+), 55 deletions(-) diff --git a/src/core/hle/ipc.h b/src/core/hle/ipc.h index cd9a5863d..3a5d481a5 100644 --- a/src/core/hle/ipc.h +++ b/src/core/hle/ipc.h @@ -10,7 +10,8 @@ namespace Kernel { -static const int kCommandHeaderOffset = 0x80; ///< Offset into command buffer of header +/// Offset into command buffer of header +static const int kCommandHeaderOffset = 0x80; /** * Returns a pointer to the command buffer in the current thread's TLS @@ -26,8 +27,8 @@ inline u32* GetCommandBuffer(const int offset = 0) { offset); } -static const int kStaticBuffersOffset = - 0x100; ///< Offset into static buffers, relative to command buffer header +/// Offset into static buffers, relative to command buffer header +static const int kStaticBuffersOffset = 0x100; /** * Returns a pointer to the static buffers area in the current thread's TLS diff --git a/src/core/hle/ipc_helpers.h b/src/core/hle/ipc_helpers.h index 11a33c8bd..263b0ff5d 100644 --- a/src/core/hle/ipc_helpers.h +++ b/src/core/hle/ipc_helpers.h @@ -62,14 +62,8 @@ public: template void Push(T value); - void Push(u32 value) { - cmdbuf[index++] = value; - } template - void Push(const First& first_value, const Other&... other_values) { - Push(first_value); - Push(other_values...); - } + void Push(const First& first_value, const Other&... other_values); /** * @brief Copies the content of the given trivially copyable class to the buffer as a normal @@ -77,59 +71,96 @@ public: * @note: The input class must be correctly packed/padded to fit hardware layout. */ template - void PushRaw(const T& value) { - static_assert(std::is_trivially_copyable(), "Raw types should be trivially copyable"); - std::memcpy(cmdbuf + index, &value, sizeof(T)); - index += (sizeof(T) + 3) / 4; // round up to word length - } + void PushRaw(const T& value); // TODO : ensure that translate params are added after all regular params template - void PushCopyHandles(H... handles) { - Push(CopyHandleDesc(sizeof...(H))); - Push(static_cast(handles)...); - } + void PushCopyHandles(H... handles); template - void PushMoveHandles(H... handles) { - Push(MoveHandleDesc(sizeof...(H))); - Push(static_cast(handles)...); - } + void PushMoveHandles(H... handles); - void PushCurrentPIDHandle() { - Push(CallingPidDesc()); - Push(u32(0)); - } + void PushCurrentPIDHandle(); - void PushStaticBuffer(VAddr buffer_vaddr, u32 size, u8 buffer_id) { - Push(StaticBufferDesc(size, buffer_id)); - Push(buffer_vaddr); - } + void PushStaticBuffer(VAddr buffer_vaddr, u32 size, u8 buffer_id); - void PushMappedBuffer(VAddr buffer_vaddr, u32 size, MappedBufferPermissions perms) { - Push(MappedBufferDesc(size, perms)); - Push(buffer_vaddr); - } + void PushMappedBuffer(VAddr buffer_vaddr, u32 size, MappedBufferPermissions perms); }; /// Push /// template <> -inline void RequestBuilder::Push(u32 value) { - Push(value); +inline void RequestBuilder::Push(u32 value) { + cmdbuf[index++] = value; +} + +template +void RequestBuilder::PushRaw(const T& value) { + static_assert(std::is_trivially_copyable(), "Raw types should be trivially copyable"); + std::memcpy(cmdbuf + index, &value, sizeof(T)); + index += (sizeof(T) + 3) / 4; // round up to word length } template <> -inline void RequestBuilder::Push(u64 value) { +inline void RequestBuilder::Push(u8 value) { + PushRaw(value); +} + +template <> +inline void RequestBuilder::Push(u16 value) { + PushRaw(value); +} + +template <> +inline void RequestBuilder::Push(u64 value) { Push(static_cast(value)); Push(static_cast(value >> 32)); } template <> -inline void RequestBuilder::Push(ResultCode value) { +inline void RequestBuilder::Push(bool value) { + Push(u8(value)); +} + +template <> +inline void RequestBuilder::Push(ResultCode value) { Push(value.raw); } +template +void RequestBuilder::Push(const First& first_value, const Other&... other_values) { + Push(first_value); + Push(other_values...); +} + +template +inline void RequestBuilder::PushCopyHandles(H... handles) { + Push(CopyHandleDesc(sizeof...(H))); + Push(static_cast(handles)...); +} + +template +inline void RequestBuilder::PushMoveHandles(H... handles) { + Push(MoveHandleDesc(sizeof...(H))); + Push(static_cast(handles)...); +} + +inline void RequestBuilder::PushCurrentPIDHandle() { + Push(CallingPidDesc()); + Push(u32(0)); +} + +inline void RequestBuilder::PushStaticBuffer(VAddr buffer_vaddr, u32 size, u8 buffer_id) { + Push(StaticBufferDesc(size, buffer_id)); + Push(buffer_vaddr); +} + +inline void RequestBuilder::PushMappedBuffer(VAddr buffer_vaddr, u32 size, + MappedBufferPermissions perms) { + Push(MappedBufferDesc(size, perms)); + Push(buffer_vaddr); +} + class RequestParser : public RequestHelperBase { public: RequestParser(u32* command_buffer, Header command_header) @@ -197,24 +228,60 @@ public: */ template void PopRaw(T& value); + + /** + * @brief Reads the next normal parameters as a struct, by copying it into a new value + * @note: The output class must be correctly packed/padded to fit hardware layout. + */ + template + T PopRaw(); }; /// Pop /// template <> -inline u32 RequestParser::Pop() { +inline u32 RequestParser::Pop() { return cmdbuf[index++]; } +template +void RequestParser::PopRaw(T& value) { + static_assert(std::is_trivially_copyable(), "Raw types should be trivially copyable"); + std::memcpy(&value, cmdbuf + index, sizeof(T)); + index += (sizeof(T) + 3) / 4; // round up to word length +} + +template +T RequestParser::PopRaw() { + T value; + PopRaw(value); + return value; +} + template <> -inline u64 RequestParser::Pop() { +inline u8 RequestParser::Pop() { + return PopRaw(); +} + +template <> +inline u16 RequestParser::Pop() { + return PopRaw(); +} + +template <> +inline u64 RequestParser::Pop() { const u64 lsw = Pop(); const u64 msw = Pop(); return msw << 32 | lsw; } template <> -inline ResultCode RequestParser::Pop() { +inline bool RequestParser::Pop() { + return Pop() != 0; // != 0 to remove warning C4800 +} + +template <> +inline ResultCode RequestParser::Pop() { return ResultCode{Pop()}; } @@ -277,11 +344,4 @@ inline VAddr RequestParser::PopMappedBuffer(size_t* data_size, return Pop(); } -template -void RequestParser::PopRaw(T& value) { - static_assert(std::is_trivially_copyable(), "Raw types should be trivially copyable"); - std::memcpy(&value, cmdbuf + index, sizeof(T)); - index += (sizeof(T) + 3) / 4; // round up to word length -} - } // namespace IPC diff --git a/src/core/hle/service/ptm/ptm.cpp b/src/core/hle/service/ptm/ptm.cpp index 016ac8d4f..bdfa7391a 100644 --- a/src/core/hle/service/ptm/ptm.cpp +++ b/src/core/hle/service/ptm/ptm.cpp @@ -101,7 +101,7 @@ void CheckNew3DS(IPC::RequestBuilder& rb) { } rb.Push(RESULT_SUCCESS); - rb.Push(u32(is_new_3ds ? 1 : 0)); + rb.Push(is_new_3ds); LOG_WARNING(Service_PTM, "(STUBBED) called isNew3DS = 0x%08x", static_cast(is_new_3ds)); } diff --git a/src/core/hle/service/y2r_u.cpp b/src/core/hle/service/y2r_u.cpp index 907d9c8fa..cfea62962 100644 --- a/src/core/hle/service/y2r_u.cpp +++ b/src/core/hle/service/y2r_u.cpp @@ -189,11 +189,9 @@ static void SetSpacialDithering(Interface* self) { * 2 : u8, 0 = Disabled, 1 = Enabled */ static void GetSpacialDithering(Interface* self) { - u32* cmd_buff = Kernel::GetCommandBuffer(); - - cmd_buff[0] = IPC::MakeHeader(0xA, 2, 0); - cmd_buff[1] = RESULT_SUCCESS.raw; - cmd_buff[2] = spacial_dithering_enabled; + IPC::RequestBuilder rb(Kernel::GetCommandBuffer(), 0xA, 2, 0); + rb.Push(RESULT_SUCCESS); + rb.Push(bool(spacial_dithering_enabled)); LOG_WARNING(Service_Y2R, "(STUBBED) called"); }