static int get_phys_addr_v6(CPUState *env, uint32_t address, int access_type,

			    int is_user, uint32_t *phys_ptr, int *prot)

{

    int code;

    uint32_t table;

    uint32_t desc;

    uint32_t xn;

    int type;

    int ap;

    int domain;

    uint32_t phys_addr;



    /* Pagetable walk.  */

    /* Lookup l1 descriptor.  */

    table = get_level1_table_address(env, address);

    desc = ldl_phys(table);

    type = (desc & 3);

    if (type == 0) {

        /* Section translation fault.  */

        code = 5;

        domain = 0;

        goto do_fault;

    } else if (type == 2 && (desc & (1 << 18))) {

        /* Supersection.  */

        domain = 0;

    } else {

        /* Section or page.  */

        domain = (desc >> 4) & 0x1e;

    }

    domain = (env->cp15.c3 >> domain) & 3;

    if (domain == 0 || domain == 2) {

        if (type == 2)

            code = 9; /* Section domain fault.  */

        else

            code = 11; /* Page domain fault.  */

        goto do_fault;

    }

    if (type == 2) {

        if (desc & (1 << 18)) {

            /* Supersection.  */

            phys_addr = (desc & 0xff000000) | (address & 0x00ffffff);

        } else {

            /* Section.  */

            phys_addr = (desc & 0xfff00000) | (address & 0x000fffff);

        }

        ap = ((desc >> 10) & 3) | ((desc >> 13) & 4);

        xn = desc & (1 << 4);

        code = 13;

    } else {

        /* Lookup l2 entry.  */

        table = (desc & 0xfffffc00) | ((address >> 10) & 0x3fc);

        desc = ldl_phys(table);

        ap = ((desc >> 4) & 3) | ((desc >> 7) & 4);

        switch (desc & 3) {

        case 0: /* Page translation fault.  */

            code = 7;

            goto do_fault;

        case 1: /* 64k page.  */

            phys_addr = (desc & 0xffff0000) | (address & 0xffff);

            xn = desc & (1 << 15);

            break;

        case 2: case 3: /* 4k page.  */

            phys_addr = (desc & 0xfffff000) | (address & 0xfff);

            xn = desc & 1;

            break;

        default:

            /* Never happens, but compiler isn't smart enough to tell.  */

            abort();

        }

        code = 15;

    }

    if (xn && access_type == 2)

        goto do_fault;



    /* The simplified model uses AP[0] as an access control bit.  */

    if ((env->cp15.c1_sys & (1 << 29)) && (ap & 1) == 0) {

        /* Access flag fault.  */

        code = (code == 15) ? 6 : 3;

        goto do_fault;

    }

    *prot = check_ap(env, ap, domain, access_type, is_user);

    if (!*prot) {

        /* Access permission fault.  */

        goto do_fault;

    }

    *phys_ptr = phys_addr;

    return 0;

do_fault:

    return code | (domain << 4);

}

static int get_phys_addr_v6(CPUState *env, uint32_t address, int access_type,

			    int is_user, uint32_t *phys_ptr, int *prot)

{

    int code;

    uint32_t table;

    uint32_t desc;

    uint32_t xn;

    int type;

    int ap;

    int domain;

    uint32_t phys_addr;



    

    

    table = get_level1_table_address(env, address);

    desc = ldl_phys(table);

    type = (desc & 3);

    if (type == 0) {

        

        code = 5;

        domain = 0;

        goto do_fault;

    } else if (type == 2 && (desc & (1 << 18))) {

        

        domain = 0;

    } else {

        

        domain = (desc >> 4) & 0x1e;

    }

    domain = (env->cp15.c3 >> domain) & 3;

    if (domain == 0 || domain == 2) {

        if (type == 2)

            code = 9; 

        else

            code = 11; 

        goto do_fault;

    }

    if (type == 2) {

        if (desc & (1 << 18)) {

            

            phys_addr = (desc & 0xff000000) | (address & 0x00ffffff);

        } else {

            

            phys_addr = (desc & 0xfff00000) | (address & 0x000fffff);

        }

        ap = ((desc >> 10) & 3) | ((desc >> 13) & 4);

        xn = desc & (1 << 4);

        code = 13;

    } else {

        

        table = (desc & 0xfffffc00) | ((address >> 10) & 0x3fc);

        desc = ldl_phys(table);

        ap = ((desc >> 4) & 3) | ((desc >> 7) & 4);

        switch (desc & 3) {

        case 0: 

            code = 7;

            goto do_fault;

        case 1: 

            phys_addr = (desc & 0xffff0000) | (address & 0xffff);

            xn = desc & (1 << 15);

            break;

        case 2: case 3: 

            phys_addr = (desc & 0xfffff000) | (address & 0xfff);

            xn = desc & 1;

            break;

        default:

            

            abort();

        }

        code = 15;

    }

    if (xn && access_type == 2)

        goto do_fault;



    

    if ((env->cp15.c1_sys & (1 << 29)) && (ap & 1) == 0) {

        

        code = (code == 15) ? 6 : 3;

        goto do_fault;

    }

    *prot = check_ap(env, ap, domain, access_type, is_user);

    if (!*prot) {

        

        goto do_fault;

    }

    *phys_ptr = phys_addr;

    return 0;

do_fault:

    return code | (domain << 4);

}

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

			    int VAR_3, uint32_t *VAR_4, int *VAR_5)

