From 2dee4b12be04db0966cabf6a21459912296b3542 Mon Sep 17 00:00:00 2001 From: Stanislav Shwartsman Date: Wed, 21 Dec 2011 09:11:51 +0000 Subject: [PATCH] added VMX .bochsrc option to ctoggle VMX ON/OFF on runtime --- bochs/.bochsrc | 4 +++ bochs/PARAM_TREE.txt | 1 + bochs/config.cc | 14 +++++++++ bochs/cpu/generic_cpuid.cc | 53 +++++++++++++++++++-------------- bochs/doc/docbook/user/user.dbk | 5 ++++ bochs/doc/man/bochsrc.5 | 5 ++++ bochs/param_names.h | 1 + 7 files changed, 61 insertions(+), 22 deletions(-) diff --git a/bochs/.bochsrc b/bochs/.bochsrc index 975a5d9bc..b530b4870 100644 --- a/bochs/.bochsrc +++ b/bochs/.bochsrc @@ -260,6 +260,10 @@ cpu: cpuid_limit_winnt=0 # When this option is enabled MWAIT will not put the CPU into a sleep state. # This option exists only if Bochs compiled with --enable-monitor-mwait. # +# VMX: +# Select VMX extensions emulation support. +# This option exists only if Bochs compiled with --enable-vmx option. +# # VENDOR_STRING: # Set the CPUID vendor string returned by CPUID(0x0). This should be a # twelve-character ASCII string. diff --git a/bochs/PARAM_TREE.txt b/bochs/PARAM_TREE.txt index c9d492494..582b98690 100644 --- a/bochs/PARAM_TREE.txt +++ b/bochs/PARAM_TREE.txt @@ -41,6 +41,7 @@ cpuid movbe xsave xsaveopt + vmx avx avx_f16c avx_fma diff --git a/bochs/config.cc b/bochs/config.cc index 5a440ca4a..30a517464 100644 --- a/bochs/config.cc +++ b/bochs/config.cc @@ -446,6 +446,13 @@ void bx_init_options() "Don't put CPU to sleep state by MWAIT", 0); #endif +#if BX_SUPPORT_VMX + new bx_param_num_c(cpuid_param, + "vmx", "Support for Intel VMX extensions emulation", + "Support for Intel VMX extensions emulation", + 0, BX_SUPPORT_VMX, + 1); +#endif #endif cpuid_param->set_options(menu->SHOW_PARENT); @@ -2797,6 +2804,10 @@ static int parse_line_formatted(const char *context, int num_params, char *param PARSE_ERR(("%s: cpuid directive malformed.", context)); } #endif +#if BX_SUPPORT_VMX + } else if (!strncmp(params[i], "vmx=", 4)) { + SIM->get_param_num(BXPN_CPUID_VMX)->set(atol(¶ms[i][4])); +#endif #if BX_SUPPORT_X86_64 } else if (!strncmp(params[i], "x86_64=", 7)) { if (parse_param_bool(params[i], 7, BXPN_CPUID_X86_64) < 0) { @@ -4152,6 +4163,9 @@ int bx_write_configuration(const char *rc, int overwrite) SIM->get_param_bool(BXPN_CPUID_TBM)->get(), SIM->get_param_bool(BXPN_CPUID_FMA4)->get()); #endif +#if BX_SUPPORT_VMX + fprintf(fp, ", vmx=%d", SIM->get_param_num(BXPN_CPUID_VMX)->get()); +#endif #if BX_SUPPORT_X86_64 fprintf(fp, ", x86_64=%d, 1g_pages=%d, pcid=%d, fsgsbase=%d", SIM->get_param_bool(BXPN_CPUID_X86_64)->get(), diff --git a/bochs/cpu/generic_cpuid.cc b/bochs/cpu/generic_cpuid.cc index c3c9f4335..63423869c 100644 --- a/bochs/cpu/generic_cpuid.cc +++ b/bochs/cpu/generic_cpuid.cc @@ -853,11 +853,14 @@ void bx_generic_cpuid_t::init_isa_extensions_bitmask(void) #endif // BX_SUPPORT_X86_64 #if BX_SUPPORT_VMX - features_bitmask |= BX_ISA_VMX; + static unsigned vmx_enabled = SIM->get_param_num(BXPN_CPUID_VMX)->get(); + if (vmx_enabled) { + features_bitmask |= BX_ISA_VMX; - if (! sep_enabled) { - BX_PANIC(("PANIC: VMX emulation requires SYSENTER/SYSEXIT support !")); - return; + if (! sep_enabled) { + BX_PANIC(("PANIC: VMX emulation requires SYSENTER/SYSEXIT support !")); + return; + } } #endif @@ -937,30 +940,36 @@ void bx_generic_cpuid_t::init_cpu_extensions_bitmask(void) #if BX_SUPPORT_VMX void bx_generic_cpuid_t::init_vmx_extensions_bitmask(void) { - Bit32u features_bitmask = BX_VMX_VIRTUAL_NMI; + Bit32u features_bitmask = 0; - static bx_bool x86_64_enabled = SIM->get_param_bool(BXPN_CPUID_X86_64)->get(); - if (x86_64_enabled) { - features_bitmask |= BX_VMX_TPR_SHADOW; + static unsigned vmx_enabled = SIM->get_param_num(BXPN_CPUID_VMX)->get(); + if (vmx_enabled) { + features_bitmask |= BX_VMX_VIRTUAL_NMI; - features_bitmask |= BX_VMX_APIC_VIRTUALIZATION | - BX_VMX_WBINVD_VMEXIT; + static bx_bool x86_64_enabled = SIM->get_param_bool(BXPN_CPUID_X86_64)->get(); + if (x86_64_enabled) { + features_bitmask |= BX_VMX_TPR_SHADOW | + BX_VMX_APIC_VIRTUALIZATION | + BX_VMX_WBINVD_VMEXIT; #if BX_SUPPORT_VMX >= 2 - features_bitmask |= BX_VMX_PREEMPTION_TIMER | - BX_VMX_PAT | - BX_VMX_EFER | - BX_VMX_EPT | - BX_VMX_VPID | - BX_VMX_UNRESTRICTED_GUEST | - BX_VMX_DESCRIPTOR_TABLE_EXIT | - BX_VMX_X2APIC_VIRTUALIZATION | - BX_VMX_PAUSE_LOOP_EXITING; + if (vmx_enabled >= 2) { + features_bitmask |= BX_VMX_PREEMPTION_TIMER | + BX_VMX_PAT | + BX_VMX_EFER | + BX_VMX_EPT | + BX_VMX_VPID | + BX_VMX_UNRESTRICTED_GUEST | + BX_VMX_DESCRIPTOR_TABLE_EXIT | + BX_VMX_X2APIC_VIRTUALIZATION | + BX_VMX_PAUSE_LOOP_EXITING; - features_bitmask |= BX_VMX_SAVE_DEBUGCTL_DISABLE | - /* BX_VMX_MONITOR_TRAP_FLAG | */ // not implemented yet - BX_VMX_PERF_GLOBAL_CTRL; + features_bitmask |= BX_VMX_SAVE_DEBUGCTL_DISABLE | + /* BX_VMX_MONITOR_TRAP_FLAG | */ // not implemented yet + BX_VMX_PERF_GLOBAL_CTRL; + } #endif + } } this->vmx_extensions_bitmask = features_bitmask; diff --git a/bochs/doc/docbook/user/user.dbk b/bochs/doc/docbook/user/user.dbk index d78a9b2bb..272b9a3c5 100644 --- a/bochs/doc/docbook/user/user.dbk +++ b/bochs/doc/docbook/user/user.dbk @@ -3095,6 +3095,11 @@ This option exists only if Bochs compiled with --enable-monitor-mwait. When this option is enabled MWAIT will not put the CPU into a sleep state. This option exists only if Bochs compiled with --enable-monitor-mwait. +vmx + +Select VMX extensions emulation support. +This option exists only if Bochs compiled with --enable-vmx option. + family Set family information returned by CPUID. Default family value determined diff --git a/bochs/doc/man/bochsrc.5 b/bochs/doc/man/bochsrc.5 index 99efe4196..b2a570d84 100644 --- a/bochs/doc/man/bochsrc.5 +++ b/bochs/doc/man/bochsrc.5 @@ -304,6 +304,11 @@ mwait_is_nop: When this option is enabled MWAIT will not put the CPU into a sleep state. This option exists only if Bochs compiled with --enable-monitor-mwait. +vmx: + +Select VMX extensions emulation support. +This option exists only if Bochs compiled with --enable-vmx option. + family: Set family information returned by CPUID. Default family value determined diff --git a/bochs/param_names.h b/bochs/param_names.h index e20752870..a50d325e1 100644 --- a/bochs/param_names.h +++ b/bochs/param_names.h @@ -55,6 +55,7 @@ #define BXPN_CPUID_SEP "cpuid.sep" #define BXPN_CPUID_XSAVE "cpuid.xsave" #define BXPN_CPUID_XSAVEOPT "cpuid.xsaveopt" +#define BXPN_CPUID_VMX "cpuid.vmx" #define BXPN_CPUID_AVX "cpuid.avx" #define BXPN_CPUID_AVX_F16CVT "cpuid.avx_f16c" #define BXPN_CPUID_AVX_FMA "cpuid.avx_fma"