1 /* `Deep Thought', a softcore CPU implemented on a FPGA
3 Copyright (C) 2010 Markus Hofstaetter <markus.manrow@gmx.at>
4 Copyright (C) 2010 Martin Perner <e0725782@student.tuwien.ac.at>
5 Copyright (C) 2010 Stefan Rebernig <stefan.rebernig@gmail.com>
6 Copyright (C) 2010 Manfred Schwarz <e0725898@student.tuwien.ac.at>
7 Copyright (C) 2010 Bernhard Urban <lewurm@gmail.com>
9 This program is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include "../Iinstr.hpp"
24 class Cshift : public Iinstr {
30 std::string toString();
35 * Name: create_instruction
36 * Purpose: if compiled as shared library, this functions creates the
39 * Returns: pointer to instruction object
41 extern "C" Iinstr* create_instruction() {
45 Iinstr* Cshift::getNew()
50 * Name: destroy_instruction
51 * Purpose: if compiled as shared library, this functions destoys the
54 * Parameter: IInstruction - the instruction object to delete
56 extern "C" void destroy_instruction(Iinstr* p) {
60 Cshift::Cshift() : m_typ(0)
66 void Cshift::evalInstr()
68 this->m_d = argbits[0];
69 this->m_c = argbits[1];
72 dynamic_bitset<> type = argbits;
74 this->m_typ = type.to_ulong();
78 cerr << "INVALID shift type, using logic left shift!" << endl;
90 cerr << "What have you done? 2 bits that have more than 4 values?!" << endl;
94 dynamic_bitset<> immb = argbits;
96 this->m_imm = immb.to_ulong();
98 m_ra = this->getRegister(argbits);
100 m_rd = this->getRegister(argbits);
103 void Cshift::execInstr()
105 CDatd val = this->m_cpu->getRegister(m_ra);
106 switch(this->m_typ) {
109 // this->name = "lls";
110 for(unsigned int i = 0; i < m_imm; i++) {
115 this->m_cpu->updateCarry(((val >> BIT_LEN) & 0x1) != 0);
119 // this->name = "lrs";
121 bool carry = this->m_cpu->getCarry();
122 for(unsigned int i = 0; i < m_imm; i++) {
126 //if user wants carry, and carry is set
127 if(this->m_c && carry) {
129 val |= (CDat)(1<<(BIT_LEN-1));
133 val &= (~(1<<(BIT_LEN-1)));
139 // this->name = "ars";
140 //>> is a ars, but val is CDatd => we have to set the MSB manually
142 bool msb = (val & (1<<(BIT_LEN-1)) >> (BIT_LEN-1));
143 for(unsigned int i = 0; i < m_imm; i++) {
147 val |= (CDat)(1<<(BIT_LEN-1));
151 val &= (~(1<<(BIT_LEN-1)));
157 cerr << "What have you done? 2 bits that have more than 4 values?!" << endl;
159 this->m_cpu->setRegister(m_rd, val);
162 std::string Cshift::toString()
165 op << this->getName();
169 op << this->getConditionFlag();
170 op << " r" << m_rd << ", r" << m_ra << ", " << m_imm;