Example #1
0
            }
            break;
        }
        case 0xE:{
            // AL
            break;
        }
        default:{
            // Not recognized condition code
            THROW_EXCEPTION("Unrecognized condition code: " << cond);
            break;
        }
    }
}
""")
condCheckOp = trap.HelperOperation('condition_check', opCode)
condCheckOp.addUserInstructionElement('cond')
# Now I define the behavior for the shift immediate operation: all data processing instructions with
# an immediate value and a shift use it
opCode = cxx_writer.writer_code.Code("""
if(shift_op == 0 && shift_amm == 0){
    operand = rm;
    carry = (CPSR[key_C] != 0);
}
else{
    switch(shift_op) {
        case 0x0:{
            // Logical shift left
            operand = rm << shift_amm;
            carry = ((rm & (0x01 << (32 - shift_amm))) != 0);
            break;}
""")
SignExtend_method = trap.HelperMethod('SignExtend', opCode, 'execute')
SignExtend_method.setSignature(('BIT<32>'), [('bitSeq', 'BIT<32>'), cxx_writer.writer_code.Parameter('bitSeq_length', cxx_writer.writer_code.uintType)])

# PC increment
opCode = cxx_writer.writer_code.Code("""
if (TARGET == 0xffffffff) {
	PC = PC + 4;
	DSFLAG = 0x0;
} else {
	PC = TARGET;
	TARGET = 0xffffffff;
	DSFLAG = 0x1;
}
""")
IncrementPC = trap.HelperOperation('IncrementPC', opCode, inline = False)

opCode = cxx_writer.writer_code.Code("""
	if ( IMMREG & 0x80000000 ) {  /* IMM instruction */
		imm_value = ((int)imm & 0x0000ffff) + (int)(IMMREG << 16);
		IMMREG &= 0x7fffffff;
	} else {	/* No IMM instruction */
		imm_value = (int)SignExtend(imm,16);
	} 
	
	
""")
IMM_handler = trap.HelperOperation('IMM_handler', opCode)
IMM_handler.addInstuctionVar(('imm_value', 'BIT<32>'))
IMM_handler.addUserInstructionElement('imm')
Example #3
0
                                     cxx_writer.writer_code.uintType))
RaiseException_methodParams.append(
    cxx_writer.writer_code.Parameter('customTrapOffset',
                                     cxx_writer.writer_code.uintType,
                                     initValue='0'))
RaiseException_method.setSignature(cxx_writer.writer_code.voidType,
                                   RaiseException_methodParams)

# Code used increment the program counter, moving it to the next instruction in
# the instruction stream
opCode = cxx_writer.writer_code.Code("""unsigned int npc = NPC;
PC = npc;
npc += 4;
NPC = npc;
""")
IncrementPC = trap.HelperOperation('IncrementPC', opCode, exception=False)

# Write back of the result of most operations, expecially ALUs;
# such operations do not modify the PSR
opCode = cxx_writer.writer_code.Code("""
rd = result;
""")
WB_plain = trap.HelperOperation('WB_plain', opCode, exception=False)
WB_plain.addInstuctionVar(('result', 'BIT<32>'))
WB_plain.addUserInstructionElement('rd')

# Write back of the result of most operations, expecially ALUs;
# such operations also modify the PSR
opCode = cxx_writer.writer_code.Code("""
if(!temp_V){
    rd = result;