summaryrefslogtreecommitdiff
path: root/inc
diff options
context:
space:
mode:
authorbd <bdunahu@operationnull.com>2025-03-30 14:28:45 -0400
committerbd <bdunahu@operationnull.com>2025-03-30 14:28:45 -0400
commit8c46ba4f216aec9f512cd398317f891be9b07e84 (patch)
treecb502366f721c6bca60becc309fd9de288769d87 /inc
parent916949133a5797772dcd6966e469c12230ffc3fa (diff)
Add mock stage, proper decode tests
Diffstat (limited to 'inc')
-rw-r--r--inc/controller.h9
-rw-r--r--inc/dum.h28
-rw-r--r--inc/ex.h4
-rw-r--r--inc/id.h8
-rw-r--r--inc/if.h9
-rw-r--r--inc/mm.h4
-rw-r--r--inc/stage.h12
-rw-r--r--inc/wb.h6
8 files changed, 57 insertions, 23 deletions
diff --git a/inc/controller.h b/inc/controller.h
index 1c7b2d6..17aba37 100644
--- a/inc/controller.h
+++ b/inc/controller.h
@@ -1,8 +1,8 @@
#ifndef CONTROLLER_H
#define CONTROLLER_H
+#include "instrDTO.h"
#include "response.h"
#include "stage.h"
-#include "instrDTO.h"
/**
* Houses the clock, and acts as the main API to the GUI.
@@ -18,7 +18,8 @@ class Controller : public Stage
* @return A newly allocated controller object.
*/
Controller(Stage *stage, Storage *storage, bool is_pipelined);
-
+ InstrDTO *advance(Response p) override;
+
/**
* Direct the simulator to run for `number` clock cycles.
* @param the number of clock cycles to run for.
@@ -36,7 +37,9 @@ class Controller : public Stage
* @return the pc.
*/
int get_pc();
- InstrDTO *advance(Response p) override;
+
+ private:
+ void advance_helper() override;
};
#endif /* CONTROLLER_H_INCLUDED */
diff --git a/inc/dum.h b/inc/dum.h
new file mode 100644
index 0000000..da64b9d
--- /dev/null
+++ b/inc/dum.h
@@ -0,0 +1,28 @@
+#ifndef DUM_H
+#define DUM_H
+#include "instrDTO.h"
+#include "response.h"
+#include "stage.h"
+
+/**
+ * Don't underestimate mocks (the DUM pipe stage).
+ */
+class DUM : public Stage
+{
+ public:
+ /**
+ * Constructor.
+ * @param The next stage in the pipeline.
+ * @return A newly allocated DUM object.
+ */
+ DUM(Stage *next);
+
+ InstrDTO *advance(Response p) override;
+
+ void set_curr_instr(InstrDTO *);
+
+ private:
+ void advance_helper() override;
+};
+
+#endif /* DUM_H_INCLUDED */
diff --git a/inc/ex.h b/inc/ex.h
index 19c3ac9..cc8062b 100644
--- a/inc/ex.h
+++ b/inc/ex.h
@@ -14,10 +14,10 @@ class EX : public Stage
* @return A newly allocated EX object.
*/
EX(Stage *next);
-
- InstrDTO *advance(Response p) override;
+ using Stage::advance;
private:
+ void advance_helper();
/**
* Maps each mnemonic to a function which carries out the instruction's base
* logic.
diff --git a/inc/id.h b/inc/id.h
index c5c1f1d..9911440 100644
--- a/inc/id.h
+++ b/inc/id.h
@@ -14,8 +14,7 @@ class ID : public Stage
* @return A newly allocated ID object.
*/
ID(Stage *next);
-
- InstrDTO *advance(Response p) override;
+ using Stage::advance;
/* The following methods are made public so that they may be tested, and are
* not to be called from outside classes during standard execution.
@@ -56,10 +55,7 @@ class ID : public Stage
void write_guard(signed int &r);
private:
- /**
- * Decodes `curr_instr` and sets status to BLOCKED if a data hazard occurs.
- */
- void advance_helper();
+ void advance_helper() override;
/**
* Helper for `get_instr_fields`
* Attempts to parse and dereference instruction arguments. Uses read and
diff --git a/inc/if.h b/inc/if.h
index d58b06a..63ca90e 100644
--- a/inc/if.h
+++ b/inc/if.h
@@ -18,14 +18,7 @@ class IF : public Stage
InstrDTO *advance(Response p) override;
private:
- /**
- * Performs a fetch only if a current fetch is not pending. Pending means
- * that a fetch has completed successfully, but the caller stage in the
- * pipeline is not ready to receive it. In this case, `curr_instr` is not
- * the nullptr.
- * @return STALLED if we are waiting on the storage devices, OK otherwise.
- */
- void advance_helper();
+ void advance_helper() override;
};
#endif /* IF_H_INCLUDED */
diff --git a/inc/mm.h b/inc/mm.h
index 6081802..cee3f17 100644
--- a/inc/mm.h
+++ b/inc/mm.h
@@ -13,8 +13,10 @@ class MM : public Stage
* @return A newly allocated MM object.
*/
MM(Stage *next);
+ using Stage::advance;
- InstrDTO *advance(Response p) override;
+ private:
+ void advance_helper() override;
};
#endif /* MM_H_INCLUDED */
diff --git a/inc/stage.h b/inc/stage.h
index c0dc6a8..56a3589 100644
--- a/inc/stage.h
+++ b/inc/stage.h
@@ -28,16 +28,26 @@ class Stage
virtual ~Stage();
/**
* Advances this stage by a single clock cycle.
+ * A boilerplate version is provided in stage.cc.
+ *
* @param a DTO object containing the next instruction to be processed.
* @param a response, indicating whether or not the parent pipe stage is
* ready to accept a new instruction object next cycle.
* @return a response, indicating whether this pipeline stage is stalling,
* busy, or done.
+ *
+ * Must set the status to STALLED when an operation completes.
*/
- virtual InstrDTO *advance(Response p) = 0;
+ virtual InstrDTO *advance(Response p);
protected:
/**
+ * The function expected to do the majority of the work.
+ *
+ * Must set the status to OK when an operation is ready.
+ */
+ virtual void advance_helper() = 0;
+ /**
* Sets the bit in the condition code register corresponding to `c`.
* @param the condition code to set.
* @param the truthy value to set it to.
diff --git a/inc/wb.h b/inc/wb.h
index 7c796ab..62cef17 100644
--- a/inc/wb.h
+++ b/inc/wb.h
@@ -13,8 +13,10 @@ class WB : public Stage
* @return A newly allocated WB object.
*/
WB(Stage *next);
-
- InstrDTO *advance(Response p) override;
+ using Stage::advance;
+
+ private:
+ void advance_helper() override;
};
#endif /* WB_H_INCLUDED */