* [Qemu-devel] [PATCH] target-i386: set CC_OP to CC_OP_EFLAGS in cpu_load_eflags
@ 2014-05-15 17:04 Paolo Bonzini
2014-05-15 17:30 ` Richard Henderson
0 siblings, 1 reply; 5+ messages in thread
From: Paolo Bonzini @ 2014-05-15 17:04 UTC (permalink / raw)
To: qemu-devel; +Cc: rth
There is no reason to keep that out of the function. The comment refers
to the disassembler's cc_op state rather than the CPUState field.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
target-i386/cpu.h | 3 ++-
target-i386/seg_helper.c | 2 --
target-i386/smm_helper.c | 2 --
target-i386/svm_helper.c | 1 -
4 files changed, 2 insertions(+), 6 deletions(-)
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index e9cbdab..f451a62 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -1234,11 +1234,12 @@ static inline uint32_t cpu_compute_eflags(CPUX86State *env)
return env->eflags | cpu_cc_compute_all(env, CC_OP) | (env->df & DF_MASK);
}
-/* NOTE: CC_OP must be modified manually to CC_OP_EFLAGS */
+/* NOTE: set CC_OP to CC_OP_EFLAGS after calling a helper that uses this! */
static inline void cpu_load_eflags(CPUX86State *env, int eflags,
int update_mask)
{
CC_SRC = eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
+ CC_OP = CC_OP_EFLAGS;
env->df = 1 - (2 * ((eflags >> 10) & 1));
env->eflags = (env->eflags & ~update_mask) |
(eflags & update_mask) | 0x2;
diff --git a/target-i386/seg_helper.c b/target-i386/seg_helper.c
index 3cf862e..6c0142a 100644
--- a/target-i386/seg_helper.c
+++ b/target-i386/seg_helper.c
@@ -1600,7 +1600,6 @@ void helper_ljmp_protected(CPUX86State *env, int new_cs, target_ulong new_eip,
}
next_eip = env->eip + next_eip_addend;
switch_tss(env, new_cs, e1, e2, SWITCH_TSS_JMP, next_eip);
- CC_OP = CC_OP_EFLAGS;
break;
case 4: /* 286 call gate */
case 12: /* 386 call gate */
@@ -1769,7 +1768,6 @@ void helper_lcall_protected(CPUX86State *env, int new_cs, target_ulong new_eip,
raise_exception_err(env, EXCP0D_GPF, new_cs & 0xfffc);
}
switch_tss(env, new_cs, e1, e2, SWITCH_TSS_CALL, next_eip);
- CC_OP = CC_OP_EFLAGS;
return;
case 4: /* 286 call gate */
case 12: /* 386 call gate */
diff --git a/target-i386/smm_helper.c b/target-i386/smm_helper.c
index 4841d53..2f99493 100644
--- a/target-i386/smm_helper.c
+++ b/target-i386/smm_helper.c
@@ -168,7 +168,6 @@ void do_smm_enter(X86CPU *cpu)
CR0_PG_MASK));
cpu_x86_update_cr4(env, 0);
env->dr[7] = 0x00000400;
- CC_OP = CC_OP_EFLAGS;
cpu_x86_load_seg_cache(env, R_CS, (env->smbase >> 4) & 0xffff, env->smbase,
0xffffffff, 0);
@@ -296,7 +295,6 @@ void helper_rsm(CPUX86State *env)
env->smbase = ldl_phys(cs->as, sm_state + 0x7ef8) & ~0x7fff;
}
#endif
- CC_OP = CC_OP_EFLAGS;
env->hflags &= ~HF_SMM_MASK;
cpu_smm_update(env);
diff --git a/target-i386/svm_helper.c b/target-i386/svm_helper.c
index 846eaa5..2b1da12 100644
--- a/target-i386/svm_helper.c
+++ b/target-i386/svm_helper.c
@@ -260,7 +260,6 @@ void helper_vmrun(CPUX86State *env, int aflag, int next_eip_addend)
env->vm_vmcb + offsetof(struct vmcb,
save.rflags)),
~(CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C | DF_MASK));
- CC_OP = CC_OP_EFLAGS;
svm_load_seg_cache(env, env->vm_vmcb + offsetof(struct vmcb, save.es),
R_ES);
--
1.8.3.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] target-i386: set CC_OP to CC_OP_EFLAGS in cpu_load_eflags
2014-05-15 17:04 [Qemu-devel] [PATCH] target-i386: set CC_OP to CC_OP_EFLAGS in cpu_load_eflags Paolo Bonzini
@ 2014-05-15 17:30 ` Richard Henderson
2014-05-16 9:34 ` Paolo Bonzini
0 siblings, 1 reply; 5+ messages in thread
From: Richard Henderson @ 2014-05-15 17:30 UTC (permalink / raw)
To: Paolo Bonzini, qemu-devel
On 05/15/2014 10:04 AM, Paolo Bonzini wrote:
> There is no reason to keep that out of the function. The comment refers
> to the disassembler's cc_op state rather than the CPUState field.
Yes, but...
> -/* NOTE: CC_OP must be modified manually to CC_OP_EFLAGS */
> +/* NOTE: set CC_OP to CC_OP_EFLAGS after calling a helper that uses this! */
> static inline void cpu_load_eflags(CPUX86State *env, int eflags,
> int update_mask)
> {
> CC_SRC = eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
> + CC_OP = CC_OP_EFLAGS;
> env->df = 1 - (2 * ((eflags >> 10) & 1));
... we'd do well to reflect that in the comment here, rather than
in the commit message. Because by itself it looks like the comment
is out of date.
How about
/* NOTE: the translator must set DisasContext.cc_op to CC_OP_EFLAGS
after generating a call to a helper that uses this. */
> --- a/target-i386/svm_helper.c
> +++ b/target-i386/svm_helper.c
> @@ -260,7 +260,6 @@ void helper_vmrun(CPUX86State *env, int aflag, int next_eip_addend)
> env->vm_vmcb + offsetof(struct vmcb,
> save.rflags)),
> ~(CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C | DF_MASK));
> - CC_OP = CC_OP_EFLAGS;
>
> svm_load_seg_cache(env, env->vm_vmcb + offsetof(struct vmcb, save.es),
> R_ES);
> --
I see two sets of CC_OP in svm_helper.c. Missed one?
r~
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] target-i386: set CC_OP to CC_OP_EFLAGS in cpu_load_eflags
2014-05-15 17:30 ` Richard Henderson
@ 2014-05-16 9:34 ` Paolo Bonzini
0 siblings, 0 replies; 5+ messages in thread
From: Paolo Bonzini @ 2014-05-16 9:34 UTC (permalink / raw)
To: Richard Henderson, qemu-devel
Il 15/05/2014 19:30, Richard Henderson ha scritto:
> On 05/15/2014 10:04 AM, Paolo Bonzini wrote:
>> There is no reason to keep that out of the function. The comment refers
>> to the disassembler's cc_op state rather than the CPUState field.
>
> Yes, but...
>
>> -/* NOTE: CC_OP must be modified manually to CC_OP_EFLAGS */
>> +/* NOTE: set CC_OP to CC_OP_EFLAGS after calling a helper that uses this! */
>> static inline void cpu_load_eflags(CPUX86State *env, int eflags,
>> int update_mask)
>> {
>> CC_SRC = eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
>> + CC_OP = CC_OP_EFLAGS;
>> env->df = 1 - (2 * ((eflags >> 10) & 1));
>
> ... we'd do well to reflect that in the comment here, rather than
> in the commit message. Because by itself it looks like the comment
> is out of date.
That's what I tried to do, but my wording was awful.
> /* NOTE: the translator must set DisasContext.cc_op to CC_OP_EFLAGS
> after generating a call to a helper that uses this. */
Much better.
>> --- a/target-i386/svm_helper.c
>> +++ b/target-i386/svm_helper.c
>> @@ -260,7 +260,6 @@ void helper_vmrun(CPUX86State *env, int aflag, int next_eip_addend)
>> env->vm_vmcb + offsetof(struct vmcb,
>> save.rflags)),
>> ~(CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C | DF_MASK));
>> - CC_OP = CC_OP_EFLAGS;
>>
>> svm_load_seg_cache(env, env->vm_vmcb + offsetof(struct vmcb, save.es),
>> R_ES);
>> --
>
> I see two sets of CC_OP in svm_helper.c. Missed one?
Yes.
Paolo
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH] target-i386: set CC_OP to CC_OP_EFLAGS in cpu_load_eflags
@ 2014-05-16 9:36 Paolo Bonzini
2014-05-16 14:51 ` Richard Henderson
0 siblings, 1 reply; 5+ messages in thread
From: Paolo Bonzini @ 2014-05-16 9:36 UTC (permalink / raw)
To: qemu-devel; +Cc: rth
There is no reason to keep that out of the function. The comment refers
to the disassembler's cc_op state rather than the CPUState field.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
target-i386/cpu.h | 5 ++++-
target-i386/seg_helper.c | 2 --
target-i386/smm_helper.c | 2 --
target-i386/svm_helper.c | 2 --
4 files changed, 4 insertions(+), 7 deletions(-)
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index e9cbdab..1c00f1d 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -1234,11 +1234,14 @@ static inline uint32_t cpu_compute_eflags(CPUX86State *env)
return env->eflags | cpu_cc_compute_all(env, CC_OP) | (env->df & DF_MASK);
}
-/* NOTE: CC_OP must be modified manually to CC_OP_EFLAGS */
+/* NOTE: the translator must set DisasContext.cc_op to CC_OP_EFLAGS
+ * after generating a call to a helper that uses this.
+ */
static inline void cpu_load_eflags(CPUX86State *env, int eflags,
int update_mask)
{
CC_SRC = eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
+ CC_OP = CC_OP_EFLAGS;
env->df = 1 - (2 * ((eflags >> 10) & 1));
env->eflags = (env->eflags & ~update_mask) |
(eflags & update_mask) | 0x2;
diff --git a/target-i386/seg_helper.c b/target-i386/seg_helper.c
index 3cf862e..6c0142a 100644
--- a/target-i386/seg_helper.c
+++ b/target-i386/seg_helper.c
@@ -1600,7 +1600,6 @@ void helper_ljmp_protected(CPUX86State *env, int new_cs, target_ulong new_eip,
}
next_eip = env->eip + next_eip_addend;
switch_tss(env, new_cs, e1, e2, SWITCH_TSS_JMP, next_eip);
- CC_OP = CC_OP_EFLAGS;
break;
case 4: /* 286 call gate */
case 12: /* 386 call gate */
@@ -1769,7 +1768,6 @@ void helper_lcall_protected(CPUX86State *env, int new_cs, target_ulong new_eip,
raise_exception_err(env, EXCP0D_GPF, new_cs & 0xfffc);
}
switch_tss(env, new_cs, e1, e2, SWITCH_TSS_CALL, next_eip);
- CC_OP = CC_OP_EFLAGS;
return;
case 4: /* 286 call gate */
case 12: /* 386 call gate */
diff --git a/target-i386/smm_helper.c b/target-i386/smm_helper.c
index 4841d53..2f99493 100644
--- a/target-i386/smm_helper.c
+++ b/target-i386/smm_helper.c
@@ -168,7 +168,6 @@ void do_smm_enter(X86CPU *cpu)
CR0_PG_MASK));
cpu_x86_update_cr4(env, 0);
env->dr[7] = 0x00000400;
- CC_OP = CC_OP_EFLAGS;
cpu_x86_load_seg_cache(env, R_CS, (env->smbase >> 4) & 0xffff, env->smbase,
0xffffffff, 0);
@@ -296,7 +295,6 @@ void helper_rsm(CPUX86State *env)
env->smbase = ldl_phys(cs->as, sm_state + 0x7ef8) & ~0x7fff;
}
#endif
- CC_OP = CC_OP_EFLAGS;
env->hflags &= ~HF_SMM_MASK;
cpu_smm_update(env);
diff --git a/target-i386/svm_helper.c b/target-i386/svm_helper.c
index 846eaa5..8dc6f8c 100644
--- a/target-i386/svm_helper.c
+++ b/target-i386/svm_helper.c
@@ -260,7 +260,6 @@ void helper_vmrun(CPUX86State *env, int aflag, int next_eip_addend)
env->vm_vmcb + offsetof(struct vmcb,
save.rflags)),
~(CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C | DF_MASK));
- CC_OP = CC_OP_EFLAGS;
svm_load_seg_cache(env, env->vm_vmcb + offsetof(struct vmcb, save.es),
R_ES);
@@ -702,7 +701,6 @@ void helper_vmexit(CPUX86State *env, uint32_t exit_code, uint64_t exit_info_1)
save.rflags)),
~(CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C | DF_MASK |
VM_MASK));
- CC_OP = CC_OP_EFLAGS;
svm_load_seg_cache(env, env->vm_hsave + offsetof(struct vmcb, save.es),
R_ES);
--
1.8.3.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] target-i386: set CC_OP to CC_OP_EFLAGS in cpu_load_eflags
2014-05-16 9:36 Paolo Bonzini
@ 2014-05-16 14:51 ` Richard Henderson
0 siblings, 0 replies; 5+ messages in thread
From: Richard Henderson @ 2014-05-16 14:51 UTC (permalink / raw)
To: Paolo Bonzini, qemu-devel
On 05/16/2014 02:36 AM, Paolo Bonzini wrote:
> There is no reason to keep that out of the function. The comment refers
> to the disassembler's cc_op state rather than the CPUState field.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> target-i386/cpu.h | 5 ++++-
> target-i386/seg_helper.c | 2 --
> target-i386/smm_helper.c | 2 --
> target-i386/svm_helper.c | 2 --
> 4 files changed, 4 insertions(+), 7 deletions(-)
Reviewed-by: Richard Henderson <rth@twiddle.net>
r~
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-05-16 14:51 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-15 17:04 [Qemu-devel] [PATCH] target-i386: set CC_OP to CC_OP_EFLAGS in cpu_load_eflags Paolo Bonzini
2014-05-15 17:30 ` Richard Henderson
2014-05-16 9:34 ` Paolo Bonzini
-- strict thread matches above, loose matches on Subject: below --
2014-05-16 9:36 Paolo Bonzini
2014-05-16 14:51 ` Richard Henderson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).