summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Tony Wasserka2015-05-09 15:57:29 +0200
committerGravatar Tony Wasserka2015-05-09 15:57:29 +0200
commite35e72d0a5c90c37d22328115fa0f29dd17aeaee (patch)
tree4053db2c53a1ac77294c03782de75c91c0cf4b27 /src
parentLoader: Add missing include (diff)
parentMemory: Add GetPhysicalPointer helper function (diff)
downloadyuzu-e35e72d0a5c90c37d22328115fa0f29dd17aeaee.tar.gz
yuzu-e35e72d0a5c90c37d22328115fa0f29dd17aeaee.tar.xz
yuzu-e35e72d0a5c90c37d22328115fa0f29dd17aeaee.zip
Merge pull request #734 from yuriks/memmap
Small memory map definitions cleanup
Diffstat (limited to 'src')
-rw-r--r--src/citra_qt/debugger/graphics_cmdlists.cpp4
-rw-r--r--src/citra_qt/debugger/graphics_framebuffer.cpp2
-rw-r--r--src/core/core.cpp2
-rw-r--r--src/core/hle/kernel/session.h2
-rw-r--r--src/core/hle/kernel/thread.cpp5
-rw-r--r--src/core/hle/service/dsp_dsp.cpp2
-rw-r--r--src/core/hw/gpu.cpp10
-rw-r--r--src/core/loader/3dsx.cpp4
-rw-r--r--src/core/loader/elf.cpp2
-rw-r--r--src/core/mem_map.cpp20
-rw-r--r--src/core/mem_map.h195
-rw-r--r--src/core/mem_map_funcs.cpp106
-rw-r--r--src/video_core/command_processor.cpp4
-rw-r--r--src/video_core/pica.h11
-rw-r--r--src/video_core/rasterizer.cpp10
-rw-r--r--src/video_core/renderer_opengl/renderer_opengl.cpp8
16 files changed, 195 insertions, 192 deletions
diff --git a/src/citra_qt/debugger/graphics_cmdlists.cpp b/src/citra_qt/debugger/graphics_cmdlists.cpp
index 9bcd25821..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) {
159} 159}
160 160
161QPixmap TextureInfoDockWidget::ReloadPixmap() const { 161QPixmap TextureInfoDockWidget::ReloadPixmap() const {
162 u8* src = Memory::GetPointer(Pica::PAddrToVAddr(info.physical_address)); 162 u8* src = Memory::GetPhysicalPointer(info.physical_address);
163 return QPixmap::fromImage(LoadTexture(src, info)); 163 return QPixmap::fromImage(LoadTexture(src, info));
164} 164}
165 165
@@ -274,7 +274,7 @@ void GPUCommandListWidget::SetCommandInfo(const QModelIndex& index) {
274 auto format = Pica::registers.GetTextures()[index].format; 274 auto format = Pica::registers.GetTextures()[index].format;
275 275
276 auto info = Pica::DebugUtils::TextureInfo::FromPicaRegister(config, format); 276 auto info = Pica::DebugUtils::TextureInfo::FromPicaRegister(config, format);
277 u8* src = Memory::GetPointer(Pica::PAddrToVAddr(config.GetPhysicalAddress())); 277 u8* src = Memory::GetPhysicalPointer(config.GetPhysicalAddress());
278 new_info_widget = new TextureInfoWidget(src, info); 278 new_info_widget = new TextureInfoWidget(src, info);
279 } else { 279 } else {
280 new_info_widget = new QWidget; 280 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..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()
215 u32 bytes_per_pixel = GraphicsFramebufferWidget::BytesPerPixel(framebuffer_format); 215 u32 bytes_per_pixel = GraphicsFramebufferWidget::BytesPerPixel(framebuffer_format);
216 216
217 QImage decoded_image(framebuffer_width, framebuffer_height, QImage::Format_ARGB32); 217 QImage decoded_image(framebuffer_width, framebuffer_height, QImage::Format_ARGB32);
218 u8* buffer = Memory::GetPointer(Pica::PAddrToVAddr(framebuffer_address)); 218 u8* buffer = Memory::GetPhysicalPointer(framebuffer_address);
219 219
220 for (unsigned int y = 0; y < framebuffer_height; ++y) { 220 for (unsigned int y = 0; y < framebuffer_height; ++y) {
221 for (unsigned int x = 0; x < framebuffer_width; ++x) { 221 for (unsigned int x = 0; x < framebuffer_width; ++x) {
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() {
63 63
64 // TODO: Whenever TLS is implemented, this should contain 64 // TODO: Whenever TLS is implemented, this should contain
65 // the address of the 0x200-byte TLS 65 // the address of the 0x200-byte TLS
66 g_app_core->SetCP15Register(CP15_THREAD_URO, Memory::KERNEL_MEMORY_VADDR); 66 g_app_core->SetCP15Register(CP15_THREAD_URO, Memory::TLS_AREA_VADDR);
67 67
68 LOG_DEBUG(Core, "Initialized OK"); 68 LOG_DEBUG(Core, "Initialized OK");
69 return 0; 69 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
17 * @return Pointer to command buffer 17 * @return Pointer to command buffer
18 */ 18 */
19inline static u32* GetCommandBuffer(const int offset=0) { 19inline static u32* GetCommandBuffer(const int offset=0) {
20 return (u32*)Memory::GetPointer(Memory::KERNEL_MEMORY_VADDR + kCommandHeaderOffset + offset); 20 return (u32*)Memory::GetPointer(Memory::TLS_AREA_VADDR + kCommandHeaderOffset + offset);
21} 21}
22 22
23/** 23/**
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) {
443 443
444SharedPtr<Thread> SetupIdleThread() { 444SharedPtr<Thread> SetupIdleThread() {
445 // We need to pass a few valid values to get around parameter checking in Thread::Create. 445 // We need to pass a few valid values to get around parameter checking in Thread::Create.
446 auto thread = Thread::Create("idle", Memory::KERNEL_MEMORY_VADDR, THREADPRIO_LOWEST, 0, 446 // TODO(yuriks): Figure out a way to avoid passing the bogus VAddr parameter
447 auto thread = Thread::Create("idle", Memory::TLS_AREA_VADDR, THREADPRIO_LOWEST, 0,
447 THREADPROCESSORID_0, 0).MoveFrom(); 448 THREADPROCESSORID_0, 0).MoveFrom();
448 449
449 thread->idle = true; 450 thread->idle = true;
@@ -455,7 +456,7 @@ SharedPtr<Thread> SetupMainThread(u32 stack_size, u32 entry_point, s32 priority)
455 456
456 // Initialize new "main" thread 457 // Initialize new "main" thread
457 auto thread_res = Thread::Create("main", entry_point, priority, 0, 458 auto thread_res = Thread::Create("main", entry_point, priority, 0,
458 THREADPROCESSORID_0, Memory::SCRATCHPAD_VADDR_END); 459 THREADPROCESSORID_0, Memory::HEAP_VADDR_END - stack_size);
459 460
460 SharedPtr<Thread> thread = thread_res.MoveFrom(); 461 SharedPtr<Thread> thread = thread_res.MoveFrom();
461 462
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) {
42 u32 addr = cmd_buff[1]; 42 u32 addr = cmd_buff[1];
43 43
44 cmd_buff[1] = 0; // No error 44 cmd_buff[1] = 0; // No error
45 cmd_buff[2] = (addr << 1) + (Memory::DSP_MEMORY_VADDR + 0x40000); 45 cmd_buff[2] = (addr << 1) + (Memory::DSP_RAM_VADDR + 0x40000);
46 46
47 LOG_WARNING(Service_DSP, "(STUBBED) called with address 0x%08X", addr); 47 LOG_WARNING(Service_DSP, "(STUBBED) called with address 0x%08X", addr);
48} 48}
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) {
76 auto& config = g_regs.memory_fill_config[is_second_filler]; 76 auto& config = g_regs.memory_fill_config[is_second_filler];
77 77
78 if (config.address_start && config.trigger) { 78 if (config.address_start && config.trigger) {
79 u8* start = Memory::GetPointer(Memory::PhysicalToVirtualAddress(config.GetStartAddress())); 79 u8* start = Memory::GetPhysicalPointer(config.GetStartAddress());
80 u8* end = Memory::GetPointer(Memory::PhysicalToVirtualAddress(config.GetEndAddress())); 80 u8* end = Memory::GetPhysicalPointer(config.GetEndAddress());
81 81
82 if (config.fill_24bit) { 82 if (config.fill_24bit) {
83 // fill with 24-bit values 83 // fill with 24-bit values
@@ -114,8 +114,8 @@ inline void Write(u32 addr, const T data) {
114 { 114 {
115 const auto& config = g_regs.display_transfer_config; 115 const auto& config = g_regs.display_transfer_config;
116 if (config.trigger & 1) { 116 if (config.trigger & 1) {
117 u8* src_pointer = Memory::GetPointer(Memory::PhysicalToVirtualAddress(config.GetPhysicalInputAddress())); 117 u8* src_pointer = Memory::GetPhysicalPointer(config.GetPhysicalInputAddress());
118 u8* dst_pointer = Memory::GetPointer(Memory::PhysicalToVirtualAddress(config.GetPhysicalOutputAddress())); 118 u8* dst_pointer = Memory::GetPhysicalPointer(config.GetPhysicalOutputAddress());
119 119
120 if (config.scaling > config.ScaleXY) { 120 if (config.scaling > config.ScaleXY) {
121 LOG_CRITICAL(HW_GPU, "Unimplemented display transfer scaling mode %u", config.scaling.Value()); 121 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) {
257 const auto& config = g_regs.command_processor_config; 257 const auto& config = g_regs.command_processor_config;
258 if (config.trigger & 1) 258 if (config.trigger & 1)
259 { 259 {
260 u32* buffer = (u32*)Memory::GetPointer(Memory::PhysicalToVirtualAddress(config.GetPhysicalAddress())); 260 u32* buffer = (u32*)Memory::GetPhysicalPointer(config.GetPhysicalAddress());
261 Pica::CommandProcessor::ProcessCommandList(buffer, config.size); 261 Pica::CommandProcessor::ProcessCommandList(buffer, config.size);
262 } 262 }
263 break; 263 break;
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() {
234 Kernel::g_current_process->svc_access_mask.set(); 234 Kernel::g_current_process->svc_access_mask.set();
235 Kernel::g_current_process->address_mappings = default_address_mappings; 235 Kernel::g_current_process->address_mappings = default_address_mappings;
236 236
237 Load3DSXFile(*file, Memory::EXEFS_CODE_VADDR); 237 Load3DSXFile(*file, Memory::PROCESS_IMAGE_VADDR);
238 238
239 Kernel::g_current_process->Run(Memory::EXEFS_CODE_VADDR, 48, Kernel::DEFAULT_STACK_SIZE); 239 Kernel::g_current_process->Run(Memory::PROCESS_IMAGE_VADDR, 48, Kernel::DEFAULT_STACK_SIZE);
240 240
241 is_loaded = true; 241 is_loaded = true;
242 return ResultStatus::Success; 242 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() {
355 Kernel::g_current_process->address_mappings = default_address_mappings; 355 Kernel::g_current_process->address_mappings = default_address_mappings;
356 356
357 ElfReader elf_reader(&buffer[0]); 357 ElfReader elf_reader(&buffer[0]);
358 elf_reader.LoadInto(Memory::EXEFS_CODE_VADDR); 358 elf_reader.LoadInto(Memory::PROCESS_IMAGE_VADDR);
359 // TODO: Fill application title 359 // TODO: Fill application title
360 360
361 Kernel::g_current_process->Run(elf_reader.GetEntryPoint(), 48, Kernel::DEFAULT_STACK_SIZE); 361 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..f99520464 100644
--- a/src/core/mem_map.cpp
+++ b/src/core/mem_map.cpp
@@ -12,13 +12,12 @@
12namespace Memory { 12namespace Memory {
13 13
14u8* g_exefs_code; ///< ExeFS:/.code is loaded here 14u8* g_exefs_code; ///< ExeFS:/.code is loaded here
15u8* g_system_mem; ///< System memory
16u8* g_heap; ///< Application heap (main memory) 15u8* g_heap; ///< Application heap (main memory)
16u8* g_shared_mem; ///< Shared memory
17u8* g_heap_linear; ///< Linear heap 17u8* g_heap_linear; ///< Linear heap
18u8* g_vram; ///< Video memory (VRAM) pointer 18u8* g_vram; ///< Video memory (VRAM) pointer
19u8* g_shared_mem; ///< Shared memory
20u8* g_dsp_mem; ///< DSP memory 19u8* g_dsp_mem; ///< DSP memory
21u8* g_kernel_mem; ///< Kernel memory 20u8* g_tls_mem; ///< TLS memory
22 21
23namespace { 22namespace {
24 23
@@ -29,14 +28,13 @@ struct MemoryArea {
29 28
30// We don't declare the IO regions in here since its handled by other means. 29// We don't declare the IO regions in here since its handled by other means.
31static MemoryArea memory_areas[] = { 30static MemoryArea memory_areas[] = {
32 {&g_exefs_code, EXEFS_CODE_SIZE }, 31 {&g_exefs_code, PROCESS_IMAGE_MAX_SIZE},
33 {&g_vram, VRAM_SIZE }, 32 {&g_heap, HEAP_SIZE },
34 {&g_heap, HEAP_SIZE }, 33 {&g_shared_mem, SHARED_MEMORY_SIZE },
35 {&g_shared_mem, SHARED_MEMORY_SIZE}, 34 {&g_heap_linear, LINEAR_HEAP_SIZE },
36 {&g_system_mem, SYSTEM_MEMORY_SIZE}, 35 {&g_vram, VRAM_SIZE },
37 {&g_dsp_mem, DSP_MEMORY_SIZE }, 36 {&g_dsp_mem, DSP_RAM_SIZE },
38 {&g_kernel_mem, KERNEL_MEMORY_SIZE}, 37 {&g_tls_mem, TLS_AREA_SIZE },
39 {&g_heap_linear, HEAP_LINEAR_SIZE },
40}; 38};
41 39
42} 40}
diff --git a/src/core/mem_map.h b/src/core/mem_map.h
index fb582d65a..64de76c39 100644
--- a/src/core/mem_map.h
+++ b/src/core/mem_map.h
@@ -12,79 +12,93 @@ namespace Memory {
12 12
13const u32 PAGE_SIZE = 0x1000; 13const u32 PAGE_SIZE = 0x1000;
14 14
15enum : u32 { 15/// Physical memory regions as seen from the ARM11
16 BOOTROM_SIZE = 0x00010000, ///< Bootrom (super secret code/data @ 0x8000) size 16enum : PAddr {
17 BOOTROM_PADDR = 0x00000000, ///< Bootrom physical address 17 /// IO register area
18 BOOTROM_PADDR_END = (BOOTROM_PADDR + BOOTROM_SIZE), 18 IO_AREA_PADDR = 0x10100000,
19 19 IO_AREA_SIZE = 0x01000000, ///< IO area size (16MB)
20 BOOTROM_MIRROR_SIZE = 0x00010000, ///< Bootrom Mirror size 20 IO_AREA_PADDR_END = IO_AREA_PADDR + IO_AREA_SIZE,
21 BOOTROM_MIRROR_PADDR = 0x00010000, ///< Bootrom Mirror physical address 21
22 BOOTROM_MIRROR_PADDR_END = (BOOTROM_MIRROR_PADDR + BOOTROM_MIRROR_SIZE), 22 /// MPCore internal memory region
23 23 MPCORE_RAM_PADDR = 0x17E00000,
24 MPCORE_PRIV_SIZE = 0x00002000, ///< MPCore private memory region size 24 MPCORE_RAM_SIZE = 0x00002000, ///< MPCore internal memory size (8KB)
25 MPCORE_PRIV_PADDR = 0x17E00000, ///< MPCore private memory region physical address 25 MPCORE_RAM_PADDR_END = MPCORE_RAM_PADDR + MPCORE_RAM_SIZE,
26 MPCORE_PRIV_PADDR_END = (MPCORE_PRIV_PADDR + MPCORE_PRIV_SIZE), 26
27 27 /// Video memory
28 FCRAM_SIZE = 0x08000000, ///< FCRAM size 28 VRAM_PADDR = 0x18000000,
29 FCRAM_PADDR = 0x20000000, ///< FCRAM physical address 29 VRAM_SIZE = 0x00600000, ///< VRAM size (6MB)
30 FCRAM_PADDR_END = (FCRAM_PADDR + FCRAM_SIZE), 30 VRAM_PADDR_END = VRAM_PADDR + VRAM_SIZE,
31 31
32 HEAP_SIZE = FCRAM_SIZE, ///< Application heap size 32 /// DSP memory
33 HEAP_VADDR = 0x08000000, 33 DSP_RAM_PADDR = 0x1FF00000,
34 HEAP_VADDR_END = (HEAP_VADDR + HEAP_SIZE), 34 DSP_RAM_SIZE = 0x00080000, ///< DSP memory size (512KB)
35 35 DSP_RAM_PADDR_END = DSP_RAM_PADDR + DSP_RAM_SIZE,
36 HEAP_LINEAR_SIZE = FCRAM_SIZE, 36
37 HEAP_LINEAR_VADDR = 0x14000000, 37 /// AXI WRAM
38 HEAP_LINEAR_VADDR_END = (HEAP_LINEAR_VADDR + HEAP_LINEAR_SIZE), 38 AXI_WRAM_PADDR = 0x1FF80000,
39 39 AXI_WRAM_SIZE = 0x00080000, ///< AXI WRAM size (512KB)
40 AXI_WRAM_SIZE = 0x00080000, ///< AXI WRAM size 40 AXI_WRAM_PADDR_END = AXI_WRAM_PADDR + AXI_WRAM_SIZE,
41 AXI_WRAM_PADDR = 0x1FF80000, ///< AXI WRAM physical address 41
42 AXI_WRAM_PADDR_END = (AXI_WRAM_PADDR + AXI_WRAM_SIZE), 42 /// Main FCRAM
43 43 FCRAM_PADDR = 0x20000000,
44 SHARED_MEMORY_SIZE = 0x04000000, ///< Shared memory size 44 FCRAM_SIZE = 0x08000000, ///< FCRAM size (128MB)
45 SHARED_MEMORY_VADDR = 0x10000000, ///< Shared memory 45 FCRAM_PADDR_END = FCRAM_PADDR + FCRAM_SIZE,
46 SHARED_MEMORY_VADDR_END = (SHARED_MEMORY_VADDR + SHARED_MEMORY_SIZE), 46};
47 47
48 DSP_MEMORY_SIZE = 0x00080000, ///< DSP memory size 48/// Virtual user-space memory regions
49 DSP_MEMORY_VADDR = 0x1FF00000, ///< DSP memory virtual address 49enum : VAddr {
50 DSP_MEMORY_VADDR_END = (DSP_MEMORY_VADDR + DSP_MEMORY_SIZE), 50 /// Where the application text, data and bss reside.
51 51 PROCESS_IMAGE_VADDR = 0x00100000,
52 CONFIG_MEMORY_SIZE = 0x00001000, ///< Configuration memory size 52 PROCESS_IMAGE_MAX_SIZE = 0x03F00000,
53 CONFIG_MEMORY_VADDR = 0x1FF80000, ///< Configuration memory virtual address 53 PROCESS_IMAGE_VADDR_END = PROCESS_IMAGE_VADDR + PROCESS_IMAGE_MAX_SIZE,
54 CONFIG_MEMORY_VADDR_END = (CONFIG_MEMORY_VADDR + CONFIG_MEMORY_SIZE), 54
55 55 /// Area where IPC buffers are mapped onto.
56 SHARED_PAGE_SIZE = 0x00001000, ///< Shared page size 56 IPC_MAPPING_VADDR = 0x04000000,
57 SHARED_PAGE_VADDR = 0x1FF81000, ///< Shared page virtual address 57 IPC_MAPPING_SIZE = 0x04000000,
58 SHARED_PAGE_VADDR_END = (SHARED_PAGE_VADDR + SHARED_PAGE_SIZE), 58 IPC_MAPPING_VADDR_END = IPC_MAPPING_VADDR + IPC_MAPPING_SIZE,
59 59
60 KERNEL_MEMORY_SIZE = 0x00001000, ///< Kernel memory size 60 /// Application heap (includes stack).
61 KERNEL_MEMORY_VADDR = 0xFFFF0000, ///< Kernel memory where the kthread objects etc are 61 HEAP_VADDR = 0x08000000,
62 KERNEL_MEMORY_VADDR_END = (KERNEL_MEMORY_VADDR + KERNEL_MEMORY_SIZE), 62 HEAP_SIZE = 0x08000000,
63 63 HEAP_VADDR_END = HEAP_VADDR + HEAP_SIZE,
64 EXEFS_CODE_SIZE = 0x03F00000, 64
65 EXEFS_CODE_VADDR = 0x00100000, ///< ExeFS:/.code is loaded here 65 /// Area where shared memory buffers are mapped onto.
66 EXEFS_CODE_VADDR_END = (EXEFS_CODE_VADDR + EXEFS_CODE_SIZE), 66 SHARED_MEMORY_VADDR = 0x10000000,
67 67 SHARED_MEMORY_SIZE = 0x04000000,
68 // Region of FCRAM used by system 68 SHARED_MEMORY_VADDR_END = SHARED_MEMORY_VADDR + SHARED_MEMORY_SIZE,
69 SYSTEM_MEMORY_SIZE = 0x02C00000, ///< 44MB 69
70 SYSTEM_MEMORY_VADDR = 0x04000000, 70 /// Maps 1:1 to an offset in FCRAM. Used for HW allocations that need to be linear in physical memory.
71 SYSTEM_MEMORY_VADDR_END = (SYSTEM_MEMORY_VADDR + SYSTEM_MEMORY_SIZE), 71 LINEAR_HEAP_VADDR = 0x14000000,
72 72 LINEAR_HEAP_SIZE = 0x08000000,
73 HARDWARE_IO_SIZE = 0x01000000, 73 LINEAR_HEAP_VADDR_END = LINEAR_HEAP_VADDR + LINEAR_HEAP_SIZE,
74 HARDWARE_IO_PADDR = 0x10000000, ///< IO physical address start 74
75 HARDWARE_IO_VADDR = 0x1EC00000, ///< IO virtual address start 75 /// Maps 1:1 to the IO register area.
76 HARDWARE_IO_PADDR_END = (HARDWARE_IO_PADDR + HARDWARE_IO_SIZE), 76 IO_AREA_VADDR = 0x1EC00000,
77 HARDWARE_IO_VADDR_END = (HARDWARE_IO_VADDR + HARDWARE_IO_SIZE), 77 IO_AREA_VADDR_END = IO_AREA_VADDR + IO_AREA_SIZE,
78 78
79 VRAM_SIZE = 0x00600000, 79 /// Maps 1:1 to VRAM.
80 VRAM_PADDR = 0x18000000, 80 VRAM_VADDR = 0x1F000000,
81 VRAM_VADDR = 0x1F000000, 81 VRAM_VADDR_END = VRAM_VADDR + VRAM_SIZE,
82 VRAM_PADDR_END = (VRAM_PADDR + VRAM_SIZE), 82
83 VRAM_VADDR_END = (VRAM_VADDR + VRAM_SIZE), 83 /// Maps 1:1 to DSP memory.
84 84 DSP_RAM_VADDR = 0x1FF00000,
85 SCRATCHPAD_SIZE = 0x00004000, ///< Typical stack size - TODO: Read from exheader 85 DSP_RAM_VADDR_END = DSP_RAM_VADDR + DSP_RAM_SIZE,
86 SCRATCHPAD_VADDR_END = 0x10000000, 86
87 SCRATCHPAD_VADDR = (SCRATCHPAD_VADDR_END - SCRATCHPAD_SIZE), ///< Stack space 87 /// Read-only page containing kernel and system configuration values.
88 CONFIG_MEMORY_VADDR = 0x1FF80000,
89 CONFIG_MEMORY_SIZE = 0x00001000,
90 CONFIG_MEMORY_VADDR_END = CONFIG_MEMORY_VADDR + CONFIG_MEMORY_SIZE,
91
92 /// Usually read-only page containing mostly values read from hardware.
93 SHARED_PAGE_VADDR = 0x1FF81000,
94 SHARED_PAGE_SIZE = 0x00001000,
95 SHARED_PAGE_VADDR_END = SHARED_PAGE_VADDR + SHARED_PAGE_SIZE,
96
97 // TODO(yuriks): The exact location and size of this area is uncomfirmed.
98 /// Area where TLS (Thread-Local Storage) buffers are allocated.
99 TLS_AREA_VADDR = 0x1FFA0000,
100 TLS_AREA_SIZE = 0x00002000, // Each TLS buffer is 0x200 bytes, allows for 16 threads
101 TLS_AREA_VADDR_END = TLS_AREA_VADDR + TLS_AREA_SIZE,
88}; 102};
89 103
90//////////////////////////////////////////////////////////////////////////////////////////////////// 104////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -107,14 +121,13 @@ struct MemoryBlock {
107 121
108//////////////////////////////////////////////////////////////////////////////////////////////////// 122////////////////////////////////////////////////////////////////////////////////////////////////////
109 123
110extern u8* g_heap_linear; ///< Linear heap (main memory) 124extern u8* g_exefs_code; ///< ExeFS:/.code is loaded here
111extern u8* g_heap; ///< Application heap (main memory) 125extern u8* g_heap; ///< Application heap (main memory)
112extern u8* g_vram; ///< Video memory (VRAM) 126extern u8* g_shared_mem; ///< Shared memory
113extern u8* g_shared_mem; ///< Shared memory 127extern u8* g_heap_linear; ///< Linear heap (main memory)
114extern u8* g_kernel_mem; ///< Kernel memory 128extern u8* g_vram; ///< Video memory (VRAM)
115extern u8* g_dsp_mem; ///< DSP memory 129extern u8* g_dsp_mem; ///< DSP memory
116extern u8* g_system_mem; ///< System memory 130extern u8* g_tls_mem; ///< TLS memory
117extern u8* g_exefs_code; ///< ExeFS:/.code is loaded here
118 131
119void Init(); 132void Init();
120void Shutdown(); 133void Shutdown();
@@ -168,10 +181,24 @@ inline const char* GetCharPointer(const VAddr address) {
168 return (const char *)GetPointer(address); 181 return (const char *)GetPointer(address);
169} 182}
170 183
171/// Converts a physical address to virtual address 184/**
185 * Converts a virtual address inside a region with 1:1 mapping to physical memory to a physical
186 * address. This should be used by services to translate addresses for use by the hardware.
187 */
188PAddr VirtualToPhysicalAddress(VAddr addr);
189
190/**
191 * Undoes a mapping performed by VirtualToPhysicalAddress().
192 */
172VAddr PhysicalToVirtualAddress(PAddr addr); 193VAddr PhysicalToVirtualAddress(PAddr addr);
173 194
174/// Converts a virtual address to physical address 195/**
175PAddr VirtualToPhysicalAddress(VAddr addr); 196 * Gets a pointer to the memory region beginning at the specified physical address.
197 *
198 * @note This is currently implemented using PhysicalToVirtualAddress().
199 */
200inline u8* GetPhysicalPointer(PAddr address) {
201 return GetPointer(PhysicalToVirtualAddress(address));
202}
176 203
177} // namespace 204} // namespace
diff --git a/src/core/mem_map_funcs.cpp b/src/core/mem_map_funcs.cpp
index 9a19c9bf8..a8e0fed07 100644
--- a/src/core/mem_map_funcs.cpp
+++ b/src/core/mem_map_funcs.cpp
@@ -18,40 +18,40 @@ namespace Memory {
18static std::map<u32, MemoryBlock> heap_map; 18static std::map<u32, MemoryBlock> heap_map;
19static std::map<u32, MemoryBlock> heap_linear_map; 19static std::map<u32, MemoryBlock> heap_linear_map;
20 20
21/// Convert a physical address to virtual address 21PAddr VirtualToPhysicalAddress(const VAddr addr) {
22VAddr PhysicalToVirtualAddress(const PAddr addr) {
23 // Our memory interface read/write functions assume virtual addresses. Put any physical address
24 // to virtual address translations here. This is quite hacky, but necessary until we implement
25 // proper MMU emulation.
26 // TODO: Screw it, I'll let bunnei figure out how to do this properly.
27 if (addr == 0) { 22 if (addr == 0) {
28 return 0; 23 return 0;
29 } else if ((addr >= VRAM_PADDR) && (addr < VRAM_PADDR_END)) { 24 } else if (addr >= VRAM_VADDR && addr < VRAM_VADDR_END) {
30 return addr - VRAM_PADDR + VRAM_VADDR; 25 return addr - VRAM_VADDR + VRAM_PADDR;
31 } else if ((addr >= FCRAM_PADDR) && (addr < FCRAM_PADDR_END)) { 26 } else if (addr >= LINEAR_HEAP_VADDR && addr < LINEAR_HEAP_VADDR_END) {
32 return addr - FCRAM_PADDR + HEAP_LINEAR_VADDR; 27 return addr - LINEAR_HEAP_VADDR + FCRAM_PADDR;
28 } else if (addr >= DSP_RAM_VADDR && addr < DSP_RAM_VADDR_END) {
29 return addr - DSP_RAM_VADDR + DSP_RAM_PADDR;
30 } else if (addr >= IO_AREA_VADDR && addr < IO_AREA_VADDR_END) {
31 return addr - IO_AREA_VADDR + IO_AREA_PADDR;
33 } 32 }
34 33
35 LOG_ERROR(HW_Memory, "Unknown physical address @ 0x%08x", addr); 34 LOG_ERROR(HW_Memory, "Unknown virtual address @ 0x%08x", addr);
36 return addr; 35 // To help with debugging, set bit on address so that it's obviously invalid.
36 return addr | 0x80000000;
37} 37}
38 38
39/// Convert a physical address to virtual address 39VAddr PhysicalToVirtualAddress(const PAddr addr) {
40PAddr VirtualToPhysicalAddress(const VAddr addr) {
41 // Our memory interface read/write functions assume virtual addresses. Put any physical address
42 // to virtual address translations here. This is quite hacky, but necessary until we implement
43 // proper MMU emulation.
44 // TODO: Screw it, I'll let bunnei figure out how to do this properly.
45 if (addr == 0) { 40 if (addr == 0) {
46 return 0; 41 return 0;
47 } else if ((addr >= VRAM_VADDR) && (addr < VRAM_VADDR_END)) { 42 } else if (addr >= VRAM_PADDR && addr < VRAM_PADDR_END) {
48 return addr - VRAM_VADDR + VRAM_PADDR; 43 return addr - VRAM_PADDR + VRAM_VADDR;
49 } else if ((addr >= HEAP_LINEAR_VADDR) && (addr < HEAP_LINEAR_VADDR_END)) { 44 } else if (addr >= FCRAM_PADDR && addr < FCRAM_PADDR_END) {
50 return addr - HEAP_LINEAR_VADDR + FCRAM_PADDR; 45 return addr - FCRAM_PADDR + LINEAR_HEAP_VADDR;
46 } else if (addr >= DSP_RAM_PADDR && addr < DSP_RAM_PADDR_END) {
47 return addr - DSP_RAM_PADDR + DSP_RAM_VADDR;
48 } else if (addr >= IO_AREA_PADDR && addr < IO_AREA_PADDR_END) {
49 return addr - IO_AREA_PADDR + IO_AREA_VADDR;
51 } 50 }
52 51
53 LOG_ERROR(HW_Memory, "Unknown virtual address @ 0x%08x", addr); 52 LOG_ERROR(HW_Memory, "Unknown physical address @ 0x%08x", addr);
54 return addr; 53 // To help with debugging, set bit on address so that it's obviously invalid.
54 return addr | 0x80000000;
55} 55}
56 56
57template <typename T> 57template <typename T>
@@ -61,16 +61,16 @@ inline void Read(T &var, const VAddr vaddr) {
61 // Could just do a base-relative read, too.... TODO 61 // Could just do a base-relative read, too.... TODO
62 62
63 // Kernel memory command buffer 63 // Kernel memory command buffer
64 if (vaddr >= KERNEL_MEMORY_VADDR && vaddr < KERNEL_MEMORY_VADDR_END) { 64 if (vaddr >= TLS_AREA_VADDR && vaddr < TLS_AREA_VADDR_END) {
65 var = *((const T*)&g_kernel_mem[vaddr - KERNEL_MEMORY_VADDR]); 65 var = *((const T*)&g_tls_mem[vaddr - TLS_AREA_VADDR]);
66 66
67 // ExeFS:/.code is loaded here 67 // ExeFS:/.code is loaded here
68 } else if ((vaddr >= EXEFS_CODE_VADDR) && (vaddr < EXEFS_CODE_VADDR_END)) { 68 } else if ((vaddr >= PROCESS_IMAGE_VADDR) && (vaddr < PROCESS_IMAGE_VADDR_END)) {
69 var = *((const T*)&g_exefs_code[vaddr - EXEFS_CODE_VADDR]); 69 var = *((const T*)&g_exefs_code[vaddr - PROCESS_IMAGE_VADDR]);
70 70
71 // FCRAM - linear heap 71 // FCRAM - linear heap
72 } else if ((vaddr >= HEAP_LINEAR_VADDR) && (vaddr < HEAP_LINEAR_VADDR_END)) { 72 } else if ((vaddr >= LINEAR_HEAP_VADDR) && (vaddr < LINEAR_HEAP_VADDR_END)) {
73 var = *((const T*)&g_heap_linear[vaddr - HEAP_LINEAR_VADDR]); 73 var = *((const T*)&g_heap_linear[vaddr - LINEAR_HEAP_VADDR]);
74 74
75 // FCRAM - application heap 75 // FCRAM - application heap
76 } else if ((vaddr >= HEAP_VADDR) && (vaddr < HEAP_VADDR_END)) { 76 } else if ((vaddr >= HEAP_VADDR) && (vaddr < HEAP_VADDR_END)) {
@@ -80,10 +80,6 @@ inline void Read(T &var, const VAddr vaddr) {
80 } else if ((vaddr >= SHARED_MEMORY_VADDR) && (vaddr < SHARED_MEMORY_VADDR_END)) { 80 } else if ((vaddr >= SHARED_MEMORY_VADDR) && (vaddr < SHARED_MEMORY_VADDR_END)) {
81 var = *((const T*)&g_shared_mem[vaddr - SHARED_MEMORY_VADDR]); 81 var = *((const T*)&g_shared_mem[vaddr - SHARED_MEMORY_VADDR]);
82 82
83 // System memory
84 } else if ((vaddr >= SYSTEM_MEMORY_VADDR) && (vaddr < SYSTEM_MEMORY_VADDR_END)) {
85 var = *((const T*)&g_system_mem[vaddr - SYSTEM_MEMORY_VADDR]);
86
87 // Config memory 83 // Config memory
88 } else if ((vaddr >= CONFIG_MEMORY_VADDR) && (vaddr < CONFIG_MEMORY_VADDR_END)) { 84 } else if ((vaddr >= CONFIG_MEMORY_VADDR) && (vaddr < CONFIG_MEMORY_VADDR_END)) {
89 ConfigMem::Read<T>(var, vaddr); 85 ConfigMem::Read<T>(var, vaddr);
@@ -93,8 +89,8 @@ inline void Read(T &var, const VAddr vaddr) {
93 SharedPage::Read<T>(var, vaddr); 89 SharedPage::Read<T>(var, vaddr);
94 90
95 // DSP memory 91 // DSP memory
96 } else if ((vaddr >= DSP_MEMORY_VADDR) && (vaddr < DSP_MEMORY_VADDR_END)) { 92 } else if ((vaddr >= DSP_RAM_VADDR) && (vaddr < DSP_RAM_VADDR_END)) {
97 var = *((const T*)&g_dsp_mem[vaddr - DSP_MEMORY_VADDR]); 93 var = *((const T*)&g_dsp_mem[vaddr - DSP_RAM_VADDR]);
98 94
99 // VRAM 95 // VRAM
100 } else if ((vaddr >= VRAM_VADDR) && (vaddr < VRAM_VADDR_END)) { 96 } else if ((vaddr >= VRAM_VADDR) && (vaddr < VRAM_VADDR_END)) {
@@ -109,16 +105,16 @@ template <typename T>
109inline void Write(const VAddr vaddr, const T data) { 105inline void Write(const VAddr vaddr, const T data) {
110 106
111 // Kernel memory command buffer 107 // Kernel memory command buffer
112 if (vaddr >= KERNEL_MEMORY_VADDR && vaddr < KERNEL_MEMORY_VADDR_END) { 108 if (vaddr >= TLS_AREA_VADDR && vaddr < TLS_AREA_VADDR_END) {
113 *(T*)&g_kernel_mem[vaddr - KERNEL_MEMORY_VADDR] = data; 109 *(T*)&g_tls_mem[vaddr - TLS_AREA_VADDR] = data;
114 110
115 // ExeFS:/.code is loaded here 111 // ExeFS:/.code is loaded here
116 } else if ((vaddr >= EXEFS_CODE_VADDR) && (vaddr < EXEFS_CODE_VADDR_END)) { 112 } else if ((vaddr >= PROCESS_IMAGE_VADDR) && (vaddr < PROCESS_IMAGE_VADDR_END)) {
117 *(T*)&g_exefs_code[vaddr - EXEFS_CODE_VADDR] = data; 113 *(T*)&g_exefs_code[vaddr - PROCESS_IMAGE_VADDR] = data;
118 114
119 // FCRAM - linear heap 115 // FCRAM - linear heap
120 } else if ((vaddr >= HEAP_LINEAR_VADDR) && (vaddr < HEAP_LINEAR_VADDR_END)) { 116 } else if ((vaddr >= LINEAR_HEAP_VADDR) && (vaddr < LINEAR_HEAP_VADDR_END)) {
121 *(T*)&g_heap_linear[vaddr - HEAP_LINEAR_VADDR] = data; 117 *(T*)&g_heap_linear[vaddr - LINEAR_HEAP_VADDR] = data;
122 118
123 // FCRAM - application heap 119 // FCRAM - application heap
124 } else if ((vaddr >= HEAP_VADDR) && (vaddr < HEAP_VADDR_END)) { 120 } else if ((vaddr >= HEAP_VADDR) && (vaddr < HEAP_VADDR_END)) {
@@ -128,17 +124,13 @@ inline void Write(const VAddr vaddr, const T data) {
128 } else if ((vaddr >= SHARED_MEMORY_VADDR) && (vaddr < SHARED_MEMORY_VADDR_END)) { 124 } else if ((vaddr >= SHARED_MEMORY_VADDR) && (vaddr < SHARED_MEMORY_VADDR_END)) {
129 *(T*)&g_shared_mem[vaddr - SHARED_MEMORY_VADDR] = data; 125 *(T*)&g_shared_mem[vaddr - SHARED_MEMORY_VADDR] = data;
130 126
131 // System memory
132 } else if ((vaddr >= SYSTEM_MEMORY_VADDR) && (vaddr < SYSTEM_MEMORY_VADDR_END)) {
133 *(T*)&g_system_mem[vaddr - SYSTEM_MEMORY_VADDR] = data;
134
135 // VRAM 127 // VRAM
136 } else if ((vaddr >= VRAM_VADDR) && (vaddr < VRAM_VADDR_END)) { 128 } else if ((vaddr >= VRAM_VADDR) && (vaddr < VRAM_VADDR_END)) {
137 *(T*)&g_vram[vaddr - VRAM_VADDR] = data; 129 *(T*)&g_vram[vaddr - VRAM_VADDR] = data;
138 130
139 // DSP memory 131 // DSP memory
140 } else if ((vaddr >= DSP_MEMORY_VADDR) && (vaddr < DSP_MEMORY_VADDR_END)) { 132 } else if ((vaddr >= DSP_RAM_VADDR) && (vaddr < DSP_RAM_VADDR_END)) {
141 *(T*)&g_dsp_mem[vaddr - DSP_MEMORY_VADDR] = data; 133 *(T*)&g_dsp_mem[vaddr - DSP_RAM_VADDR] = data;
142 134
143 //} else if ((vaddr & 0xFFFF0000) == 0x1FF80000) { 135 //} else if ((vaddr & 0xFFFF0000) == 0x1FF80000) {
144 // ASSERT_MSG(MEMMAP, false, "umimplemented write to Configuration Memory"); 136 // ASSERT_MSG(MEMMAP, false, "umimplemented write to Configuration Memory");
@@ -153,16 +145,16 @@ inline void Write(const VAddr vaddr, const T data) {
153 145
154u8 *GetPointer(const VAddr vaddr) { 146u8 *GetPointer(const VAddr vaddr) {
155 // Kernel memory command buffer 147 // Kernel memory command buffer
156 if (vaddr >= KERNEL_MEMORY_VADDR && vaddr < KERNEL_MEMORY_VADDR_END) { 148 if (vaddr >= TLS_AREA_VADDR && vaddr < TLS_AREA_VADDR_END) {
157 return g_kernel_mem + (vaddr - KERNEL_MEMORY_VADDR); 149 return g_tls_mem + (vaddr - TLS_AREA_VADDR);
158 150
159 // ExeFS:/.code is loaded here 151 // ExeFS:/.code is loaded here
160 } else if ((vaddr >= EXEFS_CODE_VADDR) && (vaddr < EXEFS_CODE_VADDR_END)) { 152 } else if ((vaddr >= PROCESS_IMAGE_VADDR) && (vaddr < PROCESS_IMAGE_VADDR_END)) {
161 return g_exefs_code + (vaddr - EXEFS_CODE_VADDR); 153 return g_exefs_code + (vaddr - PROCESS_IMAGE_VADDR);
162 154
163 // FCRAM - linear heap 155 // FCRAM - linear heap
164 } else if ((vaddr >= HEAP_LINEAR_VADDR) && (vaddr < HEAP_LINEAR_VADDR_END)) { 156 } else if ((vaddr >= LINEAR_HEAP_VADDR) && (vaddr < LINEAR_HEAP_VADDR_END)) {
165 return g_heap_linear + (vaddr - HEAP_LINEAR_VADDR); 157 return g_heap_linear + (vaddr - LINEAR_HEAP_VADDR);
166 158
167 // FCRAM - application heap 159 // FCRAM - application heap
168 } else if ((vaddr >= HEAP_VADDR) && (vaddr < HEAP_VADDR_END)) { 160 } else if ((vaddr >= HEAP_VADDR) && (vaddr < HEAP_VADDR_END)) {
@@ -172,10 +164,6 @@ u8 *GetPointer(const VAddr vaddr) {
172 } else if ((vaddr >= SHARED_MEMORY_VADDR) && (vaddr < SHARED_MEMORY_VADDR_END)) { 164 } else if ((vaddr >= SHARED_MEMORY_VADDR) && (vaddr < SHARED_MEMORY_VADDR_END)) {
173 return g_shared_mem + (vaddr - SHARED_MEMORY_VADDR); 165 return g_shared_mem + (vaddr - SHARED_MEMORY_VADDR);
174 166
175 // System memory
176 } else if ((vaddr >= SYSTEM_MEMORY_VADDR) && (vaddr < SYSTEM_MEMORY_VADDR_END)) {
177 return g_system_mem + (vaddr - SYSTEM_MEMORY_VADDR);
178
179 // VRAM 167 // VRAM
180 } else if ((vaddr >= VRAM_VADDR) && (vaddr < VRAM_VADDR_END)) { 168 } else if ((vaddr >= VRAM_VADDR) && (vaddr < VRAM_VADDR_END)) {
181 return g_vram + (vaddr - VRAM_VADDR); 169 return g_vram + (vaddr - VRAM_VADDR);
@@ -206,7 +194,7 @@ u32 MapBlock_Heap(u32 size, u32 operation, u32 permissions) {
206u32 MapBlock_HeapLinear(u32 size, u32 operation, u32 permissions) { 194u32 MapBlock_HeapLinear(u32 size, u32 operation, u32 permissions) {
207 MemoryBlock block; 195 MemoryBlock block;
208 196
209 block.base_address = HEAP_LINEAR_VADDR; 197 block.base_address = LINEAR_HEAP_VADDR;
210 block.size = size; 198 block.size = size;
211 block.operation = operation; 199 block.operation = operation;
212 block.permissions = permissions; 200 block.permissions = permissions;
diff --git a/src/video_core/command_processor.cpp b/src/video_core/command_processor.cpp
index c4cdf672b..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) {
102 bool is_indexed = (id == PICA_REG_INDEX(trigger_draw_indexed)); 102 bool is_indexed = (id == PICA_REG_INDEX(trigger_draw_indexed));
103 103
104 const auto& index_info = registers.index_array; 104 const auto& index_info = registers.index_array;
105 const u8* index_address_8 = Memory::GetPointer(PAddrToVAddr(base_address + index_info.offset)); 105 const u8* index_address_8 = Memory::GetPhysicalPointer(base_address + index_info.offset);
106 const u16* index_address_16 = (u16*)index_address_8; 106 const u16* index_address_16 = (u16*)index_address_8;
107 bool index_u16 = index_info.format != 0; 107 bool index_u16 = index_info.format != 0;
108 108
@@ -135,7 +135,7 @@ static inline void WritePicaReg(u32 id, u32 value, u32 mask) {
135 input.attr[i][2].ToFloat32(), input.attr[i][3].ToFloat32()); 135 input.attr[i][2].ToFloat32(), input.attr[i][3].ToFloat32());
136 } else { 136 } else {
137 for (unsigned int comp = 0; comp < vertex_attribute_elements[i]; ++comp) { 137 for (unsigned int comp = 0; comp < vertex_attribute_elements[i]; ++comp) {
138 const u8* srcdata = Memory::GetPointer(PAddrToVAddr(vertex_attribute_sources[i] + vertex_attribute_strides[i] * vertex + comp * vertex_attribute_element_size[i])); 138 const u8* srcdata = Memory::GetPhysicalPointer(vertex_attribute_sources[i] + vertex_attribute_strides[i] * vertex + comp * vertex_attribute_element_size[i]);
139 139
140 const float srcval = (vertex_attribute_formats[i] == Regs::VertexAttributeFormat::BYTE) ? *(s8*)srcdata : 140 const float srcval = (vertex_attribute_formats[i] == Regs::VertexAttributeFormat::BYTE) ? *(s8*)srcdata :
141 (vertex_attribute_formats[i] == Regs::VertexAttributeFormat::UBYTE) ? *(u8*)srcdata : 141 (vertex_attribute_formats[i] == Regs::VertexAttributeFormat::UBYTE) ? *(u8*)srcdata :
diff --git a/src/video_core/pica.h b/src/video_core/pica.h
index a0ba715f3..e4a91058c 100644
--- a/src/video_core/pica.h
+++ b/src/video_core/pica.h
@@ -998,15 +998,4 @@ union CommandHeader {
998 BitField<31, 1, u32> group_commands; 998 BitField<31, 1, u32> group_commands;
999}; 999};
1000 1000
1001// TODO: Ugly, should fix PhysicalToVirtualAddress instead
1002inline static u32 PAddrToVAddr(u32 addr) {
1003 if (addr >= Memory::VRAM_PADDR && addr < Memory::VRAM_PADDR + Memory::VRAM_SIZE) {
1004 return addr - Memory::VRAM_PADDR + Memory::VRAM_VADDR;
1005 } else if (addr >= Memory::FCRAM_PADDR && addr < Memory::FCRAM_PADDR + Memory::FCRAM_SIZE) {
1006 return addr - Memory::FCRAM_PADDR + Memory::HEAP_LINEAR_VADDR;
1007 } else {
1008 return 0;
1009 }
1010}
1011
1012} // namespace 1001} // namespace
diff --git a/src/video_core/rasterizer.cpp b/src/video_core/rasterizer.cpp
index 6ec253601..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<u8>& color) {
30 const u32 coarse_y = y & ~7; 30 const u32 coarse_y = y & ~7;
31 u32 bytes_per_pixel = GPU::Regs::BytesPerPixel(GPU::Regs::PixelFormat(registers.framebuffer.color_format.Value())); 31 u32 bytes_per_pixel = GPU::Regs::BytesPerPixel(GPU::Regs::PixelFormat(registers.framebuffer.color_format.Value()));
32 u32 dst_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * registers.framebuffer.width * bytes_per_pixel; 32 u32 dst_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * registers.framebuffer.width * bytes_per_pixel;
33 u8* dst_pixel = Memory::GetPointer(PAddrToVAddr(addr)) + dst_offset; 33 u8* dst_pixel = Memory::GetPhysicalPointer(addr) + dst_offset;
34 34
35 switch (registers.framebuffer.color_format) { 35 switch (registers.framebuffer.color_format) {
36 case registers.framebuffer.RGBA8: 36 case registers.framebuffer.RGBA8:
@@ -67,7 +67,7 @@ static const Math::Vec4<u8> GetPixel(int x, int y) {
67 const u32 coarse_y = y & ~7; 67 const u32 coarse_y = y & ~7;
68 u32 bytes_per_pixel = GPU::Regs::BytesPerPixel(GPU::Regs::PixelFormat(registers.framebuffer.color_format.Value())); 68 u32 bytes_per_pixel = GPU::Regs::BytesPerPixel(GPU::Regs::PixelFormat(registers.framebuffer.color_format.Value()));
69 u32 src_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * registers.framebuffer.width * bytes_per_pixel; 69 u32 src_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * registers.framebuffer.width * bytes_per_pixel;
70 u8* src_pixel = Memory::GetPointer(PAddrToVAddr(addr)) + src_offset; 70 u8* src_pixel = Memory::GetPhysicalPointer(addr) + src_offset;
71 71
72 switch (registers.framebuffer.color_format) { 72 switch (registers.framebuffer.color_format) {
73 case registers.framebuffer.RGBA8: 73 case registers.framebuffer.RGBA8:
@@ -95,7 +95,7 @@ static const Math::Vec4<u8> GetPixel(int x, int y) {
95 95
96static u32 GetDepth(int x, int y) { 96static u32 GetDepth(int x, int y) {
97 const PAddr addr = registers.framebuffer.GetDepthBufferPhysicalAddress(); 97 const PAddr addr = registers.framebuffer.GetDepthBufferPhysicalAddress();
98 u8* depth_buffer = Memory::GetPointer(PAddrToVAddr(addr)); 98 u8* depth_buffer = Memory::GetPhysicalPointer(addr);
99 99
100 y = (registers.framebuffer.height - y); 100 y = (registers.framebuffer.height - y);
101 101
@@ -122,7 +122,7 @@ static u32 GetDepth(int x, int y) {
122 122
123static void SetDepth(int x, int y, u32 value) { 123static void SetDepth(int x, int y, u32 value) {
124 const PAddr addr = registers.framebuffer.GetDepthBufferPhysicalAddress(); 124 const PAddr addr = registers.framebuffer.GetDepthBufferPhysicalAddress();
125 u8* depth_buffer = Memory::GetPointer(PAddrToVAddr(addr)); 125 u8* depth_buffer = Memory::GetPhysicalPointer(addr);
126 126
127 y = (registers.framebuffer.height - y); 127 y = (registers.framebuffer.height - y);
128 128
@@ -361,7 +361,7 @@ static void ProcessTriangleInternal(const VertexShader::OutputVertex& v0,
361 s = GetWrappedTexCoord(texture.config.wrap_s, s, texture.config.width); 361 s = GetWrappedTexCoord(texture.config.wrap_s, s, texture.config.width);
362 t = texture.config.height - 1 - GetWrappedTexCoord(texture.config.wrap_t, t, texture.config.height); 362 t = texture.config.height - 1 - GetWrappedTexCoord(texture.config.wrap_t, t, texture.config.height);
363 363
364 u8* texture_data = Memory::GetPointer(PAddrToVAddr(texture.config.GetPhysicalAddress())); 364 u8* texture_data = Memory::GetPhysicalPointer(texture.config.GetPhysicalAddress());
365 auto info = DebugUtils::TextureInfo::FromPicaRegister(texture.config, texture.format); 365 auto info = DebugUtils::TextureInfo::FromPicaRegister(texture.config, texture.format);
366 366
367 texture_color[i] = DebugUtils::LookupTexture(texture_data, s, t, info); 367 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() {
119void RendererOpenGL::LoadFBToActiveGLTexture(const GPU::Regs::FramebufferConfig& framebuffer, 119void RendererOpenGL::LoadFBToActiveGLTexture(const GPU::Regs::FramebufferConfig& framebuffer,
120 const TextureInfo& texture) { 120 const TextureInfo& texture) {
121 121
122 const VAddr framebuffer_vaddr = Memory::PhysicalToVirtualAddress( 122 const PAddr framebuffer_addr = framebuffer.active_fb == 0 ?
123 framebuffer.active_fb == 0 ? framebuffer.address_left1 : framebuffer.address_left2); 123 framebuffer.address_left1 : framebuffer.address_left2;
124 124
125 LOG_TRACE(Render_OpenGL, "0x%08x bytes from 0x%08x(%dx%d), fmt %x", 125 LOG_TRACE(Render_OpenGL, "0x%08x bytes from 0x%08x(%dx%d), fmt %x",
126 framebuffer.stride * framebuffer.height, 126 framebuffer.stride * framebuffer.height,
127 framebuffer_vaddr, (int)framebuffer.width, 127 framebuffer_addr, (int)framebuffer.width,
128 (int)framebuffer.height, (int)framebuffer.format); 128 (int)framebuffer.height, (int)framebuffer.format);
129 129
130 const u8* framebuffer_data = Memory::GetPointer(framebuffer_vaddr); 130 const u8* framebuffer_data = Memory::GetPhysicalPointer(framebuffer_addr);
131 131
132 int bpp = GPU::Regs::BytesPerPixel(framebuffer.color_format); 132 int bpp = GPU::Regs::BytesPerPixel(framebuffer.color_format);
133 size_t pixel_stride = framebuffer.stride / bpp; 133 size_t pixel_stride = framebuffer.stride / bpp;