From 3cd11b02eef1261e0596fc963916d1de2e0c6f69 Mon Sep 17 00:00:00 2001 From: Stanislav Shwartsman Date: Thu, 4 Oct 2012 21:30:50 +0000 Subject: [PATCH] optimization and bugfix for prev commit --- bochs/cpu/exception.cc | 51 ++++++++++++++++++------------------------ bochs/cpu/svm.cc | 3 +-- bochs/cpu/vmexit.cc | 2 -- bochs/cpu/vmx.cc | 1 + 4 files changed, 24 insertions(+), 33 deletions(-) diff --git a/bochs/cpu/exception.cc b/bochs/cpu/exception.cc index 78dbe03cd..124e436ef 100644 --- a/bochs/cpu/exception.cc +++ b/bochs/cpu/exception.cc @@ -823,7 +823,6 @@ struct BxExceptionInfo exceptions_info[BX_CPU_HANDLED_EXCEPTIONS] = { // vector: 0..255: vector in IDT // error_code: if exception generates and error, push this error code -// trap: override exception class to TRAP void BX_CPU_C::exception(unsigned vector, Bit16u error_code) { BX_INSTR_EXCEPTION(BX_CPU_ID, vector, error_code); @@ -860,34 +859,6 @@ void BX_CPU_C::exception(unsigned vector, Bit16u error_code) SvmInterceptException(BX_HARDWARE_EXCEPTION, vector, error_code, push_error); #endif - if (BX_CPU_THIS_PTR last_exception_type == BX_ET_DOUBLE_FAULT) { - // restore RIP/RSP to value before error occurred - RIP = BX_CPU_THIS_PTR prev_rip; - if (BX_CPU_THIS_PTR speculative_rsp) - RSP = BX_CPU_THIS_PTR prev_rsp; - - debug(BX_CPU_THIS_PTR prev_rip); // print debug information to the log -#if BX_SUPPORT_VMX - VMexit_TripleFault(); -#endif -#if BX_DEBUGGER - // trap into debugger (similar as done when PANIC occured) - bx_debug_break(); -#endif - if (SIM->get_param_bool(BXPN_RESET_ON_TRIPLE_FAULT)->get()) { - BX_ERROR(("exception(): 3rd (%d) exception with no resolution, shutdown status is %02xh, resetting", vector, DEV_cmos_get_reg(0x0f))); - bx_pc_system.Reset(BX_RESET_HARDWARE); - } - else { - BX_PANIC(("exception(): 3rd (%d) exception with no resolution", vector)); - BX_ERROR(("WARNING: Any simulation after this point is completely bogus !")); - shutdown(); - } - longjmp(BX_CPU_THIS_PTR jmp_buf_env, 1); // go back to main decode loop - } - - // note: fault-class exceptions _except_ #DB set RF in - // eflags image. if (exception_class == BX_EXCEPTION_CLASS_FAULT) { // restore RIP/RSP to value before error occurred @@ -895,6 +866,28 @@ void BX_CPU_C::exception(unsigned vector, Bit16u error_code) if (BX_CPU_THIS_PTR speculative_rsp) RSP = BX_CPU_THIS_PTR prev_rsp; + if (BX_CPU_THIS_PTR last_exception_type == BX_ET_DOUBLE_FAULT) + { + debug(BX_CPU_THIS_PTR prev_rip); // print debug information to the log +#if BX_SUPPORT_VMX + VMexit_TripleFault(); +#endif +#if BX_DEBUGGER + // trap into debugger (similar as done when PANIC occured) + bx_debug_break(); +#endif + if (SIM->get_param_bool(BXPN_RESET_ON_TRIPLE_FAULT)->get()) { + BX_ERROR(("exception(): 3rd (%d) exception with no resolution, shutdown status is %02xh, resetting", vector, DEV_cmos_get_reg(0x0f))); + bx_pc_system.Reset(BX_RESET_HARDWARE); + } + else { + BX_PANIC(("exception(): 3rd (%d) exception with no resolution", vector)); + BX_ERROR(("WARNING: Any simulation after this point is completely bogus !")); + shutdown(); + } + longjmp(BX_CPU_THIS_PTR jmp_buf_env, 1); // go back to main decode loop + } + if (vector != BX_DB_EXCEPTION) BX_CPU_THIS_PTR assert_RF(); } diff --git a/bochs/cpu/svm.cc b/bochs/cpu/svm.cc index e5339cc07..13d907144 100644 --- a/bochs/cpu/svm.cc +++ b/bochs/cpu/svm.cc @@ -630,6 +630,7 @@ void BX_CPU_C::Svm_Vmexit(int reason, Bit64u exitinfo1, Bit64u exitinfo2) // BX_CPU_THIS_PTR EXT = 0; + BX_CPU_THIS_PTR last_exception_type = 0; #if BX_DEBUGGER if (BX_CPU_THIS_PTR vmexit_break) { @@ -744,8 +745,6 @@ void BX_CPU_C::SvmInterceptException(unsigned type, unsigned vector, Bit16u errc BX_CPU_THIS_PTR debug_trap = 0; // clear debug_trap field BX_CPU_THIS_PTR inhibit_mask = 0; - BX_CPU_THIS_PTR last_exception_type = 0; // error resolved - Svm_Vmexit(SVM_VMEXIT_EXCEPTION + vector, (errcode_valid ? errcode : 0), qualification); } diff --git a/bochs/cpu/vmexit.cc b/bochs/cpu/vmexit.cc index 9ef9ef83f..cbc67bccf 100644 --- a/bochs/cpu/vmexit.cc +++ b/bochs/cpu/vmexit.cc @@ -255,8 +255,6 @@ void BX_CPU_C::VMexit_Event(unsigned type, unsigned vector, Bit16u errcode, bx_b BX_CPU_THIS_PTR debug_trap = 0; BX_CPU_THIS_PTR inhibit_mask = 0; - BX_CPU_THIS_PTR last_exception_type = 0; // error resolved - Bit32u interruption_info = vector | (type << 8); if (errcode_valid) interruption_info |= (1 << 11); // error code delivered diff --git a/bochs/cpu/vmx.cc b/bochs/cpu/vmx.cc index d95d766b3..8beae499a 100644 --- a/bochs/cpu/vmx.cc +++ b/bochs/cpu/vmx.cc @@ -2244,6 +2244,7 @@ void BX_CPU_C::VMexit(Bit32u reason, Bit64u qualification) mask_event(BX_EVENT_INIT); // INIT is disabled in VMX root mode BX_CPU_THIS_PTR EXT = 0; + BX_CPU_THIS_PTR last_exception_type = 0; #if BX_DEBUGGER if (BX_CPU_THIS_PTR vmexit_break) {