Пример #1
0
def CBZClass(binary, width, bool):
    rtKey = binary[-5:]
    inst = 'CBZ '
    char = ''
    if width == 64:
        char = 'X'
    else:
        char = 'W'
    inst += char
    regnum = utilFunc.uInt(rtKey)
    inst += str(regnum) + ', OFFSET('
    imm19Key = binary[8:27]

    (instpart, offset) = utilFunc.getOffset(imm19Key)
    inst += instpart + ')'

    regValue = getRegValueByStringkey(rtKey, '0')
    regValue = regValue[0:width]  #since CBZ_32
    if bool:
        if regValue == '0' * width:
            utilFunc.branchWithOffset(offset)
    else:
        if regValue != '0' * width:
            utilFunc.branchWithOffset(offset)
    utilFunc.finalize_simple(inst)
Пример #2
0
def CBZClass(binary,width,bool):
    rtKey=binary[-5:]
    inst='CBZ '
    char=''
    if width==64:
        char='X'
    else:
        char='W'
    inst+=char
    regnum=utilFunc.uInt(rtKey)
    inst+=str(regnum)+', OFFSET('
    imm19Key=binary[8:27]

    (instpart,offset)=utilFunc.getOffset(imm19Key)
    inst+=instpart+')'
    
    regValue=getRegValueByStringkey(rtKey, '0')
    regValue=regValue[0:width]#since CBZ_32
    if bool:
        if regValue=='0'*width:
            utilFunc.branchWithOffset(offset)
    else:
        if regValue!='0'*width:
            utilFunc.branchWithOffset(offset)
    utilFunc.finalize_simple(inst)
def helper_l(binary, instr):
    rtKey = utilFunc.getRegKeyByStringKey(binary[27:32])
    imm19 = binary[8:27]
    opc = binary[0:2]
    signed = False
    
    if(opc == '00'):
        size = 4
    elif(opc == '01'):
        size = 8
    elif(opc == '10'):
        size = 4
        signed = True
        
    offset = utilFunc.signExtend(imm19 + '00', 64)
    offset = utilFunc.sInt(offset, 64)
    
    address = armdebug.getPC() + offset
    dataSize = size * 8
    
    data = utilFunc.fetchFromMemory(address, dataSize)
    
    if(data == const.TRAP):
            utilFunc.finalize_simple(instr)
            print "HEY!!! There seems to be a problem - memory location can not be accessed"
            print "Moving ahead without executing the instruction"
            return
    
    if(signed):
        data = utilFunc.signExtend(data, 64)
    instr += str(rtKey) + ", #" + str(offset)
    utilFunc.finalize(rtKey, data.zfill(64), instr, '0')
Пример #4
0
def helper_l(binary, instr):
    rtKey = utilFunc.getRegKeyByStringKey(binary[27:32])
    imm19 = binary[8:27]
    opc = binary[0:2]
    signed = False

    if (opc == '00'):
        size = 4
    elif (opc == '01'):
        size = 8
    elif (opc == '10'):
        size = 4
        signed = True

    offset = utilFunc.signExtend(imm19 + '00', 64)
    offset = utilFunc.sInt(offset, 64)

    address = armdebug.getPC() + offset
    dataSize = size * 8

    data = utilFunc.fetchFromMemory(address, dataSize)

    if (data == const.TRAP):
        utilFunc.finalize_simple(instr)
        print "HEY!!! There seems to be a problem - memory location can not be accessed"
        print "Moving ahead without executing the instruction"
        return

    if (signed):
        data = utilFunc.signExtend(data, 64)
    instr += str(rtKey) + ", #" + str(offset)
    utilFunc.finalize(rtKey, data.zfill(64), instr, '0')
