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

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

Modification on giet_xml parser and driver:

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