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/>. */
26 #include <boost/dynamic_bitset.hpp>
39 /* concept from https://groups.google.com/group/comp.arch.embedded/msg/9d430b6d3da12c8f */
40 #define to_HEX__(x) 0x##x##LU
42 #define to_B5__(x) ((x & 0x0000FUL) ? 1 : 0) \
43 +((x & 0x000F0UL) ? 2 : 0) \
44 +((x & 0x00F00UL) ? 4 : 0) \
45 +((x & 0x0F000UL) ? 8 : 0) \
46 +((x & 0xF0000UL) ? 16 : 0)
48 #define B5(x) ((unsigned char)to_B5__(to_HEX__(x)))
52 using namespace boost;
75 short opcode, clockcount;
77 short m_ra, m_rb, m_rd;
78 bool m_c, m_d, m_hl, m_f, m_s;
81 boost::dynamic_bitset<> argbits;
83 Iinstr() : opcode(0), clockcount(1), name(""), m_ra(0), m_rb(0), m_rd(0), m_c(0), m_d(0), m_hl(0), m_f(0), m_s(0), m_imm(0), m_cond(ALWAYS), argbits(32), hexdump(0) {}
85 CDat generate16ImmFill(const CDat value) const {
87 if(m_hl == true && m_f == true) {
91 else if(m_hl == true && m_f == false) {
95 else if(m_hl == false && m_f == true) {
105 CDat generate16ImmSign(const CDat value) const {
110 else if(m_s == true && (i & 0x8000) != 0) {
117 CDat generate12ImmSign(const CDat value) const {
119 if(m_s == true && (i & 0x0800) != 0) {
126 CDat generate15ImmSign(const CDat value) const {
128 if(m_s == true && (i & 0x4000) != 0) {
137 int getRegister(boost::dynamic_bitset<> bits) {
139 return bits.to_ulong();
143 static disasm* m_disasm;
147 static void setCPU(CCpu* cpu) { m_cpu = cpu; }
148 static void setDisasm(disasm* dasm) { m_disasm = dasm; }
151 virtual short getOpcode() { return this->opcode; }
152 virtual std::string getName() { return this->name; }
153 virtual void loadBits(boost::dynamic_bitset<> bits) { argbits = bits; this->constructHex(); }
154 virtual void evalInstr() = 0;
155 virtual void execInstr() = 0;
156 virtual std::string toString() = 0;
157 virtual Iinstr* getNew() = 0;
159 unsigned long toNum() { return this->hexdump; }
161 short getCondition() {
165 short getClockCount() {
169 void decodeCondition(short condition) {
170 if(condition >= 0 && condition <= 15) {
174 throw std::string("Invalid Condition!");
182 hexdump = this->m_cond;
184 hexdump += this->opcode;
186 hexdump += this->argbits.to_ulong();
189 std::string getConditionFlag()
242 cerr << "What did you do? more than 16 values in 5 bits?!" << endl;