Removed some more unused filed and cleanup MIPSAssembler.

This commit is contained in:
Jean-Philip Desjardins 2014-09-28 23:44:54 -04:00
parent e58b107b4b
commit d78be1d608
8 changed files with 208 additions and 599 deletions

View File

@ -1,17 +1,12 @@
#include "MIPSAssembler.h"
#include "MipsAssemblerDefinitions.h"
#include "MIPS.h"
#include <boost/tokenizer.hpp>
#include <boost/function.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/bind.hpp>
#include <limits.h>
#include "lexical_cast_ex.h"
CMIPSAssembler::CMIPSAssembler(uint32* pPtr)
CMIPSAssembler::CMIPSAssembler(uint32* ptr)
: m_nextLabelId(1)
, m_pPtr(pPtr)
, m_pStartPtr(pPtr)
, m_ptr(ptr)
, m_startPtr(ptr)
{
}
@ -23,7 +18,7 @@ CMIPSAssembler::~CMIPSAssembler()
unsigned int CMIPSAssembler::GetProgramSize()
{
return static_cast<unsigned int>(m_pPtr - m_pStartPtr);
return static_cast<unsigned int>(m_ptr - m_startPtr);
}
CMIPSAssembler::LABEL CMIPSAssembler::CreateLabel()
@ -62,53 +57,53 @@ void CMIPSAssembler::ResolveLabelReferences()
{
throw std::runtime_error("Jump length too long.");
}
uint32& instruction = m_pStartPtr[referencePos];
uint32& instruction = m_startPtr[referencePos];
instruction &= 0xFFFF0000;
instruction |= static_cast<uint16>(offset);
}
m_labelReferences.clear();
}
void CMIPSAssembler::ADDIU(unsigned int nRT, unsigned int nRS, uint16 nImmediate)
void CMIPSAssembler::ADDIU(unsigned int rt, unsigned int rs, uint16 immediate)
{
(*m_pPtr) = ((0x09) << 26) | (nRS << 21) | (nRT << 16) | nImmediate;
m_pPtr++;
(*m_ptr) = ((0x09) << 26) | (rs << 21) | (rt << 16) | immediate;
m_ptr++;
}
void CMIPSAssembler::ADDU(unsigned int nRD, unsigned int nRS, unsigned int nRT)
void CMIPSAssembler::ADDU(unsigned int rd, unsigned int rs, unsigned int rt)
{
(*m_pPtr) = (nRS << 21) | (nRT << 16) | (nRD << 11) | (0x21);
m_pPtr++;
(*m_ptr) = (rs << 21) | (rt << 16) | (rd << 11) | (0x21);
m_ptr++;
}
void CMIPSAssembler::AND(unsigned int nRD, unsigned int nRS, unsigned int nRT)
void CMIPSAssembler::AND(unsigned int rd, unsigned int rs, unsigned int rt)
{
(*m_pPtr) = (nRS << 21) | (nRT << 16) | (nRD << 11) | (0x24);
m_pPtr++;
(*m_ptr) = (rs << 21) | (rt << 16) | (rd << 11) | (0x24);
m_ptr++;
}
void CMIPSAssembler::ANDI(unsigned int nRT, unsigned int nRS, uint16 nImmediate)
void CMIPSAssembler::ANDI(unsigned int rt, unsigned int rs, uint16 immediate)
{
(*m_pPtr) = ((0x0C) << 26) | (nRS << 21) | (nRT << 16) | nImmediate;
m_pPtr++;
(*m_ptr) = ((0x0C) << 26) | (rs << 21) | (rt << 16) | immediate;
m_ptr++;
}
void CMIPSAssembler::BEQ(unsigned int nRS, unsigned int nRT, uint16 nImmediate)
void CMIPSAssembler::BEQ(unsigned int rs, unsigned int rt, uint16 immediate)
{
(*m_pPtr) = ((0x04) << 26) | (nRS << 21) | (nRT << 16) | nImmediate;
m_pPtr++;
(*m_ptr) = ((0x04) << 26) | (rs << 21) | (rt << 16) | immediate;
m_ptr++;
}
void CMIPSAssembler::BEQ(unsigned int nRS, unsigned int nRT, LABEL label)
void CMIPSAssembler::BEQ(unsigned int rs, unsigned int rt, LABEL label)
{
CreateLabelReference(label);
BEQ(nRS, nRT, 0);
BEQ(rs, rt, 0);
}
void CMIPSAssembler::BGEZ(unsigned int nRS, uint16 nImmediate)
void CMIPSAssembler::BGEZ(unsigned int rs, uint16 immediate)
{
(*m_pPtr) = ((0x01) << 26) | (nRS << 21) | ((0x01) << 16) | nImmediate;
m_pPtr++;
(*m_ptr) = ((0x01) << 26) | (rs << 21) | ((0x01) << 16) | immediate;
m_ptr++;
}
void CMIPSAssembler::BGEZ(unsigned int rs, LABEL label)
@ -117,160 +112,160 @@ void CMIPSAssembler::BGEZ(unsigned int rs, LABEL label)
BGEZ(rs, 0);
}
void CMIPSAssembler::BGTZ(unsigned int nRS, uint16 nImmediate)
void CMIPSAssembler::BGTZ(unsigned int rs, uint16 immediate)
{
(*m_pPtr) = ((0x07) << 26) | (nRS << 21) | nImmediate;
m_pPtr++;
(*m_ptr) = ((0x07) << 26) | (rs << 21) | immediate;
m_ptr++;
}
void CMIPSAssembler::BNE(unsigned int nRS, unsigned int nRT, uint16 nImmediate)
void CMIPSAssembler::BNE(unsigned int rs, unsigned int rt, uint16 immediate)
{
(*m_pPtr) = ((0x05) << 26) | (nRS << 21) | (nRT << 16) | nImmediate;
m_pPtr++;
(*m_ptr) = ((0x05) << 26) | (rs << 21) | (rt << 16) | immediate;
m_ptr++;
}
void CMIPSAssembler::BNE(unsigned int nRS, unsigned int nRT, LABEL label)
void CMIPSAssembler::BNE(unsigned int rs, unsigned int rt, LABEL label)
{
CreateLabelReference(label);
BNE(nRS, nRT, 0);
BNE(rs, rt, 0);
}
void CMIPSAssembler::BLEZ(unsigned int nRS, uint16 nImmediate)
void CMIPSAssembler::BLEZ(unsigned int rs, uint16 immediate)
{
(*m_pPtr) = ((0x06) << 26) | (nRS << 21) | nImmediate;
m_pPtr++;
(*m_ptr) = ((0x06) << 26) | (rs << 21) | immediate;
m_ptr++;
}
void CMIPSAssembler::BLTZ(unsigned int nRS, uint16 nImmediate)
void CMIPSAssembler::BLTZ(unsigned int rs, uint16 immediate)
{
(*m_pPtr) = ((0x01) << 26) | (nRS << 21) | nImmediate;
m_pPtr++;
(*m_ptr) = ((0x01) << 26) | (rs << 21) | immediate;
m_ptr++;
}
void CMIPSAssembler::DADDU(unsigned int nRD, unsigned int nRS, unsigned int nRT)
void CMIPSAssembler::DADDU(unsigned int rd, unsigned int rs, unsigned int rt)
{
(*m_pPtr) = (nRS << 21) | (nRT << 16) | (nRD << 11) | (0x2D);
m_pPtr++;
(*m_ptr) = (rs << 21) | (rt << 16) | (rd << 11) | (0x2D);
m_ptr++;
}
void CMIPSAssembler::DADDIU(unsigned int nRT, unsigned int nRS, uint16 nImmediate)
void CMIPSAssembler::DADDIU(unsigned int rt, unsigned int rs, uint16 immediate)
{
(*m_pPtr) = ((0x19) << 26) | (nRS << 21) | (nRT << 16) | nImmediate;
m_pPtr++;
(*m_ptr) = ((0x19) << 26) | (rs << 21) | (rt << 16) | immediate;
m_ptr++;
}
void CMIPSAssembler::DSLL(unsigned int nRD, unsigned int nRT, unsigned int nSA)
void CMIPSAssembler::DSLL(unsigned int rd, unsigned int rt, unsigned int sa)
{
nSA &= 0x1F;
(*m_pPtr) = (nRT << 16) | (nRD << 11) | (nSA << 6) | 0x38;
m_pPtr++;
sa &= 0x1F;
(*m_ptr) = (rt << 16) | (rd << 11) | (sa << 6) | 0x38;
m_ptr++;
}
void CMIPSAssembler::DSLL32(unsigned int nRD, unsigned int nRT, unsigned int nSA)
void CMIPSAssembler::DSLL32(unsigned int rd, unsigned int rt, unsigned int sa)
{
nSA &= 0x1F;
(*m_pPtr) = (nRT << 16) | (nRD << 11) | (nSA << 6) | 0x3C;
m_pPtr++;
sa &= 0x1F;
(*m_ptr) = (rt << 16) | (rd << 11) | (sa << 6) | 0x3C;
m_ptr++;
}
void CMIPSAssembler::DSLLV(unsigned int nRD, unsigned int nRT, unsigned int nRS)
void CMIPSAssembler::DSLLV(unsigned int rd, unsigned int rt, unsigned int rs)
{
(*m_pPtr) = (nRS << 21) | (nRT << 16) | (nRD << 11) | 0x14;
m_pPtr++;
(*m_ptr) = (rs << 21) | (rt << 16) | (rd << 11) | 0x14;
m_ptr++;
}
void CMIPSAssembler::DSRA(unsigned int nRD, unsigned int nRT, unsigned int nSA)
void CMIPSAssembler::DSRA(unsigned int rd, unsigned int rt, unsigned int sa)
{
nSA &= 0x1F;
(*m_pPtr) = (nRT << 16) | (nRD << 11) | (nSA << 6) | 0x3B;
m_pPtr++;
sa &= 0x1F;
(*m_ptr) = (rt << 16) | (rd << 11) | (sa << 6) | 0x3B;
m_ptr++;
}
void CMIPSAssembler::DSRA32(unsigned int nRD, unsigned int nRT, unsigned int nSA)
void CMIPSAssembler::DSRA32(unsigned int rd, unsigned int rt, unsigned int sa)
{
nSA &= 0x1F;
(*m_pPtr) = (nRT << 16) | (nRD << 11) | (nSA << 6) | 0x3F;
m_pPtr++;
sa &= 0x1F;
(*m_ptr) = (rt << 16) | (rd << 11) | (sa << 6) | 0x3F;
m_ptr++;
}
void CMIPSAssembler::DSRAV(unsigned int nRD, unsigned int nRT, unsigned int nRS)
void CMIPSAssembler::DSRAV(unsigned int rd, unsigned int rt, unsigned int rs)
{
(*m_pPtr) = (nRS << 21) | (nRT << 16) | (nRD << 11) | 0x17;
m_pPtr++;
(*m_ptr) = (rs << 21) | (rt << 16) | (rd << 11) | 0x17;
m_ptr++;
}
void CMIPSAssembler::DSRL(unsigned int nRD, unsigned int nRT, unsigned int nSA)
void CMIPSAssembler::DSRL(unsigned int rd, unsigned int rt, unsigned int sa)
{
nSA &= 0x1F;
(*m_pPtr) = (nRT << 16) | (nRD << 11) | (nSA << 6) | 0x3A;
m_pPtr++;
sa &= 0x1F;
(*m_ptr) = (rt << 16) | (rd << 11) | (sa << 6) | 0x3A;
m_ptr++;
}
void CMIPSAssembler::DSRL32(unsigned int nRD, unsigned int nRT, unsigned int nSA)
void CMIPSAssembler::DSRL32(unsigned int rd, unsigned int rt, unsigned int sa)
{
nSA &= 0x1F;
(*m_pPtr) = (nRT << 16) | (nRD << 11) | (nSA << 6) | 0x3E;
m_pPtr++;
sa &= 0x1F;
(*m_ptr) = (rt << 16) | (rd << 11) | (sa << 6) | 0x3E;
m_ptr++;
}
void CMIPSAssembler::DSRLV(unsigned int nRD, unsigned int nRT, unsigned int nRS)
void CMIPSAssembler::DSRLV(unsigned int rd, unsigned int rt, unsigned int rs)
{
(*m_pPtr) = (nRS << 21) | (nRT << 16) | (nRD << 11) | 0x16;
m_pPtr++;
(*m_ptr) = (rs << 21) | (rt << 16) | (rd << 11) | 0x16;
m_ptr++;
}
void CMIPSAssembler::DSUBU(unsigned int nRD, unsigned int nRS, unsigned int nRT)
void CMIPSAssembler::DSUBU(unsigned int rd, unsigned int rs, unsigned int rt)
{
(*m_pPtr) = (nRS << 21) | (nRT << 16) | (nRD << 11) | (0x2F);
m_pPtr++;
(*m_ptr) = (rs << 21) | (rt << 16) | (rd << 11) | (0x2F);
m_ptr++;
}
void CMIPSAssembler::ERET()
{
(*m_pPtr) = 0x42000018;
m_pPtr++;
(*m_ptr) = 0x42000018;
m_ptr++;
}
void CMIPSAssembler::JAL(uint32 address)
{
(*m_pPtr) = ((0x03) << 26) | ((address >> 2) & 0x03FFFFFF);
m_pPtr++;
(*m_ptr) = ((0x03) << 26) | ((address >> 2) & 0x03FFFFFF);
m_ptr++;
}
void CMIPSAssembler::JALR(unsigned int nRS, unsigned int nRD)
void CMIPSAssembler::JALR(unsigned int rs, unsigned int rd)
{
(*m_pPtr) = (nRS << 21) | (nRD << 11) | (0x09);
m_pPtr++;
(*m_ptr) = (rs << 21) | (rd << 11) | (0x09);
m_ptr++;
}
void CMIPSAssembler::JR(unsigned int nRS)
void CMIPSAssembler::JR(unsigned int rs)
{
(*m_pPtr) = (nRS << 21) | (0x08);
m_pPtr++;
(*m_ptr) = (rs << 21) | (0x08);
m_ptr++;
}
void CMIPSAssembler::LD(unsigned int nRT, uint16 nOffset, unsigned int nBase)
void CMIPSAssembler::LD(unsigned int rt, uint16 nOffset, unsigned int nBase)
{
(*m_pPtr) = ((0x37) << 26) | (nBase << 21) | (nRT << 16) | nOffset;
m_pPtr++;
(*m_ptr) = ((0x37) << 26) | (nBase << 21) | (rt << 16) | nOffset;
m_ptr++;
}
void CMIPSAssembler::LDL(unsigned int nRT, uint16 nOffset, unsigned int nBase)
void CMIPSAssembler::LDL(unsigned int rt, uint16 nOffset, unsigned int nBase)
{
(*m_pPtr) = ((0x1A) << 26) | (nBase << 21) | (nRT << 16) | nOffset;
m_pPtr++;
(*m_ptr) = ((0x1A) << 26) | (nBase << 21) | (rt << 16) | nOffset;
m_ptr++;
}
void CMIPSAssembler::LDR(unsigned int nRT, uint16 nOffset, unsigned int nBase)
void CMIPSAssembler::LDR(unsigned int rt, uint16 nOffset, unsigned int nBase)
{
(*m_pPtr) = ((0x1B) << 26) | (nBase << 21) | (nRT << 16) | nOffset;
m_pPtr++;
(*m_ptr) = ((0x1B) << 26) | (nBase << 21) | (rt << 16) | nOffset;
m_ptr++;
}
void CMIPSAssembler::LHU(unsigned int nRT, uint16 nOffset, unsigned int nBase)
void CMIPSAssembler::LHU(unsigned int rt, uint16 nOffset, unsigned int nBase)
{
(*m_pPtr) = ((0x25) << 26) | (nBase << 21) | (nRT << 16) | nOffset;
m_pPtr++;
(*m_ptr) = ((0x25) << 26) | (nBase << 21) | (rt << 16) | nOffset;
m_ptr++;
}
void CMIPSAssembler::LI(unsigned int rt, uint32 immediate)
@ -284,100 +279,100 @@ void CMIPSAssembler::LI(unsigned int rt, uint32 immediate)
}
}
void CMIPSAssembler::LUI(unsigned int nRT, uint16 nImmediate)
void CMIPSAssembler::LUI(unsigned int rt, uint16 immediate)
{
(*m_pPtr) = ((0x0F) << 26) | (nRT << 16) | nImmediate;
m_pPtr++;
(*m_ptr) = ((0x0F) << 26) | (rt << 16) | immediate;
m_ptr++;
}
void CMIPSAssembler::LQ(unsigned int nRT, uint16 nOffset, unsigned int nBase)
void CMIPSAssembler::LQ(unsigned int rt, uint16 nOffset, unsigned int nBase)
{
(*m_pPtr) = ((0x1E) << 26) | (nBase << 21) | (nRT << 16) | nOffset;
m_pPtr++;
(*m_ptr) = ((0x1E) << 26) | (nBase << 21) | (rt << 16) | nOffset;
m_ptr++;
}
void CMIPSAssembler::LBU(unsigned int rt, uint16 offset, unsigned int base)
{
(*m_pPtr) = ((0x24) << 26) | (base << 21) | (rt << 16) | offset;
m_pPtr++;
(*m_ptr) = ((0x24) << 26) | (base << 21) | (rt << 16) | offset;
m_ptr++;
}
void CMIPSAssembler::LW(unsigned int nRT, uint16 nOffset, unsigned int nBase)
void CMIPSAssembler::LW(unsigned int rt, uint16 nOffset, unsigned int nBase)
{
(*m_pPtr) = ((0x23) << 26) | (nBase << 21) | (nRT << 16) | nOffset;
m_pPtr++;
(*m_ptr) = ((0x23) << 26) | (nBase << 21) | (rt << 16) | nOffset;
m_ptr++;
}
void CMIPSAssembler::LWL(unsigned int nRT, uint16 nOffset, unsigned int nBase)
void CMIPSAssembler::LWL(unsigned int rt, uint16 nOffset, unsigned int nBase)
{
(*m_pPtr) = ((0x22) << 26) | (nBase << 21) | (nRT << 16) | nOffset;
m_pPtr++;
(*m_ptr) = ((0x22) << 26) | (nBase << 21) | (rt << 16) | nOffset;
m_ptr++;
}
void CMIPSAssembler::LWR(unsigned int nRT, uint16 nOffset, unsigned int nBase)
void CMIPSAssembler::LWR(unsigned int rt, uint16 nOffset, unsigned int nBase)
{
(*m_pPtr) = ((0x26) << 26) | (nBase << 21) | (nRT << 16) | nOffset;
m_pPtr++;
(*m_ptr) = ((0x26) << 26) | (nBase << 21) | (rt << 16) | nOffset;
m_ptr++;
}
void CMIPSAssembler::MFC0(unsigned int nRT, unsigned int nRD)
void CMIPSAssembler::MFC0(unsigned int rt, unsigned int rd)
{
(*m_pPtr) = ((0x10) << 26) | (nRT << 16) | (nRD << 11);
m_pPtr++;
(*m_ptr) = ((0x10) << 26) | (rt << 16) | (rd << 11);
m_ptr++;
}
void CMIPSAssembler::MFHI(unsigned int rd)
{
(*m_pPtr) = ((0x00) << 26) | (rd << 11) | (0x10);
m_pPtr++;
(*m_ptr) = ((0x00) << 26) | (rd << 11) | (0x10);
m_ptr++;
}
void CMIPSAssembler::MFHI1(unsigned int rd)
{
(*m_pPtr) = ((0x1C) << 26) | (rd << 11) | (0x10);
m_pPtr++;
(*m_ptr) = ((0x1C) << 26) | (rd << 11) | (0x10);
m_ptr++;
}
void CMIPSAssembler::MFLO(unsigned int rd)
{
(*m_pPtr) = ((0x00) << 26) | (rd << 11) | (0x12);
m_pPtr++;
(*m_ptr) = ((0x00) << 26) | (rd << 11) | (0x12);
m_ptr++;
}
void CMIPSAssembler::MFLO1(unsigned int rd)
{
(*m_pPtr) = ((0x1C) << 26) | (rd << 11) | (0x12);
m_pPtr++;
(*m_ptr) = ((0x1C) << 26) | (rd << 11) | (0x12);
m_ptr++;
}
void CMIPSAssembler::MTC0(unsigned int nRT, unsigned int nRD)
void CMIPSAssembler::MTC0(unsigned int rt, unsigned int rd)
{
(*m_pPtr) = ((0x10) << 26) | ((0x04) << 21) | (nRT << 16) | (nRD << 11);
m_pPtr++;
(*m_ptr) = ((0x10) << 26) | ((0x04) << 21) | (rt << 16) | (rd << 11);
m_ptr++;
}
void CMIPSAssembler::MTHI(unsigned int rs)
{
(*m_pPtr) = ((0x00) << 26) | (rs << 21) | (0x11);
m_pPtr++;
(*m_ptr) = ((0x00) << 26) | (rs << 21) | (0x11);
m_ptr++;
}
void CMIPSAssembler::MTHI1(unsigned int rs)
{
(*m_pPtr) = ((0x1C) << 26) | (rs << 21) | (0x11);
m_pPtr++;
(*m_ptr) = ((0x1C) << 26) | (rs << 21) | (0x11);
m_ptr++;
}
void CMIPSAssembler::MTLO(unsigned int rs)
{
(*m_pPtr) = ((0x00) << 26) | (rs << 21) | (0x13);
m_pPtr++;
(*m_ptr) = ((0x00) << 26) | (rs << 21) | (0x13);
m_ptr++;
}
void CMIPSAssembler::MTLO1(unsigned int rs)
{
(*m_pPtr) = ((0x1C) << 26) | (rs << 21) | (0x13);
m_pPtr++;
(*m_ptr) = ((0x1C) << 26) | (rs << 21) | (0x13);
m_ptr++;
}
void CMIPSAssembler::MOV(unsigned int rd, unsigned int rs)
@ -385,177 +380,131 @@ void CMIPSAssembler::MOV(unsigned int rd, unsigned int rs)
ADDU(rd, rs, 0);
}
void CMIPSAssembler::MULT(unsigned int nRD, unsigned int nRS, unsigned int nRT)
void CMIPSAssembler::MULT(unsigned int rd, unsigned int rs, unsigned int rt)
{
(*m_pPtr) = (nRS << 21) | (nRT << 16) | (nRD << 11) | 0x18;
m_pPtr++;
(*m_ptr) = (rs << 21) | (rt << 16) | (rd << 11) | 0x18;
m_ptr++;
}
void CMIPSAssembler::MULTU(unsigned int nRS, unsigned int nRT, unsigned int nRD)
void CMIPSAssembler::MULTU(unsigned int rs, unsigned int rt, unsigned int rd)
{
(*m_pPtr) = (nRS << 21) | (nRT << 16) | (nRD << 11) | 0x19;
m_pPtr++;
(*m_ptr) = (rs << 21) | (rt << 16) | (rd << 11) | 0x19;
m_ptr++;
}
void CMIPSAssembler::NOP()
{
(*m_pPtr) = 0;
m_pPtr++;
(*m_ptr) = 0;
m_ptr++;
}
void CMIPSAssembler::NOR(unsigned int nRD, unsigned int nRS, unsigned int nRT)
void CMIPSAssembler::NOR(unsigned int rd, unsigned int rs, unsigned int rt)
{
(*m_pPtr) = (nRS << 21) | (nRT << 16) | (nRD << 11) | 0x27;
m_pPtr++;
(*m_ptr) = (rs << 21) | (rt << 16) | (rd << 11) | 0x27;
m_ptr++;
}
void CMIPSAssembler::OR(unsigned int nRD, unsigned int nRS, unsigned int nRT)
void CMIPSAssembler::OR(unsigned int rd, unsigned int rs, unsigned int rt)
{
(*m_pPtr) = (nRS << 21) | (nRT << 16) | (nRD << 11) | 0x25;
m_pPtr++;
(*m_ptr) = (rs << 21) | (rt << 16) | (rd << 11) | 0x25;
m_ptr++;
}
void CMIPSAssembler::ORI(unsigned int nRT, unsigned int nRS, uint16 nImmediate)
void CMIPSAssembler::ORI(unsigned int rt, unsigned int rs, uint16 immediate)
{
(*m_pPtr) = ((0x0D) << 26) | (nRS << 21) | (nRT << 16) | nImmediate;
m_pPtr++;
(*m_ptr) = ((0x0D) << 26) | (rs << 21) | (rt << 16) | immediate;
m_ptr++;
}
void CMIPSAssembler::SD(unsigned int nRT, uint16 nOffset, unsigned int nBase)
void CMIPSAssembler::SD(unsigned int rt, uint16 nOffset, unsigned int nBase)
{
(*m_pPtr) = ((0x3F) << 26) | (nBase << 21) | (nRT << 16) | nOffset;
m_pPtr++;
(*m_ptr) = ((0x3F) << 26) | (nBase << 21) | (rt << 16) | nOffset;
m_ptr++;
}
void CMIPSAssembler::SLL(unsigned int nRD, unsigned int nRT, unsigned int nSA)
void CMIPSAssembler::SLL(unsigned int rd, unsigned int rt, unsigned int sa)
{
nSA &= 0x1F;
(*m_pPtr) = (nRT << 16) | (nRD << 11) | (nSA << 6);
m_pPtr++;
sa &= 0x1F;
(*m_ptr) = (rt << 16) | (rd << 11) | (sa << 6);
m_ptr++;
}
void CMIPSAssembler::SLLV(unsigned int nRD, unsigned int nRT, unsigned int nRS)
void CMIPSAssembler::SLLV(unsigned int rd, unsigned int rt, unsigned int rs)
{
(*m_pPtr) = (nRS << 21) | (nRT << 16) | (nRD << 11) | 0x04;
m_pPtr++;
(*m_ptr) = (rs << 21) | (rt << 16) | (rd << 11) | 0x04;
m_ptr++;
}
void CMIPSAssembler::SLT(unsigned int nRD, unsigned int nRS, unsigned int nRT)
void CMIPSAssembler::SLT(unsigned int rd, unsigned int rs, unsigned int rt)
{
(*m_pPtr) = (nRS << 21) | (nRT << 16) | (nRD << 11) | 0x2A;
m_pPtr++;
(*m_ptr) = (rs << 21) | (rt << 16) | (rd << 11) | 0x2A;
m_ptr++;
}
void CMIPSAssembler::SLTI(unsigned int nRT, unsigned int nRS, uint16 nImmediate)
void CMIPSAssembler::SLTI(unsigned int rt, unsigned int rs, uint16 immediate)
{
(*m_pPtr) = ((0x0A) << 26) | (nRS << 21) | (nRT << 16) | nImmediate;
m_pPtr++;
(*m_ptr) = ((0x0A) << 26) | (rs << 21) | (rt << 16) | immediate;
m_ptr++;
}
void CMIPSAssembler::SLTIU(unsigned int nRT, unsigned int nRS, uint16 nImmediate)
void CMIPSAssembler::SLTIU(unsigned int rt, unsigned int rs, uint16 immediate)
{
(*m_pPtr) = ((0x0B) << 26) | (nRS << 21) | (nRT << 16) | nImmediate;
m_pPtr++;
(*m_ptr) = ((0x0B) << 26) | (rs << 21) | (rt << 16) | immediate;
m_ptr++;
}
void CMIPSAssembler::SLTU(unsigned int nRD, unsigned int nRS, unsigned int nRT)
void CMIPSAssembler::SLTU(unsigned int rd, unsigned int rs, unsigned int rt)
{
(*m_pPtr) = (nRS << 21) | (nRT << 16) | (nRD << 11) | 0x2B;
m_pPtr++;
(*m_ptr) = (rs << 21) | (rt << 16) | (rd << 11) | 0x2B;
m_ptr++;
}
void CMIPSAssembler::SRA(unsigned int nRD, unsigned int nRT, unsigned int nSA)
void CMIPSAssembler::SRA(unsigned int rd, unsigned int rt, unsigned int sa)
{
nSA &= 0x1F;
(*m_pPtr) = (nRT << 16) | (nRD << 11) | (nSA << 6) | 0x03;
m_pPtr++;
sa &= 0x1F;
(*m_ptr) = (rt << 16) | (rd << 11) | (sa << 6) | 0x03;
m_ptr++;
}
void CMIPSAssembler::SRAV(unsigned int nRD, unsigned int nRT, unsigned int nRS)
void CMIPSAssembler::SRAV(unsigned int rd, unsigned int rt, unsigned int rs)
{
(*m_pPtr) = (nRS << 21) | (nRT << 16) | (nRD << 11) | 0x07;
m_pPtr++;
(*m_ptr) = (rs << 21) | (rt << 16) | (rd << 11) | 0x07;
m_ptr++;
}
void CMIPSAssembler::SRL(unsigned int nRD, unsigned int nRT, unsigned int nSA)
void CMIPSAssembler::SRL(unsigned int rd, unsigned int rt, unsigned int sa)
{
nSA &= 0x1F;
(*m_pPtr) = (nRT << 16) | (nRD << 11) | (nSA << 6) | 0x02;
m_pPtr++;
sa &= 0x1F;
(*m_ptr) = (rt << 16) | (rd << 11) | (sa << 6) | 0x02;
m_ptr++;
}
void CMIPSAssembler::SRLV(unsigned int nRD, unsigned int nRT, unsigned int nRS)
void CMIPSAssembler::SRLV(unsigned int rd, unsigned int rt, unsigned int rs)
{
(*m_pPtr) = (nRS << 21) | (nRT << 16) | (nRD << 11) | 0x06;
m_pPtr++;
(*m_ptr) = (rs << 21) | (rt << 16) | (rd << 11) | 0x06;
m_ptr++;
}
void CMIPSAssembler::SQ(unsigned int nRT, uint16 nOffset, unsigned int nBase)
void CMIPSAssembler::SQ(unsigned int rt, uint16 nOffset, unsigned int nBase)
{
(*m_pPtr) = ((0x1F) << 26) | (nBase << 21) | (nRT << 16) | nOffset;
m_pPtr++;
(*m_ptr) = ((0x1F) << 26) | (nBase << 21) | (rt << 16) | nOffset;
m_ptr++;
}
void CMIPSAssembler::SB(unsigned int rt, uint16 offset, unsigned int base)
{
(*m_pPtr) = ((0x28) << 26) | (base << 21) | (rt << 16) | offset;
m_pPtr++;
(*m_ptr) = ((0x28) << 26) | (base << 21) | (rt << 16) | offset;
m_ptr++;
}
void CMIPSAssembler::SW(unsigned int nRT, uint16 nOffset, unsigned int nBase)
void CMIPSAssembler::SW(unsigned int rt, uint16 nOffset, unsigned int nBase)
{
(*m_pPtr) = ((0x2B) << 26) | (nBase << 21) | (nRT << 16) | nOffset;
m_pPtr++;
(*m_ptr) = ((0x2B) << 26) | (nBase << 21) | (rt << 16) | nOffset;
m_ptr++;
}
void CMIPSAssembler::SYSCALL()
{
(*m_pPtr) = 0x0000000C;
m_pPtr++;
}
void CMIPSAssembler::AssembleString(const char* sCode)
{
std::string sString(sCode);
boost::tokenizer<> Tokens(sString);
boost::tokenizer<>::iterator itToken(Tokens.begin());
//First token must be the instruction mnemonic
const char* sMnemonic = (*itToken).c_str();
bool nFound(false);
for(unsigned int i = 0; ; i++)
{
MipsAssemblerDefinitions::Instruction* pInstruction(MipsAssemblerDefinitions::g_Instructions[i]);
if(pInstruction == NULL) break;
if(!strcmp(pInstruction->m_sMnemonic, sMnemonic))
{
pInstruction->Invoke(Tokens, itToken, this);
nFound = true;
break;
}
}
if(nFound == false)
{
throw std::runtime_error("Invalid mnemonic specified.");
}
}
unsigned int CMIPSAssembler::GetRegisterIndex(const char* sRegisterName)
{
unsigned int nRegister = -1;
for(unsigned int i = 0; i < 32; i++)
{
if(!strcmp(CMIPS::m_sGPRName[i], sRegisterName))
{
nRegister = i;
break;
}
}
return nRegister;
(*m_ptr) = 0x0000000C;
m_ptr++;
}

