mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 12:38:12 +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 <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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue