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
|
2009-10-21 02:23:42 +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.
|
2009-04-19 02:14:50 +00:00
|
|
|
*
|
2009-09-08 12:08:10 +00:00
|
|
|
* 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-04-19 02:14:50 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
// Implementations found here: CALL and JMP! (unconditional only)
|
2009-11-06 21:45:30 +00:00
|
|
|
|
|
|
|
namespace x86Emitter {
|
2009-04-19 02:14:50 +00:00
|
|
|
|
2009-10-21 02:23:42 +00:00
|
|
|
#ifdef __GNUG__
|
|
|
|
// GCC has a bug that causes the templated function handler for Jmp/Call emitters to generate
|
|
|
|
// bad asm code. (error is something like "7#*_uber_379s_mangled_$&02_name is already defined!")
|
2010-08-09 04:10:38 +00:00
|
|
|
// Using GCC's always_inline attribute fixes it. This differs from __fi in that it
|
2009-10-21 02:23:42 +00:00
|
|
|
// inlines *even in debug builds* which is (usually) undesirable.
|
2009-10-21 07:10:30 +00:00
|
|
|
// ... except when it avoids compiler bugs.
|
2009-10-21 02:23:42 +00:00
|
|
|
# define __always_inline_tmpl_fail __attribute__((always_inline))
|
2009-10-21 07:10:30 +00:00
|
|
|
#else
|
|
|
|
# define __always_inline_tmpl_fail
|
2009-10-21 02:23:42 +00:00
|
|
|
#endif
|
|
|
|
|
2009-11-06 21:45:30 +00:00
|
|
|
extern void xJccKnownTarget( JccComparisonType comparison, const void* target, bool slideForward );
|
|
|
|
|
2009-04-19 02:14:50 +00:00
|
|
|
// ------------------------------------------------------------------------
|
2009-11-06 21:45:30 +00:00
|
|
|
struct xImpl_JmpCall
|
2009-04-19 02:14:50 +00:00
|
|
|
{
|
2009-11-06 21:45:30 +00:00
|
|
|
bool isJmp;
|
2009-04-19 02:14:50 +00:00
|
|
|
|
2009-11-06 21:45:30 +00:00
|
|
|
void operator()( const xRegister32& absreg ) const;
|
2010-07-05 19:15:19 +00:00
|
|
|
void operator()( const xIndirect32& src ) const;
|
2009-04-19 02:14:50 +00:00
|
|
|
|
2009-11-06 21:45:30 +00:00
|
|
|
void operator()( const xRegister16& absreg ) const;
|
2010-07-05 19:15:19 +00:00
|
|
|
void operator()( const xIndirect16& src ) const;
|
2009-10-21 02:23:42 +00:00
|
|
|
|
2009-04-19 02:14:50 +00:00
|
|
|
// Special form for calling functions. This form automatically resolves the
|
|
|
|
// correct displacement based on the size of the instruction being generated.
|
2010-08-09 04:10:38 +00:00
|
|
|
template< typename T > __fi __always_inline_tmpl_fail
|
2009-10-21 02:23:42 +00:00
|
|
|
void operator()( T* func ) const
|
2009-04-19 02:14:50 +00:00
|
|
|
{
|
|
|
|
if( isJmp )
|
2009-04-24 11:44:07 +00:00
|
|
|
xJccKnownTarget( Jcc_Unconditional, (void*)(uptr)func, false ); // double cast to/from (uptr) needed to appease GCC
|
2009-04-19 02:14:50 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// calls are relative to the instruction after this one, and length is
|
|
|
|
// always 5 bytes (16 bit calls are bad mojo, so no bother to do special logic).
|
2009-10-21 02:23:42 +00:00
|
|
|
|
2009-04-24 11:25:10 +00:00
|
|
|
sptr dest = (sptr)func - ((sptr)xGetPtr() + 5);
|
|
|
|
xWrite8( 0xe8 );
|
|
|
|
xWrite32( dest );
|
2009-04-19 02:14:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2009-04-24 11:25:10 +00:00
|
|
|
|
2009-11-06 21:45:30 +00:00
|
|
|
} // End namespace x86Emitter
|
|
|
|
|