From 8d23a6c6ab7f7f83f169ea2d8603d85b37cfbac2 Mon Sep 17 00:00:00 2001 From: arcum42 Date: Sat, 11 Oct 2008 08:24:00 +0000 Subject: [PATCH] Change a few things in ix86.c to the way they were originally *if* you are running the 64 bit version. I've marked what each section breaks, if rama wants to look at it. I also fixed up the indentation in the file... git-svn-id: http://pcsx2-playground.googlecode.com/svn/trunk@189 a6443dda-0b58-4228-96e9-037be469359c --- pcsx2/x86/ix86/ix86.c | 647 ++++++++++++++++++++++-------------------- 1 file changed, 336 insertions(+), 311 deletions(-) diff --git a/pcsx2/x86/ix86/ix86.c b/pcsx2/x86/ix86/ix86.c index 20569b9386..6ba15616de 100644 --- a/pcsx2/x86/ix86/ix86.c +++ b/pcsx2/x86/ix86/ix86.c @@ -18,9 +18,9 @@ /* * ix86 core v0.6.2 * Authors: linuzappz - * alexey silinov - * goldfinger - * zerofrog(@gmail.com) + * alexey silinov + * goldfinger + * zerofrog(@gmail.com) */ // stop compiling if NORECBUILD build (only for Visual Studio) @@ -35,6 +35,7 @@ #ifdef __x86_64__ +#define _64_BIT_HACK #ifdef _MSC_VER // visual studio calling convention x86IntRegType g_x86savedregs[] = { RBX, RBP, RSI, RDI, R12, R13, R14, R15 }; @@ -67,7 +68,7 @@ u32 *j32Ptr[32]; extern void SysPrintf(char *fmt, ...); -_inline void WriteRmOffset(x86IntRegType to, int offset) +_inline void WriteRmOffset(x86IntRegType to, s32 offset) { if( (to&7) == ESP ) { if( offset == 0 ) { @@ -102,7 +103,7 @@ _inline void WriteRmOffset(x86IntRegType to, int offset) _inline void WriteRmOffsetFrom(x86IntRegType to, x86IntRegType from, int offset) { - if ((from&7) == ESP) { + if ((from&7) == ESP) { if( offset == 0 ) { ModRM( 0, to, 0x4 ); SibSB( 0, 0x4, 0x4 ); @@ -115,7 +116,7 @@ _inline void WriteRmOffsetFrom(x86IntRegType to, x86IntRegType from, int offset) else { ModRM( 2, to, 0x4 ); SibSB( 0, 0x4, 0x4 ); - write32(offset); + write32(offset); } } else { @@ -141,36 +142,36 @@ _inline void CheckX86Ptr( void ) _inline void write64( u64 val ) { #ifdef _DEBUG - CheckX86Ptr( ); + CheckX86Ptr( ); #endif - *(u64*)x86Ptr = val; - x86Ptr += 8; + *(u64*)x86Ptr = val; + x86Ptr += 8; } -_inline void ModRM( int mod, int reg, int rm ) -{ +_inline void ModRM( s32 mod, s32 reg, s32 rm ) +{ write8( ( mod << 6 ) | ( (reg & 7) << 3 ) | ( rm & 7 ) ); } -_inline void SibSB( int ss, int index, int base ) +_inline void SibSB( s32 ss, s32 index, s32 base ) { write8( ( ss << 6 ) | ( (index & 7) << 3 ) | ( base & 7 ) ); } _inline void SET8R( int cc, int to ) { - RexB(0, to); + RexB(0, to); write8( 0x0F ); - write8( cc ); + write8( cc ); write8( 0xC0 | ( to ) ); } __forceinline u8* J8Rel( int cc, int to ) { write8( cc ); - write8( to ); - return x86Ptr - 1; + write8( to ); + return x86Ptr - 1; } __forceinline u16* J16Rel( int cc, u32 to ) @@ -184,22 +185,22 @@ __forceinline u16* J16Rel( int cc, u32 to ) __forceinline u32* J32Rel( int cc, u32 to ) { write8( 0x0F ); - write8( cc ); - write32( to ); - return (u32*)( x86Ptr - 4 ); + write8( cc ); + write32( to ); + return (u32*)( x86Ptr - 4 ); } _inline void CMOV32RtoR( int cc, int to, int from ) { - RexRB(0,to, from); + RexRB(0,to, from); write8( 0x0F ); - write8( cc ); + write8( cc ); ModRM( 3, to, from ); } _inline void CMOV32MtoR( int cc, int to, uptr from ) { - RexR(0, to); + RexR(0, to); write8( 0x0F ); write8( cc ); ModRM( 0, to, DISP32 ); @@ -295,16 +296,16 @@ _inline void x86Align( int bytes ) _inline void STC( void ) { - write8( 0xF9 ); + write8( 0xF9 ); } _inline void CLC( void ) { - write8( 0xF8 ); + write8( 0xF8 ); } //////////////////////////////////// -// mov instructions / +// mov instructions / //////////////////////////////////// /* mov r64 to r64 */ @@ -346,7 +347,7 @@ _inline void MOV64I32toM(uptr to, u32 from ) // mov imm64 to r64 _inline void MOV64ItoR( x86IntRegType to, u64 from) { - RexB(1, to); + RexB(1, to); write8( 0xB8 | (to & 0x7) ); write64( from ); } @@ -363,18 +364,18 @@ _inline void MOV64I32toR( x86IntRegType to, s32 from ) // mov imm64 to [r64+off] _inline void MOV64ItoRmOffset( x86IntRegType to, u32 from, int offset) { - RexB(1,to); + RexB(1,to); write8( 0xC7 ); - WriteRmOffset(to, offset); + WriteRmOffset(to, offset); write32(from); } // mov [r64+offset] to r64 _inline void MOV64RmOffsettoR( x86IntRegType to, x86IntRegType from, int offset ) { - RexRB(1, to, from); + RexRB(1, to, from); write8( 0x8B ); - WriteRmOffsetFrom(to, from, offset); + WriteRmOffsetFrom(to, from, offset); } /* mov [r64][r64*scale] to r64 */ @@ -388,9 +389,9 @@ _inline void MOV64RmStoR( x86IntRegType to, x86IntRegType from, x86IntRegType fr /* mov r64 to [r64+offset] */ _inline void MOV64RtoRmOffset( x86IntRegType to, x86IntRegType from, int offset ) { - RexRB(1,from,to); + RexRB(1,from,to); write8( 0x89 ); - WriteRmOffsetFrom(from, to, offset); + WriteRmOffsetFrom(from, to, offset); } /* mov r64 to [r64][r64*scale] */ @@ -405,7 +406,7 @@ _inline void MOV64RtoRmS( x86IntRegType to, x86IntRegType from, x86IntRegType fr /* mov r32 to r32 */ _inline void MOV32RtoR( x86IntRegType to, x86IntRegType from ) { - RexRB(0, from, to); + RexRB(0, from, to); write8( 0x89 ); ModRM( 3, from, to ); } @@ -413,7 +414,7 @@ _inline void MOV32RtoR( x86IntRegType to, x86IntRegType from ) /* mov r32 to m32 */ void MOV32RtoM( uptr to, x86IntRegType from ) { - RexR(0, from); + RexR(0, from); write8( 0x89 ); ModRM( 0, from, DISP32 ); write32( MEMADDR(to, 4) ); @@ -430,20 +431,20 @@ _inline void MOV32MtoR( x86IntRegType to, uptr from ) /* mov [r32] to r32 */ _inline void MOV32RmtoR( x86IntRegType to, x86IntRegType from ) { - RexRB(0, to, from); - write8(0x8B); - WriteRmOffsetFrom(to, from, 0); + RexRB(0, to, from); + write8(0x8B); + WriteRmOffsetFrom(to, from, 0); } _inline void MOV32RmtoROffset( x86IntRegType to, x86IntRegType from, int offset ) { RexRB(0, to, from); write8( 0x8B ); - WriteRmOffsetFrom(to, from, offset); + WriteRmOffsetFrom(to, from, offset); } /* mov [r32+r32*scale] to r32 */ _inline void MOV32RmStoR( x86IntRegType to, x86IntRegType from, x86IntRegType from2, int scale) { - RexRXB(0,to,from2,from); + RexRXB(0,to,from2,from); write8( 0x8B ); ModRM( 0, to, 0x4 ); SibSB(scale, from2, from ); @@ -452,7 +453,7 @@ _inline void MOV32RmStoR( x86IntRegType to, x86IntRegType from, x86IntRegType fr // mov r32 to [r32< 0x7f ) { - assert( to <= 0xffffffff ); - return (u8*)JMP32( to ); + assert( to <= 0xffffffff ); + return (u8*)JMP32( to ); } else { - return (u8*)JMP8( to ); + return (u8*)JMP8( to ); } } @@ -2600,7 +2625,7 @@ __forceinline u8* JMP8( u8 to ) /* jmp rel32 */ __forceinline u32* JMP32( uptr to ) { - assert( (sptr)to <= 0x7fffffff && (sptr)to >= -0x7fffffff ); + assert( (sptr)to <= 0x7fffffff && (sptr)to >= -0x7fffffff ); write8( 0xE9 ); write32( to ); return (u32*)(x86Ptr - 4 ); @@ -2609,7 +2634,7 @@ __forceinline u32* JMP32( uptr to ) /* jmp r32/r64 */ _inline void JMPR( x86IntRegType to ) { - RexB(0, to); + RexB(0, to); write8( 0xFF ); ModRM( 3, 4, to ); } @@ -2862,9 +2887,9 @@ __forceinline u32* JS32( u32 to ) /* call func */ _inline void CALLFunc( uptr func ) { - func -= ( (uptr)x86Ptr + 5 ); - assert( (sptr)func <= 0x7fffffff && (sptr)func >= -0x7fffffff ); - CALL32(func); + func -= ( (uptr)x86Ptr + 5 ); + assert( (sptr)func <= 0x7fffffff && (sptr)func >= -0x7fffffff ); + CALL32(func); } /* call rel32 */ @@ -2898,7 +2923,7 @@ _inline void CALL32M( u32 to ) } //////////////////////////////////// -// misc instructions / +// misc instructions / //////////////////////////////////// /* cmp imm32 to r64 */ @@ -2908,7 +2933,7 @@ _inline void CMP64I32toR( x86IntRegType to, u32 from ) if ( to == EAX ) { write8( 0x3D ); } - else { + else { write8( 0x81 ); ModRM( 3, 7, to ); } @@ -2927,7 +2952,7 @@ _inline void CMP64MtoR( x86IntRegType to, uptr from ) // cmp r64 to r64 _inline void CMP64RtoR( x86IntRegType to, x86IntRegType from ) { - RexRB(1,from,to); + RexRB(1,from,to); write8( 0x39 ); ModRM( 3, from, to ); } @@ -2935,12 +2960,12 @@ _inline void CMP64RtoR( x86IntRegType to, x86IntRegType from ) /* cmp imm32 to r32 */ _inline void CMP32ItoR( x86IntRegType to, u32 from ) { - RexB(0,to); + RexB(0,to); if ( to == EAX ) { write8( 0x3D ); } - else { - write8( 0x81 ); + else { + write8( 0x81 ); ModRM( 3, 7, to ); } write32( from ); @@ -2958,7 +2983,7 @@ _inline void CMP32ItoM( uptr to, u32 from ) /* cmp r32 to r32 */ _inline void CMP32RtoR( x86IntRegType to, x86IntRegType from ) { - RexRB(0,from,to); + RexRB(0,from,to); write8( 0x39 ); ModRM( 3, from, to ); } @@ -2966,7 +2991,7 @@ _inline void CMP32RtoR( x86IntRegType to, x86IntRegType from ) /* cmp m32 to r32 */ _inline void CMP32MtoR( x86IntRegType to, uptr from ) { - RexR(0,to); + RexR(0,to); write8( 0x3B ); ModRM( 0, to, DISP32 ); write32( MEMADDR(from, 4) ); @@ -2975,7 +3000,7 @@ _inline void CMP32MtoR( x86IntRegType to, uptr from ) // cmp imm8 to [r32] _inline void CMP32I8toRm( x86IntRegType to, u8 from) { - RexB(0,to); + RexB(0,to); write8( 0x83 ); ModRM( 0, 7, to ); write8(from); @@ -2984,7 +3009,7 @@ _inline void CMP32I8toRm( x86IntRegType to, u8 from) // cmp imm32 to [r32+off] _inline void CMP32I8toRmOffset8( x86IntRegType to, u8 from, u8 off) { - RexB(0,to); + RexB(0,to); write8( 0x83 ); ModRM( 1, 7, to ); write8(off); @@ -3004,7 +3029,7 @@ _inline void CMP32I8toM( uptr to, u8 from) _inline void CMP16ItoR( x86IntRegType to, u16 from ) { write8( 0x66 ); - RexB(0,to); + RexB(0,to); if ( to == EAX ) { write8( 0x3D ); @@ -3031,7 +3056,7 @@ _inline void CMP16ItoM( uptr to, u16 from ) _inline void CMP16RtoR( x86IntRegType to, x86IntRegType from ) { write8( 0x66 ); - RexRB(0,from,to); + RexRB(0,from,to); write8( 0x39 ); ModRM( 3, from, to ); } @@ -3040,7 +3065,7 @@ _inline void CMP16RtoR( x86IntRegType to, x86IntRegType from ) _inline void CMP16MtoR( x86IntRegType to, uptr from ) { write8( 0x66 ); - RexR(0,to); + RexR(0,to); write8( 0x3B ); ModRM( 0, to, DISP32 ); write32( MEMADDR(from, 4) ); @@ -3049,7 +3074,7 @@ _inline void CMP16MtoR( x86IntRegType to, uptr from ) // cmp imm8 to r8 _inline void CMP8ItoR( x86IntRegType to, u8 from ) { - RexB(0,to); + RexB(0,to); if ( to == EAX ) { write8( 0x3C ); @@ -3065,7 +3090,7 @@ _inline void CMP8ItoR( x86IntRegType to, u8 from ) // cmp m8 to r8 _inline void CMP8MtoR( x86IntRegType to, uptr from ) { - RexR(0,to); + RexR(0,to); write8( 0x3A ); ModRM( 0, to, DISP32 ); write32( MEMADDR(from, 4) ); @@ -3074,7 +3099,7 @@ _inline void CMP8MtoR( x86IntRegType to, uptr from ) /* test imm32 to r32 */ _inline void TEST32ItoR( x86IntRegType to, u32 from ) { - RexB(0,to); + RexB(0,to); if ( to == EAX ) { write8( 0xA9 ); @@ -3098,7 +3123,7 @@ _inline void TEST32ItoM( uptr to, u32 from ) /* test r32 to r32 */ _inline void TEST32RtoR( x86IntRegType to, x86IntRegType from ) { - RexRB(0,from,to); + RexRB(0,from,to); write8( 0x85 ); ModRM( 3, from, to ); } @@ -3106,7 +3131,7 @@ _inline void TEST32RtoR( x86IntRegType to, x86IntRegType from ) // test imm32 to [r32] _inline void TEST32ItoRm( x86IntRegType to, u32 from ) { - RexB(0,to); + RexB(0,to); write8( 0xF7 ); ModRM( 0, 0, to ); write32(from); @@ -3115,8 +3140,8 @@ _inline void TEST32ItoRm( x86IntRegType to, u32 from ) // test imm16 to r16 _inline void TEST16ItoR( x86IntRegType to, u16 from ) { - write8(0x66); - RexB(0,to); + write8(0x66); + RexB(0,to); if ( to == EAX ) { write8( 0xA9 ); @@ -3132,8 +3157,8 @@ _inline void TEST16ItoR( x86IntRegType to, u16 from ) // test r16 to r16 _inline void TEST16RtoR( x86IntRegType to, x86IntRegType from ) { - write8(0x66); - RexRB(0,from,to); + write8(0x66); + RexRB(0,from,to); write8( 0x85 ); ModRM( 3, from, to ); } @@ -3141,7 +3166,7 @@ _inline void TEST16RtoR( x86IntRegType to, x86IntRegType from ) // test r8 to r8 _inline void TEST8RtoR( x86IntRegType to, x86IntRegType from ) { - RexRB(0, from, to); + RexRB(0, from, to); write8( 0x84 ); ModRM( 3, from, to ); } @@ -3150,7 +3175,7 @@ _inline void TEST8RtoR( x86IntRegType to, x86IntRegType from ) // test imm8 to r8 _inline void TEST8ItoR( x86IntRegType to, u8 from ) { - RexB(0,to); + RexB(0,to); if ( to == EAX ) { write8( 0xA8 ); @@ -3175,7 +3200,7 @@ _inline void TEST8ItoM( uptr to, u8 from ) /* sets r8 */ _inline void SETS8R( x86IntRegType to ) { - SET8R( 0x98, to ); + SET8R( 0x98, to ); } /* setl r8 */ @@ -3204,9 +3229,9 @@ _inline void SETE8R( x86IntRegType to ) { SET8R(0x94, to); } /* push imm32 */ _inline void PUSH32I( u32 from ) { - X86_64ASSERT(); + X86_64ASSERT(); write8( 0x68 ); - write32( from ); + write32( from ); } #ifdef __x86_64__ @@ -3214,7 +3239,7 @@ _inline void PUSH32I( u32 from ) /* push r32 */ void PUSH32R( x86IntRegType from ) { - RexB(0,from); + RexB(0,from); write8( 0x51 | from ); } @@ -3228,7 +3253,7 @@ void PUSH32M( uptr from ) /* pop r64 */ void POP64R( x86IntRegType from ) { - RexB(0,from); + RexB(0,from); write8( 0x59 | from ); } @@ -3243,7 +3268,7 @@ _inline void PUSH32R( x86IntRegType from ) { write8( 0x50 | from ); } /* push m32 */ _inline void PUSH32M( u32 from ) { - write8( 0xFF ); + write8( 0xFF ); ModRM( 0, 6, DISP32 ); write32( MEMADDR(from, 4) ); } @@ -3318,7 +3343,7 @@ _inline void LEA16RtoR(x86IntRegType to, x86IntRegType from, u16 offset) _inline void LEA32RtoR(x86IntRegType to, x86IntRegType from, u32 offset) { - RexRB(0,to,from); + RexRB(0,to,from); write8(0x8d); if( (from&7) == ESP ) { @@ -3361,15 +3386,15 @@ _inline void LEA16RRtoR(x86IntRegType to, x86IntRegType from0, x86IntRegType fro _inline void LEA32RRtoR(x86IntRegType to, x86IntRegType from0, x86IntRegType from1) { - RexRXB(0, to, from0, from1); + RexRXB(0, to, from0, from1); write8(0x8d); - if( (from1&7) == EBP ) { - ModRM(1, to, 4); + if( (from1&7) == EBP ) { + ModRM(1, to, 4); ModRM(0, from0, from1); write8(0); - } - else { + } + else { ModRM(0, to, 4); ModRM(0, from0, from1); } @@ -3390,14 +3415,14 @@ _inline void LEA32RStoR(x86IntRegType to, x86IntRegType from, u32 scale) } if( from != ESP ) { - RexRXB(0,to,from,0); + RexRXB(0,to,from,0); write8(0x8d); ModRM(0, to, 4); ModRM(scale, from, 5); write32(0); } else { - assert( to != ESP ); + assert( to != ESP ); MOV32RtoR(to, from); LEA32RStoR(to, to, scale); }