Index: soft/giet_vm/xml/xml_parser.c
===================================================================
--- soft/giet_vm/xml/xml_parser.c	(revision 175)
+++ soft/giet_vm/xml/xml_parser.c	(revision 181)
@@ -1,5 +1,5 @@
 ///////////////////////////////////////////////////////////////////////////////////////
 // File     : xml_parser.c
-// Date     : 04/04/2012
+// Date     : 14/04/2012
 // Author   : alain greiner
 // Copyright (c) UPMC-LIP6
@@ -17,4 +17,5 @@
 #include  <stdio.h>
 #include  <string.h>
+#include  <assert.h>
 #include  <libxml/xmlreader.h>
 #include  <mapping_info.h>
@@ -27,6 +28,11 @@
 #define MAX_VSEGS		4096
 #define MAX_VOBJS		8192
-
-#define XML_PARSER_DEBUG	0
+#define MAX_PROCS		1024
+#define MAX_IRQS		8192
+#define MAX_COPROCS		4096
+#define MAX_CP_PORTS	8192
+#define MAX_CP_REGS		8192
+
+#define XML_PARSER_DEBUG	1
 
 ///////////////////////////////////////////////////////////////////////////////////
@@ -34,16 +40,49 @@
 ///////////////////////////////////////////////////////////////////////////////////
 
-mapping_header_t*	header;
-mapping_cluster_t*	cluster[MAX_CLUSTERS];		// cluster array
-mapping_pseg_t*		pseg[MAX_PSEGS];		// pseg array
-mapping_vspace_t*	vspace[MAX_VSPACES];		// vspace array
-mapping_vseg_t*		vseg[MAX_VSEGS];		// vseg array
-mapping_vobj_t*		vobj[MAX_VOBJS];		// vobj array
-mapping_task_t*		task[MAX_TASKS];		// task array
+mapping_header_t*       header;
+mapping_cluster_t*      cluster[MAX_CLUSTERS];	// cluster array
+mapping_pseg_t*	        pseg[MAX_PSEGS];		// pseg array
+mapping_vspace_t*       vspace[MAX_VSPACES];	// vspace array
+mapping_vseg_t*	        vseg[MAX_VSEGS];		// vseg array
+mapping_vobj_t*	        vobj[MAX_VOBJS];		// vobj array
+mapping_task_t*	        task[MAX_TASKS];		// task array
+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];	
 
 unsigned int		cluster_index  = 0;
 unsigned int		vspace_index   = 0;
 unsigned int		global_index   = 0;
-unsigned int		pseg_index     = 0;
+unsigned int		pseg_index     = 0;		
+
+unsigned int		proc_index     = 0;
+unsigned int		proc_loc_index = 0;
+
+unsigned int		irq_index      = 0;
+unsigned int		irq_loc_index  = 0;
+
+unsigned int		coproc_index     = 0;
+unsigned int		coproc_loc_index = 0;
+
+unsigned int		cp_port_index     = 0;
+unsigned int		cp_port_loc_index = 0;
+
+unsigned int		cp_reg_index     = 0;
+unsigned int		cp_reg_loc_index = 0;
+
 unsigned int		vseg_index     = 0;
 unsigned int		vseg_loc_index = 0;
@@ -127,27 +166,48 @@
 } // end getStringValue()
 
-//////////////////////////
-int getPsegId( char* str )
+///////////////////////////////////////
+int getPsegId( unsigned int	cluster_id,
+               char*        pseg_name )
 {
     unsigned int pseg_id;
-
-    for ( pseg_id = 0 ; pseg_id < header->psegs ; pseg_id++ )
-    {
-        if ( strcmp(pseg[pseg_id]->name, str) == 0 ) return pseg_id;
+    unsigned int pseg_min = cluster[cluster_id]->pseg_offset;
+    unsigned int pseg_max = pseg_min + cluster[cluster_id]->psegs;
+
+    for ( pseg_id = pseg_min ; pseg_id < pseg_max ; pseg_id++ )
+    {
+        if ( strcmp(pseg[pseg_id]->name, pseg_name) == 0 ) return pseg_id;
     }
     return -1;
 }
 
-//////////////////////////////////////////
+////////////////////////////////////////////
+int getVspaceId( char*         vspace_name)
+////////////////////////////////////////////
+{
+    unsigned int vspace_id;
+
+    for( vspace_id = 0; vspace_id < vspace_index ; vspace_id++)
+    {
+        if( !strcmp(vspace[vspace_id]->name, vspace_name))
+        {
+            return vspace_id;
+        }
+    }
+    return -1;
+}
+
+////////////////////////////////////////////
 int getVobjLocId( unsigned int	vspace_id,
-                  char*		str )
+                  char*		    vobj_name,
+                  unsigned int  vspace_max)
+////////////////////////////////////////////
 {
     unsigned int vobj_id;
     unsigned int vobj_min = vspace[vspace_id]->vobj_offset;
-    unsigned int vobj_max = vobj_min + vobj_loc_index;
+    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, str) == 0 )
+        if ( strcmp(vobj[vobj_id]->name, vobj_name) == 0 )
         {
              return (vobj_id - vobj_min);
@@ -157,6 +217,309 @@
 }
 
