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

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

new version of map.xml supporting the routage and the coproc.
the xml_parser/xml_driver are also updated aproprietly.

File size: 18.4 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
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
31        "BUFFER",       // Any "no intialiasation needed" objects (stacks...)
32        "BARRIER"       // Barrier
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_IOC",
51        "ISR_FBDMA",
52        "ISR_TTY"
53    };
54
55    const char* reg_type[] =
56    {
57        "STATUS",
58        "CONFIG"
59    };
60
61    const char* port_direction[] =
62    {
63        "TO_COPROC",
64        "FROM_COPROC"
65    };
66
67    const char* mode_str[] = 
68    { "____",
69      "___U", 
70      "__W_", 
71      "__WU", 
72      "_X__", 
73      "_X_U", 
74      "_XW_", 
75      "_XWU", 
76      "C___", 
77      "C__U", 
78      "C_W_", 
79      "C_WU", 
80      "CX__", 
81      "CX_U", 
82      "CXW_", 
83      "CXWU" 
84    };
85
86    unsigned int                vspace_id;
87    unsigned int                cluster_id;
88    unsigned int                pseg_id;
89    unsigned int                vseg_id;
90    unsigned int                vobj_id;
91    unsigned int                task_id;
92    unsigned int                proc_id;
93    unsigned int                irq_id;
94    unsigned int                coproc_id;
95    unsigned int                port_id;
96    unsigned int                reg_id;
97
98    mapping_cluster_t*      cluster;
99    mapping_pseg_t*             pseg;
100    mapping_vspace_t*       vspace;
101    mapping_vseg_t*             vseg;
102    mapping_vobj_t*             vobj;
103    mapping_task_t*             task;
104    mapping_proc_t*             proc;
105    mapping_irq_t*              irq;   
106    mapping_coproc_t*       coproc;
107    mapping_coproc_port_t*      cp_port;
108    mapping_coproc_reg_t*   cp_reg;
109
110    // computes the base adresss for clusters array,
111    cluster = (mapping_cluster_t*)((char*)header +
112                                  MAPPING_HEADER_SIZE );
113
114    // computes the base adresss for psegs array,
115    pseg    = (mapping_pseg_t*)   ((char*)header +
116                                  MAPPING_HEADER_SIZE +
117                                  MAPPING_CLUSTER_SIZE*header->clusters );
118
119    // computes the base adresss for vspaces array,
120    vspace  = (mapping_vspace_t*) ((char*)header +
121                                  MAPPING_HEADER_SIZE +
122                                  MAPPING_CLUSTER_SIZE*header->clusters +
123                                  MAPPING_PSEG_SIZE*header->psegs );
124
125    // computes the base adresss for vsegs array,
126    vseg    = (mapping_vseg_t*)   ((char*)header +
127                                  MAPPING_HEADER_SIZE +
128                                  MAPPING_CLUSTER_SIZE*header->clusters +
129                                  MAPPING_PSEG_SIZE*header->psegs +
130                                  MAPPING_VSPACE_SIZE*header->vspaces );
131
132    // computes the base adresss for vobjs array,
133    vobj    = (mapping_vobj_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                                  MAPPING_VSEG_SIZE*header->vsegs );
139
140    // computes the base address for tasks array
141    task    = (mapping_task_t*)   ((char*)header +
142                                  MAPPING_HEADER_SIZE +
143                                  MAPPING_CLUSTER_SIZE*header->clusters +
144                                  MAPPING_PSEG_SIZE*header->psegs +
145                                  MAPPING_VSPACE_SIZE*header->vspaces +
146                                  MAPPING_VOBJ_SIZE*header->vobjs +
147                                  MAPPING_VSEG_SIZE*header->vsegs );
148
149    // computes the base address the array
150    proc    = (mapping_proc_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                                  MAPPING_TASK_SIZE*header->tasks);
158
159    // computes the base address the array
160    irq    = (mapping_irq_t*)   ((char*)header +
161                                  MAPPING_HEADER_SIZE +
162                                  MAPPING_CLUSTER_SIZE*header->clusters +
163                                  MAPPING_PSEG_SIZE*header->psegs +
164                                  MAPPING_VSPACE_SIZE*header->vspaces +
165                                  MAPPING_VOBJ_SIZE*header->vobjs +
166                                  MAPPING_VSEG_SIZE*header->vsegs+
167                                  MAPPING_TASK_SIZE*header->tasks+
168                                  MAPPING_PROC_SIZE*header->procs
169                                    );
170
171    // computes the base address the array
172    coproc    = (mapping_coproc_t*)   ((char*)header +
173                                  MAPPING_HEADER_SIZE +
174                                  MAPPING_CLUSTER_SIZE*header->clusters +
175                                  MAPPING_PSEG_SIZE*header->psegs +
176                                  MAPPING_VSPACE_SIZE*header->vspaces +
177                                  MAPPING_VOBJ_SIZE*header->vobjs +
178                                  MAPPING_VSEG_SIZE*header->vsegs+
179                                  MAPPING_TASK_SIZE*header->tasks+
180                                  MAPPING_PROC_SIZE*header->procs+
181                                  MAPPING_IRQ_SIZE*header->irqs
182                                    );
183
184    // computes the base address the array
185    cp_port    = (mapping_coproc_port_t*)   ((char*)header +
186                                  MAPPING_HEADER_SIZE +
187                                  MAPPING_CLUSTER_SIZE*header->clusters +
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                                  MAPPING_IRQ_SIZE*header->irqs+
195                                  MAPPING_COPROC_SIZE*header->coprocs
196                                    );
197
198    // computes the base address the array
199    cp_reg    = (mapping_coproc_reg_t*)   ((char*)header +
200                                  MAPPING_HEADER_SIZE +
201                                  MAPPING_CLUSTER_SIZE*header->clusters +
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                                  MAPPING_IRQ_SIZE*header->irqs+
209                                  MAPPING_COPROC_SIZE*header->coprocs+
210                                  MAPPING_CP_PORT_SIZE*header->cp_ports
211                                    );
212
213    fprintf( fpout, "<?xml version = \"1.0\"?>\n\n");
214
215    ///////////////////////// header /////////////////////////////////////////////
216
217    fprintf( fpout, "<mapping_info signature = \"0x%x\"\n", header->signature);
218    fprintf( fpout, "              name      = \"%s\"\n", header->name);
219    fprintf( fpout, "              clusters  = \"%d\"\n", header->clusters);
220    fprintf( fpout, "              ttys      = \"%d\"\n", header->ttys);
221    fprintf( fpout, "              fbs       = \"%d\"\n", header->fbs);
222    fprintf( fpout, "              vspaces   = \"%d\"\n", header->vspaces);
223    fprintf( fpout, "              globals   = \"%d\" >\n\n", header->globals);
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\"\n",        pseg[pseg_id].name);
236            fprintf( fpout, "                          type   = \"%s\"\n",  pseg_type[pseg[pseg_id].type]);
237            fprintf( fpout, "                          base   = \"0x%x\"\n",      pseg[pseg_id].base);
238            fprintf( fpout, "                          length = \"0x%x\" />\n",   pseg[pseg_id].length);
239        }
240        for ( proc_id = cluster[cluster_id].proc_offset ; 
241                proc_id < cluster[cluster_id].proc_offset + cluster[cluster_id].procs ;
242                    proc_id++ )
243        {
244            fprintf( fpout, "                   <proc index   = \"%d\" >\n",       proc_id);
245            for ( irq_id = proc[proc_id].irq_offset ; irq_id < proc[proc_id].irq_offset + proc[proc_id].irqs ; irq_id++ )
246            {
247                fprintf( fpout, "                         <irq    type    = \"%s\"\n",  irq_type[irq[irq_id].type]);
248                fprintf( fpout, "                                 icuid   = \"0x%x\"\n",      irq[irq_id].icuid);
249                fprintf( fpout, "                                 isr     = \"%s\"\n",  isr_type[irq[irq_id].isr]);
250                fprintf( fpout, "                                 channel = \"0x%x\" />\n",   irq[irq_id].channel);
251            }
252            fprintf( fpout, "                   </proc>\n" );
253        }
254
255        for ( coproc_id = cluster[cluster_id].coproc_offset ; 
256                coproc_id < cluster[cluster_id].coproc_offset + cluster[cluster_id].coprocs ;
257                    coproc_id++ )
258        {
259            fprintf( fpout, "                   <coproc name       = \"%s\"\n",       coproc[coproc_id].name);
260            fprintf( fpout, "                           psegname   = \"%s\" >\n",       pseg[coproc[coproc_id].psegid].name);
261            for ( port_id = coproc[coproc_id].port_offset ; port_id < coproc[coproc_id].port_offset + coproc[coproc_id].ports ; port_id++ )
262            {
263                unsigned int vobj_id = cp_port[port_id].vobjlocid + vspace[cp_port[port_id].vspaceid].vobj_offset; 
264                fprintf( fpout, "                           <port   direction    = \"%s\"\n",  port_direction[ cp_port[port_id].direction]);
265                fprintf( fpout, "                                   vspacename   = \"%s\"\n",  vspace[cp_port[port_id].vspaceid].name);
266                fprintf( fpout, "                                   vobjname     = \"%s\" />\n",  vobj[vobj_id].name);
267            }
268            for ( reg_id = coproc[coproc_id].reg_offset ; 
269                    reg_id < coproc[coproc_id].reg_offset+coproc[coproc_id].regs ;
270                        reg_id++ )
271            {
272                fprintf( fpout, "                           <reg    name        = \"%s\"\n",        cp_reg[reg_id].name);
273                fprintf( fpout, "                                   type        = \"%s\"\n",        reg_type[cp_reg[reg_id].type]);
274                fprintf( fpout, "                                   value       = \"0x%x\"\n",      cp_reg[reg_id].value);
275                fprintf( fpout, "                                   channel     = \"0x%x\"\n",      cp_reg[reg_id].channel_id);
276                fprintf( fpout, "                                   index       = \"0x%x\" />\n",   cp_reg[reg_id].loc_id);
277            }
278            fprintf( fpout, "                   </coproc>\n" );
279        }
280        fprintf( fpout, "        </cluster>\n" );
281    }
282    fprintf( fpout, "    </clusterset>\n\n" );
283
284    /////////////////// globals /////////////////////////////////////////////////
285
286    fprintf( fpout, "    <globalset>\n" );
287    for ( vseg_id = 0 ; vseg_id < header->globals ; vseg_id++ )
288    {
289        unsigned int pseg_id = vseg[vseg_id].psegid; 
290
291        fprintf( fpout, "        <vseg    name      = \"%s\"\n",      vseg[vseg_id].name);
292        fprintf( fpout, "                 vbase     = \"0x%x\"\n",    vseg[vseg_id].vbase);
293        fprintf( fpout, "                 mode      = \"%s\"\n", mode_str[vseg[vseg_id].mode]);
294        fprintf( fpout, "                 clusterid = \"%d\"\n",      pseg[pseg_id].cluster);
295        fprintf( fpout, "                 psegname  = \"%s\"\n",      pseg[pseg_id].name);
296        fprintf( fpout, "                 ident     = \"%d\" >\n",    vseg[vseg_id].ident);
297        for ( vobj_id = vseg[vseg_id].vobj_offset;
298              vobj_id < (vseg[vseg_id].vobj_offset + vseg[vseg_id].vobjs); 
299              vobj_id++ )
300        {
301            fprintf( fpout, "                 <vobj name     = \"%s\"\n",    vobj[vobj_id].name);
302            fprintf( fpout, "                       type     = \"%s\"\n",    vobj_type[vobj[vobj_id].type]);
303            fprintf( fpout, "                       length   = \"0x%x\"\n",  vobj[vobj_id].length);
304            fprintf( fpout, "                       align    = \"%d\"\n",    vobj[vobj_id].align);
305            fprintf( fpout, "                       init     = \"%d\" \n",   vobj[vobj_id].init);
306            fprintf( fpout, "                       binpath  = \"%s\" />\n", vobj[vobj_id].binpath);
307        }
308        fprintf( fpout, "        </vseg>\n");
309    }
310    fprintf( fpout, "    </globalset>\n" );
311
312    //////////////////// vspaces ////////////////////////////////////////////////
313
314    fprintf( fpout, "\n    <vspaceset>\n\n" );
315    for ( vspace_id = 0 ; vspace_id < header->vspaces ; vspace_id++ )
316    {
317        unsigned int func_id = vspace[vspace_id].vobj_offset + vspace[vspace_id].start_offset; 
318        fprintf( fpout, "        <vspace  name      = \"%s\"\n",     vspace[vspace_id].name); 
319        fprintf( fpout, "                 startname = \"%s\" >\n\n", vobj[func_id].name); 
320
321        for ( vseg_id = vspace[vspace_id].vseg_offset ;
322              vseg_id < (vspace[vspace_id].vseg_offset + vspace[vspace_id].vsegs) ; vseg_id++ )
323        {
324            unsigned int pseg_id = vseg[vseg_id].psegid; 
325
326            fprintf( fpout, "                 <vseg name      = \"%s\"\n",      vseg[vseg_id].name);
327            fprintf( fpout, "                       vbase     = \"0x%x\"\n",    vseg[vseg_id].vbase);
328            fprintf( fpout, "                       mode      = \"%s\"\n", mode_str[vseg[vseg_id].mode]);
329            fprintf( fpout, "                       clusterid = \"%d\"\n",      pseg[pseg_id].cluster);
330            fprintf( fpout, "                       psegname  = \"%s\"\n",      pseg[pseg_id].name);
331            fprintf( fpout, "                       ident     = \"%d\" >\n",    vseg[vseg_id].ident);
332
333            for ( vobj_id = vseg[vseg_id].vobj_offset ;
334                  vobj_id < (vseg[vseg_id].vobj_offset + vseg[vseg_id].vobjs) ; 
335                  vobj_id++ )
336            {
337                fprintf( fpout, "                       <vobj name     = \"%s\"\n",    vobj[vobj_id].name);
338                fprintf( fpout, "                             type     = \"%s\" \n",   vobj_type[vobj[vobj_id].type]);
339                fprintf( fpout, "                             length   = \"0x%x\" \n", vobj[vobj_id].length);
340                fprintf( fpout, "                             align    = \"%d\" \n",   vobj[vobj_id].align);
341                fprintf( fpout, "                             init     = \"%d\" \n",   vobj[vobj_id].init);
342                fprintf( fpout, "                             binpath  = \"%s\" />\n", vobj[vobj_id].binpath);
343            }
344            fprintf( fpout, "                 </vseg>\n");
345        }
346        for ( task_id = vspace[vspace_id].task_offset ;
347              task_id < (vspace[vspace_id].task_offset + vspace[vspace_id].tasks) ; 
348              task_id++ )
349        {
350            unsigned int vobj_id = task[task_id].vobjlocid + vspace[vspace_id].vobj_offset; 
351
352            fprintf( fpout, "                 <task name      = \"%s\"\n",      task[task_id].name);
353            fprintf( fpout, "                       clusterid = \"%d\"\n",      task[task_id].clusterid);
354            fprintf( fpout, "                       proclocid = \"%d\"\n",      task[task_id].proclocid);
355            fprintf( fpout, "                       stackname = \"%s\"\n",      vobj[vobj_id].name);
356            fprintf( fpout, "                       startid   = \"%d\"\n",      task[task_id].startid);
357            fprintf( fpout, "                       usetty    = \"%d\"\n",      task[task_id].use_tty);
358            fprintf( fpout, "                       usefb     = \"%d\" />\n\n", task[task_id].use_fb);
359        }
360        fprintf( fpout, "        </vspace>\n\n");
361    }
362    fprintf( fpout, "    </vspaceset>\n" );
363    fprintf( fpout, "</mapping_info>\n");
364} // end buildXml()
365
366/////////////////////////////////////
367int  main ( int argc, char* argv[] )
368{
369    if ( argc < 2 ) 
370    {
371        printf("Usage: bin2xml <input_file_path> <output_file_path>\n");
372        return 1;
373    }
374
375    unsigned int      bin[0x10000];             // 64 K int = 256 Kbytes
376
377    int fdin = open( argv[1], O_RDONLY );
378    if (fdin < 0) 
379    {
380        perror("open");
381        exit(1);
382    }
383
384    FILE* fpout = fopen( argv[2], "w" );
385    if (fpout == NULL) 
386    {
387        perror("open");
388        exit(1);
389    }
390
391    unsigned int length = read(fdin, bin, 0x40000);
392
393    if ( length <= 0 )
394    {
395        perror("read");
396        exit(1);
397    }
398
399    if ( bin[0] == IN_MAPPING_SIGNATURE )
400    {
401        buildXml( (mapping_header_t*)bin, fpout );
402    } 
403    else
404    {
405        printf("[ERROR] Wrong file format\n");
406        exit(1);
407    }
408    return 0;
409} // end main()
Note: See TracBrowser for help on using the repository browser.