diff options
Diffstat (limited to 'inc')
| -rw-r--r-- | inc/controller.h | 9 | ||||
| -rw-r--r-- | inc/definitions.h | 6 | ||||
| -rw-r--r-- | inc/dum.h | 28 | ||||
| -rw-r--r-- | inc/ex.h | 14 | ||||
| -rw-r--r-- | inc/id.h | 8 | ||||
| -rw-r--r-- | inc/if.h | 9 | ||||
| -rw-r--r-- | inc/instr.h | 1 | ||||
| -rw-r--r-- | inc/mm.h | 4 | ||||
| -rw-r--r-- | inc/stage.h | 30 | ||||
| -rw-r--r-- | inc/wb.h | 6 | 
10 files changed, 92 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/definitions.h b/inc/definitions.h index 3238a8b..c81c4e3 100644 --- a/inc/definitions.h +++ b/inc/definitions.h @@ -77,6 +77,12 @@  #define OPCODE_SIZE 4  /** + * The maximum value an integer can hold. + * The minimum is always this number plus one negated. + */ +#define MAX_INT 2147483647 + +/**   * Return the N least-significant bits from integer K using a bit mask   * @param the integer to be parsed   * @param the number of bits to be parsed 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 */ @@ -3,6 +3,7 @@  #include "instrDTO.h"  #include "response.h"  #include "stage.h" +#include <unordered_map>  class EX : public Stage  { @@ -13,8 +14,19 @@ class EX : public Stage  	 * @return A newly allocated EX object.  	 */  	EX(Stage *next); +	using Stage::advance; -	InstrDTO *advance(Response p) override; +  private: +	void advance_helper(); +	/** +	 * Maps each mnemonic to a function which carries out the instruction's base +	 * logic. +	 * All instructions store the result into s1. +	 */ +	std::unordered_map< +		Mnemonic, +		std::function<void(signed int &s1, signed int s2)>> +		instr_map;  };  #endif /* EX_H_INCLUDED */ @@ -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 @@ -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/instr.h b/inc/instr.h index 08b4fd0..7fbb42b 100644 --- a/inc/instr.h +++ b/inc/instr.h @@ -49,7 +49,6 @@ namespace instr  {  // clang-format off  	extern const std::unordered_map<unsigned int, Mnemonic> mnemonic_map; -	extern const std::unordered_map<Mnemonic, std::function<void(signed int &s1, signed int &s2, signed int &s3)>> instr_map;  // clang-format on  } // namespace instr @@ -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 50c413a..56a3589 100644 --- a/inc/stage.h +++ b/inc/stage.h @@ -9,6 +9,13 @@  #include <deque>  #include <memory> +enum CC { +	GT, +	EQ, +	UF, +	OF, +}; +  class Stage  {    public: @@ -21,16 +28,37 @@ 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. +	 */ +	void set_condition(CC c, bool v); +	/** +	 * Gets the bit in the condition code register correspondng to `c`. +	 * @param the condition code to retrieve, +	 */ +	bool get_condition(CC c); +	/**  	 * Helper for `check_out`.  	 * Returns true if r are not checked out, false otherwise.  	 * @param a list of register numbers. @@ -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 */ | 
