Skip to content

Commit b67e279

Browse files
Lara Lazierbonzini
authored andcommitted
target/i386: Added VGIF V_IRQ masking capability
VGIF provides masking capability for when virtual interrupts are taken. (APM2) Signed-off-by: Lara Lazier <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent e3126a5 commit b67e279

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

target/i386/cpu.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5657,6 +5657,7 @@ static void x86_cpu_reset(DeviceState *dev)
56575657
/* init to reset state */
56585658
env->int_ctl = 0;
56595659
env->hflags2 |= HF2_GIF_MASK;
5660+
env->hflags2 |= HF2_VGIF_MASK;
56605661
env->hflags &= ~HF_GUEST_MASK;
56615662

56625663
cpu_x86_update_cr0(env, 0x60000010);
@@ -6540,10 +6541,12 @@ int x86_cpu_pending_interrupt(CPUState *cs, int interrupt_request)
65406541
!(env->hflags & HF_INHIBIT_IRQ_MASK))))) {
65416542
return CPU_INTERRUPT_HARD;
65426543
#if !defined(CONFIG_USER_ONLY)
6543-
} else if ((interrupt_request & CPU_INTERRUPT_VIRQ) &&
6544+
} else if (env->hflags2 & HF2_VGIF_MASK) {
6545+
if((interrupt_request & CPU_INTERRUPT_VIRQ) &&
65446546
(env->eflags & IF_MASK) &&
65456547
!(env->hflags & HF_INHIBIT_IRQ_MASK)) {
6546-
return CPU_INTERRUPT_VIRQ;
6548+
return CPU_INTERRUPT_VIRQ;
6549+
}
65476550
#endif
65486551
}
65496552
}

target/i386/cpu.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ typedef enum X86Seg {
203203
#define HF2_MPX_PR_SHIFT 5 /* BNDCFGx.BNDPRESERVE */
204204
#define HF2_NPT_SHIFT 6 /* Nested Paging enabled */
205205
#define HF2_IGNNE_SHIFT 7 /* Ignore CR0.NE=0 */
206+
#define HF2_VGIF_SHIFT 8 /* Can take VIRQ*/
206207

207208
#define HF2_GIF_MASK (1 << HF2_GIF_SHIFT)
208209
#define HF2_HIF_MASK (1 << HF2_HIF_SHIFT)
@@ -212,6 +213,7 @@ typedef enum X86Seg {
212213
#define HF2_MPX_PR_MASK (1 << HF2_MPX_PR_SHIFT)
213214
#define HF2_NPT_MASK (1 << HF2_NPT_SHIFT)
214215
#define HF2_IGNNE_MASK (1 << HF2_IGNNE_SHIFT)
216+
#define HF2_VGIF_MASK (1 << HF2_VGIF_SHIFT)
215217

216218
#define CR0_PE_SHIFT 0
217219
#define CR0_MP_SHIFT 1

target/i386/tcg/sysemu/svm_helper.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ static inline bool virtual_gif_enabled(CPUX86State *env)
130130
return false;
131131
}
132132

133+
static inline bool virtual_gif_set(CPUX86State *env)
134+
{
135+
return !virtual_gif_enabled(env) || (env->int_ctl & V_GIF_MASK);
136+
}
137+
133138
void helper_vmrun(CPUX86State *env, int aflag, int next_eip_addend)
134139
{
135140
CPUState *cs = env_cpu(env);
@@ -364,6 +369,10 @@ void helper_vmrun(CPUX86State *env, int aflag, int next_eip_addend)
364369
cs->interrupt_request |= CPU_INTERRUPT_VIRQ;
365370
}
366371

372+
if (virtual_gif_set(env)) {
373+
env->hflags2 |= HF2_VGIF_MASK;
374+
}
375+
367376
/* maybe we need to inject an event */
368377
event_inj = x86_ldl_phys(cs, env->vm_vmcb + offsetof(struct vmcb,
369378
control.event_inj));
@@ -520,6 +529,7 @@ void helper_stgi(CPUX86State *env)
520529

521530
if (virtual_gif_enabled(env)) {
522531
env->int_ctl |= V_GIF_MASK;
532+
env->hflags2 |= HF2_VGIF_MASK;
523533
} else {
524534
env->hflags2 |= HF2_GIF_MASK;
525535
}
@@ -531,6 +541,7 @@ void helper_clgi(CPUX86State *env)
531541

532542
if (virtual_gif_enabled(env)) {
533543
env->int_ctl &= ~V_GIF_MASK;
544+
env->hflags2 &= ~HF2_VGIF_MASK;
534545
} else {
535546
env->hflags2 &= ~HF2_GIF_MASK;
536547
}
@@ -812,6 +823,7 @@ void do_vmexit(CPUX86State *env)
812823
env->vm_vmcb + offsetof(struct vmcb, control.event_inj), 0);
813824

814825
env->hflags2 &= ~HF2_GIF_MASK;
826+
env->hflags2 &= ~HF2_VGIF_MASK;
815827
/* FIXME: Resets the current ASID register to zero (host ASID). */
816828

817829
/* Clears the V_IRQ and V_INTR_MASKING bits inside the processor. */

0 commit comments

Comments
 (0)