summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-07-12 17:42:57 +0200
committerAndreas Kling <kling@serenityos.org>2020-07-12 17:42:57 +0200
commit94f07660e90ede0c15a26ff0d53a10ed55355f16 (patch)
tree75dacecb66ccc779b7f1b702c22d72f97de7e4d8
parent274ac3c6288b42c7464e0e60966b5c5bc2c158ac (diff)
downloadserenity-94f07660e90ede0c15a26ff0d53a10ed55355f16.zip
UserspaceEmulator: Add some convenient SoftMMU APIs for copying data
We'll soon want to copy data in and out of the SoftMMU memory space.
-rw-r--r--DevTools/UserspaceEmulator/SoftMMU.cpp20
-rw-r--r--DevTools/UserspaceEmulator/SoftMMU.h4
2 files changed, 24 insertions, 0 deletions
diff --git a/DevTools/UserspaceEmulator/SoftMMU.cpp b/DevTools/UserspaceEmulator/SoftMMU.cpp
index cf4d95cf25..a1c8485d2b 100644
--- a/DevTools/UserspaceEmulator/SoftMMU.cpp
+++ b/DevTools/UserspaceEmulator/SoftMMU.cpp
@@ -25,6 +25,7 @@
*/
#include "SoftMMU.h"
+#include <AK/ByteBuffer.h>
namespace UserspaceEmulator {
@@ -119,4 +120,23 @@ void SoftMMU::write32(X86::LogicalAddress address, u32 value)
region->write32(address.offset() - region->base(), value);
}
+void SoftMMU::copy_to_vm(FlatPtr destination, const void* source, size_t size)
+{
+ for (size_t i = 0; i < size; ++i)
+ write8({ 0x20, destination + i }, ((const u8*)source)[i]);
+}
+
+void SoftMMU::copy_from_vm(void* destination, const FlatPtr source, size_t size)
+{
+ for (size_t i = 0; i < size; ++i)
+ ((u8*)destination)[i] = read8({ 0x20, source + i });
+}
+
+ByteBuffer SoftMMU::copy_buffer_from_vm(const FlatPtr source, size_t size)
+{
+ auto buffer = ByteBuffer::create_uninitialized(size);
+ copy_from_vm(buffer.data(), source, size);
+ return buffer;
+}
+
}
diff --git a/DevTools/UserspaceEmulator/SoftMMU.h b/DevTools/UserspaceEmulator/SoftMMU.h
index 1a0f46c17c..4fad77a391 100644
--- a/DevTools/UserspaceEmulator/SoftMMU.h
+++ b/DevTools/UserspaceEmulator/SoftMMU.h
@@ -78,6 +78,10 @@ public:
void add_region(NonnullOwnPtr<Region>);
void set_tls_region(NonnullOwnPtr<Region>);
+ void copy_to_vm(FlatPtr destination, const void* source, size_t);
+ void copy_from_vm(void* destination, const FlatPtr source, size_t);
+ ByteBuffer copy_buffer_from_vm(const FlatPtr source, size_t);
+
private:
OwnPtr<Region> m_tls_region;
NonnullOwnPtrVector<Region> m_regions;