static int restore_user_regs(CPUPPCState *env,

                             struct target_mcontext *frame, int sig)

{

    target_ulong save_r2 = 0;

    target_ulong msr;

    target_ulong ccr;



    int i;



    if (!sig) {

        save_r2 = env->gpr[2];

    }



    /* Restore general registers.  */

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

        if (__get_user(env->gpr[i], &frame->mc_gregs[i])) {

            return 1;

        }

    }

    if (__get_user(env->nip, &frame->mc_gregs[TARGET_PT_NIP])

        || __get_user(env->ctr, &frame->mc_gregs[TARGET_PT_CTR])

        || __get_user(env->lr, &frame->mc_gregs[TARGET_PT_LNK])

        || __get_user(env->xer, &frame->mc_gregs[TARGET_PT_XER]))

        return 1;

    if (__get_user(ccr, &frame->mc_gregs[TARGET_PT_CCR]))

        return 1;



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

        env->crf[i] = (ccr >> (32 - ((i + 1) * 4))) & 0xf;

    }



    if (!sig) {

        env->gpr[2] = save_r2;

    }

    /* Restore MSR.  */

    if (__get_user(msr, &frame->mc_gregs[TARGET_PT_MSR]))

        return 1;



    /* If doing signal return, restore the previous little-endian mode.  */

    if (sig)

        env->msr = (env->msr & ~MSR_LE) | (msr & MSR_LE);



    /* Restore Altivec registers if necessary.  */

    if (env->insns_flags & PPC_ALTIVEC) {

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

            ppc_avr_t *avr = &env->avr[i];

            ppc_avr_t *vreg = &frame->mc_vregs.altivec[i];



            if (__get_user(avr->u64[0], &vreg->u64[0]) ||

                __get_user(avr->u64[1], &vreg->u64[1])) {

                return 1;

            }

        }

        /* Set MSR_VEC in the saved MSR value to indicate that

           frame->mc_vregs contains valid data.  */

        if (__get_user(env->spr[SPR_VRSAVE],

                       (target_ulong *)(&frame->mc_vregs.altivec[32].u32[3])))

            return 1;

    }



    /* Restore floating point registers.  */

    if (env->insns_flags & PPC_FLOAT) {

        uint64_t fpscr;

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

            if (__get_user(env->fpr[i], &frame->mc_fregs[i])) {

                return 1;

            }

        }

        if (__get_user(fpscr, &frame->mc_fregs[32]))

            return 1;

        env->fpscr = (uint32_t) fpscr;

    }



    /* Save SPE registers.  The kernel only saves the high half.  */

    if (env->insns_flags & PPC_SPE) {

#if defined(TARGET_PPC64)

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

            uint32_t hi;



            if (__get_user(hi, &frame->mc_vregs.spe[i])) {

                return 1;

            }

            env->gpr[i] = ((uint64_t)hi << 32) | ((uint32_t) env->gpr[i]);

        }

#else

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

            if (__get_user(env->gprh[i], &frame->mc_vregs.spe[i])) {

                return 1;

            }

        }

#endif

        if (__get_user(env->spe_fscr, &frame->mc_vregs.spe[32]))

            return 1;

    }



    return 0;

}

static int restore_user_regs(CPUPPCState *env,

                             struct target_mcontext *frame, int sig)

{

    target_ulong save_r2 = 0;

    target_ulong msr;

    target_ulong ccr;



    int i;



    if (!sig) {

        save_r2 = env->gpr[2];

    }



    

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

