Index: soft/giet_vm/xml/xml_parser.c
===================================================================
--- soft/giet_vm/xml/xml_parser.c	(revision 188)
+++ soft/giet_vm/xml/xml_parser.c	(revision 189)
@@ -20,4 +20,5 @@
 #include  <libxml/xmlreader.h>
 #include  <mapping_info.h>
+#include  <irq_handler.h>
 
 #define MAX_CLUSTERS	1024
@@ -32,5 +33,5 @@
 #define MAX_COPROCS		4096
 #define MAX_CP_PORTS	8192
-#define MAX_CP_REGS		8192
+#define MAX_PERIPHS		8192
 
 #define XML_PARSER_DEBUG	0
@@ -49,19 +50,9 @@
 mapping_proc_t*	        proc[MAX_PROCS];		// proc array
 mapping_irq_t*	        irq[MAX_IRQS];			// irq array
-mapping_coproc_t*       coproc[MAX_COPROCS];		// coproc array
-mapping_coproc_port_t*	cp_port[MAX_CP_PORTS];	// coproc port array
-mapping_coproc_reg_t*   cp_reg[MAX_CP_REGS];     // coproc reg array
-
-typedef struct vobj_ref_s
-{
-    char vspace_name[32];
-    char vobj_name[32];
-}vobj_ref_t;
-
-// This arrray is useful to temporary save the a vobj referece 
-// formed by a vspace_name and a vobj_name (struct vobj_ref_s).
-// This arry will be used to set the attribute vobj_id of coproc_port
-// once all the vspace have been parsed.
-vobj_ref_t*	            cp_port_vobj_ref[MAX_CP_PORTS];	
+mapping_coproc_t*       coproc[MAX_COPROCS];	// coproc array
+mapping_cp_port_t*	    cp_port[MAX_CP_PORTS];	// coproc port array
+mapping_periph_t*       periph[MAX_PERIPHS];    // peripheral array
+
+// Index for the various arrays
 
 unsigned int		cluster_index  = 0;
@@ -82,18 +73,32 @@
 unsigned int		cp_port_loc_index = 0;
 
-unsigned int		cp_reg_index     = 0;
-unsigned int		cp_reg_loc_index = 0;
+unsigned int		periph_index     = 0;
+unsigned int		periph_loc_index = 0;
 
 unsigned int		vseg_index     = 0;
 unsigned int		vseg_loc_index = 0;
+
 unsigned int		task_index     = 0;
 unsigned int		task_loc_index = 0;
+
 unsigned int		vobj_index     = 0;
 unsigned int		vobj_loc_index = 0;
 unsigned int		vobj_count     = 0;
 
