static int mmu40x_get_physical_address (CPUState *env, mmu_ctx_t *ctx,

                                 target_ulong address, int rw, int access_type)

{

    ppcemb_tlb_t *tlb;

    target_phys_addr_t raddr;

    int i, ret, zsel, zpr, pr;



    ret = -1;

    raddr = (target_phys_addr_t)-1ULL;

    pr = msr_pr;

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

        tlb = &env->tlb[i].tlbe;

        if (ppcemb_tlb_check(env, tlb, &raddr, address,

                             env->spr[SPR_40x_PID], 0, i) < 0)

            continue;

        zsel = (tlb->attr >> 4) & 0xF;

        zpr = (env->spr[SPR_40x_ZPR] >> (28 - (2 * zsel))) & 0x3;

        LOG_SWTLB("%s: TLB %d zsel %d zpr %d rw %d attr %08x\n",

                    __func__, i, zsel, zpr, rw, tlb->attr);

        /* Check execute enable bit */

        switch (zpr) {

        case 0x2:

            if (pr != 0)

                goto check_perms;

            /* No break here */

        case 0x3:

            /* All accesses granted */

            ctx->prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;

            ret = 0;

            break;

        case 0x0:

            if (pr != 0) {

                ctx->prot = 0;

                ret = -2;

                break;

            }

            /* No break here */

        case 0x1:

        check_perms:

            /* Check from TLB entry */

            /* XXX: there is a problem here or in the TLB fill code... */

            ctx->prot = tlb->prot;

            ctx->prot |= PAGE_EXEC;

            ret = check_prot(ctx->prot, rw, access_type);

            break;

        }

        if (ret >= 0) {

            ctx->raddr = raddr;

            LOG_SWTLB("%s: access granted " TARGET_FMT_lx " => " TARGET_FMT_plx

                      " %d %d\n", __func__, address, ctx->raddr, ctx->prot,

                      ret);

            return 0;

        }

    }

    LOG_SWTLB("%s: access refused " TARGET_FMT_lx " => " TARGET_FMT_plx

              " %d %d\n", __func__, address, raddr, ctx->prot, ret);



    return ret;

}

static int mmu40x_get_physical_address (CPUState *env, mmu_ctx_t *ctx,

                                 target_ulong address, int rw, int access_type)

{

    ppcemb_tlb_t *tlb;

    target_phys_addr_t raddr;

    int i, ret, zsel, zpr, pr;



    ret = -1;

    raddr = (target_phys_addr_t)-1ULL;

    pr = msr_pr;

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

        tlb = &env->tlb[i].tlbe;

        if (ppcemb_tlb_check(env, tlb, &raddr, address,

                             env->spr[SPR_40x_PID], 0, i) < 0)

            continue;

        zsel = (tlb->attr >> 4) & 0xF;

        zpr = (env->spr[SPR_40x_ZPR] >> (28 - (2 * zsel))) & 0x3;

        LOG_SWTLB("%s: TLB %d zsel %d zpr %d rw %d attr %08x\n",

                    __func__, i, zsel, zpr, rw, tlb->attr);

        

        switch (zpr) {

        case 0x2:

            if (pr != 0)

                goto check_perms;

            

        case 0x3:

            

            ctx->prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;

            ret = 0;

            break;

        case 0x0:

            if (pr != 0) {

                ctx->prot = 0;

                ret = -2;

                break;

            }

            

        case 0x1:

        check_perms:

            

            

            ctx->prot = tlb->prot;

            ctx->prot |= PAGE_EXEC;

            ret = check_prot(ctx->prot, rw, access_type);

            break;

        }

        if (ret >= 0) {

            ctx->raddr = raddr;

            LOG_SWTLB("%s: access granted " TARGET_FMT_lx " => " TARGET_FMT_plx

                      " %d %d\n", __func__, address, ctx->raddr, ctx->prot,

                      ret);

            return 0;

        }

    }

    LOG_SWTLB("%s: access refused " TARGET_FMT_lx " => " TARGET_FMT_plx

              " %d %d\n", __func__, address, raddr, ctx->prot, ret);



    return ret;

}

static int FUNC_0 (CPUState *VAR_0, mmu_ctx_t *VAR_1,

                                 target_ulong VAR_2, int VAR_3, int VAR_4)

