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

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

Introducing a major release, to suppoort the tsar_generic_leti platform
and the various (external or internal) peripherals configurations.
The map.xml format has been modified, in order to support the new
vci_iopic componentand a new policy for peripherals initialisation.
The IRQs are nom described in the XICU and IOPIC components
(and not anymore in the processors).
To enforce this major change, the map.xml file signature changed:
The signature value must be: 0xDACE2014

This new release has been tested on the tsar_generic_leti platform
for the following mappings:

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