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')
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')
def printMemEngine(command): base = command[2] # x or d address = command[3] freq = command[1] listOfHex = '' address = int(address, 16) #assume to be in hex freqcount = int(freq[0:-1]) freqtype = freq[-1] # b w or d numOfBits = '' if freqtype == 'w': for i in range(freqcount): data = mem.fetchWordFromMemory(address + (4 * i)) if data == const.TRAP: print 'Memory location could not be accessed' return listOfHex += data + ' ' numOfBits = 32 elif freqtype == 'd': for i in range(0, freqcount): data1 = mem.fetchWordFromMemory(address + (8 * i)) data2 = mem.fetchWordFromMemory(address + (8 * i) + 4) if data1 == const.TRAP or data2 == const.TRAP: print 'Memory location could not be accessed' return listOfHex += data2 + '' + data1 + ' ' numOfBits = 64 elif freqtype == 'b': for i in range(0, freqcount): data = mem.fetchByteFromHelperMemory(address + i) if data == const.TRAP: print 'Memory location could not be accessed' return listOfHex += data + ' ' numOfBits = 8 listOfHex = listOfHex.split() #print '' #print listOfHex #print '<'+command[3]+'>'+' : \t\t', pretty = 0 for i in listOfHex: if (pretty % 4 == 0): print '' print '<' + command[3] + '>' + ' + ' + str( (pretty * numOfBits) / 8) + ' : \t\t', if base == 'x': print '0x' + i + '\t\t', elif base == 'd': binary = utilFunc.hexToBin('0x' + i, numOfBits) print str(utilFunc.sInt(binary, numOfBits)) + '\t\t', print ' ', pretty = pretty + 1 print ''
def printMemEngine(command): base=command[2] # x or d address=command[3] freq=command[1] listOfHex='' address=int(address,16) #assume to be in hex freqcount=int(freq[0:-1]) freqtype=freq[-1] # b w or d numOfBits='' if freqtype=='w': for i in range(freqcount): data=mem.fetchWordFromMemory(address+(4*i)) if data==const.TRAP: print 'Memory location could not be accessed' return listOfHex+=data+' ' numOfBits=32 elif freqtype=='d': for i in range(0,freqcount): data1=mem.fetchWordFromMemory(address+(8*i)) data2=mem.fetchWordFromMemory(address+(8*i)+4) if data1==const.TRAP or data2==const.TRAP: print 'Memory location could not be accessed' return listOfHex+=data2+''+data1+' ' numOfBits=64 elif freqtype=='b': for i in range(0,freqcount): data=mem.fetchByteFromHelperMemory(address+i) if data==const.TRAP: print 'Memory location could not be accessed' return listOfHex+=data+' ' numOfBits=8 listOfHex=listOfHex.split() #print '' #print listOfHex #print '<'+command[3]+'>'+' : \t\t', pretty=0 for i in listOfHex: if (pretty%4==0): print '' print '<'+command[3]+'>'+' + '+str((pretty*numOfBits)/8)+' : \t\t', if base=='x': print '0x'+i+'\t\t', elif base=='d': binary=utilFunc.hexToBin('0x'+i, numOfBits) print str(utilFunc.sInt(binary, numOfBits))+'\t\t', print ' ', pretty=pretty+1 print ''
def helper_reg_unsignedOffset(binary, instr): rtKey = utilFunc.getRegKeyByStringKey(binary[27:32]) rnKey = utilFunc.getRegKeyByStringKey(binary[22:27]) imm12 = binary[10:22] opc = binary[8:10] size = binary[0:2] wback = False postIndex = False scale = utilFunc.uInt(size) offset = utilFunc.lsl(utilFunc.zeroExtend(imm12, 64), scale) offset = utilFunc.sInt(offset, 64) instr += str(rtKey) + ", [x" + str(rnKey) + ", #" + str(offset) + "]" helper_all(binary, opc, size, wback, postIndex, offset, rtKey, rnKey, scale, instr)
def helper_reg_prei(binary, instr): rtKey = utilFunc.getRegKeyByStringKey(binary[27:32]) rnKey = utilFunc.getRegKeyByStringKey(binary[22:27]) imm9 = binary[11:20] opc = binary[8:10] size = binary[0:2] wback = True postIndex = False scale = utilFunc.uInt(size) offset = utilFunc.signExtend(imm9, 64) offset = utilFunc.sInt(offset, 64) instr += str(rtKey) + ", [x" + str(rnKey) + ", #" + str(offset) + "]!" helper_all(binary, opc, size, wback, postIndex, offset, rtKey, rnKey, scale, instr)
def helper_reg(binary, instr): rtKey = utilFunc.getRegKeyByStringKey(binary[27:32]) rnKey = utilFunc.getRegKeyByStringKey(binary[22:27]) rmKey = utilFunc.getRegKeyByStringKey(binary[11:16]) rnVal = utilFunc.getRegValueByStringkey(binary[22:27], '1') rmVal = utilFunc.getRegValueByStringkey(binary[11:16], '0') s = binary[19] option = binary[16:19] opc = binary[8:10] size = binary[0:2] wback = False postIndex = False scale = utilFunc.uInt(size) if s == '1': shift = scale else: shift = 0 if (option[1:3] == '10'): rmToPrint = 'w' elif (option[1:3] == '11'): rmToPrint = 'x' instr += str(rtKey) + ", [x" + str(rnKey) + ", " + rmToPrint + str( rmKey) + ", " offset, instr = utilFunc.extendReg(rmVal, shift, option, instr, 64) offset = utilFunc.sInt(offset, 64) instr += ' #' if size == '10': if s == '0': instr += '0' else: instr += '2' if size == '11': if s == '0': instr += '0' else: instr += '3' instr += ']' helper_all(binary, opc, size, wback, postIndex, offset, rtKey, rnKey, scale, instr)
def helper_reg(binary, instr): rtKey = utilFunc.getRegKeyByStringKey(binary[27:32]) rnKey = utilFunc.getRegKeyByStringKey(binary[22:27]) rmKey = utilFunc.getRegKeyByStringKey(binary[11:16]) rnVal = utilFunc.getRegValueByStringkey(binary[22:27], '1') rmVal = utilFunc.getRegValueByStringkey(binary[11:16], '0') s = binary[19] option = binary[16:19] opc = binary[8:10] size = binary[0:2] wback = False postIndex = False scale = utilFunc.uInt(size) if s == '1': shift = scale else: shift = 0 if(option[1:3] == '10'): rmToPrint = 'w' elif(option[1:3] == '11'): rmToPrint = 'x' instr += str(rtKey) + ", [x" + str(rnKey) + ", " + rmToPrint + str(rmKey) + ", " offset, instr = utilFunc.extendReg(rmVal, shift, option, instr, 64) offset = utilFunc.sInt(offset, 64) instr += ' #' if size == '10': if s == '0': instr += '0' else: instr += '2' if size == '11': if s == '0': instr += '0' else: instr += '3' instr += ']' helper_all(binary, opc, size, wback, postIndex, offset, rtKey, rnKey, scale, 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)
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)