View File

@ -1,5 +1,4 @@
#ifndef _MIPSASSEMBLER_H_
#define _MIPSASSEMBLER_H_
#pragma once
#include "Types.h"
#include <map>
@ -97,10 +96,6 @@ public:
void SW(unsigned int, uint16, unsigned int);
void SYSCALL();
void AssembleString(const char*);
static unsigned int GetRegisterIndex(const char*);
private:
void ResolveLabelReferences();
void CreateLabelReference(LABEL);
@ -113,11 +108,9 @@ private:
typedef std::map<LABEL, size_t> LabelMapType;
typedef std::multimap<LABEL, LABELREF> LabelReferenceMapType;
uint32* m_pPtr;
uint32* m_pStartPtr;
uint32* m_ptr = nullptr;
uint32* m_startPtr = nullptr;
LabelMapType m_labels;
LabelReferenceMapType m_labelReferences;
unsigned int m_nextLabelId;
};
#endif

View File

@ -1,292 +0,0 @@
#include "MipsAssemblerDefinitions.h"
#include "MIPSAssembler.h"
#include <stdexcept>
#include <functional>
#include <boost/lexical_cast.hpp>
#include "lexical_cast_ex.h"
#include "placeholder_def.h"
namespace MipsAssemblerDefinitions
{
//RsRtImm Parser
//-----------------------------
struct RsRtImm
{
typedef void (CMIPSAssembler::*AssemblerFunctionType) (unsigned int, unsigned int, uint16);
RsRtImm(const AssemblerFunctionType& assemblerFunction)
: m_assemblerFunction(assemblerFunction)
{
}
void operator ()(boost::tokenizer<>& Tokens, boost::tokenizer<>::iterator& itToken, CMIPSAssembler* pAssembler)
{
if(itToken == Tokens.end()) throw std::exception();
unsigned int nRS = CMIPSAssembler::GetRegisterIndex((*(++itToken)).c_str());
if(itToken == Tokens.end()) throw std::exception();
unsigned int nRT = CMIPSAssembler::GetRegisterIndex((*(++itToken)).c_str());
if(itToken == Tokens.end()) throw std::exception();
uint16 nImm = lexical_cast_hex<std::string>((*(++itToken)).c_str());
if(nRT == -1) throw std::exception();
if(nRS == -1) throw std::exception();
((pAssembler)->*(m_assemblerFunction))(nRS, nRT, nImm);
}
AssemblerFunctionType m_assemblerFunction;
};
//RtRsImm Parser
//-----------------------------
struct RtRsImm
{
typedef void (CMIPSAssembler::*AssemblerFunctionType) (unsigned int, unsigned int, uint16);
RtRsImm(const AssemblerFunctionType& assemblerFunction)
: m_assemblerFunction(assemblerFunction)
{
}
void operator ()(boost::tokenizer<>& Tokens, boost::tokenizer<>::iterator& itToken, CMIPSAssembler* pAssembler)
{
if(itToken == Tokens.end()) throw std::exception();
unsigned int nRT = CMIPSAssembler::GetRegisterIndex((*(++itToken)).c_str());
if(itToken == Tokens.end()) throw std::exception();
unsigned int nRS = CMIPSAssembler::GetRegisterIndex((*(++itToken)).c_str());
if(itToken == Tokens.end()) throw std::exception();
uint16 nImm = lexical_cast_hex<std::string>((*(++itToken)).c_str());
if(nRT == -1) throw std::exception();
if(nRS == -1) throw std::exception();
((pAssembler)->*(m_assemblerFunction))(nRT, nRS, nImm);
}
AssemblerFunctionType m_assemblerFunction;
};
//RdRsRt Parser
//-----------------------------
struct RdRsRt
{
typedef void (CMIPSAssembler::*AssemblerFunctionType) (unsigned int, unsigned int, unsigned int);
RdRsRt(const AssemblerFunctionType& assemblerFunction)
: m_assemblerFunction(assemblerFunction)
{
}
void operator ()(boost::tokenizer<>& Tokens, boost::tokenizer<>::iterator& itToken, CMIPSAssembler* pAssembler)
{
if(itToken == Tokens.end()) throw std::exception();
unsigned int nRD = CMIPSAssembler::GetRegisterIndex((*(++itToken)).c_str());
if(itToken == Tokens.end()) throw std::exception();
unsigned int nRS = CMIPSAssembler::GetRegisterIndex((*(++itToken)).c_str());
if(itToken == Tokens.end()) throw std::exception();
unsigned int nRT = CMIPSAssembler::GetRegisterIndex((*(++itToken)).c_str());
if(nRT == -1) throw std::exception();
if(nRS == -1) throw std::exception();
if(nRD == -1) throw std::exception();
((pAssembler)->*(m_assemblerFunction))(nRD, nRS, nRT);
}
AssemblerFunctionType m_assemblerFunction;
};
//RsImm Parser
//-----------------------------
struct RsImm
{
typedef void (CMIPSAssembler::*AssemblerFunctionType) (unsigned int, uint16);
RsImm(const AssemblerFunctionType& assemblerFunction)
: m_assemblerFunction(assemblerFunction)
{
}
void operator ()(boost::tokenizer<>& Tokens, boost::tokenizer<>::iterator& itToken, CMIPSAssembler* pAssembler)
{
if(itToken == Tokens.end()) throw std::exception();
unsigned int nRS = CMIPSAssembler::GetRegisterIndex((*(++itToken)).c_str());
if(itToken == Tokens.end()) throw std::exception();
uint16 nImm = lexical_cast_hex<std::string>((*(++itToken)).c_str());
if(nRS == -1) throw std::exception();
((pAssembler)->*(m_assemblerFunction))(nRS, nImm);
}
AssemblerFunctionType m_assemblerFunction;
};
//RtImm Parser
//-----------------------------
struct RtImm
{
typedef void (CMIPSAssembler::*AssemblerFunctionType) (unsigned int, uint16);
RtImm(const AssemblerFunctionType& assemblerFunction)
: m_assemblerFunction(assemblerFunction)
{
}
void operator ()(boost::tokenizer<>& Tokens, boost::tokenizer<>::iterator& itToken, CMIPSAssembler* pAssembler)
{
if(itToken == Tokens.end()) throw std::exception();
unsigned int nRT = CMIPSAssembler::GetRegisterIndex((*(++itToken)).c_str());
if(itToken == Tokens.end()) throw std::exception();
uint16 nImm = lexical_cast_hex<std::string>((*(++itToken)).c_str());
if(nRT == -1) throw std::exception();
((pAssembler)->*(m_assemblerFunction))(nRT, nImm);
}
AssemblerFunctionType m_assemblerFunction;
};
//RtRsSa Parser
//-----------------------------
struct RtRsSa
{
typedef void (CMIPSAssembler::*AssemblerFunctionType) (unsigned int, unsigned int, unsigned int);
RtRsSa(const AssemblerFunctionType& assemblerFunction)
: m_assemblerFunction(assemblerFunction)
{
}
void operator()(boost::tokenizer<>& Tokens, boost::tokenizer<>::iterator& itToken, CMIPSAssembler* pAssembler)
{
if(itToken == Tokens.end()) throw std::exception();
unsigned int nRT = CMIPSAssembler::GetRegisterIndex((*(++itToken)).c_str());
if(itToken == Tokens.end()) throw std::exception();
unsigned int nRS = CMIPSAssembler::GetRegisterIndex((*(++itToken)).c_str());
if(itToken == Tokens.end()) throw std::exception();
unsigned int nSA = boost::lexical_cast<unsigned int>((*(++itToken)).c_str());
if(nRT == -1) throw std::exception();
if(nRS == -1) throw std::exception();
((pAssembler)->*(m_assemblerFunction))(nRT, nRS, nSA);
}
AssemblerFunctionType m_assemblerFunction;
};
//RtOfsBase Parser
//-----------------------------
struct RtOfsBase
{
typedef void (CMIPSAssembler::*AssemblerFunctionType) (unsigned int, uint16, unsigned int);
RtOfsBase(const AssemblerFunctionType& assemblerFunction)
: m_assemblerFunction(assemblerFunction)
{
}
void operator ()(boost::tokenizer<>& Tokens, boost::tokenizer<>::iterator& itToken, CMIPSAssembler* pAssembler)
{
if(itToken == Tokens.end()) throw std::exception();
unsigned int nRT = CMIPSAssembler::GetRegisterIndex((*(++itToken)).c_str());
if(itToken == Tokens.end()) throw std::exception();
uint16 nOfs = lexical_cast_hex<std::string>((*(++itToken)).c_str());
if(itToken == Tokens.end()) throw std::exception();
unsigned int nBase = CMIPSAssembler::GetRegisterIndex((*(++itToken)).c_str());
if(nBase == -1) throw std::exception();
if(nRT == -1) throw std::exception();
((pAssembler)->*(m_assemblerFunction))(nRT, nOfs, nBase);
}
AssemblerFunctionType m_assemblerFunction;
};
template <typename Functor>
struct SpecInstruction : public Instruction
{
SpecInstruction(const char* sMnemonic, const Functor& Parser) :
Instruction(sMnemonic),
m_Parser(Parser)
{
}
virtual void Invoke(boost::tokenizer<>& Tokens, boost::tokenizer<>::iterator& itToken, CMIPSAssembler* pAssembler)
{
m_Parser(Tokens, itToken, pAssembler);
}
Functor m_Parser;
};
//Instruction definitions
//-------------------------------
SpecInstruction<RdRsRt> Instruction_ADDU = SpecInstruction<RdRsRt>("ADDU", RdRsRt(&CMIPSAssembler::ADDU));
SpecInstruction<RtRsImm> Instruction_ADDIU = SpecInstruction<RtRsImm>("ADDIU", RtRsImm(&CMIPSAssembler::ADDIU));
SpecInstruction<RsRtImm> Instruction_BEQ = SpecInstruction<RsRtImm>("BEQ", RsRtImm(&CMIPSAssembler::BEQ));
SpecInstruction<RsImm> Instruction_BGEZ = SpecInstruction<RsImm>("BGEZ", RsImm(&CMIPSAssembler::BGEZ));
SpecInstruction<RsImm> Instruction_BLEZ = SpecInstruction<RsImm>("BLEZ", RsImm(&CMIPSAssembler::BLEZ));
SpecInstruction<RsRtImm> Instruction_BNE = SpecInstruction<RsRtImm>("BNE", RsRtImm(&CMIPSAssembler::BNE));
SpecInstruction<RtRsImm> Instruction_DADDIU = SpecInstruction<RtRsImm>("DADDIU", RtRsImm(&CMIPSAssembler::DADDIU));
SpecInstruction<RtRsSa> Instruction_DSRA32 = SpecInstruction<RtRsSa>("DSRA32", RtRsSa(&CMIPSAssembler::DSRA32));
SpecInstruction<RtOfsBase> Instruction_LHU = SpecInstruction<RtOfsBase>("LHU", RtOfsBase(&CMIPSAssembler::LHU));
SpecInstruction<RtImm> Instruction_LUI = SpecInstruction<RtImm>("LUI", RtImm(&CMIPSAssembler::LUI));
SpecInstruction<RtOfsBase> Instruction_LW = SpecInstruction<RtOfsBase>("LW", RtOfsBase(&CMIPSAssembler::LW));
SpecInstruction<RdRsRt> Instruction_MULT = SpecInstruction<RdRsRt>("MULT", RdRsRt(&CMIPSAssembler::MULT));
SpecInstruction<RdRsRt> Instruction_OR = SpecInstruction<RdRsRt>("OR", RdRsRt(&CMIPSAssembler::OR));
SpecInstruction<RtRsSa> Instruction_SLL = SpecInstruction<RtRsSa>("SLL", RtRsSa(&CMIPSAssembler::SLL));
SpecInstruction<RtRsImm> Instruction_SLTI = SpecInstruction<RtRsImm>("SLTI", RtRsImm(&CMIPSAssembler::SLTI));
SpecInstruction<RtRsImm> Instruction_SLTIU = SpecInstruction<RtRsImm>("SLTIU", RtRsImm(&CMIPSAssembler::SLTIU));
SpecInstruction<RdRsRt> Instruction_SLTU = SpecInstruction<RdRsRt>("SLTU", RdRsRt(&CMIPSAssembler::SLTU));
SpecInstruction<RtRsSa> Instruction_SRA = SpecInstruction<RtRsSa>("SRA", RtRsSa(&CMIPSAssembler::SRA));
Instruction* g_Instructions[] =
{
&Instruction_ADDU,
&Instruction_ADDIU,
&Instruction_BEQ,
&Instruction_BGEZ,
&Instruction_BLEZ,
&Instruction_BNE,
&Instruction_DADDIU,
&Instruction_DSRA32,
&Instruction_LHU,
&Instruction_LUI,
&Instruction_LW,
&Instruction_MULT,
&Instruction_OR,
&Instruction_SLL,
&Instruction_SLTI,
&Instruction_SLTIU,
&Instruction_SLTU,
&Instruction_SRA,
NULL,
};
}

