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

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

Extending the mapping name to 64 characters.

  • 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    };
75
76    const char * periph_type[] =
77    {
78        "CMA",
79        "DMA",
80        "FBF",
81        "IOB",
82        "IOC",
83        "MMC",
84        "MWR",
85        "NIC",
86        "ROM",
87        "SIM",
88        "TIM",
89        "TTY",
90        "XCU",
91        "PIC",
92        "DROM",
93    };
94
95    const char * ioc_subtype[] =
96    {
97        "BDV",
98        "HBA",
99        "SDC",
100    };
101
102    const char * mode_str[] = 
103    { 
104        "____",
105        "___U", 
106        "__W_", 
107        "__WU", 
108        "_X__", 
109        "_X_U", 
110        "_XW_", 
111        "_XWU", 
112        "C___", 
113        "C__U", 
114        "C_W_", 
115        "C_WU", 
116        "CX__", 
117        "CX_U", 
118        "CXW_", 
119        "CXWU", 
120    };
121
122    unsigned int vspace_id;
123    unsigned int cluster_id;
124    unsigned int pseg_id;
125    unsigned int vseg_id;
126    unsigned int task_id;
127    unsigned int proc_id;
128    unsigned int irq_id;
129    unsigned int periph_id;
130
131    mapping_cluster_t * cluster;
132    mapping_pseg_t * pseg;
133    mapping_vspace_t * vspace;
134    mapping_vseg_t * vseg;
135    mapping_task_t * task;
136    mapping_proc_t * proc;
137    mapping_irq_t * irq;   
138    mapping_periph_t * periph;
139
140    // computes the base adresss for clusters array,
141    cluster = (mapping_cluster_t *)((char *) header +
142            MAPPING_HEADER_SIZE);
143
144    // computes the base adresss for psegs array,
145    pseg = (mapping_pseg_t *) ((char *) header +
146            MAPPING_HEADER_SIZE +
147            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size);
148
149    // computes the base adresss for vspaces array,
150    vspace = (mapping_vspace_t *) ((char *) header +
151            MAPPING_HEADER_SIZE +
152            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size +
153            MAPPING_PSEG_SIZE * header->psegs);
154
155    // computes the base adresss for vsegs array,
156    vseg = (mapping_vseg_t *) ((char *) header +
157            MAPPING_HEADER_SIZE +
158            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size +
159            MAPPING_PSEG_SIZE * header->psegs +
160            MAPPING_VSPACE_SIZE * header->vspaces);
161
162    // computes the base address for tasks array
163    task = (mapping_task_t *) ((char *) header +
164            MAPPING_HEADER_SIZE +
165            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size +
166            MAPPING_PSEG_SIZE * header->psegs +
167            MAPPING_VSPACE_SIZE * header->vspaces +
168            MAPPING_VSEG_SIZE * header->vsegs);
169
170    // computes the base address for procs array
171    proc = (mapping_proc_t *) ((char *) header +
172            MAPPING_HEADER_SIZE +
173            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size +
174            MAPPING_PSEG_SIZE * header->psegs +
175            MAPPING_VSPACE_SIZE * header->vspaces +
176            MAPPING_VSEG_SIZE * header->vsegs +
177            MAPPING_TASK_SIZE * header->tasks);
178
179    // computes the base address for irqs array
180    irq = (mapping_irq_t *) ((char *) header +
181            MAPPING_HEADER_SIZE +
182            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size +
183            MAPPING_PSEG_SIZE * header->psegs +
184            MAPPING_VSPACE_SIZE * header->vspaces +
185            MAPPING_VSEG_SIZE * header->vsegs +
186            MAPPING_TASK_SIZE * header->tasks +
187            MAPPING_PROC_SIZE * header->procs);
188
189    // computes the base address for periphs array
190    periph = (mapping_periph_t *) ((char *) header +
191            MAPPING_HEADER_SIZE +
192            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size +
193            MAPPING_PSEG_SIZE * header->psegs +
194            MAPPING_VSPACE_SIZE * header->vspaces +
195            MAPPING_VSEG_SIZE * header->vsegs +
196            MAPPING_TASK_SIZE * header->tasks +
197            MAPPING_PROC_SIZE * header->procs +
198            MAPPING_IRQ_SIZE * header->irqs);
199
200    ///////////////////////// header /////////////////////////////////////////////
201
202    fprintf(fpout, "<?xml version = \"1.0\"?>\n\n");
203
204    fprintf(fpout, "<mapping_info signature    = \"0x%x\" \n" , header->signature);
205    fprintf(fpout, "              name         = \"%s\"   \n" , header->name);
206    fprintf(fpout, "              x_size       = \"%d\"   \n" , header->x_size);
207    fprintf(fpout, "              y_size       = \"%d\"   \n" , header->y_size);
208    fprintf(fpout, "              x_width      = \"%d\"   \n" , header->x_width);
209    fprintf(fpout, "              y_width      = \"%d\"   \n" , header->y_width);
210    fprintf(fpout, "              irq_per_proc = \"%d\"   \n" , header->irq_per_proc);
211    fprintf(fpout, "              use_ram_disk = \"%d\"   \n" , header->use_ram_disk);
212    fprintf(fpout, "              x_io         = \"%d\"   \n" , header->x_io);
213    fprintf(fpout, "              y_io         = \"%d\" >\n\n", header->y_io);
214
215    ///////////////////// clusters ///////////////////////////////////////////////
216
217    fprintf( fpout, "    <clusterset>\n");
218    for (cluster_id = 0; cluster_id < (header->x_size * header->y_size); cluster_id++) 
219    {
220        fprintf(fpout, "        <cluster x=\"%d\" y=\"%d\" >\n", 
221                cluster[cluster_id].x, cluster[cluster_id].y );
222
223        ///////////////////// psegs   ////////////////////////////////////////////////
224
225        for (pseg_id = cluster[cluster_id].pseg_offset;
226             pseg_id < cluster[cluster_id].pseg_offset + cluster[cluster_id].psegs;
227             pseg_id++) 
228        {
229            fprintf(fpout, "            <pseg name=\"%s\"", pseg[pseg_id].name);
230            fprintf(fpout, " type=\"%s\"", pseg_type[pseg[pseg_id].type]);
231            fprintf(fpout, " base=\"0x%llx\"", pseg[pseg_id].base);
232            fprintf(fpout, " length=\"0x%llx\" />\n", pseg[pseg_id].length);
233        }
234
235        ///////////////////// processors /////////////////////////////////////////////
236
237        unsigned int proc_index = 0;
238        for (proc_id = cluster[cluster_id].proc_offset;
239             proc_id < cluster[cluster_id].proc_offset + cluster[cluster_id].procs;
240             proc_id++, proc_index++) 
241        {
242            fprintf(fpout, "            <proc index=\"%d\" />\n", proc_index);
243        }
244
245        ///////////////////// periphs  ///////////////////////////////////////////////
246
247        for (periph_id = cluster[cluster_id].periph_offset;
248             periph_id < cluster[cluster_id].periph_offset + cluster[cluster_id].periphs;
249             periph_id++) 
250        {
251            fprintf(fpout, "            <periph type=\"%s\"", periph_type[periph[periph_id].type]);
252
253            if (periph[periph_id].type == PERIPH_TYPE_IOC) 
254                fprintf(fpout, " subtype=\"%s\"", ioc_subtype[periph[periph_id].subtype]);
255
256            if (periph[periph_id].type == PERIPH_TYPE_MWR) 
257                fprintf(fpout, " subtype=\"%s\"", mwr_subtype[periph[periph_id].subtype]);
258
259            fprintf(fpout, " psegname=\"%s\"", pseg[periph[periph_id].psegid].name);
260            fprintf(fpout, " channels=\"%d\"",  periph[periph_id].channels);
261            fprintf(fpout, " arg0=\"%d\" >\n",  periph[periph_id].arg0);
262            fprintf(fpout, " arg1=\"%d\" >\n",  periph[periph_id].arg1);
263            fprintf(fpout, " arg2=\"%d\" >\n",  periph[periph_id].arg2);
264            fprintf(fpout, " arg3=\"%d\" >\n",  periph[periph_id].arg3);
265            if ( (periph[periph_id].type == PERIPH_TYPE_PIC) ||
266                 (periph[periph_id].type == PERIPH_TYPE_XCU) )
267            {
268                for (irq_id = periph[periph_id].irq_offset; 
269                     irq_id < periph[periph_id].irq_offset + periph[periph_id].irqs;
270                     irq_id++) 
271                {
272                    fprintf(fpout, "                <irq srctype=\"%s\"", irq_type[irq[irq_id].srctype]);
273                    fprintf(fpout, " srcid=\"%d\"", irq[irq_id].srcid);
274                    fprintf(fpout, " isr=\"%s\"", isr_type[irq[irq_id].isr]);
275                    fprintf(fpout, " channel=\"%d\" />\n", irq[irq_id].channel);
276                }
277            }
278            fprintf(fpout, "            </periph>\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        unsigned int cluster_id = pseg[pseg_id].clusterid;
291
292        fprintf(fpout, "        <vseg name=\"%s\"", vseg[vseg_id].name);
293        fprintf(fpout, " vbase=\"0x%x\"", vseg[vseg_id].vbase);
294        fprintf(fpout, " length=\"0x%x\"", vseg[vseg_id].length);
295        fprintf(fpout, " type=\"%s\"", vseg_type[vseg[vseg_id].type]);
296        fprintf(fpout, " mode=\"%s\"", mode_str[vseg[vseg_id].mode]);
297        fprintf(fpout, "\n             ");     
298        fprintf(fpout, " x=\"%d\"", cluster[cluster_id].x);
299        fprintf(fpout, " y=\"%d\"", cluster[cluster_id].y);
300        fprintf(fpout, " psegname=\"%s\"", pseg[pseg_id].name);
301        if( vseg[vseg_id].ident ) 
302        fprintf(fpout, " ident=\"1\"");
303        if( vseg[vseg_id].local ) 
304        fprintf(fpout, " local=\"1\"");
305        if( vseg[vseg_id].big ) 
306        fprintf(fpout, " big=\"1\"");
307        if( vseg[vseg_id].binpath[0] != 0 ) 
308        fprintf(fpout, " binpath=\"%s\"", vseg[vseg_id].binpath);
309        fprintf(fpout, " >\n");
310    }
311    fprintf(fpout, "    </globalset>\n" );
312
313    //////////////////// vspaces ////////////////////////////////////////////////
314
315    fprintf( fpout, "\n    <vspaceset>\n\n" );
316    for (vspace_id = 0; vspace_id < header->vspaces; vspace_id++) 
317    {
318        unsigned int vseg_id = vspace[vspace_id].start_vseg_id;
319        fprintf(fpout, "        <vspace name = \"%s\" ", vspace[vspace_id].name); 
320        fprintf(fpout, " startname = \"%s\" >\n", vseg[vseg_id].name); 
321
322        //////////////////// vsegs //////////////////////////////////////////////
323
324        for (vseg_id = vspace[vspace_id].vseg_offset;
325             vseg_id < (vspace[vspace_id].vseg_offset + vspace[vspace_id].vsegs);
326             vseg_id++) 
327        {
328            unsigned int pseg_id    = vseg[vseg_id].psegid; 
329            unsigned int cluster_id = pseg[pseg_id].clusterid;
330
331            fprintf(fpout, "            <vseg name=\"%s\"", vseg[vseg_id].name);
332            fprintf(fpout, " vbase=\"0x%x\"", vseg[vseg_id].vbase);
333            fprintf(fpout, " length=\"0x%x\"", vseg[vseg_id].length);
334            fprintf(fpout, " type=\"%s\"", vseg_type[vseg[vseg_id].type]);
335            fprintf(fpout, " mode=\"%s\"", mode_str[vseg[vseg_id].mode]);
336            fprintf(fpout, "\n                 ");     
337            fprintf(fpout, " x=\"%d\"", cluster[cluster_id].x);
338            fprintf(fpout, " y=\"%d\"", cluster[cluster_id].y);
339            fprintf(fpout, " psegname=\"%s\"", pseg[pseg_id].name);
340            if( vseg[vseg_id].ident ) 
341            fprintf(fpout, " ident=\"1\"");
342            if( vseg[vseg_id].local ) 
343            fprintf(fpout, " local=\"1\"");
344            if( vseg[vseg_id].big ) 
345            fprintf(fpout, " big=\"1\"");
346            if( vseg[vseg_id].binpath[0] != 0 ) 
347            fprintf(fpout, " binpath=\"%s\"", vseg[vseg_id].binpath);
348            fprintf(fpout, " >\n");
349        }
350
351        //////////////////// tasks //////////////////////////////////////////////
352
353        for (task_id = vspace[vspace_id].task_offset;
354             task_id < (vspace[vspace_id].task_offset + vspace[vspace_id].tasks);
355             task_id++) 
356        {
357            unsigned int stack_vseg_id = task[task_id].stack_vseg_id; 
358            unsigned int heap_vseg_id  = task[task_id].heap_vseg_id; 
359            unsigned int cluster_id    = task[task_id].clusterid;
360
361            fprintf(fpout, "            <task name=\"%s\"", task[task_id].name);
362            fprintf(fpout, " trdid=\"%d\"", task[task_id].trdid);
363            fprintf(fpout, " x=\"%d\"", cluster[cluster_id].x);
364            fprintf(fpout, " y=\"%d\"", cluster[cluster_id].y);
365            fprintf(fpout, " p=\"%d\"", task[task_id].proclocid);
366            fprintf(fpout, "\n                 ");     
367            fprintf(fpout, " stackname=\"%s\"", vseg[stack_vseg_id].name);
368            if (heap_vseg_id != -1) 
369            fprintf(fpout, " heapname=\"%s\"", vseg[heap_vseg_id].name);
370            fprintf(fpout, " startid = \"%d\"", task[task_id].startid);
371            fprintf(fpout, " />\n");
372        }
373        fprintf(fpout, "        </vspace>\n\n");
374    }
375    fprintf(fpout, "    </vspaceset>\n");
376    fprintf(fpout, "</mapping_info>\n");
377} // end buildXml()
378
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()
424
425
426
427// Local Variables:
428// tab-width: 4
429// c-basic-offset: 4
430// c-file-offsets:((innamespace . 0)(inline-open . 0))
431// indent-tabs-mode: nil
432// End:
433// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
434
Note: See TracBrowser for help on using the repository browser.