static int get_physical_address (CPUState *env, target_ulong *physical,

                                int *prot, target_ulong address,

                                int rw, int access_type)

{

    /* User mode can only access useg/xuseg */

    int user_mode = (env->hflags & MIPS_HFLAG_MODE) == MIPS_HFLAG_UM;

    int supervisor_mode = (env->hflags & MIPS_HFLAG_MODE) == MIPS_HFLAG_SM;

    int kernel_mode = !user_mode && !supervisor_mode;

#if defined(TARGET_MIPS64)

    int UX = (env->CP0_Status & (1 << CP0St_UX)) != 0;

    int SX = (env->CP0_Status & (1 << CP0St_SX)) != 0;

    int KX = (env->CP0_Status & (1 << CP0St_KX)) != 0;

#endif

    int ret = TLBRET_MATCH;



#if 0

    if (logfile) {

        fprintf(logfile, "user mode %d h %08x\n",

                user_mode, env->hflags);

    }

#endif



    if (address <= (int32_t)0x7FFFFFFFUL) {

        /* useg */

        if (env->CP0_Status & (1 << CP0St_ERL)) {

            *physical = address & 0xFFFFFFFF;

            *prot = PAGE_READ | PAGE_WRITE;

        } else {

            ret = env->tlb->map_address(env, physical, prot, address, rw, access_type);

        }

#if defined(TARGET_MIPS64)

    } else if (address < 0x4000000000000000ULL) {

        /* xuseg */

	if (UX && address < (0x3FFFFFFFFFFFFFFFULL & env->SEGMask)) {

            ret = env->tlb->map_address(env, physical, prot, address, rw, access_type);

	} else {

	    ret = TLBRET_BADADDR;

        }

    } else if (address < 0x8000000000000000ULL) {

        /* xsseg */

	if ((supervisor_mode || kernel_mode) &&

	    SX && address < (0x7FFFFFFFFFFFFFFFULL & env->SEGMask)) {

            ret = env->tlb->map_address(env, physical, prot, address, rw, access_type);

	} else {

	    ret = TLBRET_BADADDR;

        }

    } else if (address < 0xC000000000000000ULL) {

        /* xkphys */

        /* XXX: Assumes PABITS = 36 (correct for MIPS64R1) */

        if (kernel_mode && KX &&

            (address & 0x07FFFFFFFFFFFFFFULL) < 0x0000000FFFFFFFFFULL) {

            *physical = address & 0x0000000FFFFFFFFFULL;

            *prot = PAGE_READ | PAGE_WRITE;

	} else {

	    ret = TLBRET_BADADDR;

	}

    } else if (address < 0xFFFFFFFF80000000ULL) {

        /* xkseg */

	if (kernel_mode && KX &&

	    address < (0xFFFFFFFF7FFFFFFFULL & env->SEGMask)) {

            ret = env->tlb->map_address(env, physical, prot, address, rw, access_type);

	} else {

	    ret = TLBRET_BADADDR;

	}

#endif

    } else if (address < (int32_t)0xA0000000UL) {

        /* kseg0 */

        if (kernel_mode) {

            *physical = address - (int32_t)0x80000000UL;

            *prot = PAGE_READ | PAGE_WRITE;

        } else {

            ret = TLBRET_BADADDR;

        }

    } else if (address < (int32_t)0xC0000000UL) {

        /* kseg1 */

        if (kernel_mode) {

            *physical = address - (int32_t)0xA0000000UL;

            *prot = PAGE_READ | PAGE_WRITE;

        } else {

            ret = TLBRET_BADADDR;

        }

    } else if (address < (int32_t)0xE0000000UL) {

        /* sseg (kseg2) */

        if (supervisor_mode || kernel_mode) {

            ret = env->tlb->map_address(env, physical, prot, address, rw, access_type);

        } else {

            ret = TLBRET_BADADDR;

        }

    } else {

        /* kseg3 */

        /* XXX: debug segment is not emulated */

        if (kernel_mode) {

            ret = env->tlb->map_address(env, physical, prot, address, rw, access_type);

        } else {

            ret = TLBRET_BADADDR;

        }

    }

#if 0

    if (logfile) {

        fprintf(logfile, TARGET_FMT_lx " %d %d => " TARGET_FMT_lx " %d (%d)\n",

		address, rw, access_type, *physical, *prot, ret);

    }

#endif



    return ret;

}

static int get_physical_address (CPUState *env, target_ulong *physical,

                                int *prot, target_ulong address,

                                int rw, int access_type)

