diff options
| author | 2015-07-29 12:08:00 -0300 | |
|---|---|---|
| committer | 2015-08-16 01:03:46 -0300 | |
| commit | 69c3021a8d203dbbea9673977535f1eb75b274a1 (patch) | |
| tree | 7fce1fe7dce9f94062361832d1f1a1378a66e4af /src/core/hle/kernel | |
| parent | Memory: Move address type conversion routines to memory.cpp/h (diff) | |
| download | yuzu-69c3021a8d203dbbea9673977535f1eb75b274a1.tar.gz yuzu-69c3021a8d203dbbea9673977535f1eb75b274a1.tar.xz yuzu-69c3021a8d203dbbea9673977535f1eb75b274a1.zip | |
Move core/mem_map.{cpp,h} => core/hle/kernel/memory.{cpp,h}
Diffstat (limited to 'src/core/hle/kernel')
| -rw-r--r-- | src/core/hle/kernel/memory.cpp | 124 | ||||
| -rw-r--r-- | src/core/hle/kernel/memory.h | 35 | ||||
| -rw-r--r-- | src/core/hle/kernel/process.cpp | 2 |
3 files changed, 160 insertions, 1 deletions
diff --git a/src/core/hle/kernel/memory.cpp b/src/core/hle/kernel/memory.cpp new file mode 100644 index 000000000..57e1912d3 --- /dev/null +++ b/src/core/hle/kernel/memory.cpp | |||
| @@ -0,0 +1,124 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <map> | ||
| 6 | #include <memory> | ||
| 7 | #include <utility> | ||
| 8 | #include <vector> | ||
| 9 | |||
| 10 | #include "common/common_types.h" | ||
| 11 | #include "common/logging/log.h" | ||
| 12 | |||
| 13 | #include "core/hle/config_mem.h" | ||
| 14 | #include "core/hle/kernel/vm_manager.h" | ||
| 15 | #include "core/hle/result.h" | ||
| 16 | #include "core/hle/shared_page.h" | ||
| 17 | #include "core/memory.h" | ||
| 18 | #include "core/memory_setup.h" | ||
| 19 | |||
| 20 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 21 | |||
| 22 | namespace Memory { | ||
| 23 | |||
| 24 | namespace { | ||
| 25 | |||
| 26 | struct MemoryArea { | ||
| 27 | u32 base; | ||
| 28 | u32 size; | ||
| 29 | const char* name; | ||
| 30 | }; | ||
| 31 | |||
| 32 | // We don't declare the IO regions in here since its handled by other means. | ||
| 33 | static MemoryArea memory_areas[] = { | ||
| 34 | {SHARED_MEMORY_VADDR, SHARED_MEMORY_SIZE, "Shared Memory"}, // Shared memory | ||
| 35 | {VRAM_VADDR, VRAM_SIZE, "VRAM"}, // Video memory (VRAM) | ||
| 36 | {DSP_RAM_VADDR, DSP_RAM_SIZE, "DSP RAM"}, // DSP memory | ||
| 37 | {TLS_AREA_VADDR, TLS_AREA_SIZE, "TLS Area"}, // TLS memory | ||
| 38 | }; | ||
| 39 | |||
| 40 | /// Represents a block of memory mapped by ControlMemory/MapMemoryBlock | ||
| 41 | struct MemoryBlock { | ||
| 42 | MemoryBlock() : handle(0), base_address(0), address(0), size(0), operation(0), permissions(0) { | ||
| 43 | } | ||
| 44 | u32 handle; | ||
| 45 | u32 base_address; | ||
| 46 | u32 address; | ||
| 47 | u32 size; | ||
| 48 | u32 operation; | ||
| 49 | u32 permissions; | ||
| 50 | |||
| 51 | const u32 GetVirtualAddress() const{ | ||
| 52 | return base_address + address; | ||
| 53 | } | ||
| 54 | }; | ||
| 55 | |||
| 56 | static std::map<u32, MemoryBlock> heap_map; | ||
| 57 | static std::map<u32, MemoryBlock> heap_linear_map; | ||
| 58 | |||
| 59 | } | ||
| 60 | |||
| 61 | u32 MapBlock_Heap(u32 size, u32 operation, u32 permissions) { | ||
| 62 | MemoryBlock block; | ||
| 63 | |||
| 64 | block.base_address = HEAP_VADDR; | ||
| 65 | block.size = size; | ||
| 66 | block.operation = operation; | ||
| 67 | block.permissions = permissions; | ||
| 68 | |||
| 69 | if (heap_map.size() > 0) { | ||
| 70 | const MemoryBlock last_block = heap_map.rbegin()->second; | ||
| 71 | block.address = last_block.address + last_block.size; | ||
| 72 | } | ||
| 73 | heap_map[block.GetVirtualAddress()] = block; | ||
| 74 | |||
| 75 | return block.GetVirtualAddress(); | ||
| 76 | } | ||
| 77 | |||
| 78 | u32 MapBlock_HeapLinear(u32 size, u32 operation, u32 permissions) { | ||
| 79 | MemoryBlock block; | ||
| 80 | |||
| 81 | block.base_address = LINEAR_HEAP_VADDR; | ||
| 82 | block.size = size; | ||
| 83 | block.operation = operation; | ||
| 84 | block.permissions = permissions; | ||
| 85 | |||
| 86 | if (heap_linear_map.size() > 0) { | ||
| 87 | const MemoryBlock last_block = heap_linear_map.rbegin()->second; | ||
| 88 | block.address = last_block.address + last_block.size; | ||
| 89 | } | ||
| 90 | heap_linear_map[block.GetVirtualAddress()] = block; | ||
| 91 | |||
| 92 | return block.GetVirtualAddress(); | ||
| 93 | } | ||
| 94 | |||
| 95 | void Init() { | ||
| 96 | InitMemoryMap(); | ||
| 97 | LOG_DEBUG(HW_Memory, "initialized OK"); | ||
| 98 | } | ||
| 99 | |||
| 100 | void InitLegacyAddressSpace(Kernel::VMManager& address_space) { | ||
| 101 | using namespace Kernel; | ||
| 102 | |||
| 103 | for (MemoryArea& area : memory_areas) { | ||
| 104 | auto block = std::make_shared<std::vector<u8>>(area.size); | ||
| 105 | address_space.MapMemoryBlock(area.base, std::move(block), 0, area.size, MemoryState::Private).Unwrap(); | ||
| 106 | } | ||
| 107 | |||
| 108 | auto cfg_mem_vma = address_space.MapBackingMemory(CONFIG_MEMORY_VADDR, | ||
| 109 | (u8*)&ConfigMem::config_mem, CONFIG_MEMORY_SIZE, MemoryState::Shared).MoveFrom(); | ||
| 110 | address_space.Reprotect(cfg_mem_vma, VMAPermission::Read); | ||
| 111 | |||
| 112 | auto shared_page_vma = address_space.MapBackingMemory(SHARED_PAGE_VADDR, | ||
| 113 | (u8*)&SharedPage::shared_page, SHARED_PAGE_SIZE, MemoryState::Shared).MoveFrom(); | ||
| 114 | address_space.Reprotect(shared_page_vma, VMAPermission::Read); | ||
| 115 | } | ||
| 116 | |||
| 117 | void Shutdown() { | ||
| 118 | heap_map.clear(); | ||
| 119 | heap_linear_map.clear(); | ||
| 120 | |||
| 121 | LOG_DEBUG(HW_Memory, "shutdown OK"); | ||
| 122 | } | ||
| 123 | |||
| 124 | } // namespace | ||
diff --git a/src/core/hle/kernel/memory.h b/src/core/hle/kernel/memory.h new file mode 100644 index 000000000..cba8a0714 --- /dev/null +++ b/src/core/hle/kernel/memory.h | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "common/common_types.h" | ||
| 8 | |||
| 9 | namespace Kernel { | ||
| 10 | class VMManager; | ||
| 11 | } | ||
| 12 | |||
| 13 | namespace Memory { | ||
| 14 | |||
| 15 | void Init(); | ||
| 16 | void InitLegacyAddressSpace(Kernel::VMManager& address_space); | ||
| 17 | void Shutdown(); | ||
| 18 | |||
| 19 | /** | ||
| 20 | * Maps a block of memory on the heap | ||
| 21 | * @param size Size of block in bytes | ||
| 22 | * @param operation Memory map operation type | ||
| 23 | * @param permissions Memory allocation permissions | ||
| 24 | */ | ||
| 25 | u32 MapBlock_Heap(u32 size, u32 operation, u32 permissions); | ||
| 26 | |||
| 27 | /** | ||
| 28 | * Maps a block of memory on the GSP heap | ||
| 29 | * @param size Size of block in bytes | ||
| 30 | * @param operation Memory map operation type | ||
| 31 | * @param permissions Control memory permissions | ||
| 32 | */ | ||
| 33 | u32 MapBlock_HeapLinear(u32 size, u32 operation, u32 permissions); | ||
| 34 | |||
| 35 | } // namespace | ||
diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp index 561824305..2cd1cfc14 100644 --- a/src/core/hle/kernel/process.cpp +++ b/src/core/hle/kernel/process.cpp | |||
| @@ -7,11 +7,11 @@ | |||
| 7 | #include "common/logging/log.h" | 7 | #include "common/logging/log.h" |
| 8 | #include "common/make_unique.h" | 8 | #include "common/make_unique.h" |
| 9 | 9 | ||
| 10 | #include "core/hle/kernel/memory.h" | ||
| 10 | #include "core/hle/kernel/process.h" | 11 | #include "core/hle/kernel/process.h" |
| 11 | #include "core/hle/kernel/resource_limit.h" | 12 | #include "core/hle/kernel/resource_limit.h" |
| 12 | #include "core/hle/kernel/thread.h" | 13 | #include "core/hle/kernel/thread.h" |
| 13 | #include "core/hle/kernel/vm_manager.h" | 14 | #include "core/hle/kernel/vm_manager.h" |
| 14 | #include "core/mem_map.h" | ||
| 15 | #include "core/memory.h" | 15 | #include "core/memory.h" |
| 16 | 16 | ||
| 17 | namespace Kernel { | 17 | namespace Kernel { |