fix call(<label>)

This commit is contained in:
MITSUNARI Shigeo 2010-07-08 16:03:13 +09:00
parent ab4fd63480
commit 9fa05da02b
5 changed files with 57 additions and 59 deletions

View file

@ -1,5 +1,5 @@
C++用x86(IA-32), x64(AMD64, x86-64) JITアセンブラ Xbyak version 2.27
C++用x86(IA-32), x64(AMD64, x86-64) JITアセンブラ Xbyak version 2.29
-----------------------------------------------------------------------------
◎概要
@ -199,6 +199,8 @@ sample/{echo,hello}.bfは http://www.kmonos.net/alang/etc/brainfuck.php から
-----------------------------------------------------------------------------
◎履歴
2010/07/07 ver 2.29 fix call(<label>)
2010/06/17 ver 2.28 move some member functions to public
2010/06/01 ver 2.27 support encoding of mov(reg64, imm) like yasm(not nasm)
2010/05/24 ver 2.26 fix sub(rsp, 1000)
2010/04/26 ver 2.25 add jc/jnc(I forgot to implement them...)

View file

@ -1,5 +1,5 @@
Xbyak 2.27 ; JIT assembler for x86(IA32), x64(AMD64, x86-64) by C++
Xbyak 2.29 ; JIT assembler for x86(IA32), x64(AMD64, x86-64) by C++
-----------------------------------------------------------------------------
<Abstract>
@ -148,6 +148,8 @@ http://www.opensource.org/licenses/bsd-license.php
-----------------------------------------------------------------------------
<History>
2010/Jun/07 ver 2.29 fix call(<label>)
2010/Jun/17 ver 2.28 move some member functions to public
2010/Jun/01 ver 2.27 support encoding of mov(reg64, imm) like yasm(not nasm)
2010/May/24 ver 2.26 fix sub(rsp, 1000)
2010/Apr/26 ver 2.25 add jc/jnc(I forgot to implement them...)
@ -185,5 +187,5 @@ http://www.opensource.org/licenses/bsd-license.php
MITSUNARI Shigeo(herumi at nifty dot com)
---
$Revision: 1.47 $
$Date: 2010/06/01 01:21:39 $
$Revision: 1.49 $
$Date: 2010/07/07 01:00:04 $

View file

