Ejemplo n.º 1
0
bool RARSetLastInstrOperands(RARProgram *prog, uint8_t addressingmode1, uint32_t value1, uint8_t addressingmode2, uint32_t value2)
{
    RAROpcode *opcode = &prog->opcodes[prog->length - 1];
    int numoperands;

    if (addressingmode1 >= RARNumberOfAddressingModes || addressingmode2 >= RARNumberOfAddressingModes)
        return false;
    if (!prog->length || opcode->addressingmode1 || opcode->value1 || opcode->addressingmode2 || opcode->value2)
        return false;

    numoperands = NumberOfRARInstructionOperands(opcode->instruction);
    if (numoperands == 0)
        return true;

    if (addressingmode1 == RARImmediateAddressingMode && RARInstructionWritesFirstOperand(opcode->instruction))
        return false;
    opcode->addressingmode1 = addressingmode1;
    opcode->value1 = value1;

    if (numoperands == 2) {
        if (addressingmode2 == RARImmediateAddressingMode && RARInstructionWritesSecondOperand(opcode->instruction))
            return false;
        opcode->addressingmode2 = addressingmode2;
        opcode->value2 = value2;
    }

    return true;
}
Ejemplo n.º 2
0
bool PrepareRAROpcodes(RAROpcode *opcodes,int numopcodes)
{
	void **instructionlabels_32,**instructionlabels_8;

	RunVirtualMachineOrGetLabels(NULL,NULL,0,&instructionlabels_32);
	instructionlabels_8=&instructionlabels_32[RARNumberOfInstructions];

	for(int i=0;i<numopcodes;i++)
	{
		if(opcodes[i].instruction>=RARNumberOfInstructions) return false;

		void **instructionlabels;
		RARSetterFunction *setterfunctions;
		RARGetterFunction *getterfunctions;

		if(opcodes[i].instruction==RARMovsxInstruction||opcodes[i].instruction==RARMovzxInstruction)
		{
			instructionlabels=instructionlabels_32;
			getterfunctions=OperandGetters_8;
			setterfunctions=OperandSetters_32;
		}
		else if(opcodes[i].bytemode)
		{
			if(!RARInstructionHasByteMode(opcodes[i].instruction)) return false;

			instructionlabels=instructionlabels_8;
			getterfunctions=OperandGetters_8;
			setterfunctions=OperandSetters_8;
		}
		else
		{
			instructionlabels=instructionlabels_32;
			getterfunctions=OperandGetters_32;
			setterfunctions=OperandSetters_32;
		}

		opcodes[i].instructionlabel=instructionlabels[opcodes[i].instruction];

		int numoperands=NumberOfRARInstructionOperands(opcodes[i].instruction);

		if(numoperands>=1)
		{
			if(opcodes[i].addressingmode1>=RARNumberOfAddressingModes) return false;
			opcodes[i].operand1getter=getterfunctions[opcodes[i].addressingmode1];
			opcodes[i].operand1setter=setterfunctions[opcodes[i].addressingmode1];

			if(opcodes[i].addressingmode1==RARImmediateAddressingMode)
			{
				if(RARInstructionWritesFirstOperand(opcodes[i].instruction)) return false;
			}
			else if(opcodes[i].addressingmode1==RARAbsoluteAddressingMode)
			{
				opcodes[i].value1&=RARProgramMemoryMask;
			}
		}

		if(numoperands==2)
		{
			if(opcodes[i].addressingmode2>=RARNumberOfAddressingModes) return false;
			opcodes[i].operand2getter=getterfunctions[opcodes[i].addressingmode2];
			opcodes[i].operand2setter=setterfunctions[opcodes[i].addressingmode2];

			if(opcodes[i].addressingmode2==RARImmediateAddressingMode)
			{
				if(RARInstructionWritesSecondOperand(opcodes[i].instruction)) return false;
			}
			else if(opcodes[i].addressingmode2==RARAbsoluteAddressingMode)
			{
				opcodes[i].value2&=RARProgramMemoryMask;
			}
		}
	}

	return true;
}