Index: /soft/giet_vm/giet_boot/boot.c
===================================================================
--- /soft/giet_vm/giet_boot/boot.c	(revision 818)
+++ /soft/giet_vm/giet_boot/boot.c	(revision 819)
@@ -405,5 +405,5 @@
     // The three flags (Local, Remote and Dirty) are set to 1 
     // to avoid hardware update for these flags, because GIET_VM 
-    // does use these flags.
+    // does not use these flags.
     unsigned int flags = 0;
     if (vseg->mode & C_MODE_MASK) flags |= PTE_C;
@@ -411,8 +411,11 @@
     if (vseg->mode & W_MODE_MASK) flags |= PTE_W;
     if (vseg->mode & U_MODE_MASK) flags |= PTE_U;
-    if ( global )                 flags |= PTE_G;
                                   flags |= PTE_L;
                                   flags |= PTE_R;
                                   flags |= PTE_D;
+
+#if GIET_USE_MMU_GLOBAL_FLAG
+    if ( global ) flags |= PTE_G;
+#endif
 
     // compute VPN, PPN and number of pages (big or small) 
@@ -849,9 +852,9 @@
 //              idle_thread context, the  HWI / PTI / WTI interrupt vectors,
 //              and the XCU HWI / PTI / WTI masks.
-// - In Step 2, it scan all threads in all vspaces to complete the threads contexts, 
+// - In Step 2, it scan all threads in all vspaces to complete the threads contexts,
 //              initialisation as specified in the mapping_info data structure,
-//              and set the CP0_SCHED register. 
+//              and set the CP0_SCHED register.
 ////////////////////////////////////////////////////////////////////////////////////
