/* `Deep Thought', a softcore CPU implemented on a FPGA Copyright (C) 2010 Markus Hofstaetter Copyright (C) 2010 Martin Perner Copyright (C) 2010 Stefan Rebernig Copyright (C) 2010 Manfred Schwarz Copyright (C) 2010 Bernhard Urban 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 . */ #include "../Iinstr.hpp" class Cbranchreg : public Iinstr { private: bool m_taken; char m_typ; public: Cbranchreg(); void evalInstr(); void execInstr(); std::string toString(); Iinstr* getNew(); }; /** * Name: create_instruction * Purpose: if compiled as shared library, this functions creates the instruction object * Returns: pointer to instruction object */ extern "C" Iinstr* create_instruction() { return new Cbranchreg(); } Iinstr* Cbranchreg::getNew() { return new Cbranchreg(); } /** * Name: destroy_instruction * Purpose: if compiled as shared library, this functions destoys the instruction object * Parameter: IInstruction - the instruction object to delete */ extern "C" void destroy_instruction(Iinstr* p) { delete p; } Cbranchreg::Cbranchreg() : m_taken(1), m_typ(0) { opcode = B5(10111); name = "branchreg"; } void Cbranchreg::evalInstr() { argbits >>= 2; dynamic_bitset<> type = argbits; type.resize(1); this->m_typ = type.to_ulong(); switch(this->m_typ) { case 0: this->name = "brr"; break; case 1: this->name = "callr"; break; default: cerr << "What have you done? 1 bits that have more than 2 values?!" << endl; } argbits >>= 17; m_rd = this->getRegister(argbits); } void Cbranchreg::execInstr() { //cout << "should exec " << this->toString() << endl; CDat pc = this->m_cpu->getRegister(this->m_rd); pc *= 4; //komisch fix? if(this->m_typ == 1) { CDat sp = this->m_cpu->getStack(); sp -= 4; this->m_cpu->setRAM(sp, this->m_cpu->getNextPC()); this->m_cpu->setStack(sp); } this->m_cpu->setNextPC(pc); } std::string Cbranchreg::toString() { stringstream op; op << this->getName(); op << this->getConditionFlag(); op << " r" << m_rd; return op.str(); }