diff options
Diffstat (limited to 'emulate/cpustate.hpp')
| -rw-r--r-- | emulate/cpustate.hpp | 52 |
1 files changed, 18 insertions, 34 deletions
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 <iostream> #include <array> #include <bitset> -#include <iomanip> #define REGISTER1( NAME ) \ private: \ @@ -12,7 +10,7 @@ public: \ uint32_t& e##NAME##x() { \ return *reinterpret_cast<uint32_t*>(NAME##_storage.data()); \ } \ - \ + \ uint16_t& NAME##x() { \ return *reinterpret_cast<uint16_t*>(NAME##_storage.data()); \ } \ @@ -32,7 +30,15 @@ public: \ uint32_t& e##NAME() { \ return *reinterpret_cast<uint32_t*>(NAME##_storage.data()); \ } \ - \ + \ + uint16_t& NAME() { \ + return *reinterpret_cast<uint16_t*>(NAME##_storage.data()); \ + } \ + +#define SEGMENT_REGISTER( NAME ) \ +private: \ + alignas(2) std::array<uint8_t,2> NAME##_storage = {{0,0}}; \ +public: \ uint16_t& NAME() { \ return *reinterpret_cast<uint16_t*>(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); |
