static int save_user_regs(CPUPPCState *env, struct target_mcontext *frame,

                          int sigret)

{

    target_ulong msr = env->msr;

    int i;

    target_ulong ccr = 0;



    /* In general, the kernel attempts to be intelligent about what it

       needs to save for Altivec/FP/SPE registers.  We don't care that

       much, so we just go ahead and save everything.  */



    /* Save general registers.  */

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

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

            return 1;

        }

    }

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

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

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

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

        return 1;



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

        ccr |= env->crf[i] << (32 - ((i + 1) * 4));

    }

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

        return 1;



    /* Save 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 (__put_user(avr->u64[0], &vreg->u64[0]) ||

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

                return 1;

            }

        }

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

           frame->mc_vregs contains valid data.  */

        msr |= MSR_VR;

        if (__put_user((uint32_t)env->spr[SPR_VRSAVE],

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

            return 1;

    }



    /* Save floating point registers.  */

    if (env->insns_flags & PPC_FLOAT) {

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

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

                return 1;

            }

        }

        if (__put_user((uint64_t) env->fpscr, &frame->mc_fregs[32]))

            return 1;

    }



    /* 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++) {

            if (__put_user(env->gpr[i] >> 32, &frame->mc_vregs.spe[i])) {

                return 1;

            }

        }

#else

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

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

                return 1;

            }

        }

#endif

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

           frame->mc_vregs contains valid data.  */

        msr |= MSR_SPE;

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

            return 1;

    }



    /* Store MSR.  */

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

        return 1;



    /* Set up the sigreturn trampoline: li r0,sigret; sc.  */

    if (sigret) {

        if (__put_user(0x38000000UL | sigret, &frame->tramp[0]) ||

            __put_user(0x44000002UL, &frame->tramp[1])) {

            return 1;

        }

    }



    return 0;

}

static int save_user_regs(CPUPPCState *env, struct target_mcontext *frame,

                          int sigret)

{

    target_ulong msr = env->msr;

    int i;

    target_ulong ccr = 0;



    







    

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

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

            return 1;

        }

    }

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

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

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

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

        return 1;



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

        ccr |= env->crf[i] << (32 - ((i + 1) * 4));

    }

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

        return 1;



    

    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 (__put_user(avr->u64[0], &vreg->u64[0]) ||

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

                return 1;

            }

        }

        



        msr |= MSR_VR;

        if (__put_user((uint32_t)env->spr[SPR_VRSAVE],

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

            return 1;

    }



    

    if (env->insns_flags & PPC_FLOAT) {

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

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

                return 1;

            }

        }

        if (__put_user((uint64_t) env->fpscr, &frame->mc_fregs[32]))

            return 1;

    }



    

    if (env->insns_flags & PPC_SPE) {

#if defined(TARGET_PPC64)

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

            if (__put_user(env->gpr[i] >> 32, &frame->mc_vregs.spe[i])) {

                return 1;

            }

        }

#else

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

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

                return 1;

            }

        }

#endif

        



        msr |= MSR_SPE;

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

            return 1;

    }



    

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

        return 1;



    

    if (sigret) {

        if (__put_user(0x38000000UL | sigret, &frame->tramp[0]) ||

            __put_user(0x44000002UL, &frame->tramp[1])) {

            return 1;

        }

    }



    return 0;

}

static int FUNC_0(CPUPPCState *VAR_0, struct target_mcontext *VAR_1,

                          int VAR_2)

{

    target_ulong msr = VAR_0->msr;

    int VAR_3;

    target_ulong ccr = 0;



    







    

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

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

            return 1;

        }

    }

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

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

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

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

        return 1;



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

        ccr |= VAR_0->crf[VAR_3] << (32 - ((VAR_3 + 1) * 4));

    }

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

        return 1;



    

    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 (__put_user(avr->u64[0], &vreg->u64[0]) ||

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

                return 1;

            }

        }

        



        msr |= MSR_VR;

        if (__put_user((uint32_t)VAR_0->spr[SPR_VRSAVE],

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

            return 1;

    }



    

    if (VAR_0->insns_flags & PPC_FLOAT) {

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

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

                return 1;

            }

        }

        if (__put_user((uint64_t) VAR_0->fpscr, &VAR_1->mc_fregs[32]))

            return 1;

    }



    

    if (VAR_0->insns_flags & PPC_SPE) {

#if defined(TARGET_PPC64)

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

            if (__put_user(VAR_0->gpr[VAR_3] >> 32, &VAR_1->mc_vregs.spe[VAR_3])) {

                return 1;

            }

        }

