*.o
*.so
*.d
+*.dthex
sim
void close_prog(const std::vector<std::string> &);
CCpu* Iinstr::m_cpu;
+disasm* Iinstr::m_disasm;
CCpu* global_cpu = NULL;
Iinstr::setCPU(&cpu);
+ disasm disasm(instr);
+
+ Iinstr::setDisasm(&disasm);
std::string str = "";
int addr = 0;
boost::char_separator<char> sep(";", "", boost::keep_empty_tokens);
boost::tokenizer<boost::char_separator<char> > tokens(str, sep);
- disasm disasm(instr);
while(getline(inFile, str)) {
int count = 0;
tokens.assign(str);
#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
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), 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) {}
CDat generate16ImmFill(const CDat value) const {
CDat i = value;
}
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;
}
protected:
+ void constructHex()
+ {
+ hexdump = this->m_cond;
+ hexdump <<= 5;
+ hexdump += this->opcode;
+ hexdump <<= 23;
+ hexdump += this->argbits.to_ulong();
+ }
+
std::string getConditionFlag()
{
stringstream cond;
CCpu* Iinstr::m_cpu;
+disasm* Iinstr::m_disasm;
int main(int argc, char* argv[])
{
string hex = "0x";
hex.append(str);
- unsigned int val = lexical_cast<uint32_from_hex>(hex);
+ CDat val = lexical_cast<uint32_from_hex>(hex);
+ return this->decodeNum(val);
+}
+
+Iinstr* disasm::decodeNum(CDat val)
+{
dynamic_bitset<> bits(32,val), opcode(32,val), condition(9), args(32);
args = opcode;
+#ifndef __DISASM_H__
+#define __DISASM_H__
+
#include <iostream>
#include <string>
#include <map>
#include "uint32_from_hex.hpp"
+
+class Iinstr;
+
#include "Iinstr.hpp"
using namespace std;
public:
disasm(std::map<short,Iinstr*> map) : instrs(map) {};
Iinstr* decode(std::string);
+ Iinstr* decodeNum(CDat);
std::string decodeToString(std::string str);
};
+#endif
--- /dev/null
+#include "../Iinstr.hpp"
+
+
+class Cldx : public Iinstr {
+ public:
+ Cldx();
+ 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 Cldx();
+}
+
+Iinstr* Cldx::getNew()
+{
+ return new Cldx();
+}
+
+/**
+ * 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;
+}
+
+Cldx::Cldx()
+{
+ opcode = B5(10100);
+ name = "ldx";
+}
+
+void Cldx::evalInstr()
+{
+ this->m_s = true;
+
+ dynamic_bitset<> immb = argbits;
+ immb.resize(15);
+ this->m_imm = this->generate15ImmSign(immb.to_ulong());
+
+ argbits >>= 15;
+ m_ra = this->getRegister(argbits);
+ argbits >>= 4;
+ m_rd = this->getRegister(argbits);
+
+}
+
+void Cldx::execInstr()
+{
+ //cout << "should exec " << this->toString() << endl;
+ CDat val = this->m_cpu->getRegister(this->m_ra);
+ val += m_imm;
+ this->m_cpu->setRegister(this->m_rd, this->m_cpu->getProg(val)->toNum());
+}
+
+std::string Cldx::toString()
+{
+ stringstream op;
+ op << this->getName();
+
+ op << this->getConditionFlag() << " r" << m_rd << ", " << m_imm << "(r" << m_ra << ")";
+
+ return op.str();
+}
--- /dev/null
+#include "../Iinstr.hpp"
+
+
+class Cstx : public Iinstr {
+ public:
+ Cstx();
+ 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 Cstx();
+}
+
+Iinstr* Cstx::getNew()
+{
+ return new Cstx();
+}
+
+/**
+ * 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;
+}
+
+Cstx::Cstx()
+{
+ opcode = B5(10101);
+ name = "stx";
+}
+
+void Cstx::evalInstr()
+{
+ this->m_s = true;
+
+ dynamic_bitset<> immb = argbits;
+ immb.resize(15);
+ this->m_imm = this->generate15ImmSign(immb.to_ulong());
+
+ argbits >>= 15;
+ m_ra = this->getRegister(argbits);
+ argbits >>= 4;
+ m_rd = this->getRegister(argbits);
+
+}
+
+void Cstx::execInstr()
+{
+ //cout << "should exec " << this->toString() << endl;
+ CDat val = this->m_cpu->getRegister(this->m_ra);
+ val += m_imm;
+ this->m_cpu->setProg(val, m_disasm->decodeNum(this->m_cpu->getRegister(this->m_rd)));
+}
+
+std::string Cstx::toString()
+{
+ stringstream op;
+ op << this->getName();
+
+ op << this->getConditionFlag() << " r" << m_rd << ", " << m_imm << "(r" << m_ra << ")";
+
+ return op.str();
+}