Commit 967f4da2 authored by Roman Bolshakov's avatar Roman Bolshakov Committed by Paolo Bonzini
Browse files

i386: hvf: Drop rflags from HVFX86EmulatorState



HVFX86EmulatorState carries it's own copy of x86 flags. It can be
dropped in favor of eflags in generic CPUX86State.

Signed-off-by: default avatarRoman Bolshakov <r.bolshakov@yadro.com>
Message-Id: <20200528193758.51454-9-r.bolshakov@yadro.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 2d5f696c
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -723,8 +723,7 @@ int hvf_vcpu_exec(CPUState *cpu)

        hvf_store_events(cpu, ins_len, idtvec_info);
        rip = rreg(cpu->hvf_fd, HV_X86_RIP);
        RFLAGS(env) = rreg(cpu->hvf_fd, HV_X86_RFLAGS);
        env->eflags = RFLAGS(env);
        env->eflags = rreg(cpu->hvf_fd, HV_X86_RFLAGS);

        qemu_mutex_lock_iothread();

@@ -736,7 +735,7 @@ int hvf_vcpu_exec(CPUState *cpu)
        case EXIT_REASON_HLT: {
            macvm_set_rip(cpu, rip + ins_len);
            if (!((cpu->interrupt_request & CPU_INTERRUPT_HARD) &&
                (EFLAGS(env) & IF_MASK))
                (env->eflags & IF_MASK))
                && !(cpu->interrupt_request & CPU_INTERRUPT_NMI) &&
                !(idtvec_info & VMCS_IDT_VEC_VALID)) {
                cpu->halted = 1;
+1 −1
Original line number Diff line number Diff line
@@ -131,7 +131,7 @@ bool x86_is_v8086(struct CPUState *cpu)
{
    X86CPU *x86_cpu = X86_CPU(cpu);
    CPUX86State *env = &x86_cpu->env;
    return x86_is_protected(cpu) && (RFLAGS(env) & RFLAGS_VM);
    return x86_is_protected(cpu) && (env->eflags & RFLAGS_VM);
}

bool x86_is_long_mode(struct CPUState *cpu)
+0 −42
Original line number Diff line number Diff line
@@ -62,44 +62,6 @@ typedef enum x86_rflags {
    RFLAGS_ID       = (1L << 21),
} x86_rflags;

/* rflags register */
typedef struct x86_reg_flags {
    union {
        struct {
            uint64_t rflags;
        };
        struct {
            uint32_t eflags;
            uint32_t hi32_unused1;
        };
        struct {
            uint32_t cf:1;
            uint32_t unused1:1;
            uint32_t pf:1;
            uint32_t unused2:1;
            uint32_t af:1;
            uint32_t unused3:1;
            uint32_t zf:1;
            uint32_t sf:1;
            uint32_t tf:1;
            uint32_t ief:1;
            uint32_t df:1;
            uint32_t of:1;
            uint32_t iopl:2;
            uint32_t nt:1;
            uint32_t unused4:1;
            uint32_t rf:1;
            uint32_t vm:1;
            uint32_t ac:1;
            uint32_t vif:1;
            uint32_t vip:1;
            uint32_t id:1;
            uint32_t unused5:10;
            uint32_t hi32_unused2;
        };
    };
} __attribute__ ((__packed__)) x86_reg_flags;

typedef enum x86_reg_cr0 {
    CR0_PE =            (1L << 0),
    CR0_MP =            (1L << 1),
@@ -294,15 +256,11 @@ typedef struct lazy_flags {
/* Definition of hvf_x86_state is here */
struct HVFX86EmulatorState {
    struct x86_register regs[16];
    struct x86_reg_flags   rflags;
    struct lazy_flags   lflags;
    uint8_t mmio_buf[4096];
};

/* useful register access  macros */
#define RFLAGS(cpu) (cpu->hvf_emul->rflags.rflags)
#define EFLAGS(cpu) (cpu->hvf_emul->rflags.eflags)

#define RRX(cpu, reg) (cpu->hvf_emul->regs[reg].rrx)
#define RAX(cpu)        RRX(cpu, R_EAX)
#define RCX(cpu)        RRX(cpu, R_ECX)
+3 −3
Original line number Diff line number Diff line
@@ -459,7 +459,7 @@ static inline void string_increment_reg(struct CPUX86State *env, int reg,
                                        struct x86_decode *decode)
{
    target_ulong val = read_reg(env, reg, decode->addressing_size);
    if (env->hvf_emul->rflags.df) {
    if (env->eflags & DF_MASK) {
        val -= decode->operand_size;
    } else {
        val += decode->operand_size;
@@ -1432,7 +1432,7 @@ void load_regs(struct CPUState *cpu)
        RRX(env, i) = rreg(cpu->hvf_fd, HV_X86_RAX + i);
    }

    RFLAGS(env) = rreg(cpu->hvf_fd, HV_X86_RFLAGS);
    env->eflags = rreg(cpu->hvf_fd, HV_X86_RFLAGS);
    rflags_to_lflags(env);
    env->eip = rreg(cpu->hvf_fd, HV_X86_RIP);
}
@@ -1456,7 +1456,7 @@ void store_regs(struct CPUState *cpu)
    }

    lflags_to_rflags(env);
    wreg(cpu->hvf_fd, HV_X86_RFLAGS, RFLAGS(env));
    wreg(cpu->hvf_fd, HV_X86_RFLAGS, env->eflags);
    macvm_set_rip(cpu, env->eip);
}

+12 −12
Original line number Diff line number Diff line
@@ -295,21 +295,21 @@ void set_SF(CPUX86State *env, bool val)

void lflags_to_rflags(CPUX86State *env)
{
    env->hvf_emul->rflags.cf = get_CF(env);
    env->hvf_emul->rflags.pf = get_PF(env);
    env->hvf_emul->rflags.af = get_AF(env);
    env->hvf_emul->rflags.zf = get_ZF(env);
    env->hvf_emul->rflags.sf = get_SF(env);
    env->hvf_emul->rflags.of = get_OF(env);
    env->eflags |= get_CF(env) ? CC_C : 0;
    env->eflags |= get_PF(env) ? CC_P : 0;
    env->eflags |= get_AF(env) ? CC_A : 0;
    env->eflags |= get_ZF(env) ? CC_Z : 0;
    env->eflags |= get_SF(env) ? CC_S : 0;
    env->eflags |= get_OF(env) ? CC_O : 0;
}

void rflags_to_lflags(CPUX86State *env)
{
    env->hvf_emul->lflags.auxbits = env->hvf_emul->lflags.result = 0;
    set_OF(env, env->hvf_emul->rflags.of);
    set_SF(env, env->hvf_emul->rflags.sf);
    set_ZF(env, env->hvf_emul->rflags.zf);
    set_AF(env, env->hvf_emul->rflags.af);
    set_PF(env, env->hvf_emul->rflags.pf);
    set_CF(env, env->hvf_emul->rflags.cf);
    set_OF(env, env->eflags & CC_O);
    set_SF(env, env->eflags & CC_S);
    set_ZF(env, env->eflags & CC_Z);
    set_AF(env, env->eflags & CC_A);
    set_PF(env, env->eflags & CC_P);
    set_CF(env, env->eflags & CC_C);
}
Loading