source: soft/giet_vm/giet_xml/xml_parser.c @ 286

Last change on this file since 286 was 281, checked in by cfuguet, 10 years ago

Modifications in GIET_VM:

  • Supporting platforms with more than one IRQ per processor from the XICU.

When this is the case, the IRQ per processor can be signalled
by the XCU peripheric number of channels on the XML file.

The xml_parser will generate a constant on the hard_config.h
file, called IRQ_PER_PROCESSOR and this constant will be use
by the GIET_VM to create accordingly the irq masks on the
ICU

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