summaryrefslogtreecommitdiff
path: root/src/CPU.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/CPU.h')
-rw-r--r--src/CPU.h57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/CPU.h b/src/CPU.h
new file mode 100644
index 0000000..1ad96aa
--- /dev/null
+++ b/src/CPU.h
@@ -0,0 +1,57 @@
+#pragma once
+
+#include <cstdint>
+#include <memory>
+
+#include "Instruction.h"
+#include "Bus.h"
+#include "ExecutorCases.h"
+#include "CPUContext.h"
+
+enum class CPUExecutionMode {
+ BIT_32,
+};
+
+struct CPUStatus {
+ uint32_t* m_Registers;
+ uint32_t& m_IP;
+ Instruction& m_Instruction;
+};
+
+class CPU {
+public:
+ CPU(std::shared_ptr<Bus>& bus);
+ ~CPU() = default;
+
+public:
+ void Step();
+
+ void Dump();
+ void Reset();
+
+ bool IsHalted() { return m_IsHalted; }
+
+ CPUStatus GetStatus();
+
+private:
+ void FetchDecode();
+ void Execute();
+
+private:
+ CPUExecutionMode m_Mode;
+ uint32_t m_Registers[8];
+ uint16_t m_SegmentRegisters[8];
+ uint32_t m_InstructionPointer;
+ uint32_t m_Flags;
+ bool m_IsHalted;
+
+ std::shared_ptr<Bus> m_Bus;
+
+ Instruction m_Instruction;
+
+ CPUContext m_Context;
+private:
+ // FetchDecode() must set m_Length before calling FetchModRMFields()
+ void FetchModRMFields(uint8_t modrm);
+ void FetchSIB();
+};