static int ppc_hash32_get_bat(CPUPPCState *env, struct mmu_ctx_hash32 *ctx,

                              target_ulong virtual, int rwx)

{

    target_ulong *BATlt, *BATut;

    target_ulong BEPIl, BEPIu, bl;

    int i, valid, prot;

    int ret = -1;



    LOG_BATS("%s: %cBAT v " TARGET_FMT_lx "\n", __func__,

             rwx == 2 ? 'I' : 'D', virtual);

    if (rwx == 2) {

        BATlt = env->IBAT[1];

        BATut = env->IBAT[0];

    } else {

        BATlt = env->DBAT[1];

        BATut = env->DBAT[0];

    }

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

        target_ulong batu = BATut[i];

        target_ulong batl = BATlt[i];



        BEPIu = batu & BATU32_BEPIU;

        BEPIl = batu & BATU32_BEPIL;

        if (unlikely(env->mmu_model == POWERPC_MMU_601)) {

            hash32_bat_601_size(env, &bl, &valid, batu, batl);

            prot = hash32_bat_601_prot(env, batu, batl);

        } else {

            hash32_bat_size(env, &bl, &valid, batu, batl);

            prot = hash32_bat_prot(env, batu, batl);

        }

        LOG_BATS("%s: %cBAT%d v " TARGET_FMT_lx " BATu " TARGET_FMT_lx

                 " BATl " TARGET_FMT_lx "\n", __func__,

                 type == ACCESS_CODE ? 'I' : 'D', i, virtual, batu, batl);

        if ((virtual & BATU32_BEPIU) == BEPIu &&

            ((virtual & BATU32_BEPIL) & ~bl) == BEPIl) {

            /* BAT matches */

            if (valid != 0) {

                /* Get physical address */

                ctx->raddr = (batl & BATL32_BRPNU) |

                    ((virtual & BATU32_BEPIL & bl) | (batl & BATL32_BRPNL)) |

                    (virtual & 0x0001F000);

                /* Compute access rights */

                ctx->prot = prot;

                ret = ppc_hash32_check_prot(ctx->prot, rwx);

                if (ret == 0) {

                    LOG_BATS("BAT %d match: r " TARGET_FMT_plx " prot=%c%c\n",

                             i, ctx->raddr, ctx->prot & PAGE_READ ? 'R' : '-',

                             ctx->prot & PAGE_WRITE ? 'W' : '-');

                }

                break;

            }

        }

    }

    if (ret < 0) {

#if defined(DEBUG_BATS)

        if (qemu_log_enabled()) {

            LOG_BATS("no BAT match for " TARGET_FMT_lx ":\n", virtual);

            for (i = 0; i < 4; i++) {

                BATu = &BATut[i];

                BATl = &BATlt[i];

                BEPIu = *BATu & BATU32_BEPIU;

                BEPIl = *BATu & BATU32_BEPIL;

                bl = (*BATu & 0x00001FFC) << 15;

                LOG_BATS("%s: %cBAT%d v " TARGET_FMT_lx " BATu " TARGET_FMT_lx

                         " BATl " TARGET_FMT_lx "\n\t" TARGET_FMT_lx " "

                         TARGET_FMT_lx " " TARGET_FMT_lx "\n",

                         __func__, type == ACCESS_CODE ? 'I' : 'D', i, virtual,

                         *BATu, *BATl, BEPIu, BEPIl, bl);

            }

        }

#endif

    }

    /* No hit */

    return ret;

}

static int ppc_hash32_get_bat(CPUPPCState *env, struct mmu_ctx_hash32 *ctx,

                              target_ulong virtual, int rwx)

