[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 | { |
---|
| 22 | const char* mode_str[] = { "____", |
---|
| 23 | "___U", |
---|
| 24 | "__W_", |
---|
| 25 | "__WU", |
---|
| 26 | "_X__", |
---|
| 27 | "_X_U", |
---|
| 28 | "_XW_", |
---|
| 29 | "_XWU", |
---|
| 30 | "C___", |
---|
| 31 | "C__U", |
---|
| 32 | "C_W_", |
---|
| 33 | "C_WU", |
---|
| 34 | "CX__", |
---|
| 35 | "CX_U", |
---|
| 36 | "CXW_", |
---|
| 37 | "CXWU" }; |
---|
| 38 | |
---|
| 39 | unsigned int vspace_id; |
---|
| 40 | unsigned int cluster_id; |
---|
| 41 | unsigned int pseg_id; |
---|
| 42 | unsigned int vseg_id; |
---|
| 43 | unsigned int task_id; |
---|
| 44 | |
---|
| 45 | mapping_cluster_t* cluster; |
---|
| 46 | mapping_pseg_t* pseg; |
---|
| 47 | mapping_vspace_t* vspace; |
---|
| 48 | mapping_vseg_t* vseg; |
---|
| 49 | mapping_task_t* task; |
---|
| 50 | |
---|
| 51 | // computes the base adresss for clusters array, |
---|
| 52 | cluster = (mapping_cluster_t*)((char*)header + |
---|
| 53 | MAPPING_HEADER_SIZE ); |
---|
| 54 | |
---|
| 55 | // computes the base adresss for psegs array, |
---|
| 56 | pseg = (mapping_pseg_t*) ((char*)header + |
---|
| 57 | MAPPING_HEADER_SIZE + |
---|
| 58 | MAPPING_CLUSTER_SIZE*header->clusters ); |
---|
| 59 | |
---|
| 60 | // computes the base adresss for vspaces array, |
---|
| 61 | vspace = (mapping_vspace_t*) ((char*)header + |
---|
| 62 | MAPPING_HEADER_SIZE + |
---|
| 63 | MAPPING_CLUSTER_SIZE*header->clusters + |
---|
| 64 | MAPPING_PSEG_SIZE*header->psegs ); |
---|
| 65 | |
---|
| 66 | // computes the base adresss for vsegs array, |
---|
| 67 | vseg = (mapping_vseg_t*) ((char*)header + |
---|
| 68 | MAPPING_HEADER_SIZE + |
---|
| 69 | MAPPING_CLUSTER_SIZE*header->clusters + |
---|
| 70 | MAPPING_PSEG_SIZE*header->psegs + |
---|
| 71 | MAPPING_VSPACE_SIZE*header->vspaces ); |
---|
| 72 | |
---|
| 73 | // computes the base address for tasks array |
---|
| 74 | task = (mapping_task_t*) ((char*)header + |
---|
| 75 | MAPPING_HEADER_SIZE + |
---|
| 76 | MAPPING_CLUSTER_SIZE*header->clusters + |
---|
| 77 | MAPPING_PSEG_SIZE*header->psegs + |
---|
| 78 | MAPPING_VSPACE_SIZE*header->vspaces + |
---|
| 79 | MAPPING_VSEG_SIZE*header->vsegs ); |
---|
| 80 | |
---|
| 81 | fprintf( fpout, "<?xml version = \"1.0\"?>\n\n"); |
---|
| 82 | |
---|
| 83 | ///////////////////////// header ///////////////////////////////////////////// |
---|
| 84 | |
---|
| 85 | fprintf( fpout, "<mapping_info signature = \"0x%x\"\n", header->signature); |
---|
| 86 | fprintf( fpout, " name = \"%s\"\n", header->name); |
---|
| 87 | fprintf( fpout, " clusters = \"%d\"\n", header->clusters); |
---|
| 88 | fprintf( fpout, " psegs = \"%d\"\n", header->psegs); |
---|
| 89 | fprintf( fpout, " ttys = \"%d\"\n", header->ttys); |
---|
| 90 | fprintf( fpout, " vspaces = \"%d\"\n", header->vspaces); |
---|
| 91 | fprintf( fpout, " globals = \"%d\"\n", header->globals); |
---|
| 92 | fprintf( fpout, " syspath = \"%s\" >\n", header->syspath); |
---|
| 93 | |
---|
| 94 | ///////////////////// clusters /////////////////////////////////////////////// |
---|
| 95 | |
---|
| 96 | fprintf( fpout, " <clusterset>\n" ); |
---|
| 97 | for ( cluster_id = 0 ; cluster_id < header->clusters ; cluster_id++ ) |
---|
| 98 | { |
---|
| 99 | fprintf( fpout, " <cluster procs = \"%d\"\n", cluster[cluster_id].procs); |
---|
| 100 | fprintf( fpout, " timers = \"%d\"\n", cluster[cluster_id].timers); |
---|
| 101 | fprintf( fpout, " dmas = \"%d\" />\n\n", cluster[cluster_id].dmas); |
---|
| 102 | } |
---|
| 103 | fprintf( fpout, " </clusterset>\n" ); |
---|
| 104 | |
---|
| 105 | //////////////////// psegs /////////////////////////////////////////////////// |
---|
| 106 | |
---|
| 107 | fprintf( fpout, " <psegset>\n" ); |
---|
| 108 | for ( pseg_id = 0 ; pseg_id < header->psegs ; pseg_id++ ) |
---|
| 109 | { |
---|
| 110 | fprintf( fpout, " <pseg name = \"%s\"\n", pseg[pseg_id].name); |
---|
| 111 | fprintf( fpout, " base = \"0x%x\"\n", pseg[pseg_id].base); |
---|
| 112 | fprintf( fpout, " length = \"0x%x\" />\n\n", pseg[pseg_id].length); |
---|
| 113 | } |
---|
| 114 | fprintf( fpout, " </psegset>\n" ); |
---|
| 115 | |
---|
| 116 | |
---|
| 117 | /////////////////// globals ///////////////////////////////////////////////// |
---|
| 118 | |
---|
| 119 | fprintf( fpout, " <globalset>\n" ); |
---|
| 120 | for ( vseg_id = 0 ; vseg_id < header->globals ; vseg_id++ ) |
---|
| 121 | { |
---|
| 122 | unsigned int pseg_id = vseg[vseg_id].psegid; |
---|
| 123 | |
---|
| 124 | fprintf( fpout, " <vseg name = \"%s\"\n", vseg[vseg_id].name); |
---|
| 125 | fprintf( fpout, " vbase = \"0x%x\"\n", vseg[vseg_id].vbase); |
---|
| 126 | fprintf( fpout, " length = \"0x%x\"\n", vseg[vseg_id].length); |
---|
| 127 | fprintf( fpout, " mode = \"%s\"\n", mode_str[vseg[vseg_id].mode]); |
---|
| 128 | fprintf( fpout, " psegname = \"%s\"\n", pseg[pseg_id].name); |
---|
| 129 | fprintf( fpout, " ident = \"%d\" />\n\n", vseg[vseg_id].ident); |
---|
| 130 | } |
---|
| 131 | fprintf( fpout, " </globalset>\n" ); |
---|
| 132 | |
---|
| 133 | //////////////////// vspaces //////////////////////////////////////////////// |
---|
| 134 | |
---|
| 135 | fprintf( fpout, " <vspaceset>\n" ); |
---|
| 136 | for ( vspace_id = 0 ; vspace_id < header->vspaces ; vspace_id++ ) |
---|
| 137 | { |
---|
| 138 | fprintf( fpout, " <vspace name = \"%s\"\n", vspace[vspace_id].name); |
---|
| 139 | fprintf( fpout, " binpath = \"%s\"\n", vspace[vspace_id].binpath); |
---|
| 140 | fprintf( fpout, " vsegs = \"%d\"\n", vspace[vspace_id].vsegs); |
---|
| 141 | fprintf( fpout, " tasks = \"%d\"\n", vspace[vspace_id].tasks); |
---|
| 142 | fprintf( fpout, " mwmrs = \"%d\"\n", vspace[vspace_id].mwmrs); |
---|
| 143 | fprintf( fpout, " ttys = \"%d\" >\n\n", vspace[vspace_id].ttys); |
---|
| 144 | |
---|
| 145 | for ( vseg_id = vspace[vspace_id].vseg_offset ; |
---|
| 146 | vseg_id < (vspace[vspace_id].vseg_offset + vspace[vspace_id].vsegs) ; vseg_id++ ) |
---|
| 147 | { |
---|
| 148 | unsigned int pseg_id = vseg[vseg_id].psegid; |
---|
| 149 | |
---|
| 150 | fprintf( fpout, " <vseg name = \"%s\"\n", vseg[vseg_id].name); |
---|
| 151 | fprintf( fpout, " vbase = \"0x%x\"\n", vseg[vseg_id].vbase); |
---|
| 152 | fprintf( fpout, " length = \"0x%x\"\n", vseg[vseg_id].length); |
---|
| 153 | fprintf( fpout, " mode = \"%s\"\n", mode_str[vseg[vseg_id].mode]); |
---|
| 154 | fprintf( fpout, " psegname = \"%s\"\n", pseg[pseg_id].name); |
---|
| 155 | fprintf( fpout, " mwmr = \"%d\"\n", vseg[vseg_id].mwmr); |
---|
| 156 | fprintf( fpout, " ident = \"%d\" />\n\n", vseg[vseg_id].ident); |
---|
| 157 | } |
---|
| 158 | for ( task_id = vspace[vspace_id].task_offset ; |
---|
| 159 | task_id < (vspace[vspace_id].task_offset + vspace[vspace_id].tasks) ; task_id++ ) |
---|
| 160 | { |
---|
| 161 | unsigned int vseg_id = task[task_id].vseglocid + vspace[vspace_id].vseg_offset; |
---|
| 162 | |
---|
| 163 | fprintf( fpout, " <task name = \"%s\"\n", task[task_id].name); |
---|
| 164 | fprintf( fpout, " clusterid = \"%d\"\n", task[task_id].clusterid); |
---|
| 165 | fprintf( fpout, " proclocid = \"%d\"\n", task[task_id].proclocid); |
---|
| 166 | fprintf( fpout, " stackname = \"%s\"\n", vseg[vseg_id].name); |
---|
| 167 | fprintf( fpout, " startid = \"%d\"\n", task[task_id].startid); |
---|
| 168 | fprintf( fpout, " ttylocid = \"%d\" />\n\n", task[task_id].ttylocid); |
---|
| 169 | } |
---|
| 170 | fprintf( fpout, " </vspace>\n"); |
---|
| 171 | } |
---|
| 172 | fprintf( fpout, " </vspaceset>\n" ); |
---|
| 173 | fprintf( fpout, "</mapping_info>\n"); |
---|
| 174 | } // end buildXml() |
---|
| 175 | |
---|
| 176 | ///////////////////////////////////// |
---|
| 177 | int main ( int argc, char* argv[] ) |
---|
| 178 | { |
---|
| 179 | if ( argc < 2 ) |
---|
| 180 | { |
---|
| 181 | printf("Usage: bin2xml <input_file_path> <output_file_path>\n"); |
---|
| 182 | return 1; |
---|
| 183 | } |
---|
| 184 | |
---|
| 185 | unsigned int bin[0x10000]; // 64 K int = 256 Kbytes |
---|
| 186 | |
---|
| 187 | int fdin = open( argv[1], O_RDONLY ); |
---|
| 188 | if (fdin < 0) |
---|
| 189 | { |
---|
| 190 | perror("open"); |
---|
| 191 | exit(1); |
---|
| 192 | } |
---|
| 193 | |
---|
| 194 | FILE* fpout = fopen( argv[2], "w" ); |
---|
| 195 | if (fpout == NULL) |
---|
| 196 | { |
---|
| 197 | perror("open"); |
---|
| 198 | exit(1); |
---|
| 199 | } |
---|
| 200 | |
---|
| 201 | unsigned int length = read(fdin, bin, 0x40000); |
---|
| 202 | |
---|
| 203 | if ( length <= 0 ) |
---|
| 204 | { |
---|
| 205 | perror("read"); |
---|
| 206 | exit(1); |
---|
| 207 | } |
---|
| 208 | |
---|
| 209 | if ( bin[0] == IN_MAPPING_SIGNATURE ) |
---|
| 210 | { |
---|
| 211 | buildXml( (mapping_header_t*)bin, fpout ); |
---|
| 212 | } |
---|
| 213 | else |
---|
| 214 | { |
---|
| 215 | printf("[ERROR] Wrong file format\n"); |
---|
| 216 | exit(1); |
---|
| 217 | } |
---|
| 218 | return 0; |
---|
| 219 | } // end main() |
---|