int cpu_ppc_handle_mmu_fault (CPUState *env, uint32_t address, int rw,

                              int is_user, int is_softmmu)

{

    uint32_t physical;

    int prot;

    int exception = 0, error_code = 0;

    int access_type;

    int ret = 0;



//    printf("%s 0\n", __func__);

    access_type = env->access_type;

    if (env->user_mode_only) {

        /* user mode only emulation */

        ret = -2;

        goto do_fault;

    }

    /* NASTY BUG workaround */

    if (access_type == ACCESS_CODE && rw) {

	printf("%s: ERROR WRITE CODE ACCESS\n", __func__);

	access_type = ACCESS_INT;

    }

    ret = get_physical_address(env, &physical, &prot,

                               address, rw, access_type);

    if (ret == 0) {

	ret = tlb_set_page(env, address & ~0xFFF, physical, prot,

			   is_user, is_softmmu);

    } else if (ret < 0) {

    do_fault:

#if defined (DEBUG_MMU)

	if (loglevel > 0)

	    cpu_ppc_dump_state(env, logfile, 0);

#endif

        if (access_type == ACCESS_CODE) {

            exception = EXCP_ISI;

            switch (ret) {

            case -1:

                /* No matches in page tables */

                error_code = EXCP_ISI_TRANSLATE;

                break;

            case -2:

                /* Access rights violation */

                error_code = EXCP_ISI_PROT;

                break;

            case -3:

		/* No execute protection violation */

                error_code = EXCP_ISI_NOEXEC;

                break;

            case -4:

                /* Direct store exception */

                /* No code fetch is allowed in direct-store areas */

                error_code = EXCP_ISI_DIRECT;

                break;

            }

        } else {

            exception = EXCP_DSI;

            switch (ret) {

            case -1:

                /* No matches in page tables */

                error_code = EXCP_DSI_TRANSLATE;

                break;

            case -2:

                /* Access rights violation */

                error_code = EXCP_DSI_PROT;

                break;

            case -4:

                /* Direct store exception */

                switch (access_type) {

                case ACCESS_FLOAT:

                    /* Floating point load/store */

                    exception = EXCP_ALIGN;

                    error_code = EXCP_ALIGN_FP;

                    break;

                case ACCESS_RES:

                    /* lwarx, ldarx or srwcx. */

                    exception = EXCP_DSI;

                    error_code = EXCP_DSI_NOTSUP | EXCP_DSI_DIRECT;

                    break;

                case ACCESS_EXT:

                    /* eciwx or ecowx */

                    exception = EXCP_DSI;

                    error_code = EXCP_DSI_NOTSUP | EXCP_DSI_DIRECT |

			EXCP_DSI_ECXW;

                    break;

                default:

		    printf("DSI: invalid exception (%d)\n", ret);

                    exception = EXCP_PROGRAM;

                    error_code = EXCP_INVAL | EXCP_INVAL_INVAL;

                    break;

                }

            }

            if (rw)

                error_code |= EXCP_DSI_STORE;

	    /* Store fault address */

	    env->spr[DAR] = address;

        }

#if 0

        printf("%s: set exception to %d %02x\n",

               __func__, exception, error_code);

#endif

        env->exception_index = exception;

        env->error_code = error_code;

        ret = 1;

    }



    return ret;

}

int cpu_ppc_handle_mmu_fault (CPUState *env, uint32_t address, int rw,

                              int is_user, int is_softmmu)

