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