Rename some register defines to avoid conflict with sys headers (bug 5917, r=hamdinger).

This commit is contained in:
Nicholas Hastings 2013-10-08 21:01:21 -04:00
parent 67a2fe3751
commit 5bde264c43
4 changed files with 144 additions and 144 deletions

View File

@ -57,30 +57,30 @@ inline void Write_Execution_Prologue(JitWriter *jit, bool is_void, bool has_para
//mov esi, esp //mov esi, esp
//and esp, 0xFFFFFFF0 //and esp, 0xFFFFFFF0
//sub esp, <alignment> //sub esp, <alignment>
IA32_Push_Reg(jit, REG_EBP); IA32_Push_Reg(jit, kREG_EBP);
IA32_Mov_Reg_Rm(jit, REG_EBP, REG_ESP, MOD_REG); IA32_Mov_Reg_Rm(jit, kREG_EBP, kREG_ESP, MOD_REG);
if (!is_void) if (!is_void)
{ {
IA32_Push_Reg(jit, REG_EDI); IA32_Push_Reg(jit, kREG_EDI);
IA32_Mov_Reg_Rm_Disp8(jit, REG_EDI, REG_EBP, 12); IA32_Mov_Reg_Rm_Disp8(jit, kREG_EDI, kREG_EBP, 12);
} }
if (has_params) if (has_params)
{ {
IA32_Push_Reg(jit, REG_EBX); IA32_Push_Reg(jit, kREG_EBX);
IA32_Mov_Reg_Rm_Disp8(jit, REG_EBX, REG_EBP, 8); IA32_Mov_Reg_Rm_Disp8(jit, kREG_EBX, kREG_EBP, 8);
} }
IA32_Push_Reg(jit, REG_ESI); IA32_Push_Reg(jit, kREG_ESI);
IA32_Mov_Reg_Rm(jit, REG_ESI, REG_ESP, MOD_REG); IA32_Mov_Reg_Rm(jit, kREG_ESI, kREG_ESP, MOD_REG);
IA32_And_Rm_Imm8(jit, REG_ESP, MOD_REG, -16); IA32_And_Rm_Imm8(jit, kREG_ESP, MOD_REG, -16);
if (!jit->outbase) if (!jit->outbase)
{ {
/* Alloc this instruction before knowing the real stack usage */ /* Alloc this instruction before knowing the real stack usage */
IA32_Sub_Rm_Imm32(jit, REG_ESP, 1337, MOD_REG); IA32_Sub_Rm_Imm32(jit, kREG_ESP, 1337, MOD_REG);
} else { } else {
if (g_StackAlign) if (g_StackAlign)
{ {
IA32_Sub_Rm_Imm32(jit, REG_ESP, g_StackAlign, MOD_REG); IA32_Sub_Rm_Imm32(jit, kREG_ESP, g_StackAlign, MOD_REG);
} }
} }
} }
@ -96,18 +96,18 @@ inline void Write_Function_Epilogue(JitWriter *jit, bool is_void, bool has_param
//mov esp, ebp //mov esp, ebp
//pop ebp //pop ebp
//ret //ret
IA32_Mov_Reg_Rm(jit, REG_ESP, REG_ESI, MOD_REG); IA32_Mov_Reg_Rm(jit, kREG_ESP, kREG_ESI, MOD_REG);
IA32_Pop_Reg(jit, REG_ESI); IA32_Pop_Reg(jit, kREG_ESI);
if (has_params) if (has_params)
{ {
IA32_Pop_Reg(jit, REG_EBX); IA32_Pop_Reg(jit, kREG_EBX);
} }
if (!is_void) if (!is_void)
{ {
IA32_Pop_Reg(jit, REG_EDI); IA32_Pop_Reg(jit, kREG_EDI);
} }
IA32_Mov_Reg_Rm(jit, REG_ESP, REG_EBP, MOD_REG); IA32_Mov_Reg_Rm(jit, kREG_ESP, kREG_EBP, MOD_REG);
IA32_Pop_Reg(jit, REG_EBP); IA32_Pop_Reg(jit, kREG_EBP);
IA32_Return(jit); IA32_Return(jit);
} }
@ -125,11 +125,11 @@ inline void Write_PushPOD(JitWriter *jit, const SourceHook::PassInfo *info, unsi
//push reg //push reg
if (offset < SCHAR_MAX) if (offset < SCHAR_MAX)
{ {
IA32_Movzx_Reg32_Rm8_Disp8(jit, reg, REG_EBX, (jit_int8_t)offset); IA32_Movzx_Reg32_Rm8_Disp8(jit, reg, kREG_EBX, (jit_int8_t)offset);
} else if (!offset) { } else if (!offset) {
IA32_Movzx_Reg32_Rm8(jit, reg, REG_EBX, MOD_MEM_REG); IA32_Movzx_Reg32_Rm8(jit, reg, kREG_EBX, MOD_MEM_REG);
} else { } else {
IA32_Movzx_Reg32_Rm8_Disp32(jit, reg, REG_EBX, offset); IA32_Movzx_Reg32_Rm8_Disp32(jit, reg, kREG_EBX, offset);
} }
IA32_Push_Reg(jit, reg); IA32_Push_Reg(jit, reg);
@ -143,11 +143,11 @@ inline void Write_PushPOD(JitWriter *jit, const SourceHook::PassInfo *info, unsi
jit->write_ubyte(IA32_16BIT_PREFIX); jit->write_ubyte(IA32_16BIT_PREFIX);
if (offset < SCHAR_MAX) if (offset < SCHAR_MAX)
{ {
IA32_Movzx_Reg32_Rm16_Disp8(jit, reg, REG_EBX, (jit_int8_t)offset); IA32_Movzx_Reg32_Rm16_Disp8(jit, reg, kREG_EBX, (jit_int8_t)offset);
} else if (!offset) { } else if (!offset) {
IA32_Movzx_Reg32_Rm16(jit, reg, REG_EBX, MOD_MEM_REG); IA32_Movzx_Reg32_Rm16(jit, reg, kREG_EBX, MOD_MEM_REG);
} else { } else {
IA32_Movzx_Reg32_Rm16_Disp32(jit, reg, REG_EBX, offset); IA32_Movzx_Reg32_Rm16_Disp32(jit, reg, kREG_EBX, offset);
} }
IA32_Push_Reg(jit, reg); IA32_Push_Reg(jit, reg);
@ -160,11 +160,11 @@ inline void Write_PushPOD(JitWriter *jit, const SourceHook::PassInfo *info, unsi
//push reg //push reg
if (offset < SCHAR_MAX) if (offset < SCHAR_MAX)
{ {
IA32_Mov_Reg_Rm_Disp8(jit, reg, REG_EBX, (jit_int8_t)offset); IA32_Mov_Reg_Rm_Disp8(jit, reg, kREG_EBX, (jit_int8_t)offset);
} else if (!offset) { } else if (!offset) {
IA32_Mov_Reg_Rm(jit, reg, REG_EBX, MOD_MEM_REG); IA32_Mov_Reg_Rm(jit, reg, kREG_EBX, MOD_MEM_REG);
} else { } else {
IA32_Mov_Reg_Rm_Disp32(jit, reg, REG_EBX, offset); IA32_Mov_Reg_Rm_Disp32(jit, reg, kREG_EBX, offset);
} }
IA32_Push_Reg(jit, reg); IA32_Push_Reg(jit, reg);
@ -181,17 +181,17 @@ inline void Write_PushPOD(JitWriter *jit, const SourceHook::PassInfo *info, unsi
if (offset+4 < SCHAR_MAX) if (offset+4 < SCHAR_MAX)
{ {
IA32_Mov_Reg_Rm_Disp8(jit, reg, REG_EBX, (jit_int8_t)(offset+4)); IA32_Mov_Reg_Rm_Disp8(jit, reg, kREG_EBX, (jit_int8_t)(offset+4));
} else { } else {
IA32_Mov_Reg_Rm_Disp32(jit, reg, REG_EBX, offset+4); IA32_Mov_Reg_Rm_Disp32(jit, reg, kREG_EBX, offset+4);
} }
if (offset < SCHAR_MAX) if (offset < SCHAR_MAX)
{ {
IA32_Mov_Reg_Rm_Disp8(jit, reg2, REG_EBX, (jit_int8_t)offset); IA32_Mov_Reg_Rm_Disp8(jit, reg2, kREG_EBX, (jit_int8_t)offset);
} else if (!offset) { } else if (!offset) {
IA32_Mov_Reg_Rm(jit, reg2, REG_EBX, MOD_MEM_REG); IA32_Mov_Reg_Rm(jit, reg2, kREG_EBX, MOD_MEM_REG);
} else { } else {
IA32_Mov_Reg_Rm_Disp32(jit, reg2, REG_EBX, offset); IA32_Mov_Reg_Rm_Disp32(jit, reg2, kREG_EBX, offset);
} }
IA32_Push_Reg(jit, reg); IA32_Push_Reg(jit, reg);
IA32_Push_Reg(jit, reg2); IA32_Push_Reg(jit, reg2);
@ -205,15 +205,15 @@ inline void Write_PushPOD(JitWriter *jit, const SourceHook::PassInfo *info, unsi
//push reg //push reg
if (!offset) if (!offset)
{ {
IA32_Push_Reg(jit, REG_EBX); IA32_Push_Reg(jit, kREG_EBX);
g_StackUsage += 4; g_StackUsage += 4;
return; return;
} }
if (offset < SCHAR_MAX) if (offset < SCHAR_MAX)
{ {
IA32_Lea_DispRegImm8(jit, reg, REG_EBX, (jit_int8_t)offset); IA32_Lea_DispRegImm8(jit, reg, kREG_EBX, (jit_int8_t)offset);
} else { } else {
IA32_Lea_DispRegImm32(jit, reg, REG_EBX, offset); IA32_Lea_DispRegImm32(jit, reg, kREG_EBX, offset);
} }
IA32_Push_Reg(jit, reg); IA32_Push_Reg(jit, reg);
@ -234,11 +234,11 @@ inline void Write_PushFloat(JitWriter *jit, const SourceHook::PassInfo *info, un
//fstp DWORD PTR [esp] //fstp DWORD PTR [esp]
if (offset < SCHAR_MAX) if (offset < SCHAR_MAX)
{ {
IA32_Fld_Mem32_Disp8(jit, REG_EBX, (jit_int8_t)offset); IA32_Fld_Mem32_Disp8(jit, kREG_EBX, (jit_int8_t)offset);
} else if (!offset) { } else if (!offset) {
IA32_Fld_Mem32(jit, REG_EBX); IA32_Fld_Mem32(jit, kREG_EBX);
} else { } else {
IA32_Fld_Mem32_Disp32(jit, REG_EBX, offset); IA32_Fld_Mem32_Disp32(jit, kREG_EBX, offset);
} }
IA32_Push_Reg(jit, _DecodeRegister3(g_RegDecoder++)); IA32_Push_Reg(jit, _DecodeRegister3(g_RegDecoder++));
IA32_Fstp_Mem32_ESP(jit); IA32_Fstp_Mem32_ESP(jit);
@ -252,13 +252,13 @@ inline void Write_PushFloat(JitWriter *jit, const SourceHook::PassInfo *info, un
//fstp QWORD PTR [esp] //fstp QWORD PTR [esp]
if (offset < SCHAR_MAX) if (offset < SCHAR_MAX)
{ {
IA32_Fld_Mem64_Disp8(jit, REG_EBX, (jit_int8_t)offset); IA32_Fld_Mem64_Disp8(jit, kREG_EBX, (jit_int8_t)offset);
} else if (!offset) { } else if (!offset) {
IA32_Fld_Mem64(jit, REG_EBX); IA32_Fld_Mem64(jit, kREG_EBX);
} else { } else {
IA32_Fld_Mem64_Disp32(jit, REG_EBX, offset); IA32_Fld_Mem64_Disp32(jit, kREG_EBX, offset);
} }
IA32_Sub_Rm_Imm8(jit, REG_ESP, 8, MOD_REG); IA32_Sub_Rm_Imm8(jit, kREG_ESP, 8, MOD_REG);
IA32_Fstp_Mem64_ESP(jit); IA32_Fstp_Mem64_ESP(jit);
g_StackUsage += 8; g_StackUsage += 8;
break; break;
@ -269,7 +269,7 @@ inline void Write_PushFloat(JitWriter *jit, const SourceHook::PassInfo *info, un
//push reg //push reg
if (!offset) if (!offset)
{ {
IA32_Push_Reg(jit, REG_EBX); IA32_Push_Reg(jit, kREG_EBX);
g_StackUsage += 4; g_StackUsage += 4;
return; return;
} }
@ -277,9 +277,9 @@ inline void Write_PushFloat(JitWriter *jit, const SourceHook::PassInfo *info, un
jit_uint8_t reg = _DecodeRegister3(g_RegDecoder++); jit_uint8_t reg = _DecodeRegister3(g_RegDecoder++);
if (offset < SCHAR_MAX) if (offset < SCHAR_MAX)
{ {
IA32_Lea_DispRegImm8(jit, reg, REG_EBX, (jit_int8_t)offset); IA32_Lea_DispRegImm8(jit, reg, kREG_EBX, (jit_int8_t)offset);
} else { } else {
IA32_Lea_DispRegImm32(jit, reg, REG_EBX, offset); IA32_Lea_DispRegImm32(jit, reg, kREG_EBX, offset);
} }
IA32_Push_Reg(jit, reg); IA32_Push_Reg(jit, reg);
@ -316,36 +316,36 @@ inline void Write_PushObject(JitWriter *jit, const SourceHook::PassInfo *info, u
//pop edi //pop edi
if (info->size < SCHAR_MAX) if (info->size < SCHAR_MAX)
{ {
IA32_Sub_Rm_Imm8(jit, REG_ESP, (jit_int8_t)info->size, MOD_REG); IA32_Sub_Rm_Imm8(jit, kREG_ESP, (jit_int8_t)info->size, MOD_REG);
} else { } else {
IA32_Sub_Rm_Imm32(jit, REG_ESP, info->size, MOD_REG); IA32_Sub_Rm_Imm32(jit, kREG_ESP, info->size, MOD_REG);
} }
IA32_Cld(jit); IA32_Cld(jit);
IA32_Push_Reg(jit, REG_EDI); IA32_Push_Reg(jit, kREG_EDI);
IA32_Push_Reg(jit, REG_ESI); IA32_Push_Reg(jit, kREG_ESI);
IA32_Lea_Reg_DispRegMultImm8(jit, REG_EDI, REG_NOIDX, REG_ESP, NOSCALE, 8); IA32_Lea_Reg_DispRegMultImm8(jit, kREG_EDI, kREG_NOIDX, kREG_ESP, NOSCALE, 8);
if (offset < SCHAR_MAX) if (offset < SCHAR_MAX)
{ {
IA32_Lea_DispRegImm8(jit, REG_ESI, REG_EBX, (jit_int8_t)offset); IA32_Lea_DispRegImm8(jit, kREG_ESI, kREG_EBX, (jit_int8_t)offset);
} else if (!offset) { } else if (!offset) {
IA32_Mov_Reg_Rm(jit, REG_ESI, REG_EBX, MOD_REG); IA32_Mov_Reg_Rm(jit, kREG_ESI, kREG_EBX, MOD_REG);
} else { } else {
IA32_Lea_DispRegImm32(jit, REG_ESI, REG_EBX, offset); IA32_Lea_DispRegImm32(jit, kREG_ESI, kREG_EBX, offset);
} }
if (dwords) if (dwords)
{ {
IA32_Mov_Reg_Imm32(jit, REG_ECX, dwords); IA32_Mov_Reg_Imm32(jit, kREG_ECX, dwords);
IA32_Rep(jit); IA32_Rep(jit);
IA32_Movsd(jit); IA32_Movsd(jit);
} }
if (bytes) if (bytes)
{ {
IA32_Mov_Reg_Imm32(jit, REG_ECX, bytes); IA32_Mov_Reg_Imm32(jit, kREG_ECX, bytes);
IA32_Rep(jit); IA32_Rep(jit);
IA32_Movsb(jit); IA32_Movsb(jit);
} }
IA32_Pop_Reg(jit, REG_ESI); IA32_Pop_Reg(jit, kREG_ESI);
IA32_Pop_Reg(jit, REG_EDI); IA32_Pop_Reg(jit, kREG_EDI);
g_StackUsage += info->size; g_StackUsage += info->size;
} else if (info->flags & PASSFLAG_BYREF) { } else if (info->flags & PASSFLAG_BYREF) {
@ -354,7 +354,7 @@ push_byref:
#endif #endif
if (!offset) if (!offset)
{ {
IA32_Push_Reg(jit, REG_EBX); IA32_Push_Reg(jit, kREG_EBX);
g_StackUsage += 4; g_StackUsage += 4;
return; return;
} }
@ -364,9 +364,9 @@ push_byref:
jit_uint8_t reg = _DecodeRegister3(g_RegDecoder++); jit_uint8_t reg = _DecodeRegister3(g_RegDecoder++);
if (offset < SCHAR_MAX) if (offset < SCHAR_MAX)
{ {
IA32_Lea_DispRegImm8(jit, reg, REG_EBX, (jit_int8_t)offset); IA32_Lea_DispRegImm8(jit, reg, kREG_EBX, (jit_int8_t)offset);
} else { } else {
IA32_Lea_DispRegImm32(jit, reg, REG_EBX, offset); IA32_Lea_DispRegImm32(jit, reg, kREG_EBX, offset);
} }
IA32_Push_Reg(jit, reg); IA32_Push_Reg(jit, reg);
@ -381,20 +381,20 @@ inline void Write_PushThisPtr(JitWriter *jit)
//push reg //push reg
jit_uint8_t reg = _DecodeRegister3(g_RegDecoder++); jit_uint8_t reg = _DecodeRegister3(g_RegDecoder++);
IA32_Mov_Reg_Rm(jit, reg, REG_EBX, MOD_MEM_REG); IA32_Mov_Reg_Rm(jit, reg, kREG_EBX, MOD_MEM_REG);
IA32_Push_Reg(jit, reg); IA32_Push_Reg(jit, reg);
g_StackUsage += 4; g_StackUsage += 4;
#elif defined PLATFORM_WINDOWS #elif defined PLATFORM_WINDOWS
//mov ecx, [ebx] //mov ecx, [ebx]
IA32_Mov_Reg_Rm(jit, REG_ECX, REG_EBX, MOD_MEM_REG); IA32_Mov_Reg_Rm(jit, kREG_ECX, kREG_EBX, MOD_MEM_REG);
#endif #endif
} }
inline void Write_PushRetBuffer(JitWriter *jit) inline void Write_PushRetBuffer(JitWriter *jit)
{ {
//push edi //push edi
IA32_Push_Reg(jit, REG_EDI); IA32_Push_Reg(jit, kREG_EDI);
} }
inline void Write_CallFunction(JitWriter *jit, FuncAddrMethod method, CallWrapper *pWrapper) inline void Write_CallFunction(JitWriter *jit, FuncAddrMethod method, CallWrapper *pWrapper)
@ -414,24 +414,24 @@ inline void Write_CallFunction(JitWriter *jit, FuncAddrMethod method, CallWrappe
jit_uint32_t total_offs = funcInfo->thisptroffs + funcInfo->vtbloffs; jit_uint32_t total_offs = funcInfo->thisptroffs + funcInfo->vtbloffs;
jit_uint32_t vfunc_pos = funcInfo->vtblindex * 4; jit_uint32_t vfunc_pos = funcInfo->vtblindex * 4;
IA32_Mov_Reg_Rm(jit, REG_EDX, REG_EBX, MOD_MEM_REG); IA32_Mov_Reg_Rm(jit, kREG_EDX, kREG_EBX, MOD_MEM_REG);
if (total_offs < SCHAR_MAX) if (total_offs < SCHAR_MAX)
{ {
IA32_Mov_Reg_Rm_Disp8(jit, REG_EAX, REG_EDX, (jit_int8_t)total_offs); IA32_Mov_Reg_Rm_Disp8(jit, kREG_EAX, kREG_EDX, (jit_int8_t)total_offs);
} else if (!total_offs) { } else if (!total_offs) {
IA32_Mov_Reg_Rm(jit, REG_EAX, REG_EDX, MOD_MEM_REG); IA32_Mov_Reg_Rm(jit, kREG_EAX, kREG_EDX, MOD_MEM_REG);
} else { } else {
IA32_Mov_Reg_Rm_Disp32(jit, REG_EAX, REG_EDX, total_offs); IA32_Mov_Reg_Rm_Disp32(jit, kREG_EAX, kREG_EDX, total_offs);
} }
if (vfunc_pos < SCHAR_MAX) if (vfunc_pos < SCHAR_MAX)
{ {
IA32_Mov_Reg_Rm_Disp8(jit, REG_EDX, REG_EAX, (jit_int8_t)vfunc_pos); IA32_Mov_Reg_Rm_Disp8(jit, kREG_EDX, kREG_EAX, (jit_int8_t)vfunc_pos);
} else if (!vfunc_pos) { } else if (!vfunc_pos) {
IA32_Mov_Reg_Rm(jit, REG_EDX, REG_EAX, MOD_MEM_REG); IA32_Mov_Reg_Rm(jit, kREG_EDX, kREG_EAX, MOD_MEM_REG);
} else { } else {
IA32_Mov_Reg_Rm_Disp32(jit, REG_EDX, REG_EAX, vfunc_pos); IA32_Mov_Reg_Rm_Disp32(jit, kREG_EDX, kREG_EAX, vfunc_pos);
} }
IA32_Call_Reg(jit, REG_EDX); IA32_Call_Reg(jit, kREG_EDX);
} }
} }
@ -440,9 +440,9 @@ inline void Write_RectifyStack(JitWriter *jit, jit_uint32_t value)
//add esp, <value> //add esp, <value>
if (value < SCHAR_MAX) if (value < SCHAR_MAX)
{ {
IA32_Add_Rm_Imm8(jit, REG_ESP, (jit_int8_t)value, MOD_REG); IA32_Add_Rm_Imm8(jit, kREG_ESP, (jit_int8_t)value, MOD_REG);
} else { } else {
IA32_Add_Rm_Imm32(jit, REG_ESP, value, MOD_REG); IA32_Add_Rm_Imm32(jit, kREG_ESP, value, MOD_REG);
} }
} }
@ -455,13 +455,13 @@ inline void Write_MovRet2Buf(JitWriter *jit, const PassInfo *pRet)
case 4: case 4:
{ {
//fstp DWORD PTR [edi] //fstp DWORD PTR [edi]
IA32_Fstp_Mem32(jit, REG_EDI); IA32_Fstp_Mem32(jit, kREG_EDI);
break; break;
} }
case 8: case 8:
{ {
//fstp QWORD PTR [edi] //fstp QWORD PTR [edi]
IA32_Fstp_Mem64(jit, REG_EDI); IA32_Fstp_Mem64(jit, kREG_EDI);
break; break;
} }
} }
@ -473,28 +473,28 @@ inline void Write_MovRet2Buf(JitWriter *jit, const PassInfo *pRet)
case 1: case 1:
{ {
//mov BYTE PTR [edi], al //mov BYTE PTR [edi], al
IA32_Mov_Rm8_Reg8(jit, REG_EDI, REG_EAX, MOD_MEM_REG); IA32_Mov_Rm8_Reg8(jit, kREG_EDI, kREG_EAX, MOD_MEM_REG);
break; break;
} }
case 2: case 2:
{ {
//mov WORD PTR [edi], ax //mov WORD PTR [edi], ax
jit->write_ubyte(IA32_16BIT_PREFIX); jit->write_ubyte(IA32_16BIT_PREFIX);
IA32_Mov_Rm_Reg(jit, REG_EDI, REG_EAX, MOD_MEM_REG); IA32_Mov_Rm_Reg(jit, kREG_EDI, kREG_EAX, MOD_MEM_REG);
break; break;
} }
case 4: case 4:
{ {
//mov DWORD PTR [edi], eax //mov DWORD PTR [edi], eax
IA32_Mov_Rm_Reg(jit, REG_EDI, REG_EAX, MOD_MEM_REG); IA32_Mov_Rm_Reg(jit, kREG_EDI, kREG_EAX, MOD_MEM_REG);
break; break;
} }
case 8: case 8:
{ {
//mov DWORD PTR [edi], eax //mov DWORD PTR [edi], eax
//mov DWORD PTR [edi+4], edx //mov DWORD PTR [edi+4], edx
IA32_Mov_Rm_Reg(jit, REG_EDI, REG_EAX, MOD_MEM_REG); IA32_Mov_Rm_Reg(jit, kREG_EDI, kREG_EAX, MOD_MEM_REG);
IA32_Mov_Rm_Reg_Disp8(jit, REG_EDI, REG_EDX, 4); IA32_Mov_Rm_Reg_Disp8(jit, kREG_EDI, kREG_EDX, 4);
break; break;
} }
} }

