summaryrefslogtreecommitdiff
path: root/inc
diff options
context:
space:
mode:
authorbd <bdunahu@operationnull.com>2025-03-27 20:30:18 -0400
committerbd <bdunahu@operationnull.com>2025-03-27 20:30:18 -0400
commiteaa87e9fcd90c00d6261cbdb854efb7a09467f1d (patch)
treee7f4cc05a30e5589f8bd70ddc49f420369adbb3c /inc
parent8d37d15ebd1221e3b1698abb3b051d9d0c044c93 (diff)
Instr, InstrDTO gets/sets, other structures required for decode
Diffstat (limited to 'inc')
-rw-r--r--inc/accessor.h3
-rw-r--r--inc/ex.h7
-rw-r--r--inc/id.h7
-rw-r--r--inc/if.h14
-rw-r--r--inc/instr.h14
-rw-r--r--inc/instrDTO.h60
-rw-r--r--inc/mm.h7
-rw-r--r--inc/stage.h9
-rw-r--r--inc/wb.h7
9 files changed, 114 insertions, 14 deletions
diff --git a/inc/accessor.h b/inc/accessor.h
index fb4999d..eb56785 100644
--- a/inc/accessor.h
+++ b/inc/accessor.h
@@ -4,7 +4,10 @@
enum Accessor {
IDLE,
+ WRITE,
MEM,
+ EXEC,
+ DCDE,
FETCH,
L1CACHE,
SIDE,
diff --git a/inc/ex.h b/inc/ex.h
index f9b2f78..fef411a 100644
--- a/inc/ex.h
+++ b/inc/ex.h
@@ -7,7 +7,12 @@
class EX : public Stage
{
public:
- using Stage::Stage;
+ /**
+ * Constructor.
+ * @param The next stage in the pipeline.
+ * @return A newly allocated EX object.
+ */
+ EX(Stage *next);
Response advance(InstrDTO &i) override;
};
diff --git a/inc/id.h b/inc/id.h
index de8f677..eafe274 100644
--- a/inc/id.h
+++ b/inc/id.h
@@ -7,7 +7,12 @@
class ID : public Stage
{
public:
- using Stage::Stage;
+ /**
+ * Constructor.
+ * @param The next stage in the pipeline.
+ * @return A newly allocated ID object.
+ */
+ ID(Stage *next);
Response advance(InstrDTO &i) override;
};
diff --git a/inc/if.h b/inc/if.h
index 437fa8d..7906c22 100644
--- a/inc/if.h
+++ b/inc/if.h
@@ -1,5 +1,6 @@
#ifndef IF_H
#define IF_H
+#include "accessor.h"
#include "instrDTO.h"
#include "response.h"
#include "stage.h"
@@ -7,15 +8,14 @@
class IF : public Stage
{
public:
- using Stage::Stage;
-
- Response advance(InstrDTO &i) override;
-
- private:
/**
- * The name this pipeline stages uses to access storage.
+ * Constructor.
+ * @param The next stage in the pipeline.
+ * @return A newly allocated IF object.
*/
- const Accessor id = FETCH;
+ IF(Stage *next);
+
+ Response advance(InstrDTO &i) override;
};
#endif /* IF_H_INCLUDED */
diff --git a/inc/instr.h b/inc/instr.h
new file mode 100644
index 0000000..ce08685
--- /dev/null
+++ b/inc/instr.h
@@ -0,0 +1,14 @@
+#ifndef INSTR_H
+#define INSTR_H
+
+#include <functional>
+#include <map>
+
+namespace instr
+{
+// clang-format off
+extern const std::map<int,std::map<int,std::function<void(signed int &s1, signed int &s2, signed int &s3)>>> instr_map;
+// clang-format on
+} // namespace instr
+
+#endif /* INSTR_H_INCLUDED */
diff --git a/inc/instrDTO.h b/inc/instrDTO.h
index 86cec05..7f2c688 100644
--- a/inc/instrDTO.h
+++ b/inc/instrDTO.h
@@ -1,5 +1,7 @@
#ifndef INSTRDTO_H
#define INSTRDTO_H
+#include <string>
+#include <functional>
class InstrDTO
{
@@ -15,25 +17,81 @@ class InstrDTO
*/
int get_if_cycle();
/**
+ * @return id_cycle
+ */
+ int get_id_cycle();
+ /**
* @return instr_bits
*/
signed int get_instr_bits();
+ /**
+ * @return s1
+ */
+ signed int get_s1();
+ /**
+ * @return s2
+ */
+ signed int get_s2();
+ /**
+ * @return s3
+ */
+ signed int get_s3();
+ /**
+ * @return the string representation of oper.
+ */
+ std::string get_oper_name();
/**
* @param if_cycle
*/
void set_if_cycle(int);
/**
+ * @param id_cycle
+ */
+ void set_id_cycle(int);
+ /**
* @param instr_bits
*/
void set_instr_bits(signed int);
+ /**
+ * @param s1
+ */
+ void set_s1(signed int);
+ /**
+ * @param s2
+ */
+ void set_s2(signed int);
+ /**
+ * @param s3
+ */
+ void set_s3(signed int);
private:
/**
- * The current clock cycle.
+ * The clock cycle this instruction finished being fetched.
*/
int if_cycle;
+ /**
+ * The clock cycle this instruction finished being identified.
+ */
+ int id_cycle;
+ /**
+ * The raw bits encoding the instruction.
+ */
signed int instr_bits;
+ /**
+ * Slots in this instruction, for storing temporary registers, immediates,
+ * or other.
+ * Some instruction types may use these differently.
+ * The `oper` function is in charge of knowing how to parse these.
+ */
+ signed int s1;
+ signed int s2;
+ signed int s3;
+ /**
+ * The operation to be conducted during the execute phase.
+ */
+ std::function<void()> instr;
};
#endif /* INSTRDTO_H_INCLUDED */
diff --git a/inc/mm.h b/inc/mm.h
index 5e2b029..90ebe5a 100644
--- a/inc/mm.h
+++ b/inc/mm.h
@@ -7,7 +7,12 @@
class MM : public Stage
{
public:
- using Stage::Stage;
+ /**
+ * Constructor.
+ * @param The next stage in the pipeline.
+ * @return A newly allocated MM object.
+ */
+ MM(Stage *next);
Response advance(InstrDTO &i) override;
};
diff --git a/inc/stage.h b/inc/stage.h
index ac810a9..04de475 100644
--- a/inc/stage.h
+++ b/inc/stage.h
@@ -4,6 +4,7 @@
#include "instrDTO.h"
#include "response.h"
#include "storage.h"
+#include "accessor.h"
#include <array>
class Stage
@@ -27,13 +28,17 @@ class Stage
protected:
/**
+ * The name of the pipeline stage.
+ */
+ Accessor id;
+ /**
* The shared pool of general-purpose integer registers.
*/
- static std::array<int, GPR_NUM> gprs;
+ static std::array<signed int, GPR_NUM> gprs;
/**
* The address of the currently executing instruction.
*/
- static int pc;
+ static unsigned int pc;
/**
* A pointer to the next stage in the pipeline.
*/
diff --git a/inc/wb.h b/inc/wb.h
index b1d65f7..b8f5d8f 100644
--- a/inc/wb.h
+++ b/inc/wb.h
@@ -7,7 +7,12 @@
class WB : public Stage
{
public:
- using Stage::Stage;
+ /**
+ * Constructor.
+ * @param The next stage in the pipeline.
+ * @return A newly allocated WB object.
+ */
+ WB(Stage *next);
Response advance(InstrDTO &i) override;
};