-//////////////////////////////////////////
-void  taskNode ( 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 XML_PARSER_DEBUG
+printf("\n  port %d\n", cp_port_index);
+#endif
+
+    cp_port[cp_port_index] = (mapping_coproc_port_t*)malloc(sizeof(mapping_coproc_port_t));
+    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 XML_PARSER_DEBUG
+printf("      direction = %s\n", str);
+#endif
+        if      ( strcmp(str, "TO_COPROC")   ) cp_port[cp_port_index]->direction = PORT_TO_COPROC;
+        else if ( strcmp(str, "FROM_COPROC") ) cp_port[cp_port_index]->direction = PORT_FROM_COPROC;
+        else
+        {
+            printf("[XML ERROR] illegal <direction> for coproc_port %d in cluster %d\n",
+                   cp_port_index, cluster_index);
+            exit(1);
+        }
+    }  
+    else
+    {
+        printf("[XML ERROR] missing <direction> for coproc_port %d in cluster %d\n",
+               cp_port_index, cluster_index);
+        exit(1);
+    }
+    
+    /////////// get vspacename attribute 
+    str = getStringValue( reader, "vspacename", &ok );
+#if XML_PARSER_DEBUG
+printf("      vspacename = %s\n", str);
+#endif
+    if ( ok ) 
+    {
+        strncpy(cp_port_vobj_ref[cp_port_index]->vspace_name, str, 31);
+    }
+    else
+    {
+        printf("[XML ERROR] missing <vspacename> for coproc_port %d in cluster %d\n",
+               cp_port_index, cluster_index);
+        exit(1);
+    }
+
+    /////////// get vobjname attribute 
+    str = getStringValue( reader, "vobjname", &ok );
+#if XML_PARSER_DEBUG
+printf("      vobjname = %s\n", str);
+#endif
+    if ( ok ) 
+    {
+        strncpy(cp_port_vobj_ref[cp_port_index]->vobj_name, str, 31);
+    }
+    else
+    {
+        printf("[XML ERROR] missing <vobjname> for coproc_port %d in cluster %d\n",
+               cp_port_index, cluster_index);
+        exit(1);
+    }
+    
+    cp_port_index++;
+    cp_port_loc_index++;
+
+} // end cpPortNode()
+
+/////////////////////////////////////////
+void cpRegNode ( xmlTextReaderPtr reader )
+/////////////////////////////////////////
+{
+    char*           str;
+    unsigned int    value;
+    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 ( 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);
+    }
+    
+    ///////// 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()
+
+/////////////////////////////////////////
+void coprocNode ( xmlTextReaderPtr reader )
+/////////////////////////////////////////
+{
+    char*           str;
+    unsigned int 	ok;
+
+    cp_port_loc_index = 0;
+    cp_reg_loc_index = 0;
+
+    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);
+    }
+
+#if XML_PARSER_DEBUG
+printf("\n  coproc %d\n", coproc_index);
+#endif
+
+    coproc[coproc_index] = (mapping_coproc_t*)malloc(sizeof(mapping_coproc_t));
+
+
+    /////////// get name attribute 
+    str = getStringValue( reader, "name", &ok );
+    if ( ok ) 
+    {
+#if XML_PARSER_DEBUG
+printf("      name = %s\n", str);
+#endif
+        strncpy(coproc[coproc_index]->name, str, 31);
+    }
+    else
+    {
+        printf("[XML ERROR] illegal or missing <name> for coproc %d in cluster %d\n",
+               coproc_index, cluster_index);
+        exit(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
+        coproc[coproc_index]->psegid = index;
+        assert(pseg[index]->type == PSEG_TYPE_PERI && "coproc psegname attribute must refer to a pseg of type PERI" );
+    }
+    else              
+    {
+        printf("[XML ERROR] pseg not found for coproc %d / clusterid = %d / psegname = %s\n", 
+                   coproc_index, cluster_index, str );
+        exit(1);
+    }  
+
+    ////////// set port_offset and reg_offset attribute
+    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);
+#endif
+
+    int status = xmlTextReaderRead(reader);
+    while ( status == 1 ) 
+    {
+        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,"coproc")  == 0 ) 
+        {
+            coproc[coproc_index]->ports = cp_port_loc_index;
+            coproc[coproc_index]->regs = cp_reg_loc_index;
+            coproc_loc_index++;
+            coproc_index++;
+            return;
+        }
+        else 
+        {
+            printf("[XML ERROR] Unknown tag %s",tag);
+            exit(1);
+        }
+        status = xmlTextReaderRead ( reader );
+    }
+} // end coprocNode()
+
+///////////////////////////////////////
+void irqNode( xmlTextReaderPtr reader )
+///////////////////////////////////////
 {
     unsigned int 	ok;
@@ -166,4 +529,176 @@
     if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return;
 
+    if ( irq_index >= MAX_IRQS )
+    {
+        printf("[XML ERROR] The number of irqs is larger than %d\n", MAX_IRQS);
+    }
+
+#if XML_PARSER_DEBUG
+printf("     irq %d\n", irq_loc_index);
+#endif
+
+    irq[irq_index] = (mapping_irq_t*)malloc(sizeof(mapping_irq_t));
+
+    ///////// get type attribute
+    str = getStringValue(reader,"type", &ok);
+    if ( ok )
+    {
+#if XML_PARSER_DEBUG
+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;
+        else
+        {
+            printf("[XML ERROR] undefined IRQ  <type> for processor %d in cluster %d\n",
+                   cluster_index, proc_loc_index );
+            exit(1);
+        }
+    }  
+    else
+    {
+        printf("[XML ERROR] missing IRQ <type> for processor %d in cluster %d\n",
+               cluster_index, proc_loc_index );
+        exit(1);
+    }
+
+    ///////// get irqid attribute
+    value = getIntValue(reader, "icuid", &ok);
+    if ( ok )
+    {
+#if XML_PARSER_DEBUG
+printf("        icuid   = %d\n", value);
+#endif
+        irq[irq_index]->icuid = value;
+        if ( value >= 32 )
+        {
+            printf("[XML ERROR] IRQ <icuid> too large for processor %d in cluster %d\n",
+                   cluster_index, proc_loc_index );
+            exit(1);
+        }
+    }
+    else
+    {
+        printf("[XML ERROR] missing IRQ <icuid> for processor %d in cluster %d\n",
+               cluster_index, proc_loc_index );
+        exit(1);
+    }
+
+    ///////// get isr attribute
+    str = getStringValue(reader,"isr", &ok);
+    if ( ok )
+    {
+#if XML_PARSER_DEBUG
+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;
+        else
+        {
+            printf("[XML ERROR] illegal IRQ <isr> for processor %d in cluster %d\n",
+                   cluster_index, proc_loc_index );
+            exit(1);
+        }
+    }  
+    else
+    {
+        printf("[XML ERROR] missing IRQ <isr> for processor %d in cluster %d\n",
+               cluster_index, proc_loc_index );
+        exit(1);
+    }
+
+    ///////// get channel attribute (optionnal : 0 if missing)
+    value = getIntValue(reader, "channel", &ok);
+    if ( ok )
+    {
+#if XML_PARSER_DEBUG
+printf("        channel = %d\n", value);
+#endif
+        irq[irq_index]->channel = value;
+    }
+    else
+    {
+        irq[irq_index]->channel = 0;
+    }
+
+    irq_index++;
+    irq_loc_index++;
+
+} // end irqNode
+
+/////////////////////////////////////////
+void procNode ( xmlTextReaderPtr reader )
+/////////////////////////////////////////
+{
+    unsigned int 	ok;
+    unsigned int    value;
+
+    irq_loc_index = 0;
+
+    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);
+    }
+
+#if XML_PARSER_DEBUG
+printf("\n  proc %d\n", proc_index);
+#endif
+
+    proc[proc_index] = (mapping_proc_t*)malloc(sizeof(mapping_proc_t));
+
+
+    /////////// get index attribute (optional)
+    value = getIntValue(reader,"index",&ok);
+    if ( ok && (value != proc_index) )
+    {
+            printf("[XML ERROR] wrong proc index / expected value is %d", 
+                proc_index);
+            exit(1);
+    }
+
+    ////////// set irq_offset attribute
+    proc[proc_index]->irq_offset = irq_index;
+#if XML_PARSER_DEBUG
+printf("    irq_offset = %d\n", irq_index);
+#endif
+
+    int status = xmlTextReaderRead(reader);
+    while ( status == 1 ) 
+    {
+        const char* tag = (const char*)xmlTextReaderConstName(reader);
+
+        if      ( strcmp(tag,"irq")    == 0 ) irqNode(reader);
+        else if ( strcmp(tag,"#text")   == 0 ) { }
+        else if ( strcmp(tag,"proc")  == 0 ) 
+        {
+            proc[proc_index]->irqs = irq_loc_index;
+            proc_loc_index++;
+            proc_index++;
+            return;
+        }
+        else 
+        {
+            printf("[XML ERROR] Unknown tag %s",tag);
+            exit(1);
+        }
+        status = xmlTextReaderRead ( reader );
+    }
+} // end procNode()
+
+
+/////////////////////////////////////////
+void taskNode ( xmlTextReaderPtr reader )
+/////////////////////////////////////////
+{
+    unsigned int 	ok;
+    unsigned int 	value;
+    char*    		str;
+
+    if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return;
+
     if ( task_index >= MAX_TASKS )
     {
@@ -241,5 +776,5 @@
     if ( ok )
     {
-        int index = getVobjLocId( vspace_index, str );
+        int index = getVobjLocId( vspace_index, str , vobj_loc_index);
         if ( index >= 0 ) 
         {
@@ -380,11 +915,11 @@
         }
     }
-    else if (ok && (strcmp(type_str, "BLOB")    == 0)) vobj[vobj_index]->type = VOBJ_TYPE_BLOB;
-    else if (ok && (strcmp(type_str, "PTAB")    == 0)) vobj[vobj_index]->type = VOBJ_TYPE_PTAB;
-    else if (ok && (strcmp(type_str, "PERI")    == 0)) vobj[vobj_index]->type = VOBJ_TYPE_PERI;
-    else if (ok && (strcmp(type_str, "MWMR")    == 0)) vobj[vobj_index]->type = VOBJ_TYPE_MWMR;
-    else if (ok && (strcmp(type_str, "LOCK")    == 0)) vobj[vobj_index]->type = VOBJ_TYPE_LOCK;
-    else if (ok && (strcmp(type_str, "BUFFER")  == 0)) vobj[vobj_index]->type = VOBJ_TYPE_BUFFER;
-    else if (ok && (strcmp(type_str, "BARRIER") == 0)) vobj[vobj_index]->type = VOBJ_TYPE_BARRIER;
+    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;
+    else if (ok && (strcmp(str, "PERI")    == 0)) vobj[vobj_index]->type = VOBJ_TYPE_PERI;
+    else if (ok && (strcmp(str, "MWMR")    == 0)) vobj[vobj_index]->type = VOBJ_TYPE_MWMR;
+    else if (ok && (strcmp(str, "LOCK")    == 0)) vobj[vobj_index]->type = VOBJ_TYPE_LOCK;
+    else if (ok && (strcmp(str, "BUFFER")  == 0)) vobj[vobj_index]->type = VOBJ_TYPE_BUFFER;
+    else if (ok && (strcmp(str, "BARRIER") == 0)) vobj[vobj_index]->type = VOBJ_TYPE_BARRIER;
     else
     {
@@ -449,12 +984,12 @@
     else
     {
-        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), of type: %s\n", 
-                    vspace_index, vobj_loc_index, type_str);
-            exit(1);
-        }
-        else
-            vobj[vobj_index]->init = 0;
+        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). \
+                                        All MWMR or BARRIER vobj must have a init value \n", 
+                    vspace_index, vobj_loc_index);
+            exit(1);
+        }
+        vobj[vobj_index]->init = 0;
     }
 
