Index: soft/giet_vm/xml/xml_parser.c
===================================================================
--- soft/giet_vm/xml/xml_parser.c	(revision 249)
+++ soft/giet_vm/xml/xml_parser.c	(revision 253)
@@ -6,5 +6,5 @@
 ///////////////////////////////////////////////////////////////////////////////////////
 // This program translate a "map.xml" source file to a binary file "map.bin" that 
-// can be directly loaded in the boot ROM and used by the GIET-VM operating system.
+// can be directly loaded in memory and used by the GIET-VM operating system.
 //
 // This map.xml file contains :
@@ -14,5 +14,5 @@
 // The corresponding C structures are defined in the "mapping_info.h" file.
 // 
-// This program also generates the "hard_config.h" and the "giet_vsegs.ld" files,
+// This parser also generates the "hard_config.h" and the "giet_vsegs.ld" files,
 // required  to compile the GIET-VM code. 
 ///////////////////////////////////////////////////////////////////////////////////////
@@ -100,4 +100,5 @@
 char found_timer = 0;
 char found_icu   = 0;
+char found_xcu   = 0;
 char found_dma   = 0;
 char found_mmc   = 0;
@@ -122,5 +123,5 @@
 
 unsigned int use_iob          = 0; // using IOB component
-unsigned int use_xicu         = 0; // using XICU (not ICU)
+unsigned int use_xcu          = 0; // using XCU (not ICU)
 
 
@@ -130,5 +131,5 @@
 
 unsigned int periph_vbase_array[PERIPH_TYPE_MAX_VALUE] 
-         = { [0 ... (PERIPH_TYPE_MAX_VALUE - 1)] = 0xFFFFFFFF };
+         = { [0 ... (PERIPH_TYPE_MAX_VALUE - 1)] = 0xFFF00000 };
 
 //////////////////////////////////////////////////////////////////////
@@ -278,20 +279,68 @@
 } // end getStringValue()
 
