source: soft/giet_vm/xml/xml_driver.c @ 232

Last change on this file since 232 was 232, checked in by meunier, 11 years ago

Ajout du malloc dans le Giet.

File size: 16.1 KB
Line 
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//////////////////////////////////////////////////////
20void buildXml(mapping_header_t * header, FILE * fpout) {
21    const char * vobj_type[] = 
22    { 
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
33    };
34
35    const char * pseg_type[] = 
36    {
37        "RAM",
38        "ROM",
39        "PERI",
40    };
41
42    const char * irq_type[] =
43    {
44        "HARD",
45        "SOFT",
46    };
47
48    const char * isr_type[] =
49    {
50        "ISR_DEFAULT",
51        "ISR_SWITCH",
52        "ISR_TTY",
53        "ISR_DMA",
54        "ISR_IOC",
55        "ISR_TIMER",
56    };
57
58    const char * periph_type[] =
59    {
60        "ICU",
61        "TIM",
62        "XICU",
63        "DMA",
64        "IOC",
65        "TTY",
66        "FBF",
67        "NIC",
68        "IOB",
69    };
70
71    const char * port_direction[] =
72    {
73        "TO_COPROC",
74        "FROM_COPROC",
75    };
76
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", 
95    };
96
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;
108
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;
120
121    // computes the base adresss for clusters array,
122    cluster = (mapping_cluster_t *)((char *) header +
123            MAPPING_HEADER_SIZE);
124
125    // computes the base adresss for psegs array,
126    pseg = (mapping_pseg_t *) ((char *) header +
127            MAPPING_HEADER_SIZE +
128            MAPPING_CLUSTER_SIZE * header->clusters);
129
130    // computes the base adresss for vspaces array,
131    vspace = (mapping_vspace_t *) ((char *) header +
132            MAPPING_HEADER_SIZE +
133            MAPPING_CLUSTER_SIZE * header->clusters +
134            MAPPING_PSEG_SIZE * header->psegs);
135
136    // computes the base adresss for vsegs array,
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);
142
143    // computes the base adresss for vobjs array,
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);
150
151    // computes the base address for tasks array
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);
159
160    // computes the base address for procs array
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);
169
170    // computes the base address for irqs array
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);
180
181    // computes the base address for coprocs array
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);
192
193    // computes the base address for cp_ports array
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);
205
206    // computes the base address for periphs array
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);
219
220    ///////////////////////// header /////////////////////////////////////////////
221
222    fprintf(fpout, "<?xml version = \"1.0\"?>\n\n");
223
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);
229
230    ///////////////////// clusters ///////////////////////////////////////////////
231
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);
242        }
243
244        ///////////////////// processors /////////////////////////////////////////////
245
246        unsigned int proc_index = 0;
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);
258            }
259            fprintf(fpout, "            </proc>\n" );
260        }
261
262
263        ///////////////////// coprocessors ///////////////////////////////////////////
264
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++) {
273                unsigned int vobj_id = cp_port[port_id].mwmr_vobjid + vspace[cp_port[port_id].vspaceid].vobj_offset; 
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);
277            }
278            fprintf(fpout, "            </coproc>\n" );
279        }
280
281        ///////////////////// periphs  ///////////////////////////////////////////////
282
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);
289        }
290        fprintf(fpout, "        </cluster>\n" );
291    }
292    fprintf(fpout, "    </clusterset>\n\n" );
293
294    /////////////////// globals /////////////////////////////////////////////////
295
296    fprintf(fpout, "    <globalset>\n" );
297    for (vseg_id = 0; vseg_id < header->globals; vseg_id++) {
298        unsigned int pseg_id = vseg[vseg_id].psegid; 
299
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);
315        }
316        fprintf(fpout, "        </vseg>\n");
317    }
318    fprintf(fpout, "    </globalset>\n" );
319
320    //////////////////// vspaces ////////////////////////////////////////////////
321
322    fprintf( fpout, "\n    <vspaceset>\n\n" );
323    for (vspace_id = 0; vspace_id < header->vspaces; vspace_id++) {
324        unsigned int func_id = vspace[vspace_id].vobj_offset + vspace[vspace_id].start_offset; 
325        fprintf(fpout, "        <vspace name = \"%s\" ", vspace[vspace_id].name); 
326        fprintf(fpout, " startname = \"%s\" >\n", vobj[func_id].name); 
327
328        for (vseg_id = vspace[vspace_id].vseg_offset;
329                vseg_id < (vspace[vspace_id].vseg_offset + vspace[vspace_id].vsegs);
330                vseg_id++) {
331            unsigned int pseg_id = vseg[vseg_id].psegid; 
332
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);
339
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);
349            }
350            fprintf(fpout, "            </vseg>\n\n");
351        }
352        for (task_id = vspace[vspace_id].task_offset;
353                task_id < (vspace[vspace_id].task_offset + vspace[vspace_id].tasks);
354                task_id++) {
355            unsigned int stack_vobj_id = task[task_id].stack_vobjid + vspace[vspace_id].vobj_offset; 
356            unsigned int heap_vobj_id = task[task_id].heap_vobjid + vspace[vspace_id].vobj_offset; 
357
358            fprintf(fpout, "            <task name = \"%s\" ", task[task_id].name);
359            fprintf(fpout, "clusterid = \"%d\" ", task[task_id].clusterid);
360            fprintf(fpout, "proclocid = \"%d\" ", task[task_id].proclocid);
361            fprintf(fpout, "stackname = \"%s\" ", vobj[stack_vobj_id].name);
362            if (heap_vobj_id != -1) {
363                fprintf(fpout, "heapname = \"%s\" ", vobj[heap_vobj_id].name);
364            }
365            fprintf(fpout, "startid = \"%d\" ", task[task_id].startid);
366            fprintf(fpout, "usetty = \"%d\" ", task[task_id].use_tty);
367            fprintf(fpout, "usenic = \"%d\" ", task[task_id].use_nic);
368            fprintf(fpout, "usetimer = \"%d\" ", task[task_id].use_timer);
369            fprintf(fpout, "usefbma = \"%d\" />\n", task[task_id].use_fbdma);
370        }
371        fprintf(fpout, "        </vspace>\n\n");
372    }
373    fprintf(fpout, "    </vspaceset>\n");
374    fprintf(fpout, "</mapping_info>\n");
375} // end buildXml()
376
377
378/////////////////////////////////////
379int main(int argc, char * argv[]) {
380    if (argc < 2) {
381        printf("Usage: bin2xml <input_file_path> <output_file_path>\n");
382        return 1;
383    }
384
385    unsigned int bin[0x10000]; // 64 K int = 256 Kbytes
386
387    int fdin = open(argv[1], O_RDONLY);
388    if (fdin < 0) {
389        perror("open");
390        exit(1);
391    }
392
393    FILE * fpout = fopen( argv[2], "w");
394    if (fpout == NULL) {
395        perror("open");
396        exit(1);
397    }
398
399    unsigned int length = read(fdin, bin, 0x40000);
400
401    if (length <= 0) {
402        perror("read");
403        exit(1);
404    }
405
406    if (bin[0] == IN_MAPPING_SIGNATURE) {
407        buildXml((mapping_header_t *) bin, fpout);
408    } 
409    else {
410        printf("[ERROR] Wrong file format\n");
411        exit(1);
412    }
413    return 0;
414} // end main()
415
416
417
418// Local Variables:
419// tab-width: 4
420// c-basic-offset: 4
421// c-file-offsets:((innamespace . 0)(inline-open . 0))
422// indent-tabs-mode: nil
423// End:
424// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
425
Note: See TracBrowser for help on using the repository browser.