Index: /soft/giet_vm/boot/boot_handler.c
===================================================================
--- /soft/giet_vm/boot/boot_handler.c	(revision 179)
+++ /soft/giet_vm/boot/boot_handler.c	(revision 180)
@@ -31,10 +31,11 @@
 // As most applications use only a limited number of segments, the number of PT2s 
 // actually used by a given virtual space is generally smaller than 2048, and is
-// defined by the (GIET_NB_PT2_MAX) configuration parameter.
-// The max number of virtual spaces (GIET_NB_VSPACE_MAX) is a configuration parameter.
+// computed using the length of the vobj and stored in the _max_pte2 global variable,
+// which is table indexed by the vspace_id.
 //
 // Each page table (one page table per virtual space) is monolithic, and
-// contains one PT1 and (GIET_NB_PT2_MAX) PT2s. The PT1 is addressed using the ix1 field
-// (11 bits) of the VPN, and the selected PT2 is addressed using the ix2 field (9 bits).
+// contains one PT1 and ((vobj.length - PT1_SIZE) / PT2_SIZE ) PT2s. 
+// The PT1 is addressed using the ix1 field (11 bits) of the VPN, and 
+// the selected PT2 is addressed using the ix2 field (9 bits).
 // - PT1[2048] : a first 8K aligned array of unsigned int, indexed by the (ix1) field of VPN. 
 //   Each entry in the PT1 contains a 32 bits PTD. The MSB bit PTD[31] is 
@@ -42,5 +43,5 @@
 //   address of the selected PT2.
 //   The PT1 contains 2048 PTD of 4 bytes => 8K bytes.
-// - PT2[1024][GIET_NB_PT2_MAX] : an array of array of unsigned int. 
+// - PT2[_max_pte2[vspace_id]][1024]: an array of array of unsigned int. 
 //   Each PT2[1024] must be 4K aligned,  and each entry in a PT2 contains two unsigned int: 
 //   the first word contains the protection flags, and the second word contains the PPN.
@@ -61,8 +62,4 @@
 #endif
 
-#if !defined(GIET_NB_PT2_MAX) 
-# error The GIET_NB_PT2_MAX value must be defined in the 'giet_config.h' file !
-#endif
-
 ////////////////////////////////////////////////////////////////////////////
 //  Page Tables global variables
@@ -71,4 +68,8 @@
 // Next free PT2 index array
 unsigned int  _next_free_pt2[GIET_NB_VSPACE_MAX] =
+                         { [0 ... GIET_NB_VSPACE_MAX-1] = 0 };
+
+// Max PT2 index 
+unsigned int  _max_pte2[GIET_NB_VSPACE_MAX] =
                          { [0 ... GIET_NB_VSPACE_MAX-1] = 0 };
 
@@ -458,9 +459,20 @@
     ix2 = vpn  & 0x1FF;         //  9 bits
 
