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

Last change on this file since 204 was 204, checked in by alain, 12 years ago

mproving support for multi-clusters architectures (CLUSTER_SIZE & CLUSTER_IO_ID parameters)

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