@ -4,9 +4,9 @@
@file xbyak.h
@brief Xbyak ; JIT assembler for x86(IA32)/x64 by C++
@author herumi
@version $Revision: 1.192 $
@version $Revision: 1.196 $
@url http://homepage1.nifty.com/herumi/soft/xbyak.html
@date $Date: 2010/06/01 07:26:56 $
@date $Date: 2010/07/07 01:00:04 $
@note modified new BSD license
http://www.opensource.org/licenses/bsd-license.php
*/
@ -54,8 +54,8 @@ namespace Xbyak {
#include "xbyak_bin2hex.h"
enum {
DEFAULT_MAX_CODE_SIZE = 2048,
VERSION = 0x2270, /* 0xABCD = A.BC(D) */
DEFAULT_MAX_CODE_SIZE = 4096,
VERSION = 0x2290, /* 0xABCD = A.BC(D) */
};
#ifndef MIE_INTEGER_TYPE_DEFINED
@ -382,7 +382,7 @@ struct RegRip {
class CodeArray {
enum {
ALIGN_SIZE = 16,
ALIGN_PAGE_SIZE = 4096,
MAX_FIXED_BUF_SIZE = 8
};
enum Type {
@ -401,9 +401,9 @@ protected:
public:
CodeArray(size_t maxSize = MAX_FIXED_BUF_SIZE, void *userPtr = 0)
: type_(userPtr ? USER_BUF : maxSize <= MAX_FIXED_BUF_SIZE ? FIXED_BUF : ALLOC_BUF)
, allocPtr_(type_ == ALLOC_BUF ? new uint8[maxSize + ALIGN_SIZE] : 0)
, allocPtr_(type_ == ALLOC_BUF ? new uint8[maxSize + ALIGN_PAGE_SIZE] : 0)
, maxSize_(maxSize)
, top_(type_ == ALLOC_BUF ? getAlignedAddress(allocPtr_) : type_ == USER_BUF ? reinterpret_cast<uint8*>(userPtr) : buf_)
, top_(type_ == ALLOC_BUF ? getAlignedAddress(allocPtr_, ALIGN_PAGE_SIZE) : type_ == USER_BUF ? reinterpret_cast<uint8*>(userPtr) : buf_)
, size_(0)
{
if (type_ == ALLOC_BUF && !protect(top_, maxSize, true)) {
@ -513,7 +513,7 @@ public:
@param alingedSize [in] power of two
@return aligned addr by alingedSize
*/
static inline uint8 *getAlignedAddress(uint8 *addr, size_t alignedSize = ALIGN_SIZE)
static inline uint8 *getAlignedAddress(uint8 *addr, size_t alignedSize = 16)
{
return reinterpret_cast<uint8*>((reinterpret_cast<size_t>(addr) + alignedSize - 1) & ~(alignedSize - static_cast<size_t>(1)));
}
@ -742,7 +742,7 @@ public:
};
class CodeGenerator : public CodeArray {
protected:
public:
enum LabelType {
T_SHORT,
T_NEAR,
@ -1072,7 +1072,7 @@ private:
{
db(code1); db(code2 | reg.getIdx());
}
protected:
public:
unsigned int getVersion() const { return VERSION; }
using CodeArray::db;
const Mmx mm0, mm1, mm2, mm3, mm4, mm5, mm6, mm7;
@ -1282,7 +1282,7 @@ protected:
}
void call(const char *label)
{
opJmp(label, T_NEAR, 0, B10011010, 0);
opJmp(label, T_NEAR, 0, B11101000, 0);
}
void call(const void *addr)
{

View file

@ -1,4 +1,4 @@
const char *getVersionString() const { return "2.27"; }
const char *getVersionString() const { return "2.29"; }
void packssdw(const Mmx& mmx, const Operand& op) { opMMX(mmx, op, 0x6B); }
void packsswb(const Mmx& mmx, const Operand& op) { opMMX(mmx, op, 0x63); }
void packuswb(const Mmx& mmx, const Operand& op) { opMMX(mmx, op, 0x67); }

View file

@ -179,53 +179,47 @@ XBYAK_LOCAL_DEFINE_SET_EIP_TO_REG(ebp)
#undef XBYAK_LOCAL_DEFINE_SET_EIP_TO_REG
} // end of local
template<class Gen>
struct EnableSetEip : public Gen {
EnableSetEip(size_t maxSize = DEFAULT_MAX_CODE_SIZE, void *userPtr = 0)
: Gen(maxSize, userPtr)
{
}
/**
get eip to out register
@note out is not esp
*/
void setEipTo(const Xbyak::Reg32& out)
{
/**
get eip to out register
@note out is not esp
*/
template<class T>
void setEipTo(T *self, const Xbyak::Reg32& out)
{
#if 0
Gen::call(Gen::getCurr() + 5);
Gen::pop(out);
self->call("@f");
self->L("@@");
self->pop(out);
#else
int idx = out.getIdx();
switch (idx) {
case Xbyak::Operand::EAX:
Gen::call((void*)local::set_eip_to_eax);
break;
case Xbyak::Operand::ECX:
Gen::call((void*)local::set_eip_to_ecx);
break;
case Xbyak::Operand::EDX:
Gen::call((void*)local::set_eip_to_edx);
break;
case Xbyak::Operand::EBX:
Gen::call((void*)local::set_eip_to_ebx);
break;
case Xbyak::Operand::ESI:
Gen::call((void*)local::set_eip_to_esi);
break;
case Xbyak::Operand::EDI:
Gen::call((void*)local::set_eip_to_edi);
break;
case Xbyak::Operand::EBP:
Gen::call((void*)local::set_eip_to_ebp);
break;
default:
assert(0);
}
#endif
int idx = out.getIdx();
switch (idx) {
case Xbyak::Operand::EAX:
self->call((void*)local::set_eip_to_eax);
break;
case Xbyak::Operand::ECX:
self->call((void*)local::set_eip_to_ecx);
break;
case Xbyak::Operand::EDX:
self->call((void*)local::set_eip_to_edx);
break;
case Xbyak::Operand::EBX:
self->call((void*)local::set_eip_to_ebx);
break;
case Xbyak::Operand::ESI:
self->call((void*)local::set_eip_to_esi);
break;
case Xbyak::Operand::EDI:
self->call((void*)local::set_eip_to_edi);
break;
case Xbyak::Operand::EBP:
self->call((void*)local::set_eip_to_ebp);
break;
default:
assert(0);
}
};
#endif
}
#endif
} } // end of util
#endif