source: soft/giet_vm/giet_xml/xml_driver.c @ 567

Last change on this file since 567 was 567, checked in by alain, 9 years ago

Introduce support for the IOC_SUBTYPE_SDC.

  • Property svn:executable set to *
File size: 15.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    // mnemonics defined in mapping_info.h
23    const char * vseg_type[] = 
24    { 
25        "ELF",        // From a .elf file
26        "BLOB",       // Raw Binary
27        "PTAB",       // Page Table
28        "PERI",       // Hardware Component
29        "BUFFER",     // No intialisation needed (stacks...)
30        "SCHED",      // Scheduler
31        "HEAP",       // Heap     
32    };
33
34    // mnemonics defined in mapping_info.h
35    const char * pseg_type[] = 
36    {
37        "RAM",
38        "PERI",
39    };
40
41    // mnemonics defined in mapping_info.h
42    const char * irq_type[] =
43    {
44        "HWI",                     
45        "WTI",
46        "PTI",
47    };
48
49    // These mnemonics must be consistent with values in
50    // irq_handler.h / irq_handler.c / mapping.py
51    const char * isr_type[] =
52    {
53        "ISR_DEFAULT", 
54        "ISR_TICK",
55        "ISR_TTY_RX",
56        "ISR_TTY_TX",
57        "ISR_BDV",
58        "ISR_TIMER",
59        "ISR_WAKUP",
60        "ISR_NIC_RX",
61        "ISR_NIC_TX",
62        "ISR_CMA",
63        "ISR_MMC",
64        "ISR_DMA",
65        "ISR_SDC",
66        "ISR_MWR",
67        "ISR_HBA",
68    };
69
70    const char * mwr_subtype[] =
71    {
72        "GCD",
73        "DCT",
74        "CPY",
75    };
76
77    const char * periph_type[] =
78    {
79        "CMA",
80        "DMA",
81        "FBF",
82        "IOB",
83        "IOC",
84        "MMC",
85        "MWR",
86        "NIC",
87        "ROM",
88        "SIM",
89        "TIM",
90        "TTY",
91        "XCU",
92        "PIC",
93        "DROM",
94    };
95
96    const char * ioc_subtype[] =
97    {
98        "BDV",
99        "HBA",
100        "SDC",
101        "SPI",
102    };
103
104    const char * mode_str[] = 
105    { 
106        "____",
107        "___U", 
108        "__W_", 
109        "__WU", 
110        "_X__", 
111        "_X_U", 
112        "_XW_", 
113        "_XWU", 
114        "C___", 
115        "C__U", 
116        "C_W_", 
117        "C_WU", 
118        "CX__", 
119        "CX_U", 
120        "CXW_", 
121        "CXWU", 
122    };
123
124    unsigned int vspace_id;
125    unsigned int cluster_id;
126    unsigned int pseg_id;
127    unsigned int vseg_id;
128    unsigned int task_id;
129    unsigned int proc_id;
130    unsigned int irq_id;
131    unsigned int periph_id;
132
133    mapping_cluster_t * cluster;
134    mapping_pseg_t * pseg;
135    mapping_vspace_t * vspace;
136    mapping_vseg_t * vseg;
137    mapping_task_t * task;
138    mapping_proc_t * proc;
139    mapping_irq_t * irq;   
140    mapping_periph_t * periph;
141
142    // computes the base adresss for clusters array,
143    cluster = (mapping_cluster_t *)((char *) header +
144            MAPPING_HEADER_SIZE);
145
146    // computes the base adresss for psegs array,
147    pseg = (mapping_pseg_t *) ((char *) header +
148            MAPPING_HEADER_SIZE +
149            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size);
150
151    // computes the base adresss for vspaces array,
152    vspace = (mapping_vspace_t *) ((char *) header +
153            MAPPING_HEADER_SIZE +
154            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size +
155            MAPPING_PSEG_SIZE * header->psegs);
156
157    // computes the base adresss for vsegs array,
158    vseg = (mapping_vseg_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
164    // computes the base address for tasks array
165    task = (mapping_task_t *) ((char *) header +
166            MAPPING_HEADER_SIZE +
167            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size +
168            MAPPING_PSEG_SIZE * header->psegs +
169            MAPPING_VSPACE_SIZE * header->vspaces +
170            MAPPING_VSEG_SIZE * header->vsegs);
171
172    // computes the base address for procs array
173    proc = (mapping_proc_t *) ((char *) header +
174            MAPPING_HEADER_SIZE +
175            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size +
176            MAPPING_PSEG_SIZE * header->psegs +
177            MAPPING_VSPACE_SIZE * header->vspaces +
178            MAPPING_VSEG_SIZE * header->vsegs +
179            MAPPING_TASK_SIZE * header->tasks);
180
181    // computes the base address for irqs array
182    irq = (mapping_irq_t *) ((char *) header +
183            MAPPING_HEADER_SIZE +
184            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size +
185            MAPPING_PSEG_SIZE * header->psegs +
186            MAPPING_VSPACE_SIZE * header->vspaces +
187            MAPPING_VSEG_SIZE * header->vsegs +
188            MAPPING_TASK_SIZE * header->tasks +
189            MAPPING_PROC_SIZE * header->procs);
190
191    // computes the base address for periphs array
192    periph = (mapping_periph_t *) ((char *) header +
193            MAPPING_HEADER_SIZE +
194            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size +
195            MAPPING_PSEG_SIZE * header->psegs +
196            MAPPING_VSPACE_SIZE * header->vspaces +
197            MAPPING_VSEG_SIZE * header->vsegs +
198            MAPPING_TASK_SIZE * header->tasks +
199            MAPPING_PROC_SIZE * header->procs +
200            MAPPING_IRQ_SIZE * header->irqs);
201
202    ///////////////////////// header /////////////////////////////////////////////
203
204    fprintf(fpout, "<?xml version = \"1.0\"?>\n\n");
205
206    fprintf(fpout, "<mapping_info signature    = \"0x%x\" \n" , header->signature);
207    fprintf(fpout, "              name         = \"%s\"   \n" , header->name);
208    fprintf(fpout, "              x_size       = \"%d\"   \n" , header->x_size);
209    fprintf(fpout, "              y_size       = \"%d\"   \n" , header->y_size);
210    fprintf(fpout, "              x_width      = \"%d\"   \n" , header->x_width);
211    fprintf(fpout, "              y_width      = \"%d\"   \n" , header->y_width);
212    fprintf(fpout, "              irq_per_proc = \"%d\"   \n" , header->irq_per_proc);
213    fprintf(fpout, "              use_ram_disk = \"%d\"   \n" , header->use_ram_disk);
214    fprintf(fpout, "              x_io         = \"%d\"   \n" , header->x_io);
215    fprintf(fpout, "              y_io         = \"%d\" >\n\n", header->y_io);
216
217    ///////////////////// clusters ///////////////////////////////////////////////
218
219    fprintf( fpout, "    <clusterset>\n");
220    for (cluster_id = 0; cluster_id < (header->x_size * header->y_size); cluster_id++) 
221    {
222        fprintf(fpout, "        <cluster x=\"%d\" y=\"%d\" >\n", 
223                cluster[cluster_id].x, cluster[cluster_id].y );
224
225        ///////////////////// psegs   ////////////////////////////////////////////////
226
227        for (pseg_id = cluster[cluster_id].pseg_offset;
228             pseg_id < cluster[cluster_id].pseg_offset + cluster[cluster_id].psegs;
229             pseg_id++) 
230        {
231            fprintf(fpout, "            <pseg name=\"%s\"", pseg[pseg_id].name);
232            fprintf(fpout, " type=\"%s\"", pseg_type[pseg[pseg_id].type]);
233            fprintf(fpout, " base=\"0x%llx\"", pseg[pseg_id].base);
234            fprintf(fpout, " length=\"0x%llx\" />\n", pseg[pseg_id].length);
235        }
236
237        ///////////////////// processors /////////////////////////////////////////////
238
239        unsigned int proc_index = 0;
240        for (proc_id = cluster[cluster_id].proc_offset;
241             proc_id < cluster[cluster_id].proc_offset + cluster[cluster_id].procs;
242             proc_id++, proc_index++) 
243        {
244            fprintf(fpout, "            <proc index=\"%d\" />\n", proc_index);
245        }
246
247        ///////////////////// periphs  ///////////////////////////////////////////////
248
249        for (periph_id = cluster[cluster_id].periph_offset;
250             periph_id < cluster[cluster_id].periph_offset + cluster[cluster_id].periphs;
251             periph_id++) 
252        {
253            fprintf(fpout, "            <periph type=\"%s\"", periph_type[periph[periph_id].type]);
254
255            if (periph[periph_id].type == PERIPH_TYPE_IOC) 
256                fprintf(fpout, " subtype=\"%s\"", ioc_subtype[periph[periph_id].subtype]);
257
258            if (periph[periph_id].type == PERIPH_TYPE_MWR) 
259                fprintf(fpout, " subtype=\"%s\"", mwr_subtype[periph[periph_id].subtype]);
260
261            fprintf(fpout, " psegname=\"%s\"", pseg[periph[periph_id].psegid].name);
262            fprintf(fpout, " channels=\"%d\"",  periph[periph_id].channels);
263            fprintf(fpout, " arg0=\"%d\" >\n",  periph[periph_id].arg0);
264            fprintf(fpout, " arg1=\"%d\" >\n",  periph[periph_id].arg1);
265            fprintf(fpout, " arg2=\"%d\" >\n",  periph[periph_id].arg2);
266            fprintf(fpout, " arg3=\"%d\" >\n",  periph[periph_id].arg3);
267            if ( (periph[periph_id].type == PERIPH_TYPE_PIC) ||
268                 (periph[periph_id].type == PERIPH_TYPE_XCU) )
269            {
270                for (irq_id = periph[periph_id].irq_offset; 
271                     irq_id < periph[periph_id].irq_offset + periph[periph_id].irqs;
272                     irq_id++) 
273                {
274                    fprintf(fpout, "                <irq srctype=\"%s\"", irq_type[irq[irq_id].srctype]);
275                    fprintf(fpout, " srcid=\"%d\"", irq[irq_id].srcid);
276                    fprintf(fpout, " isr=\"%s\"", isr_type[irq[irq_id].isr]);
277                    fprintf(fpout, " channel=\"%d\" />\n", irq[irq_id].channel);
278                }
279            }
280            fprintf(fpout, "            </periph>\n");
281        }
282        fprintf(fpout, "        </cluster>\n" );
283    }
284    fprintf(fpout, "    </clusterset>\n\n" );
285
286    /////////////////// globals /////////////////////////////////////////////////
287
288    fprintf(fpout, "    <globalset>\n" );
289    for (vseg_id = 0; vseg_id < header->globals; vseg_id++) 
290    {
291        unsigned int pseg_id    = vseg[vseg_id].psegid; 
292        unsigned int cluster_id = pseg[pseg_id].clusterid;
293
294        fprintf(fpout, "        <vseg name=\"%s\"", vseg[vseg_id].name);
295        fprintf(fpout, " vbase=\"0x%x\"", vseg[vseg_id].vbase);
296        fprintf(fpout, " length=\"0x%x\"", vseg[vseg_id].length);
297        fprintf(fpout, " type=\"%s\"", vseg_type[vseg[vseg_id].type]);
298        fprintf(fpout, " mode=\"%s\"", mode_str[vseg[vseg_id].mode]);
299        fprintf(fpout, "\n             ");     
300        fprintf(fpout, " x=\"%d\"", cluster[cluster_id].x);
301        fprintf(fpout, " y=\"%d\"", cluster[cluster_id].y);
302        fprintf(fpout, " psegname=\"%s\"", pseg[pseg_id].name);
303        if( vseg[vseg_id].ident ) 
304        fprintf(fpout, " ident=\"1\"");
305        if( vseg[vseg_id].local ) 
306        fprintf(fpout, " local=\"1\"");
307        if( vseg[vseg_id].big ) 
308        fprintf(fpout, " big=\"1\"");
309        if( vseg[vseg_id].binpath[0] != 0 ) 
310        fprintf(fpout, " binpath=\"%s\"", vseg[vseg_id].binpath);
311        fprintf(fpout, " >\n");
312    }
313    fprintf(fpout, "    </globalset>\n" );
314
315    //////////////////// vspaces ////////////////////////////////////////////////
316
317    fprintf( fpout, "\n    <vspaceset>\n\n" );
318    for (vspace_id = 0; vspace_id < header->vspaces; vspace_id++) 
319    {
320        unsigned int vseg_id = vspace[vspace_id].start_vseg_id;
321        fprintf(fpout, "        <vspace name = \"%s\" ", vspace[vspace_id].name); 
322        fprintf(fpout, " startname = \"%s\" >\n", vseg[vseg_id].name); 
323
324        //////////////////// vsegs //////////////////////////////////////////////
325
326        for (vseg_id = vspace[vspace_id].vseg_offset;
327             vseg_id < (vspace[vspace_id].vseg_offset + vspace[vspace_id].vsegs);
328             vseg_id++) 
329        {
330            unsigned int pseg_id    = vseg[vseg_id].psegid; 
331            unsigned int cluster_id = pseg[pseg_id].clusterid;
332
333            fprintf(fpout, "            <vseg name=\"%s\"", vseg[vseg_id].name);
334            fprintf(fpout, " vbase=\"0x%x\"", vseg[vseg_id].vbase);
335            fprintf(fpout, " length=\"0x%x\"", vseg[vseg_id].length);
336            fprintf(fpout, " type=\"%s\"", vseg_type[vseg[vseg_id].type]);
337            fprintf(fpout, " mode=\"%s\"", mode_str[vseg[vseg_id].mode]);
338            fprintf(fpout, "\n                 ");     
339            fprintf(fpout, " x=\"%d\"", cluster[cluster_id].x);
340            fprintf(fpout, " y=\"%d\"", cluster[cluster_id].y);
341            fprintf(fpout, " psegname=\"%s\"", pseg[pseg_id].name);
342            if( vseg[vseg_id].ident ) 
343            fprintf(fpout, " ident=\"1\"");
344            if( vseg[vseg_id].local ) 
345            fprintf(fpout, " local=\"1\"");
346            if( vseg[vseg_id].big ) 
347            fprintf(fpout, " big=\"1\"");
348            if( vseg[vseg_id].binpath[0] != 0 ) 
349            fprintf(fpout, " binpath=\"%s\"", vseg[vseg_id].binpath);
350            fprintf(fpout, " >\n");
351        }
352
353        //////////////////// tasks //////////////////////////////////////////////
354
355        for (task_id = vspace[vspace_id].task_offset;
356             task_id < (vspace[vspace_id].task_offset + vspace[vspace_id].tasks);
357             task_id++) 
358        {
359            unsigned int stack_vseg_id = task[task_id].stack_vseg_id; 
360            unsigned int heap_vseg_id  = task[task_id].heap_vseg_id; 
361            unsigned int cluster_id    = task[task_id].clusterid;
362
363            fprintf(fpout, "            <task name=\"%s\"", task[task_id].name);
364            fprintf(fpout, " trdid=\"%d\"", task[task_id].trdid);
365            fprintf(fpout, " x=\"%d\"", cluster[cluster_id].x);
366            fprintf(fpout, " y=\"%d\"", cluster[cluster_id].y);
367            fprintf(fpout, " p=\"%d\"", task[task_id].proclocid);
368            fprintf(fpout, "\n                 ");     
369            fprintf(fpout, " stackname=\"%s\"", vseg[stack_vseg_id].name);
370            if (heap_vseg_id != -1) 
371            fprintf(fpout, " heapname=\"%s\"", vseg[heap_vseg_id].name);
372            fprintf(fpout, " startid = \"%d\"", task[task_id].startid);
373            fprintf(fpout, " />\n");
374        }
375        fprintf(fpout, "        </vspace>\n\n");
376    }
377    fprintf(fpout, "    </vspaceset>\n");
378    fprintf(fpout, "</mapping_info>\n");
379} // end buildXml()
380
381
382/////////////////////////////////////
383int main(int argc, char * argv[]) 
384{
385    if (argc < 2) 
386    {
387        printf("Usage: bin2xml <input_file_path> <output_file_path>\n");
388        return 1;
389    }
390
391    unsigned int bin[0x10000]; // 64 K int = 256 Kbytes
392
393    int fdin = open(argv[1], O_RDONLY);
394    if (fdin < 0) 
395    {
396        perror("open");
397        exit(1);
398    }
399
400    FILE * fpout = fopen( argv[2], "w");
401    if (fpout == NULL) 
402    {
403        perror("open");
404        exit(1);
405    }
406
407    unsigned int length = read(fdin, bin, 0x40000);
408
409    if (length <= 0) 
410    {
411        perror("read");
412        exit(1);
413    }
414
415    if (bin[0] == IN_MAPPING_SIGNATURE) 
416    {
417        buildXml((mapping_header_t *) bin, fpout);
418    } 
419    else 
420    {
421        printf("[ERROR] Wrong file format\n");
422        exit(1);
423    }
424    return 0;
425} // end main()
426
427
428
429// Local Variables:
430// tab-width: 4
431// c-basic-offset: 4
432// c-file-offsets:((innamespace . 0)(inline-open . 0))
433// indent-tabs-mode: nil
434// End:
435// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
436
Note: See TracBrowser for help on using the repository browser.