source: branch/giet_vm_ioc_drivers/giet_xml/xml_parser.c @ 283

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

Introducing branch to test ioc drivers before merging on trunk

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