View File

@ -1,25 +0,0 @@
#ifndef _MIPSASSEMBLERDEFINITIONS_H_
#define _MIPSASSEMBLERDEFINITIONS_H_
#include <boost/tokenizer.hpp>
class CMIPSAssembler;
namespace MipsAssemblerDefinitions
{
struct Instruction
{
Instruction(const char* sMnemonic) :
m_sMnemonic(sMnemonic)
{
}
const char* m_sMnemonic;
virtual void Invoke(boost::tokenizer<>&, boost::tokenizer<>::iterator&, CMIPSAssembler*) = 0;
};
extern Instruction* g_Instructions[];
};
#endif

View File

@ -340,7 +340,6 @@
<ClCompile Include="..\Source\MIPSAnalysis.cpp" />
<ClCompile Include="..\Source\MIPSArchitecture.cpp" />
<ClCompile Include="..\Source\MIPSAssembler.cpp" />
<ClCompile Include="..\Source\MipsAssemblerDefinitions.cpp" />
<ClCompile Include="..\Source\MIPSCoprocessor.cpp" />
<ClCompile Include="..\Source\MipsExecutor.cpp" />
<ClCompile Include="..\Source\MipsFunctionPatternDb.cpp" />
@ -555,7 +554,6 @@
<ClInclude Include="..\Source\MIPSAnalysis.h" />
<ClInclude Include="..\Source\MIPSArchitecture.h" />
<ClInclude Include="..\Source\MIPSAssembler.h" />
<ClInclude Include="..\Source\MipsAssemblerDefinitions.h" />
<ClInclude Include="..\Source\MIPSCoprocessor.h" />
<ClInclude Include="..\Source\MipsExecutor.h" />
<ClInclude Include="..\Source\MipsFunctionPatternDb.h" />

