spartan3e: bootrom_v1.bit
[calu.git] / 3c_disasm / Iinstr.hpp
index 95b5229d94c9d997e8f508e4a0df133326ca91f0..e16c26c13a90200373d6de7e9af94d2d28a121f2 100644 (file)
@@ -1,10 +1,19 @@
+#ifndef __IINSTR_I_
+#define __IINSTR_I_
+
 #include <string>
 #include <boost/dynamic_bitset.hpp>
 #include <iostream>
 #include <sstream>
 
-#ifndef __IINSTR_I_
-#define __IINSTR_I_
+class CCpu;
+
+#include "ccpu.hpp"
+
+class disasm;
+
+#include "disasm.h"
+
 
 /* concept from https://groups.google.com/group/comp.arch.embedded/msg/9d430b6d3da12c8f */
 #define to_HEX__(x) 0x##x##LU
@@ -16,6 +25,7 @@
                   +((x & 0xF0000UL) ? 16 : 0) 
 
 #define B5(x) ((unsigned char)to_B5__(to_HEX__(x)))
+/* end concept */
 
 using namespace std;
 using namespace boost;
@@ -41,17 +51,18 @@ enum CONDITIONS {
 
 class Iinstr {
        protected:
-               short opcode;
+               short opcode, clockcount;
                std::string name;
                short m_ra, m_rb, m_rd;
                bool m_c, m_d, m_hl, m_f, m_s;
-               int m_imm;
+               CDat m_imm;
                short m_cond;
                boost::dynamic_bitset<> argbits;
-               Iinstr() : opcode(0), 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) {}
+               CDat hexdump;
+               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) {}
 
-               int generate16ImmFill(const int value) { 
-                       int i = value;
+               CDat generate16ImmFill(const CDat value) const {
+                       CDat i = value;
                        if(m_hl == true && m_f == true) {
                                i <<= 16;
                                i |= 0x0000FFFF;
@@ -70,8 +81,8 @@ class Iinstr {
                        return i; 
                }
 
-               int generate16ImmSign(const int value) { 
-                       int i = value;
+               CDat generate16ImmSign(const CDat value) const {
+                       CDat i = value;
                        if(m_hl == true) {
                                i <<= 16;
                        }
@@ -82,8 +93,8 @@ class Iinstr {
                        return i; 
                }
 
-               int generate12ImmSign(const int value) { 
-                       int i = value;
+               CDat generate12ImmSign(const CDat value) const {
+                       CDat i = value;
                        if(m_s == true && (i & 0x0800) != 0) {
                                        i |= 0xFFFFF000;
                        }
@@ -91,8 +102,8 @@ class Iinstr {
                        return i; 
                }
 
-               int generate15ImmSign(const int value) { 
-                       int i = value;
+               CDat generate15ImmSign(const CDat value) const {
+                       CDat i = value;
                        if(m_s == true && (i & 0x4000) != 0) {
                                        i |= 0xFFFF8000;
                        }
@@ -107,14 +118,32 @@ class Iinstr {
                        return bits.to_ulong();
                }
 
+               static CCpu* m_cpu;
+               static disasm* m_disasm;
+
        public:
+
+               static void setCPU(CCpu* cpu) { m_cpu = cpu; }
+               static void setDisasm(disasm* dasm) { m_disasm = dasm; }
+
                virtual ~Iinstr() {}
                virtual short getOpcode() { return this->opcode; }
                virtual std::string getName() { return this->name; }
-               virtual void loadBits(boost::dynamic_bitset<> bits) { argbits = bits; }
+               virtual void loadBits(boost::dynamic_bitset<> bits) { argbits = bits; this->constructHex(); }
                virtual void evalInstr() = 0;
                virtual void execInstr() = 0;
                virtual std::string toString() = 0;
+               virtual Iinstr* getNew() = 0;
+
+               unsigned long toNum() { return this->hexdump; }
+
+               short getCondition() {
+                       return m_cond;
+               }
+
+               short getClockCount() {
+                       return clockcount;
+               }
 
                void decodeCondition(short condition) {
                        if(condition >= 0 && condition <= 15) {
@@ -126,6 +155,16 @@ class Iinstr {
                }
 
        protected:
+
+               void constructHex()
+               {
+                       hexdump = this->m_cond;
+                       hexdump <<= 5;
+                       hexdump += this->opcode;
+                       hexdump <<= 23;
+                       hexdump += this->argbits.to_ulong();
+               }
+
                std::string getConditionFlag()
                {
                        stringstream cond;
@@ -185,4 +224,5 @@ class Iinstr {
                        return cond.str();
                }
 };
+
 #endif