Sha256: 71ee2e2d44c8abf21da1b7abb5794bb012aed743fa80a4ec48f8b4d546d79b7c
Contents?: true
Size: 1.4 KB
Versions: 4
Compression:
Stored size: 1.4 KB
Contents
# This file is part of Metasm, the Ruby assembly manipulation suite # Copyright (C) 2006-2009 Yoann GUILLOT # # Licence is LGPL, see LICENCE in the top-level directory require 'metasm/cpu/mips/opcodes' require 'metasm/encode' module Metasm class MIPS private def encode_instr_op(exe, instr, op) base = op.bin set_field = lambda { |f, v| base |= (v & @fields_mask[f]) << @fields_shift[f] } val, mask, shift = 0, 0, 0 # convert label name for jmp/call/loop to relative offset if op.props[:setip] and op.name[0] != ?t and instr.args.last.kind_of? Expression postlabel = exe.new_label('jmp_offset') instr = instr.dup if op.args.include? :i26 pl = Expression[postlabel, :&, 0xfc00_0000] else pl = postlabel end instr.args[-1] = Expression[[instr.args[-1], :-, pl], :>>, 2] postdata = EncodedData.new '', :export => {postlabel => 0} else postdata = '' end op.args.zip(instr.args).each { |sym, arg| case sym when :rs, :rt, :rd, :ft set_field[sym, arg.i] when :rs_i16 set_field[:rs, arg.base.i] val, mask, shift = arg.offset, @fields_mask[:i16], @fields_shift[:i16] when :sa, :i16, :i20, :i26, :it, :msbd, :sel, :idb val, mask, shift = arg, @fields_mask[sym], @fields_shift[sym] val = Expression[val, :-, 1] if sym == :msbd end } Expression[base, :|, [[val, :&, mask], :<<, shift]].encode(:u32, @endianness) << postdata end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
metasm-1.0.5 | metasm/cpu/mips/encode.rb |
metasm-1.0.4 | metasm/cpu/mips/encode.rb |
metasm-1.0.3 | metasm/cpu/mips/encode.rb |
metasm-1.0.2 | metasm/cpu/mips/encode.rb |