Changeset 253 for soft/giet_vm/xml/xml_parser.c
- Timestamp:
- Aug 14, 2013, 11:19:29 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/xml/xml_parser.c
r249 r253 6 6 /////////////////////////////////////////////////////////////////////////////////////// 7 7 // This program translate a "map.xml" source file to a binary file "map.bin" that 8 // can be directly loaded in the boot ROMand used by the GIET-VM operating system.8 // can be directly loaded in memory and used by the GIET-VM operating system. 9 9 // 10 10 // This map.xml file contains : … … 14 14 // The corresponding C structures are defined in the "mapping_info.h" file. 15 15 // 16 // This p rogramalso generates the "hard_config.h" and the "giet_vsegs.ld" files,16 // This parser also generates the "hard_config.h" and the "giet_vsegs.ld" files, 17 17 // required to compile the GIET-VM code. 18 18 /////////////////////////////////////////////////////////////////////////////////////// … … 100 100 char found_timer = 0; 101 101 char found_icu = 0; 102 char found_xcu = 0; 102 103 char found_dma = 0; 103 104 char found_mmc = 0; … … 122 123 123 124 unsigned int use_iob = 0; // using IOB component 124 unsigned int use_x icu = 0; // using XICU (not ICU)125 unsigned int use_xcu = 0; // using XCU (not ICU) 125 126 126 127 … … 130 131 131 132 unsigned int periph_vbase_array[PERIPH_TYPE_MAX_VALUE] 132 = { [0 ... (PERIPH_TYPE_MAX_VALUE - 1)] = 0xFFF FFFFF};133 = { [0 ... (PERIPH_TYPE_MAX_VALUE - 1)] = 0xFFF00000 }; 133 134 134 135 ////////////////////////////////////////////////////////////////////// … … 278 279 } // end getStringValue() 279 280 280 /////////////////////////////////////////////////////// 281 void set_periph_vbase_array( unsigned int vseg_index ) 282 { 283 unsigned int vbase = vseg[vseg_index]->vbase; // peripheral vbase address 284 unsigned int psegid = vseg[vseg_index]->psegid; // pseg global index 285 unsigned int type; // peripheral type 286 unsigned int periph_id; 287 288 for ( periph_id = 0 ; periph_id < header->periphs ; periph_id++) 289 { 290 if( periph[periph_id]->psegid == psegid ) 291 { 292 type = periph[periph_id]->type; 293 if ( periph_vbase_array[type] == 0xFFFFFFFF ) 294 periph_vbase_array[type] = vbase; 295 } 281 /////////////////////////////////////////////////////////////////////////////////// 282 // This function set the vbase address for all peripheral types. 283 // For replicated peripherals with the same type the virtual base address must be: 284 // vbase = seg_type_base & 0XFFF00000 + 285 // (cluster_id * vbase_cluster_increment) & 0x000FFFFF 286 void set_periph_vbase_array() 287 { 288 unsigned int vseg_id; // vseg global index 289 unsigned int periph_id; // periph global index 290 unsigned int pseg_id; // pseg global index 291 unsigned int cluster_id; // cluster global index 292 unsigned int type; // peripheral type 293 294 unsigned int msb_mask = 0xFFF00000; 295 unsigned int lsb_mask = 0x000FFFFF; 296 297 // We are looking for any vseg matching a peripheral 298 // (i.e. they are associated to the same pseg) 299 300 // scan all vsegs 301 for (vseg_id = 0 ; vseg_id < header->vsegs ; vseg_id++) 302 { 303 // keep only vseg corresponding to a periph 304 if ( vobj[vseg[vseg_id]->vobj_offset]->type == VOBJ_TYPE_PERI ) 305 { 306 pseg_id = vseg[vseg_id]->psegid; 307 cluster_id = pseg[pseg_id]->cluster; 308 309 // scan all periphs 310 for ( periph_id = 0 ; periph_id < header->periphs ; periph_id++) 311 { 312 if( periph[periph_id]->psegid == pseg_id ) // matching !!! 313 { 314 type = periph[periph_id]->type; 315 if ( periph_vbase_array[type] == 0xFFF00000 ) // vbase not set 316 { 317 periph_vbase_array[type] = vseg[vseg_id]->vbase; 318 } 319 else // vbase already set 320 { 321 // checking 12 MSB bits for replicated peripherals 322 if( (vseg[vseg_id]->vbase & msb_mask) != 323 (periph_vbase_array[type] & msb_mask) ) 324 { 325 printf("[XML ERROR] All peripherals with same type "); 326 printf(" should share the same 12 MSB for vbase address\n"); 327 printf("periph index = %d / periph type = %d / vbase = %x\n", 328 periph_id, type, vseg[vseg_id]->vbase); 329 exit(1); 330 } 331 // checking 20 LSB bits for replicated peripherals 332 if( (vseg[vseg_id]->vbase & lsb_mask) != 333 (header->increment * cluster_id) ) 334 { 335 printf("[XML ERROR] All peripherals with same type "); 336 printf(" must have the 20 LSB bits = cluster_id * increment"); 337 printf("periph index = %d / periph type = %d / vbase = %x\n", 338 periph_id, type, vseg[vseg_id]->vbase); 339 exit(1); 340 } 341 } 342 } 343 } 344 } 296 345 } 297 346 } // end set_periph_vbase_array() … … 336 385 unsigned int vobj_max = vobj_min + vspace_max; 337 386 338 for (vobj_id = vobj_min; vobj_id < vobj_max; vobj_id++) { 339 if (strcmp(vobj[vobj_id]->name, vobj_name) == 0) { 340 return (vobj_id - vobj_min); 341 } 387 for (vobj_id = vobj_min; vobj_id < vobj_max; vobj_id++) 388 { 389 if (strcmp(vobj[vobj_id]->name, vobj_name) == 0) return (vobj_id - vobj_min); 342 390 } 343 391 return -1; 344 392 } 345 393 346 347 ///////////////////////////////////////// 394 ////////////////////////////////////// 348 395 void taskNode(xmlTextReaderPtr reader) 349 396 { … … 352 399 char * str; 353 400 354 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { return; }401 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; 355 402 356 403 if (task_index >= MAX_TASKS) 357 404 { 358 405 printf("[XML ERROR] The number of tasks is larger than %d\n", MAX_TASKS); 406 exit(1); 359 407 } 360 408 … … 540 588 } // end taskNode() 541 589 542 543 590 ////////////////////////////////////// 544 591 void vobjNode(xmlTextReaderPtr reader) … … 548 595 char * str; 549 596 550 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { return; }597 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; 551 598 552 599 if (vobj_index >= MAX_VOBJS) … … 583 630 printf(" type = %s\n", str); 584 631 #endif 585 if (ok && (strcmp(str, "ELF") == 0)) 586 { 587 vobj[vobj_index]->type = VOBJ_TYPE_ELF; 588 589 assert( (vobj_count == 0) && "[XML ERROR] an ELF vobj must be alone in a vseg"); 590 } 591 else if (ok && (strcmp(str, "PERI") == 0)) 592 { 593 vobj[vobj_index]->type = VOBJ_TYPE_PERI; 594 595 assert( (vobj_count == 0) && "[XML ERROR] a PERI vobj must be alone in a vseg"); 596 597 // fill the peripheral base address array 598 set_periph_vbase_array( vseg_index ); 599 } 632 633 if (ok && (strcmp(str, "ELF") == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_ELF; } 634 else if (ok && (strcmp(str, "PERI") == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_PERI; } 600 635 else if (ok && (strcmp(str, "BLOB") == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_BLOB; } 601 636 else if (ok && (strcmp(str, "PTAB") == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_PTAB; } … … 613 648 exit(1); 614 649 } 650 // some more checking 651 if ( (vobj[vobj_index]->type == VOBJ_TYPE_ELF) || 652 (vobj[vobj_index]->type == VOBJ_TYPE_PERI) ) 653 { 654 assert( (vobj_count == 0) && 655 "[XML ERROR] an ELF or PERI vobj must be alone in a vseg"); 656 } 657 615 658 616 659 ////////// get length attribute … … 680 723 } // end vobjNode() 681 724 682 683 725 ////////////////////////////////////// 684 726 void vsegNode(xmlTextReaderPtr reader) … … 690 732 vobj_count = 0; 691 733 692 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { return; }734 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; 693 735 694 736 if (vseg_index >= MAX_VSEGS) … … 833 875 return; 834 876 } 835 else { 877 else 878 { 836 879 printf("[XML ERROR] Unknown tag %s", tag); 837 880 exit(1); … … 841 884 } // end vsegNode() 842 885 843 844 ////////////////////////////////////////// 845 void vspaceNode(xmlTextReaderPtr reader){886 //////////////////////////////////////// 887 void vspaceNode(xmlTextReaderPtr reader) 888 { 846 889 char * str; 847 890 unsigned int ok; … … 852 895 task_loc_index = 0; 853 896 854 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { 855 return; 856 } 897 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; 857 898 858 899 // checking source file consistency … … 877 918 strncpy(vspace[vspace_index]->name, str, 31); 878 919 } 879 else { 920 else 921 { 880 922 printf("[XML ERROR] illegal or missing <name> attribute for vspace %d\n", 881 923 vspace_index); … … 899 941 //used after parsing the vobjs 900 942 } 901 else { 943 else 944 { 902 945 printf("[XML ERROR] illegal or missing <startname> attribute for vspace %s\n", 903 946 vspace[vspace_index]->name); … … 925 968 // get index of the vobj containing the start vector 926 969 int index = getVobjLocId(vspace_index, str , vobj_loc_index); 927 if (index == -1) { 970 if (index == -1) 971 { 928 972 printf("[XML ERROR] vobj containing start vector not found in vspace %s\n", 929 973 vspace[vspace_index]->name); 930 exit(-1); 931 } 932 else { 974 exit(1); 975 } 976 else 977 { 933 978 vspace[vspace_index]->start_offset = index; 934 979 #if XML_PARSER_DEBUG … … 944 989 int task_max = task_min + vspace[vspace_index]->tasks; 945 990 for (task_id = task_min; task_id < task_max; task_id++) { 946 if (task[task_id]->startid >= vspace[vspace_index]->tasks) { 991 if (task[task_id]->startid >= vspace[vspace_index]->tasks) 992 { 947 993 printf("[XML ERROR] <startid> too large for task (%d,%d)\n", 948 994 vspace_index, task_id ); … … 955 1001 return; 956 1002 } 957 else { 1003 else 1004 { 958 1005 printf("[XML ERROR] Unknown tag %s", tag); 959 1006 exit(1); … … 963 1010 } // end vspaceNode() 964 1011 965 966 /////////////////////////////////////////// 967 void cpPortNode(xmlTextReaderPtr reader){1012 //////////////////////////////////////// 1013 void cpPortNode(xmlTextReaderPtr reader) 1014 { 968 1015 char * str; 969 1016 unsigned int ok; 970 1017 971 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { 972 return; 973 } 974 975 if (cp_port_index >= MAX_CP_PORTS) { 976 printf("[XML ERROR] The number of ports (for coprocs) is larger than %d\n", MAX_CP_PORTS); 1018 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; 1019 1020 if (cp_port_index >= MAX_CP_PORTS) 1021 { 1022 printf("[XML ERROR] The number of ports (for coprocs) is larger than %d\n", 1023 MAX_CP_PORTS); 1024 exit(1); 977 1025 } 978 1026 … … 984 1032 cp_port_vobj_ref[cp_port_index] = (vobj_ref_t *) malloc(sizeof(vobj_ref_t)); 985 1033 986 987 988 1034 ///////// get direction attribute 989 1035 str = getStringValue(reader, "direction", &ok); 990 if (ok) { 1036 if (ok) 1037 { 991 1038 #if XML_PARSER_DEBUG 992 1039 printf(" direction = %s\n", str); 993 1040 #endif 994 if (strcmp(str, "TO_COPROC") == 0) { 1041 if (strcmp(str, "TO_COPROC") == 0) 1042 { 995 1043 cp_port[cp_port_index]->direction = PORT_TO_COPROC; 996 1044 } 997 else if (strcmp(str, "FROM_COPROC") == 0) { 1045 else if (strcmp(str, "FROM_COPROC") == 0) 1046 { 998 1047 cp_port[cp_port_index]->direction = PORT_FROM_COPROC; 999 1048 } 1000 else { 1049 else 1050 { 1001 1051 printf("[XML ERROR] illegal <direction> for cp_port %d in cluster %d\n", 1002 1052 cp_port_index, cluster_index); … … 1004 1054 } 1005 1055 } 1006 else { 1056 else 1057 { 1007 1058 printf("[XML ERROR] missing <direction> for cp_port %d in cluster %d\n", 1008 1059 cp_port_index, cluster_index); … … 1015 1066 printf(" vspacename = %s\n", str); 1016 1067 #endif 1017 if (ok) { 1068 if (ok) 1069 { 1018 1070 strncpy(cp_port_vobj_ref[cp_port_index]->vspace_name, str, 31); 1019 1071 } 1020 else { 1072 else 1073 { 1021 1074 printf("[XML ERROR] missing <vspacename> for cp_port %d in cluster %d\n", 1022 1075 cp_port_index, cluster_index); … … 1029 1082 printf(" vobjname = %s\n", str); 1030 1083 #endif 1031 if (ok) { 1084 if (ok) 1085 { 1032 1086 strncpy(cp_port_vobj_ref[cp_port_index]->vobj_name, str, 31); 1033 1087 } 1034 else { 1088 else 1089 { 1035 1090 printf("[XML ERROR] missing <vobjname> for cp_port %d in cluster %d\n", 1036 1091 cp_port_index, cluster_index); 1037 1092 exit(1); 1038 1093 } 1039 1040 1094 cp_port_index++; 1041 1095 cp_port_loc_index++; 1042 1043 1096 } // end cpPortNode() 1044 1045 1097 1046 1098 //////////////////////////////////////// … … 1051 1103 unsigned int ok; 1052 1104 1053 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { return; }1105 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; 1054 1106 1055 1107 if (periph_index >= MAX_PERIPHS) 1056 1108 { 1057 1109 printf("[XML ERROR] The number of periphs is larger than %d\n", MAX_PERIPHS); 1110 exit(1); 1058 1111 } 1059 1112 … … 1194 1247 cma_channels = periph[periph_index]->channels; 1195 1248 } 1196 else if (header-> nic_cluster_bis == 0xFFFFFFFF)1249 else if (header->cma_cluster_bis == 0xFFFFFFFF) 1197 1250 { 1198 1251 header->cma_cluster_bis = cluster_index; … … 1221 1274 } 1222 1275 // The TIM, ICU, XICU, DMA, MEMC peripherals are replicated in all clusters 1223 // but only one componentper cluster1276 // but it must exist only one component of each type per cluster 1224 1277 else if (strcmp(str, "TIM") == 0 ) 1225 1278 { 1226 1279 periph[periph_index]->type = PERIPH_TYPE_TIM; 1227 if (found_timer || use_x icu) error = 1;1280 if (found_timer || use_xcu) error = 1; 1228 1281 found_timer = 1; 1229 1282 if (tim_channels < periph[periph_index]->channels) … … 1235 1288 { 1236 1289 periph[periph_index]->type = PERIPH_TYPE_ICU; 1237 if (found_icu ) error = 1;1290 if (found_icu || use_xcu) error = 1; 1238 1291 found_icu = 1; 1239 1292 } 1240 else if (strcmp(str, "X ICU") == 0)1241 { 1242 periph[periph_index]->type = PERIPH_TYPE_ ICU;1293 else if (strcmp(str, "XCU") == 0) 1294 { 1295 periph[periph_index]->type = PERIPH_TYPE_XCU; 1243 1296 if (found_icu || found_timer) error = 1; 1244 found_icu = 1; 1245 if (tim_channels == 0) 1246 { 1247 tim_channels = 32; 1248 } 1249 use_xicu = 1; 1297 found_xcu = 1; 1298 found_timer = 1; 1299 tim_channels = 32; 1300 use_xcu = 1; 1250 1301 } 1251 1302 else if (strcmp(str, "DMA") == 0) … … 1291 1342 } // end periphNode 1292 1343 1293 1294 ///////////////////////////////////////// 1295 void coprocNode(xmlTextReaderPtr reader){1344 //////////////////////////////////////// 1345 void coprocNode(xmlTextReaderPtr reader) 1346 { 1296 1347 char * str; 1297 1348 unsigned int ok; … … 1299 1350 cp_port_loc_index = 0; 1300 1351 1301 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { 1302 return; 1303 } 1304 1305 if (coproc_index >= MAX_COPROCS) { 1352 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; 1353 1354 if (coproc_index >= MAX_COPROCS) 1355 { 1306 1356 printf("[XML ERROR] The number of coprocs is larger than %d\n", MAX_COPROCS); 1357 exit(1); 1307 1358 } 1308 1359 … … 1315 1366 /////////// get name attribute 1316 1367 str = getStringValue(reader, "name", &ok); 1317 if (ok) { 1368 if (ok) 1369 { 1318 1370 #if XML_PARSER_DEBUG 1319 1371 printf(" name = %s\n", str); … … 1321 1373 strncpy(coproc[coproc_index]->name, str, 31); 1322 1374 } 1323 else { 1375 else 1376 { 1324 1377 printf("[XML ERROR] illegal or missing <name> for coproc %d in cluster %d\n", 1325 1378 coproc_index, cluster_index); … … 1329 1382 /////////// get psegname attribute 1330 1383 str = getStringValue(reader, "psegname", &ok); 1331 if (ok == 0) { 1384 if (ok == 0) 1385 { 1332 1386 printf("[XML ERROR] illegal or missing <psegname> for coproc %d in cluster %d\n", 1333 1387 coproc_index, cluster_index); … … 1337 1391 /////////// set psegid attribute 1338 1392 int index = getPsegId(cluster_index, str); 1339 if (index >= 0) { 1393 if (index >= 0) 1394 { 1340 1395 #if XML_PARSER_DEBUG 1341 1396 printf(" clusterid = %d\n", cluster_index); … … 1346 1401 assert(pseg[index]->type == PSEG_TYPE_PERI && "coproc psegname attribute must refer to a pseg of type PERI" ); 1347 1402 } 1348 else { 1403 else 1404 { 1349 1405 printf("[XML ERROR] pseg not found for coproc %d / clusterid = %d / psegname = %s\n", 1350 1406 coproc_index, cluster_index, str ); … … 1360 1416 1361 1417 int status = xmlTextReaderRead(reader); 1362 while (status == 1) { 1418 while (status == 1) 1419 { 1363 1420 const char * tag = (const char *) xmlTextReaderConstName(reader); 1364 1421 1365 if (strcmp(tag, "port") == 0 ) { 1422 if (strcmp(tag, "port") == 0 ) 1423 { 1366 1424 cpPortNode(reader); 1367 1425 } 1368 1426 else if (strcmp(tag, "#text") == 0 ) { } 1369 1427 else if (strcmp(tag, "#comment") == 0 ) { } 1370 else if (strcmp(tag, "coproc") == 0 ) { 1428 else if (strcmp(tag, "coproc") == 0 ) 1429 { 1371 1430 coproc[coproc_index]->ports = cp_port_loc_index; 1372 1431 cluster[cluster_index]->coprocs++; … … 1375 1434 return; 1376 1435 } 1377 else { 1436 else 1437 { 1378 1438 printf("[XML ERROR] Unknown tag %s", tag); 1379 1439 exit(1); … … 1384 1444 1385 1445 1386 /////////////////////////////////////// 1387 void irqNode(xmlTextReaderPtr reader) { 1446 ///////////////////////////////////// 1447 void irqNode(xmlTextReaderPtr reader) 1448 { 1388 1449 unsigned int ok; 1389 1450 unsigned int value; 1390 1451 char * str; 1391 1452 1392 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { 1393 return; 1394 } 1453 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; 1395 1454 1396 1455 if (irq_index >= MAX_IRQS) { … … 1406 1465 ///////// get type attribute 1407 1466 str = getStringValue(reader, "type", &ok); 1408 if (ok) { 1467 if (ok) 1468 { 1409 1469 #if XML_PARSER_DEBUG 1410 1470 printf(" type = %s\n", str); 1411 1471 #endif 1412 if (strcmp(str, "HARD") == 0 ) { 1413 irq[irq_index]->type = 0; 1414 } 1415 else { 1416 irq[irq_index]->type = 1; 1417 } 1418 } 1419 else { 1472 if (strcmp(str, "HARD") == 0 ) irq[irq_index]->type = 0; 1473 else irq[irq_index]->type = 1; 1474 } 1475 else 1476 { 1420 1477 printf("[XML ERROR] missing IRQ <type> for processor %d in cluster %d\n", 1421 1478 cluster_index, proc_loc_index); … … 1425 1482 ///////// get icuid attribute 1426 1483 value = getIntValue(reader, "icuid", &ok); 1427 if (ok) { 1484 if (ok) 1485 { 1428 1486 #if XML_PARSER_DEBUG 1429 1487 printf(" icuid = %d\n", value); 1430 1488 #endif 1431 1489 irq[irq_index]->icuid = value; 1432 if (value >= 32) { 1490 if (value >= 32) 1491 { 1433 1492 printf("[XML ERROR] IRQ <icuid> too large for processor %d in cluster %d\n", 1434 1493 cluster_index, proc_loc_index); … … 1436 1495 } 1437 1496 } 1438 else { 1497 else 1498 { 1439 1499 printf("[XML ERROR] missing IRQ <icuid> for processor %d in cluster %d\n", 1440 1500 cluster_index, proc_loc_index); … … 1444 1504 ///////// get isr attribute 1445 1505 str = getStringValue(reader, "isr", &ok); 1446 if (ok) { 1506 if (ok) 1507 { 1447 1508 #if XML_PARSER_DEBUG 1448 1509 printf(" isr = %s\n", str); … … 1453 1514 else if (strcmp(str, "ISR_TTY" ) == 0) { irq[irq_index]->isr = ISR_TTY; } 1454 1515 else if (strcmp(str, "ISR_TIMER" ) == 0) { irq[irq_index]->isr = ISR_TIMER; } 1455 else { 1516 else 1517 { 1456 1518 printf("[XML ERROR] illegal IRQ <isr> for processor %d in cluster %d\n", 1457 1519 cluster_index, proc_loc_index); … … 1462 1524 #endif 1463 1525 } 1464 else { 1526 else 1527 { 1465 1528 printf("[XML ERROR] missing IRQ <isr> for processor %d in cluster %d\n", 1466 1529 cluster_index, proc_loc_index); … … 1470 1533 ///////// get channel attribute (optionnal : 0 if missing) 1471 1534 value = getIntValue(reader, "channel", &ok); 1472 if (ok) { 1535 if (ok) 1536 { 1473 1537 #if XML_PARSER_DEBUG 1474 1538 printf(" channel = %d\n", value); … … 1476 1540 irq[irq_index]->channel = value; 1477 1541 } 1478 else { 1542 else 1543 { 1479 1544 irq[irq_index]->channel = 0; 1480 1545 } … … 1486 1551 1487 1552 1488 ///////////////////////////////////////// 1489 void procNode(xmlTextReaderPtr reader) { 1553 ////////////////////////////////////// 1554 void procNode(xmlTextReaderPtr reader) 1555 { 1490 1556 unsigned int ok; 1491 1557 unsigned int value; … … 1493 1559 irq_loc_index = 0; 1494 1560 1495 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { 1496 return; 1497 } 1498 1499 if (proc_index >= MAX_PROCS) { 1561 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; 1562 1563 if (proc_index >= MAX_PROCS) 1564 { 1500 1565 printf("[XML ERROR] The number of procs is larger than %d\n", MAX_PROCS); 1566 exit(1); 1501 1567 } 1502 1568 … … 1506 1572 1507 1573 proc[proc_index] = (mapping_proc_t *) malloc(sizeof(mapping_proc_t)); 1508 1509 1574 1510 1575 /////////// get index attribute (optional) 1511 1576 value = getIntValue(reader, "index", &ok); 1512 if (ok && (value != proc_loc_index)) { 1577 if (ok && (value != proc_loc_index)) 1578 { 1513 1579 printf("[XML ERROR] wrong proc index / expected value is %d", 1514 1580 proc_loc_index); … … 1524 1590 1525 1591 int status = xmlTextReaderRead(reader); 1526 while (status == 1) { 1592 while (status == 1) 1593 { 1527 1594 const char * tag = (const char *) xmlTextReaderConstName(reader); 1528 1595 1529 if (strcmp(tag, "irq") == 0) { 1596 if (strcmp(tag, "irq") == 0) 1597 { 1530 1598 irqNode(reader); 1531 1599 } 1532 1600 else if (strcmp(tag, "#text") == 0) { } 1533 1601 else if (strcmp(tag, "#comment") == 0) { } 1534 else if (strcmp(tag, "proc") == 0) { 1602 else if (strcmp(tag, "proc") == 0) 1603 { 1535 1604 proc[proc_index]->irqs = irq_loc_index; 1536 1605 cluster[cluster_index]->procs++; … … 1539 1608 return; 1540 1609 } 1541 else { 1610 else 1611 { 1542 1612 printf("[XML ERROR] Unknown tag %s", tag); 1543 1613 exit(1); … … 1548 1618 1549 1619 1550 ////////////////////////////////////////// 1551 void psegNode(xmlTextReaderPtr reader) { 1620 ////////////////////////////////////// 1621 void psegNode(xmlTextReaderPtr reader) 1622 { 1552 1623 unsigned int ok; 1553 1624 paddr_t ll_value; 1554 1625 char * str; 1555 1626 1556 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { 1557 return; 1558 } 1559 1560 if (pseg_index >= MAX_PSEGS) { 1627 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; 1628 1629 if (pseg_index >= MAX_PSEGS) 1630 { 1561 1631 printf("[XML ERROR] The number of psegs is larger than %d\n", MAX_PSEGS); 1562 1632 exit(1); … … 1574 1644 printf(" name = %s\n", str); 1575 1645 #endif 1576 if (ok) { 1646 if (ok) 1647 { 1577 1648 strncpy(pseg[pseg_index]->name, str, 31); 1578 1649 } 1579 else { 1650 else 1651 { 1580 1652 printf("[XML ERROR] illegal or missing <name> for pseg %d in cluster %d\n", 1581 1653 pseg_index, cluster_index); … … 1591 1663 else if (ok && (strcmp(str, "ROM" ) == 0)) { pseg[pseg_index]->type = PSEG_TYPE_ROM; } 1592 1664 else if (ok && (strcmp(str, "PERI") == 0)) { pseg[pseg_index]->type = PSEG_TYPE_PERI; } 1593 else { 1665 else 1666 { 1594 1667 printf("[XML ERROR] illegal or missing <type> for pseg %s in cluster %d\n", 1595 1668 pseg[pseg_index]->name, cluster_index); … … 1602 1675 printf(" base = 0x%llx\n", ll_value); 1603 1676 #endif 1604 if (ok) { 1677 if (ok) 1678 { 1605 1679 pseg[pseg_index]->base = ll_value; 1606 1680 } … … 1616 1690 printf(" length = 0x%llx\n", ll_value); 1617 1691 #endif 1618 if (ok) { 1692 if (ok) 1693 { 1619 1694 pseg[pseg_index]->length = ll_value; 1620 1695 } 1621 else { 1696 else 1697 { 1622 1698 printf("[XML ERROR] illegal or missing <length> for pseg %s in cluster %d\n", 1623 1699 pseg[pseg_index]->name, cluster_index); … … 1659 1735 found_timer = 0; 1660 1736 found_icu = 0; 1737 found_xcu = 0; 1661 1738 found_dma = 0; 1662 1739 found_mmc = 0; … … 1667 1744 1668 1745 // checking source file consistency 1669 if (cluster_index >= header->clusters) { 1746 if (cluster_index >= header->clusters) 1747 { 1670 1748 printf("[XML ERROR] The cluster index is too large : %d\n", cluster_index); 1671 1749 exit(1); … … 1679 1757 /////////// check cluster index attribute (optional) 1680 1758 value = getIntValue(reader, "index", &ok); 1681 if (ok && (value != cluster_index)) { 1759 if (ok && (value != cluster_index)) 1760 { 1682 1761 printf("[XML ERROR] wrong cluster index / expected value is %d", 1683 1762 cluster_index); … … 1714 1793 { 1715 1794 1716 ///////// ///////// peripherals checks /////////////////////////1717 if ( (found_timer && use_xicu) || (!found_timer && !use_xicu))1718 { 1719 printf("[XML ERROR] illegal ormissing timer peripheral in cluster %d\n", cluster_index);1795 ///////// TIMER and ICU peripheral are mandatory ////////////// 1796 if (!found_timer && !found_xcu) 1797 { 1798 printf("[XML ERROR] missing timer peripheral in cluster %d\n", cluster_index); 1720 1799 exit(1); 1721 1800 } 1722 1801 1723 if (!found_icu )1724 { 1725 printf("[XML ERROR] illegal ormissing icu peripheral in cluster %d\n", cluster_index);1802 if (!found_icu && !found_xcu) 1803 { 1804 printf("[XML ERROR] missing icu peripheral in cluster %d\n", cluster_index); 1726 1805 exit(1); 1727 1806 } 1728 1729 if (!found_dma)1730 {1731 printf("[XML ERROR] illegal or missing dma peripheral in cluster %d\n", cluster_index);1732 exit(1);1733 }1734 1735 1807 1736 1808 if (nb_proc_max < cluster[cluster_index]->procs) … … 1757 1829 void clusterSetNode(xmlTextReaderPtr reader) 1758 1830 { 1759 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { return; }1831 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; 1760 1832 1761 1833 #if XML_PARSER_DEBUG … … 1798 1870 return; 1799 1871 } 1800 else { 1872 else 1873 { 1801 1874 printf("[XML ERROR] Unknown tag in clusterset node : %s",tag); 1802 1875 exit(1); … … 1807 1880 1808 1881 1809 ///////////////////////////////////////////// 1810 void globalSetNode(xmlTextReaderPtr reader) { 1811 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { 1812 return; 1813 } 1882 /////////////////////////////////////////// 1883 void globalSetNode(xmlTextReaderPtr reader) 1884 { 1885 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; 1814 1886 1815 1887 #if XML_PARSER_DEBUG … … 1825 1897 else if (strcmp(tag, "#text") == 0) { } 1826 1898 else if (strcmp(tag, "#comment") == 0) { } 1827 else if (strcmp(tag, "globalset") == 0) { 1899 else if (strcmp(tag, "globalset") == 0) 1900 { 1828 1901 #if XML_PARSER_DEBUG 1829 1902 printf(" end global set\n\n"); … … 1833 1906 return; 1834 1907 } 1835 else { 1908 else 1909 { 1836 1910 printf("[XML ERROR] Unknown tag in globalset node : %s",tag); 1837 1911 exit(1); … … 1842 1916 1843 1917 1844 ///////////////////////////////////////////// 1845 void vspaceSetNode(xmlTextReaderPtr reader) { 1918 /////////////////////////////////////////// 1919 void vspaceSetNode(xmlTextReaderPtr reader) 1920 { 1846 1921 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { 1847 1922 return; … … 1861 1936 else if (strcmp(tag, "#text" ) == 0 ) { } 1862 1937 else if (strcmp(tag, "#comment" ) == 0 ) { } 1863 else if (strcmp(tag, "vspaceset") == 0 ) { 1938 else if (strcmp(tag, "vspaceset") == 0 ) 1939 { 1864 1940 // checking source file consistency 1865 if (vspace_index != header->vspaces) { 1941 if (vspace_index != header->vspaces) 1942 { 1866 1943 printf("[XML ERROR] Wrong number of vspaces\n"); 1867 1944 exit(1); 1868 1945 } 1869 else { 1946 else 1947 { 1870 1948 header->vsegs = vseg_index; 1871 1949 header->vobjs = vobj_index; … … 1874 1952 } 1875 1953 } 1876 else { 1954 else 1955 { 1877 1956 printf("[XML ERROR] Unknown tag in vspaceset node : %s",tag); 1878 1957 exit(1); … … 1883 1962 1884 1963 1885 //////////////////////////////////////// //1964 //////////////////////////////////////// 1886 1965 void headerNode(xmlTextReaderPtr reader) 1887 1966 { … … 1890 1969 unsigned int ok; 1891 1970 1892 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { return; }1971 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; 1893 1972 1894 1973 #if XML_PARSER_DEBUG … … 1900 1979 ////////// get name attribute 1901 1980 name = getStringValue(reader, "name", &ok); 1902 if (ok) { 1981 if (ok) 1982 { 1903 1983 #if XML_PARSER_DEBUG 1904 1984 printf(" name = %s\n", name); … … 1906 1986 strncpy( header->name, name, 31); 1907 1987 } 1908 else { 1988 else 1989 { 1909 1990 printf("[XML ERROR] illegal or missing <name> attribute in header\n"); 1910 1991 exit(1); … … 1913 1994 /////////// get cluster_x attribute 1914 1995 cluster_x = getIntValue(reader, "cluster_x", &ok); 1915 if (ok) { 1996 if (ok) 1997 { 1916 1998 #if XML_PARSER_DEBUG 1917 1999 printf(" cluster_x = %d\n", cluster_x); … … 1919 2001 header->cluster_x = cluster_x; 1920 2002 } 1921 else { 2003 else 2004 { 1922 2005 printf("[XML ERROR] illegal or missing <cluster_x> attribute in header\n"); 1923 2006 exit(1); … … 1926 2009 /////////// get cluster_y attribute 1927 2010 cluster_y = getIntValue(reader, "cluster_y", &ok); 1928 if (ok) { 2011 if (ok) 2012 { 1929 2013 #if XML_PARSER_DEBUG 1930 2014 printf(" cluster_y = %d\n", cluster_y); … … 1932 2016 header->cluster_y = cluster_y; 1933 2017 } 1934 else { 2018 else 2019 { 1935 2020 printf("[XML ERROR] illegal or missing <cluster_y> attribute in header\n"); 1936 2021 exit(1); … … 1939 2024 //check the number of cluster 1940 2025 value = cluster_x * cluster_y; 1941 if (value >= MAX_CLUSTERS) { 2026 if (value >= MAX_CLUSTERS) 2027 { 1942 2028 printf("[XML ERROR] The number of clusters is larger than %d\n", MAX_CLUSTERS); 1943 2029 exit(1); … … 1952 2038 ///////// get vspaces attribute 1953 2039 value = getIntValue(reader, "vspaces", &ok); 1954 if (ok) { 1955 if (value >= MAX_VSPACES) { 2040 if (ok) 2041 { 2042 if (value >= MAX_VSPACES) 2043 { 1956 2044 printf("[XML ERROR] The number of vspaces is larger than %d\n", MAX_VSPACES); 1957 2045 exit(1); … … 1962 2050 header->vspaces = value; 1963 2051 } 1964 else { 2052 else 2053 { 1965 2054 printf("[XML ERROR] illegal or missing <vspaces> attribute in mapping\n"); 2055 exit(1); 2056 } 2057 2058 ///////// get increment attribute 2059 value = getIntValue(reader, "increment", &ok); 2060 if (ok) 2061 { 2062 if ( (value != 0x10000) && (value != 0x8000) && 2063 (value != 0x4000) && (value != 0x2000) ) 2064 2065 { 2066 printf("[XML ERROR] The vseg increment must be one of the following: "); 2067 printf(" 0x00010000 / 0x00008000 / 0x00004000 / 0x00002000"); 2068 exit(1); 2069 } 2070 #if XML_PARSER_DEBUG 2071 printf(" increment = %d\n", value); 2072 #endif 2073 header->increment = value; 2074 } 2075 else 2076 { 2077 printf("[XML ERROR] illegal or missing <increment> attribute in mapping\n"); 1966 2078 exit(1); 1967 2079 } … … 1985 2097 1986 2098 int status = xmlTextReaderRead(reader); 1987 while (status == 1) { 2099 while (status == 1) 2100 { 1988 2101 const char * tag = (const char *) xmlTextReaderConstName(reader); 1989 2102 1990 if (strcmp(tag, "clusterset") == 0) { 2103 if (strcmp(tag, "clusterset") == 0) 2104 { 1991 2105 clusterSetNode(reader); 1992 2106 } … … 1995 2109 else if (strcmp(tag, "#text") == 0) { } 1996 2110 else if (strcmp(tag, "#comment") == 0) { } 1997 else if (strcmp(tag, "mapping_info") == 0) { 2111 else if (strcmp(tag, "mapping_info") == 0) 2112 { 1998 2113 #if XML_PARSER_DEBUG 1999 2114 printf("end mapping_info\n"); … … 2001 2116 return; 2002 2117 } 2003 else { 2118 else 2119 { 2004 2120 printf("[XML ERROR] Unknown tag in header node : %s\n",tag); 2005 2121 exit(1); … … 2012 2128 /////////////////////////////////////// 2013 2129 void BuildTable(int fdout, const char * type, unsigned int nb_elem, 2014 unsigned int elem_size, char ** table) { 2130 unsigned int elem_size, char ** table) 2131 { 2015 2132 unsigned int i; 2016 2133 // write element … … 2027 2144 } 2028 2145 2029 2030 int open_file(const char * file_path) {2031 2146 ///////////////////////////////////// 2147 int open_file(const char * file_path) 2148 { 2032 2149 //open file 2033 2150 int fdout = open( file_path, (O_CREAT | O_RDWR), (S_IWUSR | S_IRUSR) ); 2034 if (fdout < 0) { 2151 if (fdout < 0) 2152 { 2035 2153 perror("open"); 2036 2154 exit(1); … … 2038 2156 2039 2157 //reinitialise the file 2040 if (ftruncate(fdout, 0)) { 2158 if (ftruncate(fdout, 0)) 2159 { 2041 2160 perror("truncate"); 2042 2161 exit(1); … … 2051 2170 2052 2171 2053 /////////////////////////// 2054 void buildBin(const char * file_path) { 2172 ///////////////////////////////////// 2173 void buildBin(const char * file_path) 2174 { 2055 2175 unsigned int length; 2056 2176 2057 2177 int fdout = open_file(file_path); 2178 2179 #if XML_PARSER_DEBUG 2180 printf("Building map.bin for %s\n", header->name); 2181 printf("signature = %x\n", header->signature); 2182 printf("clusters = %d\n", header->clusters); 2183 printf("vspaces = %d\n", header->vspaces); 2184 printf("psegs = %d\n", header->psegs); 2185 printf("vobjs = %d\n", header->vobjs); 2186 printf("vsegs = %d\n", header->vsegs); 2187 printf("tasks = %d\n", header->tasks); 2188 printf("procs = %d\n", header->procs); 2189 printf("irqs = %d\n", header->irqs); 2190 printf("coprocs = %d\n", header->coprocs); 2191 printf("periphs = %d\n", header->periphs); 2192 #endif 2058 2193 2059 2194 // write header to binary file 2060 2195 length = write(fdout, (char *) header, sizeof(mapping_header_t)); 2061 if (length != sizeof(mapping_header_t)) { 2196 if (length != sizeof(mapping_header_t)) 2197 { 2062 2198 printf("write header error : length = %d \n", length); 2063 2199 exit(1); … … 2160 2296 int fdout = open_file(file_path); 2161 2297 2162 char * prol = "/* Generated from the mapping_info file */\n\n"; 2163 char * ifdef = "#ifndef _HD_CONFIG_H\n#define _HD_CONFIG_H\n\n"; 2164 char * epil = "\n#endif //_HD_CONFIG_H"; 2298 char prol[80]; 2299 sprintf(prol, "/* Generated from file %s.xml */\n\n",header->name); 2300 2301 char * ifdef = "#ifndef _HARD_CONFIG_H\n#define _HARDD_CONFIG_H\n\n"; 2302 char * epil = "\n#endif //_HARD_CONFIG_H"; 2165 2303 2166 2304 file_write(fdout, prol); … … 2187 2325 file_write(fdout, "\n"); 2188 2326 2189 def_int_write(fdout, "USE_XICU ", use_x icu);2327 def_int_write(fdout, "USE_XICU ", use_xcu); 2190 2328 def_int_write(fdout, "USE_IOB ", use_iob); 2191 2329 … … 2210 2348 unsigned int vseg_id; 2211 2349 2212 char * prol = "/* Generated from the mapping_info file */\n\n"; 2350 char prol[80]; 2351 sprintf(prol, "/* Generated from file %s.xml */\n\n",header->name); 2352 2213 2353 file_write(fdout, prol); 2214 2354 … … 2273 2413 file_write(fdout, "\n"); 2274 2414 2415 // fill the peripheral base address array 2416 set_periph_vbase_array(); 2417 2275 2418 // non replicated peripherals 2276 2419 ld_write(fdout, "seg_cma_base ", periph_vbase_array[PERIPH_TYPE_CMA]); … … 2285 2428 2286 2429 // replicated peripherals 2430 ld_write(fdout, "seg_xcu_base ", periph_vbase_array[PERIPH_TYPE_XCU]); 2287 2431 ld_write(fdout, "seg_icu_base ", periph_vbase_array[PERIPH_TYPE_ICU]); 2288 2432 ld_write(fdout, "seg_tim_base ", periph_vbase_array[PERIPH_TYPE_TIM]); 2289 2433 ld_write(fdout, "seg_dma_base ", periph_vbase_array[PERIPH_TYPE_DMA]); 2290 2434 ld_write(fdout, "seg_mmc_base ", periph_vbase_array[PERIPH_TYPE_MMC]); 2435 2436 file_write(fdout, "\n"); 2437 2438 ld_write(fdout, "vseg_cluster_increment ", header->increment); 2291 2439 2292 2440 close(fdout); … … 2323 2471 } 2324 2472 2325 2326 2473 char * map_path = buildPath(argv[2], "map.bin"); 2327 2474 char * ld_path = buildPath(argv[2], "giet_vsegs.ld"); … … 2333 2480 xmlTextReaderPtr reader = xmlReaderForFile(argv[1], NULL, 0); 2334 2481 2335 if (reader != NULL) { 2482 if (reader != NULL) 2483 { 2336 2484 status = xmlTextReaderRead (reader); 2337 while (status == 1) { 2485 while (status == 1) 2486 { 2338 2487 const char * tag = (const char *) xmlTextReaderConstName(reader); 2339 2488 2340 if (strcmp(tag, "mapping_info") == 0) { 2489 if (strcmp(tag, "mapping_info") == 0) 2490 { 2341 2491 headerNode(reader); 2342 2492 prepareBuild(); … … 2345 2495 genLd(ld_path); 2346 2496 } 2347 else { 2497 else 2498 { 2348 2499 printf("[XML ERROR] Wrong file type: \"%s\"\n", argv[1]); 2349 2500 return 1; … … 2353 2504 xmlFreeTextReader(reader); 2354 2505 2355 if (status != 0) { 2506 if (status != 0) 2507 { 2356 2508 printf("[XML ERROR] Wrong Syntax in \"%s\" file\n", argv[1]); 2357 2509 return 1;
Note: See TracChangeset
for help on using the changeset viewer.