2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2011-02-25 00:54:04 +03:00
|
|
|
// $Id$
|
2005-03-19 23:44:01 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2001-10-03 17:10:38 +04:00
|
|
|
//
|
2012-03-25 15:54:32 +04:00
|
|
|
// Copyright (c) 2007-2012 Stanislav Shwartsman
|
2008-04-05 21:51:55 +04:00
|
|
|
// Written by Stanislav Shwartsman [sshwarts at sourceforge net]
|
2001-04-10 05:04:59 +04:00
|
|
|
//
|
|
|
|
// This library 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 Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library 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
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
2009-01-16 21:18:59 +03:00
|
|
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA B 02110-1301 USA
|
2008-04-05 21:51:55 +04:00
|
|
|
//
|
2007-11-18 02:28:33 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-04-05 21:51:55 +04:00
|
|
|
#ifndef BX_PUSHPOP_H
|
|
|
|
#define BX_PUSHPOP_H
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-04-05 21:51:55 +04:00
|
|
|
BX_CPP_INLINE void BX_CPP_AttrRegparmN(1)
|
|
|
|
BX_CPU_C::push_16(Bit16u value16)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2005-07-31 21:57:27 +04:00
|
|
|
#if BX_SUPPORT_X86_64
|
2012-03-13 19:18:21 +04:00
|
|
|
if (long64_mode()) { /* StackAddrSize = 64 */
|
2012-03-25 15:54:32 +04:00
|
|
|
stack_write_word(RSP-2, value16);
|
2005-07-31 21:57:27 +04:00
|
|
|
RSP -= 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
2004-09-04 23:37:37 +04:00
|
|
|
if (BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.d_b) { /* StackAddrSize = 32 */
|
2012-03-25 15:54:32 +04:00
|
|
|
stack_write_word((Bit32u) (ESP-2), value16);
|
2004-09-04 23:37:37 +04:00
|
|
|
ESP -= 2;
|
|
|
|
}
|
2012-03-13 19:18:21 +04:00
|
|
|
else /* StackAddrSize = 16 */
|
2004-09-04 23:37:37 +04:00
|
|
|
{
|
2012-03-25 15:54:32 +04:00
|
|
|
stack_write_word((Bit16u) (SP-2), value16);
|
2008-04-05 21:51:55 +04:00
|
|
|
SP -= 2;
|
2004-09-04 23:37:37 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2008-04-05 21:51:55 +04:00
|
|
|
BX_CPP_INLINE void BX_CPP_AttrRegparmN(1)
|
|
|
|
BX_CPU_C::push_32(Bit32u value32)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2005-07-31 21:57:27 +04:00
|
|
|
#if BX_SUPPORT_X86_64
|
2012-03-13 19:18:21 +04:00
|
|
|
if (long64_mode()) { /* StackAddrSize = 64 */
|
2012-03-25 15:54:32 +04:00
|
|
|
stack_write_dword(RSP-4, value32);
|
2005-07-31 21:57:27 +04:00
|
|
|
RSP -= 4;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
2001-04-10 05:04:59 +04:00
|
|
|
if (BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.d_b) { /* StackAddrSize = 32 */
|
2012-03-25 15:54:32 +04:00
|
|
|
stack_write_dword((Bit32u) (ESP-4), value32);
|
2001-04-10 05:04:59 +04:00
|
|
|
ESP -= 4;
|
2004-09-04 23:37:37 +04:00
|
|
|
}
|
2012-03-13 19:18:21 +04:00
|
|
|
else /* StackAddrSize = 16 */
|
2005-07-31 21:57:27 +04:00
|
|
|
{
|
2012-03-25 15:54:32 +04:00
|
|
|
stack_write_dword((Bit16u) (SP-4), value32);
|
2008-04-05 21:51:55 +04:00
|
|
|
SP -= 4;
|
2004-09-04 23:37:37 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2002-09-15 05:00:20 +04:00
|
|
|
|
2005-10-17 17:06:09 +04:00
|
|
|
/* push 64 bit operand */
|
2007-12-17 00:40:44 +03:00
|
|
|
#if BX_SUPPORT_X86_64
|
2008-04-05 21:51:55 +04:00
|
|
|
BX_CPP_INLINE void BX_CPP_AttrRegparmN(1)
|
|
|
|
BX_CPU_C::push_64(Bit64u value64)
|
2002-09-15 05:00:20 +04:00
|
|
|
{
|
2012-03-13 19:18:21 +04:00
|
|
|
/* StackAddrSize = 64 */
|
2012-03-25 15:54:32 +04:00
|
|
|
stack_write_qword(RSP-8, value64);
|
2007-12-17 00:40:44 +03:00
|
|
|
RSP -= 8;
|
2002-09-15 05:00:20 +04:00
|
|
|
}
|
2007-12-17 00:40:44 +03:00
|
|
|
#endif
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2005-10-17 17:06:09 +04:00
|
|
|
/* pop 16 bit operand from the stack */
|
2008-04-05 21:51:55 +04:00
|
|
|
BX_CPP_INLINE Bit16u BX_CPU_C::pop_16(void)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2007-12-20 21:29:42 +03:00
|
|
|
Bit16u value16;
|
|
|
|
|
2005-07-31 21:57:27 +04:00
|
|
|
#if BX_SUPPORT_X86_64
|
2012-03-13 19:18:21 +04:00
|
|
|
if (long64_mode()) { /* StackAddrSize = 64 */
|
2012-03-25 15:54:32 +04:00
|
|
|
value16 = stack_read_word(RSP);
|
2005-07-31 21:57:27 +04:00
|
|
|
RSP += 2;
|
2007-12-19 00:08:55 +03:00
|
|
|
}
|
2005-07-31 21:57:27 +04:00
|
|
|
else
|
|
|
|
#endif
|
2012-03-13 19:18:21 +04:00
|
|
|
if (BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.d_b) { /* StackAddrSize = 32 */
|
2012-03-25 15:54:32 +04:00
|
|
|
value16 = stack_read_word(ESP);
|
2001-04-10 05:04:59 +04:00
|
|
|
ESP += 2;
|
2007-12-19 00:08:55 +03:00
|
|
|
}
|
2012-03-13 19:18:21 +04:00
|
|
|
else { /* StackAddrSize = 16 */
|
2012-03-25 15:54:32 +04:00
|
|
|
value16 = stack_read_word(SP);
|
2008-04-05 21:51:55 +04:00
|
|
|
SP += 2;
|
2007-12-19 00:08:55 +03:00
|
|
|
}
|
2007-12-20 21:29:42 +03:00
|
|
|
|
|
|
|
return value16;
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2005-10-17 17:06:09 +04:00
|
|
|
/* pop 32 bit operand from the stack */
|
2008-04-05 21:51:55 +04:00
|
|
|
BX_CPP_INLINE Bit32u BX_CPU_C::pop_32(void)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2007-12-20 21:29:42 +03:00
|
|
|
Bit32u value32;
|
|
|
|
|
2005-07-31 21:57:27 +04:00
|
|
|
#if BX_SUPPORT_X86_64
|
2012-03-13 19:18:21 +04:00
|
|
|
if (long64_mode()) { /* StackAddrSize = 64 */
|
2012-03-25 15:54:32 +04:00
|
|
|
value32 = stack_read_dword(RSP);
|
2005-07-31 21:57:27 +04:00
|
|
|
RSP += 4;
|
2007-12-19 00:08:55 +03:00
|
|
|
}
|
2005-07-31 21:57:27 +04:00
|
|
|
else
|
|
|
|
#endif
|
2012-03-13 19:18:21 +04:00
|
|
|
if (BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.d_b) { /* StackAddrSize = 32 */
|
2012-03-25 15:54:32 +04:00
|
|
|
value32 = stack_read_dword(ESP);
|
2001-04-10 05:04:59 +04:00
|
|
|
ESP += 4;
|
2007-12-19 00:08:55 +03:00
|
|
|
}
|
2012-03-13 19:18:21 +04:00
|
|
|
else { /* StackAddrSize = 16 */
|
2012-03-25 15:54:32 +04:00
|
|
|
value32 = stack_read_dword(SP);
|
2008-04-05 21:51:55 +04:00
|
|
|
SP += 4;
|
2007-12-19 00:08:55 +03:00
|
|
|
}
|
2007-12-20 21:29:42 +03:00
|
|
|
|
|
|
|
return value32;
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2002-09-15 05:00:20 +04:00
|
|
|
|
2005-10-17 17:06:09 +04:00
|
|
|
/* pop 64 bit operand from the stack */
|
2007-12-17 00:40:44 +03:00
|
|
|
#if BX_SUPPORT_X86_64
|
2008-04-05 21:51:55 +04:00
|
|
|
BX_CPP_INLINE Bit64u BX_CPU_C::pop_64(void)
|
2002-09-15 05:00:20 +04:00
|
|
|
{
|
2012-03-13 19:18:21 +04:00
|
|
|
/* StackAddrSize = 64 */
|
2012-03-25 15:54:32 +04:00
|
|
|
Bit64u value64 = stack_read_qword(RSP);
|
2007-12-17 00:40:44 +03:00
|
|
|
RSP += 8;
|
2007-12-20 21:29:42 +03:00
|
|
|
|
|
|
|
return value64;
|
2005-07-31 21:57:27 +04:00
|
|
|
}
|
2008-04-05 21:51:55 +04:00
|
|
|
#endif // BX_SUPPORT_X86_64
|
2001-04-10 05:04:59 +04:00
|
|
|
|
I integrated my hacks to get Linux/x86-64 booting. To keep
these from interfering from a normal compile here's what I did.
In config.h.in (which will generate config.h after a configure),
I added a #define called KPL64Hacks:
#define KPL64Hacks
*After* running configure, you must set this by hand. It will
default to off, so you won't get my hacks in a normal compile.
This will go away soon. There is also a macro just after that
called BailBigRSP(). You don't need to enabled that, but you
can. In many of the instructions which seemed like they could
be hit by the fetchdecode64() process, but which also touched
EIP/ESP, I inserted a macro. Usually this macro expands to nothing.
If you like, you can enabled it, and it will panic if it finds
the upper bits of RIP/RSP set. This helped me find bugs.
Also, I cleaned up the emulation in ctrl_xfer{8,16,32}.cc.
There were some really old legacy code snippets which directly
accessed operands on the stack with access_linear. Lots of
ugly code instead of just pop_32() etc. Cleaning those up,
minimized the number of instructions which directly manipulate
the stack pointer, which should help in refining 64-bit support.
2002-09-24 04:44:56 +04:00
|
|
|
#endif
|