-///////////////////////////////////////////////////////
-void set_periph_vbase_array( unsigned int vseg_index )
-{
-    unsigned int vbase  = vseg[vseg_index]->vbase;  // peripheral vbase address
-    unsigned int psegid = vseg[vseg_index]->psegid; // pseg global index
-    unsigned int type;                              // peripheral type
-    unsigned int periph_id; 
-
-    for ( periph_id = 0 ; periph_id < header->periphs ; periph_id++)
-    {
-        if( periph[periph_id]->psegid == psegid )
-        {
-            type = periph[periph_id]->type;
-            if ( periph_vbase_array[type] == 0xFFFFFFFF ) 
-                 periph_vbase_array[type] = vbase;    
-        }
+///////////////////////////////////////////////////////////////////////////////////
+// This function set the vbase address for all peripheral types. 
+// For replicated peripherals with the same type the virtual base address must be:
+//   vbase = seg_type_base & 0XFFF00000 + 
+//          (cluster_id * vbase_cluster_increment) & 0x000FFFFF
+void set_periph_vbase_array()
+{
+    unsigned int vseg_id;      // vseg global index
+    unsigned int periph_id;    // periph global index
+    unsigned int pseg_id;      // pseg global index
+    unsigned int cluster_id;   // cluster global index
+    unsigned int type;         // peripheral type 
+
+    unsigned int msb_mask = 0xFFF00000;
+    unsigned int lsb_mask = 0x000FFFFF;
+
+    // We are looking for any vseg matching a peripheral
+    // (i.e. they are associated to the same pseg)
+
+    // scan all vsegs
+    for (vseg_id = 0 ; vseg_id < header->vsegs ; vseg_id++)
+    {
+        // keep only vseg corresponding to a periph        
+        if ( vobj[vseg[vseg_id]->vobj_offset]->type == VOBJ_TYPE_PERI )
+        {
+            pseg_id = vseg[vseg_id]->psegid; 
+            cluster_id = pseg[pseg_id]->cluster;
+
+            // scan all periphs 
+            for ( periph_id = 0 ; periph_id < header->periphs ; periph_id++)
+            {
+                if( periph[periph_id]->psegid == pseg_id ) // matching !!!
+                {
+                    type = periph[periph_id]->type;
+                    if ( periph_vbase_array[type] == 0xFFF00000 )  // vbase not set
+                    {
+                        periph_vbase_array[type] = vseg[vseg_id]->vbase;    
+                    }
+                    else                                 // vbase already set
+                    {
+                        // checking 12 MSB bits for replicated peripherals
+                        if( (vseg[vseg_id]->vbase & msb_mask) != 
+                            (periph_vbase_array[type] & msb_mask) )
+                        {
+                            printf("[XML ERROR] All peripherals with same type ");
+                            printf(" should share the same 12 MSB for vbase address\n");
+                            printf("periph index = %d / periph type = %d / vbase = %x\n",
+                                    periph_id, type, vseg[vseg_id]->vbase);
+                            exit(1);
+                        }
+                        // checking 20 LSB bits for replicated peripherals
+                        if( (vseg[vseg_id]->vbase & lsb_mask) != 
+                            (header->increment * cluster_id) )
+                        {
+                            printf("[XML ERROR] All peripherals with same type ");
+                            printf(" must have the 20 LSB bits = cluster_id * increment");
+                            printf("periph index = %d / periph type = %d / vbase = %x\n",
+                                    periph_id, type, vseg[vseg_id]->vbase);
+                            exit(1);
+                        }
+                    }
+                }
+            }
+        }    
     }
 }  // end set_periph_vbase_array()
@@ -336,14 +385,12 @@
     unsigned int vobj_max = vobj_min + vspace_max;
 
-    for (vobj_id = vobj_min; vobj_id < vobj_max; vobj_id++) {
-        if (strcmp(vobj[vobj_id]->name, vobj_name) == 0) {
-            return (vobj_id - vobj_min);
-        }
+    for (vobj_id = vobj_min; vobj_id < vobj_max; vobj_id++) 
+    {
+        if (strcmp(vobj[vobj_id]->name, vobj_name) == 0) return (vobj_id - vobj_min);
     }
     return -1;
 }
 
-
-/////////////////////////////////////////
+//////////////////////////////////////
 void taskNode(xmlTextReaderPtr reader) 
 {
@@ -352,9 +399,10 @@
     char * str;
 
-    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { return; }
+    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return;
 
     if (task_index >= MAX_TASKS) 
     {
         printf("[XML ERROR] The number of tasks is larger than %d\n", MAX_TASKS);
+        exit(1);
     }
 
@@ -540,5 +588,4 @@
 } // end taskNode()
 
-
 //////////////////////////////////////
 void vobjNode(xmlTextReaderPtr reader) 
@@ -548,5 +595,5 @@
     char * str;
 
-    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { return; }
+    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return;
 
     if (vobj_index >= MAX_VOBJS) 
@@ -583,19 +630,7 @@
 printf("        type = %s\n", str);
 #endif
-    if (ok && (strcmp(str, "ELF") == 0)) 
-    {
-        vobj[vobj_index]->type = VOBJ_TYPE_ELF;
-
-        assert( (vobj_count == 0) && "[XML ERROR] an ELF vobj must be alone in a vseg");
-    }
-    else if (ok && (strcmp(str, "PERI")     == 0)) 
-    { 
-        vobj[vobj_index]->type = VOBJ_TYPE_PERI;     
-
-        assert( (vobj_count == 0) && "[XML ERROR] a PERI vobj must be alone in a vseg");
-
-        // fill the peripheral base address array 
-        set_periph_vbase_array( vseg_index );
-    }
+
+    if      (ok && (strcmp(str, "ELF")      == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_ELF;      }
+    else if (ok && (strcmp(str, "PERI")     == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_PERI;     }
     else if (ok && (strcmp(str, "BLOB")     == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_BLOB;     }
     else if (ok && (strcmp(str, "PTAB")     == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_PTAB;     }
@@ -613,4 +648,12 @@
         exit(1);
     }
+    // some more checking
+    if ( (vobj[vobj_index]->type == VOBJ_TYPE_ELF) ||
+         (vobj[vobj_index]->type == VOBJ_TYPE_PERI) )
+    {
+        assert( (vobj_count == 0) && 
+        "[XML ERROR] an ELF or PERI vobj must be alone in a vseg");
+    }
+        
 
     ////////// get length attribute 
@@ -680,5 +723,4 @@
 } // end vobjNode()
 
-
 //////////////////////////////////////
 void vsegNode(xmlTextReaderPtr reader) 
@@ -690,5 +732,5 @@
     vobj_count = 0;
 
-    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { return; }
+    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return;
 
     if (vseg_index >= MAX_VSEGS) 
@@ -833,5 +875,6 @@
             return;
         }
-        else {
+        else 
+        {
             printf("[XML ERROR] Unknown tag %s", tag);
             exit(1);
@@ -841,7 +884,7 @@
 } // end vsegNode()
 
-
-//////////////////////////////////////////
-void vspaceNode(xmlTextReaderPtr reader) {
+////////////////////////////////////////
+void vspaceNode(xmlTextReaderPtr reader) 
+{
     char * str;
     unsigned int ok;
@@ -852,7 +895,5 @@
     task_loc_index = 0;
 
-    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) {
-        return;
-    }
+    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return;
 
     // checking source file consistency
@@ -877,5 +918,6 @@
         strncpy(vspace[vspace_index]->name, str, 31);
     }
-    else {
+    else 
+    {
         printf("[XML ERROR] illegal or missing <name> attribute for vspace %d\n", 
                 vspace_index);
@@ -899,5 +941,6 @@
         //used after parsing the vobjs
     }
-    else {
+    else 
+    {
         printf("[XML ERROR] illegal or missing <startname> attribute for vspace %s\n", 
                 vspace[vspace_index]->name);
@@ -925,10 +968,12 @@
             // get index of the vobj containing the start vector
             int index = getVobjLocId(vspace_index, str , vobj_loc_index);
-            if (index == -1) {
+            if (index == -1) 
+            {
                 printf("[XML ERROR] vobj containing start vector not found in vspace %s\n",
                         vspace[vspace_index]->name);
-                exit(-1);
-            }
-            else {
+                exit(1);
+            }
+            else 
+            {
                 vspace[vspace_index]->start_offset = index;
 #if XML_PARSER_DEBUG
@@ -944,5 +989,6 @@
             int task_max = task_min + vspace[vspace_index]->tasks; 
             for (task_id = task_min; task_id < task_max; task_id++) {
-                if (task[task_id]->startid >= vspace[vspace_index]->tasks) {
+                if (task[task_id]->startid >= vspace[vspace_index]->tasks) 
+                {
                     printf("[XML ERROR] <startid> too large for task (%d,%d)\n", 
                             vspace_index, task_id );
@@ -955,5 +1001,6 @@
             return;
         }
-        else {
+        else 
+        {
             printf("[XML ERROR] Unknown tag %s", tag);
             exit(1);
@@ -963,16 +1010,17 @@
 } // end vspaceNode()
 
-
-///////////////////////////////////////////
-void cpPortNode(xmlTextReaderPtr reader) {
+////////////////////////////////////////
+void cpPortNode(xmlTextReaderPtr reader) 
+{
     char * str;
     unsigned int ok;
 
-    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) {
-        return;
-    }
-
-    if (cp_port_index >= MAX_CP_PORTS) {
-        printf("[XML ERROR] The number of ports (for coprocs) is larger than %d\n", MAX_CP_PORTS);
+    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return;
+
+    if (cp_port_index >= MAX_CP_PORTS) 
+    {
+        printf("[XML ERROR] The number of ports (for coprocs) is larger than %d\n", 
+                 MAX_CP_PORTS);
+        exit(1);
     }
 
@@ -984,19 +1032,21 @@
     cp_port_vobj_ref[cp_port_index] = (vobj_ref_t *) malloc(sizeof(vobj_ref_t));
 
-
-
     ///////// get direction attribute
     str = getStringValue(reader, "direction", &ok);
-    if (ok) {
+    if (ok) 
+    {
 #if XML_PARSER_DEBUG
         printf("      direction = %s\n", str);
 #endif
-        if (strcmp(str, "TO_COPROC")   ==  0) {
+        if (strcmp(str, "TO_COPROC")   ==  0) 
+        {
             cp_port[cp_port_index]->direction = PORT_TO_COPROC;
         }
-        else if (strcmp(str, "FROM_COPROC") ==  0) {
+        else if (strcmp(str, "FROM_COPROC") ==  0) 
+        {
             cp_port[cp_port_index]->direction = PORT_FROM_COPROC;
         }
-        else {
+        else 
+        {
             printf("[XML ERROR] illegal <direction> for cp_port %d in cluster %d\n",
                     cp_port_index, cluster_index);
@@ -1004,5 +1054,6 @@
         }
     }  
-    else {
+    else 
+    {
         printf("[XML ERROR] missing <direction> for cp_port %d in cluster %d\n",
                 cp_port_index, cluster_index);
@@ -1015,8 +1066,10 @@
     printf("      vspacename = %s\n", str);
 #endif
-    if (ok) {
+    if (ok) 
+    {
         strncpy(cp_port_vobj_ref[cp_port_index]->vspace_name, str, 31);
     }
-    else {
+    else 
+    {
         printf("[XML ERROR] missing <vspacename> for cp_port %d in cluster %d\n",
                 cp_port_index, cluster_index);
@@ -1029,18 +1082,17 @@
     printf("      vobjname = %s\n", str);
 #endif
-    if (ok) {
+    if (ok) 
+    {
         strncpy(cp_port_vobj_ref[cp_port_index]->vobj_name, str, 31);
     }
-    else {
+    else 
+    {
         printf("[XML ERROR] missing <vobjname> for cp_port %d in cluster %d\n",
                 cp_port_index, cluster_index);
         exit(1);
     }
-
     cp_port_index++;
     cp_port_loc_index++;
-
 } // end cpPortNode()
-
 
 ////////////////////////////////////////
@@ -1051,9 +1103,10 @@
     unsigned int ok;
 
-    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { return; }
+    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return;
 
     if (periph_index >= MAX_PERIPHS) 
     {
         printf("[XML ERROR] The number of periphs is larger than %d\n", MAX_PERIPHS);
+        exit(1);
     }
 
@@ -1194,5 +1247,5 @@
                 cma_channels = periph[periph_index]->channels;
             }
-            else if (header->nic_cluster_bis == 0xFFFFFFFF) 
+            else if (header->cma_cluster_bis == 0xFFFFFFFF) 
             {
                 header->cma_cluster_bis = cluster_index;
@@ -1221,9 +1274,9 @@
         }
         // The TIM, ICU, XICU, DMA, MEMC peripherals are replicated in all clusters
-        // but only one component per cluster
+        // but it must exist only one component of each type per cluster
         else if (strcmp(str, "TIM") == 0 ) 
         {
             periph[periph_index]->type = PERIPH_TYPE_TIM;
-            if (found_timer || use_xicu)  error = 1; 
+            if (found_timer || use_xcu)  error = 1; 
             found_timer = 1;
             if (tim_channels < periph[periph_index]->channels) 
@@ -1235,17 +1288,15 @@
         {
             periph[periph_index]->type = PERIPH_TYPE_ICU;
-            if (found_icu)  error = 1; 
+            if (found_icu || use_xcu)  error = 1; 
             found_icu = 1;
         }
-        else if (strcmp(str, "XICU") == 0) 
-        {
-            periph[periph_index]->type = PERIPH_TYPE_ICU;
+        else if (strcmp(str, "XCU") == 0) 
+        {
+            periph[periph_index]->type = PERIPH_TYPE_XCU;
             if (found_icu || found_timer)  error = 1; 
-            found_icu = 1;
-            if (tim_channels == 0) 
-            { 
-                tim_channels = 32; 
-            }
-            use_xicu = 1;
+            found_xcu    = 1;
+            found_timer  = 1;
+            tim_channels = 32; 
+            use_xcu      = 1;
         }
         else if (strcmp(str, "DMA") == 0) 
@@ -1291,7 +1342,7 @@
 } // end periphNode
 
-
-/////////////////////////////////////////
-void coprocNode(xmlTextReaderPtr reader) {
+////////////////////////////////////////
+void coprocNode(xmlTextReaderPtr reader) 
+{
     char * str;
     unsigned int ok;
@@ -1299,10 +1350,10 @@
     cp_port_loc_index = 0;
 
-    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) {
-        return;
-    }
-
-    if (coproc_index >= MAX_COPROCS) {
+    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return;
+
+    if (coproc_index >= MAX_COPROCS) 
+    {
         printf("[XML ERROR] The number of coprocs is larger than %d\n", MAX_COPROCS);
+        exit(1);
     }
 
@@ -1315,5 +1366,6 @@
     /////////// get name attribute 
     str = getStringValue(reader, "name", &ok);
-    if (ok) {
+    if (ok) 
+    {
 #if XML_PARSER_DEBUG
         printf("      name = %s\n", str);
@@ -1321,5 +1373,6 @@
         strncpy(coproc[coproc_index]->name, str, 31);
     }
-    else {
+    else 
+    {
         printf("[XML ERROR] illegal or missing <name> for coproc %d in cluster %d\n",
                 coproc_index, cluster_index);
@@ -1329,5 +1382,6 @@
     /////////// get psegname attribute 
     str = getStringValue(reader, "psegname", &ok);
-    if (ok == 0) {
+    if (ok == 0) 
+    {
         printf("[XML ERROR] illegal or missing <psegname> for coproc %d in cluster %d\n", 
                 coproc_index, cluster_index);
@@ -1337,5 +1391,6 @@
     /////////// set psegid attribute
     int index = getPsegId(cluster_index, str);
-    if (index >= 0) {
+    if (index >= 0) 
+    {
 #if XML_PARSER_DEBUG
         printf("      clusterid = %d\n", cluster_index);
@@ -1346,5 +1401,6 @@
         assert(pseg[index]->type == PSEG_TYPE_PERI && "coproc psegname attribute must refer to a pseg of type PERI" );
     }
-    else {
+    else 
+    {
         printf("[XML ERROR] pseg not found for coproc %d / clusterid = %d / psegname = %s\n", 
                 coproc_index, cluster_index, str );
@@ -1360,13 +1416,16 @@
 
     int status = xmlTextReaderRead(reader);
-    while (status == 1) {
+    while (status == 1) 
+    {
         const char * tag = (const char *) xmlTextReaderConstName(reader);
 
-        if (strcmp(tag, "port") == 0 ) {
+        if (strcmp(tag, "port") == 0 ) 
+        {
             cpPortNode(reader);
         }
         else if (strcmp(tag, "#text")    == 0 ) { }
         else if (strcmp(tag, "#comment") == 0 ) { }
-        else if (strcmp(tag, "coproc") == 0 ) {
+        else if (strcmp(tag, "coproc") == 0 ) 
+        {
             coproc[coproc_index]->ports = cp_port_loc_index;
             cluster[cluster_index]->coprocs++;
@@ -1375,5 +1434,6 @@
             return;
         }
-        else {
+        else 
+        {
             printf("[XML ERROR] Unknown tag %s", tag);
             exit(1);
@@ -1384,13 +1444,12 @@
 
 
-///////////////////////////////////////
-void irqNode(xmlTextReaderPtr reader) {
+/////////////////////////////////////
+void irqNode(xmlTextReaderPtr reader) 
+{
     unsigned int ok;
     unsigned int value;
     char * str;
 
-    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) {
-        return;
-    }
+    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return;
 
     if (irq_index >= MAX_IRQS) {
@@ -1406,16 +1465,14 @@
     ///////// get type attribute
     str = getStringValue(reader, "type", &ok);
-    if (ok) {
+    if (ok) 
+    {
 #if XML_PARSER_DEBUG
         printf("        type    = %s\n", str);
 #endif
-        if (strcmp(str, "HARD") == 0 ) {
-            irq[irq_index]->type = 0;
-        }
-        else {
-            irq[irq_index]->type = 1;
-        }
-    }
-    else {
+        if (strcmp(str, "HARD") == 0 ) irq[irq_index]->type = 0;
+        else                           irq[irq_index]->type = 1;
+    }
+    else 
+    {
         printf("[XML ERROR] missing IRQ <type> for processor %d in cluster %d\n",
                 cluster_index, proc_loc_index);
@@ -1425,10 +1482,12 @@
     ///////// get icuid attribute
     value = getIntValue(reader, "icuid", &ok);
-    if (ok) {
+    if (ok) 
+    {
 #if XML_PARSER_DEBUG
         printf("        icuid   = %d\n", value);
 #endif
         irq[irq_index]->icuid = value;
-        if (value >= 32) {
+        if (value >= 32) 
+        {
             printf("[XML ERROR] IRQ <icuid> too large for processor %d in cluster %d\n",
                     cluster_index, proc_loc_index);
@@ -1436,5 +1495,6 @@
         }
     }
-    else {
+    else 
+    {
         printf("[XML ERROR] missing IRQ <icuid> for processor %d in cluster %d\n",
                 cluster_index, proc_loc_index);
@@ -1444,5 +1504,6 @@
     ///////// get isr attribute
     str = getStringValue(reader, "isr", &ok);
-    if (ok) {
+    if (ok) 
+    {
 #if XML_PARSER_DEBUG
         printf("        isr     = %s\n", str);
@@ -1453,5 +1514,6 @@
         else if (strcmp(str, "ISR_TTY"    ) == 0) { irq[irq_index]->isr = ISR_TTY; }
         else if (strcmp(str, "ISR_TIMER"  ) == 0) { irq[irq_index]->isr = ISR_TIMER; }
-        else {
+        else 
+        {
             printf("[XML ERROR] illegal IRQ <isr> for processor %d in cluster %d\n",
                     cluster_index, proc_loc_index);
@@ -1462,5 +1524,6 @@
 #endif
     }  
-    else {
+    else 
+    {
         printf("[XML ERROR] missing IRQ <isr> for processor %d in cluster %d\n",
                 cluster_index, proc_loc_index);
@@ -1470,5 +1533,6 @@
     ///////// get channel attribute (optionnal : 0 if missing)
     value = getIntValue(reader, "channel", &ok);
-    if (ok) {
+    if (ok) 
+    {
 #if XML_PARSER_DEBUG
         printf("        channel = %d\n", value);
@@ -1476,5 +1540,6 @@
         irq[irq_index]->channel = value;
     }
-    else {
+    else 
+    {
         irq[irq_index]->channel = 0;
     }
@@ -1486,6 +1551,7 @@
 
 
-/////////////////////////////////////////
-void procNode(xmlTextReaderPtr reader) {
+//////////////////////////////////////
+void procNode(xmlTextReaderPtr reader) 
+{
     unsigned int ok;
     unsigned int value;
@@ -1493,10 +1559,10 @@
     irq_loc_index = 0;
 
-    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) {
-        return;
-    }
-
-    if (proc_index >= MAX_PROCS) {
+    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return;
+
+    if (proc_index >= MAX_PROCS) 
+    {
         printf("[XML ERROR] The number of procs is larger than %d\n", MAX_PROCS);
+        exit(1);
     }
 
@@ -1506,9 +1572,9 @@
 
     proc[proc_index] = (mapping_proc_t *) malloc(sizeof(mapping_proc_t));
-
 
     /////////// get index attribute (optional)
     value = getIntValue(reader, "index", &ok);
-    if (ok && (value != proc_loc_index)) {
+    if (ok && (value != proc_loc_index)) 
+    {
         printf("[XML ERROR] wrong proc index / expected value is %d", 
                 proc_loc_index);
@@ -1524,13 +1590,16 @@
 
     int status = xmlTextReaderRead(reader);
-    while (status == 1) {
+    while (status == 1) 
+    {
         const char * tag = (const char *) xmlTextReaderConstName(reader);
 
-        if (strcmp(tag, "irq") == 0) {
+        if (strcmp(tag, "irq") == 0) 
+        {
             irqNode(reader);
         }
         else if (strcmp(tag, "#text")    == 0) { }
         else if (strcmp(tag, "#comment") == 0) { }
-        else if (strcmp(tag, "proc")     == 0) {
+        else if (strcmp(tag, "proc")     == 0) 
+        {
             proc[proc_index]->irqs = irq_loc_index;
             cluster[cluster_index]->procs++;
@@ -1539,5 +1608,6 @@
             return;
         }
-        else {
+        else 
+        {
             printf("[XML ERROR] Unknown tag %s", tag);
             exit(1);
@@ -1548,15 +1618,15 @@
 
 
-//////////////////////////////////////////
-void psegNode(xmlTextReaderPtr reader) {
+//////////////////////////////////////
+void psegNode(xmlTextReaderPtr reader) 
+{
     unsigned int ok;
     paddr_t      ll_value;
     char * str;
 
-    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) {
-        return;
-    }
-
-    if (pseg_index >= MAX_PSEGS) {
+    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return;
+
+    if (pseg_index >= MAX_PSEGS) 
+    {
         printf("[XML ERROR] The number of psegs is larger than %d\n", MAX_PSEGS);
         exit(1);
@@ -1574,8 +1644,10 @@
     printf("      name = %s\n", str);
 #endif
-    if (ok) {
+    if (ok) 
+    {
         strncpy(pseg[pseg_index]->name, str, 31);
     }
-    else {
+    else 
+    {
         printf("[XML ERROR] illegal or missing <name> for pseg %d in cluster %d\n",
                 pseg_index, cluster_index);
@@ -1591,5 +1663,6 @@
     else if (ok && (strcmp(str, "ROM" ) == 0)) { pseg[pseg_index]->type = PSEG_TYPE_ROM; }
     else if (ok && (strcmp(str, "PERI") == 0)) { pseg[pseg_index]->type = PSEG_TYPE_PERI; }
-    else {
+    else 
+    {
         printf("[XML ERROR] illegal or missing <type> for pseg %s in cluster %d\n",
                 pseg[pseg_index]->name, cluster_index);
@@ -1602,5 +1675,6 @@
     printf("      base = 0x%llx\n", ll_value);
 #endif
-    if (ok) {
+    if (ok) 
+    {
         pseg[pseg_index]->base = ll_value;
     }
@@ -1616,8 +1690,10 @@
     printf("      length = 0x%llx\n", ll_value);
 #endif
-    if (ok) {
+    if (ok) 
+    {
         pseg[pseg_index]->length = ll_value;
     }  
-    else {
+    else 
+    {
         printf("[XML ERROR] illegal or missing <length> for pseg %s in cluster %d\n",
                 pseg[pseg_index]->name, cluster_index);
@@ -1659,4 +1735,5 @@
     found_timer = 0;
     found_icu   = 0;
+    found_xcu   = 0;
     found_dma   = 0;
     found_mmc   = 0;
@@ -1667,5 +1744,6 @@
 
     // checking source file consistency
-    if (cluster_index >= header->clusters) {
+    if (cluster_index >= header->clusters) 
+    {
         printf("[XML ERROR] The cluster index is too large : %d\n", cluster_index);
         exit(1);
@@ -1679,5 +1757,6 @@
     /////////// check cluster index attribute (optional)
     value = getIntValue(reader, "index", &ok);
-    if (ok && (value != cluster_index)) {
+    if (ok && (value != cluster_index)) 
+    {
         printf("[XML ERROR] wrong cluster index / expected value is %d", 
                 cluster_index);
@@ -1714,23 +1793,16 @@
         {
 
-            ////////////////// peripherals checks /////////////////////////
-            if ((found_timer  && use_xicu) || (!found_timer  && !use_xicu)) 
-            {
-                printf("[XML ERROR] illegal or missing timer peripheral in cluster %d\n", cluster_index);
+            ///////// TIMER and ICU peripheral are mandatory //////////////
+            if (!found_timer && !found_xcu)
+            {
+                printf("[XML ERROR] missing timer peripheral in cluster %d\n", cluster_index);
                 exit(1);
             }
 
-            if (!found_icu) 
-            {
-                printf("[XML ERROR] illegal or missing icu peripheral in cluster %d\n", cluster_index);
+            if (!found_icu && !found_xcu) 
+            {
+                printf("[XML ERROR] missing icu peripheral in cluster %d\n", cluster_index);
                 exit(1);
             }
-
-            if (!found_dma) 
-            {
-                printf("[XML ERROR] illegal or missing dma peripheral in cluster %d\n", cluster_index);
-                exit(1);
-            }
-
 
             if (nb_proc_max < cluster[cluster_index]->procs) 
@@ -1757,5 +1829,5 @@
 void clusterSetNode(xmlTextReaderPtr reader) 
 {
-    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { return; }
+    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return;
 
 #if XML_PARSER_DEBUG
@@ -1798,5 +1870,6 @@
             return;
         }
-        else {
+        else 
+        {
             printf("[XML ERROR] Unknown tag in clusterset node : %s",tag);
             exit(1);
@@ -1807,9 +1880,8 @@
 
 
-/////////////////////////////////////////////
-void globalSetNode(xmlTextReaderPtr reader) {
-    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) {
-        return;
-    }
+///////////////////////////////////////////
+void globalSetNode(xmlTextReaderPtr reader) 
+{
+    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return;
 
 #if XML_PARSER_DEBUG
@@ -1825,5 +1897,6 @@
         else if (strcmp(tag, "#text")     == 0) { }
         else if (strcmp(tag, "#comment")  == 0) { }
-        else if (strcmp(tag, "globalset") == 0) {
+        else if (strcmp(tag, "globalset") == 0) 
+        {
 #if XML_PARSER_DEBUG
             printf("  end global set\n\n");
@@ -1833,5 +1906,6 @@
             return;
         }
-        else {
+        else 
+        {
             printf("[XML ERROR] Unknown tag in globalset node : %s",tag);
             exit(1);
@@ -1842,6 +1916,7 @@
 
 
-/////////////////////////////////////////////
-void vspaceSetNode(xmlTextReaderPtr reader) {
+///////////////////////////////////////////
+void vspaceSetNode(xmlTextReaderPtr reader)
+{
     if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) {
         return;
@@ -1861,11 +1936,14 @@
         else if (strcmp(tag, "#text"    ) == 0 ) { }
         else if (strcmp(tag, "#comment" ) == 0 ) { }
-        else if (strcmp(tag, "vspaceset") == 0 ) {
+        else if (strcmp(tag, "vspaceset") == 0 ) 
+        {
             // checking source file consistency
-            if (vspace_index != header->vspaces) {
+            if (vspace_index != header->vspaces) 
+            {
                 printf("[XML ERROR] Wrong number of vspaces\n");
                 exit(1);
             }
-            else {
+            else 
+            {
                 header->vsegs = vseg_index;
                 header->vobjs = vobj_index;
@@ -1874,5 +1952,6 @@
             }
         }
-        else {
+        else 
+        {
             printf("[XML ERROR] Unknown tag in vspaceset node : %s",tag);
             exit(1);
@@ -1883,5 +1962,5 @@
 
 
-//////////////////////////////////////////
+////////////////////////////////////////
 void headerNode(xmlTextReaderPtr reader) 
 {
@@ -1890,5 +1969,5 @@
     unsigned int ok;
 
-    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { return; }
+    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return;
 
 #if XML_PARSER_DEBUG
@@ -1900,5 +1979,6 @@
     ////////// get name attribute
     name = getStringValue(reader, "name", &ok);
-    if (ok) {
+    if (ok) 
+    {
 #if XML_PARSER_DEBUG
         printf("  name = %s\n", name);
@@ -1906,5 +1986,6 @@
         strncpy( header->name, name, 31);
     }
-    else {
+    else 
+    {
         printf("[XML ERROR] illegal or missing <name> attribute in header\n");
         exit(1);
@@ -1913,5 +1994,6 @@
     /////////// get cluster_x attribute
     cluster_x = getIntValue(reader, "cluster_x", &ok);
-    if (ok) {
+    if (ok) 
+    {
 #if XML_PARSER_DEBUG
         printf("  cluster_x = %d\n", cluster_x);
@@ -1919,5 +2001,6 @@
         header->cluster_x = cluster_x;
     }
-    else {
+    else 
+    {
         printf("[XML ERROR] illegal or missing <cluster_x> attribute in header\n");
         exit(1);
@@ -1926,5 +2009,6 @@
     /////////// get cluster_y attribute
     cluster_y = getIntValue(reader, "cluster_y", &ok);
-    if (ok) {
+    if (ok) 
+    {
 #if XML_PARSER_DEBUG
         printf("  cluster_y = %d\n", cluster_y);
@@ -1932,5 +2016,6 @@
         header->cluster_y = cluster_y;
     }
-    else {
+    else 
+    {
         printf("[XML ERROR] illegal or missing <cluster_y> attribute in header\n");
         exit(1);
@@ -1939,5 +2024,6 @@
     //check the number of cluster
     value = cluster_x * cluster_y;
-    if (value >= MAX_CLUSTERS) {
+    if (value >= MAX_CLUSTERS) 
+    {
         printf("[XML ERROR] The number of clusters is larger than %d\n", MAX_CLUSTERS);
         exit(1);
@@ -1952,6 +2038,8 @@
     ///////// get vspaces attribute
     value = getIntValue(reader, "vspaces", &ok);
-    if (ok) {
-        if (value >= MAX_VSPACES) {
+    if (ok) 
+    {
+        if (value >= MAX_VSPACES) 
+        {
             printf("[XML ERROR] The number of vspaces is larger than %d\n", MAX_VSPACES);
             exit(1);
@@ -1962,6 +2050,30 @@
         header->vspaces  = value;
     }
-    else {
+    else 
+    {
         printf("[XML ERROR] illegal or missing <vspaces> attribute in mapping\n");
+        exit(1);
+    }
+
+    ///////// get increment attribute
+    value = getIntValue(reader, "increment", &ok);
+    if (ok) 
+    {
+        if ( (value != 0x10000) && (value != 0x8000) &&
+             (value != 0x4000)  && (value != 0x2000) )
+       
+        {
+            printf("[XML ERROR] The vseg increment must be one of the following: ");
+            printf(" 0x00010000 / 0x00008000 / 0x00004000 / 0x00002000");
+            exit(1);
+        }
+#if XML_PARSER_DEBUG
+        printf("  increment = %d\n", value);
+#endif
+        header->increment  = value;
+    }
+    else 
+    {
+        printf("[XML ERROR] illegal or missing <increment> attribute in mapping\n");
         exit(1);
     }
@@ -1985,8 +2097,10 @@
 
     int status = xmlTextReaderRead(reader);
-    while (status == 1) {
+    while (status == 1) 
+    {
         const char * tag = (const char *) xmlTextReaderConstName(reader);
 
-        if (strcmp(tag, "clusterset") == 0) {
+        if (strcmp(tag, "clusterset") == 0) 
+        {
             clusterSetNode(reader);
         }
@@ -1995,5 +2109,6 @@
         else if (strcmp(tag, "#text")        == 0) { }
         else if (strcmp(tag, "#comment")     == 0) { }
-        else if (strcmp(tag, "mapping_info") == 0) {
+        else if (strcmp(tag, "mapping_info") == 0) 
+        {
 #if XML_PARSER_DEBUG
             printf("end mapping_info\n");
@@ -2001,5 +2116,6 @@
             return;
         }
-        else {
+        else 
+        {
             printf("[XML ERROR] Unknown tag in header node : %s\n",tag);
             exit(1);
@@ -2012,5 +2128,6 @@
 ///////////////////////////////////////
 void BuildTable(int fdout, const char * type, unsigned int nb_elem,
-                unsigned int elem_size, char ** table) {
+                unsigned int elem_size, char ** table) 
+{
     unsigned int i;
     // write element
@@ -2027,10 +2144,11 @@
 }
 
-
-int open_file(const char * file_path) {
-
+/////////////////////////////////////
+int open_file(const char * file_path) 
+{
     //open file
     int fdout = open( file_path, (O_CREAT | O_RDWR), (S_IWUSR | S_IRUSR) );
-    if (fdout < 0) {
+    if (fdout < 0) 
+    {
         perror("open");
         exit(1);
@@ -2038,5 +2156,6 @@
 
     //reinitialise the file
-    if (ftruncate(fdout, 0)) {
+    if (ftruncate(fdout, 0)) 
+    {
         perror("truncate");
         exit(1);
@@ -2051,13 +2170,30 @@
 
 
-///////////////////////////
-void buildBin(const char * file_path) {
+/////////////////////////////////////
+void buildBin(const char * file_path) 
+{
     unsigned int length;
 
     int fdout = open_file(file_path);
+
+#if XML_PARSER_DEBUG
+printf("Building map.bin for %s\n", header->name);
+printf("signature = %x\n", header->signature);
+printf("clusters  = %d\n", header->clusters);
+printf("vspaces   = %d\n", header->vspaces);
+printf("psegs     = %d\n", header->psegs);
+printf("vobjs     = %d\n", header->vobjs);
+printf("vsegs     = %d\n", header->vsegs);
+printf("tasks     = %d\n", header->tasks);
+printf("procs     = %d\n", header->procs);
+printf("irqs      = %d\n", header->irqs);
+printf("coprocs   = %d\n", header->coprocs);
+printf("periphs   = %d\n", header->periphs);
+#endif
 
     // write header to binary file
     length = write(fdout, (char *) header, sizeof(mapping_header_t));
-    if (length != sizeof(mapping_header_t)) {
+    if (length != sizeof(mapping_header_t)) 
+    {
         printf("write header error : length = %d \n", length);
         exit(1);
@@ -2160,7 +2296,9 @@
     int fdout = open_file(file_path);
 
-    char * prol   = "/* Generated from the mapping_info file */\n\n";
-    char * ifdef  = "#ifndef _HD_CONFIG_H\n#define _HD_CONFIG_H\n\n";
-    char * epil   = "\n#endif //_HD_CONFIG_H";
+    char prol[80];
+    sprintf(prol, "/* Generated from file %s.xml */\n\n",header->name);
+
+    char * ifdef  = "#ifndef _HARD_CONFIG_H\n#define _HARDD_CONFIG_H\n\n";
+    char * epil   = "\n#endif //_HARD_CONFIG_H";
 
     file_write(fdout, prol);
@@ -2187,5 +2325,5 @@
     file_write(fdout, "\n");
 
-    def_int_write(fdout, "USE_XICU          ", use_xicu);
+    def_int_write(fdout, "USE_XICU          ", use_xcu);
     def_int_write(fdout, "USE_IOB           ", use_iob);
 
@@ -2210,5 +2348,7 @@
     unsigned int vseg_id;
 
-    char * prol = "/* Generated from the mapping_info file */\n\n";
+    char prol[80];
+    sprintf(prol, "/* Generated from file %s.xml */\n\n",header->name);
+
     file_write(fdout, prol);
 
@@ -2273,4 +2413,7 @@
     file_write(fdout, "\n");
 
+    // fill the peripheral base address array 
+    set_periph_vbase_array();
+
     // non replicated peripherals
     ld_write(fdout, "seg_cma_base            ",   periph_vbase_array[PERIPH_TYPE_CMA]);
@@ -2285,8 +2428,13 @@
 
     // replicated peripherals
+    ld_write(fdout, "seg_xcu_base            ",   periph_vbase_array[PERIPH_TYPE_XCU]);
     ld_write(fdout, "seg_icu_base            ",   periph_vbase_array[PERIPH_TYPE_ICU]);
     ld_write(fdout, "seg_tim_base            ",   periph_vbase_array[PERIPH_TYPE_TIM]);
     ld_write(fdout, "seg_dma_base            ",   periph_vbase_array[PERIPH_TYPE_DMA]);
     ld_write(fdout, "seg_mmc_base            ",   periph_vbase_array[PERIPH_TYPE_MMC]);
+
+    file_write(fdout, "\n");
+
+    ld_write(fdout, "vseg_cluster_increment  ",   header->increment);
 
     close(fdout);
@@ -2323,5 +2471,4 @@
     }
 
-
     char * map_path = buildPath(argv[2], "map.bin"); 
     char * ld_path = buildPath(argv[2], "giet_vsegs.ld"); 
@@ -2333,10 +2480,13 @@
     xmlTextReaderPtr reader = xmlReaderForFile(argv[1], NULL, 0);
 
-    if (reader != NULL) {
+    if (reader != NULL) 
+    {
         status = xmlTextReaderRead (reader);
-        while (status == 1) {
+        while (status == 1) 
+        {
             const char * tag = (const char *) xmlTextReaderConstName(reader);
 
-            if (strcmp(tag, "mapping_info") == 0) { 
+            if (strcmp(tag, "mapping_info") == 0) 
+            { 
                 headerNode(reader);
                 prepareBuild();
@@ -2345,5 +2495,6 @@
                 genLd(ld_path);
             }
-            else {
+            else 
+            {
                 printf("[XML ERROR] Wrong file type: \"%s\"\n", argv[1]);
                 return 1;
@@ -2353,5 +2504,6 @@
         xmlFreeTextReader(reader);
 
-        if (status != 0) {
+        if (status != 0) 
+        {
             printf("[XML ERROR] Wrong Syntax in \"%s\" file\n", argv[1]);
             return 1;
