removed stdout reference (not portable)
[qemu] / target-ppc / helper.c
index dc2737e..55fe2b2 100644 (file)
@@ -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 <sys/mman.h>
-
 #include "exec.h"
 #if defined (USE_OPEN_FIRMWARE)
 #include <time.h>
 //#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;
@@ -203,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:
@@ -213,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");
@@ -264,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) {
@@ -401,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 */
@@ -419,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;
 }
 
@@ -483,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);
@@ -502,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;
@@ -673,11 +631,14 @@ uint32_t _load_msr (CPUState *env)
 
 void _store_msr (CPUState *env, uint32_t value)
 {
+#if 0 // TRY
     if (((value >> MSR_IR) & 0x01) != msr_ir ||
-        ((value >> MSR_DR) & 0x01) != msr_dr) {
+        ((value >> MSR_DR) & 0x01) != msr_dr)
+    {
         /* Flush all tlb when changing translation mode or privilege level */
        tlb_flush(env, 1);
     }
+#endif
     msr_pow = (value >> MSR_POW) & 0x03;
     msr_ile = (value >> MSR_ILE) & 0x01;
     msr_ee = (value >> MSR_EE) & 0x01;
@@ -703,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) 
@@ -744,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:
@@ -814,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;
@@ -846,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:
@@ -866,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;
@@ -939,4 +892,5 @@ void do_interrupt (CPUState *env)
     T0 = 0;
 #endif
 #endif
+    env->exception_index = -1;
 }