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

                             target_ulong eaddr, int rw, int access_type)

{

    ppc_tlb_t *tlb;

    int nr, best, way;

    int ret;

    

    best = -1;

    ret = -1; /* No TLB found */

    for (way = 0; way < env->nb_ways; way++) {

        nr = ppc6xx_tlb_getnum(env, eaddr, way,

                               access_type == ACCESS_CODE ? 1 : 0);

        tlb = &env->tlb[nr];

        /* This test "emulates" the PTE index match for hardware TLBs */

        if ((eaddr & TARGET_PAGE_MASK) != tlb->EPN) {

#if defined (DEBUG_SOFTWARE_TLB)

            if (loglevel != 0) {

                fprintf(logfile, "TLB %d/%d %s [%08x %08x] <> %08x\n",

                        nr, env->nb_tlb,

                        pte_is_valid(tlb->pte0) ? "valid" : "inval",

                        tlb->EPN, tlb->EPN + TARGET_PAGE_SIZE, eaddr);

            }

#endif

            continue;

        }

#if defined (DEBUG_SOFTWARE_TLB)

        if (loglevel != 0) {

            fprintf(logfile, "TLB %d/%d %s %08x <> %08x %08x %c %c\n",

                    nr, env->nb_tlb,

                    pte_is_valid(tlb->pte0) ? "valid" : "inval",

                    tlb->EPN, eaddr, tlb->pte1,

                    rw ? 'S' : 'L', access_type == ACCESS_CODE ? 'I' : 'D');

        }

#endif

        switch (pte_check(ctx, tlb->pte0, tlb->pte1, 0, rw)) {

        case -3:

            /* TLB inconsistency */

            return -1;

        case -2:

            /* Access violation */

            ret = -2;

            best = nr;

            break;

        case -1:

        default:

            /* No match */

            break;

        case 0:

            /* access granted */

            /* XXX: we should go on looping to check all TLBs consistency

             *      but we can speed-up the whole thing as the

             *      result would be undefined if TLBs are not consistent.

             */

            ret = 0;

            best = nr;

            goto done;

        }

    }

    if (best != -1) {

    done:

#if defined (DEBUG_SOFTWARE_TLB)

        if (loglevel > 0) {

            fprintf(logfile, "found TLB at addr 0x%08lx prot=0x%01x ret=%d\n",

                    ctx->raddr & TARGET_PAGE_MASK, ctx->prot, ret);

        }

#endif

        /* Update page flags */

        pte_update_flags(ctx, &env->tlb[best].pte1, ret, rw);

    }



    return ret;

}

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

                             target_ulong eaddr, int rw, int access_type)

{

    ppc_tlb_t *tlb;

    int nr, best, way;

    int ret;

    

    best = -1;

    ret = -1; 

    for (way = 0; way < env->nb_ways; way++) {

        nr = ppc6xx_tlb_getnum(env, eaddr, way,

                               access_type == ACCESS_CODE ? 1 : 0);

        tlb = &env->tlb[nr];

        

        if ((eaddr & TARGET_PAGE_MASK) != tlb->EPN) {

#if defined (DEBUG_SOFTWARE_TLB)

            if (loglevel != 0) {

                fprintf(logfile, "TLB %d/%d %s [%08x %08x] <> %08x\n",

                        nr, env->nb_tlb,

                        pte_is_valid(tlb->pte0) ? "valid" : "inval",

                        tlb->EPN, tlb->EPN + TARGET_PAGE_SIZE, eaddr);

            }

#endif

            continue;

        }

#if defined (DEBUG_SOFTWARE_TLB)

        if (loglevel != 0) {

            fprintf(logfile, "TLB %d/%d %s %08x <> %08x %08x %c %c\n",

                    nr, env->nb_tlb,

                    pte_is_valid(tlb->pte0) ? "valid" : "inval",

                    tlb->EPN, eaddr, tlb->pte1,

                    rw ? 'S' : 'L', access_type == ACCESS_CODE ? 'I' : 'D');

        }

#endif

        switch (pte_check(ctx, tlb->pte0, tlb->pte1, 0, rw)) {

        case -3:

            

            return -1;

        case -2:

            

            ret = -2;

            best = nr;

            break;

        case -1:

        default:

            

            break;

        case 0:

            

            







            ret = 0;

            best = nr;

            goto done;

        }

    }

    if (best != -1) {

    done:

#if defined (DEBUG_SOFTWARE_TLB)

        if (loglevel > 0) {

            fprintf(logfile, "found TLB at addr 0x%08lx prot=0x%01x ret=%d\n",

                    ctx->raddr & TARGET_PAGE_MASK, ctx->prot, ret);

        }

#endif

        

        pte_update_flags(ctx, &env->tlb[best].pte1, ret, rw);

    }



    return ret;

}

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

                             target_ulong VAR_2, int VAR_3, int VAR_4)

