Index: /soft/giet_vm/giet_boot/boot.c
===================================================================
--- /soft/giet_vm/giet_boot/boot.c	(revision 731)
+++ /soft/giet_vm/giet_boot/boot.c	(revision 732)
@@ -31,5 +31,5 @@
 //    - the various "application.elf" files.
 //
-// 2) The GIET-VM uses the paged virtual memory to provides two services:
+// 2) The GIET-VM uses the paged virtual memory to provide two services:
 //    - classical memory protection, when several independant applications compiled
 //      in different virtual spaces are executing on the same hardware platform.
@@ -198,4 +198,10 @@
 // As each vseg is mapped by a different processor, the PT1 entry cannot
 // be concurrently accessed, and we don't need to take any lock.
+//
+// Implementation note:
+// This function checks that the PT1 entry is not already mapped, 
+// to enforce the rule: only one vseg in a given BPP. 
+// The 4 vsegs used by the boot code being packed in one single BPP, 
+// this verif is not done for all identity mapping vsegs.
 //////////////////////////////////////////////////////////////////////////////
 void boot_add_pte1( unsigned int vspace_id,
@@ -204,13 +210,17 @@
                     unsigned int vpn,        // 20 bits right-justified
                     unsigned int flags,      // 10 bits left-justified 
-                    unsigned int ppn )       // 28 bits right-justified
+                    unsigned int ppn,        // 28 bits right-justified
+                    unsigned int ident )     // identity mapping if non zero
 {
+    unsigned int   pte1;     // PTE1 value
+    paddr_t        paddr;    // PTE1 physical address
+
     // compute index in PT1
     unsigned int    ix1 = vpn >> 9;         // 11 bits for ix1
 
-    // get page table physical base address 
-    paddr_t  pt1_pbase = _ptabs_paddr[vspace_id][x][y];
-
-    if ( pt1_pbase == 0 )
+    // get PT1 physical base address 
+    paddr_t  pt1_base = _ptabs_paddr[vspace_id][x][y];
+
+    if ( pt1_base == 0 )
     {
         _printf("\n[BOOT ERROR] in boot_add_pte1() : no PTAB in cluster[%d,%d]"
@@ -219,11 +229,23 @@
     }
 
+    // compute pte1 physical address
+    paddr = pt1_base + 4*ix1;
+
+    // check PTE1 not already mapped
+    if ( ident == 0 )
+    {
+        if ( _physical_read( paddr ) & PTE_V )
+        {
+            _printf("\n[BOOT ERROR] in boot_add_pte1() : vpn %x already mapped "
+                    "in PTAB[%d,%d] for vspace %d\n", vpn , x , y , vspace_id );
+            _exit();
+        }
+    }
+
     // compute pte1 : 2 bits V T / 8 bits flags / 3 bits RSVD / 19 bits bppi
-    unsigned int    pte1 = PTE_V |
-                           (flags & 0x3FC00000) |
-                           ((ppn>>9) & 0x0007FFFF);
+    pte1 = PTE_V | (flags & 0x3FC00000) | ((ppn>>9) & 0x0007FFFF);
 
     // write pte1 in PT1
-    _physical_write( pt1_pbase + 4*ix1, pte1 );
+    _physical_write( paddr , pte1 );
 
     asm volatile ("sync");
@@ -238,5 +260,5 @@
 // allocation), this function checks a possible overflow of the PT2 array.
 // As a given entry in PT1 can be shared by several vsegs, mapped by 
-// different processors, we need to take the lock protecting PTAB[v][x]y].
+// different processors, we need to take the lock protecting PTAB[v][x][y].
 //////////////////////////////////////////////////////////////////////////////
 void boot_add_pte2( unsigned int vspace_id,
@@ -245,5 +267,6 @@
                     unsigned int vpn,        // 20 bits right-justified
                     unsigned int flags,      // 10 bits left-justified 
-                    unsigned int ppn )       // 28 bits right-justified
+                    unsigned int ppn,        // 28 bits right-justified
+                    unsigned int ident )     // identity mapping if non zero
 {
     unsigned int ix1;
@@ -331,10 +354,10 @@
 //
 // A given vseg can be mapped in a Big Physical Pages (BPP: 2 Mbytes) or in a
-// Small Physical Pages (SPP: 4 Kbytes), depending on the "big" attribute of vseg,
-// with the following rules:
-// - SPP : There is only one vseg in a small physical page, but a single vseg
-//   can cover several contiguous small physical pages.
-// - BPP : It can exist several vsegs in a single big physical page, and a single
-//   vseg can cover several contiguous big physical pages.
+// Small Physical Pages (SPP: 4 Kbytes), depending on the "big" attribute of vseg.
+//
+// All boot vsegs are packed in a single BPP (2 Mbytes). For all other vsegs,
+// there is only one vseg in a given page (BPP or SPP), but a single vseg can
+// cover several contiguous physical pages.
+// Only the vsegs used by the boot code can be identity mapping. 
 //
 // 1) First step: it computes various vseg attributes and checks 
@@ -343,15 +366,11 @@
 // 2) Second step: it allocates the required number of contiguous physical pages, 
 //    computes the physical base address (if the vseg is not identity mapping),
-//    and register it in the vseg pbase field.
-//    Only the vsegs used by the boot code and the peripheral vsegs
-//    can be identity mapping. The first big physical page in cluster[0,0] 
-//    is reserved for the boot vsegs.
+//    register it in the vseg pbase field, and update the page table(s).
 //
-// 3) Third step (only for vseg that have the VSEG_TYPE_PTAB): the M page tables
-//    associated to the M vspaces must be packed in the same vseg.
+// 3) Third step (only for vseg that have the VSEG_TYPE_PTAB): for a given cluster,
+//    the M page tables associated to the M vspaces are packed in the same vseg.
 //    We divide this vseg in M sub-segments, and compute the vbase and pbase
 //    addresses for M page tables, and register these addresses in the _ptabs_paddr
 //    and _ptabs_vaddr arrays.
-//  
 /////////////////////////////////////////////////////////////////////////////////////
 void boot_vseg_map( mapping_vseg_t* vseg,
@@ -414,5 +433,5 @@
 
     // compute ppn
-    if ( vseg->ident )           // identity mapping
+    if ( vseg->ident )           // identity mapping : no memory allocation required
     {
         ppn = vpn;
@@ -425,49 +444,11 @@
             pmem_alloc_t*     palloc = &boot_pmem_alloc[x_dest][y_dest];
 
-            if ( big == 0 )             // SPP : small physical pages
+            if ( big == 0 )      // allocate contiguous SPPs
             {
-                // allocate contiguous small physical pages
                 ppn = _get_small_ppn( palloc, npages );
             }
-            else                            // BPP : big physical pages
+            else                 // allocate contiguous BPPs 
             {
- 
-                // one big page can be shared by several vsegs 
-                // we must chek if BPP already allocated 
-                if ( is_ptab )   // It cannot be mapped
-                {
-                    ppn = _get_big_ppn( palloc, npages ); 
-                }
-                else             // It can be mapped
-                {
-                    unsigned int ix1   = vpn >> 9;   // 11 bits
-                    paddr_t      paddr = _ptabs_paddr[vsid][x_dest][y_dest] + (ix1<<2);
-                    unsigned int pte1  = _physical_read( paddr );
-
-                    if ( (pte1 & PTE_V) == 0 )     // BPP not allocated yet
-                    {
-                        // allocate contiguous big physical pages 
-                        ppn = _get_big_ppn( palloc, npages );
-                    }
-                    else                           // BPP already allocated
-                    {
-                        // test if new vseg has the same mode bits than
-                        // the other vsegs in the same big page
-                        unsigned int pte1_mode = 0;
-                        if (pte1 & PTE_C) pte1_mode |= C_MODE_MASK;
-                        if (pte1 & PTE_X) pte1_mode |= X_MODE_MASK;
-                        if (pte1 & PTE_W) pte1_mode |= W_MODE_MASK;
-                        if (pte1 & PTE_U) pte1_mode |= U_MODE_MASK;
-                        if (vseg->mode != pte1_mode) 
-                        {
-                            _printf("\n[BOOT ERROR] in boot_vseg_map() : "
-                                    "vseg %s has different flags than another vseg "
-                                    "in the same BPP\n", vseg->name );
-                            _exit();
-                        }
-                        ppn = ((pte1 << 9) & 0x0FFFFE00);
-                    }
-                }
-                ppn = ppn | (vpn & 0x1FF);
+                ppn = _get_big_ppn( palloc, npages ); 
             }
         }
@@ -478,8 +459,7 @@
     }
 
-    // update vseg.pbase field and update vsegs chaining
+    // update vseg.pbase field and register vseg mapped
     vseg->pbase     = ((paddr_t)ppn) << 12;
     vseg->mapped    = 1;
-
 
     //////////// Third step : (only if the vseg is a page table)
@@ -611,5 +591,6 @@
                                vpn + (p<<9),
                                flags, 
-                               ppn + (p<<9) );
+                               ppn + (p<<9),
+                               vseg->ident );
             }
             else         // small pages => PTE2s
