//////////////////////////////////////////////////////////////////////////// // File : xml_driver.c // Date : 04/04/2012 // Author : alain greiner // Copyright (c) UPMC-LIP6 //////////////////////////////////////////////////////////////////////////// // This program translate a binary file containing a MAPPING_INFO // data structure to an xml file. //////////////////////////////////////////////////////////////////////////// #include #include #include #include #include #include #include ///////////////////////////////////////////////////// void buildXml( mapping_header_t* header, FILE* fpout) { const char* vobj_type[] = { "ELF", "PTAB", //page table "PERI", //hardware component "MWMR", //MWMR channel "LOCK", //Lock "BUFFER", //Any "no intialiasation needed" objects (stacks...) "BARRIER" //Barrier }; const char* mode_str[] = { "____", "___U", "__W_", "__WU", "_X__", "_X_U", "_XW_", "_XWU", "C___", "C__U", "C_W_", "C_WU", "CX__", "CX_U", "CXW_", "CXWU" }; unsigned int vspace_id; unsigned int cluster_id; unsigned int pseg_id; unsigned int vseg_id; unsigned int vobj_id; unsigned int task_id; mapping_cluster_t* cluster; mapping_pseg_t* pseg; mapping_vspace_t* vspace; mapping_vseg_t* vseg; mapping_vobj_t* vobj; mapping_task_t* task; // computes the base adresss for clusters array, cluster = (mapping_cluster_t*)((char*)header + MAPPING_HEADER_SIZE ); // computes the base adresss for psegs array, pseg = (mapping_pseg_t*) ((char*)header + MAPPING_HEADER_SIZE + MAPPING_CLUSTER_SIZE*header->clusters ); // computes the base adresss for vspaces array, vspace = (mapping_vspace_t*) ((char*)header + MAPPING_HEADER_SIZE + MAPPING_CLUSTER_SIZE*header->clusters + MAPPING_PSEG_SIZE*header->psegs ); // computes the base adresss for vsegs array, vseg = (mapping_vseg_t*) ((char*)header + MAPPING_HEADER_SIZE + MAPPING_CLUSTER_SIZE*header->clusters + MAPPING_PSEG_SIZE*header->psegs + MAPPING_VSPACE_SIZE*header->vspaces ); // computes the base adresss for vobjs array, vobj = (mapping_vobj_t*) ((char*)header + MAPPING_HEADER_SIZE + MAPPING_CLUSTER_SIZE*header->clusters + MAPPING_PSEG_SIZE*header->psegs + MAPPING_VSPACE_SIZE*header->vspaces + MAPPING_VSEG_SIZE*header->vsegs ); // computes the base address for tasks array task = (mapping_task_t*) ((char*)header + MAPPING_HEADER_SIZE + MAPPING_CLUSTER_SIZE*header->clusters + MAPPING_PSEG_SIZE*header->psegs + MAPPING_VSPACE_SIZE*header->vspaces + MAPPING_VOBJ_SIZE*header->vobjs + MAPPING_VSEG_SIZE*header->vsegs ); fprintf( fpout, "\n\n"); ///////////////////////// header ///////////////////////////////////////////// fprintf( fpout, "signature); fprintf( fpout, " name = \"%s\"\n", header->name); fprintf( fpout, " clusters = \"%d\"\n", header->clusters); fprintf( fpout, " psegs = \"%d\"\n", header->psegs); fprintf( fpout, " ttys = \"%d\"\n", header->ttys); fprintf( fpout, " fbs = \"%d\"\n", header->fbs); fprintf( fpout, " vspaces = \"%d\"\n", header->vspaces); fprintf( fpout, " globals = \"%d\" >\n\n", header->globals); ///////////////////// clusters /////////////////////////////////////////////// fprintf( fpout, " \n" ); for ( cluster_id = 0 ; cluster_id < header->clusters ; cluster_id++ ) { fprintf( fpout, " \n\n", cluster[cluster_id].procs); } fprintf( fpout, " \n" ); //////////////////// psegs /////////////////////////////////////////////////// fprintf( fpout, " \n" ); for ( pseg_id = 0 ; pseg_id < header->psegs ; pseg_id++ ) { fprintf( fpout, " \n\n", pseg[pseg_id].length); } fprintf( fpout, " \n" ); /////////////////// globals ///////////////////////////////////////////////// fprintf( fpout, " \n" ); for ( vseg_id = 0 ; vseg_id < header->globals ; vseg_id++ ) { unsigned int pseg_id = vseg[vseg_id].psegid; fprintf( fpout, " \n", vseg[vseg_id].ident); for ( vobj_id = vseg[vseg_id].vobj_offset; vobj_id < (vseg[vseg_id].vobj_offset + vseg[vseg_id].vobjs); vobj_id++ ) { fprintf( fpout, " \n", vobj[vobj_id].binpath); } fprintf( fpout, " \n\n"); } fprintf( fpout, " \n" ); //////////////////// vspaces //////////////////////////////////////////////// fprintf( fpout, " \n" ); for ( vspace_id = 0 ; vspace_id < header->vspaces ; vspace_id++ ) { unsigned int func_id = vspace[vspace_id].vobj_offset + vspace[vspace_id].start_offset; fprintf( fpout, " \n\n", vobj[func_id].name); for ( vseg_id = vspace[vspace_id].vseg_offset ; vseg_id < (vspace[vspace_id].vseg_offset + vspace[vspace_id].vsegs) ; vseg_id++ ) { unsigned int pseg_id = vseg[vseg_id].psegid; fprintf( fpout, " \n", vseg[vseg_id].ident); for ( vobj_id = vseg[vseg_id].vobj_offset ; vobj_id < (vseg[vseg_id].vobj_offset + vseg[vseg_id].vobjs) ; vobj_id++ ) { fprintf( fpout, " \n", vobj[vobj_id].binpath); } fprintf( fpout, " \n\n"); } for ( task_id = vspace[vspace_id].task_offset ; task_id < (vspace[vspace_id].task_offset + vspace[vspace_id].tasks) ; task_id++ ) { unsigned int vobj_id = task[task_id].vobjlocid + vspace[vspace_id].vobj_offset; fprintf( fpout, " \n\n", task[task_id].use_fb); } fprintf( fpout, " \n\n"); } fprintf( fpout, " \n" ); fprintf( fpout, "\n"); } // end buildXml() ///////////////////////////////////// int main ( int argc, char* argv[] ) { if ( argc < 2 ) { printf("Usage: bin2xml \n"); return 1; } unsigned int bin[0x10000]; // 64 K int = 256 Kbytes int fdin = open( argv[1], O_RDONLY ); if (fdin < 0) { perror("open"); exit(1); } FILE* fpout = fopen( argv[2], "w" ); if (fpout == NULL) { perror("open"); exit(1); } unsigned int length = read(fdin, bin, 0x40000); if ( length <= 0 ) { perror("read"); exit(1); } if ( bin[0] == IN_MAPPING_SIGNATURE ) { buildXml( (mapping_header_t*)bin, fpout ); } else { printf("[ERROR] Wrong file format\n"); exit(1); } return 0; } // end main()