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
|
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
|
|
|
|
2012-10-04 00:24:29 +04:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::setEFlags(Bit32u new_eflags)
|
2005-09-29 21:32:32 +04:00
|
|
|
{
|
2012-10-04 00:24:29 +04:00
|
|
|
Bit32u eflags = BX_CPU_THIS_PTR eflags;
|
|
|
|
|
2005-09-29 21:32:32 +04:00
|
|
|
// 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 !"));
|
2012-10-04 00:24:29 +04:00
|
|
|
new_eflags &= ~EFlagsVMMask;
|
2005-09-29 21:32:32 +04:00
|
|
|
}
|
2005-11-22 00:10:59 +03:00
|
|
|
#endif
|
|
|
|
|
2012-10-04 00:24:29 +04:00
|
|
|
BX_CPU_THIS_PTR eflags = new_eflags;
|
|
|
|
setEFlagsOSZAPC(new_eflags); // update lazy flags state
|
|
|
|
|
|
|
|
if (BX_CPU_THIS_PTR get_RF()) invalidate_prefetch_q();
|
2011-06-24 17:38:34 +04:00
|
|
|
|
2012-10-04 00:24:29 +04:00
|
|
|
if (BX_CPU_THIS_PTR get_TF()) {
|
2012-09-25 13:35:38 +04:00
|
|
|
BX_CPU_THIS_PTR async_event = 1; // TF == 1
|
2008-08-12 23:25:42 +04:00
|
|
|
}
|
|
|
|
|
2012-10-04 00:24:29 +04:00
|
|
|
if ((eflags ^ new_eflags) & EFlagsIFMask) {
|
|
|
|
handleInterruptMaskChange();
|
2008-08-12 23:25:42 +04:00
|
|
|
}
|
|
|
|
|
2012-03-25 23:07:17 +04:00
|
|
|
#if BX_CPU_LEVEL >= 4
|
2010-04-22 21:51:37 +04:00
|
|
|
handleAlignmentCheck(/* EFLAGS.AC reloaded */);
|
2007-08-01 00:25:52 +04:00
|
|
|
#endif
|
|
|
|
|
2012-10-04 00:24:29 +04:00
|
|
|
if ((eflags ^ new_eflags) & EFlagsVMMask) {
|
|
|
|
handleCpuModeChange(); // VM flag was 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;
|
|
|
|
|
2012-01-10 00:52:15 +04:00
|
|
|
Bit32u newEFlags = (read_eflags() & ~changeMask) | (flags & changeMask);
|
2006-04-05 21:31:35 +04:00
|
|
|
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)
|
2021-01-30 11:35:35 +03:00
|
|
|
BX_CPU_C::write_flags(Bit16u flags, bool change_IOPL, 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
|
|
|
{
|
2011-09-12 23:36:53 +04:00
|
|
|
Bit32u newflags = getB_CF();
|
|
|
|
newflags |= getB_PF() << 2;
|
|
|
|
newflags |= getB_AF() << 4;
|
|
|
|
newflags |= getB_ZF() << 6;
|
|
|
|
newflags |= getB_SF() << 7;
|
|
|
|
newflags |= getB_OF() << 11;
|
|
|
|
|
|
|
|
BX_CPU_THIS_PTR eflags = (BX_CPU_THIS_PTR eflags & ~EFlagsOSZAPCMask)
|
|
|
|
| (newflags & EFlagsOSZAPCMask);
|
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
|
|
|
}
|
2012-10-04 00:24:29 +04:00
|
|
|
|
|
|
|
void BX_CPU_C::handleInterruptMaskChange(void)
|
|
|
|
{
|
|
|
|
if (BX_CPU_THIS_PTR get_IF()) {
|
|
|
|
// EFLAGS.IF was set, unmask all affected events
|
|
|
|
unmask_event(BX_EVENT_VMX_INTERRUPT_WINDOW_EXITING |
|
|
|
|
BX_EVENT_PENDING_INTR |
|
|
|
|
BX_EVENT_PENDING_LAPIC_INTR |
|
|
|
|
BX_EVENT_PENDING_VMX_VIRTUAL_INTR);
|
|
|
|
|
|
|
|
#if BX_SUPPORT_SVM
|
|
|
|
if (BX_CPU_THIS_PTR in_svm_guest) {
|
|
|
|
if ((SVM_V_INTR_PRIO > SVM_V_TPR) || SVM_V_IGNORE_TPR)
|
|
|
|
unmask_event(BX_EVENT_SVM_VIRQ_PENDING);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// EFLAGS.IF was cleared, some events like INTR would be masked
|
|
|
|
|
|
|
|
#if BX_SUPPORT_VMX
|
|
|
|
if (BX_CPU_THIS_PTR in_vmx_guest && PIN_VMEXIT(VMX_VM_EXEC_CTRL1_EXTERNAL_INTERRUPT_VMEXIT)) {
|
|
|
|
// if 'External-interrupt exiting' control is set, the value of EFLAGS.IF
|
|
|
|
// doesn't affect interrupt blocking
|
|
|
|
mask_event(BX_EVENT_VMX_INTERRUPT_WINDOW_EXITING | BX_EVENT_PENDING_VMX_VIRTUAL_INTR);
|
2014-07-08 23:15:54 +04:00
|
|
|
unmask_event(BX_EVENT_PENDING_INTR | BX_EVENT_PENDING_LAPIC_INTR);
|
2012-10-04 00:24:29 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if BX_SUPPORT_SVM
|
|
|
|
if (BX_CPU_THIS_PTR in_svm_guest && SVM_V_INTR_MASKING) {
|
|
|
|
if (! SVM_HOST_IF)
|
|
|
|
mask_event(BX_EVENT_PENDING_INTR | BX_EVENT_PENDING_LAPIC_INTR);
|
|
|
|
|
|
|
|
mask_event(BX_EVENT_SVM_VIRQ_PENDING);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
mask_event(BX_EVENT_VMX_INTERRUPT_WINDOW_EXITING |
|
|
|
|
BX_EVENT_PENDING_INTR |
|
|
|
|
BX_EVENT_PENDING_LAPIC_INTR |
|
|
|
|
BX_EVENT_PENDING_VMX_VIRTUAL_INTR |
|
|
|
|
BX_EVENT_SVM_VIRQ_PENDING);
|
|
|
|
}
|
|
|
|
}
|