[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 | |
---|
[189] | 19 | ////////////////////////////////////////////////////// |
---|
[228] | 20 | void buildXml(mapping_header_t * header, FILE * fpout) { |
---|
| 21 | const char * vobj_type[] = |
---|
[160] | 22 | { |
---|
[228] | 23 | "ELF", // binary code generated by GCC |
---|
| 24 | "BLOB", // binary code generated by GCC |
---|
| 25 | "PTAB", // page table |
---|
| 26 | "PERI", // hardware component |
---|
| 27 | "MWMR", // MWMR channel |
---|
| 28 | "LOCK", // Spin-Lock |
---|
| 29 | "BUFFER", // Any "no intialiasation needed" objects (stacks...) |
---|
| 30 | "BARRIER", // Barrier |
---|
| 31 | "CONST", // Constant |
---|
| 32 | "MEMSPACE", // Memspace |
---|
[160] | 33 | }; |
---|
[158] | 34 | |
---|
[228] | 35 | const char * pseg_type[] = |
---|
[181] | 36 | { |
---|
| 37 | "RAM", |
---|
| 38 | "ROM", |
---|
[189] | 39 | "PERI", |
---|
[181] | 40 | }; |
---|
| 41 | |
---|
[228] | 42 | const char * irq_type[] = |
---|
[181] | 43 | { |
---|
| 44 | "HARD", |
---|
[189] | 45 | "SOFT", |
---|
[181] | 46 | }; |
---|
| 47 | |
---|
[228] | 48 | const char * isr_type[] = |
---|
[181] | 49 | { |
---|
[189] | 50 | "ISR_DEFAULT", |
---|
| 51 | "ISR_SWITCH", |
---|
| 52 | "ISR_TTY", |
---|
| 53 | "ISR_DMA", |
---|
[181] | 54 | "ISR_IOC", |
---|
[189] | 55 | "ISR_TIMER", |
---|
[181] | 56 | }; |
---|
| 57 | |
---|
[228] | 58 | const char * periph_type[] = |
---|
[181] | 59 | { |
---|
[215] | 60 | "ICU", |
---|
| 61 | "TIM", |
---|
| 62 | "XICU", |
---|
| 63 | "DMA", |
---|
[189] | 64 | "IOC", |
---|
| 65 | "TTY", |
---|
| 66 | "FBF", |
---|
| 67 | "NIC", |
---|
| 68 | "IOB", |
---|
[181] | 69 | }; |
---|
| 70 | |
---|
[228] | 71 | const char * port_direction[] = |
---|
[181] | 72 | { |
---|
| 73 | "TO_COPROC", |
---|
[189] | 74 | "FROM_COPROC", |
---|
[181] | 75 | }; |
---|
| 76 | |
---|
[228] | 77 | const char * mode_str[] = |
---|
| 78 | { |
---|
| 79 | "____", |
---|
| 80 | "___U", |
---|
| 81 | "__W_", |
---|
| 82 | "__WU", |
---|
| 83 | "_X__", |
---|
| 84 | "_X_U", |
---|
| 85 | "_XW_", |
---|
| 86 | "_XWU", |
---|
| 87 | "C___", |
---|
| 88 | "C__U", |
---|
| 89 | "C_W_", |
---|
| 90 | "C_WU", |
---|
| 91 | "CX__", |
---|
| 92 | "CX_U", |
---|
| 93 | "CXW_", |
---|
| 94 | "CXWU", |
---|
[181] | 95 | }; |
---|
| 96 | |
---|
[228] | 97 | unsigned int vspace_id; |
---|
| 98 | unsigned int cluster_id; |
---|
| 99 | unsigned int pseg_id; |
---|
| 100 | unsigned int vseg_id; |
---|
| 101 | unsigned int vobj_id; |
---|
| 102 | unsigned int task_id; |
---|
| 103 | unsigned int proc_id; |
---|
| 104 | unsigned int irq_id; |
---|
| 105 | unsigned int coproc_id; |
---|
| 106 | unsigned int port_id; |
---|
| 107 | unsigned int periph_id; |
---|
[158] | 108 | |
---|
[228] | 109 | mapping_cluster_t * cluster; |
---|
| 110 | mapping_pseg_t * pseg; |
---|
| 111 | mapping_vspace_t * vspace; |
---|
| 112 | mapping_vseg_t * vseg; |
---|
| 113 | mapping_vobj_t * vobj; |
---|
| 114 | mapping_task_t * task; |
---|
| 115 | mapping_proc_t * proc; |
---|
| 116 | mapping_irq_t * irq; |
---|
| 117 | mapping_coproc_t * coproc; |
---|
| 118 | mapping_cp_port_t * cp_port; |
---|
| 119 | mapping_periph_t * periph; |
---|
[158] | 120 | |
---|
| 121 | // computes the base adresss for clusters array, |
---|
[228] | 122 | cluster = (mapping_cluster_t *)((char *) header + |
---|
| 123 | MAPPING_HEADER_SIZE); |
---|
[158] | 124 | |
---|
| 125 | // computes the base adresss for psegs array, |
---|
[228] | 126 | pseg = (mapping_pseg_t *) ((char *) header + |
---|
| 127 | MAPPING_HEADER_SIZE + |
---|
| 128 | MAPPING_CLUSTER_SIZE * header->clusters); |
---|
[158] | 129 | |
---|
| 130 | // computes the base adresss for vspaces array, |
---|
[228] | 131 | vspace = (mapping_vspace_t *) ((char *) header + |
---|
| 132 | MAPPING_HEADER_SIZE + |
---|
| 133 | MAPPING_CLUSTER_SIZE * header->clusters + |
---|
| 134 | MAPPING_PSEG_SIZE * header->psegs); |
---|
[158] | 135 | |
---|
| 136 | // computes the base adresss for vsegs array, |
---|
[228] | 137 | vseg = (mapping_vseg_t *) ((char *) header + |
---|
| 138 | MAPPING_HEADER_SIZE + |
---|
| 139 | MAPPING_CLUSTER_SIZE * header->clusters + |
---|
| 140 | MAPPING_PSEG_SIZE * header->psegs + |
---|
| 141 | MAPPING_VSPACE_SIZE * header->vspaces); |
---|
[158] | 142 | |
---|
[160] | 143 | // computes the base adresss for vobjs array, |
---|
[228] | 144 | vobj = (mapping_vobj_t *) ((char *) header + |
---|
| 145 | MAPPING_HEADER_SIZE + |
---|
| 146 | MAPPING_CLUSTER_SIZE * header->clusters + |
---|
| 147 | MAPPING_PSEG_SIZE * header->psegs + |
---|
| 148 | MAPPING_VSPACE_SIZE * header->vspaces + |
---|
| 149 | MAPPING_VSEG_SIZE * header->vsegs); |
---|
[160] | 150 | |
---|
[158] | 151 | // computes the base address for tasks array |
---|
[228] | 152 | task = (mapping_task_t *) ((char *) header + |
---|
| 153 | MAPPING_HEADER_SIZE + |
---|
| 154 | MAPPING_CLUSTER_SIZE * header->clusters + |
---|
| 155 | MAPPING_PSEG_SIZE * header->psegs + |
---|
| 156 | MAPPING_VSPACE_SIZE * header->vspaces + |
---|
| 157 | MAPPING_VOBJ_SIZE * header->vobjs + |
---|
| 158 | MAPPING_VSEG_SIZE * header->vsegs); |
---|
[158] | 159 | |
---|
[189] | 160 | // computes the base address for procs array |
---|
[228] | 161 | proc = (mapping_proc_t *) ((char *) header + |
---|
| 162 | MAPPING_HEADER_SIZE + |
---|
| 163 | MAPPING_CLUSTER_SIZE * header->clusters + |
---|
| 164 | MAPPING_PSEG_SIZE * header->psegs + |
---|
| 165 | MAPPING_VSPACE_SIZE * header->vspaces + |
---|
| 166 | MAPPING_VOBJ_SIZE * header->vobjs + |
---|
| 167 | MAPPING_VSEG_SIZE * header->vsegs + |
---|
| 168 | MAPPING_TASK_SIZE * header->tasks); |
---|
[181] | 169 | |
---|
[189] | 170 | // computes the base address for irqs array |
---|
[228] | 171 | irq = (mapping_irq_t *) ((char *) header + |
---|
| 172 | MAPPING_HEADER_SIZE + |
---|
| 173 | MAPPING_CLUSTER_SIZE * header->clusters + |
---|
| 174 | MAPPING_PSEG_SIZE * header->psegs + |
---|
| 175 | MAPPING_VSPACE_SIZE * header->vspaces + |
---|
| 176 | MAPPING_VOBJ_SIZE * header->vobjs + |
---|
| 177 | MAPPING_VSEG_SIZE * header->vsegs + |
---|
| 178 | MAPPING_TASK_SIZE * header->tasks + |
---|
| 179 | MAPPING_PROC_SIZE * header->procs); |
---|
[181] | 180 | |
---|
[189] | 181 | // computes the base address for coprocs array |
---|
[228] | 182 | coproc = (mapping_coproc_t *) ((char *) header + |
---|
| 183 | MAPPING_HEADER_SIZE + |
---|
| 184 | MAPPING_CLUSTER_SIZE * header->clusters + |
---|
| 185 | MAPPING_PSEG_SIZE * header->psegs + |
---|
| 186 | MAPPING_VSPACE_SIZE * header->vspaces + |
---|
| 187 | MAPPING_VOBJ_SIZE * header->vobjs + |
---|
| 188 | MAPPING_VSEG_SIZE * header->vsegs + |
---|
| 189 | MAPPING_TASK_SIZE * header->tasks + |
---|
| 190 | MAPPING_PROC_SIZE * header->procs + |
---|
| 191 | MAPPING_IRQ_SIZE * header->irqs); |
---|
[181] | 192 | |
---|
[189] | 193 | // computes the base address for cp_ports array |
---|
[228] | 194 | cp_port = (mapping_cp_port_t *) ((char *) header + |
---|
| 195 | MAPPING_HEADER_SIZE + |
---|
| 196 | MAPPING_CLUSTER_SIZE * header->clusters + |
---|
| 197 | MAPPING_PSEG_SIZE * header->psegs + |
---|
| 198 | MAPPING_VSPACE_SIZE * header->vspaces + |
---|
| 199 | MAPPING_VOBJ_SIZE * header->vobjs + |
---|
| 200 | MAPPING_VSEG_SIZE * header->vsegs + |
---|
| 201 | MAPPING_TASK_SIZE * header->tasks + |
---|
| 202 | MAPPING_PROC_SIZE * header->procs + |
---|
| 203 | MAPPING_IRQ_SIZE * header->irqs + |
---|
| 204 | MAPPING_COPROC_SIZE * header->coprocs); |
---|
[181] | 205 | |
---|
[189] | 206 | // computes the base address for periphs array |
---|
[228] | 207 | periph = (mapping_periph_t *) ((char *) header + |
---|
| 208 | MAPPING_HEADER_SIZE + |
---|
| 209 | MAPPING_CLUSTER_SIZE * header->clusters + |
---|
| 210 | MAPPING_PSEG_SIZE * header->psegs + |
---|
| 211 | MAPPING_VSPACE_SIZE * header->vspaces + |
---|
| 212 | MAPPING_VOBJ_SIZE * header->vobjs + |
---|
| 213 | MAPPING_VSEG_SIZE * header->vsegs + |
---|
| 214 | MAPPING_TASK_SIZE * header->tasks + |
---|
| 215 | MAPPING_PROC_SIZE * header->procs + |
---|
| 216 | MAPPING_IRQ_SIZE * header->irqs + |
---|
| 217 | MAPPING_COPROC_SIZE * header->coprocs + |
---|
| 218 | MAPPING_CP_PORT_SIZE * header->cp_ports); |
---|
[181] | 219 | |
---|
[189] | 220 | ///////////////////////// header ///////////////////////////////////////////// |
---|
| 221 | |
---|
[228] | 222 | fprintf(fpout, "<?xml version = \"1.0\"?>\n\n"); |
---|
[158] | 223 | |
---|
[228] | 224 | fprintf(fpout, "<mapping_info signature = \"0x%x\" ", header->signature); |
---|
| 225 | fprintf(fpout, " name = \"%s\" ", header->name); |
---|
| 226 | fprintf(fpout, " cluster_x = \"%d\" ", header->cluster_x); |
---|
| 227 | fprintf(fpout, " cluster_y = \"%d\" ", header->cluster_y); |
---|
| 228 | fprintf(fpout, " vspaces = \"%d\" >\n\n", header->vspaces); |
---|
[158] | 229 | |
---|
| 230 | ///////////////////// clusters /////////////////////////////////////////////// |
---|
| 231 | |
---|
[228] | 232 | fprintf( fpout, " <clusterset>\n"); |
---|
| 233 | for (cluster_id = 0; cluster_id < header->clusters; cluster_id++) { |
---|
| 234 | fprintf(fpout, " <cluster index = \"%d\" >\n", cluster_id); |
---|
| 235 | for (pseg_id = cluster[cluster_id].pseg_offset; |
---|
| 236 | pseg_id < cluster[cluster_id].pseg_offset + cluster[cluster_id].psegs; |
---|
| 237 | pseg_id++) { |
---|
| 238 | fprintf(fpout, " <pseg name = \"%s\" ", pseg[pseg_id].name); |
---|
| 239 | fprintf(fpout, " type = \"%s\" ", pseg_type[pseg[pseg_id].type]); |
---|
| 240 | fprintf(fpout, " base = \"0x%x\" ", pseg[pseg_id].base); |
---|
| 241 | fprintf(fpout, " length = \"0x%x\" />\n", pseg[pseg_id].length); |
---|
[181] | 242 | } |
---|
[189] | 243 | |
---|
[228] | 244 | ///////////////////// processors ///////////////////////////////////////////// |
---|
[189] | 245 | |
---|
[215] | 246 | unsigned int proc_index = 0; |
---|
[228] | 247 | for (proc_id = cluster[cluster_id].proc_offset; |
---|
| 248 | proc_id < cluster[cluster_id].proc_offset + cluster[cluster_id].procs; |
---|
| 249 | proc_id++) { |
---|
| 250 | fprintf(fpout, " <proc index = \"%d\" >\n", proc_index); |
---|
| 251 | for (irq_id = proc[proc_id].irq_offset; |
---|
| 252 | irq_id < proc[proc_id].irq_offset + proc[proc_id].irqs; |
---|
| 253 | irq_id++) { |
---|
| 254 | fprintf(fpout, " <irq type = \"%s\" ", irq_type[irq[irq_id].type]); |
---|
| 255 | fprintf(fpout, " icuid = \"0x%x\" ", irq[irq_id].icuid); |
---|
| 256 | fprintf(fpout, " isr = \"%s\" ", isr_type[irq[irq_id].isr]); |
---|
| 257 | fprintf(fpout, " channel = \"0x%x\" />\n", irq[irq_id].channel); |
---|
[181] | 258 | } |
---|
[228] | 259 | fprintf(fpout, " </proc>\n" ); |
---|
[181] | 260 | } |
---|
[158] | 261 | |
---|
[189] | 262 | |
---|
[228] | 263 | ///////////////////// coprocessors /////////////////////////////////////////// |
---|
[189] | 264 | |
---|
[228] | 265 | for (coproc_id = cluster[cluster_id].coproc_offset; |
---|
| 266 | coproc_id < cluster[cluster_id].coproc_offset + cluster[cluster_id].coprocs; |
---|
| 267 | coproc_id++) { |
---|
| 268 | fprintf(fpout, " <coproc name = \"%s\" ", coproc[coproc_id].name); |
---|
| 269 | fprintf(fpout, " psegname = \"%s\" >\n", pseg[coproc[coproc_id].psegid].name); |
---|
| 270 | for (port_id = coproc[coproc_id].port_offset; |
---|
| 271 | port_id < coproc[coproc_id].port_offset + coproc[coproc_id].ports; |
---|
| 272 | port_id++) { |
---|
[181] | 273 | unsigned int vobj_id = cp_port[port_id].vobjlocid + vspace[cp_port[port_id].vspaceid].vobj_offset; |
---|
[228] | 274 | fprintf(fpout, " <port direction = \"%s\" ", port_direction[cp_port[port_id].direction]); |
---|
| 275 | fprintf(fpout, " vspacename = \"%s\" ", vspace[cp_port[port_id].vspaceid].name); |
---|
| 276 | fprintf(fpout, " vobjname = \"%s\" />\n", vobj[vobj_id].name); |
---|
[181] | 277 | } |
---|
[228] | 278 | fprintf(fpout, " </coproc>\n" ); |
---|
[181] | 279 | } |
---|
[189] | 280 | |
---|
[228] | 281 | ///////////////////// periphs /////////////////////////////////////////////// |
---|
[189] | 282 | |
---|
[228] | 283 | for (periph_id = cluster[cluster_id].periph_offset; |
---|
| 284 | periph_id < cluster[cluster_id].periph_offset + cluster[cluster_id].periphs; |
---|
| 285 | periph_id++) { |
---|
| 286 | fprintf(fpout, " <periph type = \"%s\" ", periph_type[periph[periph_id].type]); |
---|
| 287 | fprintf(fpout, " psegname = \"%s\" ", pseg[periph[periph_id].psegid].name); |
---|
| 288 | fprintf(fpout, " channels = \"%d\" />\n", periph[periph_id].channels); |
---|
[189] | 289 | } |
---|
[228] | 290 | fprintf(fpout, " </cluster>\n" ); |
---|
[158] | 291 | } |
---|
[228] | 292 | fprintf(fpout, " </clusterset>\n\n" ); |
---|
[158] | 293 | |
---|
| 294 | /////////////////// globals ///////////////////////////////////////////////// |
---|
| 295 | |
---|
[228] | 296 | fprintf(fpout, " <globalset>\n" ); |
---|
| 297 | for (vseg_id = 0; vseg_id < header->globals; vseg_id++) { |
---|
[158] | 298 | unsigned int pseg_id = vseg[vseg_id].psegid; |
---|
| 299 | |
---|
[228] | 300 | fprintf(fpout, " <vseg name = \"%s\" ", vseg[vseg_id].name); |
---|
| 301 | fprintf(fpout, "vbase = \"0x%x\" ", vseg[vseg_id].vbase); |
---|
| 302 | fprintf(fpout, "mode = \"%s\" ", mode_str[vseg[vseg_id].mode]); |
---|
| 303 | fprintf(fpout, "clusterid = \"%d\" ", pseg[pseg_id].cluster); |
---|
| 304 | fprintf(fpout, "psegname = \"%s\" ", pseg[pseg_id].name); |
---|
| 305 | fprintf(fpout, "ident = \"%d\" >\n", vseg[vseg_id].ident); |
---|
| 306 | for (vobj_id = vseg[vseg_id].vobj_offset; |
---|
| 307 | vobj_id < (vseg[vseg_id].vobj_offset + vseg[vseg_id].vobjs); |
---|
| 308 | vobj_id++) { |
---|
| 309 | fprintf(fpout, " <vobj name = \"%s\" ", vobj[vobj_id].name); |
---|
| 310 | fprintf(fpout, "type = \"%s\" ", vobj_type[vobj[vobj_id].type]); |
---|
| 311 | fprintf(fpout, "length = \"0x%x\" ", vobj[vobj_id].length); |
---|
| 312 | fprintf(fpout, "align = \"%d\" ", vobj[vobj_id].align); |
---|
| 313 | fprintf(fpout, "init = \"%d\" ", vobj[vobj_id].init); |
---|
| 314 | fprintf(fpout, "binpath = \"%s\" />\n", vobj[vobj_id].binpath); |
---|
[165] | 315 | } |
---|
[228] | 316 | fprintf(fpout, " </vseg>\n"); |
---|
[158] | 317 | } |
---|
[228] | 318 | fprintf(fpout, " </globalset>\n" ); |
---|
[158] | 319 | |
---|
| 320 | //////////////////// vspaces //////////////////////////////////////////////// |
---|
| 321 | |
---|
[181] | 322 | fprintf( fpout, "\n <vspaceset>\n\n" ); |
---|
[228] | 323 | for (vspace_id = 0; vspace_id < header->vspaces; vspace_id++) { |
---|
[165] | 324 | unsigned int func_id = vspace[vspace_id].vobj_offset + vspace[vspace_id].start_offset; |
---|
[228] | 325 | fprintf(fpout, " <vspace name = \"%s\" ", vspace[vspace_id].name); |
---|
| 326 | fprintf(fpout, " startname = \"%s\" >\n", vobj[func_id].name); |
---|
[158] | 327 | |
---|
[228] | 328 | for (vseg_id = vspace[vspace_id].vseg_offset; |
---|
| 329 | vseg_id < (vspace[vspace_id].vseg_offset + vspace[vspace_id].vsegs); |
---|
| 330 | vseg_id++) { |
---|
[158] | 331 | unsigned int pseg_id = vseg[vseg_id].psegid; |
---|
| 332 | |
---|
[228] | 333 | fprintf(fpout, " <vseg name = \"%s\" ", vseg[vseg_id].name); |
---|
| 334 | fprintf(fpout, "vbase = \"0x%x\" ", vseg[vseg_id].vbase); |
---|
| 335 | fprintf(fpout, "mode = \"%s\" ", mode_str[vseg[vseg_id].mode]); |
---|
| 336 | fprintf(fpout, "clusterid = \"%d\" ", pseg[pseg_id].cluster); |
---|
| 337 | fprintf(fpout, "psegname = \"%s\" ", pseg[pseg_id].name); |
---|
| 338 | fprintf(fpout, "ident = \"%d\" >\n", vseg[vseg_id].ident); |
---|
[160] | 339 | |
---|
[228] | 340 | for (vobj_id = vseg[vseg_id].vobj_offset; |
---|
| 341 | vobj_id < (vseg[vseg_id].vobj_offset + vseg[vseg_id].vobjs); |
---|
| 342 | vobj_id++) { |
---|
| 343 | fprintf(fpout, " <vobj name = \"%s\" ", vobj[vobj_id].name); |
---|
| 344 | fprintf(fpout, "type = \"%s\" ", vobj_type[vobj[vobj_id].type]); |
---|
| 345 | fprintf(fpout, "length = \"0x%x\" ", vobj[vobj_id].length); |
---|
| 346 | fprintf(fpout, "align = \"%d\" ", vobj[vobj_id].align); |
---|
| 347 | fprintf(fpout, "init = \"%d\" ", vobj[vobj_id].init); |
---|
| 348 | fprintf(fpout, "binpath = \"%s\" />\n", vobj[vobj_id].binpath); |
---|
[160] | 349 | } |
---|
[228] | 350 | fprintf(fpout, " </vseg>\n\n"); |
---|
[158] | 351 | } |
---|
[228] | 352 | for (task_id = vspace[vspace_id].task_offset; |
---|
| 353 | task_id < (vspace[vspace_id].task_offset + vspace[vspace_id].tasks); |
---|
| 354 | task_id++) { |
---|
[160] | 355 | unsigned int vobj_id = task[task_id].vobjlocid + vspace[vspace_id].vobj_offset; |
---|
[158] | 356 | |
---|
[228] | 357 | fprintf(fpout, " <task name = \"%s\" ", task[task_id].name); |
---|
| 358 | fprintf(fpout, "clusterid = \"%d\" ", task[task_id].clusterid); |
---|
| 359 | fprintf(fpout, "proclocid = \"%d\" ", task[task_id].proclocid); |
---|
| 360 | fprintf(fpout, "stackname = \"%s\" ", vobj[vobj_id].name); |
---|
| 361 | fprintf(fpout, "startid = \"%d\" ", task[task_id].startid); |
---|
| 362 | fprintf(fpout, "usetty = \"%d\" ", task[task_id].use_tty); |
---|
| 363 | fprintf(fpout, "usenic = \"%d\" ", task[task_id].use_nic); |
---|
| 364 | fprintf(fpout, "usetimer = \"%d\" ", task[task_id].use_timer); |
---|
| 365 | fprintf(fpout, "usefbma = \"%d\" />\n", task[task_id].use_fbdma); |
---|
[158] | 366 | } |
---|
[228] | 367 | fprintf(fpout, " </vspace>\n\n"); |
---|
[158] | 368 | } |
---|
[228] | 369 | fprintf(fpout, " </vspaceset>\n"); |
---|
| 370 | fprintf(fpout, "</mapping_info>\n"); |
---|
[158] | 371 | } // end buildXml() |
---|
| 372 | |
---|
[228] | 373 | |
---|
[158] | 374 | ///////////////////////////////////// |
---|
[228] | 375 | int main(int argc, char * argv[]) { |
---|
| 376 | if (argc < 2) { |
---|
[158] | 377 | printf("Usage: bin2xml <input_file_path> <output_file_path>\n"); |
---|
| 378 | return 1; |
---|
| 379 | } |
---|
| 380 | |
---|
[228] | 381 | unsigned int bin[0x10000]; // 64 K int = 256 Kbytes |
---|
[158] | 382 | |
---|
[228] | 383 | int fdin = open(argv[1], O_RDONLY); |
---|
| 384 | if (fdin < 0) { |
---|
[158] | 385 | perror("open"); |
---|
| 386 | exit(1); |
---|
| 387 | } |
---|
| 388 | |
---|
[228] | 389 | FILE * fpout = fopen( argv[2], "w"); |
---|
| 390 | if (fpout == NULL) { |
---|
[158] | 391 | perror("open"); |
---|
| 392 | exit(1); |
---|
| 393 | } |
---|
| 394 | |
---|
| 395 | unsigned int length = read(fdin, bin, 0x40000); |
---|
| 396 | |
---|
[228] | 397 | if (length <= 0) { |
---|
[158] | 398 | perror("read"); |
---|
| 399 | exit(1); |
---|
| 400 | } |
---|
| 401 | |
---|
[228] | 402 | if (bin[0] == IN_MAPPING_SIGNATURE) { |
---|
| 403 | buildXml((mapping_header_t *) bin, fpout); |
---|
[158] | 404 | } |
---|
[228] | 405 | else { |
---|
[158] | 406 | printf("[ERROR] Wrong file format\n"); |
---|
| 407 | exit(1); |
---|
| 408 | } |
---|
| 409 | return 0; |
---|
| 410 | } // end main() |
---|
[228] | 411 | |
---|
| 412 | |
---|
| 413 | |
---|
| 414 | // Local Variables: |
---|
| 415 | // tab-width: 4 |
---|
| 416 | // c-basic-offset: 4 |
---|
| 417 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 418 | // indent-tabs-mode: nil |
---|
| 419 | // End: |
---|
| 420 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 421 | |
---|