        if (__get_user(env->gpr[i], &frame->mc_gregs[i])) {

            return 1;

        }

    }

    if (__get_user(env->nip, &frame->mc_gregs[TARGET_PT_NIP])

        || __get_user(env->ctr, &frame->mc_gregs[TARGET_PT_CTR])

        || __get_user(env->lr, &frame->mc_gregs[TARGET_PT_LNK])

        || __get_user(env->xer, &frame->mc_gregs[TARGET_PT_XER]))

        return 1;

    if (__get_user(ccr, &frame->mc_gregs[TARGET_PT_CCR]))

        return 1;



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

        env->crf[i] = (ccr >> (32 - ((i + 1) * 4))) & 0xf;

    }



    if (!sig) {

        env->gpr[2] = save_r2;

    }

    

    if (__get_user(msr, &frame->mc_gregs[TARGET_PT_MSR]))

        return 1;



    

    if (sig)

        env->msr = (env->msr & ~MSR_LE) | (msr & MSR_LE);



    

    if (env->insns_flags & PPC_ALTIVEC) {

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

            ppc_avr_t *avr = &env->avr[i];

            ppc_avr_t *vreg = &frame->mc_vregs.altivec[i];



            if (__get_user(avr->u64[0], &vreg->u64[0]) ||

                __get_user(avr->u64[1], &vreg->u64[1])) {

                return 1;

            }

        }

        



        if (__get_user(env->spr[SPR_VRSAVE],

                       (target_ulong *)(&frame->mc_vregs.altivec[32].u32[3])))

            return 1;

    }



    

    if (env->insns_flags & PPC_FLOAT) {

        uint64_t fpscr;

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

            if (__get_user(env->fpr[i], &frame->mc_fregs[i])) {

                return 1;

            }

        }

        if (__get_user(fpscr, &frame->mc_fregs[32]))

            return 1;

        env->fpscr = (uint32_t) fpscr;

    }



    

    if (env->insns_flags & PPC_SPE) {

#if defined(TARGET_PPC64)

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

            uint32_t hi;



            if (__get_user(hi, &frame->mc_vregs.spe[i])) {

                return 1;

            }

            env->gpr[i] = ((uint64_t)hi << 32) | ((uint32_t) env->gpr[i]);

        }

#else

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

            if (__get_user(env->gprh[i], &frame->mc_vregs.spe[i])) {

                return 1;

            }

        }

#endif

        if (__get_user(env->spe_fscr, &frame->mc_vregs.spe[32]))

            return 1;

    }



    return 0;

}

static int FUNC_0(CPUPPCState *VAR_0,

                             struct target_mcontext *VAR_1, int VAR_2)

{

    target_ulong save_r2 = 0;

    target_ulong msr;

    target_ulong ccr;



    int VAR_3;



    if (!VAR_2) {

        save_r2 = VAR_0->gpr[2];

    }



    

    for (VAR_3 = 0; VAR_3 < ARRAY_SIZE(VAR_0->gpr); VAR_3++) {

        if (__get_user(VAR_0->gpr[VAR_3], &VAR_1->mc_gregs[VAR_3])) {

            return 1;

        }

    }

    if (__get_user(VAR_0->nip, &VAR_1->mc_gregs[TARGET_PT_NIP])

        || __get_user(VAR_0->ctr, &VAR_1->mc_gregs[TARGET_PT_CTR])

        || __get_user(VAR_0->lr, &VAR_1->mc_gregs[TARGET_PT_LNK])

        || __get_user(VAR_0->xer, &VAR_1->mc_gregs[TARGET_PT_XER]))

        return 1;

    if (__get_user(ccr, &VAR_1->mc_gregs[TARGET_PT_CCR]))

        return 1;



    for (VAR_3 = 0; VAR_3 < ARRAY_SIZE(VAR_0->crf); VAR_3++) {

        VAR_0->crf[VAR_3] = (ccr >> (32 - ((VAR_3 + 1) * 4))) & 0xf;

    }



    if (!VAR_2) {

        VAR_0->gpr[2] = save_r2;

    }

    

    if (__get_user(msr, &VAR_1->mc_gregs[TARGET_PT_MSR]))

        return 1;



    

    if (VAR_2)

        VAR_0->msr = (VAR_0->msr & ~MSR_LE) | (msr & MSR_LE);



    

    if (VAR_0->insns_flags & PPC_ALTIVEC) {

        for (VAR_3 = 0; VAR_3 < ARRAY_SIZE(VAR_0->avr); VAR_3++) {

            ppc_avr_t *avr = &VAR_0->avr[VAR_3];

            ppc_avr_t *vreg = &VAR_1->mc_vregs.altivec[VAR_3];



            if (__get_user(avr->u64[0], &vreg->u64[0]) ||

                __get_user(avr->u64[1], &vreg->u64[1])) {

                return 1;

            }

        }

        



        if (__get_user(VAR_0->spr[SPR_VRSAVE],

                       (target_ulong *)(&VAR_1->mc_vregs.altivec[32].u32[3])))

            return 1;

    }



    

    if (VAR_0->insns_flags & PPC_FLOAT) {

        uint64_t fpscr;

        for (VAR_3 = 0; VAR_3 < ARRAY_SIZE(VAR_0->fpr); VAR_3++) {

            if (__get_user(VAR_0->fpr[VAR_3], &VAR_1->mc_fregs[VAR_3])) {

                return 1;

            }

        }

        if (__get_user(fpscr, &VAR_1->mc_fregs[32]))

            return 1;

        VAR_0->fpscr = (uint32_t) fpscr;

    }



    