@@ -525,4 +1060,38 @@
     }
 
+    ////////// get clusterid and psegname attributes
+    value = getIntValue(reader,"clusterid", &ok);
+    if ( ok == 0 )
+    {
+        printf("[XML ERROR] illegal or missing <clusterid> for vseg %d\n", 
+                 vseg_loc_index);
+        exit(1);
+    }
+    str = getStringValue(reader,"psegname", &ok);
+    if ( ok == 0 )
+    {
+        printf("[XML ERROR] illegal or missing <psegname> for vseg %d\n", 
+                 vseg_loc_index);
+        exit(1);
+    }
+
+    /////////// set psegid field
+    int index = getPsegId( value, str );
+    if ( index >= 0 ) 
+    {
+#if XML_PARSER_DEBUG
+printf("      clusterid = %d\n", value);
+printf("      psegname  = %s\n", str);
+printf("      psegid    = %d\n", index);
+#endif
+        vseg[vseg_index]->psegid = index;
+    }
+    else              
+    {
+        printf("[XML ERROR] pseg not found for vseg %d / clusterid = %d / psegname = %s\n", 
+                   vseg_loc_index, value, str );
+        exit(1);
+    }  
+
     ////////// get ident attribute (optional : 0 if missing)
     value = getIntValue(reader,"ident", &ok);