+    // since the max_pte2 has to be > 1, we check that he have been set
+    // otherwise it means tha the ptabs has not been set
+    unsigned int max_pte2   = _max_pte2[vspace_id];
+    if(max_pte2 == 0)
+    {
+        boot_puts("Unfound page table for vspace ");
+        boot_putw(vspace_id);
+        boot_puts("\n");
+        boot_exit();
+    }
+
     page_table_t* pt = (page_table_t *)_ptabs[vspace_id];
     if ( (pt->pt1[ix1] & PTE_V) == 0 )   // set a new PTD in PT1 
     {
         pt2_id = _next_free_pt2[vspace_id];
-        if ( pt2_id == GIET_NB_PT2_MAX )
+        if ( pt2_id == max_pte2 )
         {
             boot_puts("\n[BOOT ERROR] in boot_add_pte() function\n");
@@ -665,12 +677,5 @@
         if ( vobj[vobj_id].type == VOBJ_TYPE_PTAB )
         {
-            if(vobj[vobj_id].length < (PT1_SIZE + PT2_SIZE*GIET_NB_PT2_MAX) ) 
-            {
-                boot_puts( "\n[BOOT ERROR] in boot_vseg_map() function: " );
-                boot_puts("PTAB vobj is too small in vspace ");
-                boot_putw(vspace_id);
-                boot_puts("\n");
-                boot_exit();
-            }
+
             if(vspace_id == ((unsigned int) -1))    // global vseg
             {
@@ -679,5 +684,17 @@
                 boot_exit();
             }
-            _ptabs[vspace_id] = (page_table_t*)vobj[vobj_id].paddr;
+
+            if(vobj[vobj_id].length < (PT1_SIZE + PT2_SIZE) ) //at least one pte2 => ( max_pte2 >= 1)
+            {
+                boot_puts( "\n[BOOT ERROR] in boot_vseg_map() function, " );
+                boot_puts("PTAB too small, minumum size is: ");
+                boot_putw( PT1_SIZE + PT2_SIZE);
+                boot_exit();
+            }
+
+            /* getting the physical address of the ptab */
+            _ptabs[vspace_id]        = (page_table_t*) vobj[vobj_id].paddr;
+            /* computing the number of second level page */
+            _max_pte2[vspace_id]    = (vobj[vobj_id].length - PT1_SIZE) / PT2_SIZE;
         }
     } // end for vobjs
@@ -849,4 +866,6 @@
 boot_puts("\n>>> page table physical address = ");
 boot_putw((unsigned int)_ptabs[vspace_id]);
+boot_puts(", page table max_pte2 = ");
+boot_putw((unsigned int)_max_pte2[vspace_id]);
 boot_puts("\n");
 #endif
Index: /soft/giet_vm/boot/boot_handler.h
===================================================================
--- /soft/giet_vm/boot/boot_handler.h	(revision 179)
+++ /soft/giet_vm/boot/boot_handler.h	(revision 180)
@@ -54,5 +54,7 @@
 {
 	unsigned int    pt1[PT1_SIZE];                    // PT1 (index is ix1)
-	unsigned int    pt2[GIET_NB_PT2_MAX][PT2_SIZE];   // PT2s (index is 2*ix2)
+	unsigned int    pt2[1][PT2_SIZE];   // PT2s (index is 2*ix2)
+    /*  The number `1` is onmy here to indicate to the compiler that this is a table 
+     ** of two dimension and the actual value is computed dynamically(see boot_handler.c)*/ 
 } page_table_t;
 
Index: /soft/giet_vm/giet_config.h
===================================================================
--- /soft/giet_vm/giet_config.h	(revision 179)
+++ /soft/giet_vm/giet_config.h	(revision 180)
@@ -34,5 +34,4 @@
 #define GIET_NB_TASKS_MAX 	4	    /* max number of tasks per processor */
 #define GIET_NB_VSPACE_MAX	4	    /* max number of virtual spaces */
-#define GIET_NB_PT2_MAX  	16	    /* max number of level 2 page tables per vspace */
 #define GIET_TICK_VALUE	    16384   /* context switch period (number of cycles) */
 #define GIET_IOMMU_ACTIVE   0		/* The IOMMU vspace is defined */
Index: /soft/giet_vm/sys/vm_handler.h
===================================================================
--- /soft/giet_vm/sys/vm_handler.h	(revision 179)
+++ /soft/giet_vm/sys/vm_handler.h	(revision 180)
@@ -53,6 +53,8 @@
 typedef struct PageTable 
 {
-	unsigned int    pt1[PT1_SIZE/4];                      // PT1 (index is ix1)
-	unsigned int    pt2[GIET_NB_PT2_MAX][PT2_SIZE/4];     // PT2s (index is 2*ix2)
+	unsigned int    pt1[PT1_SIZE/4];        // PT1 (index is ix1)
+	unsigned int    pt2[1][PT2_SIZE/4];     // PT2s (index is 2*ix2)
+    /*  The number `1` is onmy here to indicate to the compiler that this is a table 
+     ** of two dimension and the actual value is computed dynamically(see boot_handler.c)*/ 
 } page_table_t;
 
