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

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

ntroducing the TOTAL_PROCS variable in the hard_config.h file
(used by the synchronisation barrier in kernel_init.c)

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