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