aboutsummaryrefslogtreecommitdiff
path: root/src/core/memory.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/memory.cpp')
-rw-r--r--src/core/memory.cpp61
1 files changed, 40 insertions, 21 deletions
diff --git a/src/core/memory.cpp b/src/core/memory.cpp
index 9b394f84b..847e69710 100644
--- a/src/core/memory.cpp
+++ b/src/core/memory.cpp
@@ -110,8 +110,8 @@ static u8* GetPointerFromVMA(VAddr vaddr) {
/**
* This function should only be called for virtual addreses with attribute `PageType::Special`.
*/
-static MMIORegionPointer GetMMIOHandler(VAddr vaddr) {
- for (const auto& region : current_page_table->special_regions) {
+static MMIORegionPointer GetMMIOHandler(const PageTable& page_table, VAddr vaddr) {
+ for (const auto& region : page_table.special_regions) {
if (vaddr >= region.base && vaddr < (region.base + region.size)) {
return region.handler;
}
@@ -120,6 +120,11 @@ static MMIORegionPointer GetMMIOHandler(VAddr vaddr) {
return nullptr; // Should never happen
}
+static MMIORegionPointer GetMMIOHandler(VAddr vaddr) {
+ const PageTable& page_table = Kernel::g_current_process->vm_manager.page_table;
+ return GetMMIOHandler(page_table, vaddr);
+}
+
template <typename T>
T ReadMMIO(MMIORegionPointer mmio_handler, VAddr addr);
@@ -204,18 +209,20 @@ void Write(const VAddr vaddr, const T data) {
}
}
-bool IsValidVirtualAddress(const VAddr vaddr) {
- const u8* page_pointer = current_page_table->pointers[vaddr >> PAGE_BITS];
+bool IsValidVirtualAddress(const Kernel::Process& process, const VAddr vaddr) {
+ auto& page_table = process.vm_manager.page_table;
+
+ const u8* page_pointer = page_table.pointers[vaddr >> PAGE_BITS];
if (page_pointer)
return true;
- if (current_page_table->attributes[vaddr >> PAGE_BITS] == PageType::RasterizerCachedMemory)
+ if (page_table.attributes[vaddr >> PAGE_BITS] == PageType::RasterizerCachedMemory)
return true;
- if (current_page_table->attributes[vaddr >> PAGE_BITS] != PageType::Special)
+ if (page_table.attributes[vaddr >> PAGE_BITS] != PageType::Special)
return false;
- MMIORegionPointer mmio_region = GetMMIOHandler(vaddr);
+ MMIORegionPointer mmio_region = GetMMIOHandler(page_table, vaddr);
if (mmio_region) {
return mmio_region->IsValidAddress(vaddr);
}
@@ -223,6 +230,10 @@ bool IsValidVirtualAddress(const VAddr vaddr) {
return false;
}
+bool IsValidVirtualAddress(const VAddr vaddr) {
+ return IsValidVirtualAddress(*Kernel::g_current_process, vaddr);
+}
+
bool IsValidPhysicalAddress(const PAddr paddr) {
return GetPhysicalPointer(paddr) != nullptr;
}
@@ -466,7 +477,7 @@ void ReadBlock(const VAddr src_addr, void* dest_buffer, const size_t size) {
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;
+ const VAddr current_vaddr = static_cast<VAddr>((page_index << PAGE_BITS) + page_offset);
switch (current_page_table->attributes[page_index]) {
case PageType::Unmapped: {
@@ -489,13 +500,15 @@ void ReadBlock(const VAddr src_addr, void* dest_buffer, const size_t size) {
break;
}
case PageType::RasterizerCachedMemory: {
- RasterizerFlushVirtualRegion(current_vaddr, copy_amount, FlushMode::Flush);
+ RasterizerFlushVirtualRegion(current_vaddr, static_cast<u32>(copy_amount),
+ FlushMode::Flush);
std::memcpy(dest_buffer, GetPointerFromVMA(current_vaddr), copy_amount);
break;
}
case PageType::RasterizerCachedSpecial: {
DEBUG_ASSERT(GetMMIOHandler(current_vaddr));
- RasterizerFlushVirtualRegion(current_vaddr, copy_amount, FlushMode::Flush);
+ RasterizerFlushVirtualRegion(current_vaddr, static_cast<u32>(copy_amount),
+ FlushMode::Flush);
GetMMIOHandler(current_vaddr)->ReadBlock(current_vaddr, dest_buffer, copy_amount);
break;
}
@@ -533,7 +546,7 @@ void WriteBlock(const VAddr dest_addr, const void* src_buffer, const size_t size
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;
+ const VAddr current_vaddr = static_cast<VAddr>((page_index << PAGE_BITS) + page_offset);
switch (current_page_table->attributes[page_index]) {
case PageType::Unmapped: {
@@ -556,13 +569,15 @@ void WriteBlock(const VAddr dest_addr, const void* src_buffer, const size_t size
break;
}
case PageType::RasterizerCachedMemory: {
- RasterizerFlushVirtualRegion(current_vaddr, copy_amount, FlushMode::FlushAndInvalidate);
+ RasterizerFlushVirtualRegion(current_vaddr, static_cast<u32>(copy_amount),
+ FlushMode::FlushAndInvalidate);
std::memcpy(GetPointerFromVMA(current_vaddr), src_buffer, copy_amount);
break;
}
case PageType::RasterizerCachedSpecial: {
DEBUG_ASSERT(GetMMIOHandler(current_vaddr));
- RasterizerFlushVirtualRegion(current_vaddr, copy_amount, FlushMode::FlushAndInvalidate);
+ RasterizerFlushVirtualRegion(current_vaddr, static_cast<u32>(copy_amount),
+ FlushMode::FlushAndInvalidate);
GetMMIOHandler(current_vaddr)->WriteBlock(current_vaddr, src_buffer, copy_amount);
break;
}
@@ -586,7 +601,7 @@ void ZeroBlock(const VAddr dest_addr, const size_t size) {
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;
+ const VAddr current_vaddr = static_cast<VAddr>((page_index << PAGE_BITS) + page_offset);
switch (current_page_table->attributes[page_index]) {
case PageType::Unmapped: {
@@ -608,13 +623,15 @@ void ZeroBlock(const VAddr dest_addr, const size_t size) {
break;
}
case PageType::RasterizerCachedMemory: {
- RasterizerFlushVirtualRegion(current_vaddr, copy_amount, FlushMode::FlushAndInvalidate);
+ RasterizerFlushVirtualRegion(current_vaddr, static_cast<u32>(copy_amount),
+ FlushMode::FlushAndInvalidate);
std::memset(GetPointerFromVMA(current_vaddr), 0, copy_amount);
break;
}
case PageType::RasterizerCachedSpecial: {
DEBUG_ASSERT(GetMMIOHandler(current_vaddr));
- RasterizerFlushVirtualRegion(current_vaddr, copy_amount, FlushMode::FlushAndInvalidate);
+ RasterizerFlushVirtualRegion(current_vaddr, static_cast<u32>(copy_amount),
+ FlushMode::FlushAndInvalidate);
GetMMIOHandler(current_vaddr)->WriteBlock(current_vaddr, zeros.data(), copy_amount);
break;
}
@@ -635,7 +652,7 @@ void CopyBlock(VAddr dest_addr, VAddr src_addr, const size_t size) {
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;
+ const VAddr current_vaddr = static_cast<VAddr>((page_index << PAGE_BITS) + page_offset);
switch (current_page_table->attributes[page_index]) {
case PageType::Unmapped: {
@@ -659,13 +676,15 @@ void CopyBlock(VAddr dest_addr, VAddr src_addr, const size_t size) {
break;
}
case PageType::RasterizerCachedMemory: {
- RasterizerFlushVirtualRegion(current_vaddr, copy_amount, FlushMode::Flush);
+ RasterizerFlushVirtualRegion(current_vaddr, static_cast<u32>(copy_amount),
+ FlushMode::Flush);
WriteBlock(dest_addr, GetPointerFromVMA(current_vaddr), copy_amount);
break;
}
case PageType::RasterizerCachedSpecial: {
DEBUG_ASSERT(GetMMIOHandler(current_vaddr));
- RasterizerFlushVirtualRegion(current_vaddr, copy_amount, FlushMode::Flush);
+ RasterizerFlushVirtualRegion(current_vaddr, static_cast<u32>(copy_amount),
+ FlushMode::Flush);
std::vector<u8> buffer(copy_amount);
GetMMIOHandler(current_vaddr)->ReadBlock(current_vaddr, buffer.data(), buffer.size());
@@ -678,8 +697,8 @@ void CopyBlock(VAddr dest_addr, VAddr src_addr, const size_t size) {
page_index++;
page_offset = 0;
- dest_addr += copy_amount;
- src_addr += copy_amount;
+ dest_addr += static_cast<VAddr>(copy_amount);
+ src_addr += static_cast<VAddr>(copy_amount);
remaining_size -= copy_amount;
}
}