From: Martin Perner Date: Sun, 31 Oct 2010 22:27:40 +0000 (+0100) Subject: sim: new instructions, bugfix in others X-Git-Tag: bootrom_v1~217 X-Git-Url: http://wien.tomnetworks.com/gitweb/?p=calu.git;a=commitdiff_plain;h=f7afa120e8de972b9afb88125fb7dc49fcfccbbe sim: new instructions, bugfix in others not tested! --- diff --git a/3c_disasm/instr/add.cpp b/3c_disasm/instr/add.cpp index 4131932..b5cd4f9 100644 --- a/3c_disasm/instr/add.cpp +++ b/3c_disasm/instr/add.cpp @@ -63,7 +63,9 @@ void Cadd::execInstr() CDat rb = this->m_cpu->getRegister(m_rb); CDatd val = ra + rb; this->m_cpu->setRegister(m_rd, val); - this->m_cpu->updateFlags(val, ra, rb); + if(!this->m_d) { + this->m_cpu->updateFlags(val, ra, rb); + } } std::string Cadd::toString() diff --git a/3c_disasm/instr/addi.cpp b/3c_disasm/instr/addi.cpp index 9b9b44f..5aab94c 100644 --- a/3c_disasm/instr/addi.cpp +++ b/3c_disasm/instr/addi.cpp @@ -66,7 +66,9 @@ void Caddi::execInstr() CDat ra = this->m_cpu->getRegister(m_ra); CDatd reg = ra + this->m_imm; this->m_cpu->setRegister(m_rd, reg); - this->m_cpu->updateFlags(reg, ra, this->m_imm); + if(!this->m_d) { + this->m_cpu->updateFlags(reg, ra, this->m_imm); + } } std::string Caddi::toString() diff --git a/3c_disasm/instr/and.cpp b/3c_disasm/instr/and.cpp new file mode 100644 index 0000000..b1aae59 --- /dev/null +++ b/3c_disasm/instr/and.cpp @@ -0,0 +1,80 @@ +#include "../Iinstr.hpp" + +class Cand : public Iinstr { + public: + Cand(); + 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 Cand(); +} + +Iinstr* Cand::getNew() { + return new Cand(); +} + +/** + * 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; +} + +Cand::Cand() +{ + opcode = B5(00100); + name = "and"; +} + +void Cand::evalInstr() +{ + this->m_d = argbits[0]; + + argbits >>= 11; + m_rb = this->getRegister(argbits); + + argbits >>= 4; + m_ra = this->getRegister(argbits); + + argbits >>= 4; + m_rd = this->getRegister(argbits); +} + +void Cand::execInstr() +{ + //cout << "should exec " << this->toString() << endl; + CDat ra = this->m_cpu->getRegister(m_ra); + CDat rb = this->m_cpu->getRegister(m_rb); + CDat val = ra & rb; + this->m_cpu->setRegister(m_rd, val); + if(!this->m_d) { + this->m_cpu->updateFlags(val); + } +} + +std::string Cand::toString() +{ + stringstream op; + op << this->getName(); + + if(m_d) op << 'D'; + if(m_c) op << 'C'; + + op << " r" << m_rd << ", r" << m_ra << ", r" << m_rb; + return op.str(); +} diff --git a/3c_disasm/instr/andx.cpp b/3c_disasm/instr/andx.cpp new file mode 100644 index 0000000..fed2237 --- /dev/null +++ b/3c_disasm/instr/andx.cpp @@ -0,0 +1,84 @@ +#include "../Iinstr.hpp" + + +class Candx : public Iinstr { + public: + Candx(); + 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 Candx(); +} + +Iinstr* Candx::getNew() +{ + return new Candx(); +} +/** + * 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; +} + +Candx::Candx() +{ + opcode = B5(00101); + name = "andx"; +} + +void Candx::evalInstr() +{ + this->m_d = argbits[0]; + this->m_f = argbits[1]; + this->m_hl = argbits[2]; + + argbits >>= 3; + dynamic_bitset<> immb = argbits; + immb.resize(16); + this->m_imm = this->generate16ImmSign(immb.to_ulong()); + + argbits >>= 16; + m_rd = this->getRegister(argbits); +} + +void Candx::execInstr() +{ + CDat val = this->m_cpu->getRegister(this->m_rd); + CDat imm = generate16ImmFill(this->m_imm); + val &= imm; + + this->m_cpu->setRegister(this->m_rd, val); + if(!this->m_d) { + this->m_cpu->updateFlags(val); + } +} + +std::string Candx::toString() +{ + stringstream op; + op << this->getName(); + + if(m_hl) op << 'H'; + if(m_f) op << 'F'; + if(m_d) op << 'D'; + + op << this->getConditionFlag() << " r" << m_rd << ", " << m_imm; + + return op.str(); +} diff --git a/3c_disasm/instr/or.cpp b/3c_disasm/instr/or.cpp new file mode 100644 index 0000000..e81b41d --- /dev/null +++ b/3c_disasm/instr/or.cpp @@ -0,0 +1,80 @@ +#include "../Iinstr.hpp" + +class Cor : public Iinstr { + public: + Cor(); + 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 Cor(); +} + +Iinstr* Cor::getNew() { + return new Cor(); +} + +/** + * 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; +} + +Cor::Cor() +{ + opcode = B5(00110); + name = "or"; +} + +void Cor::evalInstr() +{ + this->m_d = argbits[0]; + + argbits >>= 11; + m_rb = this->getRegister(argbits); + + argbits >>= 4; + m_ra = this->getRegister(argbits); + + argbits >>= 4; + m_rd = this->getRegister(argbits); +} + +void Cor::execInstr() +{ + //cout << "should exec " << this->toString() << endl; + CDat ra = this->m_cpu->getRegister(m_ra); + CDat rb = this->m_cpu->getRegister(m_rb); + CDat val = ra | rb; + this->m_cpu->setRegister(m_rd, val); + if(!this->m_d) { + this->m_cpu->updateFlags(val); + } +} + +std::string Cor::toString() +{ + stringstream op; + op << this->getName(); + + if(m_d) op << 'D'; + if(m_c) op << 'C'; + + op << " r" << m_rd << ", r" << m_ra << ", r" << m_rb; + return op.str(); +} diff --git a/3c_disasm/instr/orx.cpp b/3c_disasm/instr/orx.cpp new file mode 100644 index 0000000..95e32ea --- /dev/null +++ b/3c_disasm/instr/orx.cpp @@ -0,0 +1,84 @@ +#include "../Iinstr.hpp" + + +class Corx : public Iinstr { + public: + Corx(); + 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 Corx(); +} + +Iinstr* Corx::getNew() +{ + return new Corx(); +} +/** + * 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; +} + +Corx::Corx() +{ + opcode = B5(00111); + name = "orx"; +} + +void Corx::evalInstr() +{ + this->m_d = argbits[0]; + this->m_f = argbits[1]; + this->m_hl = argbits[2]; + + argbits >>= 3; + dynamic_bitset<> immb = argbits; + immb.resize(16); + this->m_imm = this->generate16ImmSign(immb.to_ulong()); + + argbits >>= 16; + m_rd = this->getRegister(argbits); +} + +void Corx::execInstr() +{ + CDat val = this->m_cpu->getRegister(this->m_rd); + CDat imm = generate16ImmFill(this->m_imm); + val |= imm; + + this->m_cpu->setRegister(this->m_rd, val); + if(!this->m_d) { + this->m_cpu->updateFlags(val); + } +} + +std::string Corx::toString() +{ + stringstream op; + op << this->getName(); + + if(m_hl) op << 'H'; + if(m_f) op << 'F'; + if(m_d) op << 'D'; + + op << this->getConditionFlag() << " r" << m_rd << ", " << m_imm; + + return op.str(); +} diff --git a/3c_disasm/instr/sub.cpp b/3c_disasm/instr/sub.cpp new file mode 100644 index 0000000..d174735 --- /dev/null +++ b/3c_disasm/instr/sub.cpp @@ -0,0 +1,81 @@ +#include "../Iinstr.hpp" + +class Csub : public Iinstr { + public: + Csub(); + 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 Csub(); +} + +Iinstr* Csub::getNew() { + return new Csub(); +} + +/** + * 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; +} + +Csub::Csub() +{ + opcode = B5(00001); + name = "sub"; +} + +void Csub::evalInstr() +{ + this->m_d = argbits[0]; + this->m_c = argbits[1]; + + argbits >>= 11; + m_rb = this->getRegister(argbits); + + argbits >>= 4; + m_ra = this->getRegister(argbits); + + argbits >>= 4; + m_rd = this->getRegister(argbits); +} + +void Csub::execInstr() +{ + //cout << "should exec " << this->toString() << endl; + CDat ra = this->m_cpu->getRegister(m_ra); + CDat rb = this->m_cpu->getRegister(m_rb); + CDatd val = ra - rb; + this->m_cpu->setRegister(m_rd, val); + if(!this->m_d) { + this->m_cpu->updateFlags(val, ra, rb); + } +} + +std::string Csub::toString() +{ + stringstream op; + op << this->getName(); + + if(m_d) op << 'D'; + if(m_c) op << 'C'; + + op << " r" << m_rd << ", r" << m_ra << ", r" << m_rb; + return op.str(); +} diff --git a/3c_disasm/instr/subi.cpp b/3c_disasm/instr/subi.cpp index 69ba7e1..701599c 100644 --- a/3c_disasm/instr/subi.cpp +++ b/3c_disasm/instr/subi.cpp @@ -65,7 +65,9 @@ void Csubi::execInstr() CDat ra = this->m_cpu->getRegister(m_ra); CDatd reg = ra - this->m_imm; this->m_cpu->setRegister(m_rd, reg); - this->m_cpu->updateFlags(reg, ra, this->m_imm); + if(!this->m_d) { + this->m_cpu->updateFlags(reg, ra, this->m_imm); + } } std::string Csubi::toString() diff --git a/3c_disasm/instr/xor.cpp b/3c_disasm/instr/xor.cpp new file mode 100644 index 0000000..900dbc3 --- /dev/null +++ b/3c_disasm/instr/xor.cpp @@ -0,0 +1,80 @@ +#include "../Iinstr.hpp" + +class Cxor : public Iinstr { + public: + Cxor(); + 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 Cxor(); +} + +Iinstr* Cxor::getNew() { + return new Cxor(); +} + +/** + * 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; +} + +Cxor::Cxor() +{ + opcode = B5(01000); + name = "or"; +} + +void Cxor::evalInstr() +{ + this->m_d = argbits[0]; + + argbits >>= 11; + m_rb = this->getRegister(argbits); + + argbits >>= 4; + m_ra = this->getRegister(argbits); + + argbits >>= 4; + m_rd = this->getRegister(argbits); +} + +void Cxor::execInstr() +{ + //cout << "should exec " << this->toString() << endl; + CDat ra = this->m_cpu->getRegister(m_ra); + CDat rb = this->m_cpu->getRegister(m_rb); + CDat val = ra ^ rb; + this->m_cpu->setRegister(m_rd, val); + if(!this->m_d) { + this->m_cpu->updateFlags(val); + } +} + +std::string Cxor::toString() +{ + stringstream op; + op << this->getName(); + + if(m_d) op << 'D'; + if(m_c) op << 'C'; + + op << " r" << m_rd << ", r" << m_ra << ", r" << m_rb; + return op.str(); +} diff --git a/3c_disasm/instr/xorx.cpp b/3c_disasm/instr/xorx.cpp new file mode 100644 index 0000000..ca940ae --- /dev/null +++ b/3c_disasm/instr/xorx.cpp @@ -0,0 +1,84 @@ +#include "../Iinstr.hpp" + + +class Cxorx : public Iinstr { + public: + Cxorx(); + 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 Cxorx(); +} + +Iinstr* Cxorx::getNew() +{ + return new Cxorx(); +} +/** + * 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; +} + +Cxorx::Cxorx() +{ + opcode = B5(01001); + name = "xorx"; +} + +void Cxorx::evalInstr() +{ + this->m_d = argbits[0]; + this->m_f = argbits[1]; + this->m_hl = argbits[2]; + + argbits >>= 3; + dynamic_bitset<> immb = argbits; + immb.resize(16); + this->m_imm = this->generate16ImmSign(immb.to_ulong()); + + argbits >>= 16; + m_rd = this->getRegister(argbits); +} + +void Cxorx::execInstr() +{ + CDat val = this->m_cpu->getRegister(this->m_rd); + CDat imm = generate16ImmFill(this->m_imm); + val ^= imm; + + this->m_cpu->setRegister(this->m_rd, val); + if(!this->m_d) { + this->m_cpu->updateFlags(val); + } +} + +std::string Cxorx::toString() +{ + stringstream op; + op << this->getName(); + + if(m_hl) op << 'H'; + if(m_f) op << 'F'; + if(m_d) op << 'D'; + + op << this->getConditionFlag() << " r" << m_rd << ", " << m_imm; + + return op.str(); +}