From fa930961c21826d5cc5434886e762875110fa780 Mon Sep 17 00:00:00 2001 From: Stanislav Shwartsman Date: Tue, 23 Aug 2011 21:25:34 +0000 Subject: [PATCH] small optimization --- bochs/cpu/crregs.cc | 36 ++++++++++++++++++++++++------------ bochs/cpu/msr.cc | 6 ++++-- bochs/cpu/paging.cc | 3 ++- bochs/cpu/proc_ctrl.cc | 15 ++++++++++----- bochs/cpu/protect_ctrl.cc | 6 ++++-- bochs/cpu/xsave.cc | 3 ++- 6 files changed, 46 insertions(+), 23 deletions(-) diff --git a/bochs/cpu/crregs.cc b/bochs/cpu/crregs.cc index 40b093eb7..c39ec9fe4 100644 --- a/bochs/cpu/crregs.cc +++ b/bochs/cpu/crregs.cc @@ -50,7 +50,8 @@ BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::MOV_DdRd(bxInstruction_c *i) exception(BX_DB_EXCEPTION, 0); } - if (!real_mode() && CPL!=0) { + // CPL is always 0 in real mode + if (/* !real_mode() && */ CPL!=0) { BX_ERROR(("MOV_DdRd: CPL!=0 not in real mode")); exception(BX_GP_EXCEPTION, 0); } @@ -154,7 +155,8 @@ BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::MOV_RdDd(bxInstruction_c *i) exception(BX_DB_EXCEPTION, 0); } - if (!real_mode() && CPL!=0) { + // CPL is always 0 in real mode + if (/* !real_mode() && */ CPL!=0) { BX_ERROR(("MOV_RdDd: CPL!=0 not in real mode")); exception(BX_GP_EXCEPTION, 0); } @@ -378,7 +380,8 @@ BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::MOV_RqDq(bxInstruction_c *i) BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::MOV_CR0Rd(bxInstruction_c *i) { - if (!real_mode() && CPL!=0) { + // CPL is always 0 in real mode + if (/* !real_mode() && */ CPL!=0) { BX_ERROR(("MOV_CR0Rd: CPL!=0 not in real mode")); exception(BX_GP_EXCEPTION, 0); } @@ -400,7 +403,8 @@ BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::MOV_CR0Rd(bxInstruction_c *i) BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::MOV_CR2Rd(bxInstruction_c *i) { - if (!real_mode() && CPL!=0) { + // CPL is always 0 in real mode + if (/* !real_mode() && */ CPL!=0) { BX_ERROR(("MOV_CR2Rd: CPL!=0 not in real mode")); exception(BX_GP_EXCEPTION, 0); } @@ -412,7 +416,8 @@ BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::MOV_CR2Rd(bxInstruction_c *i) BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::MOV_CR3Rd(bxInstruction_c *i) { - if (!real_mode() && CPL!=0) { + // CPL is always 0 in real mode + if (/* !real_mode() && */ CPL!=0) { BX_ERROR(("MOV_CR3Rd: CPL!=0 not in real mode")); exception(BX_GP_EXCEPTION, 0); } @@ -446,7 +451,8 @@ BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::MOV_CR3Rd(bxInstruction_c *i) BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::MOV_CR4Rd(bxInstruction_c *i) { #if BX_CPU_LEVEL >= 5 - if (!real_mode() && CPL!=0) { + // CPL is always 0 in real mode + if (/* !real_mode() && */ CPL!=0) { BX_ERROR(("MOV_CR4Rd: CPL!=0 not in real mode")); exception(BX_GP_EXCEPTION, 0); } @@ -469,7 +475,8 @@ BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::MOV_CR4Rd(bxInstruction_c *i) BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::MOV_RdCR0(bxInstruction_c *i) { - if (!real_mode() && CPL!=0) { + // CPL is always 0 in real mode + if (/* !real_mode() && */ CPL!=0) { BX_ERROR(("MOV_RdCR0: CPL!=0 not in real mode")); exception(BX_GP_EXCEPTION, 0); } @@ -483,7 +490,8 @@ BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::MOV_RdCR0(bxInstruction_c *i) BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::MOV_RdCR2(bxInstruction_c *i) { - if (!real_mode() && CPL!=0) { + // CPL is always 0 in real mode + if (/* !real_mode() && */ CPL!=0) { BX_ERROR(("MOV_RdCd: CPL!=0 not in real mode")); exception(BX_GP_EXCEPTION, 0); } @@ -495,7 +503,8 @@ BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::MOV_RdCR2(bxInstruction_c *i) BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::MOV_RdCR3(bxInstruction_c *i) { - if (!real_mode() && CPL!=0) { + // CPL is always 0 in real mode + if (/* !real_mode() && */ CPL!=0) { BX_ERROR(("MOV_RdCd: CPL!=0 not in real mode")); exception(BX_GP_EXCEPTION, 0); } @@ -515,7 +524,8 @@ BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::MOV_RdCR3(bxInstruction_c *i) BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::MOV_RdCR4(bxInstruction_c *i) { #if BX_CPU_LEVEL >= 5 - if (!real_mode() && CPL!=0) { + // CPL is always 0 in real mode + if (/* !real_mode() && */ CPL!=0) { BX_ERROR(("MOV_RdCd: CPL!=0 not in real mode")); exception(BX_GP_EXCEPTION, 0); } @@ -765,7 +775,8 @@ BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::LMSW_Ew(bxInstruction_c *i) { Bit16u msw; - if (!real_mode() && CPL!=0) { + // CPL is always 0 in real mode + if (/* !real_mode() && */ CPL!=0) { BX_ERROR(("LMSW: CPL!=0 not in real mode")); exception(BX_GP_EXCEPTION, 0); } @@ -1219,7 +1230,8 @@ bx_bool BX_CPP_AttrRegparmN(1) BX_CPU_C::SetEFER(bx_address val_64) BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::CLTS(bxInstruction_c *i) { - if (!real_mode() && CPL!=0) { + // CPL is always 0 in real mode + if (/* !real_mode() && */ CPL!=0) { BX_ERROR(("CLTS: priveledge check failed, generate #GP(0)")); exception(BX_GP_EXCEPTION, 0); } diff --git a/bochs/cpu/msr.cc b/bochs/cpu/msr.cc index 1b5538f6c..d9f3f0fe2 100644 --- a/bochs/cpu/msr.cc +++ b/bochs/cpu/msr.cc @@ -288,7 +288,8 @@ bx_bool BX_CPP_AttrRegparmN(2) BX_CPU_C::rdmsr(Bit32u index, Bit64u *msr) BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::RDMSR(bxInstruction_c *i) { #if BX_CPU_LEVEL >= 5 - if (!real_mode() && CPL != 0) { + // CPL is always 0 in real mode + if (/* !real_mode() && */ CPL!=0) { BX_ERROR(("RDMSR: CPL != 0 not in real mode")); exception(BX_GP_EXCEPTION, 0); } @@ -739,7 +740,8 @@ bx_bool BX_CPU_C::relocate_apic(Bit64u val_64) BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::WRMSR(bxInstruction_c *i) { #if BX_CPU_LEVEL >= 5 - if (!real_mode() && CPL != 0) { + // CPL is always 0 in real mode + if (/* !real_mode() && */ CPL!=0) { BX_ERROR(("WRMSR: CPL != 0 not in real mode")); exception(BX_GP_EXCEPTION, 0); } diff --git a/bochs/cpu/paging.cc b/bochs/cpu/paging.cc index a0dfc0d85..fc1fdcc7f 100644 --- a/bochs/cpu/paging.cc +++ b/bochs/cpu/paging.cc @@ -464,7 +464,8 @@ void BX_CPU_C::TLB_invlpg(bx_address laddr) BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::INVLPG(bxInstruction_c* i) { - if (!real_mode() && CPL!=0) { + // CPL is always 0 in real mode + if (/* !real_mode() && */ CPL!=0) { BX_ERROR(("INVLPG: priveledge check failed, generate #GP(0)")); exception(BX_GP_EXCEPTION, 0); } diff --git a/bochs/cpu/proc_ctrl.cc b/bochs/cpu/proc_ctrl.cc index f5e8bf9ab..8e8654c1e 100644 --- a/bochs/cpu/proc_ctrl.cc +++ b/bochs/cpu/proc_ctrl.cc @@ -119,7 +119,8 @@ void BX_CPU_C::shutdown(void) BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::HLT(bxInstruction_c *i) { - if (!real_mode() && CPL!=0) { + // CPL is always 0 in real mode + if (/* !real_mode() && */ CPL!=0) { BX_DEBUG(("HLT: %s priveledge check failed, CPL=%d, generate #GP(0)", cpu_mode_string(BX_CPU_THIS_PTR cpu_mode), CPL)); exception(BX_GP_EXCEPTION, 0); @@ -163,7 +164,8 @@ BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::HLT(bxInstruction_c *i) /* 0F 08 */ BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::INVD(bxInstruction_c *i) { - if (!real_mode() && CPL!=0) { + // CPL is always 0 in real mode + if (/* !real_mode() && */ CPL!=0) { BX_ERROR(("INVD: priveledge check failed, generate #GP(0)")); exception(BX_GP_EXCEPTION, 0); } @@ -188,7 +190,8 @@ BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::INVD(bxInstruction_c *i) /* 0F 09 */ BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::WBINVD(bxInstruction_c *i) { - if (!real_mode() && CPL!=0) { + // CPL is always 0 in real mode + if (/* !real_mode() && */ CPL!=0) { BX_ERROR(("INVD/WBINVD: priveledge check failed, generate #GP(0)")); exception(BX_GP_EXCEPTION, 0); } @@ -553,7 +556,8 @@ void BX_CPU_C::check_monitor(bx_phy_address begin_addr, unsigned len) BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::MONITOR(bxInstruction_c *i) { #if BX_SUPPORT_MONITOR_MWAIT - if (!real_mode() && CPL != 0) { + // CPL is always 0 in real mode + if (/* !real_mode() && */ CPL != 0) { BX_DEBUG(("MWAIT instruction not recognized when CPL != 0")); exception(BX_UD_EXCEPTION, 0); } @@ -618,7 +622,8 @@ BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::MONITOR(bxInstruction_c *i) BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::MWAIT(bxInstruction_c *i) { #if BX_SUPPORT_MONITOR_MWAIT - if (!real_mode() && CPL != 0) { + // CPL is always 0 in real mode + if (/* !real_mode() && */ CPL != 0) { BX_DEBUG(("MWAIT instruction not recognized when CPL != 0")); exception(BX_UD_EXCEPTION, 0); } diff --git a/bochs/cpu/protect_ctrl.cc b/bochs/cpu/protect_ctrl.cc index 0557eaead..c6467c908 100644 --- a/bochs/cpu/protect_ctrl.cc +++ b/bochs/cpu/protect_ctrl.cc @@ -764,7 +764,8 @@ BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::LGDT_Ms(bxInstruction_c *i) { BX_ASSERT(BX_CPU_THIS_PTR cpu_mode != BX_MODE_LONG_64); - if (!real_mode() && CPL!=0) { + // CPL is always 0 is real mode + if (/* !real_mode() && */ CPL!=0) { BX_ERROR(("LGDT: CPL != 0 causes #GP")); exception(BX_GP_EXCEPTION, 0); } @@ -792,7 +793,8 @@ BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::LIDT_Ms(bxInstruction_c *i) { BX_ASSERT(BX_CPU_THIS_PTR cpu_mode != BX_MODE_LONG_64); - if (!real_mode() && CPL!=0) { + // CPL is always 0 is real mode + if (/* !real_mode() && */ CPL!=0) { BX_ERROR(("LIDT: CPL != 0 causes #GP")); exception(BX_GP_EXCEPTION, 0); } diff --git a/bochs/cpu/xsave.cc b/bochs/cpu/xsave.cc index 547bafa01..4daaccca4 100644 --- a/bochs/cpu/xsave.cc +++ b/bochs/cpu/xsave.cc @@ -394,7 +394,8 @@ BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::XSETBV(bxInstruction_c *i) } #endif - if (v8086_mode() || CPL != 0) { + // CPL is always 3 in vm8086 mode + if (/* v8086_mode() || */ CPL != 0) { BX_ERROR(("XSETBV: The current priveledge level is not 0")); exception(BX_GP_EXCEPTION, 0); }