diff options
Diffstat (limited to 'src/core/hle/service/gsp.cpp')
| -rw-r--r-- | src/core/hle/service/gsp.cpp | 71 |
1 files changed, 66 insertions, 5 deletions
diff --git a/src/core/hle/service/gsp.cpp b/src/core/hle/service/gsp.cpp index 88c1f1a0f..12c7dabcd 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,51 @@ | |||
| 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 | }; | ||
| 33 | |||
| 34 | /// Gets the address of the start (header) of a command buffer in GSP shared memory | ||
| 35 | static inline u32 GX_GetCmdBufferAddress(u32 thread_id) { | ||
| 36 | return (0x10002000 + 0x800 + (thread_id * 0x200)); | ||
| 37 | } | ||
| 38 | |||
| 39 | /// Gets a pointer to the start (header) of a command buffer in GSP shared memory | ||
| 40 | static inline u8* GX_GetCmdBufferPointer(u32 thread_id, u32 offset=0) { | ||
| 41 | return Memory::GetPointer(GX_GetCmdBufferAddress(thread_id) + offset); | ||
| 42 | } | ||
| 43 | |||
| 44 | /// Finishes execution of a GSP command | ||
| 45 | void GX_FinishCommand(u32 thread_id) { | ||
| 46 | GX_CmdBufferHeader* header = (GX_CmdBufferHeader*)GX_GetCmdBufferPointer(thread_id); | ||
| 47 | header->number_commands = header->number_commands - 1; | ||
| 48 | } | ||
| 49 | |||
| 50 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 15 | // Namespace GSP_GPU | 51 | // Namespace GSP_GPU |
| 16 | 52 | ||
| 17 | namespace GSP_GPU { | 53 | namespace GSP_GPU { |
| 18 | 54 | ||
| 55 | u32 g_thread_id = 0; | ||
| 56 | |||
| 57 | enum { | ||
| 58 | CMD_GX_REQUEST_DMA = 0x00000000, | ||
| 59 | }; | ||
| 60 | |||
| 19 | enum { | 61 | enum { |
| 20 | REG_FRAMEBUFFER_1 = 0x00400468, | 62 | REG_FRAMEBUFFER_1 = 0x00400468, |
| 21 | REG_FRAMEBUFFER_2 = 0x00400494, | 63 | REG_FRAMEBUFFER_2 = 0x00400494, |
| @@ -26,7 +68,7 @@ void ReadHWRegs(Service::Interface* self) { | |||
| 26 | static const u32 framebuffer_1[] = {LCD::PADDR_VRAM_TOP_LEFT_FRAME1, LCD::PADDR_VRAM_TOP_RIGHT_FRAME1}; | 68 | 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}; | 69 | static const u32 framebuffer_2[] = {LCD::PADDR_VRAM_TOP_LEFT_FRAME2, LCD::PADDR_VRAM_TOP_RIGHT_FRAME2}; |
| 28 | 70 | ||
| 29 | u32* cmd_buff = (u32*)HLE::GetPointer(HLE::CMD_BUFFER_ADDR + Service::kCommandHeaderOffset); | 71 | u32* cmd_buff = Service::GetCommandBuffer(); |
| 30 | u32 reg_addr = cmd_buff[1]; | 72 | u32 reg_addr = cmd_buff[1]; |
| 31 | u32 size = cmd_buff[2]; | 73 | u32 size = cmd_buff[2]; |
| 32 | u32* dst = (u32*)Memory::GetPointer(cmd_buff[0x41]); | 74 | u32* dst = (u32*)Memory::GetPointer(cmd_buff[0x41]); |
| @@ -50,18 +92,37 @@ void ReadHWRegs(Service::Interface* self) { | |||
| 50 | break; | 92 | break; |
| 51 | 93 | ||
| 52 | default: | 94 | default: |
| 53 | ERROR_LOG(OSHLE, "GSP_GPU::ReadHWRegs unknown register read at address %08X", reg_addr); | 95 | ERROR_LOG(GSP, "ReadHWRegs unknown register read at address %08X", reg_addr); |
| 54 | } | 96 | } |
| 55 | 97 | ||
| 56 | } | 98 | } |
| 57 | 99 | ||
| 58 | void RegisterInterruptRelayQueue(Service::Interface* self) { | 100 | void RegisterInterruptRelayQueue(Service::Interface* self) { |
| 59 | u32* cmd_buff = (u32*)HLE::GetPointer(HLE::CMD_BUFFER_ADDR + Service::kCommandHeaderOffset); | 101 | u32* cmd_buff = Service::GetCommandBuffer(); |
| 60 | u32 flags = cmd_buff[1]; | 102 | u32 flags = cmd_buff[1]; |
| 61 | u32 event_handle = cmd_buff[3]; // TODO(bunnei): Implement event handling | 103 | u32 event_handle = cmd_buff[3]; // TODO(bunnei): Implement event handling |
| 104 | |||
| 105 | cmd_buff[2] = g_thread_id; // ThreadID | ||
| 62 | cmd_buff[4] = self->NewHandle(); | 106 | cmd_buff[4] = self->NewHandle(); |
| 107 | } | ||
| 108 | |||
| 109 | /// This triggers handling of the GX command written to the command buffer in shared memory. | ||
| 110 | void TriggerCmdReqQueue(Service::Interface* self) { | ||
| 111 | GX_CmdBufferHeader* header = (GX_CmdBufferHeader*)GX_GetCmdBufferPointer(g_thread_id); | ||
| 112 | u32* cmd_buff = (u32*)GX_GetCmdBufferPointer(g_thread_id, 0x20 + (header->index * 0x20)); | ||
| 63 | 113 | ||
| 64 | return; | 114 | switch (cmd_buff[0]) { |
| 115 | |||
| 116 | // GX request DMA - typically used for copying memory from GSP heap to VRAM | ||
| 117 | case CMD_GX_REQUEST_DMA: | ||
| 118 | memcpy(Memory::GetPointer(cmd_buff[2]), Memory::GetPointer(cmd_buff[1]), cmd_buff[3]); | ||
| 119 | break; | ||
| 120 | |||
| 121 | default: | ||
| 122 | ERROR_LOG(GSP, "TriggerCmdReqQueue unknown command 0x%08X", cmd_buff[0]); | ||
| 123 | } | ||
| 124 | |||
| 125 | GX_FinishCommand(g_thread_id); | ||
| 65 | } | 126 | } |
| 66 | 127 | ||
| 67 | const Interface::FunctionInfo FunctionTable[] = { | 128 | const Interface::FunctionInfo FunctionTable[] = { |
| @@ -76,7 +137,7 @@ const Interface::FunctionInfo FunctionTable[] = { | |||
| 76 | {0x00090082, NULL, "InvalidateDataCache"}, | 137 | {0x00090082, NULL, "InvalidateDataCache"}, |
| 77 | {0x000A0044, NULL, "RegisterInterruptEvents"}, | 138 | {0x000A0044, NULL, "RegisterInterruptEvents"}, |
| 78 | {0x000B0040, NULL, "SetLcdForceBlack"}, | 139 | {0x000B0040, NULL, "SetLcdForceBlack"}, |
| 79 | {0x000C0000, NULL, "TriggerCmdReqQueue"}, | 140 | {0x000C0000, TriggerCmdReqQueue, "TriggerCmdReqQueue"}, |
| 80 | {0x000D0140, NULL, "SetDisplayTransfer"}, | 141 | {0x000D0140, NULL, "SetDisplayTransfer"}, |
| 81 | {0x000E0180, NULL, "SetTextureCopy"}, | 142 | {0x000E0180, NULL, "SetTextureCopy"}, |
| 82 | {0x000F0200, NULL, "SetMemoryFill"}, | 143 | {0x000F0200, NULL, "SetMemoryFill"}, |