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