{

    target_ulong *BATlt, *BATut;

    target_ulong BEPIl, BEPIu, bl;

    int i, valid, prot;

    int ret = -1;



    LOG_BATS("%s: %cBAT v " TARGET_FMT_lx "\n", __func__,

             rwx == 2 ? 'I' : 'D', virtual);

    if (rwx == 2) {

        BATlt = env->IBAT[1];

        BATut = env->IBAT[0];

    } else {

        BATlt = env->DBAT[1];

        BATut = env->DBAT[0];

    }

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

        target_ulong batu = BATut[i];

        target_ulong batl = BATlt[i];



        BEPIu = batu & BATU32_BEPIU;

        BEPIl = batu & BATU32_BEPIL;

        if (unlikely(env->mmu_model == POWERPC_MMU_601)) {

            hash32_bat_601_size(env, &bl, &valid, batu, batl);

            prot = hash32_bat_601_prot(env, batu, batl);

        } else {

            hash32_bat_size(env, &bl, &valid, batu, batl);

            prot = hash32_bat_prot(env, batu, batl);

        }

        LOG_BATS("%s: %cBAT%d v " TARGET_FMT_lx " BATu " TARGET_FMT_lx

                 " BATl " TARGET_FMT_lx "\n", __func__,

                 type == ACCESS_CODE ? 'I' : 'D', i, virtual, batu, batl);

        if ((virtual & BATU32_BEPIU) == BEPIu &&

            ((virtual & BATU32_BEPIL) & ~bl) == BEPIl) {

            

            if (valid != 0) {

                

                ctx->raddr = (batl & BATL32_BRPNU) |

                    ((virtual & BATU32_BEPIL & bl) | (batl & BATL32_BRPNL)) |

                    (virtual & 0x0001F000);

                

                ctx->prot = prot;

                ret = ppc_hash32_check_prot(ctx->prot, rwx);

                if (ret == 0) {

                    LOG_BATS("BAT %d match: r " TARGET_FMT_plx " prot=%c%c\n",

                             i, ctx->raddr, ctx->prot & PAGE_READ ? 'R' : '-',

                             ctx->prot & PAGE_WRITE ? 'W' : '-');

                }

                break;

            }

        }

    }

    if (ret < 0) {

#if defined(DEBUG_BATS)

        if (qemu_log_enabled()) {

            LOG_BATS("no BAT match for " TARGET_FMT_lx ":\n", virtual);

            for (i = 0; i < 4; i++) {

                BATu = &BATut[i];

                BATl = &BATlt[i];

                BEPIu = *BATu & BATU32_BEPIU;

                BEPIl = *BATu & BATU32_BEPIL;

                bl = (*BATu & 0x00001FFC) << 15;

                LOG_BATS("%s: %cBAT%d v " TARGET_FMT_lx " BATu " TARGET_FMT_lx

                         " BATl " TARGET_FMT_lx "\n\t" TARGET_FMT_lx " "

                         TARGET_FMT_lx " " TARGET_FMT_lx "\n",

                         __func__, type == ACCESS_CODE ? 'I' : 'D', i, virtual,

                         *BATu, *BATl, BEPIu, BEPIl, bl);

            }

        }

#endif

    }

    

    return ret;

}

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

                              target_ulong VAR_2, int VAR_3)

{

    target_ulong *BATlt, *BATut;

    target_ulong BEPIl, BEPIu, bl;

    int VAR_4, VAR_5, VAR_6;

    int VAR_7 = -1;



    LOG_BATS("%s: %cBAT v " TARGET_FMT_lx "\n", __func__,

             VAR_3 == 2 ? 'I' : 'D', VAR_2);

    if (VAR_3 == 2) {

        BATlt = VAR_0->IBAT[1];

        BATut = VAR_0->IBAT[0];

    } else {

        BATlt = VAR_0->DBAT[1];

        BATut = VAR_0->DBAT[0];

    }

    for (VAR_4 = 0; VAR_4 < VAR_0->nb_BATs; VAR_4++) {

        target_ulong batu = BATut[VAR_4];

        target_ulong batl = BATlt[VAR_4];



        BEPIu = batu & BATU32_BEPIU;

        BEPIl = batu & BATU32_BEPIL;

        if (unlikely(VAR_0->mmu_model == POWERPC_MMU_601)) {

            hash32_bat_601_size(VAR_0, &bl, &VAR_5, batu, batl);

            VAR_6 = hash32_bat_601_prot(VAR_0, batu, batl);

        } else {

            hash32_bat_size(VAR_0, &bl, &VAR_5, batu, batl);

            VAR_6 = hash32_bat_prot(VAR_0, batu, batl);

        }

        LOG_BATS("%s: %cBAT%d v " TARGET_FMT_lx " BATu " TARGET_FMT_lx

                 " BATl " TARGET_FMT_lx "\n", __func__,

                 type == ACCESS_CODE ? 'I' : 'D', VAR_4, VAR_2, batu, batl);

        if ((VAR_2 & BATU32_BEPIU) == BEPIu &&

            ((VAR_2 & BATU32_BEPIL) & ~bl) == BEPIl) {

            

            if (VAR_5 != 0) {

                

                VAR_1->raddr = (batl & BATL32_BRPNU) |

                    ((VAR_2 & BATU32_BEPIL & bl) | (batl & BATL32_BRPNL)) |

                    (VAR_2 & 0x0001F000);

                

                VAR_1->VAR_6 = VAR_6;

                VAR_7 = ppc_hash32_check_prot(VAR_1->VAR_6, VAR_3);

                if (VAR_7 == 0) {

                    LOG_BATS("BAT %d match: r " TARGET_FMT_plx " VAR_6=%c%c\n",

                             VAR_4, VAR_1->raddr, VAR_1->VAR_6 & PAGE_READ ? 'R' : '-',

                             VAR_1->VAR_6 & PAGE_WRITE ? 'W' : '-');

                }

                break;

            }

        }

    }

    if (VAR_7 < 0) {

#if defined(DEBUG_BATS)

        if (qemu_log_enabled()) {

            LOG_BATS("no BAT match for " TARGET_FMT_lx ":\n", VAR_2);

            for (VAR_4 = 0; VAR_4 < 4; VAR_4++) {

                BATu = &BATut[VAR_4];

                BATl = &BATlt[VAR_4];

                BEPIu = *BATu & BATU32_BEPIU;

                BEPIl = *BATu & BATU32_BEPIL;

                bl = (*BATu & 0x00001FFC) << 15;

                LOG_BATS("%s: %cBAT%d v " TARGET_FMT_lx " BATu " TARGET_FMT_lx

                         " BATl " TARGET_FMT_lx "\n\t" TARGET_FMT_lx " "

                         TARGET_FMT_lx " " TARGET_FMT_lx "\n",

                         __func__, type == ACCESS_CODE ? 'I' : 'D', VAR_4, VAR_2,

                         *BATu, *BATl, BEPIu, BEPIl, bl);

            }

        }

#endif

    }

    

    return VAR_7;

}

