def arm_sub(ctx, i): a = operand.get(ctx, i, 0) b = operand.get(ctx, i, 1) print i.update_flags print dir(i)
def arm_stm(ctx, i): value = operand.get(ctx, i, 0) address = operand.get(ctx, i, 1) ctx.emit(stm_(value, address)) if i.writeback: operand.writeback(ctx, i, 1)
def arm_stm(ctx, i): value = operand.get(ctx, i, 0) address = operand.get(ctx, i, 1) ctx.emit( stm_ (value, address)) if i.writeback: operand.writeback(ctx, i, 1)
def _arm_mov(ctx, i): prev_value = operand.get(ctx, i, 1) value = ctx.tmp(ctx.word_size) ctx.emit(str_(prev_value, value)) if i.update_flags: set_N(ctx, value) set_Z(ctx, value) operand.set(ctx, i, 0, value)
def arm_blx(ctx, i): target = operand.get(ctx, i, 0) pc = operand.get_register(ctx, i, 'pc') if ctx.thumb: prev_pc = pc pc = ctx.tmp(32) ctx.emit( or_ (prev_pc, imm(1, 32), pc)) operand.set_register(ctx, i, 'lr', pc) ctx.emit( jcc_ (imm(1, 8), target))
def _arm_mov(ctx, i): prev_value = operand.get(ctx, i, 1) value = ctx.tmp(ctx.word_size) ctx.emit( str_ (prev_value, value)) if i.update_flags: set_N(ctx, value) set_Z(ctx, value) operand.set(ctx, i, 0, value)
def arm_movt(ctx, i): # first extract the low 16 bits of the destination prev_value = operand.get(ctx, i, 0) value = ctx.tmp(ctx.word_size) ctx.emit(and_(prev_value, imm(mask(16), 32), value)) # then compute the high 16 bits prev_result = operand.get(ctx, i, 1) result = ctx.tmp(ctx.word_size) ctx.emit(str_(prev_result, result)) ctx.emit(lshl_(result, imm(16, 32), result)) ctx.emit(or_(value, result, result)) if i.update_flags: set_N(ctx, result) set_Z(ctx, result) operand.set(ctx, i, 0, result)
def arm_add(ctx, i): if len(i.operands) == 3: dst_idx = 0 a_idx = 1 b_idx = 2 else: dst_idx = 0 a_idx = 0 b_idx = 1 a = operand.get(ctx, i, a_idx) b = operand.get(ctx, i, b_idx) result = ctx.tmp(a.size * 2) ctx.emit( add_ (a, b, result)) if i.update_flags: raise NotImplementedError() operand.set(ctx, i, dst_idx, result)
def arm_add(ctx, i): if len(i.operands) == 3: dst_idx = 0 a_idx = 1 b_idx = 2 else: dst_idx = 0 a_idx = 0 b_idx = 1 a = operand.get(ctx, i, a_idx) b = operand.get(ctx, i, b_idx) result = ctx.tmp(a.size * 2) ctx.emit(add_(a, b, result)) if i.update_flags: raise NotImplementedError() operand.set(ctx, i, dst_idx, result)
def arm_movt(ctx, i): # first extract the low 16 bits of the destination prev_value = operand.get(ctx, i, 0) value = ctx.tmp(ctx.word_size) ctx.emit( and_ (prev_value, imm(mask(16), 32), value)) # then compute the high 16 bits prev_result = operand.get(ctx, i, 1) result = ctx.tmp(ctx.word_size) ctx.emit( str_ (prev_result, result)) ctx.emit( lshl_ (result, imm(16, 32), result)) ctx.emit( or_ (value, result, result)) if i.update_flags: set_N(ctx, result) set_Z(ctx, result) operand.set(ctx, i, 0, result)
def arm_push(ctx, i): for op in i.operands: value = operand.get(ctx, i, 0) ctx.emit( sub_(ctx.stack_ptr, imm(ctx.word_size // 8, ctx.word_size), ctx.stack_ptr)) if value.size != ctx.word_size: prev_value = value value = ctx.tmp(ctx.word_size) ctx.emit(sex_(prev_value, value)) ctx.emit(stm_(value, ctx.stack_ptr))
def arm_push(ctx, i): for op in i.operands: value = operand.get(ctx, i, 0) ctx.emit( sub_ (ctx.stack_ptr, imm(ctx.word_size // 8, ctx.word_size), ctx.stack_ptr)) if value.size != ctx.word_size: prev_value = value value = ctx.tmp(ctx.word_size) ctx.emit( sex_ (prev_value, value)) ctx.emit( stm_ (value, ctx.stack_ptr))
def arm_str(ctx, i): value = operand.get(ctx, i, 1) operand.set(ctx, i, 0, value)
def arm_b(ctx, i): target = operand.get(ctx, i, 0) ctx.emit( jcc_ (imm(1, 8), target))