Index: trunk/hal/tsar_mips32/core/hal_exception.c
===================================================================
--- trunk/hal/tsar_mips32/core/hal_exception.c	(revision 401)
+++ trunk/hal/tsar_mips32/core/hal_exception.c	(revision 406)
@@ -24,4 +24,5 @@
 #include <hal_types.h>
 #include <hal_irqmask.h>
+#include <hal_special.h>
 #include <hal_exception.h>
 #include <thread.h>
@@ -35,5 +36,5 @@
 #include <syscalls.h>
 #include <remote_spinlock.h>
-#include <mips32_uzone.h>
+#include <hal_kentry.h>
 
 
@@ -57,13 +58,13 @@
 
 //////////////////////////////////////////////////////////////////////////////////////////
-// This enum defines the relevant subtypes for a MMU exception reported by the mips32.
+// This enum defines the mask valuesi for an MMU exception code reported by the mips32.
 //////////////////////////////////////////////////////////////////////////////////////////
 
 typedef enum
 {
-    MMU_EXCP_PAGE_UNMAPPED,
-    MMU_EXCP_USER_PRIVILEGE,
-    MMU_EXCP_USER_EXEC,
-    MMU_EXCP_USER_WRITE,
+    MMU_EXCP_PAGE_UNMAPPED   = 0x0003,
+    MMU_EXCP_USER_PRIVILEGE  = 0x0004,
+    MMU_EXCP_USER_WRITE      = 0x0008,
+    MMU_EXCP_USER_EXEC       = 0x1010,
 }
 mmu_exception_subtype_t;
@@ -86,5 +87,5 @@
 
 //////////////////////////////////////////////////////////////////////////////////////////
-// This static function is called when a FPU Coprocessor Unavailable exception has been 
+// This function is called when a FPU Coprocessor Unavailable exception has been 
 // detected for the calling thread. 
 // It enables the FPU, It saves the current FPU context in the current owner thread 
@@ -94,5 +95,5 @@
 // @ return always EXCP_NON_FATAL
 //////////////////////////////////////////////////////////////////////////////////////////