{

    ppcemb_tlb_t *tlb;

    target_phys_addr_t raddr;

    int VAR_5, VAR_6, VAR_7, VAR_8, VAR_9;



    VAR_6 = -1;

    raddr = (target_phys_addr_t)-1ULL;

    VAR_9 = msr_pr;

    for (VAR_5 = 0; VAR_5 < VAR_0->nb_tlb; VAR_5++) {

        tlb = &VAR_0->tlb[VAR_5].tlbe;

        if (ppcemb_tlb_check(VAR_0, tlb, &raddr, VAR_2,

                             VAR_0->spr[SPR_40x_PID], 0, VAR_5) < 0)

            continue;

        VAR_7 = (tlb->attr >> 4) & 0xF;

        VAR_8 = (VAR_0->spr[SPR_40x_ZPR] >> (28 - (2 * VAR_7))) & 0x3;

        LOG_SWTLB("%s: TLB %d VAR_7 %d VAR_8 %d VAR_3 %d attr %08x\n",

                    __func__, VAR_5, VAR_7, VAR_8, VAR_3, tlb->attr);

        

        switch (VAR_8) {

        case 0x2:

            if (VAR_9 != 0)

                goto check_perms;

            

        case 0x3:

            

            VAR_1->prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;

            VAR_6 = 0;

            break;

        case 0x0:

            if (VAR_9 != 0) {

                VAR_1->prot = 0;

                VAR_6 = -2;

                break;

            }

            

        case 0x1:

        check_perms:

            

            

            VAR_1->prot = tlb->prot;

            VAR_1->prot |= PAGE_EXEC;

            VAR_6 = check_prot(VAR_1->prot, VAR_3, VAR_4);

            break;

        }

        if (VAR_6 >= 0) {

            VAR_1->raddr = raddr;

            LOG_SWTLB("%s: access granted " TARGET_FMT_lx " => " TARGET_FMT_plx

                      " %d %d\n", __func__, VAR_2, VAR_1->raddr, VAR_1->prot,

                      VAR_6);

            return 0;

        }

    }

    LOG_SWTLB("%s: access refused " TARGET_FMT_lx " => " TARGET_FMT_plx

              " %d %d\n", __func__, VAR_2, raddr, VAR_1->prot, VAR_6);



    return VAR_6;

}

static int FUNC_0 (CPUState *VAR_0, mmu_ctx_t *VAR_1,
target_ulong VAR_2, int VAR_3, int VAR_4)
{ ppcemb_tlb_t *tlb; target_phys_addr_t raddr; int VAR_5, VAR_6, VAR_7, VAR_8, VAR_9; VAR_6 = -1; raddr = (target_phys_addr_t)-1ULL; VAR_9 = msr_pr; for (VAR_5 = 0; VAR_5 < VAR_0->nb_tlb; VAR_5++) { tlb = &VAR_0->tlb[VAR_5].tlbe; if (ppcemb_tlb_check(VAR_0, tlb, &raddr, VAR_2,
VAR_0->spr[SPR_40x_PID], 0, VAR_5) < 0)
continue; VAR_7 = (tlb->attr >> 4) & 0xF; VAR_8 = (VAR_0->spr[SPR_40x_ZPR] >> (28 - (2 * VAR_7))) & 0x3; LOG_SWTLB("%s: TLB %d VAR_7 %d VAR_8 %d VAR_3 %d attr %08x\n",
__func__, VAR_5, VAR_7, VAR_8, VAR_3, tlb->attr); switch (VAR_8) { case 0x2:
if (VAR_9 != 0)
goto check_perms; case 0x3:
VAR_1->prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC; VAR_6 = 0; break; case 0x0:
if (VAR_9 != 0) { VAR_1->prot = 0; VAR_6 = -2; break; } case 0x1:
check_perms:
VAR_1->prot = tlb->prot; VAR_1->prot |= PAGE_EXEC; VAR_6 = check_prot(VAR_1->prot, VAR_3, VAR_4); break; } if (VAR_6 >= 0) { VAR_1->raddr = raddr; LOG_SWTLB("%s: access granted " TARGET_FMT_lx " => " TARGET_FMT_plx
" %d %d\n", __func__, VAR_2, VAR_1->raddr, VAR_1->prot,
VAR_6); return 0; } } LOG_SWTLB("%s: access refused " TARGET_FMT_lx " => " TARGET_FMT_plx
" %d %d\n", __func__, VAR_2, raddr, VAR_1->prot, VAR_6); return VAR_6; }