@@ -537,31 +1106,4 @@
     {
         vseg[vseg_index]->ident = 0;
-    }
-
-    ////////// get psegname attribute
-    str = getStringValue(reader,"psegname", &ok);
-    if ( ok )
-    {
-        int index = getPsegId( str );
-        if ( index >= 0 ) 
-        {
-#if XML_PARSER_DEBUG
-printf("      psegname = %s\n", str);
-printf("      psegid   = %d\n", index);
-#endif
-            vseg[vseg_index]->psegid = index;
-        }
-        else              
-        {
-            printf("[XML ERROR] illegal or missing <psegname> for vseg %d\n", 
-                     vseg_loc_index);
-            exit(1);
-        }
-    }  
-    else
-    {
-        printf("[XML ERROR] illegal or missing <psegname> for vseg %d\n", 
-                 vseg_loc_index);
-        exit(1);
     }
 
@@ -594,18 +1136,14 @@
     }
     
-    ////////// set the length attribute to 0
-    vseg[vseg_index]->length = value;
-
-    ////////// get vobjs
-    int status = xmlTextReaderRead ( reader );
+    ////////// get vobjs in vseg
+    int status = xmlTextReaderRead(reader);
     while ( status == 1 ) 
     {
         const char* tag = (const char*)xmlTextReaderConstName(reader);
 
-        if      ( strcmp(tag,"vobj") == 0    ) vobjNode(reader);
+        if      ( strcmp(tag,"vobj")    == 0 ) vobjNode(reader);
         else if ( strcmp(tag,"#text"  ) == 0 ) { }
-        else if ( strcmp(tag,"vseg") == 0  ) 
-        {
-            //  checking source file consistency?
+        else if ( strcmp(tag,"vseg")    == 0 ) 
+        {
             vseg[vseg_index]->vobjs = vobj_count;
             vseg_index++;
@@ -688,20 +1226,20 @@
     }
 
-    int status = xmlTextReaderRead ( reader );
+    int status = xmlTextReaderRead(reader);
     while ( status == 1 ) 
     {
         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,"vspace") == 0  ) 
-        {
-            vspace[vspace_index]->vobjs = vobj_loc_index;
+        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,"vspace")  == 0 ) 
+        {
+            vspace[vspace_index]->vobjs = vobj_loc_index; 
             vspace[vspace_index]->tasks = task_loc_index ;
             vspace[vspace_index]->vsegs = vseg_loc_index ;
 
             // get index of the vobj containing the start vector
-            int index =  getVobjLocId( vspace_index, str );
+            int index =  getVobjLocId( vspace_index, str , vobj_loc_index );
             if(index == -1)
             {
@@ -713,6 +1251,7 @@
                 vspace[vspace_index]->start_offset = index;
 #if XML_PARSER_DEBUG
-printf("  startname = %s\n", str);
-printf("  startid   = %d\n", index);
+printf("      startname = %s\n", str);
+printf("      startid   = %d\n", index);
+printf("  end vspace %d\n\n", vspace_index);
 #endif
             }
@@ -765,8 +1304,8 @@
     pseg[pseg_index] = (mapping_pseg_t*)malloc(sizeof(mapping_pseg_t));
 
-    // get name attribute
+    /////// get name attribute
     str = getStringValue( reader, "name", &ok );
 #if XML_PARSER_DEBUG
-printf("    name = %s\n", str);
+printf("      name = %s\n", str);
 #endif
     if ( ok ) 
@@ -776,12 +1315,28 @@
     else
     {
-        printf("[XML ERROR] illegal or missing <name> for pseg %d\n", pseg_index);
-        exit(1);
-    }
-
-    // get base attribute
+        printf("[XML ERROR] illegal or missing <name> for pseg %d in cluster %d\n",
+               pseg_index, cluster_index);
+        exit(1);
+    }
+
+    //////// get type attribute
+    str = getStringValue(reader, "type", &ok);
+#if XML_PARSER_DEBUG
+printf("      type = %s\n", str);
+#endif
+    if      (ok && (strcmp(str, "RAM" ) == 0)) pseg[pseg_index]->type = PSEG_TYPE_RAM;
+    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
+    {
+        printf("[XML ERROR] illegal or missing <type> for pseg %s in cluster %d\n",
+        pseg[pseg_index]->name, cluster_index);
+        exit(1);
+    }
+
+    //////// get base attribute
     value = getIntValue( reader, "base", &ok );
 #if XML_PARSER_DEBUG