static int FUNC_0(CPUPPCState *VAR_0, struct mmu_ctx_hash32 *VAR_1,
target_ulong VAR_2, int VAR_3)
{ target_ulong *BATlt, *BATut; target_ulong BEPIl, BEPIu, bl; int VAR_4, VAR_5, VAR_6; int VAR_7 = -1; LOG_BATS("%s: %cBAT v " TARGET_FMT_lx "\n", __func__,
VAR_3 == 2 ? 'I' : 'D', VAR_2); if (VAR_3 == 2) { BATlt = VAR_0->IBAT[1]; BATut = VAR_0->IBAT[0]; } else { BATlt = VAR_0->DBAT[1]; BATut = VAR_0->DBAT[0]; } for (VAR_4 = 0; VAR_4 < VAR_0->nb_BATs; VAR_4++) { target_ulong batu = BATut[VAR_4]; target_ulong batl = BATlt[VAR_4]; BEPIu = batu & BATU32_BEPIU; BEPIl = batu & BATU32_BEPIL; if (unlikely(VAR_0->mmu_model == POWERPC_MMU_601)) { hash32_bat_601_size(VAR_0, &bl, &VAR_5, batu, batl); VAR_6 = hash32_bat_601_prot(VAR_0, batu, batl); } else { hash32_bat_size(VAR_0, &bl, &VAR_5, batu, batl); VAR_6 = hash32_bat_prot(VAR_0, batu, batl); } LOG_BATS("%s: %cBAT%d v " TARGET_FMT_lx " BATu " TARGET_FMT_lx
" BATl " TARGET_FMT_lx "\n", __func__,
type == ACCESS_CODE ? 'I' : 'D', VAR_4, VAR_2, batu, batl); if ((VAR_2 & BATU32_BEPIU) == BEPIu &&
((VAR_2 & BATU32_BEPIL) & ~bl) == BEPIl) { if (VAR_5 != 0) { VAR_1->raddr = (batl & BATL32_BRPNU) |
((VAR_2 & BATU32_BEPIL & bl) | (batl & BATL32_BRPNL)) |
(VAR_2 & 0x0001F000); VAR_1->VAR_6 = VAR_6; VAR_7 = ppc_hash32_check_prot(VAR_1->VAR_6, VAR_3); if (VAR_7 == 0) { LOG_BATS("BAT %d match: r " TARGET_FMT_plx " VAR_6=%c%c\n",
VAR_4, VAR_1->raddr, VAR_1->VAR_6 & PAGE_READ ? 'R' : '-',
VAR_1->VAR_6 & PAGE_WRITE ? 'W' : '-'); } break; } } } if (VAR_7 < 0) { #if defined(DEBUG_BATS)
if (qemu_log_enabled()) { LOG_BATS("no BAT match for " TARGET_FMT_lx ":\n", VAR_2); for (VAR_4 = 0; VAR_4 < 4; VAR_4++) { BATu = &BATut[VAR_4]; BATl = &BATlt[VAR_4]; BEPIu = *BATu & BATU32_BEPIU; BEPIl = *BATu & BATU32_BEPIL; bl = (*BATu & 0x00001FFC) << 15; LOG_BATS("%s: %cBAT%d v " TARGET_FMT_lx " BATu " TARGET_FMT_lx
" BATl " TARGET_FMT_lx "\n\t" TARGET_FMT_lx " "
TARGET_FMT_lx " " TARGET_FMT_lx "\n",
__func__, type == ACCESS_CODE ? 'I' : 'D', VAR_4, VAR_2,
*BATu, *BATl, BEPIu, BEPIl, bl); } } #endif
} return VAR_7; }