{

    uint32_t physical;

    int prot;

    int exception = 0, error_code = 0;

    int access_type;

    int ret = 0;





    access_type = env->access_type;

    if (env->user_mode_only) {

        

        ret = -2;

        goto do_fault;

    }

    

    if (access_type == ACCESS_CODE && rw) {

	printf("%s: ERROR WRITE CODE ACCESS\n", __func__);

	access_type = ACCESS_INT;

    }

    ret = get_physical_address(env, &physical, &prot,

                               address, rw, access_type);

    if (ret == 0) {

	ret = tlb_set_page(env, address & ~0xFFF, physical, prot,

			   is_user, is_softmmu);

    } else if (ret < 0) {

    do_fault:

#if defined (DEBUG_MMU)

	if (loglevel > 0)

	    cpu_ppc_dump_state(env, logfile, 0);

#endif

        if (access_type == ACCESS_CODE) {

            exception = EXCP_ISI;

            switch (ret) {

            case -1:

                

                error_code = EXCP_ISI_TRANSLATE;

                break;

            case -2:

                

                error_code = EXCP_ISI_PROT;

                break;

            case -3:

		

                error_code = EXCP_ISI_NOEXEC;

                break;

            case -4:

                

                

                error_code = EXCP_ISI_DIRECT;

                break;

            }

        } else {

            exception = EXCP_DSI;

            switch (ret) {

            case -1:

                

                error_code = EXCP_DSI_TRANSLATE;

                break;

            case -2:

                

                error_code = EXCP_DSI_PROT;

                break;

            case -4:

                

                switch (access_type) {

                case ACCESS_FLOAT:

                    

                    exception = EXCP_ALIGN;

                    error_code = EXCP_ALIGN_FP;

                    break;

                case ACCESS_RES:

                    

                    exception = EXCP_DSI;

                    error_code = EXCP_DSI_NOTSUP | EXCP_DSI_DIRECT;

                    break;

                case ACCESS_EXT:

                    

                    exception = EXCP_DSI;

                    error_code = EXCP_DSI_NOTSUP | EXCP_DSI_DIRECT |

			EXCP_DSI_ECXW;

                    break;

                default:

		    printf("DSI: invalid exception (%d)\n", ret);

                    exception = EXCP_PROGRAM;

                    error_code = EXCP_INVAL | EXCP_INVAL_INVAL;

                    break;

                }

            }

            if (rw)

                error_code |= EXCP_DSI_STORE;

	    

	    env->spr[DAR] = address;

        }

#if 0

        printf("%s: set exception to %d %02x\n",

               __func__, exception, error_code);

#endif

        env->exception_index = exception;

        env->error_code = error_code;

        ret = 1;

    }



    return ret;

}

int FUNC_0 (CPUState *VAR_0, uint32_t VAR_1, int VAR_2,

                              int VAR_3, int VAR_4)

{

    uint32_t physical;

    int VAR_5;

    int VAR_6 = 0, VAR_7 = 0;

    int VAR_8;

    int VAR_9 = 0;





    VAR_8 = VAR_0->VAR_8;

    if (VAR_0->user_mode_only) {

        

        VAR_9 = -2;

        goto do_fault;

    }

    

    if (VAR_8 == ACCESS_CODE && VAR_2) {

	printf("%s: ERROR WRITE CODE ACCESS\n", __func__);

	VAR_8 = ACCESS_INT;

    }

    VAR_9 = get_physical_address(VAR_0, &physical, &VAR_5,

                               VAR_1, VAR_2, VAR_8);

    if (VAR_9 == 0) {

	VAR_9 = tlb_set_page(VAR_0, VAR_1 & ~0xFFF, physical, VAR_5,

			   VAR_3, VAR_4);

    } else if (VAR_9 < 0) {

    do_fault:

#if defined (DEBUG_MMU)

	if (loglevel > 0)

	    cpu_ppc_dump_state(VAR_0, logfile, 0);

#endif

        if (VAR_8 == ACCESS_CODE) {

            VAR_6 = EXCP_ISI;

            switch (VAR_9) {

            case -1:

                

                VAR_7 = EXCP_ISI_TRANSLATE;

                break;

            case -2:

                

                VAR_7 = EXCP_ISI_PROT;

                break;

            case -3:

		

                VAR_7 = EXCP_ISI_NOEXEC;

                break;

            case -4:

                

                

                VAR_7 = EXCP_ISI_DIRECT;

                break;

            }

        } else {

            VAR_6 = EXCP_DSI;

            switch (VAR_9) {

            case -1:

                

                VAR_7 = EXCP_DSI_TRANSLATE;

                break;

            case -2:

                

                VAR_7 = EXCP_DSI_PROT;

                break;

            case -4:

                

                switch (VAR_8) {

                case ACCESS_FLOAT:

                    

                    VAR_6 = EXCP_ALIGN;

                    VAR_7 = EXCP_ALIGN_FP;

                    break;

                case ACCESS_RES:

                    

                    VAR_6 = EXCP_DSI;

                    VAR_7 = EXCP_DSI_NOTSUP | EXCP_DSI_DIRECT;

                    break;

                case ACCESS_EXT:

                    

                    VAR_6 = EXCP_DSI;

                    VAR_7 = EXCP_DSI_NOTSUP | EXCP_DSI_DIRECT |

			EXCP_DSI_ECXW;

                    break;

                default:

		    printf("DSI: invalid VAR_6 (%d)\n", VAR_9);

                    VAR_6 = EXCP_PROGRAM;

                    VAR_7 = EXCP_INVAL | EXCP_INVAL_INVAL;

                    break;

                }

            }

            if (VAR_2)

                VAR_7 |= EXCP_DSI_STORE;

	    

	    VAR_0->spr[DAR] = VAR_1;

        }

#if 0

        printf("%s: set VAR_6 to %d %02x\n",

               __func__, VAR_6, VAR_7);

#endif

        VAR_0->exception_index = VAR_6;

        VAR_0->VAR_7 = VAR_7;

        VAR_9 = 1;

    }



    return VAR_9;

}

