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

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

Adding BLOB type for vobj.
Don't forget to set as BLOB type the mapping_info vobj in the xml.

File size: 11.2 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* 
24    vobj_type[] = 
25    { 
26        "ELF",
27        "BLOB",
28        "PTAB",   //page table
29        "PERI",   //hardware component
30        "MWMR",   //MWMR channel
31        "LOCK",   //Lock
32        "BUFFER", //Any "no intialiasation needed" objects (stacks...)
33        "BARRIER" //Barrier
34    };
35    const char* mode_str[] = { "____",
36                               "___U", 
37                               "__W_", 
38                               "__WU", 
39                               "_X__", 
40                               "_X_U", 
41                               "_XW_", 
42                               "_XWU", 
43                               "C___", 
44                               "C__U", 
45                               "C_W_", 
46                               "C_WU", 
47                               "CX__", 
48                               "CX_U", 
49                               "CXW_", 
50                               "CXWU" };
51
52    unsigned int                vspace_id;
53    unsigned int                cluster_id;
54    unsigned int                pseg_id;
55    unsigned int                vseg_id;
56    unsigned int                vobj_id;
57    unsigned int                task_id;
58
59    mapping_cluster_t*  cluster;
60    mapping_pseg_t*     pseg;
61    mapping_vspace_t*   vspace;
62    mapping_vseg_t*     vseg;
63    mapping_vobj_t*     vobj;
64    mapping_task_t*     task;
65
66    // computes the base adresss for clusters array,
67    cluster = (mapping_cluster_t*)((char*)header +
68                                  MAPPING_HEADER_SIZE );
69
70    // computes the base adresss for psegs array,
71    pseg    = (mapping_pseg_t*)   ((char*)header +
72                                  MAPPING_HEADER_SIZE +
73                                  MAPPING_CLUSTER_SIZE*header->clusters );
74
75    // computes the base adresss for vspaces array,
76    vspace  = (mapping_vspace_t*) ((char*)header +
77                                  MAPPING_HEADER_SIZE +
78                                  MAPPING_CLUSTER_SIZE*header->clusters +
79                                  MAPPING_PSEG_SIZE*header->psegs );
80
81    // computes the base adresss for vsegs array,
82    vseg    = (mapping_vseg_t*)   ((char*)header +
83                                  MAPPING_HEADER_SIZE +
84                                  MAPPING_CLUSTER_SIZE*header->clusters +
85                                  MAPPING_PSEG_SIZE*header->psegs +
86                                  MAPPING_VSPACE_SIZE*header->vspaces );
87
88    // computes the base adresss for vobjs array,
89    vobj    = (mapping_vobj_t*)   ((char*)header +
90                                  MAPPING_HEADER_SIZE +
91                                  MAPPING_CLUSTER_SIZE*header->clusters +
92                                  MAPPING_PSEG_SIZE*header->psegs +
93                                  MAPPING_VSPACE_SIZE*header->vspaces +
94                                  MAPPING_VSEG_SIZE*header->vsegs );
95
96    // computes the base address for tasks array
97    task    = (mapping_task_t*)   ((char*)header +
98                                  MAPPING_HEADER_SIZE +
99                                  MAPPING_CLUSTER_SIZE*header->clusters +
100                                  MAPPING_PSEG_SIZE*header->psegs +
101                                  MAPPING_VSPACE_SIZE*header->vspaces +
102                                  MAPPING_VOBJ_SIZE*header->vobjs +
103                                  MAPPING_VSEG_SIZE*header->vsegs );
104
105    fprintf( fpout, "<?xml version = \"1.0\"?>\n\n");
106
107    ///////////////////////// header /////////////////////////////////////////////
108
109    fprintf( fpout, "<mapping_info signature = \"0x%x\"\n", header->signature);
110    fprintf( fpout, "              name      = \"%s\"\n", header->name);
111    fprintf( fpout, "              clusters  = \"%d\"\n", header->clusters);
112    fprintf( fpout, "              psegs     = \"%d\"\n", header->psegs);
113    fprintf( fpout, "              ttys      = \"%d\"\n", header->ttys);
114    fprintf( fpout, "              fbs       = \"%d\"\n", header->fbs);
115    fprintf( fpout, "              vspaces   = \"%d\"\n", header->vspaces);
116    fprintf( fpout, "              globals   = \"%d\" >\n\n", header->globals);
117
118    ///////////////////// clusters ///////////////////////////////////////////////
119
120    fprintf( fpout, "    <clusterset>\n" );
121    for ( cluster_id = 0 ; cluster_id < header->clusters ; cluster_id++ )
122    {
123        fprintf( fpout, "        <cluster index  = \"%d\"\n",      cluster_id);
124        fprintf( fpout, "                 procs  = \"%d\" />\n\n", cluster[cluster_id].procs);
125    }
126    fprintf( fpout, "    </clusterset>\n" );
127
128    //////////////////// psegs ///////////////////////////////////////////////////
129
130    fprintf( fpout, "    <psegset>\n" );
131    for ( pseg_id = 0 ; pseg_id < header->psegs ; pseg_id++ )
132    {
133        fprintf( fpout, "        <pseg    name   = \"%s\"\n",        pseg[pseg_id].name);
134        fprintf( fpout, "                 base   = \"0x%x\"\n",      pseg[pseg_id].base);
135        fprintf( fpout, "                 length = \"0x%x\" />\n\n", pseg[pseg_id].length);
136    }
137    fprintf( fpout, "    </psegset>\n" );
138
139
140    /////////////////// globals /////////////////////////////////////////////////
141
142    fprintf( fpout, "    <globalset>\n" );
143    for ( vseg_id = 0 ; vseg_id < header->globals ; vseg_id++ )
144    {
145        unsigned int pseg_id = vseg[vseg_id].psegid; 
146
147        fprintf( fpout, "        <vseg    name     = \"%s\"\n",      vseg[vseg_id].name);
148        fprintf( fpout, "                 vbase    = \"0x%x\"\n",    vseg[vseg_id].vbase);
149        fprintf( fpout, "                 mode     = \"%s\"\n", mode_str[vseg[vseg_id].mode]);
150        fprintf( fpout, "                 psegname = \"%s\"\n",      pseg[pseg_id].name);
151        fprintf( fpout, "                 ident    = \"%d\" >\n",    vseg[vseg_id].ident);
152        for ( vobj_id = vseg[vseg_id].vobj_offset;
153              vobj_id < (vseg[vseg_id].vobj_offset + vseg[vseg_id].vobjs); 
154              vobj_id++ )
155        {
156            fprintf( fpout, "                 <vobj name     = \"%s\"\n",    vobj[vobj_id].name);
157            fprintf( fpout, "                       type     = \"%s\"\n",    vobj_type[vobj[vobj_id].type]);
158            fprintf( fpout, "                       length   = \"0x%x\"\n",  vobj[vobj_id].length);
159            fprintf( fpout, "                       align    = \"%d\"\n",    vobj[vobj_id].align);
160            fprintf( fpout, "                       init     = \"%d\" \n",   vobj[vobj_id].init);
161            fprintf( fpout, "                       binpath  = \"%s\" />\n", vobj[vobj_id].binpath);
162        }
163        fprintf( fpout, "        </vseg>\n\n");
164    }
165    fprintf( fpout, "    </globalset>\n" );
166
167    //////////////////// vspaces ////////////////////////////////////////////////
168
169    fprintf( fpout, "    <vspaceset>\n" );
170    for ( vspace_id = 0 ; vspace_id < header->vspaces ; vspace_id++ )
171    {
172        unsigned int func_id = vspace[vspace_id].vobj_offset + vspace[vspace_id].start_offset; 
173        fprintf( fpout, "        <vspace  name      = \"%s\"\n",     vspace[vspace_id].name); 
174        fprintf( fpout, "                 startname = \"%s\" >\n\n", vobj[func_id].name); 
175
176        for ( vseg_id = vspace[vspace_id].vseg_offset ;
177              vseg_id < (vspace[vspace_id].vseg_offset + vspace[vspace_id].vsegs) ; vseg_id++ )
178        {
179            unsigned int pseg_id = vseg[vseg_id].psegid; 
180
181            fprintf( fpout, "                 <vseg name      = \"%s\"\n",      vseg[vseg_id].name);
182            fprintf( fpout, "                       vbase     = \"0x%x\"\n",    vseg[vseg_id].vbase);
183            fprintf( fpout, "                       mode      = \"%s\"\n", mode_str[vseg[vseg_id].mode]);
184            fprintf( fpout, "                       psegname  = \"%s\"\n",      pseg[pseg_id].name);
185            fprintf( fpout, "                       ident     = \"%d\" >\n",    vseg[vseg_id].ident);
186
187            for ( vobj_id = vseg[vseg_id].vobj_offset ;
188                  vobj_id < (vseg[vseg_id].vobj_offset + vseg[vseg_id].vobjs) ; 
189                  vobj_id++ )
190            {
191                fprintf( fpout, "                       <vobj name     = \"%s\"\n",    vobj[vobj_id].name);
192                fprintf( fpout, "                             type     = \"%s\" \n",   vobj_type[vobj[vobj_id].type]);
193                fprintf( fpout, "                             length   = \"0x%x\" \n", vobj[vobj_id].length);
194                fprintf( fpout, "                             align    = \"%d\" \n",   vobj[vobj_id].align);
195                fprintf( fpout, "                             init     = \"%d\" \n",   vobj[vobj_id].init);
196                fprintf( fpout, "                             binpath  = \"%s\" />\n", vobj[vobj_id].binpath);
197            }
198            fprintf( fpout, "                 </vseg>\n\n");
199        }
200        for ( task_id = vspace[vspace_id].task_offset ;
201              task_id < (vspace[vspace_id].task_offset + vspace[vspace_id].tasks) ; 
202              task_id++ )
203        {
204            unsigned int vobj_id = task[task_id].vobjlocid + vspace[vspace_id].vobj_offset; 
205
206            fprintf( fpout, "                 <task name      = \"%s\"\n",      task[task_id].name);
207            fprintf( fpout, "                       clusterid = \"%d\"\n",      task[task_id].clusterid);
208            fprintf( fpout, "                       proclocid = \"%d\"\n",      task[task_id].proclocid);
209            fprintf( fpout, "                       stackname = \"%s\"\n",      vobj[vobj_id].name);
210            fprintf( fpout, "                       startid   = \"%d\"\n",      task[task_id].startid);
211            fprintf( fpout, "                       usetty    = \"%d\"\n",      task[task_id].use_tty);
212            fprintf( fpout, "                       usefb     = \"%d\" />\n\n", task[task_id].use_fb);
213        }
214        fprintf( fpout, "        </vspace>\n\n");
215    }
216    fprintf( fpout, "    </vspaceset>\n" );
217    fprintf( fpout, "</mapping_info>\n");
218} // end buildXml()
219
220/////////////////////////////////////
221int  main ( int argc, char* argv[] )
222{
223    if ( argc < 2 ) 
224    {
225        printf("Usage: bin2xml <input_file_path> <output_file_path>\n");
226        return 1;
227    }
228
229    unsigned int      bin[0x10000];             // 64 K int = 256 Kbytes
230
231    int fdin = open( argv[1], O_RDONLY );
232    if (fdin < 0) 
233    {
234        perror("open");
235        exit(1);
236    }
237
238    FILE* fpout = fopen( argv[2], "w" );
239    if (fpout == NULL) 
240    {
241        perror("open");
242        exit(1);
243    }
244
245    unsigned int length = read(fdin, bin, 0x40000);
246
247    if ( length <= 0 )
248    {
249        perror("read");
250        exit(1);
251    }
252
253    if ( bin[0] == IN_MAPPING_SIGNATURE )
254    {
255        buildXml( (mapping_header_t*)bin, fpout );
256    } 
257    else
258    {
259        printf("[ERROR] Wrong file format\n");
260        exit(1);
261    }
262    return 0;
263} // end main()
Note: See TracBrowser for help on using the repository browser.