-unsigned int		tty_index      = 1;
-unsigned int		fb_index       = 0;
-            
+///////////////////////////////////////////////////////////////////////
+// This arrray is useful to build a temporary list of vobj references. 
+// The struct vobj_ref_s is formed by a vspace_name and a vobj_name.
+// This array is used to set the attribute vobj_id of a cp_port
+// once all the vspace have been parsed.
+
+typedef struct vobj_ref_s
+{
+    char vspace_name[32];
+    char vobj_name[32];
+}vobj_ref_t;
+
+vobj_ref_t*	        cp_port_vobj_ref[MAX_CP_PORTS];	
+
+
 //////////////////////////////////////////////////
 unsigned int getIntValue( xmlTextReaderPtr reader, 
@@ -183,5 +188,4 @@
 ////////////////////////////////////////////
 int getVspaceId( char*         vspace_name)
-////////////////////////////////////////////
 {
     unsigned int vspace_id;
@@ -201,5 +205,4 @@
                   char*		    vobj_name,
                   unsigned int  vspace_max)
-////////////////////////////////////////////
 {
     unsigned int vobj_id;
@@ -235,5 +238,5 @@
 #endif
 
-    cp_port[cp_port_index] = (mapping_coproc_port_t*)malloc(sizeof(mapping_coproc_port_t));
+    cp_port[cp_port_index] = (mapping_cp_port_t*)malloc(sizeof(mapping_cp_port_t));
     cp_port_vobj_ref[cp_port_index] = (vobj_ref_t*)malloc(sizeof(vobj_ref_t));
 
@@ -251,5 +254,5 @@
         else
         {
-            printf("[XML ERROR] illegal <direction> for coproc_port %d in cluster %d\n",
+            printf("[XML ERROR] illegal <direction> for cp_port %d in cluster %d\n",
                    cp_port_index, cluster_index);
             exit(1);
@@ -258,5 +261,5 @@
     else
     {
-        printf("[XML ERROR] missing <direction> for coproc_port %d in cluster %d\n",
+        printf("[XML ERROR] missing <direction> for cp_port %d in cluster %d\n",
                cp_port_index, cluster_index);
         exit(1);
@@ -274,5 +277,5 @@
     else
     {
-        printf("[XML ERROR] missing <vspacename> for coproc_port %d in cluster %d\n",
+        printf("[XML ERROR] missing <vspacename> for cp_port %d in cluster %d\n",
                cp_port_index, cluster_index);
         exit(1);
@@ -290,5 +293,5 @@
     else
     {
-        printf("[XML ERROR] missing <vobjname> for coproc_port %d in cluster %d\n",
+        printf("[XML ERROR] missing <vobjname> for cp_port %d in cluster %d\n",
                cp_port_index, cluster_index);
         exit(1);
@@ -300,120 +303,133 @@
 } // end cpPortNode()
 
-/////////////////////////////////////////
-void cpRegNode ( xmlTextReaderPtr reader )
-/////////////////////////////////////////
+///////////////////////////////////////////
+void periphNode ( xmlTextReaderPtr reader )
+///////////////////////////////////////////
 {
     char*           str;
     unsigned int    value;
-    unsigned int    ok;
+    unsigned int 	ok;
 
     if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return;
 
-    /* TWO: check source file consistency if possible */
-    if ( cp_reg_index >= MAX_CP_REGS )
-    {
-        printf("[XML ERROR] The number of regs (for coprocs) is larger than %d\n", MAX_CP_REGS);
-    }
-
-#if XML_PARSER_DEBUG
-printf("\n  reg %d\n", cp_reg_index);
-#endif
-
-    /* THIRD*/
-    cp_reg[cp_reg_index] = (mapping_coproc_reg_t*)malloc(sizeof(mapping_coproc_reg_t));
-
-    /* FOURTH: read all attribute*/
-
-    /////////// get name attribute 
-    str = getStringValue( reader, "name", &ok );
-#if XML_PARSER_DEBUG
-printf("      name = %s\n", str);
-#endif
+    if ( periph_index >= MAX_PERIPHS )
+    {
+        printf("[XML ERROR] The number of periphs is larger than %d\n", MAX_PERIPHS);
+    }
+
+#if XML_PARSER_DEBUG
+printf("\n  periph %d\n", periph_index);
+#endif
+
+    periph[periph_index] = (mapping_periph_t*)malloc(sizeof(mapping_periph_t));
+
+    /////////// get type attribute 
+    str = getStringValue( reader, "type", &ok );
     if ( ok ) 
     {
-        strncpy(cp_reg[cp_reg_index]->name, str, 31);
-    }
-    else
-    {
-        printf("[XML ERROR] illegal or missing <name> for coproc_reg %d in cluster %d\n",
-               cp_reg_index, cluster_index);
-        exit(1);
-    }
+#if XML_PARSER_DEBUG
+printf("      type     = %s\n", str);
+#endif
+        unsigned int error = 0;
+  
+        // The TTY, IOC, NIC, FBF and IOB peripherals cannot be replicated
+        if      ( strcmp( str, "IOC" ) == 0 ) 
+        {
+            periph[periph_index]->type = PERIPH_TYPE_IOC;
+            if ( header->ioc_clusterid == 0xFFFFFFFF) header->ioc_clusterid = cluster_index;
+            else  error = 1;
+        } 
+        else if ( strcmp( str, "TTY" ) == 0 )
+        {
+            periph[periph_index]->type = PERIPH_TYPE_TTY;
+            if ( header->ioc_clusterid == 0xFFFFFFFF) header->ioc_clusterid = cluster_index;
+            else  error = 1;
+        }
+        else if ( strcmp( str, "FBF" ) == 0 ) 
+        {
+            periph[periph_index]->type = PERIPH_TYPE_FBF;
+            if ( header->ioc_clusterid == 0xFFFFFFFF) header->ioc_clusterid = cluster_index;
+            else  error = 1;
+        }
+        else if ( strcmp( str, "NIC" ) == 0 ) 
+        {
+            periph[periph_index]->type = PERIPH_TYPE_NIC;
+            if ( header->ioc_clusterid == 0xFFFFFFFF) header->ioc_clusterid = cluster_index;
+            else  error = 1;
+        }
+        // The TIM, DMA and IOB peripherals can be replicated in several clusters
+        else if ( strcmp( str, "TIM" ) == 0 ) 
+        {
+            periph[periph_index]->type = PERIPH_TYPE_TIM;
+        }
+        else if ( strcmp( str, "DMA" ) == 0 ) 
+        {
+            periph[periph_index]->type = PERIPH_TYPE_DMA;
+        }
+        else if ( strcmp( str, "IOB" ) == 0 ) 
+        {
+            periph[periph_index]->type = PERIPH_TYPE_IOB;
+        }
+        else
+        {
+            printf("[XML ERROR] illegal <type> for peripheral %d in cluster %d\n",
+                   periph_loc_index, cluster_index);
+            exit(1);
+        }
+    }
+    else
+    {
+        printf("[XML ERROR] missing <type> for peripheral  %d in cluster %d\n",
+               periph_loc_index, cluster_index);
+        exit(1);
+    }
+
+    ///////// get channels attribute (optionnal : 1 if missing)
+    value = getIntValue( reader, "channels", &ok );
+    if ( ok )
+    {
+#if XML_PARSER_DEBUG
+printf("      channels = %d\n", value);
+#endif
+        periph[periph_index]->channels = value;
+    }
+    else
+    {
+        periph[periph_index]->channels = 1;
+    }
+
+    /////////// get psegname attribute 
+    str = getStringValue(reader,"psegname", &ok);
+    if ( ok == 0 )
+    {
+        printf("[XML ERROR] illegal or missing <psegname> for coproc %d in cluster %d\n", 
+                 coproc_index, cluster_index);
+        exit(1);
+    }
+
+    /////////// set psegid attribute
+    int index = getPsegId( cluster_index, str );
+    if ( index >= 0 ) 
+    {
+#if XML_PARSER_DEBUG
+printf("      clusterid = %d\n", cluster_index);
+printf("      psegname  = %s\n", str);
+printf("      psegid    = %d\n", index);
+#endif
+        periph[periph_index]->psegid = index;
+        assert(pseg[index]->type == PSEG_TYPE_PERI && 
+        "peripheral psegname attribute must refer to a pseg of type PERI" );
+    }
+    else              
+    {
+        printf("[XML ERROR] pseg not found for periph %d / clusterid = %d / psegname = %s\n", 
+                   periph_loc_index, cluster_index, str );
+        exit(1);
+    }  
     
-    ///////// get type attribute
-    str = getStringValue( reader, "type", &ok );
-    if ( ok )
-    {
-#if XML_PARSER_DEBUG
-printf("      type = %s\n", str);
-#endif
-        if      ( strcmp(str, "STATUS")   ) cp_reg[cp_reg_index]->type = REG_TYPE_STATUS;
-        else if ( strcmp(str, "CONFIG")   ) cp_reg[cp_reg_index]->type = REG_TYPE_CONFIG;
-        else
-        {
-            printf("[XML ERROR] illegal <type> for coproc_reg %d in cluster %d\n",
-                   cp_reg_index, cluster_index);
-            exit(1);
-        }
-    }  
-    else
-    {
-        printf("[XML ERROR] missing <type> for coproc_reg %d in cluster %d\n",
-               cp_reg_index, cluster_index);
-        exit(1);
-    }
-
-    ///////// get value attribute
-    value = getIntValue(reader, "value", &ok);
-    if ( ok )
-    {
-#if XML_PARSER_DEBUG
-printf("        value   = %d\n", value);
-#endif
-        cp_reg[cp_reg_index]->value = value;
-    }
-    else
-    {
-        printf("[XML ERROR] illegal or missing <value> for coproc_reg %d in cluster %d\n",
-               cp_reg_index, cluster_index);
-        exit(1);
-    }
-
-    ///////// get channel attribute
-    value = getIntValue(reader, "channel", &ok);
-    if ( ok )
-    {
-#if XML_PARSER_DEBUG
-printf("        channel   = %d\n", value);
-#endif
-        cp_reg[cp_reg_index]->channel_id = value;
-    }
-    else
-    {
-        printf("[XML ERROR] illegal or missing <channel> for coproc_reg %d in cluster %d\n",
-               cp_reg_index, cluster_index);
-        exit(1);
-    }
-
-    ///////// get index attribute
-    value = getIntValue(reader, "index", &ok);
-    if ( ok )
-    {
-#if XML_PARSER_DEBUG
-printf("        index   = %d\n", value);
-#endif
-        cp_reg[cp_reg_index]->loc_id = value;
-    }
-    else
-    {
-        printf("[XML ERROR] illegal or missing <index> for coproc_reg %d in cluster %d\n",
-               cp_reg_index, cluster_index);
-        exit(1);
-    }
-    
-    cp_reg_index++;
-    cp_reg_loc_index++;
-
-} // end cpRegNode()
+    periph_index++;
+    periph_loc_index++;
+
+} // end periphNode
 
 /////////////////////////////////////////
@@ -425,5 +441,4 @@
 
     cp_port_loc_index = 0;
-    cp_reg_loc_index = 0;
 
     if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return;
@@ -439,5 +454,4 @@
 
     coproc[coproc_index] = (mapping_coproc_t*)malloc(sizeof(mapping_coproc_t));
-
 
     /////////// get name attribute 
@@ -485,11 +499,9 @@
     }  
 
-    ////////// set port_offset and reg_offset attribute
+    ////////// set port_offset 
     coproc[coproc_index]->port_offset = cp_port_index;
-    coproc[coproc_index]->reg_offset = cp_reg_index;
-
-#if XML_PARSER_DEBUG
-printf("    port_offset = %d\n", cp_port_index);
-printf("    reg_offset = %d\n", cp_reg_index);
+
+#if XML_PARSER_DEBUG
+printf("      port_offset = %d\n", cp_port_index);
 #endif
 
@@ -499,12 +511,10 @@
         const char* tag = (const char*)xmlTextReaderConstName(reader);
 
-        if      ( strcmp(tag,"port")    == 0 ) cpPortNode(reader);
-        else if ( strcmp(tag,"reg")   == 0 ) cpRegNode(reader);
-        else if ( strcmp(tag,"#text"  ) == 0 ) { }
-        else if ( strcmp(tag,"#comment") == 0 );
-        else if ( strcmp(tag,"coproc")  == 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 ) 
         {
             coproc[coproc_index]->ports = cp_port_loc_index;
-            coproc[coproc_index]->regs = cp_reg_loc_index;
             coproc_loc_index++;
             coproc_index++;
@@ -548,6 +558,6 @@
 printf("        type    = %s\n", str);
 #endif
-        if      ( strcmp(str, "HARD") ) irq[irq_index]->type = IRQ_TYPE_HARD;
-        else if ( strcmp(str, "SOFT") ) irq[irq_index]->type = IRQ_TYPE_SOFT;
+        if      ( strcmp(str, "HARD") == 0 ) irq[irq_index]->type = 0;
+        else if ( strcmp(str, "SOFT") == 0 ) irq[irq_index]->type = 1;
         else
         {
@@ -564,5 +574,5 @@
     }
 
-    ///////// get irqid attribute
+    ///////// get icuid attribute
     value = getIntValue(reader, "icuid", &ok);
     if ( ok )
@@ -593,8 +603,9 @@
 printf("        isr     = %s\n", str);
 #endif
-        if      ( strcmp(str, "ISR_SWITCH") ) irq[irq_index]->isr = ISR_SWITCH;
-        else if ( strcmp(str, "ISR_IOC")    ) irq[irq_index]->isr = ISR_IOC;
-        else if ( strcmp(str, "ISR_FBDMA")  ) irq[irq_index]->isr = ISR_FBDMA;
-        else if ( strcmp(str, "ISR_TTY")    ) irq[irq_index]->isr = ISR_TTY;
+        if      ( strcmp(str, "ISR_SWITCH" ) == 0 ) irq[irq_index]->isr = ISR_SWITCH;
+        else if ( strcmp(str, "ISR_IOC"    ) == 0 ) irq[irq_index]->isr = ISR_IOC;
+        else if ( strcmp(str, "ISR_DMA"    ) == 0 ) irq[irq_index]->isr = ISR_DMA;
+        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
         {
@@ -603,4 +614,7 @@
             exit(1);
         }
+#if XML_PARSER_DEBUG
+printf("        isrnum  = %d\n", irq[irq_index]->isr);
+#endif
     }  
     else
@@ -664,4 +678,5 @@
     ////////// set irq_offset attribute
     proc[proc_index]->irq_offset = irq_index;
+
 #if XML_PARSER_DEBUG
 printf("    irq_offset = %d\n", irq_index);
@@ -673,8 +688,8 @@
         const char* tag = (const char*)xmlTextReaderConstName(reader);
 
-        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 ) 
+        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 ) 
         {
             proc[proc_index]->irqs = irq_loc_index;
@@ -817,5 +832,5 @@
     }
 
-    /////////// get use_tty  attribute (optionnal : 0 if missing)
+    /////////// get usetty  attribute (optionnal : 0 if missing)
     value = getIntValue(reader,"usetty", &ok);
     if ( ok )
@@ -824,12 +839,5 @@
 printf("      usetty = %x\n", value);
 #endif
-        if ( (value != 0) && (tty_index >= header->ttys) )
-        {
-            printf("[XML ERROR] The tty index is too large for task (%d,%d)\n", 
-                vspace_index, task_loc_index);
-            exit(1);
-        }
         task[task_index]->use_tty = value;
-        if (value != 0) tty_index++;
     }  
     else
@@ -838,23 +846,44 @@
     }
 
-    /////////// get use_fb  attribute (optionnal : 0 if missing)
-    value = getIntValue(reader,"usefb", &ok);
-    if ( ok )
-    {
-#if XML_PARSER_DEBUG
-printf("      usefb = %x\n", value);
-#endif
-        if ( (value != 0) && (fb_index >= header->fbs) )
-        {
-            printf("[XML ERROR] The fb channel index is too large for task (%d,%d)\n", 
-                vspace_index, task_loc_index);
-            exit(1);
-        }
-        task[task_index]->use_fb = value;
-        if (value != 0) fb_index++;
+    /////////// get usenic  attribute (optionnal : 0 if missing)
+    value = getIntValue(reader,"usenic", &ok);
+    if ( ok )
+    {
+#if XML_PARSER_DEBUG
+printf("      usenic = %x\n", value);
+#endif
+        task[task_index]->use_nic = value;
     }  
     else
     {
-        task[task_index]->use_fb = 0;
+        task[task_index]->use_nic = 0;
+    }
+
+    /////////// get usetimer attribute (optionnal : 0 if missing)
+    value = getIntValue(reader,"usetimer", &ok);
+    if ( ok )
+    {
+#if XML_PARSER_DEBUG
+printf("      usetimer = %x\n", value);
+#endif
+        task[task_index]->use_timer = value;
+    }  
+    else
+    {
+        task[task_index]->use_timer = 0;
+    }
+
+    /////////// get usefbdma  attribute (optionnal : 0 if missing)
+    value = getIntValue(reader,"usefbdma", &ok);
+    if ( ok )
+    {
+#if XML_PARSER_DEBUG
+printf("      usefbdma = %x\n", value);
+#endif
+        task[task_index]->use_fbdma = value;
+    }  
+    else
+    {
+        task[task_index]->use_fbdma = 0;
     }
 
@@ -865,4 +894,5 @@
 //////////////////////////////////////////
 void  vobjNode ( xmlTextReaderPtr reader )
+//////////////////////////////////////////
 {
     unsigned int 	ok;
@@ -986,5 +1016,6 @@
     else
     {
-        if((vobj[vobj_index]->type == VOBJ_TYPE_MWMR || vobj[vobj_index]->type == VOBJ_TYPE_BARRIER ))
+        if( (vobj[vobj_index]->type == VOBJ_TYPE_MWMR) || 
+            (vobj[vobj_index]->type == VOBJ_TYPE_BARRIER) )
         {
             printf("[XML ERROR] illegal or missing <value> attribute for vobj (%d,%d). \
@@ -1003,4 +1034,5 @@
 //////////////////////////////////////////
 void  vsegNode ( xmlTextReaderPtr reader )
+//////////////////////////////////////////
 {
     unsigned int 	ok;
@@ -1144,7 +1176,8 @@
         const char* tag = (const char*)xmlTextReaderConstName(reader);
 
-        if      ( strcmp(tag,"vobj")    == 0 ) vobjNode(reader);
-        else if ( strcmp(tag,"#text"  ) == 0 ) { }
-        else if ( strcmp(tag,"vseg")    == 0 ) 
+        if      ( strcmp(tag, "vobj")     == 0 ) vobjNode(reader);
+        else if ( strcmp(tag, "#text"  )  == 0 ) { }
+        else if ( strcmp(tag, "#comment") == 0 ) { }
+        else if ( strcmp(tag, "vseg")     == 0 ) 
         {
             vseg[vseg_index]->vobjs = vobj_count;
@@ -1164,4 +1197,5 @@
 //////////////////////////////////////////
 void vspaceNode( xmlTextReaderPtr reader )
+//////////////////////////////////////////
 {
     char*    		str;
@@ -1233,9 +1267,9 @@
         const char* tag = (const char*)xmlTextReaderConstName(reader);
 
-        if      ( strcmp(tag,"vseg")    == 0 ) vsegNode(reader);
-        else if ( strcmp(tag,"task")    == 0 ) taskNode(reader);
-        else if ( strcmp(tag,"#text")   == 0 ) { }
-        else if ( strcmp(tag,"#comment") == 0 );
-        else if ( strcmp(tag,"vspace")  == 0 ) 
+        if      ( strcmp(tag, "vseg")     == 0 ) vsegNode(reader);
+        else if ( strcmp(tag, "task")     == 0 ) taskNode(reader);
+        else if ( strcmp(tag, "#text")    == 0 ) { }
+        else if ( strcmp(tag, "#comment") == 0 ) { }
+        else if ( strcmp(tag, "vspace")   == 0 ) 
         {
             vspace[vspace_index]->vobjs = vobj_loc_index; 
@@ -1288,4 +1322,5 @@
 //////////////////////////////////////////
 void  psegNode ( xmlTextReaderPtr reader )
+//////////////////////////////////////////
 {
     unsigned int 	ok;
@@ -1379,4 +1414,5 @@
 /////////////////////////////////////////////
 void  clusterNode ( xmlTextReaderPtr reader )
+/////////////////////////////////////////////
 {
     unsigned int ok;
@@ -1385,5 +1421,5 @@
     proc_loc_index = 0;
     coproc_loc_index = 0;
-    cluster[cluster_index] = 0;
+    periph_loc_index = 0;
 
     if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return;
@@ -1402,5 +1438,5 @@
     cluster[cluster_index] = (mapping_cluster_t*)malloc(sizeof(mapping_cluster_t));
 
-    /////////// get index attribute (optional)
+    /////////// check cluster index attribute (optional)
     value = getIntValue(reader,"index",&ok);
     if ( ok && (value != cluster_index) )
@@ -1411,16 +1447,18 @@
     }
 
-
-    ////////// set pseg_offset attribute
-    cluster[cluster_index]->pseg_offset = pseg_index;
-    cluster[cluster_index]->proc_offset = proc_index;
+    ////////// set offsets
+    cluster[cluster_index]->pseg_offset   = pseg_index;
+    cluster[cluster_index]->proc_offset   = proc_index;
     cluster[cluster_index]->coproc_offset = coproc_index;
-#if XML_PARSER_DEBUG
-printf("    pseg_offset = %d\n", pseg_index);
-printf("    proc_offset = %d\n", proc_index);
+    cluster[cluster_index]->periph_offset = periph_index;
+
+#if XML_PARSER_DEBUG
+printf("    pseg_offset   = %d\n", pseg_index);
+printf("    proc_offset   = %d\n", proc_index);
 printf("    coproc_offset = %d\n", coproc_index);
-#endif
-
-    ////////// get psegs, coproc and/or procs
+printf("    periph_offset = %d\n", coproc_index);
+#endif
+
+    ////////// get psegs, procs, coprocs and periphs
     int status = xmlTextReaderRead(reader);
 
@@ -1429,17 +1467,26 @@
         const char* tag = (const char*)xmlTextReaderConstName(reader);
 
-        if      ( strcmp(tag, "pseg")    == 0 ) psegNode(reader);
-        else if ( strcmp(tag, "proc")    == 0 ) procNode(reader);
-        else if ( strcmp(tag, "coproc")    == 0 ) coprocNode(reader);
-        else if ( strcmp(tag, "#text")   == 0 ) { }
-        else if ( strcmp(tag,"#comment") == 0 );
-        else if ( strcmp(tag, "cluster") == 0 ) 
-        {
-#if XML_PARSER_DEBUG
+        if      ( strcmp(tag, "pseg")     == 0 ) psegNode(reader);
+        else if ( strcmp(tag, "proc")     == 0 ) procNode(reader);
+        else if ( strcmp(tag, "coproc")   == 0 ) coprocNode(reader);
+        else if ( strcmp(tag, "periph")   == 0 ) periphNode(reader);
+        else if ( strcmp(tag, "#text")    == 0 ) { }
+        else if ( strcmp(tag, "#comment") == 0 ) { }
+        else if ( strcmp(tag, "cluster")  == 0 ) 
+        {
+            cluster[cluster_index]->procs   = proc_loc_index;
+            cluster[cluster_index]->coprocs = coproc_loc_index;
+            cluster[cluster_index]->periphs = periph_loc_index;
+
+            // cluster[cluster_index]psegs update is done in psegNode(),
+            // because the coprocNode() call to getPsegId() need it
+
+#if XML_PARSER_DEBUG
+printf("    psegs   = %d\n", cluster[cluster_index]->psegs);
+printf("    procs   = %d\n", cluster[cluster_index]->procs);
+printf("    coprocs = %d\n", cluster[cluster_index]->coprocs);
+printf("    periphs = %d\n", cluster[cluster_index]->periphs);
 printf("  end cluster %d\n", cluster_index);
 #endif
-            cluster[cluster_index]->procs = proc_loc_index;
-            cluster[cluster_index]->coprocs = coproc_loc_index;
-            //psegs = pseg_loc_index is done in psegNode(), so coprocNode() call to getPsegId() success
             cluster_index++;
             return;
@@ -1451,4 +1498,5 @@
 //////////////////////////////////////////////
 void clusterSetNode( xmlTextReaderPtr reader )
+//////////////////////////////////////////////
 {
     if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return;
@@ -1463,8 +1511,8 @@
         const char* tag = (const char*)xmlTextReaderConstName(reader);
 
-        if      ( strcmp(tag,"cluster") == 0 ) clusterNode(reader);
-        else if ( strcmp(tag,"#text") == 0 ) { }
-        else if ( strcmp(tag,"#comment") == 0 );
-        else if ( strcmp(tag,"clusterset") == 0 ) 
+        if      ( strcmp(tag, "cluster")    == 0 ) clusterNode(reader);
+        else if ( strcmp(tag, "#text")      == 0 ) { }
+        else if ( strcmp(tag, "#comment")   == 0 ) { }
+        else if ( strcmp(tag, "clusterset") == 0 ) 
         {
             // checking source file consistency
@@ -1479,10 +1527,9 @@
 printf("  end cluster set\n\n");
 #endif
-                header->psegs = pseg_index;
-                header->procs = proc_index;
-                header->irqs  = irq_index;
-                header->coprocs = coproc_index;
+                header->psegs    = pseg_index;
+                header->procs    = proc_index;
+                header->irqs     = irq_index;
+                header->coprocs  = coproc_index;
                 header->cp_ports = cp_port_index;
-                header->cp_regs = cp_reg_index;
                 return;
             }
@@ -1499,4 +1546,5 @@
 /////////////////////////////////////////////
 void globalSetNode( xmlTextReaderPtr reader )
+/////////////////////////////////////////////
 {
     if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return;
@@ -1511,8 +1559,8 @@
         const char* tag = (const char*)xmlTextReaderConstName(reader);
 
-        if      ( strcmp(tag,"vseg") == 0    ) vsegNode(reader);
-        else if ( strcmp(tag,"#text"  ) == 0 ) { }
-        else if ( strcmp(tag,"#comment") == 0 );
-        else if ( strcmp(tag,"globalset") == 0  ) 
+        if      ( strcmp(tag, "vseg")      == 0 ) vsegNode(reader);
+        else if ( strcmp(tag, "#text"  )   == 0 ) { }
+        else if ( strcmp(tag, "#comment")  == 0 ) { }
+        else if ( strcmp(tag, "globalset") == 0 ) 
         {
             // checking source file consistency
@@ -1542,4 +1590,5 @@
 /////////////////////////////////////////////
 void vspaceSetNode( xmlTextReaderPtr reader )
+/////////////////////////////////////////////
 {
     if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return;
@@ -1554,8 +1603,8 @@
         const char* tag = (const char*)xmlTextReaderConstName(reader);
 
-        if      ( strcmp(tag,"vspace") == 0    ) vspaceNode(reader);
-        else if ( strcmp(tag,"#text"  ) == 0 ) { }
-        else if ( strcmp(tag,"#comment") == 0 );
-        else if ( strcmp(tag,"vspaceset") == 0  ) 
+        if      ( strcmp(tag, "vspace"   ) == 0 ) vspaceNode(reader);
+        else if ( strcmp(tag, "#text"    ) == 0 ) { }
+        else if ( strcmp(tag, "#comment" ) == 0 ) { }
+        else if ( strcmp(tag, "vspaceset") == 0 ) 
         {
             // checking source file consistency
@@ -1584,4 +1633,5 @@
 //////////////////////////////////////////
 void headerNode(xmlTextReaderPtr reader )
+//////////////////////////////////////////
 {
     char*       	name;
@@ -1632,34 +1682,4 @@
     }
 
-    ///////// get ttys attribute
-    value = getIntValue(reader, "ttys", &ok);
-    if ( ok )
-    {
-#if XML_PARSER_DEBUG
-printf("  ttys = %d\n", value);
-#endif
-	header->ttys  = value;
-    }
-    else
-    {
-        printf("[XML ERROR] illegal or missing <ttys> attribute in header\n");
-        exit(1);
-    }
-
-    ///////// get fbs attribute
-    value = getIntValue(reader, "fbs", &ok);
-    if ( ok )
-    {
-#if XML_PARSER_DEBUG
-printf("  fbs = %d\n", value);
-#endif
-	header->fbs  = value;
-    }
-    else
-    {
-        printf("[XML ERROR] illegal or missing <fbs> attribute in header\n");
-        exit(1);
-    }
-
     ///////// get vspaces attribute
     value = getIntValue(reader, "vspaces", &ok);
@@ -1702,4 +1722,11 @@
     }
 
+    //////// initialise non replicated peripherals cluster_id
+    header->tty_clusterid = 0xFFFFFFFF;
+    header->nic_clusterid = 0xFFFFFFFF;
+    header->ioc_clusterid = 0xFFFFFFFF;
+    header->fbf_clusterid = 0xFFFFFFFF;
+
+    ///////// set signature
     header->signature = IN_MAPPING_SIGNATURE;
 
@@ -1709,10 +1736,10 @@
         const char* tag = (const char*)xmlTextReaderConstName(reader);
 
-        if      ( strcmp(tag,"clusterset")   == 0 ) clusterSetNode(reader);
-        else if ( strcmp(tag,"globalset")    == 0 ) globalSetNode(reader);
-        else if ( strcmp(tag,"vspaceset")    == 0 ) vspaceSetNode(reader);
-        else if ( strcmp(tag,"#text")        == 0 ) ;
-        else if ( strcmp(tag,"#comment")     == 0 ) ;
-        else if ( strcmp(tag,"mapping_info") == 0 ) 
+        if      ( strcmp(tag, "clusterset")   == 0 ) clusterSetNode(reader);
+        else if ( strcmp(tag, "globalset")    == 0 ) globalSetNode(reader);
+        else if ( strcmp(tag, "vspaceset")    == 0 ) vspaceSetNode(reader);
+        else if ( strcmp(tag, "#text")        == 0 ) { }
+        else if ( strcmp(tag, "#comment")     == 0 ) { }
+        else if ( strcmp(tag, "mapping_info") == 0 ) 
         {
 #if XML_PARSER_DEBUG
@@ -1730,4 +1757,5 @@
 } // end headerNode()
     
+///////////////////////////////////////
 void BuildTable( int fdout,
                const char* type,
@@ -1735,4 +1763,5 @@
                unsigned int elem_size,
                char** table)        
+////////////////////////////////////////
 {
     unsigned int i;
@@ -1758,4 +1787,5 @@
 ///////////////////////////
 void  buildBin( int fdout )
+///////////////////////////
 {
     unsigned int    vspace_id;
@@ -1823,23 +1853,22 @@
     }
 
-    // write tasks
+    // write tasks array
     BuildTable(fdout, "task", task_index, sizeof(mapping_task_t), (char**) task);
-    //building proc
+    //building procs array
     BuildTable(fdout, "proc", proc_index, sizeof(mapping_proc_t), (char**) proc);
-    //building irq
+    //building irqs array
     BuildTable(fdout, "irq", irq_index, sizeof(mapping_irq_t), (char**)irq);
-    //building coproc
+    //building coprocs array
     BuildTable(fdout, "coproc", coproc_index, sizeof(mapping_coproc_t), (char**)coproc);
-    //building cp_port
-    BuildTable(fdout, "cp_port", cp_port_index, sizeof(mapping_coproc_port_t),(char**) cp_port);
-    //building cp_reg
-    BuildTable(fdout, "cp_reg", cp_reg_index, sizeof(mapping_coproc_reg_t), (char**)cp_reg);
+    //building cp_ports array
+    BuildTable(fdout, "cp_port", cp_port_index, sizeof(mapping_cp_port_t),(char**) cp_port);
+    //building periphs array
+    BuildTable(fdout, "periph", periph_index, sizeof(mapping_periph_t), (char**)periph);
 
 } // end buildBin()
 
-/////////////////////////////////////////
-// this function set the value of vobj_id 
-// of the coproc_ports.
-///////////////////
+///////////////////////////////////////////////////////////////////////
+// this function set the value the vobj_id fiels of all cp_ports
+///////////////////////////////////////////////////////////////////////
 void prepareBuild()
 {
@@ -1850,5 +1879,5 @@
         if ( vspace_id < 0 ) 
         {
-            printf("[XML ERROR] illegal  <vspacename> for coproc_port %d,\n", 
+            printf("[XML ERROR] illegal  <vspacename> for cp_port %d,\n", 
                     i);
             exit(1);
@@ -1856,9 +1885,12 @@
         cp_port[i]->vspaceid = vspace_id;
         
-        int vobj_id = getVobjLocId( vspace_id, cp_port_vobj_ref[i]->vobj_name, vspace[vspace_id]->vobjs );
+        int vobj_id = getVobjLocId( vspace_id, 
+                                    cp_port_vobj_ref[i]->vobj_name, 
+                                    vspace[vspace_id]->vobjs );
         if ( vobj_id >= 0 ) 
         {
-#if XML_PARSER_DEBUG
-printf("coproc_port = %d\n", i);
+
+#if XML_PARSER_DEBUG
+printf("\ncp_port = %d\n", i);
 printf("      vspace_name  = %s\n", cp_port_vobj_ref[i]->vspace_name);
 printf("      vobj_name    = %s\n", cp_port_vobj_ref[i]->vobj_name);
@@ -1866,13 +1898,14 @@
 #endif
             cp_port[i]->vobjlocid = vobj_id;
-            assert((vobj[ vspace[vspace_id]->vobj_offset + vobj_id]->type == VOBJ_TYPE_MWMR) && "coproc ports has to refere to a vobj of type MWMR");
+
+            assert((vobj[ vspace[vspace_id]->vobj_offset + vobj_id]->type == VOBJ_TYPE_MWMR)
+            && "coproc ports has to refere to a vobj of type MWMR");
         }
         else              
         {
-            printf("[XML ERROR] illegal  <vobjname> for coproc_port %d,\n", 
+            printf("[XML ERROR] illegal  <vobjname> for cp_port %d,\n", 
                     i);
             exit(1);
         }
-        
     }
 }
@@ -1880,4 +1913,5 @@
 /////////////////////////////////////
 int  main ( int argc, char* argv[] )
+/////////////////////////////////////
 {
     if ( argc < 3 ) 
@@ -1913,6 +1947,4 @@
             }
             else
-            if ( strcmp(tag,"#comment") == 0 );// a way to skips comment
-            else
             {
                 printf("[XML ERROR] Wrong file type: \"%s\"\n", argv[1]);
