Index: trunk/hal/tsar_mips32/core/hal_exception.c
===================================================================
--- trunk/hal/tsar_mips32/core/hal_exception.c	(revision 381)
+++ trunk/hal/tsar_mips32/core/hal_exception.c	(revision 391)
@@ -172,71 +172,10 @@
 		     __FUNCTION__, this->trdid , process->pid , bad_vaddr , excp_code );
 
-    // a kernel thread should not rise an MMU exception
-	if( this->type != THREAD_USER )
-	{
-		printk("\n[PANIC] in %s : thread %x is a kernel thread / vaddr = %x\n",
-		       __FUNCTION__ , this->trdid , bad_vaddr );
-		return EXCP_KERNEL_PANIC;
-	}
-  
-    // enable IRQs 
-	hal_enable_irq( NULL );
-
+    // 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 );
+  
     // vaddr must be contained in a registered vseg
-    vseg = vmm_get_vseg( process , bad_vaddr );
-
-    if( vseg == NULL )   // vseg not found in local cluster
-	{
-        // get extended pointer on reference process
-        xptr_t ref_xp = process->ref_xp;
-
-        // get cluster and local pointer on reference process 
-        cxy_t       ref_cxy = GET_CXY( ref_xp );
-        process_t * ref_ptr = (process_t *)GET_PTR( ref_xp );
-
-        if( local_cxy != ref_cxy )   // reference process is remote
-        {
-            // get extended pointer on reference vseg
-            xptr_t vseg_xp;
-            rpc_vmm_get_ref_vseg_client( ref_cxy , ref_ptr , bad_vaddr , &vseg_xp );
-            
-        
-            if( vseg == NULL )          // vseg not found => illegal user vaddr 
-            {
-                printk("\n[ERROR] in %s for thread %x : illegal vaddr = %x\n",
-                       __FUNCTION__ , this->trdid , bad_vaddr );
-
-                hal_disable_irq( NULL );
-		        return EXCP_USER_ERROR;
-            }
-            else                        // vseg found => make a local copy
-            {
-                // allocate a vseg in local cluster
-                vseg = vseg_alloc();
-
-                if( vseg == NULL )
-                {
-		            printk("\n[PANIC] in %s : no memory for vseg / thread = %x\n",
-		                   __FUNCTION__ , this->trdid );
-                    hal_disable_irq( NULL );
-		            return EXCP_KERNEL_PANIC;
-                }
-
-                // initialise local vseg from reference
-                vseg_init_from_ref( vseg , ref_xp );
-
-                // register local vseg in local VMM
-                error = vseg_attach( &process->vmm , vseg );
-            }
-        }
-        else                   // reference is local => illegal user vaddr
-        {
-            printk("\n[ERROR] in %s for thread %x : illegal vaddr = %x\n",
-                   __FUNCTION__ , this->trdid , bad_vaddr );
-
-            hal_disable_irq( NULL );
-		    return EXCP_USER_ERROR;
-        }
-    }
+    error = vmm_get_vseg( process , bad_vaddr , &vseg );
 
 	vmm_dmsg("\n[INFO] %s : found vseg for thread %x / vseg_min = %x / vseg_max = %x\n", 
@@ -246,24 +185,26 @@
     if( excp_code & MMU_EXCP_PAGE_UNMAPPED )
     {
+        // enable IRQs before handling page fault
+        hal_enable_irq( NULL );
+
         // try to map the unmapped PTE
         error = vmm_handle_page_fault( process, 
                                        vseg,
                                        bad_vaddr >> CONFIG_PPM_PAGE_SHIFT );  // vpn
-
-        if( error )
-        {
-            printk("\n[PANIC] in %s for thread %x : cannot map legal vaddr = %x\n",
+        // disable IRQs
+        hal_disable_irq( NULL );
+
+        if( error )     // not enough memory
+        {
+            printk("\n[ERROR] in %s for thread %x : cannot map legal vaddr = %x\n",
                __FUNCTION__ , this->trdid , bad_vaddr );
 
-            hal_disable_irq( NULL );
-		    return EXCP_KERNEL_PANIC;
-        }
-        else
+		    return EXCP_USER_ERROR;
+        } 
+        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 );
   
-            // page fault successfully handled
-            hal_disable_irq( NULL );
             return EXCP_NON_FATAL;
         }
@@ -274,5 +215,4 @@
                __FUNCTION__ , this->trdid , bad_vaddr );
 
-        hal_disable_irq( NULL );
         return EXCP_USER_ERROR;
     }
@@ -282,5 +222,4 @@
                __FUNCTION__ , this->trdid , bad_vaddr );
 
-        hal_disable_irq( NULL );
         return EXCP_USER_ERROR;
     }
@@ -290,5 +229,4 @@
                __FUNCTION__ , this->trdid , bad_vaddr );
 
-        hal_disable_irq( NULL );
         return EXCP_USER_ERROR;
     }
@@ -299,5 +237,4 @@
                __FUNCTION__ , this->trdid , excp_code , bad_vaddr );
 
-        hal_disable_irq( NULL );
         return EXCP_KERNEL_PANIC;
     }
