[158] | 1 | //////////////////////////////////////////////////////////////////////////// |
---|
| 2 | // File : xml_driver.c |
---|
| 3 | // Date : 04/04/2012 |
---|
| 4 | // Author : alain greiner |
---|
| 5 | // Copyright (c) UPMC-LIP6 |
---|
| 6 | //////////////////////////////////////////////////////////////////////////// |
---|
| 7 | // This program translate a binary file containing a MAPPING_INFO |
---|
| 8 | // data structure to an xml file. |
---|
| 9 | //////////////////////////////////////////////////////////////////////////// |
---|
| 10 | |
---|
| 11 | #include <stdlib.h> |
---|
| 12 | #include <fcntl.h> |
---|
| 13 | #include <unistd.h> |
---|
| 14 | #include <stdio.h> |
---|
| 15 | #include <string.h> |
---|
| 16 | #include <stdint.h> |
---|
| 17 | #include <mapping_info.h> |
---|
| 18 | |
---|
| 19 | ///////////////////////////////////////////////////// |
---|
| 20 | void buildXml( mapping_header_t* header, FILE* fpout) |
---|
| 21 | { |
---|
[160] | 22 | |
---|
| 23 | const char* |
---|
| 24 | vobj_type[] = |
---|
| 25 | { |
---|
| 26 | "ELF", |
---|
| 27 | "PTAB", //page table |
---|
| 28 | "PERI", //hardware component |
---|
| 29 | "MWMR", //MWMR channel |
---|
| 30 | "LOCK", //Lock |
---|
| 31 | "BUFFER", //Any "no intialiasation needed" objects (stacks...) |
---|
| 32 | "BARRIER" //Barrier |
---|
| 33 | }; |
---|
[158] | 34 | const char* mode_str[] = { "____", |
---|
| 35 | "___U", |
---|
| 36 | "__W_", |
---|
| 37 | "__WU", |
---|
| 38 | "_X__", |
---|
| 39 | "_X_U", |
---|
| 40 | "_XW_", |
---|
| 41 | "_XWU", |
---|
| 42 | "C___", |
---|
| 43 | "C__U", |
---|
| 44 | "C_W_", |
---|
| 45 | "C_WU", |
---|
| 46 | "CX__", |
---|
| 47 | "CX_U", |
---|
| 48 | "CXW_", |
---|
| 49 | "CXWU" }; |
---|
| 50 | |
---|
| 51 | unsigned int vspace_id; |
---|
| 52 | unsigned int cluster_id; |
---|
| 53 | unsigned int pseg_id; |
---|
| 54 | unsigned int vseg_id; |
---|
[160] | 55 | unsigned int vobj_id; |
---|
[158] | 56 | unsigned int task_id; |
---|
| 57 | |
---|
| 58 | mapping_cluster_t* cluster; |
---|
| 59 | mapping_pseg_t* pseg; |
---|
| 60 | mapping_vspace_t* vspace; |
---|
| 61 | mapping_vseg_t* vseg; |
---|
[160] | 62 | mapping_vobj_t* vobj; |
---|
[158] | 63 | mapping_task_t* task; |
---|
| 64 | |
---|
| 65 | // computes the base adresss for clusters array, |
---|
| 66 | cluster = (mapping_cluster_t*)((char*)header + |
---|
| 67 | MAPPING_HEADER_SIZE ); |
---|
| 68 | |
---|
| 69 | // computes the base adresss for psegs array, |
---|
| 70 | pseg = (mapping_pseg_t*) ((char*)header + |
---|
| 71 | MAPPING_HEADER_SIZE + |
---|
| 72 | MAPPING_CLUSTER_SIZE*header->clusters ); |
---|
| 73 | |
---|
| 74 | // computes the base adresss for vspaces array, |
---|
| 75 | vspace = (mapping_vspace_t*) ((char*)header + |
---|
| 76 | MAPPING_HEADER_SIZE + |
---|
| 77 | MAPPING_CLUSTER_SIZE*header->clusters + |
---|
| 78 | MAPPING_PSEG_SIZE*header->psegs ); |
---|
| 79 | |
---|
| 80 | // computes the base adresss for vsegs array, |
---|
| 81 | vseg = (mapping_vseg_t*) ((char*)header + |
---|
| 82 | MAPPING_HEADER_SIZE + |
---|
| 83 | MAPPING_CLUSTER_SIZE*header->clusters + |
---|
| 84 | MAPPING_PSEG_SIZE*header->psegs + |
---|
| 85 | MAPPING_VSPACE_SIZE*header->vspaces ); |
---|
| 86 | |
---|
[160] | 87 | // computes the base adresss for vobjs array, |
---|
| 88 | vobj = (mapping_vobj_t*) ((char*)header + |
---|
| 89 | MAPPING_HEADER_SIZE + |
---|
| 90 | MAPPING_CLUSTER_SIZE*header->clusters + |
---|
| 91 | MAPPING_PSEG_SIZE*header->psegs + |
---|
| 92 | MAPPING_VSPACE_SIZE*header->vspaces + |
---|
| 93 | MAPPING_VSEG_SIZE*header->vsegs ); |
---|
| 94 | |
---|
[158] | 95 | // computes the base address for tasks array |
---|
| 96 | task = (mapping_task_t*) ((char*)header + |
---|
| 97 | MAPPING_HEADER_SIZE + |
---|
| 98 | MAPPING_CLUSTER_SIZE*header->clusters + |
---|
| 99 | MAPPING_PSEG_SIZE*header->psegs + |
---|
| 100 | MAPPING_VSPACE_SIZE*header->vspaces + |
---|
[160] | 101 | MAPPING_VOBJ_SIZE*header->vobjs + |
---|
[158] | 102 | MAPPING_VSEG_SIZE*header->vsegs ); |
---|
| 103 | |
---|
| 104 | fprintf( fpout, "<?xml version = \"1.0\"?>\n\n"); |
---|
| 105 | |
---|
| 106 | ///////////////////////// header ///////////////////////////////////////////// |
---|
| 107 | |
---|
| 108 | fprintf( fpout, "<mapping_info signature = \"0x%x\"\n", header->signature); |
---|
| 109 | fprintf( fpout, " name = \"%s\"\n", header->name); |
---|
| 110 | fprintf( fpout, " clusters = \"%d\"\n", header->clusters); |
---|
| 111 | fprintf( fpout, " psegs = \"%d\"\n", header->psegs); |
---|
| 112 | fprintf( fpout, " ttys = \"%d\"\n", header->ttys); |
---|
| 113 | fprintf( fpout, " vspaces = \"%d\"\n", header->vspaces); |
---|
[160] | 114 | fprintf( fpout, " globals = \"%d\" />\n\n", header->globals); |
---|
[158] | 115 | |
---|
| 116 | ///////////////////// clusters /////////////////////////////////////////////// |
---|
| 117 | |
---|
| 118 | fprintf( fpout, " <clusterset>\n" ); |
---|
| 119 | for ( cluster_id = 0 ; cluster_id < header->clusters ; cluster_id++ ) |
---|
| 120 | { |
---|
| 121 | fprintf( fpout, " <cluster procs = \"%d\"\n", cluster[cluster_id].procs); |
---|
| 122 | fprintf( fpout, " timers = \"%d\"\n", cluster[cluster_id].timers); |
---|
| 123 | fprintf( fpout, " dmas = \"%d\" />\n\n", cluster[cluster_id].dmas); |
---|
| 124 | } |
---|
| 125 | fprintf( fpout, " </clusterset>\n" ); |
---|
| 126 | |
---|
| 127 | //////////////////// psegs /////////////////////////////////////////////////// |
---|
| 128 | |
---|
| 129 | fprintf( fpout, " <psegset>\n" ); |
---|
| 130 | for ( pseg_id = 0 ; pseg_id < header->psegs ; pseg_id++ ) |
---|
| 131 | { |
---|
| 132 | fprintf( fpout, " <pseg name = \"%s\"\n", pseg[pseg_id].name); |
---|
| 133 | fprintf( fpout, " base = \"0x%x\"\n", pseg[pseg_id].base); |
---|
| 134 | fprintf( fpout, " length = \"0x%x\" />\n\n", pseg[pseg_id].length); |
---|
| 135 | } |
---|
| 136 | fprintf( fpout, " </psegset>\n" ); |
---|
| 137 | |
---|
| 138 | |
---|
| 139 | /////////////////// globals ///////////////////////////////////////////////// |
---|
| 140 | |
---|
| 141 | fprintf( fpout, " <globalset>\n" ); |
---|
| 142 | for ( vseg_id = 0 ; vseg_id < header->globals ; vseg_id++ ) |
---|
| 143 | { |
---|
| 144 | unsigned int pseg_id = vseg[vseg_id].psegid; |
---|
| 145 | |
---|
| 146 | fprintf( fpout, " <vseg name = \"%s\"\n", vseg[vseg_id].name); |
---|
| 147 | fprintf( fpout, " vbase = \"0x%x\"\n", vseg[vseg_id].vbase); |
---|
| 148 | fprintf( fpout, " mode = \"%s\"\n", mode_str[vseg[vseg_id].mode]); |
---|
| 149 | fprintf( fpout, " psegname = \"%s\"\n", pseg[pseg_id].name); |
---|
[160] | 150 | fprintf( fpout, " ident = \"%d\" >\n", vseg[vseg_id].ident); |
---|
| 151 | for ( vobj_id = vseg[vseg_id].vobj_offset ; |
---|
| 152 | vobj_id < (vseg[vseg_id].vobj_offset + vseg[vseg_id].vobjs) ; vobj_id++ ) |
---|
| 153 | { |
---|
| 154 | fprintf( fpout, " <vobj name = \"%s\"\n", vobj[vobj_id].name); |
---|
| 155 | fprintf( fpout, " type = \"%s\" \n", vobj_type[vobj[vobj_id].type]); |
---|
| 156 | if(vobj[vobj_id].length) |
---|
| 157 | fprintf( fpout, " length = \"0x%x\" \n", vobj[vobj_id].length); |
---|
| 158 | if(vobj[vobj_id].align) |
---|
| 159 | fprintf( fpout, " align = \"%d\" \n", vobj[vobj_id].align); |
---|
| 160 | if(vobj[vobj_id].binpath[0]!='\0') |
---|
| 161 | fprintf( fpout, " binpath = \"%s\" \n", vobj[vobj_id].binpath); |
---|
| 162 | fprintf( fpout, " />\n"); |
---|
| 163 | } |
---|
| 164 | fprintf( fpout, " </vseg>\n\n"); |
---|
[158] | 165 | } |
---|
| 166 | fprintf( fpout, " </globalset>\n" ); |
---|
| 167 | |
---|
| 168 | //////////////////// vspaces //////////////////////////////////////////////// |
---|
| 169 | |
---|
| 170 | fprintf( fpout, " <vspaceset>\n" ); |
---|
| 171 | for ( vspace_id = 0 ; vspace_id < header->vspaces ; vspace_id++ ) |
---|
| 172 | { |
---|
[160] | 173 | unsigned int func_id = vspace[vspace_id].vobj_offset + vspace[vspace_id].funcs_offset; |
---|
[158] | 174 | fprintf( fpout, " <vspace name = \"%s\"\n", vspace[vspace_id].name); |
---|
[160] | 175 | fprintf( fpout, " funcs = \"%s\"\n", vobj[func_id].name); |
---|
[158] | 176 | fprintf( fpout, " ttys = \"%d\" >\n\n", vspace[vspace_id].ttys); |
---|
| 177 | |
---|
| 178 | for ( vseg_id = vspace[vspace_id].vseg_offset ; |
---|
| 179 | vseg_id < (vspace[vspace_id].vseg_offset + vspace[vspace_id].vsegs) ; vseg_id++ ) |
---|
| 180 | { |
---|
| 181 | unsigned int pseg_id = vseg[vseg_id].psegid; |
---|
| 182 | |
---|
| 183 | fprintf( fpout, " <vseg name = \"%s\"\n", vseg[vseg_id].name); |
---|
| 184 | fprintf( fpout, " vbase = \"0x%x\"\n", vseg[vseg_id].vbase); |
---|
| 185 | fprintf( fpout, " mode = \"%s\"\n", mode_str[vseg[vseg_id].mode]); |
---|
| 186 | fprintf( fpout, " psegname = \"%s\"\n", pseg[pseg_id].name); |
---|
[160] | 187 | fprintf( fpout, " ident = \"%d\" >\n", vseg[vseg_id].ident); |
---|
| 188 | |
---|
| 189 | for ( vobj_id = vseg[vseg_id].vobj_offset ; |
---|
| 190 | vobj_id < (vseg[vseg_id].vobj_offset + vseg[vseg_id].vobjs) ; vobj_id++ ) |
---|
| 191 | { |
---|
| 192 | fprintf( fpout, "\t <vobj name = \"%s\"\n", vobj[vobj_id].name); |
---|
| 193 | fprintf( fpout, "\t type = \"%s\" \n", vobj_type[vobj[vobj_id].type]); |
---|
| 194 | if(vobj[vobj_id].length) |
---|
| 195 | fprintf( fpout, "\t length = \"0x%x\" \n", vobj[vobj_id].length); |
---|
| 196 | if(vobj[vobj_id].align) |
---|
| 197 | fprintf( fpout, "\t align = \"%d\" \n", vobj[vobj_id].align); |
---|
| 198 | if(vobj[vobj_id].binpath[0]!='\0') |
---|
| 199 | fprintf( fpout, "\t binpath = \"%s\" \n", vobj[vobj_id].binpath); |
---|
| 200 | fprintf( fpout, "\t />\n"); |
---|
| 201 | } |
---|
| 202 | fprintf( fpout, "\t\t </vseg>\n\n"); |
---|
[158] | 203 | } |
---|
| 204 | for ( task_id = vspace[vspace_id].task_offset ; |
---|
| 205 | task_id < (vspace[vspace_id].task_offset + vspace[vspace_id].tasks) ; task_id++ ) |
---|
| 206 | { |
---|
[160] | 207 | unsigned int vobj_id = task[task_id].vobjlocid + vspace[vspace_id].vobj_offset; |
---|
[158] | 208 | |
---|
| 209 | fprintf( fpout, " <task name = \"%s\"\n", task[task_id].name); |
---|
| 210 | fprintf( fpout, " clusterid = \"%d\"\n", task[task_id].clusterid); |
---|
| 211 | fprintf( fpout, " proclocid = \"%d\"\n", task[task_id].proclocid); |
---|
[160] | 212 | fprintf( fpout, " stackname = \"%s\"\n", vobj[vobj_id].name); |
---|
[158] | 213 | fprintf( fpout, " startid = \"%d\"\n", task[task_id].startid); |
---|
| 214 | fprintf( fpout, " ttylocid = \"%d\" />\n\n", task[task_id].ttylocid); |
---|
| 215 | } |
---|
| 216 | fprintf( fpout, " </vspace>\n"); |
---|
| 217 | } |
---|
| 218 | fprintf( fpout, " </vspaceset>\n" ); |
---|
| 219 | fprintf( fpout, "</mapping_info>\n"); |
---|
| 220 | } // end buildXml() |
---|
| 221 | |
---|
| 222 | ///////////////////////////////////// |
---|
| 223 | int main ( int argc, char* argv[] ) |
---|
| 224 | { |
---|
| 225 | if ( argc < 2 ) |
---|
| 226 | { |
---|
| 227 | printf("Usage: bin2xml <input_file_path> <output_file_path>\n"); |
---|
| 228 | return 1; |
---|
| 229 | } |
---|
| 230 | |
---|
| 231 | unsigned int bin[0x10000]; // 64 K int = 256 Kbytes |
---|
| 232 | |
---|
| 233 | int fdin = open( argv[1], O_RDONLY ); |
---|
| 234 | if (fdin < 0) |
---|
| 235 | { |
---|
| 236 | perror("open"); |
---|
| 237 | exit(1); |
---|
| 238 | } |
---|
| 239 | |
---|
| 240 | FILE* fpout = fopen( argv[2], "w" ); |
---|
| 241 | if (fpout == NULL) |
---|
| 242 | { |
---|
| 243 | perror("open"); |
---|
| 244 | exit(1); |
---|
| 245 | } |
---|
| 246 | |
---|
| 247 | unsigned int length = read(fdin, bin, 0x40000); |
---|
| 248 | |
---|
| 249 | if ( length <= 0 ) |
---|
| 250 | { |
---|
| 251 | perror("read"); |
---|
| 252 | exit(1); |
---|
| 253 | } |
---|
| 254 | |
---|
| 255 | if ( bin[0] == IN_MAPPING_SIGNATURE ) |
---|
| 256 | { |
---|
| 257 | buildXml( (mapping_header_t*)bin, fpout ); |
---|
| 258 | } |
---|
| 259 | else |
---|
| 260 | { |
---|
| 261 | printf("[ERROR] Wrong file format\n"); |
---|
| 262 | exit(1); |
---|
| 263 | } |
---|
| 264 | return 0; |
---|
| 265 | } // end main() |
---|