static int get_segment64(CPUPPCState *env, struct mmu_ctx_hash64 *ctx,

                         target_ulong eaddr, int rw, int type)

{

    hwaddr hash;

    target_ulong vsid;

    int pr, target_page_bits;

    int ret, ret2;



    pr = msr_pr;

    ctx->eaddr = eaddr;

    ppc_slb_t *slb;

    target_ulong pageaddr;

    int segment_bits;



    LOG_MMU("Check SLBs\n");

    slb = slb_lookup(env, eaddr);

    if (!slb) {

        return -5;

    }



    if (slb->vsid & SLB_VSID_B) {

        vsid = (slb->vsid & SLB_VSID_VSID) >> SLB_VSID_SHIFT_1T;

        segment_bits = 40;

    } else {

        vsid = (slb->vsid & SLB_VSID_VSID) >> SLB_VSID_SHIFT;

        segment_bits = 28;

    }



    target_page_bits = (slb->vsid & SLB_VSID_L)

        ? TARGET_PAGE_BITS_16M : TARGET_PAGE_BITS;

    ctx->key = !!(pr ? (slb->vsid & SLB_VSID_KP)

                  : (slb->vsid & SLB_VSID_KS));

    ctx->nx = !!(slb->vsid & SLB_VSID_N);



    pageaddr = eaddr & ((1ULL << segment_bits)

                            - (1ULL << target_page_bits));

    if (slb->vsid & SLB_VSID_B) {

        hash = vsid ^ (vsid << 25) ^ (pageaddr >> target_page_bits);

    } else {

        hash = vsid ^ (pageaddr >> target_page_bits);

    }

    /* Only 5 bits of the page index are used in the AVPN */

    ctx->ptem = (slb->vsid & SLB_VSID_PTEM) |

        ((pageaddr >> 16) & ((1ULL << segment_bits) - 0x80));



    LOG_MMU("pte segment: key=%d nx %d vsid " TARGET_FMT_lx "\n",

            ctx->key, ctx->nx, vsid);

    ret = -1;



    /* Check if instruction fetch is allowed, if needed */

    if (type != ACCESS_CODE || ctx->nx == 0) {

        /* Page address translation */

        LOG_MMU("htab_base " TARGET_FMT_plx " htab_mask " TARGET_FMT_plx

                " hash " TARGET_FMT_plx "\n",

                env->htab_base, env->htab_mask, hash);

        ctx->hash[0] = hash;

        ctx->hash[1] = ~hash;



        /* Initialize real address with an invalid value */

        ctx->raddr = (hwaddr)-1ULL;

        LOG_MMU("0 htab=" TARGET_FMT_plx "/" TARGET_FMT_plx

                " vsid=" TARGET_FMT_lx " ptem=" TARGET_FMT_lx

                " hash=" TARGET_FMT_plx "\n",

                env->htab_base, env->htab_mask, vsid, ctx->ptem,

                ctx->hash[0]);

        /* Primary table lookup */

        ret = find_pte64(env, ctx, 0, rw, type, target_page_bits);

        if (ret < 0) {

            /* Secondary table lookup */

            LOG_MMU("1 htab=" TARGET_FMT_plx "/" TARGET_FMT_plx

                    " vsid=" TARGET_FMT_lx " api=" TARGET_FMT_lx

                    " hash=" TARGET_FMT_plx "\n", env->htab_base,

                    env->htab_mask, vsid, ctx->ptem, ctx->hash[1]);

            ret2 = find_pte64(env, ctx, 1, rw, type, target_page_bits);

            if (ret2 != -1) {

                ret = ret2;

            }

        }

    } else {

        LOG_MMU("No access allowed\n");

        ret = -3;

    }



    return ret;

}

static int get_segment64(CPUPPCState *env, struct mmu_ctx_hash64 *ctx,

                         target_ulong eaddr, int rw, int type)