-printf("    base = %x\n", value);
+printf("      base = 0x%x\n", value);
 #endif
     if ( ok ) 
@@ -791,12 +1346,13 @@
     else
     {
-        printf("[XML ERROR] illegal or missing <base> for pseg %d\n", pseg_index);
-        exit(1);
-    }
-
-    // get length attribute
+        printf("[XML ERROR] illegal or missing <base> for pseg %s in cluster %d\n",
+        pseg[pseg_index]->name, cluster_index);
+        exit(1);
+    }
+
+    //////// get length attribute
     value = getIntValue( reader, "length", &ok );
 #if XML_PARSER_DEBUG
-printf("    length = %x\n\n", value);
+printf("      length = 0x%x\n", value);
 #endif
     if ( ok )
@@ -806,9 +1362,14 @@
     else
     {
-        printf("[XML ERROR] illegal or missing <length> for pseg %d\n", pseg_index);
-        exit(1);
-    }
+        printf("[XML ERROR] illegal or missing <length> for pseg %s in cluster %d\n",
+        pseg[pseg_index]->name, cluster_index);
+        exit(1);
+    }
+
+    //////// set cluster attribute
+    pseg[pseg_index]->cluster = cluster_index;
 
     pseg_index++;
+    cluster[cluster_index]->psegs++;
 } // end psegNode()
 