{

    ppc_tlb_t *tlb;

    int VAR_5, VAR_6, VAR_7;

    int VAR_8;

    

    VAR_6 = -1;

    VAR_8 = -1; 

    for (VAR_7 = 0; VAR_7 < VAR_0->nb_ways; VAR_7++) {

        VAR_5 = ppc6xx_tlb_getnum(VAR_0, VAR_2, VAR_7,

                               VAR_4 == ACCESS_CODE ? 1 : 0);

        tlb = &VAR_0->tlb[VAR_5];

        

        if ((VAR_2 & TARGET_PAGE_MASK) != tlb->EPN) {

#if defined (DEBUG_SOFTWARE_TLB)

            if (loglevel != 0) {

                fprintf(logfile, "TLB %d/%d %s [%08x %08x] <> %08x\n",

                        VAR_5, VAR_0->nb_tlb,

                        pte_is_valid(tlb->pte0) ? "valid" : "inval",

                        tlb->EPN, tlb->EPN + TARGET_PAGE_SIZE, VAR_2);

            }

#endif

            continue;

        }

#if defined (DEBUG_SOFTWARE_TLB)

        if (loglevel != 0) {

            fprintf(logfile, "TLB %d/%d %s %08x <> %08x %08x %c %c\n",

                    VAR_5, VAR_0->nb_tlb,

                    pte_is_valid(tlb->pte0) ? "valid" : "inval",

                    tlb->EPN, VAR_2, tlb->pte1,

                    VAR_3 ? 'S' : 'L', VAR_4 == ACCESS_CODE ? 'I' : 'D');

        }

#endif

        switch (pte_check(VAR_1, tlb->pte0, tlb->pte1, 0, VAR_3)) {

        case -3:

            

            return -1;

        case -2:

            

            VAR_8 = -2;

            VAR_6 = VAR_5;

            break;

        case -1:

        default:

            

            break;

        case 0:

            

            







            VAR_8 = 0;

            VAR_6 = VAR_5;

            goto done;

        }

    }

    if (VAR_6 != -1) {

    done:

#if defined (DEBUG_SOFTWARE_TLB)

        if (loglevel > 0) {

            fprintf(logfile, "found TLB at addr 0x%08lx prot=0x%01x VAR_8=%d\n",

                    VAR_1->raddr & TARGET_PAGE_MASK, VAR_1->prot, VAR_8);

        }

#endif

        

        pte_update_flags(VAR_1, &VAR_0->tlb[VAR_6].pte1, VAR_8, VAR_3);

    }



    return VAR_8;

}

static int FUNC_0 (CPUState *VAR_0, mmu_ctx_t *VAR_1,
target_ulong VAR_2, int VAR_3, int VAR_4)
{ ppc_tlb_t *tlb; int VAR_5, VAR_6, VAR_7; int VAR_8; VAR_6 = -1; VAR_8 = -1; for (VAR_7 = 0; VAR_7 < VAR_0->nb_ways; VAR_7++) { VAR_5 = ppc6xx_tlb_getnum(VAR_0, VAR_2, VAR_7,
VAR_4 == ACCESS_CODE ? 1 : 0); tlb = &VAR_0->tlb[VAR_5]; if ((VAR_2 & TARGET_PAGE_MASK) != tlb->EPN) { #if defined (DEBUG_SOFTWARE_TLB)
if (loglevel != 0) { fprintf(logfile, "TLB %d/%d %s [%08x %08x] <> %08x\n",
VAR_5, VAR_0->nb_tlb,
pte_is_valid(tlb->pte0) ? "valid" : "inval",
tlb->EPN, tlb->EPN + TARGET_PAGE_SIZE, VAR_2); } #endif
continue; } #if defined (DEBUG_SOFTWARE_TLB)
if (loglevel != 0) { fprintf(logfile, "TLB %d/%d %s %08x <> %08x %08x %c %c\n",
VAR_5, VAR_0->nb_tlb,
pte_is_valid(tlb->pte0) ? "valid" : "inval",
tlb->EPN, VAR_2, tlb->pte1,
VAR_3 ? 'S' : 'L', VAR_4 == ACCESS_CODE ? 'I' : 'D'); } #endif
switch (pte_check(VAR_1, tlb->pte0, tlb->pte1, 0, VAR_3)) { case -3:
return -1; case -2:
VAR_8 = -2; VAR_6 = VAR_5; break; case -1:
default:
break; case 0:
VAR_8 = 0; VAR_6 = VAR_5; goto done; } } if (VAR_6 != -1) { done:
#if defined (DEBUG_SOFTWARE_TLB)
if (loglevel > 0) { fprintf(logfile, "found TLB at addr 0x%08lx prot=0x%01x VAR_8=%d\n",
VAR_1->raddr & TARGET_PAGE_MASK, VAR_1->prot, VAR_8); } #endif
pte_update_flags(VAR_1, &VAR_0->tlb[VAR_6].pte1, VAR_8, VAR_3); } return VAR_8; }