Пример #5
0
def helper_all(binary, opc, size, wback, postIndex, offset, rtKey, rnKey,
               scale, instr):
    if (opc[0] == '0'):
        if (opc[1] == '1'):
            memOp = const.MEM_OP_LOAD
        else:
            memOp = const.MEM_OP_STORE
        if (size == '11'):
            regSize = 64
        else:
            regSize = 32
        signed = False
    else:
        if (size == '11'):
            memOp = const.MEM_OP_PREFETCH
        else:
            memOp = const.MEM_OP_LOAD
            if opc[1] == '1':
                regSize = 32
            else:
                regSize = 64
            signed = True

    dataSize = 8 << scale

    '''wb_unknown = False
    rt_unknown = False'''  # commenting - assuming them to be false always

    address = utilFunc.getRegValueByStringkey(binary[22:27], '1')
    address = utilFunc.uInt(address)
    if not (postIndex):
        address = address + offset

    if (memOp == const.MEM_OP_STORE):
        data = utilFunc.getRegValueByStringkey(binary[27:32], '0')
        utilFunc.storeToMemory(data, address, dataSize)

    elif (memOp == const.MEM_OP_LOAD):
        data = utilFunc.fetchFromMemory(address, dataSize)
        if (data == const.TRAP):
            utilFunc.finalize_simple(instr)
            print "HEY!!! There seems to be a problem - memory location can not be accessed"
            print "Moving ahead without executing the instruction"
            return
        if (signed):
            data = utilFunc.signExtend(data, regSize)
        else:
            data = utilFunc.zeroExtend(data, regSize)

    utilFunc.setRegValue(rtKey, data.zfill(64), '0')

    if (wback):
        if postIndex:
            address = address + offset
        address = utilFunc.intToBinary(address, 64)
        utilFunc.setRegValue(rnKey, address, '1')

    utilFunc.finalize_simple(instr)
Пример #6
0
def execB(binary):
    inst = 'B OFFSET('
    imm26key = binary[6:32]

    (instpart, offset) = utilFunc.getOffset(imm26key)
    inst += instpart + ')'

    utilFunc.branchWithOffset(offset)  #the magic!
    utilFunc.finalize_simple(inst)
Пример #7
0
def execB(binary):
    inst ='B OFFSET('
    imm26key=binary[6:32]
    
    (instpart,offset)=utilFunc.getOffset(imm26key)
    inst+=instpart+')'
    
    utilFunc.branchWithOffset(offset) #the magic!
    utilFunc.finalize_simple(inst)
def helper_all(binary, opc, size, wback, postIndex, offset, rtKey, rnKey, scale, instr):
    if(opc[0] == '0'):
        if(opc[1] == '1'):
            memOp = const.MEM_OP_LOAD
        else:
            memOp = const.MEM_OP_STORE
        if(size == '11'):
            regSize = 64
        else:
            regSize = 32
        signed = False
    else:
        if(size == '11'):
            memOp = const.MEM_OP_PREFETCH
        else:
            memOp = const.MEM_OP_LOAD
            if opc[1] == '1':
                regSize = 32
            else:
                regSize = 64
            signed = True
            
    dataSize = 8 << scale
    
    '''wb_unknown = False
    rt_unknown = False'''  # commenting - assuming them to be false always 
    
    address = utilFunc.getRegValueByStringkey(binary[22:27], '1')
    address = utilFunc.uInt(address)
    if not(postIndex):
        address = address + offset
        
    if(memOp == const.MEM_OP_STORE):
        data = utilFunc.getRegValueByStringkey(binary[27:32], '0')
        utilFunc.storeToMemory(data, address, dataSize)
            
    elif(memOp == const.MEM_OP_LOAD):
        data = utilFunc.fetchFromMemory(address, dataSize)
        if(data == const.TRAP):
            utilFunc.finalize_simple(instr)
            print "HEY!!! There seems to be a problem - memory location can not be accessed"
            print "Moving ahead without executing the instruction"            
            return   
        if(signed):
            data = utilFunc.signExtend(data, regSize)
        else:
            data = utilFunc.zeroExtend(data, regSize)
            
    utilFunc.setRegValue(rtKey, data.zfill(64), '0')
        
    if(wback):
        if postIndex:
            address = address + offset
        address = utilFunc.intToBinary(address, 64)
        utilFunc.setRegValue(rnKey, address, '1')
    
    utilFunc.finalize_simple(instr)
Пример #9
0
def execBL(binary):
    inst='BL OFFSET('
    imm26key=binary[-26:]
    
    (instpart,offset)=utilFunc.getOffset(imm26key)
    inst+=instpart+')'
    
    nextAddr=armdebug.getPC()+4
    utilFunc.setRegValue(30, utilFunc.intToBinary(nextAddr, 64), '0')
    utilFunc.branchWithOffset(offset)
    utilFunc.finalize_simple(inst)
Пример #10
0
def execBL(binary):
    inst = 'BL OFFSET('
    imm26key = binary[-26:]

    (instpart, offset) = utilFunc.getOffset(imm26key)
    inst += instpart + ')'

    nextAddr = armdebug.getPC() + 4
    utilFunc.setRegValue(30, utilFunc.intToBinary(nextAddr, 64), '0')
    utilFunc.branchWithOffset(offset)
    utilFunc.finalize_simple(inst)
