diff options
Diffstat (limited to 'src/core/hle/service/gsp.cpp')
| -rw-r--r-- | src/core/hle/service/gsp.cpp | 76 |
1 files changed, 71 insertions, 5 deletions
diff --git a/src/core/hle/service/gsp.cpp b/src/core/hle/service/gsp.cpp index 88c1f1a0f..58df970c4 100644 --- a/src/core/hle/service/gsp.cpp +++ b/src/core/hle/service/gsp.cpp | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | #include "common/log.h" | 6 | #include "common/log.h" |
| 7 | #include "common/bit_field.h" | ||
| 7 | 8 | ||
| 8 | #include "core/mem_map.h" | 9 | #include "core/mem_map.h" |
| 9 | #include "core/hle/hle.h" | 10 | #include "core/hle/hle.h" |
| @@ -12,10 +13,56 @@ | |||
| 12 | #include "core/hw/lcd.h" | 13 | #include "core/hw/lcd.h" |
| 13 | 14 | ||
| 14 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 15 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 16 | |||
| 17 | /// GSP shared memory GX command buffer header | ||
| 18 | union GX_CmdBufferHeader { | ||
| 19 | u32 hex; | ||
| 20 | |||
| 21 | // Current command index. This index is updated by GSP module after loading the command data, | ||
| 22 | // right before the command is processed. When this index is updated by GSP module, the total | ||
| 23 | // commands field is decreased by one as well. | ||
| 24 | BitField<0,8,u32> index; | ||
| 25 | |||
| 26 | // Total commands to process, must not be value 0 when GSP module handles commands. This must be | ||
| 27 | // <=15 when writing a command to shared memory. This is incremented by the application when | ||
| 28 | // writing a command to shared memory, after increasing this value TriggerCmdReqQueue is only | ||
| 29 | // used if this field is value 1. | ||
| 30 | BitField<8,8,u32> number_commands; | ||
| 31 | |||
| 32 | // Must not be value 1. When the error-code u32 is set, this u8 is set to value 0x80. | ||
| 33 | BitField<16,8,u32> unk_0; | ||
| 34 | |||
| 35 | // Bit 0 must not be set | ||
| 36 | BitField<24,8,u32> unk_1; | ||
| 37 | }; | ||
| 38 | |||
| 39 | /// Gets the address of the start (header) of a command buffer in GSP shared memory | ||
| 40 | static inline u32 GX_GetCmdBufferAddress(u32 thread_id) { | ||
| 41 | return (0x10002000 + 0x800 + (thread_id * 0x200)); | ||
| 42 | } | ||
| 43 | |||
| 44 | /// Gets a pointer to the start (header) of a command buffer in GSP shared memory | ||
| 45 | static inline u8* GX_GetCmdBufferPointer(u32 thread_id, u32 offset=0) { | ||
| 46 | return Memory::GetPointer(GX_GetCmdBufferAddress(thread_id) + offset); | ||
| 47 | } | ||
| 48 | |||
| 49 | /// Finishes execution of a GSP command | ||
| 50 | void GX_FinishCommand(u32 thread_id) { | ||
| 51 | GX_CmdBufferHeader* header = (GX_CmdBufferHeader*)GX_GetCmdBufferPointer(thread_id); | ||
| 52 | header->number_commands = header->number_commands - 1; | ||
| 53 | } | ||
| 54 | |||
| 55 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 15 | // Namespace GSP_GPU | 56 | // Namespace GSP_GPU |
| 16 | 57 | ||
| 17 | namespace GSP_GPU { | 58 | namespace GSP_GPU { |
| 18 | 59 | ||
| 60 | u32 g_thread_id = 0; | ||
| 61 | |||
| 62 | enum { | ||
| 63 | CMD_GX_REQUEST_DMA = 0x00000000, | ||
| 64 | }; | ||
| 65 | |||
| 19 | enum { | 66 | enum { |
| 20 | REG_FRAMEBUFFER_1 = 0x00400468, | 67 | REG_FRAMEBUFFER_1 = 0x00400468, |
| 21 | REG_FRAMEBUFFER_2 = 0x00400494, | 68 | REG_FRAMEBUFFER_2 = 0x00400494, |
| @@ -26,7 +73,7 @@ void ReadHWRegs(Service::Interface* self) { | |||
| 26 | static const u32 framebuffer_1[] = {LCD::PADDR_VRAM_TOP_LEFT_FRAME1, LCD::PADDR_VRAM_TOP_RIGHT_FRAME1}; | 73 | static const u32 framebuffer_1[] = {LCD::PADDR_VRAM_TOP_LEFT_FRAME1, LCD::PADDR_VRAM_TOP_RIGHT_FRAME1}; |
| 27 | static const u32 framebuffer_2[] = {LCD::PADDR_VRAM_TOP_LEFT_FRAME2, LCD::PADDR_VRAM_TOP_RIGHT_FRAME2}; | 74 | static const u32 framebuffer_2[] = {LCD::PADDR_VRAM_TOP_LEFT_FRAME2, LCD::PADDR_VRAM_TOP_RIGHT_FRAME2}; |
| 28 | 75 | ||
| 29 | u32* cmd_buff = (u32*)HLE::GetPointer(HLE::CMD_BUFFER_ADDR + Service::kCommandHeaderOffset); | 76 | u32* cmd_buff = Service::GetCommandBuffer(); |
| 30 | u32 reg_addr = cmd_buff[1]; | 77 | u32 reg_addr = cmd_buff[1]; |
| 31 | u32 size = cmd_buff[2]; | 78 | u32 size = cmd_buff[2]; |
| 32 | u32* dst = (u32*)Memory::GetPointer(cmd_buff[0x41]); | 79 | u32* dst = (u32*)Memory::GetPointer(cmd_buff[0x41]); |
| @@ -50,18 +97,37 @@ void ReadHWRegs(Service::Interface* self) { | |||
| 50 | break; | 97 | break; |
| 51 | 98 | ||
| 52 | default: | 99 | default: |
| 53 | ERROR_LOG(OSHLE, "GSP_GPU::ReadHWRegs unknown register read at address %08X", reg_addr); | 100 | ERROR_LOG(GSP, "ReadHWRegs unknown register read at address %08X", reg_addr); |
| 54 | } | 101 | } |
| 55 | 102 | ||
| 56 | } | 103 | } |
| 57 | 104 | ||
| 58 | void RegisterInterruptRelayQueue(Service::Interface* self) { | 105 | void RegisterInterruptRelayQueue(Service::Interface* self) { |
| 59 | u32* cmd_buff = (u32*)HLE::GetPointer(HLE::CMD_BUFFER_ADDR + Service::kCommandHeaderOffset); | 106 | u32* cmd_buff = Service::GetCommandBuffer(); |
| 60 | u32 flags = cmd_buff[1]; | 107 | u32 flags = cmd_buff[1]; |
| 61 | u32 event_handle = cmd_buff[3]; // TODO(bunnei): Implement event handling | 108 | u32 event_handle = cmd_buff[3]; // TODO(bunnei): Implement event handling |
| 109 | |||
| 110 | cmd_buff[2] = g_thread_id; // ThreadID | ||
| 62 | cmd_buff[4] = self->NewHandle(); | 111 | cmd_buff[4] = self->NewHandle(); |
| 112 | } | ||
| 113 | |||
| 114 | /// This triggers handling of the GX command written to the command buffer in shared memory. | ||
| 115 | void TriggerCmdReqQueue(Service::Interface* self) { | ||
| 116 | GX_CmdBufferHeader* header = (GX_CmdBufferHeader*)GX_GetCmdBufferPointer(g_thread_id); | ||
| 117 | u32* cmd_buff = (u32*)GX_GetCmdBufferPointer(g_thread_id, 0x20 + (header->index * 0x20)); | ||
| 63 | 118 | ||
| 64 | return; | 119 | switch (cmd_buff[0]) { |
| 120 | |||
| 121 | // GX request DMA - typically used for copying memory from GSP heap to VRAM | ||
| 122 | case CMD_GX_REQUEST_DMA: | ||
| 123 | memcpy(Memory::GetPointer(cmd_buff[2]), Memory::GetPointer(cmd_buff[1]), cmd_buff[3]); | ||
| 124 | break; | ||
| 125 | |||
| 126 | default: | ||
| 127 | ERROR_LOG(GSP, "TriggerCmdReqQueue unknown command 0x%08X", cmd_buff[0]); | ||
| 128 | } | ||
| 129 | |||
| 130 | GX_FinishCommand(g_thread_id); | ||
| 65 | } | 131 | } |
| 66 | 132 | ||
| 67 | const Interface::FunctionInfo FunctionTable[] = { | 133 | const Interface::FunctionInfo FunctionTable[] = { |
| @@ -76,7 +142,7 @@ const Interface::FunctionInfo FunctionTable[] = { | |||
| 76 | {0x00090082, NULL, "InvalidateDataCache"}, | 142 | {0x00090082, NULL, "InvalidateDataCache"}, |
| 77 | {0x000A0044, NULL, "RegisterInterruptEvents"}, | 143 | {0x000A0044, NULL, "RegisterInterruptEvents"}, |
| 78 | {0x000B0040, NULL, "SetLcdForceBlack"}, | 144 | {0x000B0040, NULL, "SetLcdForceBlack"}, |
| 79 | {0x000C0000, NULL, "TriggerCmdReqQueue"}, | 145 | {0x000C0000, TriggerCmdReqQueue, "TriggerCmdReqQueue"}, |
| 80 | {0x000D0140, NULL, "SetDisplayTransfer"}, | 146 | {0x000D0140, NULL, "SetDisplayTransfer"}, |
| 81 | {0x000E0180, NULL, "SetTextureCopy"}, | 147 | {0x000E0180, NULL, "SetTextureCopy"}, |
| 82 | {0x000F0200, NULL, "SetMemoryFill"}, | 148 | {0x000F0200, NULL, "SetMemoryFill"}, |