-
Notifications
You must be signed in to change notification settings - Fork 878
emulate: save/restore host flags in fastop_dispatch #216
Conversation
OK to verify |
emmm I'm investigating another interesting issue in PR#204 recently and finally came to the same root cause as described in this PR, that FLAGS are corrupted after fastop. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In generally, it's better to add PUSHF/POPF at begin/end and adjust stack_arg offset accordingly.
core/emulate_ops.asm
Outdated
@@ -210,11 +210,13 @@ fastop_dispatch: | |||
mov reg_dst, [ebx] | |||
mov reg_src1, [esi] | |||
mov reg_src2, [edi] | |||
pushf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll suggest move PUSHF to beginning, after push ebp. And move POPF to end, before pop ebp. Then change stack_arg(index) by adding another 0x4 offset. No need to change call stack_arg() so that the fastop handler and remaining arguments are still start from index 0.
core/emulate_ops.asm
Outdated
@@ -237,11 +239,13 @@ fastop_dispatch: | |||
mov reg_dst, [rsi] | |||
mov reg_src1, [r10] | |||
mov reg_src2, [r11] | |||
pushf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto. Move this PUSHF to beginning and adjust stack_arg() offset. Move POPF to end.
core/emulate_ops.asm
Outdated
@@ -262,11 +266,13 @@ fastop_dispatch: | |||
mov reg_dst, [r11] | |||
mov reg_src1, [r8] | |||
mov reg_src2, [r9] | |||
pushf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
Looks good to me! Thanks for the patch @jarveson, I also agree with the new |
sure, so something like this then? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new change looks good to me. I'll merge this PR.
@jarveson would you mind update the commit message in your own branch? I'll merge it. |
fastop_dispatch isn't saving/restoring host flags before overwriting with guest flags, which can cause some interesting issues. This fixes that by just pushing and poping host flags before/after executing fastop instruction. Signed-off-by: Jake Arveson <jarveson@gmail.com>
like this? otherwise im not fully sure what you mean |
Exactly. Unlike PR comments, detailed commit msg in original commit will remains in git repo which helps future development. |
fastop_dispatch isn't saving/restoring host flags before overwriting with guest flags, which can cause some interesting issues. This fixes that by just pushing and poping host flags before/after executing fastop instruction.