예제 #1
0
파일: ldstr.py 프로젝트: iamedu/armdev
    def execute(self, proc, inst):
        if not utils.checkCondition(proc, inst):
            return

        modes =  component.getAllUtilitiesRegisteredFor(IARMLSMAddressingMode)
        for mode in modes:
            if utils.testInstruction(mode, inst):
                start_address, end_address = mode.getVal(proc, inst)
                break

        register_list = Bitset(utils.getBits(inst, 0, 16), 32)

        address = start_address
  
	print "Entra"

        for i in range(16):
            if register_list[i]:
		print i, getattr(proc, 'r' + str(i))
                proc.saveAddr(address, getattr(proc, 'r' + str(i)))
                address += 4

	print "Sale"

        if end_address != address - 4:
            raise exceptions.DataAbort()
예제 #2
0
파일: ldstr.py 프로젝트: iamedu/armdev
    def execute(self, proc, inst):
        if not utils.checkCondition(proc, inst):
            return

        modes =  component.getAllUtilitiesRegisteredFor(IARMLSMAddressingMode)
        for mode in modes:
            if utils.testInstruction(mode, inst):
                start_address, end_address = mode.getVal(proc, inst)
                break

        register_list = Bitset(utils.getBits(inst, 0, 16), 32)

        address = start_address
  
        for i in range(15):
            if register_list[i]:
                setattr(proc, 'r' + str(i), proc.readAddr(address, 4))
                address += 4

        if register_list[15]:
            value = proc.readAddr(address, 4)
            proc.pc = value & 0xFFFFFFFE
            address += 4

        if end_address != address - 4:
            raise exceptions.DataAbort()
예제 #3
0
파일: dp.py 프로젝트: iamedu/armdev
    def execute(self, proc, inst):
        shifter_operand   = 0
        shifter_carry_out = 0
        if not checkCondition(proc, inst):
            return

        S  = utils.getBits(inst, 20)
        I  = utils.getBits(inst, 25)
        rd = utils.getBits(inst, 12, 4)
        rd = 'r' + str(rd)
        rn = utils.getBits(inst, 16, 4)
        rn = 'r' + str(rn)
        rdVal = getattr(proc, rd)
        rnVal = getattr(proc, rn)

        modes =  component.getAllUtilitiesRegisteredFor(IARMDPAddressingMode)
        for mode in modes:
            if testInstruction(mode, inst):
                shifter_operand, shifter_carry_out = mode.getVal(proc, inst)
                break

        setattr(proc, rd, rnVal ^ shifter_operand)
        if S == 1 and rd == 'r15':
            try:
                proc.cpsr = proc.spsr
            except:
                print "UNPREDICTABLE"
        elif S == 1:
            proc.setStatusFlag('N', utils.getBits(getattr(proc, rd), 31))
            proc.setStatusFlag('Z', int(getattr(proc, rd) == 0))
            proc.setStatusFlag('C', shifter_carry_out)
예제 #4
0
파일: dp.py 프로젝트: iamedu/armdev
    def execute(self, proc, inst):
        shifter_operand   = 0
        shifter_carry_out = 0
        if not checkCondition(proc, inst):
            return

        rn = utils.getBits(inst, 16, 4)
        rn = 'r' + str(rn)
        rnVal = getattr(proc, rn)

        modes =  component.getAllUtilitiesRegisteredFor(IARMDPAddressingMode)
        for mode in modes:
            if testInstruction(mode, inst):
                shifter_operand, shifter_carry_out = mode.getVal(proc, inst)
                break

        rnBitset      = Bitset(rnVal, 32)
        shifterBitset = Bitset(shifter_operand, 32)
        alu_out, carry = rnBitset + shifter_operand
        
        if utils.getBits(rnVal, 31) == 0 and utils.getBits(int(result), 31) == 1:
            v = 1
        else:
            v = 0
        proc.setStatusFlag('N', utils.getBits(int(alu_out), 31))
        proc.setStatusFlag('Z', int(int(alu_out) == 0))
        proc.setStatusFlag('C', carry)
        proc.setStatusFlag('V', v)
예제 #5
0
    def run(self):
        processor = self
        instructions = component.getAllUtilitiesRegisteredFor(IARMInstruction)
        instructionLog = open('ilog', 'w')

        while self.__running:
            inst = processor.fetch()
            processor.step()
            executed = False
            if inst == 0:
                break
            try:
                for instruction in instructions:
                    if testInstruction(instruction, inst):
                        instructionLog.write(str(type(instruction)) + '\n')
                        instructionLog.flush()
                        instruction.execute(processor, inst)
                        executed = True
                        break
            except exceptions.ProcessorException as ex:
                ex.preprocess(self)
                executed = True

            if not executed:
                print "Instruction not recognized %x" % inst
        self.__running = False
