Ejemplo n.º 1
0
  def _synthesize_epilogue(self):
    """
    Restore the caller-save registers
    """

    # Pop callee-save regs and clean up the stack frame
    self._epilogue = [self.lbl_epilogue,
                      x86.pop(ebx, ignore_active = True),
                      x86.pop(esi, ignore_active = True),
                      x86.pop(edi, ignore_active = True),
                      x86.leave(ignore_active = True),
                      x86.ret(ignore_active = True)]
    return
Ejemplo n.º 2
0
    def _synthesize_epilogue(self):
        """
    Restore the caller-save registers
    """

        # Pop callee-save regs and clean up the stack frame
        self._epilogue = [
            self.lbl_epilogue,
            x86.pop(ebx, ignore_active=True),
            x86.pop(esi, ignore_active=True),
            x86.pop(edi, ignore_active=True),
            x86.leave(ignore_active=True),
            x86.ret(ignore_active=True)
        ]
        return
Ejemplo n.º 3
0
    def _synthesize_epilogue(self):
        """
    Save the caller-save registers
    """

        # Reset the epilogue
        self._epilogue = [self.lbl_epilogue]

        # Pop callee-save regs and clean up the stack frame
        self._epilogue.append(x86.pop(ebx, ignore_active=True))
        self._epilogue.append(x86.pop(esi, ignore_active=True))
        self._epilogue.append(x86.pop(edi, ignore_active=True))
        self._epilogue.append(x86.leave(ignore_active=True))
        self._epilogue.append(x86.ret(ignore_active=True))
        return
