diff options
| author | 2014-06-01 13:58:14 +0200 | |
|---|---|---|
| committer | 2014-07-23 00:33:05 +0200 | |
| commit | cb8f49b7eaeb071d875fa59142124e4a5c1e0f7d (patch) | |
| tree | 4d860bedf9382550d94f6eaf9a5b443039d399b6 /src | |
| parent | Use a more compatible choice of initial framebuffer addresses. (diff) | |
| download | yuzu-cb8f49b7eaeb071d875fa59142124e4a5c1e0f7d.tar.gz yuzu-cb8f49b7eaeb071d875fa59142124e4a5c1e0f7d.tar.xz yuzu-cb8f49b7eaeb071d875fa59142124e4a5c1e0f7d.zip | |
GSP: Implement ReadHWRegs and WriteHWRegs properly.
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/service/gsp.cpp | 73 |
1 files changed, 46 insertions, 27 deletions
diff --git a/src/core/hle/service/gsp.cpp b/src/core/hle/service/gsp.cpp index 1fdbdf342..cc111b0bb 100644 --- a/src/core/hle/service/gsp.cpp +++ b/src/core/hle/service/gsp.cpp | |||
| @@ -47,11 +47,6 @@ Handle g_shared_memory = 0; | |||
| 47 | 47 | ||
| 48 | u32 g_thread_id = 0; | 48 | u32 g_thread_id = 0; |
| 49 | 49 | ||
| 50 | enum { | ||
| 51 | REG_FRAMEBUFFER_1 = 0x00400468, | ||
| 52 | REG_FRAMEBUFFER_2 = 0x00400494, | ||
| 53 | }; | ||
| 54 | |||
| 55 | /// Gets a pointer to the start (header) of a command buffer in GSP shared memory | 50 | /// Gets a pointer to the start (header) of a command buffer in GSP shared memory |
| 56 | static inline u8* GX_GetCmdBufferPointer(u32 thread_id, u32 offset=0) { | 51 | static inline u8* GX_GetCmdBufferPointer(u32 thread_id, u32 offset=0) { |
| 57 | return Kernel::GetSharedMemoryPointer(g_shared_memory, 0x800 + (thread_id * 0x200) + offset); | 52 | return Kernel::GetSharedMemoryPointer(g_shared_memory, 0x800 + (thread_id * 0x200) + offset); |
| @@ -67,38 +62,62 @@ void GX_FinishCommand(u32 thread_id) { | |||
| 67 | // TODO: Increment header->index? | 62 | // TODO: Increment header->index? |
| 68 | } | 63 | } |
| 69 | 64 | ||
| 65 | /// Write a GSP GPU hardware register | ||
| 66 | void WriteHWRegs(Service::Interface* self) { | ||
| 67 | u32* cmd_buff = Service::GetCommandBuffer(); | ||
| 68 | u32 reg_addr = cmd_buff[1]; | ||
| 69 | u32 size = cmd_buff[2]; | ||
| 70 | |||
| 71 | // TODO: Return proper error codes | ||
| 72 | if (reg_addr + size >= 0x420000) { | ||
| 73 | ERROR_LOG(GPU, "Write address out of range! (address=0x%08x, size=0x%08x)", reg_addr, size); | ||
| 74 | return; | ||
| 75 | } | ||
| 76 | |||
| 77 | // size should be word-aligned | ||
| 78 | if ((size % 4) != 0) { | ||
| 79 | ERROR_LOG(GPU, "Invalid size 0x%08x", size); | ||
| 80 | return; | ||
| 81 | } | ||
| 82 | |||
| 83 | u32* src = (u32*)Memory::GetPointer(cmd_buff[0x4]); | ||
| 84 | |||
| 85 | while (size > 0) { | ||
| 86 | GPU::Write<u32>(reg_addr + 0x1EB00000, *src); | ||
| 87 | |||
| 88 | size -= 4; | ||
| 89 | ++src; | ||
| 90 | reg_addr += 4; | ||
| 91 | } | ||
| 92 | } | ||
| 93 | |||
| 70 | /// Read a GSP GPU hardware register | 94 | /// Read a GSP GPU hardware register |
| 71 | void ReadHWRegs(Service::Interface* self) { | 95 | void ReadHWRegs(Service::Interface* self) { |
| 72 | static const u32 framebuffer_1[] = {GPU::PADDR_VRAM_TOP_LEFT_FRAME1, GPU::PADDR_VRAM_TOP_RIGHT_FRAME1}; | ||
| 73 | static const u32 framebuffer_2[] = {GPU::PADDR_VRAM_TOP_LEFT_FRAME2, GPU::PADDR_VRAM_TOP_RIGHT_FRAME2}; | ||
| 74 | |||
| 75 | u32* cmd_buff = Service::GetCommandBuffer(); | 96 | u32* cmd_buff = Service::GetCommandBuffer(); |
| 76 | u32 reg_addr = cmd_buff[1]; | 97 | u32 reg_addr = cmd_buff[1]; |
| 77 | u32 size = cmd_buff[2]; | 98 | u32 size = cmd_buff[2]; |
| 78 | u32* dst = (u32*)Memory::GetPointer(cmd_buff[0x41]); | ||
| 79 | 99 | ||
| 80 | switch (reg_addr) { | 100 | // TODO: Return proper error codes |
| 101 | if (reg_addr + size >= 0x420000) { | ||
| 102 | ERROR_LOG(GPU, "Read address out of range! (address=0x%08x, size=0x%08x)", reg_addr, size); | ||
| 103 | return; | ||
| 104 | } | ||
| 81 | 105 | ||
| 82 | // NOTE: Calling SetFramebufferLocation here is a hack... Not sure the correct way yet to set | 106 | // size should be word-aligned |
| 83 | // whether the framebuffers should be in VRAM or GSP heap, but from what I understand, if the | 107 | if ((size % 4) != 0) { |
| 84 | // user application is reading from either of these registers, then its going to be in VRAM. | 108 | ERROR_LOG(GPU, "Invalid size 0x%08x", size); |
| 109 | return; | ||
| 110 | } | ||
| 85 | 111 | ||
| 86 | // Top framebuffer 1 addresses | 112 | u32* dst = (u32*)Memory::GetPointer(cmd_buff[0x41]); |
| 87 | case REG_FRAMEBUFFER_1: | ||
| 88 | GPU::SetFramebufferLocation(GPU::FRAMEBUFFER_LOCATION_VRAM); | ||
| 89 | memcpy(dst, framebuffer_1, size); | ||
| 90 | break; | ||
| 91 | 113 | ||
| 92 | // Top framebuffer 2 addresses | 114 | while (size > 0) { |
| 93 | case REG_FRAMEBUFFER_2: | 115 | GPU::Read<u32>(*dst, reg_addr + 0x1EB00000); |
| 94 | GPU::SetFramebufferLocation(GPU::FRAMEBUFFER_LOCATION_VRAM); | ||
| 95 | memcpy(dst, framebuffer_2, size); | ||
| 96 | break; | ||
| 97 | 116 | ||
| 98 | default: | 117 | size -= 4; |
| 99 | ERROR_LOG(GSP, "unknown register read at address %08X", reg_addr); | 118 | ++dst; |
| 119 | reg_addr += 4; | ||
| 100 | } | 120 | } |
| 101 | |||
| 102 | } | 121 | } |
| 103 | 122 | ||
| 104 | /** | 123 | /** |
| @@ -179,7 +198,7 @@ void TriggerCmdReqQueue(Service::Interface* self) { | |||
| 179 | } | 198 | } |
| 180 | 199 | ||
| 181 | const Interface::FunctionInfo FunctionTable[] = { | 200 | const Interface::FunctionInfo FunctionTable[] = { |
| 182 | {0x00010082, nullptr, "WriteHWRegs"}, | 201 | {0x00010082, WriteHWRegs, "WriteHWRegs"}, |
| 183 | {0x00020084, nullptr, "WriteHWRegsWithMask"}, | 202 | {0x00020084, nullptr, "WriteHWRegsWithMask"}, |
| 184 | {0x00030082, nullptr, "WriteHWRegRepeat"}, | 203 | {0x00030082, nullptr, "WriteHWRegRepeat"}, |
| 185 | {0x00040080, ReadHWRegs, "ReadHWRegs"}, | 204 | {0x00040080, ReadHWRegs, "ReadHWRegs"}, |