summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/hle/syscall.cpp26
-rw-r--r--src/core/mem_map.h25
-rw-r--r--src/core/mem_map_funcs.cpp26
3 files changed, 76 insertions, 1 deletions
diff --git a/src/core/hle/syscall.cpp b/src/core/hle/syscall.cpp
index c5b887795..0cb563955 100644
--- a/src/core/hle/syscall.cpp
+++ b/src/core/hle/syscall.cpp
@@ -4,6 +4,10 @@
4 4
5#include <map> 5#include <map>
6 6
7#include "core/mem_map.h"
8
9#include "core/hw/hw_lcd.h"
10
7#include "core/hle/function_wrappers.h" 11#include "core/hle/function_wrappers.h"
8#include "core/hle/syscall.h" 12#include "core/hle/syscall.h"
9#include "core/hle/service/service.h" 13#include "core/hle/service/service.h"
@@ -13,6 +17,26 @@
13 17
14namespace Syscall { 18namespace Syscall {
15 19
20/// Map application or GSP heap memory
21Result ControlMemory(void* outaddr, u32 addr0, u32 addr1, u32 size, u32 operation, u32 permissions) {
22 u32 virtual_address = 0x00000000;
23
24 switch (operation) {
25
26 // Map GSP heap memory?
27 case 0x00010003:
28 virtual_address = Memory::MapBlock_HeapGSP(size, operation, permissions);
29 break;
30
31 // Unknown ControlMemory operation
32 default:
33 ERROR_LOG(OSHLE, "Unknown ControlMemory operation %08X", operation);
34 }
35
36 Core::g_app_core->SetReg(1, Memory::MapBlock_HeapGSP(size, operation, permissions));
37 return 0;
38}
39
16/// Connect to an OS service given the port name, returns the handle to the port to out 40/// Connect to an OS service given the port name, returns the handle to the port to out
17Result ConnectToPort(void* out, const char* port_name) { 41Result ConnectToPort(void* out, const char* port_name) {
18 Service::Interface* service = Service::g_manager->FetchFromPortName(port_name); 42 Service::Interface* service = Service::g_manager->FetchFromPortName(port_name);
@@ -41,7 +65,7 @@ Result WaitSynchronization1(Handle handle, s64 nanoseconds) {
41 65
42const HLE::FunctionDef Syscall_Table[] = { 66const HLE::FunctionDef Syscall_Table[] = {
43 {0x00, NULL, "Unknown"}, 67 {0x00, NULL, "Unknown"},
44 {0x01, NULL, "ControlMemory"}, 68 {0x01, WrapI_VUUUUU<ControlMemory>, "ControlMemory"},
45 {0x02, NULL, "QueryMemory"}, 69 {0x02, NULL, "QueryMemory"},
46 {0x03, NULL, "ExitProcess"}, 70 {0x03, NULL, "ExitProcess"},
47 {0x04, NULL, "GetProcessAffinityMask"}, 71 {0x04, NULL, "GetProcessAffinityMask"},
diff --git a/src/core/mem_map.h b/src/core/mem_map.h
index 9931daece..ab1eb2606 100644
--- a/src/core/mem_map.h
+++ b/src/core/mem_map.h
@@ -49,6 +49,23 @@ enum {
49 49
50//////////////////////////////////////////////////////////////////////////////////////////////////// 50////////////////////////////////////////////////////////////////////////////////////////////////////
51 51
52/// Represents a block of heap memory mapped by ControlMemory
53struct HeapBlock {
54 HeapBlock() : base_address(0), address(0), size(0), operation(0), permissions(0) {
55 }
56 u32 base_address;
57 u32 address;
58 u32 size;
59 u32 operation;
60 u32 permissions;
61
62 const u32 GetVirtualAddress() const{
63 return base_address + address;
64 }
65};
66
67////////////////////////////////////////////////////////////////////////////////////////////////////
68
52// Base is a pointer to the base of the memory map. Yes, some MMU tricks 69// Base is a pointer to the base of the memory map. Yes, some MMU tricks
53// are used to set up a full GC or Wii memory map in process memory. on 70// are used to set up a full GC or Wii memory map in process memory. on
54// 32-bit, you have to mask your offsets with 0x3FFFFFFF. This means that 71// 32-bit, you have to mask your offsets with 0x3FFFFFFF. This means that
@@ -81,6 +98,14 @@ void Write32(const u32 addr, const u32 data);
81 98
82u8* GetPointer(const u32 Address); 99u8* GetPointer(const u32 Address);
83 100
101/**
102 * Maps a block of memory on the GSP heap
103 * @param size Size of block in bytes
104 * @param operation Control memory operation
105 * @param permissions Control memory permissions
106 */
107u32 MapBlock_HeapGSP(u32 size, u32 operation, u32 permissions);
108
84inline const char* GetCharPointer(const u32 address) { 109inline const char* GetCharPointer(const u32 address) {
85 return (const char *)GetPointer(address); 110 return (const char *)GetPointer(address);
86} 111}
diff --git a/src/core/mem_map_funcs.cpp b/src/core/mem_map_funcs.cpp
index 8e97ef111..af4cfacbd 100644
--- a/src/core/mem_map_funcs.cpp
+++ b/src/core/mem_map_funcs.cpp
@@ -2,6 +2,8 @@
2// Licensed under GPLv2 2// Licensed under GPLv2
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <map>
6
5#include "common/common.h" 7#include "common/common.h"
6 8
7#include "core/mem_map.h" 9#include "core/mem_map.h"
@@ -10,6 +12,8 @@
10 12
11namespace Memory { 13namespace Memory {
12 14
15std::map<u32, HeapBlock> g_heap_gsp_map;
16
13/// Convert a physical address to virtual address 17/// Convert a physical address to virtual address
14u32 _AddressPhysicalToVirtual(const u32 addr) { 18u32 _AddressPhysicalToVirtual(const u32 addr) {
15 // Our memory interface read/write functions assume virtual addresses. Put any physical address 19 // Our memory interface read/write functions assume virtual addresses. Put any physical address
@@ -116,6 +120,28 @@ u8 *GetPointer(const u32 addr) {
116 } 120 }
117} 121}
118 122
123/**
124 * Maps a block of memory on the GSP heap
125 * @param size Size of block in bytes
126 * @param flags Memory allocation flags
127 */
128u32 MapBlock_HeapGSP(u32 size, u32 operation, u32 permissions) {
129 HeapBlock block;
130
131 block.base_address = HEAP_GSP_VADDR;
132 block.size = size;
133 block.operation = operation;
134 block.permissions = permissions;
135
136 if (g_heap_gsp_map.size() > 0) {
137 const HeapBlock last_block = g_heap_gsp_map.rbegin()->second;
138 block.address = last_block.address + last_block.size;
139 }
140 g_heap_gsp_map[block.GetVirtualAddress()] = block;
141
142 return block.GetVirtualAddress();
143}
144
119u8 Read8(const u32 addr) { 145u8 Read8(const u32 addr) {
120 u8 _var = 0; 146 u8 _var = 0;
121 _Read<u8>(_var, addr); 147 _Read<u8>(_var, addr);