mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 13:57:35 +00:00
UserspaceEmulator: Add some convenient SoftMMU APIs for copying data
We'll soon want to copy data in and out of the SoftMMU memory space.
This commit is contained in:
parent
274ac3c628
commit
94f07660e9
2 changed files with 24 additions and 0 deletions
|
@ -25,6 +25,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "SoftMMU.h"
|
#include "SoftMMU.h"
|
||||||
|
#include <AK/ByteBuffer.h>
|
||||||
|
|
||||||
namespace UserspaceEmulator {
|
namespace UserspaceEmulator {
|
||||||
|
|
||||||
|
@ -119,4 +120,23 @@ void SoftMMU::write32(X86::LogicalAddress address, u32 value)
|
||||||
region->write32(address.offset() - region->base(), 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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,6 +78,10 @@ public:
|
||||||
void add_region(NonnullOwnPtr<Region>);
|
void add_region(NonnullOwnPtr<Region>);
|
||||||
void set_tls_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:
|
private:
|
||||||
OwnPtr<Region> m_tls_region;
|
OwnPtr<Region> m_tls_region;
|
||||||
NonnullOwnPtrVector<Region> m_regions;
|
NonnullOwnPtrVector<Region> m_regions;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue