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