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

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

Introduce the "active" field in vspace.

  • Property svn:executable set to *
File size: 14.7 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_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 irqs array
172    irq = (mapping_irq_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            MAPPING_PROC_SIZE * header->procs);
180
181    // computes the base address for periphs array
182    periph = (mapping_periph_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            MAPPING_IRQ_SIZE * header->irqs);
191
192    ///////////////////////// header /////////////////////////////////////////////
193
194    fprintf(fpout, "<?xml version = \"1.0\"?>\n\n");
195
196    fprintf(fpout, "<mapping_info signature    = \"0x%x\" \n" , header->signature);
197    fprintf(fpout, "              name         = \"%s\"   \n" , header->name);
198    fprintf(fpout, "              x_size       = \"%d\"   \n" , header->x_size);
199    fprintf(fpout, "              y_size       = \"%d\"   \n" , header->y_size);
200    fprintf(fpout, "              x_width      = \"%d\"   \n" , header->x_width);
201    fprintf(fpout, "              y_width      = \"%d\"   \n" , header->y_width);
202    fprintf(fpout, "              irq_per_proc = \"%d\"   \n" , header->irq_per_proc);
203    fprintf(fpout, "              use_ram_disk = \"%d\"   \n" , header->use_ram_disk);
204    fprintf(fpout, "              x_io         = \"%d\"   \n" , header->x_io);
205    fprintf(fpout, "              y_io         = \"%d\" >\n\n", header->y_io);
206
207    ///////////////////// clusters ///////////////////////////////////////////////
208
209    fprintf( fpout, "    <clusterset>\n");
210    for (cluster_id = 0; cluster_id < (header->x_size * header->y_size); cluster_id++) 
211    {
212        fprintf(fpout, "        <cluster x=\"%d\" y=\"%d\" >\n", 
213                cluster[cluster_id].x, cluster[cluster_id].y );
214
215        ///////////////////// psegs   ////////////////////////////////////////////////
216
217        for (pseg_id = cluster[cluster_id].pseg_offset;
218             pseg_id < cluster[cluster_id].pseg_offset + cluster[cluster_id].psegs;
219             pseg_id++) 
220        {
221            fprintf(fpout, "            <pseg name=\"%s\"", pseg[pseg_id].name);
222            fprintf(fpout, " type=\"%s\"", pseg_type[pseg[pseg_id].type]);
223            fprintf(fpout, " base=\"0x%llx\"", pseg[pseg_id].base);
224            fprintf(fpout, " length=\"0x%llx\" />\n", pseg[pseg_id].length);
225        }
226
227        ///////////////////// processors /////////////////////////////////////////////
228
229        unsigned int proc_index = 0;
230        for (proc_id = cluster[cluster_id].proc_offset;
231             proc_id < cluster[cluster_id].proc_offset + cluster[cluster_id].procs;
232             proc_id++, proc_index++) 
233        {
234            fprintf(fpout, "            <proc index=\"%d\" />\n", proc_index);
235        }
236
237        ///////////////////// periphs  ///////////////////////////////////////////////
238
239        for (periph_id = cluster[cluster_id].periph_offset;
240             periph_id < cluster[cluster_id].periph_offset + cluster[cluster_id].periphs;
241             periph_id++) 
242        {
243            fprintf(fpout, "            <periph type=\"%s\"", periph_type[periph[periph_id].type]);
244
245            if (periph[periph_id].type == PERIPH_TYPE_IOC) 
246                fprintf(fpout, " subtype=\"%s\"", ioc_subtype[periph[periph_id].subtype]);
247
248            if (periph[periph_id].type == PERIPH_TYPE_MWR) 
249                fprintf(fpout, " subtype=\"%s\"", mwr_subtype[periph[periph_id].subtype]);
250
251            fprintf(fpout, " psegname=\"%s\"", pseg[periph[periph_id].psegid].name);
252            fprintf(fpout, " channels=\"%d\"",  periph[periph_id].channels);
253            fprintf(fpout, " arg0=\"%d\"",  periph[periph_id].arg0);
254            fprintf(fpout, " arg1=\"%d\"",  periph[periph_id].arg1);
255            fprintf(fpout, " arg2=\"%d\"",  periph[periph_id].arg2);
256            fprintf(fpout, " arg3=\"%d\" >\n",  periph[periph_id].arg3);
257            if ( (periph[periph_id].type == PERIPH_TYPE_PIC) ||
258                 (periph[periph_id].type == PERIPH_TYPE_XCU) )
259            {
260                for (irq_id = periph[periph_id].irq_offset; 
261                     irq_id < periph[periph_id].irq_offset + periph[periph_id].irqs;
262                     irq_id++) 
263                {
264                    fprintf(fpout, "                <irq srctype=\"%s\"", irq_type[irq[irq_id].srctype]);
265                    fprintf(fpout, " srcid=\"%d\"", irq[irq_id].srcid);
266                    fprintf(fpout, " isr=\"%s\"", isr_type[irq[irq_id].isr]);
267                    fprintf(fpout, " channel=\"%d\" />\n", irq[irq_id].channel);
268                }
269            }
270            fprintf(fpout, "            </periph>\n");
271        }
272        fprintf(fpout, "        </cluster>\n" );
273    }
274    fprintf(fpout, "    </clusterset>\n\n" );
275
276    /////////////////// globals /////////////////////////////////////////////////
277
278    fprintf(fpout, "    <globalset>\n" );
279    for (vseg_id = 0; vseg_id < header->globals; vseg_id++) 
280    {
281        unsigned int pseg_id    = vseg[vseg_id].psegid; 
282        unsigned int cluster_id = pseg[pseg_id].clusterid;
283
284        fprintf(fpout, "        <vseg name=\"%s\"", vseg[vseg_id].name);
285        fprintf(fpout, " vbase=\"0x%x\"", vseg[vseg_id].vbase);
286        fprintf(fpout, " length=\"0x%x\"", vseg[vseg_id].length);
287        fprintf(fpout, " type=\"%s\"", vseg_type[vseg[vseg_id].type]);
288        fprintf(fpout, " mode=\"%s\"", mode_str[vseg[vseg_id].mode]);
289        fprintf(fpout, "\n             ");     
290        fprintf(fpout, " x=\"%d\"", cluster[cluster_id].x);
291        fprintf(fpout, " y=\"%d\"", cluster[cluster_id].y);
292        fprintf(fpout, " psegname=\"%s\"", pseg[pseg_id].name);
293        if( vseg[vseg_id].ident ) 
294        fprintf(fpout, " ident=\"1\"");
295        if( vseg[vseg_id].local ) 
296        fprintf(fpout, " local=\"1\"");
297        if( vseg[vseg_id].big ) 
298        fprintf(fpout, " big=\"1\"");
299        if( vseg[vseg_id].binpath[0] != 0 ) 
300        fprintf(fpout, " binpath=\"%s\"", vseg[vseg_id].binpath);
301        fprintf(fpout, " >\n");
302    }
303    fprintf(fpout, "    </globalset>\n" );
304
305    //////////////////// vspaces ////////////////////////////////////////////////
306
307    fprintf( fpout, "\n    <vspaceset>\n\n" );
308    for (vspace_id = 0; vspace_id < header->vspaces; vspace_id++) 
309    {
310        unsigned int vseg_id = vspace[vspace_id].start_vseg_id;
311        fprintf(fpout, "        <vspace name=\"%s\"", vspace[vspace_id].name); 
312        fprintf(fpout, " startname=\"%s\"", vseg[vseg_id].name); 
313        fprintf(fpout, " active=\"%d\" >\n", vspace[vspace_id].active); 
314
315        //////////////////// vsegs //////////////////////////////////////////////
316
317        for (vseg_id = vspace[vspace_id].vseg_offset;
318             vseg_id < (vspace[vspace_id].vseg_offset + vspace[vspace_id].vsegs);
319             vseg_id++) 
320        {
321            unsigned int pseg_id    = vseg[vseg_id].psegid; 
322            unsigned int cluster_id = pseg[pseg_id].clusterid;
323
324            fprintf(fpout, "            <vseg name=\"%s\"", vseg[vseg_id].name);
325            fprintf(fpout, " vbase=\"0x%x\"", vseg[vseg_id].vbase);
326            fprintf(fpout, " length=\"0x%x\"", vseg[vseg_id].length);
327            fprintf(fpout, " type=\"%s\"", vseg_type[vseg[vseg_id].type]);
328            fprintf(fpout, " mode=\"%s\"", mode_str[vseg[vseg_id].mode]);
329            fprintf(fpout, "\n                 ");     
330            fprintf(fpout, " x=\"%d\"", cluster[cluster_id].x);
331            fprintf(fpout, " y=\"%d\"", cluster[cluster_id].y);
332            fprintf(fpout, " psegname=\"%s\"", pseg[pseg_id].name);
333            if( vseg[vseg_id].ident ) 
334            fprintf(fpout, " ident=\"1\"");
335            if( vseg[vseg_id].local ) 
336            fprintf(fpout, " local=\"1\"");
337            if( vseg[vseg_id].big ) 
338            fprintf(fpout, " big=\"1\"");
339            if( vseg[vseg_id].binpath[0] != 0 ) 
340            fprintf(fpout, " binpath=\"%s\"", vseg[vseg_id].binpath);
341            fprintf(fpout, " >\n");
342        }
343
344        //////////////////// tasks //////////////////////////////////////////////
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 stack_vseg_id = task[task_id].stack_vseg_id; 
351            unsigned int heap_vseg_id  = task[task_id].heap_vseg_id; 
352            unsigned int cluster_id    = task[task_id].clusterid;
353
354            fprintf(fpout, "            <task name=\"%s\"", task[task_id].name);
355            fprintf(fpout, " trdid=\"%d\"", task[task_id].trdid);
356            fprintf(fpout, " x=\"%d\"", cluster[cluster_id].x);
357            fprintf(fpout, " y=\"%d\"", cluster[cluster_id].y);
358            fprintf(fpout, " p=\"%d\"", task[task_id].proclocid);
359            fprintf(fpout, "\n                 ");     
360            fprintf(fpout, " stackname=\"%s\"", vseg[stack_vseg_id].name);
361            if (heap_vseg_id != -1) 
362            fprintf(fpout, " heapname=\"%s\"", vseg[heap_vseg_id].name);
363            fprintf(fpout, " startid = \"%d\"", task[task_id].startid);
364            fprintf(fpout, " />\n");
365        }
366        fprintf(fpout, "        </vspace>\n\n");
367    }
368    fprintf(fpout, "    </vspaceset>\n");
369    fprintf(fpout, "</mapping_info>\n");
370} // end buildXml()
371
372
373/////////////////////////////////////
374int main(int argc, char * argv[]) 
375{
376    if (argc < 2) 
377    {
378        printf("Usage: bin2xml <input_file_path> <output_file_path>\n");
379        return 1;
380    }
381
382    unsigned int bin[0x10000]; // 64 K int = 256 Kbytes
383
384    int fdin = open(argv[1], O_RDONLY);
385    if (fdin < 0) 
386    {
387        perror("open");
388        exit(1);
389    }
390
391    FILE * fpout = fopen( argv[2], "w");
392    if (fpout == NULL) 
393    {
394        perror("open");
395        exit(1);
396    }
397
398    unsigned int length = read(fdin, bin, 0x40000);
399
400    if (length <= 0) 
401    {
402        perror("read");
403        exit(1);
404    }
405
406    if (bin[0] == IN_MAPPING_SIGNATURE) 
407    {
408        buildXml((mapping_header_t *) bin, fpout);
409    } 
410    else 
411    {
412        printf("[ERROR] Wrong file format\n");
413        exit(1);
414    }
415    return 0;
416} // end main()
417
418
419
420// Local Variables:
421// tab-width: 4
422// c-basic-offset: 4
423// c-file-offsets:((innamespace . 0)(inline-open . 0))
424// indent-tabs-mode: nil
425// End:
426// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
427
Note: See TracBrowser for help on using the repository browser.