From 1c0b87edc2d8262c06ea4c301bcfc884875f918b Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Sat, 9 May 2015 00:39:56 -0300 Subject: Memory: Re-organize and rename memory area address constants --- src/core/core.cpp | 2 +- src/core/hle/kernel/session.h | 2 +- src/core/hle/kernel/thread.cpp | 5 +- src/core/hle/service/dsp_dsp.cpp | 2 +- src/core/loader/3dsx.cpp | 4 +- src/core/loader/elf.cpp | 2 +- src/core/mem_map.cpp | 18 ++--- src/core/mem_map.h | 163 +++++++++++++++++++++------------------ src/core/mem_map_funcs.cpp | 64 +++++++-------- src/video_core/pica.h | 2 +- 10 files changed, 132 insertions(+), 132 deletions(-) (limited to 'src') diff --git a/src/core/core.cpp b/src/core/core.cpp index 1c9680d41..bb2ed7a92 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -63,7 +63,7 @@ int Init() { // TODO: Whenever TLS is implemented, this should contain // the address of the 0x200-byte TLS - g_app_core->SetCP15Register(CP15_THREAD_URO, Memory::KERNEL_MEMORY_VADDR); + g_app_core->SetCP15Register(CP15_THREAD_URO, Memory::TLS_AREA_VADDR); LOG_DEBUG(Core, "Initialized OK"); return 0; diff --git a/src/core/hle/kernel/session.h b/src/core/hle/kernel/session.h index 9e9288e0f..0fd18148a 100644 --- a/src/core/hle/kernel/session.h +++ b/src/core/hle/kernel/session.h @@ -17,7 +17,7 @@ static const int kCommandHeaderOffset = 0x80; ///< Offset into command buffer of * @return Pointer to command buffer */ inline static u32* GetCommandBuffer(const int offset=0) { - return (u32*)Memory::GetPointer(Memory::KERNEL_MEMORY_VADDR + kCommandHeaderOffset + offset); + return (u32*)Memory::GetPointer(Memory::TLS_AREA_VADDR + kCommandHeaderOffset + offset); } /** diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index 9577b889a..0a3fd7cb1 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp @@ -443,7 +443,8 @@ void Thread::BoostPriority(s32 priority) { SharedPtr SetupIdleThread() { // We need to pass a few valid values to get around parameter checking in Thread::Create. - auto thread = Thread::Create("idle", Memory::KERNEL_MEMORY_VADDR, THREADPRIO_LOWEST, 0, + // TODO(yuriks): Figure out a way to avoid passing the bogus VAddr parameter + auto thread = Thread::Create("idle", Memory::TLS_AREA_VADDR, THREADPRIO_LOWEST, 0, THREADPROCESSORID_0, 0).MoveFrom(); thread->idle = true; @@ -455,7 +456,7 @@ SharedPtr SetupMainThread(u32 stack_size, u32 entry_point, s32 priority) // Initialize new "main" thread auto thread_res = Thread::Create("main", entry_point, priority, 0, - THREADPROCESSORID_0, Memory::SCRATCHPAD_VADDR_END); + THREADPROCESSORID_0, Memory::HEAP_VADDR_END - stack_size); SharedPtr thread = thread_res.MoveFrom(); diff --git a/src/core/hle/service/dsp_dsp.cpp b/src/core/hle/service/dsp_dsp.cpp index 20dc4d648..fafb43a2f 100644 --- a/src/core/hle/service/dsp_dsp.cpp +++ b/src/core/hle/service/dsp_dsp.cpp @@ -42,7 +42,7 @@ static void ConvertProcessAddressFromDspDram(Service::Interface* self) { u32 addr = cmd_buff[1]; cmd_buff[1] = 0; // No error - cmd_buff[2] = (addr << 1) + (Memory::DSP_MEMORY_VADDR + 0x40000); + cmd_buff[2] = (addr << 1) + (Memory::DSP_RAM_VADDR + 0x40000); LOG_WARNING(Service_DSP, "(STUBBED) called with address 0x%08X", addr); } diff --git a/src/core/loader/3dsx.cpp b/src/core/loader/3dsx.cpp index 15527c5a6..e28986085 100644 --- a/src/core/loader/3dsx.cpp +++ b/src/core/loader/3dsx.cpp @@ -234,9 +234,9 @@ ResultStatus AppLoader_THREEDSX::Load() { Kernel::g_current_process->svc_access_mask.set(); Kernel::g_current_process->address_mappings = default_address_mappings; - Load3DSXFile(*file, Memory::EXEFS_CODE_VADDR); + Load3DSXFile(*file, Memory::PROCESS_IMAGE_VADDR); - Kernel::g_current_process->Run(Memory::EXEFS_CODE_VADDR, 48, Kernel::DEFAULT_STACK_SIZE); + Kernel::g_current_process->Run(Memory::PROCESS_IMAGE_VADDR, 48, Kernel::DEFAULT_STACK_SIZE); is_loaded = true; return ResultStatus::Success; diff --git a/src/core/loader/elf.cpp b/src/core/loader/elf.cpp index f86a98b8c..47d4e8cea 100644 --- a/src/core/loader/elf.cpp +++ b/src/core/loader/elf.cpp @@ -355,7 +355,7 @@ ResultStatus AppLoader_ELF::Load() { Kernel::g_current_process->address_mappings = default_address_mappings; ElfReader elf_reader(&buffer[0]); - elf_reader.LoadInto(Memory::EXEFS_CODE_VADDR); + elf_reader.LoadInto(Memory::PROCESS_IMAGE_VADDR); // TODO: Fill application title Kernel::g_current_process->Run(elf_reader.GetEntryPoint(), 48, Kernel::DEFAULT_STACK_SIZE); diff --git a/src/core/mem_map.cpp b/src/core/mem_map.cpp index 46e271c80..74faf0dce 100644 --- a/src/core/mem_map.cpp +++ b/src/core/mem_map.cpp @@ -12,13 +12,12 @@ namespace Memory { u8* g_exefs_code; ///< ExeFS:/.code is loaded here -u8* g_system_mem; ///< System memory u8* g_heap; ///< Application heap (main memory) u8* g_heap_linear; ///< Linear heap u8* g_vram; ///< Video memory (VRAM) pointer u8* g_shared_mem; ///< Shared memory u8* g_dsp_mem; ///< DSP memory -u8* g_kernel_mem; ///< Kernel memory +u8* g_tls_mem; ///< TLS memory namespace { @@ -29,14 +28,13 @@ struct MemoryArea { // We don't declare the IO regions in here since its handled by other means. static MemoryArea memory_areas[] = { - {&g_exefs_code, EXEFS_CODE_SIZE }, - {&g_vram, VRAM_SIZE }, - {&g_heap, HEAP_SIZE }, - {&g_shared_mem, SHARED_MEMORY_SIZE}, - {&g_system_mem, SYSTEM_MEMORY_SIZE}, - {&g_dsp_mem, DSP_MEMORY_SIZE }, - {&g_kernel_mem, KERNEL_MEMORY_SIZE}, - {&g_heap_linear, HEAP_LINEAR_SIZE }, + {&g_exefs_code, PROCESS_IMAGE_MAX_SIZE}, + {&g_vram, VRAM_SIZE }, + {&g_heap, HEAP_SIZE }, + {&g_shared_mem, SHARED_MEMORY_SIZE }, + {&g_dsp_mem, DSP_RAM_SIZE }, + {&g_tls_mem, TLS_AREA_SIZE }, + {&g_heap_linear, LINEAR_HEAP_SIZE }, }; } diff --git a/src/core/mem_map.h b/src/core/mem_map.h index fb582d65a..3866a3a11 100644 --- a/src/core/mem_map.h +++ b/src/core/mem_map.h @@ -12,79 +12,93 @@ namespace Memory { const u32 PAGE_SIZE = 0x1000; -enum : u32 { - BOOTROM_SIZE = 0x00010000, ///< Bootrom (super secret code/data @ 0x8000) size - BOOTROM_PADDR = 0x00000000, ///< Bootrom physical address - BOOTROM_PADDR_END = (BOOTROM_PADDR + BOOTROM_SIZE), - - BOOTROM_MIRROR_SIZE = 0x00010000, ///< Bootrom Mirror size - BOOTROM_MIRROR_PADDR = 0x00010000, ///< Bootrom Mirror physical address - BOOTROM_MIRROR_PADDR_END = (BOOTROM_MIRROR_PADDR + BOOTROM_MIRROR_SIZE), - - MPCORE_PRIV_SIZE = 0x00002000, ///< MPCore private memory region size - MPCORE_PRIV_PADDR = 0x17E00000, ///< MPCore private memory region physical address - MPCORE_PRIV_PADDR_END = (MPCORE_PRIV_PADDR + MPCORE_PRIV_SIZE), - - FCRAM_SIZE = 0x08000000, ///< FCRAM size - FCRAM_PADDR = 0x20000000, ///< FCRAM physical address - FCRAM_PADDR_END = (FCRAM_PADDR + FCRAM_SIZE), - - HEAP_SIZE = FCRAM_SIZE, ///< Application heap size - HEAP_VADDR = 0x08000000, - HEAP_VADDR_END = (HEAP_VADDR + HEAP_SIZE), - - HEAP_LINEAR_SIZE = FCRAM_SIZE, - HEAP_LINEAR_VADDR = 0x14000000, - HEAP_LINEAR_VADDR_END = (HEAP_LINEAR_VADDR + HEAP_LINEAR_SIZE), - - AXI_WRAM_SIZE = 0x00080000, ///< AXI WRAM size - AXI_WRAM_PADDR = 0x1FF80000, ///< AXI WRAM physical address - AXI_WRAM_PADDR_END = (AXI_WRAM_PADDR + AXI_WRAM_SIZE), - - SHARED_MEMORY_SIZE = 0x04000000, ///< Shared memory size - SHARED_MEMORY_VADDR = 0x10000000, ///< Shared memory - SHARED_MEMORY_VADDR_END = (SHARED_MEMORY_VADDR + SHARED_MEMORY_SIZE), - - DSP_MEMORY_SIZE = 0x00080000, ///< DSP memory size - DSP_MEMORY_VADDR = 0x1FF00000, ///< DSP memory virtual address - DSP_MEMORY_VADDR_END = (DSP_MEMORY_VADDR + DSP_MEMORY_SIZE), - - CONFIG_MEMORY_SIZE = 0x00001000, ///< Configuration memory size - CONFIG_MEMORY_VADDR = 0x1FF80000, ///< Configuration memory virtual address - CONFIG_MEMORY_VADDR_END = (CONFIG_MEMORY_VADDR + CONFIG_MEMORY_SIZE), - - SHARED_PAGE_SIZE = 0x00001000, ///< Shared page size - SHARED_PAGE_VADDR = 0x1FF81000, ///< Shared page virtual address - SHARED_PAGE_VADDR_END = (SHARED_PAGE_VADDR + SHARED_PAGE_SIZE), - - KERNEL_MEMORY_SIZE = 0x00001000, ///< Kernel memory size - KERNEL_MEMORY_VADDR = 0xFFFF0000, ///< Kernel memory where the kthread objects etc are - KERNEL_MEMORY_VADDR_END = (KERNEL_MEMORY_VADDR + KERNEL_MEMORY_SIZE), - - EXEFS_CODE_SIZE = 0x03F00000, - EXEFS_CODE_VADDR = 0x00100000, ///< ExeFS:/.code is loaded here - EXEFS_CODE_VADDR_END = (EXEFS_CODE_VADDR + EXEFS_CODE_SIZE), - - // Region of FCRAM used by system - SYSTEM_MEMORY_SIZE = 0x02C00000, ///< 44MB - SYSTEM_MEMORY_VADDR = 0x04000000, - SYSTEM_MEMORY_VADDR_END = (SYSTEM_MEMORY_VADDR + SYSTEM_MEMORY_SIZE), - - HARDWARE_IO_SIZE = 0x01000000, - HARDWARE_IO_PADDR = 0x10000000, ///< IO physical address start - HARDWARE_IO_VADDR = 0x1EC00000, ///< IO virtual address start - HARDWARE_IO_PADDR_END = (HARDWARE_IO_PADDR + HARDWARE_IO_SIZE), - HARDWARE_IO_VADDR_END = (HARDWARE_IO_VADDR + HARDWARE_IO_SIZE), - - VRAM_SIZE = 0x00600000, - VRAM_PADDR = 0x18000000, - VRAM_VADDR = 0x1F000000, - VRAM_PADDR_END = (VRAM_PADDR + VRAM_SIZE), - VRAM_VADDR_END = (VRAM_VADDR + VRAM_SIZE), - - SCRATCHPAD_SIZE = 0x00004000, ///< Typical stack size - TODO: Read from exheader - SCRATCHPAD_VADDR_END = 0x10000000, - SCRATCHPAD_VADDR = (SCRATCHPAD_VADDR_END - SCRATCHPAD_SIZE), ///< Stack space +/// Physical memory regions as seen from the ARM11 +enum : PAddr { + /// IO register area + IO_AREA_PADDR = 0x10100000, + IO_AREA_SIZE = 0x01000000, ///< IO area size (16MB) + IO_AREA_PADDR_END = IO_AREA_PADDR + IO_AREA_SIZE, + + /// MPCore internal memory region + MPCORE_RAM_PADDR = 0x17E00000, + MPCORE_RAM_SIZE = 0x00002000, ///< MPCore internal memory size (8KB) + MPCORE_RAM_PADDR_END = MPCORE_RAM_PADDR + MPCORE_RAM_SIZE, + + /// Video memory + VRAM_PADDR = 0x18000000, + VRAM_SIZE = 0x00600000, ///< VRAM size (6MB) + VRAM_PADDR_END = VRAM_PADDR + VRAM_SIZE, + + /// DSP memory + DSP_RAM_PADDR = 0x1FF00000, + DSP_RAM_SIZE = 0x00080000, ///< DSP memory size (512KB) + DSP_RAM_PADDR_END = DSP_RAM_PADDR + DSP_RAM_SIZE, + + /// AXI WRAM + AXI_WRAM_PADDR = 0x1FF80000, + AXI_WRAM_SIZE = 0x00080000, ///< AXI WRAM size (512KB) + AXI_WRAM_PADDR_END = AXI_WRAM_PADDR + AXI_WRAM_SIZE, + + /// Main FCRAM + FCRAM_PADDR = 0x20000000, + FCRAM_SIZE = 0x08000000, ///< FCRAM size (128MB) + FCRAM_PADDR_END = FCRAM_PADDR + FCRAM_SIZE, +}; + +/// Virtual user-space memory regions +enum : VAddr { + /// Where the application text, data and bss reside. + PROCESS_IMAGE_VADDR = 0x00100000, + PROCESS_IMAGE_MAX_SIZE = 0x03F00000, + PROCESS_IMAGE_VADDR_END = PROCESS_IMAGE_VADDR + PROCESS_IMAGE_MAX_SIZE, + + /// Area where IPC buffers are mapped onto. + IPC_MAPPING_VADDR = 0x04000000, + IPC_MAPPING_SIZE = 0x04000000, + IPC_MAPPING_VADDR_END = IPC_MAPPING_VADDR + IPC_MAPPING_SIZE, + + /// Application heap (includes stack). + HEAP_VADDR = 0x08000000, + HEAP_SIZE = 0x08000000, + HEAP_VADDR_END = HEAP_VADDR + HEAP_SIZE, + + /// Area where shared memory buffers are mapped onto. + SHARED_MEMORY_VADDR = 0x10000000, + SHARED_MEMORY_SIZE = 0x04000000, + SHARED_MEMORY_VADDR_END = SHARED_MEMORY_VADDR + SHARED_MEMORY_SIZE, + + /// Maps 1:1 to an offset in FCRAM. Used for HW allocations that need to be linear in physical memory. + LINEAR_HEAP_VADDR = 0x14000000, + LINEAR_HEAP_SIZE = 0x08000000, + LINEAR_HEAP_VADDR_END = LINEAR_HEAP_VADDR + LINEAR_HEAP_SIZE, + + /// Maps 1:1 to the IO register area. + IO_AREA_VADDR = 0x1EC00000, + IO_AREA_VADDR_END = IO_AREA_VADDR + IO_AREA_SIZE, + + /// Maps 1:1 to VRAM. + VRAM_VADDR = 0x1F000000, + VRAM_VADDR_END = VRAM_VADDR + VRAM_SIZE, + + /// Maps 1:1 to DSP memory. + DSP_RAM_VADDR = 0x1FF00000, + DSP_RAM_VADDR_END = DSP_RAM_VADDR + DSP_RAM_SIZE, + + /// Read-only page containing kernel and system configuration values. + CONFIG_MEMORY_VADDR = 0x1FF80000, + CONFIG_MEMORY_SIZE = 0x00001000, + CONFIG_MEMORY_VADDR_END = CONFIG_MEMORY_VADDR + CONFIG_MEMORY_SIZE, + + /// Usually read-only page containing mostly values read from hardware. + SHARED_PAGE_VADDR = 0x1FF81000, + SHARED_PAGE_SIZE = 0x00001000, + SHARED_PAGE_VADDR_END = SHARED_PAGE_VADDR + SHARED_PAGE_SIZE, + + // TODO(yuriks): The exact location and size of this area is uncomfirmed. + /// Area where TLS (Thread-Local Storage) buffers are allocated. + TLS_AREA_VADDR = 0x1FFA0000, + TLS_AREA_SIZE = 0x00002000, // Each TLS buffer is 0x200 bytes, allows for 16 threads + TLS_AREA_VADDR_END = TLS_AREA_VADDR + TLS_AREA_SIZE, }; //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -111,9 +125,8 @@ extern u8* g_heap_linear; ///< Linear heap (main memory) extern u8* g_heap; ///< Application heap (main memory) extern u8* g_vram; ///< Video memory (VRAM) extern u8* g_shared_mem; ///< Shared memory -extern u8* g_kernel_mem; ///< Kernel memory +extern u8* g_tls_mem; ///< TLS memory extern u8* g_dsp_mem; ///< DSP memory -extern u8* g_system_mem; ///< System memory extern u8* g_exefs_code; ///< ExeFS:/.code is loaded here void Init(); diff --git a/src/core/mem_map_funcs.cpp b/src/core/mem_map_funcs.cpp index 9a19c9bf8..f96ae6e9e 100644 --- a/src/core/mem_map_funcs.cpp +++ b/src/core/mem_map_funcs.cpp @@ -29,7 +29,7 @@ VAddr PhysicalToVirtualAddress(const PAddr addr) { } else if ((addr >= VRAM_PADDR) && (addr < VRAM_PADDR_END)) { return addr - VRAM_PADDR + VRAM_VADDR; } else if ((addr >= FCRAM_PADDR) && (addr < FCRAM_PADDR_END)) { - return addr - FCRAM_PADDR + HEAP_LINEAR_VADDR; + return addr - FCRAM_PADDR + LINEAR_HEAP_VADDR; } LOG_ERROR(HW_Memory, "Unknown physical address @ 0x%08x", addr); @@ -46,8 +46,8 @@ PAddr VirtualToPhysicalAddress(const VAddr addr) { return 0; } else if ((addr >= VRAM_VADDR) && (addr < VRAM_VADDR_END)) { return addr - VRAM_VADDR + VRAM_PADDR; - } else if ((addr >= HEAP_LINEAR_VADDR) && (addr < HEAP_LINEAR_VADDR_END)) { - return addr - HEAP_LINEAR_VADDR + FCRAM_PADDR; + } else if ((addr >= LINEAR_HEAP_VADDR) && (addr < LINEAR_HEAP_VADDR_END)) { + return addr - LINEAR_HEAP_VADDR + FCRAM_PADDR; } LOG_ERROR(HW_Memory, "Unknown virtual address @ 0x%08x", addr); @@ -61,16 +61,16 @@ inline void Read(T &var, const VAddr vaddr) { // Could just do a base-relative read, too.... TODO // Kernel memory command buffer - if (vaddr >= KERNEL_MEMORY_VADDR && vaddr < KERNEL_MEMORY_VADDR_END) { - var = *((const T*)&g_kernel_mem[vaddr - KERNEL_MEMORY_VADDR]); + if (vaddr >= TLS_AREA_VADDR && vaddr < TLS_AREA_VADDR_END) { + var = *((const T*)&g_tls_mem[vaddr - TLS_AREA_VADDR]); // ExeFS:/.code is loaded here - } else if ((vaddr >= EXEFS_CODE_VADDR) && (vaddr < EXEFS_CODE_VADDR_END)) { - var = *((const T*)&g_exefs_code[vaddr - EXEFS_CODE_VADDR]); + } else if ((vaddr >= PROCESS_IMAGE_VADDR) && (vaddr < PROCESS_IMAGE_VADDR_END)) { + var = *((const T*)&g_exefs_code[vaddr - PROCESS_IMAGE_VADDR]); // FCRAM - linear heap - } else if ((vaddr >= HEAP_LINEAR_VADDR) && (vaddr < HEAP_LINEAR_VADDR_END)) { - var = *((const T*)&g_heap_linear[vaddr - HEAP_LINEAR_VADDR]); + } else if ((vaddr >= LINEAR_HEAP_VADDR) && (vaddr < LINEAR_HEAP_VADDR_END)) { + var = *((const T*)&g_heap_linear[vaddr - LINEAR_HEAP_VADDR]); // FCRAM - application heap } else if ((vaddr >= HEAP_VADDR) && (vaddr < HEAP_VADDR_END)) { @@ -80,10 +80,6 @@ inline void Read(T &var, const VAddr vaddr) { } else if ((vaddr >= SHARED_MEMORY_VADDR) && (vaddr < SHARED_MEMORY_VADDR_END)) { var = *((const T*)&g_shared_mem[vaddr - SHARED_MEMORY_VADDR]); - // System memory - } else if ((vaddr >= SYSTEM_MEMORY_VADDR) && (vaddr < SYSTEM_MEMORY_VADDR_END)) { - var = *((const T*)&g_system_mem[vaddr - SYSTEM_MEMORY_VADDR]); - // Config memory } else if ((vaddr >= CONFIG_MEMORY_VADDR) && (vaddr < CONFIG_MEMORY_VADDR_END)) { ConfigMem::Read(var, vaddr); @@ -93,8 +89,8 @@ inline void Read(T &var, const VAddr vaddr) { SharedPage::Read(var, vaddr); // DSP memory - } else if ((vaddr >= DSP_MEMORY_VADDR) && (vaddr < DSP_MEMORY_VADDR_END)) { - var = *((const T*)&g_dsp_mem[vaddr - DSP_MEMORY_VADDR]); + } else if ((vaddr >= DSP_RAM_VADDR) && (vaddr < DSP_RAM_VADDR_END)) { + var = *((const T*)&g_dsp_mem[vaddr - DSP_RAM_VADDR]); // VRAM } else if ((vaddr >= VRAM_VADDR) && (vaddr < VRAM_VADDR_END)) { @@ -109,16 +105,16 @@ template inline void Write(const VAddr vaddr, const T data) { // Kernel memory command buffer - if (vaddr >= KERNEL_MEMORY_VADDR && vaddr < KERNEL_MEMORY_VADDR_END) { - *(T*)&g_kernel_mem[vaddr - KERNEL_MEMORY_VADDR] = data; + if (vaddr >= TLS_AREA_VADDR && vaddr < TLS_AREA_VADDR_END) { + *(T*)&g_tls_mem[vaddr - TLS_AREA_VADDR] = data; // ExeFS:/.code is loaded here - } else if ((vaddr >= EXEFS_CODE_VADDR) && (vaddr < EXEFS_CODE_VADDR_END)) { - *(T*)&g_exefs_code[vaddr - EXEFS_CODE_VADDR] = data; + } else if ((vaddr >= PROCESS_IMAGE_VADDR) && (vaddr < PROCESS_IMAGE_VADDR_END)) { + *(T*)&g_exefs_code[vaddr - PROCESS_IMAGE_VADDR] = data; // FCRAM - linear heap - } else if ((vaddr >= HEAP_LINEAR_VADDR) && (vaddr < HEAP_LINEAR_VADDR_END)) { - *(T*)&g_heap_linear[vaddr - HEAP_LINEAR_VADDR] = data; + } else if ((vaddr >= LINEAR_HEAP_VADDR) && (vaddr < LINEAR_HEAP_VADDR_END)) { + *(T*)&g_heap_linear[vaddr - LINEAR_HEAP_VADDR] = data; // FCRAM - application heap } else if ((vaddr >= HEAP_VADDR) && (vaddr < HEAP_VADDR_END)) { @@ -128,17 +124,13 @@ inline void Write(const VAddr vaddr, const T data) { } else if ((vaddr >= SHARED_MEMORY_VADDR) && (vaddr < SHARED_MEMORY_VADDR_END)) { *(T*)&g_shared_mem[vaddr - SHARED_MEMORY_VADDR] = data; - // System memory - } else if ((vaddr >= SYSTEM_MEMORY_VADDR) && (vaddr < SYSTEM_MEMORY_VADDR_END)) { - *(T*)&g_system_mem[vaddr - SYSTEM_MEMORY_VADDR] = data; - // VRAM } else if ((vaddr >= VRAM_VADDR) && (vaddr < VRAM_VADDR_END)) { *(T*)&g_vram[vaddr - VRAM_VADDR] = data; // DSP memory - } else if ((vaddr >= DSP_MEMORY_VADDR) && (vaddr < DSP_MEMORY_VADDR_END)) { - *(T*)&g_dsp_mem[vaddr - DSP_MEMORY_VADDR] = data; + } else if ((vaddr >= DSP_RAM_VADDR) && (vaddr < DSP_RAM_VADDR_END)) { + *(T*)&g_dsp_mem[vaddr - DSP_RAM_VADDR] = data; //} else if ((vaddr & 0xFFFF0000) == 0x1FF80000) { // ASSERT_MSG(MEMMAP, false, "umimplemented write to Configuration Memory"); @@ -153,16 +145,16 @@ inline void Write(const VAddr vaddr, const T data) { u8 *GetPointer(const VAddr vaddr) { // Kernel memory command buffer - if (vaddr >= KERNEL_MEMORY_VADDR && vaddr < KERNEL_MEMORY_VADDR_END) { - return g_kernel_mem + (vaddr - KERNEL_MEMORY_VADDR); + if (vaddr >= TLS_AREA_VADDR && vaddr < TLS_AREA_VADDR_END) { + return g_tls_mem + (vaddr - TLS_AREA_VADDR); // ExeFS:/.code is loaded here - } else if ((vaddr >= EXEFS_CODE_VADDR) && (vaddr < EXEFS_CODE_VADDR_END)) { - return g_exefs_code + (vaddr - EXEFS_CODE_VADDR); + } else if ((vaddr >= PROCESS_IMAGE_VADDR) && (vaddr < PROCESS_IMAGE_VADDR_END)) { + return g_exefs_code + (vaddr - PROCESS_IMAGE_VADDR); // FCRAM - linear heap - } else if ((vaddr >= HEAP_LINEAR_VADDR) && (vaddr < HEAP_LINEAR_VADDR_END)) { - return g_heap_linear + (vaddr - HEAP_LINEAR_VADDR); + } else if ((vaddr >= LINEAR_HEAP_VADDR) && (vaddr < LINEAR_HEAP_VADDR_END)) { + return g_heap_linear + (vaddr - LINEAR_HEAP_VADDR); // FCRAM - application heap } else if ((vaddr >= HEAP_VADDR) && (vaddr < HEAP_VADDR_END)) { @@ -172,10 +164,6 @@ u8 *GetPointer(const VAddr vaddr) { } else if ((vaddr >= SHARED_MEMORY_VADDR) && (vaddr < SHARED_MEMORY_VADDR_END)) { return g_shared_mem + (vaddr - SHARED_MEMORY_VADDR); - // System memory - } else if ((vaddr >= SYSTEM_MEMORY_VADDR) && (vaddr < SYSTEM_MEMORY_VADDR_END)) { - return g_system_mem + (vaddr - SYSTEM_MEMORY_VADDR); - // VRAM } else if ((vaddr >= VRAM_VADDR) && (vaddr < VRAM_VADDR_END)) { return g_vram + (vaddr - VRAM_VADDR); @@ -206,7 +194,7 @@ u32 MapBlock_Heap(u32 size, u32 operation, u32 permissions) { u32 MapBlock_HeapLinear(u32 size, u32 operation, u32 permissions) { MemoryBlock block; - block.base_address = HEAP_LINEAR_VADDR; + block.base_address = LINEAR_HEAP_VADDR; block.size = size; block.operation = operation; block.permissions = permissions; diff --git a/src/video_core/pica.h b/src/video_core/pica.h index a0ba715f3..4c48b6bf7 100644 --- a/src/video_core/pica.h +++ b/src/video_core/pica.h @@ -1003,7 +1003,7 @@ inline static u32 PAddrToVAddr(u32 addr) { if (addr >= Memory::VRAM_PADDR && addr < Memory::VRAM_PADDR + Memory::VRAM_SIZE) { return addr - Memory::VRAM_PADDR + Memory::VRAM_VADDR; } else if (addr >= Memory::FCRAM_PADDR && addr < Memory::FCRAM_PADDR + Memory::FCRAM_SIZE) { - return addr - Memory::FCRAM_PADDR + Memory::HEAP_LINEAR_VADDR; + return addr - Memory::FCRAM_PADDR + Memory::LINEAR_HEAP_VADDR; } else { return 0; } -- cgit v1.2.3 From e7b6ed757849bcec43d736ec8efaf17141a46d4b Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Sat, 9 May 2015 00:44:29 -0300 Subject: Memory: Sort memory region variables by VAddr --- src/core/mem_map.cpp | 6 +++--- src/core/mem_map.h | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/core/mem_map.cpp b/src/core/mem_map.cpp index 74faf0dce..f99520464 100644 --- a/src/core/mem_map.cpp +++ b/src/core/mem_map.cpp @@ -13,9 +13,9 @@ namespace Memory { u8* g_exefs_code; ///< ExeFS:/.code is loaded here u8* g_heap; ///< Application heap (main memory) +u8* g_shared_mem; ///< Shared memory u8* g_heap_linear; ///< Linear heap u8* g_vram; ///< Video memory (VRAM) pointer -u8* g_shared_mem; ///< Shared memory u8* g_dsp_mem; ///< DSP memory u8* g_tls_mem; ///< TLS memory @@ -29,12 +29,12 @@ struct MemoryArea { // We don't declare the IO regions in here since its handled by other means. static MemoryArea memory_areas[] = { {&g_exefs_code, PROCESS_IMAGE_MAX_SIZE}, - {&g_vram, VRAM_SIZE }, {&g_heap, HEAP_SIZE }, {&g_shared_mem, SHARED_MEMORY_SIZE }, + {&g_heap_linear, LINEAR_HEAP_SIZE }, + {&g_vram, VRAM_SIZE }, {&g_dsp_mem, DSP_RAM_SIZE }, {&g_tls_mem, TLS_AREA_SIZE }, - {&g_heap_linear, LINEAR_HEAP_SIZE }, }; } diff --git a/src/core/mem_map.h b/src/core/mem_map.h index 3866a3a11..1591fc0a9 100644 --- a/src/core/mem_map.h +++ b/src/core/mem_map.h @@ -121,13 +121,13 @@ struct MemoryBlock { //////////////////////////////////////////////////////////////////////////////////////////////////// -extern u8* g_heap_linear; ///< Linear heap (main memory) -extern u8* g_heap; ///< Application heap (main memory) -extern u8* g_vram; ///< Video memory (VRAM) -extern u8* g_shared_mem; ///< Shared memory -extern u8* g_tls_mem; ///< TLS memory -extern u8* g_dsp_mem; ///< DSP memory -extern u8* g_exefs_code; ///< ExeFS:/.code is loaded here +extern u8* g_exefs_code; ///< ExeFS:/.code is loaded here +extern u8* g_heap; ///< Application heap (main memory) +extern u8* g_shared_mem; ///< Shared memory +extern u8* g_heap_linear; ///< Linear heap (main memory) +extern u8* g_vram; ///< Video memory (VRAM) +extern u8* g_dsp_mem; ///< DSP memory +extern u8* g_tls_mem; ///< TLS memory void Init(); void Shutdown(); -- cgit v1.2.3 From 28a9e4c1d55c66e99b5cf16fda00dcb75ab27fde Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Sat, 9 May 2015 03:08:11 -0300 Subject: Memory: Support more regions in the VAddr-PAddr translation functions Also adds better documentation and removes the one-off reimplementation of the function in pica.h. --- src/citra_qt/debugger/graphics_cmdlists.cpp | 4 +-- src/citra_qt/debugger/graphics_framebuffer.cpp | 2 +- src/core/mem_map.h | 13 ++++--- src/core/mem_map_funcs.cpp | 48 +++++++++++++------------- src/video_core/command_processor.cpp | 4 +-- src/video_core/pica.h | 11 ------ src/video_core/rasterizer.cpp | 10 +++--- 7 files changed, 43 insertions(+), 49 deletions(-) (limited to 'src') diff --git a/src/citra_qt/debugger/graphics_cmdlists.cpp b/src/citra_qt/debugger/graphics_cmdlists.cpp index 9bcd25821..6727acf18 100644 --- a/src/citra_qt/debugger/graphics_cmdlists.cpp +++ b/src/citra_qt/debugger/graphics_cmdlists.cpp @@ -159,7 +159,7 @@ void TextureInfoDockWidget::OnStrideChanged(int value) { } QPixmap TextureInfoDockWidget::ReloadPixmap() const { - u8* src = Memory::GetPointer(Pica::PAddrToVAddr(info.physical_address)); + u8* src = Memory::GetPointer(Memory::PhysicalToVirtualAddress(info.physical_address)); return QPixmap::fromImage(LoadTexture(src, info)); } @@ -274,7 +274,7 @@ void GPUCommandListWidget::SetCommandInfo(const QModelIndex& index) { auto format = Pica::registers.GetTextures()[index].format; auto info = Pica::DebugUtils::TextureInfo::FromPicaRegister(config, format); - u8* src = Memory::GetPointer(Pica::PAddrToVAddr(config.GetPhysicalAddress())); + u8* src = Memory::GetPointer(Memory::PhysicalToVirtualAddress(config.GetPhysicalAddress())); new_info_widget = new TextureInfoWidget(src, info); } else { new_info_widget = new QWidget; diff --git a/src/citra_qt/debugger/graphics_framebuffer.cpp b/src/citra_qt/debugger/graphics_framebuffer.cpp index d621d7204..fa101a6a2 100644 --- a/src/citra_qt/debugger/graphics_framebuffer.cpp +++ b/src/citra_qt/debugger/graphics_framebuffer.cpp @@ -215,7 +215,7 @@ void GraphicsFramebufferWidget::OnUpdate() u32 bytes_per_pixel = GraphicsFramebufferWidget::BytesPerPixel(framebuffer_format); QImage decoded_image(framebuffer_width, framebuffer_height, QImage::Format_ARGB32); - u8* buffer = Memory::GetPointer(Pica::PAddrToVAddr(framebuffer_address)); + u8* buffer = Memory::GetPointer(Memory::PhysicalToVirtualAddress(framebuffer_address)); for (unsigned int y = 0; y < framebuffer_height; ++y) { for (unsigned int x = 0; x < framebuffer_width; ++x) { diff --git a/src/core/mem_map.h b/src/core/mem_map.h index 1591fc0a9..5a08cc105 100644 --- a/src/core/mem_map.h +++ b/src/core/mem_map.h @@ -181,10 +181,15 @@ inline const char* GetCharPointer(const VAddr address) { return (const char *)GetPointer(address); } -/// Converts a physical address to virtual address -VAddr PhysicalToVirtualAddress(PAddr addr); - -/// Converts a virtual address to physical address +/** + * Converts a virtual address inside a region with 1:1 mapping to physical memory to a physical + * address. This should be used by services to translate addresses for use by the hardware. + */ PAddr VirtualToPhysicalAddress(VAddr addr); +/** + * Undoes a mapping performed by VirtualToPhysicalAddress(). + */ +VAddr PhysicalToVirtualAddress(PAddr addr); + } // namespace diff --git a/src/core/mem_map_funcs.cpp b/src/core/mem_map_funcs.cpp index f96ae6e9e..a8e0fed07 100644 --- a/src/core/mem_map_funcs.cpp +++ b/src/core/mem_map_funcs.cpp @@ -18,40 +18,40 @@ namespace Memory { static std::map heap_map; static std::map heap_linear_map; -/// Convert a physical address to virtual address -VAddr PhysicalToVirtualAddress(const PAddr addr) { - // Our memory interface read/write functions assume virtual addresses. Put any physical address - // to virtual address translations here. This is quite hacky, but necessary until we implement - // proper MMU emulation. - // TODO: Screw it, I'll let bunnei figure out how to do this properly. +PAddr VirtualToPhysicalAddress(const VAddr addr) { if (addr == 0) { return 0; - } else if ((addr >= VRAM_PADDR) && (addr < VRAM_PADDR_END)) { - return addr - VRAM_PADDR + VRAM_VADDR; - } else if ((addr >= FCRAM_PADDR) && (addr < FCRAM_PADDR_END)) { - return addr - FCRAM_PADDR + LINEAR_HEAP_VADDR; + } else if (addr >= VRAM_VADDR && addr < VRAM_VADDR_END) { + return addr - VRAM_VADDR + VRAM_PADDR; + } else if (addr >= LINEAR_HEAP_VADDR && addr < LINEAR_HEAP_VADDR_END) { + return addr - LINEAR_HEAP_VADDR + FCRAM_PADDR; + } else if (addr >= DSP_RAM_VADDR && addr < DSP_RAM_VADDR_END) { + return addr - DSP_RAM_VADDR + DSP_RAM_PADDR; + } else if (addr >= IO_AREA_VADDR && addr < IO_AREA_VADDR_END) { + return addr - IO_AREA_VADDR + IO_AREA_PADDR; } - LOG_ERROR(HW_Memory, "Unknown physical address @ 0x%08x", addr); - return addr; + LOG_ERROR(HW_Memory, "Unknown virtual address @ 0x%08x", addr); + // To help with debugging, set bit on address so that it's obviously invalid. + return addr | 0x80000000; } -/// Convert a physical address to virtual address -PAddr VirtualToPhysicalAddress(const VAddr addr) { - // Our memory interface read/write functions assume virtual addresses. Put any physical address - // to virtual address translations here. This is quite hacky, but necessary until we implement - // proper MMU emulation. - // TODO: Screw it, I'll let bunnei figure out how to do this properly. +VAddr PhysicalToVirtualAddress(const PAddr addr) { if (addr == 0) { return 0; - } else if ((addr >= VRAM_VADDR) && (addr < VRAM_VADDR_END)) { - return addr - VRAM_VADDR + VRAM_PADDR; - } else if ((addr >= LINEAR_HEAP_VADDR) && (addr < LINEAR_HEAP_VADDR_END)) { - return addr - LINEAR_HEAP_VADDR + FCRAM_PADDR; + } else if (addr >= VRAM_PADDR && addr < VRAM_PADDR_END) { + return addr - VRAM_PADDR + VRAM_VADDR; + } else if (addr >= FCRAM_PADDR && addr < FCRAM_PADDR_END) { + return addr - FCRAM_PADDR + LINEAR_HEAP_VADDR; + } else if (addr >= DSP_RAM_PADDR && addr < DSP_RAM_PADDR_END) { + return addr - DSP_RAM_PADDR + DSP_RAM_VADDR; + } else if (addr >= IO_AREA_PADDR && addr < IO_AREA_PADDR_END) { + return addr - IO_AREA_PADDR + IO_AREA_VADDR; } - LOG_ERROR(HW_Memory, "Unknown virtual address @ 0x%08x", addr); - return addr; + LOG_ERROR(HW_Memory, "Unknown physical address @ 0x%08x", addr); + // To help with debugging, set bit on address so that it's obviously invalid. + return addr | 0x80000000; } template diff --git a/src/video_core/command_processor.cpp b/src/video_core/command_processor.cpp index c4cdf672b..7c4047e33 100644 --- a/src/video_core/command_processor.cpp +++ b/src/video_core/command_processor.cpp @@ -102,7 +102,7 @@ static inline void WritePicaReg(u32 id, u32 value, u32 mask) { bool is_indexed = (id == PICA_REG_INDEX(trigger_draw_indexed)); const auto& index_info = registers.index_array; - const u8* index_address_8 = Memory::GetPointer(PAddrToVAddr(base_address + index_info.offset)); + const u8* index_address_8 = Memory::GetPointer(Memory::PhysicalToVirtualAddress(base_address + index_info.offset)); const u16* index_address_16 = (u16*)index_address_8; bool index_u16 = index_info.format != 0; @@ -135,7 +135,7 @@ static inline void WritePicaReg(u32 id, u32 value, u32 mask) { input.attr[i][2].ToFloat32(), input.attr[i][3].ToFloat32()); } else { for (unsigned int comp = 0; comp < vertex_attribute_elements[i]; ++comp) { - const u8* srcdata = Memory::GetPointer(PAddrToVAddr(vertex_attribute_sources[i] + vertex_attribute_strides[i] * vertex + comp * vertex_attribute_element_size[i])); + const u8* srcdata = Memory::GetPointer(Memory::PhysicalToVirtualAddress(vertex_attribute_sources[i] + vertex_attribute_strides[i] * vertex + comp * vertex_attribute_element_size[i])); const float srcval = (vertex_attribute_formats[i] == Regs::VertexAttributeFormat::BYTE) ? *(s8*)srcdata : (vertex_attribute_formats[i] == Regs::VertexAttributeFormat::UBYTE) ? *(u8*)srcdata : diff --git a/src/video_core/pica.h b/src/video_core/pica.h index 4c48b6bf7..e4a91058c 100644 --- a/src/video_core/pica.h +++ b/src/video_core/pica.h @@ -998,15 +998,4 @@ union CommandHeader { BitField<31, 1, u32> group_commands; }; -// TODO: Ugly, should fix PhysicalToVirtualAddress instead -inline static u32 PAddrToVAddr(u32 addr) { - if (addr >= Memory::VRAM_PADDR && addr < Memory::VRAM_PADDR + Memory::VRAM_SIZE) { - return addr - Memory::VRAM_PADDR + Memory::VRAM_VADDR; - } else if (addr >= Memory::FCRAM_PADDR && addr < Memory::FCRAM_PADDR + Memory::FCRAM_SIZE) { - return addr - Memory::FCRAM_PADDR + Memory::LINEAR_HEAP_VADDR; - } else { - return 0; - } -} - } // namespace diff --git a/src/video_core/rasterizer.cpp b/src/video_core/rasterizer.cpp index 6ec253601..ab7776929 100644 --- a/src/video_core/rasterizer.cpp +++ b/src/video_core/rasterizer.cpp @@ -30,7 +30,7 @@ static void DrawPixel(int x, int y, const Math::Vec4& color) { const u32 coarse_y = y & ~7; u32 bytes_per_pixel = GPU::Regs::BytesPerPixel(GPU::Regs::PixelFormat(registers.framebuffer.color_format.Value())); u32 dst_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * registers.framebuffer.width * bytes_per_pixel; - u8* dst_pixel = Memory::GetPointer(PAddrToVAddr(addr)) + dst_offset; + u8* dst_pixel = Memory::GetPointer(Memory::PhysicalToVirtualAddress(addr)) + dst_offset; switch (registers.framebuffer.color_format) { case registers.framebuffer.RGBA8: @@ -67,7 +67,7 @@ static const Math::Vec4 GetPixel(int x, int y) { const u32 coarse_y = y & ~7; u32 bytes_per_pixel = GPU::Regs::BytesPerPixel(GPU::Regs::PixelFormat(registers.framebuffer.color_format.Value())); u32 src_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * registers.framebuffer.width * bytes_per_pixel; - u8* src_pixel = Memory::GetPointer(PAddrToVAddr(addr)) + src_offset; + u8* src_pixel = Memory::GetPointer(Memory::PhysicalToVirtualAddress(addr)) + src_offset; switch (registers.framebuffer.color_format) { case registers.framebuffer.RGBA8: @@ -95,7 +95,7 @@ static const Math::Vec4 GetPixel(int x, int y) { static u32 GetDepth(int x, int y) { const PAddr addr = registers.framebuffer.GetDepthBufferPhysicalAddress(); - u8* depth_buffer = Memory::GetPointer(PAddrToVAddr(addr)); + u8* depth_buffer = Memory::GetPointer(Memory::PhysicalToVirtualAddress(addr)); y = (registers.framebuffer.height - y); @@ -122,7 +122,7 @@ static u32 GetDepth(int x, int y) { static void SetDepth(int x, int y, u32 value) { const PAddr addr = registers.framebuffer.GetDepthBufferPhysicalAddress(); - u8* depth_buffer = Memory::GetPointer(PAddrToVAddr(addr)); + u8* depth_buffer = Memory::GetPointer(Memory::PhysicalToVirtualAddress(addr)); y = (registers.framebuffer.height - y); @@ -361,7 +361,7 @@ static void ProcessTriangleInternal(const VertexShader::OutputVertex& v0, s = GetWrappedTexCoord(texture.config.wrap_s, s, texture.config.width); t = texture.config.height - 1 - GetWrappedTexCoord(texture.config.wrap_t, t, texture.config.height); - u8* texture_data = Memory::GetPointer(PAddrToVAddr(texture.config.GetPhysicalAddress())); + u8* texture_data = Memory::GetPointer(Memory::PhysicalToVirtualAddress(texture.config.GetPhysicalAddress())); auto info = DebugUtils::TextureInfo::FromPicaRegister(texture.config, texture.format); texture_color[i] = DebugUtils::LookupTexture(texture_data, s, t, info); -- cgit v1.2.3 From 17a8cae0038b82202149bad687823b89074aa696 Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Sat, 9 May 2015 04:02:32 -0300 Subject: Memory: Add GetPhysicalPointer helper function --- src/citra_qt/debugger/graphics_cmdlists.cpp | 4 ++-- src/citra_qt/debugger/graphics_framebuffer.cpp | 2 +- src/core/hw/gpu.cpp | 10 +++++----- src/core/mem_map.h | 9 +++++++++ src/video_core/command_processor.cpp | 4 ++-- src/video_core/rasterizer.cpp | 10 +++++----- src/video_core/renderer_opengl/renderer_opengl.cpp | 8 ++++---- 7 files changed, 28 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/citra_qt/debugger/graphics_cmdlists.cpp b/src/citra_qt/debugger/graphics_cmdlists.cpp index 6727acf18..66e11dd5b 100644 --- a/src/citra_qt/debugger/graphics_cmdlists.cpp +++ b/src/citra_qt/debugger/graphics_cmdlists.cpp @@ -159,7 +159,7 @@ void TextureInfoDockWidget::OnStrideChanged(int value) { } QPixmap TextureInfoDockWidget::ReloadPixmap() const { - u8* src = Memory::GetPointer(Memory::PhysicalToVirtualAddress(info.physical_address)); + u8* src = Memory::GetPhysicalPointer(info.physical_address); return QPixmap::fromImage(LoadTexture(src, info)); } @@ -274,7 +274,7 @@ void GPUCommandListWidget::SetCommandInfo(const QModelIndex& index) { auto format = Pica::registers.GetTextures()[index].format; auto info = Pica::DebugUtils::TextureInfo::FromPicaRegister(config, format); - u8* src = Memory::GetPointer(Memory::PhysicalToVirtualAddress(config.GetPhysicalAddress())); + u8* src = Memory::GetPhysicalPointer(config.GetPhysicalAddress()); new_info_widget = new TextureInfoWidget(src, info); } else { new_info_widget = new QWidget; diff --git a/src/citra_qt/debugger/graphics_framebuffer.cpp b/src/citra_qt/debugger/graphics_framebuffer.cpp index fa101a6a2..3287b4706 100644 --- a/src/citra_qt/debugger/graphics_framebuffer.cpp +++ b/src/citra_qt/debugger/graphics_framebuffer.cpp @@ -215,7 +215,7 @@ void GraphicsFramebufferWidget::OnUpdate() u32 bytes_per_pixel = GraphicsFramebufferWidget::BytesPerPixel(framebuffer_format); QImage decoded_image(framebuffer_width, framebuffer_height, QImage::Format_ARGB32); - u8* buffer = Memory::GetPointer(Memory::PhysicalToVirtualAddress(framebuffer_address)); + u8* buffer = Memory::GetPhysicalPointer(framebuffer_address); for (unsigned int y = 0; y < framebuffer_height; ++y) { for (unsigned int x = 0; x < framebuffer_width; ++x) { diff --git a/src/core/hw/gpu.cpp b/src/core/hw/gpu.cpp index 0ad7e2963..e4a0e14c4 100644 --- a/src/core/hw/gpu.cpp +++ b/src/core/hw/gpu.cpp @@ -76,8 +76,8 @@ inline void Write(u32 addr, const T data) { auto& config = g_regs.memory_fill_config[is_second_filler]; if (config.address_start && config.trigger) { - u8* start = Memory::GetPointer(Memory::PhysicalToVirtualAddress(config.GetStartAddress())); - u8* end = Memory::GetPointer(Memory::PhysicalToVirtualAddress(config.GetEndAddress())); + u8* start = Memory::GetPhysicalPointer(config.GetStartAddress()); + u8* end = Memory::GetPhysicalPointer(config.GetEndAddress()); if (config.fill_24bit) { // fill with 24-bit values @@ -114,8 +114,8 @@ inline void Write(u32 addr, const T data) { { const auto& config = g_regs.display_transfer_config; if (config.trigger & 1) { - u8* src_pointer = Memory::GetPointer(Memory::PhysicalToVirtualAddress(config.GetPhysicalInputAddress())); - u8* dst_pointer = Memory::GetPointer(Memory::PhysicalToVirtualAddress(config.GetPhysicalOutputAddress())); + u8* src_pointer = Memory::GetPhysicalPointer(config.GetPhysicalInputAddress()); + u8* dst_pointer = Memory::GetPhysicalPointer(config.GetPhysicalOutputAddress()); if (config.scaling > config.ScaleXY) { LOG_CRITICAL(HW_GPU, "Unimplemented display transfer scaling mode %u", config.scaling.Value()); @@ -257,7 +257,7 @@ inline void Write(u32 addr, const T data) { const auto& config = g_regs.command_processor_config; if (config.trigger & 1) { - u32* buffer = (u32*)Memory::GetPointer(Memory::PhysicalToVirtualAddress(config.GetPhysicalAddress())); + u32* buffer = (u32*)Memory::GetPhysicalPointer(config.GetPhysicalAddress()); Pica::CommandProcessor::ProcessCommandList(buffer, config.size); } break; diff --git a/src/core/mem_map.h b/src/core/mem_map.h index 5a08cc105..64de76c39 100644 --- a/src/core/mem_map.h +++ b/src/core/mem_map.h @@ -192,4 +192,13 @@ PAddr VirtualToPhysicalAddress(VAddr addr); */ VAddr PhysicalToVirtualAddress(PAddr addr); +/** + * Gets a pointer to the memory region beginning at the specified physical address. + * + * @note This is currently implemented using PhysicalToVirtualAddress(). + */ +inline u8* GetPhysicalPointer(PAddr address) { + return GetPointer(PhysicalToVirtualAddress(address)); +} + } // namespace diff --git a/src/video_core/command_processor.cpp b/src/video_core/command_processor.cpp index 7c4047e33..1ea7cad07 100644 --- a/src/video_core/command_processor.cpp +++ b/src/video_core/command_processor.cpp @@ -102,7 +102,7 @@ static inline void WritePicaReg(u32 id, u32 value, u32 mask) { bool is_indexed = (id == PICA_REG_INDEX(trigger_draw_indexed)); const auto& index_info = registers.index_array; - const u8* index_address_8 = Memory::GetPointer(Memory::PhysicalToVirtualAddress(base_address + index_info.offset)); + const u8* index_address_8 = Memory::GetPhysicalPointer(base_address + index_info.offset); const u16* index_address_16 = (u16*)index_address_8; bool index_u16 = index_info.format != 0; @@ -135,7 +135,7 @@ static inline void WritePicaReg(u32 id, u32 value, u32 mask) { input.attr[i][2].ToFloat32(), input.attr[i][3].ToFloat32()); } else { for (unsigned int comp = 0; comp < vertex_attribute_elements[i]; ++comp) { - const u8* srcdata = Memory::GetPointer(Memory::PhysicalToVirtualAddress(vertex_attribute_sources[i] + vertex_attribute_strides[i] * vertex + comp * vertex_attribute_element_size[i])); + const u8* srcdata = Memory::GetPhysicalPointer(vertex_attribute_sources[i] + vertex_attribute_strides[i] * vertex + comp * vertex_attribute_element_size[i]); const float srcval = (vertex_attribute_formats[i] == Regs::VertexAttributeFormat::BYTE) ? *(s8*)srcdata : (vertex_attribute_formats[i] == Regs::VertexAttributeFormat::UBYTE) ? *(u8*)srcdata : diff --git a/src/video_core/rasterizer.cpp b/src/video_core/rasterizer.cpp index ab7776929..3b3fef484 100644 --- a/src/video_core/rasterizer.cpp +++ b/src/video_core/rasterizer.cpp @@ -30,7 +30,7 @@ static void DrawPixel(int x, int y, const Math::Vec4& color) { const u32 coarse_y = y & ~7; u32 bytes_per_pixel = GPU::Regs::BytesPerPixel(GPU::Regs::PixelFormat(registers.framebuffer.color_format.Value())); u32 dst_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * registers.framebuffer.width * bytes_per_pixel; - u8* dst_pixel = Memory::GetPointer(Memory::PhysicalToVirtualAddress(addr)) + dst_offset; + u8* dst_pixel = Memory::GetPhysicalPointer(addr) + dst_offset; switch (registers.framebuffer.color_format) { case registers.framebuffer.RGBA8: @@ -67,7 +67,7 @@ static const Math::Vec4 GetPixel(int x, int y) { const u32 coarse_y = y & ~7; u32 bytes_per_pixel = GPU::Regs::BytesPerPixel(GPU::Regs::PixelFormat(registers.framebuffer.color_format.Value())); u32 src_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * registers.framebuffer.width * bytes_per_pixel; - u8* src_pixel = Memory::GetPointer(Memory::PhysicalToVirtualAddress(addr)) + src_offset; + u8* src_pixel = Memory::GetPhysicalPointer(addr) + src_offset; switch (registers.framebuffer.color_format) { case registers.framebuffer.RGBA8: @@ -95,7 +95,7 @@ static const Math::Vec4 GetPixel(int x, int y) { static u32 GetDepth(int x, int y) { const PAddr addr = registers.framebuffer.GetDepthBufferPhysicalAddress(); - u8* depth_buffer = Memory::GetPointer(Memory::PhysicalToVirtualAddress(addr)); + u8* depth_buffer = Memory::GetPhysicalPointer(addr); y = (registers.framebuffer.height - y); @@ -122,7 +122,7 @@ static u32 GetDepth(int x, int y) { static void SetDepth(int x, int y, u32 value) { const PAddr addr = registers.framebuffer.GetDepthBufferPhysicalAddress(); - u8* depth_buffer = Memory::GetPointer(Memory::PhysicalToVirtualAddress(addr)); + u8* depth_buffer = Memory::GetPhysicalPointer(addr); y = (registers.framebuffer.height - y); @@ -361,7 +361,7 @@ static void ProcessTriangleInternal(const VertexShader::OutputVertex& v0, s = GetWrappedTexCoord(texture.config.wrap_s, s, texture.config.width); t = texture.config.height - 1 - GetWrappedTexCoord(texture.config.wrap_t, t, texture.config.height); - u8* texture_data = Memory::GetPointer(Memory::PhysicalToVirtualAddress(texture.config.GetPhysicalAddress())); + u8* texture_data = Memory::GetPhysicalPointer(texture.config.GetPhysicalAddress()); auto info = DebugUtils::TextureInfo::FromPicaRegister(texture.config, texture.format); texture_color[i] = DebugUtils::LookupTexture(texture_data, s, t, info); diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp index 6b242a6ed..0c072120d 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.cpp +++ b/src/video_core/renderer_opengl/renderer_opengl.cpp @@ -119,15 +119,15 @@ void RendererOpenGL::SwapBuffers() { void RendererOpenGL::LoadFBToActiveGLTexture(const GPU::Regs::FramebufferConfig& framebuffer, const TextureInfo& texture) { - const VAddr framebuffer_vaddr = Memory::PhysicalToVirtualAddress( - framebuffer.active_fb == 0 ? framebuffer.address_left1 : framebuffer.address_left2); + const PAddr framebuffer_addr = framebuffer.active_fb == 0 ? + framebuffer.address_left1 : framebuffer.address_left2; LOG_TRACE(Render_OpenGL, "0x%08x bytes from 0x%08x(%dx%d), fmt %x", framebuffer.stride * framebuffer.height, - framebuffer_vaddr, (int)framebuffer.width, + framebuffer_addr, (int)framebuffer.width, (int)framebuffer.height, (int)framebuffer.format); - const u8* framebuffer_data = Memory::GetPointer(framebuffer_vaddr); + const u8* framebuffer_data = Memory::GetPhysicalPointer(framebuffer_addr); int bpp = GPU::Regs::BytesPerPixel(framebuffer.color_format); size_t pixel_stride = framebuffer.stride / bpp; -- cgit v1.2.3