//////////////////////////////////////////////////////////////////////////// // 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", // binary code generated by GCC "BLOB", // binary code generated by GCC "PTAB", // page table "PERI", // hardware component "MWMR", // MWMR channel "LOCK", // Spin-Lock "BUFFER", // Any "no intialiasation needed" objects (stacks...) "BARRIER", // Barrier }; const char* pseg_type[] = { "RAM", "ROM", "PERI", }; const char* irq_type[] = { "HARD", "SOFT", }; const char* isr_type[] = { "ISR_DEFAULT", "ISR_SWITCH", "ISR_TTY", "ISR_DMA", "ISR_IOC", "ISR_TIMER", }; const char* periph_type[] = { "IOC", "TTY", "TIM", "DMA", "FBF", "NIC", "IOB", }; const char* port_direction[] = { "TO_COPROC", "FROM_COPROC", }; 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; unsigned int proc_id; unsigned int irq_id; unsigned int coproc_id; unsigned int port_id; unsigned int periph_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; mapping_proc_t* proc; mapping_irq_t* irq; mapping_coproc_t* coproc; mapping_cp_port_t* cp_port; mapping_periph_t* periph; // 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 ); // computes the base address for procs array proc = (mapping_proc_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 + MAPPING_TASK_SIZE*header->tasks); // computes the base address for irqs array irq = (mapping_irq_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 + MAPPING_TASK_SIZE*header->tasks + MAPPING_PROC_SIZE*header->procs); // computes the base address for coprocs array coproc = (mapping_coproc_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 + MAPPING_TASK_SIZE*header->tasks + MAPPING_PROC_SIZE*header->procs + MAPPING_IRQ_SIZE*header->irqs); // computes the base address for cp_ports array cp_port = (mapping_cp_port_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 + MAPPING_TASK_SIZE*header->tasks + MAPPING_PROC_SIZE*header->procs + MAPPING_IRQ_SIZE*header->irqs + MAPPING_COPROC_SIZE*header->coprocs); // computes the base address for periphs array periph = (mapping_periph_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 + MAPPING_TASK_SIZE*header->tasks + MAPPING_PROC_SIZE*header->procs + MAPPING_IRQ_SIZE*header->irqs + MAPPING_COPROC_SIZE*header->coprocs + MAPPING_CP_PORT_SIZE*header->cp_ports); ///////////////////////// header ///////////////////////////////////////////// fprintf( fpout, "\n\n"); fprintf( fpout, "signature); fprintf( fpout, " name = \"%s\"\n", header->name); fprintf( fpout, " clusters = \"%d\"\n", header->clusters); 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", cluster_id); for ( pseg_id = cluster[cluster_id].pseg_offset ; pseg_id < cluster[cluster_id].pseg_offset + cluster[cluster_id].psegs ; pseg_id++ ) { fprintf( fpout, " \n", pseg[pseg_id].length); } ///////////////////// processors ///////////////////////////////////////////// for ( proc_id = cluster[cluster_id].proc_offset ; proc_id < cluster[cluster_id].proc_offset + cluster[cluster_id].procs ; proc_id++ ) { fprintf( fpout, " \n", proc_id); for ( irq_id = proc[proc_id].irq_offset ; irq_id < proc[proc_id].irq_offset + proc[proc_id].irqs ; irq_id++ ) { fprintf( fpout, " \n", irq[irq_id].channel); } fprintf( fpout, " \n" ); } ///////////////////// coprocessors /////////////////////////////////////////// for ( coproc_id = cluster[cluster_id].coproc_offset ; coproc_id < cluster[cluster_id].coproc_offset + cluster[cluster_id].coprocs ; coproc_id++ ) { fprintf( fpout, " \n", pseg[coproc[coproc_id].psegid].name); for ( port_id = coproc[coproc_id].port_offset ; port_id < coproc[coproc_id].port_offset + coproc[coproc_id].ports ; port_id++ ) { unsigned int vobj_id = cp_port[port_id].vobjlocid + vspace[cp_port[port_id].vspaceid].vobj_offset; fprintf( fpout, " \n", vobj[vobj_id].name); } fprintf( fpout, " \n" ); } ///////////////////// periphs /////////////////////////////////////////////// for ( periph_id = cluster[cluster_id].periph_offset ; periph_id < cluster[cluster_id].periph_offset + cluster[cluster_id].periphs ; periph_id++ ) { fprintf( fpout, " \n", periph[periph_id].channels); } fprintf( fpout, " \n" ); } fprintf( fpout, " \n\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"); } fprintf( fpout, " \n" ); //////////////////// vspaces //////////////////////////////////////////////// fprintf( fpout, "\n \n\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"); } 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_fbdma); } 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()