X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=target-ppc%2Fhelper.c;h=55fe2b22419b6583a744d2d4222ad9a8762475fa;hb=6d463de2b3e261e95f224767605eef02acbd2701;hp=ccfd2ea92603e0d72a8c6f663652b8200222e954;hpb=046d6672e2238342b1c174e45c41005be78285a7;p=qemu diff --git a/target-ppc/helper.c b/target-ppc/helper.c index ccfd2ea..55fe2b2 100644 --- a/target-ppc/helper.c +++ b/target-ppc/helper.c @@ -17,8 +17,6 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include - #include "exec.h" #if defined (USE_OPEN_FIRMWARE) #include @@ -29,50 +27,6 @@ //#define DEBUG_BATS //#define DEBUG_EXCEPTIONS -extern FILE *logfile, *stdout, *stderr; -void exit (int); -void abort (void); - -void cpu_loop_exit(void) -{ - longjmp(env->jmp_env, 1); -} - -void do_process_exceptions (void) -{ - cpu_loop_exit(); -} - -int check_exception_state (CPUState *env) -{ - int i; - - /* Process PPC exceptions */ - for (i = 1; i < EXCP_PPC_MAX; i++) { - if (env->exceptions & (1 << i)) { - switch (i) { - case EXCP_EXTERNAL: - case EXCP_DECR: - if (msr_ee == 0) - return 0; - break; - case EXCP_PROGRAM: - if (env->errors[EXCP_PROGRAM] == EXCP_FP && - msr_fe0 == 0 && msr_fe1 == 0) - return 0; - break; - default: - break; - } - env->exception_index = i; - env->error_code = env->errors[i]; - return 1; - } - } - - return 0; -} - /*****************************************************************************/ /* PPC MMU emulation */ int cpu_ppc_handle_mmu_fault (CPUState *env, uint32_t address, int rw, @@ -133,14 +87,14 @@ static int get_bat (CPUState *env, uint32_t *real, int *prot, ((virtual & 0x0FFE0000 & bl) | (*BATl & 0x0FFE0000)) | (virtual & 0x0001F000); if (*BATl & 0x00000001) - *prot = PROT_READ; + *prot = PAGE_READ; if (*BATl & 0x00000002) - *prot = PROT_WRITE | PROT_READ; + *prot = PAGE_WRITE | PAGE_READ; #if defined (DEBUG_BATS) if (loglevel > 0) { fprintf(logfile, "BAT %d match: r 0x%08x prot=%c%c\n", - i, *real, *prot & PROT_READ ? 'R' : '-', - *prot & PROT_WRITE ? 'W' : '-'); + i, *real, *prot & PAGE_READ ? 'R' : '-', + *prot & PAGE_WRITE ? 'W' : '-'); } #endif ret = 0; @@ -163,7 +117,6 @@ static int get_bat (CPUState *env, uint32_t *real, int *prot, *BATu, *BATl, BEPIu, BEPIl, bl); } #endif - env->spr[DAR] = virtual; } /* No hit */ return ret; @@ -204,9 +157,9 @@ static int find_pte (uint32_t *RPN, int *prot, uint32_t base, uint32_t va, } /* Check access rights */ if (key == 0) { - access = PROT_READ; + access = PAGE_READ; if ((pte1 & 0x00000003) != 0x3) - access |= PROT_WRITE; + access |= PAGE_WRITE; } else { switch (pte1 & 0x00000003) { case 0x0: @@ -214,16 +167,16 @@ static int find_pte (uint32_t *RPN, int *prot, uint32_t base, uint32_t va, break; case 0x1: case 0x3: - access = PROT_READ; + access = PAGE_READ; break; case 0x2: - access = PROT_READ | PROT_WRITE; + access = PAGE_READ | PAGE_WRITE; break; } } if (ret < 0) { - if ((rw == 0 && (access & PROT_READ)) || - (rw == 1 && (access & PROT_WRITE))) { + if ((rw == 0 && (access & PAGE_READ)) || + (rw == 1 && (access & PAGE_WRITE))) { #if defined (DEBUG_MMU) if (loglevel > 0) fprintf(logfile, "PTE access granted !\n"); @@ -265,7 +218,7 @@ static int find_pte (uint32_t *RPN, int *prot, uint32_t base, uint32_t va, store = 1; } else { /* Force page fault for first write access */ - *prot &= ~PROT_WRITE; + *prot &= ~PAGE_WRITE; } } if (store) { @@ -402,15 +355,16 @@ int get_physical_address (CPUState *env, uint32_t *physical, int *prot, uint32_t address, int rw, int access_type) { int ret; - +#if 0 if (loglevel > 0) { fprintf(logfile, "%s\n", __func__); } - - if ((access_type == ACCESS_CODE && msr_ir == 0) || msr_dr == 0) { +#endif + if ((access_type == ACCESS_CODE && msr_ir == 0) || + (access_type != ACCESS_CODE && msr_dr == 0)) { /* No address translation */ *physical = address & ~0xFFF; - *prot = PROT_READ | PROT_WRITE; + *prot = PAGE_READ | PAGE_WRITE; ret = 0; } else { /* Try to find a BAT */ @@ -420,11 +374,12 @@ int get_physical_address (CPUState *env, uint32_t *physical, int *prot, ret = get_segment(env, physical, prot, address, rw, access_type); } } +#if 0 if (loglevel > 0) { fprintf(logfile, "%s address %08x => %08x\n", __func__, address, *physical); } - +#endif return ret; } @@ -484,11 +439,14 @@ void tlb_fill(unsigned long addr, int is_write, int is_user, void *retaddr) tlb_addrr = env->tlb_read[is_user][index].address; tlb_addrw = env->tlb_write[is_user][index].address; #if 0 - printf("%s 1 %p %p idx=%d addr=0x%08lx tbl_addr=0x%08lx 0x%08lx " + if (loglevel) { + fprintf(logfile, + "%s 1 %p %p idx=%d addr=0x%08lx tbl_addr=0x%08lx 0x%08lx " "(0x%08lx 0x%08lx)\n", __func__, env, &env->tlb_read[is_user][index], index, addr, tlb_addrr, tlb_addrw, addr & TARGET_PAGE_MASK, tlb_addrr & (TARGET_PAGE_MASK | TLB_INVALID_MASK)); + } #endif } ret = cpu_ppc_handle_mmu_fault(env, addr, is_write, is_user, 1); @@ -503,8 +461,7 @@ void tlb_fill(unsigned long addr, int is_write, int is_user, void *retaddr) cpu_restore_state(tb, env, pc, NULL); } } - do_queue_exception_err(env->exception_index, env->error_code); - do_process_exceptions(); + do_raise_exception_err(env->exception_index, env->error_code); } { unsigned long tlb_addrr, tlb_addrw; @@ -543,12 +500,12 @@ int cpu_ppc_handle_mmu_fault (CPUState *env, uint32_t address, int rw, access_type = env->access_type; if (env->user_mode_only) { /* user mode only emulation */ - ret = -1; + ret = -2; goto do_fault; } /* NASTY BUG workaround */ if (access_type == ACCESS_CODE && rw) { - // printf("%s: ERROR WRITE CODE ACCESS\n", __func__); + printf("%s: ERROR WRITE CODE ACCESS\n", __func__); access_type = ACCESS_INT; } ret = get_physical_address(env, &physical, &prot, @@ -674,11 +631,14 @@ uint32_t _load_msr (CPUState *env) void _store_msr (CPUState *env, uint32_t value) { - if (((T0 >> MSR_IR) & 0x01) != msr_ir || - ((T0 >> MSR_DR) & 0x01) != msr_dr) { +#if 0 // TRY + if (((value >> MSR_IR) & 0x01) != msr_ir || + ((value >> MSR_DR) & 0x01) != msr_dr) + { /* Flush all tlb when changing translation mode or privilege level */ - do_tlbia(); + tlb_flush(env, 1); } +#endif msr_pow = (value >> MSR_POW) & 0x03; msr_ile = (value >> MSR_ILE) & 0x01; msr_ee = (value >> MSR_EE) & 0x01; @@ -704,9 +664,6 @@ void do_interrupt (CPUState *env) uint32_t msr; int excp = env->exception_index; - /* Dequeue PPC exceptions */ - if (excp < EXCP_PPC_MAX) - env->exceptions &= ~(1 << excp); msr = _load_msr(env); #if defined (DEBUG_EXCEPTIONS) if ((excp == EXCP_PROGRAM || excp == EXCP_DSI) && msr_pr == 1) @@ -745,13 +702,8 @@ void do_interrupt (CPUState *env) goto store_next; case EXCP_MACHINE_CHECK: if (msr_me == 0) { - printf("Machine check exception while not allowed !\n"); - if (loglevel) { - fprintf(logfile, - "Machine check exception while not allowed !\n"); + cpu_abort(env, "Machine check exception while not allowed\n"); } - abort(); - } msr_me = 0; break; case EXCP_DSI: @@ -815,7 +767,7 @@ void do_interrupt (CPUState *env) } #endif /* Requeue it */ - do_queue_exception(EXCP_EXTERNAL); + do_raise_exception(EXCP_EXTERNAL); return; } goto store_next; @@ -847,7 +799,7 @@ void do_interrupt (CPUState *env) env->fpscr[7] |= 0x4; break; case EXCP_INVAL: - printf("Invalid instruction at 0x%08x\n", env->nip); + // printf("Invalid instruction at 0x%08x\n", env->nip); msr |= 0x00080000; break; case EXCP_PRIV: @@ -867,7 +819,7 @@ void do_interrupt (CPUState *env) case EXCP_DECR: if (msr_ee == 0) { /* Requeue it */ - do_queue_exception(EXCP_DECR); + do_raise_exception(EXCP_DECR); return; } goto store_next; @@ -931,7 +883,7 @@ void do_interrupt (CPUState *env) env->nip = excp << 8; env->exception_index = EXCP_NONE; /* Invalidate all TLB as we may have changed translation mode */ - do_tlbia(); + tlb_flush(env, 1); /* ensure that no TB jump will be modified as the program flow was changed */ #ifdef __sparc__ @@ -940,4 +892,5 @@ void do_interrupt (CPUState *env) T0 = 0; #endif #endif + env->exception_index = -1; }