diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/controller.cc (renamed from src/sim/controller.cc) | 4 | ||||
| -rw-r--r-- | src/ex.cc (renamed from src/sim/ex.cc) | 16 | ||||
| -rw-r--r-- | src/id.cc (renamed from src/sim/id.cc) | 38 | ||||
| -rw-r--r-- | src/if.cc (renamed from src/sim/if.cc) | 23 | ||||
| -rw-r--r-- | src/instr.cc (renamed from src/sim/instr.cc) | 0 | ||||
| -rw-r--r-- | src/logger.cc (renamed from src/logger/logger.cc) | 0 | ||||
| -rw-r--r-- | src/mm.cc (renamed from src/sim/mm.cc) | 17 | ||||
| -rw-r--r-- | src/response.cc (renamed from src/utils/response.cc) | 2 | ||||
| -rw-r--r-- | src/sim/dum.cc | 44 | ||||
| -rw-r--r-- | src/sim/instrDTO.cc | 71 | ||||
| -rw-r--r-- | src/stage.cc (renamed from src/sim/stage.cc) | 31 | ||||
| -rw-r--r-- | src/utils/accessor.cc | 27 | ||||
| -rw-r--r-- | src/wb.cc (renamed from src/sim/wb.cc) | 38 | 
13 files changed, 60 insertions, 251 deletions
| diff --git a/src/sim/controller.cc b/src/controller.cc index 59fbbb7..8df4b97 100644 --- a/src/sim/controller.cc +++ b/src/controller.cc @@ -31,8 +31,6 @@ Controller::Controller(Stage *stage, Storage *storage, bool is_pipelined)  	this->checked_out = {};  	this->gprs = {0};  	this->gprs.at(2) = MEM_WORDS; // set the stack pointer -	// grant side-door access -	this->id = SIDE;  }  void Controller::run_for(int number) @@ -40,7 +38,7 @@ void Controller::run_for(int number)  	int i;  	for (i = 0; i < number; ++i) {  		try { -			this->advance(WAIT); +			this->advance(READY);  		} catch (HaltException &e) {  			break;  		} diff --git a/src/sim/ex.cc b/src/ex.cc index d345ecf..eac24ff 100644 --- a/src/sim/ex.cc +++ b/src/ex.cc @@ -16,7 +16,6 @@  // along with this program.  If not, see <https://www.gnu.org/licenses/>.  #include "ex.h" -#include "accessor.h"  #include "instrDTO.h"  #include "pipe_spec.h"  #include "response.h" @@ -32,7 +31,6 @@  EX::EX(Stage *stage) : Stage(stage)  { -	this->id = EXEC;  	instr_map = {  		/* R type instructions */ @@ -424,15 +422,15 @@ void EX::advance_helper()  	unsigned int pc;  	Mnemonic m; -	m = this->curr_instr->get_mnemonic(); -	s1 = this->curr_instr->get_s1(); -	s2 = this->curr_instr->get_s2(); -	s3 = this->curr_instr->get_s3(); -	pc = this->curr_instr->get_pc(); +	m = this->curr_instr->mnemonic; +	s1 = this->curr_instr->operands.integer.slot_one; +	s2 = this->curr_instr->operands.integer.slot_two; +	s3 = this->curr_instr->operands.integer.slot_three; +	pc = this->curr_instr->slot_B;  	this->instr_map[m](s1, s2, s3, pc); -	this->curr_instr->set_s1(s1); +	this->curr_instr->operands.integer.slot_one = s1;  	this->status = OK;  } @@ -442,7 +440,7 @@ void EX::handle_divide(signed int &s1, signed int s2, bool is_mod)  	this->set_condition(UF, false);  	if (s2 == 0) {  		// handle everything here -		this->curr_instr->set_s1(MAX_INT); +		this->curr_instr->operands.integer.slot_one = MAX_INT;  		this->status = OK;  		throw HaltException();  	} else if ((s1 == -(MAX_INT)-1) && s2 == -1) { diff --git a/src/sim/id.cc b/src/id.cc index cdbaba9..d2a8f02 100644 --- a/src/sim/id.cc +++ b/src/id.cc @@ -16,15 +16,12 @@  // along with this program.  If not, see <https://www.gnu.org/licenses/>.  #include "id.h" -#include "accessor.h"  #include "instr.h"  #include "instrDTO.h"  #include "logger.h"  #include "response.h"  #include "stage.h" -ID::ID(Stage *stage) : Stage(stage) { this->id = DCDE; } -  void ID::split_instr(signed int &raw, unsigned int &type, Mnemonic &m)  {  	unsigned int opcode, opcode_size; @@ -60,7 +57,7 @@ void ID::write_guard(signed int &v)  		// keep track in the instrDTO for displaying to user and writeback  		// keep track in checked_out so we can still access this information!  		this->checked_out.push_back(v); -		this->curr_instr->set_checked_out(v); +		this->curr_instr->checked_out = v;  	}  	v = this->dereference_register(v);  } @@ -69,44 +66,39 @@ void ID::advance_helper()  {  	signed int s1, s2, s3;  	Mnemonic m; -	Type t; -	if (curr_instr->get_mnemonic() == NOP) +	if (curr_instr->mnemonic == NOP)  		this->status = OK;  	else { -		s1 = curr_instr->get_instr_bits(); -		get_instr_fields(s1, s2, s3, m, t); +		s1 = curr_instr->slot_A; +		get_instr_fields(s1, s2, s3, m);  		if (this->status == OK) { -			curr_instr->set_s1(s1); -			curr_instr->set_s2(s2); -			curr_instr->set_s3(s3); -			curr_instr->set_mnemonic(m); -			curr_instr->set_type(t); +			curr_instr->operands.integer.slot_one = s1; +			curr_instr->operands.integer.slot_two = s2; +			curr_instr->operands.integer.slot_three = s3; +			curr_instr->mnemonic = m;  		}  	}  }  void ID::get_instr_fields( -	signed int &s1, signed int &s2, signed int &s3, Mnemonic &m, Type &t) +	signed int &s1, signed int &s2, signed int &s3, Mnemonic &m)  {  	unsigned int type;  	this->split_instr(s1, type, m);  	switch (type) {  	case 0b00: -		t = R;  		this->decode_R_type(s1, s2, s3, m);  		break;  	case 0b01: -		t = I;  		this->decode_I_type(s1, s2, s3, m);  		break;  	case 0b10: -		t = J;  		this->decode_J_type(s1, s2, s3, m);  		break;  	case 0b11: -		t = INV; +		m = NOP;  		this->status = OK;  	}  } @@ -219,13 +211,3 @@ void ID::decode_J_type(  	}  } - -std::vector<int> ID::stage_info() -{ -	std::vector<int> info; -	if (this->curr_instr) { -		info.push_back(this->curr_instr->is_squashed()); -		info.push_back(this->curr_instr->get_instr_bits()); -	} -	return info; -} diff --git a/src/sim/if.cc b/src/if.cc index e8e7272..0f622d4 100644 --- a/src/sim/if.cc +++ b/src/if.cc @@ -16,21 +16,18 @@  // along with this program.  If not, see <https://www.gnu.org/licenses/>.  #include "if.h" -#include "accessor.h"  #include "instrDTO.h"  #include "response.h"  #include "stage.h" -IF::IF(Stage *stage) : Stage(stage) { this->id = FETCH; } -  InstrDTO *IF::advance(Response p)  {  	InstrDTO *r = nullptr;  	this->advance_helper(); -	if (this->curr_instr != nullptr && p == WAIT) { +	if (this->curr_instr != nullptr && p == READY) {  		// don't increment PC if the PC was just set by wb -		if (this->curr_instr->is_squashed() != 1) +		if (this->curr_instr->is_squashed != 1)  			++this->pc;  		r = new InstrDTO(*this->curr_instr);  		delete curr_instr; @@ -40,15 +37,6 @@ InstrDTO *IF::advance(Response p)  	return r;  } -std::vector<int> IF::stage_info() { -	std::vector<int> info; -	if(this->curr_instr){ -		info.push_back(this->curr_instr->is_squashed()); -		info.push_back(this->curr_instr->get_instr_bits()); -	} -	return info; -} -  void IF::advance_helper()  {  	Response r; @@ -60,8 +48,11 @@ void IF::advance_helper()  		r = i ? OK : STALLED;  		if (r == OK) {  			this->curr_instr = new InstrDTO(); -			this->curr_instr->set_instr_bits(bits); -			this->curr_instr->set_pc(this->pc); +			this->curr_instr->slot_A = bits; +			this->curr_instr->slot_B = this->pc; +			this->curr_instr->is_squashed = 0; +			this->curr_instr->checked_out = -1; +			this->curr_instr->mnemonic = ADD;  			this->is_empty = false;  		}  	} diff --git a/src/sim/instr.cc b/src/instr.cc index 9bd951b..9bd951b 100644 --- a/src/sim/instr.cc +++ b/src/instr.cc diff --git a/src/logger/logger.cc b/src/logger.cc index a665dcd..a665dcd 100644 --- a/src/logger/logger.cc +++ b/src/logger.cc diff --git a/src/sim/mm.cc b/src/mm.cc index e1057d5..ac77433 100644 --- a/src/sim/mm.cc +++ b/src/mm.cc @@ -16,24 +16,22 @@  // along with this program.  If not, see <https://www.gnu.org/licenses/>.  #include "mm.h" -#include "accessor.h"  #include "instrDTO.h"  #include "response.h"  #include "stage.h" -MM::MM(Stage *stage) : Stage(stage) { this->id = MEM; } -  void MM::advance_helper()  {  	signed int data;  	int i; -	switch (this->curr_instr->get_mnemonic()) { +	switch (this->curr_instr->mnemonic) {  	case LOAD: -		i = this->storage->read_word(this, this->curr_instr->get_s1(), data); +		i = this->storage->read_word( +			this, this->curr_instr->operands.integer.slot_one, data);  		this->status = i ? OK : STALLED;  		if (this->status == OK) { -			this->curr_instr->set_s1(data); +			this->curr_instr->operands.integer.slot_one = data;  		} else  			this->status = STALLED;  		break; @@ -41,7 +39,8 @@ void MM::advance_helper()  	case PUSH:  	case STORE:  		i = this->storage->write_word( -			this, this->curr_instr->get_s2(), this->curr_instr->get_s1()); +			this, this->curr_instr->operands.integer.slot_two, +			this->curr_instr->operands.integer.slot_one);  		this->status = i ? OK : STALLED;  		if (this->status != OK) {  			this->status = STALLED; @@ -49,10 +48,10 @@ void MM::advance_helper()  		break;  	case POP: -		i = this->storage->read_word(this, this->curr_instr->get_s3(), data); +		i = this->storage->read_word(this, this->curr_instr->operands.integer.slot_three, data);  		this->status = i ? OK : STALLED;  		if (this->status == OK) { -			this->curr_instr->set_s3(data); +			this->curr_instr->operands.integer.slot_three = data;  		} else  			this->status = STALLED;  		break; diff --git a/src/utils/response.cc b/src/response.cc index d56419a..7624b82 100644 --- a/src/utils/response.cc +++ b/src/response.cc @@ -20,6 +20,6 @@  std::ostream &operator<<(std::ostream &os, Response r)  { -	const std::string nameR[] = {"OK", "WAIT", "BLOCKED", "STALLED"}; +	const std::string nameR[] = {"OK", "READY", "STALLED"};  	return os << nameR[r];  } diff --git a/src/sim/dum.cc b/src/sim/dum.cc deleted file mode 100644 index 744c110..0000000 --- a/src/sim/dum.cc +++ /dev/null @@ -1,44 +0,0 @@ -// Simulator for the RISC-V[ECTOR] mini-ISA -// Copyright (C) 2025 Siddarth Suresh -// Copyright (C) 2025 bdunahu - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program.  If not, see <https://www.gnu.org/licenses/>. - -#include "dum.h" -#include "accessor.h" -#include "instrDTO.h" -#include "response.h" -#include "stage.h" - -DUM::DUM(Stage *stage) : Stage(stage) { this->id = IDLE; } - -InstrDTO *DUM::advance(Response p) -{ -	InstrDTO *r = nullptr; - -	if (this->curr_instr && p == WAIT) { -		r = new InstrDTO(*this->curr_instr); -		delete this->curr_instr; -		curr_instr = nullptr; -	} - -	return r; -} - -void DUM::advance_helper() {} - -void DUM::set_curr_instr(InstrDTO *d) -{ -	this->curr_instr = d; -} diff --git a/src/sim/instrDTO.cc b/src/sim/instrDTO.cc deleted file mode 100644 index 00b6d5f..0000000 --- a/src/sim/instrDTO.cc +++ /dev/null @@ -1,71 +0,0 @@ -// Simulator for the RISC-V[ECTOR] mini-ISA -// Copyright (C) 2025 Siddarth Suresh -// Copyright (C) 2025 bdunahu - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program.  If not, see <https://www.gnu.org/licenses/>. - -#include "instrDTO.h" -#include "accessor.h" - -InstrDTO::InstrDTO() -{ -	this->instr_bits = 0; -	this->checked_out = -1; -	this->s1 = 0; -	this->s2 = 0; -	this->s3 = 0; -	this->mnemonic = ADD; -	this->type = INV; -	this->pc = 0; -	this->squashed = 0; -} - -signed int InstrDTO::get_instr_bits() { return this->instr_bits; } - -signed int InstrDTO::get_checked_out() { return this->checked_out; } - -signed int InstrDTO::get_s1() { return this->s1; } - -signed int InstrDTO::get_s2() { return this->s2; } - -signed int InstrDTO::get_s3() { return this->s3; } - -Mnemonic InstrDTO::get_mnemonic() { return this->mnemonic; } - -Type InstrDTO::get_type() { return this->type; } - -unsigned int InstrDTO::get_pc() { return this->pc; } - -int InstrDTO::is_squashed() { return this->squashed; } - -void InstrDTO::set_instr_bits(signed int instr) { this->instr_bits = instr; } - -void InstrDTO::set_checked_out(signed int checked_out) -{ -	this->checked_out = checked_out; -} - -void InstrDTO::set_s1(signed int s) { this->s1 = s; } - -void InstrDTO::set_s2(signed int s) { this->s2 = s; } - -void InstrDTO::set_s3(signed int s) { this->s3 = s; } - -void InstrDTO::set_mnemonic(Mnemonic m) { this->mnemonic = m; } - -void InstrDTO::set_type(Type t) { this->type = t; } - -void InstrDTO::set_pc(unsigned int pc) { this->pc = pc; } - -void InstrDTO::squash() { this->squashed = 1; } diff --git a/src/sim/stage.cc b/src/stage.cc index 35c6936..4efe2fe 100644 --- a/src/sim/stage.cc +++ b/src/stage.cc @@ -23,7 +23,7 @@ Stage::Stage(Stage *next)  {  	this->next = next;  	this->curr_instr = nullptr; -	this->status = WAIT; +	this->status = READY;  }  Stage::~Stage() { delete this->next; }; @@ -45,44 +45,27 @@ InstrDTO *Stage::advance(Response p)  	InstrDTO *s = nullptr;  	Response n; -	// std::cout << "advance: " << this->id << ": " << this->curr_instr << "?: " -	// << p << ": " << this->checked_out.size() << ": "; if (curr_instr) -	// 	std::cout << curr_instr->get_mnemonic(); -	// for (long unsigned int i = 0; i < this->checked_out.size(); ++i) -	// 	std::cout << this->checked_out[i] << " "; -	// std::cout << std::endl; -	if (this->curr_instr && this->curr_instr->is_squashed() == 1) +	if (this->curr_instr && this->curr_instr->is_squashed == 1)  		this->status = OK;  	if (this->curr_instr && this->status != OK) {  		this->advance_helper();  	} -	if (this->status == OK && p == WAIT && this->curr_instr) { +	if (this->status == OK && p == READY && this->curr_instr) {  		// mutual consent  		r = new InstrDTO(*this->curr_instr);  		delete curr_instr;  		curr_instr = nullptr; -		this->status = WAIT; +		this->status = READY;  	} -	n = (p != WAIT || this->status != WAIT) ? STALLED : WAIT; +	n = (p != READY || this->status != READY) ? STALLED : READY;  	s = this->next->advance(n);  	if (s)  		this->curr_instr = s;  	return r;  } -std::vector<int> Stage::stage_info() -{ -	std::vector<int> info; -	if (this->curr_instr) { -		info.push_back(this->curr_instr->get_mnemonic()); -		info.push_back(this->curr_instr->is_squashed()); -		info.push_back(this->curr_instr->get_s1()); -		info.push_back(this->curr_instr->get_s2()); -		info.push_back(this->curr_instr->get_s3()); -	} -	return info; -} +InstrDTO *Stage::get_instr() { return this->curr_instr; }  void Stage::set_condition(CC c, bool v)  { @@ -127,7 +110,7 @@ bool Stage::is_checked_out(signed int r)  void Stage::squash()  {  	if (curr_instr) { -		this->curr_instr->squash(); +		this->curr_instr->is_squashed = 1;  		this->status = OK;  	}  	if (this->next) { diff --git a/src/utils/accessor.cc b/src/utils/accessor.cc deleted file mode 100644 index c49a2b2..0000000 --- a/src/utils/accessor.cc +++ /dev/null @@ -1,27 +0,0 @@ -// Simulator for the RISC-V[ECTOR] mini-ISA -// Copyright (C) 2025 Siddarth Suresh -// Copyright (C) 2025 bdunahu - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program.  If not, see <https://www.gnu.org/licenses/>. - -#include "accessor.h" -#include <iostream> - -std::ostream &operator<<(std::ostream &os, Accessor a) -{ -	const std::string nameA[] = { -		"IDLE", "WRITE", "MEM", "EXEC", "DCDE", "FETCH", "L1CACHE", "SIDE", -	}; -	return os << nameA[a]; -} diff --git a/src/sim/wb.cc b/src/wb.cc index 0348b51..cd24c6a 100644 --- a/src/sim/wb.cc +++ b/src/wb.cc @@ -16,20 +16,16 @@  // along with this program.  If not, see <https://www.gnu.org/licenses/>.  #include "wb.h" -#include "accessor.h"  #include "instrDTO.h"  #include "response.h"  #include "stage.h" -#include <array>  #include <algorithm> - -WB::WB(Stage *stage) : Stage(stage) { this->id = WRITE; } +#include <array>  void WB::advance_helper()  { -	if (this->curr_instr->get_mnemonic() != NOP && -		this->curr_instr->get_type() != INV) { -		if (this->curr_instr->get_checked_out() > 0) +	if (this->curr_instr->mnemonic != NOP) { +		if (this->curr_instr->checked_out > 0)  			this->write_handler();  		else if (this->should_jump())  			this->jump_handler(); @@ -45,34 +41,38 @@ void WB::write_handler()  		throw std::runtime_error("instruction tried to pop a register out of "  								 "an empty queue during writeback."); -	if (this->curr_instr->get_mnemonic() == POP) { +	if (this->curr_instr->mnemonic == POP) {  		// POP performs a second register write  		reg = this->checked_out.front();  		this->checked_out.pop_front(); -		this->store_register(reg, this->curr_instr->get_s3()); +		this->store_register( +			reg, this->curr_instr->operands.integer.slot_three);  	}  	this->checked_out.pop_front(); -	reg = this->curr_instr->get_checked_out(); -	this->store_register(reg, this->curr_instr->get_s1()); - +	reg = this->curr_instr->checked_out; +	this->store_register(reg, this->curr_instr->operands.integer.slot_one);  }  void WB::jump_handler()  { -	if (this->curr_instr->get_s1() > 0) { -		if (this->curr_instr->get_mnemonic() == JAL) -			this->gprs[1] = this->curr_instr->get_pc() + 1;; -		this->pc = this->curr_instr->get_s1(); +	if (this->curr_instr->operands.integer.slot_one > 0) { +		if (this->curr_instr->mnemonic == JAL) +			this->gprs[1] = this->curr_instr->slot_B + 1; +		; +		this->pc = this->curr_instr->operands.integer.slot_one;  		this->checked_out = {};  		this->next->squash();  	}  } +// TODO clean this up...  bool WB::should_jump()  { -	Type t; +	vector<Mnemonic> Js = {JMP, JRL, JAL, BEQ, BGT, BUF, BOF, PUSH, POP, RET}; -	t = this->curr_instr->get_type(); -	return t == J; +	if (find(Js.begin(), Js.end(), this->curr_instr->mnemonic) != Js.end()) +		return true; +	else +		return false;  } | 
