static int kvmppc_get_books_sregs(PowerPCCPU *cpu)

{

    CPUPPCState *env = &cpu->env;

    struct kvm_sregs sregs;

    int ret;

    int i;



    ret = kvm_vcpu_ioctl(CPU(cpu), KVM_GET_SREGS, &sregs);

    if (ret < 0) {

        return ret;

    }



    if (!env->external_htab) {

        ppc_store_sdr1(env, sregs.u.s.sdr1);

    }



    /* Sync SLB */

#ifdef TARGET_PPC64

    /*

     * The packed SLB array we get from KVM_GET_SREGS only contains

     * information about valid entries. So we flush our internal copy

     * to get rid of stale ones, then put all valid SLB entries back

     * in.

     */

    memset(env->slb, 0, sizeof(env->slb));

    for (i = 0; i < ARRAY_SIZE(env->slb); i++) {

        target_ulong rb = sregs.u.s.ppc64.slb[i].slbe;

        target_ulong rs = sregs.u.s.ppc64.slb[i].slbv;

        /*

         * Only restore valid entries

         */

        if (rb & SLB_ESID_V) {

            ppc_store_slb(cpu, rb & 0xfff, rb & ~0xfffULL, rs);

        }

    }

#endif



    /* Sync SRs */

    for (i = 0; i < 16; i++) {

        env->sr[i] = sregs.u.s.ppc32.sr[i];

    }



    /* Sync BATs */

    for (i = 0; i < 8; i++) {

        env->DBAT[0][i] = sregs.u.s.ppc32.dbat[i] & 0xffffffff;

        env->DBAT[1][i] = sregs.u.s.ppc32.dbat[i] >> 32;

        env->IBAT[0][i] = sregs.u.s.ppc32.ibat[i] & 0xffffffff;

        env->IBAT[1][i] = sregs.u.s.ppc32.ibat[i] >> 32;

    }



    return 0;

}

static int kvmppc_get_books_sregs(PowerPCCPU *cpu)

{

    CPUPPCState *env = &cpu->env;

    struct kvm_sregs sregs;

    int ret;

    int i;



    ret = kvm_vcpu_ioctl(CPU(cpu), KVM_GET_SREGS, &sregs);

    if (ret < 0) {

        return ret;

    }



    if (!env->external_htab) {

        ppc_store_sdr1(env, sregs.u.s.sdr1);

    }



    

#ifdef TARGET_PPC64

    











    memset(env->slb, 0, sizeof(env->slb));

    for (i = 0; i < ARRAY_SIZE(env->slb); i++) {

        target_ulong rb = sregs.u.s.ppc64.slb[i].slbe;

        target_ulong rs = sregs.u.s.ppc64.slb[i].slbv;

        





        if (rb & SLB_ESID_V) {

            ppc_store_slb(cpu, rb & 0xfff, rb & ~0xfffULL, rs);

        }

    }

#endif



    

    for (i = 0; i < 16; i++) {

        env->sr[i] = sregs.u.s.ppc32.sr[i];

    }



    

    for (i = 0; i < 8; i++) {

        env->DBAT[0][i] = sregs.u.s.ppc32.dbat[i] & 0xffffffff;

        env->DBAT[1][i] = sregs.u.s.ppc32.dbat[i] >> 32;

        env->IBAT[0][i] = sregs.u.s.ppc32.ibat[i] & 0xffffffff;

        env->IBAT[1][i] = sregs.u.s.ppc32.ibat[i] >> 32;

    }



    return 0;

}

static int FUNC_0(PowerPCCPU *VAR_0)

{

    CPUPPCState *env = &VAR_0->env;

    struct kvm_sregs VAR_1;

    int VAR_2;

    int VAR_3;



    VAR_2 = kvm_vcpu_ioctl(CPU(VAR_0), KVM_GET_SREGS, &VAR_1);

    if (VAR_2 < 0) {

        return VAR_2;

    }



    if (!env->external_htab) {

        ppc_store_sdr1(env, VAR_1.u.s.sdr1);

    }



    

#ifdef TARGET_PPC64

    











    memset(env->slb, 0, sizeof(env->slb));

    for (VAR_3 = 0; VAR_3 < ARRAY_SIZE(env->slb); VAR_3++) {

        target_ulong rb = VAR_1.u.s.ppc64.slb[VAR_3].slbe;

        target_ulong rs = VAR_1.u.s.ppc64.slb[VAR_3].slbv;

        





        if (rb & SLB_ESID_V) {

            ppc_store_slb(VAR_0, rb & 0xfff, rb & ~0xfffULL, rs);

        }

    }

#endif



    

    for (VAR_3 = 0; VAR_3 < 16; VAR_3++) {

        env->sr[VAR_3] = VAR_1.u.s.ppc32.sr[VAR_3];

    }



    

    for (VAR_3 = 0; VAR_3 < 8; VAR_3++) {

        env->DBAT[0][VAR_3] = VAR_1.u.s.ppc32.dbat[VAR_3] & 0xffffffff;

        env->DBAT[1][VAR_3] = VAR_1.u.s.ppc32.dbat[VAR_3] >> 32;

        env->IBAT[0][VAR_3] = VAR_1.u.s.ppc32.ibat[VAR_3] & 0xffffffff;

        env->IBAT[1][VAR_3] = VAR_1.u.s.ppc32.ibat[VAR_3] >> 32;

    }



    return 0;

}

static int FUNC_0(PowerPCCPU *VAR_0)
{ CPUPPCState *env = &VAR_0->env; struct kvm_sregs VAR_1; int VAR_2; int VAR_3; VAR_2 = kvm_vcpu_ioctl(CPU(VAR_0), KVM_GET_SREGS, &VAR_1); if (VAR_2 < 0) { return VAR_2; } if (!env->external_htab) { ppc_store_sdr1(env, VAR_1.u.s.sdr1); } #ifdef TARGET_PPC64
memset(env->slb, 0, sizeof(env->slb)); for (VAR_3 = 0; VAR_3 < ARRAY_SIZE(env->slb); VAR_3++) { target_ulong rb = VAR_1.u.s.ppc64.slb[VAR_3].slbe; target_ulong rs = VAR_1.u.s.ppc64.slb[VAR_3].slbv; if (rb & SLB_ESID_V) { ppc_store_slb(VAR_0, rb & 0xfff, rb & ~0xfffULL, rs); } } #endif
for (VAR_3 = 0; VAR_3 < 16; VAR_3++) { env->sr[VAR_3] = VAR_1.u.s.ppc32.sr[VAR_3]; } for (VAR_3 = 0; VAR_3 < 8; VAR_3++) { env->DBAT[0][VAR_3] = VAR_1.u.s.ppc32.dbat[VAR_3] & 0xffffffff; env->DBAT[1][VAR_3] = VAR_1.u.s.ppc32.dbat[VAR_3] >> 32; env->IBAT[0][VAR_3] = VAR_1.u.s.ppc32.ibat[VAR_3] & 0xffffffff; env->IBAT[1][VAR_3] = VAR_1.u.s.ppc32.ibat[VAR_3] >> 32; } return 0; }