View File

@ -112,9 +112,6 @@
<ClCompile Include="..\Source\MIPSAssembler.cpp">
<Filter>Source Files\Core</Filter>
</ClCompile>
<ClCompile Include="..\Source\MipsAssemblerDefinitions.cpp">
<Filter>Source Files\Core</Filter>
</ClCompile>
<ClCompile Include="..\Source\MIPSCoprocessor.cpp">
<Filter>Source Files\Core</Filter>
</ClCompile>
@ -699,9 +696,6 @@
<ClInclude Include="..\Source\MIPSAssembler.h">
<Filter>Source Files\Core</Filter>
</ClInclude>
<ClInclude Include="..\Source\MipsAssemblerDefinitions.h">
<Filter>Source Files\Core</Filter>
</ClInclude>
<ClInclude Include="..\Source\MIPSCoprocessor.h">
<Filter>Source Files\Core</Filter>
</ClInclude>

View File

@ -161,7 +161,6 @@
<ClCompile Include="..\..\Source\MIPSAnalysis.cpp" />
<ClCompile Include="..\..\Source\MIPSArchitecture.cpp" />
<ClCompile Include="..\..\Source\MIPSAssembler.cpp" />
<ClCompile Include="..\..\Source\MipsAssemblerDefinitions.cpp" />
<ClCompile Include="..\..\Source\MIPSCoprocessor.cpp" />
<ClCompile Include="..\..\Source\MipsExecutor.cpp" />
<ClCompile Include="..\..\Source\MIPSInstructionFactory.cpp" />
@ -191,7 +190,6 @@
<ClInclude Include="..\..\Source\MIPSAnalysis.h" />
<ClInclude Include="..\..\Source\MIPSArchitecture.h" />
<ClInclude Include="..\..\Source\MIPSAssembler.h" />
<ClInclude Include="..\..\Source\MipsAssemblerDefinitions.h" />
<ClInclude Include="..\..\Source\MIPSCoprocessor.h" />
<ClInclude Include="..\..\Source\MipsExecutor.h" />
<ClInclude Include="..\..\Source\MIPSInstructionFactory.h" />

View File

@ -70,9 +70,6 @@
<ClCompile Include="..\..\Source\MIPSAssembler.cpp">
<Filter>Source Files\Play Core</Filter>
</ClCompile>
<ClCompile Include="..\..\Source\MipsAssemblerDefinitions.cpp">
<Filter>Source Files\Play Core</Filter>
</ClCompile>
<ClCompile Include="Source\Add64Test.cpp">
<Filter>Source Files\Tests</Filter>
</ClCompile>
@ -141,9 +138,6 @@
<ClInclude Include="..\..\Source\MIPSAssembler.h">
<Filter>Source Files\Play Core</Filter>
</ClInclude>
<ClInclude Include="..\..\Source\MipsAssemblerDefinitions.h">
<Filter>Source Files\Play Core</Filter>
</ClInclude>
<ClInclude Include="Source\Test.h">
<Filter>Source Files</Filter>
</ClInclude>