Пример #11
0
def execBR(binary):
    inst = 'BR X'
    rnKey=binary[22:27]
    address_binary=utilFunc.getRegValueByStringkey(rnKey, '0')
    regnum=utilFunc.uInt(rnKey)
    inst+=str(regnum)
    hexstr = utilFunc.binaryToHexStr(address_binary)
    if not armdebug.checkIfValidBreakPoint(hexstr):
        utilFunc.finalize_simple('Instruction aborted. Invalid instruction address in register.')
        return
    utilFunc.branchToAddress(int(hexstr,16))
    utilFunc.finalize_simple(inst)
Пример #12
0
def execADR(binary):
    inst='ADR X'
    rdKey=binary[-5:]
    regnum=utilFunc.uInt(rdKey)
    inst+=str(regnum)+', OFFSET('
    immLo=binary[1:3]
    immHi=binary[8:27]
    imm=immHi+immLo
    (inst_part,offset)=utilFunc.getOffsetWithoutTimes(imm)
    inst+=inst_part+')'
    nextAddr=utilFunc.PCwithOffset(offset)#as our PC implementation is wrong till now
    utilFunc.setRegValue(regnum, utilFunc.intToBinary(nextAddr, 64), '0')
    utilFunc.finalize_simple(inst)
Пример #13
0
def execBR(binary):
    inst = 'BR X'
    rnKey = binary[22:27]
    address_binary = utilFunc.getRegValueByStringkey(rnKey, '0')
    regnum = utilFunc.uInt(rnKey)
    inst += str(regnum)
    hexstr = utilFunc.binaryToHexStr(address_binary)
    if not armdebug.checkIfValidBreakPoint(hexstr):
        utilFunc.finalize_simple(
            'Instruction aborted. Invalid instruction address in register.')
        return
    utilFunc.branchToAddress(int(hexstr, 16))
    utilFunc.finalize_simple(inst)
Пример #14
0
def execBCond(binary):

    bits_four = binary[-4:]
    xx = utilFunc.conditionHolds(bits_four)
    if not xx[0]:
        return

    inst = 'B.' + xx[1] + ' OFFSET('
    imm19key = binary[8:27]

    (instpart, offset) = utilFunc.getOffset(imm19key)
    inst += instpart + ')'

    utilFunc.branchWithOffset(offset)  #the magic!
    utilFunc.finalize_simple(inst)
Пример #15
0
def execBCond(binary):
    
    bits_four=binary[-4:]
    xx=utilFunc.conditionHolds(bits_four)    
    if not xx[0]:
        return
    
    inst ='B.'+xx[1]+' OFFSET('
    imm19key=binary[8:27]
    
    (instpart,offset)=utilFunc.getOffset(imm19key)
    inst+=instpart+')'
    
    utilFunc.branchWithOffset(offset) #the magic!
    utilFunc.finalize_simple(inst)
Пример #16
0
def execNOP(binary):
    utilFunc.finalize_simple("NOP")
Пример #17
0
def helper_rp(wback, postIndex, binary, instr):
    rtKey = utilFunc.getRegKeyByStringKey(binary[27:32])
    rnKey = utilFunc.getRegKeyByStringKey(binary[22:27])
    rt2Key = utilFunc.getRegKeyByStringKey(binary[17:22])

    imm7 = binary[10:17]
    l = binary[9]
    opc = binary[0:2]

    if (l == '1'):
        memOp = const.MEM_OP_LOAD
    else:
        memOp = const.MEM_OP_STORE

    signed = (opc[1] != '0')
    scale = 2 + utilFunc.uInt(opc[0])

    dataSize = 8 << scale
    offset = utilFunc.lsl(utilFunc.signExtend(imm7, 64), scale)
    offset = utilFunc.sInt(offset, 64)

    dbytes = dataSize / 8

    address = utilFunc.getRegValueByStringkey(binary[22:27], '1')
    address = utilFunc.uInt(address)

    if not (postIndex):
        address = address + offset

    type = binary[7:9]
    if (opc == '00'):
        r = 'w'
    if (opc == '10'):
        r = 'x'

    if (type == '01'):
        #Post-index
        instr += " " + r + str(rtKey) + ", " + r + str(rt2Key) + ", [x" + str(
            rnKey) + "], #" + str(offset)
    if (type == '11'):
        #Pre-index
        instr += " " + r + str(rtKey) + ", " + r + str(rt2Key) + ", [x" + str(
            rnKey) + ", #" + str(offset) + "]!"
    if (type == '10'):
        #Signed-offset
        instr += " " + r + str(rtKey) + ", " + r + str(rt2Key) + ", [x" + str(
            rnKey) + ", #" + str(offset) + "]"

    if (memOp == const.MEM_OP_STORE):
        data1 = utilFunc.getRegValueByStringkey(binary[27:32], '0')
        data2 = utilFunc.getRegValueByStringkey(binary[17:22], '0')
        utilFunc.storeToMemory(data1, address, dataSize)
        utilFunc.storeToMemory(data2, address + dbytes, dataSize)

    elif (memOp == const.MEM_OP_LOAD):
        data1 = utilFunc.fetchFromMemory(address, dataSize)
        data2 = utilFunc.fetchFromMemory(address + dbytes, dataSize)

        if (data1 == const.TRAP or data2 == const.TRAP):
            utilFunc.finalize_simple(instr)
            print "HEY!!! There seems to be a problem - memory location can not be accessed"
            print "Moving ahead without executing the instruction"
            return

        if (signed):
            data1 = utilFunc.signExtend(data1, 64)
            data2 = utilFunc.signExtend(data2, 64)

        utilFunc.setRegValue(rtKey, data1.zfill(64), '0')
        utilFunc.setRegValue(rt2Key, data2.zfill(64), '0')

    if (wback):
        if postIndex:
            address = address + offset
        address = utilFunc.intToBinary(address, 64)
        utilFunc.setRegValue(rnKey, address, '1')

    utilFunc.finalize_simple(instr)