View File

@ -53,15 +53,15 @@ inline jit_uint8_t _DecodeRegister3(jit_uint32_t val)
{ {
case 0: case 0:
{ {
return REG_EAX; return kREG_EAX;
} }
case 1: case 1:
{ {
return REG_EDX; return kREG_EDX;
} }
case 2: case 2:
{ {
return REG_ECX; return kREG_ECX;
} }
} }

View File

@ -44,15 +44,15 @@ inline void Write_Function_Prologue(JitWriter *jit, bool RetInMemory)
//push ebp //push ebp
//push ebx //push ebx
//mov ebp, esp //mov ebp, esp
IA32_Push_Reg(jit, REG_EBP); IA32_Push_Reg(jit, kREG_EBP);
IA32_Push_Reg(jit, REG_EBX); IA32_Push_Reg(jit, kREG_EBX);
IA32_Mov_Reg_Rm(jit, REG_EBP, REG_ESP, MOD_REG); IA32_Mov_Reg_Rm(jit, kREG_EBP, kREG_ESP, MOD_REG);
#if defined PLATFORM_WINDOWS #if defined PLATFORM_WINDOWS
//mov ebx, ecx //mov ebx, ecx
IA32_Mov_Reg_Rm(jit, REG_EBX, REG_ECX, MOD_REG); IA32_Mov_Reg_Rm(jit, kREG_EBX, kREG_ECX, MOD_REG);
#elif defined PLATFORM_LINUX || defined PLATFORM_APPLE #elif defined PLATFORM_LINUX || defined PLATFORM_APPLE
//mov ebx, [ebp+12+(RetInMemory)?4:0] //mov ebx, [ebp+12+(RetInMemory)?4:0]
IA32_Mov_Reg_Rm_Disp8(jit, REG_EBX, REG_EBP, 12+((RetInMemory)?4:0)); IA32_Mov_Reg_Rm_Disp8(jit, kREG_EBX, kREG_EBP, 12+((RetInMemory)?4:0));
#endif #endif
} }
@ -62,9 +62,9 @@ inline void Write_Function_Epilogue(JitWriter *jit, unsigned short size)
//pop ebx //pop ebx
//pop ebp //pop ebp
//ret <value> //ret <value>
IA32_Mov_Reg_Rm(jit, REG_ESP, REG_EBP, MOD_REG); IA32_Mov_Reg_Rm(jit, kREG_ESP, kREG_EBP, MOD_REG);
IA32_Pop_Reg(jit, REG_EBX); IA32_Pop_Reg(jit, kREG_EBX);
IA32_Pop_Reg(jit, REG_EBP); IA32_Pop_Reg(jit, kREG_EBP);
if (size == 0) if (size == 0)
{ {
IA32_Return(jit); IA32_Return(jit);
@ -80,11 +80,11 @@ inline void Write_Stack_Alloc(JitWriter *jit, jit_uint32_t size)
//sub esp, <value> //sub esp, <value>
if (size <= SCHAR_MAX) if (size <= SCHAR_MAX)
{ {
IA32_Sub_Rm_Imm8(jit, REG_ESP, (jit_int8_t)size, MOD_REG); IA32_Sub_Rm_Imm8(jit, kREG_ESP, (jit_int8_t)size, MOD_REG);
} }
else else
{ {
IA32_Sub_Rm_Imm32(jit, REG_ESP, size, MOD_REG); IA32_Sub_Rm_Imm32(jit, kREG_ESP, size, MOD_REG);
} }
} }
@ -111,17 +111,17 @@ inline void Write_Copy_Params(JitWriter *jit, bool RetInMemory, jit_uint32_t ret
jit_uint32_t bytes = paramsize & 0x3; jit_uint32_t bytes = paramsize & 0x3;
IA32_Cld(jit); IA32_Cld(jit);
IA32_Push_Reg(jit, REG_EDI); IA32_Push_Reg(jit, kREG_EDI);
IA32_Push_Reg(jit, REG_ESI); IA32_Push_Reg(jit, kREG_ESI);
offs = -(jit_int32_t)retsize - paramsize; offs = -(jit_int32_t)retsize - paramsize;
if (offs > SCHAR_MIN) if (offs > SCHAR_MIN)
{ {
IA32_Lea_DispRegImm8(jit, REG_EDI, REG_EBP, (jit_int8_t)offs); IA32_Lea_DispRegImm8(jit, kREG_EDI, kREG_EBP, (jit_int8_t)offs);
} }
else else
{ {
IA32_Lea_DispRegImm32(jit, REG_EDI, REG_EBP, offs); IA32_Lea_DispRegImm32(jit, kREG_EDI, kREG_EBP, offs);
} }
offs = 12 + ((RetInMemory) ? sizeof(void *) : 0); offs = 12 + ((RetInMemory) ? sizeof(void *) : 0);
@ -131,26 +131,26 @@ inline void Write_Copy_Params(JitWriter *jit, bool RetInMemory, jit_uint32_t ret
if (offs < SCHAR_MAX) if (offs < SCHAR_MAX)
{ {
IA32_Lea_DispRegImm8(jit, REG_ESI, REG_EBP, (jit_int8_t)offs); IA32_Lea_DispRegImm8(jit, kREG_ESI, kREG_EBP, (jit_int8_t)offs);
} }
else else
{ {
IA32_Lea_DispRegImm32(jit, REG_ESI, REG_EBP, offs); IA32_Lea_DispRegImm32(jit, kREG_ESI, kREG_EBP, offs);
} }
if (dwords) if (dwords)
{ {
IA32_Mov_Reg_Imm32(jit, REG_ECX, dwords); IA32_Mov_Reg_Imm32(jit, kREG_ECX, dwords);
IA32_Rep(jit); IA32_Rep(jit);
IA32_Movsd(jit); IA32_Movsd(jit);
} }
if (bytes) if (bytes)
{ {
IA32_Mov_Reg_Imm32(jit, REG_ECX, bytes); IA32_Mov_Reg_Imm32(jit, kREG_ECX, bytes);
IA32_Rep(jit); IA32_Rep(jit);
IA32_Movsb(jit); IA32_Movsb(jit);
} }
IA32_Pop_Reg(jit, REG_ESI); IA32_Pop_Reg(jit, kREG_ESI);
IA32_Pop_Reg(jit, REG_EDI); IA32_Pop_Reg(jit, kREG_EDI);
} }
inline void Write_Push_Params(JitWriter *jit, inline void Write_Push_Params(JitWriter *jit,
@ -161,7 +161,7 @@ inline void Write_Push_Params(JitWriter *jit,
HookWrapper *pWrapper) HookWrapper *pWrapper)
{ {
//and esp, 0xFFFFFFF0 //and esp, 0xFFFFFFF0
IA32_And_Rm_Imm8(jit, REG_ESP, MOD_REG, -16); IA32_And_Rm_Imm8(jit, kREG_ESP, MOD_REG, -16);
//if retvoid //if retvoid
// push 0 // push 0
@ -177,13 +177,13 @@ inline void Write_Push_Params(JitWriter *jit,
jit_int32_t offs = -(jit_int32_t)retsize; jit_int32_t offs = -(jit_int32_t)retsize;
if (offs >= SCHAR_MIN) if (offs >= SCHAR_MIN)
{ {
IA32_Lea_DispRegImm8(jit, REG_EAX, REG_EBP, (jit_int8_t)offs); IA32_Lea_DispRegImm8(jit, kREG_EAX, kREG_EBP, (jit_int8_t)offs);
} }
else else
{ {
IA32_Lea_DispRegImm32(jit, REG_EAX, REG_EBP, offs); IA32_Lea_DispRegImm32(jit, kREG_EAX, kREG_EBP, offs);
} }
IA32_Push_Reg(jit, REG_EAX); IA32_Push_Reg(jit, kREG_EAX);
} }
//if void //if void
@ -200,18 +200,18 @@ inline void Write_Push_Params(JitWriter *jit,
jit_int32_t offs = -(jit_int32_t)retsize - paramsize; jit_int32_t offs = -(jit_int32_t)retsize - paramsize;
if (offs > SCHAR_MIN) if (offs > SCHAR_MIN)
{ {
IA32_Lea_DispRegImm8(jit, REG_EDX, REG_EBP, (jit_int8_t)offs); IA32_Lea_DispRegImm8(jit, kREG_EDX, kREG_EBP, (jit_int8_t)offs);
} else { } else {
IA32_Lea_DispRegImm32(jit, REG_EDX, REG_EBP, offs); IA32_Lea_DispRegImm32(jit, kREG_EDX, kREG_EBP, offs);
} }
IA32_Push_Reg(jit, REG_EDX); IA32_Push_Reg(jit, kREG_EDX);
} }
//push eax (thisptr) //push eax (thisptr)
//IA32_Push_Reg(jit, REG_ECX); //IA32_Push_Reg(jit, kREG_ECX);
//push ebx //push ebx
IA32_Push_Reg(jit, REG_EBX); IA32_Push_Reg(jit, kREG_EBX);
//push <pWrapper> //push <pWrapper>
IA32_Push_Imm32(jit, (jit_int32_t)pWrapper); IA32_Push_Imm32(jit, (jit_int32_t)pWrapper);
@ -243,13 +243,13 @@ inline void Write_Copy_RetVal(JitWriter *jit, SourceHook::PassInfo *pRetInfo)
case 4: case 4:
{ {
//fld DWORD PTR [ebp-4] //fld DWORD PTR [ebp-4]
IA32_Fld_Mem32_Disp8(jit, REG_EBP, -4); IA32_Fld_Mem32_Disp8(jit, kREG_EBP, -4);
break; break;
} }
case 8: case 8:
{ {
//fld QWORD PTR [ebp-8] //fld QWORD PTR [ebp-8]
IA32_Fld_Mem64_Disp8(jit, REG_EBP, -8); IA32_Fld_Mem64_Disp8(jit, kREG_EBP, -8);
break; break;
} }
} }
@ -276,36 +276,36 @@ inline void Write_Copy_RetVal(JitWriter *jit, SourceHook::PassInfo *pRetInfo)
jit_uint32_t bytes = size & 0x3; jit_uint32_t bytes = size & 0x3;
IA32_Cld(jit); IA32_Cld(jit);
IA32_Push_Reg(jit, REG_EDI); IA32_Push_Reg(jit, kREG_EDI);
IA32_Push_Reg(jit, REG_ESI); IA32_Push_Reg(jit, kREG_ESI);
IA32_Mov_Reg_Rm_Disp8(jit, REG_EDI, REG_EBP, 12); IA32_Mov_Reg_Rm_Disp8(jit, kREG_EDI, kREG_EBP, 12);
offs = -(jit_int32_t)pRetInfo->size; offs = -(jit_int32_t)pRetInfo->size;
if (offs >= SCHAR_MIN) if (offs >= SCHAR_MIN)
{ {
IA32_Lea_DispRegImm8(jit, REG_ESI, REG_EBP, (jit_int8_t)offs); IA32_Lea_DispRegImm8(jit, kREG_ESI, kREG_EBP, (jit_int8_t)offs);
} }
else else
{ {
IA32_Lea_DispRegImm32(jit, REG_ESI, REG_EBP, offs); IA32_Lea_DispRegImm32(jit, kREG_ESI, kREG_EBP, offs);
} }
IA32_Mov_Reg_Rm(jit, REG_EAX, REG_EDI, MOD_REG); IA32_Mov_Reg_Rm(jit, kREG_EAX, kREG_EDI, MOD_REG);
if (dwords) if (dwords)
{ {
IA32_Mov_Reg_Imm32(jit, REG_ECX, dwords); IA32_Mov_Reg_Imm32(jit, kREG_ECX, dwords);
IA32_Rep(jit); IA32_Rep(jit);
IA32_Movsd(jit); IA32_Movsd(jit);
} }
if (bytes) if (bytes)
{ {
IA32_Mov_Reg_Imm32(jit, REG_ECX, bytes); IA32_Mov_Reg_Imm32(jit, kREG_ECX, bytes);
IA32_Rep(jit); IA32_Rep(jit);
IA32_Movsb(jit); IA32_Movsb(jit);
} }
IA32_Pop_Reg(jit, REG_ESI); IA32_Pop_Reg(jit, kREG_ESI);
IA32_Pop_Reg(jit, REG_EDI); IA32_Pop_Reg(jit, kREG_EDI);
} }
else else
{ {
@ -314,20 +314,20 @@ inline void Write_Copy_RetVal(JitWriter *jit, SourceHook::PassInfo *pRetInfo)
case 1: case 1:
{ {
//mov al, BYTE PTR [ebp-4] //mov al, BYTE PTR [ebp-4]
IA32_Mov_Reg8_Rm8_Disp8(jit, REG_EAX, REG_EBP, -4); IA32_Mov_Reg8_Rm8_Disp8(jit, kREG_EAX, kREG_EBP, -4);
break; break;
} }
case 2: case 2:
{ {
//mov ax, WORD PTR [ebp-4] //mov ax, WORD PTR [ebp-4]
jit->write_ubyte(IA32_16BIT_PREFIX); jit->write_ubyte(IA32_16BIT_PREFIX);
IA32_Mov_Reg_Rm_Disp8(jit, REG_EAX, REG_EBP, -4); IA32_Mov_Reg_Rm_Disp8(jit, kREG_EAX, kREG_EBP, -4);
break; break;
} }
case 4: case 4:
{ {
//mov eax, DWORD PTR [ebp-4] //mov eax, DWORD PTR [ebp-4]
IA32_Mov_Reg_Rm_Disp8(jit, REG_EAX, REG_EBP, -4); IA32_Mov_Reg_Rm_Disp8(jit, kREG_EAX, kREG_EBP, -4);
break; break;
} }
case 8: case 8:
@ -335,8 +335,8 @@ inline void Write_Copy_RetVal(JitWriter *jit, SourceHook::PassInfo *pRetInfo)
//mov eax, DWORD PTR [ebp-8] //mov eax, DWORD PTR [ebp-8]
//mov edx, DWORD PTR [ebp-4] //mov edx, DWORD PTR [ebp-4]
//:TODO: this is broken due to SH //:TODO: this is broken due to SH
IA32_Mov_Reg_Rm_Disp8(jit, REG_EAX, REG_EBP, -8); IA32_Mov_Reg_Rm_Disp8(jit, kREG_EAX, kREG_EBP, -8);
IA32_Mov_Reg_Rm_Disp8(jit, REG_EDX, REG_EBP, -4); IA32_Mov_Reg_Rm_Disp8(jit, kREG_EDX, kREG_EBP, -4);
break; break;
} }
} }

