summaryrefslogtreecommitdiff
path: root/src/core/hle/service
diff options
context:
space:
mode:
authorGravatar bunnei2014-05-07 21:04:55 -0400
committerGravatar bunnei2014-05-07 21:04:55 -0400
commit72622a1b5a13083e1b4eda3d4584bfa2f04dc55c (patch)
tree1a230947b66fd7001c58f96a47f352532d64e4ec /src/core/hle/service
parentadded kernel memory to mem_map (diff)
downloadyuzu-72622a1b5a13083e1b4eda3d4584bfa2f04dc55c.tar.gz
yuzu-72622a1b5a13083e1b4eda3d4584bfa2f04dc55c.tar.xz
yuzu-72622a1b5a13083e1b4eda3d4584bfa2f04dc55c.zip
- removed HLE mem "hack" and replaced with kernel mem region
- added a helper function for getting command buffer for services - fixed bug where GSP DMA was incorrectly being done in DataSynchronizationBarrier (instead of gsp_TriggerCmdReqQueue)
Diffstat (limited to 'src/core/hle/service')
-rw-r--r--src/core/hle/service/apt.cpp2
-rw-r--r--src/core/hle/service/gsp.cpp76
-rw-r--r--src/core/hle/service/service.h12
-rw-r--r--src/core/hle/service/srv.cpp2
4 files changed, 84 insertions, 8 deletions
diff --git a/src/core/hle/service/apt.cpp b/src/core/hle/service/apt.cpp
index 4a1e8c992..709ac5493 100644
--- a/src/core/hle/service/apt.cpp
+++ b/src/core/hle/service/apt.cpp
@@ -18,7 +18,7 @@ void Initialize(Service::Interface* self) {
18} 18}
19 19
20void GetLockHandle(Service::Interface* self) { 20void GetLockHandle(Service::Interface* self) {
21 u32* cmd_buff = (u32*)HLE::GetPointer(HLE::CMD_BUFFER_ADDR + Service::kCommandHeaderOffset); 21 u32* cmd_buff = Service::GetCommandBuffer();
22 cmd_buff[5] = 0x00000000; // TODO: This should be an actual mutex handle 22 cmd_buff[5] = 0x00000000; // TODO: This should be an actual mutex handle
23} 23}
24 24
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
18union 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
40static 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
45static 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
50void 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
17namespace GSP_GPU { 58namespace GSP_GPU {
18 59
60u32 g_thread_id = 0;
61
62enum {
63 CMD_GX_REQUEST_DMA = 0x00000000,
64};
65
19enum { 66enum {
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
58void RegisterInterruptRelayQueue(Service::Interface* self) { 105void 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.
115void 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
67const Interface::FunctionInfo FunctionTable[] = { 133const 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"},
diff --git a/src/core/hle/service/service.h b/src/core/hle/service/service.h
index b79dc9458..b260a290a 100644
--- a/src/core/hle/service/service.h
+++ b/src/core/hle/service/service.h
@@ -10,6 +10,7 @@
10 10
11#include "common/common.h" 11#include "common/common.h"
12#include "common/common_types.h" 12#include "common/common_types.h"
13#include "core/mem_map.h"
13#include "core/hle/syscall.h" 14#include "core/hle/syscall.h"
14 15
15//////////////////////////////////////////////////////////////////////////////////////////////////// 16////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -22,6 +23,15 @@ typedef s32 NativeUID; ///< Native handle for a service
22static const int kMaxPortSize = 0x08; ///< Maximum size of a port name (8 characters) 23static const int kMaxPortSize = 0x08; ///< Maximum size of a port name (8 characters)
23static const int kCommandHeaderOffset = 0x80; ///< Offset into command buffer of header 24static const int kCommandHeaderOffset = 0x80; ///< Offset into command buffer of header
24 25
26/**
27 * Returns a pointer to the command buffer in kernel memory
28 * @param offset Optional offset into command buffer
29 * @return Pointer to command buffer
30 */
31inline static u32* GetCommandBuffer(const int offset=0) {
32 return (u32*)Memory::GetPointer(Memory::KERNEL_MEMORY_VADDR + kCommandHeaderOffset + offset);
33}
34
25class Manager; 35class Manager;
26 36
27/// Interface to a CTROS service 37/// Interface to a CTROS service
@@ -81,7 +91,7 @@ public:
81 * @return Return result of svcSendSyncRequest passed back to user app 91 * @return Return result of svcSendSyncRequest passed back to user app
82 */ 92 */
83 Syscall::Result Sync() { 93 Syscall::Result Sync() {
84 u32* cmd_buff = (u32*)HLE::GetPointer(HLE::CMD_BUFFER_ADDR + kCommandHeaderOffset); 94 u32* cmd_buff = GetCommandBuffer();
85 auto itr = m_functions.find(cmd_buff[0]); 95 auto itr = m_functions.find(cmd_buff[0]);
86 96
87 if (itr == m_functions.end()) { 97 if (itr == m_functions.end()) {
diff --git a/src/core/hle/service/srv.cpp b/src/core/hle/service/srv.cpp
index 9437868c5..071741444 100644
--- a/src/core/hle/service/srv.cpp
+++ b/src/core/hle/service/srv.cpp
@@ -18,7 +18,7 @@ void Initialize(Service::Interface* self) {
18 18
19void GetServiceHandle(Service::Interface* self) { 19void GetServiceHandle(Service::Interface* self) {
20 Syscall::Result res = 0; 20 Syscall::Result res = 0;
21 u32* cmd_buff = (u32*)HLE::GetPointer(HLE::CMD_BUFFER_ADDR + Service::kCommandHeaderOffset); 21 u32* cmd_buff = Service::GetCommandBuffer();
22 22
23 std::string port_name = std::string((const char*)&cmd_buff[1], 0, Service::kMaxPortSize); 23 std::string port_name = std::string((const char*)&cmd_buff[1], 0, Service::kMaxPortSize);
24 Service::Interface* service = Service::g_manager->FetchFromPortName(port_name); 24 Service::Interface* service = Service::g_manager->FetchFromPortName(port_name);