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

Last change on this file since 268 was 267, checked in by cfuguet, 10 years ago
  • Adding new task context information: THREAD INDEX.

This value can be accessed by USER applications to get the
thread index of the current task. This thread index
corresponds to the index in a vspace.

The value of this index can be forced in the vspace part
of the XML description file using the trdid field in the
task description. When this value is missing, for each
task, a value from 0 to N-1 will be assigned, where N is
the number of task in the vspace.

The user application access this value through the
giet_thread_id() function defined in the stdio library
which uses the SYSCALL_THREAD_ID to access the task
context information.

  • Supporting mono TTY platforms

When the GIET_MONO_TTY constant defined in the giet_config
file, contains a value different than 0, all tasks will
share the TTY[0]. If this is the case, in the stdio
library, the giet_tty_printf() function will take the TTY
hardware lock before writing

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