From ca642d0c8b0a3dd5f768749b58ba66ac35472610 Mon Sep 17 00:00:00 2001 From: Dennis Brentjes Date: Sat, 16 Jun 2018 15:36:39 +0200 Subject: Fixes a bug with calculating memory offsets and exposes some more registers. --- emulate/cpustate.hpp | 52 ++++++++++++++++++---------------------------------- 1 file changed, 18 insertions(+), 34 deletions(-) (limited to 'emulate/cpustate.hpp') diff --git a/emulate/cpustate.hpp b/emulate/cpustate.hpp index 6b80551..be9c254 100644 --- a/emulate/cpustate.hpp +++ b/emulate/cpustate.hpp @@ -1,9 +1,7 @@ #pragma once -#include #include #include -#include #define REGISTER1( NAME ) \ private: \ @@ -12,7 +10,7 @@ public: \ uint32_t& e##NAME##x() { \ return *reinterpret_cast(NAME##_storage.data()); \ } \ - \ + \ uint16_t& NAME##x() { \ return *reinterpret_cast(NAME##_storage.data()); \ } \ @@ -32,7 +30,15 @@ public: \ uint32_t& e##NAME() { \ return *reinterpret_cast(NAME##_storage.data()); \ } \ - \ + \ + uint16_t& NAME() { \ + return *reinterpret_cast(NAME##_storage.data()); \ + } \ + +#define SEGMENT_REGISTER( NAME ) \ +private: \ + alignas(2) std::array NAME##_storage = {{0,0}}; \ +public: \ uint16_t& NAME() { \ return *reinterpret_cast(NAME##_storage.data()); \ } \ @@ -70,40 +76,18 @@ struct CpuState { REGISTER2(bp) REGISTER2(si) REGISTER2(di) + SEGMENT_REGISTER(cs) + SEGMENT_REGISTER(ds) + SEGMENT_REGISTER(es) + SEGMENT_REGISTER(ss) + SEGMENT_REGISTER(fs) + SEGMENT_REGISTER(gs) EFLAGS }; #undef REGISTER1 #undef REGISTER2 +#undef SEGMENT_REGISTER #undef EFLAGS -std::ostream& operator<<(std::ostream& os, CpuState& cpu) { - os << "EIP: 0x" << std::hex << std::setw(8) << std::setfill('0') << cpu.eip() << std::endl - << "EAX: 0x" << std::hex << std::setw(8) << std::setfill('0') << cpu.eax() << std::endl - << "EBX: 0x" << std::hex << std::setw(8) << std::setfill('0') << cpu.ebx() << std::endl - << "ECX: 0x" << std::hex << std::setw(8) << std::setfill('0') << cpu.ecx() << std::endl - << "EDX: 0x" << std::hex << std::setw(8) << std::setfill('0') << cpu.edx() << std::endl - << "ESP: 0x" << std::hex << std::setw(8) << std::setfill('0') << cpu.esp() << std::endl - << "EBP: 0x" << std::hex << std::setw(8) << std::setfill('0') << cpu.ebp() << std::endl - << "ESI: 0x" << std::hex << std::setw(8) << std::setfill('0') << cpu.esi() << std::endl - << "EDI: 0x" << std::hex << std::setw(8) << std::setfill('0') << cpu.edi() << std::endl - << "cf \tpf \taf \tzf \tsf \ttf \tintf \tdf \tof \tnt \trf \tvm \tac \tvif \tvip \tid" << std::endl - << cpu.cf() << "\t" - << cpu.pf() << "\t" - << cpu.af() << "\t" - << cpu.zf() << "\t" - << cpu.sf() << "\t" - << cpu.tf() << "\t" - << cpu.intf() << "\t" - << cpu.df() << "\t" - << cpu.of() << "\t" - << cpu.nt() << "\t" - << cpu.rf() << "\t" - << cpu.vm() << "\t" - << cpu.ac() << "\t" - << cpu.vif() << "\t" - << cpu.vip() << "\t" - << cpu.id() << "\t" - << std::endl; - return os; -} +std::ostream& operator<<(std::ostream& os, CpuState& cpu); -- cgit v1.2.3-70-g09d2