Ignore:
Timestamp:
Feb 12, 2013, 6:33:31 PM (11 years ago)
Author:
meunier
Message:

Added support for memspaces and const.
Added an interrupt masking to the "giet_context_switch" syscall
Corrected two bugs in boot/boot_init.c (one minor and one regarding barriers initialization)
Reformatted the code in all files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/xml/xml_parser.c

    r226 r228  
    3030#include  <irq_handler.h>
    3131
    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
     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
    4646
    4747///////////////////////////////////////////////////////////////////////////////////
    48 //      global variables used to store and index the data structures
     48//     global variables used to store and index the data structures
    4949///////////////////////////////////////////////////////////////////////////////////
    5050
    51 mapping_header_t*      header;
    52 mapping_cluster_t*      cluster[MAX_CLUSTERS];  // cluster array
    53 mapping_pseg_t*         pseg[MAX_PSEGS];                // pseg array
    54 mapping_vspace_t*       vspace[MAX_VSPACES];    // vspace array
    55 mapping_vseg_t*         vseg[MAX_VSEGS];                // vseg array
    56 mapping_vobj_t*         vobj[MAX_VOBJS];                // vobj array
    57 mapping_task_t*         task[MAX_TASKS];                // task array
    58 mapping_proc_t*         proc[MAX_PROCS];                // proc array
    59 mapping_irq_t*          irq[MAX_IRQS];                  // irq array
    60 mapping_coproc_t*       coproc[MAX_COPROCS];    // coproc array
    61 mapping_cp_port_t*          cp_port[MAX_CP_PORTS];      // coproc port array
    62 mapping_periph_t*       periph[MAX_PERIPHS];    // peripheral array
     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
    6363
    6464// Index for the various arrays
    6565
    66 unsigned int            cluster_index  = 0;
    67 unsigned int            vspace_index  = 0;
    68 unsigned int            global_index  = 0;
    69 unsigned int            pseg_index     = 0;             
    70 
    71 unsigned int            proc_index    = 0;
    72 unsigned int            proc_loc_index = 0;
    73 
    74 unsigned int            irq_index      = 0;
    75 unsigned int            irq_loc_index  = 0;
    76 
    77 unsigned int            coproc_index    = 0;
    78 unsigned int            coproc_loc_index = 0;
    79 
    80 unsigned int            cp_port_index    = 0;
    81 unsigned int            cp_port_loc_index = 0;
    82 
    83 unsigned int            periph_index    = 0;
    84 unsigned int            periph_loc_index = 0;
    85 
    86 unsigned int            vseg_index    = 0;
    87 unsigned int            vseg_loc_index = 0;
    88 
    89 unsigned int            task_index    = 0;
    90 unsigned int            task_loc_index = 0;
    91 
    92 unsigned int            vobj_index    = 0;
    93 unsigned int            vobj_loc_index = 0;
    94 unsigned int            vobj_count    = 0;
     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;
    9595
    9696
     
    107107//needed to generate map_config.ld
    108108//////////////////////////////////
    109 unsigned int cluster_y              = 0;
    110 unsigned int cluster_x              = 0;
    111 unsigned int nb_proc_max            = 0; // max number of processors per cluster
    112 unsigned int nb_timer_channel_max   = 0; // max number of user timer
    113 unsigned int nb_dma_channel_max     = 0;
    114 unsigned int nb_tty_channel         = 0;
    115 unsigned int nb_ioc_channel         = 0;
    116 unsigned int nb_nic_channel         = 0;
    117 unsigned int io_mmu_active          = 0;
    118 unsigned int use_xicu               = 0xFFFFFFFF;
     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;
    119119
    120120
     
    124124
    125125//kernel and boot code
    126 unsigned int kernel_code_base    = 0x80000000;  /* kernel code */
    127 unsigned int kernel_data_base    = 0x80010000;  /* system cacheable data */
    128 unsigned int kernel_uncdata_base = 0x80080000;  /* system uncacheable data */
    129 unsigned int kernel_init_base    = 0x80090000;  /* system init entry */
    130 
    131 unsigned int boot_code_base      = 0xBFC00000;  /* boot code */
    132 unsigned int boot_stack_base     = 0xBFC08000;  /* boot temporary stack */
    133 unsigned int boot_mapping_base   = 0xBFC0C000;  /* mapping_info blob */
     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 */
     130
     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 */
    134134
    135135//periphs
     
    151151// once all the vspace have been parsed.
    152152/////////////////////////////////////////////////////////////////////
    153 typedef struct vobj_ref_s
    154 {
     153typedef struct vobj_ref_s {
    155154    char vspace_name[32];
    156155    char vobj_name[32];
    157 }vobj_ref_t;
    158 
    159 vobj_ref_t*             cp_port_vobj_ref[MAX_CP_PORTS];
     156} vobj_ref_t;
     157
     158vobj_ref_t * cp_port_vobj_ref[MAX_CP_PORTS];   
    160159
    161160
    162161//////////////////////////////////////////////////
    163 unsigned int getIntValue( xmlTextReaderPtr reader,
    164                           const char*      attributeName,
    165                           unsigned int*    ok )
    166 {
    167     unsigned int        value = 0;
    168     unsigned int        i;
    169     char        c;
    170 
    171     char* string = (char*)xmlTextReaderGetAttribute(reader, (const xmlChar*)attributeName);
    172 
    173     if ( string == NULL )  // missing argument
    174     {
     162unsigned int getIntValue(xmlTextReaderPtr reader, const char * attributeName, unsigned int * ok) {
     163    unsigned int value = 0;
     164    unsigned int i;
     165    char c;
     166
     167    char * string = (char *) xmlTextReaderGetAttribute(reader, (const xmlChar *) attributeName);
     168
     169    if (string == NULL) {
     170        // missing argument
    175171        *ok = 0;
    176172        return 0;
    177173    }
    178     else
    179     {
    180         if ( (string[0] == '0') && ((string[1] == 'x') || (string[1] == 'X')) )  // Hexa
    181         {
    182             for ( i = 2 ; (string[i] != 0) && (i < 10) ; i++ )
    183             {
     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++) {
    184178                c = string[i];
    185                 if      ((c >= '0') && (c <= '9')) value = (value<<4) + string[i] - 48;
    186                 else if ((c >= 'a') && (c <= 'f')) value = (value<<4) + string[i] - 87;
    187                 else if ((c >= 'A') && (c <= 'F')) value = (value<<4) + string[i] - 55;
    188                 else   
    189                 {
     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 {
    190183                    *ok = 0;
    191184                    return 0;
     
    193186            }
    194187        }
    195         else                                                            // Decimal
    196         {
    197             for ( i = 0 ; (string[i] != 0) && (i < 9) ; i++ )
    198             {
     188        else {
     189            // Decimal
     190            for (i = 0; (string[i] != 0) && (i < 9); i++) {
    199191                c = string[i];
    200                 if ((c >= '0') && (c <= '9')) value = (value*10) + string[i] - 48;
    201                 else
    202                 {
     192                if ((c >= '0') && (c <= '9')) value = (value * 10) + string[i] - 48;
     193                else {
    203194                    *ok = 0;
    204195                    return 0;
     
    211202} // end getIntValue()
    212203
     204
    213205///////////////////////////////////////////////
    214 char* getStringValue ( xmlTextReaderPtr reader,
    215                        const char*      attributeName,
    216                        unsigned int*    ok )
    217 {
    218     char* string = (char*)xmlTextReaderGetAttribute(reader, (const xmlChar*)attributeName);
    219 
    220    
    221     if ( string == NULL )  // missing argument
    222     {
     206char * getStringValue(xmlTextReaderPtr reader, const char * attributeName, unsigned int * ok) {
     207    char * string = (char *) xmlTextReaderGetAttribute(reader, (const xmlChar *) attributeName);
     208
     209
     210    if (string == NULL) {
     211        // missing argument
    223212        *ok = 0;
    224213        return NULL;
    225214    }
    226     else
    227     {
     215    else {
    228216        //we read only string smaller than 32 byte
    229         if(strlen(string) > 32)
    230         {
     217        if (strlen(string) > 32) {
    231218            printf("[XML ERROR] all strings must be less than 32 bytes\n");
    232219            exit(1);
     
    238225} // end getStringValue()
    239226
     227
    240228///////////////////////////////////////
    241 int getPsegId( unsigned int     cluster_id,
    242                char*        pseg_name )
    243 {
     229int getPsegId(unsigned int cluster_id, char * pseg_name) {
    244230    unsigned int pseg_id;
    245231    unsigned int pseg_min = cluster[cluster_id]->pseg_offset;
    246232    unsigned int pseg_max = pseg_min + cluster[cluster_id]->psegs;
    247233
    248     for ( pseg_id = pseg_min ; pseg_id < pseg_max ; pseg_id++ )
    249     {
    250         if ( strcmp(pseg[pseg_id]->name, pseg_name) == 0 )
    251         {
     234    for (pseg_id = pseg_min; pseg_id < pseg_max; pseg_id++) {
     235        if (strcmp(pseg[pseg_id]->name, pseg_name) == 0) {
    252236            return pseg_id;
    253237        }
     
    256240}
    257241
     242
    258243////////////////////////////////////////////
    259 int getVspaceId( char*         vspace_name)
    260 {
     244int getVspaceId(char * vspace_name) {
    261245    unsigned int vspace_id;
    262246
    263     for( vspace_id = 0; vspace_id < vspace_index ; vspace_id++)
    264     {
    265         if( !strcmp(vspace[vspace_id]->name, vspace_name))
    266         {
     247    for (vspace_id = 0; vspace_id < vspace_index; vspace_id++) {
     248        if (!strcmp(vspace[vspace_id]->name, vspace_name)) {
    267249            return vspace_id;
    268250        }
     
    271253}
    272254
     255
    273256////////////////////////////////////////////
    274 int getVobjLocId( unsigned int  vspace_id,
    275                   char*             vobj_name,
    276                   unsigned int  vspace_max)
    277 {
     257int getVobjLocId(unsigned int vspace_id, char * vobj_name, unsigned int vspace_max) {
    278258    unsigned int vobj_id;
    279259    unsigned int vobj_min = vspace[vspace_id]->vobj_offset;
    280260    unsigned int vobj_max = vobj_min + vspace_max;
    281261
    282     for ( vobj_id = vobj_min ; vobj_id < vobj_max ; vobj_id++ )
    283     {
    284         if ( strcmp(vobj[vobj_id]->name, vobj_name) == 0 )
    285         {
    286              return (vobj_id - vobj_min);
     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);
    287265        }
    288266    }
     
    290268}
    291269
     270
    292271/////////////////////////////////////////
    293 void taskNode ( xmlTextReaderPtr reader )
    294 /////////////////////////////////////////
    295 {
    296     unsigned int        ok;
    297     unsigned int        value;
    298     char*               str;
    299 
    300     if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return;
    301 
    302     if ( task_index >= MAX_TASKS )
    303     {
     272void taskNode(xmlTextReaderPtr reader) {
     273    unsigned int ok;
     274    unsigned int value;
     275    char * str;
     276
     277    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) {
     278        return;
     279    }
     280
     281    if (task_index >= MAX_TASKS) {
    304282        printf("[XML ERROR] The number of tasks is larger than %d\n", MAX_TASKS);
    305283    }
    306284
    307285#if XML_PARSER_DEBUG
    308 printf("   task %d\n", task_loc_index);
    309 #endif
    310 
    311     task[task_index] = (mapping_task_t*)malloc(sizeof(mapping_task_t));
     286    printf("   task %d\n", task_loc_index);
     287#endif
     288
     289    task[task_index] = (mapping_task_t *) malloc(sizeof(mapping_task_t));
    312290
    313291    ////////// get name attribute
    314292    str = getStringValue(reader, "name", &ok);
    315     if ( ok )
    316     {
    317 #if XML_PARSER_DEBUG
    318 printf("      name = %s\n", str);
     293    if (ok) {
     294#if XML_PARSER_DEBUG
     295        printf("      name = %s\n", str);
    319296#endif
    320297        strncpy( task[task_index]->name, str, 31 );
    321298    }
    322     else
    323     {
     299    else {
    324300        printf("[XML ERROR] illegal or missing <name> attribute for task (%d,%d)\n",
    325                vspace_index, task_loc_index);
     301                vspace_index, task_loc_index);
    326302        exit(1);
    327303    }
    328304
    329305    ///////// get clusterid attribute
    330     value = getIntValue(reader,"clusterid", &ok);
    331     if ( ok )
    332     {
    333 #if XML_PARSER_DEBUG
    334 printf("      clusterid = %x\n", value);
    335 #endif
    336         if ( value >= header->clusters )
    337         {
     306    value = getIntValue(reader, "clusterid", &ok);
     307    if (ok) {
     308#if XML_PARSER_DEBUG
     309        printf("      clusterid = %x\n", value);
     310#endif
     311        if (value >= header->clusters) {
    338312            printf("[XML ERROR] <clusterid> too large for task (%d,%d)\n",
    339                    vspace_index, task_loc_index);
     313                    vspace_index, task_loc_index);
    340314            exit(1);
    341315        }
    342316        task[task_index]->clusterid = value;
    343317    } 
    344     else
    345     {
     318    else {
    346319        printf("[XML ERROR] illegal or missing <clusterid> attribute for task (%d,%d)\n",
    347                vspace_index, task_loc_index);
     320                vspace_index, task_loc_index);
    348321        exit(1);
    349322    }
    350323
    351324    ////////// get proclocid attribute
    352     value = getIntValue(reader,"proclocid", &ok);
    353     if ( ok )
    354     {
    355 #if XML_PARSER_DEBUG
    356 printf("      proclocid = %x\n", value);
    357 #endif
    358         if ( value >= cluster[task[task_index]->clusterid]->procs )
    359         {
     325    value = getIntValue(reader, "proclocid", &ok);
     326    if (ok) {
     327#if XML_PARSER_DEBUG
     328        printf("      proclocid = %x\n", value);
     329#endif
     330        if (value >= cluster[task[task_index]->clusterid]->procs) {
    360331            printf("[XML ERROR] <proclocid> too large for task (%d,%d)\n",
    361                    vspace_index, task_loc_index);
     332                    vspace_index, task_loc_index);
    362333            exit(1);
    363334        }
    364335        task[task_index]->proclocid = value;
    365336    } 
    366     else
    367     {
     337    else {
    368338        printf("[XML ERROR] illegal or missing <locprocid> attribute for task (%d,%d)\n",
    369339                vspace_index, task_loc_index);
     
    373343    ////////// get stackname attribute
    374344    str = getStringValue(reader, "stackname" , &ok);
    375     if ( ok )
    376     {
    377         int index = getVobjLocId( vspace_index, str , vobj_loc_index);
    378         if ( index >= 0 )
    379         {
    380 #if XML_PARSER_DEBUG
    381 printf("      stackname = %s\n", str);
    382 printf("      stackid   = %d\n", index);
     345    if (ok) {
     346        int index = getVobjLocId(vspace_index, str , vobj_loc_index);
     347        if (index >= 0) {
     348#if XML_PARSER_DEBUG
     349            printf("      stackname = %s\n", str);
     350            printf("      stackid   = %d\n", index);
    383351#endif
    384352            task[task_index]->vobjlocid = index;
    385353        }
    386         else             
    387         {
     354        else {
    388355            printf("[XML ERROR] illegal or missing <stackname> for task (%d,%d)\n",
    389356                    vspace_index, task_loc_index);
     
    391358        }
    392359    } 
    393     else
    394     {
     360    else {
    395361        printf("[XML ERROR] illegal or missing <stackname> for task (%d,%d)\n",
    396362                vspace_index, task_loc_index);
     
    399365
    400366    ////////// get startid  attribute
    401     value = getIntValue(reader,"startid", &ok);
    402     if ( ok )
    403     {
    404 #if XML_PARSER_DEBUG
    405 printf("      startid = %x\n", value);
     367    value = getIntValue(reader, "startid", &ok);
     368    if (ok) {
     369#if XML_PARSER_DEBUG
     370        printf("      startid = %x\n", value);
    406371#endif
    407372        task[task_index]->startid = value;
    408373    } 
    409     else
    410     {
     374    else {
    411375        printf("[XML ERROR] illegal or missing <startid> attribute for task (%d,%d)\n",
    412376                vspace_index, task_loc_index);
     
    415379
    416380    /////////// get usetty  attribute (optionnal : 0 if missing)
    417     value = getIntValue(reader,"usetty", &ok);
    418     if ( ok )
    419     {
    420 #if XML_PARSER_DEBUG
    421 printf("      usetty = %x\n", value);
     381    value = getIntValue(reader, "usetty", &ok);
     382    if (ok) {
     383#if XML_PARSER_DEBUG
     384        printf("      usetty = %x\n", value);
    422385#endif
    423386        task[task_index]->use_tty = value;
    424387    } 
    425     else
    426     {
     388    else {
    427389        task[task_index]->use_tty = 0;
    428390    }
    429391
    430392    /////////// get usenic  attribute (optionnal : 0 if missing)
    431     value = getIntValue(reader,"usenic", &ok);
    432     if ( ok )
    433     {
    434 #if XML_PARSER_DEBUG
    435 printf("      usenic = %x\n", value);
     393    value = getIntValue(reader, "usenic", &ok);
     394    if (ok) {
     395#if XML_PARSER_DEBUG
     396        printf("      usenic = %x\n", value);
    436397#endif
    437398        task[task_index]->use_nic = value;
    438399    } 
    439     else
    440     {
     400    else {
    441401        task[task_index]->use_nic = 0;
    442402    }
    443403
    444404    /////////// get usetimer attribute (optionnal : 0 if missing)
    445     value = getIntValue(reader,"usetimer", &ok);
    446     if ( ok )
    447     {
    448 #if XML_PARSER_DEBUG
    449 printf("      usetimer = %x\n", value);
     405    value = getIntValue(reader, "usetimer", &ok);
     406    if (ok) {
     407#if XML_PARSER_DEBUG
     408        printf("      usetimer = %x\n", value);
    450409#endif
    451410        task[task_index]->use_timer = value;
    452411    } 
    453     else
    454     {
     412    else {
    455413        task[task_index]->use_timer = 0;
    456414    }
    457415
    458416    /////////// get usefbdma  attribute (optionnal : 0 if missing)
    459     value = getIntValue(reader,"usefbdma", &ok);
    460     if ( ok )
    461     {
    462 #if XML_PARSER_DEBUG
    463 printf("      usefbdma = %x\n", value);
     417    value = getIntValue(reader, "usefbdma", &ok);
     418    if (ok) {
     419#if XML_PARSER_DEBUG
     420        printf("      usefbdma = %x\n", value);
    464421#endif
    465422        task[task_index]->use_fbdma = value;
    466     } 
    467     else
    468     {
     423    }
     424    else {
    469425        task[task_index]->use_fbdma = 0;
    470426    }
     
    474430} // end taskNode()
    475431
     432
    476433//////////////////////////////////////////
    477 void  vobjNode ( xmlTextReaderPtr reader )
    478 //////////////////////////////////////////
    479 {
    480     unsigned int        ok;
    481     unsigned int        value;
    482     char*               str;
    483 
    484     if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return;
    485 
    486     if ( vobj_index >= MAX_VOBJS )
    487     {
     434void vobjNode(xmlTextReaderPtr reader) {
     435    unsigned int ok;
     436    unsigned int value;
     437    char * str;
     438
     439    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) {
     440        return;
     441    }
     442
     443    if (vobj_index >= MAX_VOBJS) {
    488444        printf("[XML ERROR] The number of vobjs is larger than %d\n", MAX_VSEGS);
    489445        exit(1);
     
    491447
    492448#if XML_PARSER_DEBUG
    493 printf("      vobj %d\n", vobj_loc_index);
    494 #endif
    495 
    496     vobj[vobj_index] = (mapping_vobj_t*)malloc(sizeof(mapping_vobj_t));
     449    printf("      vobj %d\n", vobj_loc_index);
     450#endif
     451
     452    vobj[vobj_index] = (mapping_vobj_t *) malloc(sizeof(mapping_vobj_t));
    497453
    498454    ///////// get name attribute
    499455    str = getStringValue(reader, "name", &ok);
    500     if ( ok )
    501     {
    502 #if XML_PARSER_DEBUG
    503 printf("        name = %s\n", str);
    504 #endif
    505         strncpy( vobj[vobj_index]->name, str, 31);
    506     }
    507     else
    508     {
     456    if (ok) {
     457#if XML_PARSER_DEBUG
     458        printf("        name = %s\n", str);
     459#endif
     460        strncpy(vobj[vobj_index]->name, str, 31);
     461    }
     462    else {
    509463        printf("[XML ERROR] illegal or missing <name> attribute for vobj (%d,%d)\n",
    510464                vseg_index, vobj_loc_index);
     
    515469    str = getStringValue(reader, "type", &ok);
    516470#if XML_PARSER_DEBUG
    517 printf("        type = %s\n", str);
    518 #endif
    519     if (ok && (strcmp(str, "ELF") == 0))
    520     {
     471    printf("        type = %s\n", str);
     472#endif
     473    if (ok && (strcmp(str, "ELF") == 0)) {
    521474        vobj[vobj_index]->type = VOBJ_TYPE_ELF;
    522475
    523476        //check that this vobj is the first in vseg
    524         if(vobj_count != 0)
    525         {
     477        if (vobj_count != 0) {
    526478            printf("[XML ERROR] an ELF vobj must be alone in a vseg (%d,%d)\n",
    527479                    vspace_index, vobj_loc_index);
     
    529481        }
    530482    }
    531     else if (ok && (strcmp(str, "BLOB")    == 0)) vobj[vobj_index]->type = VOBJ_TYPE_BLOB;
    532     else if (ok && (strcmp(str, "PTAB")    == 0)) vobj[vobj_index]->type = VOBJ_TYPE_PTAB;
    533     else if (ok && (strcmp(str, "PERI")    == 0)) vobj[vobj_index]->type = VOBJ_TYPE_PERI;
    534     else if (ok && (strcmp(str, "MWMR")    == 0)) vobj[vobj_index]->type = VOBJ_TYPE_MWMR;
    535     else if (ok && (strcmp(str, "LOCK")    == 0)) vobj[vobj_index]->type = VOBJ_TYPE_LOCK;
    536     else if (ok && (strcmp(str, "BUFFER")  == 0)) vobj[vobj_index]->type = VOBJ_TYPE_BUFFER;
    537     else if (ok && (strcmp(str, "BARRIER") == 0)) vobj[vobj_index]->type = VOBJ_TYPE_BARRIER;
    538     else
    539     {
     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 {
    540493        printf("[XML ERROR] illegal or missing <type> attribute for vobj (%d,%d)\n",
    541494                vspace_index, vobj_loc_index);
     
    544497
    545498    ////////// get length attribute
    546     value = getIntValue(reader,"length", &ok);
    547     if ( ok )
    548     {
    549 #if XML_PARSER_DEBUG
    550 printf("        length = %d\n", value);
     499    value = getIntValue(reader, "length", &ok);
     500    if (ok) {
     501#if XML_PARSER_DEBUG
     502        printf("        length = %d\n", value);
    551503#endif
    552504        vobj[vobj_index]->length = value;
    553505    } 
    554     else
    555     {
     506    else {
    556507        printf("[XML ERROR] illegal or missing <length> attribute for vobj (%d,%d)\n",
    557508                vspace_index, vobj_loc_index);
     
    560511
    561512    ////////// get align attribute (optional : 0 if missing)
    562     value = getIntValue(reader,"align", &ok);
    563     if ( ok )
    564     {
    565 #if XML_PARSER_DEBUG
    566 printf("        align = %d\n", value);
     513    value = getIntValue(reader, "align", &ok);
     514    if (ok) {
     515#if XML_PARSER_DEBUG
     516        printf("        align = %d\n", value);
    567517#endif
    568518        vobj[vobj_index]->align = value;
    569519    } 
    570     else
    571     {
     520    else {
    572521        vobj[vobj_index]->align = 0;
    573522    }
     
    575524    ////////// get binpath attribute (optional : '\0' if missing)
    576525    str = getStringValue(reader, "binpath", &ok);
    577     if ( ok )
    578     {
    579 #if XML_PARSER_DEBUG
    580 printf("        binpath = %s\n", str);
     526    if (ok) {
     527#if XML_PARSER_DEBUG
     528        printf("        binpath = %s\n", str);
    581529#endif
    582530        strncpy(vobj[vobj_index]->binpath, str, 63);
    583531    } 
    584     else
    585     {
     532    else {
    586533        vobj[vobj_index]->binpath[0] = '\0';
    587534    }
    588    
     535
    589536    ////////// get init attribute (mandatory for mwmr and barrier)
    590     value = getIntValue(reader,"init", &ok);
    591     if ( ok )
    592     {
    593 #if XML_PARSER_DEBUG
    594 printf("        init  = %d\n", value);
     537    value = getIntValue(reader, "init", &ok);
     538    if (ok) {
     539#if XML_PARSER_DEBUG
     540        printf("        init  = %d\n", value);
    595541#endif
    596542        vobj[vobj_index]->init = value;
    597543    } 
    598     else
    599     {
    600         if( (vobj[vobj_index]->type == VOBJ_TYPE_MWMR) ||
    601             (vobj[vobj_index]->type == VOBJ_TYPE_BARRIER) )
    602         {
     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)) {
    603548            printf("[XML ERROR] illegal or missing <value> attribute for vobj (%d,%d). \
    604                                         All MWMR or BARRIER vobj must have a init value \n",
     549                    All MWMR or BARRIER vobj must have a init value \n",
    605550                    vspace_index, vobj_loc_index);
    606551            exit(1);
     
    614559} // end vobjNode()
    615560
     561
    616562//////////////////////////////////////////
    617 void  vsegNode ( xmlTextReaderPtr reader )
    618 //////////////////////////////////////////
    619 {
    620     unsigned int        ok;
    621     unsigned int        value;
    622     char*               str;
    623 
    624         vobj_count = 0;
    625 
    626     if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return;
    627 
    628     if ( vseg_index >= MAX_VSEGS )
    629     {
     563void vsegNode(xmlTextReaderPtr reader) {
     564    unsigned int ok;
     565    unsigned int value;
     566    char * str;
     567
     568    vobj_count = 0;
     569
     570    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) {
     571        return;
     572    }
     573
     574    if (vseg_index >= MAX_VSEGS) {
    630575        printf("[XML ERROR] The number of vsegs is larger than %d\n", MAX_VSEGS);
    631576        exit(1);
     
    633578
    634579#if XML_PARSER_DEBUG
    635 printf("    vseg %d\n", vseg_loc_index);
    636 #endif
    637 
    638     vseg[vseg_index] = (mapping_vseg_t*)malloc(sizeof(mapping_vseg_t));
    639    
     580    printf("    vseg %d\n", vseg_loc_index);
     581#endif
     582
     583    vseg[vseg_index] = (mapping_vseg_t *) malloc(sizeof(mapping_vseg_t));
     584
    640585    ////////// set vobj_offset attributes
    641586    vseg[vseg_index]->vobj_offset = vobj_index;
    642587#if XML_PARSER_DEBUG
    643 printf("      vobj_offset = %d\n", vobj_index);
     588    printf("      vobj_offset = %d\n", vobj_index);
    644589#endif
    645590
    646591    ///////// get name attribute
    647592    str = getStringValue(reader, "name", &ok);
    648     if ( ok )
    649     {
    650 #if XML_PARSER_DEBUG
    651 printf("      name = %s\n", str);
     593    if (ok) {
     594#if XML_PARSER_DEBUG
     595        printf("      name = %s\n", str);
    652596#endif
    653597        strncpy( vseg[vseg_index]->name, str, 31);
    654598    }
    655     else
    656     {
     599    else {
    657600        printf("[XML ERROR] illegal or missing <name> attribute for vseg (%d,%d)\n",
    658601                vspace_index, vseg_loc_index);
     
    661604
    662605    ////////// get ident attribute (optional : 0 if missing)
    663     value = getIntValue(reader,"ident", &ok);
    664     if ( ok )
    665     {
    666 #if XML_PARSER_DEBUG
    667 printf("      ident = %d\n", value);
     606    value = getIntValue(reader, "ident", &ok);
     607    if (ok) {
     608#if XML_PARSER_DEBUG
     609        printf("      ident = %d\n", value);
    668610#endif
    669611        vseg[vseg_index]->ident = value;
    670612    } 
    671     else
    672     {
     613    else {
    673614        vseg[vseg_index]->ident = 0;
    674615    }
    675616
    676617    /////////// get vbase attribute
    677     value = getIntValue(reader,"vbase", &ok);
    678     if ( ok )
    679     {
    680 #if XML_PARSER_DEBUG
    681 printf("      vbase = 0x%x\n", value);
     618    value = getIntValue(reader, "vbase", &ok);
     619    if (ok) {
     620#if XML_PARSER_DEBUG
     621        printf("      vbase = 0x%x\n", value);
    682622#endif
    683623        vseg[vseg_index]->vbase = value;
    684624    }
    685     else
    686     {
     625    else {
    687626        printf("[XML ERROR] illegal or missing <vbase> attribute for vseg (%d,%d)\n",
    688627                vspace_index, vseg_loc_index);
     
    691630
    692631    ////////// get clusterid and psegname attributes
    693     value = getIntValue(reader,"clusterid", &ok);
    694     if ( ok == 0 )
    695     {
     632    value = getIntValue(reader, "clusterid", &ok);
     633    if (ok == 0) {
    696634        printf("[XML ERROR] illegal or missing <clusterid> for vseg %d\n",
    697                  vseg_loc_index);
    698         exit(1);
    699     }
    700     str = getStringValue(reader,"psegname", &ok);
    701     if ( ok == 0 )
    702     {
     635                vseg_loc_index);
     636        exit(1);
     637    }
     638    str = getStringValue(reader, "psegname", &ok);
     639    if (ok == 0) {
    703640        printf("[XML ERROR] illegal or missing <psegname> for vseg %d\n",
    704                  vseg_loc_index);
     641                vseg_loc_index);
    705642        exit(1);
    706643    }
    707644
    708645    /////////// set psegid field
    709     int index = getPsegId( value, str );
    710     if ( index >= 0 )
    711     {
    712 #if XML_PARSER_DEBUG
    713 printf("      clusterid = %d\n", value);
    714 printf("      psegname  = %s\n", str);
    715 printf("      psegid    = %d\n", index);
     646    int index = getPsegId(value, str);
     647    if (index >= 0) {
     648#if XML_PARSER_DEBUG
     649        printf("      clusterid = %d\n", value);
     650        printf("      psegname  = %s\n", str);
     651        printf("      psegid    = %d\n", index);
    716652#endif
    717653        vseg[vseg_index]->psegid = index;
    718654    }
    719     else             
    720     {
     655    else {
    721656        printf("[XML ERROR] pseg not found for vseg %d / clusterid = %d / psegname = %s\n",
    722                    vseg_loc_index, value, str );
     657                vseg_loc_index, value, str );
    723658        exit(1);
    724659    } 
    725660
    726661    //////// get mode attribute
    727     str = getStringValue(reader,"mode", &ok);
    728 #if XML_PARSER_DEBUG
    729 printf("      mode = %s\n", str);
    730 #endif
    731     if      (ok && (strcmp(str, "CXWU") == 0)) vseg[vseg_index]->mode = 0xF;
    732     else if (ok && (strcmp(str, "CXW_") == 0)) vseg[vseg_index]->mode = 0xE;
    733     else if (ok && (strcmp(str, "CX_U") == 0)) vseg[vseg_index]->mode = 0xD;
    734     else if (ok && (strcmp(str, "CX__") == 0)) vseg[vseg_index]->mode = 0xC;
    735     else if (ok && (strcmp(str, "C_WU") == 0)) vseg[vseg_index]->mode = 0xB;
    736     else if (ok && (strcmp(str, "C_W_") == 0)) vseg[vseg_index]->mode = 0xA;
    737     else if (ok && (strcmp(str, "C__U") == 0)) vseg[vseg_index]->mode = 0x9;
    738     else if (ok && (strcmp(str, "C___") == 0)) vseg[vseg_index]->mode = 0x8;
    739     else if (ok && (strcmp(str, "_XWU") == 0)) vseg[vseg_index]->mode = 0x7;
    740     else if (ok && (strcmp(str, "_XW_") == 0)) vseg[vseg_index]->mode = 0x6;
    741     else if (ok && (strcmp(str, "_X_U") == 0)) vseg[vseg_index]->mode = 0x5;
    742     else if (ok && (strcmp(str, "_X__") == 0)) vseg[vseg_index]->mode = 0x4;
    743     else if (ok && (strcmp(str, "__WU") == 0)) vseg[vseg_index]->mode = 0x3;
    744     else if (ok && (strcmp(str, "__W_") == 0)) vseg[vseg_index]->mode = 0x2;
    745     else if (ok && (strcmp(str, "___U") == 0)) vseg[vseg_index]->mode = 0x1;
    746     else if (ok && (strcmp(str, "____") == 0)) vseg[vseg_index]->mode = 0x0;
    747     else
    748     {
     662    str = getStringValue(reader, "mode", &ok);
     663#if XML_PARSER_DEBUG
     664    printf("      mode = %s\n", str);
     665#endif
     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 {
    749683        printf("[XML ERROR] illegal or missing <mode> attribute for vseg (%d,%d)\n",
    750684                vspace_index, vseg_loc_index);
    751685        exit(1);
    752686    }
    753    
     687
    754688    ////////// get vobjs in vseg
    755689    int status = xmlTextReaderRead(reader);
    756     while ( status == 1 )
    757     {
    758         const char* tag = (const char*)xmlTextReaderConstName(reader);
    759 
    760         if      ( strcmp(tag, "vobj")     == 0 ) vobjNode(reader);
    761         else if ( strcmp(tag, "#text"  )  == 0 ) { }
    762         else if ( strcmp(tag, "#comment") == 0 ) { }
    763         else if ( strcmp(tag, "vseg")     == 0 )
    764         {
     690    while (status == 1) {
     691        const char * tag = (const char *) xmlTextReaderConstName(reader);
     692
     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 ) {
    765699            vseg[vseg_index]->vobjs = vobj_count;
    766700            vseg_index++;
     
    768702            return;
    769703        }
    770         else
    771         {
    772             printf("[XML ERROR] Unknown tag %s",tag);
    773             exit(1);
    774         }
    775         status = xmlTextReaderRead ( reader );
     704        else {
     705            printf("[XML ERROR] Unknown tag %s", tag);
     706            exit(1);
     707        }
     708        status = xmlTextReaderRead (reader);
    776709    }
    777710} // end vsegNode()
    778711
     712
    779713//////////////////////////////////////////
    780 void vspaceNode( xmlTextReaderPtr reader )
    781 //////////////////////////////////////////
    782 {
    783     char*               str;
    784     unsigned int        ok;
     714void vspaceNode(xmlTextReaderPtr reader) {
     715    char * str;
     716    unsigned int ok;
    785717
    786718    vobj_loc_index = 0;
    787         vseg_loc_index = 0;
    788         task_loc_index = 0;
    789 
    790     if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return;
     719    vseg_loc_index = 0;
     720    task_loc_index = 0;
     721
     722    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) {
     723        return;
     724    }
    791725
    792726    // checking source file consistency
    793     if ( vspace_index >= header->vspaces )
    794     {
     727    if (vspace_index >= header->vspaces) {
    795728        printf("[XML ERROR] The vspace index is too large : %d\n",
    796                  vspace_index);
    797         exit(1);
    798     }
    799 
    800 #if XML_PARSER_DEBUG
    801 printf("\n  vspace %d\n", vspace_index);
    802 #endif
    803 
    804     vspace[vspace_index] = (mapping_vspace_t*)malloc(sizeof(mapping_vspace_t));
     729                vspace_index);
     730        exit(1);
     731    }
     732
     733#if XML_PARSER_DEBUG
     734    printf("\n  vspace %d\n", vspace_index);
     735#endif
     736
     737    vspace[vspace_index] = (mapping_vspace_t *) malloc(sizeof(mapping_vspace_t));
    805738
    806739    ////////// get name attribute
    807740    str = getStringValue(reader, "name", &ok);
    808     if ( ok )
    809     {
    810 #if XML_PARSER_DEBUG
    811 printf("  name = %s\n", str);
     741    if (ok) {
     742#if XML_PARSER_DEBUG
     743        printf("  name = %s\n", str);
    812744#endif
    813745        strncpy(vspace[vspace_index]->name, str, 31);
    814746    }
    815     else
    816     {
     747    else {
    817748        printf("[XML ERROR] illegal or missing <name> attribute for vspace %d\n",
    818                  vspace_index);
     749                vspace_index);
    819750        exit(1);
    820751    }
     
    824755    vspace[vspace_index]->vobj_offset = vobj_index;
    825756    vspace[vspace_index]->task_offset = task_index;
    826    
    827 #if XML_PARSER_DEBUG
    828 printf("  vseg_offset = %d\n", vseg_index);
    829 printf("  vobj_offset = %d\n", vobj_index);
    830 printf("  task_offset = %d\n", task_index);
     757
     758#if XML_PARSER_DEBUG
     759    printf("  vseg_offset = %d\n", vseg_index);
     760    printf("  vobj_offset = %d\n", vobj_index);
     761    printf("  task_offset = %d\n", task_index);
    831762#endif
    832763
    833764    ////////// get startname attribute
    834765    str = getStringValue(reader, "startname", &ok);
    835     if ( ok )
    836     {
     766    if (ok) {
    837767        //used after parsing the vobjs
    838768    }
    839     else
    840     {
     769    else {
    841770        printf("[XML ERROR] illegal or missing <startname> attribute for vspace %s\n",
    842                  vspace[vspace_index]->name);
     771                vspace[vspace_index]->name);
    843772        exit(1);
    844773    }
    845774
    846775    int status = xmlTextReaderRead(reader);
    847     while ( status == 1 )
    848     {
    849         const char* tag = (const char*)xmlTextReaderConstName(reader);
    850 
    851         if      ( strcmp(tag, "vseg")     == 0 ) vsegNode(reader);
    852         else if ( strcmp(tag, "task")     == 0 ) taskNode(reader);
    853         else if ( strcmp(tag, "#text")    == 0 ) { }
    854         else if ( strcmp(tag, "#comment") == 0 ) { }
    855         else if ( strcmp(tag, "vspace")   == 0 )
    856         {
     776    while (status == 1) {
     777        const char * tag = (const char *) xmlTextReaderConstName(reader);
     778
     779        if (strcmp(tag, "vseg")     == 0 ) {
     780            vsegNode(reader);
     781        }
     782        else if (strcmp(tag, "task")     == 0 ) {
     783            taskNode(reader);
     784        }
     785        else if (strcmp(tag, "#text")    == 0 ) { }
     786        else if (strcmp(tag, "#comment") == 0 ) { }
     787        else if (strcmp(tag, "vspace")   == 0 ) {
    857788            vspace[vspace_index]->vobjs = vobj_loc_index;
    858789            vspace[vspace_index]->tasks = task_loc_index ;
     
    860791
    861792            // get index of the vobj containing the start vector
    862             int index =  getVobjLocId( vspace_index, str , vobj_loc_index );
    863             if(index == -1)
    864             {
     793            int index = getVobjLocId(vspace_index, str , vobj_loc_index);
     794            if (index == -1) {
    865795                printf("[XML ERROR] vobj containing start vector not found in vspace %s\n",
    866796                        vspace[vspace_index]->name);
    867797                exit(-1);
    868798            }
    869             else
    870             {
     799            else {
    871800                vspace[vspace_index]->start_offset = index;
    872801#if XML_PARSER_DEBUG
    873 printf("      startname = %s\n", str);
    874 printf("      startid   = %d\n", index);
    875 printf("  end vspace %d\n\n", vspace_index);
     802                printf("      startname = %s\n", str);
     803                printf("      startid   = %d\n", index);
     804                printf("  end vspace %d\n\n", vspace_index);
    876805#endif
    877806            }
     
    881810            int task_min = vspace[vspace_index]->task_offset;
    882811            int task_max = task_min + vspace[vspace_index]->tasks;
    883             for ( task_id = task_min ; task_id < task_max ; task_id++ )
    884             {
    885                 if ( task[task_id]->startid >= vspace[vspace_index]->tasks )
    886                 {
     812            for (task_id = task_min; task_id < task_max; task_id++) {
     813                if (task[task_id]->startid >= vspace[vspace_index]->tasks) {
    887814                    printf("[XML ERROR] <startid> too large for task (%d,%d)\n",
    888                            vspace_index, task_id );
     815                            vspace_index, task_id );
    889816                    exit(1);
    890817                }
     
    894821            return;
    895822        }
    896         else
    897         {
    898             printf("[XML ERROR] Unknown tag %s",tag);
    899             exit(1);
    900         }
    901         status = xmlTextReaderRead ( reader );
     823        else {
     824            printf("[XML ERROR] Unknown tag %s", tag);
     825            exit(1);
     826        }
     827        status = xmlTextReaderRead(reader);
    902828    }
    903829} // end vspaceNode()
    904830
     831
    905832///////////////////////////////////////////
    906 void cpPortNode ( xmlTextReaderPtr reader )
    907 ///////////////////////////////////////////
    908 {
    909     char*           str;
    910     unsigned int    ok;
    911 
    912     if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return;
    913 
    914     if ( cp_port_index >= MAX_CP_PORTS )
    915     {
     833void cpPortNode(xmlTextReaderPtr reader) {
     834    char * str;
     835    unsigned int ok;
     836
     837    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) {
     838        return;
     839    }
     840
     841    if (cp_port_index >= MAX_CP_PORTS) {
    916842        printf("[XML ERROR] The number of ports (for coprocs) is larger than %d\n", MAX_CP_PORTS);
    917843    }
    918844
    919845#if XML_PARSER_DEBUG
    920 printf("\n  port %d\n", cp_port_index);
    921 #endif
    922 
    923     cp_port[cp_port_index] = (mapping_cp_port_t*)malloc(sizeof(mapping_cp_port_t));
    924     cp_port_vobj_ref[cp_port_index] = (vobj_ref_t*)malloc(sizeof(vobj_ref_t));
    925 
    926 
    927    
     846    printf("\n  port %d\n", cp_port_index);
     847#endif
     848
     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));
     851
     852
     853
    928854    ///////// get direction attribute
    929     str = getStringValue( reader, "direction", &ok );
    930     if ( ok )
    931     {
    932 #if XML_PARSER_DEBUG
    933 printf("      direction = %s\n", str);
    934 #endif
    935         if      ( strcmp(str, "TO_COPROC")   ==  0 ) cp_port[cp_port_index]->direction = PORT_TO_COPROC;
    936         else if ( strcmp(str, "FROM_COPROC") ==  0 ) cp_port[cp_port_index]->direction = PORT_FROM_COPROC;
    937         else
    938         {
     855    str = getStringValue(reader, "direction", &ok);
     856    if (ok) {
     857#if XML_PARSER_DEBUG
     858        printf("      direction = %s\n", str);
     859#endif
     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 {
    939867            printf("[XML ERROR] illegal <direction> for cp_port %d in cluster %d\n",
    940                    cp_port_index, cluster_index);
     868                    cp_port_index, cluster_index);
    941869            exit(1);
    942870        }
    943871    } 
    944     else
    945     {
     872    else {
    946873        printf("[XML ERROR] missing <direction> for cp_port %d in cluster %d\n",
    947                cp_port_index, cluster_index);
    948         exit(1);
    949     }
    950    
     874                cp_port_index, cluster_index);
     875        exit(1);
     876    }
     877
    951878    /////////// get vspacename attribute
    952     str = getStringValue( reader, "vspacename", &ok );
    953 #if XML_PARSER_DEBUG
    954 printf("      vspacename = %s\n", str);
    955 #endif
    956     if ( ok )
    957     {
     879    str = getStringValue(reader, "vspacename", &ok);
     880#if XML_PARSER_DEBUG
     881    printf("      vspacename = %s\n", str);
     882#endif
     883    if (ok) {
    958884        strncpy(cp_port_vobj_ref[cp_port_index]->vspace_name, str, 31);
    959885    }
    960     else
    961     {
     886    else {
    962887        printf("[XML ERROR] missing <vspacename> for cp_port %d in cluster %d\n",
    963                cp_port_index, cluster_index);
     888                cp_port_index, cluster_index);
    964889        exit(1);
    965890    }
    966891
    967892    /////////// get vobjname attribute
    968     str = getStringValue( reader, "vobjname", &ok );
    969 #if XML_PARSER_DEBUG
    970 printf("      vobjname = %s\n", str);
    971 #endif
    972     if ( ok )
    973     {
     893    str = getStringValue(reader, "vobjname", &ok);
     894#if XML_PARSER_DEBUG
     895    printf("      vobjname = %s\n", str);
     896#endif
     897    if (ok) {
    974898        strncpy(cp_port_vobj_ref[cp_port_index]->vobj_name, str, 31);
    975899    }
    976     else
    977     {
     900    else {
    978901        printf("[XML ERROR] missing <vobjname> for cp_port %d in cluster %d\n",
    979                cp_port_index, cluster_index);
    980         exit(1);
    981     }
    982    
     902                cp_port_index, cluster_index);
     903        exit(1);
     904    }
     905
    983906    cp_port_index++;
    984907    cp_port_loc_index++;
     
    986909} // end cpPortNode()
    987910
     911
    988912///////////////////////////////////////////
    989 void periphNode ( xmlTextReaderPtr reader )
    990 ///////////////////////////////////////////
    991 {
    992     char*           str;
    993     unsigned int    value;
    994     unsigned int        ok;
    995 
    996     if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return;
    997 
    998     if ( periph_index >= MAX_PERIPHS )
    999     {
     913void periphNode(xmlTextReaderPtr reader) {
     914    char * str;
     915    unsigned int value;
     916    unsigned int ok;
     917
     918    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) {
     919        return;
     920    }
     921
     922    if (periph_index >= MAX_PERIPHS) {
    1000923        printf("[XML ERROR] The number of periphs is larger than %d\n", MAX_PERIPHS);
    1001924    }
    1002925
    1003926#if XML_PARSER_DEBUG
    1004 printf("\n  periph %d\n", periph_index);
    1005 #endif
    1006 
    1007     periph[periph_index] = (mapping_periph_t*)malloc(sizeof(mapping_periph_t));
     927    printf("\n  periph %d\n", periph_index);
     928#endif
     929
     930    periph[periph_index] = (mapping_periph_t *) malloc(sizeof(mapping_periph_t));
    1008931
    1009932
    1010933    ///////// get channels attribute (optionnal : 1 if missing)
    1011     value = getIntValue( reader, "channels", &ok );
    1012     if ( ok )
    1013     {
    1014 #if XML_PARSER_DEBUG
    1015 printf("      channels = %d\n", value);
     934    value = getIntValue(reader, "channels", &ok);
     935    if (ok) {
     936#if XML_PARSER_DEBUG
     937        printf("      channels = %d\n", value);
    1016938#endif
    1017939        periph[periph_index]->channels = value;
    1018940    }
    1019     else
    1020     {
     941    else {
    1021942        periph[periph_index]->channels = 1;
    1022943    }
    1023944
    1024945    /////////// get psegname attribute
    1025     str = getStringValue(reader,"psegname", &ok);
    1026     if ( ok == 0 )
    1027     {
     946    str = getStringValue(reader, "psegname", &ok);
     947    if (ok == 0) {
    1028948        printf("[XML ERROR] illegal or missing <psegname> for coproc %d in cluster %d\n",
    1029                  coproc_index, cluster_index);
     949                coproc_index, cluster_index);
    1030950        exit(1);
    1031951    }
    1032952
    1033953    /////////// set psegid attribute
    1034     int index = getPsegId( cluster_index, str );
    1035     if ( index >= 0 )
    1036     {
    1037 #if XML_PARSER_DEBUG
    1038 printf("      clusterid = %d\n", cluster_index);
    1039 printf("      psegname  = %s\n", str);
    1040 printf("      psegid    = %d\n", index);
     954    int index = getPsegId(cluster_index, str);
     955    if (index >= 0) {
     956#if XML_PARSER_DEBUG
     957        printf("      clusterid = %d\n", cluster_index);
     958        printf("      psegname  = %s\n", str);
     959        printf("      psegid    = %d\n", index);
    1041960#endif
    1042961        periph[periph_index]->psegid = index;
    1043962        assert(pseg[index]->type == PSEG_TYPE_PERI &&
    1044         "peripheral psegname attribute must refer to a pseg of type PERI" );
    1045     }
    1046     else             
    1047     {
     963                "peripheral psegname attribute must refer to a pseg of type PERI" );
     964    }
     965    else {
    1048966        printf("[XML ERROR] pseg not found for periph %d / clusterid = %d / psegname = %s\n",
    1049                    periph_loc_index, cluster_index, str );
     967                periph_loc_index, cluster_index, str );
    1050968        exit(1);
    1051969    } 
     
    1053971
    1054972    /////////// get type attribute
    1055     str = getStringValue( reader, "type", &ok );
    1056     if ( ok )
    1057     {
    1058 #if XML_PARSER_DEBUG
    1059 printf("      type     = %s\n", str);
     973    str = getStringValue(reader, "type", &ok);
     974    if (ok) {
     975#if XML_PARSER_DEBUG
     976        printf("      type     = %s\n", str);
    1060977#endif
    1061978        unsigned int error = 0;
    1062  
     979
    1063980        // The TTY, IOC, NIC, FBF and IOB peripherals cannot be replicated
    1064981        // one per architecture
    1065         if      ( strcmp( str, "IOC" ) == 0 )
    1066         {
     982        if (strcmp(str, "IOC") == 0) {
    1067983            periph[periph_index]->type = PERIPH_TYPE_IOC;
    1068             if ( header->ioc_clusterid == 0xFFFFFFFF) header->ioc_clusterid = cluster_index;
    1069             else  error = 1;
    1070 
    1071             ioc_base_offset = pseg[ periph[periph_index]->psegid ]->base;
     984            if (header->ioc_clusterid == 0xFFFFFFFF) {
     985                header->ioc_clusterid = cluster_index;
     986            }
     987            else {
     988                error = 1;
     989            }
     990
     991            ioc_base_offset = pseg[periph[periph_index]->psegid]->base;
    1072992            nb_ioc_channel = periph[periph_index]->channels;
    1073993        }
    1074         else if ( strcmp( str, "TTY" ) == 0 )
    1075         {
     994        else if (strcmp(str, "TTY") == 0) {
    1076995            periph[periph_index]->type = PERIPH_TYPE_TTY;
    1077             if ( header->tty_clusterid == 0xFFFFFFFF) header->tty_clusterid = cluster_index;
    1078             else  error = 1;
    1079 
    1080             tty_base_offset = pseg[ periph[periph_index]->psegid ]->base;
     996            if (header->tty_clusterid == 0xFFFFFFFF) {
     997                header->tty_clusterid = cluster_index;
     998            }
     999            else  {
     1000                error = 1;
     1001            }
     1002
     1003            tty_base_offset = pseg[periph[periph_index]->psegid]->base;
    10811004            nb_tty_channel = periph[periph_index]->channels;
    10821005        }
    1083         else if ( strcmp( str, "FBF" ) == 0 )
    1084         {
     1006        else if (strcmp(str, "FBF") == 0) {
    10851007            periph[periph_index]->type = PERIPH_TYPE_FBF;
    1086             if ( header->fbf_clusterid == 0xFFFFFFFF) header->fbf_clusterid = cluster_index;
    1087             else  error = 1;
    1088 
    1089             fbf_base_offset = pseg[ periph[periph_index]->psegid ]->base;
    1090         }
    1091         else if ( strcmp( str, "NIC" ) == 0 )
    1092         {
     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;
     1015        }
     1016        else if (strcmp(str, "NIC") == 0) {
    10931017            periph[periph_index]->type = PERIPH_TYPE_NIC;
    1094             if ( header->nic_clusterid == 0xFFFFFFFF) header->nic_clusterid = cluster_index;
    1095             else  error = 1;
    1096 
    1097             nic_base_offset = pseg[ periph[periph_index]->psegid ]->base;
     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;
    10981025            nb_nic_channel = periph[periph_index]->channels;
    10991026        }
    1100         else if ( strcmp( str, "IOB" ) == 0 )
    1101         {
     1027        else if (strcmp(str, "IOB") == 0) {
    11021028            periph[periph_index]->type = PERIPH_TYPE_IOB;
    1103             iob_base_offset = pseg[ periph[periph_index]->psegid ]->base;
    1104 
    1105             if(io_mmu_active) error = 1;
     1029            iob_base_offset = pseg[periph[periph_index]->psegid]->base;
     1030
     1031            if (io_mmu_active) {
     1032                error = 1;
     1033            }
    11061034            io_mmu_active = 1;
    11071035        }
    11081036        // The TIM, ICU, XICU, DMA and IOB peripherals can be replicated in several clusters
    11091037        // one per cluster
    1110         else if ( strcmp( str, "TIM" ) == 0 )
    1111         {
     1038        else if (strcmp(str, "TIM") == 0 ) {
    11121039            periph[periph_index]->type = PERIPH_TYPE_TIM;
    1113             if(found_timer) error = 1;
     1040            if (found_timer) {
     1041                error = 1;
     1042            }
    11141043            found_timer = 1;
    11151044
    1116             if(tim_base_offset == 0xFFFFFFFF)
     1045            if (tim_base_offset == 0xFFFFFFFF) {
    11171046                tim_base_offset = pseg[ periph[periph_index]->psegid ]->base;
    1118 
    1119             if(nb_timer_channel_max < periph[periph_index]->channels)
     1047            }
     1048
     1049            if (nb_timer_channel_max < periph[periph_index]->channels) {
    11201050                nb_timer_channel_max = periph[periph_index]->channels;
    1121         }
    1122         else if ( strcmp( str, "ICU" ) == 0 )
    1123         {
     1051            }
     1052        }
     1053        else if (strcmp(str, "ICU") == 0) {
    11241054            periph[periph_index]->type = PERIPH_TYPE_ICU;
    1125             if(found_icu) error = 1;
     1055            if (found_icu) {
     1056                error = 1;
     1057            }
    11261058            found_icu = 1;
    11271059
    1128             if(icu_base_offset == 0xFFFFFFFF)
     1060            if (icu_base_offset == 0xFFFFFFFF) {
     1061                icu_base_offset = pseg[periph[periph_index]->psegid]->base;
     1062            }
     1063        }
     1064        else if (strcmp(str, "XICU") == 0) {
     1065            periph[periph_index]->type = PERIPH_TYPE_XICU;
     1066            if (found_xicu) {
     1067                error = 1;
     1068            }
     1069            found_xicu = 1;
     1070
     1071            //'icu' since we can't have both xicu and icu in an arch
     1072            if (icu_base_offset == 0xFFFFFFFF) {
    11291073                icu_base_offset = pseg[ periph[periph_index]->psegid ]->base;
    1130         }
    1131         else if ( strcmp( str, "XICU" ) == 0 )
    1132         {
    1133             periph[periph_index]->type = PERIPH_TYPE_XICU;
    1134             if(found_xicu) error = 1;
    1135             found_xicu = 1;
    1136 
    1137             //'icu' since we can't have both xicu and icu in an arch
    1138             if(icu_base_offset == 0xFFFFFFFF)
    1139                 icu_base_offset = pseg[ periph[periph_index]->psegid ]->base;
    1140 
    1141             if(nb_timer_channel_max == 0)
     1074            }
     1075
     1076            if (nb_timer_channel_max == 0) {
    11421077                nb_timer_channel_max = 32;
    1143         }
    1144         else if ( strcmp( str, "DMA" ) == 0 )
    1145         {
     1078            }
     1079        }
     1080        else if (strcmp(str, "DMA") == 0) {
    11461081            periph[periph_index]->type = PERIPH_TYPE_DMA;
    1147             if(found_dma) error = 1;
     1082            if (found_dma) {
     1083                error = 1;
     1084            }
    11481085            found_dma = 1;
    11491086
    1150             if(dma_base_offset == 0xFFFFFFFF)
    1151                 dma_base_offset = pseg[ periph[periph_index]->psegid ]->base;
    1152             if(nb_dma_channel_max < periph[periph_index]->channels)
     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) {
    11531091                nb_dma_channel_max = periph[periph_index]->channels;
    1154         }
    1155         else
    1156         {
     1092            }
     1093        }
     1094        else {
    11571095            printf("[XML ERROR] illegal <type> for peripheral %d in cluster %d\n",
    1158                    periph_loc_index, cluster_index);
    1159             exit(1);
    1160         }
    1161 
    1162         if(error)
    1163         {
     1096                    periph_loc_index, cluster_index);
     1097            exit(1);
     1098        }
     1099
     1100        if (error) {
    11641101            printf("[XML ERROR] illegal <type> for peripheral %d in cluster %d\n",
    1165                    periph_loc_index, cluster_index);
    1166             exit(1);
    1167         }
    1168     }
    1169     else
    1170     {
     1102                    periph_loc_index, cluster_index);
     1103            exit(1);
     1104        }
     1105    }
     1106    else {
    11711107        printf("[XML ERROR] missing <type> for peripheral  %d in cluster %d\n",
    1172                periph_loc_index, cluster_index);
    1173         exit(1);
    1174     }
    1175 
    1176    
     1108                periph_loc_index, cluster_index);
     1109        exit(1);
     1110    }
     1111
     1112
    11771113    periph_index++;
    11781114    periph_loc_index++;
     
    11811117} // end periphNode
    11821118
     1119
    11831120/////////////////////////////////////////
    1184 void coprocNode ( xmlTextReaderPtr reader )
    1185 /////////////////////////////////////////
    1186 {
    1187     char*           str;
    1188     unsigned int        ok;
     1121void coprocNode(xmlTextReaderPtr reader) {
     1122    char * str;
     1123    unsigned int ok;
    11891124
    11901125    cp_port_loc_index = 0;
    11911126
    1192     if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return;
    1193 
    1194     if ( coproc_index >= MAX_COPROCS )
    1195     {
     1127    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) {
     1128        return;
     1129    }
     1130
     1131    if (coproc_index >= MAX_COPROCS) {
    11961132        printf("[XML ERROR] The number of coprocs is larger than %d\n", MAX_COPROCS);
    11971133    }
    11981134
    11991135#if XML_PARSER_DEBUG
    1200 printf("\n  coproc %d\n", coproc_index);
    1201 #endif
    1202 
    1203     coproc[coproc_index] = (mapping_coproc_t*)malloc(sizeof(mapping_coproc_t));
     1136    printf("\n  coproc %d\n", coproc_index);
     1137#endif
     1138
     1139    coproc[coproc_index] = (mapping_coproc_t *) malloc(sizeof(mapping_coproc_t));
    12041140
    12051141    /////////// get name attribute
    1206     str = getStringValue( reader, "name", &ok );
    1207     if ( ok )
    1208     {
    1209 #if XML_PARSER_DEBUG
    1210        printf("      name = %s\n", str);
     1142    str = getStringValue(reader, "name", &ok);
     1143    if (ok) {
     1144#if XML_PARSER_DEBUG
     1145        printf("      name = %s\n", str);
    12111146#endif
    12121147        strncpy(coproc[coproc_index]->name, str, 31);
    12131148    }
    1214     else
    1215     {
     1149    else {
    12161150        printf("[XML ERROR] illegal or missing <name> for coproc %d in cluster %d\n",
    1217                coproc_index, cluster_index);
     1151                coproc_index, cluster_index);
    12181152        exit(1);
    12191153    }
    12201154
    12211155    /////////// get psegname attribute
    1222     str = getStringValue(reader,"psegname", &ok);
    1223     if ( ok == 0 )
    1224     {
     1156    str = getStringValue(reader, "psegname", &ok);
     1157    if (ok == 0) {
    12251158        printf("[XML ERROR] illegal or missing <psegname> for coproc %d in cluster %d\n",
    1226                  coproc_index, cluster_index);
     1159                coproc_index, cluster_index);
    12271160        exit(1);
    12281161    }
    12291162
    12301163    /////////// set psegid attribute
    1231     int index = getPsegId( cluster_index, str );
    1232     if ( index >= 0 )
    1233     {
    1234 #if XML_PARSER_DEBUG
    1235 printf("      clusterid = %d\n", cluster_index);
    1236 printf("      psegname  = %s\n", str);
    1237 printf("      psegid    = %d\n", index);
     1164    int index = getPsegId(cluster_index, str);
     1165    if (index >= 0) {
     1166#if XML_PARSER_DEBUG
     1167        printf("      clusterid = %d\n", cluster_index);
     1168        printf("      psegname  = %s\n", str);
     1169        printf("      psegid    = %d\n", index);
    12381170#endif
    12391171        coproc[coproc_index]->psegid = index;
    12401172        assert(pseg[index]->type == PSEG_TYPE_PERI && "coproc psegname attribute must refer to a pseg of type PERI" );
    12411173    }
    1242     else             
    1243     {
     1174    else {
    12441175        printf("[XML ERROR] pseg not found for coproc %d / clusterid = %d / psegname = %s\n",
    1245                    coproc_index, cluster_index, str );
     1176                coproc_index, cluster_index, str );
    12461177        exit(1);
    12471178    } 
     
    12511182
    12521183#if XML_PARSER_DEBUG
    1253 printf("      port_offset = %d\n", cp_port_index);
     1184    printf("      port_offset = %d\n", cp_port_index);
    12541185#endif
    12551186
    12561187    int status = xmlTextReaderRead(reader);
    1257     while ( status == 1 )
    1258     {
    1259         const char* tag = (const char*)xmlTextReaderConstName(reader);
    1260 
    1261         if      ( strcmp(tag, "port")     == 0 ) cpPortNode(reader);
    1262         else if ( strcmp(tag, "#text")    == 0 ) { }
    1263         else if ( strcmp(tag, "#comment") == 0 ) { }
    1264         else if ( strcmp(tag, "coproc")   == 0 )
    1265         {
     1188    while (status == 1) {
     1189        const char * tag = (const char *) xmlTextReaderConstName(reader);
     1190
     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 ) {
    12661197            coproc[coproc_index]->ports = cp_port_loc_index;
    12671198            cluster[cluster_index]->coprocs++;
     
    12701201            return;
    12711202        }
    1272         else
    1273         {
    1274             printf("[XML ERROR] Unknown tag %s",tag);
    1275             exit(1);
    1276         }
    1277         status = xmlTextReaderRead ( reader );
     1203        else {
     1204            printf("[XML ERROR] Unknown tag %s", tag);
     1205            exit(1);
     1206        }
     1207        status = xmlTextReaderRead(reader);
    12781208    }
    12791209} // end coprocNode()
    12801210
     1211
    12811212///////////////////////////////////////
    1282 void irqNode( xmlTextReaderPtr reader )
    1283 ///////////////////////////////////////
    1284 {
    1285     unsigned int        ok;
    1286     unsigned int        value;
    1287     char*               str;
    1288 
    1289     if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return;
    1290 
    1291     if ( irq_index >= MAX_IRQS )
    1292     {
     1213void irqNode(xmlTextReaderPtr reader) {
     1214    unsigned int ok;
     1215    unsigned int value;
     1216    char * str;
     1217
     1218    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) {
     1219        return;
     1220    }
     1221
     1222    if (irq_index >= MAX_IRQS) {
    12931223        printf("[XML ERROR] The number of irqs is larger than %d\n", MAX_IRQS);
    12941224    }
    12951225
    12961226#if XML_PARSER_DEBUG
    1297 printf("     irq %d\n", irq_loc_index);
    1298 #endif
    1299 
    1300     irq[irq_index] = (mapping_irq_t*)malloc(sizeof(mapping_irq_t));
     1227    printf("     irq %d\n", irq_loc_index);
     1228#endif
     1229
     1230    irq[irq_index] = (mapping_irq_t *) malloc(sizeof(mapping_irq_t));
    13011231
    13021232    ///////// get type attribute
    1303     str = getStringValue(reader,"type", &ok);
    1304     if ( ok )
    1305     {
    1306 #if XML_PARSER_DEBUG
    1307 printf("        type    = %s\n", str);
    1308 #endif
    1309         if      ( strcmp(str, "HARD") == 0 ) irq[irq_index]->type = 0;
    1310         else if ( strcmp(str, "SOFT") == 0 ) irq[irq_index]->type = 1;
    1311         else
    1312         {
     1233    str = getStringValue(reader, "type", &ok);
     1234    if (ok) {
     1235#if XML_PARSER_DEBUG
     1236        printf("        type    = %s\n", str);
     1237#endif
     1238        if (strcmp(str, "HARD") == 0 ) {
     1239            irq[irq_index]->type = 0;
     1240        }
     1241        else if (strcmp(str, "SOFT") == 0 ) {
     1242            irq[irq_index]->type = 1;
     1243        }
     1244        else {
    13131245            printf("[XML ERROR] undefined IRQ  <type> for processor %d in cluster %d\n",
    1314                    cluster_index, proc_loc_index );
     1246                    cluster_index, proc_loc_index);
    13151247            exit(1);
    13161248        }
    13171249    } 
    1318     else
    1319     {
     1250    else {
    13201251        printf("[XML ERROR] missing IRQ <type> for processor %d in cluster %d\n",
    1321                cluster_index, proc_loc_index );
     1252                cluster_index, proc_loc_index);
    13221253        exit(1);
    13231254    }
     
    13251256    ///////// get icuid attribute
    13261257    value = getIntValue(reader, "icuid", &ok);
    1327     if ( ok )
    1328     {
    1329 #if XML_PARSER_DEBUG
    1330 printf("        icuid   = %d\n", value);
     1258    if (ok) {
     1259#if XML_PARSER_DEBUG
     1260        printf("        icuid   = %d\n", value);
    13311261#endif
    13321262        irq[irq_index]->icuid = value;
    1333         if ( value >= 32 )
    1334         {
     1263        if (value >= 32) {
    13351264            printf("[XML ERROR] IRQ <icuid> too large for processor %d in cluster %d\n",
    1336                    cluster_index, proc_loc_index );
    1337             exit(1);
    1338         }
    1339     }
    1340     else
    1341     {
     1265                    cluster_index, proc_loc_index);
     1266            exit(1);
     1267        }
     1268    }
     1269    else {
    13421270        printf("[XML ERROR] missing IRQ <icuid> for processor %d in cluster %d\n",
    1343                cluster_index, proc_loc_index );
     1271                cluster_index, proc_loc_index);
    13441272        exit(1);
    13451273    }
    13461274
    13471275    ///////// get isr attribute
    1348     str = getStringValue(reader,"isr", &ok);
    1349     if ( ok )
    1350     {
    1351 #if XML_PARSER_DEBUG
    1352 printf("        isr     = %s\n", str);
    1353 #endif
    1354         if      ( strcmp(str, "ISR_SWITCH" ) == 0 ) irq[irq_index]->isr = ISR_SWITCH;
    1355         else if ( strcmp(str, "ISR_IOC"    ) == 0 ) irq[irq_index]->isr = ISR_IOC;
    1356         else if ( strcmp(str, "ISR_DMA"    ) == 0 ) irq[irq_index]->isr = ISR_DMA;
    1357         else if ( strcmp(str, "ISR_TTY"    ) == 0 ) irq[irq_index]->isr = ISR_TTY;
    1358         else if ( strcmp(str, "ISR_TIMER"  ) == 0 ) irq[irq_index]->isr = ISR_TIMER;
    1359         else
    1360         {
     1276    str = getStringValue(reader, "isr", &ok);
     1277    if (ok) {
     1278#if XML_PARSER_DEBUG
     1279        printf("        isr     = %s\n", str);
     1280#endif
     1281        if      (strcmp(str, "ISR_SWITCH" ) == 0) { irq[irq_index]->isr = ISR_SWITCH; }
     1282        else if (strcmp(str, "ISR_IOC"    ) == 0) { irq[irq_index]->isr = ISR_IOC; }
     1283        else if (strcmp(str, "ISR_DMA"    ) == 0) { irq[irq_index]->isr = ISR_DMA; }
     1284        else if (strcmp(str, "ISR_TTY"    ) == 0) { irq[irq_index]->isr = ISR_TTY; }
     1285        else if (strcmp(str, "ISR_TIMER"  ) == 0) { irq[irq_index]->isr = ISR_TIMER; }
     1286        else {
    13611287            printf("[XML ERROR] illegal IRQ <isr> for processor %d in cluster %d\n",
    1362                    cluster_index, proc_loc_index );
    1363             exit(1);
    1364         }
    1365 #if XML_PARSER_DEBUG
    1366 printf("        isrnum  = %d\n", irq[irq_index]->isr);
     1288                    cluster_index, proc_loc_index);
     1289            exit(1);
     1290        }
     1291#if XML_PARSER_DEBUG
     1292        printf("        isrnum  = %d\n", irq[irq_index]->isr);
    13671293#endif
    13681294    } 
    1369     else
    1370     {
     1295    else {
    13711296        printf("[XML ERROR] missing IRQ <isr> for processor %d in cluster %d\n",
    1372                cluster_index, proc_loc_index );
     1297                cluster_index, proc_loc_index);
    13731298        exit(1);
    13741299    }
     
    13761301    ///////// get channel attribute (optionnal : 0 if missing)
    13771302    value = getIntValue(reader, "channel", &ok);
    1378     if ( ok )
    1379     {
    1380 #if XML_PARSER_DEBUG
    1381 printf("        channel = %d\n", value);
     1303    if (ok) {
     1304#if XML_PARSER_DEBUG
     1305        printf("        channel = %d\n", value);
    13821306#endif
    13831307        irq[irq_index]->channel = value;
    13841308    }
    1385     else
    1386     {
     1309    else {
    13871310        irq[irq_index]->channel = 0;
    13881311    }
     
    13931316} // end irqNode
    13941317
     1318
    13951319/////////////////////////////////////////
    1396 void procNode ( xmlTextReaderPtr reader )
    1397 /////////////////////////////////////////
    1398 {
    1399     unsigned int        ok;
    1400     unsigned int    value;
     1320void procNode(xmlTextReaderPtr reader) {
     1321    unsigned int ok;
     1322    unsigned int value;
    14011323
    14021324    irq_loc_index = 0;
    14031325
    1404     if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return;
    1405 
    1406     if ( proc_index >= MAX_PROCS )
    1407     {
     1326    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) {
     1327        return;
     1328    }
     1329
     1330    if (proc_index >= MAX_PROCS) {
    14081331        printf("[XML ERROR] The number of procs is larger than %d\n", MAX_PROCS);
    14091332    }
    14101333
    14111334#if XML_PARSER_DEBUG
    1412 printf("\n  proc %d\n", proc_index);
    1413 #endif
    1414 
    1415     proc[proc_index] = (mapping_proc_t*)malloc(sizeof(mapping_proc_t));
     1335    printf("\n  proc %d\n", proc_index);
     1336#endif
     1337
     1338    proc[proc_index] = (mapping_proc_t *) malloc(sizeof(mapping_proc_t));
    14161339
    14171340
    14181341    /////////// get index attribute (optional)
    1419     value = getIntValue(reader,"index",&ok);
    1420     if ( ok && (value != proc_loc_index) )
    1421     {
    1422             printf("[XML ERROR] wrong proc index / expected value is %d",
     1342    value = getIntValue(reader, "index", &ok);
     1343    if (ok && (value != proc_loc_index)) {
     1344        printf("[XML ERROR] wrong proc index / expected value is %d",
    14231345                proc_loc_index);
    1424             exit(1);
     1346        exit(1);
    14251347    }
    14261348
     
    14291351
    14301352#if XML_PARSER_DEBUG
    1431 printf("    irq_offset = %d\n", irq_index);
     1353    printf("    irq_offset = %d\n", irq_index);
    14321354#endif
    14331355
    14341356    int status = xmlTextReaderRead(reader);
    1435     while ( status == 1 )
    1436     {
    1437         const char* tag = (const char*)xmlTextReaderConstName(reader);
    1438 
    1439         if      ( strcmp(tag, "irq")      == 0 ) irqNode(reader);
    1440         else if ( strcmp(tag, "#text")    == 0 ) { }
    1441         else if ( strcmp(tag, "#comment") == 0 ) { }
    1442         else if ( strcmp(tag, "proc")     == 0 )
    1443         {
     1357    while (status == 1) {
     1358        const char * tag = (const char *) xmlTextReaderConstName(reader);
     1359
     1360        if (strcmp(tag, "irq") == 0) {
     1361            irqNode(reader);
     1362        }
     1363        else if (strcmp(tag, "#text")    == 0) { }
     1364        else if (strcmp(tag, "#comment") == 0) { }
     1365        else if (strcmp(tag, "proc")     == 0) {
    14441366            proc[proc_index]->irqs = irq_loc_index;
    14451367            cluster[cluster_index]->procs++;
     
    14481370            return;
    14491371        }
    1450         else
    1451         {
    1452             printf("[XML ERROR] Unknown tag %s",tag);
    1453             exit(1);
    1454         }
    1455         status = xmlTextReaderRead ( reader );
     1372        else {
     1373            printf("[XML ERROR] Unknown tag %s", tag);
     1374            exit(1);
     1375        }
     1376        status = xmlTextReaderRead(reader);
    14561377    }
    14571378} // end procNode()
     
    14591380
    14601381//////////////////////////////////////////
    1461 void  psegNode ( xmlTextReaderPtr reader )
    1462 //////////////////////////////////////////
    1463 {
    1464     unsigned int        ok;
    1465     unsigned int        value;
    1466     char*               str;
    1467 
    1468     if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return;
    1469 
    1470     if ( pseg_index >= MAX_PSEGS )
    1471     {
     1382void psegNode(xmlTextReaderPtr reader) {
     1383    unsigned int ok;
     1384    unsigned int value;
     1385    char * str;
     1386
     1387    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) {
     1388        return;
     1389    }
     1390
     1391    if (pseg_index >= MAX_PSEGS) {
    14721392        printf("[XML ERROR] The number of psegs is larger than %d\n", MAX_PSEGS);
    14731393        exit(1);
     
    14751395
    14761396#if XML_PARSER_DEBUG
    1477 printf("    pseg %d\n", pseg_index);
    1478 #endif
    1479 
    1480     pseg[pseg_index] = (mapping_pseg_t*)malloc(sizeof(mapping_pseg_t));
     1397    printf("    pseg %d\n", pseg_index);
     1398#endif
     1399
     1400    pseg[pseg_index] = (mapping_pseg_t *) malloc(sizeof(mapping_pseg_t));
    14811401
    14821402    /////// get name attribute
    1483     str = getStringValue( reader, "name", &ok );
    1484 #if XML_PARSER_DEBUG
    1485 printf("      name = %s\n", str);
    1486 #endif
    1487     if ( ok )
    1488     {
     1403    str = getStringValue(reader, "name", &ok);
     1404#if XML_PARSER_DEBUG
     1405    printf("      name = %s\n", str);
     1406#endif
     1407    if (ok) {
    14891408        strncpy(pseg[pseg_index]->name, str, 31);
    14901409    }
    1491     else
    1492     {
     1410    else {
    14931411        printf("[XML ERROR] illegal or missing <name> for pseg %d in cluster %d\n",
    1494                pseg_index, cluster_index);
     1412                pseg_index, cluster_index);
    14951413        exit(1);
    14961414    }
     
    14991417    str = getStringValue(reader, "type", &ok);
    15001418#if XML_PARSER_DEBUG
    1501 printf("      type = %s\n", str);
    1502 #endif
    1503     if      (ok && (strcmp(str, "RAM" ) == 0)) pseg[pseg_index]->type = PSEG_TYPE_RAM;
    1504     else if (ok && (strcmp(str, "ROM" ) == 0)) pseg[pseg_index]->type = PSEG_TYPE_ROM;
    1505     else if (ok && (strcmp(str, "PERI") == 0)) pseg[pseg_index]->type = PSEG_TYPE_PERI;
    1506     else
    1507     {
     1419    printf("      type = %s\n", str);
     1420#endif
     1421    if      (ok && (strcmp(str, "RAM" ) == 0)) { pseg[pseg_index]->type = PSEG_TYPE_RAM; }
     1422    else if (ok && (strcmp(str, "ROM" ) == 0)) { pseg[pseg_index]->type = PSEG_TYPE_ROM; }
     1423    else if (ok && (strcmp(str, "PERI") == 0)) { pseg[pseg_index]->type = PSEG_TYPE_PERI; }
     1424    else {
    15081425        printf("[XML ERROR] illegal or missing <type> for pseg %s in cluster %d\n",
    1509         pseg[pseg_index]->name, cluster_index);
     1426                pseg[pseg_index]->name, cluster_index);
    15101427        exit(1);
    15111428    }
    15121429
    15131430    //////// get base attribute
    1514     value = getIntValue( reader, "base", &ok );
    1515 #if XML_PARSER_DEBUG
    1516 printf("      base = 0x%x\n", value);
    1517 #endif
    1518     if ( ok )
    1519     {
     1431    value = getIntValue(reader, "base", &ok);
     1432#if XML_PARSER_DEBUG
     1433    printf("      base = 0x%x\n", value);
     1434#endif
     1435    if (ok) {
    15201436        pseg[pseg_index]->base = value;
    15211437    }
    1522     else
    1523     {
     1438    else {
    15241439        printf("[XML ERROR] illegal or missing <base> for pseg %s in cluster %d\n",
    1525         pseg[pseg_index]->name, cluster_index);
     1440                pseg[pseg_index]->name, cluster_index);
    15261441        exit(1);
    15271442    }
    15281443
    15291444    //////// get length attribute
    1530     value = getIntValue( reader, "length", &ok );
    1531 #if XML_PARSER_DEBUG
    1532 printf("      length = 0x%x\n", value);
    1533 #endif
    1534     if ( ok )
    1535     {
     1445    value = getIntValue(reader, "length", &ok);
     1446#if XML_PARSER_DEBUG
     1447    printf("      length = 0x%x\n", value);
     1448#endif
     1449    if (ok) {
    15361450        pseg[pseg_index]->length = value;
    15371451    } 
    1538     else
    1539     {
     1452    else {
    15401453        printf("[XML ERROR] illegal or missing <length> for pseg %s in cluster %d\n",
    1541         pseg[pseg_index]->name, cluster_index);
     1454                pseg[pseg_index]->name, cluster_index);
    15421455        exit(1);
    15431456    }
     
    15501463} // end psegNode()
    15511464
     1465
    15521466/////////////////////////////////////////////
    1553 void  clusterNode ( xmlTextReaderPtr reader )
    1554 /////////////////////////////////////////////
    1555 {
     1467void clusterNode(xmlTextReaderPtr reader) {
    15561468    unsigned int ok;
    15571469    unsigned int value;
    15581470
    1559     cluster[cluster_index] = (mapping_cluster_t*)malloc(sizeof(mapping_cluster_t));
    1560    
     1471    cluster[cluster_index] = (mapping_cluster_t *) malloc(sizeof(mapping_cluster_t));
     1472
    15611473    //initialise all variables
    15621474    //they will be incremented by *Node() functions
     
    15801492    found_dma = 0;
    15811493
    1582     if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return;
     1494    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) {
     1495        return;
     1496    }
    15831497
    15841498    // checking source file consistency
    1585     if ( cluster_index >= header->clusters )
    1586     {
     1499    if (cluster_index >= header->clusters) {
    15871500        printf("[XML ERROR] The cluster index is too large : %d\n", cluster_index);
    15881501        exit(1);
     
    15901503
    15911504#if XML_PARSER_DEBUG
    1592 printf("  cluster %d\n", cluster_index);
     1505    printf("  cluster %d\n", cluster_index);
    15931506#endif
    15941507
    15951508
    15961509    /////////// check cluster index attribute (optional)
    1597     value = getIntValue(reader,"index",&ok);
    1598     if ( ok && (value != cluster_index) )
    1599     {
    1600             printf("[XML ERROR] wrong cluster index / expected value is %d",
     1510    value = getIntValue(reader, "index", &ok);
     1511    if (ok && (value != cluster_index)) {
     1512        printf("[XML ERROR] wrong cluster index / expected value is %d",
    16011513                cluster_index);
    1602             exit(1);
     1514        exit(1);
    16031515    }
    16041516
    16051517    ////////// set offsets
    1606     cluster[cluster_index]->pseg_offset   = pseg_index;
    1607     cluster[cluster_index]->proc_offset   = proc_index;
     1518    cluster[cluster_index]->pseg_offset = pseg_index;
     1519    cluster[cluster_index]->proc_offset = proc_index;
    16081520    cluster[cluster_index]->coproc_offset = coproc_index;
    16091521    cluster[cluster_index]->periph_offset = periph_index;
    16101522
    16111523#if XML_PARSER_DEBUG
    1612 printf("    pseg_offset   = %d\n", pseg_index);
    1613 printf("    proc_offset   = %d\n", proc_index);
    1614 printf("    coproc_offset = %d\n", coproc_index);
    1615 printf("    periph_offset = %d\n", coproc_index);
     1524    printf("    pseg_offset   = %d\n", pseg_index);
     1525    printf("    proc_offset   = %d\n", proc_index);
     1526    printf("    coproc_offset = %d\n", coproc_index);
     1527    printf("    periph_offset = %d\n", coproc_index);
    16161528#endif
    16171529
     
    16191531    int status = xmlTextReaderRead(reader);
    16201532
    1621     while ( status == 1 )
    1622     {
    1623         const char* tag = (const char*)xmlTextReaderConstName(reader);
    1624 
    1625         if      ( strcmp(tag, "pseg")     == 0 ) psegNode(reader);
    1626         else if ( strcmp(tag, "proc")     == 0 ) procNode(reader);
    1627         else if ( strcmp(tag, "coproc")   == 0 ) coprocNode(reader);
    1628         else if ( strcmp(tag, "periph")   == 0 ) periphNode(reader);
    1629         else if ( strcmp(tag, "#text")    == 0 ) { }
    1630         else if ( strcmp(tag, "#comment") == 0 ) { }
    1631         else if ( strcmp(tag, "cluster")  == 0 )
    1632         {
    1633 
    1634             if(use_xicu == 0xFFFFFFFF)
     1533    while (status == 1) {
     1534        const char * tag = (const char *) xmlTextReaderConstName(reader);
     1535
     1536        if      (strcmp(tag, "pseg")     == 0) psegNode(reader);
     1537        else if (strcmp(tag, "proc")     == 0) procNode(reader);
     1538        else if (strcmp(tag, "coproc")   == 0) coprocNode(reader);
     1539        else if (strcmp(tag, "periph")   == 0) periphNode(reader);
     1540        else if (strcmp(tag, "#text")    == 0) { }
     1541        else if (strcmp(tag, "#comment") == 0) { }
     1542        else if (strcmp(tag, "cluster")  == 0) {
     1543
     1544            if (use_xicu == 0xFFFFFFFF) {
    16351545                use_xicu = found_xicu;
     1546            }
    16361547
    16371548            ////////////////// peripherals checks ////////////////////
    1638             if( (found_timer  && use_xicu) || (!found_timer  && !use_xicu) )
    1639             {
     1549            if ((found_timer  && use_xicu) || (!found_timer  && !use_xicu)) {
    16401550                printf("[XML ERROR] illegal or missing timer peripheral in cluster %d\n", cluster_index);
    16411551                exit(1);
    16421552            }
    16431553
    1644             if( (found_icu  && use_xicu) || (!found_icu  && !use_xicu) )
    1645             {
     1554            if ((found_icu && use_xicu) || (!found_icu && !use_xicu)) {
    16461555                printf("[XML ERROR] illegal or missing icu peripheral in cluster %d\n", cluster_index);
    16471556                exit(1);
    16481557            }
    16491558
    1650             if( !found_xicu && use_xicu)
    1651             {
     1559            if (!found_xicu && use_xicu) {
    16521560                printf("[XML ERROR] illegal or missing dma peripheral in cluster %d\n", cluster_index);
    16531561                exit(1);
    16541562            }
    16551563
    1656             if(!found_dma)
    1657             {
     1564            if (!found_dma) {
    16581565                printf("[XML ERROR] illegal or missing dma peripheral in cluster %d\n", cluster_index);
    16591566                exit(1);
    16601567            }
    16611568
    1662                
    1663             if(nb_proc_max < cluster[cluster_index]->procs)
     1569
     1570            if (nb_proc_max < cluster[cluster_index]->procs) {
    16641571                nb_proc_max = cluster[cluster_index]->procs;
    1665 
    1666 #if XML_PARSER_DEBUG
    1667 printf("    psegs   = %d\n", cluster[cluster_index]->psegs);
    1668 printf("    procs   = %d\n", cluster[cluster_index]->procs);
    1669 printf("    coprocs = %d\n", cluster[cluster_index]->coprocs);
    1670 printf("    periphs = %d\n", cluster[cluster_index]->periphs);
    1671 printf("    end cluster %d\n", cluster_index);
     1572            }
     1573
     1574#if XML_PARSER_DEBUG
     1575            printf("    psegs   = %d\n", cluster[cluster_index]->psegs);
     1576            printf("    procs   = %d\n", cluster[cluster_index]->procs);
     1577            printf("    coprocs = %d\n", cluster[cluster_index]->coprocs);
     1578            printf("    periphs = %d\n", cluster[cluster_index]->periphs);
     1579            printf("    end cluster %d\n", cluster_index);
    16721580#endif
    16731581            cluster_index++;
     
    16781586} // end clusterNode()
    16791587
     1588
    16801589//////////////////////////////////////////////
    1681 void clusterSetNode( xmlTextReaderPtr reader )
    1682 //////////////////////////////////////////////
    1683 {
    1684     if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return;
    1685 
    1686 #if XML_PARSER_DEBUG
    1687 printf("\n  clusters set\n");
     1590void clusterSetNode(xmlTextReaderPtr reader) {
     1591    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) {
     1592        return;
     1593    }
     1594
     1595#if XML_PARSER_DEBUG
     1596    printf("\n  clusters set\n");
    16881597#endif
    16891598
    16901599    int status = xmlTextReaderRead(reader);
    1691     while ( status == 1 )
    1692     {
    1693         const char* tag = (const char*)xmlTextReaderConstName(reader);
    1694 
    1695         if      ( strcmp(tag, "cluster")    == 0 ) clusterNode(reader);
    1696         else if ( strcmp(tag, "#text")      == 0 ) { }
    1697         else if ( strcmp(tag, "#comment")   == 0 ) { }
    1698         else if ( strcmp(tag, "clusterset") == 0 )
    1699         {
     1600    while (status == 1) {
     1601        const char * tag = (const char *) xmlTextReaderConstName(reader);
     1602
     1603        if (strcmp(tag, "cluster")    == 0) {
     1604            clusterNode(reader);
     1605        }
     1606        else if (strcmp(tag, "#text")      == 0) { }
     1607        else if (strcmp(tag, "#comment")   == 0) { }
     1608        else if (strcmp(tag, "clusterset") == 0) {
    17001609            // checking source file consistency
    1701             if ( cluster_index != header->clusters )
    1702             {
     1610            if (cluster_index != header->clusters) {
    17031611                printf("[XML ERROR] Wrong number of clusters\n");
    17041612                exit(1);
    17051613            }
    17061614
    1707             if(header->tty_clusterid == 0xFFFFFFFF)
    1708             {
     1615            if (header->tty_clusterid == 0xFFFFFFFF) {
    17091616                printf("[XML ERROR] illegal or missing tty peripheral");
    17101617                exit(1);
     
    17121619
    17131620#if XML_PARSER_DEBUG
    1714 printf("  end cluster set\n\n");
    1715 #endif
    1716             header->psegs    = pseg_index;
    1717             header->procs    = proc_index;
    1718             header->irqs     = irq_index;
    1719             header->coprocs  = coproc_index;
     1621            printf("  end cluster set\n\n");
     1622#endif
     1623            header->psegs = pseg_index;
     1624            header->procs = proc_index;
     1625            header->irqs = irq_index;
     1626            header->coprocs = coproc_index;
    17201627            header->cp_ports = cp_port_index;
    17211628            return;
    17221629        }
    1723         else
    1724         {
     1630        else {
    17251631            printf("[XML ERROR] Unknown tag in clusterset node : %s",tag);
    17261632            exit(1);
     
    17301636} // end clusterSetNode()
    17311637
     1638
    17321639/////////////////////////////////////////////
    1733 void globalSetNode( xmlTextReaderPtr reader )
    1734 /////////////////////////////////////////////
    1735 {
    1736     if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return;
    1737 
    1738 #if XML_PARSER_DEBUG
    1739 printf("  globals set\n");
     1640void globalSetNode(xmlTextReaderPtr reader) {
     1641    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) {
     1642        return;
     1643    }
     1644
     1645#if XML_PARSER_DEBUG
     1646    printf("  globals set\n");
    17401647#endif
    17411648
    17421649    int status = xmlTextReaderRead(reader);
    1743     while ( status == 1 )
    1744     {
    1745         const char* tag = (const char*)xmlTextReaderConstName(reader);
    1746 
    1747         if      ( strcmp(tag, "vseg")      == 0 ) vsegNode(reader);
    1748         else if ( strcmp(tag, "#text"  )   == 0 ) { }
    1749         else if ( strcmp(tag, "#comment")  == 0 ) { }
    1750         else if ( strcmp(tag, "globalset") == 0 )
    1751         {
    1752 #if XML_PARSER_DEBUG
    1753 printf("  end global set\n\n");
     1650    while (status == 1) {
     1651        const char * tag = (const char *) xmlTextReaderConstName(reader);
     1652
     1653        if (strcmp(tag, "vseg") == 0) {
     1654            vsegNode(reader);
     1655        }
     1656        else if (strcmp(tag, "#text")     == 0) { }
     1657        else if (strcmp(tag, "#comment")  == 0) { }
     1658        else if (strcmp(tag, "globalset") == 0) {
     1659#if XML_PARSER_DEBUG
     1660            printf("  end global set\n\n");
    17541661#endif
    17551662            header->globals = vseg_index;
     
    17571664            return;
    17581665        }
    1759         else
    1760         {
     1666        else {
    17611667            printf("[XML ERROR] Unknown tag in globalset node : %s",tag);
    17621668            exit(1);
    17631669        }
    1764         status = xmlTextReaderRead ( reader );
     1670        status = xmlTextReaderRead(reader);
    17651671    }
    17661672} // end globalSetNode()
    17671673
     1674
    17681675/////////////////////////////////////////////
    1769 void vspaceSetNode( xmlTextReaderPtr reader )
    1770 /////////////////////////////////////////////
    1771 {
    1772     if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return;
    1773 
    1774 #if XML_PARSER_DEBUG
    1775 printf("\n  vspaces set\n");
     1676void vspaceSetNode(xmlTextReaderPtr reader) {
     1677    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) {
     1678        return;
     1679    }
     1680
     1681#if XML_PARSER_DEBUG
     1682    printf("\n  vspaces set\n");
    17761683#endif
    17771684
    17781685    int status = xmlTextReaderRead ( reader );
    1779     while ( status == 1 )
    1780     {
    1781         const char* tag = (const char*)xmlTextReaderConstName(reader);
    1782 
    1783         if      ( strcmp(tag, "vspace"   ) == 0 ) vspaceNode(reader);
    1784         else if ( strcmp(tag, "#text"    ) == 0 ) { }
    1785         else if ( strcmp(tag, "#comment" ) == 0 ) { }
    1786         else if ( strcmp(tag, "vspaceset") == 0 )
    1787         {
     1686    while (status == 1) {
     1687        const char * tag = (const char *) xmlTextReaderConstName(reader);
     1688
     1689        if (strcmp(tag, "vspace") == 0) {
     1690            vspaceNode(reader);
     1691        }
     1692        else if (strcmp(tag, "#text"    ) == 0 ) { }
     1693        else if (strcmp(tag, "#comment" ) == 0 ) { }
     1694        else if (strcmp(tag, "vspaceset") == 0 ) {
    17881695            // checking source file consistency
    1789             if ( vspace_index != header->vspaces )
    1790             {
     1696            if (vspace_index != header->vspaces) {
    17911697                printf("[XML ERROR] Wrong number of vspaces\n");
    17921698                exit(1);
    17931699            }
    1794             else
    1795             {
     1700            else {
    17961701                header->vsegs = vseg_index;
    17971702                header->vobjs = vobj_index;
     
    18001705            }
    18011706        }
    1802         else
    1803         {
     1707        else {
    18041708            printf("[XML ERROR] Unknown tag in vspaceset node : %s",tag);
    18051709            exit(1);
    18061710        }
    1807         status = xmlTextReaderRead ( reader );
     1711        status = xmlTextReaderRead(reader);
    18081712    }
    18091713} // end globalSetNode()
    18101714
     1715
    18111716//////////////////////////////////////////
    1812 void headerNode(xmlTextReaderPtr reader )
    1813 //////////////////////////////////////////
    1814 {
    1815     char*               name;
    1816     unsigned int        value;
    1817     unsigned int        ok;
    1818 
    1819     if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return;
    1820 
    1821 #if XML_PARSER_DEBUG
    1822 printf("mapping_info\n");
    1823 #endif
    1824 
    1825     header = (mapping_header_t*)malloc(sizeof(mapping_header_t));
     1717void headerNode(xmlTextReaderPtr reader) {
     1718    char * name;
     1719    unsigned int value;
     1720    unsigned int ok;
     1721
     1722    if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) {
     1723        return;
     1724    }
     1725
     1726#if XML_PARSER_DEBUG
     1727    printf("mapping_info\n");
     1728#endif
     1729
     1730    header = (mapping_header_t *) malloc(sizeof(mapping_header_t));
    18261731
    18271732    ////////// get name attribute
    18281733    name = getStringValue(reader, "name", &ok);
    1829     if ( ok )
    1830     {
    1831 #if XML_PARSER_DEBUG
    1832 printf("  name = %s\n", name);
    1833 #endif
    1834         strncpy( header->name, name, 31);
    1835     }     
    1836     else
    1837     {
     1734    if (ok) {
     1735#if XML_PARSER_DEBUG
     1736        printf("  name = %s\n", name);
     1737#endif
     1738        strncpy( header->name, name, 31);
     1739    }
     1740    else {
    18381741        printf("[XML ERROR] illegal or missing <name> attribute in header\n");
    18391742        exit(1);
     
    18421745    /////////// get cluster_x attribute
    18431746    cluster_x = getIntValue(reader, "cluster_x", &ok);
    1844     if ( ok )
    1845     {
    1846 #if XML_PARSER_DEBUG
    1847 printf("  cluster_x = %d\n", cluster_x);
     1747    if (ok) {
     1748#if XML_PARSER_DEBUG
     1749        printf("  cluster_x = %d\n", cluster_x);
    18481750#endif
    18491751        header->cluster_x = cluster_x;
    18501752    }
    1851     else
    1852     {
     1753    else {
    18531754        printf("[XML ERROR] illegal or missing <cluster_x> attribute in header\n");
    18541755        exit(1);
     
    18571758    /////////// get cluster_y attribute
    18581759    cluster_y = getIntValue(reader, "cluster_y", &ok);
    1859     if ( ok )
    1860     {
    1861 #if XML_PARSER_DEBUG
    1862 printf("  cluster_y = %d\n", cluster_y);
     1760    if (ok) {
     1761#if XML_PARSER_DEBUG
     1762        printf("  cluster_y = %d\n", cluster_y);
    18631763#endif
    18641764        header->cluster_y = cluster_y;
    18651765    }
    1866     else
    1867     {
     1766    else {
    18681767        printf("[XML ERROR] illegal or missing <cluster_y> attribute in header\n");
    18691768        exit(1);
     
    18711770
    18721771    //check the number of cluster
    1873     value = cluster_x*cluster_y;
    1874     if ( value >= MAX_CLUSTERS )
    1875     {
     1772    value = cluster_x * cluster_y;
     1773    if (value >= MAX_CLUSTERS) {
    18761774        printf("[XML ERROR] The number of clusters is larger than %d\n", MAX_CLUSTERS);
    18771775        exit(1);
    18781776    }
    1879        
     1777
    18801778    header->clusters  = value;
    18811779
    18821780#if XML_PARSER_DEBUG
    1883 printf("  clusters = %d\n", value);
     1781    printf("  clusters = %d\n", value);
    18841782#endif
    18851783
    18861784    ///////// get vspaces attribute
    18871785    value = getIntValue(reader, "vspaces", &ok);
    1888     if ( ok )
    1889     {
    1890         if ( value >= MAX_VSPACES )
    1891         {
     1786    if (ok) {
     1787        if (value >= MAX_VSPACES) {
    18921788            printf("[XML ERROR] The number of vspaces is larger than %d\n", MAX_VSPACES);
    18931789            exit(1);
    18941790        }
    18951791#if XML_PARSER_DEBUG
    1896 printf("  vspaces = %d\n", value);
    1897 #endif
    1898         header->vspaces  = value;
    1899     }
    1900     else
    1901     {
     1792        printf("  vspaces = %d\n", value);
     1793#endif
     1794        header->vspaces  = value;
     1795    }
     1796    else {
    19021797        printf("[XML ERROR] illegal or missing <vspaces> attribute in mapping\n");
    19031798        exit(1);
     
    19141809
    19151810    int status = xmlTextReaderRead(reader);
    1916     while ( status == 1 )
    1917     {
    1918         const char* tag = (const char*)xmlTextReaderConstName(reader);
    1919 
    1920         if      ( strcmp(tag, "clusterset")   == 0 ) clusterSetNode(reader);
    1921         else if ( strcmp(tag, "globalset")    == 0 ) globalSetNode(reader);
    1922         else if ( strcmp(tag, "vspaceset")    == 0 ) vspaceSetNode(reader);
    1923         else if ( strcmp(tag, "#text")        == 0 ) { }
    1924         else if ( strcmp(tag, "#comment")     == 0 ) { }
    1925         else if ( strcmp(tag, "mapping_info") == 0 )
    1926         {
    1927 #if XML_PARSER_DEBUG
    1928 printf("end mapping_info\n");
     1811    while (status == 1) {
     1812        const char * tag = (const char *) xmlTextReaderConstName(reader);
     1813
     1814        if (strcmp(tag, "clusterset") == 0) {
     1815            clusterSetNode(reader);
     1816        }
     1817        else if (strcmp(tag, "globalset")    == 0) { globalSetNode(reader); }
     1818        else if (strcmp(tag, "vspaceset")    == 0) { vspaceSetNode(reader); }
     1819        else if (strcmp(tag, "#text")        == 0) { }
     1820        else if (strcmp(tag, "#comment")     == 0) { }
     1821        else if (strcmp(tag, "mapping_info") == 0) {
     1822#if XML_PARSER_DEBUG
     1823            printf("end mapping_info\n");
    19291824#endif
    19301825            return;
    19311826        }
    1932         else
    1933         {
     1827        else {
    19341828            printf("[XML ERROR] Unknown tag in header node : %s\n",tag);
    19351829            exit(1);
     
    19381832    }
    19391833} // end headerNode()
    1940    
     1834
     1835
    19411836///////////////////////////////////////
    1942 void BuildTable( int fdout,
    1943                const char* type,
    1944                unsigned int nb_elem,
    1945                unsigned int elem_size,
    1946                char** table)       
    1947 ////////////////////////////////////////
    1948 {
     1837void BuildTable(int fdout, const char * type, unsigned int nb_elem,
     1838                unsigned int elem_size, char ** table) {
    19491839    unsigned int i;
    19501840    // write element
    1951     for ( i = 0 ; i < nb_elem ; i++ )
    1952     {
    1953         if(elem_size != write(fdout, table[i], elem_size))
    1954         {
     1841    for (i = 0; i < nb_elem; i++) {
     1842        if (elem_size != write(fdout, table[i], elem_size)) {
    19551843            printf("function %s: %s(%d) write  error \n", __FUNCTION__, type, i);
    19561844            exit(1);
     
    19581846
    19591847#if XML_PARSER_DEBUG
    1960 printf("Building binary: writing %s %d\n", type, i);
     1848        printf("Building binary: writing %s %d\n", type, i);
    19611849#endif
    19621850    }
    19631851}
    19641852
    1965 int open_file(const char* file_path)
    1966 {
     1853
     1854int open_file(const char * file_path) {
    19671855
    19681856    //open file
    1969     int fdout = open( file_path, (O_CREAT | O_RDWR | O_TRUNC), (S_IWUSR | S_IRUSR) );
    1970     if ( fdout < 0)
    1971     {
     1857    int fdout = open( file_path, (O_CREAT | O_RDWR), (S_IWUSR | S_IRUSR) );
     1858    if (fdout < 0) {
    19721859        perror("open");
    19731860        exit(1);
    19741861    }
    19751862
    1976 //#if XML_PARSER_DEBUG
    1977     printf("%s\n",file_path);
    1978 //#endif
     1863    //reinitialise the file
     1864    if (ftruncate(fdout, 0)) {
     1865        perror("truncate");
     1866        exit(1);
     1867    }
     1868
     1869    //#if XML_PARSER_DEBUG
     1870    printf("%s\n", file_path);
     1871    //#endif
    19791872
    19801873    return fdout;
     
    19831876
    19841877///////////////////////////
    1985 void  buildBin( const char* file_path )
    1986 ///////////////////////////
    1987 {
    1988     unsigned int    length;
     1878void buildBin(const char * file_path) {
     1879    unsigned int length;
    19891880
    19901881    int fdout = open_file(file_path);
    19911882
    19921883    // write header to binary file
    1993     length = write(fdout, (char*)header, sizeof(mapping_header_t));
    1994     if ( length != sizeof(mapping_header_t) )
    1995     {
     1884    length = write(fdout, (char *) header, sizeof(mapping_header_t));
     1885    if (length != sizeof(mapping_header_t)) {
    19961886        printf("write header error : length = %d \n", length);
    19971887        exit(1);
     
    19991889
    20001890    // write clusters
    2001     BuildTable(fdout, "cluster", cluster_index, sizeof(mapping_cluster_t), (char**) cluster);
     1891    BuildTable(fdout, "cluster", cluster_index, sizeof(mapping_cluster_t), (char **) cluster);
    20021892    // write psegs
    2003     BuildTable(fdout, "pseg", pseg_index, sizeof(mapping_pseg_t), (char**) pseg);
     1893    BuildTable(fdout, "pseg", pseg_index, sizeof(mapping_pseg_t), (char **) pseg);
    20041894    // write vspaces
    2005     BuildTable(fdout, "vspace", vspace_index, sizeof(mapping_vspace_t), (char**) vspace);
     1895    BuildTable(fdout, "vspace", vspace_index, sizeof(mapping_vspace_t), (char **) vspace);
    20061896    // write vsegs
    2007     BuildTable(fdout, "vseg", vseg_index, sizeof(mapping_vseg_t), (char**) vseg);
     1897    BuildTable(fdout, "vseg", vseg_index, sizeof(mapping_vseg_t), (char **) vseg);
    20081898    // write vobjs
    2009     BuildTable(fdout, "vobj", vobj_index, sizeof(mapping_vobj_t), (char**) vobj);
     1899    BuildTable(fdout, "vobj", vobj_index, sizeof(mapping_vobj_t), (char **) vobj);
    20101900    // write tasks array
    2011     BuildTable(fdout, "task", task_index, sizeof(mapping_task_t), (char**) task);
     1901    BuildTable(fdout, "task", task_index, sizeof(mapping_task_t), (char **) task);
    20121902    //building procs array
    2013     BuildTable(fdout, "proc", proc_index, sizeof(mapping_proc_t), (char**) proc);
     1903    BuildTable(fdout, "proc", proc_index, sizeof(mapping_proc_t), (char **) proc);
    20141904    //building irqs array
    2015     BuildTable(fdout, "irq", irq_index, sizeof(mapping_irq_t), (char**)irq);
     1905    BuildTable(fdout, "irq", irq_index, sizeof(mapping_irq_t), (char **) irq);
    20161906    //building coprocs array
    2017     BuildTable(fdout, "coproc", coproc_index, sizeof(mapping_coproc_t), (char**)coproc);
     1907    BuildTable(fdout, "coproc", coproc_index, sizeof(mapping_coproc_t), (char **) coproc);
    20181908    //building cp_ports array
    2019     BuildTable(fdout, "cp_port", cp_port_index, sizeof(mapping_cp_port_t),(char**) cp_port);
     1909    BuildTable(fdout, "cp_port", cp_port_index, sizeof(mapping_cp_port_t),(char **) cp_port);
    20201910    //building periphs array
    2021     BuildTable(fdout, "periph", periph_index, sizeof(mapping_periph_t), (char**)periph);
    2022    
     1911    BuildTable(fdout, "periph", periph_index, sizeof(mapping_periph_t), (char **) periph);
     1912
    20231913    close(fdout);
    20241914
    20251915} // end buildBin()
     1916
    20261917
    20271918///////////////////////////////////////////////////////////////////////
    20281919// this function set the value the vobj_id fiels of all cp_ports
    20291920///////////////////////////////////////////////////////////////////////
    2030 void prepareBuild()
    2031 {
     1921void prepareBuild() {
    20321922    unsigned int i;
    20331923    //asign for all cp_ports the correct vspaceid and vobjid
    2034     for(i=0; i< cp_port_index; i++)
    2035     {
    2036         int vspace_id = getVspaceId( cp_port_vobj_ref[i]->vspace_name );
    2037         if ( vspace_id < 0 )
    2038         {
    2039             printf("[XML ERROR] illegal  <vspacename> for cp_port %d,\n",
    2040                     i);
     1924    for (i = 0; i < cp_port_index; i++) {
     1925        int vspace_id = getVspaceId(cp_port_vobj_ref[i]->vspace_name);
     1926        if (vspace_id < 0) {
     1927            printf("[XML ERROR] illegal  <vspacename> for cp_port %d,\n", i);
    20411928            exit(1);
    20421929        }
    20431930        cp_port[i]->vspaceid = vspace_id;
    2044        
    2045         int vobj_id = getVobjLocId( vspace_id,
    2046                                     cp_port_vobj_ref[i]->vobj_name,
    2047                                     vspace[vspace_id]->vobjs );
    2048         if ( vobj_id >= 0 )
    2049         {
    2050 
    2051 #if XML_PARSER_DEBUG
    2052 printf("\ncp_port = %d\n", i);
    2053 printf("      vspace_name  = %s\n", cp_port_vobj_ref[i]->vspace_name);
    2054 printf("      vobj_name    = %s\n", cp_port_vobj_ref[i]->vobj_name);
    2055 printf("      vobj_index   = %d\n", vobj_id);
     1931
     1932        int vobj_id = getVobjLocId(vspace_id, cp_port_vobj_ref[i]->vobj_name, vspace[vspace_id]->vobjs);
     1933        if (vobj_id >= 0) {
     1934
     1935#if XML_PARSER_DEBUG
     1936            printf("\ncp_port = %d\n", i);
     1937            printf("      vspace_name  = %s\n", cp_port_vobj_ref[i]->vspace_name);
     1938            printf("      vobj_name    = %s\n", cp_port_vobj_ref[i]->vobj_name);
     1939            printf("      vobj_index   = %d\n", vobj_id);
    20561940#endif
    20571941            cp_port[i]->vobjlocid = vobj_id;
    20581942
    20591943            assert((vobj[ vspace[vspace_id]->vobj_offset + vobj_id]->type == VOBJ_TYPE_MWMR)
    2060             && "coproc ports has to refere to a vobj of type MWMR");
    2061         }
    2062         else             
    2063         {
    2064             printf("[XML ERROR] illegal  <vobjname> for cp_port %d,\n",
    2065                     i);
     1944                    && "coproc ports have to refer to a vobj of type MWMR");
     1945        }
     1946        else {
     1947            printf("[XML ERROR] illegal  <vobjname> for cp_port %d,\n", i);
    20661948            exit(1);
    20671949        }
     
    20691951}
    20701952
     1953
    20711954//////////////////////////////////////////
    2072 void file_write(int fdout, char* towrite)
    2073 {
     1955void file_write(int fdout, char * towrite) {
    20741956    unsigned int size = strlen(towrite);
    2075     if(size != write(fdout, towrite, size))
    2076     {
     1957    if (size != write(fdout, towrite, size)) {
    20771958        printf("file_write error");
    20781959        exit(1);
     
    20801961}
    20811962
     1963
    20821964//////////////////////////////////////////////////
    2083 void def_int_write(int fdout, char* def, int num)
    2084 {
    2085     char buf[64];
     1965void def_int_write(int fdout, char * def, int num) {
     1966    char  buf[64];
    20861967    sprintf(buf, "#define\t %s  %d\n", def, num);
    20871968    file_write(fdout, buf);
    20881969}
    20891970
     1971
    20901972/////////////////////////////////////////////////
    2091 void def_hex_write(int fdout, char* def, int num)
    2092 {
    2093     char buf[64];
     1973void def_hex_write(int fdout, char * def, int num) {
     1974    char  buf[64];
    20941975    sprintf(buf, "#define\t %s  0x%x\n", def, num);
    20951976    file_write(fdout, buf);
    20961977}
    20971978
     1979
    20981980///////////////////////////////////////
    2099 void  genHd( const char* file_path )
    2100 ///////////////////////////////////////
    2101 {
     1981void  genHd(const char * file_path) {
    21021982    int fdout = open_file(file_path);
    21031983
    2104     char* prol = " /* Generated from the mapping_info file */\n\n#ifndef _HD_CONFIG_H\n#define _HD_CONFIG_H\n\n";
     1984    char * prol = " /* Generated from the mapping_info file */\n\n#ifndef _HD_CONFIG_H\n#define _HD_CONFIG_H\n\n";
    21051985    file_write(fdout, prol);
    21061986
    2107     def_int_write(fdout, "CLUSTER_X"       , cluster_x);
    2108     def_int_write(fdout, "CLUSTER_Y"       , cluster_y);
    2109     def_int_write(fdout, "NB_CLUSTERS"     , cluster_index);
    2110     def_hex_write(fdout, "CLUSTER_SIZE"    , (((unsigned long long) 1) << 32) / cluster_index);
    2111     def_int_write(fdout, "NB_PROCS_MAX"    , nb_proc_max);
    2112     def_int_write(fdout, "NB_TIMERS_MAX"   , nb_timer_channel_max);
    2113     def_int_write(fdout, "NB_DMAS_MAX"     , nb_dma_channel_max);
    2114     def_int_write(fdout, "NB_TTYS"         , nb_tty_channel);
    2115     def_int_write(fdout, "NB_IOCS"         , nb_ioc_channel);
    2116     def_int_write(fdout, "NB_NICS"         , nb_nic_channel);
    2117    
     1987    def_int_write(fdout, "CLUSTER_X"    , cluster_x);
     1988    def_int_write(fdout, "CLUSTER_Y"    , cluster_y);
     1989    def_int_write(fdout, "NB_CLUSTERS"  , cluster_index);
     1990    def_hex_write(fdout, "CLUSTER_SIZE" , (((unsigned long long) 1) << 32) / cluster_index);
     1991    def_int_write(fdout, "NB_PROCS_MAX" , nb_proc_max);
     1992    def_int_write(fdout, "NB_TIMERS_MAX", nb_timer_channel_max);
     1993    def_int_write(fdout, "NB_DMAS_MAX"  , nb_dma_channel_max);
     1994    def_int_write(fdout, "NB_TTYS"      , nb_tty_channel);
     1995    def_int_write(fdout, "NB_IOCS"      , nb_ioc_channel);
     1996    def_int_write(fdout, "NB_NICS"      , nb_nic_channel);
     1997
    21181998    file_write(fdout, "\n");
    2119     def_int_write(fdout, "USE_XICU"         , use_xicu);
    2120     def_int_write(fdout, "IOMMU_ACTIVE "    , io_mmu_active);
    2121 
    2122     char* epil = "\n#endif //_HD_CONFIG_H";
     1999    def_int_write(fdout, "USE_XICU"     , use_xicu);
     2000    def_int_write(fdout, "IOMMU_ACTIVE ", io_mmu_active);
     2001
     2002    char * epil = "\n#endif //_HD_CONFIG_H";
    21232003    file_write(fdout, epil);
    21242004
     
    21262006}
    21272007
     2008
    21282009////////////////////////////////////////////////////////
    2129 void ld_write(int fdout, char* seg, unsigned int addr)
    2130 {
    2131     char  buf[64];
     2010void ld_write(int fdout, char * seg, unsigned int addr) {
     2011    char buf[64];
    21322012    sprintf(buf, "%s = 0x%x;\n", seg, addr);
    21332013    file_write(fdout, buf);
     
    21352015}
    21362016
     2017
    21372018///////////////////////////////////////
    2138 void  genLd (const char * file_path)
    2139 ///////////////////////////////////////
    2140 {
     2019void genLd(const char * file_path) {
    21412020    int fdout = open_file(file_path);
    21422021
    2143     char* prol = "/* Generated from the mapping_info file */\n\n";
     2022    char * prol = "/* Generated from the mapping_info file */\n\n";
    21442023    file_write(fdout, prol);
    21452024
    21462025    //boot
    2147     ld_write(fdout, "seg_boot_code_base"           , boot_code_base);
    2148     ld_write(fdout, "seg_boot_stack_base"          , boot_stack_base);
    2149     ld_write(fdout, "seg_mapping_base"             , boot_mapping_base);
     2026    ld_write(fdout, "seg_boot_code_base", boot_code_base);
     2027    ld_write(fdout, "seg_boot_stack_base", boot_stack_base);
     2028    ld_write(fdout, "seg_mapping_base", boot_mapping_base);
    21502029
    21512030    //kernel
    2152     ld_write(fdout, "\nseg_kernel_code_base"       , kernel_code_base);
    2153     ld_write(fdout, "seg_kernel_data_base"         , kernel_data_base);
    2154     ld_write(fdout, "seg_kernel_uncdata_base"      , kernel_uncdata_base);
    2155     ld_write(fdout, "seg_kernel_init_base"         , kernel_init_base);
     2031    ld_write(fdout, "\nseg_kernel_code_base", kernel_code_base);
     2032    ld_write(fdout, "seg_kernel_data_base",    kernel_data_base);
     2033    ld_write(fdout, "seg_kernel_uncdata_base", kernel_uncdata_base);
     2034    ld_write(fdout, "seg_kernel_init_base",    kernel_init_base);
    21562035
    21572036    //peripherals
    2158     ld_write(fdout, "\nseg_fbf_base",  fbf_base_offset);
    2159     ld_write(fdout, "seg_icu_base"  ,  icu_base_offset);
    2160     ld_write(fdout, "seg_ioc_base"  ,  ioc_base_offset);
    2161     ld_write(fdout, "seg_nic_base"  ,  nic_base_offset);
    2162     ld_write(fdout, "seg_tty_base"  ,  tty_base_offset);
    2163     ld_write(fdout, "seg_dma_base"  ,  dma_base_offset);
    2164     ld_write(fdout, "seg_tim_base"  ,  tim_base_offset);
    2165     ld_write(fdout, "seg_gcd_base"  ,  gcd_base_offset);
    2166     ld_write(fdout, "seg_iob_base"  ,  iob_base_offset);
     2037    ld_write(fdout, "\nseg_fbf_base", fbf_base_offset);
     2038    ld_write(fdout, "seg_icu_base",   icu_base_offset);
     2039    ld_write(fdout, "seg_ioc_base",   ioc_base_offset);
     2040    ld_write(fdout, "seg_nic_base",   nic_base_offset);
     2041    ld_write(fdout, "seg_tty_base",   tty_base_offset);
     2042    ld_write(fdout, "seg_dma_base",   dma_base_offset);
     2043    ld_write(fdout, "seg_tim_base",   tim_base_offset);
     2044    ld_write(fdout, "seg_gcd_base",   gcd_base_offset);
     2045    ld_write(fdout, "seg_iob_base",   iob_base_offset);
    21672046
    21682047    close(fdout);
    21692048}
    21702049
    2171 char * buildPath(const char * path, const char * name)
    2172 {
     2050
     2051char * buildPath(const char * path, const char * name) {
    21732052    char * res = calloc(strlen(path) + strlen(name) + 1, 1);
    21742053    strcat(res, path);
     
    21782057}
    21792058
     2059
    21802060/////////////////////////////////////
    2181 int  main(int argc, char * argv[])
    2182 /////////////////////////////////////
    2183 {
    2184     if ( argc < 3 )
    2185     {
     2061int main(int argc, char * argv[]) {
     2062    if (argc < 3) {
    21862063        printf("Usage: xml2bin <input_file_path> <output_path>\n");
    21872064        return 1;
     
    21892066
    21902067    struct stat dir_st;
    2191     if(stat( argv[2], &dir_st ))
    2192     {
     2068    if (stat( argv[2], &dir_st)) {
    21932069        perror("bad path");
    21942070        exit(1);
    21952071    }
    21962072
    2197     if((dir_st.st_mode & S_IFDIR) == 0)
    2198     {
     2073    if ((dir_st.st_mode & S_IFDIR) == 0) {
    21992074        printf("path is not a dir: %s", argv[2] );
    22002075        exit(1);
    22012076    }
    22022077
    2203    
    2204     char *map_path = buildPath(argv[2], "map.bin");
    2205     char *ld_path = buildPath(argv[2], "giet_vsegs.ld");
    2206     char *hd_path = buildPath(argv[2], "hard_config.h");
     2078
     2079    char * map_path = buildPath(argv[2], "map.bin");
     2080    char * ld_path = buildPath(argv[2], "giet_vsegs.ld");
     2081    char * hd_path = buildPath(argv[2], "hard_config.h");
    22072082
    22082083    LIBXML_TEST_VERSION;
    22092084
    22102085    int status;
    2211     xmlTextReaderPtr reader = xmlReaderForFile ( argv[1], NULL, 0 );
    2212 
    2213     if ( reader != NULL )
    2214     {
    2215         status = xmlTextReaderRead ( reader );
    2216         while ( status == 1 )
    2217         {
    2218             const char* tag = (const char*)xmlTextReaderConstName(reader);
    2219 
    2220             if ( strcmp(tag,"mapping_info") == 0 )
    2221             {
    2222                 headerNode( reader );
     2086    xmlTextReaderPtr reader = xmlReaderForFile(argv[1], NULL, 0);
     2087
     2088    if (reader != NULL) {
     2089        status = xmlTextReaderRead (reader);
     2090        while (status == 1) {
     2091            const char * tag = (const char *) xmlTextReaderConstName(reader);
     2092
     2093            if (strcmp(tag, "mapping_info") == 0) {
     2094                headerNode(reader);
    22232095                prepareBuild();
    2224                 buildBin( map_path );
     2096                buildBin(map_path);
    22252097                genHd(hd_path);
    22262098                genLd(ld_path);
    22272099            }
    2228             else
    2229             {
     2100            else {
    22302101                printf("[XML ERROR] Wrong file type: \"%s\"\n", argv[1]);
    22312102                return 1;
    22322103            }
    2233             status = xmlTextReaderRead ( reader );
    2234         }
    2235         xmlFreeTextReader ( reader );
    2236 
    2237         if ( status != 0 )
    2238         {
     2104            status = xmlTextReaderRead(reader);
     2105        }
     2106        xmlFreeTextReader(reader);
     2107
     2108        if (status != 0) {
    22392109            printf("[XML ERROR] Wrong Syntax in \"%s\" file\n", argv[1]);
    22402110            return 1;
     
    22452115
    22462116
    2247 
    2248 
     2117// Local Variables:
     2118// tab-width: 4
     2119// c-basic-offset: 4
     2120// c-file-offsets:((innamespace . 0)(inline-open . 0))
     2121// indent-tabs-mode: nil
     2122// End:
     2123// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     2124
Note: See TracChangeset for help on using the changeset viewer.