@@ -819,4 +1380,8 @@
     unsigned int value;
 
+    proc_loc_index = 0;
+    coproc_loc_index = 0;
+    cluster[cluster_index] = 0;
+
     if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return;
 
@@ -829,14 +1394,11 @@
 
 #if XML_PARSER_DEBUG
-printf("  cluster %d :\n", cluster_index);
+printf("  cluster %d\n", cluster_index);
 #endif
 
     cluster[cluster_index] = (mapping_cluster_t*)malloc(sizeof(mapping_cluster_t));
 
-    // get index attribute (optional)
+    /////////// get index attribute (optional)
     value = getIntValue(reader,"index",&ok);
-#if XML_PARSER_DEBUG
-printf("    index = %d\n", value);
-#endif
     if ( ok && (value != cluster_index) )
     {
@@ -846,21 +1408,39 @@
     }
 
-    // get procs attribute
-    value = getIntValue(reader,"procs",&ok);
-#if XML_PARSER_DEBUG
-printf("    procs = %d\n", value);
-#endif
-    if ( ok )
-    {
-        cluster[cluster_index]->procs = value;
-    }
-    else
-    {
-        printf("[XML ERROR] illegal or missing <procs> attribute for cluster %d", 
-                cluster_index);
-        exit(1);
-    }
-
-    cluster_index++;
+
+    ////////// set pseg_offset attribute
+    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);
+printf("    coproc_offset = %d\n", coproc_index);
+#endif
+
+    ////////// get psegs, coproc and/or procs
+    int status = xmlTextReaderRead(reader);
+
+    while ( status == 1 )
+    {
+        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, "cluster") == 0 ) 
+        {
+#if XML_PARSER_DEBUG
+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;
+        }
+        status = xmlTextReaderRead(reader);
+    }
 } // end clusterNode()
 
@@ -874,5 +1454,5 @@
 #endif
 
-    int status = xmlTextReaderRead ( reader );
+    int status = xmlTextReaderRead(reader);
     while ( status == 1 ) 
     {
@@ -891,4 +1471,13 @@
             else
             {
+#if XML_PARSER_DEBUG
+printf("  end cluster set\n\n");
+#endif
+                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;
             }
@@ -899,45 +1488,7 @@
             exit(1);
         }
-        status = xmlTextReaderRead ( reader );
+        status = xmlTextReaderRead(reader);
     }
 } // end clusterSetNode()
