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

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

Removing the use_tty, use_nic, use_tim, use_cma, etc.) in the mapping.
These static constructs are replaced by new system calls in the stdio library.

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