Skip to contentSkip to conversation

target-i386: Fix eflags.TF/#DB handling of syscall/sysret insns

GIT PULL Doug Evans 1 participant 1 message Dec 23, 2016

lore
Share & tools
lore

Doug Evans

author
#0 lore raw

target/i386/translate.c static target_ulong disas_insn(CPUX86State *env,

Quoted 23 lines · Paolo Bonzini

From: Doug Evans <[email protected]>

The syscall and sysret instructions behave a bit differently:
TF is checked after the instruction completes.
This allows the o/s to disable #DB at a syscall by adding TF to FMASK. And then when the sysret is executed the #DB is taken "as if" the syscall insn just completed.

Message-Id: <[email protected]>

---
 target/i386/bpt_helper.c |  7 +++++++
 target/i386/helper.h     |  1 +
 target/i386/translate.c  | 29 ++++++++++++++++++++++++-----
 3 files changed, 32 insertions(+), 5 deletions(-)

...

target/i386/translate.c +0 -0
index 324103c..59e11fc 100644
@@ -6423,7 +6435,10 @@ static target_ulong disas_insn(CPUX86State *env,  

DisasContext *s,

target/i386/translate.c static target_ulong disas_insn(CPUX86State *env, · line 6435

Quoted 1 line
target/i386/translate.c +0 -0
                                       tcg_const_i32(s->pc -  

s->cs_base));

target/i386/translate.c static target_ulong disas_insn(CPUX86State *env, · line 6438

Quoted 4 lines
target/i386/translate.c +1 -1
             set_cc_op(s, CC_OP_EFLAGS);
         }
-        gen_eob(s);
+        /* TF handling for the syscall insn is different. The TF bit is  

checked

target/i386/translate.c static target_ulong disas_insn(CPUX86State *env, · line 6440

Quoted 2 lines
target/i386/translate.c +2 -0
+           after the syscall insn completes. This allows #DB to not be
+           generated after one has entered CPL0 if TF is set in FMASK.   

*/

target/i386/translate.c static target_ulong disas_insn(CPUX86State *env,

Quoted 5 lines
target/i386/translate.c +1 -0
+        gen_eob_worker(s, false, true);
         break;
     case 0xe8: /* call im */
         {
@@ -7115,7 +7130,11 @@ static target_ulong disas_insn(CPUX86State *env,  

DisasContext *s,

target/i386/translate.c static target_ulong disas_insn(CPUX86State *env, · line 7133

Quoted 5 lines
target/i386/translate.c +1 -1
             if (s->lma) {
                 set_cc_op(s, CC_OP_EFLAGS);
             }
-            gen_eob(s);
+            /* TF handling for the sysret insn is different. The TF bit  

is

target/i386/translate.c static target_ulong disas_insn(CPUX86State *env, · line 7134

Quoted 1 line
target/i386/translate.c +1 -0
+               checked after the sysret insn completes. This allows #DB  

to be

target/i386/translate.c static target_ulong disas_insn(CPUX86State *env, · line 7140

Quoted 6 lines
target/i386/translate.c +3 -0
+               generated "as if" the syscall insn in userspace has just
+               completed.  */
+            gen_eob_worker(s, false, true);
         }
         break;
 #endif

Hi. Just a heads up that this patch got applied wrong (patch does that some times).

The change to the "syscall" insn got applied to the "iret" instruction instead.

Working on a fix.