-
-///////////////////////////////////////////
-void psegSetNode( xmlTextReaderPtr reader )
-{
-    if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return;
-
-#if XML_PARSER_DEBUG
-printf("  psegs set\n");
-#endif
-
-    int status = xmlTextReaderRead ( reader );
-    while ( status == 1 ) 
-    {
-        const char* tag = (const char*)xmlTextReaderConstName(reader);
-
-        if      ( strcmp(tag,"pseg") == 0    ) psegNode(reader);
-        else if ( strcmp(tag,"#text") == 0 ) { }
-        else if ( strcmp(tag,"psegset") == 0  ) 
-        {
-            // checking source file consistency
-            if ( pseg_index != header->psegs )
-            {
-                printf("[XML ERROR] Wrong number of psegs\n");
-                exit(1);
-            }
-            else
-            {
-                return;
-            }
-        }
-        else 
-        {
-            printf("[XML ERROR] Unknown tag in psegset node : %s",tag);
-            exit(1);
-        }
-        status = xmlTextReaderRead ( reader );
-    }
-} // end psegSetNode()
 
 /////////////////////////////////////////////
@@ -950,5 +1501,5 @@
 #endif
 
-    int status = xmlTextReaderRead ( reader );
+    int status = xmlTextReaderRead(reader);
     while ( status == 1 ) 
     {
@@ -967,4 +1518,7 @@
             else
             {
+#if XML_PARSER_DEBUG
+printf("  end global set\n\n");
+#endif
                 vseg_loc_index = 0;
                 return;
@@ -1071,24 +1625,4 @@
     }
 
-    ////////// get psegs attribute
-    value = getIntValue(reader, "psegs", &ok);
-    if ( ok )
-    {
-        if ( value >= MAX_PSEGS )
-        {
-            printf("[XML ERROR] The number of psegs is larger than %d\n", MAX_PSEGS);
-            exit(1);
-        }
-#if XML_PARSER_DEBUG
-printf("  psegs = %d\n", value);
-#endif
-	header->psegs = value;
-    }
-    else
-    {
-        printf("[XML ERROR] illegal or missing <psegs> attribute in header\n");
-        exit(1);
-    }
-
     ///////// get ttys attribute
     value = getIntValue(reader, "ttys", &ok);
@@ -1163,5 +1697,5 @@
     header->signature = IN_MAPPING_SIGNATURE;
 
-    int status = xmlTextReaderRead ( reader );
+    int status = xmlTextReaderRead(reader);
     while ( status == 1 ) 
     {
@@ -1169,6 +1703,5 @@
 
         if      ( strcmp(tag,"clusterset")   == 0 ) clusterSetNode(reader);
-        else if ( strcmp(tag,"psegset")      == 0 ) psegSetNode(reader);
-        else if ( strcmp(tag,"globalset")   == 0 ) globalSetNode(reader);
+        else if ( strcmp(tag,"globalset")    == 0 ) globalSetNode(reader);
         else if ( strcmp(tag,"vspaceset")    == 0 ) vspaceSetNode(reader);
         else if ( strcmp(tag,"#text")        == 0 ) { }
@@ -1185,18 +1718,39 @@
             exit(1);
         }
-        status = xmlTextReaderRead ( reader );
+        status = xmlTextReaderRead(reader);
     }
 } // end headerNode()
