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

Last change on this file since 363 was 363, checked in by alain, 10 years ago

Remove the seg_boot_buffer.

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