-void boot_scheduler_init( unsigned int x, 
+void boot_scheduler_init( unsigned int x,
                           unsigned int y )
 {
@@ -864,19 +867,19 @@
     mapping_irq_t*       irq     = _get_irq_base(header);
 
-    unsigned int         periph_id; 
+    unsigned int         periph_id;
     unsigned int         irq_id;
     unsigned int         vspace_id;
     unsigned int         vseg_id;
-    unsigned int         thread_id; 
-
-    unsigned int         sched_vbase;          // schedulers array vbase address 
+    unsigned int         thread_id;
+
+    unsigned int         sched_vbase;          // schedulers array vbase address
     unsigned int         sched_length;         // schedulers array length
     static_scheduler_t*  psched;               // pointer on processor scheduler
 
     unsigned int cluster_id = (x * Y_SIZE) + y;
-    unsigned int cluster_xy = (x << Y_WIDTH) + y;  
+    unsigned int cluster_xy = (x << Y_WIDTH) + y;
     unsigned int nprocs = cluster[cluster_id].procs;
-    unsigned int lpid;                       
-    
+    unsigned int lpid;
+
     if ( nprocs > 8 )
     {
@@ -886,11 +889,11 @@
 
     ////////////////////////////////////////////////////////////////////////////////
-    // Step 1 : - initialize the schedulers[] array of pointers, 
-    //          - initialize the "threads" and "current variables. 
+    // Step 1 : - initialize the schedulers[] array of pointers,
+    //          - initialize the "threads" and "current variables.
     //          - initialise the idle_thread context.
     //          - initialize the HWI, PTI and WTI interrupt vectors.
     //          - initialize the XCU masks for HWI / WTI / PTI interrupts.
     //
-    // The general policy for interrupts routing is the following:         
+    // The general policy for interrupts routing is the following:
     //          - the local HWI are statically allocatedted to local processors.
     //          - the nprocs first PTI are allocated for TICK (one per processor).
@@ -955,5 +958,5 @@
     unsigned int wti_mask[8] = {0,0,0,0,0,0,0,0};
 
-    // scan local peripherals to get and check local XCU 
+    // scan local peripherals to get and check local XCU
     mapping_periph_t*  xcu = NULL;
     unsigned int       min = cluster[cluster_id].periph_offset ;
@@ -962,5 +965,5 @@
     for ( periph_id = min ; periph_id < max ; periph_id++ )
     {
-        if( periph[periph_id].type == PERIPH_TYPE_XCU ) 
+        if( periph[periph_id].type == PERIPH_TYPE_XCU )
         {
             xcu = &periph[periph_id];
@@ -996,8 +999,8 @@
             }
         }
-    } 
+    }
 
     if ( xcu == NULL )
-    {         
+    {
         _printf("\n[BOOT ERROR] missing XCU in cluster[%d,%d]\n", x , y );
         _exit();
@@ -1005,5 +1008,5 @@
 
     // HWI interrupt vector definition
-    // scan HWI connected to local XCU 
+    // scan HWI connected to local XCU
     // for round-robin allocation to local processors
     lpid = 0;
@@ -1029,5 +1032,5 @@
         hwi_mask[lpid] = hwi_mask[lpid] | (1<<srcid);
 
-        lpid = (lpid + 1) % nprocs; 
+        lpid = (lpid + 1) % nprocs;
     } // end for irqs
 
@@ -1057,10 +1060,10 @@
     }
 
-    // set the XCU masks for HWI / WTI / PTI interrupts 
+    // set the XCU masks for HWI / WTI / PTI interrupts
     for ( lpid = 0 ; lpid < nprocs ; lpid++ )
     {
-        unsigned int channel = lpid * IRQ_PER_PROCESSOR; 
-
-        _xcu_set_mask( cluster_xy, channel, hwi_mask[lpid], IRQ_TYPE_HWI ); 
+        unsigned int channel = lpid * IRQ_PER_PROCESSOR;
+
+        _xcu_set_mask( cluster_xy, channel, hwi_mask[lpid], IRQ_TYPE_HWI );
         _xcu_set_mask( cluster_xy, channel, wti_mask[lpid], IRQ_TYPE_WTI );
         _xcu_set_mask( cluster_xy, channel, pti_mask[lpid], IRQ_TYPE_PTI );
@@ -1079,13 +1082,13 @@
     // Step 2 : Initialise the threads context. The context of a thread placed
     //          on  processor P must be stored in the scheduler of P.
-    //          For each vspace, this require two nested loops: loop on the threads, 
-    //          and loop on the local processors in cluster[x,y]. 
+    //          For each vspace, this require two nested loops: loop on the threads,
+    //          and loop on the local processors in cluster[x,y].
     //          We complete the scheduler when the required placement matches
     //          the local processor.
     ///////////////////////////////////////////////////////////////////////////////
 
-    for (vspace_id = 0; vspace_id < header->vspaces; vspace_id++) 
-    {
-        // We must set the PTPR depending on the vspace, because the start_vector 
+    for (vspace_id = 0; vspace_id < header->vspaces; vspace_id++)
+    {
+        // We must set the PTPR depending on the vspace, because the start_vector
         // and the stack address are defined in virtual space.
         _set_mmu_ptpr( (unsigned int)(_ptabs_paddr[vspace_id][x][y] >> 13) );
@@ -1094,10 +1097,21 @@
         for (thread_id = vspace[vspace_id].thread_offset;
              thread_id < (vspace[vspace_id].thread_offset + vspace[vspace_id].threads);
-             thread_id++) 
+             thread_id++)
         {
             // get the required thread placement coordinates [x,y,p]
             unsigned int req_x      = cluster[thread[thread_id].clusterid].x;
             unsigned int req_y      = cluster[thread[thread_id].clusterid].y;
-            unsigned int req_p      = thread[thread_id].proclocid;                 
+            unsigned int req_p      = thread[thread_id].proclocid;
+
+            // skip this thread if it is allocated to another cluster
+            if ( ( req_x != x ) || ( req_y != y ) ) continue;
+
+            if ( req_p >= NB_PROCS_MAX )
+            {
+                _printf("\n[BOOT ERROR] Bad allocation of thread %s from vspace %s\n",
+                        thread[thread_id].name,
+                        vspace[vspace_id].name);
+                _exit();
+            }
 
             // ctx_norun : two conditions to activate a thread
@@ -1117,59 +1131,54 @@
 
             // ctx_entry : Get the virtual address of the memory location containing
-            // the thread entry point : the start_vector is stored by GCC in the 
-            // seg_data segment, and we must wait the application.elf loading to get 
+            // the thread entry point : the start_vector is stored by GCC in the
+            // seg_data segment, and we must wait the application.elf loading to get
             // the entry point value...
-            vseg_id = vspace[vspace_id].start_vseg_id;     
+            vseg_id = vspace[vspace_id].start_vseg_id;
             unsigned int ctx_entry = vseg[vseg_id].vbase + (thread[thread_id].startid)*4;
 
-            // ctx_sp :  Get the vseg containing the stack 
+            // ctx_sp :  Get the vseg containing the stack
             // allocate 16 slots (64 bytes) for possible arguments.
             vseg_id = thread[thread_id].stack_vseg_id;
             unsigned int ctx_sp = vseg[vseg_id].vbase + vseg[vseg_id].length - 64;
 
-            // loop on the local processors
-            for ( lpid = 0 ; lpid < nprocs ; lpid++ )
-            {
-                if ( (x == req_x) && (y == req_y) && (req_p == lpid) )   // fit
-                {
-                    // pointer on selected scheduler
-                    psched = _schedulers[x][y][lpid];
-
-                    // ltid : compute local thread index in scheduler
-                    unsigned int ltid = psched->threads;
-
-                    // update the threads field in scheduler:
-                    psched->threads   = ltid + 1;
-
-                    // ctx_trdid : compute pthread global identifier
-                    unsigned int ctx_trdid = x << 24 | y<<16 | lpid<<8 | ltid;
-
-                    // initializes the thread context 
-                    psched->context[ltid].slot[CTX_CR_ID]     = 0;
-                    psched->context[ltid].slot[CTX_SR_ID]     = GIET_SR_INIT_VALUE;
-                    psched->context[ltid].slot[CTX_SP_ID]     = ctx_sp;
-                    psched->context[ltid].slot[CTX_EPC_ID]    = ctx_entry;
-                    psched->context[ltid].slot[CTX_ENTRY_ID]  = ctx_entry;
-                    psched->context[ltid].slot[CTX_PTPR_ID]   = ctx_ptpr;
-                    psched->context[ltid].slot[CTX_PTAB_ID]   = ctx_ptab;
-                    psched->context[ltid].slot[CTX_NPT2_ID]   = ctx_npt2;
-                    psched->context[ltid].slot[CTX_LTID_ID]   = ltid;
-                    psched->context[ltid].slot[CTX_TRDID_ID]  = ctx_trdid;
-                    psched->context[ltid].slot[CTX_VSID_ID]   = vspace_id;
-                    psched->context[ltid].slot[CTX_NORUN_ID]  = ctx_norun;
-                    psched->context[ltid].slot[CTX_SIGS_ID]   = 0;
-                    psched->context[ltid].slot[CTX_LOCKS_ID]  = 0;
-
-                    psched->context[ltid].slot[CTX_TTY_ID]    = 0xFFFFFFFF;
-                    psched->context[ltid].slot[CTX_CMA_FB_ID] = 0xFFFFFFFF;
-                    psched->context[ltid].slot[CTX_CMA_RX_ID] = 0xFFFFFFFF;
-                    psched->context[ltid].slot[CTX_CMA_TX_ID] = 0xFFFFFFFF;
-                    psched->context[ltid].slot[CTX_NIC_RX_ID] = 0xFFFFFFFF;
-                    psched->context[ltid].slot[CTX_NIC_TX_ID] = 0xFFFFFFFF;
-                    psched->context[ltid].slot[CTX_TIM_ID]    = 0xFFFFFFFF;
-                    psched->context[ltid].slot[CTX_HBA_ID]    = 0xFFFFFFFF;
-
-                    // update thread ltid field in the mapping
-                    thread[thread_id].ltid = ltid;
+            // pointer on selected scheduler
+            psched = _schedulers[x][y][req_p];
+
+            // ltid : compute local thread index in scheduler
+            unsigned int ltid = psched->threads;
+
+            // update the threads field in scheduler:
+            psched->threads = ltid + 1;
+
+            // ctx_trdid : compute pthread global identifier
+            unsigned int ctx_trdid = (x<<24) | (y<<16) | (req_p<<8) | ltid;
+
+            // initializes the thread context
+            psched->context[ltid].slot[CTX_CR_ID]     = 0;
+            psched->context[ltid].slot[CTX_SR_ID]     = GIET_SR_INIT_VALUE;
+            psched->context[ltid].slot[CTX_SP_ID]     = ctx_sp;
+            psched->context[ltid].slot[CTX_EPC_ID]    = ctx_entry;
+            psched->context[ltid].slot[CTX_ENTRY_ID]  = ctx_entry;
+            psched->context[ltid].slot[CTX_PTPR_ID]   = ctx_ptpr;
+            psched->context[ltid].slot[CTX_PTAB_ID]   = ctx_ptab;
+            psched->context[ltid].slot[CTX_NPT2_ID]   = ctx_npt2;
+            psched->context[ltid].slot[CTX_LTID_ID]   = ltid;
+            psched->context[ltid].slot[CTX_TRDID_ID]  = ctx_trdid;
+            psched->context[ltid].slot[CTX_VSID_ID]   = vspace_id;
+            psched->context[ltid].slot[CTX_NORUN_ID]  = ctx_norun;
+            psched->context[ltid].slot[CTX_SIGS_ID]   = 0;
+            psched->context[ltid].slot[CTX_LOCKS_ID]  = 0;
+
+            psched->context[ltid].slot[CTX_TTY_ID]    = 0xFFFFFFFF;
+            psched->context[ltid].slot[CTX_CMA_FB_ID] = 0xFFFFFFFF;
+            psched->context[ltid].slot[CTX_CMA_RX_ID] = 0xFFFFFFFF;
+            psched->context[ltid].slot[CTX_CMA_TX_ID] = 0xFFFFFFFF;
+            psched->context[ltid].slot[CTX_NIC_RX_ID] = 0xFFFFFFFF;
+            psched->context[ltid].slot[CTX_NIC_TX_ID] = 0xFFFFFFFF;
+            psched->context[ltid].slot[CTX_TIM_ID]    = 0xFFFFFFFF;
+            psched->context[ltid].slot[CTX_HBA_ID]    = 0xFFFFFFFF;
+
+            // update thread ltid field in the mapping
+            thread[thread_id].ltid = ltid;
 
 #if BOOT_DEBUG_SCHED
@@ -1188,5 +1197,5 @@
         thread[thread_id].name,
         vspace[vspace_id].name,
-        x, y, lpid,
+        x, y, req_p,
         psched->context[ltid].slot[CTX_LTID_ID],
         psched->context[ltid].slot[CTX_TRDID_ID],
@@ -1201,6 +1210,4 @@
         psched->context[ltid].slot[CTX_SIGS_ID] );
 #endif
-                } // end if FIT
-            } // end for loop on local procs
         } // end loop on threads
     } // end loop on vspaces
Index: /soft/giet_vm/giet_config.h
===================================================================
--- /soft/giet_vm/giet_config.h	(revision 818)
+++ /soft/giet_vm/giet_config.h	(revision 819)
@@ -62,4 +62,5 @@
 #define GIET_SR_INIT_VALUE        0x2000FF13   /* SR initial value (before eret) */
 #define GIET_USE_HARD_FLOAT       0            /* hard float supported */
+#define GIET_USE_MMU_GLOBAL_FLAG  0            /* enable the use of the PTE_G flag */
 
 #endif