+    
+void BuildTable( int fdout,
+               const char* type,
+               unsigned int nb_elem,
+               unsigned int elem_size,
+               char** table)        
+{
+    unsigned int i;
+    unsigned int length;
+    // write element
+    for ( i = 0 ; i < nb_elem ; i++ )
+    {
+        length = write(fdout, table[i], elem_size);
+    
+#if XML_PARSER_DEBUG
+printf("Building binary: writing %s %d\n", type, i);
+#endif
+
+        if ( length != elem_size )
+        {
+            printf("type: %s\n", type);
+            perror("error writing");
+            exit(1);
+        }
+    }
+}
 
 ///////////////////////////
 void  buildBin( int fdout )
 {
-    unsigned int    cluster_id;
-    unsigned int    pseg_id;
     unsigned int    vspace_id;
-    unsigned int    vseg_id;
     unsigned int    vobj_id;
-    unsigned int    task_id;
-
     unsigned int    length;
 
@@ -1210,39 +1764,13 @@
     if ( length != sizeof(mapping_header_t) )
     {
-        perror("write header");
+        printf("write header error : length = %d \n", length);
         exit(1);
     }
 
     // write clusters
-    for ( cluster_id = 0 ; cluster_id < header->clusters ; cluster_id++ )
-    {
-        length = write(fdout, (char*)cluster[cluster_id], sizeof(mapping_cluster_t));
-    
-#if XML_PARSER_DEBUG
-printf("\n*** write cluster %d\n", cluster_id);
-#endif
-
-        if ( length != sizeof(mapping_cluster_t) )
-        {
-            perror("write cluster");
-            exit(1);
-        }
-    }
+    BuildTable(fdout, "cluster", cluster_index, sizeof(mapping_cluster_t), (char**) cluster);
 
     // write psegs
-    for ( pseg_id = 0 ; pseg_id < header->psegs ; pseg_id++ )
-    {
-        length = write(fdout, (char*)pseg[pseg_id], sizeof(mapping_pseg_t));
-    
-#if XML_PARSER_DEBUG
-printf("write pseg %d\n", pseg_id);
-#endif
-
-        if ( length != sizeof(mapping_pseg_t) )
-        {
-            perror("write pseg");
-            exit(1);
-        }
-    }
+    BuildTable(fdout, "pseg", pseg_index, sizeof(mapping_pseg_t), (char**) pseg);
 
     // write vspaces
@@ -1266,18 +1794,5 @@
 
     // write vsegs
-    for ( vseg_id = 0 ; vseg_id < header->vsegs ; vseg_id++ )
-    {
-        length = write(fdout, (char*)vseg[vseg_id], sizeof(mapping_vseg_t));
-    
-#if XML_PARSER_DEBUG
-printf("write vseg %d\n", vseg_id);
-#endif
-
-        if ( length != sizeof(mapping_vseg_t) )
-        {
-            perror("write vseg");
-            exit(1);
-        }
-    }
+    BuildTable(fdout, "vseg", vseg_index, sizeof(mapping_vseg_t), (char**) vseg);
     
     // write vobjs
@@ -1301,19 +1816,57 @@
 
     // write tasks
-    for ( task_id = 0 ; task_id < header->tasks ; task_id++ )
-    {
-        length = write(fdout, (char*)task[task_id], sizeof(mapping_task_t));
-    
-#if XML_PARSER_DEBUG
-printf("write task %d\n", task_id);
-#endif
-
-        if ( length != sizeof(mapping_task_t) )
-        {
-            perror("write task");
-            exit(1);
-        }
-    }
+    BuildTable(fdout, "task", task_index, sizeof(mapping_task_t), (char**) task);
+    //building proc
+    BuildTable(fdout, "proc", proc_index, sizeof(mapping_proc_t), (char**) proc);
+    //building irq
+    BuildTable(fdout, "irq", irq_index, sizeof(mapping_irq_t), (char**)irq);
+    //building coproc
+    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);
+
 } // end buildBin()
+
+/////////////////////////////////////////
+// this function set the value of vobj_id 
+// of the coproc_ports.
+///////////////////
+void prepareBuild()
+{
+    unsigned int i;
+    for(i=0; i< cp_port_index; i++)
+    {
+        int vspace_id = getVspaceId( cp_port_vobj_ref[i]->vspace_name );
+        if ( vspace_id < 0 ) 
+        {
+            printf("[XML ERROR] illegal  <vspacename> for coproc_port %d,\n", 
+                    i);
+            exit(1);
+        }
+        cp_port[i]->vspaceid = vspace_id;
+        
+        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);
+printf("      vspace_name  = %s\n", cp_port_vobj_ref[i]->vspace_name);
+printf("      vobj_name    = %s\n", cp_port_vobj_ref[i]->vobj_name);
+printf("      vobj_index   = %d\n", vobj_id);
+#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");
+        }
+        else              
+        {
+            printf("[XML ERROR] illegal  <vobjname> for coproc_port %d,\n", 
+                    i);
+            exit(1);
+        }
+        
+    }
+}
 
 /////////////////////////////////////
@@ -1335,5 +1888,5 @@
     LIBXML_TEST_VERSION;
 
-    int              status;
+    int status;
     xmlTextReaderPtr reader = xmlReaderForFile ( argv[1], NULL, 0 );
 
@@ -1344,7 +1897,9 @@
         {
             const char* tag = (const char*)xmlTextReaderConstName(reader);
+
             if ( strcmp(tag,"mapping_info") == 0 )
             { 
                 headerNode( reader );
+                prepareBuild();
                 buildBin( fdout );
             }
