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