{

    int VAR_6;

    uint32_t table;

    uint32_t desc;

    uint32_t xn;

    int VAR_7;

    int VAR_8;

    int VAR_9;

    uint32_t phys_addr;



    

    

    table = get_level1_table_address(VAR_0, VAR_1);

    desc = ldl_phys(table);

    VAR_7 = (desc & 3);

    if (VAR_7 == 0) {

        

        VAR_6 = 5;

        VAR_9 = 0;

        goto do_fault;

    } else if (VAR_7 == 2 && (desc & (1 << 18))) {

        

        VAR_9 = 0;

    } else {

        

        VAR_9 = (desc >> 4) & 0x1e;

    }

    VAR_9 = (VAR_0->cp15.c3 >> VAR_9) & 3;

    if (VAR_9 == 0 || VAR_9 == 2) {

        if (VAR_7 == 2)

            VAR_6 = 9; 

        else

            VAR_6 = 11; 

        goto do_fault;

    }

    if (VAR_7 == 2) {

        if (desc & (1 << 18)) {

            

            phys_addr = (desc & 0xff000000) | (VAR_1 & 0x00ffffff);

        } else {

            

            phys_addr = (desc & 0xfff00000) | (VAR_1 & 0x000fffff);

        }

        VAR_8 = ((desc >> 10) & 3) | ((desc >> 13) & 4);

        xn = desc & (1 << 4);

        VAR_6 = 13;

    } else {

        

        table = (desc & 0xfffffc00) | ((VAR_1 >> 10) & 0x3fc);

        desc = ldl_phys(table);

        VAR_8 = ((desc >> 4) & 3) | ((desc >> 7) & 4);

        switch (desc & 3) {

        case 0: 

            VAR_6 = 7;

            goto do_fault;

        case 1: 

            phys_addr = (desc & 0xffff0000) | (VAR_1 & 0xffff);

            xn = desc & (1 << 15);

            break;

        case 2: case 3: 

            phys_addr = (desc & 0xfffff000) | (VAR_1 & 0xfff);

            xn = desc & 1;

            break;

        default:

            

            abort();

        }

        VAR_6 = 15;

    }

    if (xn && VAR_2 == 2)

        goto do_fault;



    

    if ((VAR_0->cp15.c1_sys & (1 << 29)) && (VAR_8 & 1) == 0) {

        

        VAR_6 = (VAR_6 == 15) ? 6 : 3;

        goto do_fault;

    }

    *VAR_5 = check_ap(VAR_0, VAR_8, VAR_9, VAR_2, VAR_3);

    if (!*VAR_5) {

        

        goto do_fault;

    }

    *VAR_4 = phys_addr;

    return 0;

do_fault:

    return VAR_6 | (VAR_9 << 4);

}

static int FUNC_0(CPUState *VAR_0, uint32_t VAR_1, int VAR_2,
int VAR_3, uint32_t *VAR_4, int *VAR_5)
{ int VAR_6; uint32_t table; uint32_t desc; uint32_t xn; int VAR_7; int VAR_8; int VAR_9; uint32_t phys_addr; table = get_level1_table_address(VAR_0, VAR_1); desc = ldl_phys(table); VAR_7 = (desc & 3); if (VAR_7 == 0) { VAR_6 = 5; VAR_9 = 0; goto do_fault; } else if (VAR_7 == 2 && (desc & (1 << 18))) { VAR_9 = 0; } else { VAR_9 = (desc >> 4) & 0x1e; } VAR_9 = (VAR_0->cp15.c3 >> VAR_9) & 3; if (VAR_9 == 0 || VAR_9 == 2) { if (VAR_7 == 2)
VAR_6 = 9; else
VAR_6 = 11; goto do_fault; } if (VAR_7 == 2) { if (desc & (1 << 18)) { phys_addr = (desc & 0xff000000) | (VAR_1 & 0x00ffffff); } else { phys_addr = (desc & 0xfff00000) | (VAR_1 & 0x000fffff); } VAR_8 = ((desc >> 10) & 3) | ((desc >> 13) & 4); xn = desc & (1 << 4); VAR_6 = 13; } else { table = (desc & 0xfffffc00) | ((VAR_1 >> 10) & 0x3fc); desc = ldl_phys(table); VAR_8 = ((desc >> 4) & 3) | ((desc >> 7) & 4); switch (desc & 3) { case 0:
VAR_6 = 7; goto do_fault; case 1:
phys_addr = (desc & 0xffff0000) | (VAR_1 & 0xffff); xn = desc & (1 << 15); break; case 2: case 3:
phys_addr = (desc & 0xfffff000) | (VAR_1 & 0xfff); xn = desc & 1; break; default:
abort(); } VAR_6 = 15; } if (xn && VAR_2 == 2)
goto do_fault; if ((VAR_0->cp15.c1_sys & (1 << 29)) && (VAR_8 & 1) == 0) { VAR_6 = (VAR_6 == 15) ? 6 : 3; goto do_fault; } *VAR_5 = check_ap(VAR_0, VAR_8, VAR_9, VAR_2, VAR_3); if (!*VAR_5) { goto do_fault; } *VAR_4 = phys_addr; return 0; do_fault:
return VAR_6 | (VAR_9 << 4); }