{

    hwaddr hash;

    target_ulong vsid;

    int pr, target_page_bits;

    int ret, ret2;



    pr = msr_pr;

    ctx->eaddr = eaddr;

    ppc_slb_t *slb;

    target_ulong pageaddr;

    int segment_bits;



    LOG_MMU("Check SLBs\n");

    slb = slb_lookup(env, eaddr);

    if (!slb) {

        return -5;

    }



    if (slb->vsid & SLB_VSID_B) {

        vsid = (slb->vsid & SLB_VSID_VSID) >> SLB_VSID_SHIFT_1T;

        segment_bits = 40;

    } else {

        vsid = (slb->vsid & SLB_VSID_VSID) >> SLB_VSID_SHIFT;

        segment_bits = 28;

    }



    target_page_bits = (slb->vsid & SLB_VSID_L)

        ? TARGET_PAGE_BITS_16M : TARGET_PAGE_BITS;

    ctx->key = !!(pr ? (slb->vsid & SLB_VSID_KP)

                  : (slb->vsid & SLB_VSID_KS));

    ctx->nx = !!(slb->vsid & SLB_VSID_N);



    pageaddr = eaddr & ((1ULL << segment_bits)

                            - (1ULL << target_page_bits));

    if (slb->vsid & SLB_VSID_B) {

        hash = vsid ^ (vsid << 25) ^ (pageaddr >> target_page_bits);

    } else {

        hash = vsid ^ (pageaddr >> target_page_bits);

    }

    

    ctx->ptem = (slb->vsid & SLB_VSID_PTEM) |

        ((pageaddr >> 16) & ((1ULL << segment_bits) - 0x80));



    LOG_MMU("pte segment: key=%d nx %d vsid " TARGET_FMT_lx "\n",

            ctx->key, ctx->nx, vsid);

    ret = -1;



    

    if (type != ACCESS_CODE || ctx->nx == 0) {

        

        LOG_MMU("htab_base " TARGET_FMT_plx " htab_mask " TARGET_FMT_plx

                " hash " TARGET_FMT_plx "\n",

                env->htab_base, env->htab_mask, hash);

        ctx->hash[0] = hash;

        ctx->hash[1] = ~hash;



        

        ctx->raddr = (hwaddr)-1ULL;

        LOG_MMU("0 htab=" TARGET_FMT_plx "/" TARGET_FMT_plx

                " vsid=" TARGET_FMT_lx " ptem=" TARGET_FMT_lx

                " hash=" TARGET_FMT_plx "\n",

                env->htab_base, env->htab_mask, vsid, ctx->ptem,

                ctx->hash[0]);

        

        ret = find_pte64(env, ctx, 0, rw, type, target_page_bits);

        if (ret < 0) {

            

            LOG_MMU("1 htab=" TARGET_FMT_plx "/" TARGET_FMT_plx

                    " vsid=" TARGET_FMT_lx " api=" TARGET_FMT_lx

                    " hash=" TARGET_FMT_plx "\n", env->htab_base,

                    env->htab_mask, vsid, ctx->ptem, ctx->hash[1]);

            ret2 = find_pte64(env, ctx, 1, rw, type, target_page_bits);

            if (ret2 != -1) {

                ret = ret2;

            }

        }

    } else {

        LOG_MMU("No access allowed\n");

        ret = -3;

    }



    return ret;

}

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

                         target_ulong VAR_2, int VAR_3, int VAR_4)

{

    hwaddr hash;

    target_ulong vsid;

    int VAR_5, VAR_6;

    int VAR_7, VAR_8;



    VAR_5 = msr_pr;

    VAR_1->VAR_2 = VAR_2;

    ppc_slb_t *slb;

    target_ulong pageaddr;

    int VAR_9;



    LOG_MMU("Check SLBs\n");

    slb = slb_lookup(VAR_0, VAR_2);

    if (!slb) {

        return -5;

    }



    if (slb->vsid & SLB_VSID_B) {

        vsid = (slb->vsid & SLB_VSID_VSID) >> SLB_VSID_SHIFT_1T;

        VAR_9 = 40;

    } else {

        vsid = (slb->vsid & SLB_VSID_VSID) >> SLB_VSID_SHIFT;

        VAR_9 = 28;

    }



    VAR_6 = (slb->vsid & SLB_VSID_L)

        ? TARGET_PAGE_BITS_16M : TARGET_PAGE_BITS;

    VAR_1->key = !!(VAR_5 ? (slb->vsid & SLB_VSID_KP)

                  : (slb->vsid & SLB_VSID_KS));

    VAR_1->nx = !!(slb->vsid & SLB_VSID_N);



    pageaddr = VAR_2 & ((1ULL << VAR_9)

                            - (1ULL << VAR_6));

    if (slb->vsid & SLB_VSID_B) {

        hash = vsid ^ (vsid << 25) ^ (pageaddr >> VAR_6);

    } else {

        hash = vsid ^ (pageaddr >> VAR_6);

    }

    

    VAR_1->ptem = (slb->vsid & SLB_VSID_PTEM) |

        ((pageaddr >> 16) & ((1ULL << VAR_9) - 0x80));



    LOG_MMU("pte segment: key=%d nx %d vsid " TARGET_FMT_lx "\n",

            VAR_1->key, VAR_1->nx, vsid);

    VAR_7 = -1;



    

    if (VAR_4 != ACCESS_CODE || VAR_1->nx == 0) {

        

        LOG_MMU("htab_base " TARGET_FMT_plx " htab_mask " TARGET_FMT_plx

                " hash " TARGET_FMT_plx "\n",

                VAR_0->htab_base, VAR_0->htab_mask, hash);

        VAR_1->hash[0] = hash;

        VAR_1->hash[1] = ~hash;



        

        VAR_1->raddr = (hwaddr)-1ULL;

        LOG_MMU("0 htab=" TARGET_FMT_plx "/" TARGET_FMT_plx

                " vsid=" TARGET_FMT_lx " ptem=" TARGET_FMT_lx

                " hash=" TARGET_FMT_plx "\n",

                VAR_0->htab_base, VAR_0->htab_mask, vsid, VAR_1->ptem,

                VAR_1->hash[0]);

        

        VAR_7 = find_pte64(VAR_0, VAR_1, 0, VAR_3, VAR_4, VAR_6);

        if (VAR_7 < 0) {

            

            LOG_MMU("1 htab=" TARGET_FMT_plx "/" TARGET_FMT_plx

                    " vsid=" TARGET_FMT_lx " api=" TARGET_FMT_lx

                    " hash=" TARGET_FMT_plx "\n", VAR_0->htab_base,

                    VAR_0->htab_mask, vsid, VAR_1->ptem, VAR_1->hash[1]);

            VAR_8 = find_pte64(VAR_0, VAR_1, 1, VAR_3, VAR_4, VAR_6);

            if (VAR_8 != -1) {

                VAR_7 = VAR_8;

            }

        }

    } else {

        LOG_MMU("No access allowed\n");

        VAR_7 = -3;

    }



    return VAR_7;

}

