We can easier pass them around if flags are stored in struct
parse_context.

Just a preparation, no functional change so far.

Signed-off-by: Ralf Ramsauer <[email protected]>
---
 hypervisor/arch/x86/mmio.c | 52 +++++++++++++++++++-------------------
 1 file changed, 26 insertions(+), 26 deletions(-)

diff --git a/hypervisor/arch/x86/mmio.c b/hypervisor/arch/x86/mmio.c
index c04cf449..df8c97a1 100644
--- a/hypervisor/arch/x86/mmio.c
+++ b/hypervisor/arch/x86/mmio.c
@@ -49,6 +49,11 @@ struct parse_context {
        unsigned int count;
        unsigned int size;
        const u8 *inst;
+       bool has_immediate;
+       bool does_write;
+       bool has_rex_w;
+       bool has_rex_r;
+       bool has_addrsz_prefix;
 };
 
 static bool ctx_update(struct parse_context *ctx, u64 *pc, unsigned int 
advance,
@@ -88,12 +93,7 @@ x86_mmio_parse(const struct guest_paging_structures 
*pg_structs, bool is_write)
        struct mmio_instruction inst = { 0 };
        u64 pc = vcpu_vendor_get_rip();
        unsigned int n, skip_len = 0;
-       bool has_immediate = false;
        union opcode op[4] = { };
-       bool does_write = false;
-       bool has_rex_w = false;
-       bool has_rex_r = false;
-       bool has_addrsz_prefix = false;
 
        if (!ctx_update(&ctx, &pc, 0, pg_structs))
                goto error_noinst;
@@ -102,9 +102,9 @@ restart:
        op[0].raw = *ctx.inst;
        if (op[0].rex.code == X86_REX_CODE) {
                if (op[0].rex.w)
-                       has_rex_w = true;
+                       ctx.has_rex_w = true;
                if (op[0].rex.r)
-                       has_rex_r = true;
+                       ctx.has_rex_r = true;
                if (op[0].rex.x)
                        goto error_unsupported;
 
@@ -116,7 +116,7 @@ restart:
        case X86_PREFIX_ADDR_SZ:
                if (!ctx_update(&ctx, &pc, 1, pg_structs))
                        goto error_noinst;
-               has_addrsz_prefix = true;
+               ctx.has_addrsz_prefix = true;
                goto restart;
        case X86_OP_MOVZX_OPC1:
                if (!ctx_update(&ctx, &pc, 1, pg_structs))
@@ -131,33 +131,33 @@ restart:
                break;
        case X86_OP_MOVB_TO_MEM:
                inst.access_size = 1;
-               does_write = true;
+               ctx.does_write = true;
                break;
        case X86_OP_MOV_TO_MEM:
-               inst.access_size = has_rex_w ? 8 : 4;
-               does_write = true;
+               inst.access_size = ctx.has_rex_w ? 8 : 4;
+               ctx.does_write = true;
                break;
        case X86_OP_MOVB_FROM_MEM:
                inst.access_size = 1;
                break;
        case X86_OP_MOV_FROM_MEM:
-               inst.access_size = has_rex_w ? 8 : 4;
+               inst.access_size = ctx.has_rex_w ? 8 : 4;
                break;
        case X86_OP_MOV_IMMEDIATE_TO_MEM:
-               inst.access_size = has_rex_w ? 8 : 4;
-               has_immediate = true;
-               does_write = true;
+               inst.access_size = ctx.has_rex_w ? 8 : 4;
+               ctx.has_immediate = true;
+               ctx.does_write = true;
                break;
        case X86_OP_MOV_MEM_TO_AX:
-               inst.inst_len += get_address_width(has_addrsz_prefix);
-               inst.access_size = has_rex_w ? 8 : 4;
+               inst.inst_len += get_address_width(ctx.has_addrsz_prefix);
+               inst.access_size = ctx.has_rex_w ? 8 : 4;
                inst.in_reg_num = 15;
                goto final;
        case X86_OP_MOV_AX_TO_MEM:
-               inst.inst_len += get_address_width(has_addrsz_prefix);
-               inst.access_size = has_rex_w ? 8 : 4;
+               inst.inst_len += get_address_width(ctx.has_addrsz_prefix);
+               inst.access_size = ctx.has_rex_w ? 8 : 4;
                inst.out_val = guest_regs->by_index[15];
-               does_write = true;
+               ctx.does_write = true;
                goto final;
        default:
                goto error_unsupported;
@@ -168,7 +168,7 @@ restart:
 
        op[2].raw = *ctx.inst;
 
-       if (!does_write && inst.access_size < 4)
+       if (!ctx.does_write && inst.access_size < 4)
                inst.reg_preserve_mask = ~BYTE_MASK(inst.access_size);
 
        /* ensure that we are actually talking about mov imm,<mem> */
@@ -198,14 +198,14 @@ restart:
                goto error_unsupported;
        }
 
-       if (has_rex_r)
+       if (ctx.has_rex_r)
                inst.in_reg_num = 7 - op[2].modrm.reg;
        else if (op[2].modrm.reg == 4)
                goto error_unsupported;
        else
                inst.in_reg_num = 15 - op[2].modrm.reg;
 
-       if (has_immediate) {
+       if (ctx.has_immediate) {
                /* walk any not yet retrieved SIB or displacement bytes */
                if (!ctx_update(&ctx, &pc, skip_len, pg_structs))
                        goto error_noinst;
@@ -218,16 +218,16 @@ restart:
                }
 
                /* sign-extend immediate if the target is 64-bit */
-               if (has_rex_w)
+               if (ctx.has_rex_w)
                        inst.out_val = (s64)(s32)inst.out_val;
        } else {
                inst.inst_len += skip_len;
-               if (does_write)
+               if (ctx.does_write)
                        inst.out_val = guest_regs->by_index[inst.in_reg_num];
        }
 
 final:
-       if (does_write != is_write)
+       if (ctx.does_write != is_write)
                goto error_inconsitent;
 
        inst.inst_len += ctx.count;
-- 
2.21.0

-- 
You received this message because you are subscribed to the Google Groups 
"Jailhouse" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jailhouse-dev/20190606224457.1053-3-ralf.ramsauer%40oth-regensburg.de.
For more options, visit https://groups.google.com/d/optout.

Reply via email to