diff --git a/bochs/cpu/cpu.cc b/bochs/cpu/cpu.cc index a9b24688d..7fd48c4c5 100644 --- a/bochs/cpu/cpu.cc +++ b/bochs/cpu/cpu.cc @@ -26,6 +26,8 @@ #include "cpustats.h" +jmp_buf BX_CPU_C::jmp_buf_env; + void BX_CPU_C::cpu_loop(void) { #if BX_DEBUGGER @@ -134,12 +136,6 @@ void BX_CPU_C::cpu_loop(void) void BX_CPU_C::cpu_run_trace(void) { - if (setjmp(BX_CPU_THIS_PTR jmp_buf_env)) { - // can get here only from exception function or VMEXIT - BX_CPU_THIS_PTR icount++; - return; - } - // check on events which occurred for previous instructions (traps) // and ones which are asynchronous to the CPU (hardware interrupts) if (BX_CPU_THIS_PTR async_event) { diff --git a/bochs/cpu/cpu.h b/bochs/cpu/cpu.h index 404ace882..5ab485a86 100644 --- a/bochs/cpu/cpu.h +++ b/bochs/cpu/cpu.h @@ -1216,7 +1216,7 @@ public: // for now... #endif // for exceptions - jmp_buf jmp_buf_env; + static jmp_buf jmp_buf_env; unsigned last_exception_type; // Boundaries of current code page, based on EIP diff --git a/bochs/main.cc b/bochs/main.cc index 088ce5860..18c01d54f 100644 --- a/bochs/main.cc +++ b/bochs/main.cc @@ -1060,14 +1060,22 @@ int bx_begin_simulation(int argc, char *argv[]) static int quantum = SIM->get_param_num(BXPN_SMP_QUANTUM)->get(); Bit32u executed = 0, processor = 0; + bool run = true; + if (setjmp(BX_CPU_C::jmp_buf_env)) { + // can get here only from exception function or VMEXIT + BX_CPU(processor)->icount++; + run = false; + } while (1) { // do some instructions in each processor - Bit64u icount = BX_CPU(processor)->icount_last_sync = BX_CPU(processor)->get_icount(); - BX_CPU(processor)->cpu_run_trace(); + if (run) + BX_CPU(processor)->cpu_run_trace(); + else + run = true; // see how many instruction it was able to run - Bit32u n = (Bit32u)(BX_CPU(processor)->get_icount() - icount); + Bit32u n = (Bit32u)(BX_CPU(processor)->get_icount() - BX_CPU(processor)->icount_last_sync); if (n == 0) n = quantum; // the CPU was halted executed += n; @@ -1077,6 +1085,8 @@ int bx_begin_simulation(int argc, char *argv[]) executed %= BX_SMP_PROCESSORS; } + BX_CPU(processor)->icount_last_sync = BX_CPU(processor)->get_icount(); + if (bx_pc_system.kill_bochs_request) break; }