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

Last change on this file since 273 was 263, checked in by alain, 11 years ago

Introducing support for TSAR fixed format cluster index (cluster_xy)
We have now 4 parameters defined in map.xml:

  • X_WIDTH, Y_WIDTH define the fixed format (typically X_WIDTH = 4 / Y_WIDTH = 4)
  • X_SIZE, Y_SIZE define the actual TSAR 2D mesh variable size (from 1 to 16)
  • Property svn:executable set to *
File size: 17.6 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    const char * vobj_type[] = 
22    { 
23        "ELF",        // binary code generated by GCC
24        "BLOB",       // binary code generated by GCC
25        "PTAB",       // page table
26        "PERI",       // hardware component
27        "MWMR",       // MWMR channel
28        "LOCK",       // Spin-Lock
29        "BUFFER",     // Any "no intialiasation needed" objects (stacks...)
30        "BARRIER",    // Barrier
31        "CONST",      // Constant
32        "MEMSPACE",   // Memspace
33        "SCHED",      // Scheduler
34    };
35
36    const char * pseg_type[] = 
37    {
38        "RAM",
39        "ROM",
40        "PERI",
41    };
42
43    const char * irq_type[] =
44    {
45        "HARD",
46        "SOFT",
47    };
48
49    const char * isr_type[] =
50    {
51        "ISR_DEFAULT",
52        "ISR_SWITCH",
53        "ISR_TTY",
54        "ISR_DMA",
55        "ISR_IOC",
56        "ISR_TIMER",
57    };
58
59    const char * periph_type[] =
60    {
61        "CMA",
62        "DMA",
63        "FBF",
64        "HBA",
65        "ICU",
66        "IOB",
67        "IOC",
68        "MMC",
69        "MWR",
70        "NIC",
71        "ROM",
72        "SIM",
73        "TIM",
74        "TTY",
75        "XCU",
76    };
77
78    const char * port_direction[] =
79    {
80        "TO_COPROC",
81        "FROM_COPROC",
82    };
83
84    const char * mode_str[] = 
85    { 
86        "____",
87        "___U", 
88        "__W_", 
89        "__WU", 
90        "_X__", 
91        "_X_U", 
92        "_XW_", 
93        "_XWU", 
94        "C___", 
95        "C__U", 
96        "C_W_", 
97        "C_WU", 
98        "CX__", 
99        "CX_U", 
100        "CXW_", 
101        "CXWU", 
102    };
103
104    unsigned int vspace_id;
105    unsigned int cluster_id;
106    unsigned int pseg_id;
107    unsigned int vseg_id;
108    unsigned int vobj_id;
109    unsigned int task_id;
110    unsigned int proc_id;
111    unsigned int irq_id;
112    unsigned int coproc_id;
113    unsigned int port_id;
114    unsigned int periph_id;
115
116    mapping_cluster_t * cluster;
117    mapping_pseg_t * pseg;
118    mapping_vspace_t * vspace;
119    mapping_vseg_t * vseg;
120    mapping_vobj_t * vobj;
121    mapping_task_t * task;
122    mapping_proc_t * proc;
123    mapping_irq_t * irq;   
124    mapping_coproc_t * coproc;
125    mapping_cp_port_t * cp_port;
126    mapping_periph_t * periph;
127
128    // computes the base adresss for clusters array,
129    cluster = (mapping_cluster_t *)((char *) header +
130            MAPPING_HEADER_SIZE);
131
132    // computes the base adresss for psegs array,
133    pseg = (mapping_pseg_t *) ((char *) header +
134            MAPPING_HEADER_SIZE +
135            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size);
136
137    // computes the base adresss for vspaces array,
138    vspace = (mapping_vspace_t *) ((char *) header +
139            MAPPING_HEADER_SIZE +
140            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size +
141            MAPPING_PSEG_SIZE * header->psegs);
142
143    // computes the base adresss for vsegs array,
144    vseg = (mapping_vseg_t *) ((char *) header +
145            MAPPING_HEADER_SIZE +
146            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size +
147            MAPPING_PSEG_SIZE * header->psegs +
148            MAPPING_VSPACE_SIZE * header->vspaces);
149
150    // computes the base adresss for vobjs array,
151    vobj = (mapping_vobj_t *) ((char *) header +
152            MAPPING_HEADER_SIZE +
153            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size +
154            MAPPING_PSEG_SIZE * header->psegs +
155            MAPPING_VSPACE_SIZE * header->vspaces +
156            MAPPING_VSEG_SIZE * header->vsegs);
157
158    // computes the base address for tasks array
159    task = (mapping_task_t *) ((char *) header +
160            MAPPING_HEADER_SIZE +
161            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size +
162            MAPPING_PSEG_SIZE * header->psegs +
163            MAPPING_VSPACE_SIZE * header->vspaces +
164            MAPPING_VOBJ_SIZE * header->vobjs +
165            MAPPING_VSEG_SIZE * header->vsegs);
166
167    // computes the base address for procs array
168    proc = (mapping_proc_t *) ((char *) header +
169            MAPPING_HEADER_SIZE +
170            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size +
171            MAPPING_PSEG_SIZE * header->psegs +
172            MAPPING_VSPACE_SIZE * header->vspaces +
173            MAPPING_VOBJ_SIZE * header->vobjs +
174            MAPPING_VSEG_SIZE * header->vsegs +
175            MAPPING_TASK_SIZE * header->tasks);
176
177    // computes the base address for irqs array
178    irq = (mapping_irq_t *) ((char *) header +
179            MAPPING_HEADER_SIZE +
180            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size +
181            MAPPING_PSEG_SIZE * header->psegs +
182            MAPPING_VSPACE_SIZE * header->vspaces +
183            MAPPING_VOBJ_SIZE * header->vobjs +
184            MAPPING_VSEG_SIZE * header->vsegs +
185            MAPPING_TASK_SIZE * header->tasks +
186            MAPPING_PROC_SIZE * header->procs);
187
188    // computes the base address for coprocs array
189    coproc = (mapping_coproc_t *) ((char *) header +
190            MAPPING_HEADER_SIZE +
191            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size +
192            MAPPING_PSEG_SIZE * header->psegs +
193            MAPPING_VSPACE_SIZE * header->vspaces +
194            MAPPING_VOBJ_SIZE * header->vobjs +
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    // computes the base address for cp_ports array
201    cp_port = (mapping_cp_port_t *) ((char *) header +
202            MAPPING_HEADER_SIZE +
203            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size +
204            MAPPING_PSEG_SIZE * header->psegs +
205            MAPPING_VSPACE_SIZE * header->vspaces +
206            MAPPING_VOBJ_SIZE * header->vobjs +
207            MAPPING_VSEG_SIZE * header->vsegs +
208            MAPPING_TASK_SIZE * header->tasks +
209            MAPPING_PROC_SIZE * header->procs +
210            MAPPING_IRQ_SIZE * header->irqs +
211            MAPPING_COPROC_SIZE * header->coprocs);
212
213    // computes the base address for periphs array
214    periph = (mapping_periph_t *) ((char *) header +
215            MAPPING_HEADER_SIZE +
216            MAPPING_CLUSTER_SIZE * header->x_size * header->y_size +
217            MAPPING_PSEG_SIZE * header->psegs +
218            MAPPING_VSPACE_SIZE * header->vspaces +
219            MAPPING_VOBJ_SIZE * header->vobjs +
220            MAPPING_VSEG_SIZE * header->vsegs +
221            MAPPING_TASK_SIZE * header->tasks +
222            MAPPING_PROC_SIZE * header->procs +
223            MAPPING_IRQ_SIZE * header->irqs +
224            MAPPING_COPROC_SIZE * header->coprocs +
225            MAPPING_CP_PORT_SIZE * header->cp_ports);
226
227    ///////////////////////// header /////////////////////////////////////////////
228
229    fprintf(fpout, "<?xml version = \"1.0\"?>\n\n");
230
231    fprintf(fpout, "<mapping_info signature = \"0x%x\" \n", header->signature);
232    fprintf(fpout, "              name      = \"%s\"   \n", header->name);
233    fprintf(fpout, "              x_size    = \"%d\"   \n", header->x_size);
234    fprintf(fpout, "              y_size    = \"%d\"   \n", header->y_size);
235    fprintf(fpout, "              x_width   = \"%d\"   \n", header->x_width);
236    fprintf(fpout, "              y_width   = \"%d\"   \n", header->y_width);
237    fprintf(fpout, "              vspaces   = \"%d\"   \n", header->vspaces);
238    fprintf(fpout, "              increment = \"%d\" >\n\n", header->vspaces);
239
240    ///////////////////// clusters ///////////////////////////////////////////////
241
242    fprintf( fpout, "    <clusterset>\n");
243    for (cluster_id = 0; cluster_id < (header->x_size * header->y_size); cluster_id++) 
244    {
245        fprintf(fpout, "        <cluster x = \"%d\" y = \"%d\" >\n", 
246                cluster[cluster_id].x, cluster[cluster_id].y );
247
248        ///////////////////// psegs   ////////////////////////////////////////////////
249
250        for (pseg_id = cluster[cluster_id].pseg_offset;
251             pseg_id < cluster[cluster_id].pseg_offset + cluster[cluster_id].psegs;
252             pseg_id++) 
253        {
254            fprintf(fpout, "            <pseg name = \"%s\" ", pseg[pseg_id].name);
255            fprintf(fpout, "type = \"%s\" ", pseg_type[pseg[pseg_id].type]);
256            fprintf(fpout, "base = \"0x%llx\" ", pseg[pseg_id].base);
257            fprintf(fpout, "length = \"0x%llx\" />\n",   pseg[pseg_id].length);
258        }
259
260        ///////////////////// processors /////////////////////////////////////////////
261
262        unsigned int proc_index = 0;
263        for (proc_id = cluster[cluster_id].proc_offset;
264             proc_id < cluster[cluster_id].proc_offset + cluster[cluster_id].procs;
265             proc_id++) 
266        {
267            fprintf(fpout, "            <proc index = \"%d\" >\n", proc_index);
268            for (irq_id = proc[proc_id].irq_offset; 
269                 irq_id < proc[proc_id].irq_offset + proc[proc_id].irqs;
270                 irq_id++) 
271            {
272                fprintf(fpout, "                <irq type = \"%s\" ", irq_type[irq[irq_id].type]);
273                fprintf(fpout, " icuid = \"0x%x\" ", irq[irq_id].icuid);
274                fprintf(fpout, " isr = \"%s\" ", isr_type[irq[irq_id].isr]);
275                fprintf(fpout, " channel = \"0x%x\" />\n", irq[irq_id].channel);
276            }
277            fprintf(fpout, "            </proc>\n" );
278        }
279
280
281        ///////////////////// coprocessors ///////////////////////////////////////////
282
283        for (coproc_id = cluster[cluster_id].coproc_offset;
284             coproc_id < cluster[cluster_id].coproc_offset + cluster[cluster_id].coprocs;
285             coproc_id++) 
286        {
287            fprintf(fpout, "            <coproc name = \"%s\" ", coproc[coproc_id].name);
288            fprintf(fpout, " psegname = \"%s\" >\n", pseg[coproc[coproc_id].psegid].name);
289            for (port_id = coproc[coproc_id].port_offset;
290                 port_id < coproc[coproc_id].port_offset + coproc[coproc_id].ports;
291                 port_id++) 
292            {
293                unsigned int vobj_id = cp_port[port_id].mwmr_vobjid + vspace[cp_port[port_id].vspaceid].vobj_offset; 
294                fprintf(fpout, "             <port direction = \"%s\" ",  port_direction[cp_port[port_id].direction]);
295                fprintf(fpout, " vspacename = \"%s\" ", vspace[cp_port[port_id].vspaceid].name);
296                fprintf(fpout, " vobjname = \"%s\" />\n",  vobj[vobj_id].name);
297            }
298            fprintf(fpout, "            </coproc>\n" );
299        }
300
301        ///////////////////// periphs  ///////////////////////////////////////////////
302
303        for (periph_id = cluster[cluster_id].periph_offset;
304             periph_id < cluster[cluster_id].periph_offset + cluster[cluster_id].periphs;
305             periph_id++) 
306        {
307            fprintf(fpout, "            <periph type = \"%s\" ", periph_type[periph[periph_id].type]);
308            fprintf(fpout, " psegname = \"%s\" ", pseg[periph[periph_id].psegid].name);
309            fprintf(fpout, " channels = \"%d\" />\n",  periph[periph_id].channels);
310        }
311        fprintf(fpout, "        </cluster>\n" );
312    }
313    fprintf(fpout, "    </clusterset>\n\n" );
314
315    /////////////////// globals /////////////////////////////////////////////////
316
317    fprintf(fpout, "    <globalset>\n" );
318    for (vseg_id = 0; vseg_id < header->globals; vseg_id++) 
319    {
320        unsigned int pseg_id = vseg[vseg_id].psegid; 
321
322        fprintf(fpout, "        <vseg name = \"%s\" ", vseg[vseg_id].name);
323        fprintf(fpout, "vbase = \"0x%x\" ", vseg[vseg_id].vbase);
324        fprintf(fpout, "mode  = \"%s\" ", mode_str[vseg[vseg_id].mode]);
325        fprintf(fpout, "clusterid = \"%d\" ", pseg[pseg_id].clusterid);
326        fprintf(fpout, "psegname = \"%s\" ", pseg[pseg_id].name);
327        fprintf(fpout, "ident = \"%d\" >\n", vseg[vseg_id].ident);
328        for (vobj_id = vseg[vseg_id].vobj_offset;
329             vobj_id < (vseg[vseg_id].vobj_offset + vseg[vseg_id].vobjs); 
330             vobj_id++) 
331        {
332            fprintf(fpout, "            <vobj name = \"%s\" ", vobj[vobj_id].name);
333            fprintf(fpout, "type = \"%s\" ", vobj_type[vobj[vobj_id].type]);
334            fprintf(fpout, "length = \"0x%x\" ", vobj[vobj_id].length);
335            fprintf(fpout, "align = \"%d\" ", vobj[vobj_id].align);
336            fprintf(fpout, "init = \"%d\" ", vobj[vobj_id].init);
337            fprintf(fpout, "binpath = \"%s\" />\n", vobj[vobj_id].binpath);
338        }
339        fprintf(fpout, "        </vseg>\n");
340    }
341    fprintf(fpout, "    </globalset>\n" );
342
343    //////////////////// vspaces ////////////////////////////////////////////////
344
345    fprintf( fpout, "\n    <vspaceset>\n\n" );
346    for (vspace_id = 0; vspace_id < header->vspaces; vspace_id++) 
347    {
348        unsigned int func_id = vspace[vspace_id].vobj_offset + vspace[vspace_id].start_offset; 
349        fprintf(fpout, "        <vspace name = \"%s\" ", vspace[vspace_id].name); 
350        fprintf(fpout, " startname = \"%s\" >\n", vobj[func_id].name); 
351
352        //////////////////// vsegs //////////////////////////////////////////////
353
354        for (vseg_id = vspace[vspace_id].vseg_offset;
355             vseg_id < (vspace[vspace_id].vseg_offset + vspace[vspace_id].vsegs);
356             vseg_id++) 
357        {
358            unsigned int pseg_id    = vseg[vseg_id].psegid; 
359            unsigned int cluster_id = pseg[pseg_id].clusterid;
360            unsigned int x          = cluster_id >> header->y_width;
361            unsigned int y          = cluster_id & ((1<<header->y_width)-1);
362
363            fprintf(fpout, "            <vseg name = \"%s\" ", vseg[vseg_id].name);
364            fprintf(fpout, "vbase = \"0x%x\" ", vseg[vseg_id].vbase);
365            fprintf(fpout, "mode = \"%s\" ", mode_str[vseg[vseg_id].mode]);
366            fprintf(fpout, "x = \"%d\" ", x);
367            fprintf(fpout, "y = \"%d\" ", y);
368            fprintf(fpout, "psegname = \"%s\" ", pseg[pseg_id].name);
369            fprintf(fpout, "ident = \"%d\" >\n", vseg[vseg_id].ident);
370
371            for (vobj_id = vseg[vseg_id].vobj_offset;
372                 vobj_id < (vseg[vseg_id].vobj_offset + vseg[vseg_id].vobjs);
373                 vobj_id++) 
374            {
375                fprintf(fpout, "             <vobj name = \"%s\" ", vobj[vobj_id].name);
376                fprintf(fpout, "type = \"%s\" ", vobj_type[vobj[vobj_id].type]);
377                fprintf(fpout, "length = \"0x%x\" ", vobj[vobj_id].length);
378                fprintf(fpout, "align = \"%d\" ", vobj[vobj_id].align);
379                fprintf(fpout, "init = \"%d\" ", vobj[vobj_id].init);
380                fprintf(fpout, "binpath = \"%s\" />\n", vobj[vobj_id].binpath);
381            }
382            fprintf(fpout, "            </vseg>\n\n");
383        }
384
385        //////////////////// tasks //////////////////////////////////////////////
386
387        for (task_id = vspace[vspace_id].task_offset;
388             task_id < (vspace[vspace_id].task_offset + vspace[vspace_id].tasks);
389             task_id++) 
390        {
391            unsigned int stack_vobj_id = task[task_id].stack_vobjid + vspace[vspace_id].vobj_offset; 
392            unsigned int heap_vobj_id = task[task_id].heap_vobjid + vspace[vspace_id].vobj_offset; 
393            unsigned int cluster_id   = task[task_id].clusterid;
394            unsigned int x            = cluster_id >> header->y_width;
395            unsigned int y            = cluster_id & ((1<<header->y_width)-1);
396
397            fprintf(fpout, "            <task name = \"%s\" ", task[task_id].name);
398            fprintf(fpout, "x = \"%d\" ", x);
399            fprintf(fpout, "y = \"%d\" ", y);
400            fprintf(fpout, "proclocid = \"%d\" ", task[task_id].proclocid);
401            fprintf(fpout, "stackname = \"%s\" ", vobj[stack_vobj_id].name);
402            if (heap_vobj_id != -1) 
403            {
404                fprintf(fpout, "heapname = \"%s\" ", vobj[heap_vobj_id].name);
405            }
406            fprintf(fpout, "startid = \"%d\" ", task[task_id].startid);
407            fprintf(fpout, "usetty = \"%d\" ", task[task_id].use_tty);
408            fprintf(fpout, "usenic = \"%d\" ", task[task_id].use_nic);
409            fprintf(fpout, "usecma = \"%d\" ", task[task_id].use_cma);
410            fprintf(fpout, "usetim = \"%d\" ", task[task_id].use_tim);
411            fprintf(fpout, "usehba = \"%d\" />\n", task[task_id].use_hba);
412        }
413        fprintf(fpout, "        </vspace>\n\n");
414    }
415    fprintf(fpout, "    </vspaceset>\n");
416    fprintf(fpout, "</mapping_info>\n");
417} // end buildXml()
418
419
420/////////////////////////////////////
421int main(int argc, char * argv[]) {
422    if (argc < 2) {
423        printf("Usage: bin2xml <input_file_path> <output_file_path>\n");
424        return 1;
425    }
426
427    unsigned int bin[0x10000]; // 64 K int = 256 Kbytes
428
429    int fdin = open(argv[1], O_RDONLY);
430    if (fdin < 0) {
431        perror("open");
432        exit(1);
433    }
434
435    FILE * fpout = fopen( argv[2], "w");
436    if (fpout == NULL) {
437        perror("open");
438        exit(1);
439    }
440
441    unsigned int length = read(fdin, bin, 0x40000);
442
443    if (length <= 0) {
444        perror("read");
445        exit(1);
446    }
447
448    if (bin[0] == IN_MAPPING_SIGNATURE) {
449        buildXml((mapping_header_t *) bin, fpout);
450    } 
451    else {
452        printf("[ERROR] Wrong file format\n");
453        exit(1);
454    }
455    return 0;
456} // end main()
457
458
459
460// Local Variables:
461// tab-width: 4
462// c-basic-offset: 4
463// c-file-offsets:((innamespace . 0)(inline-open . 0))
464// indent-tabs-mode: nil
465// End:
466// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
467
Note: See TracBrowser for help on using the repository browser.