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

Last change on this file since 215 was 215, checked in by karaoui, 12 years ago

New components are now mandotory in the XML description:

The files giet_vsegs.ld and hard_config.h are now autogenerated by the xml2bin tool.

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