-static error_t hal_fpu_exception( thread_t * this )
+error_t hal_fpu_exception( thread_t * this )
 {
 	core_t   * core = this->core; 
@@ -119,5 +120,5 @@
 
 //////////////////////////////////////////////////////////////////////////////////////////
-// This static function is called when an MMU exception has been detected. 
+// This function is called when an MMU exception has been detected. 
 // It get the relevant exception arguments from the MMU.
 // It signal a fatal error in case of illegal access. In case of page unmapped
@@ -128,20 +129,25 @@
 //////////////////////////////////////////////////////////////////////////////////////////
 // @ this     : pointer on faulty thread descriptor.
+// @ is_ins   : IBE if true / DBE if false.
 // @ return EXCP_NON_FATAL / EXCP_USER_ERROR / EXCP_KERNEL_PANIC
 //////////////////////////////////////////////////////////////////////////////////////////
-static error_t hal_mmu_exception( thread_t * this ) 
-{
-	process_t      * process;     // local process descriptor
-    error_t          error;       // return value
-
-    reg_t            mmu_ins_excp_code;
-    reg_t            mmu_ins_bad_vaddr;
-    reg_t            mmu_dat_excp_code;
-    reg_t            mmu_dat_bad_vaddr;
-
-    intptr_t         bad_vaddr;
+error_t hal_mmu_exception( thread_t * this,
+                           bool_t     is_ins ) 
+{
+	process_t      * process;
+    error_t          error;
+
+    uint32_t         mmu_ins_excp_code;
+    uint32_t         mmu_ins_bad_vaddr;
+    uint32_t         mmu_dat_excp_code;
+    uint32_t         mmu_dat_bad_vaddr;
+
+    uint32_t         bad_vaddr;
     uint32_t         excp_code;
 	
-    process     = this->process;
+    process = this->process;
+
+    excp_dmsg("\n[DMSG] %s : enter for thread %x in process %x / is_ins = %d\n",
+    __FUNCTION__ , this->trdid , process->pid , is_ins );
 
     // get relevant values from MMU
@@ -151,33 +157,30 @@
 	                  &mmu_dat_bad_vaddr );
 
-    // get exception code and faulty vaddr
-    if( mmu_ins_excp_code )
+    excp_dmsg("\n[DMSG] %s : icode = %x / ivaddr = %x / dcode = %x / dvaddr = %x\n",
+    __FUNCTION__ , mmu_ins_excp_code , mmu_ins_bad_vaddr ,
+                   mmu_dat_excp_code , mmu_dat_bad_vaddr );
+
+    // get exception code and faulty vaddr, depending on IBE/DBE
+    if( is_ins )
     {
         excp_code = mmu_ins_excp_code;
         bad_vaddr = mmu_ins_bad_vaddr;
     }
-    else if( mmu_dat_excp_code )
+    else 
     {
         excp_code = mmu_dat_excp_code;
         bad_vaddr = mmu_dat_bad_vaddr;
     }
-    else
-    {
-         return EXCP_NON_FATAL;
-    }
-
-	vmm_dmsg("\n[INFO] %s : enters for thread %x / process %x"
-             " / bad_vaddr = %x / excep_code = %x\n", 
-		     __FUNCTION__, this->trdid , process->pid , bad_vaddr , excp_code );
-
-    // on TSAR, a kernel thread should not rise an MMU exception
-	assert( (this->type != THREAD_USER) , __FUNCTION__ ,
-    "thread %x is a kernel thread / vaddr = %x\n", this->trdid , bad_vaddr );
-  
+
+    excp_dmsg("\n[DMSG] %s : excp_code = %x / bad_vaddr = %x\n",
+    __FUNCTION__ , excp_code , bad_vaddr );
+
     // analyse exception code
     if( excp_code & MMU_EXCP_PAGE_UNMAPPED )
     {
+        excp_dmsg("\n[DMSG] %s : type PAGE_UNMAPPED\n", __FUNCTION__ );
+
         // enable IRQs before handling page fault
-        hal_enable_irq( NULL );
+        // hal_enable_irq( NULL );
 
         // try to map the unmapped PTE
@@ -185,9 +188,9 @@
                                        bad_vaddr >> CONFIG_PPM_PAGE_SHIFT );  // vpn
         // disable IRQs
-        hal_disable_irq( NULL );
+        // hal_disable_irq( NULL );
 
         if( error )     // not enough memory
         {
-            printk("\n[ERROR] in %s for thread %x : cannot map legal vaddr = %x\n",
+            printk("\n[ERROR] in %s for thread %x : cannot map vaddr = %x\n",
                __FUNCTION__ , this->trdid , bad_vaddr );
 
@@ -196,6 +199,6 @@
         else            // page fault successfully handled
         {
-            vmm_dmsg("\n[INFO] %s : page fault handled for vaddr = %x in thread %x\n",
-		             __FUNCTION__ , bad_vaddr , this->trdid );
+            excp_dmsg("\n[DMSG] %s : page fault handled / bad_vaddr = %x / excp_code = %x\n",
+		             __FUNCTION__ , bad_vaddr , excp_code );
   
             return EXCP_NON_FATAL;
@@ -223,5 +226,4 @@
         return EXCP_USER_ERROR;
     }
-
     else  // this is a kernel error => panic    
     {
@@ -309,13 +311,19 @@
 	excCode        = (regs_tbl[UZ_CR] >> 2) & 0xF;
 
+    excp_dmsg("\n[DMSG] %s : enter for thread %x in process %x / xcode = %x / cycle %d\n",
+    __FUNCTION__ , this->trdid , this->process->pid , excCode , hal_time_stamp() );
+
 	switch(excCode)
 	{
         case XCODE_DBE:     // can be non fatal
+        {
+		    error = hal_mmu_exception( this , false );  // data MMU exception
+            break;
+        }
 	    case XCODE_IBE:     // can be non fatal
         {
-		    error = hal_mmu_exception( this );
-        }
-		break;
-
+		    error = hal_mmu_exception( this , true );   // ins MMU exception
+		    break;
+        }
 	    case XCODE_CPU:    // can be non fatal
         {
@@ -328,7 +336,6 @@
 		        error = EXCP_USER_ERROR;
             }
-        }
-		break;
-
+		    break;
+        }
         case XCODE_OVR:    // user fatal error
         case XCODE_RI:     // user fatal error
@@ -337,7 +344,6 @@
         {
 		    error = EXCP_USER_ERROR;
-        }
-	    break;
-
+	        break;
+        }
         default:
         {
@@ -357,4 +363,8 @@
         hal_core_sleep();
     }
+
+    excp_dmsg("\n[DMSG] %s : exit for thread %x in process %x / cycle %d\n",
+    __FUNCTION__ , this->trdid , this->process->pid , hal_time_stamp() );
+
 }  // end hal_do_exception()
 
