mirror of
https://git.h3cjp.net/H3cJP/citra.git
synced 2024-12-26 13:16:58 +00:00
Kernel: make config_mem and MapSharedPages members of KernelSystem
This commit is contained in:
parent
95790218f2
commit
773ec47629
|
@ -9,9 +9,7 @@
|
|||
|
||||
namespace ConfigMem {
|
||||
|
||||
ConfigMemDef config_mem;
|
||||
|
||||
void Init() {
|
||||
Handler::Handler() {
|
||||
std::memset(&config_mem, 0, sizeof(config_mem));
|
||||
|
||||
// Values extracted from firmware 11.2.0-35E
|
||||
|
@ -28,4 +26,8 @@ void Init() {
|
|||
config_mem.firm_ctr_sdk_ver = 0x0000F297;
|
||||
}
|
||||
|
||||
ConfigMemDef& Handler::GetConfigMem() {
|
||||
return config_mem;
|
||||
}
|
||||
|
||||
} // namespace ConfigMem
|
||||
|
|
|
@ -49,8 +49,13 @@ struct ConfigMemDef {
|
|||
static_assert(sizeof(ConfigMemDef) == Memory::CONFIG_MEMORY_SIZE,
|
||||
"Config Memory structure size is wrong");
|
||||
|
||||
extern ConfigMemDef config_mem;
|
||||
class Handler {
|
||||
public:
|
||||
Handler();
|
||||
ConfigMemDef& GetConfigMem();
|
||||
|
||||
void Init();
|
||||
private:
|
||||
ConfigMemDef config_mem;
|
||||
};
|
||||
|
||||
} // namespace ConfigMem
|
||||
|
|
|
@ -16,9 +16,7 @@ namespace Kernel {
|
|||
|
||||
/// Initialize the kernel
|
||||
KernelSystem::KernelSystem(u32 system_mode) {
|
||||
ConfigMem::Init();
|
||||
|
||||
Kernel::MemoryInit(system_mode);
|
||||
MemoryInit(system_mode);
|
||||
|
||||
resource_limits = std::make_unique<ResourceLimitList>(*this);
|
||||
thread_manager = std::make_unique<ThreadManager>();
|
||||
|
|
|
@ -12,6 +12,10 @@
|
|||
#include "common/common_types.h"
|
||||
#include "core/hle/result.h"
|
||||
|
||||
namespace ConfigMem {
|
||||
class Handler;
|
||||
}
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
class AddressArbiter;
|
||||
|
@ -30,6 +34,7 @@ class ResourceLimitList;
|
|||
class SharedMemory;
|
||||
class ThreadManager;
|
||||
class TimerManager;
|
||||
class VMManager;
|
||||
|
||||
enum class ResetType {
|
||||
OneShot,
|
||||
|
@ -195,7 +200,11 @@ public:
|
|||
TimerManager& GetTimerManager();
|
||||
const TimerManager& GetTimerManager() const;
|
||||
|
||||
void MapSharedPages(VMManager& address_space);
|
||||
|
||||
private:
|
||||
void MemoryInit(u32 mem_type);
|
||||
|
||||
std::unique_ptr<ResourceLimitList> resource_limits;
|
||||
std::atomic<u32> next_object_id{0};
|
||||
|
||||
|
@ -210,6 +219,8 @@ private:
|
|||
|
||||
std::unique_ptr<ThreadManager> thread_manager;
|
||||
std::unique_ptr<TimerManager> timer_manager;
|
||||
|
||||
std::unique_ptr<ConfigMem::Handler> config_mem_handler;
|
||||
};
|
||||
|
||||
} // namespace Kernel
|
||||
|
|
|
@ -41,7 +41,7 @@ static const u32 memory_region_sizes[8][3] = {
|
|||
{0x0B200000, 0x02E00000, 0x02000000}, // 7
|
||||
};
|
||||
|
||||
void MemoryInit(u32 mem_type) {
|
||||
void KernelSystem::MemoryInit(u32 mem_type) {
|
||||
// TODO(yuriks): On the n3DS, all o3DS configurations (<=5) are forced to 6 instead.
|
||||
ASSERT_MSG(mem_type <= 5, "New 3DS memory configuration aren't supported yet!");
|
||||
ASSERT(mem_type != 1);
|
||||
|
@ -64,7 +64,8 @@ void MemoryInit(u32 mem_type) {
|
|||
// We must've allocated the entire FCRAM by the end
|
||||
ASSERT(base == Memory::FCRAM_SIZE);
|
||||
|
||||
using ConfigMem::config_mem;
|
||||
config_mem_handler = std::make_unique<ConfigMem::Handler>();
|
||||
auto& config_mem = config_mem_handler->GetConfigMem();
|
||||
config_mem.app_mem_type = mem_type;
|
||||
// app_mem_malloc does not always match the configured size for memory_region[0]: in case the
|
||||
// n3DS type override is in effect it reports the size the game expects, not the real one.
|
||||
|
@ -152,12 +153,13 @@ void HandleSpecialMapping(VMManager& address_space, const AddressMapping& mappin
|
|||
mapping.read_only ? VMAPermission::Read : VMAPermission::ReadWrite);
|
||||
}
|
||||
|
||||
void MapSharedPages(VMManager& address_space) {
|
||||
auto cfg_mem_vma = address_space
|
||||
.MapBackingMemory(Memory::CONFIG_MEMORY_VADDR,
|
||||
reinterpret_cast<u8*>(&ConfigMem::config_mem),
|
||||
Memory::CONFIG_MEMORY_SIZE, MemoryState::Shared)
|
||||
.Unwrap();
|
||||
void KernelSystem::MapSharedPages(VMManager& address_space) {
|
||||
auto cfg_mem_vma =
|
||||
address_space
|
||||
.MapBackingMemory(Memory::CONFIG_MEMORY_VADDR,
|
||||
reinterpret_cast<u8*>(&config_mem_handler->GetConfigMem()),
|
||||
Memory::CONFIG_MEMORY_SIZE, MemoryState::Shared)
|
||||
.Unwrap();
|
||||
address_space.Reprotect(cfg_mem_vma, VMAPermission::Read);
|
||||
|
||||
auto shared_page_vma =
|
||||
|
|
|
@ -20,12 +20,10 @@ struct MemoryRegionInfo {
|
|||
std::shared_ptr<std::vector<u8>> linear_heap_memory;
|
||||
};
|
||||
|
||||
void MemoryInit(u32 mem_type);
|
||||
void MemoryShutdown();
|
||||
MemoryRegionInfo* GetMemoryRegion(MemoryRegion region);
|
||||
|
||||
void HandleSpecialMapping(VMManager& address_space, const AddressMapping& mapping);
|
||||
void MapSharedPages(VMManager& address_space);
|
||||
|
||||
extern MemoryRegionInfo memory_regions[3];
|
||||
} // namespace Kernel
|
||||
|
|
|
@ -143,7 +143,7 @@ void Process::Run(s32 main_thread_priority, u32 stack_size) {
|
|||
memory_region->used += stack_size;
|
||||
|
||||
// Map special address mappings
|
||||
MapSharedPages(vm_manager);
|
||||
kernel.MapSharedPages(vm_manager);
|
||||
for (const auto& mapping : address_mappings) {
|
||||
HandleSpecialMapping(vm_manager, mapping);
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ TEST_CASE("Memory::IsValidVirtualAddress", "[core][memory]") {
|
|||
|
||||
SECTION("CONFIG_MEMORY_VADDR and SHARED_PAGE_VADDR should be valid after mapping them") {
|
||||
auto process = kernel.CreateProcess(kernel.CreateCodeSet("", 0));
|
||||
Kernel::MapSharedPages(process->vm_manager);
|
||||
kernel.MapSharedPages(process->vm_manager);
|
||||
CHECK(Memory::IsValidVirtualAddress(*process, Memory::CONFIG_MEMORY_VADDR) == true);
|
||||
CHECK(Memory::IsValidVirtualAddress(*process, Memory::SHARED_PAGE_VADDR) == true);
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ TEST_CASE("Memory::IsValidVirtualAddress", "[core][memory]") {
|
|||
|
||||
SECTION("Unmapping a VAddr should make it invalid") {
|
||||
auto process = kernel.CreateProcess(kernel.CreateCodeSet("", 0));
|
||||
Kernel::MapSharedPages(process->vm_manager);
|
||||
kernel.MapSharedPages(process->vm_manager);
|
||||
process->vm_manager.UnmapRange(Memory::CONFIG_MEMORY_VADDR, Memory::CONFIG_MEMORY_SIZE);
|
||||
CHECK(Memory::IsValidVirtualAddress(*process, Memory::CONFIG_MEMORY_VADDR) == false);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue