2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2009-12-04 19:53:12 +03:00
|
|
|
// $Id: flag_ctrl_pro.cc,v 1.39 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
|
2008-01-29 20:13:10 +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
|
|
|
|
2005-09-29 21:32:32 +04:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::setEFlags(Bit32u val)
|
|
|
|
{
|
|
|
|
// VM flag could not be set from long mode
|
2005-11-22 00:10:59 +03:00
|
|
|
#if BX_SUPPORT_X86_64
|
2006-10-04 23:08:40 +04:00
|
|
|
if (long_mode()) {
|
2006-04-05 21:31:35 +04:00
|
|
|
if (BX_CPU_THIS_PTR get_VM()) BX_PANIC(("VM is set in long mode !"));
|
2005-09-29 21:32:32 +04:00
|
|
|
val &= ~EFlagsVMMask;
|
|
|
|
}
|
2005-11-22 00:10:59 +03:00
|
|
|
#endif
|
|
|
|
|
2009-02-13 23:09:56 +03:00
|
|
|
if (val & (EFlagsTFMask|EFlagsRFMask)) {
|
|
|
|
BX_CPU_THIS_PTR async_event = 1; // TF == 1 || RF == 1
|
2008-08-12 23:25:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (val & EFlagsIFMask) {
|
|
|
|
if (! BX_CPU_THIS_PTR get_IF())
|
|
|
|
BX_CPU_THIS_PTR async_event = 1; // IF bit was set
|
|
|
|
}
|
|
|
|
|
2008-04-25 12:19:36 +04:00
|
|
|
BX_CPU_THIS_PTR eflags = val;
|
|
|
|
BX_CPU_THIS_PTR lf_flags_status = 0; // OSZAPC flags are known.
|
|
|
|
|
2007-08-01 00:25:52 +04:00
|
|
|
#if BX_CPU_LEVEL >= 4 && BX_SUPPORT_ALIGNMENT_CHECK
|
2007-11-21 00:22:03 +03:00
|
|
|
handleAlignmentCheck();
|
2007-08-01 00:25:52 +04:00
|
|
|
#endif
|
|
|
|
|
2008-01-22 19:20:30 +03:00
|
|
|
handleCpuModeChange(); // VM flag might be changed
|
2005-09-29 21:32:32 +04:00
|
|
|
}
|
|
|
|
|
2003-03-03 02:59:12 +03:00
|
|
|
void BX_CPP_AttrRegparmN(2)
|
2002-10-05 10:33:10 +04:00
|
|
|
BX_CPU_C::writeEFlags(Bit32u flags, Bit32u changeMask)
|
|
|
|
{
|
|
|
|
// Build a mask of the non-reserved bits:
|
2005-10-17 03:13:19 +04:00
|
|
|
// ID,VIP,VIF,AC,VM,RF,x,NT,IOPL,OF,DF,IF,TF,SF,ZF,x,AF,x,PF,x,CF
|
2007-09-20 21:33:35 +04:00
|
|
|
Bit32u supportMask = 0x00037fd5;
|
2002-10-05 10:33:10 +04:00
|
|
|
#if BX_CPU_LEVEL >= 4
|
2005-10-17 03:13:19 +04:00
|
|
|
supportMask |= (EFlagsIDMask | EFlagsACMask); // ID/AC
|
|
|
|
#endif
|
2009-08-10 19:44:50 +04:00
|
|
|
#if BX_CPU_LEVEL >= 5
|
2007-09-20 21:33:35 +04:00
|
|
|
supportMask |= (EFlagsVIPMask | EFlagsVIFMask); // VIP/VIF
|
2002-10-05 10:33:10 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Screen out changing of any unsupported bits.
|
|
|
|
changeMask &= supportMask;
|
|
|
|
|
2008-01-30 01:26:29 +03:00
|
|
|
Bit32u newEFlags = (BX_CPU_THIS_PTR eflags & ~changeMask) |
|
2002-10-05 10:33:10 +04:00
|
|
|
(flags & changeMask);
|
2006-04-05 21:31:35 +04:00
|
|
|
setEFlags(newEFlags);
|
2005-09-29 21:32:32 +04:00
|
|
|
// OSZAPC flags are known - done in setEFlags(newEFlags)
|
2002-10-05 10:33:10 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2003-03-03 02:59:12 +03:00
|
|
|
void BX_CPP_AttrRegparmN(3)
|
2002-10-25 15:44:41 +04:00
|
|
|
BX_CPU_C::write_flags(Bit16u flags, bx_bool change_IOPL, bx_bool change_IF)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2005-10-17 03:13:19 +04:00
|
|
|
// Build a mask of the following bits:
|
|
|
|
// x,NT,IOPL,OF,DF,IF,TF,SF,ZF,x,AF,x,PF,x,CF
|
2002-10-05 10:33:10 +04:00
|
|
|
Bit32u changeMask = 0x0dd5;
|
2002-09-08 08:08:14 +04:00
|
|
|
|
|
|
|
#if BX_CPU_LEVEL >= 3
|
2005-10-17 03:13:19 +04:00
|
|
|
changeMask |= EFlagsNTMask; // NT is modified as requested.
|
2001-04-10 05:04:59 +04:00
|
|
|
if (change_IOPL)
|
2005-10-17 03:13:19 +04:00
|
|
|
changeMask |= EFlagsIOPLMask; // IOPL is modified as requested.
|
2001-04-10 05:04:59 +04:00
|
|
|
#endif
|
2002-09-12 22:10:46 +04:00
|
|
|
if (change_IF)
|
2005-10-17 03:13:19 +04:00
|
|
|
changeMask |= EFlagsIFMask;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2002-10-05 10:33:10 +04:00
|
|
|
writeEFlags(Bit32u(flags), changeMask);
|
2002-09-08 08:08:14 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2005-06-16 21:25:04 +04:00
|
|
|
// Cause arithmetic flags to be in known state and cached in val32.
|
|
|
|
Bit32u BX_CPU_C::force_flags(void)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2002-09-08 08:08:14 +04:00
|
|
|
if (BX_CPU_THIS_PTR lf_flags_status) {
|
2007-11-19 22:55:09 +03:00
|
|
|
Bit32u newflags;
|
|
|
|
|
|
|
|
newflags = get_CF() ? EFlagsCFMask : 0;
|
|
|
|
newflags |= get_PF() ? EFlagsPFMask : 0;
|
|
|
|
newflags |= get_AF() ? EFlagsAFMask : 0;
|
|
|
|
newflags |= get_ZF() ? EFlagsZFMask : 0;
|
|
|
|
newflags |= get_SF() ? EFlagsSFMask : 0;
|
|
|
|
newflags |= get_OF() ? EFlagsOFMask : 0;
|
|
|
|
|
|
|
|
setEFlagsOSZAPC(newflags);
|
2004-09-30 20:50:03 +04:00
|
|
|
}
|
|
|
|
|
2008-01-30 01:26:29 +03:00
|
|
|
return BX_CPU_THIS_PTR eflags;
|
2005-06-16 21:25:04 +04:00
|
|
|
}
|