2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2011-02-25 00:54:04 +03:00
|
|
|
// $Id$
|
2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2011-07-07 00:01:18 +04:00
|
|
|
// Copyright (C) 2001-2011 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
|
|
|
|
2011-07-07 00:01:18 +04:00
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::PUSH_RX(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2010-12-07 00:45:56 +03:00
|
|
|
push_16(BX_READ_16BIT_REG(i->rm()));
|
2011-07-07 00:01:18 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2012-02-03 14:24:59 +04:00
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::PUSH16_Sw(bxInstruction_c *i)
|
2005-07-31 21:57:27 +04:00
|
|
|
{
|
2012-02-03 14:24:59 +04:00
|
|
|
push_16(BX_CPU_THIS_PTR sregs[i->nnn()].selector.value);
|
2011-07-07 00:01:18 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
2005-07-31 21:57:27 +04:00
|
|
|
}
|
|
|
|
|
2012-02-03 14:24:59 +04:00
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::POP16_Sw(bxInstruction_c *i)
|
2005-07-31 21:57:27 +04:00
|
|
|
{
|
2009-03-10 19:28:01 +03:00
|
|
|
RSP_SPECULATIVE;
|
2007-11-24 17:22:34 +03:00
|
|
|
|
2012-02-03 14:24:59 +04:00
|
|
|
Bit16u selector = pop_16();
|
|
|
|
load_seg_reg(&BX_CPU_THIS_PTR sregs[i->nnn()], selector);
|
2007-11-24 17:22:34 +03:00
|
|
|
|
2009-03-10 19:28:01 +03:00
|
|
|
RSP_COMMIT;
|
2011-07-07 00:01:18 +04:00
|
|
|
|
2012-02-03 14:24:59 +04:00
|
|
|
if (i->nnn() == BX_SEG_REG_SS) {
|
|
|
|
// 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()
|
|
|
|
inhibit_interrupts(BX_INHIBIT_INTERRUPTS_BY_MOVSS);
|
|
|
|
}
|
2011-07-07 00:01:18 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
2005-07-31 21:57:27 +04:00
|
|
|
}
|
|
|
|
|
2011-07-07 00:01:18 +04:00
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::POP_RX(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2010-12-07 00:45:56 +03:00
|
|
|
BX_WRITE_16BIT_REG(i->rm(), pop_16());
|
2011-07-07 00:01:18 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2011-07-07 00:01:18 +04:00
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::POP_EwM(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
|
|
|
Bit16u val16 = pop_16();
|
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
|
|
|
|
// SP in the modrm addressing. If used, the value of SP after the
|
2007-11-20 20:15:33 +03:00
|
|
|
// pop is used to calculate the address.
|
2008-08-08 13:22:49 +04:00
|
|
|
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
|
2008-04-03 21:56:59 +04:00
|
|
|
|
2008-08-08 13:22:49 +04:00
|
|
|
write_virtual_word(i->seg(), eaddr, val16);
|
2007-11-24 17:22:34 +03:00
|
|
|
|
2009-03-10 19:28:01 +03:00
|
|
|
RSP_COMMIT;
|
2011-07-07 00:01:18 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
2007-11-18 21:49:19 +03:00
|
|
|
}
|
|
|
|
|
2011-07-07 00:01:18 +04:00
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::PUSH_Iw(bxInstruction_c *i)
|
2007-11-18 21:52:44 +03:00
|
|
|
{
|
|
|
|
push_16(i->Iw());
|
2011-07-07 00:01:18 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
2007-11-18 21:52:44 +03:00
|
|
|
}
|
|
|
|
|
2011-07-07 00:01:18 +04:00
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::PUSH_EwM(bxInstruction_c *i)
|
2007-11-18 21:52:44 +03:00
|
|
|
{
|
2008-08-08 13:22:49 +04:00
|
|
|
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
|
2008-01-10 22:37:56 +03:00
|
|
|
|
2008-08-08 13:22:49 +04:00
|
|
|
Bit16u op1_16 = read_virtual_word(i->seg(), eaddr);
|
2007-11-18 21:52:44 +03:00
|
|
|
|
|
|
|
push_16(op1_16);
|
2011-07-07 00:01:18 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
2007-11-18 21:52:44 +03:00
|
|
|
}
|
|
|
|
|
2011-07-07 00:01:18 +04:00
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::PUSHAD16(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_word_32(BX_SEG_REG_SS, (Bit32u)(temp_ESP - 2), AX);
|
|
|
|
write_virtual_word_32(BX_SEG_REG_SS, (Bit32u)(temp_ESP - 4), CX);
|
|
|
|
write_virtual_word_32(BX_SEG_REG_SS, (Bit32u)(temp_ESP - 6), DX);
|
|
|
|
write_virtual_word_32(BX_SEG_REG_SS, (Bit32u)(temp_ESP - 8), BX);
|
|
|
|
write_virtual_word_32(BX_SEG_REG_SS, (Bit32u)(temp_ESP - 10), temp_SP);
|
|
|
|
write_virtual_word_32(BX_SEG_REG_SS, (Bit32u)(temp_ESP - 12), BP);
|
|
|
|
write_virtual_word_32(BX_SEG_REG_SS, (Bit32u)(temp_ESP - 14), SI);
|
|
|
|
write_virtual_word_32(BX_SEG_REG_SS, (Bit32u)(temp_ESP - 16), DI);
|
2007-03-03 00:03:25 +03:00
|
|
|
ESP -= 16;
|
2005-05-21 00:06:50 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-06-12 23:14:40 +04:00
|
|
|
write_virtual_word_32(BX_SEG_REG_SS, (Bit16u)(temp_SP - 2), AX);
|
|
|
|
write_virtual_word_32(BX_SEG_REG_SS, (Bit16u)(temp_SP - 4), CX);
|
|
|
|
write_virtual_word_32(BX_SEG_REG_SS, (Bit16u)(temp_SP - 6), DX);
|
|
|
|
write_virtual_word_32(BX_SEG_REG_SS, (Bit16u)(temp_SP - 8), BX);
|
|
|
|
write_virtual_word_32(BX_SEG_REG_SS, (Bit16u)(temp_SP - 10), temp_SP);
|
|
|
|
write_virtual_word_32(BX_SEG_REG_SS, (Bit16u)(temp_SP - 12), BP);
|
|
|
|
write_virtual_word_32(BX_SEG_REG_SS, (Bit16u)(temp_SP - 14), SI);
|
|
|
|
write_virtual_word_32(BX_SEG_REG_SS, (Bit16u)(temp_SP - 16), DI);
|
2007-03-03 00:03:25 +03:00
|
|
|
SP -= 16;
|
2005-05-21 00:06:50 +04:00
|
|
|
}
|
2011-07-07 00:01:18 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2011-07-07 00:01:18 +04:00
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::POPAD16(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2011-04-21 17:27:42 +04:00
|
|
|
Bit16u di, si, bp, bx, dx, cx, ax;
|
2005-05-21 00:06:50 +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
|
|
|
di = read_virtual_word_32(BX_SEG_REG_SS, (Bit32u)(temp_ESP + 0));
|
|
|
|
si = read_virtual_word_32(BX_SEG_REG_SS, (Bit32u)(temp_ESP + 2));
|
|
|
|
bp = read_virtual_word_32(BX_SEG_REG_SS, (Bit32u)(temp_ESP + 4));
|
2011-04-21 17:27:42 +04:00
|
|
|
read_virtual_word_32(BX_SEG_REG_SS, (Bit32u)(temp_ESP + 6));
|
2008-06-12 23:14:40 +04:00
|
|
|
bx = read_virtual_word_32(BX_SEG_REG_SS, (Bit32u)(temp_ESP + 8));
|
|
|
|
dx = read_virtual_word_32(BX_SEG_REG_SS, (Bit32u)(temp_ESP + 10));
|
|
|
|
cx = read_virtual_word_32(BX_SEG_REG_SS, (Bit32u)(temp_ESP + 12));
|
|
|
|
ax = read_virtual_word_32(BX_SEG_REG_SS, (Bit32u)(temp_ESP + 14));
|
2007-03-03 00:03:25 +03:00
|
|
|
ESP += 16;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Bit16u temp_SP = SP;
|
2008-06-12 23:14:40 +04:00
|
|
|
di = read_virtual_word_32(BX_SEG_REG_SS, (Bit16u)(temp_SP + 0));
|
|
|
|
si = read_virtual_word_32(BX_SEG_REG_SS, (Bit16u)(temp_SP + 2));
|
|
|
|
bp = read_virtual_word_32(BX_SEG_REG_SS, (Bit16u)(temp_SP + 4));
|
2011-04-21 17:27:42 +04:00
|
|
|
read_virtual_word_32(BX_SEG_REG_SS, (Bit16u)(temp_SP + 6));
|
2008-06-12 23:14:40 +04:00
|
|
|
bx = read_virtual_word_32(BX_SEG_REG_SS, (Bit16u)(temp_SP + 8));
|
|
|
|
dx = read_virtual_word_32(BX_SEG_REG_SS, (Bit16u)(temp_SP + 10));
|
|
|
|
cx = read_virtual_word_32(BX_SEG_REG_SS, (Bit16u)(temp_SP + 12));
|
|
|
|
ax = read_virtual_word_32(BX_SEG_REG_SS, (Bit16u)(temp_SP + 14));
|
2007-03-03 00:03:25 +03:00
|
|
|
SP += 16;
|
2005-05-21 00:06:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DI = di;
|
|
|
|
SI = si;
|
|
|
|
BP = bp;
|
|
|
|
BX = bx;
|
|
|
|
DX = dx;
|
|
|
|
CX = cx;
|
|
|
|
AX = ax;
|
2011-07-07 00:01:18 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2008-05-08 22:02:21 +04:00
|
|
|
|
2011-07-07 00:01:18 +04:00
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::ENTER16_IwIb(bxInstruction_c *i)
|
2008-05-08 22:02:21 +04:00
|
|
|
{
|
|
|
|
Bit16u imm16 = i->Iw();
|
|
|
|
Bit8u level = i->Ib2();
|
|
|
|
level &= 0x1F;
|
|
|
|
|
2009-03-10 19:28:01 +03:00
|
|
|
RSP_SPECULATIVE;
|
2008-05-08 22:02:21 +04:00
|
|
|
|
|
|
|
push_16(BP);
|
|
|
|
Bit16u frame_ptr16 = SP;
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
if (level > 0) {
|
|
|
|
/* do level-1 times */
|
|
|
|
while (--level) {
|
|
|
|
ebp -= 2;
|
2008-06-12 23:14:40 +04:00
|
|
|
Bit16u temp16 = read_virtual_word_32(BX_SEG_REG_SS, ebp);
|
2008-05-08 22:02:21 +04:00
|
|
|
push_16(temp16);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* push(frame pointer) */
|
|
|
|
push_16(frame_ptr16);
|
|
|
|
}
|
|
|
|
|
|
|
|
ESP -= 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:ESP
|
|
|
|
read_RMW_virtual_word(BX_SEG_REG_SS, ESP);
|
|
|
|
|
|
|
|
BP = frame_ptr16;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Bit16u bp = BP;
|
|
|
|
|
|
|
|
if (level > 0) {
|
|
|
|
/* do level-1 times */
|
|
|
|
while (--level) {
|
|
|
|
bp -= 2;
|
2008-06-12 23:14:40 +04:00
|
|
|
Bit16u temp16 = read_virtual_word_32(BX_SEG_REG_SS, bp);
|
2008-05-08 22:02:21 +04:00
|
|
|
push_16(temp16);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* push(frame pointer) */
|
|
|
|
push_16(frame_ptr16);
|
|
|
|
}
|
|
|
|
|
|
|
|
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_word_32(BX_SEG_REG_SS, SP);
|
2008-05-08 22:02:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BP = frame_ptr16;
|
|
|
|
|
2009-03-10 19:28:01 +03:00
|
|
|
RSP_COMMIT;
|
2011-07-07 00:01:18 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
2008-05-08 22:02:21 +04:00
|
|
|
}
|
2008-08-28 01:57:40 +04:00
|
|
|
|
2011-07-07 00:01:18 +04:00
|
|
|
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::LEAVE16(bxInstruction_c *i)
|
2008-08-28 01:57:40 +04:00
|
|
|
{
|
|
|
|
BX_ASSERT(BX_CPU_THIS_PTR cpu_mode != BX_MODE_LONG_64);
|
|
|
|
|
|
|
|
Bit16u value16;
|
|
|
|
|
|
|
|
if (BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.d_b) {
|
|
|
|
value16 = read_virtual_word_32(BX_SEG_REG_SS, EBP);
|
|
|
|
ESP = EBP + 2;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
value16 = read_virtual_word_32(BX_SEG_REG_SS, BP);
|
|
|
|
SP = BP + 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
BP = value16;
|
2011-07-07 00:01:18 +04:00
|
|
|
|
|
|
|
BX_NEXT_INSTR(i);
|
2008-08-28 01:57:40 +04:00
|
|
|
}
|