#else

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

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

                return 1;

            }

        }

#endif

        



        msr |= MSR_SPE;

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

            return 1;

    }



    

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

        return 1;



    

    if (VAR_2) {

        if (__put_user(0x38000000UL | VAR_2, &VAR_1->tramp[0]) ||

            __put_user(0x44000002UL, &VAR_1->tramp[1])) {

            return 1;

        }

    }



    return 0;

}

static int FUNC_0(CPUPPCState *VAR_0, struct target_mcontext *VAR_1,
int VAR_2)
{ target_ulong msr = VAR_0->msr; int VAR_3; target_ulong ccr = 0; for (VAR_3 = 0; VAR_3 < ARRAY_SIZE(VAR_0->gpr); VAR_3++) { if (__put_user(VAR_0->gpr[VAR_3], &VAR_1->mc_gregs[VAR_3])) { return 1; } } if (__put_user(VAR_0->nip, &VAR_1->mc_gregs[TARGET_PT_NIP])
|| __put_user(VAR_0->ctr, &VAR_1->mc_gregs[TARGET_PT_CTR])
|| __put_user(VAR_0->lr, &VAR_1->mc_gregs[TARGET_PT_LNK])
|| __put_user(VAR_0->xer, &VAR_1->mc_gregs[TARGET_PT_XER]))
return 1; for (VAR_3 = 0; VAR_3 < ARRAY_SIZE(VAR_0->crf); VAR_3++) { ccr |= VAR_0->crf[VAR_3] << (32 - ((VAR_3 + 1) * 4)); } if (__put_user(ccr, &VAR_1->mc_gregs[TARGET_PT_CCR]))
return 1; 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 (__put_user(avr->u64[0], &vreg->u64[0]) ||
__put_user(avr->u64[1], &vreg->u64[1])) { return 1; } } msr |= MSR_VR; if (__put_user((uint32_t)VAR_0->spr[SPR_VRSAVE],
&VAR_1->mc_vregs.altivec[32].u32[3]))
return 1; } if (VAR_0->insns_flags & PPC_FLOAT) { for (VAR_3 = 0; VAR_3 < ARRAY_SIZE(VAR_0->fpr); VAR_3++) { if (__put_user(VAR_0->fpr[VAR_3], &VAR_1->mc_fregs[VAR_3])) { return 1; } } if (__put_user((uint64_t) VAR_0->fpscr, &VAR_1->mc_fregs[32]))
return 1; } if (VAR_0->insns_flags & PPC_SPE) { #if defined(TARGET_PPC64)
for (VAR_3 = 0; VAR_3 < ARRAY_SIZE(VAR_0->gpr); VAR_3++) { if (__put_user(VAR_0->gpr[VAR_3] >> 32, &VAR_1->mc_vregs.spe[VAR_3])) { return 1; } } #else
for (VAR_3 = 0; VAR_3 < ARRAY_SIZE(VAR_0->gprh); VAR_3++) { if (__put_user(VAR_0->gprh[VAR_3], &VAR_1->mc_vregs.spe[VAR_3])) { return 1; } } #endif
msr |= MSR_SPE; if (__put_user(VAR_0->spe_fscr, &VAR_1->mc_vregs.spe[32]))
return 1; } if (__put_user(msr, &VAR_1->mc_gregs[TARGET_PT_MSR]))
return 1; if (VAR_2) { if (__put_user(0x38000000UL | VAR_2, &VAR_1->tramp[0]) ||
__put_user(0x44000002UL, &VAR_1->tramp[1])) { return 1; } } return 0; }