static int FUNC_0(CPUPPCState *VAR_0, struct mmu_ctx_hash64 *VAR_1,
target_ulong VAR_2, int VAR_3, int VAR_4)
{ hwaddr hash; target_ulong vsid; int VAR_5, VAR_6; int VAR_7, VAR_8; VAR_5 = msr_pr; VAR_1->VAR_2 = VAR_2; ppc_slb_t *slb; target_ulong pageaddr; int VAR_9; LOG_MMU("Check SLBs\n"); slb = slb_lookup(VAR_0, VAR_2); if (!slb) { return -5; } if (slb->vsid & SLB_VSID_B) { vsid = (slb->vsid & SLB_VSID_VSID) >> SLB_VSID_SHIFT_1T; VAR_9 = 40; } else { vsid = (slb->vsid & SLB_VSID_VSID) >> SLB_VSID_SHIFT; VAR_9 = 28; } VAR_6 = (slb->vsid & SLB_VSID_L)
? TARGET_PAGE_BITS_16M : TARGET_PAGE_BITS; VAR_1->key = !!(VAR_5 ? (slb->vsid & SLB_VSID_KP)
: (slb->vsid & SLB_VSID_KS)); VAR_1->nx = !!(slb->vsid & SLB_VSID_N); pageaddr = VAR_2 & ((1ULL << VAR_9)
- (1ULL << VAR_6)); if (slb->vsid & SLB_VSID_B) { hash = vsid ^ (vsid << 25) ^ (pageaddr >> VAR_6); } else { hash = vsid ^ (pageaddr >> VAR_6); } VAR_1->ptem = (slb->vsid & SLB_VSID_PTEM) |
((pageaddr >> 16) & ((1ULL << VAR_9) - 0x80)); LOG_MMU("pte segment: key=%d nx %d vsid " TARGET_FMT_lx "\n",
VAR_1->key, VAR_1->nx, vsid); VAR_7 = -1; if (VAR_4 != ACCESS_CODE || VAR_1->nx == 0) { LOG_MMU("htab_base " TARGET_FMT_plx " htab_mask " TARGET_FMT_plx
" hash " TARGET_FMT_plx "\n",
VAR_0->htab_base, VAR_0->htab_mask, hash); VAR_1->hash[0] = hash; VAR_1->hash[1] = ~hash; VAR_1->raddr = (hwaddr)-1ULL; LOG_MMU("0 htab=" TARGET_FMT_plx "/" TARGET_FMT_plx
" vsid=" TARGET_FMT_lx " ptem=" TARGET_FMT_lx
" hash=" TARGET_FMT_plx "\n",
VAR_0->htab_base, VAR_0->htab_mask, vsid, VAR_1->ptem,
VAR_1->hash[0]); VAR_7 = find_pte64(VAR_0, VAR_1, 0, VAR_3, VAR_4, VAR_6); if (VAR_7 < 0) { LOG_MMU("1 htab=" TARGET_FMT_plx "/" TARGET_FMT_plx
" vsid=" TARGET_FMT_lx " api=" TARGET_FMT_lx
" hash=" TARGET_FMT_plx "\n", VAR_0->htab_base,
VAR_0->htab_mask, vsid, VAR_1->ptem, VAR_1->hash[1]); VAR_8 = find_pte64(VAR_0, VAR_1, 1, VAR_3, VAR_4, VAR_6); if (VAR_8 != -1) { VAR_7 = VAR_8; } } } else { LOG_MMU("No access allowed\n"); VAR_7 = -3; } return VAR_7; }