2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2009-12-04 19:53:12 +03:00
|
|
|
// $Id: segment_ctrl.cc,v 1.24 2009-12-04 16:53:12 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
|
2005-03-19 23:44:01 +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
|
|
|
|
2009-10-15 00:45:29 +04:00
|
|
|
// LES/LDS can't be called from long64 mode
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::LES_GwMp(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2009-10-15 00:45:29 +04:00
|
|
|
BX_ASSERT(BX_CPU_THIS_PTR cpu_mode != BX_MODE_LONG_64);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2009-10-15 00:45:29 +04:00
|
|
|
Bit32u eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
|
2008-01-10 22:37:56 +03:00
|
|
|
|
2009-10-15 00:45:29 +04:00
|
|
|
Bit16u reg_16 = read_virtual_word_32(i->seg(), eaddr);
|
|
|
|
Bit16u es = read_virtual_word_32(i->seg(), eaddr + 2);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2007-04-10 00:28:15 +04:00
|
|
|
load_seg_reg(&BX_CPU_THIS_PTR sregs[BX_SEG_REG_ES], es);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2007-04-10 00:28:15 +04:00
|
|
|
BX_WRITE_16BIT_REG(i->nnn(), reg_16);
|
|
|
|
}
|
|
|
|
|
2009-10-15 00:45:29 +04:00
|
|
|
// LES/LDS can't be called from long64 mode
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::LES_GdMp(bxInstruction_c *i)
|
2007-04-10 00:28:15 +04:00
|
|
|
{
|
2009-10-15 00:45:29 +04:00
|
|
|
BX_ASSERT(BX_CPU_THIS_PTR cpu_mode != BX_MODE_LONG_64);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2009-10-15 00:45:29 +04:00
|
|
|
Bit32u eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
|
2008-01-10 22:37:56 +03:00
|
|
|
|
2009-10-15 00:45:29 +04:00
|
|
|
Bit16u es = read_virtual_word_32(i->seg(), eaddr + 4);
|
|
|
|
Bit32u reg_32 = read_virtual_dword_32(i->seg(), eaddr);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2007-04-10 00:28:15 +04:00
|
|
|
load_seg_reg(&BX_CPU_THIS_PTR sregs[BX_SEG_REG_ES], es);
|
|
|
|
|
|
|
|
BX_WRITE_32BIT_REGZ(i->nnn(), reg_32);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2009-10-15 00:45:29 +04:00
|
|
|
// LES/LDS can't be called from long64 mode
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::LDS_GwMp(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2009-10-15 00:45:29 +04:00
|
|
|
BX_ASSERT(BX_CPU_THIS_PTR cpu_mode != BX_MODE_LONG_64);
|
2007-04-10 00:28:15 +04:00
|
|
|
|
2009-10-15 00:45:29 +04:00
|
|
|
Bit32u eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
|
2008-01-10 22:37:56 +03:00
|
|
|
|
2009-10-15 00:45:29 +04:00
|
|
|
Bit16u reg_16 = read_virtual_word_32(i->seg(), eaddr);
|
|
|
|
Bit16u ds = read_virtual_word_32(i->seg(), eaddr + 2);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2007-04-10 00:28:15 +04:00
|
|
|
load_seg_reg(&BX_CPU_THIS_PTR sregs[BX_SEG_REG_DS], ds);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2007-04-10 00:28:15 +04:00
|
|
|
BX_WRITE_16BIT_REG(i->nnn(), reg_16);
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2009-10-15 00:45:29 +04:00
|
|
|
// LES/LDS can't be called from long64 mode
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::LDS_GdMp(bxInstruction_c *i)
|
2007-04-10 00:28:15 +04:00
|
|
|
{
|
2009-10-15 00:45:29 +04:00
|
|
|
BX_ASSERT(BX_CPU_THIS_PTR cpu_mode != BX_MODE_LONG_64);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2009-10-15 00:45:29 +04:00
|
|
|
Bit32u eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
|
2008-01-10 22:37:56 +03:00
|
|
|
|
2009-10-15 00:45:29 +04:00
|
|
|
Bit16u ds = read_virtual_word_32(i->seg(), eaddr + 4);
|
|
|
|
Bit32u reg_32 = read_virtual_dword_32(i->seg(), eaddr);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2007-04-10 00:28:15 +04:00
|
|
|
load_seg_reg(&BX_CPU_THIS_PTR sregs[BX_SEG_REG_DS], ds);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2007-04-10 00:28:15 +04:00
|
|
|
BX_WRITE_32BIT_REGZ(i->nnn(), reg_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::LFS_GwMp(bxInstruction_c *i)
|
2005-03-19 23:44:01 +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
|
|
|
|
2009-10-15 00:45:29 +04:00
|
|
|
Bit16u reg_16 = read_virtual_word(i->seg(), eaddr);
|
|
|
|
Bit16u fs = read_virtual_word(i->seg(), eaddr + 2);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2007-04-10 00:28:15 +04:00
|
|
|
load_seg_reg(&BX_CPU_THIS_PTR sregs[BX_SEG_REG_FS], fs);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2007-04-10 00:28:15 +04:00
|
|
|
BX_WRITE_16BIT_REG(i->nnn(), reg_16);
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::LFS_GdMp(bxInstruction_c *i)
|
2007-04-10 00:28:15 +04: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
|
|
|
|
2009-10-15 00:45:29 +04:00
|
|
|
Bit16u fs = read_virtual_word(i->seg(), eaddr + 4);
|
|
|
|
Bit32u reg_32 = read_virtual_dword(i->seg(), eaddr);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2007-04-10 00:28:15 +04:00
|
|
|
load_seg_reg(&BX_CPU_THIS_PTR sregs[BX_SEG_REG_FS], fs);
|
|
|
|
|
|
|
|
BX_WRITE_32BIT_REGZ(i->nnn(), reg_32);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2007-04-10 00:28:15 +04:00
|
|
|
#if BX_SUPPORT_X86_64
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::LFS_GqMp(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04: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
|
|
|
|
2009-10-15 00:45:29 +04:00
|
|
|
Bit16u fs = read_virtual_word_64(i->seg(), eaddr + 8);
|
|
|
|
Bit64u reg_64 = read_virtual_qword_64(i->seg(), eaddr);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2007-04-10 00:28:15 +04:00
|
|
|
load_seg_reg(&BX_CPU_THIS_PTR sregs[BX_SEG_REG_FS], fs);
|
|
|
|
|
|
|
|
BX_WRITE_64BIT_REG(i->nnn(), reg_64);
|
|
|
|
}
|
|
|
|
#endif
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::LGS_GwMp(bxInstruction_c *i)
|
2007-04-10 00:28:15 +04: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
|
|
|
|
2009-10-15 00:45:29 +04:00
|
|
|
Bit16u reg_16 = read_virtual_word(i->seg(), eaddr);
|
|
|
|
Bit16u gs = read_virtual_word(i->seg(), eaddr + 2);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2007-04-10 00:28:15 +04:00
|
|
|
load_seg_reg(&BX_CPU_THIS_PTR sregs[BX_SEG_REG_GS], gs);
|
|
|
|
|
|
|
|
BX_WRITE_16BIT_REG(i->nnn(), reg_16);
|
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::LGS_GdMp(bxInstruction_c *i)
|
2007-04-10 00:28:15 +04: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
|
|
|
|
2009-10-15 00:45:29 +04:00
|
|
|
Bit16u gs = read_virtual_word(i->seg(), eaddr + 4);
|
|
|
|
Bit32u reg_32 = read_virtual_dword(i->seg(), eaddr);
|
2007-04-10 00:28:15 +04:00
|
|
|
|
|
|
|
load_seg_reg(&BX_CPU_THIS_PTR sregs[BX_SEG_REG_GS], gs);
|
|
|
|
|
|
|
|
BX_WRITE_32BIT_REGZ(i->nnn(), reg_32);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2007-04-10 00:28:15 +04:00
|
|
|
#if BX_SUPPORT_X86_64
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::LGS_GqMp(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04: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
|
|
|
|
2009-10-15 00:45:29 +04:00
|
|
|
Bit16u gs = read_virtual_word_64(i->seg(), eaddr + 8);
|
|
|
|
Bit64u reg_64 = read_virtual_qword_64(i->seg(), eaddr);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2007-04-10 00:28:15 +04:00
|
|
|
load_seg_reg(&BX_CPU_THIS_PTR sregs[BX_SEG_REG_GS], gs);
|
|
|
|
|
|
|
|
BX_WRITE_64BIT_REG(i->nnn(), reg_64);
|
|
|
|
}
|
|
|
|
#endif
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::LSS_GwMp(bxInstruction_c *i)
|
2007-04-10 00:28:15 +04: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
|
|
|
|
2009-10-15 00:45:29 +04:00
|
|
|
Bit16u reg_16 = read_virtual_word(i->seg(), eaddr);
|
|
|
|
Bit16u ss = read_virtual_word(i->seg(), eaddr + 2);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2007-04-10 00:28:15 +04:00
|
|
|
load_seg_reg(&BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS], ss);
|
|
|
|
|
|
|
|
BX_WRITE_16BIT_REG(i->nnn(), reg_16);
|
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::LSS_GdMp(bxInstruction_c *i)
|
2007-04-10 00:28:15 +04: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
|
|
|
|
2009-10-15 00:45:29 +04:00
|
|
|
Bit16u ss = read_virtual_word(i->seg(), eaddr + 4);
|
|
|
|
Bit32u reg_32 = read_virtual_dword(i->seg(), eaddr);
|
2007-04-10 00:28:15 +04:00
|
|
|
|
|
|
|
load_seg_reg(&BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS], ss);
|
|
|
|
|
|
|
|
BX_WRITE_32BIT_REGZ(i->nnn(), reg_32);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2005-03-19 23:44:01 +03:00
|
|
|
|
2007-04-10 00:28:15 +04:00
|
|
|
#if BX_SUPPORT_X86_64
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::LSS_GqMp(bxInstruction_c *i)
|
2007-04-10 00:28:15 +04: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
|
|
|
|
2009-10-15 00:45:29 +04:00
|
|
|
Bit16u ss = read_virtual_word_64(i->seg(), eaddr + 8);
|
|
|
|
Bit64u reg_64 = read_virtual_qword_64(i->seg(), eaddr);
|
2007-04-10 00:28:15 +04:00
|
|
|
|
|
|
|
load_seg_reg(&BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS], ss);
|
|
|
|
|
|
|
|
BX_WRITE_64BIT_REG(i->nnn(), reg_64);
|
|
|
|
}
|
2005-03-19 23:44:01 +03:00
|
|
|
#endif
|