source: branch/giet_vm_ioc_drivers/giet_xml/xml_driver.c @ 284

Last change on this file since 284 was 283, checked in by cfuguet, 11 years ago

Introducing branch to test ioc drivers before merging on trunk

  • Property svn:executable set to *
File size: 17.9 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        "SCHED",      // Scheduler
34    };
35
36    const char * pseg_type[] = 
37    {
38        "RAM",
39        "ROM",
40        "PERI",
41    };
42
43    const char * irq_type[] =
44    {
45        "HARD",
46        "SOFT",
47    };
48
49    const char * isr_type[] =
50    {
51        "ISR_DEFAULT",
52        "ISR_SWITCH",
53        "ISR_TTY",
54        "ISR_DMA",
55        "ISR_IOC",
56        "ISR_TIMER",
57    };
58
59    const char * periph_type[] =
60    {
61        "CMA",
62        "DMA",
63        "FBF",
64        "HBA",
65        "ICU",
66        "IOB",
67        "IOC",
68        "MMC",
69        "MWR",
70        "NIC",
71        "ROM",
72        "SIM",
73        "TIM",
74        "TTY",
75        "XCU",
76    };
77
78    const char * periph_subtype[] =
79    {
80        "BDV",
81        "HBA",
82        "SPI",
83    };
84
85    const char * port_direction[] =
86    {
87        "TO_COPROC",
88        "FROM_COPROC",
89    };
90
91    const char * mode_str[] = 
92    { 
93        "____",
94        "___U", 
95        "__W_", 
96        "__WU", 
97        "_X__", 
98        "_X_U", 
99        "_XW_", 
100        "_XWU", 
101        "C___", 
102        "C__U", 
103        "C_W_", 
104        "C_WU", 
105        "CX__", 
106        "CX_U", 
107        "CXW_", 
108        "CXWU", 
109    };
110
111    unsigned int vspace_id;
112    unsigned int cluster_id;
113    unsigned int pseg_id;
114    unsigned int vseg_id;
115    unsigned int vobj_id;
116    unsigned int task_id;
117    unsigned int proc_id;
118    unsigned int irq_id;
119    unsigned int coproc_id;
120    unsigned int port_id;
121    unsigned int periph_id;
122
123    mapping_cluster_t * cluster;
124    mapping_pseg_t * pseg;
125    mapping_vspace_t * vspace;
126    mapping_vseg_t * vseg;
127    mapping_vobj_t * vobj;
128    mapping_task_t * task;
129    mapping_proc_t * proc;
130    mapping_irq_t * irq;   
131    mapping_coproc_t * coproc;
132    mapping_cp_port_t * cp_port;
133    mapping_periph_t * periph;
134
135    // computes the base adresss for clusters array,
136    cluster = (mapping_cluster_t *)((char *) header +
137            MAPPING_HEADER_SIZE);
138
139    // computes the base adresss for psegs array,
140    pseg = (mapping_pseg_t *) ((char *) header +
141            MAPPING_HEADER_SIZE +
142            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size);
143
144    // computes the base adresss for vspaces array,
145    vspace = (mapping_vspace_t *) ((char *) header +
146            MAPPING_HEADER_SIZE +
147            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size +
148            MAPPING_PSEG_SIZE * header->psegs);
149
150    // computes the base adresss for vsegs array,
151    vseg = (mapping_vseg_t *) ((char *) header +
152            MAPPING_HEADER_SIZE +
153            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size +
154            MAPPING_PSEG_SIZE * header->psegs +
155            MAPPING_VSPACE_SIZE * header->vspaces);
156
157    // computes the base adresss for vobjs array,
158    vobj = (mapping_vobj_t *) ((char *) header +
159            MAPPING_HEADER_SIZE +
160            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size +
161            MAPPING_PSEG_SIZE * header->psegs +
162            MAPPING_VSPACE_SIZE * header->vspaces +
163            MAPPING_VSEG_SIZE * header->vsegs);
164
165    // computes the base address for tasks array
166    task = (mapping_task_t *) ((char *) header +
167            MAPPING_HEADER_SIZE +
168            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size +
169            MAPPING_PSEG_SIZE * header->psegs +
170            MAPPING_VSPACE_SIZE * header->vspaces +
171            MAPPING_VOBJ_SIZE * header->vobjs +
172            MAPPING_VSEG_SIZE * header->vsegs);
173
174    // computes the base address for procs array
175    proc = (mapping_proc_t *) ((char *) header +
176            MAPPING_HEADER_SIZE +
177            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size +
178            MAPPING_PSEG_SIZE * header->psegs +
179            MAPPING_VSPACE_SIZE * header->vspaces +
180            MAPPING_VOBJ_SIZE * header->vobjs +
181            MAPPING_VSEG_SIZE * header->vsegs +
182            MAPPING_TASK_SIZE * header->tasks);
183
184    // computes the base address for irqs array
185    irq = (mapping_irq_t *) ((char *) header +
186            MAPPING_HEADER_SIZE +
187            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size +
188            MAPPING_PSEG_SIZE * header->psegs +
189            MAPPING_VSPACE_SIZE * header->vspaces +
190            MAPPING_VOBJ_SIZE * header->vobjs +
191            MAPPING_VSEG_SIZE * header->vsegs +
192            MAPPING_TASK_SIZE * header->tasks +
193            MAPPING_PROC_SIZE * header->procs);
194
195    // computes the base address for coprocs array
196    coproc = (mapping_coproc_t *) ((char *) header +
197            MAPPING_HEADER_SIZE +
198            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size +
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            MAPPING_IRQ_SIZE * header->irqs);
206
207    // computes the base address for cp_ports array
208    cp_port = (mapping_cp_port_t *) ((char *) header +
209            MAPPING_HEADER_SIZE +
210            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size +
211            MAPPING_PSEG_SIZE * header->psegs +
212            MAPPING_VSPACE_SIZE * header->vspaces +
213            MAPPING_VOBJ_SIZE * header->vobjs +
214            MAPPING_VSEG_SIZE * header->vsegs +
215            MAPPING_TASK_SIZE * header->tasks +
216            MAPPING_PROC_SIZE * header->procs +
217            MAPPING_IRQ_SIZE * header->irqs +
218            MAPPING_COPROC_SIZE * header->coprocs);
219
220    // computes the base address for periphs array
221    periph = (mapping_periph_t *) ((char *) header +
222            MAPPING_HEADER_SIZE +
223            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size +
224            MAPPING_PSEG_SIZE * header->psegs +
225            MAPPING_VSPACE_SIZE * header->vspaces +
226            MAPPING_VOBJ_SIZE * header->vobjs +
227            MAPPING_VSEG_SIZE * header->vsegs +
228            MAPPING_TASK_SIZE * header->tasks +
229            MAPPING_PROC_SIZE * header->procs +
230            MAPPING_IRQ_SIZE * header->irqs +
231            MAPPING_COPROC_SIZE * header->coprocs +
232            MAPPING_CP_PORT_SIZE * header->cp_ports);
233
234    ///////////////////////// header /////////////////////////////////////////////
235
236    fprintf(fpout, "<?xml version = \"1.0\"?>\n\n");
237
238    fprintf(fpout, "<mapping_info signature = \"0x%x\" \n", header->signature);
239    fprintf(fpout, "              name      = \"%s\"   \n", header->name);
240    fprintf(fpout, "              x_size    = \"%d\"   \n", header->x_size);
241    fprintf(fpout, "              y_size    = \"%d\"   \n", header->y_size);
242    fprintf(fpout, "              x_width   = \"%d\"   \n", header->x_width);
243    fprintf(fpout, "              y_width   = \"%d\"   \n", header->y_width);
244    fprintf(fpout, "              vspaces   = \"%d\"   \n", header->vspaces);
245    fprintf(fpout, "              increment = \"%d\" >\n\n", header->vspaces);
246
247    ///////////////////// clusters ///////////////////////////////////////////////
248
249    fprintf( fpout, "    <clusterset>\n");
250    for (cluster_id = 0; cluster_id < (header->x_size * header->y_size); cluster_id++) 
251    {
252        fprintf(fpout, "        <cluster x = \"%d\" y = \"%d\" >\n", 
253                cluster[cluster_id].x, cluster[cluster_id].y );
254
255        ///////////////////// psegs   ////////////////////////////////////////////////
256
257        for (pseg_id = cluster[cluster_id].pseg_offset;
258             pseg_id < cluster[cluster_id].pseg_offset + cluster[cluster_id].psegs;
259             pseg_id++) 
260        {
261            fprintf(fpout, "            <pseg name = \"%s\" ", pseg[pseg_id].name);
262            fprintf(fpout, "type = \"%s\" ", pseg_type[pseg[pseg_id].type]);
263            fprintf(fpout, "base = \"0x%llx\" ", pseg[pseg_id].base);
264            fprintf(fpout, "length = \"0x%llx\" />\n",   pseg[pseg_id].length);
265        }
266
267        ///////////////////// processors /////////////////////////////////////////////
268
269        unsigned int proc_index = 0;
270        for (proc_id = cluster[cluster_id].proc_offset;
271             proc_id < cluster[cluster_id].proc_offset + cluster[cluster_id].procs;
272             proc_id++) 
273        {
274            fprintf(fpout, "            <proc index = \"%d\" >\n", proc_index);
275            for (irq_id = proc[proc_id].irq_offset; 
276                 irq_id < proc[proc_id].irq_offset + proc[proc_id].irqs;
277                 irq_id++) 
278            {
279                fprintf(fpout, "                <irq type = \"%s\" ", irq_type[irq[irq_id].type]);
280                fprintf(fpout, " icuid = \"0x%x\" ", irq[irq_id].icuid);
281                fprintf(fpout, " isr = \"%s\" ", isr_type[irq[irq_id].isr]);
282                fprintf(fpout, " channel = \"0x%x\" />\n", irq[irq_id].channel);
283            }
284            fprintf(fpout, "            </proc>\n" );
285        }
286
287
288        ///////////////////// coprocessors ///////////////////////////////////////////
289
290        for (coproc_id = cluster[cluster_id].coproc_offset;
291             coproc_id < cluster[cluster_id].coproc_offset + cluster[cluster_id].coprocs;
292             coproc_id++) 
293        {
294            fprintf(fpout, "            <coproc name = \"%s\" ", coproc[coproc_id].name);
295            fprintf(fpout, " psegname = \"%s\" >\n", pseg[coproc[coproc_id].psegid].name);
296            for (port_id = coproc[coproc_id].port_offset;
297                 port_id < coproc[coproc_id].port_offset + coproc[coproc_id].ports;
298                 port_id++) 
299            {
300                unsigned int vobj_id = cp_port[port_id].mwmr_vobjid + vspace[cp_port[port_id].vspaceid].vobj_offset; 
301                fprintf(fpout, "             <port direction = \"%s\" ",  port_direction[cp_port[port_id].direction]);
302                fprintf(fpout, " vspacename = \"%s\" ", vspace[cp_port[port_id].vspaceid].name);
303                fprintf(fpout, " vobjname = \"%s\" />\n",  vobj[vobj_id].name);
304            }
305            fprintf(fpout, "            </coproc>\n" );
306        }
307
308        ///////////////////// periphs  ///////////////////////////////////////////////
309
310        for (periph_id = cluster[cluster_id].periph_offset;
311             periph_id < cluster[cluster_id].periph_offset + cluster[cluster_id].periphs;
312             periph_id++) 
313        {
314            fprintf(fpout, "            <periph type = \"%s\" ", periph_type[periph[periph_id].type]);
315
316            if (periph[periph_id].subtype < PERIPH_SUBTYPE_MAX_VALUE) 
317                fprintf(fpout, " subtype = \"%s\" ", periph_subtype[periph[periph_id].subtype]);
318
319            fprintf(fpout, " psegname = \"%s\" ", pseg[periph[periph_id].psegid].name);
320            fprintf(fpout, " channels = \"%d\" />\n",  periph[periph_id].channels);
321        }
322        fprintf(fpout, "        </cluster>\n" );
323    }
324    fprintf(fpout, "    </clusterset>\n\n" );
325
326    /////////////////// globals /////////////////////////////////////////////////
327
328    fprintf(fpout, "    <globalset>\n" );
329    for (vseg_id = 0; vseg_id < header->globals; vseg_id++) 
330    {
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].clusterid);
337        fprintf(fpout, "psegname = \"%s\" ", pseg[pseg_id].name);
338        fprintf(fpout, "ident = \"%d\" >\n", vseg[vseg_id].ident);
339        for (vobj_id = vseg[vseg_id].vobj_offset;
340             vobj_id < (vseg[vseg_id].vobj_offset + vseg[vseg_id].vobjs); 
341             vobj_id++) 
342        {
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");
351    }
352    fprintf(fpout, "    </globalset>\n" );
353
354    //////////////////// vspaces ////////////////////////////////////////////////
355
356    fprintf( fpout, "\n    <vspaceset>\n\n" );
357    for (vspace_id = 0; vspace_id < header->vspaces; vspace_id++) 
358    {
359        unsigned int func_id = vspace[vspace_id].vobj_offset + vspace[vspace_id].start_offset; 
360        fprintf(fpout, "        <vspace name = \"%s\" ", vspace[vspace_id].name); 
361        fprintf(fpout, " startname = \"%s\" >\n", vobj[func_id].name); 
362
363        //////////////////// vsegs //////////////////////////////////////////////
364
365        for (vseg_id = vspace[vspace_id].vseg_offset;
366             vseg_id < (vspace[vspace_id].vseg_offset + vspace[vspace_id].vsegs);
367             vseg_id++) 
368        {
369            unsigned int pseg_id    = vseg[vseg_id].psegid; 
370            unsigned int cluster_id = pseg[pseg_id].clusterid;
371            unsigned int x          = cluster_id >> header->y_width;
372            unsigned int y          = cluster_id & ((1<<header->y_width)-1);
373
374            fprintf(fpout, "            <vseg name = \"%s\" ", vseg[vseg_id].name);
375            fprintf(fpout, "vbase = \"0x%x\" ", vseg[vseg_id].vbase);
376            fprintf(fpout, "mode = \"%s\" ", mode_str[vseg[vseg_id].mode]);
377            fprintf(fpout, "x = \"%d\" ", x);
378            fprintf(fpout, "y = \"%d\" ", y);
379            fprintf(fpout, "psegname = \"%s\" ", pseg[pseg_id].name);
380            fprintf(fpout, "ident = \"%d\" >\n", vseg[vseg_id].ident);
381
382            for (vobj_id = vseg[vseg_id].vobj_offset;
383                 vobj_id < (vseg[vseg_id].vobj_offset + vseg[vseg_id].vobjs);
384                 vobj_id++) 
385            {
386                fprintf(fpout, "             <vobj name = \"%s\" ", vobj[vobj_id].name);
387                fprintf(fpout, "type = \"%s\" ", vobj_type[vobj[vobj_id].type]);
388                fprintf(fpout, "length = \"0x%x\" ", vobj[vobj_id].length);
389                fprintf(fpout, "align = \"%d\" ", vobj[vobj_id].align);
390                fprintf(fpout, "init = \"%d\" ", vobj[vobj_id].init);
391                fprintf(fpout, "binpath = \"%s\" />\n", vobj[vobj_id].binpath);
392            }
393            fprintf(fpout, "            </vseg>\n\n");
394        }
395
396        //////////////////// tasks //////////////////////////////////////////////
397
398        for (task_id = vspace[vspace_id].task_offset;
399             task_id < (vspace[vspace_id].task_offset + vspace[vspace_id].tasks);
400             task_id++) 
401        {
402            unsigned int stack_vobj_id = task[task_id].stack_vobjid + vspace[vspace_id].vobj_offset; 
403            unsigned int heap_vobj_id = task[task_id].heap_vobjid + vspace[vspace_id].vobj_offset; 
404            unsigned int cluster_id   = task[task_id].clusterid;
405            unsigned int x            = cluster_id >> header->y_width;
406            unsigned int y            = cluster_id & ((1<<header->y_width)-1);
407
408            fprintf(fpout, "            <task name = \"%s\" ", task[task_id].name);
409            fprintf(fpout, "x = \"%d\" ", x);
410            fprintf(fpout, "y = \"%d\" ", y);
411            fprintf(fpout, "proclocid = \"%d\" ", task[task_id].proclocid);
412            fprintf(fpout, "stackname = \"%s\" ", vobj[stack_vobj_id].name);
413            if (heap_vobj_id != -1) 
414            {
415                fprintf(fpout, "heapname = \"%s\" ", vobj[heap_vobj_id].name);
416            }
417            fprintf(fpout, "startid = \"%d\" ", task[task_id].startid);
418            fprintf(fpout, "usetty = \"%d\" ", task[task_id].use_tty);
419            fprintf(fpout, "usenic = \"%d\" ", task[task_id].use_nic);
420            fprintf(fpout, "usecma = \"%d\" ", task[task_id].use_cma);
421            fprintf(fpout, "usetim = \"%d\" ", task[task_id].use_tim);
422            fprintf(fpout, "usehba = \"%d\" />\n", task[task_id].use_hba);
423        }
424        fprintf(fpout, "        </vspace>\n\n");
425    }
426    fprintf(fpout, "    </vspaceset>\n");
427    fprintf(fpout, "</mapping_info>\n");
428} // end buildXml()
429
430
431/////////////////////////////////////
432int main(int argc, char * argv[]) {
433    if (argc < 2) {
434        printf("Usage: bin2xml <input_file_path> <output_file_path>\n");
435        return 1;
436    }
437
438    unsigned int bin[0x10000]; // 64 K int = 256 Kbytes
439
440    int fdin = open(argv[1], O_RDONLY);
441    if (fdin < 0) {
442        perror("open");
443        exit(1);
444    }
445
446    FILE * fpout = fopen( argv[2], "w");
447    if (fpout == NULL) {
448        perror("open");
449        exit(1);
450    }
451
452    unsigned int length = read(fdin, bin, 0x40000);
453
454    if (length <= 0) {
455        perror("read");
456        exit(1);
457    }
458
459    if (bin[0] == IN_MAPPING_SIGNATURE) {
460        buildXml((mapping_header_t *) bin, fpout);
461    } 
462    else {
463        printf("[ERROR] Wrong file format\n");
464        exit(1);
465    }
466    return 0;
467} // end main()
468
469
470
471// Local Variables:
472// tab-width: 4
473// c-basic-offset: 4
474// c-file-offsets:((innamespace . 0)(inline-open . 0))
475// indent-tabs-mode: nil
476// End:
477// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
478
Note: See TracBrowser for help on using the repository browser.