Ejemplo n.º 4
0
def Test():
    prgm = env.Program()
    code = prgm.get_stream()
    proc = env.Processor()
    params = env.ExecParams()
    params.p1 = 3
    mr32 = MemRef(ebp, 8)
    mr8 = MemRef(ebp, 8, data_size = 8)


    lbl1 = prgm.get_label("lbl1")
    lbl2 = prgm.get_label("lbl2")

    code.add(x86_isa.xor(eax, eax))

    code.add(x86_isa.cmp(eax, 1))
    code.add(x86_isa.jne(lbl1))

    code.add(x86_isa.ret())

    code.add(lbl1)
    code.add(x86_isa.cmp(eax, 1))
    code.add(x86_isa.je(lbl2))
    code.add(x86_isa.add(eax, 12))
    code.add(lbl2)

    prgm += code
    ret = proc.execute(prgm)
    print "ret", ret
    assert(ret == 12)

    prgm = env.Program()
    code = prgm.get_stream()

    fwd_lbl = prgm.get_label("FORWARD")
    bck_lbl = prgm.get_label("BACKWARD")

    code.add(x86_isa.xor(eax, eax))
    code.add(bck_lbl)
    code.add(x86_isa.cmp(eax, 1))
    code.add(x86_isa.jne(fwd_lbl))
    for i in xrange(0, 65):
      code.add(x86_isa.pop(edi))
    code.add(fwd_lbl)

    prgm += code
    ret = proc.execute(prgm, mode = 'int')
    assert(ret == 0)


    prgm = env.Program()
    code = prgm.get_stream()

    loop_lbl = prgm.get_label("LOOP")
    out_lbl = prgm.get_label("OUT")
    skip_lbl = prgm.get_label("SKIP")

    code.add(x86_isa.xor(eax, eax))
    code.add(loop_lbl)
    r_tmp = prgm.acquire_register()
    for i in range(0, 1):
      for i in xrange(0, 24):
        code.add(x86_isa.add(r_tmp, MemRef(esp, 4)))

      code.add(x86_isa.add(eax, 4))
      code.add(x86_isa.cmp(eax, 20))
      code.add(x86_isa.je(out_lbl))

      for i in xrange(0, 24):
        code.add(x86_isa.add(r_tmp, MemRef(esp, 4)))

      code.add(x86_isa.cmp(eax, 32))
      code.add(x86_isa.jne(loop_lbl))

    code.add(out_lbl)

    code.add(x86_isa.jmp(skip_lbl))
    for i in xrange(0, 2):
      code.add(x86_isa.add(r_tmp, MemRef(esp, 4)))
    code.add(skip_lbl)

    prgm.release_register(r_tmp)

    prgm += code
    ret = proc.execute(prgm, mode = 'int')
    print "ret", ret
    assert(ret == 20)


    prgm = env.Program()
    code = prgm.get_stream()

    loop_lbl = prgm.get_label("LOOP")
    else_lbl = prgm.get_label("ELSE")
    finish_lbl = prgm.get_label("finish")

    code.add(x86_isa.mov(eax, -1))
    code.add(x86_isa.mov(edx, 0))

    code.add(loop_lbl)

    code.add(x86_isa.add(eax, 1))
    code.add(x86_isa.cmp(eax, 16))
    code.add(x86_isa.jge(finish_lbl))

    code.add(x86_isa.add(edx, eax))
    code.add(x86_isa.mov(edx, edi))
    code.add(x86_isa.and_(edi, 0x1))
    code.add(x86_isa.jnz(else_lbl))

    code.add(x86_isa.add(edx, 1))
    code.add(x86_isa.jmp(loop_lbl))

    code.add(else_lbl)
    code.add(x86_isa.add(edx, edi))
    code.add(x86_isa.jmp(loop_lbl))

    code.add(finish_lbl)
    code.add(x86_isa.mov(eax, edx))

    prgm += code
    ret = proc.execute(prgm, mode = 'int')
    print "ret", ret
    assert(ret == 1)


    prgm = env.Program()
    code = prgm.get_stream()

    loop_lbl = prgm.get_label("LOOP")

    code.add(x86_isa.xor(eax, eax))
    code.add(x86_isa.xor(ecx, ecx))
    code.add(x86_isa.mov(edx, 1))

    code.add(loop_lbl)
    code.add(x86_isa.inc(eax))
    code.add(x86_isa.cmp(eax, 7))
    code.add(x86_isa.cmove(ecx, edx))
    code.add(x86_isa.jecxz(loop_lbl))

    prgm += code
    ret = proc.execute(prgm, mode = 'int')
    print "ret", ret
    assert(ret == 7)


    prgm = env.Program()
    code = prgm.get_stream()

    code.add(x86_isa.add(eax, 200))
    code.add(x86_isa.xor(eax, eax))
    code.add(x86_isa.add(al, 32))
    code.add(x86_isa.add(bl, 32))
    code.add(x86_isa.xor(bl, bl))
    code.add(x86_isa.mov(mr8, al))
    code.add(x86_isa.add(mr32, 0))
    code.add(x86_isa.mov(eax, mr32))
    code.add(x86_isa.mov(al, mr8))

    code.add(x86_isa.imul(ax, ax, 4))
    code.add(x86_isa.imul(ebx, eax, 10))
    code.add(x86_isa.mov(cx, 1232))
    code.add(x86_isa.sub(ax, cx))
    code.add(x86_isa.xor(eax,eax))
    code.add(x86_isa.mov(eax,ebx))
    code.add(x86_isa.clc())
    code.add(x86_isa.rcl(eax, 1))
    code.add(x86_isa.rcr(eax, 1))


    prgm += code
    #ret = proc.execute(code, debug = True, params = params)
    id1 = proc.execute(prgm, params = params, mode = 'int', async = True)
    id2 = proc.execute(prgm, params = params, mode = 'int', async = True)
    ret = proc.execute(prgm, params = params, mode = 'int')
    print "Return main thread: %d" % (ret)
    ret = proc.join(id1)
    print "Return thread 1: %d" % (ret)
    ret = proc.join(id2)
    print "Return thread 2: %d" % (ret)

    prgm = env.Program()
    code = prgm.get_stream()
    code.add(x86_isa.fldpi())
    code.add(x86_isa.fld1())
    code.add(x86_isa.fadd(st0, st0))
    code.add(x86_isa.fmulp())
    code.add(x86_isa.fsin())
    code.add(x86_isa.fcos())
    code.add(x86_isa.fld1())
    code.add(x86_isa.fyl2xp1())

    prgm += code
    ret = proc.execute(prgm, params = params, mode = 'fp')
    print "Return main thread: %f" % (ret)

    prgm = env.Program()
    code = prgm.get_stream()
    code.add(x86_isa.movd(xmm0, mr32))
    code.add(x86_isa.mov(ebx, mr32))
    code.add(x86_isa.movd(xmm1, ebx))
    code.add(x86_isa.paddq(xmm0, xmm1))
    code.add(x86_isa.pextrw(ecx, xmm0, 0))
    code.add(x86_isa.pxor(mm1, mm1))
    code.add(x86_isa.pinsrw(mm1, ecx, 0))
    code.add(x86_isa.movq2dq(xmm0, mm1))
    code.add(x86_isa.movdq2q(mm2, xmm0))
    code.add(x86_isa.movd(edx,mm2))
    code.add(x86_isa.movd(xmm5,edx))
    code.add(x86_isa.movd(ecx, xmm5))
    code.add(x86_isa.pxor(xmm6, xmm6))
    code.add(x86_isa.pinsrw(xmm6, ecx, 0))
    code.add(x86_isa.movd(eax, xmm6))
    code.add(x86_isa.emms())

    prgm += code
    prgm.print_code(hex = True)
    ret = proc.execute(prgm, params = params, mode = 'int')
    print "Return main thread: %d" % (ret)


    # Try the LOCK prefix
    prgm = env.Program()
    code = prgm.get_stream()

    code.add(x86_isa.xor(eax, eax))
    code.add(x86_isa.add(mr32, eax))
    code.add(x86_isa.add(mr32, eax, lock = True))

    prgm += code
    prgm.print_code(hex = True)

    proc.execute(prgm, params = params)
    return