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

                    target_ulong virtual, int rw, int type)

{

    target_ulong *BATlt, *BATut, *BATu, *BATl;

    target_ulong base, BEPIl, BEPIu, bl;

    int i;

    int ret = -1;



#if defined (DEBUG_BATS)

    if (loglevel != 0) {

        fprintf(logfile, "%s: %cBAT v 0x" ADDRX "\n", __func__,

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

    }

#endif

    switch (type) {

    case ACCESS_CODE:

        BATlt = env->IBAT[1];

        BATut = env->IBAT[0];

        break;

    default:

        BATlt = env->DBAT[1];

        BATut = env->DBAT[0];

        break;

    }

#if defined (DEBUG_BATS)

    if (loglevel != 0) {

        fprintf(logfile, "%s...: %cBAT v 0x" ADDRX "\n", __func__,

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

    }

#endif

    base = virtual & 0xFFFC0000;

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

        BATu = &BATut[i];

        BATl = &BATlt[i];

        BEPIu = *BATu & 0xF0000000;

        BEPIl = *BATu & 0x0FFE0000;

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

#if defined (DEBUG_BATS)

        if (loglevel != 0) {

            fprintf(logfile, "%s: %cBAT%d v 0x" ADDRX " BATu 0x" ADDRX

                    " BATl 0x" ADDRX "\n",

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

                    *BATu, *BATl);

        }

#endif

        if ((virtual & 0xF0000000) == BEPIu &&

            ((virtual & 0x0FFE0000) & ~bl) == BEPIl) {

            /* BAT matches */

            if ((msr_pr == 0 && (*BATu & 0x00000002)) ||

                (msr_pr == 1 && (*BATu & 0x00000001))) {

                /* Get physical address */

                ctx->raddr = (*BATl & 0xF0000000) |

                    ((virtual & 0x0FFE0000 & bl) | (*BATl & 0x0FFE0000)) |

                    (virtual & 0x0001F000);

                if (*BATl & 0x00000001)

                    ctx->prot = PAGE_READ;

                if (*BATl & 0x00000002)

                    ctx->prot = PAGE_WRITE | PAGE_READ;

#if defined (DEBUG_BATS)

                if (loglevel != 0) {

                    fprintf(logfile, "BAT %d match: r 0x" PADDRX

                            " prot=%c%c\n",

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

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

                }

#endif

                ret = 0;

                break;

            }

        }

    }

    if (ret < 0) {

#if defined (DEBUG_BATS)

        if (loglevel != 0) {

            fprintf(logfile, "no BAT match for 0x" ADDRX ":\n", virtual);

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

                BATu = &BATut[i];

                BATl = &BATlt[i];

                BEPIu = *BATu & 0xF0000000;

                BEPIl = *BATu & 0x0FFE0000;

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

                fprintf(logfile, "%s: %cBAT%d v 0x" ADDRX " BATu 0x" ADDRX

                        " BATl 0x" ADDRX " \n\t"

                        "0x" ADDRX " 0x" ADDRX " 0x" ADDRX "\n",

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

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

            }

        }

#endif

    }

    /* No hit */

    return ret;

}

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

                    target_ulong virtual, int rw, int type)

{

    target_ulong *BATlt, *BATut, *BATu, *BATl;

    target_ulong base, BEPIl, BEPIu, bl;

    int i;

    int ret = -1;



#if defined (DEBUG_BATS)

    if (loglevel != 0) {

        fprintf(logfile, "%s: %cBAT v 0x" ADDRX "\n", __func__,

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

    }

#endif

    switch (type) {

    case ACCESS_CODE:

        BATlt = env->IBAT[1];

        BATut = env->IBAT[0];

        break;

    default:

        BATlt = env->DBAT[1];

        BATut = env->DBAT[0];

        break;

    }

#if defined (DEBUG_BATS)

    if (loglevel != 0) {

        fprintf(logfile, "%s...: %cBAT v 0x" ADDRX "\n", __func__,

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

    }

#endif

    base = virtual & 0xFFFC0000;

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

        BATu = &BATut[i];

        BATl = &BATlt[i];

        BEPIu = *BATu & 0xF0000000;

        BEPIl = *BATu & 0x0FFE0000;

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

#if defined (DEBUG_BATS)

        if (loglevel != 0) {

            fprintf(logfile, "%s: %cBAT%d v 0x" ADDRX " BATu 0x" ADDRX

                    " BATl 0x" ADDRX "\n",

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

                    *BATu, *BATl);

        }

#endif

        if ((virtual & 0xF0000000) == BEPIu &&

            ((virtual & 0x0FFE0000) & ~bl) == BEPIl) {

            

            if ((msr_pr == 0 && (*BATu & 0x00000002)) ||

                (msr_pr == 1 && (*BATu & 0x00000001))) {

                

                ctx->raddr = (*BATl & 0xF0000000) |

                    ((virtual & 0x0FFE0000 & bl) | (*BATl & 0x0FFE0000)) |

                    (virtual & 0x0001F000);

                if (*BATl & 0x00000001)

                    ctx->prot = PAGE_READ;

                if (*BATl & 0x00000002)

                    ctx->prot = PAGE_WRITE | PAGE_READ;

#if defined (DEBUG_BATS)

                if (loglevel != 0) {

                    fprintf(logfile, "BAT %d match: r 0x" PADDRX

                            " prot=%c%c\n",

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

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

                }

#endif

                ret = 0;

                break;

            }

        }

    }

    if (ret < 0) {

#if defined (DEBUG_BATS)

        if (loglevel != 0) {

            fprintf(logfile, "no BAT match for 0x" ADDRX ":\n", virtual);

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

                BATu = &BATut[i];

                BATl = &BATlt[i];

                BEPIu = *BATu & 0xF0000000;

                BEPIl = *BATu & 0x0FFE0000;

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

                fprintf(logfile, "%s: %cBAT%d v 0x" ADDRX " BATu 0x" ADDRX

                        " BATl 0x" ADDRX " \n\t"

                        "0x" ADDRX " 0x" ADDRX " 0x" ADDRX "\n",

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

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

            }

        }

#endif

    }

    

    return ret;

}

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

                    target_ulong VAR_2, int VAR_3, int VAR_4)

{

    target_ulong *BATlt, *BATut, *BATu, *BATl;

    target_ulong base, BEPIl, BEPIu, bl;

    int VAR_5;

    int VAR_6 = -1;



#if defined (DEBUG_BATS)

    if (loglevel != 0) {

        fprintf(logfile, "%s: %cBAT v 0x" ADDRX "\n", __func__,

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

    }

#endif

    switch (VAR_4) {

    case ACCESS_CODE:

        BATlt = VAR_0->IBAT[1];

        BATut = VAR_0->IBAT[0];

        break;

    default:

        BATlt = VAR_0->DBAT[1];

        BATut = VAR_0->DBAT[0];

        break;

    }

#if defined (DEBUG_BATS)

    if (loglevel != 0) {

        fprintf(logfile, "%s...: %cBAT v 0x" ADDRX "\n", __func__,

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

    }

#endif

    base = VAR_2 & 0xFFFC0000;

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

        BATu = &BATut[VAR_5];

        BATl = &BATlt[VAR_5];

        BEPIu = *BATu & 0xF0000000;

        BEPIl = *BATu & 0x0FFE0000;

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

#if defined (DEBUG_BATS)

        if (loglevel != 0) {

            fprintf(logfile, "%s: %cBAT%d v 0x" ADDRX " BATu 0x" ADDRX

                    " BATl 0x" ADDRX "\n",

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

                    *BATu, *BATl);

        }

#endif

        if ((VAR_2 & 0xF0000000) == BEPIu &&

            ((VAR_2 & 0x0FFE0000) & ~bl) == BEPIl) {

            

            if ((msr_pr == 0 && (*BATu & 0x00000002)) ||

                (msr_pr == 1 && (*BATu & 0x00000001))) {

                

                VAR_1->raddr = (*BATl & 0xF0000000) |

                    ((VAR_2 & 0x0FFE0000 & bl) | (*BATl & 0x0FFE0000)) |

                    (VAR_2 & 0x0001F000);

                if (*BATl & 0x00000001)

                    VAR_1->prot = PAGE_READ;

                if (*BATl & 0x00000002)

                    VAR_1->prot = PAGE_WRITE | PAGE_READ;

#if defined (DEBUG_BATS)

                if (loglevel != 0) {

                    fprintf(logfile, "BAT %d match: r 0x" PADDRX

                            " prot=%c%c\n",

                            VAR_5, VAR_1->raddr, VAR_1->prot & PAGE_READ ? 'R' : '-',

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

                }

#endif

                VAR_6 = 0;

                break;

            }

        }

    }

    if (VAR_6 < 0) {

#if defined (DEBUG_BATS)

        if (loglevel != 0) {

            fprintf(logfile, "no BAT match for 0x" ADDRX ":\n", VAR_2);

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

                BATu = &BATut[VAR_5];

                BATl = &BATlt[VAR_5];

                BEPIu = *BATu & 0xF0000000;

                BEPIl = *BATu & 0x0FFE0000;

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

                fprintf(logfile, "%s: %cBAT%d v 0x" ADDRX " BATu 0x" ADDRX

                        " BATl 0x" ADDRX " \n\t"

                        "0x" ADDRX " 0x" ADDRX " 0x" ADDRX "\n",

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

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

            }

        }

#endif

    }

    

    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)
{ target_ulong *BATlt, *BATut, *BATu, *BATl; target_ulong base, BEPIl, BEPIu, bl; int VAR_5; int VAR_6 = -1; #if defined (DEBUG_BATS)
if (loglevel != 0) { fprintf(logfile, "%s: %cBAT v 0x" ADDRX "\n", __func__,
VAR_4 == ACCESS_CODE ? 'I' : 'D', VAR_2); } #endif
switch (VAR_4) { case ACCESS_CODE:
BATlt = VAR_0->IBAT[1]; BATut = VAR_0->IBAT[0]; break; default:
BATlt = VAR_0->DBAT[1]; BATut = VAR_0->DBAT[0]; break; } #if defined (DEBUG_BATS)
if (loglevel != 0) { fprintf(logfile, "%s...: %cBAT v 0x" ADDRX "\n", __func__,
VAR_4 == ACCESS_CODE ? 'I' : 'D', VAR_2); } #endif
base = VAR_2 & 0xFFFC0000; for (VAR_5 = 0; VAR_5 < 4; VAR_5++) { BATu = &BATut[VAR_5]; BATl = &BATlt[VAR_5]; BEPIu = *BATu & 0xF0000000; BEPIl = *BATu & 0x0FFE0000; bl = (*BATu & 0x00001FFC) << 15; #if defined (DEBUG_BATS)
if (loglevel != 0) { fprintf(logfile, "%s: %cBAT%d v 0x" ADDRX " BATu 0x" ADDRX
" BATl 0x" ADDRX "\n",
__func__, VAR_4 == ACCESS_CODE ? 'I' : 'D', VAR_5, VAR_2,
*BATu, *BATl); } #endif
if ((VAR_2 & 0xF0000000) == BEPIu &&
((VAR_2 & 0x0FFE0000) & ~bl) == BEPIl) { if ((msr_pr == 0 && (*BATu & 0x00000002)) ||
(msr_pr == 1 && (*BATu & 0x00000001))) { VAR_1->raddr = (*BATl & 0xF0000000) |
((VAR_2 & 0x0FFE0000 & bl) | (*BATl & 0x0FFE0000)) |
(VAR_2 & 0x0001F000); if (*BATl & 0x00000001)
VAR_1->prot = PAGE_READ; if (*BATl & 0x00000002)
VAR_1->prot = PAGE_WRITE | PAGE_READ; #if defined (DEBUG_BATS)
if (loglevel != 0) { fprintf(logfile, "BAT %d match: r 0x" PADDRX
" prot=%c%c\n",
VAR_5, VAR_1->raddr, VAR_1->prot & PAGE_READ ? 'R' : '-',
VAR_1->prot & PAGE_WRITE ? 'W' : '-'); } #endif
VAR_6 = 0; break; } } } if (VAR_6 < 0) { #if defined (DEBUG_BATS)
if (loglevel != 0) { fprintf(logfile, "no BAT match for 0x" ADDRX ":\n", VAR_2); for (VAR_5 = 0; VAR_5 < 4; VAR_5++) { BATu = &BATut[VAR_5]; BATl = &BATlt[VAR_5]; BEPIu = *BATu & 0xF0000000; BEPIl = *BATu & 0x0FFE0000; bl = (*BATu & 0x00001FFC) << 15; fprintf(logfile, "%s: %cBAT%d v 0x" ADDRX " BATu 0x" ADDRX
" BATl 0x" ADDRX " \n\t"
"0x" ADDRX " 0x" ADDRX " 0x" ADDRX "\n",
__func__, VAR_4 == ACCESS_CODE ? 'I' : 'D', VAR_5, VAR_2,
*BATu, *BATl, BEPIu, BEPIl, bl); } } #endif
} return VAR_6; }