source: soft/giet_vm/xml/xml_parser.c @ 253

Last change on this file since 253 was 253, checked in by alain, 11 years ago

1/ introducing support to display images on the frame buffer
with the vci_chbuf_dma (in stdio.c and drivers.c)
2/ introducing support for mem_cache configuration segment
as the memory cache is considered as another addressable peripheral type
(in drivers.c)
3/ Introducing the new "increment" parameter in the mapping header.
This parameter define the virtual address increment for the vsegs
associated to the replicated peripherals (ICU, XICU, MDMA, TIMER, MMC).
This parameter is mandatory, and all map.xml files the "mappings"
directory have been updated.

File size: 75.1 KB
RevLine 
[158]1///////////////////////////////////////////////////////////////////////////////////////
2// File     : xml_parser.c
[181]3// Date     : 14/04/2012
[158]4// Author   : alain greiner
5// Copyright (c) UPMC-LIP6
6///////////////////////////////////////////////////////////////////////////////////////
[217]7// This program translate a "map.xml" source file to a binary file "map.bin" that
[253]8// can be directly loaded in memory and used by the GIET-VM operating system.
[217]9//
10// This map.xml file contains :
11// 1) the multi-cluster/multi-processors hardware architecture description
12// 2) the various multi-threaded software applications
13// 3) the mapping directives bor both the tasks and the virtual segments.
14// The corresponding C structures are defined in the "mapping_info.h" file.
15//
[253]16// This parser also generates the "hard_config.h" and the "giet_vsegs.ld" files,
[217]17// required  to compile the GIET-VM code.
[158]18///////////////////////////////////////////////////////////////////////////////////////
19
20#include  <stdlib.h>
21#include  <fcntl.h>
[162]22#include  <sys/types.h>
23#include  <sys/stat.h>
[158]24#include  <unistd.h>
25#include  <stdio.h>
26#include  <string.h>
[181]27#include  <assert.h>
[158]28#include  <libxml/xmlreader.h>
29#include  <mapping_info.h>
[189]30#include  <irq_handler.h>
[158]31
[228]32#define MAX_CLUSTERS   1024
33#define MAX_PSEGS      4096
34#define MAX_VSPACES    1024
35#define MAX_TASKS      4096
36#define MAX_MWMRS      4096
37#define MAX_VSEGS      4096
38#define MAX_VOBJS      8192
39#define MAX_PROCS      1024
40#define MAX_IRQS       8192
41#define MAX_COPROCS    4096
42#define MAX_CP_PORTS   8192
43#define MAX_PERIPHS    8192
[158]44
[228]45#define XML_PARSER_DEBUG  0
[158]46
47///////////////////////////////////////////////////////////////////////////////////
[228]48//     global variables used to store and index the data structures
[158]49///////////////////////////////////////////////////////////////////////////////////
50
[238]51mapping_header_t *   header;
52mapping_cluster_t *  cluster[MAX_CLUSTERS];  // cluster array
53mapping_pseg_t *     pseg[MAX_PSEGS];        // pseg array
54mapping_vspace_t *   vspace[MAX_VSPACES];    // vspace array
55mapping_vseg_t *     vseg[MAX_VSEGS];        // vseg array
56mapping_vobj_t *     vobj[MAX_VOBJS];        // vobj array
57mapping_task_t *     task[MAX_TASKS];        // task array
58mapping_proc_t *     proc[MAX_PROCS];        // proc array
59mapping_irq_t *      irq[MAX_IRQS];          // irq array
60mapping_coproc_t *   coproc[MAX_COPROCS];    // coproc array
61mapping_cp_port_t *  cp_port[MAX_CP_PORTS];  // coproc port array
62mapping_periph_t *   periph[MAX_PERIPHS];    // peripheral array
[158]63
[189]64// Index for the various arrays
[181]65
[228]66unsigned int cluster_index  = 0;
67unsigned int vspace_index = 0;
68unsigned int global_index = 0;
69unsigned int pseg_index = 0;       
[181]70
[228]71unsigned int proc_index = 0;
72unsigned int proc_loc_index = 0;
[181]73
[228]74unsigned int irq_index = 0;
75unsigned int irq_loc_index  = 0;
[181]76
[228]77unsigned int coproc_index = 0;
78unsigned int coproc_loc_index = 0;
[181]79
[228]80unsigned int cp_port_index = 0;
81unsigned int cp_port_loc_index = 0;
[181]82
[228]83unsigned int periph_index = 0;
84unsigned int periph_loc_index = 0;
[181]85
[228]86unsigned int vseg_index = 0;
87unsigned int vseg_loc_index = 0;
[189]88
[228]89unsigned int task_index = 0;
90unsigned int task_loc_index = 0;
[189]91
[228]92unsigned int vobj_index = 0;
93unsigned int vobj_loc_index = 0;
94unsigned int vobj_count = 0;
[165]95
[215]96
[238]97//////////////////////////////
98// for replicated peripheral
99//////////////////////////////
[215]100char found_timer = 0;
[249]101char found_icu   = 0;
[253]102char found_xcu   = 0;
[249]103char found_dma   = 0;
104char found_mmc   = 0;
[215]105
106
[238]107////////////////////////////////////////////////////////////////////
108// These variables are used to generate the hard_config.h file
109////////////////////////////////////////////////////////////////////
[232]110
[238]111unsigned int cluster_y        = 0; // number of clusters in a column
112unsigned int cluster_x        = 0; // number of clusters in a row
113unsigned int nb_proc_max      = 0; // max number of processors per cluster
114unsigned int nb_tasks_max     = 0; // max number of tasks (for all vspaces)
[215]115
[238]116unsigned int tim_channels     = 0; // max number of user timers per cluster
117unsigned int dma_channels     = 0; // max number of DMA channels per cluster
[215]118
[238]119unsigned int tty_channels     = 0; // total number of terminals in first TTY
120unsigned int ioc_channels     = 0; // total number of channels in first IOC
121unsigned int nic_channels     = 0; // total number of channels in first NIC
122unsigned int cma_channels     = 0; // total number of channels in first CMA
[215]123
[249]124unsigned int use_iob          = 0; // using IOB component
[253]125unsigned int use_xcu          = 0; // using XCU (not ICU)
[215]126
127
[238]128////////////////////////////////////////////////////////////////
129// These variables are used to generate the giet_vseg.ld file
130////////////////////////////////////////////////////////////////
[215]131
[238]132unsigned int periph_vbase_array[PERIPH_TYPE_MAX_VALUE] 
[253]133         = { [0 ... (PERIPH_TYPE_MAX_VALUE - 1)] = 0xFFF00000 };
[215]134
135//////////////////////////////////////////////////////////////////////
[189]136// This arrray is useful to build a temporary list of vobj references.
137// The struct vobj_ref_s is formed by a vspace_name and a vobj_name.
138// This array is used to set the attribute vobj_id of a cp_port
139// once all the vspace have been parsed.
[215]140/////////////////////////////////////////////////////////////////////
[238]141typedef struct vobj_ref_s
142{
[189]143    char vspace_name[32];
144    char vobj_name[32];
[228]145} vobj_ref_t;
[189]146
[228]147vobj_ref_t * cp_port_vobj_ref[MAX_CP_PORTS];   
[189]148
149
[158]150//////////////////////////////////////////////////
[238]151unsigned int getIntValue( xmlTextReaderPtr reader, 
152                          const char * attributeName, 
153                          unsigned int * ok) 
154{
[228]155    unsigned int value = 0;
156    unsigned int i;
157    char c;
[158]158
[238]159    char * string = (char *) xmlTextReaderGetAttribute(reader, 
160                                (const xmlChar *) attributeName);
[158]161
[238]162    if (string == NULL) 
163    {
[228]164        // missing argument
[158]165        *ok = 0;
166        return 0;
167    }
[238]168    else 
169    {
170        if ((string[0] == '0') && ((string[1] == 'x') || (string[1] == 'X'))) 
171        {
[228]172            // Hexa
[238]173            for (i = 2 ; (string[i] != 0) && (i < 10) ; i++) 
174            {
[158]175                c = string[i];
[228]176                if      ((c >= '0') && (c <= '9')) { value = (value << 4) + string[i] - 48; }
177                else if ((c >= 'a') && (c <= 'f')) { value = (value << 4) + string[i] - 87; }
178                else if ((c >= 'A') && (c <= 'F')) { value = (value << 4) + string[i] - 55; }
[238]179                else 
180                {
[158]181                    *ok = 0;
182                    return 0;
183                }
184            }
185        }
[238]186        else 
187        {
[228]188            // Decimal
[238]189            for (i = 0; (string[i] != 0) && (i < 9); i++) 
190            {
[158]191                c = string[i];
[228]192                if ((c >= '0') && (c <= '9')) value = (value * 10) + string[i] - 48;
[238]193                else 
194                {
[158]195                    *ok = 0;
196                    return 0;
197                }
198            }
199        }
200        *ok = 1;
201        return value; 
202    }
203} // end getIntValue()
204
[238]205////////////////////////////////////////////////
206paddr_t getPaddrValue( xmlTextReaderPtr reader, 
207                       const char * attributeName, 
208                       unsigned int * ok) 
209{
210    paddr_t value = 0;
211    unsigned int i;
212    char c;
[228]213
[238]214    char * string = (char *) xmlTextReaderGetAttribute(reader, 
215                                (const xmlChar *) attributeName);
[158]216
[238]217    if (string == NULL) 
218    {
219        // missing argument
220        *ok = 0;
221        return 0;
222    }
223    else 
224    {
225        if ((string[0] == '0') && ((string[1] == 'x') || (string[1] == 'X'))) 
226        {
227            // Hexa
228            for (i = 2 ; (string[i] != 0) && (i < 18) ; i++) 
229            {
230                c = string[i];
231                if      ((c >= '0') && (c <= '9')) { value = (value << 4) + string[i] - 48; }
232                else if ((c >= 'a') && (c <= 'f')) { value = (value << 4) + string[i] - 87; }
233                else if ((c >= 'A') && (c <= 'F')) { value = (value << 4) + string[i] - 55; }
234                else 
235                {
236                    *ok = 0;
237                    return 0;
238                }
239            }
240        }
241        else 
242        {
243            // Decimal not supported for paddr_t
244            *ok = 0;
245            return 0;
246        }
247        *ok = 1;
248        return value; 
249    }
250} // end getPaddrValue()
[228]251
[238]252////////////////////////////////////////////////
253char * getStringValue( xmlTextReaderPtr reader, 
254                       const char * attributeName, 
255                       unsigned int * ok ) 
256{
257    char * string = (char *) xmlTextReaderGetAttribute(reader, 
258                               (const xmlChar *) attributeName);
259
260
261    if (string == NULL) 
262    {
[228]263        // missing argument
[158]264        *ok = 0;
265        return NULL;
266    }
[238]267    else 
268    {
[215]269        //we read only string smaller than 32 byte
[238]270        if (strlen(string) > 32) 
271        {
[215]272            printf("[XML ERROR] all strings must be less than 32 bytes\n");
273            exit(1);
274        }
275
[158]276        *ok = 1;
277        return string;
278    }
279} // end getStringValue()
280
[253]281///////////////////////////////////////////////////////////////////////////////////
282// This function set the vbase address for all peripheral types.
283// For replicated peripherals with the same type the virtual base address must be:
284//   vbase = seg_type_base & 0XFFF00000 +
285//          (cluster_id * vbase_cluster_increment) & 0x000FFFFF
286void set_periph_vbase_array()
[238]287{
[253]288    unsigned int vseg_id;      // vseg global index
289    unsigned int periph_id;    // periph global index
290    unsigned int pseg_id;      // pseg global index
291    unsigned int cluster_id;   // cluster global index
292    unsigned int type;         // peripheral type
[228]293
[253]294    unsigned int msb_mask = 0xFFF00000;
295    unsigned int lsb_mask = 0x000FFFFF;
296
297    // We are looking for any vseg matching a peripheral
298    // (i.e. they are associated to the same pseg)
299
300    // scan all vsegs
301    for (vseg_id = 0 ; vseg_id < header->vsegs ; vseg_id++)
[238]302    {
[253]303        // keep only vseg corresponding to a periph       
304        if ( vobj[vseg[vseg_id]->vobj_offset]->type == VOBJ_TYPE_PERI )
[238]305        {
[253]306            pseg_id = vseg[vseg_id]->psegid; 
307            cluster_id = pseg[pseg_id]->cluster;
308
309            // scan all periphs
310            for ( periph_id = 0 ; periph_id < header->periphs ; periph_id++)
311            {
312                if( periph[periph_id]->psegid == pseg_id ) // matching !!!
313                {
314                    type = periph[periph_id]->type;
315                    if ( periph_vbase_array[type] == 0xFFF00000 )  // vbase not set
316                    {
317                        periph_vbase_array[type] = vseg[vseg_id]->vbase;   
318                    }
319                    else                                 // vbase already set
320                    {
321                        // checking 12 MSB bits for replicated peripherals
322                        if( (vseg[vseg_id]->vbase & msb_mask) != 
323                            (periph_vbase_array[type] & msb_mask) )
324                        {
325                            printf("[XML ERROR] All peripherals with same type ");
326                            printf(" should share the same 12 MSB for vbase address\n");
327                            printf("periph index = %d / periph type = %d / vbase = %x\n",
328                                    periph_id, type, vseg[vseg_id]->vbase);
329                            exit(1);
330                        }
331                        // checking 20 LSB bits for replicated peripherals
332                        if( (vseg[vseg_id]->vbase & lsb_mask) != 
333                            (header->increment * cluster_id) )
334                        {
335                            printf("[XML ERROR] All peripherals with same type ");
336                            printf(" must have the 20 LSB bits = cluster_id * increment");
337                            printf("periph index = %d / periph type = %d / vbase = %x\n",
338                                    periph_id, type, vseg[vseg_id]->vbase);
339                            exit(1);
340                        }
341                    }
342                }
343            }
344        }   
[238]345    }
346}  // end set_periph_vbase_array()
347
348////////////////////////////////////////////////////////
349int getPsegId(unsigned int cluster_id, char * pseg_name) 
350{
[158]351    unsigned int pseg_id;
[181]352    unsigned int pseg_min = cluster[cluster_id]->pseg_offset;
353    unsigned int pseg_max = pseg_min + cluster[cluster_id]->psegs;
[158]354
[238]355    for (pseg_id = pseg_min; pseg_id < pseg_max; pseg_id++) 
356    {
357        if (strcmp(pseg[pseg_id]->name, pseg_name) == 0) 
358        {
[215]359            return pseg_id;
360        }
[158]361    }
362    return -1;
363}
364
[238]365///////////////////////////////////
366int getVspaceId(char * vspace_name) 
367{
[181]368    unsigned int vspace_id;
369
[238]370    for (vspace_id = 0; vspace_id < vspace_index; vspace_id++) 
371    {
372        if (strcmp(vspace[vspace_id]->name, vspace_name) == 0) 
373        {
[181]374            return vspace_id;
375        }
376    }
377    return -1;
378}
379
[238]380///////////////////////////////////////////////////////////////////////////////////
381int getVobjLocId(unsigned int vspace_id, char * vobj_name, unsigned int vspace_max) 
382{
[160]383    unsigned int vobj_id;
384    unsigned int vobj_min = vspace[vspace_id]->vobj_offset;
[181]385    unsigned int vobj_max = vobj_min + vspace_max;
[158]386
[253]387    for (vobj_id = vobj_min; vobj_id < vobj_max; vobj_id++) 
388    {
389        if (strcmp(vobj[vobj_id]->name, vobj_name) == 0) return (vobj_id - vobj_min);
[158]390    }
391    return -1;
392}
393
[253]394//////////////////////////////////////
[238]395void taskNode(xmlTextReaderPtr reader) 
396{
[228]397    unsigned int ok;
398    unsigned int value;
399    char * str;
[181]400
[253]401    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return;
[181]402
[238]403    if (task_index >= MAX_TASKS) 
404    {
[158]405        printf("[XML ERROR] The number of tasks is larger than %d\n", MAX_TASKS);
[253]406        exit(1);
[158]407    }
408
409#if XML_PARSER_DEBUG
[238]410printf("   task %d\n", task_loc_index);
[158]411#endif
412
[228]413    task[task_index] = (mapping_task_t *) malloc(sizeof(mapping_task_t));
[158]414
415    ////////// get name attribute
416    str = getStringValue(reader, "name", &ok);
[238]417    if (ok) 
418    {
[158]419#if XML_PARSER_DEBUG
[238]420printf("      name = %s\n", str);
[158]421#endif
422        strncpy( task[task_index]->name, str, 31 );
423    }
[238]424    else 
425    {
[158]426        printf("[XML ERROR] illegal or missing <name> attribute for task (%d,%d)\n", 
[228]427                vspace_index, task_loc_index);
[158]428        exit(1);
429    }
430
431    ///////// get clusterid attribute
[228]432    value = getIntValue(reader, "clusterid", &ok);
[238]433    if (ok) 
434    {
[158]435#if XML_PARSER_DEBUG
[238]436printf("      clusterid = %x\n", value);
[158]437#endif
[238]438        if (value >= header->clusters) 
439        {
[165]440            printf("[XML ERROR] <clusterid> too large for task (%d,%d)\n",
[228]441                    vspace_index, task_loc_index);
[165]442            exit(1);
443        }
[158]444        task[task_index]->clusterid = value;
445    } 
[238]446    else 
447    {
[158]448        printf("[XML ERROR] illegal or missing <clusterid> attribute for task (%d,%d)\n",
[228]449                vspace_index, task_loc_index);
[158]450        exit(1);
451    }
452
453    ////////// get proclocid attribute
[228]454    value = getIntValue(reader, "proclocid", &ok);
[238]455    if (ok) 
456    {
[158]457#if XML_PARSER_DEBUG
[238]458printf("      proclocid = %x\n", value);
[158]459#endif
[238]460        if (value >= cluster[task[task_index]->clusterid]->procs) 
461        {
[165]462            printf("[XML ERROR] <proclocid> too large for task (%d,%d)\n",
[228]463                    vspace_index, task_loc_index);
[165]464            exit(1);
465        }
[158]466        task[task_index]->proclocid = value;
467    } 
[238]468    else 
469    {
[158]470        printf("[XML ERROR] illegal or missing <locprocid> attribute for task (%d,%d)\n", 
471                vspace_index, task_loc_index);
472        exit(1);
473    }
474
475    ////////// get stackname attribute
476    str = getStringValue(reader, "stackname" , &ok);
[238]477    if (ok) 
478    {
[228]479        int index = getVobjLocId(vspace_index, str , vobj_loc_index);
[238]480        if (index >= 0) 
481        {
[158]482#if XML_PARSER_DEBUG
[238]483printf("      stackname = %s\n", str);
484printf("      stackid   = %d\n", index);
[158]485#endif
[232]486            task[task_index]->stack_vobjid = index;
[158]487        }
[238]488        else 
489        {
[165]490            printf("[XML ERROR] illegal or missing <stackname> for task (%d,%d)\n", 
491                    vspace_index, task_loc_index);
[158]492            exit(1);
493        }
494    } 
[238]495    else 
496    {
[165]497        printf("[XML ERROR] illegal or missing <stackname> for task (%d,%d)\n", 
[158]498                vspace_index, task_loc_index);
499        exit(1);
500    }
501
[232]502    ////////// get heap attribute
503    str = getStringValue(reader, "heapname", &ok);
[238]504    if (ok) 
505    {
[232]506        int index = getVobjLocId(vspace_index, str, vobj_loc_index);
[238]507        if (index >= 0) 
508        {
[232]509#if XML_PARSER_DEBUG
[238]510printf("      heapname = %s\n", str);
511printf("      heapid   = %d\n", index);
[232]512#endif
513            task[task_index]->heap_vobjid = index;
514        }
[238]515        else 
516        {
517            printf("[XML ERROR] illegal or missing <heapname> for task (%d,%d)\n", 
518                   vspace_index, task_loc_index);
[232]519            exit(1);
520        }
521    } 
[238]522    else 
523    {
[232]524        task[task_index]->heap_vobjid = -1;
525    }
526
527
[158]528    ////////// get startid  attribute
[228]529    value = getIntValue(reader, "startid", &ok);
[238]530    if (ok) 
531    {
[158]532#if XML_PARSER_DEBUG
[238]533printf("      startid = %x\n", value);
[158]534#endif
535        task[task_index]->startid = value;
536    } 
[238]537    else 
538    {
[158]539        printf("[XML ERROR] illegal or missing <startid> attribute for task (%d,%d)\n", 
540                vspace_index, task_loc_index);
541        exit(1);
542    }
543
[189]544    /////////// get usetty  attribute (optionnal : 0 if missing)
[228]545    value = getIntValue(reader, "usetty", &ok);
[158]546#if XML_PARSER_DEBUG
[238]547printf("      usetty = %x\n", value);
[158]548#endif
[238]549    task[task_index]->use_tty = (ok)? value : 0;
[165]550
[189]551    /////////// get usenic  attribute (optionnal : 0 if missing)
[228]552    value = getIntValue(reader, "usenic", &ok);
[165]553#if XML_PARSER_DEBUG
[238]554printf("      usenic = %x\n", value);
[165]555#endif
[238]556    task[task_index]->use_nic = (ok)? value : 0;
[158]557
[238]558    /////////// get usetim attribute (optionnal : 0 if missing)
559    value = getIntValue(reader, "usetim", &ok);
[189]560#if XML_PARSER_DEBUG
[238]561printf("      usetim = %x\n", value);
[189]562#endif
[238]563    task[task_index]->use_tim = (ok)? value : 0;
[189]564
[238]565    /////////// get usedma  attribute (optionnal : 0 if missing)
566    value = getIntValue(reader, "usedma", &ok);
[189]567#if XML_PARSER_DEBUG
[238]568printf("      usedma = %x\n", value);
[189]569#endif
[238]570    task[task_index]->use_dma = (ok)? value : 0;
[189]571
[238]572    /////////// get useioc  attribute (optionnal : 0 if missing)
573    value = getIntValue(reader, "useioc", &ok);
574#if XML_PARSER_DEBUG
575printf("      useioc = %x\n", value);
576#endif
577    task[task_index]->use_ioc = (ok)? value : 0;
578
579    /////////// get usecma  attribute (optionnal : 0 if missing)
580    value = getIntValue(reader, "usecma", &ok);
581#if XML_PARSER_DEBUG
582printf("      usecma = %x\n", value);
583#endif
584    task[task_index]->use_cma = (ok)? value : 0;
585
[158]586    task_index++;
587    task_loc_index++;
588} // end taskNode()
589
[238]590//////////////////////////////////////
591void vobjNode(xmlTextReaderPtr reader) 
592{
[228]593    unsigned int ok;
594    unsigned int value;
595    char * str;
[160]596
[253]597    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return;
[160]598
[238]599    if (vobj_index >= MAX_VOBJS) 
600    {
601        printf("[XML ERROR] The number of vobjs is larger than %d\n", MAX_VOBJS);
[160]602        exit(1);
603    }
604
605#if XML_PARSER_DEBUG
[238]606printf("      vobj %d\n", vobj_loc_index);
[160]607#endif
608
[228]609    vobj[vobj_index] = (mapping_vobj_t *) malloc(sizeof(mapping_vobj_t));
[160]610
611    ///////// get name attribute
612    str = getStringValue(reader, "name", &ok);
[238]613    if (ok) 
614    {
[160]615#if XML_PARSER_DEBUG
[238]616printf("        name = %s\n", str);
[160]617#endif
[228]618        strncpy(vobj[vobj_index]->name, str, 31);
[160]619    }
[238]620    else 
621    {
[160]622        printf("[XML ERROR] illegal or missing <name> attribute for vobj (%d,%d)\n", 
623                vseg_index, vobj_loc_index);
624        exit(1);
625    }
626
[165]627    //////// get type attribute
[182]628    str = getStringValue(reader, "type", &ok);
[160]629#if XML_PARSER_DEBUG
[238]630printf("        type = %s\n", str);
[160]631#endif
[165]632
[253]633    if      (ok && (strcmp(str, "ELF")      == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_ELF;      }
634    else if (ok && (strcmp(str, "PERI")     == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_PERI;     }
[238]635    else if (ok && (strcmp(str, "BLOB")     == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_BLOB;     }
636    else if (ok && (strcmp(str, "PTAB")     == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_PTAB;     }
637    else if (ok && (strcmp(str, "MWMR")     == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_MWMR;     }
638    else if (ok && (strcmp(str, "LOCK")     == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_LOCK;     }
639    else if (ok && (strcmp(str, "BUFFER")   == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_BUFFER;   }
640    else if (ok && (strcmp(str, "BARRIER")  == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_BARRIER;  }
641    else if (ok && (strcmp(str, "CONST")    == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_CONST;    }
[228]642    else if (ok && (strcmp(str, "MEMSPACE") == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_MEMSPACE; }
[238]643    else if (ok && (strcmp(str, "SCHED")    == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_SCHED;    }
644    else 
645    {
[160]646        printf("[XML ERROR] illegal or missing <type> attribute for vobj (%d,%d)\n", 
[165]647                vspace_index, vobj_loc_index);
[160]648        exit(1);
649    }
[253]650    // some more checking
651    if ( (vobj[vobj_index]->type == VOBJ_TYPE_ELF) ||
652         (vobj[vobj_index]->type == VOBJ_TYPE_PERI) )
653    {
654        assert( (vobj_count == 0) && 
655        "[XML ERROR] an ELF or PERI vobj must be alone in a vseg");
656    }
657       
[160]658
[165]659    ////////// get length attribute
[228]660    value = getIntValue(reader, "length", &ok);
661    if (ok) {
[160]662#if XML_PARSER_DEBUG
[238]663printf("        length = %d\n", value);
[160]664#endif
665        vobj[vobj_index]->length = value;
666    } 
[228]667    else {
[165]668        printf("[XML ERROR] illegal or missing <length> attribute for vobj (%d,%d)\n", 
669                vspace_index, vobj_loc_index);
670        exit(1);
[160]671    }
672
[165]673    ////////// get align attribute (optional : 0 if missing)
[228]674    value = getIntValue(reader, "align", &ok);
675    if (ok) {
[160]676#if XML_PARSER_DEBUG
[238]677printf("        align = %d\n", value);
[160]678#endif
679        vobj[vobj_index]->align = value;
680    } 
[228]681    else {
[160]682        vobj[vobj_index]->align = 0;
683    }
684
[165]685    ////////// get binpath attribute (optional : '\0' if missing)
[160]686    str = getStringValue(reader, "binpath", &ok);
[228]687    if (ok) {
[160]688#if XML_PARSER_DEBUG
[238]689printf("        binpath = %s\n", str);
[160]690#endif
691        strncpy(vobj[vobj_index]->binpath, str, 63);
692    } 
[228]693    else {
[160]694        vobj[vobj_index]->binpath[0] = '\0';
695    }
[228]696
[175]697    ////////// get init attribute (mandatory for mwmr and barrier)
[228]698    value = getIntValue(reader, "init", &ok);
[238]699    if (ok) 
700    {
[165]701#if XML_PARSER_DEBUG
[238]702printf("        init  = %d\n", value);
[165]703#endif
704        vobj[vobj_index]->init = value;
705    } 
[238]706    else 
707    {
[228]708        if ((vobj[vobj_index]->type == VOBJ_TYPE_MWMR) || 
[238]709            (vobj[vobj_index]->type == VOBJ_TYPE_BARRIER) ||
710            (vobj[vobj_index]->type == VOBJ_TYPE_CONST)) 
711        {
[181]712            printf("[XML ERROR] illegal or missing <value> attribute for vobj (%d,%d). \
[238]713                    All MWMR or BARRIER or CONST vobj must have a init value \n", 
[181]714                    vspace_index, vobj_loc_index);
[175]715            exit(1);
716        }
[181]717        vobj[vobj_index]->init = 0;
[165]718    }
719
[160]720    vobj_index++;
[165]721    vobj_count++;
[160]722    vobj_loc_index++;
[165]723} // end vobjNode()
[160]724
[238]725//////////////////////////////////////
726void vsegNode(xmlTextReaderPtr reader) 
727{
[228]728    unsigned int ok;
729    unsigned int value;
730    char * str;
[158]731
[228]732    vobj_count = 0;
[165]733
[253]734    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return;
[158]735
[238]736    if (vseg_index >= MAX_VSEGS) 
737    {
[158]738        printf("[XML ERROR] The number of vsegs is larger than %d\n", MAX_VSEGS);
739        exit(1);
740    }
741
742#if XML_PARSER_DEBUG
[238]743printf("    vseg %d\n", vseg_loc_index);
[158]744#endif
745
[228]746    vseg[vseg_index] = (mapping_vseg_t *) malloc(sizeof(mapping_vseg_t));
747
[160]748    ////////// set vobj_offset attributes
749    vseg[vseg_index]->vobj_offset = vobj_index;
[238]750
[160]751#if XML_PARSER_DEBUG
[238]752printf("      vobj_offset = %d\n", vobj_index);
[160]753#endif
[158]754
755    ///////// get name attribute
756    str = getStringValue(reader, "name", &ok);
[238]757    if (ok) 
758    {
[158]759#if XML_PARSER_DEBUG
[238]760printf("      name = %s\n", str);
[158]761#endif
762        strncpy( vseg[vseg_index]->name, str, 31);
763    }
[238]764    else 
765    {
[158]766        printf("[XML ERROR] illegal or missing <name> attribute for vseg (%d,%d)\n", 
767                vspace_index, vseg_loc_index);
768        exit(1);
769    }
770
[203]771    ////////// get ident attribute (optional : 0 if missing)
[228]772    value = getIntValue(reader, "ident", &ok);
[238]773    if (ok) 
774    {
[203]775#if XML_PARSER_DEBUG
[238]776printf("      ident = %d\n", value);
[203]777#endif
778        vseg[vseg_index]->ident = value;
779    } 
[238]780    else 
781    {
[203]782        vseg[vseg_index]->ident = 0;
783    }
784
[158]785    /////////// get vbase attribute
[228]786    value = getIntValue(reader, "vbase", &ok);
[238]787    if (ok) 
788    {
[158]789#if XML_PARSER_DEBUG
[238]790printf("      vbase = 0x%x\n", value);
[158]791#endif
792        vseg[vseg_index]->vbase = value;
793    }
[238]794    else 
795    {
[158]796        printf("[XML ERROR] illegal or missing <vbase> attribute for vseg (%d,%d)\n", 
797                vspace_index, vseg_loc_index);
798        exit(1);
799    }
800
[181]801    ////////// get clusterid and psegname attributes
[228]802    value = getIntValue(reader, "clusterid", &ok);
[238]803    if (ok == 0) 
804    {
[181]805        printf("[XML ERROR] illegal or missing <clusterid> for vseg %d\n", 
[228]806                vseg_loc_index);
[181]807        exit(1);
808    }
[228]809    str = getStringValue(reader, "psegname", &ok);
[238]810    if (ok == 0) 
811    {
[181]812        printf("[XML ERROR] illegal or missing <psegname> for vseg %d\n", 
[228]813                vseg_loc_index);
[181]814        exit(1);
815    }
816
817    /////////// set psegid field
[228]818    int index = getPsegId(value, str);
[238]819    if (index >= 0) 
820    {
[181]821#if XML_PARSER_DEBUG
[238]822printf("      clusterid = %d\n", value);
823printf("      psegname  = %s\n", str);
824printf("      psegid    = %d\n", index);
[181]825#endif
826        vseg[vseg_index]->psegid = index;
827    }
[238]828    else 
829    {
[181]830        printf("[XML ERROR] pseg not found for vseg %d / clusterid = %d / psegname = %s\n", 
[228]831                vseg_loc_index, value, str );
[181]832        exit(1);
833    } 
834
[165]835    //////// get mode attribute
[228]836    str = getStringValue(reader, "mode", &ok);
[158]837#if XML_PARSER_DEBUG
[238]838printf("      mode = %s\n", str);
[158]839#endif
[228]840    if      (ok && (strcmp(str, "CXWU") == 0)) { vseg[vseg_index]->mode = 0xF; }
841    else if (ok && (strcmp(str, "CXW_") == 0)) { vseg[vseg_index]->mode = 0xE; }
842    else if (ok && (strcmp(str, "CX_U") == 0)) { vseg[vseg_index]->mode = 0xD; }
843    else if (ok && (strcmp(str, "CX__") == 0)) { vseg[vseg_index]->mode = 0xC; }
844    else if (ok && (strcmp(str, "C_WU") == 0)) { vseg[vseg_index]->mode = 0xB; }
845    else if (ok && (strcmp(str, "C_W_") == 0)) { vseg[vseg_index]->mode = 0xA; }
846    else if (ok && (strcmp(str, "C__U") == 0)) { vseg[vseg_index]->mode = 0x9; }
847    else if (ok && (strcmp(str, "C___") == 0)) { vseg[vseg_index]->mode = 0x8; }
848    else if (ok && (strcmp(str, "_XWU") == 0)) { vseg[vseg_index]->mode = 0x7; }
849    else if (ok && (strcmp(str, "_XW_") == 0)) { vseg[vseg_index]->mode = 0x6; }
850    else if (ok && (strcmp(str, "_X_U") == 0)) { vseg[vseg_index]->mode = 0x5; }
851    else if (ok && (strcmp(str, "_X__") == 0)) { vseg[vseg_index]->mode = 0x4; }
852    else if (ok && (strcmp(str, "__WU") == 0)) { vseg[vseg_index]->mode = 0x3; }
853    else if (ok && (strcmp(str, "__W_") == 0)) { vseg[vseg_index]->mode = 0x2; }
854    else if (ok && (strcmp(str, "___U") == 0)) { vseg[vseg_index]->mode = 0x1; }
855    else if (ok && (strcmp(str, "____") == 0)) { vseg[vseg_index]->mode = 0x0; }
856    else {
[158]857        printf("[XML ERROR] illegal or missing <mode> attribute for vseg (%d,%d)\n", 
858                vspace_index, vseg_loc_index);
859        exit(1);
860    }
[228]861
[181]862    ////////// get vobjs in vseg
863    int status = xmlTextReaderRead(reader);
[228]864    while (status == 1) {
865        const char * tag = (const char *) xmlTextReaderConstName(reader);
[160]866
[238]867        if      (strcmp(tag, "vobj")     == 0 ) { vobjNode(reader); }
[228]868        else if (strcmp(tag, "#text"  )  == 0 ) { }
869        else if (strcmp(tag, "#comment") == 0 ) { }
[238]870        else if (strcmp(tag, "vseg")     == 0 ) 
871        {
[165]872            vseg[vseg_index]->vobjs = vobj_count;
[160]873            vseg_index++;
874            vseg_loc_index++;
875            return;
876        }
[253]877        else 
878        {
[228]879            printf("[XML ERROR] Unknown tag %s", tag);
[160]880            exit(1);
881        }
[228]882        status = xmlTextReaderRead (reader);
[160]883    }
[158]884} // end vsegNode()
885
[253]886////////////////////////////////////////
887void vspaceNode(xmlTextReaderPtr reader) 
888{
[228]889    char * str;
890    unsigned int ok;
[232]891    unsigned int nb_task_vspace = 0;
[165]892
893    vobj_loc_index = 0;
[228]894    vseg_loc_index = 0;
895    task_loc_index = 0;
[158]896
[253]897    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return;
[158]898
899    // checking source file consistency
[228]900    if (vspace_index >= header->vspaces) {
[158]901        printf("[XML ERROR] The vspace index is too large : %d\n", 
[228]902                vspace_index);
[158]903        exit(1);
904    }
905
906#if XML_PARSER_DEBUG
[238]907printf("\n  vspace %d\n", vspace_index);
[158]908#endif
909
[228]910    vspace[vspace_index] = (mapping_vspace_t *) malloc(sizeof(mapping_vspace_t));
[158]911
912    ////////// get name attribute
913    str = getStringValue(reader, "name", &ok);
[228]914    if (ok) {
[158]915#if XML_PARSER_DEBUG
[238]916printf("  name = %s\n", str);
[158]917#endif
918        strncpy(vspace[vspace_index]->name, str, 31);
919    }
[253]920    else 
921    {
[165]922        printf("[XML ERROR] illegal or missing <name> attribute for vspace %d\n", 
[228]923                vspace_index);
[158]924        exit(1);
925    }
926
[165]927    ////////// set vseg_offset and task_offset attributes
928    vspace[vspace_index]->vseg_offset = vseg_index;
929    vspace[vspace_index]->vobj_offset = vobj_index;
930    vspace[vspace_index]->task_offset = task_index;
[228]931
[158]932#if XML_PARSER_DEBUG
[228]933    printf("  vseg_offset = %d\n", vseg_index);
934    printf("  vobj_offset = %d\n", vobj_index);
935    printf("  task_offset = %d\n", task_index);
[158]936#endif
937
[165]938    ////////// get startname attribute
939    str = getStringValue(reader, "startname", &ok);
[228]940    if (ok) {
[165]941        //used after parsing the vobjs
[158]942    }
[253]943    else 
944    {
[203]945        printf("[XML ERROR] illegal or missing <startname> attribute for vspace %s\n", 
[228]946                vspace[vspace_index]->name);
[158]947        exit(1);
948    }
949
[181]950    int status = xmlTextReaderRead(reader);
[228]951    while (status == 1) {
952        const char * tag = (const char *) xmlTextReaderConstName(reader);
[158]953
[230]954        if (strcmp(tag, "vseg") == 0) {
[228]955            vsegNode(reader);
956        }
[230]957        else if (strcmp(tag, "task") == 0) {
[228]958            taskNode(reader);
[232]959            nb_task_vspace++;
[228]960        }
[230]961        else if (strcmp(tag, "#text")    == 0) { }
962        else if (strcmp(tag, "#comment") == 0) { }
963        else if (strcmp(tag, "vspace")   == 0) {
[181]964            vspace[vspace_index]->vobjs = vobj_loc_index; 
[160]965            vspace[vspace_index]->tasks = task_loc_index ;
966            vspace[vspace_index]->vsegs = vseg_loc_index ;
[165]967
968            // get index of the vobj containing the start vector
[228]969            int index = getVobjLocId(vspace_index, str , vobj_loc_index);
[253]970            if (index == -1) 
971            {
[203]972                printf("[XML ERROR] vobj containing start vector not found in vspace %s\n",
973                        vspace[vspace_index]->name);
[253]974                exit(1);
[158]975            }
[253]976            else 
977            {
[165]978                vspace[vspace_index]->start_offset = index;
979#if XML_PARSER_DEBUG
[228]980                printf("      startname = %s\n", str);
981                printf("      startid   = %d\n", index);
982                printf("  end vspace %d\n\n", vspace_index);
[165]983#endif
984            }
[160]985
[165]986            // checking startid values for all tasks in vspace
987            int task_id;
988            int task_min = vspace[vspace_index]->task_offset;
989            int task_max = task_min + vspace[vspace_index]->tasks; 
[228]990            for (task_id = task_min; task_id < task_max; task_id++) {
[253]991                if (task[task_id]->startid >= vspace[vspace_index]->tasks) 
992                {
[165]993                    printf("[XML ERROR] <startid> too large for task (%d,%d)\n", 
[228]994                            vspace_index, task_id );
[165]995                    exit(1);
996                }
997            }
998
[232]999            nb_tasks_max += nb_task_vspace;
[160]1000            vspace_index++;
1001            return;
[158]1002        }
[253]1003        else 
1004        {
[228]1005            printf("[XML ERROR] Unknown tag %s", tag);
[158]1006            exit(1);
1007        }
[228]1008        status = xmlTextReaderRead(reader);
[158]1009    }
1010} // end vspaceNode()
1011
[253]1012////////////////////////////////////////
1013void cpPortNode(xmlTextReaderPtr reader) 
1014{
[228]1015    char * str;
1016    unsigned int ok;
[215]1017
[253]1018    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return;
[215]1019
[253]1020    if (cp_port_index >= MAX_CP_PORTS) 
1021    {
1022        printf("[XML ERROR] The number of ports (for coprocs) is larger than %d\n", 
1023                 MAX_CP_PORTS);
1024        exit(1);
[215]1025    }
1026
1027#if XML_PARSER_DEBUG
[228]1028    printf("\n  port %d\n", cp_port_index);
[215]1029#endif
1030
[228]1031    cp_port[cp_port_index] = (mapping_cp_port_t *) malloc(sizeof(mapping_cp_port_t));
1032    cp_port_vobj_ref[cp_port_index] = (vobj_ref_t *) malloc(sizeof(vobj_ref_t));
[215]1033
1034    ///////// get direction attribute
[228]1035    str = getStringValue(reader, "direction", &ok);
[253]1036    if (ok) 
1037    {
[215]1038#if XML_PARSER_DEBUG
[228]1039        printf("      direction = %s\n", str);
[215]1040#endif
[253]1041        if (strcmp(str, "TO_COPROC")   ==  0) 
1042        {
[228]1043            cp_port[cp_port_index]->direction = PORT_TO_COPROC;
1044        }
[253]1045        else if (strcmp(str, "FROM_COPROC") ==  0) 
1046        {
[228]1047            cp_port[cp_port_index]->direction = PORT_FROM_COPROC;
1048        }
[253]1049        else 
1050        {
[215]1051            printf("[XML ERROR] illegal <direction> for cp_port %d in cluster %d\n",
[228]1052                    cp_port_index, cluster_index);
[215]1053            exit(1);
1054        }
1055    } 
[253]1056    else 
1057    {
[215]1058        printf("[XML ERROR] missing <direction> for cp_port %d in cluster %d\n",
[228]1059                cp_port_index, cluster_index);
[215]1060        exit(1);
1061    }
[228]1062
[215]1063    /////////// get vspacename attribute
[228]1064    str = getStringValue(reader, "vspacename", &ok);
[215]1065#if XML_PARSER_DEBUG
[228]1066    printf("      vspacename = %s\n", str);
[215]1067#endif
[253]1068    if (ok) 
1069    {
[215]1070        strncpy(cp_port_vobj_ref[cp_port_index]->vspace_name, str, 31);
1071    }
[253]1072    else 
1073    {
[215]1074        printf("[XML ERROR] missing <vspacename> for cp_port %d in cluster %d\n",
[228]1075                cp_port_index, cluster_index);
[215]1076        exit(1);
1077    }
1078
1079    /////////// get vobjname attribute
[228]1080    str = getStringValue(reader, "vobjname", &ok);
[215]1081#if XML_PARSER_DEBUG
[228]1082    printf("      vobjname = %s\n", str);
[215]1083#endif
[253]1084    if (ok) 
1085    {
[215]1086        strncpy(cp_port_vobj_ref[cp_port_index]->vobj_name, str, 31);
1087    }
[253]1088    else 
1089    {
[215]1090        printf("[XML ERROR] missing <vobjname> for cp_port %d in cluster %d\n",
[228]1091                cp_port_index, cluster_index);
[215]1092        exit(1);
1093    }
1094    cp_port_index++;
1095    cp_port_loc_index++;
1096} // end cpPortNode()
1097
[238]1098////////////////////////////////////////
1099void periphNode(xmlTextReaderPtr reader) 
1100{
[228]1101    char * str;
1102    unsigned int value;
1103    unsigned int ok;
[215]1104
[253]1105    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return;
[215]1106
[238]1107    if (periph_index >= MAX_PERIPHS) 
1108    {
[215]1109        printf("[XML ERROR] The number of periphs is larger than %d\n", MAX_PERIPHS);
[253]1110        exit(1);
[215]1111    }
1112
1113#if XML_PARSER_DEBUG
[228]1114    printf("\n  periph %d\n", periph_index);
[215]1115#endif
1116
[228]1117    periph[periph_index] = (mapping_periph_t *) malloc(sizeof(mapping_periph_t));
[215]1118
1119    ///////// get channels attribute (optionnal : 1 if missing)
[228]1120    value = getIntValue(reader, "channels", &ok);
[238]1121    if (ok) 
1122    {
[215]1123#if XML_PARSER_DEBUG
[228]1124        printf("      channels = %d\n", value);
[215]1125#endif
1126        periph[periph_index]->channels = value;
1127    }
[238]1128    else 
1129    {
[215]1130        periph[periph_index]->channels = 1;
1131    }
1132
1133    /////////// get psegname attribute
[228]1134    str = getStringValue(reader, "psegname", &ok);
[238]1135    if (ok == 0) 
1136    {
[215]1137        printf("[XML ERROR] illegal or missing <psegname> for coproc %d in cluster %d\n", 
[228]1138                coproc_index, cluster_index);
[215]1139        exit(1);
1140    }
1141
1142    /////////// set psegid attribute
[228]1143    int index = getPsegId(cluster_index, str);
[238]1144    if (index >= 0) 
1145    {
[215]1146#if XML_PARSER_DEBUG
[228]1147        printf("      clusterid = %d\n", cluster_index);
1148        printf("      psegname  = %s\n", str);
1149        printf("      psegid    = %d\n", index);
[215]1150#endif
1151        periph[periph_index]->psegid = index;
1152        assert(pseg[index]->type == PSEG_TYPE_PERI && 
[228]1153                "peripheral psegname attribute must refer to a pseg of type PERI" );
[215]1154    }
[238]1155    else 
1156    {
[215]1157        printf("[XML ERROR] pseg not found for periph %d / clusterid = %d / psegname = %s\n", 
[228]1158                periph_loc_index, cluster_index, str );
[215]1159        exit(1);
1160    } 
1161
1162    /////////// get type attribute
[228]1163    str = getStringValue(reader, "type", &ok);
[238]1164    if (ok) 
1165    {
[215]1166#if XML_PARSER_DEBUG
[228]1167        printf("      type     = %s\n", str);
[215]1168#endif
1169        unsigned int error = 0;
[228]1170
[238]1171        // The TTY, IOC, NIC, FBF, CMA and IOB peripherals are not replicated in all clusters
1172        // but can be replicated in two different clusters for fault tolerance
1173        // In case of replication, the number of channels must be the same
1174        if (strcmp(str, "IOC") == 0) 
1175        {
[215]1176            periph[periph_index]->type = PERIPH_TYPE_IOC;
[238]1177            if (header->ioc_cluster == 0xFFFFFFFF)
1178            {
1179                header->ioc_cluster  = cluster_index; 
1180                ioc_channels = periph[periph_index]->channels;
[228]1181            }
[238]1182            else if (header->ioc_cluster_bis == 0xFFFFFFFF) 
1183            {
1184                header->ioc_cluster_bis = cluster_index;
1185            }
1186            else
1187            {
[228]1188                error = 1;
1189            }
[215]1190        } 
[238]1191        else if (strcmp(str, "TTY") == 0) 
1192        {
[215]1193            periph[periph_index]->type = PERIPH_TYPE_TTY;
[238]1194            if (header->tty_cluster == 0xFFFFFFFF) 
1195            {
1196                header->tty_cluster = cluster_index;
1197                tty_channels = periph[periph_index]->channels;
[228]1198            }
[238]1199            else if (header->tty_cluster_bis == 0xFFFFFFFF) 
1200            {
1201                header->tty_cluster_bis = cluster_index;
1202            }
1203            else 
1204            {
[228]1205                error = 1;
1206            }
[215]1207        }
[238]1208        else if (strcmp(str, "FBF") == 0) 
1209        {
[215]1210            periph[periph_index]->type = PERIPH_TYPE_FBF;
[238]1211            if (header->fbf_cluster == 0xFFFFFFFF) 
1212            {
1213                header->fbf_cluster = cluster_index; 
[228]1214            }
[238]1215            else if (header->fbf_cluster_bis == 0xFFFFFFFF) 
1216            {
1217                header->fbf_cluster_bis = cluster_index; 
1218            }
1219            else 
1220            {
[228]1221                error = 1;
1222            }
[215]1223        }
[238]1224        else if (strcmp(str, "NIC") == 0) 
1225        {
[215]1226            periph[periph_index]->type = PERIPH_TYPE_NIC;
[238]1227            if (header->nic_cluster == 0xFFFFFFFF) 
1228            {
1229                header->nic_cluster = cluster_index;
1230                nic_channels = periph[periph_index]->channels;
[228]1231            }
[238]1232            else if (header->nic_cluster_bis == 0xFFFFFFFF) 
1233            {
1234                header->nic_cluster_bis = cluster_index;
1235            }
1236            else 
1237            {
[228]1238                error = 1;
1239            }
[215]1240        }
[238]1241        else if (strcmp(str, "CMA") == 0) 
1242        {
1243            periph[periph_index]->type = PERIPH_TYPE_CMA;
1244            if (header->cma_cluster == 0xFFFFFFFF) 
1245            {
1246                header->cma_cluster = cluster_index;
1247                cma_channels = periph[periph_index]->channels;
1248            }
[253]1249            else if (header->cma_cluster_bis == 0xFFFFFFFF) 
[238]1250            {
1251                header->cma_cluster_bis = cluster_index;
1252            }
1253            else 
1254            {
1255                error = 1;
1256            }
1257        }
1258        else if (strcmp(str, "IOB") == 0) 
1259        {
[215]1260            periph[periph_index]->type = PERIPH_TYPE_IOB;
[249]1261            use_iob = 1;
[238]1262            if (header->iob_cluster == 0xFFFFFFFF) 
1263            {
1264                header->iob_cluster = cluster_index; 
1265            }
1266            else if (header->iob_cluster_bis == 0xFFFFFFFF) 
1267            {
1268                header->iob_cluster_bis = cluster_index; 
1269            }
1270            else 
1271            {
[228]1272                error = 1;
1273            }
[215]1274        }
[249]1275        // The TIM, ICU, XICU, DMA, MEMC peripherals are replicated in all clusters
[253]1276        // but it must exist only one component of each type per cluster
[238]1277        else if (strcmp(str, "TIM") == 0 ) 
1278        {
[215]1279            periph[periph_index]->type = PERIPH_TYPE_TIM;
[253]1280            if (found_timer || use_xcu)  error = 1; 
[215]1281            found_timer = 1;
[238]1282            if (tim_channels < periph[periph_index]->channels) 
1283            {
1284                tim_channels = periph[periph_index]->channels;
[228]1285            }
[215]1286        }
[238]1287        else if (strcmp(str, "ICU") == 0) 
1288        {
[215]1289            periph[periph_index]->type = PERIPH_TYPE_ICU;
[253]1290            if (found_icu || use_xcu)  error = 1; 
[215]1291            found_icu = 1;
1292        }
[253]1293        else if (strcmp(str, "XCU") == 0) 
[238]1294        {
[253]1295            periph[periph_index]->type = PERIPH_TYPE_XCU;
[238]1296            if (found_icu || found_timer)  error = 1; 
[253]1297            found_xcu    = 1;
1298            found_timer  = 1;
1299            tim_channels = 32; 
1300            use_xcu      = 1;
[215]1301        }
[238]1302        else if (strcmp(str, "DMA") == 0) 
1303        {
[215]1304            periph[periph_index]->type = PERIPH_TYPE_DMA;
[238]1305            if (found_dma)  error = 1; 
[215]1306            found_dma = 1;
[238]1307            if (dma_channels < periph[periph_index]->channels)
1308                dma_channels = periph[periph_index]->channels;
[215]1309        }
[249]1310        else if (strcmp(str, "MMC") == 0) 
1311        {
1312            periph[periph_index]->type = PERIPH_TYPE_MMC;
1313            if (found_mmc)  error = 1; 
1314            found_mmc = 1;
1315            if ( periph[periph_index]->channels != 1 ) error = 1;
1316        }
[238]1317        else 
1318        {
[215]1319            printf("[XML ERROR] illegal <type> for peripheral %d in cluster %d\n",
[228]1320                    periph_loc_index, cluster_index);
[215]1321            exit(1);
1322        }
1323
[238]1324        if (error) 
1325        {
[215]1326            printf("[XML ERROR] illegal <type> for peripheral %d in cluster %d\n",
[228]1327                    periph_loc_index, cluster_index);
[215]1328            exit(1);
1329        }
1330    }
[238]1331    else 
1332    {
[215]1333        printf("[XML ERROR] missing <type> for peripheral  %d in cluster %d\n",
[228]1334                periph_loc_index, cluster_index);
[215]1335        exit(1);
1336    }
1337
1338    periph_index++;
1339    periph_loc_index++;
1340    cluster[cluster_index]->periphs++;
1341
1342} // end periphNode
1343
[253]1344////////////////////////////////////////
1345void coprocNode(xmlTextReaderPtr reader) 
1346{
[228]1347    char * str;
1348    unsigned int ok;
[215]1349
1350    cp_port_loc_index = 0;
1351
[253]1352    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return;
[215]1353
[253]1354    if (coproc_index >= MAX_COPROCS) 
1355    {
[215]1356        printf("[XML ERROR] The number of coprocs is larger than %d\n", MAX_COPROCS);
[253]1357        exit(1);
[215]1358    }
1359
1360#if XML_PARSER_DEBUG
[228]1361    printf("\n  coproc %d\n", coproc_index);
[215]1362#endif
1363
[228]1364    coproc[coproc_index] = (mapping_coproc_t *) malloc(sizeof(mapping_coproc_t));
[215]1365
1366    /////////// get name attribute
[228]1367    str = getStringValue(reader, "name", &ok);
[253]1368    if (ok) 
1369    {
[215]1370#if XML_PARSER_DEBUG
[228]1371        printf("      name = %s\n", str);
[215]1372#endif
1373        strncpy(coproc[coproc_index]->name, str, 31);
1374    }
[253]1375    else 
1376    {
[215]1377        printf("[XML ERROR] illegal or missing <name> for coproc %d in cluster %d\n",
[228]1378                coproc_index, cluster_index);
[215]1379        exit(1);
1380    }
1381
1382    /////////// get psegname attribute
[228]1383    str = getStringValue(reader, "psegname", &ok);
[253]1384    if (ok == 0) 
1385    {
[215]1386        printf("[XML ERROR] illegal or missing <psegname> for coproc %d in cluster %d\n", 
[228]1387                coproc_index, cluster_index);
[215]1388        exit(1);
1389    }
1390
1391    /////////// set psegid attribute
[228]1392    int index = getPsegId(cluster_index, str);
[253]1393    if (index >= 0) 
1394    {
[215]1395#if XML_PARSER_DEBUG
[228]1396        printf("      clusterid = %d\n", cluster_index);
1397        printf("      psegname  = %s\n", str);
1398        printf("      psegid    = %d\n", index);
[215]1399#endif
1400        coproc[coproc_index]->psegid = index;
1401        assert(pseg[index]->type == PSEG_TYPE_PERI && "coproc psegname attribute must refer to a pseg of type PERI" );
1402    }
[253]1403    else 
1404    {
[215]1405        printf("[XML ERROR] pseg not found for coproc %d / clusterid = %d / psegname = %s\n", 
[228]1406                coproc_index, cluster_index, str );
[215]1407        exit(1);
1408    } 
1409
1410    ////////// set port_offset
1411    coproc[coproc_index]->port_offset = cp_port_index;
1412
1413#if XML_PARSER_DEBUG
[228]1414    printf("      port_offset = %d\n", cp_port_index);
[215]1415#endif
1416
1417    int status = xmlTextReaderRead(reader);
[253]1418    while (status == 1) 
1419    {
[228]1420        const char * tag = (const char *) xmlTextReaderConstName(reader);
[215]1421
[253]1422        if (strcmp(tag, "port") == 0 ) 
1423        {
[228]1424            cpPortNode(reader);
1425        }
1426        else if (strcmp(tag, "#text")    == 0 ) { }
1427        else if (strcmp(tag, "#comment") == 0 ) { }
[253]1428        else if (strcmp(tag, "coproc") == 0 ) 
1429        {
[215]1430            coproc[coproc_index]->ports = cp_port_loc_index;
1431            cluster[cluster_index]->coprocs++;
1432            coproc_loc_index++;
1433            coproc_index++;
1434            return;
1435        }
[253]1436        else 
1437        {
[228]1438            printf("[XML ERROR] Unknown tag %s", tag);
[215]1439            exit(1);
1440        }
[228]1441        status = xmlTextReaderRead(reader);
[215]1442    }
1443} // end coprocNode()
1444
[228]1445
[253]1446/////////////////////////////////////
1447void irqNode(xmlTextReaderPtr reader) 
1448{
[228]1449    unsigned int ok;
1450    unsigned int value;
1451    char * str;
[215]1452
[253]1453    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return;
[215]1454
[228]1455    if (irq_index >= MAX_IRQS) {
[215]1456        printf("[XML ERROR] The number of irqs is larger than %d\n", MAX_IRQS);
1457    }
1458
1459#if XML_PARSER_DEBUG
[228]1460    printf("     irq %d\n", irq_loc_index);
[215]1461#endif
1462
[228]1463    irq[irq_index] = (mapping_irq_t *) malloc(sizeof(mapping_irq_t));
[215]1464
1465    ///////// get type attribute
[228]1466    str = getStringValue(reader, "type", &ok);
[253]1467    if (ok) 
1468    {
[215]1469#if XML_PARSER_DEBUG
[228]1470        printf("        type    = %s\n", str);
[215]1471#endif
[253]1472        if (strcmp(str, "HARD") == 0 ) irq[irq_index]->type = 0;
1473        else                           irq[irq_index]->type = 1;
[231]1474    }
[253]1475    else 
1476    {
[215]1477        printf("[XML ERROR] missing IRQ <type> for processor %d in cluster %d\n",
[228]1478                cluster_index, proc_loc_index);
[215]1479        exit(1);
1480    }
1481
1482    ///////// get icuid attribute
1483    value = getIntValue(reader, "icuid", &ok);
[253]1484    if (ok) 
1485    {
[215]1486#if XML_PARSER_DEBUG
[228]1487        printf("        icuid   = %d\n", value);
[215]1488#endif
1489        irq[irq_index]->icuid = value;
[253]1490        if (value >= 32) 
1491        {
[215]1492            printf("[XML ERROR] IRQ <icuid> too large for processor %d in cluster %d\n",
[228]1493                    cluster_index, proc_loc_index);
[215]1494            exit(1);
1495        }
1496    }
[253]1497    else 
1498    {
[215]1499        printf("[XML ERROR] missing IRQ <icuid> for processor %d in cluster %d\n",
[228]1500                cluster_index, proc_loc_index);
[215]1501        exit(1);
1502    }
1503
1504    ///////// get isr attribute
[228]1505    str = getStringValue(reader, "isr", &ok);
[253]1506    if (ok) 
1507    {
[215]1508#if XML_PARSER_DEBUG
[228]1509        printf("        isr     = %s\n", str);
[215]1510#endif
[228]1511        if      (strcmp(str, "ISR_SWITCH" ) == 0) { irq[irq_index]->isr = ISR_SWITCH; }
1512        else if (strcmp(str, "ISR_IOC"    ) == 0) { irq[irq_index]->isr = ISR_IOC; }
1513        else if (strcmp(str, "ISR_DMA"    ) == 0) { irq[irq_index]->isr = ISR_DMA; }
1514        else if (strcmp(str, "ISR_TTY"    ) == 0) { irq[irq_index]->isr = ISR_TTY; }
1515        else if (strcmp(str, "ISR_TIMER"  ) == 0) { irq[irq_index]->isr = ISR_TIMER; }
[253]1516        else 
1517        {
[215]1518            printf("[XML ERROR] illegal IRQ <isr> for processor %d in cluster %d\n",
[228]1519                    cluster_index, proc_loc_index);
[215]1520            exit(1);
1521        }
1522#if XML_PARSER_DEBUG
[228]1523        printf("        isrnum  = %d\n", irq[irq_index]->isr);
[215]1524#endif
1525    } 
[253]1526    else 
1527    {
[215]1528        printf("[XML ERROR] missing IRQ <isr> for processor %d in cluster %d\n",
[228]1529                cluster_index, proc_loc_index);
[215]1530        exit(1);
1531    }
1532
1533    ///////// get channel attribute (optionnal : 0 if missing)
1534    value = getIntValue(reader, "channel", &ok);
[253]1535    if (ok) 
1536    {
[215]1537#if XML_PARSER_DEBUG
[228]1538        printf("        channel = %d\n", value);
[215]1539#endif
1540        irq[irq_index]->channel = value;
1541    }
[253]1542    else 
1543    {
[215]1544        irq[irq_index]->channel = 0;
1545    }
1546
1547    irq_index++;
1548    irq_loc_index++;
1549
1550} // end irqNode
1551
[228]1552
[253]1553//////////////////////////////////////
1554void procNode(xmlTextReaderPtr reader) 
1555{
[228]1556    unsigned int ok;
1557    unsigned int value;
[215]1558
1559    irq_loc_index = 0;
1560
[253]1561    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return;
[215]1562
[253]1563    if (proc_index >= MAX_PROCS) 
1564    {
[215]1565        printf("[XML ERROR] The number of procs is larger than %d\n", MAX_PROCS);
[253]1566        exit(1);
[215]1567    }
1568
1569#if XML_PARSER_DEBUG
[228]1570    printf("\n  proc %d\n", proc_index);
[215]1571#endif
1572
[228]1573    proc[proc_index] = (mapping_proc_t *) malloc(sizeof(mapping_proc_t));
[215]1574
1575    /////////// get index attribute (optional)
[228]1576    value = getIntValue(reader, "index", &ok);
[253]1577    if (ok && (value != proc_loc_index)) 
1578    {
[228]1579        printf("[XML ERROR] wrong proc index / expected value is %d", 
[215]1580                proc_loc_index);
[228]1581        exit(1);
[215]1582    }
1583
1584    ////////// set irq_offset attribute
1585    proc[proc_index]->irq_offset = irq_index;
1586
1587#if XML_PARSER_DEBUG
[228]1588    printf("    irq_offset = %d\n", irq_index);
[215]1589#endif
1590
1591    int status = xmlTextReaderRead(reader);
[253]1592    while (status == 1) 
1593    {
[228]1594        const char * tag = (const char *) xmlTextReaderConstName(reader);
[215]1595
[253]1596        if (strcmp(tag, "irq") == 0) 
1597        {
[228]1598            irqNode(reader);
1599        }
1600        else if (strcmp(tag, "#text")    == 0) { }
1601        else if (strcmp(tag, "#comment") == 0) { }
[253]1602        else if (strcmp(tag, "proc")     == 0) 
1603        {
[215]1604            proc[proc_index]->irqs = irq_loc_index;
1605            cluster[cluster_index]->procs++;
1606            proc_loc_index++;
1607            proc_index++;
1608            return;
1609        }
[253]1610        else 
1611        {
[228]1612            printf("[XML ERROR] Unknown tag %s", tag);
[215]1613            exit(1);
1614        }
[228]1615        status = xmlTextReaderRead(reader);
[215]1616    }
1617} // end procNode()
1618
1619
[253]1620//////////////////////////////////////
1621void psegNode(xmlTextReaderPtr reader) 
1622{
[228]1623    unsigned int ok;
[238]1624    paddr_t      ll_value;
[228]1625    char * str;
[158]1626
[253]1627    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return;
[158]1628
[253]1629    if (pseg_index >= MAX_PSEGS) 
1630    {
[158]1631        printf("[XML ERROR] The number of psegs is larger than %d\n", MAX_PSEGS);
1632        exit(1);
1633    }
1634
1635#if XML_PARSER_DEBUG
[228]1636    printf("    pseg %d\n", pseg_index);
[158]1637#endif
1638
[228]1639    pseg[pseg_index] = (mapping_pseg_t *) malloc(sizeof(mapping_pseg_t));
[158]1640
[181]1641    /////// get name attribute
[228]1642    str = getStringValue(reader, "name", &ok);
[158]1643#if XML_PARSER_DEBUG
[228]1644    printf("      name = %s\n", str);
[158]1645#endif
[253]1646    if (ok) 
1647    {
[158]1648        strncpy(pseg[pseg_index]->name, str, 31);
1649    }
[253]1650    else 
1651    {
[181]1652        printf("[XML ERROR] illegal or missing <name> for pseg %d in cluster %d\n",
[228]1653                pseg_index, cluster_index);
[158]1654        exit(1);
1655    }
1656
[181]1657    //////// get type attribute
1658    str = getStringValue(reader, "type", &ok);
1659#if XML_PARSER_DEBUG
[228]1660    printf("      type = %s\n", str);
[181]1661#endif
[228]1662    if      (ok && (strcmp(str, "RAM" ) == 0)) { pseg[pseg_index]->type = PSEG_TYPE_RAM; }
1663    else if (ok && (strcmp(str, "ROM" ) == 0)) { pseg[pseg_index]->type = PSEG_TYPE_ROM; }
1664    else if (ok && (strcmp(str, "PERI") == 0)) { pseg[pseg_index]->type = PSEG_TYPE_PERI; }
[253]1665    else 
1666    {
[181]1667        printf("[XML ERROR] illegal or missing <type> for pseg %s in cluster %d\n",
[228]1668                pseg[pseg_index]->name, cluster_index);
[181]1669        exit(1);
1670    }
1671
1672    //////// get base attribute
[238]1673    ll_value = getPaddrValue(reader, "base", &ok);
[158]1674#if XML_PARSER_DEBUG
[238]1675    printf("      base = 0x%llx\n", ll_value);
[158]1676#endif
[253]1677    if (ok) 
1678    {
[238]1679        pseg[pseg_index]->base = ll_value;
[158]1680    }
[228]1681    else {
[181]1682        printf("[XML ERROR] illegal or missing <base> for pseg %s in cluster %d\n",
[228]1683                pseg[pseg_index]->name, cluster_index);
[158]1684        exit(1);
1685    }
1686
[181]1687    //////// get length attribute
[238]1688    ll_value = getPaddrValue(reader, "length", &ok);
[158]1689#if XML_PARSER_DEBUG
[238]1690    printf("      length = 0x%llx\n", ll_value);
[158]1691#endif
[253]1692    if (ok) 
1693    {
[238]1694        pseg[pseg_index]->length = ll_value;
[158]1695    } 
[253]1696    else 
1697    {
[181]1698        printf("[XML ERROR] illegal or missing <length> for pseg %s in cluster %d\n",
[228]1699                pseg[pseg_index]->name, cluster_index);
[158]1700        exit(1);
1701    }
1702
[181]1703    //////// set cluster attribute
1704    pseg[pseg_index]->cluster = cluster_index;
1705
[158]1706    pseg_index++;
[181]1707    cluster[cluster_index]->psegs++;
[158]1708} // end psegNode()
1709
[228]1710
[238]1711/////////////////////////////////////////
1712void clusterNode(xmlTextReaderPtr reader) 
1713{
[158]1714    unsigned int ok;
1715    unsigned int value;
1716
[228]1717    cluster[cluster_index] = (mapping_cluster_t *) malloc(sizeof(mapping_cluster_t));
1718
[215]1719    //initialise all variables
1720    //they will be incremented by *Node() functions
1721    //FIXME: calloc?
1722    cluster[cluster_index]->psegs = 0;
1723    cluster[cluster_index]->procs = 0;
1724    cluster[cluster_index]->coprocs = 0;
1725    cluster[cluster_index]->periphs = 0;
1726
1727
1728    //initialise global variables
1729    //TODO: delete those three
[181]1730    proc_loc_index = 0;
1731    coproc_loc_index = 0;
[189]1732    periph_loc_index = 0;
[181]1733
[215]1734    // for replicated periph
1735    found_timer = 0;
[249]1736    found_icu   = 0;
[253]1737    found_xcu   = 0;
[249]1738    found_dma   = 0;
1739    found_mmc   = 0;
[215]1740
[228]1741    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) {
1742        return;
1743    }
[158]1744
1745    // checking source file consistency
[253]1746    if (cluster_index >= header->clusters) 
1747    {
[158]1748        printf("[XML ERROR] The cluster index is too large : %d\n", cluster_index);
1749        exit(1);
1750    }
1751
1752#if XML_PARSER_DEBUG
[228]1753    printf("  cluster %d\n", cluster_index);
[158]1754#endif
1755
1756
[189]1757    /////////// check cluster index attribute (optional)
[228]1758    value = getIntValue(reader, "index", &ok);
[253]1759    if (ok && (value != cluster_index)) 
1760    {
[228]1761        printf("[XML ERROR] wrong cluster index / expected value is %d", 
[158]1762                cluster_index);
[228]1763        exit(1);
[158]1764    }
1765
[189]1766    ////////// set offsets
[228]1767    cluster[cluster_index]->pseg_offset = pseg_index;
1768    cluster[cluster_index]->proc_offset = proc_index;
[189]1769    cluster[cluster_index]->coproc_offset = coproc_index;
1770    cluster[cluster_index]->periph_offset = periph_index;
[181]1771
[158]1772#if XML_PARSER_DEBUG
[228]1773    printf("    pseg_offset   = %d\n", pseg_index);
1774    printf("    proc_offset   = %d\n", proc_index);
1775    printf("    coproc_offset = %d\n", coproc_index);
1776    printf("    periph_offset = %d\n", coproc_index);
[158]1777#endif
[181]1778
[189]1779    ////////// get psegs, procs, coprocs and periphs
[181]1780    int status = xmlTextReaderRead(reader);
1781
[238]1782    while (status == 1) 
1783    {
[228]1784        const char * tag = (const char *) xmlTextReaderConstName(reader);
[181]1785
[228]1786        if      (strcmp(tag, "pseg")     == 0) psegNode(reader);
1787        else if (strcmp(tag, "proc")     == 0) procNode(reader);
1788        else if (strcmp(tag, "coproc")   == 0) coprocNode(reader);
1789        else if (strcmp(tag, "periph")   == 0) periphNode(reader);
1790        else if (strcmp(tag, "#text")    == 0) { }
1791        else if (strcmp(tag, "#comment") == 0) { }
[238]1792        else if (strcmp(tag, "cluster")  == 0) 
1793        {
[189]1794
[253]1795            ///////// TIMER and ICU peripheral are mandatory //////////////
1796            if (!found_timer && !found_xcu)
[238]1797            {
[253]1798                printf("[XML ERROR] missing timer peripheral in cluster %d\n", cluster_index);
[215]1799                exit(1);
1800            }
1801
[253]1802            if (!found_icu && !found_xcu) 
[238]1803            {
[253]1804                printf("[XML ERROR] missing icu peripheral in cluster %d\n", cluster_index);
[215]1805                exit(1);
1806            }
1807
[238]1808            if (nb_proc_max < cluster[cluster_index]->procs) 
1809            {
[215]1810                nb_proc_max = cluster[cluster_index]->procs;
[228]1811            }
[215]1812
[181]1813#if XML_PARSER_DEBUG
[228]1814            printf("    psegs   = %d\n", cluster[cluster_index]->psegs);
1815            printf("    procs   = %d\n", cluster[cluster_index]->procs);
1816            printf("    coprocs = %d\n", cluster[cluster_index]->coprocs);
1817            printf("    periphs = %d\n", cluster[cluster_index]->periphs);
1818            printf("    end cluster %d\n", cluster_index);
[181]1819#endif
1820            cluster_index++;
1821            return;
1822        }
1823        status = xmlTextReaderRead(reader);
[158]1824    }
1825} // end clusterNode()
1826
[228]1827
[158]1828//////////////////////////////////////////////
[238]1829void clusterSetNode(xmlTextReaderPtr reader) 
1830{
[253]1831    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return;
[158]1832
1833#if XML_PARSER_DEBUG
[228]1834    printf("\n  clusters set\n");
[158]1835#endif
1836
[181]1837    int status = xmlTextReaderRead(reader);
[238]1838    while (status == 1) 
1839    {
[228]1840        const char * tag = (const char *) xmlTextReaderConstName(reader);
[158]1841
[238]1842        if      (strcmp(tag, "cluster")    == 0) { clusterNode(reader); }
[228]1843        else if (strcmp(tag, "#text")      == 0) { }
1844        else if (strcmp(tag, "#comment")   == 0) { }
[238]1845        else if (strcmp(tag, "clusterset") == 0) 
1846        {
[158]1847            // checking source file consistency
[238]1848            if (cluster_index != header->clusters) 
1849            {
[158]1850                printf("[XML ERROR] Wrong number of clusters\n");
1851                exit(1);
1852            }
[215]1853
[238]1854            // At least one TTY terminal for system boot
1855            if (header->tty_cluster == 0xFFFFFFFF) 
1856            {
[215]1857                printf("[XML ERROR] illegal or missing tty peripheral");
1858                exit(1);
1859            }
1860
[181]1861#if XML_PARSER_DEBUG
[228]1862            printf("  end cluster set\n\n");
[181]1863#endif
[228]1864            header->psegs = pseg_index;
1865            header->procs = proc_index;
1866            header->irqs = irq_index;
1867            header->coprocs = coproc_index;
[215]1868            header->cp_ports = cp_port_index;
[238]1869            header->periphs = periph_index;
[215]1870            return;
[158]1871        }
[253]1872        else 
1873        {
[158]1874            printf("[XML ERROR] Unknown tag in clusterset node : %s",tag);
1875            exit(1);
1876        }
[181]1877        status = xmlTextReaderRead(reader);
[158]1878    }
1879} // end clusterSetNode()
1880
[228]1881
[253]1882///////////////////////////////////////////
1883void globalSetNode(xmlTextReaderPtr reader) 
1884{
1885    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return;
[158]1886
1887#if XML_PARSER_DEBUG
[228]1888    printf("  globals set\n");
[158]1889#endif
1890
[181]1891    int status = xmlTextReaderRead(reader);
[238]1892    while (status == 1) 
1893    {
[228]1894        const char * tag = (const char *) xmlTextReaderConstName(reader);
[158]1895
[238]1896        if      (strcmp(tag, "vseg")      == 0) { vsegNode(reader); }
[228]1897        else if (strcmp(tag, "#text")     == 0) { }
1898        else if (strcmp(tag, "#comment")  == 0) { }
[253]1899        else if (strcmp(tag, "globalset") == 0) 
1900        {
[181]1901#if XML_PARSER_DEBUG
[228]1902            printf("  end global set\n\n");
[181]1903#endif
[204]1904            header->globals = vseg_index;
1905            vseg_loc_index = 0;
1906            return;
[158]1907        }
[253]1908        else 
1909        {
[158]1910            printf("[XML ERROR] Unknown tag in globalset node : %s",tag);
1911            exit(1);
1912        }
[228]1913        status = xmlTextReaderRead(reader);
[158]1914    }
1915} // end globalSetNode()
1916
[228]1917
[253]1918///////////////////////////////////////////
1919void vspaceSetNode(xmlTextReaderPtr reader)
1920{
[228]1921    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) {
1922        return;
1923    }
[158]1924
1925#if XML_PARSER_DEBUG
[228]1926    printf("\n  vspaces set\n");
[158]1927#endif
1928
1929    int status = xmlTextReaderRead ( reader );
[228]1930    while (status == 1) {
1931        const char * tag = (const char *) xmlTextReaderConstName(reader);
[158]1932
[228]1933        if (strcmp(tag, "vspace") == 0) {
1934            vspaceNode(reader);
1935        }
1936        else if (strcmp(tag, "#text"    ) == 0 ) { }
1937        else if (strcmp(tag, "#comment" ) == 0 ) { }
[253]1938        else if (strcmp(tag, "vspaceset") == 0 ) 
1939        {
[158]1940            // checking source file consistency
[253]1941            if (vspace_index != header->vspaces) 
1942            {
[158]1943                printf("[XML ERROR] Wrong number of vspaces\n");
1944                exit(1);
1945            }
[253]1946            else 
1947            {
[158]1948                header->vsegs = vseg_index;
[160]1949                header->vobjs = vobj_index;
[158]1950                header->tasks = task_index;
1951                return;
1952            }
1953        }
[253]1954        else 
1955        {
[158]1956            printf("[XML ERROR] Unknown tag in vspaceset node : %s",tag);
1957            exit(1);
1958        }
[228]1959        status = xmlTextReaderRead(reader);
[158]1960    }
1961} // end globalSetNode()
1962
[228]1963
[253]1964////////////////////////////////////////
[238]1965void headerNode(xmlTextReaderPtr reader) 
1966{
[228]1967    char * name;
1968    unsigned int value;
1969    unsigned int ok;
[158]1970
[253]1971    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return;
[158]1972
1973#if XML_PARSER_DEBUG
[228]1974    printf("mapping_info\n");
[158]1975#endif
1976
[228]1977    header = (mapping_header_t *) malloc(sizeof(mapping_header_t));
[158]1978
[165]1979    ////////// get name attribute
[158]1980    name = getStringValue(reader, "name", &ok);
[253]1981    if (ok) 
1982    {
[158]1983#if XML_PARSER_DEBUG
[228]1984        printf("  name = %s\n", name);
[158]1985#endif
[228]1986        strncpy( header->name, name, 31);
1987    }
[253]1988    else 
1989    {
[158]1990        printf("[XML ERROR] illegal or missing <name> attribute in header\n");
1991        exit(1);
1992    }
1993
[215]1994    /////////// get cluster_x attribute
1995    cluster_x = getIntValue(reader, "cluster_x", &ok);
[253]1996    if (ok) 
1997    {
[158]1998#if XML_PARSER_DEBUG
[228]1999        printf("  cluster_x = %d\n", cluster_x);
[158]2000#endif
[215]2001        header->cluster_x = cluster_x;
[158]2002    }
[253]2003    else 
2004    {
[215]2005        printf("[XML ERROR] illegal or missing <cluster_x> attribute in header\n");
[158]2006        exit(1);
2007    }
2008
[215]2009    /////////// get cluster_y attribute
2010    cluster_y = getIntValue(reader, "cluster_y", &ok);
[253]2011    if (ok) 
2012    {
[215]2013#if XML_PARSER_DEBUG
[228]2014        printf("  cluster_y = %d\n", cluster_y);
[215]2015#endif
2016        header->cluster_y = cluster_y;
2017    }
[253]2018    else 
2019    {
[215]2020        printf("[XML ERROR] illegal or missing <cluster_y> attribute in header\n");
2021        exit(1);
2022    }
2023
2024    //check the number of cluster
[228]2025    value = cluster_x * cluster_y;
[253]2026    if (value >= MAX_CLUSTERS) 
2027    {
[215]2028        printf("[XML ERROR] The number of clusters is larger than %d\n", MAX_CLUSTERS);
2029        exit(1);
2030    }
[228]2031
[215]2032    header->clusters  = value;
2033
2034#if XML_PARSER_DEBUG
[228]2035    printf("  clusters = %d\n", value);
[215]2036#endif
2037
[165]2038    ///////// get vspaces attribute
[158]2039    value = getIntValue(reader, "vspaces", &ok);
[253]2040    if (ok) 
2041    {
2042        if (value >= MAX_VSPACES) 
2043        {
[158]2044            printf("[XML ERROR] The number of vspaces is larger than %d\n", MAX_VSPACES);
2045            exit(1);
2046        }
2047#if XML_PARSER_DEBUG
[228]2048        printf("  vspaces = %d\n", value);
[158]2049#endif
[228]2050        header->vspaces  = value;
[158]2051    }
[253]2052    else 
2053    {
[158]2054        printf("[XML ERROR] illegal or missing <vspaces> attribute in mapping\n");
2055        exit(1);
2056    }
2057
[253]2058    ///////// get increment attribute
2059    value = getIntValue(reader, "increment", &ok);
2060    if (ok) 
2061    {
2062        if ( (value != 0x10000) && (value != 0x8000) &&
2063             (value != 0x4000)  && (value != 0x2000) )
2064       
2065        {
2066            printf("[XML ERROR] The vseg increment must be one of the following: ");
2067            printf(" 0x00010000 / 0x00008000 / 0x00004000 / 0x00002000");
2068            exit(1);
2069        }
2070#if XML_PARSER_DEBUG
2071        printf("  increment = %d\n", value);
2072#endif
2073        header->increment  = value;
2074    }
2075    else 
2076    {
2077        printf("[XML ERROR] illegal or missing <increment> attribute in mapping\n");
2078        exit(1);
2079    }
2080
[238]2081    //////// initialise non replicated peripherals cluster index
2082    header->tty_cluster = 0xFFFFFFFF;
2083    header->nic_cluster = 0xFFFFFFFF;
2084    header->ioc_cluster = 0xFFFFFFFF;
2085    header->fbf_cluster = 0xFFFFFFFF;
2086    header->cma_cluster = 0xFFFFFFFF;
2087    header->iob_cluster = 0xFFFFFFFF;
2088    header->tty_cluster_bis = 0xFFFFFFFF;
2089    header->nic_cluster_bis = 0xFFFFFFFF;
2090    header->ioc_cluster_bis = 0xFFFFFFFF;
2091    header->fbf_cluster_bis = 0xFFFFFFFF;
2092    header->cma_cluster_bis = 0xFFFFFFFF;
2093    header->iob_cluster_bis = 0xFFFFFFFF;
[189]2094
2095    ///////// set signature
[158]2096    header->signature = IN_MAPPING_SIGNATURE;
2097
[181]2098    int status = xmlTextReaderRead(reader);
[253]2099    while (status == 1) 
2100    {
[228]2101        const char * tag = (const char *) xmlTextReaderConstName(reader);
[158]2102
[253]2103        if (strcmp(tag, "clusterset") == 0) 
2104        {
[228]2105            clusterSetNode(reader);
2106        }
2107        else if (strcmp(tag, "globalset")    == 0) { globalSetNode(reader); }
2108        else if (strcmp(tag, "vspaceset")    == 0) { vspaceSetNode(reader); }
2109        else if (strcmp(tag, "#text")        == 0) { }
2110        else if (strcmp(tag, "#comment")     == 0) { }
[253]2111        else if (strcmp(tag, "mapping_info") == 0) 
2112        {
[158]2113#if XML_PARSER_DEBUG
[228]2114            printf("end mapping_info\n");
[158]2115#endif
2116            return;
2117        }
[253]2118        else 
2119        {
[174]2120            printf("[XML ERROR] Unknown tag in header node : %s\n",tag);
[158]2121            exit(1);
2122        }
[181]2123        status = xmlTextReaderRead(reader);
[158]2124    }
2125} // end headerNode()
[228]2126
2127
[189]2128///////////////////////////////////////
[228]2129void BuildTable(int fdout, const char * type, unsigned int nb_elem,
[253]2130                unsigned int elem_size, char ** table) 
2131{
[181]2132    unsigned int i;
2133    // write element
[228]2134    for (i = 0; i < nb_elem; i++) {
2135        if (elem_size != write(fdout, table[i], elem_size)) {
[215]2136            printf("function %s: %s(%d) write  error \n", __FUNCTION__, type, i);
2137            exit(1);
2138        }
2139
[181]2140#if XML_PARSER_DEBUG
[228]2141        printf("Building binary: writing %s %d\n", type, i);
[181]2142#endif
[215]2143    }
2144}
[158]2145
[253]2146/////////////////////////////////////
2147int open_file(const char * file_path) 
2148{
[215]2149    //open file
[228]2150    int fdout = open( file_path, (O_CREAT | O_RDWR), (S_IWUSR | S_IRUSR) );
[253]2151    if (fdout < 0) 
2152    {
[215]2153        perror("open");
2154        exit(1);
[181]2155    }
[215]2156
[228]2157    //reinitialise the file
[253]2158    if (ftruncate(fdout, 0)) 
2159    {
[228]2160        perror("truncate");
2161        exit(1);
2162    }
[215]2163
[228]2164    //#if XML_PARSER_DEBUG
2165    printf("%s\n", file_path);
2166    //#endif
2167
[215]2168    return fdout;
[181]2169}
2170
[215]2171
[253]2172/////////////////////////////////////
2173void buildBin(const char * file_path) 
2174{
[228]2175    unsigned int length;
[158]2176
[215]2177    int fdout = open_file(file_path);
2178
[253]2179#if XML_PARSER_DEBUG
2180printf("Building map.bin for %s\n", header->name);
2181printf("signature = %x\n", header->signature);
2182printf("clusters  = %d\n", header->clusters);
2183printf("vspaces   = %d\n", header->vspaces);
2184printf("psegs     = %d\n", header->psegs);
2185printf("vobjs     = %d\n", header->vobjs);
2186printf("vsegs     = %d\n", header->vsegs);
2187printf("tasks     = %d\n", header->tasks);
2188printf("procs     = %d\n", header->procs);
2189printf("irqs      = %d\n", header->irqs);
2190printf("coprocs   = %d\n", header->coprocs);
2191printf("periphs   = %d\n", header->periphs);
2192#endif
2193
[158]2194    // write header to binary file
[228]2195    length = write(fdout, (char *) header, sizeof(mapping_header_t));
[253]2196    if (length != sizeof(mapping_header_t)) 
2197    {
[181]2198        printf("write header error : length = %d \n", length);
[158]2199        exit(1);
2200    }
2201
2202    // write clusters
[228]2203    BuildTable(fdout, "cluster", cluster_index, sizeof(mapping_cluster_t), (char **) cluster);
[158]2204    // write psegs
[228]2205    BuildTable(fdout, "pseg", pseg_index, sizeof(mapping_pseg_t), (char **) pseg);
[158]2206    // write vspaces
[228]2207    BuildTable(fdout, "vspace", vspace_index, sizeof(mapping_vspace_t), (char **) vspace);
[158]2208    // write vsegs
[228]2209    BuildTable(fdout, "vseg", vseg_index, sizeof(mapping_vseg_t), (char **) vseg);
[160]2210    // write vobjs
[228]2211    BuildTable(fdout, "vobj", vobj_index, sizeof(mapping_vobj_t), (char **) vobj);
[189]2212    // write tasks array
[228]2213    BuildTable(fdout, "task", task_index, sizeof(mapping_task_t), (char **) task);
[189]2214    //building procs array
[228]2215    BuildTable(fdout, "proc", proc_index, sizeof(mapping_proc_t), (char **) proc);
[189]2216    //building irqs array
[228]2217    BuildTable(fdout, "irq", irq_index, sizeof(mapping_irq_t), (char **) irq);
[189]2218    //building coprocs array
[228]2219    BuildTable(fdout, "coproc", coproc_index, sizeof(mapping_coproc_t), (char **) coproc);
[189]2220    //building cp_ports array
[228]2221    BuildTable(fdout, "cp_port", cp_port_index, sizeof(mapping_cp_port_t),(char **) cp_port);
[189]2222    //building periphs array
[228]2223    BuildTable(fdout, "periph", periph_index, sizeof(mapping_periph_t), (char **) periph);
2224
[215]2225    close(fdout);
[181]2226
2227} // end buildBin()
2228
[228]2229
[189]2230///////////////////////////////////////////////////////////////////////
2231// this function set the value the vobj_id fiels of all cp_ports
2232///////////////////////////////////////////////////////////////////////
[238]2233void prepareBuild() 
2234{
[181]2235    unsigned int i;
[200]2236    //asign for all cp_ports the correct vspaceid and vobjid
[228]2237    for (i = 0; i < cp_port_index; i++) {
2238        int vspace_id = getVspaceId(cp_port_vobj_ref[i]->vspace_name);
2239        if (vspace_id < 0) {
2240            printf("[XML ERROR] illegal  <vspacename> for cp_port %d,\n", i);
[181]2241            exit(1);
2242        }
2243        cp_port[i]->vspaceid = vspace_id;
[189]2244
[228]2245        int vobj_id = getVobjLocId(vspace_id, cp_port_vobj_ref[i]->vobj_name, vspace[vspace_id]->vobjs);
2246        if (vobj_id >= 0) {
2247
[158]2248#if XML_PARSER_DEBUG
[228]2249            printf("\ncp_port = %d\n", i);
2250            printf("      vspace_name  = %s\n", cp_port_vobj_ref[i]->vspace_name);
2251            printf("      vobj_name    = %s\n", cp_port_vobj_ref[i]->vobj_name);
2252            printf("      vobj_index   = %d\n", vobj_id);
[158]2253#endif
[232]2254            cp_port[i]->mwmr_vobjid = vobj_id;
[189]2255
2256            assert((vobj[ vspace[vspace_id]->vobj_offset + vobj_id]->type == VOBJ_TYPE_MWMR)
[228]2257                    && "coproc ports have to refer to a vobj of type MWMR");
[181]2258        }
[228]2259        else {
2260            printf("[XML ERROR] illegal  <vobjname> for cp_port %d,\n", i);
[158]2261            exit(1);
2262        }
2263    }
[181]2264}
[158]2265
[217]2266//////////////////////////////////////////
[238]2267void file_write(int fdout, char * towrite) 
2268{
[215]2269    unsigned int size = strlen(towrite);
[238]2270    if (size != write(fdout, towrite, size)) 
2271    {
[215]2272        printf("file_write error");
2273        exit(1);
2274    }
2275}
2276
[217]2277//////////////////////////////////////////////////
[238]2278void def_int_write(int fdout, char * def, int num) 
2279{
[228]2280    char  buf[64];
[215]2281    sprintf(buf, "#define\t %s  %d\n", def, num);
2282    file_write(fdout, buf);
2283}
2284
[238]2285//////////////////////////////////////////////////
2286void def_hex_write(int fdout, char * def, int num) 
2287{
[228]2288    char  buf[64];
[215]2289    sprintf(buf, "#define\t %s  0x%x\n", def, num);
2290    file_write(fdout, buf);
2291}
2292
[238]2293///////////////////////////////////
2294void  genHd(const char * file_path) 
2295{
[215]2296    int fdout = open_file(file_path);
2297
[253]2298    char prol[80];
2299    sprintf(prol, "/* Generated from file %s.xml */\n\n",header->name);
[238]2300
[253]2301    char * ifdef  = "#ifndef _HARD_CONFIG_H\n#define _HARDD_CONFIG_H\n\n";
2302    char * epil   = "\n#endif //_HARD_CONFIG_H";
2303
[215]2304    file_write(fdout, prol);
[238]2305    file_write(fdout, ifdef);
[215]2306
[238]2307    def_int_write(fdout, "CLUSTER_X         ", cluster_x);
2308    def_int_write(fdout, "CLUSTER_Y         ", cluster_y);
2309    def_int_write(fdout, "NB_CLUSTERS       ", cluster_index);
2310    def_int_write(fdout, "NB_PROCS_MAX      ", nb_proc_max);
2311    def_int_write(fdout, "NB_TASKS_MAX      ", nb_tasks_max);
[228]2312
[215]2313    file_write(fdout, "\n");
2314
[238]2315    def_int_write(fdout, "NB_TIM_CHANNELS   ", tim_channels);
2316    def_int_write(fdout, "NB_DMA_CHANNELS   ", dma_channels);
2317
2318    file_write(fdout, "\n");
2319
2320    def_int_write(fdout, "NB_TTY_CHANNELS   ", tty_channels);
2321    def_int_write(fdout, "NB_IOC_CHANNELS   ", ioc_channels);
2322    def_int_write(fdout, "NB_NIC_CHANNELS   ", nic_channels);
2323    def_int_write(fdout, "NB_CMA_CHANNELS   ", cma_channels);
2324
2325    file_write(fdout, "\n");
2326
[253]2327    def_int_write(fdout, "USE_XICU          ", use_xcu);
[249]2328    def_int_write(fdout, "USE_IOB           ", use_iob);
[238]2329
[215]2330    file_write(fdout, epil);
2331
2332    close(fdout);
2333}
2334
[217]2335////////////////////////////////////////////////////////
[238]2336void ld_write(int fdout, char * seg, unsigned int addr) 
2337{
[228]2338    char buf[64];
[215]2339    sprintf(buf, "%s = 0x%x;\n", seg, addr);
2340    file_write(fdout, buf);
2341}
2342
[238]2343//////////////////////////////////
2344void genLd(const char * file_path) 
2345{
2346    int          fdout = open_file(file_path);
2347    unsigned int count = 0;
2348    unsigned int vseg_id;
[228]2349
[253]2350    char prol[80];
2351    sprintf(prol, "/* Generated from file %s.xml */\n\n",header->name);
2352
[215]2353    file_write(fdout, prol);
2354
[238]2355    // boot and kernel segments
2356    for (vseg_id = 0 ; vseg_id < header->vsegs ; vseg_id++)
2357    {
2358        if ( strcmp(vseg[vseg_id]->name, "seg_boot_code") == 0 )
2359        {
2360            ld_write(fdout, "seg_boot_code_base      ",  vseg[vseg_id]->vbase);
2361            count++;
2362        }
[245]2363        else if ( strcmp(vseg[vseg_id]->name, "seg_boot_data") == 0 )
2364        {
2365            ld_write(fdout, "seg_boot_data_base      ",  vseg[vseg_id]->vbase);
2366            count++;
2367        }
[238]2368        else if ( strcmp(vseg[vseg_id]->name, "seg_boot_stack") == 0 )
2369        {
2370            ld_write(fdout, "seg_boot_stack_base     ",  vseg[vseg_id]->vbase);
2371            count++;
2372        }
2373        else if ( strcmp(vseg[vseg_id]->name, "seg_boot_mapping") == 0 )
2374        {
2375            ld_write(fdout, "seg_mapping_base        ",  vseg[vseg_id]->vbase);
2376            count++;
2377        }
2378        else if ( strcmp(vseg[vseg_id]->name, "seg_kernel_code") == 0 )
2379        {
2380            ld_write(fdout, "seg_kernel_code_base    ",  vseg[vseg_id]->vbase);
2381            count++;
2382        }
2383        else if ( strcmp(vseg[vseg_id]->name, "seg_kernel_data") == 0 )
2384        {
2385            ld_write(fdout, "seg_kernel_data_base    ",  vseg[vseg_id]->vbase);
2386            count++;
2387        }
2388        else if ( strcmp(vseg[vseg_id]->name, "seg_kernel_uncdata") == 0 )
2389        {
2390            ld_write(fdout, "seg_kernel_uncdata_base ",  vseg[vseg_id]->vbase);
2391            count++;
2392        }
2393        else if ( strcmp(vseg[vseg_id]->name, "seg_kernel_init") == 0 )
2394        {
2395            ld_write(fdout, "seg_kernel_init_base    ",  vseg[vseg_id]->vbase);
2396            count++;
2397        }
2398    }
[245]2399    if ( count != 8 )
[238]2400    { 
2401        printf ("[XML ERROR] Missing Boot or Kernel vseg : only %d\n", count);
2402        printf ("Mandatory segments are :\n");
2403        printf (" - seg_boot_code\n");
[245]2404        printf (" - seg_boot_data\n");
[238]2405        printf (" - seg_boot_stack\n");
2406        printf (" - seg_boot_mapping\n");
2407        printf (" - seg_kernel_code\n");
2408        printf (" - seg_kernel_data\n");
2409        printf (" - seg_kernel_uncdata\n");
2410        printf (" - seg_kernel_init\n");
2411    }
[215]2412
[238]2413    file_write(fdout, "\n");
[215]2414
[253]2415    // fill the peripheral base address array
2416    set_periph_vbase_array();
2417
[238]2418    // non replicated peripherals
[249]2419    ld_write(fdout, "seg_cma_base            ",   periph_vbase_array[PERIPH_TYPE_CMA]);
[238]2420    ld_write(fdout, "seg_ioc_base            ",   periph_vbase_array[PERIPH_TYPE_IOC]);
[249]2421    ld_write(fdout, "seg_tty_base            ",   periph_vbase_array[PERIPH_TYPE_TTY]);
2422    ld_write(fdout, "seg_fbf_base            ",   periph_vbase_array[PERIPH_TYPE_FBF]);
[238]2423    ld_write(fdout, "seg_nic_base            ",   periph_vbase_array[PERIPH_TYPE_NIC]);
[249]2424    ld_write(fdout, "seg_iob_base            ",   periph_vbase_array[PERIPH_TYPE_IOB]);
[238]2425    ld_write(fdout, "seg_gcd_base            ",   periph_vbase_array[PERIPH_TYPE_GCD]);
[215]2426
[238]2427    file_write(fdout, "\n");
2428
2429    // replicated peripherals
[253]2430    ld_write(fdout, "seg_xcu_base            ",   periph_vbase_array[PERIPH_TYPE_XCU]);
[238]2431    ld_write(fdout, "seg_icu_base            ",   periph_vbase_array[PERIPH_TYPE_ICU]);
[249]2432    ld_write(fdout, "seg_tim_base            ",   periph_vbase_array[PERIPH_TYPE_TIM]);
[238]2433    ld_write(fdout, "seg_dma_base            ",   periph_vbase_array[PERIPH_TYPE_DMA]);
[249]2434    ld_write(fdout, "seg_mmc_base            ",   periph_vbase_array[PERIPH_TYPE_MMC]);
[238]2435
[253]2436    file_write(fdout, "\n");
2437
2438    ld_write(fdout, "vseg_cluster_increment  ",   header->increment);
2439
[215]2440    close(fdout);
2441}
2442
[238]2443//////////////////////////////////////////////////////
2444char * buildPath(const char * path, const char * name) 
2445{
[222]2446    char * res = calloc(strlen(path) + strlen(name) + 1, 1);
[215]2447    strcat(res, path);
2448    strcat(res, "/");
2449    strcat(res, name);
2450    return res; 
2451}
2452
[228]2453
[238]2454//////////////////////////////////
2455int main(int argc, char * argv[]) 
2456{
[228]2457    if (argc < 3) {
[215]2458        printf("Usage: xml2bin <input_file_path> <output_path>\n");
[158]2459        return 1;
2460    }
2461
[215]2462    struct stat dir_st;
[228]2463    if (stat( argv[2], &dir_st)) {
[215]2464        perror("bad path");
[158]2465        exit(1);
2466    }
[215]2467
[228]2468    if ((dir_st.st_mode & S_IFDIR) == 0) {
[215]2469        printf("path is not a dir: %s", argv[2] );
2470        exit(1);
2471    }
2472
[228]2473    char * map_path = buildPath(argv[2], "map.bin"); 
2474    char * ld_path = buildPath(argv[2], "giet_vsegs.ld"); 
2475    char * hd_path = buildPath(argv[2], "hard_config.h"); 
2476
[158]2477    LIBXML_TEST_VERSION;
2478
[181]2479    int status;
[228]2480    xmlTextReaderPtr reader = xmlReaderForFile(argv[1], NULL, 0);
[158]2481
[253]2482    if (reader != NULL) 
2483    {
[228]2484        status = xmlTextReaderRead (reader);
[253]2485        while (status == 1) 
2486        {
[228]2487            const char * tag = (const char *) xmlTextReaderConstName(reader);
[181]2488
[253]2489            if (strcmp(tag, "mapping_info") == 0) 
2490            { 
[228]2491                headerNode(reader);
[181]2492                prepareBuild();
[228]2493                buildBin(map_path);
[215]2494                genHd(hd_path);
2495                genLd(ld_path);
[158]2496            }
[253]2497            else 
2498            {
[158]2499                printf("[XML ERROR] Wrong file type: \"%s\"\n", argv[1]);
2500                return 1;
2501            }
[228]2502            status = xmlTextReaderRead(reader);
[158]2503        }
[228]2504        xmlFreeTextReader(reader);
[158]2505
[253]2506        if (status != 0) 
2507        {
[158]2508            printf("[XML ERROR] Wrong Syntax in \"%s\" file\n", argv[1]);
2509            return 1;
2510        }
2511    }
2512    return 0;
2513} // end main()
[222]2514
2515
[228]2516// Local Variables:
2517// tab-width: 4
2518// c-basic-offset: 4
2519// c-file-offsets:((innamespace . 0)(inline-open . 0))
2520// indent-tabs-mode: nil
2521// End:
2522// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
[222]2523
Note: See TracBrowser for help on using the repository browser.