    if (VAR_0->insns_flags & PPC_SPE) {

#if defined(TARGET_PPC64)

        for (VAR_3 = 0; VAR_3 < ARRAY_SIZE(VAR_0->gpr); VAR_3++) {

            uint32_t hi;



            if (__get_user(hi, &VAR_1->mc_vregs.spe[VAR_3])) {

                return 1;

            }

            VAR_0->gpr[VAR_3] = ((uint64_t)hi << 32) | ((uint32_t) VAR_0->gpr[VAR_3]);

        }

#else

        for (VAR_3 = 0; VAR_3 < ARRAY_SIZE(VAR_0->gprh); VAR_3++) {

            if (__get_user(VAR_0->gprh[VAR_3], &VAR_1->mc_vregs.spe[VAR_3])) {

                return 1;

            }

        }

#endif

        if (__get_user(VAR_0->spe_fscr, &VAR_1->mc_vregs.spe[32]))

            return 1;

    }



    return 0;

}

static int FUNC_0(CPUPPCState *VAR_0,
struct target_mcontext *VAR_1, int VAR_2)
{ target_ulong save_r2 = 0; target_ulong msr; target_ulong ccr; int VAR_3; if (!VAR_2) { save_r2 = VAR_0->gpr[2]; } for (VAR_3 = 0; VAR_3 < ARRAY_SIZE(VAR_0->gpr); VAR_3++) { if (__get_user(VAR_0->gpr[VAR_3], &VAR_1->mc_gregs[VAR_3])) { return 1; } } if (__get_user(VAR_0->nip, &VAR_1->mc_gregs[TARGET_PT_NIP])
|| __get_user(VAR_0->ctr, &VAR_1->mc_gregs[TARGET_PT_CTR])
|| __get_user(VAR_0->lr, &VAR_1->mc_gregs[TARGET_PT_LNK])
|| __get_user(VAR_0->xer, &VAR_1->mc_gregs[TARGET_PT_XER]))
return 1; if (__get_user(ccr, &VAR_1->mc_gregs[TARGET_PT_CCR]))
return 1; for (VAR_3 = 0; VAR_3 < ARRAY_SIZE(VAR_0->crf); VAR_3++) { VAR_0->crf[VAR_3] = (ccr >> (32 - ((VAR_3 + 1) * 4))) & 0xf; } if (!VAR_2) { VAR_0->gpr[2] = save_r2; } if (__get_user(msr, &VAR_1->mc_gregs[TARGET_PT_MSR]))
return 1; if (VAR_2)
VAR_0->msr = (VAR_0->msr & ~MSR_LE) | (msr & MSR_LE); if (VAR_0->insns_flags & PPC_ALTIVEC) { for (VAR_3 = 0; VAR_3 < ARRAY_SIZE(VAR_0->avr); VAR_3++) { ppc_avr_t *avr = &VAR_0->avr[VAR_3]; ppc_avr_t *vreg = &VAR_1->mc_vregs.altivec[VAR_3]; if (__get_user(avr->u64[0], &vreg->u64[0]) ||
__get_user(avr->u64[1], &vreg->u64[1])) { return 1; } } if (__get_user(VAR_0->spr[SPR_VRSAVE],
(target_ulong *)(&VAR_1->mc_vregs.altivec[32].u32[3])))
return 1; } if (VAR_0->insns_flags & PPC_FLOAT) { uint64_t fpscr; for (VAR_3 = 0; VAR_3 < ARRAY_SIZE(VAR_0->fpr); VAR_3++) { if (__get_user(VAR_0->fpr[VAR_3], &VAR_1->mc_fregs[VAR_3])) { return 1; } } if (__get_user(fpscr, &VAR_1->mc_fregs[32]))
return 1; VAR_0->fpscr = (uint32_t) fpscr; } if (VAR_0->insns_flags & PPC_SPE) { #if defined(TARGET_PPC64)
for (VAR_3 = 0; VAR_3 < ARRAY_SIZE(VAR_0->gpr); VAR_3++) { uint32_t hi; if (__get_user(hi, &VAR_1->mc_vregs.spe[VAR_3])) { return 1; } VAR_0->gpr[VAR_3] = ((uint64_t)hi << 32) | ((uint32_t) VAR_0->gpr[VAR_3]); } #else
for (VAR_3 = 0; VAR_3 < ARRAY_SIZE(VAR_0->gprh); VAR_3++) { if (__get_user(VAR_0->gprh[VAR_3], &VAR_1->mc_vregs.spe[VAR_3])) { return 1; } } #endif
if (__get_user(VAR_0->spe_fscr, &VAR_1->mc_vregs.spe[32]))
return 1; } return 0; }