From 49bb3ba8f502673e06cfa77afcd5e1b2304c334b Mon Sep 17 00:00:00 2001 From: Stanislav Shwartsman Date: Wed, 3 Oct 2012 15:49:45 +0000 Subject: [PATCH] some cleanups and optimizations with new event interface --- bochs/bochs.h | 3 ++- bochs/cpu/apic.cc | 3 --- bochs/cpu/cpu.h | 9 ++++----- bochs/cpu/event.cc | 12 +++++++++--- bochs/cpu/init.cc | 2 +- bochs/cpu/proc_ctrl.cc | 3 +-- bochs/cpu/svm.cc | 2 +- bochs/cpu/vmexit.cc | 12 ------------ bochs/iodev/pic.cc | 6 +++--- bochs/pc_system.cc | 15 ++++++++++++--- bochs/pc_system.h | 4 +++- 11 files changed, 36 insertions(+), 35 deletions(-) diff --git a/bochs/bochs.h b/bochs/bochs.h index 5c269eb37..5269a0155 100644 --- a/bochs/bochs.h +++ b/bochs/bochs.h @@ -182,7 +182,8 @@ void print_tree(bx_param_c *node, int level = 0); #define BX_TICK1() bx_pc_system.tick1() #define BX_TICKN(n) bx_pc_system.tickn(n) #define BX_INTR bx_pc_system.INTR -#define BX_SET_INTR(b) bx_pc_system.set_INTR(b) +#define BX_RAISE_INTR() bx_pc_system.raise_INTR() +#define BX_CLEAR_INTR() bx_pc_system.clear_INTR() #define BX_HRQ bx_pc_system.HRQ #if BX_SUPPORT_SMP diff --git a/bochs/cpu/apic.cc b/bochs/cpu/apic.cc index f50f996a7..3d4a6e636 100644 --- a/bochs/cpu/apic.cc +++ b/bochs/cpu/apic.cc @@ -880,7 +880,6 @@ Bit8u bx_local_apic_c::acknowledge_int(void) if(!INTR) BX_PANIC(("APIC %d acknowledged an interrupt, but INTR=0", apic_id)); - BX_ASSERT(INTR); int vector = highest_priority_int(irr); if (vector < 0) goto spurious; if((vector & 0xf0) <= get_ppr()) goto spurious; @@ -893,13 +892,11 @@ Bit8u bx_local_apic_c::acknowledge_int(void) print_status(); } INTR = 0; - cpu->async_event = 1; service_local_apic(); // will set INTR again if another is ready return vector; spurious: INTR = 0; - cpu->async_event = 1; return spurious_vector; } diff --git a/bochs/cpu/cpu.h b/bochs/cpu/cpu.h index 354fb4f6b..152daca83 100644 --- a/bochs/cpu/cpu.h +++ b/bochs/cpu/cpu.h @@ -1105,7 +1105,7 @@ public: // for now... BX_SMF BX_CPP_INLINE void signal_event(Bit32u event) { BX_CPU_THIS_PTR pending_event |= event; - BX_CPU_THIS_PTR async_event = 1; + if (! is_masked_event(event)) BX_CPU_THIS_PTR async_event = 1; } BX_SMF BX_CPP_INLINE void clear_event(Bit32u event) { @@ -3976,7 +3976,6 @@ public: // for now... #endif BX_SMF void TLB_flush(void); BX_SMF void TLB_invlpg(bx_address laddr); - BX_SMF void set_INTR(bx_bool value); BX_SMF void inhibit_interrupts(unsigned mask); BX_SMF bx_bool interrupts_inhibited(unsigned mask); BX_SMF const char *strseg(bx_segment_reg_t *seg); @@ -4109,6 +4108,9 @@ public: // for now... BX_SMF void smram_save_state(Bit32u *smm_saved_state); BX_SMF bx_bool smram_restore_state(const Bit32u *smm_saved_state); + BX_SMF void raise_INTR(void); + BX_SMF void clear_INTR(void); + BX_SMF void deliver_INIT(void); BX_SMF void deliver_NMI(void); BX_SMF void deliver_SMI(void); @@ -4326,9 +4328,6 @@ public: // for now... BX_SMF void VMexit_ExtInterrupt(void); BX_SMF void VMexit_TaskSwitch(Bit16u tss_selector, unsigned source) BX_CPP_AttrRegparmN(2); BX_SMF void VMexit_PAUSE(void); -#if BX_SUPPORT_VMX >= 2 - BX_SMF void VMexit_PreemptionTimerExpired(void); -#endif BX_SMF bx_bool VMexit_CLTS(void); BX_SMF void VMexit_MSR(unsigned op, Bit32u msr) BX_CPP_AttrRegparmN(2); BX_SMF void VMexit_IO(bxInstruction_c *i, unsigned port, unsigned len) BX_CPP_AttrRegparmN(3); diff --git a/bochs/cpu/event.cc b/bochs/cpu/event.cc index 0700208b0..1a0fb6f52 100644 --- a/bochs/cpu/event.cc +++ b/bochs/cpu/event.cc @@ -251,7 +251,8 @@ bx_bool BX_CPU_C::handleAsyncEvent(void) #if BX_SUPPORT_VMX >= 2 else if (is_unmasked_event_pending(BX_EVENT_VMX_PREEMPTION_TIMER_EXPIRED)) { clear_event(BX_EVENT_VMX_PREEMPTION_TIMER_EXPIRED); - VMexit_PreemptionTimerExpired(); + BX_DEBUG(("VMEXIT: VMX Preemption Timer Expired")); + VMexit(VMX_VMEXIT_VMX_PREEMPTION_TIMER_EXPIRED, 0); } #endif #if BX_SUPPORT_VMX @@ -397,12 +398,17 @@ void BX_CPU_C::deliver_SMI(void) signal_event(BX_EVENT_SMI); } -void BX_CPU_C::set_INTR(bx_bool value) +void BX_CPU_C::raise_INTR(void) { - BX_CPU_THIS_PTR INTR = value; + BX_CPU_THIS_PTR INTR = 1; BX_CPU_THIS_PTR async_event = 1; } +void BX_CPU_C::clear_INTR(void) +{ + BX_CPU_THIS_PTR INTR = 0; +} + #if BX_DEBUGGER void BX_CPU_C::dbg_take_irq(void) diff --git a/bochs/cpu/init.cc b/bochs/cpu/init.cc index e1c402d2b..12ec17b85 100644 --- a/bochs/cpu/init.cc +++ b/bochs/cpu/init.cc @@ -187,7 +187,7 @@ static bx_cpuid_t *cpuid_factory(BX_CPU_C *cpu) // BX_CPU_C constructor void BX_CPU_C::initialize(void) { - BX_CPU_THIS_PTR set_INTR(0); + BX_CPU_THIS_PTR clear_INTR(); #if BX_CPU_LEVEL >= 4 BX_CPU_THIS_PTR cpuid = cpuid_factory(this); diff --git a/bochs/cpu/proc_ctrl.cc b/bochs/cpu/proc_ctrl.cc index d1708ee88..982f6fe40 100644 --- a/bochs/cpu/proc_ctrl.cc +++ b/bochs/cpu/proc_ctrl.cc @@ -1066,8 +1066,7 @@ BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::SYSCALL(bxInstruction_c *i) BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.l = 0; BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.avl = 0; /* available for use by system */ - writeEFlags(read_eflags() & (~MSR_FMASK), EFlagsValidMask); - BX_CPU_THIS_PTR clear_RF(); + writeEFlags(read_eflags() & ~MSR_FMASK & ~(EFlagsRFMask), EFlagsValidMask); RIP = temp_RIP; } else diff --git a/bochs/cpu/svm.cc b/bochs/cpu/svm.cc index 1a8bc375f..2a21de2eb 100644 --- a/bochs/cpu/svm.cc +++ b/bochs/cpu/svm.cc @@ -950,6 +950,7 @@ BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::VMRUN(bxInstruction_c *i) BX_CPU_THIS_PTR in_svm_guest = 1; BX_CPU_THIS_PTR svm_gif = 1; + BX_CPU_THIS_PTR async_event = 1; // // Step 4: Inject events to the guest @@ -1108,7 +1109,6 @@ BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::CLGI(bxInstruction_c *i) } BX_CPU_THIS_PTR svm_gif = 0; - BX_CPU_THIS_PTR async_event = 1; #endif BX_NEXT_TRACE(i); diff --git a/bochs/cpu/vmexit.cc b/bochs/cpu/vmexit.cc index 93064a679..84425ed6e 100644 --- a/bochs/cpu/vmexit.cc +++ b/bochs/cpu/vmexit.cc @@ -178,18 +178,6 @@ void BX_CPU_C::VMexit_ExtInterrupt(void) } } -#if BX_SUPPORT_VMX >= 2 -void BX_CPU_C::VMexit_PreemptionTimerExpired(void) -{ - BX_ASSERT(BX_CPU_THIS_PTR in_vmx_guest); - - if (PIN_VMEXIT(VMX_VM_EXEC_CTRL1_VMX_PREEMPTION_TIMER_VMEXIT)) { - BX_DEBUG(("VMEXIT: VMX Preemption Timer Expired")); - VMexit(VMX_VMEXIT_VMX_PREEMPTION_TIMER_EXPIRED, 0); - } -} -#endif - void BX_CPU_C::VMexit_Event(unsigned type, unsigned vector, Bit16u errcode, bx_bool errcode_valid, Bit64u qualification) { if (! BX_CPU_THIS_PTR in_vmx_guest) return; diff --git a/bochs/iodev/pic.cc b/bochs/iodev/pic.cc index 009219202..1a79716aa 100644 --- a/bochs/iodev/pic.cc +++ b/bochs/iodev/pic.cc @@ -295,7 +295,7 @@ void bx_pic_c::write(Bit32u address, Bit32u value, unsigned io_len) else { BX_DEBUG(("master: ICW1: edge triggered mode selected")); } - BX_SET_INTR(0); + BX_CLEAR_INTR(); return; } @@ -743,7 +743,7 @@ void bx_pic_c::service_master_pic(void) BX_DEBUG(("signalling IRQ(%u)", (unsigned) irq)); BX_PIC_THIS s.master_pic.INT = 1; BX_PIC_THIS s.master_pic.irq = irq; - BX_SET_INTR(1); + BX_RAISE_INTR(); return; } /* if (unmasked_requests & ... */ } @@ -822,7 +822,7 @@ Bit8u bx_pic_c::IAC(void) Bit8u vector; Bit8u irq; - BX_SET_INTR(0); + BX_CLEAR_INTR(); BX_PIC_THIS s.master_pic.INT = 0; // Check for spurious interrupt if (BX_PIC_THIS s.master_pic.irr == 0) { diff --git a/bochs/pc_system.cc b/bochs/pc_system.cc index 5d97cc4ae..a0f792d77 100644 --- a/bochs/pc_system.cc +++ b/bochs/pc_system.cc @@ -89,11 +89,20 @@ void bx_pc_system_c::set_HRQ(bx_bool val) BX_CPU(0)->async_event = 1; } -void bx_pc_system_c::set_INTR(bx_bool value) +void bx_pc_system_c::raise_INTR(void) { if (bx_dbg.interrupts) - BX_INFO(("pc_system: Setting INTR=%d on bootstrap processor %d", (int)value, BX_BOOTSTRAP_PROCESSOR)); - BX_CPU(BX_BOOTSTRAP_PROCESSOR)->set_INTR(value); + BX_INFO(("pc_system: Setting INTR=1 on bootstrap processor %d", BX_BOOTSTRAP_PROCESSOR)); + + BX_CPU(BX_BOOTSTRAP_PROCESSOR)->raise_INTR(); +} + +void bx_pc_system_c::clear_INTR(void) +{ + if (bx_dbg.interrupts) + BX_INFO(("pc_system: Setting INTR=0 on bootstrap processor %d", BX_BOOTSTRAP_PROCESSOR)); + + BX_CPU(BX_BOOTSTRAP_PROCESSOR)->clear_INTR(); } // diff --git a/bochs/pc_system.h b/bochs/pc_system.h index 01b58fd26..6cbbdb5d0 100644 --- a/bochs/pc_system.h +++ b/bochs/pc_system.h @@ -157,7 +157,9 @@ public: volatile bx_bool kill_bochs_request; void set_HRQ(bx_bool val); // set the Hold ReQuest line - void set_INTR(bx_bool value); // set the INTR line to value + + void raise_INTR(void); + void clear_INTR(void); // Cpu and System Reset int Reset(unsigned type);