int FUNC_0 (CPUState *VAR_0, uint32_t VAR_1, int VAR_2,
int VAR_3, int VAR_4)
{ uint32_t physical; int VAR_5; int VAR_6 = 0, VAR_7 = 0; int VAR_8; int VAR_9 = 0; VAR_8 = VAR_0->VAR_8; if (VAR_0->user_mode_only) { VAR_9 = -2; goto do_fault; } if (VAR_8 == ACCESS_CODE && VAR_2) { printf("%s: ERROR WRITE CODE ACCESS\n", __func__); VAR_8 = ACCESS_INT; } VAR_9 = get_physical_address(VAR_0, &physical, &VAR_5,
VAR_1, VAR_2, VAR_8); if (VAR_9 == 0) { VAR_9 = tlb_set_page(VAR_0, VAR_1 & ~0xFFF, physical, VAR_5,
VAR_3, VAR_4); } else if (VAR_9 < 0) { do_fault:
#if defined (DEBUG_MMU)
if (loglevel > 0)
cpu_ppc_dump_state(VAR_0, logfile, 0); #endif
if (VAR_8 == ACCESS_CODE) { VAR_6 = EXCP_ISI; switch (VAR_9) { case -1:
VAR_7 = EXCP_ISI_TRANSLATE; break; case -2:
VAR_7 = EXCP_ISI_PROT; break; case -3:
VAR_7 = EXCP_ISI_NOEXEC; break; case -4:
VAR_7 = EXCP_ISI_DIRECT; break; } } else { VAR_6 = EXCP_DSI; switch (VAR_9) { case -1:
VAR_7 = EXCP_DSI_TRANSLATE; break; case -2:
VAR_7 = EXCP_DSI_PROT; break; case -4:
switch (VAR_8) { case ACCESS_FLOAT:
VAR_6 = EXCP_ALIGN; VAR_7 = EXCP_ALIGN_FP; break; case ACCESS_RES:
VAR_6 = EXCP_DSI; VAR_7 = EXCP_DSI_NOTSUP | EXCP_DSI_DIRECT; break; case ACCESS_EXT:
VAR_6 = EXCP_DSI; VAR_7 = EXCP_DSI_NOTSUP | EXCP_DSI_DIRECT |
EXCP_DSI_ECXW; break; default:
printf("DSI: invalid VAR_6 (%d)\n", VAR_9); VAR_6 = EXCP_PROGRAM; VAR_7 = EXCP_INVAL | EXCP_INVAL_INVAL; break; } } if (VAR_2)
VAR_7 |= EXCP_DSI_STORE; VAR_0->spr[DAR] = VAR_1; } #if 0
printf("%s: set VAR_6 to %d %02x\n",
__func__, VAR_6, VAR_7); #endif
VAR_0->exception_index = VAR_6; VAR_0->VAR_7 = VAR_7; VAR_9 = 1; } return VAR_9; }