[306] | 1 | ////////////////////////////////////////////////////////////////////////////////////// |
---|
[258] | 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 | |
---|
| 17 | #include <stdlib.h> |
---|
| 18 | #include <fcntl.h> |
---|
| 19 | #include <sys/types.h> |
---|
| 20 | #include <sys/stat.h> |
---|
| 21 | #include <unistd.h> |
---|
| 22 | #include <stdio.h> |
---|
| 23 | #include <string.h> |
---|
| 24 | #include <assert.h> |
---|
| 25 | #include <libxml/xmlreader.h> |
---|
| 26 | #include <mapping_info.h> |
---|
| 27 | #include <irq_handler.h> |
---|
[627] | 28 | #include <giet_config.h> |
---|
[258] | 29 | |
---|
| 30 | #define MAX_CLUSTERS 1024 |
---|
| 31 | #define MAX_PSEGS 4096 |
---|
| 32 | #define MAX_VSPACES 1024 |
---|
| 33 | #define MAX_TASKS 4096 |
---|
| 34 | #define MAX_VSEGS 4096 |
---|
| 35 | #define MAX_PROCS 1024 |
---|
| 36 | #define MAX_IRQS 8192 |
---|
| 37 | #define MAX_PERIPHS 8192 |
---|
| 38 | |
---|
[511] | 39 | #define XML_PARSER_DEBUG 1 |
---|
[258] | 40 | |
---|
| 41 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 42 | // global variables used to store and index the data structures |
---|
| 43 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 44 | |
---|
| 45 | mapping_header_t * header; |
---|
| 46 | mapping_cluster_t * cluster[MAX_CLUSTERS]; // cluster array |
---|
| 47 | mapping_pseg_t * pseg[MAX_PSEGS]; // pseg array |
---|
| 48 | mapping_vspace_t * vspace[MAX_VSPACES]; // vspace array |
---|
| 49 | mapping_vseg_t * vseg[MAX_VSEGS]; // vseg array |
---|
| 50 | mapping_task_t * task[MAX_TASKS]; // task array |
---|
| 51 | mapping_proc_t * proc[MAX_PROCS]; // proc array |
---|
| 52 | mapping_irq_t * irq[MAX_IRQS]; // irq array |
---|
| 53 | mapping_periph_t * periph[MAX_PERIPHS]; // peripheral array |
---|
| 54 | |
---|
| 55 | // Index for the various arrays |
---|
| 56 | |
---|
| 57 | unsigned int cluster_index = 0; |
---|
| 58 | unsigned int vspace_index = 0; |
---|
| 59 | unsigned int global_index = 0; |
---|
| 60 | unsigned int pseg_index = 0; |
---|
| 61 | |
---|
| 62 | unsigned int proc_index = 0; |
---|
| 63 | unsigned int proc_loc_index = 0; |
---|
| 64 | |
---|
| 65 | unsigned int irq_index = 0; |
---|
| 66 | unsigned int irq_loc_index = 0; |
---|
| 67 | |
---|
| 68 | unsigned int periph_index = 0; |
---|
| 69 | unsigned int periph_loc_index = 0; |
---|
| 70 | |
---|
| 71 | unsigned int vseg_index = 0; |
---|
| 72 | unsigned int vseg_loc_index = 0; |
---|
| 73 | |
---|
| 74 | unsigned int task_index = 0; |
---|
| 75 | unsigned int task_loc_index = 0; |
---|
| 76 | |
---|
| 77 | |
---|
| 78 | ////////////////////////////////////////////////// |
---|
| 79 | unsigned int getIntValue( xmlTextReaderPtr reader, |
---|
| 80 | const char * attributeName, |
---|
| 81 | unsigned int * ok) |
---|
| 82 | { |
---|
| 83 | unsigned int value = 0; |
---|
| 84 | unsigned int i; |
---|
| 85 | char c; |
---|
| 86 | |
---|
| 87 | char * string = (char *) xmlTextReaderGetAttribute(reader, |
---|
| 88 | (const xmlChar *) attributeName); |
---|
| 89 | |
---|
| 90 | if (string == NULL) |
---|
| 91 | { |
---|
| 92 | // missing argument |
---|
| 93 | *ok = 0; |
---|
| 94 | return 0; |
---|
| 95 | } |
---|
| 96 | else |
---|
| 97 | { |
---|
| 98 | if ((string[0] == '0') && ((string[1] == 'x') || (string[1] == 'X'))) |
---|
| 99 | { |
---|
| 100 | // Hexa |
---|
| 101 | for (i = 2 ; (string[i] != 0) && (i < 10) ; i++) |
---|
| 102 | { |
---|
| 103 | c = string[i]; |
---|
| 104 | if ((c >= '0') && (c <= '9')) { value = (value << 4) + string[i] - 48; } |
---|
| 105 | else if ((c >= 'a') && (c <= 'f')) { value = (value << 4) + string[i] - 87; } |
---|
| 106 | else if ((c >= 'A') && (c <= 'F')) { value = (value << 4) + string[i] - 55; } |
---|
| 107 | else |
---|
| 108 | { |
---|
| 109 | *ok = 0; |
---|
| 110 | return 0; |
---|
| 111 | } |
---|
| 112 | } |
---|
| 113 | } |
---|
| 114 | else |
---|
| 115 | { |
---|
| 116 | // Decimal |
---|
| 117 | for (i = 0; (string[i] != 0) && (i < 9); i++) |
---|
| 118 | { |
---|
| 119 | c = string[i]; |
---|
| 120 | if ((c >= '0') && (c <= '9')) value = (value * 10) + string[i] - 48; |
---|
| 121 | else |
---|
| 122 | { |
---|
| 123 | *ok = 0; |
---|
| 124 | return 0; |
---|
| 125 | } |
---|
| 126 | } |
---|
| 127 | } |
---|
| 128 | *ok = 1; |
---|
| 129 | return value; |
---|
| 130 | } |
---|
| 131 | } // end getIntValue() |
---|
| 132 | |
---|
| 133 | //////////////////////////////////////////////// |
---|
| 134 | paddr_t getPaddrValue( xmlTextReaderPtr reader, |
---|
| 135 | const char * attributeName, |
---|
| 136 | unsigned int * ok) |
---|
| 137 | { |
---|
| 138 | paddr_t value = 0; |
---|
| 139 | unsigned int i; |
---|
| 140 | char c; |
---|
| 141 | |
---|
| 142 | char * string = (char *) xmlTextReaderGetAttribute(reader, |
---|
| 143 | (const xmlChar *) attributeName); |
---|
| 144 | |
---|
| 145 | if (string == NULL) |
---|
| 146 | { |
---|
| 147 | // missing argument |
---|
| 148 | *ok = 0; |
---|
| 149 | return 0; |
---|
| 150 | } |
---|
| 151 | else |
---|
| 152 | { |
---|
| 153 | if ((string[0] == '0') && ((string[1] == 'x') || (string[1] == 'X'))) |
---|
| 154 | { |
---|
| 155 | // Hexa |
---|
| 156 | for (i = 2 ; (string[i] != 0) && (i < 18) ; i++) |
---|
| 157 | { |
---|
| 158 | c = string[i]; |
---|
| 159 | if ((c >= '0') && (c <= '9')) { value = (value << 4) + string[i] - 48; } |
---|
| 160 | else if ((c >= 'a') && (c <= 'f')) { value = (value << 4) + string[i] - 87; } |
---|
| 161 | else if ((c >= 'A') && (c <= 'F')) { value = (value << 4) + string[i] - 55; } |
---|
| 162 | else |
---|
| 163 | { |
---|
| 164 | *ok = 0; |
---|
| 165 | return 0; |
---|
| 166 | } |
---|
| 167 | } |
---|
| 168 | } |
---|
| 169 | else |
---|
| 170 | { |
---|
| 171 | // Decimal not supported for paddr_t |
---|
| 172 | *ok = 0; |
---|
| 173 | return 0; |
---|
| 174 | } |
---|
| 175 | *ok = 1; |
---|
| 176 | return value; |
---|
| 177 | } |
---|
| 178 | } // end getPaddrValue() |
---|
| 179 | |
---|
| 180 | //////////////////////////////////////////////// |
---|
| 181 | char * getStringValue( xmlTextReaderPtr reader, |
---|
| 182 | const char * attributeName, |
---|
| 183 | unsigned int * ok ) |
---|
| 184 | { |
---|
| 185 | char * string = (char *) xmlTextReaderGetAttribute(reader, |
---|
| 186 | (const xmlChar *) attributeName); |
---|
| 187 | |
---|
| 188 | |
---|
| 189 | if (string == NULL) |
---|
| 190 | { |
---|
| 191 | // missing argument |
---|
| 192 | *ok = 0; |
---|
| 193 | return NULL; |
---|
| 194 | } |
---|
| 195 | else |
---|
| 196 | { |
---|
| 197 | //we read only string smaller than 32 byte |
---|
| 198 | if (strlen(string) > 32) |
---|
| 199 | { |
---|
| 200 | printf("[XML ERROR] all strings must be less than 32 bytes\n"); |
---|
| 201 | exit(1); |
---|
| 202 | } |
---|
| 203 | |
---|
| 204 | *ok = 1; |
---|
| 205 | return string; |
---|
| 206 | } |
---|
| 207 | } // end getStringValue() |
---|
| 208 | |
---|
[263] | 209 | /////////////////////////////////////////////////////////////// |
---|
| 210 | int getClusterId( unsigned int x, unsigned int y ) |
---|
[258] | 211 | { |
---|
[263] | 212 | // associative search of cluster index |
---|
| 213 | unsigned int cluster_id; |
---|
| 214 | |
---|
| 215 | for( cluster_id = 0 ; cluster_id < (header->x_size * header->y_size) ; cluster_id++ ) |
---|
| 216 | { |
---|
| 217 | if( (cluster[cluster_id]->x == x) && (cluster[cluster_id]->y == y) ) |
---|
| 218 | { |
---|
| 219 | return cluster_id; |
---|
| 220 | } |
---|
| 221 | } |
---|
| 222 | return -1; |
---|
| 223 | } // end getClusterId() |
---|
| 224 | |
---|
| 225 | /////////////////////////////////////////////////////////////// |
---|
| 226 | int getPsegId(unsigned int x, unsigned int y, char * pseg_name) |
---|
| 227 | { |
---|
| 228 | int cluster_id = getClusterId( x, y ); |
---|
| 229 | |
---|
| 230 | if ( cluster_id == -1 ) return -1; |
---|
| 231 | |
---|
| 232 | // associative search for pseg index |
---|
[258] | 233 | unsigned int pseg_id; |
---|
| 234 | unsigned int pseg_min = cluster[cluster_id]->pseg_offset; |
---|
| 235 | unsigned int pseg_max = pseg_min + cluster[cluster_id]->psegs; |
---|
| 236 | |
---|
| 237 | for (pseg_id = pseg_min; pseg_id < pseg_max; pseg_id++) |
---|
| 238 | { |
---|
| 239 | if (strcmp(pseg[pseg_id]->name, pseg_name) == 0) |
---|
| 240 | { |
---|
| 241 | return pseg_id; |
---|
| 242 | } |
---|
| 243 | } |
---|
| 244 | return -1; |
---|
[263] | 245 | } // end getPsegId() |
---|
[258] | 246 | |
---|
| 247 | /////////////////////////////////// |
---|
| 248 | int getVspaceId(char * vspace_name) |
---|
| 249 | { |
---|
| 250 | unsigned int vspace_id; |
---|
| 251 | |
---|
| 252 | for (vspace_id = 0; vspace_id < vspace_index; vspace_id++) |
---|
| 253 | { |
---|
| 254 | if (strcmp(vspace[vspace_id]->name, vspace_name) == 0) |
---|
| 255 | { |
---|
| 256 | return vspace_id; |
---|
| 257 | } |
---|
| 258 | } |
---|
| 259 | return -1; |
---|
| 260 | } |
---|
| 261 | |
---|
[511] | 262 | /////////////////////////////////////////////////// |
---|
| 263 | int getVsegId( unsigned int vspace_id, char *name ) |
---|
[258] | 264 | { |
---|
[511] | 265 | unsigned int vseg_id; |
---|
| 266 | unsigned int vseg_min = vspace[vspace_id]->vseg_offset; |
---|
| 267 | unsigned int vseg_max = vseg_min + vspace[vspace_id]->vsegs; |
---|
[258] | 268 | |
---|
[511] | 269 | for (vseg_id = vseg_min ; vseg_id < vseg_max ; vseg_id++) |
---|
[258] | 270 | { |
---|
[511] | 271 | if (strcmp(vseg[vseg_id]->name, name) == 0) return vseg_id; |
---|
[258] | 272 | } |
---|
| 273 | return -1; |
---|
| 274 | } |
---|
| 275 | |
---|
[295] | 276 | |
---|
[258] | 277 | ////////////////////////////////////// |
---|
| 278 | void taskNode(xmlTextReaderPtr reader) |
---|
| 279 | { |
---|
| 280 | unsigned int ok; |
---|
| 281 | unsigned int value; |
---|
[263] | 282 | unsigned int x,y; |
---|
[258] | 283 | char * str; |
---|
| 284 | |
---|
| 285 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
| 286 | |
---|
| 287 | if (task_index >= MAX_TASKS) |
---|
| 288 | { |
---|
| 289 | printf("[XML ERROR] The number of tasks is larger than %d\n", MAX_TASKS); |
---|
| 290 | exit(1); |
---|
| 291 | } |
---|
| 292 | |
---|
| 293 | #if XML_PARSER_DEBUG |
---|
| 294 | printf(" task %d\n", task_loc_index); |
---|
| 295 | #endif |
---|
| 296 | |
---|
| 297 | task[task_index] = (mapping_task_t *) malloc(sizeof(mapping_task_t)); |
---|
| 298 | |
---|
| 299 | ////////// get name attribute |
---|
| 300 | str = getStringValue(reader, "name", &ok); |
---|
| 301 | if (ok) |
---|
| 302 | { |
---|
| 303 | #if XML_PARSER_DEBUG |
---|
[263] | 304 | printf(" name = %s\n", str); |
---|
[258] | 305 | #endif |
---|
| 306 | strncpy( task[task_index]->name, str, 31 ); |
---|
| 307 | } |
---|
| 308 | else |
---|
| 309 | { |
---|
| 310 | printf("[XML ERROR] illegal or missing <name> attribute for task (%d,%d)\n", |
---|
| 311 | vspace_index, task_loc_index); |
---|
| 312 | exit(1); |
---|
| 313 | } |
---|
| 314 | |
---|
[295] | 315 | ///////// get trdid attribute (optional) |
---|
[627] | 316 | value = getIntValue(reader, "trdid", &ok); |
---|
[263] | 317 | #if XML_PARSER_DEBUG |
---|
[627] | 318 | printf(" trdid = %d\n", value ); |
---|
[263] | 319 | #endif |
---|
[627] | 320 | if ( ok ) task[task_index]->trdid = value; |
---|
| 321 | else task[task_index]->trdid = task_loc_index; |
---|
[267] | 322 | |
---|
| 323 | ///////// get x coordinate |
---|
| 324 | x = getIntValue(reader, "x", &ok); |
---|
| 325 | #if XML_PARSER_DEBUG |
---|
| 326 | printf(" x = %d\n", x); |
---|
| 327 | #endif |
---|
[263] | 328 | if ( !(ok && (x < header->x_size)) ) |
---|
[258] | 329 | { |
---|
[263] | 330 | printf("[XML ERROR] illegal or missing < x > attribute for task (%d,%d)\n", |
---|
| 331 | vspace_index, task_loc_index); |
---|
| 332 | exit(1); |
---|
| 333 | } |
---|
| 334 | |
---|
| 335 | ///////// get y coordinate |
---|
[267] | 336 | y = getIntValue(reader, "y", &ok); |
---|
[258] | 337 | #if XML_PARSER_DEBUG |
---|
[263] | 338 | printf(" y = %d\n", y); |
---|
[258] | 339 | #endif |
---|
[263] | 340 | if ( !(ok && (y < header->y_size)) ) |
---|
| 341 | { |
---|
| 342 | printf("[XML ERROR] illegal or missing < y > attribute for task (%d,%d)\n", |
---|
| 343 | vspace_index, task_loc_index); |
---|
| 344 | exit(1); |
---|
[258] | 345 | } |
---|
[263] | 346 | |
---|
| 347 | ///////// set clusterid attribute |
---|
| 348 | int index = getClusterId( x, y ); |
---|
| 349 | #if XML_PARSER_DEBUG |
---|
| 350 | printf(" clusterid = %d\n", index); |
---|
| 351 | #endif |
---|
| 352 | if( index >= 0 ) |
---|
[258] | 353 | { |
---|
[263] | 354 | task[task_index]->clusterid = index; |
---|
| 355 | } |
---|
| 356 | else |
---|
| 357 | { |
---|
| 358 | printf("[XML ERROR] <clusterid> not found for task (%d,%d)\n", |
---|
[258] | 359 | vspace_index, task_loc_index); |
---|
| 360 | exit(1); |
---|
| 361 | } |
---|
| 362 | |
---|
[306] | 363 | ////////// get p attribute |
---|
| 364 | value = getIntValue(reader, "p", &ok); |
---|
[258] | 365 | if (ok) |
---|
| 366 | { |
---|
| 367 | #if XML_PARSER_DEBUG |
---|
| 368 | printf(" proclocid = %x\n", value); |
---|
| 369 | #endif |
---|
| 370 | if (value >= cluster[task[task_index]->clusterid]->procs) |
---|
| 371 | { |
---|
| 372 | printf("[XML ERROR] <proclocid> too large for task (%d,%d)\n", |
---|
| 373 | vspace_index, task_loc_index); |
---|
| 374 | exit(1); |
---|
| 375 | } |
---|
| 376 | task[task_index]->proclocid = value; |
---|
| 377 | } |
---|
| 378 | else |
---|
| 379 | { |
---|
[306] | 380 | printf("[XML ERROR] illegal or missing <p> attribute for task (%d,%d)\n", |
---|
[258] | 381 | vspace_index, task_loc_index); |
---|
| 382 | exit(1); |
---|
| 383 | } |
---|
| 384 | |
---|
| 385 | ////////// get stackname attribute |
---|
[511] | 386 | char* stack_name = getStringValue(reader, "stackname" , &ok); |
---|
[258] | 387 | if (ok) |
---|
| 388 | { |
---|
[511] | 389 | #if XML_PARSER_DEBUG |
---|
| 390 | printf(" stackname = %s\n", str); |
---|
| 391 | #endif |
---|
| 392 | int index = getVsegId( vspace_index , stack_name ); |
---|
[258] | 393 | if (index >= 0) |
---|
| 394 | { |
---|
| 395 | #if XML_PARSER_DEBUG |
---|
[323] | 396 | printf(" stack_id = %d\n", index); |
---|
[258] | 397 | #endif |
---|
[511] | 398 | task[task_index]->stack_vseg_id = index; |
---|
[258] | 399 | } |
---|
| 400 | else |
---|
| 401 | { |
---|
| 402 | printf("[XML ERROR] illegal or missing <stackname> for task (%d,%d)\n", |
---|
| 403 | vspace_index, task_loc_index); |
---|
| 404 | exit(1); |
---|
| 405 | } |
---|
| 406 | } |
---|
| 407 | else |
---|
| 408 | { |
---|
| 409 | printf("[XML ERROR] illegal or missing <stackname> for task (%d,%d)\n", |
---|
| 410 | vspace_index, task_loc_index); |
---|
| 411 | exit(1); |
---|
| 412 | } |
---|
| 413 | |
---|
| 414 | ////////// get heap attribute |
---|
[511] | 415 | char* heap_name = getStringValue(reader, "heapname", &ok); |
---|
[258] | 416 | if (ok) |
---|
| 417 | { |
---|
[511] | 418 | #if XML_PARSER_DEBUG |
---|
| 419 | printf(" heapname = %s\n", str); |
---|
| 420 | #endif |
---|
| 421 | int index = getVsegId( vspace_index , heap_name ); |
---|
[258] | 422 | if (index >= 0) |
---|
| 423 | { |
---|
| 424 | #if XML_PARSER_DEBUG |
---|
[323] | 425 | printf(" heap_id = %d\n", index ); |
---|
[258] | 426 | #endif |
---|
[511] | 427 | task[task_index]->heap_vseg_id = index; |
---|
[258] | 428 | } |
---|
| 429 | else |
---|
| 430 | { |
---|
| 431 | printf("[XML ERROR] illegal or missing <heapname> for task (%d,%d)\n", |
---|
| 432 | vspace_index, task_loc_index); |
---|
| 433 | exit(1); |
---|
| 434 | } |
---|
| 435 | } |
---|
| 436 | else |
---|
| 437 | { |
---|
[511] | 438 | task[task_index]->heap_vseg_id = -1; |
---|
[258] | 439 | } |
---|
| 440 | |
---|
| 441 | ////////// get startid attribute |
---|
| 442 | value = getIntValue(reader, "startid", &ok); |
---|
| 443 | if (ok) |
---|
| 444 | { |
---|
| 445 | #if XML_PARSER_DEBUG |
---|
[263] | 446 | printf(" startid = %x\n", value); |
---|
[258] | 447 | #endif |
---|
| 448 | task[task_index]->startid = value; |
---|
| 449 | } |
---|
| 450 | else |
---|
| 451 | { |
---|
| 452 | printf("[XML ERROR] illegal or missing <startid> attribute for task (%d,%d)\n", |
---|
| 453 | vspace_index, task_loc_index); |
---|
| 454 | exit(1); |
---|
| 455 | } |
---|
| 456 | |
---|
| 457 | task_index++; |
---|
| 458 | task_loc_index++; |
---|
| 459 | } // end taskNode() |
---|
| 460 | |
---|
| 461 | |
---|
| 462 | ////////////////////////////////////// |
---|
| 463 | void vsegNode(xmlTextReaderPtr reader) |
---|
| 464 | { |
---|
| 465 | unsigned int ok; |
---|
| 466 | unsigned int value; |
---|
[263] | 467 | unsigned int x,y; |
---|
[258] | 468 | char * str; |
---|
| 469 | |
---|
| 470 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
| 471 | |
---|
| 472 | if (vseg_index >= MAX_VSEGS) |
---|
| 473 | { |
---|
| 474 | printf("[XML ERROR] The number of vsegs is larger than %d\n", MAX_VSEGS); |
---|
| 475 | exit(1); |
---|
| 476 | } |
---|
| 477 | |
---|
| 478 | #if XML_PARSER_DEBUG |
---|
| 479 | printf(" vseg %d\n", vseg_loc_index); |
---|
| 480 | #endif |
---|
| 481 | |
---|
| 482 | vseg[vseg_index] = (mapping_vseg_t *) malloc(sizeof(mapping_vseg_t)); |
---|
| 483 | |
---|
| 484 | ///////// set mapped attribute |
---|
| 485 | vseg[vseg_index]->mapped = 0; |
---|
| 486 | |
---|
| 487 | ///////// get name attribute |
---|
| 488 | str = getStringValue(reader, "name", &ok); |
---|
| 489 | if (ok) |
---|
| 490 | { |
---|
| 491 | #if XML_PARSER_DEBUG |
---|
[263] | 492 | printf(" name = %s\n", str); |
---|
[258] | 493 | #endif |
---|
| 494 | strncpy( vseg[vseg_index]->name, str, 31); |
---|
| 495 | } |
---|
| 496 | else |
---|
| 497 | { |
---|
| 498 | printf("[XML ERROR] illegal or missing <name> attribute for vseg (%d,%d)\n", |
---|
| 499 | vspace_index, vseg_loc_index); |
---|
| 500 | exit(1); |
---|
| 501 | } |
---|
| 502 | |
---|
| 503 | ////////// get ident attribute (optional : 0 if missing) |
---|
| 504 | value = getIntValue(reader, "ident", &ok); |
---|
| 505 | if (ok) |
---|
| 506 | { |
---|
| 507 | #if XML_PARSER_DEBUG |
---|
[263] | 508 | printf(" ident = %d\n", value); |
---|
[258] | 509 | #endif |
---|
| 510 | vseg[vseg_index]->ident = value; |
---|
| 511 | } |
---|
| 512 | else |
---|
| 513 | { |
---|
| 514 | vseg[vseg_index]->ident = 0; |
---|
| 515 | } |
---|
| 516 | |
---|
[349] | 517 | ////////// get local attribute (optional : 0 if missing) |
---|
| 518 | value = getIntValue(reader, "local", &ok); |
---|
| 519 | if (ok) |
---|
| 520 | { |
---|
| 521 | #if XML_PARSER_DEBUG |
---|
| 522 | printf(" local = %d\n", value); |
---|
| 523 | #endif |
---|
| 524 | vseg[vseg_index]->local = value; |
---|
| 525 | } |
---|
| 526 | else |
---|
| 527 | { |
---|
| 528 | vseg[vseg_index]->local = 0; |
---|
| 529 | } |
---|
| 530 | |
---|
[511] | 531 | ////////// get big attribute (optional : 0 if missing) |
---|
| 532 | value = getIntValue(reader, "big", &ok); |
---|
| 533 | if (ok) |
---|
| 534 | { |
---|
| 535 | #if XML_PARSER_DEBUG |
---|
| 536 | printf(" big = %d\n", value); |
---|
| 537 | #endif |
---|
| 538 | vseg[vseg_index]->big = value; |
---|
| 539 | } |
---|
| 540 | else |
---|
| 541 | { |
---|
| 542 | vseg[vseg_index]->big = 0; |
---|
| 543 | } |
---|
| 544 | |
---|
[258] | 545 | /////////// get vbase attribute |
---|
| 546 | value = getIntValue(reader, "vbase", &ok); |
---|
| 547 | if (ok) |
---|
| 548 | { |
---|
| 549 | #if XML_PARSER_DEBUG |
---|
[263] | 550 | printf(" vbase = 0x%x\n", value); |
---|
[258] | 551 | #endif |
---|
| 552 | vseg[vseg_index]->vbase = value; |
---|
| 553 | } |
---|
| 554 | else |
---|
| 555 | { |
---|
| 556 | printf("[XML ERROR] illegal or missing <vbase> attribute for vseg (%d,%d)\n", |
---|
| 557 | vspace_index, vseg_loc_index); |
---|
| 558 | exit(1); |
---|
| 559 | } |
---|
| 560 | |
---|
[511] | 561 | ////////// get length attribute |
---|
| 562 | value = getIntValue(reader, "length", &ok); |
---|
| 563 | if (ok) |
---|
| 564 | { |
---|
| 565 | #if XML_PARSER_DEBUG |
---|
| 566 | printf(" length = %x\n", value); |
---|
| 567 | #endif |
---|
| 568 | vseg[vseg_index]->length = value; |
---|
| 569 | } |
---|
| 570 | else |
---|
| 571 | { |
---|
| 572 | printf("[XML ERROR] illegal or missing <length> attribute for vseg (%d,%d)\n", |
---|
| 573 | vspace_index, vseg_loc_index); |
---|
| 574 | exit(1); |
---|
| 575 | } |
---|
| 576 | |
---|
| 577 | //////// get type attribute |
---|
| 578 | str = getStringValue(reader, "type", &ok); |
---|
| 579 | |
---|
| 580 | #if XML_PARSER_DEBUG |
---|
| 581 | printf(" type = %s\n", str); |
---|
| 582 | #endif |
---|
| 583 | |
---|
| 584 | if (ok && (strcmp(str, "ELF") == 0)) vseg[vseg_index]->type = VSEG_TYPE_ELF; |
---|
| 585 | else if (ok && (strcmp(str, "PERI") == 0)) vseg[vseg_index]->type = VSEG_TYPE_PERI; |
---|
| 586 | else if (ok && (strcmp(str, "BLOB") == 0)) vseg[vseg_index]->type = VSEG_TYPE_BLOB; |
---|
| 587 | else if (ok && (strcmp(str, "PTAB") == 0)) vseg[vseg_index]->type = VSEG_TYPE_PTAB; |
---|
| 588 | else if (ok && (strcmp(str, "BUFFER") == 0)) vseg[vseg_index]->type = VSEG_TYPE_BUFFER; |
---|
| 589 | else if (ok && (strcmp(str, "SCHED") == 0)) vseg[vseg_index]->type = VSEG_TYPE_SCHED; |
---|
| 590 | else if (ok && (strcmp(str, "HEAP") == 0)) vseg[vseg_index]->type = VSEG_TYPE_HEAP; |
---|
| 591 | else |
---|
| 592 | { |
---|
| 593 | printf("[XML ERROR] illegal or missing <type> attribute for vseg (%d,%d)\n", |
---|
| 594 | vspace_index, vseg_loc_index); |
---|
| 595 | exit(1); |
---|
| 596 | } |
---|
| 597 | |
---|
[263] | 598 | ////////// get x coordinate |
---|
| 599 | x = getIntValue(reader, "x", &ok); |
---|
| 600 | #if XML_PARSER_DEBUG |
---|
| 601 | printf(" x = %d\n", x); |
---|
| 602 | #endif |
---|
| 603 | if ( !(ok && (x < header->x_size)) ) |
---|
[258] | 604 | { |
---|
[263] | 605 | printf("[XML ERROR] illegal or missing < x > attribute for vseg %d\n", |
---|
[258] | 606 | vseg_loc_index); |
---|
| 607 | exit(1); |
---|
| 608 | } |
---|
[263] | 609 | |
---|
| 610 | ////////// get y coordinate |
---|
| 611 | y = getIntValue(reader, "y", &ok); |
---|
| 612 | #if XML_PARSER_DEBUG |
---|
| 613 | printf(" y = %d\n", y); |
---|
| 614 | #endif |
---|
| 615 | if ( !(ok && (y < header->y_size)) ) |
---|
| 616 | { |
---|
| 617 | printf("[XML ERROR] illegal or missing < y > attribute for vseg %d\n", |
---|
| 618 | vseg_loc_index); |
---|
| 619 | exit(1); |
---|
| 620 | } |
---|
| 621 | |
---|
| 622 | ///////// get psegname attribute |
---|
[258] | 623 | str = getStringValue(reader, "psegname", &ok); |
---|
[263] | 624 | #if XML_PARSER_DEBUG |
---|
| 625 | printf(" psegname = %s\n", str); |
---|
| 626 | #endif |
---|
[258] | 627 | if (ok == 0) |
---|
| 628 | { |
---|
| 629 | printf("[XML ERROR] illegal or missing <psegname> for vseg %d\n", |
---|
| 630 | vseg_loc_index); |
---|
| 631 | exit(1); |
---|
| 632 | } |
---|
| 633 | |
---|
| 634 | /////////// set psegid field |
---|
[263] | 635 | int psegid = getPsegId( x, y, str ); |
---|
| 636 | #if XML_PARSER_DEBUG |
---|
| 637 | printf(" psegid = %d\n", psegid); |
---|
| 638 | #endif |
---|
[306] | 639 | if (psegid >= 0) |
---|
[258] | 640 | { |
---|
[263] | 641 | vseg[vseg_index]->psegid = psegid; |
---|
[258] | 642 | } |
---|
| 643 | else |
---|
| 644 | { |
---|
[263] | 645 | printf("[XML ERROR] pseg not found for vseg %d / x = %d / y = %d / psegname = %s\n", |
---|
| 646 | vseg_loc_index, x, y, str ); |
---|
[258] | 647 | exit(1); |
---|
| 648 | } |
---|
| 649 | |
---|
| 650 | //////// get mode attribute |
---|
| 651 | str = getStringValue(reader, "mode", &ok); |
---|
| 652 | #if XML_PARSER_DEBUG |
---|
[263] | 653 | printf(" mode = %s\n", str); |
---|
[258] | 654 | #endif |
---|
| 655 | if (ok && (strcmp(str, "CXWU") == 0)) { vseg[vseg_index]->mode = 0xF; } |
---|
| 656 | else if (ok && (strcmp(str, "CXW_") == 0)) { vseg[vseg_index]->mode = 0xE; } |
---|
| 657 | else if (ok && (strcmp(str, "CX_U") == 0)) { vseg[vseg_index]->mode = 0xD; } |
---|
| 658 | else if (ok && (strcmp(str, "CX__") == 0)) { vseg[vseg_index]->mode = 0xC; } |
---|
| 659 | else if (ok && (strcmp(str, "C_WU") == 0)) { vseg[vseg_index]->mode = 0xB; } |
---|
| 660 | else if (ok && (strcmp(str, "C_W_") == 0)) { vseg[vseg_index]->mode = 0xA; } |
---|
| 661 | else if (ok && (strcmp(str, "C__U") == 0)) { vseg[vseg_index]->mode = 0x9; } |
---|
| 662 | else if (ok && (strcmp(str, "C___") == 0)) { vseg[vseg_index]->mode = 0x8; } |
---|
| 663 | else if (ok && (strcmp(str, "_XWU") == 0)) { vseg[vseg_index]->mode = 0x7; } |
---|
| 664 | else if (ok && (strcmp(str, "_XW_") == 0)) { vseg[vseg_index]->mode = 0x6; } |
---|
| 665 | else if (ok && (strcmp(str, "_X_U") == 0)) { vseg[vseg_index]->mode = 0x5; } |
---|
| 666 | else if (ok && (strcmp(str, "_X__") == 0)) { vseg[vseg_index]->mode = 0x4; } |
---|
| 667 | else if (ok && (strcmp(str, "__WU") == 0)) { vseg[vseg_index]->mode = 0x3; } |
---|
| 668 | else if (ok && (strcmp(str, "__W_") == 0)) { vseg[vseg_index]->mode = 0x2; } |
---|
| 669 | else if (ok && (strcmp(str, "___U") == 0)) { vseg[vseg_index]->mode = 0x1; } |
---|
| 670 | else if (ok && (strcmp(str, "____") == 0)) { vseg[vseg_index]->mode = 0x0; } |
---|
| 671 | else { |
---|
| 672 | printf("[XML ERROR] illegal or missing <mode> attribute for vseg (%d,%d)\n", |
---|
| 673 | vspace_index, vseg_loc_index); |
---|
| 674 | exit(1); |
---|
| 675 | } |
---|
| 676 | |
---|
[511] | 677 | ////////// get binpath attribute (optional : "" if missing) |
---|
| 678 | str = getStringValue(reader, "binpath", &ok); |
---|
| 679 | if (ok) |
---|
[258] | 680 | { |
---|
[511] | 681 | #if XML_PARSER_DEBUG |
---|
| 682 | printf(" binpath = %s\n", str); |
---|
| 683 | #endif |
---|
| 684 | strncpy(vseg[vseg_index]->binpath, str, 63); |
---|
| 685 | } |
---|
| 686 | else |
---|
| 687 | { |
---|
| 688 | vseg[vseg_index]->binpath[0] = 0; |
---|
| 689 | } |
---|
[258] | 690 | |
---|
[511] | 691 | vseg_index++; |
---|
| 692 | vseg_loc_index++; |
---|
[258] | 693 | } // end vsegNode() |
---|
| 694 | |
---|
| 695 | //////////////////////////////////////// |
---|
| 696 | void vspaceNode(xmlTextReaderPtr reader) |
---|
| 697 | { |
---|
| 698 | unsigned int ok; |
---|
| 699 | |
---|
| 700 | vseg_loc_index = 0; |
---|
| 701 | task_loc_index = 0; |
---|
| 702 | |
---|
| 703 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
| 704 | |
---|
| 705 | vspace[vspace_index] = (mapping_vspace_t *) malloc(sizeof(mapping_vspace_t)); |
---|
[295] | 706 | header->vspaces = header->vspaces + 1; |
---|
[258] | 707 | |
---|
| 708 | ////////// get name attribute |
---|
[511] | 709 | char* vspace_name = getStringValue(reader, "name", &ok); |
---|
| 710 | if (ok) |
---|
| 711 | { |
---|
[258] | 712 | #if XML_PARSER_DEBUG |
---|
[511] | 713 | printf("\n vspace = %s\n", vspace_name ); |
---|
[258] | 714 | #endif |
---|
[511] | 715 | strncpy( vspace[vspace_index]->name, vspace_name , 31 ); |
---|
[258] | 716 | } |
---|
| 717 | else |
---|
| 718 | { |
---|
| 719 | printf("[XML ERROR] illegal or missing <name> attribute for vspace %d\n", |
---|
| 720 | vspace_index); |
---|
| 721 | exit(1); |
---|
| 722 | } |
---|
| 723 | |
---|
[645] | 724 | ////////// get active attribute (optional / default is 0) |
---|
| 725 | unsigned int value = getIntValue(reader, "active", &ok); |
---|
| 726 | if (ok) vspace[vspace_index]->active = value; |
---|
| 727 | else vspace[vspace_index]->active = 0; |
---|
| 728 | |
---|
[258] | 729 | ////////// set vseg_offset and task_offset attributes |
---|
| 730 | vspace[vspace_index]->vseg_offset = vseg_index; |
---|
| 731 | vspace[vspace_index]->task_offset = task_index; |
---|
| 732 | |
---|
[511] | 733 | ////////// initialise vsegs and tasks attributes |
---|
| 734 | vspace[vspace_index]->vsegs = 0; |
---|
| 735 | vspace[vspace_index]->tasks = 0; |
---|
[258] | 736 | |
---|
| 737 | ////////// get startname attribute |
---|
[511] | 738 | char* start_name = getStringValue(reader, "startname", &ok); |
---|
| 739 | if (ok == 0) |
---|
[323] | 740 | { |
---|
[258] | 741 | printf("[XML ERROR] illegal or missing <startname> attribute for vspace %s\n", |
---|
| 742 | vspace[vspace_index]->name); |
---|
| 743 | exit(1); |
---|
| 744 | } |
---|
| 745 | |
---|
| 746 | int status = xmlTextReaderRead(reader); |
---|
[295] | 747 | while (status == 1) |
---|
| 748 | { |
---|
[258] | 749 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
| 750 | |
---|
[263] | 751 | if (strcmp(tag, "vseg") == 0) |
---|
| 752 | { |
---|
[258] | 753 | vsegNode(reader); |
---|
[511] | 754 | vspace[vspace_index]->vsegs += 1; |
---|
[258] | 755 | } |
---|
[263] | 756 | else if (strcmp(tag, "task") == 0) |
---|
| 757 | { |
---|
[258] | 758 | taskNode(reader); |
---|
[511] | 759 | vspace[vspace_index]->tasks += 1; |
---|
[258] | 760 | } |
---|
| 761 | else if (strcmp(tag, "#text") == 0) { } |
---|
| 762 | else if (strcmp(tag, "#comment") == 0) { } |
---|
[295] | 763 | else if (strcmp(tag, "vspace") == 0) |
---|
| 764 | { |
---|
[511] | 765 | // get index of the vseg containing the start vector |
---|
| 766 | int index = getVsegId( vspace_index, start_name ); |
---|
[258] | 767 | if (index == -1) |
---|
| 768 | { |
---|
[511] | 769 | printf("[XML ERROR] vseg containing start vector not found in vspace %s\n", |
---|
[258] | 770 | vspace[vspace_index]->name); |
---|
| 771 | exit(1); |
---|
| 772 | } |
---|
| 773 | else |
---|
| 774 | { |
---|
[511] | 775 | vspace[vspace_index]->start_vseg_id = index; |
---|
| 776 | } |
---|
| 777 | |
---|
[258] | 778 | #if XML_PARSER_DEBUG |
---|
[511] | 779 | printf(" vsegs = %d\n", vspace[vspace_index]->vsegs ); |
---|
| 780 | printf(" tasks = %d\n", vspace[vspace_index]->tasks ); |
---|
| 781 | printf(" vseg_offset = %d\n", vspace[vspace_index]->vseg_offset ); |
---|
| 782 | printf(" task_offset = %d\n", vspace[vspace_index]->task_offset ); |
---|
[645] | 783 | printf(" start_id = %d\n", vspace[vspace_index]->start_vseg_id ); |
---|
| 784 | printf(" active = %x\n", vspace[vspace_index]->active ); |
---|
[511] | 785 | printf(" end vspace %d\n\n", vspace_index); |
---|
[258] | 786 | #endif |
---|
| 787 | vspace_index++; |
---|
| 788 | return; |
---|
| 789 | } |
---|
| 790 | else |
---|
| 791 | { |
---|
| 792 | printf("[XML ERROR] Unknown tag %s", tag); |
---|
| 793 | exit(1); |
---|
| 794 | } |
---|
| 795 | status = xmlTextReaderRead(reader); |
---|
| 796 | } |
---|
| 797 | } // end vspaceNode() |
---|
| 798 | |
---|
[295] | 799 | ///////////////////////////////////// |
---|
| 800 | void irqNode(xmlTextReaderPtr reader) |
---|
| 801 | { |
---|
| 802 | unsigned int ok; |
---|
| 803 | unsigned int value; |
---|
| 804 | char * str; |
---|
| 805 | |
---|
| 806 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
| 807 | |
---|
| 808 | if (irq_index >= MAX_IRQS) |
---|
| 809 | { |
---|
| 810 | printf("[XML ERROR] The number of irqs is larger than %d\n", MAX_IRQS); |
---|
| 811 | } |
---|
| 812 | |
---|
| 813 | #if XML_PARSER_DEBUG |
---|
| 814 | printf(" irq %d\n", irq_loc_index); |
---|
| 815 | #endif |
---|
| 816 | |
---|
| 817 | irq[irq_index] = (mapping_irq_t *) malloc(sizeof(mapping_irq_t)); |
---|
| 818 | |
---|
[306] | 819 | ///////// get srcid attribute |
---|
| 820 | value = getIntValue(reader, "srcid", &ok); |
---|
[295] | 821 | if (ok) |
---|
| 822 | { |
---|
| 823 | #if XML_PARSER_DEBUG |
---|
[306] | 824 | printf(" srcid = %d\n", value); |
---|
[295] | 825 | #endif |
---|
[306] | 826 | irq[irq_index]->srcid = value; |
---|
| 827 | if (value >= 32) |
---|
[295] | 828 | { |
---|
[306] | 829 | printf("[XML ERROR] IRQ <srcid> too large for periph %d in cluster %d\n", |
---|
[295] | 830 | cluster_index, periph_loc_index); |
---|
| 831 | exit(1); |
---|
| 832 | } |
---|
| 833 | } |
---|
| 834 | else |
---|
| 835 | { |
---|
[306] | 836 | printf("[XML ERROR] missing IRQ <srcid> for periph %d in cluster %d\n", |
---|
[295] | 837 | cluster_index, periph_loc_index); |
---|
| 838 | exit(1); |
---|
| 839 | } |
---|
| 840 | |
---|
[323] | 841 | ///////// get srctype attribute |
---|
| 842 | str = getStringValue(reader, "srctype", &ok); |
---|
| 843 | if (ok) |
---|
[295] | 844 | { |
---|
| 845 | #if XML_PARSER_DEBUG |
---|
[306] | 846 | printf(" srctype = %s\n", str); |
---|
[295] | 847 | #endif |
---|
[323] | 848 | if ( strcmp(str, "HWI") == 0 ) irq[irq_index]->srctype = IRQ_TYPE_HWI; |
---|
| 849 | else if ( strcmp(str, "WTI") == 0 ) irq[irq_index]->srctype = IRQ_TYPE_WTI; |
---|
| 850 | else if ( strcmp(str, "PTI") == 0 ) irq[irq_index]->srctype = IRQ_TYPE_PTI; |
---|
| 851 | else |
---|
[295] | 852 | { |
---|
[323] | 853 | printf("[XML ERROR] illegal IRQ <srctype> for periph %d in cluster %d\n", |
---|
[306] | 854 | cluster_index, periph_loc_index); |
---|
[295] | 855 | exit(1); |
---|
| 856 | } |
---|
| 857 | } |
---|
[323] | 858 | else |
---|
| 859 | { |
---|
| 860 | printf("[XML ERROR] missing IRQ <srctype> for periph %d in cluster %d\n", |
---|
| 861 | cluster_index, periph_loc_index); |
---|
| 862 | exit(1); |
---|
| 863 | } |
---|
[295] | 864 | |
---|
[323] | 865 | ///////// get isr attribute |
---|
| 866 | str = getStringValue(reader, "isr", &ok); |
---|
| 867 | if (ok) |
---|
[295] | 868 | { |
---|
| 869 | #if XML_PARSER_DEBUG |
---|
| 870 | printf(" isr = %s\n", str); |
---|
| 871 | #endif |
---|
[531] | 872 | if (strcmp(str, "ISR_DEFAULT") == 0) irq[irq_index]->isr = ISR_DEFAULT; |
---|
| 873 | else if (strcmp(str, "ISR_TICK" ) == 0) irq[irq_index]->isr = ISR_TICK; |
---|
[323] | 874 | else if (strcmp(str, "ISR_TTY_RX" ) == 0) irq[irq_index]->isr = ISR_TTY_RX; |
---|
| 875 | else if (strcmp(str, "ISR_TTY_TX" ) == 0) irq[irq_index]->isr = ISR_TTY_TX; |
---|
[531] | 876 | else if (strcmp(str, "ISR_BDV" ) == 0) irq[irq_index]->isr = ISR_BDV; |
---|
[323] | 877 | else if (strcmp(str, "ISR_TIMER" ) == 0) irq[irq_index]->isr = ISR_TIMER; |
---|
| 878 | else if (strcmp(str, "ISR_WAKUP" ) == 0) irq[irq_index]->isr = ISR_WAKUP; |
---|
| 879 | else if (strcmp(str, "ISR_NIC_RX" ) == 0) irq[irq_index]->isr = ISR_NIC_RX; |
---|
| 880 | else if (strcmp(str, "ISR_NIC_TX" ) == 0) irq[irq_index]->isr = ISR_NIC_TX; |
---|
[531] | 881 | else if (strcmp(str, "ISR_CMA" ) == 0) irq[irq_index]->isr = ISR_CMA; |
---|
[323] | 882 | else if (strcmp(str, "ISR_MMC" ) == 0) irq[irq_index]->isr = ISR_MMC; |
---|
| 883 | else if (strcmp(str, "ISR_DMA" ) == 0) irq[irq_index]->isr = ISR_DMA; |
---|
[548] | 884 | else if (strcmp(str, "ISR_SDC" ) == 0) irq[irq_index]->isr = ISR_SDC; |
---|
[531] | 885 | else if (strcmp(str, "ISR_MWR" ) == 0) irq[irq_index]->isr = ISR_MWR; |
---|
| 886 | else if (strcmp(str, "ISR_HBA" ) == 0) irq[irq_index]->isr = ISR_HBA; |
---|
[295] | 887 | else |
---|
| 888 | { |
---|
[323] | 889 | printf("[XML ERROR] illegal IRQ <isr> for periph %d in cluster %d\n", |
---|
| 890 | periph_loc_index, cluster_index ); |
---|
[295] | 891 | exit(1); |
---|
| 892 | } |
---|
[323] | 893 | } |
---|
| 894 | else |
---|
| 895 | { |
---|
| 896 | printf("[XML ERROR] missing IRQ <isr> for periph %d in cluster %d\n", |
---|
| 897 | cluster_index, periph_loc_index); |
---|
| 898 | exit(1); |
---|
[295] | 899 | } |
---|
| 900 | |
---|
| 901 | ///////// get channel attribute (optionnal : 0 if missing) |
---|
| 902 | value = getIntValue(reader, "channel", &ok); |
---|
| 903 | if (ok) |
---|
| 904 | { |
---|
| 905 | #if XML_PARSER_DEBUG |
---|
| 906 | printf(" channel = %d\n", value); |
---|
| 907 | #endif |
---|
| 908 | irq[irq_index]->channel = value; |
---|
| 909 | } |
---|
| 910 | else |
---|
| 911 | { |
---|
| 912 | irq[irq_index]->channel = 0; |
---|
| 913 | } |
---|
| 914 | |
---|
| 915 | irq_index++; |
---|
| 916 | irq_loc_index++; |
---|
| 917 | |
---|
| 918 | } // end irqNode |
---|
| 919 | |
---|
| 920 | |
---|
[258] | 921 | //////////////////////////////////////// |
---|
| 922 | void periphNode(xmlTextReaderPtr reader) |
---|
| 923 | { |
---|
| 924 | char * str; |
---|
| 925 | unsigned int value; |
---|
| 926 | unsigned int ok; |
---|
| 927 | |
---|
[295] | 928 | irq_loc_index = 0; |
---|
| 929 | |
---|
[258] | 930 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
| 931 | |
---|
| 932 | if (periph_index >= MAX_PERIPHS) |
---|
| 933 | { |
---|
| 934 | printf("[XML ERROR] The number of periphs is larger than %d\n", MAX_PERIPHS); |
---|
| 935 | exit(1); |
---|
| 936 | } |
---|
| 937 | |
---|
| 938 | #if XML_PARSER_DEBUG |
---|
[295] | 939 | printf("\n periph %d\n", periph_index); |
---|
[258] | 940 | #endif |
---|
| 941 | |
---|
| 942 | periph[periph_index] = (mapping_periph_t *) malloc(sizeof(mapping_periph_t)); |
---|
| 943 | |
---|
| 944 | ///////// get channels attribute (optionnal : 1 if missing) |
---|
| 945 | value = getIntValue(reader, "channels", &ok); |
---|
| 946 | if (ok) |
---|
| 947 | { |
---|
| 948 | #if XML_PARSER_DEBUG |
---|
[295] | 949 | printf(" channels = %d\n", value); |
---|
[258] | 950 | #endif |
---|
| 951 | periph[periph_index]->channels = value; |
---|
| 952 | } |
---|
| 953 | else |
---|
| 954 | { |
---|
| 955 | periph[periph_index]->channels = 1; |
---|
| 956 | } |
---|
| 957 | |
---|
[522] | 958 | ///////// get arg0 attribute (optionnal : undefined if missing) |
---|
| 959 | value = getIntValue(reader, "arg0", &ok); |
---|
[323] | 960 | if (ok) |
---|
| 961 | { |
---|
| 962 | #if XML_PARSER_DEBUG |
---|
[522] | 963 | printf(" arg0 = %d\n", value); |
---|
[323] | 964 | #endif |
---|
[522] | 965 | periph[periph_index]->arg0 = value; |
---|
[323] | 966 | } |
---|
[522] | 967 | |
---|
| 968 | ///////// get arg1 attribute (optionnal : undefined if missing) |
---|
| 969 | value = getIntValue(reader, "arg1", &ok); |
---|
| 970 | if (ok) |
---|
[323] | 971 | { |
---|
[522] | 972 | #if XML_PARSER_DEBUG |
---|
| 973 | printf(" arg1 = %d\n", value); |
---|
| 974 | #endif |
---|
| 975 | periph[periph_index]->arg1 = value; |
---|
[323] | 976 | } |
---|
| 977 | |
---|
[522] | 978 | ///////// get arg2 attribute (optionnal : undefined if missing) |
---|
| 979 | value = getIntValue(reader, "arg2", &ok); |
---|
| 980 | if (ok) |
---|
| 981 | { |
---|
| 982 | #if XML_PARSER_DEBUG |
---|
| 983 | printf(" arg2 = %d\n", value); |
---|
| 984 | #endif |
---|
| 985 | periph[periph_index]->arg2 = value; |
---|
| 986 | } |
---|
| 987 | |
---|
| 988 | ///////// get arg3 attribute (optionnal : undefined if missing) |
---|
| 989 | value = getIntValue(reader, "arg3", &ok); |
---|
| 990 | if (ok) |
---|
| 991 | { |
---|
| 992 | #if XML_PARSER_DEBUG |
---|
| 993 | printf(" arg3 = %d\n", value); |
---|
| 994 | #endif |
---|
| 995 | periph[periph_index]->arg3 = value; |
---|
| 996 | } |
---|
| 997 | |
---|
[258] | 998 | /////////// get psegname attribute |
---|
| 999 | str = getStringValue(reader, "psegname", &ok); |
---|
| 1000 | if (ok == 0) |
---|
| 1001 | { |
---|
[627] | 1002 | printf("[XML ERROR] illegal or missing <psegname> for periph %d in cluster %d\n", |
---|
| 1003 | periph_index, cluster_index); |
---|
[258] | 1004 | exit(1); |
---|
| 1005 | } |
---|
| 1006 | |
---|
| 1007 | /////////// set psegid attribute |
---|
[263] | 1008 | int index = getPsegId( cluster[cluster_index]->x, cluster[cluster_index]->y, str); |
---|
[258] | 1009 | if (index >= 0) |
---|
| 1010 | { |
---|
| 1011 | #if XML_PARSER_DEBUG |
---|
[295] | 1012 | printf(" clusterid = %d\n", cluster_index); |
---|
| 1013 | printf(" psegname = %s\n", str); |
---|
| 1014 | printf(" psegid = %d\n", index); |
---|
[258] | 1015 | #endif |
---|
| 1016 | periph[periph_index]->psegid = index; |
---|
| 1017 | } |
---|
| 1018 | else |
---|
| 1019 | { |
---|
| 1020 | printf("[XML ERROR] pseg not found for periph %d / clusterid = %d / psegname = %s\n", |
---|
| 1021 | periph_loc_index, cluster_index, str ); |
---|
| 1022 | exit(1); |
---|
| 1023 | } |
---|
| 1024 | |
---|
| 1025 | /////////// get type attribute |
---|
| 1026 | str = getStringValue(reader, "type", &ok); |
---|
| 1027 | if (ok) |
---|
| 1028 | { |
---|
| 1029 | #if XML_PARSER_DEBUG |
---|
[295] | 1030 | printf(" type = %s\n", str); |
---|
[258] | 1031 | #endif |
---|
[511] | 1032 | if (strcmp(str, "CMA" ) == 0) periph[periph_index]->type = PERIPH_TYPE_CMA; |
---|
[522] | 1033 | else if (strcmp(str, "DMA" ) == 0) periph[periph_index]->type = PERIPH_TYPE_DMA; |
---|
[511] | 1034 | else if (strcmp(str, "FBF" ) == 0) periph[periph_index]->type = PERIPH_TYPE_FBF; |
---|
| 1035 | else if (strcmp(str, "IOB" ) == 0) periph[periph_index]->type = PERIPH_TYPE_IOB; |
---|
| 1036 | else if (strcmp(str, "IOC" ) == 0) periph[periph_index]->type = PERIPH_TYPE_IOC; |
---|
[522] | 1037 | else if (strcmp(str, "MMC" ) == 0) periph[periph_index]->type = PERIPH_TYPE_MMC; |
---|
| 1038 | else if (strcmp(str, "MWR" ) == 0) periph[periph_index]->type = PERIPH_TYPE_MWR; |
---|
[511] | 1039 | else if (strcmp(str, "NIC" ) == 0) periph[periph_index]->type = PERIPH_TYPE_NIC; |
---|
| 1040 | else if (strcmp(str, "ROM" ) == 0) periph[periph_index]->type = PERIPH_TYPE_ROM; |
---|
| 1041 | else if (strcmp(str, "SIM" ) == 0) periph[periph_index]->type = PERIPH_TYPE_SIM; |
---|
[522] | 1042 | else if (strcmp(str, "SIM" ) == 0) periph[periph_index]->type = PERIPH_TYPE_TIM; |
---|
[511] | 1043 | else if (strcmp(str, "TTY" ) == 0) periph[periph_index]->type = PERIPH_TYPE_TTY; |
---|
[522] | 1044 | else if (strcmp(str, "XCU" ) == 0) periph[periph_index]->type = PERIPH_TYPE_XCU; |
---|
[511] | 1045 | else if (strcmp(str, "PIC" ) == 0) periph[periph_index]->type = PERIPH_TYPE_PIC; |
---|
| 1046 | else if (strcmp(str, "DROM") == 0) periph[periph_index]->type = PERIPH_TYPE_DROM; |
---|
[491] | 1047 | else |
---|
| 1048 | { |
---|
[295] | 1049 | printf("[XML ERROR] illegal peripheral type: %s in cluster %d\n", |
---|
| 1050 | str, cluster_index); |
---|
[258] | 1051 | exit(1); |
---|
| 1052 | } |
---|
[511] | 1053 | } |
---|
[258] | 1054 | |
---|
[511] | 1055 | ////////// get subtype if IOC |
---|
| 1056 | if (periph[periph_index]->type == PERIPH_TYPE_IOC ) |
---|
| 1057 | { |
---|
| 1058 | char* subtype = getStringValue(reader, "subtype", &ok); |
---|
| 1059 | if (ok) |
---|
[258] | 1060 | { |
---|
[511] | 1061 | #if XML_PARSER_DEBUG |
---|
| 1062 | printf(" subtype = %s\n", str); |
---|
| 1063 | #endif |
---|
| 1064 | if (strcmp(subtype, "BDV") == 0) |
---|
[522] | 1065 | periph[periph_index]->subtype = IOC_SUBTYPE_BDV; |
---|
[511] | 1066 | else if (strcmp(subtype, "HBA") == 0) |
---|
[522] | 1067 | periph[periph_index]->subtype = IOC_SUBTYPE_HBA; |
---|
[548] | 1068 | else if (strcmp(subtype, "SDC") == 0) |
---|
| 1069 | periph[periph_index]->subtype = IOC_SUBTYPE_SDC; |
---|
[567] | 1070 | else if (strcmp(subtype, "SPI") == 0) |
---|
| 1071 | periph[periph_index]->subtype = IOC_SUBTYPE_SPI; |
---|
[511] | 1072 | } |
---|
| 1073 | else |
---|
| 1074 | { |
---|
| 1075 | printf("[XML ERROR] illegal subtype for IOC peripheral\n"); |
---|
[258] | 1076 | exit(1); |
---|
| 1077 | } |
---|
| 1078 | } |
---|
[511] | 1079 | else |
---|
[258] | 1080 | { |
---|
[511] | 1081 | periph[periph_index]->subtype = 0XFFFFFFFF; |
---|
[258] | 1082 | } |
---|
| 1083 | |
---|
[522] | 1084 | ////////// get subtype if MWR |
---|
| 1085 | if (periph[periph_index]->type == PERIPH_TYPE_MWR ) |
---|
| 1086 | { |
---|
| 1087 | char* subtype = getStringValue(reader, "subtype", &ok); |
---|
| 1088 | if (ok) |
---|
| 1089 | { |
---|
| 1090 | #if XML_PARSER_DEBUG |
---|
| 1091 | printf(" subtype = %s\n", str); |
---|
| 1092 | #endif |
---|
| 1093 | if (strcmp(subtype, "GCD") == 0) |
---|
| 1094 | periph[periph_index]->subtype = MWR_SUBTYPE_GCD; |
---|
| 1095 | else if (strcmp(subtype, "DCT") == 0) |
---|
| 1096 | periph[periph_index]->subtype = MWR_SUBTYPE_DCT; |
---|
[559] | 1097 | else if (strcmp(subtype, "CPY") == 0) |
---|
| 1098 | periph[periph_index]->subtype = MWR_SUBTYPE_CPY; |
---|
[522] | 1099 | } |
---|
| 1100 | else |
---|
| 1101 | { |
---|
| 1102 | printf("[XML ERROR] illegal subtype for MWR peripheral\n"); |
---|
| 1103 | exit(1); |
---|
| 1104 | } |
---|
| 1105 | } |
---|
| 1106 | else |
---|
| 1107 | { |
---|
| 1108 | periph[periph_index]->subtype = 0XFFFFFFFF; |
---|
| 1109 | } |
---|
| 1110 | |
---|
[295] | 1111 | ////////////// set irq_offset attribute |
---|
| 1112 | periph[periph_index]->irq_offset = irq_index; |
---|
[258] | 1113 | |
---|
[295] | 1114 | ///////////// get IRQs |
---|
| 1115 | int status = xmlTextReaderRead(reader); |
---|
| 1116 | while (status == 1) |
---|
| 1117 | { |
---|
| 1118 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
| 1119 | |
---|
| 1120 | if (strcmp(tag, "irq") == 0) |
---|
| 1121 | { |
---|
[472] | 1122 | if ( (periph[periph_index]->type != PERIPH_TYPE_XCU) && |
---|
[295] | 1123 | (periph[periph_index]->type != PERIPH_TYPE_PIC) ) |
---|
| 1124 | { |
---|
| 1125 | printf("[XML ERROR] periph %d in cluster(%d,%d) " |
---|
[472] | 1126 | " only XCU and PIC can contain IRQs", |
---|
[295] | 1127 | periph_loc_index, cluster[cluster_index]->x, cluster[cluster_index]->y); |
---|
| 1128 | exit(1); |
---|
| 1129 | } |
---|
| 1130 | else |
---|
| 1131 | { |
---|
| 1132 | irqNode(reader); |
---|
| 1133 | } |
---|
| 1134 | } |
---|
| 1135 | else if (strcmp(tag, "#text") == 0) { } |
---|
| 1136 | else if (strcmp(tag, "#comment") == 0) { } |
---|
| 1137 | else if (strcmp(tag, "periph") == 0) |
---|
| 1138 | { |
---|
| 1139 | periph[periph_index]->irqs = irq_loc_index; |
---|
| 1140 | cluster[cluster_index]->periphs++; |
---|
| 1141 | periph_loc_index++; |
---|
| 1142 | periph_index++; |
---|
| 1143 | |
---|
| 1144 | #if XML_PARSER_DEBUG |
---|
| 1145 | printf(" irqs = %d\n", irq_loc_index); |
---|
| 1146 | printf(" irq_offset = %d\n", irq_index); |
---|
| 1147 | #endif |
---|
| 1148 | return; |
---|
| 1149 | } |
---|
| 1150 | else |
---|
| 1151 | { |
---|
| 1152 | printf("[XML ERROR] Unknown tag %s", tag); |
---|
| 1153 | exit(1); |
---|
| 1154 | } |
---|
| 1155 | status = xmlTextReaderRead(reader); |
---|
| 1156 | } |
---|
[258] | 1157 | } // end periphNode |
---|
| 1158 | |
---|
| 1159 | ////////////////////////////////////// |
---|
| 1160 | void procNode(xmlTextReaderPtr reader) |
---|
| 1161 | { |
---|
| 1162 | unsigned int ok; |
---|
| 1163 | unsigned int value; |
---|
| 1164 | |
---|
| 1165 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
| 1166 | |
---|
| 1167 | if (proc_index >= MAX_PROCS) |
---|
| 1168 | { |
---|
| 1169 | printf("[XML ERROR] The number of procs is larger than %d\n", MAX_PROCS); |
---|
| 1170 | exit(1); |
---|
| 1171 | } |
---|
| 1172 | |
---|
| 1173 | #if XML_PARSER_DEBUG |
---|
[295] | 1174 | printf("\n proc %d\n", proc_index); |
---|
[258] | 1175 | #endif |
---|
| 1176 | |
---|
| 1177 | proc[proc_index] = (mapping_proc_t *) malloc(sizeof(mapping_proc_t)); |
---|
| 1178 | |
---|
| 1179 | /////////// get index attribute (optional) |
---|
| 1180 | value = getIntValue(reader, "index", &ok); |
---|
| 1181 | if (ok && (value != proc_loc_index)) |
---|
| 1182 | { |
---|
[306] | 1183 | printf("[XML ERROR] wrong local proc index / expected value is %d", |
---|
[258] | 1184 | proc_loc_index); |
---|
| 1185 | exit(1); |
---|
| 1186 | } |
---|
[295] | 1187 | proc[proc_index]->index = proc_loc_index; |
---|
[258] | 1188 | |
---|
[295] | 1189 | cluster[cluster_index]->procs++; |
---|
| 1190 | proc_loc_index++; |
---|
| 1191 | proc_index++; |
---|
[258] | 1192 | } // end procNode() |
---|
| 1193 | |
---|
| 1194 | |
---|
| 1195 | ////////////////////////////////////// |
---|
| 1196 | void psegNode(xmlTextReaderPtr reader) |
---|
| 1197 | { |
---|
| 1198 | unsigned int ok; |
---|
| 1199 | paddr_t ll_value; |
---|
| 1200 | char * str; |
---|
| 1201 | |
---|
| 1202 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
| 1203 | |
---|
| 1204 | if (pseg_index >= MAX_PSEGS) |
---|
| 1205 | { |
---|
| 1206 | printf("[XML ERROR] The number of psegs is larger than %d\n", MAX_PSEGS); |
---|
| 1207 | exit(1); |
---|
| 1208 | } |
---|
| 1209 | |
---|
| 1210 | #if XML_PARSER_DEBUG |
---|
[295] | 1211 | printf(" pseg %d\n", pseg_index); |
---|
[258] | 1212 | #endif |
---|
| 1213 | |
---|
| 1214 | pseg[pseg_index] = (mapping_pseg_t *) malloc(sizeof(mapping_pseg_t)); |
---|
| 1215 | |
---|
| 1216 | /////// get name attribute |
---|
| 1217 | str = getStringValue(reader, "name", &ok); |
---|
| 1218 | #if XML_PARSER_DEBUG |
---|
[295] | 1219 | printf(" name = %s\n", str); |
---|
[258] | 1220 | #endif |
---|
| 1221 | if (ok) |
---|
| 1222 | { |
---|
| 1223 | strncpy(pseg[pseg_index]->name, str, 31); |
---|
| 1224 | } |
---|
| 1225 | else |
---|
| 1226 | { |
---|
| 1227 | printf("[XML ERROR] illegal or missing <name> for pseg %d in cluster %d\n", |
---|
| 1228 | pseg_index, cluster_index); |
---|
| 1229 | exit(1); |
---|
| 1230 | } |
---|
| 1231 | |
---|
| 1232 | //////// get type attribute |
---|
| 1233 | str = getStringValue(reader, "type", &ok); |
---|
| 1234 | #if XML_PARSER_DEBUG |
---|
[295] | 1235 | printf(" type = %s\n", str); |
---|
[258] | 1236 | #endif |
---|
| 1237 | if (ok && (strcmp(str, "RAM" ) == 0)) { pseg[pseg_index]->type = PSEG_TYPE_RAM; } |
---|
| 1238 | else if (ok && (strcmp(str, "PERI") == 0)) { pseg[pseg_index]->type = PSEG_TYPE_PERI; } |
---|
| 1239 | else |
---|
| 1240 | { |
---|
| 1241 | printf("[XML ERROR] illegal or missing <type> for pseg %s in cluster %d\n", |
---|
| 1242 | pseg[pseg_index]->name, cluster_index); |
---|
| 1243 | exit(1); |
---|
| 1244 | } |
---|
| 1245 | |
---|
| 1246 | //////// get base attribute |
---|
| 1247 | ll_value = getPaddrValue(reader, "base", &ok); |
---|
| 1248 | #if XML_PARSER_DEBUG |
---|
[295] | 1249 | printf(" base = 0x%llx\n", ll_value); |
---|
[258] | 1250 | #endif |
---|
| 1251 | if (ok) |
---|
| 1252 | { |
---|
| 1253 | pseg[pseg_index]->base = ll_value; |
---|
| 1254 | } |
---|
| 1255 | else { |
---|
| 1256 | printf("[XML ERROR] illegal or missing <base> for pseg %s in cluster %d\n", |
---|
| 1257 | pseg[pseg_index]->name, cluster_index); |
---|
| 1258 | exit(1); |
---|
| 1259 | } |
---|
| 1260 | |
---|
| 1261 | //////// get length attribute |
---|
| 1262 | ll_value = getPaddrValue(reader, "length", &ok); |
---|
| 1263 | #if XML_PARSER_DEBUG |
---|
[295] | 1264 | printf(" length = 0x%llx\n", ll_value); |
---|
[258] | 1265 | #endif |
---|
| 1266 | if (ok) |
---|
| 1267 | { |
---|
| 1268 | pseg[pseg_index]->length = ll_value; |
---|
| 1269 | } |
---|
| 1270 | else |
---|
| 1271 | { |
---|
| 1272 | printf("[XML ERROR] illegal or missing <length> for pseg %s in cluster %d\n", |
---|
| 1273 | pseg[pseg_index]->name, cluster_index); |
---|
| 1274 | exit(1); |
---|
| 1275 | } |
---|
| 1276 | |
---|
| 1277 | //////// set cluster attribute |
---|
[263] | 1278 | pseg[pseg_index]->clusterid = cluster_index; |
---|
[258] | 1279 | |
---|
| 1280 | //////// set next_vseg attribute |
---|
| 1281 | pseg[pseg_index]->next_vseg = 0; |
---|
| 1282 | |
---|
| 1283 | pseg_index++; |
---|
| 1284 | cluster[cluster_index]->psegs++; |
---|
| 1285 | } // end psegNode() |
---|
| 1286 | |
---|
| 1287 | |
---|
| 1288 | ///////////////////////////////////////// |
---|
| 1289 | void clusterNode(xmlTextReaderPtr reader) |
---|
| 1290 | { |
---|
| 1291 | unsigned int ok; |
---|
| 1292 | unsigned int value; |
---|
| 1293 | |
---|
| 1294 | cluster[cluster_index] = (mapping_cluster_t *) malloc(sizeof(mapping_cluster_t)); |
---|
| 1295 | |
---|
[263] | 1296 | //initialise variables that will be incremented by *Node() functions |
---|
[258] | 1297 | cluster[cluster_index]->psegs = 0; |
---|
| 1298 | cluster[cluster_index]->procs = 0; |
---|
| 1299 | cluster[cluster_index]->periphs = 0; |
---|
| 1300 | |
---|
| 1301 | //initialise global variables |
---|
| 1302 | proc_loc_index = 0; |
---|
| 1303 | periph_loc_index = 0; |
---|
| 1304 | |
---|
[295] | 1305 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
[258] | 1306 | |
---|
[263] | 1307 | #if XML_PARSER_DEBUG |
---|
| 1308 | printf("\n cluster %d\n", cluster_index); |
---|
| 1309 | #endif |
---|
| 1310 | |
---|
| 1311 | /////////// get x coordinate |
---|
| 1312 | value = getIntValue(reader, "x", &ok); |
---|
| 1313 | #if XML_PARSER_DEBUG |
---|
| 1314 | printf(" x = %d\n", value); |
---|
| 1315 | #endif |
---|
| 1316 | if (ok && (value < header->x_size) ) |
---|
[258] | 1317 | { |
---|
[263] | 1318 | cluster[cluster_index]->x = value; |
---|
| 1319 | } |
---|
| 1320 | else |
---|
| 1321 | { |
---|
| 1322 | printf("[XML ERROR] Illegal or missing < x > attribute for cluster %d", |
---|
| 1323 | cluster_index); |
---|
[258] | 1324 | exit(1); |
---|
| 1325 | } |
---|
| 1326 | |
---|
[263] | 1327 | /////////// get y coordinate |
---|
| 1328 | value = getIntValue(reader, "y", &ok); |
---|
[258] | 1329 | #if XML_PARSER_DEBUG |
---|
[263] | 1330 | printf(" y = %d\n", value); |
---|
[258] | 1331 | #endif |
---|
[263] | 1332 | if (ok && (value < header->y_size) ) |
---|
[258] | 1333 | { |
---|
[263] | 1334 | cluster[cluster_index]->y = value; |
---|
| 1335 | } |
---|
| 1336 | else |
---|
| 1337 | { |
---|
| 1338 | printf("[XML ERROR] Illegal or missing < y > attribute for cluster %d", |
---|
[258] | 1339 | cluster_index); |
---|
| 1340 | exit(1); |
---|
| 1341 | } |
---|
| 1342 | |
---|
| 1343 | ////////// set offsets |
---|
| 1344 | cluster[cluster_index]->pseg_offset = pseg_index; |
---|
| 1345 | cluster[cluster_index]->proc_offset = proc_index; |
---|
| 1346 | cluster[cluster_index]->periph_offset = periph_index; |
---|
| 1347 | |
---|
| 1348 | #if XML_PARSER_DEBUG |
---|
[263] | 1349 | printf(" pseg_offset = %d\n", pseg_index); |
---|
| 1350 | printf(" proc_offset = %d\n", proc_index); |
---|
[627] | 1351 | printf(" periph_offset = %d\n", periph_index); |
---|
[258] | 1352 | #endif |
---|
| 1353 | |
---|
[627] | 1354 | ////////// get psegs, procs, and periphs |
---|
[258] | 1355 | int status = xmlTextReaderRead(reader); |
---|
| 1356 | |
---|
| 1357 | while (status == 1) |
---|
| 1358 | { |
---|
| 1359 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
| 1360 | |
---|
| 1361 | if (strcmp(tag, "pseg") == 0) psegNode(reader); |
---|
| 1362 | else if (strcmp(tag, "proc") == 0) procNode(reader); |
---|
| 1363 | else if (strcmp(tag, "periph") == 0) periphNode(reader); |
---|
| 1364 | else if (strcmp(tag, "#text") == 0) { } |
---|
| 1365 | else if (strcmp(tag, "#comment") == 0) { } |
---|
| 1366 | else if (strcmp(tag, "cluster") == 0) |
---|
| 1367 | { |
---|
[306] | 1368 | |
---|
[258] | 1369 | #if XML_PARSER_DEBUG |
---|
[263] | 1370 | printf(" psegs = %d\n", cluster[cluster_index]->psegs); |
---|
| 1371 | printf(" procs = %d\n", cluster[cluster_index]->procs); |
---|
| 1372 | printf(" periphs = %d\n", cluster[cluster_index]->periphs); |
---|
| 1373 | printf(" end cluster %d\n", cluster_index); |
---|
[258] | 1374 | #endif |
---|
| 1375 | cluster_index++; |
---|
| 1376 | return; |
---|
| 1377 | } |
---|
| 1378 | status = xmlTextReaderRead(reader); |
---|
| 1379 | } |
---|
| 1380 | } // end clusterNode() |
---|
| 1381 | |
---|
| 1382 | |
---|
| 1383 | ////////////////////////////////////////////// |
---|
| 1384 | void clusterSetNode(xmlTextReaderPtr reader) |
---|
| 1385 | { |
---|
| 1386 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
| 1387 | |
---|
| 1388 | #if XML_PARSER_DEBUG |
---|
[263] | 1389 | printf("\n clusters set\n"); |
---|
[258] | 1390 | #endif |
---|
| 1391 | |
---|
| 1392 | int status = xmlTextReaderRead(reader); |
---|
| 1393 | while (status == 1) |
---|
| 1394 | { |
---|
| 1395 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
| 1396 | |
---|
| 1397 | if (strcmp(tag, "cluster") == 0) { clusterNode(reader); } |
---|
| 1398 | else if (strcmp(tag, "#text") == 0) { } |
---|
| 1399 | else if (strcmp(tag, "#comment") == 0) { } |
---|
| 1400 | else if (strcmp(tag, "clusterset") == 0) |
---|
| 1401 | { |
---|
[295] | 1402 | // checking number of clusters |
---|
[263] | 1403 | if ( cluster_index != (header->x_size * header->y_size) ) |
---|
[258] | 1404 | { |
---|
| 1405 | printf("[XML ERROR] Wrong number of clusters\n"); |
---|
| 1406 | exit(1); |
---|
| 1407 | } |
---|
| 1408 | |
---|
| 1409 | #if XML_PARSER_DEBUG |
---|
| 1410 | printf(" end cluster set\n\n"); |
---|
| 1411 | #endif |
---|
[627] | 1412 | header->psegs = pseg_index; |
---|
| 1413 | header->procs = proc_index; |
---|
| 1414 | header->irqs = irq_index; |
---|
[258] | 1415 | header->periphs = periph_index; |
---|
| 1416 | return; |
---|
| 1417 | } |
---|
| 1418 | else |
---|
| 1419 | { |
---|
| 1420 | printf("[XML ERROR] Unknown tag in clusterset node : %s",tag); |
---|
| 1421 | exit(1); |
---|
| 1422 | } |
---|
| 1423 | status = xmlTextReaderRead(reader); |
---|
| 1424 | } |
---|
| 1425 | } // end clusterSetNode() |
---|
| 1426 | |
---|
| 1427 | |
---|
| 1428 | /////////////////////////////////////////// |
---|
| 1429 | void globalSetNode(xmlTextReaderPtr reader) |
---|
| 1430 | { |
---|
| 1431 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
| 1432 | |
---|
| 1433 | #if XML_PARSER_DEBUG |
---|
| 1434 | printf(" globals set\n"); |
---|
| 1435 | #endif |
---|
| 1436 | |
---|
| 1437 | int status = xmlTextReaderRead(reader); |
---|
| 1438 | while (status == 1) |
---|
| 1439 | { |
---|
| 1440 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
| 1441 | |
---|
[295] | 1442 | if (strcmp(tag, "vseg") == 0) |
---|
| 1443 | { |
---|
| 1444 | vsegNode( reader ); |
---|
| 1445 | header->globals = header->globals + 1; |
---|
| 1446 | } |
---|
[258] | 1447 | else if (strcmp(tag, "#text") == 0) { } |
---|
| 1448 | else if (strcmp(tag, "#comment") == 0) { } |
---|
| 1449 | else if (strcmp(tag, "globalset") == 0) |
---|
| 1450 | { |
---|
| 1451 | #if XML_PARSER_DEBUG |
---|
| 1452 | printf(" end global set\n\n"); |
---|
| 1453 | #endif |
---|
| 1454 | vseg_loc_index = 0; |
---|
| 1455 | return; |
---|
| 1456 | } |
---|
| 1457 | else |
---|
| 1458 | { |
---|
| 1459 | printf("[XML ERROR] Unknown tag in globalset node : %s",tag); |
---|
| 1460 | exit(1); |
---|
| 1461 | } |
---|
| 1462 | status = xmlTextReaderRead(reader); |
---|
| 1463 | } |
---|
| 1464 | } // end globalSetNode() |
---|
| 1465 | |
---|
| 1466 | |
---|
| 1467 | /////////////////////////////////////////// |
---|
| 1468 | void vspaceSetNode(xmlTextReaderPtr reader) |
---|
| 1469 | { |
---|
| 1470 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { |
---|
| 1471 | return; |
---|
| 1472 | } |
---|
| 1473 | |
---|
| 1474 | #if XML_PARSER_DEBUG |
---|
| 1475 | printf("\n vspaces set\n"); |
---|
| 1476 | #endif |
---|
| 1477 | |
---|
| 1478 | int status = xmlTextReaderRead ( reader ); |
---|
| 1479 | while (status == 1) { |
---|
| 1480 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
| 1481 | |
---|
| 1482 | if (strcmp(tag, "vspace") == 0) { |
---|
| 1483 | vspaceNode(reader); |
---|
| 1484 | } |
---|
| 1485 | else if (strcmp(tag, "#text" ) == 0 ) { } |
---|
| 1486 | else if (strcmp(tag, "#comment" ) == 0 ) { } |
---|
| 1487 | else if (strcmp(tag, "vspaceset") == 0 ) |
---|
| 1488 | { |
---|
[295] | 1489 | header->vsegs = vseg_index; |
---|
| 1490 | header->tasks = task_index; |
---|
| 1491 | return; |
---|
[258] | 1492 | } |
---|
| 1493 | else |
---|
| 1494 | { |
---|
| 1495 | printf("[XML ERROR] Unknown tag in vspaceset node : %s",tag); |
---|
| 1496 | exit(1); |
---|
| 1497 | } |
---|
| 1498 | status = xmlTextReaderRead(reader); |
---|
| 1499 | } |
---|
| 1500 | } // end globalSetNode() |
---|
| 1501 | |
---|
| 1502 | |
---|
| 1503 | //////////////////////////////////////// |
---|
| 1504 | void headerNode(xmlTextReaderPtr reader) |
---|
| 1505 | { |
---|
| 1506 | char * name; |
---|
| 1507 | unsigned int value; |
---|
| 1508 | unsigned int ok; |
---|
| 1509 | |
---|
| 1510 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
| 1511 | |
---|
| 1512 | #if XML_PARSER_DEBUG |
---|
| 1513 | printf("mapping_info\n"); |
---|
| 1514 | #endif |
---|
| 1515 | |
---|
| 1516 | header = (mapping_header_t *) malloc(sizeof(mapping_header_t)); |
---|
| 1517 | |
---|
| 1518 | ////////// get name attribute |
---|
| 1519 | name = getStringValue(reader, "name", &ok); |
---|
| 1520 | if (ok) |
---|
| 1521 | { |
---|
| 1522 | #if XML_PARSER_DEBUG |
---|
| 1523 | printf(" name = %s\n", name); |
---|
| 1524 | #endif |
---|
| 1525 | strncpy( header->name, name, 31); |
---|
| 1526 | } |
---|
| 1527 | else |
---|
| 1528 | { |
---|
| 1529 | printf("[XML ERROR] illegal or missing <name> attribute in header\n"); |
---|
| 1530 | exit(1); |
---|
| 1531 | } |
---|
| 1532 | |
---|
[296] | 1533 | /////////// get signature attribute |
---|
| 1534 | value = getIntValue(reader, "signature", &ok); |
---|
| 1535 | if ( ok && (value == IN_MAPPING_SIGNATURE) ) |
---|
| 1536 | { |
---|
| 1537 | #if XML_PARSER_DEBUG |
---|
| 1538 | printf(" signature = %x\n", value); |
---|
| 1539 | #endif |
---|
| 1540 | header->signature = IN_MAPPING_SIGNATURE; |
---|
| 1541 | } |
---|
| 1542 | else |
---|
| 1543 | { |
---|
| 1544 | printf("[XML ERROR] illegal or missing <signature> for mapping %s\n", |
---|
| 1545 | header->name ); |
---|
| 1546 | exit(1); |
---|
| 1547 | } |
---|
| 1548 | |
---|
[263] | 1549 | /////////// get x_width attribute |
---|
| 1550 | value = getIntValue(reader, "x_width", &ok); |
---|
[258] | 1551 | if (ok) |
---|
| 1552 | { |
---|
| 1553 | #if XML_PARSER_DEBUG |
---|
[263] | 1554 | printf(" x_width = %d\n", value); |
---|
[258] | 1555 | #endif |
---|
[263] | 1556 | header->x_width = value; |
---|
[258] | 1557 | } |
---|
[263] | 1558 | |
---|
| 1559 | /////////// get y_width attribute |
---|
| 1560 | value = getIntValue(reader, "y_width", &ok); |
---|
| 1561 | if (ok) |
---|
| 1562 | { |
---|
| 1563 | #if XML_PARSER_DEBUG |
---|
| 1564 | printf(" y_width = %d\n", value); |
---|
| 1565 | #endif |
---|
| 1566 | header->y_width = value; |
---|
| 1567 | } |
---|
| 1568 | |
---|
| 1569 | /////////// get x_size attribute |
---|
| 1570 | unsigned int x_size = getIntValue(reader, "x_size", &ok); |
---|
| 1571 | if (ok) |
---|
| 1572 | { |
---|
| 1573 | #if XML_PARSER_DEBUG |
---|
| 1574 | printf(" x_size = %d\n", x_size); |
---|
| 1575 | #endif |
---|
| 1576 | header->x_size = x_size; |
---|
| 1577 | } |
---|
[258] | 1578 | else |
---|
| 1579 | { |
---|
[263] | 1580 | printf("[XML ERROR] illegal or missing <x_size> attribute in header\n"); |
---|
[258] | 1581 | exit(1); |
---|
| 1582 | } |
---|
| 1583 | |
---|
[263] | 1584 | /////////// get y_size attribute |
---|
| 1585 | unsigned int y_size = getIntValue(reader, "y_size", &ok); |
---|
[258] | 1586 | if (ok) |
---|
| 1587 | { |
---|
| 1588 | #if XML_PARSER_DEBUG |
---|
[263] | 1589 | printf(" y_size = %d\n", y_size); |
---|
[258] | 1590 | #endif |
---|
[263] | 1591 | header->y_size = y_size; |
---|
[258] | 1592 | } |
---|
| 1593 | else |
---|
| 1594 | { |
---|
[263] | 1595 | printf("[XML ERROR] illegal or missing <y_size> attribute in header\n"); |
---|
[258] | 1596 | exit(1); |
---|
| 1597 | } |
---|
| 1598 | |
---|
[295] | 1599 | /////////// get x_io attribute |
---|
| 1600 | unsigned int x_io = getIntValue(reader, "x_io", &ok); |
---|
| 1601 | #if XML_PARSER_DEBUG |
---|
| 1602 | printf(" x_io = %d\n", x_io); |
---|
| 1603 | #endif |
---|
| 1604 | if ( ok && (x_io < x_size) ) |
---|
[258] | 1605 | { |
---|
[295] | 1606 | header->x_io = x_io; |
---|
| 1607 | } |
---|
| 1608 | else |
---|
| 1609 | { |
---|
| 1610 | printf("[XML ERROR] illegal or missing <x_io> attribute in header\n"); |
---|
[258] | 1611 | exit(1); |
---|
| 1612 | } |
---|
| 1613 | |
---|
[295] | 1614 | /////////// get y_io attribute |
---|
| 1615 | unsigned int y_io = getIntValue(reader, "y_io", &ok); |
---|
[258] | 1616 | #if XML_PARSER_DEBUG |
---|
[296] | 1617 | printf(" y_io = %d\n", y_io); |
---|
[258] | 1618 | #endif |
---|
[295] | 1619 | if ( ok &&(y_io < y_size) ) |
---|
| 1620 | { |
---|
| 1621 | header->y_io = y_io; |
---|
[258] | 1622 | } |
---|
| 1623 | else |
---|
| 1624 | { |
---|
[295] | 1625 | printf("[XML ERROR] illegal or missing <y_io> attribute in header\n"); |
---|
[258] | 1626 | exit(1); |
---|
| 1627 | } |
---|
| 1628 | |
---|
[295] | 1629 | // check the number of cluster |
---|
| 1630 | if ( (x_size * y_size) >= MAX_CLUSTERS ) |
---|
| 1631 | { |
---|
| 1632 | printf("[XML ERROR] Number of clusters cannot be larger than %d\n", MAX_CLUSTERS); |
---|
| 1633 | exit(1); |
---|
| 1634 | } |
---|
| 1635 | |
---|
| 1636 | ///////// get irq_per_proc attribute |
---|
| 1637 | value = getIntValue(reader, "irq_per_proc", &ok); |
---|
[258] | 1638 | if (ok) |
---|
| 1639 | { |
---|
| 1640 | #if XML_PARSER_DEBUG |
---|
[295] | 1641 | printf(" irq_per_proc = %d\n", value); |
---|
[258] | 1642 | #endif |
---|
[295] | 1643 | header->irq_per_proc = value; |
---|
[258] | 1644 | } |
---|
| 1645 | else |
---|
| 1646 | { |
---|
[295] | 1647 | printf("[XML ERROR] illegal or missing <irq_per_proc> attribute in mapping\n"); |
---|
[258] | 1648 | exit(1); |
---|
| 1649 | } |
---|
| 1650 | |
---|
[306] | 1651 | ///////// get use_ram_disk attribute (default = 0) |
---|
| 1652 | value = getIntValue(reader, "use_ram_disk", &ok); |
---|
[287] | 1653 | if (ok) |
---|
| 1654 | { |
---|
| 1655 | #if XML_PARSER_DEBUG |
---|
[306] | 1656 | printf(" use_ram_disk = %d\n", value); |
---|
[287] | 1657 | #endif |
---|
[306] | 1658 | header->use_ram_disk = value; |
---|
[287] | 1659 | } |
---|
| 1660 | else |
---|
| 1661 | { |
---|
[306] | 1662 | header->use_ram_disk = 0; |
---|
[287] | 1663 | } |
---|
| 1664 | |
---|
[295] | 1665 | ///////// set other header fields |
---|
| 1666 | header->globals = 0; |
---|
| 1667 | header->vspaces = 0; |
---|
| 1668 | header->psegs = 0; |
---|
| 1669 | header->vsegs = 0; |
---|
| 1670 | header->tasks = 0; |
---|
| 1671 | header->procs = 0; |
---|
| 1672 | header->irqs = 0; |
---|
| 1673 | header->periphs = 0; |
---|
[258] | 1674 | |
---|
| 1675 | int status = xmlTextReaderRead(reader); |
---|
| 1676 | while (status == 1) |
---|
| 1677 | { |
---|
| 1678 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
| 1679 | |
---|
[295] | 1680 | if (strcmp(tag, "clusterset") == 0) { clusterSetNode(reader); } |
---|
[258] | 1681 | else if (strcmp(tag, "globalset") == 0) { globalSetNode(reader); } |
---|
| 1682 | else if (strcmp(tag, "vspaceset") == 0) { vspaceSetNode(reader); } |
---|
| 1683 | else if (strcmp(tag, "#text") == 0) { } |
---|
| 1684 | else if (strcmp(tag, "#comment") == 0) { } |
---|
| 1685 | else if (strcmp(tag, "mapping_info") == 0) |
---|
| 1686 | { |
---|
| 1687 | #if XML_PARSER_DEBUG |
---|
| 1688 | printf("end mapping_info\n"); |
---|
| 1689 | #endif |
---|
| 1690 | return; |
---|
| 1691 | } |
---|
| 1692 | else |
---|
| 1693 | { |
---|
| 1694 | printf("[XML ERROR] Unknown tag in header node : %s\n",tag); |
---|
| 1695 | exit(1); |
---|
| 1696 | } |
---|
| 1697 | status = xmlTextReaderRead(reader); |
---|
| 1698 | } |
---|
| 1699 | } // end headerNode() |
---|
| 1700 | |
---|
| 1701 | |
---|
[511] | 1702 | //////////////////////////////////// |
---|
| 1703 | void BuildTable( int fdout, |
---|
| 1704 | const char * type, |
---|
| 1705 | unsigned int nb_elem, |
---|
| 1706 | unsigned int elem_size, |
---|
| 1707 | char ** table ) |
---|
[258] | 1708 | { |
---|
| 1709 | unsigned int i; |
---|
[511] | 1710 | for (i = 0; i < nb_elem; i++) |
---|
| 1711 | { |
---|
| 1712 | if (elem_size != write(fdout, table[i], elem_size)) |
---|
| 1713 | { |
---|
[258] | 1714 | printf("function %s: %s(%d) write error \n", __FUNCTION__, type, i); |
---|
| 1715 | exit(1); |
---|
| 1716 | } |
---|
| 1717 | |
---|
| 1718 | #if XML_PARSER_DEBUG |
---|
| 1719 | printf("Building binary: writing %s %d\n", type, i); |
---|
| 1720 | #endif |
---|
| 1721 | } |
---|
| 1722 | } |
---|
| 1723 | |
---|
| 1724 | ///////////////////////////////////// |
---|
| 1725 | int open_file(const char * file_path) |
---|
| 1726 | { |
---|
| 1727 | //open file |
---|
| 1728 | int fdout = open( file_path, (O_CREAT | O_RDWR), (S_IWUSR | S_IRUSR) ); |
---|
| 1729 | if (fdout < 0) |
---|
| 1730 | { |
---|
| 1731 | perror("open"); |
---|
| 1732 | exit(1); |
---|
| 1733 | } |
---|
| 1734 | |
---|
| 1735 | //reinitialise the file |
---|
| 1736 | if (ftruncate(fdout, 0)) |
---|
| 1737 | { |
---|
| 1738 | perror("truncate"); |
---|
| 1739 | exit(1); |
---|
| 1740 | } |
---|
| 1741 | |
---|
| 1742 | //#if XML_PARSER_DEBUG |
---|
| 1743 | printf("%s\n", file_path); |
---|
| 1744 | //#endif |
---|
| 1745 | |
---|
| 1746 | return fdout; |
---|
| 1747 | } |
---|
| 1748 | |
---|
| 1749 | |
---|
| 1750 | ///////////////////////////////////// |
---|
| 1751 | void buildBin(const char * file_path) |
---|
| 1752 | { |
---|
| 1753 | unsigned int length; |
---|
| 1754 | |
---|
| 1755 | int fdout = open_file(file_path); |
---|
| 1756 | |
---|
| 1757 | #if XML_PARSER_DEBUG |
---|
| 1758 | printf("Building map.bin for %s\n", header->name); |
---|
| 1759 | printf("signature = %x\n", header->signature); |
---|
[263] | 1760 | printf("x_size = %d\n", header->x_size); |
---|
| 1761 | printf("y_size = %d\n", header->y_size); |
---|
| 1762 | printf("x_width = %d\n", header->x_width); |
---|
| 1763 | printf("y_width = %d\n", header->y_width); |
---|
[258] | 1764 | printf("vspaces = %d\n", header->vspaces); |
---|
| 1765 | printf("psegs = %d\n", header->psegs); |
---|
| 1766 | printf("vsegs = %d\n", header->vsegs); |
---|
| 1767 | printf("tasks = %d\n", header->tasks); |
---|
| 1768 | printf("procs = %d\n", header->procs); |
---|
| 1769 | printf("irqs = %d\n", header->irqs); |
---|
| 1770 | printf("periphs = %d\n", header->periphs); |
---|
| 1771 | #endif |
---|
| 1772 | |
---|
| 1773 | // write header to binary file |
---|
| 1774 | length = write(fdout, (char *) header, sizeof(mapping_header_t)); |
---|
| 1775 | if (length != sizeof(mapping_header_t)) |
---|
| 1776 | { |
---|
| 1777 | printf("write header error : length = %d \n", length); |
---|
| 1778 | exit(1); |
---|
| 1779 | } |
---|
| 1780 | |
---|
| 1781 | // write clusters |
---|
| 1782 | BuildTable(fdout, "cluster", cluster_index, sizeof(mapping_cluster_t), (char **) cluster); |
---|
| 1783 | // write psegs |
---|
| 1784 | BuildTable(fdout, "pseg", pseg_index, sizeof(mapping_pseg_t), (char **) pseg); |
---|
| 1785 | // write vspaces |
---|
| 1786 | BuildTable(fdout, "vspace", vspace_index, sizeof(mapping_vspace_t), (char **) vspace); |
---|
| 1787 | // write vsegs |
---|
| 1788 | BuildTable(fdout, "vseg", vseg_index, sizeof(mapping_vseg_t), (char **) vseg); |
---|
| 1789 | // write tasks array |
---|
| 1790 | BuildTable(fdout, "task", task_index, sizeof(mapping_task_t), (char **) task); |
---|
| 1791 | //building procs array |
---|
| 1792 | BuildTable(fdout, "proc", proc_index, sizeof(mapping_proc_t), (char **) proc); |
---|
| 1793 | //building irqs array |
---|
| 1794 | BuildTable(fdout, "irq", irq_index, sizeof(mapping_irq_t), (char **) irq); |
---|
| 1795 | //building periphs array |
---|
| 1796 | BuildTable(fdout, "periph", periph_index, sizeof(mapping_periph_t), (char **) periph); |
---|
| 1797 | |
---|
| 1798 | close(fdout); |
---|
| 1799 | |
---|
| 1800 | } // end buildBin() |
---|
| 1801 | |
---|
| 1802 | |
---|
| 1803 | ////////////////////////////////////////////////////// |
---|
| 1804 | char * buildPath(const char * path, const char * name) |
---|
| 1805 | { |
---|
| 1806 | char * res = calloc(strlen(path) + strlen(name) + 1, 1); |
---|
| 1807 | strcat(res, path); |
---|
| 1808 | strcat(res, "/"); |
---|
| 1809 | strcat(res, name); |
---|
| 1810 | return res; |
---|
| 1811 | } |
---|
| 1812 | |
---|
| 1813 | |
---|
| 1814 | ////////////////////////////////// |
---|
| 1815 | int main(int argc, char * argv[]) |
---|
| 1816 | { |
---|
[511] | 1817 | if (argc < 3) |
---|
| 1818 | { |
---|
[258] | 1819 | printf("Usage: xml2bin <input_file_path> <output_path>\n"); |
---|
| 1820 | return 1; |
---|
| 1821 | } |
---|
| 1822 | |
---|
| 1823 | struct stat dir_st; |
---|
[511] | 1824 | if (stat( argv[2], &dir_st)) |
---|
| 1825 | { |
---|
[258] | 1826 | perror("bad path"); |
---|
| 1827 | exit(1); |
---|
| 1828 | } |
---|
| 1829 | |
---|
[511] | 1830 | if ((dir_st.st_mode & S_IFDIR) == 0) |
---|
| 1831 | { |
---|
[258] | 1832 | printf("path is not a dir: %s", argv[2] ); |
---|
| 1833 | exit(1); |
---|
| 1834 | } |
---|
| 1835 | |
---|
| 1836 | char * map_path = buildPath(argv[2], "map.bin"); |
---|
| 1837 | |
---|
| 1838 | LIBXML_TEST_VERSION; |
---|
| 1839 | |
---|
| 1840 | int status; |
---|
| 1841 | xmlTextReaderPtr reader = xmlReaderForFile(argv[1], NULL, 0); |
---|
| 1842 | |
---|
| 1843 | if (reader != NULL) |
---|
| 1844 | { |
---|
| 1845 | status = xmlTextReaderRead (reader); |
---|
| 1846 | while (status == 1) |
---|
| 1847 | { |
---|
| 1848 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
| 1849 | |
---|
| 1850 | if (strcmp(tag, "mapping_info") == 0) |
---|
| 1851 | { |
---|
| 1852 | headerNode(reader); |
---|
| 1853 | buildBin(map_path); |
---|
| 1854 | } |
---|
| 1855 | else |
---|
| 1856 | { |
---|
| 1857 | printf("[XML ERROR] Wrong file type: \"%s\"\n", argv[1]); |
---|
| 1858 | return 1; |
---|
| 1859 | } |
---|
| 1860 | status = xmlTextReaderRead(reader); |
---|
| 1861 | } |
---|
| 1862 | xmlFreeTextReader(reader); |
---|
| 1863 | |
---|
| 1864 | if (status != 0) |
---|
| 1865 | { |
---|
| 1866 | printf("[XML ERROR] Wrong Syntax in \"%s\" file\n", argv[1]); |
---|
| 1867 | return 1; |
---|
| 1868 | } |
---|
| 1869 | } |
---|
| 1870 | return 0; |
---|
| 1871 | } // end main() |
---|
| 1872 | |
---|
| 1873 | |
---|
| 1874 | // Local Variables: |
---|
| 1875 | // tab-width: 4 |
---|
| 1876 | // c-basic-offset: 4 |
---|
| 1877 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 1878 | // indent-tabs-mode: nil |
---|
| 1879 | // End: |
---|
| 1880 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 1881 | |
---|