[4662] reworked SVM interrupt handling logic - fixed vmrun EIP saved value - reworked cr8 handling - added CPUState .hflags2
Revision: 4662
http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=4662 Author: bellard Date: 2008-06-04 17:02:19 +0000 (Wed, 04 Jun 2008)
Log Message:
-----------
reworked SVM interrupt handling logic - fixed vmrun EIP saved value - reworked cr8 handling - added CPUState.hflags2
Modified Paths:
--------------
trunk/cpu-exec.c
trunk/target-i386/cpu.h
trunk/target-i386/helper.c
trunk/target-i386/helper.h
trunk/target-i386/op_helper.c
trunk/target-i386/svm.h
trunk/target-i386/translate.cModified: trunk/cpu-exec.c
===================================================================
cpu-exec.c +45 -44
@@ -368,11 +368,8 @@ next_tb =0 ;/* force lookup of first TB */ for (;;) { interrupt_request = env->interrupt_request; - if (__builtin_expect(interrupt_request, 0) -#if defined(TARGET_I386 ) - && env->hflags & HF_GIF_MASK -#endif - && likely(!(env->singlestep_enabled & SSTEP_NOIRQ))) { +if (__builtin_expect (interrupt_request,0 ) && +likely (!(env->singlestep_enabled &SSTEP_NOIRQ ))) {if (interrupt_request &CPU_INTERRUPT_DEBUG ) { env->interrupt_request &= ~CPU_INTERRUPT_DEBUG ; env->exception_index =EXCP_DEBUG ;
@@ -388,47 +385,51 @@ }#endif #if defined(TARGET_I386 ) -if ((interrupt_request &CPU_INTERRUPT_SMI ) && - !(env->hflags &HF_SMM_MASK )) { -svm_check_intercept (SVM_EXIT_SMI ); - env->interrupt_request &= ~CPU_INTERRUPT_SMI ; -do_smm_enter (); - next_tb =0 ; - }else if ((interrupt_request &CPU_INTERRUPT_NMI ) && - !(env->hflags &HF_NMI_MASK )) { - env->interrupt_request &= ~CPU_INTERRUPT_NMI ; - env->hflags |=HF_NMI_MASK ; -do_interrupt (EXCP02_NMI ,0 ,0 ,0 ,1 ); - next_tb =0 ; - }else if ((interrupt_request &CPU_INTERRUPT_HARD ) && - (env->eflags &IF_MASK || env->hflags &HF_HIF_MASK ) && - !(env->hflags &HF_INHIBIT_IRQ_MASK )) { -int intno; -svm_check_intercept (SVM_EXIT_INTR ); - env->interrupt_request &= ~(CPU_INTERRUPT_HARD |CPU_INTERRUPT_VIRQ ); - intno =cpu_get_pic_interrupt (env); -if (loglevel &CPU_LOG_TB_IN_ASM ) { -fprintf (logfile,"Servicing hardware INT=0x%02x\n" , intno); - } -do_interrupt (intno,0 ,0 ,0 ,1 ); -/* ensure that no TB jump will be modified as -the program flow was changed */ - next_tb =0 ; +if (env->hflags2 &HF2_GIF_MASK ) { +if ((interrupt_request &CPU_INTERRUPT_SMI ) && + !(env->hflags &HF_SMM_MASK )) { +svm_check_intercept (SVM_EXIT_SMI ); + env->interrupt_request &= ~CPU_INTERRUPT_SMI ; +do_smm_enter (); + next_tb =0 ; + }else if ((interrupt_request &CPU_INTERRUPT_NMI ) && + !(env->hflags2 &HF2_NMI_MASK )) { + env->interrupt_request &= ~CPU_INTERRUPT_NMI ; + env->hflags2 |=HF2_NMI_MASK ; +do_interrupt (EXCP02_NMI ,0 ,0 ,0 ,1 ); + next_tb =0 ; + }else if ((interrupt_request &CPU_INTERRUPT_HARD ) && + (((env->hflags2 &HF2_VINTR_MASK ) && + (env->hflags2 &HF2_HIF_MASK )) || + (!(env->hflags2 &HF2_VINTR_MASK ) && + (env->eflags &IF_MASK && + !(env->hflags &HF_INHIBIT_IRQ_MASK ))))) { +int intno; +svm_check_intercept (SVM_EXIT_INTR ); + env->interrupt_request &= ~(CPU_INTERRUPT_HARD |CPU_INTERRUPT_VIRQ ); + intno =cpu_get_pic_interrupt (env); +if (loglevel &CPU_LOG_TB_IN_ASM ) { +fprintf (logfile,"Servicing hardware INT=0x%02x\n" , intno); + } +do_interrupt (intno,0 ,0 ,0 ,1 ); +/* ensure that no TB jump will be modified as +the program flow was changed */ + next_tb =0 ;#if !defined(CONFIG_USER_ONLY ) - } else if ((interrupt_request & CPU_INTERRUPT_VIRQ) && - (env->eflags &IF_MASK ) && !(env->hflags &HF_INHIBIT_IRQ_MASK )) { -int intno; -/* FIXME: this should respect TPR */ - env->interrupt_request &= ~CPU_INTERRUPT_VIRQ ; -svm_check_intercept (SVM_EXIT_VINTR ); - intno = ldl_phys(env->vm_vmcb + offsetof(struct vmcb, control.int_vector)); -if (loglevel &CPU_LOG_TB_IN_ASM ) -fprintf (logfile,"Servicing virtual hardware INT=0x%02x\n" , intno); -do_interrupt (intno,0 ,0 ,-1 ,1 ); - stl_phys(env->vm_vmcb + offsetof(struct vmcb, control.int_ctl), - ldl_phys(env->vm_vmcb + offsetof(struct vmcb, control.int_ctl)) & ~V_IRQ_MASK); - next_tb =0 ; + } else if ((interrupt_request & CPU_INTERRUPT_VIRQ) && + (env->eflags &IF_MASK ) && + !(env->hflags &HF_INHIBIT_IRQ_MASK )) { +int intno; +/* FIXME: this should respect TPR */ +svm_check_intercept (SVM_EXIT_VINTR ); + env->interrupt_request &= ~CPU_INTERRUPT_VIRQ ; + intno = ldl_phys(env->vm_vmcb + offsetof(struct vmcb, control.int_vector)); +if (loglevel &CPU_LOG_TB_IN_ASM ) +fprintf (logfile,"Servicing virtual hardware INT=0x%02x\n" , intno); +do_interrupt (intno,0 ,0 ,0 ,1 ); + next_tb =0 ;#endif + } }#elif defined(TARGET_PPC )#if 0
Modified: trunk/target-i386/cpu.h
===================================================================
target-i386/cpu.h +19 -10
@@ -145,11 +145,8 @@#define HF_OSFXSR_SHIFT 16/* CR4.OSFXSR */ #define HF_VM_SHIFT 17/* must be same as eflags */ #define HF_SMM_SHIFT 19/* CPU in SMM mode */ -#define HF_GIF_SHIFT 20/* if set CPU takes interrupts */ -#define HF_HIF_SHIFT 21/* shadow copy of IF_MASK when in SVM */ -#define HF_NMI_SHIFT 22/* CPU serving NMI */ -#define HF_SVME_SHIFT 23/* SVME enabled (copy of EFER.SVME) */ -#define HF_SVMI_SHIFT 24/* SVM intercepts are active */ +#define HF_SVME_SHIFT 20/* SVME enabled (copy of EFER.SVME) */ +#define HF_SVMI_SHIFT 21/* SVM intercepts are active */ #define HF_CPL_MASK (3 << HF_CPL_SHIFT)#define HF_SOFTMMU_MASK (1 << HF_SOFTMMU_SHIFT)
@@ -166,12 +163,21 @@#define HF_CS64_MASK (1 << HF_CS64_SHIFT)#define HF_OSFXSR_MASK (1 << HF_OSFXSR_SHIFT)#define HF_SMM_MASK (1 << HF_SMM_SHIFT) -#define HF_GIF_MASK (1 << HF_GIF_SHIFT) -#define HF_HIF_MASK (1 << HF_HIF_SHIFT) -#define HF_NMI_MASK (1 << HF_NMI_SHIFT)#define HF_SVME_MASK (1 << HF_SVME_SHIFT)#define HF_SVMI_MASK (1 << HF_SVMI_SHIFT) +/* hflags2 */ + +#define HF2_GIF_SHIFT 0/* if set CPU takes interrupts */ +#define HF2_HIF_SHIFT 1/* value of IF_MASK when entering SVM */ +#define HF2_NMI_SHIFT 2/* CPU serving NMI */ +#define HF2_VINTR_SHIFT 3/* value of V_INTR_MASKING bit */ + +#define HF2_GIF_MASK (1 << HF2_GIF_SHIFT) +#define HF2_HIF_MASK (1 << HF2_HIF_SHIFT) +#define HF2_NMI_MASK (1 << HF2_NMI_SHIFT) +#define HF2_VINTR_MASK (1 << HF2_VINTR_SHIFT) +#define CR0_PE_MASK (1 << 0)#define CR0_MP_MASK (1 << 1)#define CR0_EM_MASK (1 << 2)
@@ -488,7 +494,9 @@target_ulong cc_dst;uint32_t cc_op;int32_t df;/* D flag : 1 if D = 0, -1 if D = 1 */ -uint32_t hflags;/* hidden flags, see HF_xxx constants */ +uint32_t hflags;/* TB flags, see HF_xxx constants. These flags +are known at translation time. */ +uint32_t hflags2;/* various other flags, see HF2_xxx constants. */ /* segments */ SegmentCache segs[6 ];/* selector values */
@@ -497,7 +505,7 @@SegmentCache gdt;/* only base and limit are used */ SegmentCache idt;/* only base and limit are used */ -target_ulong cr[9 ];/* NOTE: cr1, cr5-7 are unused */ +target_ulong cr[5 ];/* NOTE: cr1 is unused */ uint64_t a20_mask;/* FPU state */
@@ -541,6 +549,7 @@uint16_t intercept_dr_read;uint16_t intercept_dr_write;uint32_t intercept_exceptions; +uint8_t v_tpr;#ifdef TARGET_X86_64 target_ulong lstar;
Modified: trunk/target-i386/helper.c
===================================================================
target-i386/helper.c +1 -1
@@ -374,7 +374,7 @@#ifdef CONFIG_SOFTMMU env->hflags |=HF_SOFTMMU_MASK ;#endif - env->hflags |=HF_GIF_MASK ; + env->hflags2 |=HF2_GIF_MASK ;cpu_x86_update_cr0 (env,0x60000010 ); env->a20_mask = ~0x0 ;
Modified: trunk/target-i386/helper.h
===================================================================
target-i386/helper.h +1 -4
@@ -47,9 +47,6 @@ DEF_HELPER(void, helper_write_crN, (int reg, target_ulong t0)) DEF_HELPER(void, helper_lmsw, (target_ulong t0)) DEF_HELPER(void, helper_clts, (void)) -#if !defined(CONFIG_USER_ONLY) -DEF_HELPER(target_ulong, helper_movtl_T0_cr8, (void)) -#endif DEF_HELPER(void, helper_movl_drN_T0, (int reg, target_ulong t0)) DEF_HELPER(void, helper_invlpg, (target_ulong addr))
@@ -102,7 +99,7 @@ DEF_HELPER(void, helper_vmexit, (uint32_t exit_code, uint64_t exit_info_1)) DEF_HELPER(void, helper_svm_check_io, (uint32_t port, uint32_t param, uint32_t next_eip_addend)) -DEF_HELPER(void, helper_vmrun, (int aflag)) +DEF_HELPER(void, helper_vmrun, (int aflag, int next_eip_addend)) DEF_HELPER(void, helper_vmmcall, (void)) DEF_HELPER(void, helper_vmload, (int aflag)) DEF_HELPER(void, helper_vmsave, (int aflag))
Modified: trunk/target-i386/op_helper.c
===================================================================
target-i386/op_helper.c +38 -43
216 lines not on this page · raw message
Modified: trunk/target-i386/svm.h
===================================================================
target-i386/svm.h +1 -3
@@ -205,9 +205,7 @@uint64_t sysenter_esp;uint64_t sysenter_eip;uint64_t cr2; -/* qemu: cr8 added to reuse this as hsave */ -uint64_t cr8; -uint8_t reserved_6[32 -8 ];/* originally 32 */ +uint8_t reserved_6[32 ];uint64_t g_pat;uint64_t dbgctl;uint64_t br_from;
Modified: trunk/target-i386/translate.c
===================================================================
target-i386/translate.c +5 -4
@@ -6569,10 +6569,11 @@gen_exception (s,EXCP0D_GPF , pc_start - s->cs_base);break ; }else { -tcg_gen_helper_0_1 (helper_vmrun, -tcg_const_i32 (s->aflag)); - s->cc_op =CC_OP_EFLAGS ; -gen_eob (s); +tcg_gen_helper_0_2 (helper_vmrun, +tcg_const_i32 (s->aflag), +tcg_const_i32 (s->pc - pc_start)); +tcg_gen_exit_tb (0 ); + s->is_jmp =3 ; }break ;case 1 :/* VMMCALL */