diff options
| author | 2014-04-17 23:05:31 -0400 | |
|---|---|---|
| committer | 2014-04-17 23:05:31 -0400 | |
| commit | b2baafaf8ba760ce2b975391fd04db52ad386e29 (patch) | |
| tree | db16aba20508121cd0d6d7cd489d1e1963b67525 | |
| parent | fixed bug in Memory::GetPointer (diff) | |
| download | yuzu-b2baafaf8ba760ce2b975391fd04db52ad386e29.tar.gz yuzu-b2baafaf8ba760ce2b975391fd04db52ad386e29.tar.xz yuzu-b2baafaf8ba760ce2b975391fd04db52ad386e29.zip | |
added GSP heap memory allocation
Diffstat (limited to '')
| -rw-r--r-- | src/core/hle/syscall.cpp | 26 | ||||
| -rw-r--r-- | src/core/mem_map.h | 25 | ||||
| -rw-r--r-- | src/core/mem_map_funcs.cpp | 26 |
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 | ||
| 14 | namespace Syscall { | 18 | namespace Syscall { |
| 15 | 19 | ||
| 20 | /// Map application or GSP heap memory | ||
| 21 | Result 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 |
| 17 | Result ConnectToPort(void* out, const char* port_name) { | 41 | Result 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 | ||
| 42 | const HLE::FunctionDef Syscall_Table[] = { | 66 | const 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 | ||
| 53 | struct 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 | ||
| 82 | u8* GetPointer(const u32 Address); | 99 | u8* 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 | */ | ||
| 107 | u32 MapBlock_HeapGSP(u32 size, u32 operation, u32 permissions); | ||
| 108 | |||
| 84 | inline const char* GetCharPointer(const u32 address) { | 109 | inline 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 | ||
| 11 | namespace Memory { | 13 | namespace Memory { |
| 12 | 14 | ||
| 15 | std::map<u32, HeapBlock> g_heap_gsp_map; | ||
| 16 | |||
| 13 | /// Convert a physical address to virtual address | 17 | /// Convert a physical address to virtual address |
| 14 | u32 _AddressPhysicalToVirtual(const u32 addr) { | 18 | u32 _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 | */ | ||
| 128 | u32 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 | |||
| 119 | u8 Read8(const u32 addr) { | 145 | u8 Read8(const u32 addr) { |
| 120 | u8 _var = 0; | 146 | u8 _var = 0; |
| 121 | _Read<u8>(_var, addr); | 147 | _Read<u8>(_var, addr); |