@@ -620,5 +601,6 @@
                                vpn + p,      
                                flags, 
-                               ppn + p );
+                               ppn + p,
+                               vseg->ident );
             }
         }
@@ -638,5 +620,6 @@
                                            vpn + (p<<9),
                                            flags, 
-                                           ppn + (p<<9) );
+                                           ppn + (p<<9),
+                                           vseg->ident );
                         }
                         else         // small pages => PTE2s
@@ -647,5 +630,6 @@
                                            vpn + p,
                                            flags, 
-                                           ppn + p );
+                                           ppn + p,
+                                           vseg->ident );
                         }
                     }
@@ -664,5 +648,6 @@
                                    vpn + (p<<9),
                                    flags, 
-                                   ppn + (p<<9) );
+                                   ppn + (p<<9),
+                                   vseg->ident );
                 }
                 else         // small pages = PTE2s
@@ -673,5 +658,6 @@
                                    vpn + p,
                                    flags, 
-                                   ppn + p );
+                                   ppn + p,
+                                   vseg->ident );
                 }
             }
@@ -694,5 +680,6 @@
                                                vpn + (p<<9),
                                                flags, 
-                                               ppn + (p<<9) );
+                                               ppn + (p<<9),
+                                               vseg->ident );
                             }
                             else        // small pages -> PTE2s
@@ -703,5 +690,6 @@
                                                vpn + p,
                                                flags, 
-                                               ppn + p );
+                                               ppn + p,
+                                               vseg->ident );
                             }
                         }
@@ -1337,5 +1325,5 @@
         psched->context[ltid].slot[CTX_VSID_ID],
         psched->context[ltid].slot[CTX_NORUN_ID],
-        psched->context[ltid].slot[CTX_SIG_ID] );
+        psched->context[ltid].slot[CTX_SIGS_ID] );
 #endif
                 } // end if FIT
@@ -1897,5 +1885,5 @@
             boot_ptab_extend();
 
-            _printf("\n[BOOT] Physical memory allocators and page tables"
+            _printf("\n[BOOT] Page tables"
                     " initialized at cycle %d\n", _get_proctime() );
         }
