diff options
author | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2022-02-27 23:58:53 +0330 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-03-04 20:07:05 +0100 |
commit | 70b53b44b2b0723a8a328aa04438faa5eab4a836 (patch) | |
tree | b3688bcb71f913a07d85ce59c683262c75691d47 /Userland | |
parent | f6e82a8e0a19b9d575f462bd5d34d831dd268bb3 (diff) | |
download | serenity-70b53b44b2b0723a8a328aa04438faa5eab4a836.zip |
UserspaceEmulator: Wrap the GPRs in ValueWithShadow
...instead of manually tracking their shadow data.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/DevTools/UserspaceEmulator/SoftCPU.cpp | 6 | ||||
-rw-r--r-- | Userland/DevTools/UserspaceEmulator/SoftCPU.h | 43 | ||||
-rw-r--r-- | Userland/DevTools/UserspaceEmulator/ValueWithShadow.h | 6 |
3 files changed, 25 insertions, 30 deletions
diff --git a/Userland/DevTools/UserspaceEmulator/SoftCPU.cpp b/Userland/DevTools/UserspaceEmulator/SoftCPU.cpp index 1dba8f21cf..5c664d2fdf 100644 --- a/Userland/DevTools/UserspaceEmulator/SoftCPU.cpp +++ b/Userland/DevTools/UserspaceEmulator/SoftCPU.cpp @@ -74,8 +74,10 @@ SoftCPU::SoftCPU(Emulator& emulator) : m_emulator(emulator) , m_fpu(emulator, *this) { - memset(m_gpr, 0, sizeof(m_gpr)); - memset(m_gpr_shadow, 1, sizeof(m_gpr_shadow)); + PartAddressableRegister empty_reg; + explicit_bzero(&empty_reg, sizeof(empty_reg)); + for (auto& gpr : m_gpr) + gpr = ValueWithShadow<PartAddressableRegister>::create_initialized(empty_reg); m_segment[(int)X86::SegmentRegister::CS] = 0x1b; m_segment[(int)X86::SegmentRegister::DS] = 0x23; diff --git a/Userland/DevTools/UserspaceEmulator/SoftCPU.h b/Userland/DevTools/UserspaceEmulator/SoftCPU.h index 99c6155cb7..fed286f460 100644 --- a/Userland/DevTools/UserspaceEmulator/SoftCPU.h +++ b/Userland/DevTools/UserspaceEmulator/SoftCPU.h @@ -88,21 +88,21 @@ public: { switch (reg) { case X86::RegisterAL: - return { m_gpr[X86::RegisterEAX].low_u8, m_gpr_shadow[X86::RegisterEAX].low_u8 }; + return m_gpr[X86::RegisterEAX].reference_to<&PartAddressableRegister::low_u8>(); case X86::RegisterAH: - return { m_gpr[X86::RegisterEAX].high_u8, m_gpr_shadow[X86::RegisterEAX].high_u8 }; + return m_gpr[X86::RegisterEAX].reference_to<&PartAddressableRegister::high_u8>(); case X86::RegisterBL: - return { m_gpr[X86::RegisterEBX].low_u8, m_gpr_shadow[X86::RegisterEBX].low_u8 }; + return m_gpr[X86::RegisterEBX].reference_to<&PartAddressableRegister::low_u8>(); case X86::RegisterBH: - return { m_gpr[X86::RegisterEBX].high_u8, m_gpr_shadow[X86::RegisterEBX].high_u8 }; + return m_gpr[X86::RegisterEBX].reference_to<&PartAddressableRegister::high_u8>(); case X86::RegisterCL: - return { m_gpr[X86::RegisterECX].low_u8, m_gpr_shadow[X86::RegisterECX].low_u8 }; + return m_gpr[X86::RegisterECX].reference_to<&PartAddressableRegister::low_u8>(); case X86::RegisterCH: - return { m_gpr[X86::RegisterECX].high_u8, m_gpr_shadow[X86::RegisterECX].high_u8 }; + return m_gpr[X86::RegisterECX].reference_to<&PartAddressableRegister::high_u8>(); case X86::RegisterDL: - return { m_gpr[X86::RegisterEDX].low_u8, m_gpr_shadow[X86::RegisterEDX].low_u8 }; + return m_gpr[X86::RegisterEDX].reference_to<&PartAddressableRegister::low_u8>(); case X86::RegisterDH: - return { m_gpr[X86::RegisterEDX].high_u8, m_gpr_shadow[X86::RegisterEDX].high_u8 }; + return m_gpr[X86::RegisterEDX].reference_to<&PartAddressableRegister::high_u8>(); } VERIFY_NOT_REACHED(); } @@ -111,43 +111,43 @@ public: { switch (reg) { case X86::RegisterAL: - return { m_gpr[X86::RegisterEAX].low_u8, m_gpr_shadow[X86::RegisterEAX].low_u8 }; + return m_gpr[X86::RegisterEAX].slice<&PartAddressableRegister::low_u8>(); case X86::RegisterAH: - return { m_gpr[X86::RegisterEAX].high_u8, m_gpr_shadow[X86::RegisterEAX].high_u8 }; + return m_gpr[X86::RegisterEAX].slice<&PartAddressableRegister::high_u8>(); case X86::RegisterBL: - return { m_gpr[X86::RegisterEBX].low_u8, m_gpr_shadow[X86::RegisterEBX].low_u8 }; + return m_gpr[X86::RegisterEBX].slice<&PartAddressableRegister::low_u8>(); case X86::RegisterBH: - return { m_gpr[X86::RegisterEBX].high_u8, m_gpr_shadow[X86::RegisterEBX].high_u8 }; + return m_gpr[X86::RegisterEBX].slice<&PartAddressableRegister::high_u8>(); case X86::RegisterCL: - return { m_gpr[X86::RegisterECX].low_u8, m_gpr_shadow[X86::RegisterECX].low_u8 }; + return m_gpr[X86::RegisterECX].slice<&PartAddressableRegister::low_u8>(); case X86::RegisterCH: - return { m_gpr[X86::RegisterECX].high_u8, m_gpr_shadow[X86::RegisterECX].high_u8 }; + return m_gpr[X86::RegisterECX].slice<&PartAddressableRegister::high_u8>(); case X86::RegisterDL: - return { m_gpr[X86::RegisterEDX].low_u8, m_gpr_shadow[X86::RegisterEDX].low_u8 }; + return m_gpr[X86::RegisterEDX].slice<&PartAddressableRegister::low_u8>(); case X86::RegisterDH: - return { m_gpr[X86::RegisterEDX].high_u8, m_gpr_shadow[X86::RegisterEDX].high_u8 }; + return m_gpr[X86::RegisterEDX].slice<&PartAddressableRegister::high_u8>(); } VERIFY_NOT_REACHED(); } ValueWithShadow<u16> const_gpr16(X86::RegisterIndex16 reg) const { - return { m_gpr[reg].low_u16, m_gpr_shadow[reg].low_u16 }; + return m_gpr[reg].slice<&PartAddressableRegister::low_u16>(); } ValueAndShadowReference<u16> gpr16(X86::RegisterIndex16 reg) { - return { m_gpr[reg].low_u16, m_gpr_shadow[reg].low_u16 }; + return m_gpr[reg].reference_to<&PartAddressableRegister::low_u16>(); } ValueWithShadow<u32> const_gpr32(X86::RegisterIndex32 reg) const { - return { m_gpr[reg].full_u32, m_gpr_shadow[reg].full_u32 }; + return m_gpr[reg].slice<&PartAddressableRegister::full_u32>(); } ValueAndShadowReference<u32> gpr32(X86::RegisterIndex32 reg) { - return { m_gpr[reg].full_u32, m_gpr_shadow[reg].full_u32 }; + return m_gpr[reg].reference_to<&PartAddressableRegister::full_u32>(); } template<typename T> @@ -1252,8 +1252,7 @@ private: Emulator& m_emulator; SoftFPU m_fpu; - PartAddressableRegister m_gpr[8]; - PartAddressableRegister m_gpr_shadow[8]; + ValueWithShadow<PartAddressableRegister> m_gpr[8]; u16 m_segment[8] { 0 }; u32 m_eflags { 0 }; diff --git a/Userland/DevTools/UserspaceEmulator/ValueWithShadow.h b/Userland/DevTools/UserspaceEmulator/ValueWithShadow.h index 7c64d3d6a1..e7ad1988a0 100644 --- a/Userland/DevTools/UserspaceEmulator/ValueWithShadow.h +++ b/Userland/DevTools/UserspaceEmulator/ValueWithShadow.h @@ -107,12 +107,6 @@ public: { } - ValueAndShadowReference(T& value, T& shadow) - : m_value(value) - , m_shadow(*bit_cast<ShadowType*>(&shadow)) - { - } - bool is_uninitialized() const { for (size_t i = 0; i < sizeof(ShadowType); ++i) { |