예제 #6
0
파일: ldstr.py 프로젝트: iamedu/armdev
    def execute(self, proc, inst):
        if not utils.checkCondition(proc, inst):
            return

        modes =  component.getAllUtilitiesRegisteredFor(IARMLSMAddressingMode)
        for mode in modes:
            if utils.testInstruction(mode, inst):
                start_address, end_address = mode.getVal(proc, inst)
                break
        print "Ejecutaste un ldm(3)"
예제 #7
0
파일: ldstr.py 프로젝트: iamedu/armdev
    def execute(self, proc, inst):
        if not utils.checkCondition(proc, inst):
            return

        modes =  component.getAllUtilitiesRegisteredFor(IARMLSAddressingMode)
        for mode in modes:
            if utils.testInstruction(mode, inst):
                address = mode.getVal(proc, inst)
                break
        rd = utils.getBits(inst, 12, 4)
        rd = 'r' + str(rd)

        proc.saveAddr(address, getattr(proc, rd))
예제 #8
0
파일: ldstr.py 프로젝트: iamedu/armdev
    def execute(self, proc, inst):
        if not utils.checkCondition(proc, inst):
            return

        modes =  component.getAllUtilitiesRegisteredFor(IARMLSAddressingMode)
        for mode in modes:
            if utils.testInstruction(mode, inst):
                address = mode.getVal(proc, inst)
                break
        rd = utils.getBits(inst, 12, 4)
        rd = 'r' + str(rd)

        data = proc.readAddr(address, 2)
        data = utils.signExtend(data, 16, 32)

        setattr(proc, rd, data)
예제 #9
0
파일: dp.py 프로젝트: iamedu/armdev
    def execute(self, proc, inst):
        shifter_operand   = 0
        shifter_carry_out = 0
        if not checkCondition(proc, inst):
            return

        S  = utils.getBits(inst, 20)
        I  = utils.getBits(inst, 25)
        rd = utils.getBits(inst, 12, 4)
        rd = 'r' + str(rd)
        rn = utils.getBits(inst, 16, 4)
        rn = 'r' + str(rn)
        rdVal = getattr(proc, rd)
        rnVal = getattr(proc, rn)
        rnBitset = Bitset(rnVal, 32)
        carryBitset = Bitset(proc.statusFlag('C'), 32)

        modes =  component.getAllUtilitiesRegisteredFor(IARMDPAddressingMode)
        for mode in modes:
            if testInstruction(mode, inst):
                shifter_operand, shifter_carry_out = mode.getVal(proc, inst)
                break
        
        shifter_bitset = Bitset(shifter_operand, 32)

        result, carry = shifter_bitset - rnBitset
        resultBitset  = Bitset(result, 32)
        carryBitset[0] = not carryBitset[0]
        result, carry = resultBitset - carryBitset
        setattr(proc, rd, int(result))

        if S == 1 and rd == 'r15':
            try:
                proc.cpsr = proc.spsr
            except:
                print "UNPREDICTABLE"
        elif S == 1:
            if utils.getBits(rdVal, 31) == 0 and utils.getBits(int(result), 31) == 1:
                v = 1
            else:
                v = 0
            proc.setStatusFlag('N', utils.getBits(getattr(proc, rd), 31))
            proc.setStatusFlag('Z', int(getattr(proc, rd) == 0))
            proc.setStatusFlag('C', int(carry == 0))
            proc.setStatusFlag('V', v)
        print "Ejecutaste un rsc"
예제 #10
0
파일: ldstr.py 프로젝트: iamedu/armdev
    def execute(self, proc, inst):
        if not utils.checkCondition(proc, inst):
            return

        modes =  component.getAllUtilitiesRegisteredFor(IARMLSAddressingMode)
        for mode in modes:
            if utils.testInstruction(mode, inst):
                address = mode.getVal(proc, inst)
                break
        rd = utils.getBits(inst, 12, 4)
        rd = 'r' + str(rd)

        data = proc.readAddr(address)

        if rd == 'r15':
            proc.pc = data & 0xfffffffe
        else:
            setattr(proc, rd, data)
예제 #11
0
파일: dp.py 프로젝트: iamedu/armdev
    def execute(self, proc, inst):
        shifter_operand   = 0
        shifter_carry_out = 0
        if not checkCondition(proc, inst):
            return

        rn = utils.getBits(inst, 16, 4)
        rn = 'r' + str(rn)
        rnVal = getattr(proc, rn)

        modes =  component.getAllUtilitiesRegisteredFor(IARMDPAddressingMode)
        for mode in modes:
            if testInstruction(mode, inst):
                shifter_operand, shifter_carry_out = mode.getVal(proc, inst)
                break

        alu_out = rnVal ^ shifter_operand
        
        proc.setStatusFlag('N', utils.getBits(alu_out, 31))
        proc.setStatusFlag('Z', int(alu_out == 0))
        proc.setStatusFlag('C', shifter_carry_out)