1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 02:17:35 +00:00

UserspaceEmulator: Add a SoftMMU::read<T> function

...and implement SoftCPU::read_memory<T> with it.
This allows the MMU to read a typed object (using 1-byte reads), which
is significantly nicer to use than reading the struct fields manually.
This commit is contained in:
Ali Mohammad Pur 2022-02-27 23:59:40 +03:30 committed by Andreas Kling
parent 70b53b44b2
commit baf7038919
3 changed files with 47 additions and 12 deletions

View file

@ -6,6 +6,8 @@
#pragma once
#include "AK/Debug.h"
#include "Emulator.h"
#include "Region.h"
#include "SoftFPU.h"
#include "ValueWithShadow.h"
@ -367,18 +369,12 @@ public:
template<typename T>
ValueWithShadow<T> read_memory(X86::LogicalAddress address)
{
if constexpr (sizeof(T) == 1)
return read_memory8(address);
if constexpr (sizeof(T) == 2)
return read_memory16(address);
if constexpr (sizeof(T) == 4)
return read_memory32(address);
if constexpr (sizeof(T) == 8)
return read_memory64(address);
if constexpr (sizeof(T) == 16)
return read_memory128(address);
if constexpr (sizeof(T) == 32)
return read_memory256(address);
auto value = m_emulator.mmu().read<T>(address);
if constexpr (AK::HasFormatter<T>)
outln_if(MEMORY_DEBUG, "\033[36;1mread_memory: @{:#04x}:{:p} -> {:#064x} ({:hex-dump})\033[0m", address.selector(), address.offset(), value.value(), value.shadow().span());
else
outln_if(MEMORY_DEBUG, "\033[36;1mread_memory: @{:#04x}:{:p} -> ??? ({:hex-dump})\033[0m", address.selector(), address.offset(), value.shadow().span());
return value;
}
void write_memory8(X86::LogicalAddress, ValueWithShadow<u8>);