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

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

Introduce the HBA_ISR for VciMultiAhci? component.

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