diff options
| author | 2016-12-30 15:54:40 +0100 | |
|---|---|---|
| committer | 2017-03-18 10:44:01 +0100 | |
| commit | fb70c9683c088233810abe298d587eaf671f6041 (patch) | |
| tree | 1d2720d2d362d7c6b5381c83f4f8df0aabee1bc7 /src | |
| parent | refactor APT service to use the new IPC helpers (diff) | |
| download | yuzu-fb70c9683c088233810abe298d587eaf671f6041.tar.gz yuzu-fb70c9683c088233810abe298d587eaf671f6041.tar.xz yuzu-fb70c9683c088233810abe298d587eaf671f6041.zip | |
move push out of class body and add u8 u16 bool specializations
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/ipc.h | 7 | ||||
| -rw-r--r-- | src/core/hle/ipc_helpers.h | 152 | ||||
| -rw-r--r-- | src/core/hle/service/ptm/ptm.cpp | 2 | ||||
| -rw-r--r-- | 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 @@ | |||
| 10 | 10 | ||
| 11 | namespace Kernel { | 11 | namespace Kernel { |
| 12 | 12 | ||
| 13 | static const int kCommandHeaderOffset = 0x80; ///< Offset into command buffer of header | 13 | /// Offset into command buffer of header |
| 14 | static const int kCommandHeaderOffset = 0x80; | ||
| 14 | 15 | ||
| 15 | /** | 16 | /** |
| 16 | * Returns a pointer to the command buffer in the current thread's TLS | 17 | * Returns a pointer to the command buffer in the current thread's TLS |
| @@ -26,8 +27,8 @@ inline u32* GetCommandBuffer(const int offset = 0) { | |||
| 26 | offset); | 27 | offset); |
| 27 | } | 28 | } |
| 28 | 29 | ||
| 29 | static const int kStaticBuffersOffset = | 30 | /// Offset into static buffers, relative to command buffer header |
| 30 | 0x100; ///< Offset into static buffers, relative to command buffer header | 31 | static const int kStaticBuffersOffset = 0x100; |
| 31 | 32 | ||
| 32 | /** | 33 | /** |
| 33 | * Returns a pointer to the static buffers area in the current thread's TLS | 34 | * 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: | |||
| 62 | template <typename T> | 62 | template <typename T> |
| 63 | void Push(T value); | 63 | void Push(T value); |
| 64 | 64 | ||
| 65 | void Push(u32 value) { | ||
| 66 | cmdbuf[index++] = value; | ||
| 67 | } | ||
| 68 | template <typename First, typename... Other> | 65 | template <typename First, typename... Other> |
| 69 | void Push(const First& first_value, const Other&... other_values) { | 66 | void Push(const First& first_value, const Other&... other_values); |
| 70 | Push(first_value); | ||
| 71 | Push(other_values...); | ||
| 72 | } | ||
| 73 | 67 | ||
| 74 | /** | 68 | /** |
| 75 | * @brief Copies the content of the given trivially copyable class to the buffer as a normal | 69 | * @brief Copies the content of the given trivially copyable class to the buffer as a normal |
| @@ -77,59 +71,96 @@ public: | |||
| 77 | * @note: The input class must be correctly packed/padded to fit hardware layout. | 71 | * @note: The input class must be correctly packed/padded to fit hardware layout. |
| 78 | */ | 72 | */ |
| 79 | template <typename T> | 73 | template <typename T> |
| 80 | void PushRaw(const T& value) { | 74 | void PushRaw(const T& value); |
| 81 | static_assert(std::is_trivially_copyable<T>(), "Raw types should be trivially copyable"); | ||
| 82 | std::memcpy(cmdbuf + index, &value, sizeof(T)); | ||
| 83 | index += (sizeof(T) + 3) / 4; // round up to word length | ||
| 84 | } | ||
| 85 | 75 | ||
| 86 | // TODO : ensure that translate params are added after all regular params | 76 | // TODO : ensure that translate params are added after all regular params |
| 87 | template <typename... H> | 77 | template <typename... H> |
| 88 | void PushCopyHandles(H... handles) { | 78 | void PushCopyHandles(H... handles); |
| 89 | Push(CopyHandleDesc(sizeof...(H))); | ||
| 90 | Push(static_cast<Kernel::Handle>(handles)...); | ||
| 91 | } | ||
| 92 | 79 | ||
| 93 | template <typename... H> | 80 | template <typename... H> |
| 94 | void PushMoveHandles(H... handles) { | 81 | void PushMoveHandles(H... handles); |
| 95 | Push(MoveHandleDesc(sizeof...(H))); | ||
| 96 | Push(static_cast<Kernel::Handle>(handles)...); | ||
| 97 | } | ||
| 98 | 82 | ||
| 99 | void PushCurrentPIDHandle() { | 83 | void PushCurrentPIDHandle(); |
| 100 | Push(CallingPidDesc()); | ||
| 101 | Push(u32(0)); | ||
| 102 | } | ||
| 103 | 84 | ||
| 104 | void PushStaticBuffer(VAddr buffer_vaddr, u32 size, u8 buffer_id) { | 85 | void PushStaticBuffer(VAddr buffer_vaddr, u32 size, u8 buffer_id); |
| 105 | Push(StaticBufferDesc(size, buffer_id)); | ||
| 106 | Push(buffer_vaddr); | ||
| 107 | } | ||
| 108 | 86 | ||
| 109 | void PushMappedBuffer(VAddr buffer_vaddr, u32 size, MappedBufferPermissions perms) { | 87 | void PushMappedBuffer(VAddr buffer_vaddr, u32 size, MappedBufferPermissions perms); |
| 110 | Push(MappedBufferDesc(size, perms)); | ||
| 111 | Push(buffer_vaddr); | ||
| 112 | } | ||
| 113 | }; | 88 | }; |
| 114 | 89 | ||
| 115 | /// Push /// | 90 | /// Push /// |
| 116 | 91 | ||
| 117 | template <> | 92 | template <> |
| 118 | inline void RequestBuilder::Push<u32>(u32 value) { | 93 | inline void RequestBuilder::Push(u32 value) { |
| 119 | Push(value); | 94 | cmdbuf[index++] = value; |
| 95 | } | ||
| 96 | |||
| 97 | template <typename T> | ||
| 98 | void RequestBuilder::PushRaw(const T& value) { | ||
| 99 | static_assert(std::is_trivially_copyable<T>(), "Raw types should be trivially copyable"); | ||
| 100 | std::memcpy(cmdbuf + index, &value, sizeof(T)); | ||
| 101 | index += (sizeof(T) + 3) / 4; // round up to word length | ||
| 102 | } | ||
| 103 | |||
| 104 | template <> | ||
| 105 | inline void RequestBuilder::Push(u8 value) { | ||
| 106 | PushRaw(value); | ||
| 107 | } | ||
| 108 | |||
| 109 | template <> | ||
| 110 | inline void RequestBuilder::Push(u16 value) { | ||
| 111 | PushRaw(value); | ||
| 120 | } | 112 | } |
| 121 | 113 | ||
| 122 | template <> | 114 | template <> |
| 123 | inline void RequestBuilder::Push<u64>(u64 value) { | 115 | inline void RequestBuilder::Push(u64 value) { |
| 124 | Push(static_cast<u32>(value)); | 116 | Push(static_cast<u32>(value)); |
| 125 | Push(static_cast<u32>(value >> 32)); | 117 | Push(static_cast<u32>(value >> 32)); |
| 126 | } | 118 | } |
| 127 | 119 | ||
| 128 | template <> | 120 | template <> |
| 129 | inline void RequestBuilder::Push<ResultCode>(ResultCode value) { | 121 | inline void RequestBuilder::Push(bool value) { |
| 122 | Push(u8(value)); | ||
| 123 | } | ||
| 124 | |||
| 125 | template <> | ||
| 126 | inline void RequestBuilder::Push(ResultCode value) { | ||
| 130 | Push(value.raw); | 127 | Push(value.raw); |
| 131 | } | 128 | } |
| 132 | 129 | ||
| 130 | template <typename First, typename... Other> | ||
| 131 | void RequestBuilder::Push(const First& first_value, const Other&... other_values) { | ||
| 132 | Push(first_value); | ||
| 133 | Push(other_values...); | ||
| 134 | } | ||
| 135 | |||
| 136 | template <typename... H> | ||
| 137 | inline void RequestBuilder::PushCopyHandles(H... handles) { | ||
| 138 | Push(CopyHandleDesc(sizeof...(H))); | ||
| 139 | Push(static_cast<Kernel::Handle>(handles)...); | ||
| 140 | } | ||
| 141 | |||
| 142 | template <typename... H> | ||
| 143 | inline void RequestBuilder::PushMoveHandles(H... handles) { | ||
| 144 | Push(MoveHandleDesc(sizeof...(H))); | ||
| 145 | Push(static_cast<Kernel::Handle>(handles)...); | ||
| 146 | } | ||
| 147 | |||
| 148 | inline void RequestBuilder::PushCurrentPIDHandle() { | ||
| 149 | Push(CallingPidDesc()); | ||
| 150 | Push(u32(0)); | ||
| 151 | } | ||
| 152 | |||
| 153 | inline void RequestBuilder::PushStaticBuffer(VAddr buffer_vaddr, u32 size, u8 buffer_id) { | ||
| 154 | Push(StaticBufferDesc(size, buffer_id)); | ||
| 155 | Push(buffer_vaddr); | ||
| 156 | } | ||
| 157 | |||
| 158 | inline void RequestBuilder::PushMappedBuffer(VAddr buffer_vaddr, u32 size, | ||
| 159 | MappedBufferPermissions perms) { | ||
| 160 | Push(MappedBufferDesc(size, perms)); | ||
| 161 | Push(buffer_vaddr); | ||
| 162 | } | ||
| 163 | |||
| 133 | class RequestParser : public RequestHelperBase { | 164 | class RequestParser : public RequestHelperBase { |
| 134 | public: | 165 | public: |
| 135 | RequestParser(u32* command_buffer, Header command_header) | 166 | RequestParser(u32* command_buffer, Header command_header) |
| @@ -197,24 +228,60 @@ public: | |||
| 197 | */ | 228 | */ |
| 198 | template <typename T> | 229 | template <typename T> |
| 199 | void PopRaw(T& value); | 230 | void PopRaw(T& value); |
| 231 | |||
| 232 | /** | ||
| 233 | * @brief Reads the next normal parameters as a struct, by copying it into a new value | ||
| 234 | * @note: The output class must be correctly packed/padded to fit hardware layout. | ||
| 235 | */ | ||
| 236 | template <typename T> | ||
| 237 | T PopRaw(); | ||
| 200 | }; | 238 | }; |
| 201 | 239 | ||
| 202 | /// Pop /// | 240 | /// Pop /// |
| 203 | 241 | ||
| 204 | template <> | 242 | template <> |
| 205 | inline u32 RequestParser::Pop<u32>() { | 243 | inline u32 RequestParser::Pop() { |
| 206 | return cmdbuf[index++]; | 244 | return cmdbuf[index++]; |
| 207 | } | 245 | } |
| 208 | 246 | ||
| 247 | template <typename T> | ||
| 248 | void RequestParser::PopRaw(T& value) { | ||
| 249 | static_assert(std::is_trivially_copyable<T>(), "Raw types should be trivially copyable"); | ||
| 250 | std::memcpy(&value, cmdbuf + index, sizeof(T)); | ||
| 251 | index += (sizeof(T) + 3) / 4; // round up to word length | ||
| 252 | } | ||
| 253 | |||
| 254 | template <typename T> | ||
| 255 | T RequestParser::PopRaw() { | ||
| 256 | T value; | ||
| 257 | PopRaw(value); | ||
| 258 | return value; | ||
| 259 | } | ||
| 260 | |||
| 209 | template <> | 261 | template <> |
| 210 | inline u64 RequestParser::Pop<u64>() { | 262 | inline u8 RequestParser::Pop() { |
| 263 | return PopRaw<u8>(); | ||
| 264 | } | ||
| 265 | |||
| 266 | template <> | ||
| 267 | inline u16 RequestParser::Pop() { | ||
| 268 | return PopRaw<u16>(); | ||
| 269 | } | ||
| 270 | |||
| 271 | template <> | ||
| 272 | inline u64 RequestParser::Pop() { | ||
| 211 | const u64 lsw = Pop<u32>(); | 273 | const u64 lsw = Pop<u32>(); |
| 212 | const u64 msw = Pop<u32>(); | 274 | const u64 msw = Pop<u32>(); |
| 213 | return msw << 32 | lsw; | 275 | return msw << 32 | lsw; |
| 214 | } | 276 | } |
| 215 | 277 | ||
| 216 | template <> | 278 | template <> |
| 217 | inline ResultCode RequestParser::Pop<ResultCode>() { | 279 | inline bool RequestParser::Pop() { |
| 280 | return Pop<u8>() != 0; // != 0 to remove warning C4800 | ||
| 281 | } | ||
| 282 | |||
| 283 | template <> | ||
| 284 | inline ResultCode RequestParser::Pop() { | ||
| 218 | return ResultCode{Pop<u32>()}; | 285 | return ResultCode{Pop<u32>()}; |
| 219 | } | 286 | } |
| 220 | 287 | ||
| @@ -277,11 +344,4 @@ inline VAddr RequestParser::PopMappedBuffer(size_t* data_size, | |||
| 277 | return Pop<VAddr>(); | 344 | return Pop<VAddr>(); |
| 278 | } | 345 | } |
| 279 | 346 | ||
| 280 | template <typename T> | ||
| 281 | void RequestParser::PopRaw(T& value) { | ||
| 282 | static_assert(std::is_trivially_copyable<T>(), "Raw types should be trivially copyable"); | ||
| 283 | std::memcpy(&value, cmdbuf + index, sizeof(T)); | ||
| 284 | index += (sizeof(T) + 3) / 4; // round up to word length | ||
| 285 | } | ||
| 286 | |||
| 287 | } // namespace IPC | 347 | } // 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) { | |||
| 101 | } | 101 | } |
| 102 | 102 | ||
| 103 | rb.Push(RESULT_SUCCESS); | 103 | rb.Push(RESULT_SUCCESS); |
| 104 | rb.Push(u32(is_new_3ds ? 1 : 0)); | 104 | rb.Push(is_new_3ds); |
| 105 | 105 | ||
| 106 | LOG_WARNING(Service_PTM, "(STUBBED) called isNew3DS = 0x%08x", static_cast<u32>(is_new_3ds)); | 106 | LOG_WARNING(Service_PTM, "(STUBBED) called isNew3DS = 0x%08x", static_cast<u32>(is_new_3ds)); |
| 107 | } | 107 | } |
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) { | |||
| 189 | * 2 : u8, 0 = Disabled, 1 = Enabled | 189 | * 2 : u8, 0 = Disabled, 1 = Enabled |
| 190 | */ | 190 | */ |
| 191 | static void GetSpacialDithering(Interface* self) { | 191 | static void GetSpacialDithering(Interface* self) { |
| 192 | u32* cmd_buff = Kernel::GetCommandBuffer(); | 192 | IPC::RequestBuilder rb(Kernel::GetCommandBuffer(), 0xA, 2, 0); |
| 193 | 193 | rb.Push(RESULT_SUCCESS); | |
| 194 | cmd_buff[0] = IPC::MakeHeader(0xA, 2, 0); | 194 | rb.Push(bool(spacial_dithering_enabled)); |
| 195 | cmd_buff[1] = RESULT_SUCCESS.raw; | ||
| 196 | cmd_buff[2] = spacial_dithering_enabled; | ||
| 197 | 195 | ||
| 198 | LOG_WARNING(Service_Y2R, "(STUBBED) called"); | 196 | LOG_WARNING(Service_Y2R, "(STUBBED) called"); |
| 199 | } | 197 | } |