[258] | 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 | ////////////////////////////////////////////////////// |
---|
[295] | 20 | void buildXml(mapping_header_t * header, FILE * fpout) |
---|
| 21 | { |
---|
| 22 | // mnemonics defined in mapping_info.h |
---|
[258] | 23 | const char * vobj_type[] = |
---|
| 24 | { |
---|
| 25 | "ELF", // binary code generated by GCC |
---|
| 26 | "BLOB", // binary code generated by GCC |
---|
| 27 | "PTAB", // page table |
---|
| 28 | "PERI", // hardware component |
---|
| 29 | "MWMR", // MWMR channel |
---|
| 30 | "LOCK", // Spin-Lock |
---|
[295] | 31 | "BUFFER", // Any "no intialiasation needed" object (stacks...) |
---|
[258] | 32 | "BARRIER", // Barrier |
---|
| 33 | "CONST", // Constant |
---|
| 34 | "MEMSPACE", // Memspace |
---|
| 35 | "SCHED", // Scheduler |
---|
| 36 | }; |
---|
| 37 | |
---|
[295] | 38 | // mnemonics defined in mapping_info.h |
---|
[258] | 39 | const char * pseg_type[] = |
---|
| 40 | { |
---|
| 41 | "RAM", |
---|
[295] | 42 | "ROM", // deprecated => use PERI |
---|
[258] | 43 | "PERI", |
---|
| 44 | }; |
---|
| 45 | |
---|
[295] | 46 | // mnemonics defined in mapping_info.h |
---|
[258] | 47 | const char * irq_type[] = |
---|
| 48 | { |
---|
[295] | 49 | "HWI", |
---|
| 50 | "WTI", |
---|
| 51 | "PTI", |
---|
[258] | 52 | }; |
---|
| 53 | |
---|
[295] | 54 | // mnemonics defined in irq_handler.h |
---|
[258] | 55 | const char * isr_type[] = |
---|
| 56 | { |
---|
[295] | 57 | "ISR_DEFAULT", |
---|
| 58 | "ISR_TICK", |
---|
| 59 | "ISR_TTY_RX", |
---|
| 60 | "ISR_TTY_TX", |
---|
| 61 | "ISR_BDV", |
---|
[258] | 62 | "ISR_TIMER", |
---|
[295] | 63 | "ISR_WAKUP", |
---|
| 64 | "ISR_NIC_RX", |
---|
| 65 | "ISR_NIC_TX", |
---|
| 66 | "ISR_CMA", |
---|
[258] | 67 | }; |
---|
| 68 | |
---|
[295] | 69 | // mnemonics defined in mapping_info.h |
---|
[258] | 70 | const char * periph_type[] = |
---|
| 71 | { |
---|
| 72 | "CMA", |
---|
| 73 | "DMA", |
---|
| 74 | "FBF", |
---|
| 75 | "ICU", |
---|
| 76 | "IOB", |
---|
| 77 | "IOC", |
---|
| 78 | "MMC", |
---|
| 79 | "MWR", |
---|
| 80 | "NIC", |
---|
| 81 | "ROM", |
---|
| 82 | "SIM", |
---|
| 83 | "TIM", |
---|
| 84 | "TTY", |
---|
| 85 | "XCU", |
---|
[295] | 86 | "PIC", |
---|
[258] | 87 | }; |
---|
| 88 | |
---|
[295] | 89 | const char * ioc_subtype[] = |
---|
[289] | 90 | { |
---|
| 91 | "BDV", |
---|
| 92 | "HBA", |
---|
| 93 | "SPI", |
---|
| 94 | }; |
---|
| 95 | |
---|
[258] | 96 | const char * port_direction[] = |
---|
| 97 | { |
---|
| 98 | "TO_COPROC", |
---|
| 99 | "FROM_COPROC", |
---|
| 100 | }; |
---|
| 101 | |
---|
| 102 | const char * mode_str[] = |
---|
| 103 | { |
---|
| 104 | "____", |
---|
| 105 | "___U", |
---|
| 106 | "__W_", |
---|
| 107 | "__WU", |
---|
| 108 | "_X__", |
---|
| 109 | "_X_U", |
---|
| 110 | "_XW_", |
---|
| 111 | "_XWU", |
---|
| 112 | "C___", |
---|
| 113 | "C__U", |
---|
| 114 | "C_W_", |
---|
| 115 | "C_WU", |
---|
| 116 | "CX__", |
---|
| 117 | "CX_U", |
---|
| 118 | "CXW_", |
---|
| 119 | "CXWU", |
---|
| 120 | }; |
---|
| 121 | |
---|
| 122 | unsigned int vspace_id; |
---|
| 123 | unsigned int cluster_id; |
---|
| 124 | unsigned int pseg_id; |
---|
| 125 | unsigned int vseg_id; |
---|
| 126 | unsigned int vobj_id; |
---|
| 127 | unsigned int task_id; |
---|
| 128 | unsigned int proc_id; |
---|
| 129 | unsigned int irq_id; |
---|
| 130 | unsigned int coproc_id; |
---|
| 131 | unsigned int port_id; |
---|
| 132 | unsigned int periph_id; |
---|
| 133 | |
---|
| 134 | mapping_cluster_t * cluster; |
---|
| 135 | mapping_pseg_t * pseg; |
---|
| 136 | mapping_vspace_t * vspace; |
---|
| 137 | mapping_vseg_t * vseg; |
---|
| 138 | mapping_vobj_t * vobj; |
---|
| 139 | mapping_task_t * task; |
---|
| 140 | mapping_proc_t * proc; |
---|
| 141 | mapping_irq_t * irq; |
---|
| 142 | mapping_coproc_t * coproc; |
---|
| 143 | mapping_cp_port_t * cp_port; |
---|
| 144 | mapping_periph_t * periph; |
---|
| 145 | |
---|
| 146 | // computes the base adresss for clusters array, |
---|
| 147 | cluster = (mapping_cluster_t *)((char *) header + |
---|
| 148 | MAPPING_HEADER_SIZE); |
---|
| 149 | |
---|
| 150 | // computes the base adresss for psegs array, |
---|
| 151 | pseg = (mapping_pseg_t *) ((char *) header + |
---|
| 152 | MAPPING_HEADER_SIZE + |
---|
[263] | 153 | MAPPING_CLUSTER_SIZE * header->x_size * header->y_size); |
---|
[258] | 154 | |
---|
| 155 | // computes the base adresss for vspaces array, |
---|
| 156 | vspace = (mapping_vspace_t *) ((char *) header + |
---|
| 157 | MAPPING_HEADER_SIZE + |
---|
[263] | 158 | MAPPING_CLUSTER_SIZE * header->x_size * header->y_size + |
---|
[258] | 159 | MAPPING_PSEG_SIZE * header->psegs); |
---|
| 160 | |
---|
| 161 | // computes the base adresss for vsegs array, |
---|
| 162 | vseg = (mapping_vseg_t *) ((char *) header + |
---|
| 163 | MAPPING_HEADER_SIZE + |
---|
[263] | 164 | MAPPING_CLUSTER_SIZE * header->x_size * header->y_size + |
---|
[258] | 165 | MAPPING_PSEG_SIZE * header->psegs + |
---|
| 166 | MAPPING_VSPACE_SIZE * header->vspaces); |
---|
| 167 | |
---|
| 168 | // computes the base adresss for vobjs array, |
---|
| 169 | vobj = (mapping_vobj_t *) ((char *) header + |
---|
| 170 | MAPPING_HEADER_SIZE + |
---|
[263] | 171 | MAPPING_CLUSTER_SIZE * header->x_size * header->y_size + |
---|
[258] | 172 | MAPPING_PSEG_SIZE * header->psegs + |
---|
| 173 | MAPPING_VSPACE_SIZE * header->vspaces + |
---|
| 174 | MAPPING_VSEG_SIZE * header->vsegs); |
---|
| 175 | |
---|
| 176 | // computes the base address for tasks array |
---|
| 177 | task = (mapping_task_t *) ((char *) header + |
---|
| 178 | MAPPING_HEADER_SIZE + |
---|
[263] | 179 | MAPPING_CLUSTER_SIZE * header->x_size * header->y_size + |
---|
[258] | 180 | MAPPING_PSEG_SIZE * header->psegs + |
---|
| 181 | MAPPING_VSPACE_SIZE * header->vspaces + |
---|
| 182 | MAPPING_VOBJ_SIZE * header->vobjs + |
---|
| 183 | MAPPING_VSEG_SIZE * header->vsegs); |
---|
| 184 | |
---|
| 185 | // computes the base address for procs array |
---|
| 186 | proc = (mapping_proc_t *) ((char *) header + |
---|
| 187 | MAPPING_HEADER_SIZE + |
---|
[263] | 188 | MAPPING_CLUSTER_SIZE * header->x_size * header->y_size + |
---|
[258] | 189 | MAPPING_PSEG_SIZE * header->psegs + |
---|
| 190 | MAPPING_VSPACE_SIZE * header->vspaces + |
---|
| 191 | MAPPING_VOBJ_SIZE * header->vobjs + |
---|
| 192 | MAPPING_VSEG_SIZE * header->vsegs + |
---|
| 193 | MAPPING_TASK_SIZE * header->tasks); |
---|
| 194 | |
---|
| 195 | // computes the base address for irqs array |
---|
| 196 | irq = (mapping_irq_t *) ((char *) header + |
---|
| 197 | MAPPING_HEADER_SIZE + |
---|
[263] | 198 | MAPPING_CLUSTER_SIZE * header->x_size * header->y_size + |
---|
[258] | 199 | MAPPING_PSEG_SIZE * header->psegs + |
---|
| 200 | MAPPING_VSPACE_SIZE * header->vspaces + |
---|
| 201 | MAPPING_VOBJ_SIZE * header->vobjs + |
---|
| 202 | MAPPING_VSEG_SIZE * header->vsegs + |
---|
| 203 | MAPPING_TASK_SIZE * header->tasks + |
---|
| 204 | MAPPING_PROC_SIZE * header->procs); |
---|
| 205 | |
---|
| 206 | // computes the base address for coprocs array |
---|
| 207 | coproc = (mapping_coproc_t *) ((char *) header + |
---|
| 208 | MAPPING_HEADER_SIZE + |
---|
[263] | 209 | MAPPING_CLUSTER_SIZE * header->x_size * header->y_size + |
---|
[258] | 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 | |
---|
| 218 | // computes the base address for cp_ports array |
---|
| 219 | cp_port = (mapping_cp_port_t *) ((char *) header + |
---|
| 220 | MAPPING_HEADER_SIZE + |
---|
[263] | 221 | MAPPING_CLUSTER_SIZE * header->x_size * header->y_size + |
---|
[258] | 222 | MAPPING_PSEG_SIZE * header->psegs + |
---|
| 223 | MAPPING_VSPACE_SIZE * header->vspaces + |
---|
| 224 | MAPPING_VOBJ_SIZE * header->vobjs + |
---|
| 225 | MAPPING_VSEG_SIZE * header->vsegs + |
---|
| 226 | MAPPING_TASK_SIZE * header->tasks + |
---|
| 227 | MAPPING_PROC_SIZE * header->procs + |
---|
| 228 | MAPPING_IRQ_SIZE * header->irqs + |
---|
| 229 | MAPPING_COPROC_SIZE * header->coprocs); |
---|
| 230 | |
---|
| 231 | // computes the base address for periphs array |
---|
| 232 | periph = (mapping_periph_t *) ((char *) header + |
---|
| 233 | MAPPING_HEADER_SIZE + |
---|
[263] | 234 | MAPPING_CLUSTER_SIZE * header->x_size * header->y_size + |
---|
[258] | 235 | MAPPING_PSEG_SIZE * header->psegs + |
---|
| 236 | MAPPING_VSPACE_SIZE * header->vspaces + |
---|
| 237 | MAPPING_VOBJ_SIZE * header->vobjs + |
---|
| 238 | MAPPING_VSEG_SIZE * header->vsegs + |
---|
| 239 | MAPPING_TASK_SIZE * header->tasks + |
---|
| 240 | MAPPING_PROC_SIZE * header->procs + |
---|
| 241 | MAPPING_IRQ_SIZE * header->irqs + |
---|
| 242 | MAPPING_COPROC_SIZE * header->coprocs + |
---|
| 243 | MAPPING_CP_PORT_SIZE * header->cp_ports); |
---|
| 244 | |
---|
| 245 | ///////////////////////// header ///////////////////////////////////////////// |
---|
| 246 | |
---|
| 247 | fprintf(fpout, "<?xml version = \"1.0\"?>\n\n"); |
---|
| 248 | |
---|
[287] | 249 | fprintf(fpout, "<mapping_info signature = \"0x%x\" \n" , header->signature); |
---|
| 250 | fprintf(fpout, " name = \"%s\" \n" , header->name); |
---|
| 251 | fprintf(fpout, " x_size = \"%d\" \n" , header->x_size); |
---|
| 252 | fprintf(fpout, " y_size = \"%d\" \n" , header->y_size); |
---|
| 253 | fprintf(fpout, " x_width = \"%d\" \n" , header->x_width); |
---|
| 254 | fprintf(fpout, " y_width = \"%d\" \n" , header->y_width); |
---|
[295] | 255 | fprintf(fpout, " irq_per_proc = \"%d\" \n" , header->irq_per_proc); |
---|
[306] | 256 | fprintf(fpout, " use_ram_disk = \"%d\" \n" , header->use_ram_disk); |
---|
[295] | 257 | fprintf(fpout, " x_io = \"%d\" \n" , header->x_io); |
---|
| 258 | fprintf(fpout, " y_io = \"%d\" >\n\n", header->y_io); |
---|
[258] | 259 | |
---|
| 260 | ///////////////////// clusters /////////////////////////////////////////////// |
---|
| 261 | |
---|
| 262 | fprintf( fpout, " <clusterset>\n"); |
---|
[263] | 263 | for (cluster_id = 0; cluster_id < (header->x_size * header->y_size); cluster_id++) |
---|
[258] | 264 | { |
---|
[306] | 265 | fprintf(fpout, " <cluster x=\"%d\" y=\"%d\" >\n", |
---|
[263] | 266 | cluster[cluster_id].x, cluster[cluster_id].y ); |
---|
| 267 | |
---|
| 268 | ///////////////////// psegs //////////////////////////////////////////////// |
---|
| 269 | |
---|
[258] | 270 | for (pseg_id = cluster[cluster_id].pseg_offset; |
---|
| 271 | pseg_id < cluster[cluster_id].pseg_offset + cluster[cluster_id].psegs; |
---|
| 272 | pseg_id++) |
---|
| 273 | { |
---|
[306] | 274 | fprintf(fpout, " <pseg name=\"%s\"", pseg[pseg_id].name); |
---|
| 275 | fprintf(fpout, " type=\"%s\"", pseg_type[pseg[pseg_id].type]); |
---|
| 276 | fprintf(fpout, " base=\"0x%llx\"", pseg[pseg_id].base); |
---|
| 277 | fprintf(fpout, " length=\"0x%llx\" />\n", pseg[pseg_id].length); |
---|
[258] | 278 | } |
---|
| 279 | |
---|
| 280 | ///////////////////// processors ///////////////////////////////////////////// |
---|
| 281 | |
---|
| 282 | unsigned int proc_index = 0; |
---|
| 283 | for (proc_id = cluster[cluster_id].proc_offset; |
---|
| 284 | proc_id < cluster[cluster_id].proc_offset + cluster[cluster_id].procs; |
---|
[295] | 285 | proc_id++, proc_index++) |
---|
[258] | 286 | { |
---|
[306] | 287 | fprintf(fpout, " <proc index=\"%d\" />\n", proc_index); |
---|
[258] | 288 | } |
---|
| 289 | |
---|
| 290 | ///////////////////// coprocessors /////////////////////////////////////////// |
---|
| 291 | |
---|
| 292 | for (coproc_id = cluster[cluster_id].coproc_offset; |
---|
| 293 | coproc_id < cluster[cluster_id].coproc_offset + cluster[cluster_id].coprocs; |
---|
| 294 | coproc_id++) |
---|
| 295 | { |
---|
[306] | 296 | fprintf(fpout, " <coproc name=\"%s\"", coproc[coproc_id].name); |
---|
| 297 | fprintf(fpout, " psegname=\"%s\" >\n", pseg[coproc[coproc_id].psegid].name); |
---|
[258] | 298 | for (port_id = coproc[coproc_id].port_offset; |
---|
| 299 | port_id < coproc[coproc_id].port_offset + coproc[coproc_id].ports; |
---|
| 300 | port_id++) |
---|
| 301 | { |
---|
| 302 | unsigned int vobj_id = cp_port[port_id].mwmr_vobjid + vspace[cp_port[port_id].vspaceid].vobj_offset; |
---|
[306] | 303 | fprintf(fpout, " <port direction=\"%s\"", port_direction[cp_port[port_id].direction]); |
---|
| 304 | fprintf(fpout, " vspacename=\"%s\"", vspace[cp_port[port_id].vspaceid].name); |
---|
| 305 | fprintf(fpout, " vobjname=\"%s\" />\n", vobj[vobj_id].name); |
---|
[258] | 306 | } |
---|
| 307 | fprintf(fpout, " </coproc>\n" ); |
---|
| 308 | } |
---|
| 309 | |
---|
| 310 | ///////////////////// periphs /////////////////////////////////////////////// |
---|
| 311 | |
---|
| 312 | for (periph_id = cluster[cluster_id].periph_offset; |
---|
| 313 | periph_id < cluster[cluster_id].periph_offset + cluster[cluster_id].periphs; |
---|
| 314 | periph_id++) |
---|
| 315 | { |
---|
[306] | 316 | fprintf(fpout, " <periph type=\"%s\"", periph_type[periph[periph_id].type]); |
---|
[289] | 317 | |
---|
[306] | 318 | if (periph[periph_id].type == PERIPH_TYPE_IOC) |
---|
| 319 | fprintf(fpout, " subtype=\"%s\"", ioc_subtype[periph[periph_id].subtype]); |
---|
[289] | 320 | |
---|
[306] | 321 | fprintf(fpout, " psegname=\"%s\"", pseg[periph[periph_id].psegid].name); |
---|
| 322 | fprintf(fpout, " channels=\"%d\" >\n", periph[periph_id].channels); |
---|
| 323 | if ( periph[periph_id].type == PERIPH_TYPE_PIC ) |
---|
[295] | 324 | { |
---|
[306] | 325 | for (irq_id = periph[periph_id].irq_offset; |
---|
| 326 | irq_id < periph[periph_id].irq_offset + periph[periph_id].irqs; |
---|
| 327 | irq_id++) |
---|
| 328 | { |
---|
| 329 | fprintf(fpout, " <irq srcid=\"%d\" ", irq[irq_id].srcid); |
---|
| 330 | fprintf(fpout, " dstx=\"%d\"", irq[irq_id].dstx); |
---|
| 331 | fprintf(fpout, " dsty=\"%d\"", irq[irq_id].dsty); |
---|
| 332 | fprintf(fpout, " dstid=\"%d\" />\n", irq[irq_id].dstid); |
---|
| 333 | } |
---|
[295] | 334 | } |
---|
[306] | 335 | if ( (periph[periph_id].type == PERIPH_TYPE_XCU ) || |
---|
| 336 | (periph[periph_id].type == PERIPH_TYPE_ICU ) ) |
---|
| 337 | { |
---|
| 338 | for (irq_id = periph[periph_id].irq_offset; |
---|
| 339 | irq_id < periph[periph_id].irq_offset + periph[periph_id].irqs; |
---|
| 340 | irq_id++) |
---|
| 341 | { |
---|
| 342 | fprintf(fpout, " <irq srctype=\"%s\"", irq_type[irq[irq_id].srctype]); |
---|
| 343 | fprintf(fpout, " srcid=\"%d\"", irq[irq_id].srcid); |
---|
| 344 | fprintf(fpout, " isr=\"%s\"", isr_type[irq[irq_id].isr]); |
---|
| 345 | fprintf(fpout, " channel=\"%d\"", irq[irq_id].channel); |
---|
| 346 | fprintf(fpout, " dstid=\"%d\" />\n", irq[irq_id].dstid); |
---|
| 347 | } |
---|
| 348 | } |
---|
[295] | 349 | fprintf(fpout, " </periph>\n"); |
---|
[258] | 350 | } |
---|
| 351 | fprintf(fpout, " </cluster>\n" ); |
---|
| 352 | } |
---|
| 353 | fprintf(fpout, " </clusterset>\n\n" ); |
---|
| 354 | |
---|
| 355 | /////////////////// globals ///////////////////////////////////////////////// |
---|
| 356 | |
---|
| 357 | fprintf(fpout, " <globalset>\n" ); |
---|
| 358 | for (vseg_id = 0; vseg_id < header->globals; vseg_id++) |
---|
| 359 | { |
---|
[306] | 360 | unsigned int pseg_id = vseg[vseg_id].psegid; |
---|
| 361 | unsigned int cluster_id = pseg[pseg_id].clusterid; |
---|
[258] | 362 | |
---|
[306] | 363 | fprintf(fpout, " <vseg name=\"%s\"", vseg[vseg_id].name); |
---|
| 364 | fprintf(fpout, " vbase=\"0x%x\"", vseg[vseg_id].vbase); |
---|
| 365 | fprintf(fpout, " mode=\"%s\"", mode_str[vseg[vseg_id].mode]); |
---|
| 366 | fprintf(fpout, " x=\"%d\"", cluster[cluster_id].x); |
---|
| 367 | fprintf(fpout, " y=\"%d\"", cluster[cluster_id].y); |
---|
| 368 | fprintf(fpout, " psegname=\"%s\"", pseg[pseg_id].name); |
---|
| 369 | if( vseg[vseg_id].ident ) fprintf(fpout, " ident=\"1\""); |
---|
| 370 | fprintf(fpout, " >\n"); |
---|
| 371 | |
---|
[258] | 372 | for (vobj_id = vseg[vseg_id].vobj_offset; |
---|
| 373 | vobj_id < (vseg[vseg_id].vobj_offset + vseg[vseg_id].vobjs); |
---|
| 374 | vobj_id++) |
---|
| 375 | { |
---|
[306] | 376 | fprintf(fpout, " <vobj name=\"%s\"", vobj[vobj_id].name); |
---|
| 377 | fprintf(fpout, " type=\"%s\"", vobj_type[vobj[vobj_id].type]); |
---|
| 378 | fprintf(fpout, " length=\"0x%x\"", vobj[vobj_id].length); |
---|
| 379 | if( vobj[vobj_id].align ) |
---|
| 380 | fprintf(fpout, " align=\"%d\"", vobj[vobj_id].align); |
---|
| 381 | if( vobj[vobj_id].binpath[0] != 0 ) |
---|
| 382 | fprintf(fpout, " binpath=\"%s\"", vobj[vobj_id].binpath); |
---|
| 383 | if( (vobj[vobj_id].type == VOBJ_TYPE_BARRIER) || |
---|
| 384 | (vobj[vobj_id].type == VOBJ_TYPE_MWMR ) || |
---|
| 385 | (vobj[vobj_id].type == VOBJ_TYPE_CONST ) ) |
---|
| 386 | fprintf(fpout, " init=\"%d\"", vobj[vobj_id].init); |
---|
| 387 | fprintf(fpout, " />\n"); |
---|
[258] | 388 | } |
---|
| 389 | fprintf(fpout, " </vseg>\n"); |
---|
| 390 | } |
---|
| 391 | fprintf(fpout, " </globalset>\n" ); |
---|
| 392 | |
---|
| 393 | //////////////////// vspaces //////////////////////////////////////////////// |
---|
| 394 | |
---|
| 395 | fprintf( fpout, "\n <vspaceset>\n\n" ); |
---|
| 396 | for (vspace_id = 0; vspace_id < header->vspaces; vspace_id++) |
---|
| 397 | { |
---|
| 398 | unsigned int func_id = vspace[vspace_id].vobj_offset + vspace[vspace_id].start_offset; |
---|
| 399 | fprintf(fpout, " <vspace name = \"%s\" ", vspace[vspace_id].name); |
---|
| 400 | fprintf(fpout, " startname = \"%s\" >\n", vobj[func_id].name); |
---|
| 401 | |
---|
[263] | 402 | //////////////////// vsegs ////////////////////////////////////////////// |
---|
| 403 | |
---|
[258] | 404 | for (vseg_id = vspace[vspace_id].vseg_offset; |
---|
| 405 | vseg_id < (vspace[vspace_id].vseg_offset + vspace[vspace_id].vsegs); |
---|
| 406 | vseg_id++) |
---|
| 407 | { |
---|
[263] | 408 | unsigned int pseg_id = vseg[vseg_id].psegid; |
---|
| 409 | unsigned int cluster_id = pseg[pseg_id].clusterid; |
---|
[258] | 410 | |
---|
[306] | 411 | fprintf(fpout, " <vseg name=\"%s\"", vseg[vseg_id].name); |
---|
| 412 | fprintf(fpout, " vbase=\"0x%x\"", vseg[vseg_id].vbase); |
---|
| 413 | fprintf(fpout, " mode=\"%s\"", mode_str[vseg[vseg_id].mode]); |
---|
| 414 | fprintf(fpout, " x=\"%d\"", cluster[cluster_id].x); |
---|
| 415 | fprintf(fpout, " y=\"%d\"", cluster[cluster_id].y); |
---|
| 416 | fprintf(fpout, " psegname=\"%s\"", pseg[pseg_id].name); |
---|
| 417 | if( vseg[vseg_id].ident ) fprintf(fpout, " ident=\"1\""); |
---|
| 418 | fprintf(fpout, " >\n"); |
---|
[258] | 419 | |
---|
| 420 | for (vobj_id = vseg[vseg_id].vobj_offset; |
---|
| 421 | vobj_id < (vseg[vseg_id].vobj_offset + vseg[vseg_id].vobjs); |
---|
| 422 | vobj_id++) |
---|
| 423 | { |
---|
[306] | 424 | fprintf(fpout, " <vobj name=\"%s\"", vobj[vobj_id].name); |
---|
| 425 | fprintf(fpout, " type=\"%s\"", vobj_type[vobj[vobj_id].type]); |
---|
| 426 | fprintf(fpout, " length=\"0x%x\"", vobj[vobj_id].length); |
---|
| 427 | if( vobj[vobj_id].align ) |
---|
| 428 | fprintf(fpout, " align=\"%d\"", vobj[vobj_id].align); |
---|
| 429 | if( vobj[vobj_id].binpath[0] != 0 ) |
---|
| 430 | fprintf(fpout, " binpath=\"%s\"", vobj[vobj_id].binpath); |
---|
| 431 | if( (vobj[vobj_id].type == VOBJ_TYPE_BARRIER) || |
---|
| 432 | (vobj[vobj_id].type == VOBJ_TYPE_MWMR ) || |
---|
| 433 | (vobj[vobj_id].type == VOBJ_TYPE_CONST ) ) |
---|
| 434 | fprintf(fpout, " init=\"%d\"", vobj[vobj_id].init); |
---|
| 435 | fprintf(fpout, " />\n"); |
---|
[258] | 436 | } |
---|
| 437 | fprintf(fpout, " </vseg>\n\n"); |
---|
| 438 | } |
---|
[263] | 439 | |
---|
| 440 | //////////////////// tasks ////////////////////////////////////////////// |
---|
| 441 | |
---|
[258] | 442 | for (task_id = vspace[vspace_id].task_offset; |
---|
| 443 | task_id < (vspace[vspace_id].task_offset + vspace[vspace_id].tasks); |
---|
| 444 | task_id++) |
---|
| 445 | { |
---|
| 446 | unsigned int stack_vobj_id = task[task_id].stack_vobjid + vspace[vspace_id].vobj_offset; |
---|
| 447 | unsigned int heap_vobj_id = task[task_id].heap_vobjid + vspace[vspace_id].vobj_offset; |
---|
[263] | 448 | unsigned int cluster_id = task[task_id].clusterid; |
---|
[258] | 449 | |
---|
[306] | 450 | fprintf(fpout, " <task name=\"%s\"", task[task_id].name); |
---|
| 451 | fprintf(fpout, " trdid=\"%d\"", task[task_id].trdid); |
---|
| 452 | fprintf(fpout, " x=\"%d\"", cluster[cluster_id].x); |
---|
| 453 | fprintf(fpout, " y=\"%d\"", cluster[cluster_id].y); |
---|
| 454 | fprintf(fpout, " p=\"%d\"", task[task_id].proclocid); |
---|
| 455 | fprintf(fpout, " stackname=\"%s\"", vobj[stack_vobj_id].name); |
---|
[258] | 456 | if (heap_vobj_id != -1) |
---|
| 457 | { |
---|
[306] | 458 | fprintf(fpout, " heapname=\"%s\"", vobj[heap_vobj_id].name); |
---|
[258] | 459 | } |
---|
[306] | 460 | fprintf(fpout, " startid = \"%d\"", task[task_id].startid); |
---|
| 461 | if( task[task_id].use_tty ) fprintf(fpout, " usetty=\"1\""); |
---|
| 462 | if( task[task_id].use_nic ) fprintf(fpout, " usenic=\"1\""); |
---|
| 463 | if( task[task_id].use_cma ) fprintf(fpout, " usecma=\"1\""); |
---|
| 464 | if( task[task_id].use_tim ) fprintf(fpout, " usetim=\"1\""); |
---|
| 465 | if( task[task_id].use_hba ) fprintf(fpout, " usehba=\"1\""); |
---|
| 466 | fprintf(fpout, " />\n"); |
---|
[258] | 467 | } |
---|
| 468 | fprintf(fpout, " </vspace>\n\n"); |
---|
| 469 | } |
---|
| 470 | fprintf(fpout, " </vspaceset>\n"); |
---|
| 471 | fprintf(fpout, "</mapping_info>\n"); |
---|
| 472 | } // end buildXml() |
---|
| 473 | |
---|
| 474 | |
---|
| 475 | ///////////////////////////////////// |
---|
[306] | 476 | int main(int argc, char * argv[]) |
---|
| 477 | { |
---|
| 478 | if (argc < 2) |
---|
| 479 | { |
---|
[258] | 480 | printf("Usage: bin2xml <input_file_path> <output_file_path>\n"); |
---|
| 481 | return 1; |
---|
| 482 | } |
---|
| 483 | |
---|
| 484 | unsigned int bin[0x10000]; // 64 K int = 256 Kbytes |
---|
| 485 | |
---|
| 486 | int fdin = open(argv[1], O_RDONLY); |
---|
[306] | 487 | if (fdin < 0) |
---|
| 488 | { |
---|
[258] | 489 | perror("open"); |
---|
| 490 | exit(1); |
---|
| 491 | } |
---|
| 492 | |
---|
| 493 | FILE * fpout = fopen( argv[2], "w"); |
---|
[306] | 494 | if (fpout == NULL) |
---|
| 495 | { |
---|
[258] | 496 | perror("open"); |
---|
| 497 | exit(1); |
---|
| 498 | } |
---|
| 499 | |
---|
| 500 | unsigned int length = read(fdin, bin, 0x40000); |
---|
| 501 | |
---|
[306] | 502 | if (length <= 0) |
---|
| 503 | { |
---|
[258] | 504 | perror("read"); |
---|
| 505 | exit(1); |
---|
| 506 | } |
---|
| 507 | |
---|
[306] | 508 | if (bin[0] == IN_MAPPING_SIGNATURE) |
---|
| 509 | { |
---|
[258] | 510 | buildXml((mapping_header_t *) bin, fpout); |
---|
| 511 | } |
---|
[306] | 512 | else |
---|
| 513 | { |
---|
[258] | 514 | printf("[ERROR] Wrong file format\n"); |
---|
| 515 | exit(1); |
---|
| 516 | } |
---|
| 517 | return 0; |
---|
| 518 | } // end main() |
---|
| 519 | |
---|
| 520 | |
---|
| 521 | |
---|
| 522 | // Local Variables: |
---|
| 523 | // tab-width: 4 |
---|
| 524 | // c-basic-offset: 4 |
---|
| 525 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 526 | // indent-tabs-mode: nil |
---|
| 527 | // End: |
---|
| 528 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 529 | |
---|