def helper_rp(wback, postIndex, binary, instr):
     rtKey = utilFunc.getRegKeyByStringKey(binary[27:32])
     rnKey = utilFunc.getRegKeyByStringKey(binary[22:27])
     rt2Key = utilFunc.getRegKeyByStringKey(binary[17:22])
     
     imm7 = binary[10:17]
     l = binary[9]     
     opc = binary[0:2]
     
     if(l == '1'):
         memOp = const.MEM_OP_LOAD
     else:
         memOp = const.MEM_OP_STORE

     signed = (opc[1] != '0')
     scale = 2 + utilFunc.uInt(opc[0])
     
     dataSize = 8 << scale
     offset = utilFunc.lsl(utilFunc.signExtend(imm7, 64), scale)
     offset = utilFunc.sInt(offset, 64)
     
     dbytes = dataSize / 8;
     
     address = utilFunc.getRegValueByStringkey(binary[22:27], '1')
     address = utilFunc.uInt(address)
     
     if not(postIndex):
        address = address + offset
     
     type = binary[7:9]
     if(opc == '00'):
         r = 'w'
     if(opc == '10'):
         r = 'x'
            
     if(type == '01'):
         #Post-index
         instr += " " + r + str(rtKey) +", " + r + str(rt2Key) + ", [x" + str(rnKey) + "], #" + str(offset) 
     if(type == '11'):
         #Pre-index
         instr += " " + r + str(rtKey) +", " + r + str(rt2Key) + ", [x" + str(rnKey) + ", #" + str(offset) + "]!"   
     if(type == '10'):
         #Signed-offset
         instr += " " + r + str(rtKey) +", " + r + str(rt2Key) + ", [x" + str(rnKey) + ", #" + str(offset) + "]"
     
     
     if(memOp == const.MEM_OP_STORE):
        data1 = utilFunc.getRegValueByStringkey(binary[27:32], '0')
        data2 = utilFunc.getRegValueByStringkey(binary[17:22], '0')  
        utilFunc.storeToMemory(data1, address, dataSize)
        utilFunc.storeToMemory(data2, address + dbytes, dataSize)
             
     elif(memOp == const.MEM_OP_LOAD):
        data1 = utilFunc.fetchFromMemory(address, dataSize)
        data2 = utilFunc.fetchFromMemory(address + dbytes, dataSize)
        
        if(data1 == const.TRAP or data2 == const.TRAP):
            utilFunc.finalize_simple(instr)
            print "HEY!!! There seems to be a problem - memory location can not be accessed"
            print "Moving ahead without executing the instruction"
            return
        
        if(signed):
            data1 = utilFunc.signExtend(data1, 64)
            data2 = utilFunc.signExtend(data2, 64)
            
        utilFunc.setRegValue(rtKey, data1.zfill(64), '0')
        utilFunc.setRegValue(rt2Key, data2.zfill(64), '0')
     
     if(wback):       
         if postIndex:
            address = address + offset
         address = utilFunc.intToBinary(address, 64)            
         utilFunc.setRegValue(rnKey, address, '1')
    
     utilFunc.finalize_simple(instr)