summaryrefslogtreecommitdiff
path: root/inc
diff options
context:
space:
mode:
Diffstat (limited to 'inc')
-rw-r--r--inc/ex.h2
-rw-r--r--inc/id.h4
-rw-r--r--inc/instr.h8
-rw-r--r--inc/instrDTO.h15
-rw-r--r--inc/stage.h35
-rw-r--r--inc/wb.h20
6 files changed, 55 insertions, 29 deletions
diff --git a/inc/ex.h b/inc/ex.h
index 6d4254e..e4c9d2b 100644
--- a/inc/ex.h
+++ b/inc/ex.h
@@ -25,7 +25,7 @@ class EX : public Stage
*/
std::unordered_map<
Mnemonic,
- std::function<void(signed int &s1, signed int s2, signed int s3)>>
+ std::function<void(signed int &s1, signed int s2, signed int s3, unsigned int pc)>>
instr_map;
};
diff --git a/inc/id.h b/inc/id.h
index ebbe290..fd8c874 100644
--- a/inc/id.h
+++ b/inc/id.h
@@ -66,8 +66,8 @@ class ID : public Stage
*/
void get_instr_fields(signed int &s1, signed int &s2, signed int &s3, Mnemonic &m, Type &t);
void decode_R_type(signed int &s1, signed int &s2, signed int &s3);
- void decode_I_type(signed int &s1, signed int &s2, signed int &s3);
- void decode_J_type(signed int &s1, signed int &s2);
+ void decode_I_type(signed int &s1, signed int &s2, signed int &s3, Mnemonic &m);
+ void decode_J_type(signed int &s1, signed int &s2, signed int &s3);
/**
* Helper for `get_instr_fields`.
* Given a raw instruction, returns the mnemonic and type.
diff --git a/inc/instr.h b/inc/instr.h
index d17613d..2b1807a 100644
--- a/inc/instr.h
+++ b/inc/instr.h
@@ -1,7 +1,6 @@
#ifndef INSTR_H
#define INSTR_H
#include <functional>
-#include <iostream>
#include <unordered_map>
enum Mnemonic {
@@ -45,12 +44,7 @@ enum Mnemonic {
NOP,
};
-enum Type {
- R,
- I,
- J,
- INV
-};
+enum Type { R, I, J, INV };
namespace instr
{
diff --git a/inc/instrDTO.h b/inc/instrDTO.h
index 8249122..b6dec06 100644
--- a/inc/instrDTO.h
+++ b/inc/instrDTO.h
@@ -47,6 +47,10 @@ class InstrDTO
* @return the type of the instruction
*/
Type get_type();
+ /**
+ * @return the program counter at the time this instruction was fetched
+ */
+ unsigned int get_pc();
/**
* @param set hist key
@@ -72,11 +76,15 @@ class InstrDTO
* @param the mnemonic of the instruction
*/
void set_mnemonic(Mnemonic);
-
+
/**
* @param the type of the instruction
*/
void set_type(Type);
+ /**
+ * @param the program counter at the time this instruction was fetched
+ */
+ void set_pc(unsigned int pc);
private:
/**
@@ -100,11 +108,14 @@ class InstrDTO
* The mnemonic of the operation.
*/
Mnemonic mnemonic;
-
/**
* Type of the instruction
*/
Type type;
+ /**
+ * The PC of the instruction
+ */
+ unsigned int pc;
};
#endif /* INSTRDTO_H_INCLUDED */
diff --git a/inc/stage.h b/inc/stage.h
index 03048b0..51ab667 100644
--- a/inc/stage.h
+++ b/inc/stage.h
@@ -34,7 +34,7 @@ class Stage
* ready to accept a new instruction object next cycle.
* @return a DTO object containing the next instruction to be processed.
*
- * Must set the status to STALLED when an operation completes.
+ * Must set the status to WAIT when the current instruction is evicted..
*/
virtual InstrDTO *advance(Response p);
@@ -47,31 +47,33 @@ class Stage
* @param the condition code to retrieve,
*/
bool get_condition(CC c);
-
/**
- * Sets the value of the PC register.
+ * 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.
*/
- void set_pc(unsigned int pc);
+ void set_condition(CC c, bool v);
/**
* Squashes the pipeline.
*/
void squash();
+ /**
+ * The set of registers currently checked out.
+ */
+ static std::deque<signed int> checked_out;
+
protected:
/**
* The function expected to do the majority of the work.
*
- * Must set the status to OK when an operation is ready.
+ * Must set the status to OK when an operation is done.
+ * Must set the status to STALLED when an operation cannot be completed the
+ * current cycle.
*/
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.
- */
- void set_condition(CC c, bool v);
- /**
* Helper for `check_out`.
* Returns true if r are not checked out, false otherwise.
* @param a list of register numbers.
@@ -79,6 +81,12 @@ class Stage
*/
bool is_checked_out(signed int r);
/**
+ * Stores `d` into the register indexed `v`.
+ * @param the register number.
+ * @param the value to store.
+ */
+ void store_register(signed int v, signed int d);
+ /**
* Returns the value of the register corresponding to `v`.
* @param the register number.
* @return the value in the associated register.
@@ -112,11 +120,6 @@ class Stage
* The current clock cycle.
*/
static int clock_cycle;
- // TODO fix this comment after writeback stage
- /**
- * The set of registers currently checked out.
- */
- static std::deque<signed int> checked_out;
/**
* A pointer to the next stage in the pipeline.
*/
diff --git a/inc/wb.h b/inc/wb.h
index 62cef17..c4755ea 100644
--- a/inc/wb.h
+++ b/inc/wb.h
@@ -14,9 +14,27 @@ class WB : public Stage
*/
WB(Stage *next);
using Stage::advance;
-
+
private:
void advance_helper() override;
+ /**
+ * Performs the actual work of storing into a register.
+ */
+ void write_handler();
+ /**
+ * Performs the actual work of processing a jump instruction.
+ */
+ void jump_handler();
+ /**
+ * @return true if the current instruction is an R or I type and is not a
+ * STORE.
+ */
+ bool should_write();
+ /**
+ * @return true if the current instruction is a J type and is not a push.
+ * STORE.
+ */
+ bool should_jump();
};
#endif /* WB_H_INCLUDED */