2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2010-04-30 13:12:52 +04:00
|
|
|
// $Id: stack32.cc,v 1.65 2010-04-30 09:12:52 sshwarts Exp $
|
2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2009-12-04 19:53:12 +03:00
|
|
|
// Copyright (C) 2001-2009 The Bochs Project
|
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
|
2007-12-20 21:29:42 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2001-05-24 22:46:34 +04:00
|
|
|
#define NEED_CPU_REG_SHORTCUTS 1
|
2001-04-10 05:04:59 +04:00
|
|
|
#include "bochs.h"
|
2006-03-07 01:03:16 +03:00
|
|
|
#include "cpu.h"
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
#define LOG_THIS BX_CPU_THIS_PTR
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2007-11-24 17:22:34 +03:00
|
|
|
// Make code more tidy with a few macros.
|
|
|
|
#if BX_SUPPORT_X86_64==0
|
|
|
|
#define RSP ESP
|
|
|
|
#endif
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::POP_EdM(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2009-03-10 19:28:01 +03:00
|
|
|
RSP_SPECULATIVE;
|
2007-11-24 17:22:34 +03:00
|
|
|
|
2007-12-20 21:29:42 +03:00
|
|
|
Bit32u val32 = pop_32();
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-02-03 00:46:54 +03:00
|
|
|
// Note: there is one little weirdism here. It is possible to use
|
|
|
|
// ESP in the modrm addressing. If used, the value of ESP after the
|
2007-11-20 20:15:33 +03:00
|
|
|
// pop is used to calculate the address.
|
2009-11-02 18:00:47 +03:00
|
|
|
Bit32u eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
|
2008-04-03 21:56:59 +04:00
|
|
|
|
2009-11-02 18:00:47 +03:00
|
|
|
write_virtual_dword_32(i->seg(), eaddr, val32);
|
2007-11-24 17:22:34 +03:00
|
|
|
|
2009-03-10 19:28:01 +03:00
|
|
|
RSP_COMMIT;
|
2007-11-18 21:49:19 +03:00
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PUSH_ERX(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2007-11-14 00:07:08 +03:00
|
|
|
push_32(BX_READ_32BIT_REG(i->opcodeReg()));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::POP_ERX(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2007-12-20 21:29:42 +03:00
|
|
|
BX_WRITE_32BIT_REGZ(i->opcodeReg(), pop_32());
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PUSH32_CS(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2010-04-30 13:12:52 +04:00
|
|
|
Bit16u val_16 = BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].selector.value;
|
|
|
|
|
|
|
|
if (BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.d_b) {
|
|
|
|
write_virtual_word_32(BX_SEG_REG_SS, (Bit32u) (ESP-4), val_16);
|
|
|
|
ESP -= 4;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
write_virtual_word_32(BX_SEG_REG_SS, (Bit16u) (SP-4), val_16);
|
|
|
|
SP -= 4;
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2004-11-02 19:10:02 +03:00
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PUSH32_DS(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2010-04-30 13:12:52 +04:00
|
|
|
Bit16u val_16 = BX_CPU_THIS_PTR sregs[BX_SEG_REG_DS].selector.value;
|
|
|
|
|
|
|
|
if (BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.d_b) {
|
|
|
|
write_virtual_word_32(BX_SEG_REG_SS, (Bit32u) (ESP-4), val_16);
|
|
|
|
ESP -= 4;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
write_virtual_word_32(BX_SEG_REG_SS, (Bit16u) (SP-4), val_16);
|
|
|
|
SP -= 4;
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2004-11-02 19:10:02 +03:00
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PUSH32_ES(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2010-04-30 13:12:52 +04:00
|
|
|
Bit16u val_16 = BX_CPU_THIS_PTR sregs[BX_SEG_REG_ES].selector.value;
|
|
|
|
|
|
|
|
if (BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.d_b) {
|
|
|
|
write_virtual_word_32(BX_SEG_REG_SS, (Bit32u) (ESP-4), val_16);
|
|
|
|
ESP -= 4;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
write_virtual_word_32(BX_SEG_REG_SS, (Bit16u) (SP-4), val_16);
|
|
|
|
SP -= 4;
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2004-11-02 19:10:02 +03:00
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PUSH32_FS(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2010-04-30 13:12:52 +04:00
|
|
|
Bit16u val_16 = BX_CPU_THIS_PTR sregs[BX_SEG_REG_FS].selector.value;
|
|
|
|
|
|
|
|
if (BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.d_b) {
|
|
|
|
write_virtual_word_32(BX_SEG_REG_SS, (Bit32u) (ESP-4), val_16);
|
|
|
|
ESP -= 4;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
write_virtual_word_32(BX_SEG_REG_SS, (Bit16u) (SP-4), val_16);
|
|
|
|
SP -= 4;
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2004-11-02 19:10:02 +03:00
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PUSH32_GS(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2010-04-30 13:12:52 +04:00
|
|
|
Bit16u val_16 = BX_CPU_THIS_PTR sregs[BX_SEG_REG_GS].selector.value;
|
|
|
|
|
|
|
|
if (BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.d_b) {
|
|
|
|
write_virtual_word_32(BX_SEG_REG_SS, (Bit32u) (ESP-4), val_16);
|
|
|
|
ESP -= 4;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
write_virtual_word_32(BX_SEG_REG_SS, (Bit16u) (SP-4), val_16);
|
|
|
|
SP -= 4;
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2004-11-02 19:10:02 +03:00
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PUSH32_SS(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2010-04-30 13:12:52 +04:00
|
|
|
Bit16u val_16 = BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].selector.value;
|
|
|
|
|
|
|
|
if (BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.d_b) {
|
|
|
|
write_virtual_word_32(BX_SEG_REG_SS, (Bit32u) (ESP-4), val_16);
|
|
|
|
ESP -= 4;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
write_virtual_word_32(BX_SEG_REG_SS, (Bit16u) (SP-4), val_16);
|
|
|
|
SP -= 4;
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::POP32_DS(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2009-08-06 18:50:38 +04:00
|
|
|
Bit16u ds;
|
2007-11-24 17:22:34 +03:00
|
|
|
|
2009-08-06 18:50:38 +04:00
|
|
|
if (BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.d_b) {
|
|
|
|
ds = read_virtual_word_32(BX_SEG_REG_SS, ESP);
|
|
|
|
load_seg_reg(&BX_CPU_THIS_PTR sregs[BX_SEG_REG_DS], ds);
|
|
|
|
ESP += 4;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ds = read_virtual_word_32(BX_SEG_REG_SS, SP);
|
|
|
|
load_seg_reg(&BX_CPU_THIS_PTR sregs[BX_SEG_REG_DS], ds);
|
|
|
|
SP += 4;
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2004-11-02 19:10:02 +03:00
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::POP32_ES(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2009-08-06 18:50:38 +04:00
|
|
|
Bit16u es;
|
2007-11-24 17:22:34 +03:00
|
|
|
|
2009-08-06 18:50:38 +04:00
|
|
|
if (BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.d_b) {
|
|
|
|
es = read_virtual_word_32(BX_SEG_REG_SS, ESP);
|
|
|
|
load_seg_reg(&BX_CPU_THIS_PTR sregs[BX_SEG_REG_ES], es);
|
|
|
|
ESP += 4;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
es = read_virtual_word_32(BX_SEG_REG_SS, SP);
|
|
|
|
load_seg_reg(&BX_CPU_THIS_PTR sregs[BX_SEG_REG_ES], es);
|
|
|
|
SP += 4;
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2004-11-02 19:10:02 +03:00
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::POP32_FS(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2009-08-06 18:50:38 +04:00
|
|
|
Bit16u fs;
|
2007-11-24 17:22:34 +03:00
|
|
|
|
2009-08-06 18:50:38 +04:00
|
|
|
if (BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.d_b) {
|
|
|
|
fs = read_virtual_word_32(BX_SEG_REG_SS, ESP);
|
|
|
|
load_seg_reg(&BX_CPU_THIS_PTR sregs[BX_SEG_REG_FS], fs);
|
|
|
|
ESP += 4;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fs = read_virtual_word_32(BX_SEG_REG_SS, SP);
|
|
|
|
load_seg_reg(&BX_CPU_THIS_PTR sregs[BX_SEG_REG_FS], fs);
|
|
|
|
SP += 4;
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2004-11-02 19:10:02 +03:00
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::POP32_GS(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2009-08-06 18:50:38 +04:00
|
|
|
Bit16u gs;
|
2007-11-24 17:22:34 +03:00
|
|
|
|
2009-08-06 18:50:38 +04:00
|
|
|
if (BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.d_b) {
|
|
|
|
gs = read_virtual_word_32(BX_SEG_REG_SS, ESP);
|
|
|
|
load_seg_reg(&BX_CPU_THIS_PTR sregs[BX_SEG_REG_GS], gs);
|
|
|
|
ESP += 4;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
gs = read_virtual_word_32(BX_SEG_REG_SS, SP);
|
|
|
|
load_seg_reg(&BX_CPU_THIS_PTR sregs[BX_SEG_REG_GS], gs);
|
|
|
|
SP += 4;
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2004-11-02 19:10:02 +03:00
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::POP32_SS(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2009-08-06 18:50:38 +04:00
|
|
|
Bit16u ss;
|
2007-11-24 17:22:34 +03:00
|
|
|
|
2009-08-06 18:50:38 +04:00
|
|
|
if (BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.d_b) {
|
|
|
|
ss = read_virtual_word_32(BX_SEG_REG_SS, ESP);
|
|
|
|
load_seg_reg(&BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS], ss);
|
|
|
|
ESP += 4;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ss = read_virtual_word_32(BX_SEG_REG_SS, SP);
|
|
|
|
load_seg_reg(&BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS], ss);
|
|
|
|
SP += 4;
|
|
|
|
}
|
2007-11-24 17:22:34 +03:00
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
// POP SS inhibits interrupts, debug exceptions and single-step
|
|
|
|
// trap exceptions until the execution boundary following the
|
|
|
|
// next instruction is reached.
|
|
|
|
// Same code as MOV_SwEw()
|
2009-05-21 14:39:40 +04:00
|
|
|
BX_CPU_THIS_PTR inhibit_mask |= BX_INHIBIT_INTERRUPTS_BY_MOVSS;
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_CPU_THIS_PTR async_event = 1;
|
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PUSH_Id(bxInstruction_c *i)
|
2007-11-18 21:52:44 +03:00
|
|
|
{
|
|
|
|
push_32(i->Id());
|
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PUSH_EdM(bxInstruction_c *i)
|
2007-11-18 21:52:44 +03:00
|
|
|
{
|
2009-04-07 20:12:19 +04:00
|
|
|
Bit32u eaddr = (Bit32u) BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
|
2008-01-10 22:37:56 +03:00
|
|
|
|
2008-09-19 23:18:57 +04:00
|
|
|
Bit32u op1_32 = read_virtual_dword_32(i->seg(), eaddr);
|
2007-11-18 21:52:44 +03:00
|
|
|
|
|
|
|
push_32(op1_32);
|
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PUSHAD32(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2007-03-03 00:03:25 +03:00
|
|
|
Bit32u temp_ESP = ESP;
|
|
|
|
Bit16u temp_SP = SP;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
if (BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.d_b)
|
2007-03-03 00:03:25 +03:00
|
|
|
{
|
2008-06-12 23:14:40 +04:00
|
|
|
write_virtual_dword_32(BX_SEG_REG_SS, (Bit32u) (temp_ESP - 4), EAX);
|
|
|
|
write_virtual_dword_32(BX_SEG_REG_SS, (Bit32u) (temp_ESP - 8), ECX);
|
|
|
|
write_virtual_dword_32(BX_SEG_REG_SS, (Bit32u) (temp_ESP - 12), EDX);
|
|
|
|
write_virtual_dword_32(BX_SEG_REG_SS, (Bit32u) (temp_ESP - 16), EBX);
|
|
|
|
write_virtual_dword_32(BX_SEG_REG_SS, (Bit32u) (temp_ESP - 20), temp_ESP);
|
|
|
|
write_virtual_dword_32(BX_SEG_REG_SS, (Bit32u) (temp_ESP - 24), EBP);
|
|
|
|
write_virtual_dword_32(BX_SEG_REG_SS, (Bit32u) (temp_ESP - 28), ESI);
|
|
|
|
write_virtual_dword_32(BX_SEG_REG_SS, (Bit32u) (temp_ESP - 32), EDI);
|
2007-03-03 00:03:25 +03:00
|
|
|
ESP -= 32;
|
2005-01-28 23:50:48 +03:00
|
|
|
}
|
2007-03-03 00:03:25 +03:00
|
|
|
else
|
|
|
|
{
|
2008-06-12 23:14:40 +04:00
|
|
|
write_virtual_dword_32(BX_SEG_REG_SS, (Bit16u) (temp_SP - 4), EAX);
|
|
|
|
write_virtual_dword_32(BX_SEG_REG_SS, (Bit16u) (temp_SP - 8), ECX);
|
|
|
|
write_virtual_dword_32(BX_SEG_REG_SS, (Bit16u) (temp_SP - 12), EDX);
|
|
|
|
write_virtual_dword_32(BX_SEG_REG_SS, (Bit16u) (temp_SP - 16), EBX);
|
|
|
|
write_virtual_dword_32(BX_SEG_REG_SS, (Bit16u) (temp_SP - 20), temp_ESP);
|
|
|
|
write_virtual_dword_32(BX_SEG_REG_SS, (Bit16u) (temp_SP - 24), EBP);
|
|
|
|
write_virtual_dword_32(BX_SEG_REG_SS, (Bit16u) (temp_SP - 28), ESI);
|
|
|
|
write_virtual_dword_32(BX_SEG_REG_SS, (Bit16u) (temp_SP - 32), EDI);
|
2007-03-03 00:03:25 +03:00
|
|
|
SP -= 32;
|
2005-01-28 23:50:48 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::POPAD32(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2008-05-01 00:41:40 +04:00
|
|
|
Bit32u edi, esi, ebp, ebx, edx, ecx, eax, dummy;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2007-03-03 00:03:25 +03:00
|
|
|
if (BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.d_b)
|
|
|
|
{
|
|
|
|
Bit32u temp_ESP = ESP;
|
2008-06-12 23:14:40 +04:00
|
|
|
edi = read_virtual_dword_32(BX_SEG_REG_SS, (Bit32u) (temp_ESP + 0));
|
|
|
|
esi = read_virtual_dword_32(BX_SEG_REG_SS, (Bit32u) (temp_ESP + 4));
|
|
|
|
ebp = read_virtual_dword_32(BX_SEG_REG_SS, (Bit32u) (temp_ESP + 8));
|
|
|
|
dummy = read_virtual_dword_32(BX_SEG_REG_SS, (Bit32u) (temp_ESP + 12));
|
|
|
|
ebx = read_virtual_dword_32(BX_SEG_REG_SS, (Bit32u) (temp_ESP + 16));
|
|
|
|
edx = read_virtual_dword_32(BX_SEG_REG_SS, (Bit32u) (temp_ESP + 20));
|
|
|
|
ecx = read_virtual_dword_32(BX_SEG_REG_SS, (Bit32u) (temp_ESP + 24));
|
|
|
|
eax = read_virtual_dword_32(BX_SEG_REG_SS, (Bit32u) (temp_ESP + 28));
|
2007-03-03 00:03:25 +03:00
|
|
|
ESP += 32;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Bit16u temp_SP = SP;
|
2008-06-12 23:14:40 +04:00
|
|
|
edi = read_virtual_dword_32(BX_SEG_REG_SS, (Bit16u) (temp_SP + 0));
|
|
|
|
esi = read_virtual_dword_32(BX_SEG_REG_SS, (Bit16u) (temp_SP + 4));
|
|
|
|
ebp = read_virtual_dword_32(BX_SEG_REG_SS, (Bit16u) (temp_SP + 8));
|
|
|
|
dummy = read_virtual_dword_32(BX_SEG_REG_SS, (Bit16u) (temp_SP + 12));
|
|
|
|
ebx = read_virtual_dword_32(BX_SEG_REG_SS, (Bit16u) (temp_SP + 16));
|
|
|
|
edx = read_virtual_dword_32(BX_SEG_REG_SS, (Bit16u) (temp_SP + 20));
|
|
|
|
ecx = read_virtual_dword_32(BX_SEG_REG_SS, (Bit16u) (temp_SP + 24));
|
|
|
|
eax = read_virtual_dword_32(BX_SEG_REG_SS, (Bit16u) (temp_SP + 28));
|
2007-03-03 00:03:25 +03:00
|
|
|
SP += 32;
|
2005-01-28 23:50:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
EDI = edi;
|
|
|
|
ESI = esi;
|
|
|
|
EBP = ebp;
|
|
|
|
EBX = ebx;
|
|
|
|
EDX = edx;
|
|
|
|
ECX = ecx;
|
|
|
|
EAX = eax;
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2007-11-17 15:44:10 +03:00
|
|
|
|
2008-05-08 22:02:21 +04:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::ENTER32_IwIb(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2005-02-17 00:27:21 +03:00
|
|
|
Bit16u imm16 = i->Iw();
|
2004-11-27 23:36:53 +03:00
|
|
|
Bit8u level = i->Ib2();
|
|
|
|
level &= 0x1F;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2009-03-10 19:28:01 +03:00
|
|
|
RSP_SPECULATIVE;
|
2007-11-24 17:22:34 +03:00
|
|
|
|
2008-05-08 22:02:21 +04:00
|
|
|
push_32(EBP);
|
2004-11-27 23:36:53 +03:00
|
|
|
Bit32u frame_ptr32 = ESP;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-05-08 22:02:21 +04:00
|
|
|
if (BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.d_b) {
|
|
|
|
Bit32u ebp = EBP; // Use temp copy for case of exception.
|
2005-02-17 00:27:21 +03:00
|
|
|
|
2008-05-08 22:02:21 +04:00
|
|
|
if (level > 0) {
|
|
|
|
/* do level-1 times */
|
|
|
|
while (--level) {
|
|
|
|
ebp -= 4;
|
2008-06-12 23:14:40 +04:00
|
|
|
Bit32u temp32 = read_virtual_dword_32(BX_SEG_REG_SS, ebp);
|
2008-05-08 22:02:21 +04:00
|
|
|
push_32(temp32);
|
2005-08-10 22:40:38 +04:00
|
|
|
}
|
2007-11-22 20:33:06 +03:00
|
|
|
|
2008-05-08 22:02:21 +04:00
|
|
|
/* push(frame pointer) */
|
|
|
|
push_32(frame_ptr32);
|
|
|
|
}
|
2007-11-24 17:22:34 +03:00
|
|
|
|
2007-11-22 20:33:06 +03:00
|
|
|
ESP -= imm16;
|
|
|
|
|
2008-05-08 22:02:21 +04:00
|
|
|
// ENTER finishes with memory write check on the final stack pointer
|
|
|
|
// the memory is touched but no write actually occurs
|
|
|
|
// emulate it by doing RMW read access from SS:ESP
|
2009-08-06 18:50:38 +04:00
|
|
|
read_RMW_virtual_dword_32(BX_SEG_REG_SS, ESP);
|
2007-11-22 20:33:06 +03:00
|
|
|
}
|
|
|
|
else {
|
2008-05-08 22:02:21 +04:00
|
|
|
Bit16u bp = BP;
|
|
|
|
|
|
|
|
if (level > 0) {
|
|
|
|
/* do level-1 times */
|
|
|
|
while (--level) {
|
|
|
|
bp -= 4;
|
2008-06-12 23:14:40 +04:00
|
|
|
Bit32u temp32 = read_virtual_dword_32(BX_SEG_REG_SS, bp);
|
2008-05-08 22:02:21 +04:00
|
|
|
push_32(temp32);
|
2007-11-22 20:33:06 +03:00
|
|
|
}
|
2008-05-08 22:02:21 +04:00
|
|
|
|
|
|
|
/* push(frame pointer) */
|
|
|
|
push_32(frame_ptr32);
|
2004-11-27 23:36:53 +03:00
|
|
|
}
|
2007-11-22 20:33:06 +03:00
|
|
|
|
2008-05-08 22:02:21 +04:00
|
|
|
SP -= imm16;
|
|
|
|
|
|
|
|
// ENTER finishes with memory write check on the final stack pointer
|
|
|
|
// the memory is touched but no write actually occurs
|
|
|
|
// emulate it by doing RMW read access from SS:SP
|
2008-06-12 23:14:40 +04:00
|
|
|
read_RMW_virtual_dword_32(BX_SEG_REG_SS, SP);
|
2007-11-22 20:33:06 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-05-08 22:02:21 +04:00
|
|
|
EBP = frame_ptr32;
|
2007-11-24 17:22:34 +03:00
|
|
|
|
2009-03-10 19:28:01 +03:00
|
|
|
RSP_COMMIT;
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2008-08-28 01:57:40 +04:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::LEAVE32(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2008-08-28 01:57:40 +04:00
|
|
|
BX_ASSERT(BX_CPU_THIS_PTR cpu_mode != BX_MODE_LONG_64);
|
2007-11-24 17:22:34 +03:00
|
|
|
|
2008-08-28 01:57:40 +04:00
|
|
|
Bit32u value32;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-08-28 01:57:40 +04:00
|
|
|
if (BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.d_b) {
|
|
|
|
value32 = read_virtual_dword_32(BX_SEG_REG_SS, EBP);
|
|
|
|
ESP = EBP + 4;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
value32 = read_virtual_dword_32(BX_SEG_REG_SS, BP);
|
|
|
|
SP = BP + 4;
|
|
|
|
}
|
2007-11-24 17:22:34 +03:00
|
|
|
|
2008-08-28 01:57:40 +04:00
|
|
|
EBP = value32;
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|