From eaa87e9fcd90c00d6261cbdb854efb7a09467f1d Mon Sep 17 00:00:00 2001 From: bd Date: Thu, 27 Mar 2025 20:30:18 -0400 Subject: Instr, InstrDTO gets/sets, other structures required for decode --- inc/accessor.h | 3 +++ inc/ex.h | 7 ++++++- inc/id.h | 7 ++++++- inc/if.h | 14 +++++++------- inc/instr.h | 14 ++++++++++++++ inc/instrDTO.h | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- inc/mm.h | 7 ++++++- inc/stage.h | 9 +++++++-- inc/wb.h | 7 ++++++- 9 files changed, 114 insertions(+), 14 deletions(-) create mode 100644 inc/instr.h (limited to 'inc') 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 +#include + +namespace instr +{ +// clang-format off +extern const std::map>> 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 +#include class InstrDTO { @@ -14,26 +16,82 @@ class InstrDTO * @return if_cycle */ 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 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 class Stage @@ -26,14 +27,18 @@ class Stage virtual Response advance(InstrDTO &i) = 0; protected: + /** + * The name of the pipeline stage. + */ + Accessor id; /** * The shared pool of general-purpose integer registers. */ - static std::array gprs; + static std::array 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; }; -- cgit v1.2.3