ppc fixes - gcc 3.4 compile fix (initial patch by Jocelyn Mayer)
[qemu] / target-ppc / helper.c
index 55fe2b2..21e8900 100644 (file)
@@ -29,8 +29,6 @@
 
 /*****************************************************************************/
 /* PPC MMU emulation */
-int cpu_ppc_handle_mmu_fault (CPUState *env, uint32_t address, int rw,
-                              int is_user, int is_softmmu);
 
 /* Perform BAT hit & translation */
 static int get_bat (CPUState *env, uint32_t *real, int *prot,
@@ -131,8 +129,8 @@ static int find_pte (uint32_t *RPN, int *prot, uint32_t base, uint32_t va,
     int ret = -1; /* No entry found */
 
     for (i = 0; i < 8; i++) {
-        pte0 = ldl_raw(phys_ram_base + base + (i * 8));
-        pte1 =  ldl_raw(phys_ram_base + base + (i * 8) + 4);
+        pte0 = ldl_phys(base + (i * 8));
+        pte1 =  ldl_phys(base + (i * 8) + 4);
 #if defined (DEBUG_MMU)
        if (loglevel > 0) {
            fprintf(logfile, "Load pte from 0x%08x => 0x%08x 0x%08x "
@@ -222,7 +220,7 @@ static int find_pte (uint32_t *RPN, int *prot, uint32_t base, uint32_t va,
             }
         }
         if (store) {
-           stl_raw(phys_ram_base + base + (good * 8) + 4, keep);
+           stl_phys_notdirty(base + (good * 8) + 4, keep);
        }
     }
 
@@ -421,7 +419,7 @@ target_ulong cpu_get_phys_page_debug(CPUState *env, target_ulong addr)
    NULL, it means that the function was called in C code (i.e. not
    from generated code or from helper.c) */
 /* XXX: fix it to restore all registers */
-void tlb_fill(unsigned long addr, int is_write, int is_user, void *retaddr)
+void tlb_fill(target_ulong addr, int is_write, int is_user, void *retaddr)
 {
     TranslationBlock *tb;
     CPUState *saved_env;
@@ -432,13 +430,13 @@ void tlb_fill(unsigned long addr, int is_write, int is_user, void *retaddr)
        generated code */
     saved_env = env;
     env = cpu_single_env;
+#if 0
     {
         unsigned long tlb_addrr, tlb_addrw;
         int index;
         index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
         tlb_addrr = env->tlb_read[is_user][index].address;
         tlb_addrw = env->tlb_write[is_user][index].address;
-#if 0
         if (loglevel) {
             fprintf(logfile,
                     "%s 1 %p %p idx=%d addr=0x%08lx tbl_addr=0x%08lx 0x%08lx "
@@ -447,8 +445,8 @@ void tlb_fill(unsigned long addr, int is_write, int is_user, void *retaddr)
                tlb_addrr, tlb_addrw, addr & TARGET_PAGE_MASK,
                tlb_addrr & (TARGET_PAGE_MASK | TLB_INVALID_MASK));
         }
-#endif
     }
+#endif
     ret = cpu_ppc_handle_mmu_fault(env, addr, is_write, is_user, 1);
     if (ret) {
         if (retaddr) {
@@ -463,20 +461,20 @@ void tlb_fill(unsigned long addr, int is_write, int is_user, void *retaddr)
         }
         do_raise_exception_err(env->exception_index, env->error_code);
     }
+#if 0
     {
         unsigned long tlb_addrr, tlb_addrw;
         int index;
         index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
         tlb_addrr = env->tlb_read[is_user][index].address;
         tlb_addrw = env->tlb_write[is_user][index].address;
-#if 0
         printf("%s 2 %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
     }
+#endif
     env = saved_env;
 }
 
@@ -496,18 +494,22 @@ int cpu_ppc_handle_mmu_fault (CPUState *env, uint32_t address, int rw,
     int access_type;
     int ret = 0;
 
-//    printf("%s 0\n", __func__);
-    access_type = env->access_type;
+    if (rw == 2) {
+        /* code access */
+        rw = 0;
+        access_type = ACCESS_CODE;
+    } else {
+        /* data access */
+        /* XXX: put correct access by using cpu_restore_state()
+           correctly */
+        access_type = ACCESS_INT;
+        //        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) {
@@ -517,7 +519,7 @@ int cpu_ppc_handle_mmu_fault (CPUState *env, uint32_t address, int rw,
     do_fault:
 #if defined (DEBUG_MMU)
        if (loglevel > 0)
-           cpu_ppc_dump_state(env, logfile, 0);
+           cpu_dump_state(env, logfile, fprintf, 0);
 #endif
         if (access_type == ACCESS_CODE) {
             exception = EXCP_ISI;
@@ -590,7 +592,6 @@ int cpu_ppc_handle_mmu_fault (CPUState *env, uint32_t address, int rw,
         env->error_code = error_code;
         ret = 1;
     }
-
     return ret;
 }
 
@@ -654,16 +655,21 @@ void _store_msr (CPUState *env, uint32_t value)
     msr_dr = (value >> MSR_DR) & 0x01;
     msr_ri = (value >> MSR_RI) & 0x01;
     msr_le = (value >> MSR_LE) & 0x01;
+    /* XXX: should enter PM state if msr_pow has been set */
 }
 
+#if defined (CONFIG_USER_ONLY)
 void do_interrupt (CPUState *env)
 {
-#if defined (CONFIG_USER_ONLY)
-    env->exception_index |= 0x100;
+    env->exception_index = -1;
+}
 #else
+void do_interrupt (CPUState *env)
+{
     uint32_t msr;
-    int excp = env->exception_index;
+    int excp;
 
+    excp = env->exception_index;
     msr = _load_msr(env);
 #if defined (DEBUG_EXCEPTIONS)
     if ((excp == EXCP_PROGRAM || excp == EXCP_DSI) && msr_pr == 1) 
@@ -671,11 +677,15 @@ void do_interrupt (CPUState *env)
         if (loglevel > 0) {
             fprintf(logfile, "Raise exception at 0x%08x => 0x%08x (%02x)\n",
                     env->nip, excp << 8, env->error_code);
-    }
+        }
        if (loglevel > 0)
-           cpu_ppc_dump_state(env, logfile, 0);
+           cpu_dump_state(env, logfile, fprintf, 0);
     }
 #endif
+    if (loglevel & CPU_LOG_INT) {
+        fprintf(logfile, "Raise exception at 0x%08x => 0x%08x (%02x)\n",
+                env->nip, excp << 8, env->error_code);
+    }
     /* Generate informations in save/restore registers */
     switch (excp) {
     case EXCP_OFCALL:
@@ -775,7 +785,7 @@ void do_interrupt (CPUState *env)
         /* Store exception cause */
         /* Get rS/rD and rA from faulting opcode */
         env->spr[DSISR] |=
-            (ldl_code((void *)(env->nip - 4)) & 0x03FF0000) >> 16;
+            (ldl_code((env->nip - 4)) & 0x03FF0000) >> 16;
         /* data location address has been stored
          * when the fault has been detected
          */
@@ -824,19 +834,29 @@ void do_interrupt (CPUState *env)
         }
         goto store_next;
     case EXCP_SYSCALL:
-#if defined (DEBUG_EXCEPTIONS)
-       if (msr_pr) {
-           if (loglevel) {
-               fprintf(logfile, "syscall %d 0x%08x 0x%08x 0x%08x 0x%08x\n",
-                       env->gpr[0], env->gpr[3], env->gpr[4],
-                       env->gpr[5], env->gpr[6]);
-           } else {
-               printf("syscall %d from 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
-                      env->gpr[0], env->nip, env->gpr[3], env->gpr[4],
-                      env->gpr[5], env->gpr[6]);
-           }
-       }
-#endif
+        if (loglevel & CPU_LOG_INT) {
+            fprintf(logfile, "syscall %d 0x%08x 0x%08x 0x%08x 0x%08x\n",
+                    env->gpr[0], env->gpr[3], env->gpr[4],
+                    env->gpr[5], env->gpr[6]);
+            if (env->gpr[0] == 4 && env->gpr[3] == 1) {
+                int len, addr, i;
+                uint8_t c;
+
+                fprintf(logfile, "write: ");
+                addr = env->gpr[4];
+                len = env->gpr[5];
+                if (len > 64)
+                    len = 64;
+                for(i = 0; i < len; i++) {
+                    c = 0;
+                    cpu_memory_rw_debug(env, addr + i, &c, 1, 0);
+                    if (c < 32 || c > 126)
+                        c = '.';
+                    fprintf(logfile, "%c", c);
+                }
+                fprintf(logfile, "\n");
+            }
+        }
         goto store_next;
     case EXCP_TRACE:
         goto store_next;
@@ -891,6 +911,6 @@ void do_interrupt (CPUState *env)
 #else
     T0 = 0;
 #endif
-#endif
     env->exception_index = -1;
 }
+#endif /* !CONFIG_USER_ONLY */