source: soft/giet_vm/xml/xml_parser.c @ 231

Last change on this file since 231 was 231, checked in by joannou, 11 years ago
  • Bugfix in Interruption mechanism :
    • _it_mask() and _it_restore() functions now share a global array indexed by the proc_id (used a simple global variable before => problem with multiproc)
    • added 2 new fuctions _it_enable() and _it_disable() that only affect the IE bit of the status register in COP0
    • replaced interrupt masking/restoring arround _ctx_switch() in sys_handler by a simple interrupt disabling before the call to _ctx_switch (restoring after a _ctx_switch wouldn't restore the correct task's status register)
    • replaced the use of _ctx_switch in _exit() by a call to _context_switch() (this function actually does the interrupt disabling)
  • Added some comments in the ctx_handler.h
  • Added the delay reset in the idle task (ctx_handler.c)
  • Added a new irq type (PTI)
    • Modifications in xml_parser.c to accept PTI irq type (now used in xml mappings)
    • Added the test on the irq type in the _irq_demux() function. This leads to a different argument passed to the ISR (i.e. either channel_id or irq_id (aka icuid) )
File size: 64.2 KB
RevLine 
[158]1///////////////////////////////////////////////////////////////////////////////////////
2// File     : xml_parser.c
[181]3// Date     : 14/04/2012
[158]4// Author   : alain greiner
5// Copyright (c) UPMC-LIP6
6///////////////////////////////////////////////////////////////////////////////////////
[217]7// This program translate a "map.xml" source file to a binary file "map.bin" that
8// can be directly loaded in the boot ROM 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 program also generates the "hard_config.h" and the "giet_vsegs.ld" files,
17// required  to compile the GIET-VM code.
[158]18///////////////////////////////////////////////////////////////////////////////////////
19
20#include  <stdlib.h>
21#include  <fcntl.h>
[162]22#include  <sys/types.h>
23#include  <sys/stat.h>
[158]24#include  <unistd.h>
25#include  <stdio.h>
26#include  <string.h>
[181]27#include  <assert.h>
[158]28#include  <libxml/xmlreader.h>
29#include  <mapping_info.h>
[189]30#include  <irq_handler.h>
[158]31
[228]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
[158]44
[228]45#define XML_PARSER_DEBUG  0
[158]46
47///////////////////////////////////////////////////////////////////////////////////
[228]48//     global variables used to store and index the data structures
[158]49///////////////////////////////////////////////////////////////////////////////////
50
[228]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
[158]63
[189]64// Index for the various arrays
[181]65
[228]66unsigned int cluster_index  = 0;
67unsigned int vspace_index = 0;
68unsigned int global_index = 0;
69unsigned int pseg_index = 0;       
[181]70
[228]71unsigned int proc_index = 0;
72unsigned int proc_loc_index = 0;
[181]73
[228]74unsigned int irq_index = 0;
75unsigned int irq_loc_index  = 0;
[181]76
[228]77unsigned int coproc_index = 0;
78unsigned int coproc_loc_index = 0;
[181]79
[228]80unsigned int cp_port_index = 0;
81unsigned int cp_port_loc_index = 0;
[181]82
[228]83unsigned int periph_index = 0;
84unsigned int periph_loc_index = 0;
[181]85
[228]86unsigned int vseg_index = 0;
87unsigned int vseg_loc_index = 0;
[189]88
[228]89unsigned int task_index = 0;
90unsigned int task_loc_index = 0;
[189]91
[228]92unsigned int vobj_index = 0;
93unsigned int vobj_loc_index = 0;
94unsigned int vobj_count = 0;
[165]95
[215]96
97/////////////////////////
98// found peripheral
99/////////////////////////
100char found_timer = 0;
101char found_icu = 0;
102char found_xicu = 0;
103char found_dma = 0;
104
105
106//////////////////////////////////
107//needed to generate map_config.ld
108//////////////////////////////////
[228]109unsigned int cluster_y            = 0;
110unsigned int cluster_x            = 0; 
111unsigned int nb_proc_max          = 0; // max number of processors per cluster
112unsigned int nb_timer_channel_max = 0; // max number of user timer
113unsigned int nb_dma_channel_max   = 0;
114unsigned int nb_tty_channel       = 0;
115unsigned int nb_ioc_channel       = 0;
116unsigned int nb_nic_channel       = 0;
117unsigned int io_mmu_active        = 0;
118unsigned int use_xicu             = 0xFFFFFFFF;
[215]119
120
121//////////////////////////////////
122//needed to generate giet_vseg.ld
123//////////////////////////////////
124
125//kernel and boot code
[228]126unsigned int kernel_code_base    = 0x80000000; /* kernel code */
127unsigned int kernel_data_base    = 0x80010000; /* system cacheable data */
128unsigned int kernel_uncdata_base = 0x80080000; /* system uncacheable data */
129unsigned int kernel_init_base    = 0x80090000; /* system init entry */ 
[215]130
[228]131unsigned int boot_code_base      = 0xBFC00000; /* boot code */
132unsigned int boot_stack_base     = 0xBFC08000; /* boot temporary stack */ 
133unsigned int boot_mapping_base   = 0xBFC0C000; /* mapping_info blob */
[215]134
135//periphs
136unsigned int tim_base_offset = 0xFFFFFFFF;
137unsigned int tty_base_offset = 0xFFFFFFFF;
138unsigned int dma_base_offset = 0xFFFFFFFF;
139unsigned int ioc_base_offset = 0xFFFFFFFF;
[218]140unsigned int nic_base_offset = 0xFFFFFFFF;
[215]141unsigned int fbf_base_offset = 0xFFFFFFFF;
142unsigned int icu_base_offset = 0xFFFFFFFF;
143unsigned int gcd_base_offset = 0xFFFFFFFF;
144unsigned int iob_base_offset = 0xFFFFFFFF;
145
146
147//////////////////////////////////////////////////////////////////////
[189]148// This arrray is useful to build a temporary list of vobj references.
149// The struct vobj_ref_s is formed by a vspace_name and a vobj_name.
150// This array is used to set the attribute vobj_id of a cp_port
151// once all the vspace have been parsed.
[215]152/////////////////////////////////////////////////////////////////////
[228]153typedef struct vobj_ref_s {
[189]154    char vspace_name[32];
155    char vobj_name[32];
[228]156} vobj_ref_t;
[189]157
[228]158vobj_ref_t * cp_port_vobj_ref[MAX_CP_PORTS];   
[189]159
160
[158]161//////////////////////////////////////////////////
[228]162unsigned int getIntValue(xmlTextReaderPtr reader, const char * attributeName, unsigned int * ok) {
163    unsigned int value = 0;
164    unsigned int i;
165    char c;
[158]166
[228]167    char * string = (char *) xmlTextReaderGetAttribute(reader, (const xmlChar *) attributeName);
[158]168
[228]169    if (string == NULL) {
170        // missing argument
[158]171        *ok = 0;
172        return 0;
173    }
[228]174    else {
175        if ((string[0] == '0') && ((string[1] == 'x') || (string[1] == 'X'))) {
176            // Hexa
177            for (i = 2 ; (string[i] != 0) && (i < 10) ; i++) {
[158]178                c = string[i];
[228]179                if      ((c >= '0') && (c <= '9')) { value = (value << 4) + string[i] - 48; }
180                else if ((c >= 'a') && (c <= 'f')) { value = (value << 4) + string[i] - 87; }
181                else if ((c >= 'A') && (c <= 'F')) { value = (value << 4) + string[i] - 55; }
182                else {
[158]183                    *ok = 0;
184                    return 0;
185                }
186            }
187        }
[228]188        else {
189            // Decimal
190            for (i = 0; (string[i] != 0) && (i < 9); i++) {
[158]191                c = string[i];
[228]192                if ((c >= '0') && (c <= '9')) value = (value * 10) + string[i] - 48;
193                else {
[158]194                    *ok = 0;
195                    return 0;
196                }
197            }
198        }
199        *ok = 1;
200        return value; 
201    }
202} // end getIntValue()
203
[228]204
[158]205///////////////////////////////////////////////
[228]206char * getStringValue(xmlTextReaderPtr reader, const char * attributeName, unsigned int * ok) {
207    char * string = (char *) xmlTextReaderGetAttribute(reader, (const xmlChar *) attributeName);
[158]208
[228]209
210    if (string == NULL) {
211        // missing argument
[158]212        *ok = 0;
213        return NULL;
214    }
[228]215    else {
[215]216        //we read only string smaller than 32 byte
[228]217        if (strlen(string) > 32) {
[215]218            printf("[XML ERROR] all strings must be less than 32 bytes\n");
219            exit(1);
220        }
221
[158]222        *ok = 1;
223        return string;
224    }
225} // end getStringValue()
226
[228]227
[181]228///////////////////////////////////////
[228]229int getPsegId(unsigned int cluster_id, char * pseg_name) {
[158]230    unsigned int pseg_id;
[181]231    unsigned int pseg_min = cluster[cluster_id]->pseg_offset;
232    unsigned int pseg_max = pseg_min + cluster[cluster_id]->psegs;
[158]233
[228]234    for (pseg_id = pseg_min; pseg_id < pseg_max; pseg_id++) {
235        if (strcmp(pseg[pseg_id]->name, pseg_name) == 0) {
[215]236            return pseg_id;
237        }
[158]238    }
239    return -1;
240}
241
[228]242
[181]243////////////////////////////////////////////
[228]244int getVspaceId(char * vspace_name) {
[181]245    unsigned int vspace_id;
246
[228]247    for (vspace_id = 0; vspace_id < vspace_index; vspace_id++) {
248        if (!strcmp(vspace[vspace_id]->name, vspace_name)) {
[181]249            return vspace_id;
250        }
251    }
252    return -1;
253}
254
[228]255
[181]256////////////////////////////////////////////
[228]257int getVobjLocId(unsigned int vspace_id, char * vobj_name, unsigned int vspace_max) {
[160]258    unsigned int vobj_id;
259    unsigned int vobj_min = vspace[vspace_id]->vobj_offset;
[181]260    unsigned int vobj_max = vobj_min + vspace_max;
[158]261
[228]262    for (vobj_id = vobj_min; vobj_id < vobj_max; vobj_id++) {
263        if (strcmp(vobj[vobj_id]->name, vobj_name) == 0) {
264            return (vobj_id - vobj_min);
[160]265        }
[158]266    }
267    return -1;
268}
269
[228]270
[181]271/////////////////////////////////////////
[228]272void taskNode(xmlTextReaderPtr reader) {
273    unsigned int ok;
274    unsigned int value;
275    char * str;
[181]276
[228]277    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) {
278        return;
279    }
[181]280
[228]281    if (task_index >= MAX_TASKS) {
[158]282        printf("[XML ERROR] The number of tasks is larger than %d\n", MAX_TASKS);
283    }
284
285#if XML_PARSER_DEBUG
[228]286    printf("   task %d\n", task_loc_index);
[158]287#endif
288
[228]289    task[task_index] = (mapping_task_t *) malloc(sizeof(mapping_task_t));
[158]290
291    ////////// get name attribute
292    str = getStringValue(reader, "name", &ok);
[228]293    if (ok) {
[158]294#if XML_PARSER_DEBUG
[228]295        printf("      name = %s\n", str);
[158]296#endif
297        strncpy( task[task_index]->name, str, 31 );
298    }
[228]299    else {
[158]300        printf("[XML ERROR] illegal or missing <name> attribute for task (%d,%d)\n", 
[228]301                vspace_index, task_loc_index);
[158]302        exit(1);
303    }
304
305    ///////// get clusterid attribute
[228]306    value = getIntValue(reader, "clusterid", &ok);
307    if (ok) {
[158]308#if XML_PARSER_DEBUG
[228]309        printf("      clusterid = %x\n", value);
[158]310#endif
[228]311        if (value >= header->clusters) {
[165]312            printf("[XML ERROR] <clusterid> too large for task (%d,%d)\n",
[228]313                    vspace_index, task_loc_index);
[165]314            exit(1);
315        }
[158]316        task[task_index]->clusterid = value;
317    } 
[228]318    else {
[158]319        printf("[XML ERROR] illegal or missing <clusterid> attribute for task (%d,%d)\n",
[228]320                vspace_index, task_loc_index);
[158]321        exit(1);
322    }
323
324    ////////// get proclocid attribute
[228]325    value = getIntValue(reader, "proclocid", &ok);
326    if (ok) {
[158]327#if XML_PARSER_DEBUG
[228]328        printf("      proclocid = %x\n", value);
[158]329#endif
[228]330        if (value >= cluster[task[task_index]->clusterid]->procs) {
[165]331            printf("[XML ERROR] <proclocid> too large for task (%d,%d)\n",
[228]332                    vspace_index, task_loc_index);
[165]333            exit(1);
334        }
[158]335        task[task_index]->proclocid = value;
336    } 
[228]337    else {
[158]338        printf("[XML ERROR] illegal or missing <locprocid> attribute for task (%d,%d)\n", 
339                vspace_index, task_loc_index);
340        exit(1);
341    }
342
343    ////////// get stackname attribute
344    str = getStringValue(reader, "stackname" , &ok);
[228]345    if (ok) {
346        int index = getVobjLocId(vspace_index, str , vobj_loc_index);
347        if (index >= 0) {
[158]348#if XML_PARSER_DEBUG
[228]349            printf("      stackname = %s\n", str);
350            printf("      stackid   = %d\n", index);
[158]351#endif
[160]352            task[task_index]->vobjlocid = index;
[158]353        }
[228]354        else {
[165]355            printf("[XML ERROR] illegal or missing <stackname> for task (%d,%d)\n", 
356                    vspace_index, task_loc_index);
[158]357            exit(1);
358        }
359    } 
[228]360    else {
[165]361        printf("[XML ERROR] illegal or missing <stackname> for task (%d,%d)\n", 
[158]362                vspace_index, task_loc_index);
363        exit(1);
364    }
365
366    ////////// get startid  attribute
[228]367    value = getIntValue(reader, "startid", &ok);
368    if (ok) {
[158]369#if XML_PARSER_DEBUG
[228]370        printf("      startid = %x\n", value);
[158]371#endif
372        task[task_index]->startid = value;
373    } 
[228]374    else {
[158]375        printf("[XML ERROR] illegal or missing <startid> attribute for task (%d,%d)\n", 
376                vspace_index, task_loc_index);
377        exit(1);
378    }
379
[189]380    /////////// get usetty  attribute (optionnal : 0 if missing)
[228]381    value = getIntValue(reader, "usetty", &ok);
382    if (ok) {
[158]383#if XML_PARSER_DEBUG
[228]384        printf("      usetty = %x\n", value);
[158]385#endif
[165]386        task[task_index]->use_tty = value;
[158]387    } 
[228]388    else {
[165]389        task[task_index]->use_tty = 0;
390    }
391
[189]392    /////////// get usenic  attribute (optionnal : 0 if missing)
[228]393    value = getIntValue(reader, "usenic", &ok);
394    if (ok) {
[165]395#if XML_PARSER_DEBUG
[228]396        printf("      usenic = %x\n", value);
[165]397#endif
[189]398        task[task_index]->use_nic = value;
[165]399    } 
[228]400    else {
[189]401        task[task_index]->use_nic = 0;
[158]402    }
403
[189]404    /////////// get usetimer attribute (optionnal : 0 if missing)
[228]405    value = getIntValue(reader, "usetimer", &ok);
406    if (ok) {
[189]407#if XML_PARSER_DEBUG
[228]408        printf("      usetimer = %x\n", value);
[189]409#endif
410        task[task_index]->use_timer = value;
411    } 
[228]412    else {
[189]413        task[task_index]->use_timer = 0;
414    }
415
416    /////////// get usefbdma  attribute (optionnal : 0 if missing)
[228]417    value = getIntValue(reader, "usefbdma", &ok);
418    if (ok) {
[189]419#if XML_PARSER_DEBUG
[228]420        printf("      usefbdma = %x\n", value);
[189]421#endif
422        task[task_index]->use_fbdma = value;
[228]423    }
424    else {
[189]425        task[task_index]->use_fbdma = 0;
426    }
427
[158]428    task_index++;
429    task_loc_index++;
430} // end taskNode()
431
[228]432
[165]433//////////////////////////////////////////
[228]434void vobjNode(xmlTextReaderPtr reader) {
435    unsigned int ok;
436    unsigned int value;
437    char * str;
[160]438
[228]439    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) {
440        return;
441    }
[160]442
[228]443    if (vobj_index >= MAX_VOBJS) {
[160]444        printf("[XML ERROR] The number of vobjs is larger than %d\n", MAX_VSEGS);
445        exit(1);
446    }
447
448#if XML_PARSER_DEBUG
[228]449    printf("      vobj %d\n", vobj_loc_index);
[160]450#endif
451
[228]452    vobj[vobj_index] = (mapping_vobj_t *) malloc(sizeof(mapping_vobj_t));
[160]453
454    ///////// get name attribute
455    str = getStringValue(reader, "name", &ok);
[228]456    if (ok) {
[160]457#if XML_PARSER_DEBUG
[228]458        printf("        name = %s\n", str);
[160]459#endif
[228]460        strncpy(vobj[vobj_index]->name, str, 31);
[160]461    }
[228]462    else {
[160]463        printf("[XML ERROR] illegal or missing <name> attribute for vobj (%d,%d)\n", 
464                vseg_index, vobj_loc_index);
465        exit(1);
466    }
467
[165]468    //////// get type attribute
[182]469    str = getStringValue(reader, "type", &ok);
[160]470#if XML_PARSER_DEBUG
[228]471    printf("        type = %s\n", str);
[160]472#endif
[228]473    if (ok && (strcmp(str, "ELF") == 0)) {
[165]474        vobj[vobj_index]->type = VOBJ_TYPE_ELF;
475
476        //check that this vobj is the first in vseg
[228]477        if (vobj_count != 0) {
[165]478            printf("[XML ERROR] an ELF vobj must be alone in a vseg (%d,%d)\n", 
479                    vspace_index, vobj_loc_index);
[160]480            exit(1);
481        }
482    }
[228]483    else if (ok && (strcmp(str, "BLOB")     == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_BLOB; }
484    else if (ok && (strcmp(str, "PTAB")     == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_PTAB; }
485    else if (ok && (strcmp(str, "PERI")     == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_PERI; }
486    else if (ok && (strcmp(str, "MWMR")     == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_MWMR; }
487    else if (ok && (strcmp(str, "LOCK")     == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_LOCK; }
488    else if (ok && (strcmp(str, "BUFFER")   == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_BUFFER; }
489    else if (ok && (strcmp(str, "BARRIER")  == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_BARRIER; }
490    else if (ok && (strcmp(str, "CONST")    == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_CONST; }
491    else if (ok && (strcmp(str, "MEMSPACE") == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_MEMSPACE; }
492    else {
[160]493        printf("[XML ERROR] illegal or missing <type> attribute for vobj (%d,%d)\n", 
[165]494                vspace_index, vobj_loc_index);
[160]495        exit(1);
496    }
497
[165]498    ////////// get length attribute
[228]499    value = getIntValue(reader, "length", &ok);
500    if (ok) {
[160]501#if XML_PARSER_DEBUG
[228]502        printf("        length = %d\n", value);
[160]503#endif
504        vobj[vobj_index]->length = value;
505    } 
[228]506    else {
[165]507        printf("[XML ERROR] illegal or missing <length> attribute for vobj (%d,%d)\n", 
508                vspace_index, vobj_loc_index);
509        exit(1);
[160]510    }
511
[165]512    ////////// get align attribute (optional : 0 if missing)
[228]513    value = getIntValue(reader, "align", &ok);
514    if (ok) {
[160]515#if XML_PARSER_DEBUG
[228]516        printf("        align = %d\n", value);
[160]517#endif
518        vobj[vobj_index]->align = value;
519    } 
[228]520    else {
[160]521        vobj[vobj_index]->align = 0;
522    }
523
[165]524    ////////// get binpath attribute (optional : '\0' if missing)
[160]525    str = getStringValue(reader, "binpath", &ok);
[228]526    if (ok) {
[160]527#if XML_PARSER_DEBUG
[228]528        printf("        binpath = %s\n", str);
[160]529#endif
530        strncpy(vobj[vobj_index]->binpath, str, 63);
531    } 
[228]532    else {
[160]533        vobj[vobj_index]->binpath[0] = '\0';
534    }
[228]535
[175]536    ////////// get init attribute (mandatory for mwmr and barrier)
[228]537    value = getIntValue(reader, "init", &ok);
538    if (ok) {
[165]539#if XML_PARSER_DEBUG
[228]540        printf("        init  = %d\n", value);
[165]541#endif
542        vobj[vobj_index]->init = value;
543    } 
[228]544    else {
545        if ((vobj[vobj_index]->type == VOBJ_TYPE_MWMR) || 
546                (vobj[vobj_index]->type == VOBJ_TYPE_BARRIER) ||
547                (vobj[vobj_index]->type == VOBJ_TYPE_CONST)) {
[181]548            printf("[XML ERROR] illegal or missing <value> attribute for vobj (%d,%d). \
[228]549                    All MWMR or BARRIER vobj must have a init value \n", 
[181]550                    vspace_index, vobj_loc_index);
[175]551            exit(1);
552        }
[181]553        vobj[vobj_index]->init = 0;
[165]554    }
555
[160]556    vobj_index++;
[165]557    vobj_count++;
[160]558    vobj_loc_index++;
[165]559} // end vobjNode()
[160]560
[228]561
[165]562//////////////////////////////////////////
[228]563void vsegNode(xmlTextReaderPtr reader) {
564    unsigned int ok;
565    unsigned int value;
566    char * str;
[158]567
[228]568    vobj_count = 0;
[165]569
[228]570    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) {
571        return;
572    }
[158]573
[228]574    if (vseg_index >= MAX_VSEGS) {
[158]575        printf("[XML ERROR] The number of vsegs is larger than %d\n", MAX_VSEGS);
576        exit(1);
577    }
578
579#if XML_PARSER_DEBUG
[228]580    printf("    vseg %d\n", vseg_loc_index);
[158]581#endif
582
[228]583    vseg[vseg_index] = (mapping_vseg_t *) malloc(sizeof(mapping_vseg_t));
584
[160]585    ////////// set vobj_offset attributes
586    vseg[vseg_index]->vobj_offset = vobj_index;
587#if XML_PARSER_DEBUG
[228]588    printf("      vobj_offset = %d\n", vobj_index);
[160]589#endif
[158]590
591    ///////// get name attribute
592    str = getStringValue(reader, "name", &ok);
[228]593    if (ok) {
[158]594#if XML_PARSER_DEBUG
[228]595        printf("      name = %s\n", str);
[158]596#endif
597        strncpy( vseg[vseg_index]->name, str, 31);
598    }
[228]599    else {
[158]600        printf("[XML ERROR] illegal or missing <name> attribute for vseg (%d,%d)\n", 
601                vspace_index, vseg_loc_index);
602        exit(1);
603    }
604
[203]605    ////////// get ident attribute (optional : 0 if missing)
[228]606    value = getIntValue(reader, "ident", &ok);
607    if (ok) {
[203]608#if XML_PARSER_DEBUG
[228]609        printf("      ident = %d\n", value);
[203]610#endif
611        vseg[vseg_index]->ident = value;
612    } 
[228]613    else {
[203]614        vseg[vseg_index]->ident = 0;
615    }
616
[158]617    /////////// get vbase attribute
[228]618    value = getIntValue(reader, "vbase", &ok);
619    if (ok) {
[158]620#if XML_PARSER_DEBUG
[228]621        printf("      vbase = 0x%x\n", value);
[158]622#endif
623        vseg[vseg_index]->vbase = value;
624    }
[228]625    else {
[158]626        printf("[XML ERROR] illegal or missing <vbase> attribute for vseg (%d,%d)\n", 
627                vspace_index, vseg_loc_index);
628        exit(1);
629    }
630
[181]631    ////////// get clusterid and psegname attributes
[228]632    value = getIntValue(reader, "clusterid", &ok);
633    if (ok == 0) {
[181]634        printf("[XML ERROR] illegal or missing <clusterid> for vseg %d\n", 
[228]635                vseg_loc_index);
[181]636        exit(1);
637    }
[228]638    str = getStringValue(reader, "psegname", &ok);
639    if (ok == 0) {
[181]640        printf("[XML ERROR] illegal or missing <psegname> for vseg %d\n", 
[228]641                vseg_loc_index);
[181]642        exit(1);
643    }
644
645    /////////// set psegid field
[228]646    int index = getPsegId(value, str);
647    if (index >= 0) {
[181]648#if XML_PARSER_DEBUG
[228]649        printf("      clusterid = %d\n", value);
650        printf("      psegname  = %s\n", str);
651        printf("      psegid    = %d\n", index);
[181]652#endif
653        vseg[vseg_index]->psegid = index;
654    }
[228]655    else {
[181]656        printf("[XML ERROR] pseg not found for vseg %d / clusterid = %d / psegname = %s\n", 
[228]657                vseg_loc_index, value, str );
[181]658        exit(1);
659    } 
660
[165]661    //////// get mode attribute
[228]662    str = getStringValue(reader, "mode", &ok);
[158]663#if XML_PARSER_DEBUG
[228]664    printf("      mode = %s\n", str);
[158]665#endif
[228]666    if      (ok && (strcmp(str, "CXWU") == 0)) { vseg[vseg_index]->mode = 0xF; }
667    else if (ok && (strcmp(str, "CXW_") == 0)) { vseg[vseg_index]->mode = 0xE; }
668    else if (ok && (strcmp(str, "CX_U") == 0)) { vseg[vseg_index]->mode = 0xD; }
669    else if (ok && (strcmp(str, "CX__") == 0)) { vseg[vseg_index]->mode = 0xC; }
670    else if (ok && (strcmp(str, "C_WU") == 0)) { vseg[vseg_index]->mode = 0xB; }
671    else if (ok && (strcmp(str, "C_W_") == 0)) { vseg[vseg_index]->mode = 0xA; }
672    else if (ok && (strcmp(str, "C__U") == 0)) { vseg[vseg_index]->mode = 0x9; }
673    else if (ok && (strcmp(str, "C___") == 0)) { vseg[vseg_index]->mode = 0x8; }
674    else if (ok && (strcmp(str, "_XWU") == 0)) { vseg[vseg_index]->mode = 0x7; }
675    else if (ok && (strcmp(str, "_XW_") == 0)) { vseg[vseg_index]->mode = 0x6; }
676    else if (ok && (strcmp(str, "_X_U") == 0)) { vseg[vseg_index]->mode = 0x5; }
677    else if (ok && (strcmp(str, "_X__") == 0)) { vseg[vseg_index]->mode = 0x4; }
678    else if (ok && (strcmp(str, "__WU") == 0)) { vseg[vseg_index]->mode = 0x3; }
679    else if (ok && (strcmp(str, "__W_") == 0)) { vseg[vseg_index]->mode = 0x2; }
680    else if (ok && (strcmp(str, "___U") == 0)) { vseg[vseg_index]->mode = 0x1; }
681    else if (ok && (strcmp(str, "____") == 0)) { vseg[vseg_index]->mode = 0x0; }
682    else {
[158]683        printf("[XML ERROR] illegal or missing <mode> attribute for vseg (%d,%d)\n", 
684                vspace_index, vseg_loc_index);
685        exit(1);
686    }
[228]687
[181]688    ////////// get vobjs in vseg
689    int status = xmlTextReaderRead(reader);
[228]690    while (status == 1) {
691        const char * tag = (const char *) xmlTextReaderConstName(reader);
[160]692
[228]693        if (strcmp(tag, "vobj")     == 0 ) {
694            vobjNode(reader);
695        }
696        else if (strcmp(tag, "#text"  )  == 0 ) { }
697        else if (strcmp(tag, "#comment") == 0 ) { }
698        else if (strcmp(tag, "vseg")     == 0 ) {
[165]699            vseg[vseg_index]->vobjs = vobj_count;
[160]700            vseg_index++;
701            vseg_loc_index++;
702            return;
703        }
[228]704        else {
705            printf("[XML ERROR] Unknown tag %s", tag);
[160]706            exit(1);
707        }
[228]708        status = xmlTextReaderRead (reader);
[160]709    }
[158]710} // end vsegNode()
711
[228]712
[158]713//////////////////////////////////////////
[228]714void vspaceNode(xmlTextReaderPtr reader) {
715    char * str;
716    unsigned int ok;
[165]717
718    vobj_loc_index = 0;
[228]719    vseg_loc_index = 0;
720    task_loc_index = 0;
[158]721
[228]722    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) {
723        return;
724    }
[158]725
726    // checking source file consistency
[228]727    if (vspace_index >= header->vspaces) {
[158]728        printf("[XML ERROR] The vspace index is too large : %d\n", 
[228]729                vspace_index);
[158]730        exit(1);
731    }
732
733#if XML_PARSER_DEBUG
[228]734    printf("\n  vspace %d\n", vspace_index);
[158]735#endif
736
[228]737    vspace[vspace_index] = (mapping_vspace_t *) malloc(sizeof(mapping_vspace_t));
[158]738
739    ////////// get name attribute
740    str = getStringValue(reader, "name", &ok);
[228]741    if (ok) {
[158]742#if XML_PARSER_DEBUG
[228]743        printf("  name = %s\n", str);
[158]744#endif
745        strncpy(vspace[vspace_index]->name, str, 31);
746    }
[228]747    else {
[165]748        printf("[XML ERROR] illegal or missing <name> attribute for vspace %d\n", 
[228]749                vspace_index);
[158]750        exit(1);
751    }
752
[165]753    ////////// set vseg_offset and task_offset attributes
754    vspace[vspace_index]->vseg_offset = vseg_index;
755    vspace[vspace_index]->vobj_offset = vobj_index;
756    vspace[vspace_index]->task_offset = task_index;
[228]757
[158]758#if XML_PARSER_DEBUG
[228]759    printf("  vseg_offset = %d\n", vseg_index);
760    printf("  vobj_offset = %d\n", vobj_index);
761    printf("  task_offset = %d\n", task_index);
[158]762#endif
763
[165]764    ////////// get startname attribute
765    str = getStringValue(reader, "startname", &ok);
[228]766    if (ok) {
[165]767        //used after parsing the vobjs
[158]768    }
[228]769    else {
[203]770        printf("[XML ERROR] illegal or missing <startname> attribute for vspace %s\n", 
[228]771                vspace[vspace_index]->name);
[158]772        exit(1);
773    }
774
[181]775    int status = xmlTextReaderRead(reader);
[228]776    while (status == 1) {
777        const char * tag = (const char *) xmlTextReaderConstName(reader);
[158]778
[230]779        if (strcmp(tag, "vseg") == 0) {
[228]780            vsegNode(reader);
781        }
[230]782        else if (strcmp(tag, "task") == 0) {
[228]783            taskNode(reader);
784        }
[230]785        else if (strcmp(tag, "#text")    == 0) { }
786        else if (strcmp(tag, "#comment") == 0) { }
787        else if (strcmp(tag, "vspace")   == 0) {
[181]788            vspace[vspace_index]->vobjs = vobj_loc_index; 
[160]789            vspace[vspace_index]->tasks = task_loc_index ;
790            vspace[vspace_index]->vsegs = vseg_loc_index ;
[165]791
792            // get index of the vobj containing the start vector
[228]793            int index = getVobjLocId(vspace_index, str , vobj_loc_index);
794            if (index == -1) {
[203]795                printf("[XML ERROR] vobj containing start vector not found in vspace %s\n",
796                        vspace[vspace_index]->name);
[160]797                exit(-1);
[158]798            }
[228]799            else {
[165]800                vspace[vspace_index]->start_offset = index;
801#if XML_PARSER_DEBUG
[228]802                printf("      startname = %s\n", str);
803                printf("      startid   = %d\n", index);
804                printf("  end vspace %d\n\n", vspace_index);
[165]805#endif
806            }
[160]807
[165]808            // checking startid values for all tasks in vspace
809            int task_id;
810            int task_min = vspace[vspace_index]->task_offset;
811            int task_max = task_min + vspace[vspace_index]->tasks; 
[228]812            for (task_id = task_min; task_id < task_max; task_id++) {
813                if (task[task_id]->startid >= vspace[vspace_index]->tasks) {
[165]814                    printf("[XML ERROR] <startid> too large for task (%d,%d)\n", 
[228]815                            vspace_index, task_id );
[165]816                    exit(1);
817                }
818            }
819
[160]820            vspace_index++;
821            return;
[158]822        }
[228]823        else {
824            printf("[XML ERROR] Unknown tag %s", tag);
[158]825            exit(1);
826        }
[228]827        status = xmlTextReaderRead(reader);
[158]828    }
829} // end vspaceNode()
830
[228]831
[215]832///////////////////////////////////////////
[228]833void cpPortNode(xmlTextReaderPtr reader) {
834    char * str;
835    unsigned int ok;
[215]836
[228]837    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) {
838        return;
839    }
[215]840
[228]841    if (cp_port_index >= MAX_CP_PORTS) {
[215]842        printf("[XML ERROR] The number of ports (for coprocs) is larger than %d\n", MAX_CP_PORTS);
843    }
844
845#if XML_PARSER_DEBUG
[228]846    printf("\n  port %d\n", cp_port_index);
[215]847#endif
848
[228]849    cp_port[cp_port_index] = (mapping_cp_port_t *) malloc(sizeof(mapping_cp_port_t));
850    cp_port_vobj_ref[cp_port_index] = (vobj_ref_t *) malloc(sizeof(vobj_ref_t));
[215]851
852
[228]853
[215]854    ///////// get direction attribute
[228]855    str = getStringValue(reader, "direction", &ok);
856    if (ok) {
[215]857#if XML_PARSER_DEBUG
[228]858        printf("      direction = %s\n", str);
[215]859#endif
[228]860        if (strcmp(str, "TO_COPROC")   ==  0) {
861            cp_port[cp_port_index]->direction = PORT_TO_COPROC;
862        }
863        else if (strcmp(str, "FROM_COPROC") ==  0) {
864            cp_port[cp_port_index]->direction = PORT_FROM_COPROC;
865        }
866        else {
[215]867            printf("[XML ERROR] illegal <direction> for cp_port %d in cluster %d\n",
[228]868                    cp_port_index, cluster_index);
[215]869            exit(1);
870        }
871    } 
[228]872    else {
[215]873        printf("[XML ERROR] missing <direction> for cp_port %d in cluster %d\n",
[228]874                cp_port_index, cluster_index);
[215]875        exit(1);
876    }
[228]877
[215]878    /////////// get vspacename attribute
[228]879    str = getStringValue(reader, "vspacename", &ok);
[215]880#if XML_PARSER_DEBUG
[228]881    printf("      vspacename = %s\n", str);
[215]882#endif
[228]883    if (ok) {
[215]884        strncpy(cp_port_vobj_ref[cp_port_index]->vspace_name, str, 31);
885    }
[228]886    else {
[215]887        printf("[XML ERROR] missing <vspacename> for cp_port %d in cluster %d\n",
[228]888                cp_port_index, cluster_index);
[215]889        exit(1);
890    }
891
892    /////////// get vobjname attribute
[228]893    str = getStringValue(reader, "vobjname", &ok);
[215]894#if XML_PARSER_DEBUG
[228]895    printf("      vobjname = %s\n", str);
[215]896#endif
[228]897    if (ok) {
[215]898        strncpy(cp_port_vobj_ref[cp_port_index]->vobj_name, str, 31);
899    }
[228]900    else {
[215]901        printf("[XML ERROR] missing <vobjname> for cp_port %d in cluster %d\n",
[228]902                cp_port_index, cluster_index);
[215]903        exit(1);
904    }
[228]905
[215]906    cp_port_index++;
907    cp_port_loc_index++;
908
909} // end cpPortNode()
910
[228]911
[215]912///////////////////////////////////////////
[228]913void periphNode(xmlTextReaderPtr reader) {
914    char * str;
915    unsigned int value;
916    unsigned int ok;
[215]917
[228]918    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) {
919        return;
920    }
[215]921
[228]922    if (periph_index >= MAX_PERIPHS) {
[215]923        printf("[XML ERROR] The number of periphs is larger than %d\n", MAX_PERIPHS);
924    }
925
926#if XML_PARSER_DEBUG
[228]927    printf("\n  periph %d\n", periph_index);
[215]928#endif
929
[228]930    periph[periph_index] = (mapping_periph_t *) malloc(sizeof(mapping_periph_t));
[215]931
932
933    ///////// get channels attribute (optionnal : 1 if missing)
[228]934    value = getIntValue(reader, "channels", &ok);
935    if (ok) {
[215]936#if XML_PARSER_DEBUG
[228]937        printf("      channels = %d\n", value);
[215]938#endif
939        periph[periph_index]->channels = value;
940    }
[228]941    else {
[215]942        periph[periph_index]->channels = 1;
943    }
944
945    /////////// get psegname attribute
[228]946    str = getStringValue(reader, "psegname", &ok);
947    if (ok == 0) {
[215]948        printf("[XML ERROR] illegal or missing <psegname> for coproc %d in cluster %d\n", 
[228]949                coproc_index, cluster_index);
[215]950        exit(1);
951    }
952
953    /////////// set psegid attribute
[228]954    int index = getPsegId(cluster_index, str);
955    if (index >= 0) {
[215]956#if XML_PARSER_DEBUG
[228]957        printf("      clusterid = %d\n", cluster_index);
958        printf("      psegname  = %s\n", str);
959        printf("      psegid    = %d\n", index);
[215]960#endif
961        periph[periph_index]->psegid = index;
962        assert(pseg[index]->type == PSEG_TYPE_PERI && 
[228]963                "peripheral psegname attribute must refer to a pseg of type PERI" );
[215]964    }
[228]965    else {
[215]966        printf("[XML ERROR] pseg not found for periph %d / clusterid = %d / psegname = %s\n", 
[228]967                periph_loc_index, cluster_index, str );
[215]968        exit(1);
969    } 
970
971
972    /////////// get type attribute
[228]973    str = getStringValue(reader, "type", &ok);
974    if (ok) {
[215]975#if XML_PARSER_DEBUG
[228]976        printf("      type     = %s\n", str);
[215]977#endif
978        unsigned int error = 0;
[228]979
[215]980        // The TTY, IOC, NIC, FBF and IOB peripherals cannot be replicated
981        // one per architecture
[228]982        if (strcmp(str, "IOC") == 0) {
[215]983            periph[periph_index]->type = PERIPH_TYPE_IOC;
[228]984            if (header->ioc_clusterid == 0xFFFFFFFF) {
985                header->ioc_clusterid = cluster_index;
986            }
987            else {
988                error = 1;
989            }
[215]990
[228]991            ioc_base_offset = pseg[periph[periph_index]->psegid]->base;
[215]992            nb_ioc_channel = periph[periph_index]->channels;
993        } 
[228]994        else if (strcmp(str, "TTY") == 0) {
[215]995            periph[periph_index]->type = PERIPH_TYPE_TTY;
[228]996            if (header->tty_clusterid == 0xFFFFFFFF) {
997                header->tty_clusterid = cluster_index;
998            }
999            else  {
1000                error = 1;
1001            }
[215]1002
[228]1003            tty_base_offset = pseg[periph[periph_index]->psegid]->base;
[215]1004            nb_tty_channel = periph[periph_index]->channels;
1005        }
[228]1006        else if (strcmp(str, "FBF") == 0) {
[215]1007            periph[periph_index]->type = PERIPH_TYPE_FBF;
[228]1008            if (header->fbf_clusterid == 0xFFFFFFFF) {
1009                header->fbf_clusterid = cluster_index;
1010            }
1011            else {
1012                error = 1;
1013            }
1014            fbf_base_offset = pseg[periph[periph_index]->psegid]->base;
[215]1015        }
[228]1016        else if (strcmp(str, "NIC") == 0) {
[215]1017            periph[periph_index]->type = PERIPH_TYPE_NIC;
[228]1018            if (header->nic_clusterid == 0xFFFFFFFF) {
1019                header->nic_clusterid = cluster_index;
1020            }
1021            else {
1022                error = 1;
1023            }
1024            nic_base_offset = pseg[periph[periph_index]->psegid]->base;
[215]1025            nb_nic_channel = periph[periph_index]->channels;
1026        }
[228]1027        else if (strcmp(str, "IOB") == 0) {
[215]1028            periph[periph_index]->type = PERIPH_TYPE_IOB;
[228]1029            iob_base_offset = pseg[periph[periph_index]->psegid]->base;
[215]1030
[228]1031            if (io_mmu_active) {
1032                error = 1;
1033            }
[215]1034            io_mmu_active = 1;
1035        }
1036        // The TIM, ICU, XICU, DMA and IOB peripherals can be replicated in several clusters
1037        // one per cluster
[228]1038        else if (strcmp(str, "TIM") == 0 ) {
[215]1039            periph[periph_index]->type = PERIPH_TYPE_TIM;
[228]1040            if (found_timer) {
1041                error = 1;
1042            }
[215]1043            found_timer = 1;
1044
[228]1045            if (tim_base_offset == 0xFFFFFFFF) {
[215]1046                tim_base_offset = pseg[ periph[periph_index]->psegid ]->base;
[228]1047            }
[215]1048
[228]1049            if (nb_timer_channel_max < periph[periph_index]->channels) {
[215]1050                nb_timer_channel_max = periph[periph_index]->channels;
[228]1051            }
[215]1052        }
[228]1053        else if (strcmp(str, "ICU") == 0) {
[215]1054            periph[periph_index]->type = PERIPH_TYPE_ICU;
[228]1055            if (found_icu) {
1056                error = 1;
1057            }
[215]1058            found_icu = 1;
1059
[228]1060            if (icu_base_offset == 0xFFFFFFFF) {
1061                icu_base_offset = pseg[periph[periph_index]->psegid]->base;
1062            }
[215]1063        }
[228]1064        else if (strcmp(str, "XICU") == 0) {
[215]1065            periph[periph_index]->type = PERIPH_TYPE_XICU;
[228]1066            if (found_xicu) {
1067                error = 1;
1068            }
[215]1069            found_xicu = 1;
1070
1071            //'icu' since we can't have both xicu and icu in an arch
[228]1072            if (icu_base_offset == 0xFFFFFFFF) {
[215]1073                icu_base_offset = pseg[ periph[periph_index]->psegid ]->base;
[228]1074            }
[216]1075
[228]1076            if (nb_timer_channel_max == 0) {
[216]1077                nb_timer_channel_max = 32;
[228]1078            }
[215]1079        }
[228]1080        else if (strcmp(str, "DMA") == 0) {
[215]1081            periph[periph_index]->type = PERIPH_TYPE_DMA;
[228]1082            if (found_dma) {
1083                error = 1;
1084            }
[215]1085            found_dma = 1;
1086
[228]1087            if (dma_base_offset == 0xFFFFFFFF) {
1088                dma_base_offset = pseg[periph[periph_index]->psegid]->base;
1089            }
1090            if (nb_dma_channel_max < periph[periph_index]->channels) {
[215]1091                nb_dma_channel_max = periph[periph_index]->channels;
[228]1092            }
[215]1093        }
[228]1094        else {
[215]1095            printf("[XML ERROR] illegal <type> for peripheral %d in cluster %d\n",
[228]1096                    periph_loc_index, cluster_index);
[215]1097            exit(1);
1098        }
1099
[228]1100        if (error) {
[215]1101            printf("[XML ERROR] illegal <type> for peripheral %d in cluster %d\n",
[228]1102                    periph_loc_index, cluster_index);
[215]1103            exit(1);
1104        }
1105    }
[228]1106    else {
[215]1107        printf("[XML ERROR] missing <type> for peripheral  %d in cluster %d\n",
[228]1108                periph_loc_index, cluster_index);
[215]1109        exit(1);
1110    }
1111
[228]1112
[215]1113    periph_index++;
1114    periph_loc_index++;
1115    cluster[cluster_index]->periphs++;
1116
1117} // end periphNode
1118
[228]1119
[215]1120/////////////////////////////////////////
[228]1121void coprocNode(xmlTextReaderPtr reader) {
1122    char * str;
1123    unsigned int ok;
[215]1124
1125    cp_port_loc_index = 0;
1126
[228]1127    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) {
1128        return;
1129    }
[215]1130
[228]1131    if (coproc_index >= MAX_COPROCS) {
[215]1132        printf("[XML ERROR] The number of coprocs is larger than %d\n", MAX_COPROCS);
1133    }
1134
1135#if XML_PARSER_DEBUG
[228]1136    printf("\n  coproc %d\n", coproc_index);
[215]1137#endif
1138
[228]1139    coproc[coproc_index] = (mapping_coproc_t *) malloc(sizeof(mapping_coproc_t));
[215]1140
1141    /////////// get name attribute
[228]1142    str = getStringValue(reader, "name", &ok);
1143    if (ok) {
[215]1144#if XML_PARSER_DEBUG
[228]1145        printf("      name = %s\n", str);
[215]1146#endif
1147        strncpy(coproc[coproc_index]->name, str, 31);
1148    }
[228]1149    else {
[215]1150        printf("[XML ERROR] illegal or missing <name> for coproc %d in cluster %d\n",
[228]1151                coproc_index, cluster_index);
[215]1152        exit(1);
1153    }
1154
1155    /////////// get psegname attribute
[228]1156    str = getStringValue(reader, "psegname", &ok);
1157    if (ok == 0) {
[215]1158        printf("[XML ERROR] illegal or missing <psegname> for coproc %d in cluster %d\n", 
[228]1159                coproc_index, cluster_index);
[215]1160        exit(1);
1161    }
1162
1163    /////////// set psegid attribute
[228]1164    int index = getPsegId(cluster_index, str);
1165    if (index >= 0) {
[215]1166#if XML_PARSER_DEBUG
[228]1167        printf("      clusterid = %d\n", cluster_index);
1168        printf("      psegname  = %s\n", str);
1169        printf("      psegid    = %d\n", index);
[215]1170#endif
1171        coproc[coproc_index]->psegid = index;
1172        assert(pseg[index]->type == PSEG_TYPE_PERI && "coproc psegname attribute must refer to a pseg of type PERI" );
1173    }
[228]1174    else {
[215]1175        printf("[XML ERROR] pseg not found for coproc %d / clusterid = %d / psegname = %s\n", 
[228]1176                coproc_index, cluster_index, str );
[215]1177        exit(1);
1178    } 
1179
1180    ////////// set port_offset
1181    coproc[coproc_index]->port_offset = cp_port_index;
1182
1183#if XML_PARSER_DEBUG
[228]1184    printf("      port_offset = %d\n", cp_port_index);
[215]1185#endif
1186
1187    int status = xmlTextReaderRead(reader);
[228]1188    while (status == 1) {
1189        const char * tag = (const char *) xmlTextReaderConstName(reader);
[215]1190
[228]1191        if (strcmp(tag, "port") == 0 ) {
1192            cpPortNode(reader);
1193        }
1194        else if (strcmp(tag, "#text")    == 0 ) { }
1195        else if (strcmp(tag, "#comment") == 0 ) { }
1196        else if (strcmp(tag, "coproc") == 0 ) {
[215]1197            coproc[coproc_index]->ports = cp_port_loc_index;
1198            cluster[cluster_index]->coprocs++;
1199            coproc_loc_index++;
1200            coproc_index++;
1201            return;
1202        }
[228]1203        else {
1204            printf("[XML ERROR] Unknown tag %s", tag);
[215]1205            exit(1);
1206        }
[228]1207        status = xmlTextReaderRead(reader);
[215]1208    }
1209} // end coprocNode()
1210
[228]1211
[215]1212///////////////////////////////////////
[228]1213void irqNode(xmlTextReaderPtr reader) {
1214    unsigned int ok;
1215    unsigned int value;
1216    char * str;
[215]1217
[228]1218    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) {
1219        return;
1220    }
[215]1221
[228]1222    if (irq_index >= MAX_IRQS) {
[215]1223        printf("[XML ERROR] The number of irqs is larger than %d\n", MAX_IRQS);
1224    }
1225
1226#if XML_PARSER_DEBUG
[228]1227    printf("     irq %d\n", irq_loc_index);
[215]1228#endif
1229
[228]1230    irq[irq_index] = (mapping_irq_t *) malloc(sizeof(mapping_irq_t));
[215]1231
1232    ///////// get type attribute
[228]1233    str = getStringValue(reader, "type", &ok);
1234    if (ok) {
[215]1235#if XML_PARSER_DEBUG
[228]1236        printf("        type    = %s\n", str);
[215]1237#endif
[228]1238        if (strcmp(str, "HARD") == 0 ) {
1239            irq[irq_index]->type = 0;
1240        }
[231]1241        else {
[228]1242            irq[irq_index]->type = 1;
1243        }
[231]1244    }
[228]1245    else {
[215]1246        printf("[XML ERROR] missing IRQ <type> for processor %d in cluster %d\n",
[228]1247                cluster_index, proc_loc_index);
[215]1248        exit(1);
1249    }
1250
1251    ///////// get icuid attribute
1252    value = getIntValue(reader, "icuid", &ok);
[228]1253    if (ok) {
[215]1254#if XML_PARSER_DEBUG
[228]1255        printf("        icuid   = %d\n", value);
[215]1256#endif
1257        irq[irq_index]->icuid = value;
[228]1258        if (value >= 32) {
[215]1259            printf("[XML ERROR] IRQ <icuid> too large for processor %d in cluster %d\n",
[228]1260                    cluster_index, proc_loc_index);
[215]1261            exit(1);
1262        }
1263    }
[228]1264    else {
[215]1265        printf("[XML ERROR] missing IRQ <icuid> for processor %d in cluster %d\n",
[228]1266                cluster_index, proc_loc_index);
[215]1267        exit(1);
1268    }
1269
1270    ///////// get isr attribute
[228]1271    str = getStringValue(reader, "isr", &ok);
1272    if (ok) {
[215]1273#if XML_PARSER_DEBUG
[228]1274        printf("        isr     = %s\n", str);
[215]1275#endif
[228]1276        if      (strcmp(str, "ISR_SWITCH" ) == 0) { irq[irq_index]->isr = ISR_SWITCH; }
1277        else if (strcmp(str, "ISR_IOC"    ) == 0) { irq[irq_index]->isr = ISR_IOC; }
1278        else if (strcmp(str, "ISR_DMA"    ) == 0) { irq[irq_index]->isr = ISR_DMA; }
1279        else if (strcmp(str, "ISR_TTY"    ) == 0) { irq[irq_index]->isr = ISR_TTY; }
1280        else if (strcmp(str, "ISR_TIMER"  ) == 0) { irq[irq_index]->isr = ISR_TIMER; }
1281        else {
[215]1282            printf("[XML ERROR] illegal IRQ <isr> for processor %d in cluster %d\n",
[228]1283                    cluster_index, proc_loc_index);
[215]1284            exit(1);
1285        }
1286#if XML_PARSER_DEBUG
[228]1287        printf("        isrnum  = %d\n", irq[irq_index]->isr);
[215]1288#endif
1289    } 
[228]1290    else {
[215]1291        printf("[XML ERROR] missing IRQ <isr> for processor %d in cluster %d\n",
[228]1292                cluster_index, proc_loc_index);
[215]1293        exit(1);
1294    }
1295
1296    ///////// get channel attribute (optionnal : 0 if missing)
1297    value = getIntValue(reader, "channel", &ok);
[228]1298    if (ok) {
[215]1299#if XML_PARSER_DEBUG
[228]1300        printf("        channel = %d\n", value);
[215]1301#endif
1302        irq[irq_index]->channel = value;
1303    }
[228]1304    else {
[215]1305        irq[irq_index]->channel = 0;
1306    }
1307
1308    irq_index++;
1309    irq_loc_index++;
1310
1311} // end irqNode
1312
[228]1313
[215]1314/////////////////////////////////////////
[228]1315void procNode(xmlTextReaderPtr reader) {
1316    unsigned int ok;
1317    unsigned int value;
[215]1318
1319    irq_loc_index = 0;
1320
[228]1321    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) {
1322        return;
1323    }
[215]1324
[228]1325    if (proc_index >= MAX_PROCS) {
[215]1326        printf("[XML ERROR] The number of procs is larger than %d\n", MAX_PROCS);
1327    }
1328
1329#if XML_PARSER_DEBUG
[228]1330    printf("\n  proc %d\n", proc_index);
[215]1331#endif
1332
[228]1333    proc[proc_index] = (mapping_proc_t *) malloc(sizeof(mapping_proc_t));
[215]1334
1335
1336    /////////// get index attribute (optional)
[228]1337    value = getIntValue(reader, "index", &ok);
1338    if (ok && (value != proc_loc_index)) {
1339        printf("[XML ERROR] wrong proc index / expected value is %d", 
[215]1340                proc_loc_index);
[228]1341        exit(1);
[215]1342    }
1343
1344    ////////// set irq_offset attribute
1345    proc[proc_index]->irq_offset = irq_index;
1346
1347#if XML_PARSER_DEBUG
[228]1348    printf("    irq_offset = %d\n", irq_index);
[215]1349#endif
1350
1351    int status = xmlTextReaderRead(reader);
[228]1352    while (status == 1) {
1353        const char * tag = (const char *) xmlTextReaderConstName(reader);
[215]1354
[228]1355        if (strcmp(tag, "irq") == 0) {
1356            irqNode(reader);
1357        }
1358        else if (strcmp(tag, "#text")    == 0) { }
1359        else if (strcmp(tag, "#comment") == 0) { }
1360        else if (strcmp(tag, "proc")     == 0) {
[215]1361            proc[proc_index]->irqs = irq_loc_index;
1362            cluster[cluster_index]->procs++;
1363            proc_loc_index++;
1364            proc_index++;
1365            return;
1366        }
[228]1367        else {
1368            printf("[XML ERROR] Unknown tag %s", tag);
[215]1369            exit(1);
1370        }
[228]1371        status = xmlTextReaderRead(reader);
[215]1372    }
1373} // end procNode()
1374
1375
[158]1376//////////////////////////////////////////
[228]1377void psegNode(xmlTextReaderPtr reader) {
1378    unsigned int ok;
1379    unsigned int value;
1380    char * str;
[158]1381
[228]1382    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) {
1383        return;
1384    }
[158]1385
[228]1386    if (pseg_index >= MAX_PSEGS) {
[158]1387        printf("[XML ERROR] The number of psegs is larger than %d\n", MAX_PSEGS);
1388        exit(1);
1389    }
1390
1391#if XML_PARSER_DEBUG
[228]1392    printf("    pseg %d\n", pseg_index);
[158]1393#endif
1394
[228]1395    pseg[pseg_index] = (mapping_pseg_t *) malloc(sizeof(mapping_pseg_t));
[158]1396
[181]1397    /////// get name attribute
[228]1398    str = getStringValue(reader, "name", &ok);
[158]1399#if XML_PARSER_DEBUG
[228]1400    printf("      name = %s\n", str);
[158]1401#endif
[228]1402    if (ok) {
[158]1403        strncpy(pseg[pseg_index]->name, str, 31);
1404    }
[228]1405    else {
[181]1406        printf("[XML ERROR] illegal or missing <name> for pseg %d in cluster %d\n",
[228]1407                pseg_index, cluster_index);
[158]1408        exit(1);
1409    }
1410
[181]1411    //////// get type attribute
1412    str = getStringValue(reader, "type", &ok);
1413#if XML_PARSER_DEBUG
[228]1414    printf("      type = %s\n", str);
[181]1415#endif
[228]1416    if      (ok && (strcmp(str, "RAM" ) == 0)) { pseg[pseg_index]->type = PSEG_TYPE_RAM; }
1417    else if (ok && (strcmp(str, "ROM" ) == 0)) { pseg[pseg_index]->type = PSEG_TYPE_ROM; }
1418    else if (ok && (strcmp(str, "PERI") == 0)) { pseg[pseg_index]->type = PSEG_TYPE_PERI; }
1419    else {
[181]1420        printf("[XML ERROR] illegal or missing <type> for pseg %s in cluster %d\n",
[228]1421                pseg[pseg_index]->name, cluster_index);
[181]1422        exit(1);
1423    }
1424
1425    //////// get base attribute
[228]1426    value = getIntValue(reader, "base", &ok);
[158]1427#if XML_PARSER_DEBUG
[228]1428    printf("      base = 0x%x\n", value);
[158]1429#endif
[228]1430    if (ok) {
[158]1431        pseg[pseg_index]->base = value;
1432    }
[228]1433    else {
[181]1434        printf("[XML ERROR] illegal or missing <base> for pseg %s in cluster %d\n",
[228]1435                pseg[pseg_index]->name, cluster_index);
[158]1436        exit(1);
1437    }
1438
[181]1439    //////// get length attribute
[228]1440    value = getIntValue(reader, "length", &ok);
[158]1441#if XML_PARSER_DEBUG
[228]1442    printf("      length = 0x%x\n", value);
[158]1443#endif
[228]1444    if (ok) {
[158]1445        pseg[pseg_index]->length = value;
1446    } 
[228]1447    else {
[181]1448        printf("[XML ERROR] illegal or missing <length> for pseg %s in cluster %d\n",
[228]1449                pseg[pseg_index]->name, cluster_index);
[158]1450        exit(1);
1451    }
1452
[181]1453    //////// set cluster attribute
1454    pseg[pseg_index]->cluster = cluster_index;
1455
[158]1456    pseg_index++;
[181]1457    cluster[cluster_index]->psegs++;
[158]1458} // end psegNode()
1459
[228]1460
[158]1461/////////////////////////////////////////////
[228]1462void clusterNode(xmlTextReaderPtr reader) {
[158]1463    unsigned int ok;
1464    unsigned int value;
1465
[228]1466    cluster[cluster_index] = (mapping_cluster_t *) malloc(sizeof(mapping_cluster_t));
1467
[215]1468    //initialise all variables
1469    //they will be incremented by *Node() functions
1470    //FIXME: calloc?
1471    cluster[cluster_index]->psegs = 0;
1472    cluster[cluster_index]->procs = 0;
1473    cluster[cluster_index]->coprocs = 0;
1474    cluster[cluster_index]->periphs = 0;
1475
1476
1477    //initialise global variables
1478    //TODO: delete those three
[181]1479    proc_loc_index = 0;
1480    coproc_loc_index = 0;
[189]1481    periph_loc_index = 0;
[181]1482
[215]1483    // for replicated periph
1484    found_timer = 0;
1485    found_icu = 0;
1486    found_xicu = 0;
1487    found_dma = 0;
1488
[228]1489    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) {
1490        return;
1491    }
[158]1492
1493    // checking source file consistency
[228]1494    if (cluster_index >= header->clusters) {
[158]1495        printf("[XML ERROR] The cluster index is too large : %d\n", cluster_index);
1496        exit(1);
1497    }
1498
1499#if XML_PARSER_DEBUG
[228]1500    printf("  cluster %d\n", cluster_index);
[158]1501#endif
1502
1503
[189]1504    /////////// check cluster index attribute (optional)
[228]1505    value = getIntValue(reader, "index", &ok);
1506    if (ok && (value != cluster_index)) {
1507        printf("[XML ERROR] wrong cluster index / expected value is %d", 
[158]1508                cluster_index);
[228]1509        exit(1);
[158]1510    }
1511
[189]1512    ////////// set offsets
[228]1513    cluster[cluster_index]->pseg_offset = pseg_index;
1514    cluster[cluster_index]->proc_offset = proc_index;
[189]1515    cluster[cluster_index]->coproc_offset = coproc_index;
1516    cluster[cluster_index]->periph_offset = periph_index;
[181]1517
[158]1518#if XML_PARSER_DEBUG
[228]1519    printf("    pseg_offset   = %d\n", pseg_index);
1520    printf("    proc_offset   = %d\n", proc_index);
1521    printf("    coproc_offset = %d\n", coproc_index);
1522    printf("    periph_offset = %d\n", coproc_index);
[158]1523#endif
[181]1524
[189]1525    ////////// get psegs, procs, coprocs and periphs
[181]1526    int status = xmlTextReaderRead(reader);
1527
[228]1528    while (status == 1) {
1529        const char * tag = (const char *) xmlTextReaderConstName(reader);
[181]1530
[228]1531        if      (strcmp(tag, "pseg")     == 0) psegNode(reader);
1532        else if (strcmp(tag, "proc")     == 0) procNode(reader);
1533        else if (strcmp(tag, "coproc")   == 0) coprocNode(reader);
1534        else if (strcmp(tag, "periph")   == 0) periphNode(reader);
1535        else if (strcmp(tag, "#text")    == 0) { }
1536        else if (strcmp(tag, "#comment") == 0) { }
1537        else if (strcmp(tag, "cluster")  == 0) {
[189]1538
[228]1539            if (use_xicu == 0xFFFFFFFF) {
[215]1540                use_xicu = found_xicu;
[228]1541            }
[189]1542
[215]1543            ////////////////// peripherals checks ////////////////////
[228]1544            if ((found_timer  && use_xicu) || (!found_timer  && !use_xicu)) {
[215]1545                printf("[XML ERROR] illegal or missing timer peripheral in cluster %d\n", cluster_index);
1546                exit(1);
1547            }
1548
[228]1549            if ((found_icu && use_xicu) || (!found_icu && !use_xicu)) {
[215]1550                printf("[XML ERROR] illegal or missing icu peripheral in cluster %d\n", cluster_index);
1551                exit(1);
1552            }
1553
[228]1554            if (!found_xicu && use_xicu) {
[215]1555                printf("[XML ERROR] illegal or missing dma peripheral in cluster %d\n", cluster_index);
1556                exit(1);
1557            }
1558
[228]1559            if (!found_dma) {
[215]1560                printf("[XML ERROR] illegal or missing dma peripheral in cluster %d\n", cluster_index);
1561                exit(1);
1562            }
1563
[228]1564
1565            if (nb_proc_max < cluster[cluster_index]->procs) {
[215]1566                nb_proc_max = cluster[cluster_index]->procs;
[228]1567            }
[215]1568
[181]1569#if XML_PARSER_DEBUG
[228]1570            printf("    psegs   = %d\n", cluster[cluster_index]->psegs);
1571            printf("    procs   = %d\n", cluster[cluster_index]->procs);
1572            printf("    coprocs = %d\n", cluster[cluster_index]->coprocs);
1573            printf("    periphs = %d\n", cluster[cluster_index]->periphs);
1574            printf("    end cluster %d\n", cluster_index);
[181]1575#endif
1576            cluster_index++;
1577            return;
1578        }
1579        status = xmlTextReaderRead(reader);
[158]1580    }
1581} // end clusterNode()
1582
[228]1583
[158]1584//////////////////////////////////////////////
[228]1585void clusterSetNode(xmlTextReaderPtr reader) {
1586    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) {
1587        return;
1588    }
[158]1589
1590#if XML_PARSER_DEBUG
[228]1591    printf("\n  clusters set\n");
[158]1592#endif
1593
[181]1594    int status = xmlTextReaderRead(reader);
[228]1595    while (status == 1) {
1596        const char * tag = (const char *) xmlTextReaderConstName(reader);
[158]1597
[228]1598        if (strcmp(tag, "cluster")    == 0) {
1599            clusterNode(reader);
1600        }
1601        else if (strcmp(tag, "#text")      == 0) { }
1602        else if (strcmp(tag, "#comment")   == 0) { }
1603        else if (strcmp(tag, "clusterset") == 0) {
[158]1604            // checking source file consistency
[228]1605            if (cluster_index != header->clusters) {
[158]1606                printf("[XML ERROR] Wrong number of clusters\n");
1607                exit(1);
1608            }
[215]1609
[228]1610            if (header->tty_clusterid == 0xFFFFFFFF) {
[215]1611                printf("[XML ERROR] illegal or missing tty peripheral");
1612                exit(1);
1613            }
1614
[181]1615#if XML_PARSER_DEBUG
[228]1616            printf("  end cluster set\n\n");
[181]1617#endif
[228]1618            header->psegs = pseg_index;
1619            header->procs = proc_index;
1620            header->irqs = irq_index;
1621            header->coprocs = coproc_index;
[215]1622            header->cp_ports = cp_port_index;
1623            return;
[158]1624        }
[228]1625        else {
[158]1626            printf("[XML ERROR] Unknown tag in clusterset node : %s",tag);
1627            exit(1);
1628        }
[181]1629        status = xmlTextReaderRead(reader);
[158]1630    }
1631} // end clusterSetNode()
1632
[228]1633
[158]1634/////////////////////////////////////////////
[228]1635void globalSetNode(xmlTextReaderPtr reader) {
1636    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) {
1637        return;
1638    }
[158]1639
1640#if XML_PARSER_DEBUG
[228]1641    printf("  globals set\n");
[158]1642#endif
1643
[181]1644    int status = xmlTextReaderRead(reader);
[228]1645    while (status == 1) {
1646        const char * tag = (const char *) xmlTextReaderConstName(reader);
[158]1647
[228]1648        if (strcmp(tag, "vseg") == 0) {
1649            vsegNode(reader);
1650        }
1651        else if (strcmp(tag, "#text")     == 0) { }
1652        else if (strcmp(tag, "#comment")  == 0) { }
1653        else if (strcmp(tag, "globalset") == 0) {
[181]1654#if XML_PARSER_DEBUG
[228]1655            printf("  end global set\n\n");
[181]1656#endif
[204]1657            header->globals = vseg_index;
1658            vseg_loc_index = 0;
1659            return;
[158]1660        }
[228]1661        else {
[158]1662            printf("[XML ERROR] Unknown tag in globalset node : %s",tag);
1663            exit(1);
1664        }
[228]1665        status = xmlTextReaderRead(reader);
[158]1666    }
1667} // end globalSetNode()
1668
[228]1669
[158]1670/////////////////////////////////////////////
[228]1671void vspaceSetNode(xmlTextReaderPtr reader) {
1672    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) {
1673        return;
1674    }
[158]1675
1676#if XML_PARSER_DEBUG
[228]1677    printf("\n  vspaces set\n");
[158]1678#endif
1679
1680    int status = xmlTextReaderRead ( reader );
[228]1681    while (status == 1) {
1682        const char * tag = (const char *) xmlTextReaderConstName(reader);
[158]1683
[228]1684        if (strcmp(tag, "vspace") == 0) {
1685            vspaceNode(reader);
1686        }
1687        else if (strcmp(tag, "#text"    ) == 0 ) { }
1688        else if (strcmp(tag, "#comment" ) == 0 ) { }
1689        else if (strcmp(tag, "vspaceset") == 0 ) {
[158]1690            // checking source file consistency
[228]1691            if (vspace_index != header->vspaces) {
[158]1692                printf("[XML ERROR] Wrong number of vspaces\n");
1693                exit(1);
1694            }
[228]1695            else {
[158]1696                header->vsegs = vseg_index;
[160]1697                header->vobjs = vobj_index;
[158]1698                header->tasks = task_index;
1699                return;
1700            }
1701        }
[228]1702        else {
[158]1703            printf("[XML ERROR] Unknown tag in vspaceset node : %s",tag);
1704            exit(1);
1705        }
[228]1706        status = xmlTextReaderRead(reader);
[158]1707    }
1708} // end globalSetNode()
1709
[228]1710
[158]1711//////////////////////////////////////////
[228]1712void headerNode(xmlTextReaderPtr reader) {
1713    char * name;
1714    unsigned int value;
1715    unsigned int ok;
[158]1716
[228]1717    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) {
1718        return;
1719    }
[158]1720
1721#if XML_PARSER_DEBUG
[228]1722    printf("mapping_info\n");
[158]1723#endif
1724
[228]1725    header = (mapping_header_t *) malloc(sizeof(mapping_header_t));
[158]1726
[165]1727    ////////// get name attribute
[158]1728    name = getStringValue(reader, "name", &ok);
[228]1729    if (ok) {
[158]1730#if XML_PARSER_DEBUG
[228]1731        printf("  name = %s\n", name);
[158]1732#endif
[228]1733        strncpy( header->name, name, 31);
1734    }
1735    else {
[158]1736        printf("[XML ERROR] illegal or missing <name> attribute in header\n");
1737        exit(1);
1738    }
1739
[215]1740    /////////// get cluster_x attribute
1741    cluster_x = getIntValue(reader, "cluster_x", &ok);
[228]1742    if (ok) {
[158]1743#if XML_PARSER_DEBUG
[228]1744        printf("  cluster_x = %d\n", cluster_x);
[158]1745#endif
[215]1746        header->cluster_x = cluster_x;
[158]1747    }
[228]1748    else {
[215]1749        printf("[XML ERROR] illegal or missing <cluster_x> attribute in header\n");
[158]1750        exit(1);
1751    }
1752
[215]1753    /////////// get cluster_y attribute
1754    cluster_y = getIntValue(reader, "cluster_y", &ok);
[228]1755    if (ok) {
[215]1756#if XML_PARSER_DEBUG
[228]1757        printf("  cluster_y = %d\n", cluster_y);
[215]1758#endif
1759        header->cluster_y = cluster_y;
1760    }
[228]1761    else {
[215]1762        printf("[XML ERROR] illegal or missing <cluster_y> attribute in header\n");
1763        exit(1);
1764    }
1765
1766    //check the number of cluster
[228]1767    value = cluster_x * cluster_y;
1768    if (value >= MAX_CLUSTERS) {
[215]1769        printf("[XML ERROR] The number of clusters is larger than %d\n", MAX_CLUSTERS);
1770        exit(1);
1771    }
[228]1772
[215]1773    header->clusters  = value;
1774
1775#if XML_PARSER_DEBUG
[228]1776    printf("  clusters = %d\n", value);
[215]1777#endif
1778
[165]1779    ///////// get vspaces attribute
[158]1780    value = getIntValue(reader, "vspaces", &ok);
[228]1781    if (ok) {
1782        if (value >= MAX_VSPACES) {
[158]1783            printf("[XML ERROR] The number of vspaces is larger than %d\n", MAX_VSPACES);
1784            exit(1);
1785        }
1786#if XML_PARSER_DEBUG
[228]1787        printf("  vspaces = %d\n", value);
[158]1788#endif
[228]1789        header->vspaces  = value;
[158]1790    }
[228]1791    else {
[158]1792        printf("[XML ERROR] illegal or missing <vspaces> attribute in mapping\n");
1793        exit(1);
1794    }
1795
[189]1796    //////// initialise non replicated peripherals cluster_id
1797    header->tty_clusterid = 0xFFFFFFFF;
1798    header->nic_clusterid = 0xFFFFFFFF;
1799    header->ioc_clusterid = 0xFFFFFFFF;
1800    header->fbf_clusterid = 0xFFFFFFFF;
1801
1802    ///////// set signature
[158]1803    header->signature = IN_MAPPING_SIGNATURE;
1804
[181]1805    int status = xmlTextReaderRead(reader);
[228]1806    while (status == 1) {
1807        const char * tag = (const char *) xmlTextReaderConstName(reader);
[158]1808
[228]1809        if (strcmp(tag, "clusterset") == 0) {
1810            clusterSetNode(reader);
1811        }
1812        else if (strcmp(tag, "globalset")    == 0) { globalSetNode(reader); }
1813        else if (strcmp(tag, "vspaceset")    == 0) { vspaceSetNode(reader); }
1814        else if (strcmp(tag, "#text")        == 0) { }
1815        else if (strcmp(tag, "#comment")     == 0) { }
1816        else if (strcmp(tag, "mapping_info") == 0) {
[158]1817#if XML_PARSER_DEBUG
[228]1818            printf("end mapping_info\n");
[158]1819#endif
1820            return;
1821        }
[228]1822        else {
[174]1823            printf("[XML ERROR] Unknown tag in header node : %s\n",tag);
[158]1824            exit(1);
1825        }
[181]1826        status = xmlTextReaderRead(reader);
[158]1827    }
1828} // end headerNode()
[228]1829
1830
[189]1831///////////////////////////////////////
[228]1832void BuildTable(int fdout, const char * type, unsigned int nb_elem,
1833                unsigned int elem_size, char ** table) {
[181]1834    unsigned int i;
1835    // write element
[228]1836    for (i = 0; i < nb_elem; i++) {
1837        if (elem_size != write(fdout, table[i], elem_size)) {
[215]1838            printf("function %s: %s(%d) write  error \n", __FUNCTION__, type, i);
1839            exit(1);
1840        }
1841
[181]1842#if XML_PARSER_DEBUG
[228]1843        printf("Building binary: writing %s %d\n", type, i);
[181]1844#endif
[215]1845    }
1846}
[158]1847
[215]1848
[228]1849int open_file(const char * file_path) {
1850
[215]1851    //open file
[228]1852    int fdout = open( file_path, (O_CREAT | O_RDWR), (S_IWUSR | S_IRUSR) );
1853    if (fdout < 0) {
[215]1854        perror("open");
1855        exit(1);
[181]1856    }
[215]1857
[228]1858    //reinitialise the file
1859    if (ftruncate(fdout, 0)) {
1860        perror("truncate");
1861        exit(1);
1862    }
[215]1863
[228]1864    //#if XML_PARSER_DEBUG
1865    printf("%s\n", file_path);
1866    //#endif
1867
[215]1868    return fdout;
[181]1869}
1870
[215]1871
[158]1872///////////////////////////
[228]1873void buildBin(const char * file_path) {
1874    unsigned int length;
[158]1875
[215]1876    int fdout = open_file(file_path);
1877
[158]1878    // write header to binary file
[228]1879    length = write(fdout, (char *) header, sizeof(mapping_header_t));
1880    if (length != sizeof(mapping_header_t)) {
[181]1881        printf("write header error : length = %d \n", length);
[158]1882        exit(1);
1883    }
1884
1885    // write clusters
[228]1886    BuildTable(fdout, "cluster", cluster_index, sizeof(mapping_cluster_t), (char **) cluster);
[158]1887    // write psegs
[228]1888    BuildTable(fdout, "pseg", pseg_index, sizeof(mapping_pseg_t), (char **) pseg);
[158]1889    // write vspaces
[228]1890    BuildTable(fdout, "vspace", vspace_index, sizeof(mapping_vspace_t), (char **) vspace);
[158]1891    // write vsegs
[228]1892    BuildTable(fdout, "vseg", vseg_index, sizeof(mapping_vseg_t), (char **) vseg);
[160]1893    // write vobjs
[228]1894    BuildTable(fdout, "vobj", vobj_index, sizeof(mapping_vobj_t), (char **) vobj);
[189]1895    // write tasks array
[228]1896    BuildTable(fdout, "task", task_index, sizeof(mapping_task_t), (char **) task);
[189]1897    //building procs array
[228]1898    BuildTable(fdout, "proc", proc_index, sizeof(mapping_proc_t), (char **) proc);
[189]1899    //building irqs array
[228]1900    BuildTable(fdout, "irq", irq_index, sizeof(mapping_irq_t), (char **) irq);
[189]1901    //building coprocs array
[228]1902    BuildTable(fdout, "coproc", coproc_index, sizeof(mapping_coproc_t), (char **) coproc);
[189]1903    //building cp_ports array
[228]1904    BuildTable(fdout, "cp_port", cp_port_index, sizeof(mapping_cp_port_t),(char **) cp_port);
[189]1905    //building periphs array
[228]1906    BuildTable(fdout, "periph", periph_index, sizeof(mapping_periph_t), (char **) periph);
1907
[215]1908    close(fdout);
[181]1909
1910} // end buildBin()
1911
[228]1912
[189]1913///////////////////////////////////////////////////////////////////////
1914// this function set the value the vobj_id fiels of all cp_ports
1915///////////////////////////////////////////////////////////////////////
[228]1916void prepareBuild() {
[181]1917    unsigned int i;
[200]1918    //asign for all cp_ports the correct vspaceid and vobjid
[228]1919    for (i = 0; i < cp_port_index; i++) {
1920        int vspace_id = getVspaceId(cp_port_vobj_ref[i]->vspace_name);
1921        if (vspace_id < 0) {
1922            printf("[XML ERROR] illegal  <vspacename> for cp_port %d,\n", i);
[181]1923            exit(1);
1924        }
1925        cp_port[i]->vspaceid = vspace_id;
[189]1926
[228]1927        int vobj_id = getVobjLocId(vspace_id, cp_port_vobj_ref[i]->vobj_name, vspace[vspace_id]->vobjs);
1928        if (vobj_id >= 0) {
1929
[158]1930#if XML_PARSER_DEBUG
[228]1931            printf("\ncp_port = %d\n", i);
1932            printf("      vspace_name  = %s\n", cp_port_vobj_ref[i]->vspace_name);
1933            printf("      vobj_name    = %s\n", cp_port_vobj_ref[i]->vobj_name);
1934            printf("      vobj_index   = %d\n", vobj_id);
[158]1935#endif
[181]1936            cp_port[i]->vobjlocid = vobj_id;
[189]1937
1938            assert((vobj[ vspace[vspace_id]->vobj_offset + vobj_id]->type == VOBJ_TYPE_MWMR)
[228]1939                    && "coproc ports have to refer to a vobj of type MWMR");
[181]1940        }
[228]1941        else {
1942            printf("[XML ERROR] illegal  <vobjname> for cp_port %d,\n", i);
[158]1943            exit(1);
1944        }
1945    }
[181]1946}
[158]1947
[228]1948
[217]1949//////////////////////////////////////////
[228]1950void file_write(int fdout, char * towrite) {
[215]1951    unsigned int size = strlen(towrite);
[228]1952    if (size != write(fdout, towrite, size)) {
[215]1953        printf("file_write error");
1954        exit(1);
1955    }
1956}
1957
[228]1958
[217]1959//////////////////////////////////////////////////
[228]1960void def_int_write(int fdout, char * def, int num) {
1961    char  buf[64];
[215]1962    sprintf(buf, "#define\t %s  %d\n", def, num);
1963    file_write(fdout, buf);
1964}
1965
[228]1966
[217]1967/////////////////////////////////////////////////
[228]1968void def_hex_write(int fdout, char * def, int num) {
1969    char  buf[64];
[215]1970    sprintf(buf, "#define\t %s  0x%x\n", def, num);
1971    file_write(fdout, buf);
1972}
1973
[228]1974
[217]1975///////////////////////////////////////
[228]1976void  genHd(const char * file_path) {
[215]1977    int fdout = open_file(file_path);
1978
[228]1979    char * prol = " /* Generated from the mapping_info file */\n\n#ifndef _HD_CONFIG_H\n#define _HD_CONFIG_H\n\n";
[215]1980    file_write(fdout, prol);
1981
[228]1982    def_int_write(fdout, "CLUSTER_X"    , cluster_x);
1983    def_int_write(fdout, "CLUSTER_Y"    , cluster_y);
1984    def_int_write(fdout, "NB_CLUSTERS"  , cluster_index);
1985    def_hex_write(fdout, "CLUSTER_SIZE" , (((unsigned long long) 1) << 32) / cluster_index);
1986    def_int_write(fdout, "NB_PROCS_MAX" , nb_proc_max);
1987    def_int_write(fdout, "NB_TIMERS_MAX", nb_timer_channel_max);
1988    def_int_write(fdout, "NB_DMAS_MAX"  , nb_dma_channel_max);
1989    def_int_write(fdout, "NB_TTYS"      , nb_tty_channel);
1990    def_int_write(fdout, "NB_IOCS"      , nb_ioc_channel);
1991    def_int_write(fdout, "NB_NICS"      , nb_nic_channel);
1992
[215]1993    file_write(fdout, "\n");
[228]1994    def_int_write(fdout, "USE_XICU"     , use_xicu);
1995    def_int_write(fdout, "IOMMU_ACTIVE ", io_mmu_active);
[215]1996
[228]1997    char * epil = "\n#endif //_HD_CONFIG_H";
[215]1998    file_write(fdout, epil);
1999
2000    close(fdout);
2001}
2002
[228]2003
[217]2004////////////////////////////////////////////////////////
[228]2005void ld_write(int fdout, char * seg, unsigned int addr) {
2006    char buf[64];
[215]2007    sprintf(buf, "%s = 0x%x;\n", seg, addr);
2008    file_write(fdout, buf);
2009
2010}
2011
[228]2012
[217]2013///////////////////////////////////////
[228]2014void genLd(const char * file_path) {
[215]2015    int fdout = open_file(file_path);
2016
[228]2017    char * prol = "/* Generated from the mapping_info file */\n\n";
[215]2018    file_write(fdout, prol);
2019
2020    //boot
[228]2021    ld_write(fdout, "seg_boot_code_base", boot_code_base);
2022    ld_write(fdout, "seg_boot_stack_base", boot_stack_base);
2023    ld_write(fdout, "seg_mapping_base", boot_mapping_base);
[215]2024
2025    //kernel
[228]2026    ld_write(fdout, "\nseg_kernel_code_base",  kernel_code_base);
2027    ld_write(fdout, "seg_kernel_data_base",    kernel_data_base);
2028    ld_write(fdout, "seg_kernel_uncdata_base", kernel_uncdata_base);
2029    ld_write(fdout, "seg_kernel_init_base",    kernel_init_base);
[215]2030
2031    //peripherals
[228]2032    ld_write(fdout, "\nseg_fbf_base", fbf_base_offset);
2033    ld_write(fdout, "seg_icu_base",   icu_base_offset);
2034    ld_write(fdout, "seg_ioc_base",   ioc_base_offset);
2035    ld_write(fdout, "seg_nic_base",   nic_base_offset);
2036    ld_write(fdout, "seg_tty_base",   tty_base_offset);
2037    ld_write(fdout, "seg_dma_base",   dma_base_offset);
2038    ld_write(fdout, "seg_tim_base",   tim_base_offset);
2039    ld_write(fdout, "seg_gcd_base",   gcd_base_offset);
2040    ld_write(fdout, "seg_iob_base",   iob_base_offset);
[215]2041
2042    close(fdout);
2043}
2044
[228]2045
2046char * buildPath(const char * path, const char * name) {
[222]2047    char * res = calloc(strlen(path) + strlen(name) + 1, 1);
[215]2048    strcat(res, path);
2049    strcat(res, "/");
2050    strcat(res, name);
2051    return res; 
2052}
2053
[228]2054
[158]2055/////////////////////////////////////
[228]2056int main(int argc, char * argv[]) {
2057    if (argc < 3) {
[215]2058        printf("Usage: xml2bin <input_file_path> <output_path>\n");
[158]2059        return 1;
2060    }
2061
[215]2062    struct stat dir_st;
[228]2063    if (stat( argv[2], &dir_st)) {
[215]2064        perror("bad path");
[158]2065        exit(1);
2066    }
[215]2067
[228]2068    if ((dir_st.st_mode & S_IFDIR) == 0) {
[215]2069        printf("path is not a dir: %s", argv[2] );
2070        exit(1);
2071    }
2072
2073
[228]2074    char * map_path = buildPath(argv[2], "map.bin"); 
2075    char * ld_path = buildPath(argv[2], "giet_vsegs.ld"); 
2076    char * hd_path = buildPath(argv[2], "hard_config.h"); 
2077
[158]2078    LIBXML_TEST_VERSION;
2079
[181]2080    int status;
[228]2081    xmlTextReaderPtr reader = xmlReaderForFile(argv[1], NULL, 0);
[158]2082
[228]2083    if (reader != NULL) {
2084        status = xmlTextReaderRead (reader);
2085        while (status == 1) {
2086            const char * tag = (const char *) xmlTextReaderConstName(reader);
[181]2087
[228]2088            if (strcmp(tag, "mapping_info") == 0) { 
2089                headerNode(reader);
[181]2090                prepareBuild();
[228]2091                buildBin(map_path);
[215]2092                genHd(hd_path);
2093                genLd(ld_path);
[158]2094            }
[228]2095            else {
[158]2096                printf("[XML ERROR] Wrong file type: \"%s\"\n", argv[1]);
2097                return 1;
2098            }
[228]2099            status = xmlTextReaderRead(reader);
[158]2100        }
[228]2101        xmlFreeTextReader(reader);
[158]2102
[228]2103        if (status != 0) {
[158]2104            printf("[XML ERROR] Wrong Syntax in \"%s\" file\n", argv[1]);
2105            return 1;
2106        }
2107    }
2108    return 0;
2109} // end main()
[222]2110
2111
[228]2112// Local Variables:
2113// tab-width: 4
2114// c-basic-offset: 4
2115// c-file-offsets:((innamespace . 0)(inline-open . 0))
2116// indent-tabs-mode: nil
2117// End:
2118// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
[222]2119
Note: See TracBrowser for help on using the repository browser.