mirror of
https://github.com/PabloMK7/citra.git
synced 2024-11-25 17:04:04 +00:00
Memory: ReadBlock/WriteBlock
This commit is contained in:
parent
c084fc824c
commit
3873b36db3
3 changed files with 81 additions and 4 deletions
|
@ -364,6 +364,45 @@ u64 Read64(const VAddr addr) {
|
||||||
return Read<u64_le>(addr);
|
return Read<u64_le>(addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ReadBlock(const VAddr src_addr, u8* dest_buffer, const size_t size) {
|
||||||
|
size_t remaining_size = size;
|
||||||
|
size_t page_index = src_addr >> PAGE_BITS;
|
||||||
|
size_t page_offset = src_addr & PAGE_MASK;
|
||||||
|
|
||||||
|
while (remaining_size > 0) {
|
||||||
|
const size_t copy_amount = std::min(PAGE_SIZE - page_offset, remaining_size);
|
||||||
|
const VAddr current_vaddr = (page_index << PAGE_BITS) + page_offset;
|
||||||
|
|
||||||
|
switch (current_page_table->attributes[page_index]) {
|
||||||
|
case PageType::Unmapped: {
|
||||||
|
LOG_ERROR(HW_Memory, "unmapped ReadBlock @ 0x%08X (start address = 0x%08X, size = %zu)", current_vaddr, src_addr, size);
|
||||||
|
std::memset(dest_buffer, 0, copy_amount);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case PageType::Memory: {
|
||||||
|
DEBUG_ASSERT(current_page_table->pointers[page_index]);
|
||||||
|
|
||||||
|
const u8* src_ptr = current_page_table->pointers[page_index] + page_offset;
|
||||||
|
std::memcpy(dest_buffer, src_ptr, copy_amount);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case PageType::Special: {
|
||||||
|
DEBUG_ASSERT(GetMMIOHandler(current_vaddr));
|
||||||
|
|
||||||
|
GetMMIOHandler(current_vaddr)->ReadBlock(current_vaddr, dest_buffer, copy_amount);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
UNREACHABLE();
|
||||||
|
}
|
||||||
|
|
||||||
|
page_index++;
|
||||||
|
page_offset = 0;
|
||||||
|
dest_buffer += copy_amount;
|
||||||
|
remaining_size -= copy_amount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Write8(const VAddr addr, const u8 data) {
|
void Write8(const VAddr addr, const u8 data) {
|
||||||
Write<u8>(addr, data);
|
Write<u8>(addr, data);
|
||||||
}
|
}
|
||||||
|
@ -380,9 +419,41 @@ void Write64(const VAddr addr, const u64 data) {
|
||||||
Write<u64_le>(addr, data);
|
Write<u64_le>(addr, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WriteBlock(const VAddr addr, const u8* data, const size_t size) {
|
void WriteBlock(const VAddr dest_addr, const u8* src_buffer, const size_t size) {
|
||||||
for (u32 offset = 0; offset < size; offset++) {
|
size_t remaining_size = size;
|
||||||
Write8(addr + offset, data[offset]);
|
size_t page_index = dest_addr >> PAGE_BITS;
|
||||||
|
size_t page_offset = dest_addr & PAGE_MASK;
|
||||||
|
|
||||||
|
while (remaining_size > 0) {
|
||||||
|
const size_t copy_amount = std::min(PAGE_SIZE - page_offset, remaining_size);
|
||||||
|
const VAddr current_vaddr = (page_index << PAGE_BITS) + page_offset;
|
||||||
|
|
||||||
|
switch (current_page_table->attributes[page_index]) {
|
||||||
|
case PageType::Unmapped: {
|
||||||
|
LOG_ERROR(HW_Memory, "unmapped WriteBlock @ 0x%08X (start address = 0x%08X, size = %zu)", current_vaddr, dest_addr, size);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case PageType::Memory: {
|
||||||
|
DEBUG_ASSERT(current_page_table->pointers[page_index]);
|
||||||
|
|
||||||
|
u8* dest_ptr = current_page_table->pointers[page_index] + page_offset;
|
||||||
|
std::memcpy(dest_ptr, src_buffer, copy_amount);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case PageType::Special: {
|
||||||
|
DEBUG_ASSERT(GetMMIOHandler(current_vaddr));
|
||||||
|
|
||||||
|
GetMMIOHandler(current_vaddr)->WriteBlock(current_vaddr, src_buffer, copy_amount);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
UNREACHABLE();
|
||||||
|
}
|
||||||
|
|
||||||
|
page_index++;
|
||||||
|
page_offset = 0;
|
||||||
|
src_buffer += copy_amount;
|
||||||
|
remaining_size -= copy_amount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -118,12 +118,14 @@ u16 Read16(VAddr addr);
|
||||||
u32 Read32(VAddr addr);
|
u32 Read32(VAddr addr);
|
||||||
u64 Read64(VAddr addr);
|
u64 Read64(VAddr addr);
|
||||||
|
|
||||||
|
void ReadBlock(const VAddr src_addr, u8* dest_buffer, size_t size);
|
||||||
|
|
||||||
void Write8(VAddr addr, u8 data);
|
void Write8(VAddr addr, u8 data);
|
||||||
void Write16(VAddr addr, u16 data);
|
void Write16(VAddr addr, u16 data);
|
||||||
void Write32(VAddr addr, u32 data);
|
void Write32(VAddr addr, u32 data);
|
||||||
void Write64(VAddr addr, u64 data);
|
void Write64(VAddr addr, u64 data);
|
||||||
|
|
||||||
void WriteBlock(VAddr addr, const u8* data, size_t size);
|
void WriteBlock(const VAddr dest_addr, const u8* src_buffer, size_t size);
|
||||||
|
|
||||||
u8* GetPointer(VAddr virtual_address);
|
u8* GetPointer(VAddr virtual_address);
|
||||||
|
|
||||||
|
|
|
@ -25,10 +25,14 @@ public:
|
||||||
virtual u32 Read32(VAddr addr) = 0;
|
virtual u32 Read32(VAddr addr) = 0;
|
||||||
virtual u64 Read64(VAddr addr) = 0;
|
virtual u64 Read64(VAddr addr) = 0;
|
||||||
|
|
||||||
|
virtual bool ReadBlock(VAddr src_addr, u8* dest_buffer, size_t size) = 0;
|
||||||
|
|
||||||
virtual void Write8(VAddr addr, u8 data) = 0;
|
virtual void Write8(VAddr addr, u8 data) = 0;
|
||||||
virtual void Write16(VAddr addr, u16 data) = 0;
|
virtual void Write16(VAddr addr, u16 data) = 0;
|
||||||
virtual void Write32(VAddr addr, u32 data) = 0;
|
virtual void Write32(VAddr addr, u32 data) = 0;
|
||||||
virtual void Write64(VAddr addr, u64 data) = 0;
|
virtual void Write64(VAddr addr, u64 data) = 0;
|
||||||
|
|
||||||
|
virtual bool WriteBlock(VAddr dest_addr, const u8* src_buffer, size_t size) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
using MMIORegionPointer = std::shared_ptr<MMIORegion>;
|
using MMIORegionPointer = std::shared_ptr<MMIORegion>;
|
||||||
|
|
Loading…
Reference in a new issue