split crreg access functions to separate file
This commit is contained in:
parent
35f47968d9
commit
f5ce2a7639
@ -88,6 +88,7 @@ OBJS = \
|
||||
exception.o \
|
||||
cpuid.o \
|
||||
proc_ctrl.o \
|
||||
crregs.o \
|
||||
msr.o \
|
||||
smm.o \
|
||||
lazy_flags.o \
|
||||
@ -531,6 +532,13 @@ proc_ctrl.o: proc_ctrl.@CPP_SUFFIX@ ../bochs.h ../config.h ../osdep.h \
|
||||
crregs.h descriptor.h instr.h lazy_flags.h icache.h apic.h \
|
||||
../cpu/i387.h ../fpu/softfloat.h ../config.h ../fpu/tag_w.h \
|
||||
../fpu/status_w.h ../fpu/control_w.h ../cpu/xmm.h vmx.h stack.h ../param_names.h
|
||||
crregs.o: crregs.@CPP_SUFFIX@ ../bochs.h ../config.h ../osdep.h \
|
||||
../bx_debug/debug.h ../config.h ../osdep.h ../bxversion.h \
|
||||
../gui/siminterface.h ../memory/memory.h ../pc_system.h ../plugin.h \
|
||||
../extplugin.h ../gui/gui.h ../instrument/stubs/instrument.h cpu.h \
|
||||
crregs.h descriptor.h instr.h lazy_flags.h icache.h apic.h \
|
||||
../cpu/i387.h ../fpu/softfloat.h ../config.h ../fpu/tag_w.h \
|
||||
../fpu/status_w.h ../fpu/control_w.h ../cpu/xmm.h vmx.h stack.h
|
||||
protect_ctrl.o: protect_ctrl.@CPP_SUFFIX@ ../bochs.h ../config.h ../osdep.h \
|
||||
../bx_debug/debug.h ../config.h ../osdep.h ../bxversion.h \
|
||||
../gui/siminterface.h ../memory/memory.h ../pc_system.h ../plugin.h \
|
||||
|
@ -1,8 +1,8 @@
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// $Id: cpu.h,v 1.657 2010-03-19 10:00:48 sshwarts Exp $
|
||||
// $Id: cpu.h,v 1.658 2010-03-25 21:33:06 sshwarts Exp $
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2001-2009 The Bochs Project
|
||||
// Copyright (C) 2001-2010 The Bochs Project
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
@ -3131,12 +3131,12 @@ public: // for now...
|
||||
BX_SMF bx_bool smram_restore_state(const Bit32u *smm_saved_state);
|
||||
BX_SMF int int_number(unsigned s);
|
||||
BX_SMF bx_bool SetCR0(bx_address val) BX_CPP_AttrRegparmN(1);
|
||||
BX_SMF void SetCR3(bx_address val) BX_CPP_AttrRegparmN(1);
|
||||
BX_SMF bx_bool check_CR0(bx_address val) BX_CPP_AttrRegparmN(1);
|
||||
BX_SMF bx_bool SetCR3(bx_address val) BX_CPP_AttrRegparmN(1);
|
||||
#if BX_CPU_LEVEL >= 4
|
||||
BX_SMF bx_bool SetCR4(bx_address val) BX_CPP_AttrRegparmN(1);
|
||||
BX_SMF bx_bool check_CR4(bx_address val) BX_CPP_AttrRegparmN(1);
|
||||
#endif
|
||||
BX_SMF void pagingCR0Changed(Bit32u oldCR0, Bit32u newCR0) BX_CPP_AttrRegparmN(2);
|
||||
BX_SMF void pagingCR4Changed(Bit32u oldCR4, Bit32u newCR4) BX_CPP_AttrRegparmN(2);
|
||||
#if BX_CPU_LEVEL >= 6
|
||||
BX_SMF bx_bool CheckPDPTR(Bit32u cr3_val) BX_CPP_AttrRegparmN(1);
|
||||
#endif
|
||||
|
@ -1,8 +1,8 @@
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// $Id: cpuid.cc,v 1.106 2010-03-21 20:52:36 sshwarts Exp $
|
||||
// $Id: cpuid.cc,v 1.107 2010-03-25 21:33:07 sshwarts Exp $
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2007-2009 Stanislav Shwartsman
|
||||
// Copyright (c) 2007-2010 Stanislav Shwartsman
|
||||
// Written by Stanislav Shwartsman [sshwarts at sourceforge net]
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
|
1167
bochs/cpu/crregs.cc
Executable file
1167
bochs/cpu/crregs.cc
Executable file
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,5 @@
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// $Id: crregs.h,v 1.22 2010-02-26 22:53:43 sshwarts Exp $
|
||||
// $Id: crregs.h,v 1.23 2010-03-25 21:33:07 sshwarts Exp $
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2007-2009 Stanislav Shwartsman
|
||||
@ -64,8 +64,8 @@ struct bx_cr0_t {
|
||||
IMPLEMENT_CRREG_ACCESSORS(NE, 5);
|
||||
IMPLEMENT_CRREG_ACCESSORS(WP, 16);
|
||||
IMPLEMENT_CRREG_ACCESSORS(AM, 18);
|
||||
IMPLEMENT_CRREG_ACCESSORS(CD, 29);
|
||||
IMPLEMENT_CRREG_ACCESSORS(NW, 30);
|
||||
IMPLEMENT_CRREG_ACCESSORS(NW, 29);
|
||||
IMPLEMENT_CRREG_ACCESSORS(CD, 30);
|
||||
#endif
|
||||
IMPLEMENT_CRREG_ACCESSORS(PG, 31);
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// $Id: exception.cc,v 1.155 2010-03-20 13:58:02 sshwarts Exp $
|
||||
// $Id: exception.cc,v 1.156 2010-03-25 21:33:07 sshwarts Exp $
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2001-2009 The Bochs Project
|
||||
// Copyright (C) 2001-2010 The Bochs Project
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -1,5 +1,5 @@
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// $Id: init.cc,v 1.232 2010-03-16 14:51:20 sshwarts Exp $
|
||||
// $Id: init.cc,v 1.233 2010-03-25 21:33:07 sshwarts Exp $
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2001-2009 The Bochs Project
|
||||
@ -686,7 +686,8 @@ void BX_CPU_C::after_restore_state(void)
|
||||
|
||||
if (!SetCR0(cr0.val32))
|
||||
BX_PANIC(("Incorrect CR0 state !"));
|
||||
SetCR3(cr3);
|
||||
if (!SetCR3(cr3))
|
||||
BX_PANIC(("Incorrect CR3 value !"));
|
||||
TLB_flush();
|
||||
#if BX_SUPPORT_VMX
|
||||
set_VMCSPTR(BX_CPU_THIS_PTR vmcsptr);
|
||||
@ -1179,13 +1180,12 @@ void BX_CPU_C::assert_checks(void)
|
||||
}
|
||||
|
||||
// check CR0 consistency
|
||||
if (BX_CPU_THIS_PTR cr0.get_PG() && ! BX_CPU_THIS_PTR cr0.get_PE())
|
||||
BX_PANIC(("assert_checks: CR0.PG=1 with CR0.PE=0 !"));
|
||||
#if BX_CPU_LEVEL >= 4
|
||||
if (BX_CPU_THIS_PTR cr0.get_NW() && ! BX_CPU_THIS_PTR cr0.get_CD())
|
||||
BX_PANIC(("assert_checks: CR0.NW=1 with CR0.CD=0 !"));
|
||||
#endif
|
||||
if (! check_CR0(BX_CPU_THIS_PTR cr0.val32))
|
||||
BX_PANIC(("assert_checks: CR0 consistency checks failed !"));
|
||||
|
||||
// check CR4 consistency
|
||||
if (! check_CR4(BX_CPU_THIS_PTR cr4.val32))
|
||||
BX_PANIC(("assert_checks: CR4 consistency checks failed !"));
|
||||
|
||||
#if BX_SUPPORT_X86_64
|
||||
// VM should be OFF in long mode
|
||||
|
@ -1,8 +1,8 @@
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// $Id: paging.cc,v 1.195 2010-03-23 19:58:20 sshwarts Exp $
|
||||
// $Id: paging.cc,v 1.196 2010-03-25 21:33:07 sshwarts Exp $
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2001-2009 The Bochs Project
|
||||
// Copyright (C) 2001-2010 The Bochs Project
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
@ -517,65 +517,6 @@ static unsigned tlbNonGlobalFlushes=0;
|
||||
|
||||
// ==============================================================
|
||||
|
||||
void BX_CPP_AttrRegparmN(2)
|
||||
BX_CPU_C::pagingCR0Changed(Bit32u oldCR0, Bit32u newCR0)
|
||||
{
|
||||
// Modification of PG,PE flushes TLB cache according to docs.
|
||||
// Additionally, the TLB strategy is based on the current value of
|
||||
// WP, so if that changes we must also flush the TLB.
|
||||
if ((oldCR0 & 0x80010001) != (newCR0 & 0x80010001))
|
||||
TLB_flush(); // Flush Global entries also.
|
||||
}
|
||||
|
||||
void BX_CPP_AttrRegparmN(2)
|
||||
BX_CPU_C::pagingCR4Changed(Bit32u oldCR4, Bit32u newCR4)
|
||||
{
|
||||
// Modification of PGE,PAE,PSE flushes TLB cache according to docs.
|
||||
if ((oldCR4 & 0x000000b0) != (newCR4 & 0x000000b0))
|
||||
TLB_flush(); // Flush Global entries also.
|
||||
|
||||
#if BX_CPU_LEVEL >= 6
|
||||
if ((oldCR4 & 0x00000020) != (newCR4 & 0x00000020)) {
|
||||
if (BX_CPU_THIS_PTR cr4.get_PAE() && !long_mode())
|
||||
BX_CPU_THIS_PTR cr3_masked = BX_CPU_THIS_PTR cr3 & 0xffffffe0;
|
||||
else
|
||||
BX_CPU_THIS_PTR cr3_masked = BX_CPU_THIS_PTR cr3 & BX_CONST64(0x000ffffffffff000);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void BX_CPP_AttrRegparmN(1) BX_CPU_C::SetCR3(bx_address val)
|
||||
{
|
||||
// flush TLB even if value does not change
|
||||
#if BX_CPU_LEVEL >= 6
|
||||
if (BX_CPU_THIS_PTR cr4.get_PGE())
|
||||
TLB_flushNonGlobal(); // Don't flush Global entries.
|
||||
else
|
||||
#endif
|
||||
TLB_flush(); // Flush Global entries also.
|
||||
|
||||
#if BX_CPU_LEVEL >= 6
|
||||
if (BX_CPU_THIS_PTR cr4.get_PAE()) {
|
||||
#if BX_SUPPORT_X86_64
|
||||
if (long_mode()) {
|
||||
if (! IsValidPhyAddr(val)) {
|
||||
BX_ERROR(("SetCR3(): Attempt to write to reserved bits of CR3"));
|
||||
exception(BX_GP_EXCEPTION, 0);
|
||||
}
|
||||
|
||||
BX_CPU_THIS_PTR cr3_masked = val & BX_CONST64(0x000ffffffffff000);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
BX_CPU_THIS_PTR cr3_masked = val & 0xffffffe0;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
BX_CPU_THIS_PTR cr3_masked = val & 0xfffff000;
|
||||
|
||||
BX_CPU_THIS_PTR cr3 = val;
|
||||
}
|
||||
|
||||
#if BX_CPU_LEVEL >= 6
|
||||
|
||||
bx_bool BX_CPP_AttrRegparmN(1) BX_CPU_C::CheckPDPTR(Bit32u cr3_val)
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,5 @@
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// $Id: smm.cc,v 1.65 2010-03-16 14:51:20 sshwarts Exp $
|
||||
// $Id: smm.cc,v 1.66 2010-03-25 21:33:07 sshwarts Exp $
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2006-2009 Stanislav Shwartsman
|
||||
@ -178,13 +178,13 @@ void BX_CPU_C::enter_system_management_mode(void)
|
||||
BX_CPU_THIS_PTR cr0.set_TS(0); // no task switch (bit 3)
|
||||
BX_CPU_THIS_PTR cr0.set_PG(0); // paging disabled (bit 31)
|
||||
|
||||
// paging mode was changed - flush TLB
|
||||
TLB_flush(); // Flush Global entries also
|
||||
|
||||
#if BX_CPU_LEVEL >= 4
|
||||
BX_CPU_THIS_PTR cr4.set32(0);
|
||||
#endif
|
||||
|
||||
// paging mode was changed - flush TLB
|
||||
TLB_flush(); // Flush Global entries also
|
||||
|
||||
#if BX_SUPPORT_X86_64
|
||||
BX_CPU_THIS_PTR efer.set32(0);
|
||||
#endif
|
||||
@ -600,7 +600,10 @@ bx_bool BX_CPU_C::smram_restore_state(const Bit32u *saved_state)
|
||||
setEFlags(temp_eflags);
|
||||
|
||||
bx_phy_address temp_cr3 = (bx_phy_address) SMRAM_FIELD64(saved_state, SMRAM_FIELD_CR3_HI32, SMRAM_FIELD_CR3);
|
||||
SetCR3(temp_cr3);
|
||||
if (!SetCR3(temp_cr3)) {
|
||||
BX_PANIC(("SMM restore: failed to restore CR3 !"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (int n=0; n<BX_GENERAL_REGISTERS; n++) {
|
||||
Bit64u val_64 = SMRAM_FIELD64(saved_state,
|
||||
|
@ -1,8 +1,8 @@
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// $Id: tasking.cc,v 1.86 2010-03-18 15:19:16 sshwarts Exp $
|
||||
// $Id: tasking.cc,v 1.87 2010-03-25 21:33:07 sshwarts Exp $
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2001-2009 The Bochs Project
|
||||
// Copyright (C) 2001-2010 The Bochs Project
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -1,8 +1,8 @@
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// $Id: vmexit.cc,v 1.18 2010-03-16 14:55:58 sshwarts Exp $
|
||||
// $Id: vmexit.cc,v 1.19 2010-03-25 21:33:07 sshwarts Exp $
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2009 Stanislav Shwartsman
|
||||
// Copyright (c) 2009-2010 Stanislav Shwartsman
|
||||
// Written by Stanislav Shwartsman [sshwarts at sourceforge net]
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
|
@ -1,8 +1,8 @@
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// $Id: vmx.cc,v 1.45 2010-03-19 11:38:21 sshwarts Exp $
|
||||
// $Id: vmx.cc,v 1.46 2010-03-25 21:33:07 sshwarts Exp $
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2009 Stanislav Shwartsman
|
||||
// Copyright (c) 2009-2010 Stanislav Shwartsman
|
||||
// Written by Stanislav Shwartsman [sshwarts at sourceforge net]
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
@ -1269,20 +1269,28 @@ Bit32u BX_CPU_C::VMenterLoadCheckGuestState(Bit64u *qualification)
|
||||
BX_CPU_THIS_PTR efer.set32(BX_CPU_THIS_PTR efer.get32() & ~((1 << 8) | (1 << 10)));
|
||||
#endif
|
||||
|
||||
Bit32u old_cr0 = BX_CPU_THIS_PTR cr0.get32();
|
||||
|
||||
// keep bits ET(4), reserved bits 15:6, 17, 28:19, NW(29), CD(30)
|
||||
#define VMX_KEEP_CR0_BITS 0x7FFAFFD0
|
||||
|
||||
// load CR0, keep bits ET(4), reserved bits 15:6, 17, 28:19, NW(29), CD(30)
|
||||
if (!SetCR0((old_cr0 & VMX_KEEP_CR0_BITS) | (guest.cr0 & ~VMX_KEEP_CR0_BITS))) {
|
||||
Bit32u old_cr0 = BX_CPU_THIS_PTR cr0.get32();
|
||||
guest.cr0 = (old_cr0 & VMX_KEEP_CR0_BITS) | (guest.cr0 & ~VMX_KEEP_CR0_BITS);
|
||||
|
||||
if (! check_CR0(guest.cr0)) {
|
||||
BX_PANIC(("VMENTER CR0 is broken !"));
|
||||
}
|
||||
if (!SetCR4(guest.cr4)) { // cannot fail if CR4 checks were correct
|
||||
if (! check_CR4(guest.cr4)) {
|
||||
BX_PANIC(("VMENTER CR4 is broken !"));
|
||||
}
|
||||
SetCR3(guest.cr3);
|
||||
|
||||
// flush TLB to invalidate possible APIC ACCESS PAGE caching by host
|
||||
BX_CPU_THIS_PTR cr0.set32(guest.cr0);
|
||||
BX_CPU_THIS_PTR cr4.set32(guest.cr4);
|
||||
|
||||
if (! SetCR3(guest.cr3)) {
|
||||
BX_PANIC(("VMENTER CR3 is broken !"));
|
||||
}
|
||||
|
||||
// flush TLB is always needed to invalidate possible
|
||||
// APIC ACCESS PAGE caching by host
|
||||
TLB_flush();
|
||||
|
||||
if (vmentry_ctrls & VMX_VMENTRY_CTRL1_LOAD_DBG_CTRLS) {
|
||||
@ -1607,13 +1615,23 @@ void BX_CPU_C::VMexitLoadHostState(void)
|
||||
Bit32u old_cr0 = BX_CPU_THIS_PTR cr0.get32();
|
||||
|
||||
// ET, CD, NW, 28:19, 17, 15:6, and VMX fixed bits not modified Section 19.8
|
||||
if (!SetCR0((old_cr0 & VMX_KEEP_CR0_BITS) | (host_state->cr0 & ~VMX_KEEP_CR0_BITS))) {
|
||||
host_state->cr0 = (old_cr0 & VMX_KEEP_CR0_BITS) | (host_state->cr0 & ~VMX_KEEP_CR0_BITS);
|
||||
|
||||
if (! check_CR0(host_state->cr0)) {
|
||||
BX_PANIC(("VMEXIT CR0 is broken !"));
|
||||
}
|
||||
if (!SetCR4(host_state->cr4)) {
|
||||
if (! check_CR4(host_state->cr4)) {
|
||||
BX_PANIC(("VMEXIT CR4 is broken !"));
|
||||
}
|
||||
SetCR3(host_state->cr3);
|
||||
|
||||
BX_CPU_THIS_PTR cr0.set32(host_state->cr0);
|
||||
BX_CPU_THIS_PTR cr4.set32(host_state->cr4);
|
||||
|
||||
TLB_flush(); // CR0/CR4 updated
|
||||
|
||||
if (! SetCR3(host_state->cr3)) {
|
||||
BX_PANIC(("VMEXIT CR3 is broken !"));
|
||||
}
|
||||
|
||||
BX_CPU_THIS_PTR dr7 = 0x00000400;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user