From: Martin Perner Date: Wed, 3 Nov 2010 13:58:20 +0000 (+0100) Subject: sim: added ldb, stb X-Git-Tag: bootrom_v1~186 X-Git-Url: http://wien.tomnetworks.com/gitweb/?p=calu.git;a=commitdiff_plain;h=be5651ec3f56d9a6bb057a206be362b5569db522 sim: added ldb, stb --- diff --git a/3c_disasm/instr/ldb.cpp b/3c_disasm/instr/ldb.cpp new file mode 100644 index 0000000..bb35be2 --- /dev/null +++ b/3c_disasm/instr/ldb.cpp @@ -0,0 +1,87 @@ +#include "../Iinstr.hpp" + + +class Cldb : public Iinstr { + public: + Cldb(); + 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 Cldb(); +} + +Iinstr* Cldb::getNew() +{ + return new Cldb(); +} + +/** + * 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; +} + +Cldb::Cldb() +{ + opcode = B5(10010); + name = "ldb"; +} + +void Cldb::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); + +} + +#include +#define AS_HEX std::hex << setw(8) << setfill('0') + +void Cldb::execInstr() +{ + //cout << "should exec " << this->toString() << endl; + CDat val = this->m_cpu->getRegister(this->m_ra); + val += m_imm; + MEMORY_ADDRESS temp = (val & (~(BYTE_COUNT-1))); + CDat offset = val-temp; + val = this->m_cpu->getRAM(temp); + val = (val >> (offset*8)) & ( ((1<<8)-1)); + CDat dest = this->m_cpu->getRegister(this->m_rd); + dest = dest & (~((1<<8)-1)); + dest = dest | val; + this->m_cpu->setRegister(this->m_rd,dest); +} + +std::string Cldb::toString() +{ + stringstream op; + op << this->getName(); + + op << this->getConditionFlag() << " r" << m_rd << ", " << m_imm << "(r" << m_ra << ")"; + + return op.str(); +} diff --git a/3c_disasm/instr/stb.cpp b/3c_disasm/instr/stb.cpp new file mode 100644 index 0000000..a047a6a --- /dev/null +++ b/3c_disasm/instr/stb.cpp @@ -0,0 +1,92 @@ +#include "../Iinstr.hpp" + + +class Cstb : public Iinstr { + public: + Cstb(); + 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 Cstb(); +} + +Iinstr* Cstb::getNew() +{ + return new Cstb(); +} + +/** + * 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; +} + +Cstb::Cstb() +{ + opcode = B5(10011); + name = "stb"; +} + +void Cstb::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); + +} + +#include +#define AS_HEX std::hex << setw(8) << setfill('0') + +void Cstb::execInstr() +{ + //cout << "should exec " << this->toString() << endl; + CDat addr = this->m_cpu->getRegister(this->m_ra); + addr += m_imm; + MEMORY_ADDRESS temp = (addr & (~(BYTE_COUNT-1))); + CDat offset = addr-temp; + CDat val = this->m_cpu->getRAM(temp); + + val = val & ~( ((1<<8)-1) << (offset*8)); + + //data to insert + CDat source = this->m_cpu->getRegister(this->m_rd); + source = (source & (((1<<8)-1))) << (offset*8); + + val += source; + + this->m_cpu->setRAM(temp, val); +} + +std::string Cstb::toString() +{ + stringstream op; + op << this->getName(); + + op << this->getConditionFlag() << " r" << m_rd << ", " << m_imm << "(r" << m_ra << ")"; + + return op.str(); +}