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

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