{

    

    int user_mode = (env->hflags & MIPS_HFLAG_MODE) == MIPS_HFLAG_UM;

    int supervisor_mode = (env->hflags & MIPS_HFLAG_MODE) == MIPS_HFLAG_SM;

    int kernel_mode = !user_mode && !supervisor_mode;

#if defined(TARGET_MIPS64)

    int UX = (env->CP0_Status & (1 << CP0St_UX)) != 0;

    int SX = (env->CP0_Status & (1 << CP0St_SX)) != 0;

    int KX = (env->CP0_Status & (1 << CP0St_KX)) != 0;

#endif

    int ret = TLBRET_MATCH;



#if 0

    if (logfile) {

        fprintf(logfile, "user mode %d h %08x\n",

                user_mode, env->hflags);

    }

#endif



    if (address <= (int32_t)0x7FFFFFFFUL) {

        

        if (env->CP0_Status & (1 << CP0St_ERL)) {

            *physical = address & 0xFFFFFFFF;

            *prot = PAGE_READ | PAGE_WRITE;

        } else {

            ret = env->tlb->map_address(env, physical, prot, address, rw, access_type);

        }

#if defined(TARGET_MIPS64)

    } else if (address < 0x4000000000000000ULL) {

        

	if (UX && address < (0x3FFFFFFFFFFFFFFFULL & env->SEGMask)) {

            ret = env->tlb->map_address(env, physical, prot, address, rw, access_type);

	} else {

	    ret = TLBRET_BADADDR;

        }

    } else if (address < 0x8000000000000000ULL) {

        

	if ((supervisor_mode || kernel_mode) &&

	    SX && address < (0x7FFFFFFFFFFFFFFFULL & env->SEGMask)) {

            ret = env->tlb->map_address(env, physical, prot, address, rw, access_type);

	} else {

	    ret = TLBRET_BADADDR;

        }

    } else if (address < 0xC000000000000000ULL) {

        

        

        if (kernel_mode && KX &&

            (address & 0x07FFFFFFFFFFFFFFULL) < 0x0000000FFFFFFFFFULL) {

            *physical = address & 0x0000000FFFFFFFFFULL;

            *prot = PAGE_READ | PAGE_WRITE;

	} else {

	    ret = TLBRET_BADADDR;

	}

    } else if (address < 0xFFFFFFFF80000000ULL) {

        

	if (kernel_mode && KX &&

	    address < (0xFFFFFFFF7FFFFFFFULL & env->SEGMask)) {

            ret = env->tlb->map_address(env, physical, prot, address, rw, access_type);

	} else {

	    ret = TLBRET_BADADDR;

	}

#endif

    } else if (address < (int32_t)0xA0000000UL) {

        

        if (kernel_mode) {

            *physical = address - (int32_t)0x80000000UL;

            *prot = PAGE_READ | PAGE_WRITE;

        } else {

            ret = TLBRET_BADADDR;

        }

    } else if (address < (int32_t)0xC0000000UL) {

        

        if (kernel_mode) {

            *physical = address - (int32_t)0xA0000000UL;

            *prot = PAGE_READ | PAGE_WRITE;

        } else {

            ret = TLBRET_BADADDR;

        }

    } else if (address < (int32_t)0xE0000000UL) {

        

        if (supervisor_mode || kernel_mode) {

            ret = env->tlb->map_address(env, physical, prot, address, rw, access_type);

        } else {

            ret = TLBRET_BADADDR;

        }

    } else {

        

        

        if (kernel_mode) {

            ret = env->tlb->map_address(env, physical, prot, address, rw, access_type);

        } else {

            ret = TLBRET_BADADDR;

        }

    }

#if 0

    if (logfile) {

        fprintf(logfile, TARGET_FMT_lx " %d %d => " TARGET_FMT_lx " %d (%d)\n",

		address, rw, access_type, *physical, *prot, ret);

    }

#endif



    return ret;

}

	if (UX && address < (0x3FFFFFFFFFFFFFFFULL & env->SEGMask)) { 	    SX && address < (0x7FFFFFFFFFFFFFFFULL & env->SEGMask)) {             (address & 0x07FFFFFFFFFFFFFFULL) < 0x0000000FFFFFFFFFULL) { 	    address < (0xFFFFFFFF7FFFFFFFULL & env->SEGMask)) {
static int FUNC_0 (CPUState *VAR_0, target_ulong *VAR_1,

                                int *VAR_2, target_ulong VAR_3,

                                int VAR_4, int VAR_5)

{

    

    int VAR_6 = (VAR_0->hflags & MIPS_HFLAG_MODE) == MIPS_HFLAG_UM;

    int VAR_7 = (VAR_0->hflags & MIPS_HFLAG_MODE) == MIPS_HFLAG_SM;

    int VAR_8 = !VAR_6 && !VAR_7;

#if defined(TARGET_MIPS64)

    int UX = (VAR_0->CP0_Status & (1 << CP0St_UX)) != 0;

    int SX = (VAR_0->CP0_Status & (1 << CP0St_SX)) != 0;

    int KX = (VAR_0->CP0_Status & (1 << CP0St_KX)) != 0;

#endif

    int VAR_9 = TLBRET_MATCH;



#if 0

    if (logfile) {

        fprintf(logfile, "user mode %d h %08x\n",

                VAR_6, VAR_0->hflags);

    }

#endif



    if (VAR_3 <= (int32_t)0x7FFFFFFFUL) {

        

        if (VAR_0->CP0_Status & (1 << CP0St_ERL)) {

            *VAR_1 = VAR_3 & 0xFFFFFFFF;

            *VAR_2 = PAGE_READ | PAGE_WRITE;

        } else {

            VAR_9 = VAR_0->tlb->map_address(VAR_0, VAR_1, VAR_2, VAR_3, VAR_4, VAR_5);

        }

#if defined(TARGET_MIPS64)

    } else if (VAR_3 < 0x4000000000000000ULL) {

        

	if (UX && VAR_3 < (0x3FFFFFFFFFFFFFFFULL & VAR_0->SEGMask)) {

            VAR_9 = VAR_0->tlb->map_address(VAR_0, VAR_1, VAR_2, VAR_3, VAR_4, VAR_5);

	} else {

	    VAR_9 = TLBRET_BADADDR;

        }

    } else if (VAR_3 < 0x8000000000000000ULL) {

        

	if ((VAR_7 || VAR_8) &&

	    SX && VAR_3 < (0x7FFFFFFFFFFFFFFFULL & VAR_0->SEGMask)) {

            VAR_9 = VAR_0->tlb->map_address(VAR_0, VAR_1, VAR_2, VAR_3, VAR_4, VAR_5);

	} else {

	    VAR_9 = TLBRET_BADADDR;

        }

    } else if (VAR_3 < 0xC000000000000000ULL) {

        

        

        if (VAR_8 && KX &&

            (VAR_3 & 0x07FFFFFFFFFFFFFFULL) < 0x0000000FFFFFFFFFULL) {

            *VAR_1 = VAR_3 & 0x0000000FFFFFFFFFULL;

            *VAR_2 = PAGE_READ | PAGE_WRITE;

	} else {

	    VAR_9 = TLBRET_BADADDR;

	}

    } else if (VAR_3 < 0xFFFFFFFF80000000ULL) {

        

	if (VAR_8 && KX &&

	    VAR_3 < (0xFFFFFFFF7FFFFFFFULL & VAR_0->SEGMask)) {

            VAR_9 = VAR_0->tlb->map_address(VAR_0, VAR_1, VAR_2, VAR_3, VAR_4, VAR_5);

	} else {

	    VAR_9 = TLBRET_BADADDR;

	}

#endif

    } else if (VAR_3 < (int32_t)0xA0000000UL) {

        

        if (VAR_8) {

            *VAR_1 = VAR_3 - (int32_t)0x80000000UL;

            *VAR_2 = PAGE_READ | PAGE_WRITE;

        } else {

            VAR_9 = TLBRET_BADADDR;

        }

    } else if (VAR_3 < (int32_t)0xC0000000UL) {

        

        if (VAR_8) {

            *VAR_1 = VAR_3 - (int32_t)0xA0000000UL;

            *VAR_2 = PAGE_READ | PAGE_WRITE;

        } else {

            VAR_9 = TLBRET_BADADDR;

        }

    } else if (VAR_3 < (int32_t)0xE0000000UL) {

        

        if (VAR_7 || VAR_8) {

            VAR_9 = VAR_0->tlb->map_address(VAR_0, VAR_1, VAR_2, VAR_3, VAR_4, VAR_5);

        } else {

            VAR_9 = TLBRET_BADADDR;

        }

    } else {

        

        

        if (VAR_8) {

            VAR_9 = VAR_0->tlb->map_address(VAR_0, VAR_1, VAR_2, VAR_3, VAR_4, VAR_5);

        } else {

            VAR_9 = TLBRET_BADADDR;

        }

    }

#if 0

    if (logfile) {

        fprintf(logfile, TARGET_FMT_lx " %d %d => " TARGET_FMT_lx " %d (%d)\n",

		VAR_3, VAR_4, VAR_5, *VAR_1, *VAR_2, VAR_9);

    }

#endif



    return VAR_9;

}

static int FUNC_0 (CPUState *VAR_0, target_ulong *VAR_1,
int *VAR_2, target_ulong VAR_3,
int VAR_4, int VAR_5)
{ int VAR_6 = (VAR_0->hflags & MIPS_HFLAG_MODE) == MIPS_HFLAG_UM; int VAR_7 = (VAR_0->hflags & MIPS_HFLAG_MODE) == MIPS_HFLAG_SM; int VAR_8 = !VAR_6 && !VAR_7; #if defined(TARGET_MIPS64)
int UX = (VAR_0->CP0_Status & (1 << CP0St_UX)) != 0; int SX = (VAR_0->CP0_Status & (1 << CP0St_SX)) != 0; int KX = (VAR_0->CP0_Status & (1 << CP0St_KX)) != 0; #endif
int VAR_9 = TLBRET_MATCH; #if 0
if (logfile) { fprintf(logfile, "user mode %d h %08x\n",
VAR_6, VAR_0->hflags); } #endif
if (VAR_3 <= (int32_t)0x7FFFFFFFUL) { if (VAR_0->CP0_Status & (1 << CP0St_ERL)) { *VAR_1 = VAR_3 & 0xFFFFFFFF; *VAR_2 = PAGE_READ | PAGE_WRITE; } else { VAR_9 = VAR_0->tlb->map_address(VAR_0, VAR_1, VAR_2, VAR_3, VAR_4, VAR_5); } #if defined(TARGET_MIPS64)
} else if (VAR_3 < 0x4000000000000000ULL) { if (UX && VAR_3 < (0x3FFFFFFFFFFFFFFFULL & VAR_0->SEGMask)) { VAR_9 = VAR_0->tlb->map_address(VAR_0, VAR_1, VAR_2, VAR_3, VAR_4, VAR_5); } else { VAR_9 = TLBRET_BADADDR; } } else if (VAR_3 < 0x8000000000000000ULL) { if ((VAR_7 || VAR_8) &&
SX && VAR_3 < (0x7FFFFFFFFFFFFFFFULL & VAR_0->SEGMask)) { VAR_9 = VAR_0->tlb->map_address(VAR_0, VAR_1, VAR_2, VAR_3, VAR_4, VAR_5); } else { VAR_9 = TLBRET_BADADDR; } } else if (VAR_3 < 0xC000000000000000ULL) { if (VAR_8 && KX &&
(VAR_3 & 0x07FFFFFFFFFFFFFFULL) < 0x0000000FFFFFFFFFULL) { *VAR_1 = VAR_3 & 0x0000000FFFFFFFFFULL; *VAR_2 = PAGE_READ | PAGE_WRITE; } else { VAR_9 = TLBRET_BADADDR; } } else if (VAR_3 < 0xFFFFFFFF80000000ULL) { if (VAR_8 && KX &&
VAR_3 < (0xFFFFFFFF7FFFFFFFULL & VAR_0->SEGMask)) { VAR_9 = VAR_0->tlb->map_address(VAR_0, VAR_1, VAR_2, VAR_3, VAR_4, VAR_5); } else { VAR_9 = TLBRET_BADADDR; } #endif
} else if (VAR_3 < (int32_t)0xA0000000UL) { if (VAR_8) { *VAR_1 = VAR_3 - (int32_t)0x80000000UL; *VAR_2 = PAGE_READ | PAGE_WRITE; } else { VAR_9 = TLBRET_BADADDR; } } else if (VAR_3 < (int32_t)0xC0000000UL) { if (VAR_8) { *VAR_1 = VAR_3 - (int32_t)0xA0000000UL; *VAR_2 = PAGE_READ | PAGE_WRITE; } else { VAR_9 = TLBRET_BADADDR; } } else if (VAR_3 < (int32_t)0xE0000000UL) { if (VAR_7 || VAR_8) { VAR_9 = VAR_0->tlb->map_address(VAR_0, VAR_1, VAR_2, VAR_3, VAR_4, VAR_5); } else { VAR_9 = TLBRET_BADADDR; } } else { if (VAR_8) { VAR_9 = VAR_0->tlb->map_address(VAR_0, VAR_1, VAR_2, VAR_3, VAR_4, VAR_5); } else { VAR_9 = TLBRET_BADADDR; } } #if 0
if (logfile) { fprintf(logfile, TARGET_FMT_lx " %d %d => " TARGET_FMT_lx " %d (%d)\n",
VAR_3, VAR_4, VAR_5, *VAR_1, *VAR_2, VAR_9); } #endif
return VAR_9; }