Changeset 215 for soft/giet_vm/xml
- Timestamp:
- Sep 17, 2012, 10:47:46 AM (12 years ago)
- Location:
- soft/giet_vm/xml
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/xml/mapping_info.h
r200 r215 71 71 enum periphType 72 72 { 73 PERIPH_TYPE_I OC= 0,74 PERIPH_TYPE_T TY= 1,75 PERIPH_TYPE_ TIM= 2,73 PERIPH_TYPE_ICU = 0, 74 PERIPH_TYPE_TIM = 1, 75 PERIPH_TYPE_XICU = 2, 76 76 PERIPH_TYPE_DMA = 3, 77 PERIPH_TYPE_FBF = 4, 78 PERIPH_TYPE_NIC = 5, 79 PERIPH_TYPE_IOB = 6, 77 PERIPH_TYPE_IOC = 4, 78 PERIPH_TYPE_TTY = 5, 79 PERIPH_TYPE_FBF = 6, 80 PERIPH_TYPE_NIC = 7, 81 PERIPH_TYPE_IOB = 8, 80 82 }; 81 83 … … 92 94 unsigned int signature; // must contain MAPPING_SIGNATURE 93 95 unsigned int clusters; // number of clusters 96 unsigned int cluster_x; // number of cluster on the abcsisse axe 97 unsigned int cluster_y; // number of cluster on the ordinate axe 94 98 unsigned int globals; // number of vsegs mapped in all vspaces 95 99 unsigned int vspaces; // number of virtual spaces -
soft/giet_vm/xml/xml_driver.c
r204 r215 57 57 const char* periph_type[] = 58 58 { 59 "ICU", 60 "TIM", 61 "XICU", 62 "DMA", 59 63 "IOC", 60 64 "TTY", 61 "TIM",62 "DMA",63 65 "FBF", 64 66 "NIC", … … 220 222 fprintf( fpout, "<mapping_info signature = \"0x%x\" ", header->signature); 221 223 fprintf( fpout, " name = \"%s\" ", header->name); 222 fprintf( fpout, " clusters = \"%d\" ", header->clusters); 224 fprintf( fpout, " cluster_x = \"%d\" ", header->cluster_x); 225 fprintf( fpout, " cluster_y = \"%d\" ", header->cluster_y); 223 226 fprintf( fpout, " vspaces = \"%d\" >\n\n", header->vspaces); 224 227 … … 241 244 ///////////////////// processors ///////////////////////////////////////////// 242 245 246 unsigned int proc_index = 0; 243 247 for ( proc_id = cluster[cluster_id].proc_offset ; 244 248 proc_id < cluster[cluster_id].proc_offset + cluster[cluster_id].procs ; 245 249 proc_id++ ) 246 250 { 247 fprintf( fpout, " <proc index = \"%d\" >\n", proc_i d);251 fprintf( fpout, " <proc index = \"%d\" >\n", proc_index); 248 252 for ( irq_id = proc[proc_id].irq_offset ; 249 253 irq_id < proc[proc_id].irq_offset + proc[proc_id].irqs ; -
soft/giet_vm/xml/xml_parser.c
r206 r215 86 86 unsigned int vobj_count = 0; 87 87 88 /////////////////////////////////////////////////////////////////////// 88 89 ///////////////////////// 90 // found peripheral 91 ///////////////////////// 92 char found_timer = 0; 93 char found_icu = 0; 94 char found_xicu = 0; 95 char found_dma = 0; 96 97 98 ////////////////////////////////// 99 //needed to generate map_config.ld 100 ////////////////////////////////// 101 unsigned int cluster_y = 0; 102 unsigned int cluster_x = 0; 103 unsigned int nb_proc_max = 0; // max number of processors per cluster 104 unsigned int nb_timer_channel_max = 0; // max number of user timer 105 unsigned int nb_dma_channel_max = 0; 106 unsigned int nb_tty_channel = 0; 107 unsigned int nb_ioc_channel = 0; 108 unsigned int nb_nic_channel = 0; 109 unsigned int io_mmu_active = 0; 110 unsigned int use_xicu = 0xFFFFFFFF; 111 112 113 ////////////////////////////////// 114 //needed to generate giet_vseg.ld 115 ////////////////////////////////// 116 117 //kernel and boot code 118 unsigned int kernel_code_base = 0x80000000; /* kernel code */ 119 unsigned int kernel_data_base = 0x80010000; /* system cacheable data */ 120 unsigned int kernel_uncdata_base = 0x80080000; /* system uncacheable data */ 121 unsigned int kernel_init_base = 0x80090000; /* system init entry */ 122 123 unsigned int boot_code_base = 0xBFC00000; /* boot code */ 124 unsigned int boot_stack_base = 0xBFC08000; /* boot temporary stack */ 125 unsigned int boot_mapping_base = 0xBFC0C000; /* mapping_info blob */ 126 127 //periphs 128 unsigned int tim_base_offset = 0xFFFFFFFF; 129 unsigned int tty_base_offset = 0xFFFFFFFF; 130 unsigned int dma_base_offset = 0xFFFFFFFF; 131 unsigned int ioc_base_offset = 0xFFFFFFFF; 132 unsigned int fbf_base_offset = 0xFFFFFFFF; 133 unsigned int icu_base_offset = 0xFFFFFFFF; 134 unsigned int gcd_base_offset = 0xFFFFFFFF; 135 unsigned int iob_base_offset = 0xFFFFFFFF; 136 137 138 ////////////////////////////////////////////////////////////////////// 89 139 // This arrray is useful to build a temporary list of vobj references. 90 140 // The struct vobj_ref_s is formed by a vspace_name and a vobj_name. 91 141 // This array is used to set the attribute vobj_id of a cp_port 92 142 // once all the vspace have been parsed. 93 143 ///////////////////////////////////////////////////////////////////// 94 144 typedef struct vobj_ref_s 95 145 { … … 159 209 char* string = (char*)xmlTextReaderGetAttribute(reader, (const xmlChar*)attributeName); 160 210 211 161 212 if ( string == NULL ) // missing argument 162 213 { … … 166 217 else 167 218 { 219 //we read only string smaller than 32 byte 220 if(strlen(string) > 32) 221 { 222 printf("[XML ERROR] all strings must be less than 32 bytes\n"); 223 exit(1); 224 } 225 168 226 *ok = 1; 169 227 return string; … … 181 239 for ( pseg_id = pseg_min ; pseg_id < pseg_max ; pseg_id++ ) 182 240 { 183 if ( strcmp(pseg[pseg_id]->name, pseg_name) == 0 ) return pseg_id; 241 if ( strcmp(pseg[pseg_id]->name, pseg_name) == 0 ) 242 { 243 return pseg_id; 244 } 184 245 } 185 246 return -1; … … 219 280 return -1; 220 281 } 221 222 ///////////////////////////////////////////223 void cpPortNode ( xmlTextReaderPtr reader )224 ///////////////////////////////////////////225 {226 char* str;227 unsigned int ok;228 229 if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return;230 231 if ( cp_port_index >= MAX_CP_PORTS )232 {233 printf("[XML ERROR] The number of ports (for coprocs) is larger than %d\n", MAX_CP_PORTS);234 }235 236 #if XML_PARSER_DEBUG237 printf("\n port %d\n", cp_port_index);238 #endif239 240 cp_port[cp_port_index] = (mapping_cp_port_t*)malloc(sizeof(mapping_cp_port_t));241 cp_port_vobj_ref[cp_port_index] = (vobj_ref_t*)malloc(sizeof(vobj_ref_t));242 243 244 245 ///////// get direction attribute246 str = getStringValue( reader, "direction", &ok );247 if ( ok )248 {249 #if XML_PARSER_DEBUG250 printf(" direction = %s\n", str);251 #endif252 if ( strcmp(str, "TO_COPROC") == 0 ) cp_port[cp_port_index]->direction = PORT_TO_COPROC;253 else if ( strcmp(str, "FROM_COPROC") == 0 ) cp_port[cp_port_index]->direction = PORT_FROM_COPROC;254 else255 {256 printf("[XML ERROR] illegal <direction> for cp_port %d in cluster %d\n",257 cp_port_index, cluster_index);258 exit(1);259 }260 }261 else262 {263 printf("[XML ERROR] missing <direction> for cp_port %d in cluster %d\n",264 cp_port_index, cluster_index);265 exit(1);266 }267 268 /////////// get vspacename attribute269 str = getStringValue( reader, "vspacename", &ok );270 #if XML_PARSER_DEBUG271 printf(" vspacename = %s\n", str);272 #endif273 if ( ok )274 {275 strncpy(cp_port_vobj_ref[cp_port_index]->vspace_name, str, 31);276 }277 else278 {279 printf("[XML ERROR] missing <vspacename> for cp_port %d in cluster %d\n",280 cp_port_index, cluster_index);281 exit(1);282 }283 284 /////////// get vobjname attribute285 str = getStringValue( reader, "vobjname", &ok );286 #if XML_PARSER_DEBUG287 printf(" vobjname = %s\n", str);288 #endif289 if ( ok )290 {291 strncpy(cp_port_vobj_ref[cp_port_index]->vobj_name, str, 31);292 }293 else294 {295 printf("[XML ERROR] missing <vobjname> for cp_port %d in cluster %d\n",296 cp_port_index, cluster_index);297 exit(1);298 }299 300 cp_port_index++;301 cp_port_loc_index++;302 303 } // end cpPortNode()304 305 ///////////////////////////////////////////306 void periphNode ( xmlTextReaderPtr reader )307 ///////////////////////////////////////////308 {309 char* str;310 unsigned int value;311 unsigned int ok;312 313 if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return;314 315 if ( periph_index >= MAX_PERIPHS )316 {317 printf("[XML ERROR] The number of periphs is larger than %d\n", MAX_PERIPHS);318 }319 320 #if XML_PARSER_DEBUG321 printf("\n periph %d\n", periph_index);322 #endif323 324 periph[periph_index] = (mapping_periph_t*)malloc(sizeof(mapping_periph_t));325 326 /////////// get type attribute327 str = getStringValue( reader, "type", &ok );328 if ( ok )329 {330 #if XML_PARSER_DEBUG331 printf(" type = %s\n", str);332 #endif333 unsigned int error = 0;334 335 // The TTY, IOC, NIC, FBF and IOB peripherals cannot be replicated336 if ( strcmp( str, "IOC" ) == 0 )337 {338 periph[periph_index]->type = PERIPH_TYPE_IOC;339 if ( header->ioc_clusterid == 0xFFFFFFFF) header->ioc_clusterid = cluster_index;340 else error = 1;341 }342 else if ( strcmp( str, "TTY" ) == 0 )343 {344 periph[periph_index]->type = PERIPH_TYPE_TTY;345 if ( header->ioc_clusterid == 0xFFFFFFFF) header->ioc_clusterid = cluster_index;346 else error = 1;347 }348 else if ( strcmp( str, "FBF" ) == 0 )349 {350 periph[periph_index]->type = PERIPH_TYPE_FBF;351 if ( header->ioc_clusterid == 0xFFFFFFFF) header->ioc_clusterid = cluster_index;352 else error = 1;353 }354 else if ( strcmp( str, "NIC" ) == 0 )355 {356 periph[periph_index]->type = PERIPH_TYPE_NIC;357 if ( header->ioc_clusterid == 0xFFFFFFFF) header->ioc_clusterid = cluster_index;358 else error = 1;359 }360 // The TIM, DMA and IOB peripherals can be replicated in several clusters361 else if ( strcmp( str, "TIM" ) == 0 )362 {363 periph[periph_index]->type = PERIPH_TYPE_TIM;364 }365 else if ( strcmp( str, "DMA" ) == 0 )366 {367 periph[periph_index]->type = PERIPH_TYPE_DMA;368 }369 else if ( strcmp( str, "IOB" ) == 0 )370 {371 periph[periph_index]->type = PERIPH_TYPE_IOB;372 }373 else374 {375 printf("[XML ERROR] illegal <type> for peripheral %d in cluster %d\n",376 periph_loc_index, cluster_index);377 exit(1);378 }379 }380 else381 {382 printf("[XML ERROR] missing <type> for peripheral %d in cluster %d\n",383 periph_loc_index, cluster_index);384 exit(1);385 }386 387 ///////// get channels attribute (optionnal : 1 if missing)388 value = getIntValue( reader, "channels", &ok );389 if ( ok )390 {391 #if XML_PARSER_DEBUG392 printf(" channels = %d\n", value);393 #endif394 periph[periph_index]->channels = value;395 }396 else397 {398 periph[periph_index]->channels = 1;399 }400 401 /////////// get psegname attribute402 str = getStringValue(reader,"psegname", &ok);403 if ( ok == 0 )404 {405 printf("[XML ERROR] illegal or missing <psegname> for coproc %d in cluster %d\n",406 coproc_index, cluster_index);407 exit(1);408 }409 410 /////////// set psegid attribute411 int index = getPsegId( cluster_index, str );412 if ( index >= 0 )413 {414 #if XML_PARSER_DEBUG415 printf(" clusterid = %d\n", cluster_index);416 printf(" psegname = %s\n", str);417 printf(" psegid = %d\n", index);418 #endif419 periph[periph_index]->psegid = index;420 assert(pseg[index]->type == PSEG_TYPE_PERI &&421 "peripheral psegname attribute must refer to a pseg of type PERI" );422 }423 else424 {425 printf("[XML ERROR] pseg not found for periph %d / clusterid = %d / psegname = %s\n",426 periph_loc_index, cluster_index, str );427 exit(1);428 }429 430 periph_index++;431 periph_loc_index++;432 433 } // end periphNode434 435 /////////////////////////////////////////436 void coprocNode ( xmlTextReaderPtr reader )437 /////////////////////////////////////////438 {439 char* str;440 unsigned int ok;441 442 cp_port_loc_index = 0;443 444 if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return;445 446 if ( coproc_index >= MAX_COPROCS )447 {448 printf("[XML ERROR] The number of coprocs is larger than %d\n", MAX_COPROCS);449 }450 451 #if XML_PARSER_DEBUG452 printf("\n coproc %d\n", coproc_index);453 #endif454 455 coproc[coproc_index] = (mapping_coproc_t*)malloc(sizeof(mapping_coproc_t));456 457 /////////// get name attribute458 str = getStringValue( reader, "name", &ok );459 if ( ok )460 {461 #if XML_PARSER_DEBUG462 printf(" name = %s\n", str);463 #endif464 strncpy(coproc[coproc_index]->name, str, 31);465 }466 else467 {468 printf("[XML ERROR] illegal or missing <name> for coproc %d in cluster %d\n",469 coproc_index, cluster_index);470 exit(1);471 }472 473 /////////// get psegname attribute474 str = getStringValue(reader,"psegname", &ok);475 if ( ok == 0 )476 {477 printf("[XML ERROR] illegal or missing <psegname> for coproc %d in cluster %d\n",478 coproc_index, cluster_index);479 exit(1);480 }481 482 /////////// set psegid attribute483 int index = getPsegId( cluster_index, str );484 if ( index >= 0 )485 {486 #if XML_PARSER_DEBUG487 printf(" clusterid = %d\n", cluster_index);488 printf(" psegname = %s\n", str);489 printf(" psegid = %d\n", index);490 #endif491 coproc[coproc_index]->psegid = index;492 assert(pseg[index]->type == PSEG_TYPE_PERI && "coproc psegname attribute must refer to a pseg of type PERI" );493 }494 else495 {496 printf("[XML ERROR] pseg not found for coproc %d / clusterid = %d / psegname = %s\n",497 coproc_index, cluster_index, str );498 exit(1);499 }500 501 ////////// set port_offset502 coproc[coproc_index]->port_offset = cp_port_index;503 504 #if XML_PARSER_DEBUG505 printf(" port_offset = %d\n", cp_port_index);506 #endif507 508 int status = xmlTextReaderRead(reader);509 while ( status == 1 )510 {511 const char* tag = (const char*)xmlTextReaderConstName(reader);512 513 if ( strcmp(tag, "port") == 0 ) cpPortNode(reader);514 else if ( strcmp(tag, "#text") == 0 ) { }515 else if ( strcmp(tag, "#comment") == 0 ) { }516 else if ( strcmp(tag, "coproc") == 0 )517 {518 coproc[coproc_index]->ports = cp_port_loc_index;519 coproc_loc_index++;520 coproc_index++;521 return;522 }523 else524 {525 printf("[XML ERROR] Unknown tag %s",tag);526 exit(1);527 }528 status = xmlTextReaderRead ( reader );529 }530 } // end coprocNode()531 532 ///////////////////////////////////////533 void irqNode( xmlTextReaderPtr reader )534 ///////////////////////////////////////535 {536 unsigned int ok;537 unsigned int value;538 char* str;539 540 if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return;541 542 if ( irq_index >= MAX_IRQS )543 {544 printf("[XML ERROR] The number of irqs is larger than %d\n", MAX_IRQS);545 }546 547 #if XML_PARSER_DEBUG548 printf(" irq %d\n", irq_loc_index);549 #endif550 551 irq[irq_index] = (mapping_irq_t*)malloc(sizeof(mapping_irq_t));552 553 ///////// get type attribute554 str = getStringValue(reader,"type", &ok);555 if ( ok )556 {557 #if XML_PARSER_DEBUG558 printf(" type = %s\n", str);559 #endif560 if ( strcmp(str, "HARD") == 0 ) irq[irq_index]->type = 0;561 else if ( strcmp(str, "SOFT") == 0 ) irq[irq_index]->type = 1;562 else563 {564 printf("[XML ERROR] undefined IRQ <type> for processor %d in cluster %d\n",565 cluster_index, proc_loc_index );566 exit(1);567 }568 }569 else570 {571 printf("[XML ERROR] missing IRQ <type> for processor %d in cluster %d\n",572 cluster_index, proc_loc_index );573 exit(1);574 }575 576 ///////// get icuid attribute577 value = getIntValue(reader, "icuid", &ok);578 if ( ok )579 {580 #if XML_PARSER_DEBUG581 printf(" icuid = %d\n", value);582 #endif583 irq[irq_index]->icuid = value;584 if ( value >= 32 )585 {586 printf("[XML ERROR] IRQ <icuid> too large for processor %d in cluster %d\n",587 cluster_index, proc_loc_index );588 exit(1);589 }590 }591 else592 {593 printf("[XML ERROR] missing IRQ <icuid> for processor %d in cluster %d\n",594 cluster_index, proc_loc_index );595 exit(1);596 }597 598 ///////// get isr attribute599 str = getStringValue(reader,"isr", &ok);600 if ( ok )601 {602 #if XML_PARSER_DEBUG603 printf(" isr = %s\n", str);604 #endif605 if ( strcmp(str, "ISR_SWITCH" ) == 0 ) irq[irq_index]->isr = ISR_SWITCH;606 else if ( strcmp(str, "ISR_IOC" ) == 0 ) irq[irq_index]->isr = ISR_IOC;607 else if ( strcmp(str, "ISR_DMA" ) == 0 ) irq[irq_index]->isr = ISR_DMA;608 else if ( strcmp(str, "ISR_TTY" ) == 0 ) irq[irq_index]->isr = ISR_TTY;609 else if ( strcmp(str, "ISR_TIMER" ) == 0 ) irq[irq_index]->isr = ISR_TIMER;610 else611 {612 printf("[XML ERROR] illegal IRQ <isr> for processor %d in cluster %d\n",613 cluster_index, proc_loc_index );614 exit(1);615 }616 #if XML_PARSER_DEBUG617 printf(" isrnum = %d\n", irq[irq_index]->isr);618 #endif619 }620 else621 {622 printf("[XML ERROR] missing IRQ <isr> for processor %d in cluster %d\n",623 cluster_index, proc_loc_index );624 exit(1);625 }626 627 ///////// get channel attribute (optionnal : 0 if missing)628 value = getIntValue(reader, "channel", &ok);629 if ( ok )630 {631 #if XML_PARSER_DEBUG632 printf(" channel = %d\n", value);633 #endif634 irq[irq_index]->channel = value;635 }636 else637 {638 irq[irq_index]->channel = 0;639 }640 641 irq_index++;642 irq_loc_index++;643 644 } // end irqNode645 646 /////////////////////////////////////////647 void procNode ( xmlTextReaderPtr reader )648 /////////////////////////////////////////649 {650 unsigned int ok;651 unsigned int value;652 653 irq_loc_index = 0;654 655 if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return;656 657 if ( proc_index >= MAX_PROCS )658 {659 printf("[XML ERROR] The number of procs is larger than %d\n", MAX_PROCS);660 }661 662 #if XML_PARSER_DEBUG663 printf("\n proc %d\n", proc_index);664 #endif665 666 proc[proc_index] = (mapping_proc_t*)malloc(sizeof(mapping_proc_t));667 668 669 /////////// get index attribute (optional)670 value = getIntValue(reader,"index",&ok);671 if ( ok && (value != proc_loc_index) )672 {673 printf("[XML ERROR] wrong proc index / expected value is %d",674 proc_loc_index);675 exit(1);676 }677 678 ////////// set irq_offset attribute679 proc[proc_index]->irq_offset = irq_index;680 681 #if XML_PARSER_DEBUG682 printf(" irq_offset = %d\n", irq_index);683 #endif684 685 int status = xmlTextReaderRead(reader);686 while ( status == 1 )687 {688 const char* tag = (const char*)xmlTextReaderConstName(reader);689 690 if ( strcmp(tag, "irq") == 0 ) irqNode(reader);691 else if ( strcmp(tag, "#text") == 0 ) { }692 else if ( strcmp(tag, "#comment") == 0 ) { }693 else if ( strcmp(tag, "proc") == 0 )694 {695 proc[proc_index]->irqs = irq_loc_index;696 proc_loc_index++;697 proc_index++;698 return;699 }700 else701 {702 printf("[XML ERROR] Unknown tag %s",tag);703 exit(1);704 }705 status = xmlTextReaderRead ( reader );706 }707 } // end procNode()708 709 282 710 283 ///////////////////////////////////////// … … 1321 894 } // end vspaceNode() 1322 895 896 /////////////////////////////////////////// 897 void cpPortNode ( xmlTextReaderPtr reader ) 898 /////////////////////////////////////////// 899 { 900 char* str; 901 unsigned int ok; 902 903 if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; 904 905 if ( cp_port_index >= MAX_CP_PORTS ) 906 { 907 printf("[XML ERROR] The number of ports (for coprocs) is larger than %d\n", MAX_CP_PORTS); 908 } 909 910 #if XML_PARSER_DEBUG 911 printf("\n port %d\n", cp_port_index); 912 #endif 913 914 cp_port[cp_port_index] = (mapping_cp_port_t*)malloc(sizeof(mapping_cp_port_t)); 915 cp_port_vobj_ref[cp_port_index] = (vobj_ref_t*)malloc(sizeof(vobj_ref_t)); 916 917 918 919 ///////// get direction attribute 920 str = getStringValue( reader, "direction", &ok ); 921 if ( ok ) 922 { 923 #if XML_PARSER_DEBUG 924 printf(" direction = %s\n", str); 925 #endif 926 if ( strcmp(str, "TO_COPROC") == 0 ) cp_port[cp_port_index]->direction = PORT_TO_COPROC; 927 else if ( strcmp(str, "FROM_COPROC") == 0 ) cp_port[cp_port_index]->direction = PORT_FROM_COPROC; 928 else 929 { 930 printf("[XML ERROR] illegal <direction> for cp_port %d in cluster %d\n", 931 cp_port_index, cluster_index); 932 exit(1); 933 } 934 } 935 else 936 { 937 printf("[XML ERROR] missing <direction> for cp_port %d in cluster %d\n", 938 cp_port_index, cluster_index); 939 exit(1); 940 } 941 942 /////////// get vspacename attribute 943 str = getStringValue( reader, "vspacename", &ok ); 944 #if XML_PARSER_DEBUG 945 printf(" vspacename = %s\n", str); 946 #endif 947 if ( ok ) 948 { 949 strncpy(cp_port_vobj_ref[cp_port_index]->vspace_name, str, 31); 950 } 951 else 952 { 953 printf("[XML ERROR] missing <vspacename> for cp_port %d in cluster %d\n", 954 cp_port_index, cluster_index); 955 exit(1); 956 } 957 958 /////////// get vobjname attribute 959 str = getStringValue( reader, "vobjname", &ok ); 960 #if XML_PARSER_DEBUG 961 printf(" vobjname = %s\n", str); 962 #endif 963 if ( ok ) 964 { 965 strncpy(cp_port_vobj_ref[cp_port_index]->vobj_name, str, 31); 966 } 967 else 968 { 969 printf("[XML ERROR] missing <vobjname> for cp_port %d in cluster %d\n", 970 cp_port_index, cluster_index); 971 exit(1); 972 } 973 974 cp_port_index++; 975 cp_port_loc_index++; 976 977 } // end cpPortNode() 978 979 /////////////////////////////////////////// 980 void periphNode ( xmlTextReaderPtr reader ) 981 /////////////////////////////////////////// 982 { 983 char* str; 984 unsigned int value; 985 unsigned int ok; 986 987 if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; 988 989 if ( periph_index >= MAX_PERIPHS ) 990 { 991 printf("[XML ERROR] The number of periphs is larger than %d\n", MAX_PERIPHS); 992 } 993 994 #if XML_PARSER_DEBUG 995 printf("\n periph %d\n", periph_index); 996 #endif 997 998 periph[periph_index] = (mapping_periph_t*)malloc(sizeof(mapping_periph_t)); 999 1000 1001 ///////// get channels attribute (optionnal : 1 if missing) 1002 value = getIntValue( reader, "channels", &ok ); 1003 if ( ok ) 1004 { 1005 #if XML_PARSER_DEBUG 1006 printf(" channels = %d\n", value); 1007 #endif 1008 periph[periph_index]->channels = value; 1009 } 1010 else 1011 { 1012 periph[periph_index]->channels = 1; 1013 } 1014 1015 /////////// get psegname attribute 1016 str = getStringValue(reader,"psegname", &ok); 1017 if ( ok == 0 ) 1018 { 1019 printf("[XML ERROR] illegal or missing <psegname> for coproc %d in cluster %d\n", 1020 coproc_index, cluster_index); 1021 exit(1); 1022 } 1023 1024 /////////// set psegid attribute 1025 int index = getPsegId( cluster_index, str ); 1026 if ( index >= 0 ) 1027 { 1028 #if XML_PARSER_DEBUG 1029 printf(" clusterid = %d\n", cluster_index); 1030 printf(" psegname = %s\n", str); 1031 printf(" psegid = %d\n", index); 1032 #endif 1033 periph[periph_index]->psegid = index; 1034 assert(pseg[index]->type == PSEG_TYPE_PERI && 1035 "peripheral psegname attribute must refer to a pseg of type PERI" ); 1036 } 1037 else 1038 { 1039 printf("[XML ERROR] pseg not found for periph %d / clusterid = %d / psegname = %s\n", 1040 periph_loc_index, cluster_index, str ); 1041 exit(1); 1042 } 1043 1044 1045 /////////// get type attribute 1046 str = getStringValue( reader, "type", &ok ); 1047 if ( ok ) 1048 { 1049 #if XML_PARSER_DEBUG 1050 printf(" type = %s\n", str); 1051 #endif 1052 unsigned int error = 0; 1053 1054 // The TTY, IOC, NIC, FBF and IOB peripherals cannot be replicated 1055 // one per architecture 1056 if ( strcmp( str, "IOC" ) == 0 ) 1057 { 1058 periph[periph_index]->type = PERIPH_TYPE_IOC; 1059 if ( header->ioc_clusterid == 0xFFFFFFFF) header->ioc_clusterid = cluster_index; 1060 else error = 1; 1061 1062 ioc_base_offset = pseg[ periph[periph_index]->psegid ]->base; 1063 nb_ioc_channel = periph[periph_index]->channels; 1064 } 1065 else if ( strcmp( str, "TTY" ) == 0 ) 1066 { 1067 periph[periph_index]->type = PERIPH_TYPE_TTY; 1068 if ( header->tty_clusterid == 0xFFFFFFFF) header->tty_clusterid = cluster_index; 1069 else error = 1; 1070 1071 tty_base_offset = pseg[ periph[periph_index]->psegid ]->base; 1072 nb_tty_channel = periph[periph_index]->channels; 1073 } 1074 else if ( strcmp( str, "FBF" ) == 0 ) 1075 { 1076 periph[periph_index]->type = PERIPH_TYPE_FBF; 1077 if ( header->fbf_clusterid == 0xFFFFFFFF) header->fbf_clusterid = cluster_index; 1078 else error = 1; 1079 1080 fbf_base_offset = pseg[ periph[periph_index]->psegid ]->base; 1081 } 1082 else if ( strcmp( str, "NIC" ) == 0 ) 1083 { 1084 periph[periph_index]->type = PERIPH_TYPE_NIC; 1085 if ( header->nic_clusterid == 0xFFFFFFFF) header->nic_clusterid = cluster_index; 1086 else error = 1; 1087 1088 //nic_base_offset = pseg[ periph[periph_index]->psegid ]->base; 1089 nb_nic_channel = periph[periph_index]->channels; 1090 } 1091 else if ( strcmp( str, "IOB" ) == 0 ) 1092 { 1093 periph[periph_index]->type = PERIPH_TYPE_IOB; 1094 iob_base_offset = pseg[ periph[periph_index]->psegid ]->base; 1095 1096 if(io_mmu_active) error = 1; 1097 io_mmu_active = 1; 1098 } 1099 // The TIM, ICU, XICU, DMA and IOB peripherals can be replicated in several clusters 1100 // one per cluster 1101 else if ( strcmp( str, "TIM" ) == 0 ) 1102 { 1103 periph[periph_index]->type = PERIPH_TYPE_TIM; 1104 if(found_timer) error = 1; 1105 found_timer = 1; 1106 1107 if(tim_base_offset == 0xFFFFFFFF) 1108 tim_base_offset = pseg[ periph[periph_index]->psegid ]->base; 1109 1110 if(nb_timer_channel_max < periph[periph_index]->channels) 1111 nb_timer_channel_max = periph[periph_index]->channels; 1112 } 1113 else if ( strcmp( str, "ICU" ) == 0 ) 1114 { 1115 periph[periph_index]->type = PERIPH_TYPE_ICU; 1116 if(found_icu) error = 1; 1117 found_icu = 1; 1118 1119 if(icu_base_offset == 0xFFFFFFFF) 1120 icu_base_offset = pseg[ periph[periph_index]->psegid ]->base; 1121 } 1122 else if ( strcmp( str, "XICU" ) == 0 ) 1123 { 1124 periph[periph_index]->type = PERIPH_TYPE_XICU; 1125 if(found_xicu) error = 1; 1126 found_xicu = 1; 1127 1128 //'icu' since we can't have both xicu and icu in an arch 1129 if(icu_base_offset == 0xFFFFFFFF) 1130 icu_base_offset = pseg[ periph[periph_index]->psegid ]->base; 1131 } 1132 else if ( strcmp( str, "DMA" ) == 0 ) 1133 { 1134 periph[periph_index]->type = PERIPH_TYPE_DMA; 1135 if(found_dma) error = 1; 1136 found_dma = 1; 1137 1138 if(dma_base_offset == 0xFFFFFFFF) 1139 dma_base_offset = pseg[ periph[periph_index]->psegid ]->base; 1140 if(nb_dma_channel_max < periph[periph_index]->channels) 1141 nb_dma_channel_max = periph[periph_index]->channels; 1142 } 1143 else 1144 { 1145 printf("[XML ERROR] illegal <type> for peripheral %d in cluster %d\n", 1146 periph_loc_index, cluster_index); 1147 exit(1); 1148 } 1149 1150 if(error) 1151 { 1152 printf("[XML ERROR] illegal <type> for peripheral %d in cluster %d\n", 1153 periph_loc_index, cluster_index); 1154 exit(1); 1155 } 1156 } 1157 else 1158 { 1159 printf("[XML ERROR] missing <type> for peripheral %d in cluster %d\n", 1160 periph_loc_index, cluster_index); 1161 exit(1); 1162 } 1163 1164 1165 periph_index++; 1166 periph_loc_index++; 1167 cluster[cluster_index]->periphs++; 1168 1169 } // end periphNode 1170 1171 ///////////////////////////////////////// 1172 void coprocNode ( xmlTextReaderPtr reader ) 1173 ///////////////////////////////////////// 1174 { 1175 char* str; 1176 unsigned int ok; 1177 1178 cp_port_loc_index = 0; 1179 1180 if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; 1181 1182 if ( coproc_index >= MAX_COPROCS ) 1183 { 1184 printf("[XML ERROR] The number of coprocs is larger than %d\n", MAX_COPROCS); 1185 } 1186 1187 #if XML_PARSER_DEBUG 1188 printf("\n coproc %d\n", coproc_index); 1189 #endif 1190 1191 coproc[coproc_index] = (mapping_coproc_t*)malloc(sizeof(mapping_coproc_t)); 1192 1193 /////////// get name attribute 1194 str = getStringValue( reader, "name", &ok ); 1195 if ( ok ) 1196 { 1197 #if XML_PARSER_DEBUG 1198 printf(" name = %s\n", str); 1199 #endif 1200 strncpy(coproc[coproc_index]->name, str, 31); 1201 } 1202 else 1203 { 1204 printf("[XML ERROR] illegal or missing <name> for coproc %d in cluster %d\n", 1205 coproc_index, cluster_index); 1206 exit(1); 1207 } 1208 1209 /////////// get psegname attribute 1210 str = getStringValue(reader,"psegname", &ok); 1211 if ( ok == 0 ) 1212 { 1213 printf("[XML ERROR] illegal or missing <psegname> for coproc %d in cluster %d\n", 1214 coproc_index, cluster_index); 1215 exit(1); 1216 } 1217 1218 /////////// set psegid attribute 1219 int index = getPsegId( cluster_index, str ); 1220 if ( index >= 0 ) 1221 { 1222 #if XML_PARSER_DEBUG 1223 printf(" clusterid = %d\n", cluster_index); 1224 printf(" psegname = %s\n", str); 1225 printf(" psegid = %d\n", index); 1226 #endif 1227 coproc[coproc_index]->psegid = index; 1228 assert(pseg[index]->type == PSEG_TYPE_PERI && "coproc psegname attribute must refer to a pseg of type PERI" ); 1229 } 1230 else 1231 { 1232 printf("[XML ERROR] pseg not found for coproc %d / clusterid = %d / psegname = %s\n", 1233 coproc_index, cluster_index, str ); 1234 exit(1); 1235 } 1236 1237 ////////// set port_offset 1238 coproc[coproc_index]->port_offset = cp_port_index; 1239 1240 #if XML_PARSER_DEBUG 1241 printf(" port_offset = %d\n", cp_port_index); 1242 #endif 1243 1244 int status = xmlTextReaderRead(reader); 1245 while ( status == 1 ) 1246 { 1247 const char* tag = (const char*)xmlTextReaderConstName(reader); 1248 1249 if ( strcmp(tag, "port") == 0 ) cpPortNode(reader); 1250 else if ( strcmp(tag, "#text") == 0 ) { } 1251 else if ( strcmp(tag, "#comment") == 0 ) { } 1252 else if ( strcmp(tag, "coproc") == 0 ) 1253 { 1254 coproc[coproc_index]->ports = cp_port_loc_index; 1255 cluster[cluster_index]->coprocs++; 1256 coproc_loc_index++; 1257 coproc_index++; 1258 return; 1259 } 1260 else 1261 { 1262 printf("[XML ERROR] Unknown tag %s",tag); 1263 exit(1); 1264 } 1265 status = xmlTextReaderRead ( reader ); 1266 } 1267 } // end coprocNode() 1268 1269 /////////////////////////////////////// 1270 void irqNode( xmlTextReaderPtr reader ) 1271 /////////////////////////////////////// 1272 { 1273 unsigned int ok; 1274 unsigned int value; 1275 char* str; 1276 1277 if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; 1278 1279 if ( irq_index >= MAX_IRQS ) 1280 { 1281 printf("[XML ERROR] The number of irqs is larger than %d\n", MAX_IRQS); 1282 } 1283 1284 #if XML_PARSER_DEBUG 1285 printf(" irq %d\n", irq_loc_index); 1286 #endif 1287 1288 irq[irq_index] = (mapping_irq_t*)malloc(sizeof(mapping_irq_t)); 1289 1290 ///////// get type attribute 1291 str = getStringValue(reader,"type", &ok); 1292 if ( ok ) 1293 { 1294 #if XML_PARSER_DEBUG 1295 printf(" type = %s\n", str); 1296 #endif 1297 if ( strcmp(str, "HARD") == 0 ) irq[irq_index]->type = 0; 1298 else if ( strcmp(str, "SOFT") == 0 ) irq[irq_index]->type = 1; 1299 else 1300 { 1301 printf("[XML ERROR] undefined IRQ <type> for processor %d in cluster %d\n", 1302 cluster_index, proc_loc_index ); 1303 exit(1); 1304 } 1305 } 1306 else 1307 { 1308 printf("[XML ERROR] missing IRQ <type> for processor %d in cluster %d\n", 1309 cluster_index, proc_loc_index ); 1310 exit(1); 1311 } 1312 1313 ///////// get icuid attribute 1314 value = getIntValue(reader, "icuid", &ok); 1315 if ( ok ) 1316 { 1317 #if XML_PARSER_DEBUG 1318 printf(" icuid = %d\n", value); 1319 #endif 1320 irq[irq_index]->icuid = value; 1321 if ( value >= 32 ) 1322 { 1323 printf("[XML ERROR] IRQ <icuid> too large for processor %d in cluster %d\n", 1324 cluster_index, proc_loc_index ); 1325 exit(1); 1326 } 1327 } 1328 else 1329 { 1330 printf("[XML ERROR] missing IRQ <icuid> for processor %d in cluster %d\n", 1331 cluster_index, proc_loc_index ); 1332 exit(1); 1333 } 1334 1335 ///////// get isr attribute 1336 str = getStringValue(reader,"isr", &ok); 1337 if ( ok ) 1338 { 1339 #if XML_PARSER_DEBUG 1340 printf(" isr = %s\n", str); 1341 #endif 1342 if ( strcmp(str, "ISR_SWITCH" ) == 0 ) irq[irq_index]->isr = ISR_SWITCH; 1343 else if ( strcmp(str, "ISR_IOC" ) == 0 ) irq[irq_index]->isr = ISR_IOC; 1344 else if ( strcmp(str, "ISR_DMA" ) == 0 ) irq[irq_index]->isr = ISR_DMA; 1345 else if ( strcmp(str, "ISR_TTY" ) == 0 ) irq[irq_index]->isr = ISR_TTY; 1346 else if ( strcmp(str, "ISR_TIMER" ) == 0 ) irq[irq_index]->isr = ISR_TIMER; 1347 else 1348 { 1349 printf("[XML ERROR] illegal IRQ <isr> for processor %d in cluster %d\n", 1350 cluster_index, proc_loc_index ); 1351 exit(1); 1352 } 1353 #if XML_PARSER_DEBUG 1354 printf(" isrnum = %d\n", irq[irq_index]->isr); 1355 #endif 1356 } 1357 else 1358 { 1359 printf("[XML ERROR] missing IRQ <isr> for processor %d in cluster %d\n", 1360 cluster_index, proc_loc_index ); 1361 exit(1); 1362 } 1363 1364 ///////// get channel attribute (optionnal : 0 if missing) 1365 value = getIntValue(reader, "channel", &ok); 1366 if ( ok ) 1367 { 1368 #if XML_PARSER_DEBUG 1369 printf(" channel = %d\n", value); 1370 #endif 1371 irq[irq_index]->channel = value; 1372 } 1373 else 1374 { 1375 irq[irq_index]->channel = 0; 1376 } 1377 1378 irq_index++; 1379 irq_loc_index++; 1380 1381 } // end irqNode 1382 1383 ///////////////////////////////////////// 1384 void procNode ( xmlTextReaderPtr reader ) 1385 ///////////////////////////////////////// 1386 { 1387 unsigned int ok; 1388 unsigned int value; 1389 1390 irq_loc_index = 0; 1391 1392 if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; 1393 1394 if ( proc_index >= MAX_PROCS ) 1395 { 1396 printf("[XML ERROR] The number of procs is larger than %d\n", MAX_PROCS); 1397 } 1398 1399 #if XML_PARSER_DEBUG 1400 printf("\n proc %d\n", proc_index); 1401 #endif 1402 1403 proc[proc_index] = (mapping_proc_t*)malloc(sizeof(mapping_proc_t)); 1404 1405 1406 /////////// get index attribute (optional) 1407 value = getIntValue(reader,"index",&ok); 1408 if ( ok && (value != proc_loc_index) ) 1409 { 1410 printf("[XML ERROR] wrong proc index / expected value is %d", 1411 proc_loc_index); 1412 exit(1); 1413 } 1414 1415 ////////// set irq_offset attribute 1416 proc[proc_index]->irq_offset = irq_index; 1417 1418 #if XML_PARSER_DEBUG 1419 printf(" irq_offset = %d\n", irq_index); 1420 #endif 1421 1422 int status = xmlTextReaderRead(reader); 1423 while ( status == 1 ) 1424 { 1425 const char* tag = (const char*)xmlTextReaderConstName(reader); 1426 1427 if ( strcmp(tag, "irq") == 0 ) irqNode(reader); 1428 else if ( strcmp(tag, "#text") == 0 ) { } 1429 else if ( strcmp(tag, "#comment") == 0 ) { } 1430 else if ( strcmp(tag, "proc") == 0 ) 1431 { 1432 proc[proc_index]->irqs = irq_loc_index; 1433 cluster[cluster_index]->procs++; 1434 proc_loc_index++; 1435 proc_index++; 1436 return; 1437 } 1438 else 1439 { 1440 printf("[XML ERROR] Unknown tag %s",tag); 1441 exit(1); 1442 } 1443 status = xmlTextReaderRead ( reader ); 1444 } 1445 } // end procNode() 1446 1447 1323 1448 ////////////////////////////////////////// 1324 1449 void psegNode ( xmlTextReaderPtr reader ) … … 1420 1545 unsigned int value; 1421 1546 1547 cluster[cluster_index] = (mapping_cluster_t*)malloc(sizeof(mapping_cluster_t)); 1548 1549 //initialise all variables 1550 //they will be incremented by *Node() functions 1551 //FIXME: calloc? 1552 cluster[cluster_index]->psegs = 0; 1553 cluster[cluster_index]->procs = 0; 1554 cluster[cluster_index]->coprocs = 0; 1555 cluster[cluster_index]->periphs = 0; 1556 1557 1558 //initialise global variables 1559 //TODO: delete those three 1422 1560 proc_loc_index = 0; 1423 1561 coproc_loc_index = 0; 1424 1562 periph_loc_index = 0; 1425 1563 1564 // for replicated periph 1565 found_timer = 0; 1566 found_icu = 0; 1567 found_xicu = 0; 1568 found_dma = 0; 1569 1426 1570 if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; 1427 1571 … … 1437 1581 #endif 1438 1582 1439 cluster[cluster_index] = (mapping_cluster_t*)malloc(sizeof(mapping_cluster_t));1440 1441 //initialise the number of pseg1442 //it will be incremented by PsegNode1443 cluster[cluster_index]->psegs = 0;1444 1583 1445 1584 /////////// check cluster index attribute (optional) … … 1480 1619 else if ( strcmp(tag, "cluster") == 0 ) 1481 1620 { 1482 cluster[cluster_index]->procs = proc_loc_index; 1483 cluster[cluster_index]->coprocs = coproc_loc_index; 1484 cluster[cluster_index]->periphs = periph_loc_index; 1485 1486 // cluster[cluster_index]psegs update is done in psegNode(), 1487 // because the coprocNode() call to getPsegId() need it 1621 1622 if(use_xicu == 0xFFFFFFFF) 1623 use_xicu = found_xicu; 1624 1625 ////////////////// peripherals checks //////////////////// 1626 if( (found_timer && use_xicu) || (!found_timer && !use_xicu) ) 1627 { 1628 printf("[XML ERROR] illegal or missing timer peripheral in cluster %d\n", cluster_index); 1629 exit(1); 1630 } 1631 1632 if( (found_icu && use_xicu) || (!found_icu && !use_xicu) ) 1633 { 1634 printf("[XML ERROR] illegal or missing icu peripheral in cluster %d\n", cluster_index); 1635 exit(1); 1636 } 1637 1638 if( !found_xicu && use_xicu) 1639 { 1640 printf("[XML ERROR] illegal or missing dma peripheral in cluster %d\n", cluster_index); 1641 exit(1); 1642 } 1643 1644 if(!found_dma) 1645 { 1646 printf("[XML ERROR] illegal or missing dma peripheral in cluster %d\n", cluster_index); 1647 exit(1); 1648 } 1649 1650 1651 if(nb_proc_max < cluster[cluster_index]->procs) 1652 nb_proc_max = cluster[cluster_index]->procs; 1488 1653 1489 1654 #if XML_PARSER_DEBUG … … 1492 1657 printf(" coprocs = %d\n", cluster[cluster_index]->coprocs); 1493 1658 printf(" periphs = %d\n", cluster[cluster_index]->periphs); 1494 printf(" end cluster %d\n", cluster_index);1659 printf(" end cluster %d\n", cluster_index); 1495 1660 #endif 1496 1661 cluster_index++; … … 1527 1692 exit(1); 1528 1693 } 1529 else 1694 1695 if(header->tty_clusterid == 0xFFFFFFFF) 1530 1696 { 1697 printf("[XML ERROR] illegal or missing tty peripheral"); 1698 exit(1); 1699 } 1700 1531 1701 #if XML_PARSER_DEBUG 1532 1702 printf(" end cluster set\n\n"); 1533 1703 #endif 1534 header->psegs = pseg_index; 1535 header->procs = proc_index; 1536 header->irqs = irq_index; 1537 header->coprocs = coproc_index; 1538 header->cp_ports = cp_port_index; 1539 return; 1540 } 1704 header->psegs = pseg_index; 1705 header->procs = proc_index; 1706 header->irqs = irq_index; 1707 header->coprocs = coproc_index; 1708 header->cp_ports = cp_port_index; 1709 return; 1541 1710 } 1542 1711 else … … 1659 1828 } 1660 1829 1661 /////////// get clusters attribute 1662 value = getIntValue(reader, "clusters", &ok); 1663 if ( ok ) 1664 { 1665 if ( value >= MAX_CLUSTERS ) 1666 { 1667 printf("[XML ERROR] The number of clusters is larger than %d\n", MAX_CLUSTERS); 1668 exit(1); 1669 } 1830 /////////// get cluster_x attribute 1831 cluster_x = getIntValue(reader, "cluster_x", &ok); 1832 if ( ok ) 1833 { 1834 #if XML_PARSER_DEBUG 1835 printf(" cluster_x = %d\n", cluster_x); 1836 #endif 1837 header->cluster_x = cluster_x; 1838 } 1839 else 1840 { 1841 printf("[XML ERROR] illegal or missing <cluster_x> attribute in header\n"); 1842 exit(1); 1843 } 1844 1845 /////////// get cluster_y attribute 1846 cluster_y = getIntValue(reader, "cluster_y", &ok); 1847 if ( ok ) 1848 { 1849 #if XML_PARSER_DEBUG 1850 printf(" cluster_y = %d\n", cluster_y); 1851 #endif 1852 header->cluster_y = cluster_y; 1853 } 1854 else 1855 { 1856 printf("[XML ERROR] illegal or missing <cluster_y> attribute in header\n"); 1857 exit(1); 1858 } 1859 1860 //check the number of cluster 1861 value = cluster_x*cluster_y; 1862 if ( value >= MAX_CLUSTERS ) 1863 { 1864 printf("[XML ERROR] The number of clusters is larger than %d\n", MAX_CLUSTERS); 1865 exit(1); 1866 } 1867 1868 header->clusters = value; 1869 1670 1870 #if XML_PARSER_DEBUG 1671 1871 printf(" clusters = %d\n", value); 1672 1872 #endif 1673 header->clusters = value;1674 }1675 else1676 {1677 printf("[XML ERROR] illegal or missing <clusters> attribute in header\n");1678 exit(1);1679 }1680 1873 1681 1874 ///////// get vspaces attribute … … 1743 1936 { 1744 1937 unsigned int i; 1745 unsigned int length;1746 1938 // write element 1747 1939 for ( i = 0 ; i < nb_elem ; i++ ) 1748 1940 { 1749 length = write(fdout, table[i], elem_size); 1750 1941 if(elem_size != write(fdout, table[i], elem_size)) 1942 { 1943 printf("function %s: %s(%d) write error \n", __FUNCTION__, type, i); 1944 exit(1); 1945 } 1946 1751 1947 #if XML_PARSER_DEBUG 1752 1948 printf("Building binary: writing %s %d\n", type, i); 1753 1949 #endif 1754 1755 if ( length != elem_size )1756 {1757 printf("type: %s\n", type);1758 perror("error writing");1759 exit(1);1760 }1761 1950 } 1762 1951 } 1763 1952 1953 int open_file(const char* file_path) 1954 { 1955 1956 //open file 1957 int fdout = open( file_path, (O_CREAT | O_RDWR), (S_IWUSR | S_IRUSR) ); 1958 if ( fdout < 0) 1959 { 1960 perror("open"); 1961 exit(1); 1962 } 1963 1964 //reinitialise the file 1965 if( ftruncate(fdout, 0) ) 1966 { 1967 perror("truncate"); 1968 exit(1); 1969 } 1970 1971 //#if XML_PARSER_DEBUG 1972 printf("%s\n",file_path); 1973 //#endif 1974 1975 return fdout; 1976 } 1977 1978 1764 1979 /////////////////////////// 1765 void buildBin( int fdout)1980 void buildBin( const char* file_path ) 1766 1981 /////////////////////////// 1767 1982 { 1768 unsigned int vspace_id;1769 unsigned int vobj_id;1770 1983 unsigned int length; 1984 1985 int fdout = open_file(file_path); 1771 1986 1772 1987 // write header to binary file 1773 1988 length = write(fdout, (char*)header, sizeof(mapping_header_t)); 1774 1775 #if XML_PARSER_DEBUG1776 printf("\n*** write header\n");1777 #endif1778 1779 1989 if ( length != sizeof(mapping_header_t) ) 1780 1990 { … … 1785 1995 // write clusters 1786 1996 BuildTable(fdout, "cluster", cluster_index, sizeof(mapping_cluster_t), (char**) cluster); 1787 1788 1997 // write psegs 1789 1998 BuildTable(fdout, "pseg", pseg_index, sizeof(mapping_pseg_t), (char**) pseg); 1790 1791 1999 // write vspaces 1792 for ( vspace_id = 0 ; vspace_id < header->vspaces ; vspace_id++ ) 1793 { 1794 length = write(fdout, (char*)vspace[vspace_id], sizeof(mapping_vspace_t)); 1795 1796 #if XML_PARSER_DEBUG 1797 printf("write vspace %d\n", vspace_id); 1798 printf("vspace->vobj_offset: %d\n", vspace[vspace_id]->vobj_offset); 1799 printf("vspace->vobjs: %d\n", vspace[vspace_id]->vobjs); 1800 printf("header->vobjs: %d\n", header->vobjs); 1801 #endif 1802 1803 if ( length != sizeof(mapping_vspace_t) ) 1804 { 1805 perror("write vspace"); 1806 exit(1); 1807 } 1808 } 1809 2000 BuildTable(fdout, "vspace", vspace_index, sizeof(mapping_vspace_t), (char**) vspace); 1810 2001 // write vsegs 1811 2002 BuildTable(fdout, "vseg", vseg_index, sizeof(mapping_vseg_t), (char**) vseg); 1812 1813 2003 // write vobjs 1814 for ( vobj_id = 0 ; vobj_id < header->vobjs ; vobj_id++ ) 1815 { 1816 length = write(fdout, (char*)vobj[vobj_id], sizeof(mapping_vobj_t)); 1817 1818 #if XML_PARSER_DEBUG 1819 printf("write vobj %d\n", vobj_id); 1820 printf("write vobj name %s\n", vobj[vobj_id]->name); 1821 printf("write vobj length %x\n", vobj[vobj_id]->length); 1822 printf("write vobj type %d\n", vobj[vobj_id]->type); 1823 #endif 1824 1825 if ( length != sizeof(mapping_vobj_t) ) 1826 { 1827 perror("write vobj"); 1828 exit(1); 1829 } 1830 } 1831 2004 BuildTable(fdout, "vobj", vobj_index, sizeof(mapping_vobj_t), (char**) vobj); 1832 2005 // write tasks array 1833 2006 BuildTable(fdout, "task", task_index, sizeof(mapping_task_t), (char**) task); … … 1842 2015 //building periphs array 1843 2016 BuildTable(fdout, "periph", periph_index, sizeof(mapping_periph_t), (char**)periph); 2017 2018 close(fdout); 1844 2019 1845 2020 } // end buildBin() … … 1889 2064 } 1890 2065 2066 2067 void file_write(int fdout, char* towrite) 2068 { 2069 unsigned int size = strlen(towrite); 2070 if(size != write(fdout, towrite, size)) 2071 { 2072 printf("file_write error"); 2073 exit(1); 2074 } 2075 } 2076 2077 void def_int_write(int fdout, char* def, int num) 2078 { 2079 char buf[64]; 2080 sprintf(buf, "#define\t %s %d\n", def, num); 2081 file_write(fdout, buf); 2082 2083 } 2084 2085 void def_hex_write(int fdout, char* def, int num) 2086 { 2087 char buf[64]; 2088 sprintf(buf, "#define\t %s 0x%x\n", def, num); 2089 file_write(fdout, buf); 2090 } 2091 2092 /////////////////////////// 2093 void genHd( const char* file_path ) 2094 /////////////////////////// 2095 { 2096 int fdout = open_file(file_path); 2097 2098 char* prol = " /* AUTO GENRATED FILE */\n\n#ifndef _HD_CONFIG_H\n#define _HD_CONFIG_H\n\n"; 2099 file_write(fdout, prol); 2100 2101 def_int_write(fdout, "CLUSTER_X" , cluster_x); 2102 def_int_write(fdout, "CLUSTER_Y" , cluster_y); 2103 def_int_write(fdout, "NB_CLUSTERS" , cluster_index); 2104 def_hex_write(fdout, "CLUSTER_SIZE" , ( ((unsigned long)1) << 32)/cluster_index); 2105 def_int_write(fdout, "NB_PROCS_MAX" , nb_proc_max); 2106 def_int_write(fdout, "NB_TIMERS_MAX" , nb_timer_channel_max); 2107 def_int_write(fdout, "NB_DMAS_MAX" , nb_dma_channel_max); 2108 def_int_write(fdout, "NB_TTYS" , nb_tty_channel); 2109 def_int_write(fdout, "NB_IOCS" , nb_ioc_channel); 2110 def_int_write(fdout, "NB_NICS" , nb_nic_channel); 2111 2112 file_write(fdout, "\n"); 2113 def_int_write(fdout, "USE_XICU" , use_xicu); 2114 def_int_write(fdout, "IOMMU_ACTIVE " , io_mmu_active); 2115 2116 char* epil = "\n#endif //_HD_CONFIG_H"; 2117 file_write(fdout, epil); 2118 2119 close(fdout); 2120 } 2121 2122 void ld_write(int fdout, char* seg, unsigned int addr) 2123 { 2124 char buf[64]; 2125 sprintf(buf, "%s = 0x%x;\n", seg, addr); 2126 file_write(fdout, buf); 2127 2128 } 2129 2130 /////////////////////////// 2131 void genLd( const char* file_path ) 2132 /////////////////////////// 2133 { 2134 int fdout = open_file(file_path); 2135 2136 char* prol = "/* AUTO GENRATED FILE */\n\n"; 2137 file_write(fdout, prol); 2138 2139 //boot 2140 ld_write(fdout, "seg_boot_code_base" , boot_code_base); 2141 ld_write(fdout, "seg_boot_stack_base" , boot_stack_base); 2142 ld_write(fdout, "seg_mapping_base" , boot_mapping_base ); 2143 2144 //kernel 2145 ld_write(fdout, "\nseg_kernel_code_base" , kernel_code_base); 2146 ld_write(fdout, "seg_kernel_data_base" , kernel_data_base); 2147 ld_write(fdout, "seg_kernel_uncdata_base" , kernel_uncdata_base); 2148 ld_write(fdout, "seg_kernel_init_base" , kernel_init_base); 2149 2150 //peripherals 2151 ld_write(fdout, "\nseg_fbf_base" , fbf_base_offset); 2152 ld_write(fdout, "seg_icu_base" , icu_base_offset); 2153 ld_write(fdout, "seg_ioc_base" , ioc_base_offset); 2154 ld_write(fdout, "seg_tty_base" , tty_base_offset); 2155 ld_write(fdout, "seg_dma_base" , dma_base_offset); 2156 ld_write(fdout, "seg_tim_base" , tim_base_offset); 2157 ld_write(fdout, "seg_gcd_base" , gcd_base_offset); 2158 ld_write(fdout, "seg_iob_base" , iob_base_offset); 2159 2160 close(fdout); 2161 } 2162 2163 char* buildPath(const char* path, const char*name) 2164 { 2165 char *res = calloc(strlen(path) + strlen(name) + 1, 1); 2166 strcat(res, path); 2167 strcat(res, "/"); 2168 strcat(res, name); 2169 return res; 2170 } 2171 1891 2172 ///////////////////////////////////// 1892 2173 int main ( int argc, char* argv[] ) … … 1895 2176 if ( argc < 3 ) 1896 2177 { 1897 printf("Usage: xml2bin <input_file_path> <output_ file_path>\n");2178 printf("Usage: xml2bin <input_file_path> <output_path>\n"); 1898 2179 return 1; 1899 2180 } 1900 2181 1901 int fdout = open( argv[2], (O_CREAT | O_RDWR), S_IRWXU ); 1902 if ( fdout < 0) 1903 { 1904 perror("open"); 1905 exit(1); 1906 } 2182 struct stat dir_st; 2183 if(stat( argv[2], &dir_st )) 2184 { 2185 perror("bad path"); 2186 exit(1); 2187 } 2188 2189 if((dir_st.st_mode & S_IFDIR) == 0) 2190 { 2191 printf("path is not a dir: %s", argv[2] ); 2192 exit(1); 2193 } 2194 1907 2195 2196 char *map_path = buildPath(argv[2], "map.bin"); 2197 char *ld_path = buildPath(argv[2], "giet_vsegs.ld"); 2198 char *hd_path = buildPath(argv[2], "hard_config.h"); 2199 1908 2200 LIBXML_TEST_VERSION; 1909 2201 … … 1922 2214 headerNode( reader ); 1923 2215 prepareBuild(); 1924 buildBin( fdout ); 2216 buildBin( map_path ); 2217 genHd(hd_path); 2218 genLd(ld_path); 1925 2219 } 1926 2220 else
Note: See TracChangeset
for help on using the changeset viewer.