View File

@ -51,17 +51,17 @@
#define SCALE8 3 #define SCALE8 3
//Register codes //Register codes
#define REG_EAX 0 const jit_uint8_t kREG_EAX = 0;
#define REG_ECX 1 const jit_uint8_t kREG_ECX = 1;
#define REG_EDX 2 const jit_uint8_t kREG_EDX = 2;
#define REG_EBX 3 const jit_uint8_t kREG_EBX = 3;
#define REG_ESP 4 const jit_uint8_t kREG_ESP = 4;
#define REG_SIB 4 const jit_uint8_t kREG_SIB = 4;
#define REG_NOIDX 4 const jit_uint8_t kREG_NOIDX = 4;
#define REG_IMM_BASE 5 const jit_uint8_t kREG_IMM_BASE = 5;
#define REG_EBP 5 const jit_uint8_t kREG_EBP = 5;
#define REG_ESI 6 const jit_uint8_t kREG_ESI = 6;
#define REG_EDI 7 const jit_uint8_t kREG_EDI = 7;
#define IA32_16BIT_PREFIX 0x66 #define IA32_16BIT_PREFIX 0x66
@ -372,7 +372,7 @@ inline void IA32_Lea_Reg_DispRegMultImm8(JitWriter *jit,
jit_int8_t val) jit_int8_t val)
{ {
jit->write_ubyte(IA32_LEA_REG_MEM); jit->write_ubyte(IA32_LEA_REG_MEM);
jit->write_ubyte(ia32_modrm(MOD_DISP8, dest, REG_SIB)); jit->write_ubyte(ia32_modrm(MOD_DISP8, dest, kREG_SIB));
jit->write_ubyte(ia32_sib(scale, src_index, src_base)); jit->write_ubyte(ia32_sib(scale, src_index, src_base));
jit->write_byte(val); jit->write_byte(val);
} }
@ -420,15 +420,15 @@ inline void IA32_Fld_Mem64_Disp32(JitWriter *jit, jit_uint8_t src, jit_int32_t v
inline void IA32_Fstp_Mem32_ESP(JitWriter *jit) inline void IA32_Fstp_Mem32_ESP(JitWriter *jit)
{ {
jit->write_ubyte(IA32_FSTP_MEM32); jit->write_ubyte(IA32_FSTP_MEM32);
jit->write_ubyte(ia32_modrm(MOD_MEM_REG, 3, REG_SIB)); jit->write_ubyte(ia32_modrm(MOD_MEM_REG, 3, kREG_SIB));
jit->write_ubyte(ia32_sib(NOSCALE, REG_NOIDX, REG_ESP)); jit->write_ubyte(ia32_sib(NOSCALE, kREG_NOIDX, kREG_ESP));
} }
inline void IA32_Fstp_Mem64_ESP(JitWriter *jit) inline void IA32_Fstp_Mem64_ESP(JitWriter *jit)
{ {
jit->write_ubyte(IA32_FSTP_MEM64); jit->write_ubyte(IA32_FSTP_MEM64);
jit->write_ubyte(ia32_modrm(MOD_MEM_REG, 3, REG_SIB)); jit->write_ubyte(ia32_modrm(MOD_MEM_REG, 3, kREG_SIB));
jit->write_ubyte(ia32_sib(NOSCALE, REG_NOIDX, REG_ESP)); jit->write_ubyte(ia32_sib(NOSCALE, kREG_NOIDX, kREG_ESP));
} }
inline void IA32_Return_Popstack(JitWriter *jit, unsigned short bytes) inline void IA32_Return_Popstack(JitWriter *jit, unsigned short bytes)