2009-09-08 12:08:10 +00:00
|
|
|
/* PCSX2 - PS2 Emulator for PCs
|
2010-05-03 14:08:02 +00:00
|
|
|
* Copyright (C) 2002-2010 PCSX2 Dev Team
|
2010-04-25 00:31:27 +00:00
|
|
|
*
|
2009-09-08 12:08:10 +00:00
|
|
|
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU Lesser General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with PCSX2.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2009-07-03 00:49:40 +00:00
|
|
|
/*
|
2009-09-08 12:08:10 +00:00
|
|
|
* ix86 core v0.6.2
|
|
|
|
* Authors: linuzappz <linuzappz@pcsx.net>
|
|
|
|
* alexey silinov
|
|
|
|
* goldfinger
|
|
|
|
* zerofrog(@gmail.com)
|
|
|
|
* cottonvibes(@gmail.com)
|
|
|
|
*/
|
2009-07-03 00:49:40 +00:00
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// ix86 legacy emitter functions
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "PrecompiledHeader.h"
|
|
|
|
#include "legacy_internal.h"
|
|
|
|
|
|
|
|
emitterT void ModRM( uint mod, uint reg, uint rm )
|
|
|
|
{
|
2009-10-04 15:34:40 +00:00
|
|
|
// Note: Following assertions are for legacy support only.
|
2009-07-03 00:49:40 +00:00
|
|
|
// The new emitter performs these sanity checks during operand construction, so these
|
|
|
|
// assertions can probably be removed once all legacy emitter code has been removed.
|
2009-10-04 15:34:40 +00:00
|
|
|
pxAssert( mod < 4 );
|
|
|
|
pxAssert( reg < 8 );
|
|
|
|
pxAssert( rm < 8 );
|
2009-07-03 00:49:40 +00:00
|
|
|
xWrite8( (mod << 6) | (reg << 3) | rm );
|
|
|
|
}
|
|
|
|
|
|
|
|
emitterT void SibSB( uint ss, uint index, uint base )
|
|
|
|
{
|
2009-11-06 21:45:30 +00:00
|
|
|
// Note: Following asserts are for legacy support only.
|
2009-07-03 00:49:40 +00:00
|
|
|
// The new emitter performs these sanity checks during operand construction, so these
|
|
|
|
// assertions can probably be removed once all legacy emitter code has been removed.
|
2009-10-04 15:34:40 +00:00
|
|
|
pxAssert( ss < 4 );
|
|
|
|
pxAssert( index < 8 );
|
|
|
|
pxAssert( base < 8 );
|
2009-07-03 00:49:40 +00:00
|
|
|
xWrite8( (ss << 6) | (index << 3) | base );
|
|
|
|
}
|
|
|
|
|
|
|
|
using namespace x86Emitter;
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// From here on are instructions that have NOT been implemented in the new emitter.
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
emitterT u8* J8Rel( int cc, int to )
|
|
|
|
{
|
|
|
|
xWrite8( cc );
|
|
|
|
xWrite8( to );
|
|
|
|
return (u8*)(x86Ptr - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
emitterT u16* J16Rel( int cc, u32 to )
|
|
|
|
{
|
|
|
|
xWrite16( 0x0F66 );
|
|
|
|
xWrite8( cc );
|
|
|
|
xWrite16( to );
|
|
|
|
return (u16*)( x86Ptr - 2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
emitterT u32* J32Rel( int cc, u32 to )
|
|
|
|
{
|
|
|
|
xWrite8( 0x0F );
|
|
|
|
xWrite8( cc );
|
|
|
|
xWrite32( to );
|
|
|
|
return (u32*)( x86Ptr - 4 );
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////
|
2009-07-03 20:12:33 +00:00
|
|
|
emitterT void x86SetPtr( u8* ptr )
|
2009-07-03 00:49:40 +00:00
|
|
|
{
|
|
|
|
x86Ptr = ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Jump Label API (as rough as it might be)
|
|
|
|
//
|
|
|
|
// I don't auto-inline these because of the console logging in case of error, which tends
|
|
|
|
// to cause quite a bit of code bloat.
|
|
|
|
//
|
|
|
|
void x86SetJ8( u8* j8 )
|
|
|
|
{
|
|
|
|
u32 jump = ( x86Ptr - j8 ) - 1;
|
|
|
|
|
|
|
|
if ( jump > 0x7f ) {
|
Lots of new code maintenance stuffs:
* Completely new assertion macros: pxAssert, pxAssertMsg, and pxFail, pxAssertDev (both which default to using a message). These replace *all* wxASSERT, DevAssert, and jASSUME varieties of macros. New macros borrow the best of all assertion worlds: MSVCRT, wxASSERT, and AtlAssume. :)
* Rewrote the Console namespace as a structure called IConsoleWriter, and created several varieties of ConsoleWriters for handling different states of log and console availability (should help reduce overhead of console logging nicely).
* More improvements to the PersistentThread model, using safely interlocked "Do*" style callbacks for starting and cleaning up threads.
* Fixed console logs so that they're readable in Win32 notepad again (the log writer adds CRs to naked LFs).
* Added AppInit.cpp -- contains constructor, destructor, OnInit, and command line parsing mess.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1950 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-04 08:27:27 +00:00
|
|
|
Console.Error( "j8 greater than 0x7f!!" );
|
2009-07-03 00:49:40 +00:00
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
*j8 = (u8)jump;
|
|
|
|
}
|
|
|
|
|
|
|
|
void x86SetJ8A( u8* j8 )
|
|
|
|
{
|
|
|
|
u32 jump = ( x86Ptr - j8 ) - 1;
|
|
|
|
|
|
|
|
if ( jump > 0x7f ) {
|
Lots of new code maintenance stuffs:
* Completely new assertion macros: pxAssert, pxAssertMsg, and pxFail, pxAssertDev (both which default to using a message). These replace *all* wxASSERT, DevAssert, and jASSUME varieties of macros. New macros borrow the best of all assertion worlds: MSVCRT, wxASSERT, and AtlAssume. :)
* Rewrote the Console namespace as a structure called IConsoleWriter, and created several varieties of ConsoleWriters for handling different states of log and console availability (should help reduce overhead of console logging nicely).
* More improvements to the PersistentThread model, using safely interlocked "Do*" style callbacks for starting and cleaning up threads.
* Fixed console logs so that they're readable in Win32 notepad again (the log writer adds CRs to naked LFs).
* Added AppInit.cpp -- contains constructor, destructor, OnInit, and command line parsing mess.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1950 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-04 08:27:27 +00:00
|
|
|
Console.Error( "j8 greater than 0x7f!!" );
|
2009-07-03 00:49:40 +00:00
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ((uptr)x86Ptr&0xf) > 4 ) {
|
|
|
|
|
|
|
|
uptr newjump = jump + 16-((uptr)x86Ptr&0xf);
|
|
|
|
|
|
|
|
if( newjump <= 0x7f ) {
|
|
|
|
jump = newjump;
|
|
|
|
while((uptr)x86Ptr&0xf) *x86Ptr++ = 0x90;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*j8 = (u8)jump;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////
|
2009-07-03 20:12:33 +00:00
|
|
|
emitterT void x86SetJ32( u32* j32 )
|
2009-07-03 00:49:40 +00:00
|
|
|
{
|
|
|
|
*j32 = ( x86Ptr - (u8*)j32 ) - 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
emitterT void x86SetJ32A( u32* j32 )
|
|
|
|
{
|
|
|
|
while((uptr)x86Ptr&0xf) *x86Ptr++ = 0x90;
|
|
|
|
x86SetJ32(j32);
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////
|
2009-07-03 20:12:33 +00:00
|
|
|
emitterT void x86Align( int bytes )
|
2009-07-03 00:49:40 +00:00
|
|
|
{
|
|
|
|
// forward align
|
|
|
|
x86Ptr = (u8*)( ( (uptr)x86Ptr + bytes - 1) & ~( bytes - 1 ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************/
|
|
|
|
/* IX86 instructions */
|
|
|
|
/********************/
|
|
|
|
|
|
|
|
////////////////////////////////////
|
|
|
|
// jump instructions /
|
|
|
|
////////////////////////////////////
|
|
|
|
|
|
|
|
/* jmp rel8 */
|
2009-07-03 20:12:33 +00:00
|
|
|
emitterT u8* JMP8( u8 to )
|
2009-07-03 00:49:40 +00:00
|
|
|
{
|
2009-07-03 20:12:33 +00:00
|
|
|
xWrite8( 0xEB );
|
2009-07-03 00:49:40 +00:00
|
|
|
xWrite8( to );
|
|
|
|
return x86Ptr - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* jmp rel32 */
|
2009-07-03 20:12:33 +00:00
|
|
|
emitterT u32* JMP32( uptr to )
|
2009-07-03 00:49:40 +00:00
|
|
|
{
|
|
|
|
assert( (sptr)to <= 0x7fffffff && (sptr)to >= -0x7fffffff );
|
2009-07-03 20:12:33 +00:00
|
|
|
xWrite8( 0xE9 );
|
|
|
|
xWrite32( to );
|
2009-07-03 00:49:40 +00:00
|
|
|
return (u32*)(x86Ptr - 4 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* jp rel8 */
|
|
|
|
emitterT u8* JP8( u8 to ) {
|
|
|
|
return J8Rel( 0x7A, to );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* jnp rel8 */
|
|
|
|
emitterT u8* JNP8( u8 to ) {
|
|
|
|
return J8Rel( 0x7B, to );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* je rel8 */
|
|
|
|
emitterT u8* JE8( u8 to ) {
|
|
|
|
return J8Rel( 0x74, to );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* jz rel8 */
|
2009-07-03 20:12:33 +00:00
|
|
|
emitterT u8* JZ8( u8 to )
|
2009-07-03 00:49:40 +00:00
|
|
|
{
|
2009-07-03 20:12:33 +00:00
|
|
|
return J8Rel( 0x74, to );
|
2009-07-03 00:49:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* js rel8 */
|
2009-07-03 20:12:33 +00:00
|
|
|
emitterT u8* JS8( u8 to )
|
|
|
|
{
|
2009-07-03 00:49:40 +00:00
|
|
|
return J8Rel( 0x78, to );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* jns rel8 */
|
2009-07-03 20:12:33 +00:00
|
|
|
emitterT u8* JNS8( u8 to )
|
|
|
|
{
|
2009-07-03 00:49:40 +00:00
|
|
|
return J8Rel( 0x79, to );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* jg rel8 */
|
2009-07-03 20:12:33 +00:00
|
|
|
emitterT u8* JG8( u8 to )
|
|
|
|
{
|
2009-07-03 00:49:40 +00:00
|
|
|
return J8Rel( 0x7F, to );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* jge rel8 */
|
2009-07-03 20:12:33 +00:00
|
|
|
emitterT u8* JGE8( u8 to )
|
|
|
|
{
|
|
|
|
return J8Rel( 0x7D, to );
|
2009-07-03 00:49:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* jl rel8 */
|
2009-07-03 20:12:33 +00:00
|
|
|
emitterT u8* JL8( u8 to )
|
|
|
|
{
|
|
|
|
return J8Rel( 0x7C, to );
|
2009-07-03 00:49:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ja rel8 */
|
2009-07-03 20:12:33 +00:00
|
|
|
emitterT u8* JA8( u8 to )
|
|
|
|
{
|
|
|
|
return J8Rel( 0x77, to );
|
2009-07-03 00:49:40 +00:00
|
|
|
}
|
|
|
|
|
2009-07-03 20:12:33 +00:00
|
|
|
emitterT u8* JAE8( u8 to )
|
|
|
|
{
|
|
|
|
return J8Rel( 0x73, to );
|
2009-07-03 00:49:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* jb rel8 */
|
2009-07-03 20:12:33 +00:00
|
|
|
emitterT u8* JB8( u8 to )
|
|
|
|
{
|
|
|
|
return J8Rel( 0x72, to );
|
2009-07-03 00:49:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* jbe rel8 */
|
2009-07-03 20:12:33 +00:00
|
|
|
emitterT u8* JBE8( u8 to )
|
|
|
|
{
|
|
|
|
return J8Rel( 0x76, to );
|
2009-07-03 00:49:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* jle rel8 */
|
2009-07-03 20:12:33 +00:00
|
|
|
emitterT u8* JLE8( u8 to )
|
|
|
|
{
|
|
|
|
return J8Rel( 0x7E, to );
|
2009-07-03 00:49:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* jne rel8 */
|
2009-07-03 20:12:33 +00:00
|
|
|
emitterT u8* JNE8( u8 to )
|
|
|
|
{
|
|
|
|
return J8Rel( 0x75, to );
|
2009-07-03 00:49:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* jnz rel8 */
|
2009-07-03 20:12:33 +00:00
|
|
|
emitterT u8* JNZ8( u8 to )
|
|
|
|
{
|
|
|
|
return J8Rel( 0x75, to );
|
2009-07-03 00:49:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* jng rel8 */
|
2009-07-03 20:12:33 +00:00
|
|
|
emitterT u8* JNG8( u8 to )
|
|
|
|
{
|
|
|
|
return J8Rel( 0x7E, to );
|
2009-07-03 00:49:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* jnge rel8 */
|
2009-07-03 20:12:33 +00:00
|
|
|
emitterT u8* JNGE8( u8 to )
|
|
|
|
{
|
|
|
|
return J8Rel( 0x7C, to );
|
2009-07-03 00:49:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* jnl rel8 */
|
2009-07-03 20:12:33 +00:00
|
|
|
emitterT u8* JNL8( u8 to )
|
|
|
|
{
|
|
|
|
return J8Rel( 0x7D, to );
|
2009-07-03 00:49:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* jnle rel8 */
|
2009-07-03 20:12:33 +00:00
|
|
|
emitterT u8* JNLE8( u8 to )
|
|
|
|
{
|
|
|
|
return J8Rel( 0x7F, to );
|
2009-07-03 00:49:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* jo rel8 */
|
2009-07-03 20:12:33 +00:00
|
|
|
emitterT u8* JO8( u8 to )
|
|
|
|
{
|
|
|
|
return J8Rel( 0x70, to );
|
2009-07-03 00:49:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* jno rel8 */
|
2009-07-03 20:12:33 +00:00
|
|
|
emitterT u8* JNO8( u8 to )
|
|
|
|
{
|
|
|
|
return J8Rel( 0x71, to );
|
2009-07-03 00:49:40 +00:00
|
|
|
}
|
2009-07-03 20:12:33 +00:00
|
|
|
// jb rel32
|
2009-07-03 00:49:40 +00:00
|
|
|
emitterT u32* JB32( u32 to )
|
|
|
|
{
|
|
|
|
return J32Rel( 0x82, to );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* je rel32 */
|
2009-07-03 20:12:33 +00:00
|
|
|
emitterT u32* JE32( u32 to )
|
2009-07-03 00:49:40 +00:00
|
|
|
{
|
|
|
|
return J32Rel( 0x84, to );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* jz rel32 */
|
2009-07-03 20:12:33 +00:00
|
|
|
emitterT u32* JZ32( u32 to )
|
2009-07-03 00:49:40 +00:00
|
|
|
{
|
2009-07-03 20:12:33 +00:00
|
|
|
return J32Rel( 0x84, to );
|
2009-07-03 00:49:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* js rel32 */
|
2009-07-03 20:12:33 +00:00
|
|
|
emitterT u32* JS32( u32 to )
|
|
|
|
{
|
2009-07-03 00:49:40 +00:00
|
|
|
return J32Rel( 0x88, to );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* jns rel32 */
|
2009-07-03 20:12:33 +00:00
|
|
|
emitterT u32* JNS32( u32 to )
|
|
|
|
{
|
2009-07-03 00:49:40 +00:00
|
|
|
return J32Rel( 0x89, to );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* jg rel32 */
|
2009-07-03 20:12:33 +00:00
|
|
|
emitterT u32* JG32( u32 to )
|
|
|
|
{
|
2009-07-03 00:49:40 +00:00
|
|
|
return J32Rel( 0x8F, to );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* jge rel32 */
|
2009-07-03 20:12:33 +00:00
|
|
|
emitterT u32* JGE32( u32 to )
|
|
|
|
{
|
|
|
|
return J32Rel( 0x8D, to );
|
2009-07-03 00:49:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* jl rel32 */
|
2009-07-03 20:12:33 +00:00
|
|
|
emitterT u32* JL32( u32 to )
|
|
|
|
{
|
|
|
|
return J32Rel( 0x8C, to );
|
2009-07-03 00:49:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* jle rel32 */
|
2009-07-03 20:12:33 +00:00
|
|
|
emitterT u32* JLE32( u32 to )
|
|
|
|
{
|
|
|
|
return J32Rel( 0x8E, to );
|
2009-07-03 00:49:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ja rel32 */
|
2009-07-03 20:12:33 +00:00
|
|
|
emitterT u32* JA32( u32 to )
|
|
|
|
{
|
|
|
|
return J32Rel( 0x87, to );
|
2009-07-03 00:49:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* jae rel32 */
|
2009-07-03 20:12:33 +00:00
|
|
|
emitterT u32* JAE32( u32 to )
|
|
|
|
{
|
|
|
|
return J32Rel( 0x83, to );
|
2009-07-03 00:49:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* jne rel32 */
|
2009-07-03 20:12:33 +00:00
|
|
|
emitterT u32* JNE32( u32 to )
|
|
|
|
{
|
|
|
|
return J32Rel( 0x85, to );
|
2009-07-03 00:49:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* jnz rel32 */
|
2009-07-03 20:12:33 +00:00
|
|
|
emitterT u32* JNZ32( u32 to )
|
|
|
|
{
|
|
|
|
return J32Rel( 0x85, to );
|
2009-07-03 00:49:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* jng rel32 */
|
2009-07-03 20:12:33 +00:00
|
|
|
emitterT u32* JNG32( u32 to )
|
|
|
|
{
|
|
|
|
return J32Rel( 0x8E, to );
|
2009-07-03 00:49:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* jnge rel32 */
|
2009-07-03 20:12:33 +00:00
|
|
|
emitterT u32* JNGE32( u32 to )
|
|
|
|
{
|
|
|
|
return J32Rel( 0x8C, to );
|
2009-07-03 00:49:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* jnl rel32 */
|
2009-07-03 20:12:33 +00:00
|
|
|
emitterT u32* JNL32( u32 to )
|
|
|
|
{
|
|
|
|
return J32Rel( 0x8D, to );
|
2009-07-03 00:49:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* jnle rel32 */
|
2009-07-03 20:12:33 +00:00
|
|
|
emitterT u32* JNLE32( u32 to )
|
|
|
|
{
|
|
|
|
return J32Rel( 0x8F, to );
|
2009-07-03 00:49:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* jo rel32 */
|
2009-07-03 20:12:33 +00:00
|
|
|
emitterT u32* JO32( u32 to )
|
|
|
|
{
|
|
|
|
return J32Rel( 0x80, to );
|
2009-07-03 00:49:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* jno rel32 */
|
2009-07-03 20:12:33 +00:00
|
|
|
emitterT u32* JNO32( u32 to )
|
|
|
|
{
|
|
|
|
return J32Rel( 0x81, to );
|
2009-07-03 00:49:40 +00:00
|
|
|
}
|