summaryrefslogtreecommitdiff
path: root/emulate/cpustate.hpp
diff options
context:
space:
mode:
authorDennis Brentjes <d.brentjes@gmail.com>2016-09-19 17:38:23 +0200
committerDennis Brentjes <d.brentjes@gmail.com>2016-10-04 22:18:23 +0200
commitc29ae7a65c636b8d1fa37c6589278dcdee97658f (patch)
treea0ad6583a1f954a179349e0b27d58d7c945c59b5 /emulate/cpustate.hpp
parentabd5cfdd4a6c8e9979b2deb3c48304fb3d63a44c (diff)
downloadopenwar-c29ae7a65c636b8d1fa37c6589278dcdee97658f.tar.gz
openwar-c29ae7a65c636b8d1fa37c6589278dcdee97658f.tar.bz2
openwar-c29ae7a65c636b8d1fa37c6589278dcdee97658f.zip
Started working on a x86 emulator.
Diffstat (limited to 'emulate/cpustate.hpp')
-rw-r--r--emulate/cpustate.hpp77
1 files changed, 77 insertions, 0 deletions
diff --git a/emulate/cpustate.hpp b/emulate/cpustate.hpp
new file mode 100644
index 0000000..fb9c377
--- /dev/null
+++ b/emulate/cpustate.hpp
@@ -0,0 +1,77 @@
+#pragma once
+
+#include <iostream>
+#include <array>
+#include <bitset>
+
+#define REGISTER1( NAME ) \
+private: \
+ alignas(4) std::array<uint8_t,4> NAME##_storage = {{0,0,0,0}}; \
+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()); \
+ } \
+ \
+ uint8_t& NAME##h() { \
+ return *reinterpret_cast<uint8_t*>(NAME##_storage.data()+1); \
+ } \
+ \
+ uint8_t& NAME##l() { \
+ return *reinterpret_cast<uint8_t*>(NAME##_storage.data()); \
+ } \
+
+#define REGISTER2( NAME ) \
+private: \
+ alignas(4) std::array<uint8_t,4> NAME##_storage = {{0,0,0,0}}; \
+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 EFLAGS \
+private: \
+ alignas(8) std::bitset<32> storage = 2; \
+public: \
+ using ref = std::bitset<32>::reference; \
+ ref cf() { return storage[0]; } \
+ ref pf() { return storage[2]; } \
+ ref af() { return storage[4]; } \
+ ref zf() { return storage[6]; } \
+ ref sf() { return storage[7]; } \
+ ref tf() { return storage[8]; } \
+ ref intf() { return storage[9]; } \
+ ref df() { return storage[10]; } \
+ ref of() { return storage[11]; } \
+ /*TODO: iopl*/ \
+ ref nt() { return storage[14]; } \
+ ref rf() { return storage[16]; } \
+ ref vm() { return storage[17]; } \
+ ref ac() { return storage[18]; } \
+ ref vif() { return storage[19]; } \
+ ref vip() { return storage[20]; } \
+ ref id() { return storage[21]; } \
+
+struct CpuState {
+ REGISTER2(ip)
+ REGISTER1(a)
+ REGISTER1(c)
+ REGISTER1(d)
+ REGISTER1(b)
+ REGISTER2(sp)
+ REGISTER2(bp)
+ REGISTER2(si)
+ REGISTER2(di)
+ EFLAGS
+};
+
+#undef REGISTER1
+#undef REGISTER2
+#undef EFLAGS \ No newline at end of file