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

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

Introducing support for MWMR coprocessors.

  • 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    };
102
103    const char * mode_str[] = 
104    { 
105        "____",
106        "___U", 
107        "__W_", 
108        "__WU", 
109        "_X__", 
110        "_X_U", 
111        "_XW_", 
112        "_XWU", 
113        "C___", 
114        "C__U", 
115        "C_W_", 
116        "C_WU", 
117        "CX__", 
118        "CX_U", 
119        "CXW_", 
120        "CXWU", 
121    };
122
123    unsigned int vspace_id;
124    unsigned int cluster_id;
125    unsigned int pseg_id;
126    unsigned int vseg_id;
127    unsigned int task_id;
128    unsigned int proc_id;
129    unsigned int irq_id;
130    unsigned int periph_id;
131
132    mapping_cluster_t * cluster;
133    mapping_pseg_t * pseg;
134    mapping_vspace_t * vspace;
135    mapping_vseg_t * vseg;
136    mapping_task_t * task;
137    mapping_proc_t * proc;
138    mapping_irq_t * irq;   
139    mapping_periph_t * periph;
140
141    // computes the base adresss for clusters array,
142    cluster = (mapping_cluster_t *)((char *) header +
143            MAPPING_HEADER_SIZE);
144
145    // computes the base adresss for psegs array,
146    pseg = (mapping_pseg_t *) ((char *) header +
147            MAPPING_HEADER_SIZE +
148            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size);
149
150    // computes the base adresss for vspaces array,
151    vspace = (mapping_vspace_t *) ((char *) header +
152            MAPPING_HEADER_SIZE +
153            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size +
154            MAPPING_PSEG_SIZE * header->psegs);
155
156    // computes the base adresss for vsegs array,
157    vseg = (mapping_vseg_t *) ((char *) header +
158            MAPPING_HEADER_SIZE +
159            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size +
160            MAPPING_PSEG_SIZE * header->psegs +
161            MAPPING_VSPACE_SIZE * header->vspaces);
162
163    // computes the base address for tasks array
164    task = (mapping_task_t *) ((char *) header +
165            MAPPING_HEADER_SIZE +
166            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size +
167            MAPPING_PSEG_SIZE * header->psegs +
168            MAPPING_VSPACE_SIZE * header->vspaces +
169            MAPPING_VSEG_SIZE * header->vsegs);
170
171    // computes the base address for procs array
172    proc = (mapping_proc_t *) ((char *) header +
173            MAPPING_HEADER_SIZE +
174            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size +
175            MAPPING_PSEG_SIZE * header->psegs +
176            MAPPING_VSPACE_SIZE * header->vspaces +
177            MAPPING_VSEG_SIZE * header->vsegs +
178            MAPPING_TASK_SIZE * header->tasks);
179
180    // computes the base address for irqs array
181    irq = (mapping_irq_t *) ((char *) header +
182            MAPPING_HEADER_SIZE +
183            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size +
184            MAPPING_PSEG_SIZE * header->psegs +
185            MAPPING_VSPACE_SIZE * header->vspaces +
186            MAPPING_VSEG_SIZE * header->vsegs +
187            MAPPING_TASK_SIZE * header->tasks +
188            MAPPING_PROC_SIZE * header->procs);
189
190    // computes the base address for periphs array
191    periph = (mapping_periph_t *) ((char *) header +
192            MAPPING_HEADER_SIZE +
193            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size +
194            MAPPING_PSEG_SIZE * header->psegs +
195            MAPPING_VSPACE_SIZE * header->vspaces +
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
201    ///////////////////////// header /////////////////////////////////////////////
202
203    fprintf(fpout, "<?xml version = \"1.0\"?>\n\n");
204
205    fprintf(fpout, "<mapping_info signature    = \"0x%x\" \n" , header->signature);
206    fprintf(fpout, "              name         = \"%s\"   \n" , header->name);
207    fprintf(fpout, "              x_size       = \"%d\"   \n" , header->x_size);
208    fprintf(fpout, "              y_size       = \"%d\"   \n" , header->y_size);
209    fprintf(fpout, "              x_width      = \"%d\"   \n" , header->x_width);
210    fprintf(fpout, "              y_width      = \"%d\"   \n" , header->y_width);
211    fprintf(fpout, "              irq_per_proc = \"%d\"   \n" , header->irq_per_proc);
212    fprintf(fpout, "              use_ram_disk = \"%d\"   \n" , header->use_ram_disk);
213    fprintf(fpout, "              x_io         = \"%d\"   \n" , header->x_io);
214    fprintf(fpout, "              y_io         = \"%d\" >\n\n", header->y_io);
215
216    ///////////////////// clusters ///////////////////////////////////////////////
217
218    fprintf( fpout, "    <clusterset>\n");
219    for (cluster_id = 0; cluster_id < (header->x_size * header->y_size); cluster_id++) 
220    {
221        fprintf(fpout, "        <cluster x=\"%d\" y=\"%d\" >\n", 
222                cluster[cluster_id].x, cluster[cluster_id].y );
223
224        ///////////////////// psegs   ////////////////////////////////////////////////
225
226        for (pseg_id = cluster[cluster_id].pseg_offset;
227             pseg_id < cluster[cluster_id].pseg_offset + cluster[cluster_id].psegs;
228             pseg_id++) 
229        {
230            fprintf(fpout, "            <pseg name=\"%s\"", pseg[pseg_id].name);
231            fprintf(fpout, " type=\"%s\"", pseg_type[pseg[pseg_id].type]);
232            fprintf(fpout, " base=\"0x%llx\"", pseg[pseg_id].base);
233            fprintf(fpout, " length=\"0x%llx\" />\n", pseg[pseg_id].length);
234        }
235
236        ///////////////////// processors /////////////////////////////////////////////
237
238        unsigned int proc_index = 0;
239        for (proc_id = cluster[cluster_id].proc_offset;
240             proc_id < cluster[cluster_id].proc_offset + cluster[cluster_id].procs;
241             proc_id++, proc_index++) 
242        {
243            fprintf(fpout, "            <proc index=\"%d\" />\n", proc_index);
244        }
245
246        ///////////////////// periphs  ///////////////////////////////////////////////
247
248        for (periph_id = cluster[cluster_id].periph_offset;
249             periph_id < cluster[cluster_id].periph_offset + cluster[cluster_id].periphs;
250             periph_id++) 
251        {
252            fprintf(fpout, "            <periph type=\"%s\"", periph_type[periph[periph_id].type]);
253
254            if (periph[periph_id].type == PERIPH_TYPE_IOC) 
255                fprintf(fpout, " subtype=\"%s\"", ioc_subtype[periph[periph_id].subtype]);
256
257            if (periph[periph_id].type == PERIPH_TYPE_MWR) 
258                fprintf(fpout, " subtype=\"%s\"", mwr_subtype[periph[periph_id].subtype]);
259
260            fprintf(fpout, " psegname=\"%s\"", pseg[periph[periph_id].psegid].name);
261            fprintf(fpout, " channels=\"%d\"",  periph[periph_id].channels);
262            fprintf(fpout, " arg0=\"%d\" >\n",  periph[periph_id].arg0);
263            fprintf(fpout, " arg1=\"%d\" >\n",  periph[periph_id].arg1);
264            fprintf(fpout, " arg2=\"%d\" >\n",  periph[periph_id].arg2);
265            fprintf(fpout, " arg3=\"%d\" >\n",  periph[periph_id].arg3);
266            if ( (periph[periph_id].type == PERIPH_TYPE_PIC) ||
267                 (periph[periph_id].type == PERIPH_TYPE_XCU) )
268            {
269                for (irq_id = periph[periph_id].irq_offset; 
270                     irq_id < periph[periph_id].irq_offset + periph[periph_id].irqs;
271                     irq_id++) 
272                {
273                    fprintf(fpout, "                <irq srctype=\"%s\"", irq_type[irq[irq_id].srctype]);
274                    fprintf(fpout, " srcid=\"%d\"", irq[irq_id].srcid);
275                    fprintf(fpout, " isr=\"%s\"", isr_type[irq[irq_id].isr]);
276                    fprintf(fpout, " channel=\"%d\" />\n", irq[irq_id].channel);
277                }
278            }
279            fprintf(fpout, "            </periph>\n");
280        }
281        fprintf(fpout, "        </cluster>\n" );
282    }
283    fprintf(fpout, "    </clusterset>\n\n" );
284
285    /////////////////// globals /////////////////////////////////////////////////
286
287    fprintf(fpout, "    <globalset>\n" );
288    for (vseg_id = 0; vseg_id < header->globals; vseg_id++) 
289    {
290        unsigned int pseg_id    = vseg[vseg_id].psegid; 
291        unsigned int cluster_id = pseg[pseg_id].clusterid;
292
293        fprintf(fpout, "        <vseg name=\"%s\"", vseg[vseg_id].name);
294        fprintf(fpout, " vbase=\"0x%x\"", vseg[vseg_id].vbase);
295        fprintf(fpout, " length=\"0x%x\"", vseg[vseg_id].length);
296        fprintf(fpout, " type=\"%s\"", vseg_type[vseg[vseg_id].type]);
297        fprintf(fpout, " mode=\"%s\"", mode_str[vseg[vseg_id].mode]);
298        fprintf(fpout, "\n             ");     
299        fprintf(fpout, " x=\"%d\"", cluster[cluster_id].x);
300        fprintf(fpout, " y=\"%d\"", cluster[cluster_id].y);
301        fprintf(fpout, " psegname=\"%s\"", pseg[pseg_id].name);
302        if( vseg[vseg_id].ident ) 
303        fprintf(fpout, " ident=\"1\"");
304        if( vseg[vseg_id].local ) 
305        fprintf(fpout, " local=\"1\"");
306        if( vseg[vseg_id].big ) 
307        fprintf(fpout, " big=\"1\"");
308        if( vseg[vseg_id].binpath[0] != 0 ) 
309        fprintf(fpout, " binpath=\"%s\"", vseg[vseg_id].binpath);
310        fprintf(fpout, " >\n");
311    }
312    fprintf(fpout, "    </globalset>\n" );
313
314    //////////////////// vspaces ////////////////////////////////////////////////
315
316    fprintf( fpout, "\n    <vspaceset>\n\n" );
317    for (vspace_id = 0; vspace_id < header->vspaces; vspace_id++) 
318    {
319        unsigned int vseg_id = vspace[vspace_id].start_vseg_id;
320        fprintf(fpout, "        <vspace name = \"%s\" ", vspace[vspace_id].name); 
321        fprintf(fpout, " startname = \"%s\" >\n", vseg[vseg_id].name); 
322
323        //////////////////// vsegs //////////////////////////////////////////////
324
325        for (vseg_id = vspace[vspace_id].vseg_offset;
326             vseg_id < (vspace[vspace_id].vseg_offset + vspace[vspace_id].vsegs);
327             vseg_id++) 
328        {
329            unsigned int pseg_id    = vseg[vseg_id].psegid; 
330            unsigned int cluster_id = pseg[pseg_id].clusterid;
331
332            fprintf(fpout, "            <vseg name=\"%s\"", vseg[vseg_id].name);
333            fprintf(fpout, " vbase=\"0x%x\"", vseg[vseg_id].vbase);
334            fprintf(fpout, " length=\"0x%x\"", vseg[vseg_id].length);
335            fprintf(fpout, " type=\"%s\"", vseg_type[vseg[vseg_id].type]);
336            fprintf(fpout, " mode=\"%s\"", mode_str[vseg[vseg_id].mode]);
337            fprintf(fpout, "\n                 ");     
338            fprintf(fpout, " x=\"%d\"", cluster[cluster_id].x);
339            fprintf(fpout, " y=\"%d\"", cluster[cluster_id].y);
340            fprintf(fpout, " psegname=\"%s\"", pseg[pseg_id].name);
341            if( vseg[vseg_id].ident ) 
342            fprintf(fpout, " ident=\"1\"");
343            if( vseg[vseg_id].local ) 
344            fprintf(fpout, " local=\"1\"");
345            if( vseg[vseg_id].big ) 
346            fprintf(fpout, " big=\"1\"");
347            if( vseg[vseg_id].binpath[0] != 0 ) 
348            fprintf(fpout, " binpath=\"%s\"", vseg[vseg_id].binpath);
349            fprintf(fpout, " >\n");
350        }
351
352        //////////////////// tasks //////////////////////////////////////////////
353
354        for (task_id = vspace[vspace_id].task_offset;
355             task_id < (vspace[vspace_id].task_offset + vspace[vspace_id].tasks);
356             task_id++) 
357        {
358            unsigned int stack_vseg_id = task[task_id].stack_vseg_id; 
359            unsigned int heap_vseg_id  = task[task_id].heap_vseg_id; 
360            unsigned int cluster_id    = task[task_id].clusterid;
361
362            fprintf(fpout, "            <task name=\"%s\"", task[task_id].name);
363            fprintf(fpout, " trdid=\"%d\"", task[task_id].trdid);
364            fprintf(fpout, " x=\"%d\"", cluster[cluster_id].x);
365            fprintf(fpout, " y=\"%d\"", cluster[cluster_id].y);
366            fprintf(fpout, " p=\"%d\"", task[task_id].proclocid);
367            fprintf(fpout, "\n                 ");     
368            fprintf(fpout, " stackname=\"%s\"", vseg[stack_vseg_id].name);
369            if (heap_vseg_id != -1) 
370            fprintf(fpout, " heapname=\"%s\"", vseg[heap_vseg_id].name);
371            fprintf(fpout, " startid = \"%d\"", task[task_id].startid);
372            fprintf(fpout, " />\n");
373        }
374        fprintf(fpout, "        </vspace>\n\n");
375    }
376    fprintf(fpout, "    </vspaceset>\n");
377    fprintf(fpout, "</mapping_info>\n");
378} // end buildXml()
379
380
381/////////////////////////////////////
382int main(int argc, char * argv[]) 
383{
384    if (argc < 2) 
385    {
386        printf("Usage: bin2xml <input_file_path> <output_file_path>\n");
387        return 1;
388    }
389
390    unsigned int bin[0x10000]; // 64 K int = 256 Kbytes
391
392    int fdin = open(argv[1], O_RDONLY);
393    if (fdin < 0) 
394    {
395        perror("open");
396        exit(1);
397    }
398
399    FILE * fpout = fopen( argv[2], "w");
400    if (fpout == NULL) 
401    {
402        perror("open");
403        exit(1);
404    }
405
406    unsigned int length = read(fdin, bin, 0x40000);
407
408    if (length <= 0) 
409    {
410        perror("read");
411        exit(1);
412    }
413
414    if (bin[0] == IN_MAPPING_SIGNATURE) 
415    {
416        buildXml((mapping_header_t *) bin, fpout);
417    } 
418    else 
419    {
420        printf("[ERROR] Wrong file format\n");
421        exit(1);
422    }
423    return 0;
424} // end main()
425
426
427
428// Local Variables:
429// tab-width: 4
430// c-basic-offset: 4
431// c-file-offsets:((innamespace . 0)(inline-open . 0))
432// indent-tabs-mode: nil
433// End:
434// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
435
Note: See TracBrowser for help on using the repository browser.