Exemplo n.º 1
0
def test_inst(code, inst):
  code.add(inst)
  code.cache_code()

  nasm_hex_str = get_nasm_output(code, inst)
  corepy_hex_str = get_corepy_output(code, inst)

  if nasm_hex_str == None:
      print "***************************  NASM ERROR"
      print "corepy output:", corepy_hex_str
      printer.PrintInstructionStream(code,
          printer.x86_Nasm(show_epilogue = False, show_prologue = False))
      return 'nasm_fail'
  elif nasm_hex_str == corepy_hex_str:
    print "PASS"
    return 'pass'
  else:
    #nasm_rex = int(nasm_hex_str[0:2], 16)
    #corepy_rex = int(corepy_hex_str[0:2], 16)
    #if corepy_rex - nasm_rex == 8 and (nasm_rex & 0xF0 == 0x40):
    #  print "WARNING CorePy is enabling 64bit for this inst, NASM is not"
    #  print "nasm output:   ", nasm_hex_str
    #  print "corepy output:", corepy_hex_str
    #  return 'rex_pass'
    #else:
    print "***************************  ERROR"
    print "nasm output:  ", nasm_hex_str
    print "corepy output:", corepy_hex_str
    printer.PrintInstructionStream(code,
        printer.x86_Nasm(show_epilogue = False, show_prologue = False))
    return 'fail'
  return
Exemplo n.º 2
0
    def ResetCode(self):
        self.editCtrl.ClearAll()

        fd = StringIO.StringIO()
        printer.PrintInstructionStream(self.app.code, printer.Default(), fd=fd)

        for line in fd.getvalue().split('\n'):
            if line != "" and line != "BODY:":
                self.editCtrl.AddText("%s\n" % line)
        fd.close()

        return
Exemplo n.º 3
0
def get_nasm_output(code, inst):
  """Take an instruction, and return a hex string of its encoding, as encoded by GAS"""
 
  fd = open("x86_test.s", "w")
  printer.PrintInstructionStream(code, printer.x86_Nasm(function_name="_start"), fd = fd)
  fd.close()

  ret = subprocess.call(["nasm", "-Ox", "x86_test.s"])
  if ret != 0:
    return

  output = subprocess.Popen(["xxd", "-ps", "x86_test"], stdout=subprocess.PIPE).communicate()[0]
  hex = ''.join(output.splitlines())

  # If the prolog/epilog change, these need to be updated
  startstr = "5589e5575653"
  stopstr = "5b5e5fc9c3"
  startpos = hex.find(startstr) + len(startstr)
  stoppos = hex.find(stopstr)

  return hex[startpos:stoppos]
Exemplo n.º 4
0
inp = proc.alloc_remote('f', 4, 64)
out = proc.alloc_remote('f', 4, 64)

out.clear()
for i in xrange(0, 64):
    inp[i] = float(i + 1)

cal.set_active_code(code)

cal.dcl_input(reg.v0.x, USAGE=cal.usage.pos)
cal.dcl_resource(0, cal.pixtex_type.oned, cal.fmt.float, UNNORM=True)
cal.dcl_output(reg.o0, USAGE=cal.usage.generic)

cal.sample(0, 0, reg.o0, reg.v0.x)

prgm.set_binding(reg.i0, inp)
prgm.set_binding(reg.o0, out)

prgm.add(code)
prgm.print_code()

proc.execute(prgm)

print "inp", inp
print "out", out

import corepy.lib.printer as printer

printer.PrintInstructionStream(code, printer.CAL_Asm())