source: soft/giet_vm/xml/xml_driver.c @ 238

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

Major evolution to support physical addresses larger than 32 bits.
The map.xml format has been modified: the vsegs associated to schedulers
are now explicitely defined and mapped in the page tables.

File size: 16.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    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        "ICU",
62        "TIM",
63        "XICU",
64        "DMA",
65        "IOC",
66        "TTY",
67        "FBF",
68        "NIC",
69        "IOB",
70    };
71
72    const char * port_direction[] =
73    {
74        "TO_COPROC",
75        "FROM_COPROC",
76    };
77
78    const char * mode_str[] = 
79    { 
80        "____",
81        "___U", 
82        "__W_", 
83        "__WU", 
84        "_X__", 
85        "_X_U", 
86        "_XW_", 
87        "_XWU", 
88        "C___", 
89        "C__U", 
90        "C_W_", 
91        "C_WU", 
92        "CX__", 
93        "CX_U", 
94        "CXW_", 
95        "CXWU", 
96    };
97
98    unsigned int vspace_id;
99    unsigned int cluster_id;
100    unsigned int pseg_id;
101    unsigned int vseg_id;
102    unsigned int vobj_id;
103    unsigned int task_id;
104    unsigned int proc_id;
105    unsigned int irq_id;
106    unsigned int coproc_id;
107    unsigned int port_id;
108    unsigned int periph_id;
109
110    mapping_cluster_t * cluster;
111    mapping_pseg_t * pseg;
112    mapping_vspace_t * vspace;
113    mapping_vseg_t * vseg;
114    mapping_vobj_t * vobj;
115    mapping_task_t * task;
116    mapping_proc_t * proc;
117    mapping_irq_t * irq;   
118    mapping_coproc_t * coproc;
119    mapping_cp_port_t * cp_port;
120    mapping_periph_t * periph;
121
122    // computes the base adresss for clusters array,
123    cluster = (mapping_cluster_t *)((char *) header +
124            MAPPING_HEADER_SIZE);
125
126    // computes the base adresss for psegs array,
127    pseg = (mapping_pseg_t *) ((char *) header +
128            MAPPING_HEADER_SIZE +
129            MAPPING_CLUSTER_SIZE * header->clusters);
130
131    // computes the base adresss for vspaces array,
132    vspace = (mapping_vspace_t *) ((char *) header +
133            MAPPING_HEADER_SIZE +
134            MAPPING_CLUSTER_SIZE * header->clusters +
135            MAPPING_PSEG_SIZE * header->psegs);
136
137    // computes the base adresss for vsegs array,
138    vseg = (mapping_vseg_t *) ((char *) header +
139            MAPPING_HEADER_SIZE +
140            MAPPING_CLUSTER_SIZE * header->clusters +
141            MAPPING_PSEG_SIZE * header->psegs +
142            MAPPING_VSPACE_SIZE * header->vspaces);
143
144    // computes the base adresss for vobjs array,
145    vobj = (mapping_vobj_t *) ((char *) header +
146            MAPPING_HEADER_SIZE +
147            MAPPING_CLUSTER_SIZE * header->clusters +
148            MAPPING_PSEG_SIZE * header->psegs +
149            MAPPING_VSPACE_SIZE * header->vspaces +
150            MAPPING_VSEG_SIZE * header->vsegs);
151
152    // computes the base address for tasks array
153    task = (mapping_task_t *) ((char *) header +
154            MAPPING_HEADER_SIZE +
155            MAPPING_CLUSTER_SIZE * header->clusters +
156            MAPPING_PSEG_SIZE * header->psegs +
157            MAPPING_VSPACE_SIZE * header->vspaces +
158            MAPPING_VOBJ_SIZE * header->vobjs +
159            MAPPING_VSEG_SIZE * header->vsegs);
160
161    // computes the base address for procs array
162    proc = (mapping_proc_t *) ((char *) header +
163            MAPPING_HEADER_SIZE +
164            MAPPING_CLUSTER_SIZE * header->clusters +
165            MAPPING_PSEG_SIZE * header->psegs +
166            MAPPING_VSPACE_SIZE * header->vspaces +
167            MAPPING_VOBJ_SIZE * header->vobjs +
168            MAPPING_VSEG_SIZE * header->vsegs +
169            MAPPING_TASK_SIZE * header->tasks);
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->clusters +
175            MAPPING_PSEG_SIZE * header->psegs +
176            MAPPING_VSPACE_SIZE * header->vspaces +
177            MAPPING_VOBJ_SIZE * header->vobjs +
178            MAPPING_VSEG_SIZE * header->vsegs +
179            MAPPING_TASK_SIZE * header->tasks +
180            MAPPING_PROC_SIZE * header->procs);
181
182    // computes the base address for coprocs array
183    coproc = (mapping_coproc_t *) ((char *) header +
184            MAPPING_HEADER_SIZE +
185            MAPPING_CLUSTER_SIZE * header->clusters +
186            MAPPING_PSEG_SIZE * header->psegs +
187            MAPPING_VSPACE_SIZE * header->vspaces +
188            MAPPING_VOBJ_SIZE * header->vobjs +
189            MAPPING_VSEG_SIZE * header->vsegs +
190            MAPPING_TASK_SIZE * header->tasks +
191            MAPPING_PROC_SIZE * header->procs +
192            MAPPING_IRQ_SIZE * header->irqs);
193
194    // computes the base address for cp_ports array
195    cp_port = (mapping_cp_port_t *) ((char *) header +
196            MAPPING_HEADER_SIZE +
197            MAPPING_CLUSTER_SIZE * header->clusters +
198            MAPPING_PSEG_SIZE * header->psegs +
199            MAPPING_VSPACE_SIZE * header->vspaces +
200            MAPPING_VOBJ_SIZE * header->vobjs +
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            MAPPING_COPROC_SIZE * header->coprocs);
206
207    // computes the base address for periphs array
208    periph = (mapping_periph_t *) ((char *) header +
209            MAPPING_HEADER_SIZE +
210            MAPPING_CLUSTER_SIZE * header->clusters +
211            MAPPING_PSEG_SIZE * header->psegs +
212            MAPPING_VSPACE_SIZE * header->vspaces +
213            MAPPING_VOBJ_SIZE * header->vobjs +
214            MAPPING_VSEG_SIZE * header->vsegs +
215            MAPPING_TASK_SIZE * header->tasks +
216            MAPPING_PROC_SIZE * header->procs +
217            MAPPING_IRQ_SIZE * header->irqs +
218            MAPPING_COPROC_SIZE * header->coprocs +
219            MAPPING_CP_PORT_SIZE * header->cp_ports);
220
221    ///////////////////////// header /////////////////////////////////////////////
222
223    fprintf(fpout, "<?xml version = \"1.0\"?>\n\n");
224
225    fprintf(fpout, "<mapping_info signature = \"0x%x\" ", header->signature);
226    fprintf(fpout, " name = \"%s\" ", header->name);
227    fprintf(fpout, " cluster_x = \"%d\" ", header->cluster_x);
228    fprintf(fpout, " cluster_y = \"%d\" ", header->cluster_y);
229    fprintf(fpout, " vspaces = \"%d\" >\n\n", header->vspaces);
230
231    ///////////////////// clusters ///////////////////////////////////////////////
232
233    fprintf( fpout, "    <clusterset>\n");
234    for (cluster_id = 0; cluster_id < header->clusters; cluster_id++) {
235        fprintf(fpout, "        <cluster index  = \"%d\" >\n", cluster_id);
236        for (pseg_id = cluster[cluster_id].pseg_offset;
237                pseg_id < cluster[cluster_id].pseg_offset + cluster[cluster_id].psegs;
238                pseg_id++) {
239            fprintf(fpout, "            <pseg name = \"%s\" ", pseg[pseg_id].name);
240            fprintf(fpout, " type = \"%s\" ", pseg_type[pseg[pseg_id].type]);
241            fprintf(fpout, " base = \"0x%llx\" ", pseg[pseg_id].base);
242            fprintf(fpout, " length = \"0x%llx\" />\n",   pseg[pseg_id].length);
243        }
244
245        ///////////////////// processors /////////////////////////////////////////////
246
247        unsigned int proc_index = 0;
248        for (proc_id = cluster[cluster_id].proc_offset;
249                proc_id < cluster[cluster_id].proc_offset + cluster[cluster_id].procs;
250                proc_id++) {
251            fprintf(fpout, "            <proc index = \"%d\" >\n", proc_index);
252            for (irq_id = proc[proc_id].irq_offset; 
253                    irq_id < proc[proc_id].irq_offset + proc[proc_id].irqs;
254                    irq_id++) {
255                fprintf(fpout, "                <irq type = \"%s\" ", irq_type[irq[irq_id].type]);
256                fprintf(fpout, " icuid = \"0x%x\" ", irq[irq_id].icuid);
257                fprintf(fpout, " isr = \"%s\" ", isr_type[irq[irq_id].isr]);
258                fprintf(fpout, " channel = \"0x%x\" />\n", irq[irq_id].channel);
259            }
260            fprintf(fpout, "            </proc>\n" );
261        }
262
263
264        ///////////////////// coprocessors ///////////////////////////////////////////
265
266        for (coproc_id = cluster[cluster_id].coproc_offset;
267                coproc_id < cluster[cluster_id].coproc_offset + cluster[cluster_id].coprocs;
268                coproc_id++) {
269            fprintf(fpout, "            <coproc name = \"%s\" ", coproc[coproc_id].name);
270            fprintf(fpout, " psegname = \"%s\" >\n", pseg[coproc[coproc_id].psegid].name);
271            for (port_id = coproc[coproc_id].port_offset;
272                    port_id < coproc[coproc_id].port_offset + coproc[coproc_id].ports;
273                    port_id++) {
274                unsigned int vobj_id = cp_port[port_id].mwmr_vobjid + vspace[cp_port[port_id].vspaceid].vobj_offset; 
275                fprintf(fpout, "             <port direction = \"%s\" ",  port_direction[cp_port[port_id].direction]);
276                fprintf(fpout, " vspacename = \"%s\" ", vspace[cp_port[port_id].vspaceid].name);
277                fprintf(fpout, " vobjname = \"%s\" />\n",  vobj[vobj_id].name);
278            }
279            fprintf(fpout, "            </coproc>\n" );
280        }
281
282        ///////////////////// periphs  ///////////////////////////////////////////////
283
284        for (periph_id = cluster[cluster_id].periph_offset;
285                periph_id < cluster[cluster_id].periph_offset + cluster[cluster_id].periphs;
286                periph_id++) {
287            fprintf(fpout, "            <periph type = \"%s\" ", periph_type[periph[periph_id].type]);
288            fprintf(fpout, " psegname = \"%s\" ", pseg[periph[periph_id].psegid].name);
289            fprintf(fpout, " channels = \"%d\" />\n",  periph[periph_id].channels);
290        }
291        fprintf(fpout, "        </cluster>\n" );
292    }
293    fprintf(fpout, "    </clusterset>\n\n" );
294
295    /////////////////// globals /////////////////////////////////////////////////
296
297    fprintf(fpout, "    <globalset>\n" );
298    for (vseg_id = 0; vseg_id < header->globals; vseg_id++) {
299        unsigned int pseg_id = vseg[vseg_id].psegid; 
300
301        fprintf(fpout, "        <vseg name = \"%s\" ", vseg[vseg_id].name);
302        fprintf(fpout, "vbase = \"0x%x\" ", vseg[vseg_id].vbase);
303        fprintf(fpout, "mode  = \"%s\" ", mode_str[vseg[vseg_id].mode]);
304        fprintf(fpout, "clusterid = \"%d\" ", pseg[pseg_id].cluster);
305        fprintf(fpout, "psegname = \"%s\" ", pseg[pseg_id].name);
306        fprintf(fpout, "ident = \"%d\" >\n", vseg[vseg_id].ident);
307        for (vobj_id = vseg[vseg_id].vobj_offset;
308                vobj_id < (vseg[vseg_id].vobj_offset + vseg[vseg_id].vobjs); 
309                vobj_id++) {
310            fprintf(fpout, "            <vobj name = \"%s\" ", vobj[vobj_id].name);
311            fprintf(fpout, "type = \"%s\" ", vobj_type[vobj[vobj_id].type]);
312            fprintf(fpout, "length = \"0x%x\" ", vobj[vobj_id].length);
313            fprintf(fpout, "align = \"%d\" ", vobj[vobj_id].align);
314            fprintf(fpout, "init = \"%d\" ", vobj[vobj_id].init);
315            fprintf(fpout, "binpath = \"%s\" />\n", vobj[vobj_id].binpath);
316        }
317        fprintf(fpout, "        </vseg>\n");
318    }
319    fprintf(fpout, "    </globalset>\n" );
320
321    //////////////////// vspaces ////////////////////////////////////////////////
322
323    fprintf( fpout, "\n    <vspaceset>\n\n" );
324    for (vspace_id = 0; vspace_id < header->vspaces; vspace_id++) {
325        unsigned int func_id = vspace[vspace_id].vobj_offset + vspace[vspace_id].start_offset; 
326        fprintf(fpout, "        <vspace name = \"%s\" ", vspace[vspace_id].name); 
327        fprintf(fpout, " startname = \"%s\" >\n", vobj[func_id].name); 
328
329        for (vseg_id = vspace[vspace_id].vseg_offset;
330                vseg_id < (vspace[vspace_id].vseg_offset + vspace[vspace_id].vsegs);
331                vseg_id++) {
332            unsigned int pseg_id = vseg[vseg_id].psegid; 
333
334            fprintf(fpout, "            <vseg name = \"%s\" ", vseg[vseg_id].name);
335            fprintf(fpout, "vbase = \"0x%x\" ", vseg[vseg_id].vbase);
336            fprintf(fpout, "mode  = \"%s\" ", mode_str[vseg[vseg_id].mode]);
337            fprintf(fpout, "clusterid = \"%d\" ", pseg[pseg_id].cluster);
338            fprintf(fpout, "psegname = \"%s\" ", pseg[pseg_id].name);
339            fprintf(fpout, "ident = \"%d\" >\n", vseg[vseg_id].ident);
340
341            for (vobj_id = vseg[vseg_id].vobj_offset;
342                    vobj_id < (vseg[vseg_id].vobj_offset + vseg[vseg_id].vobjs);
343                    vobj_id++) {
344                fprintf(fpout, "             <vobj name = \"%s\" ", vobj[vobj_id].name);
345                fprintf(fpout, "type = \"%s\" ", vobj_type[vobj[vobj_id].type]);
346                fprintf(fpout, "length = \"0x%x\" ", vobj[vobj_id].length);
347                fprintf(fpout, "align = \"%d\" ", vobj[vobj_id].align);
348                fprintf(fpout, "init = \"%d\" ", vobj[vobj_id].init);
349                fprintf(fpout, "binpath = \"%s\" />\n", vobj[vobj_id].binpath);
350            }
351            fprintf(fpout, "            </vseg>\n\n");
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            unsigned int stack_vobj_id = task[task_id].stack_vobjid + vspace[vspace_id].vobj_offset; 
357            unsigned int heap_vobj_id = task[task_id].heap_vobjid + vspace[vspace_id].vobj_offset; 
358
359            fprintf(fpout, "            <task name = \"%s\" ", task[task_id].name);
360            fprintf(fpout, "clusterid = \"%d\" ", task[task_id].clusterid);
361            fprintf(fpout, "proclocid = \"%d\" ", task[task_id].proclocid);
362            fprintf(fpout, "stackname = \"%s\" ", vobj[stack_vobj_id].name);
363            if (heap_vobj_id != -1) {
364                fprintf(fpout, "heapname = \"%s\" ", vobj[heap_vobj_id].name);
365            }
366            fprintf(fpout, "startid = \"%d\" ", task[task_id].startid);
367            fprintf(fpout, "usetty = \"%d\" ", task[task_id].use_tty);
368            fprintf(fpout, "usenic = \"%d\" ", task[task_id].use_nic);
369            fprintf(fpout, "usedma = \"%d\" ", task[task_id].use_dma);
370            fprintf(fpout, "usecma = \"%d\" ", task[task_id].use_cma);
371            fprintf(fpout, "usetim = \"%d\" ", task[task_id].use_tim);
372            fprintf(fpout, "useioc = \"%d\" />\n", task[task_id].use_ioc);
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    if (argc < 2) {
384        printf("Usage: bin2xml <input_file_path> <output_file_path>\n");
385        return 1;
386    }
387
388    unsigned int bin[0x10000]; // 64 K int = 256 Kbytes
389
390    int fdin = open(argv[1], O_RDONLY);
391    if (fdin < 0) {
392        perror("open");
393        exit(1);
394    }
395
396    FILE * fpout = fopen( argv[2], "w");
397    if (fpout == NULL) {
398        perror("open");
399        exit(1);
400    }
401
402    unsigned int length = read(fdin, bin, 0x40000);
403
404    if (length <= 0) {
405        perror("read");
406        exit(1);
407    }
408
409    if (bin[0] == IN_MAPPING_SIGNATURE) {
410        buildXml((mapping_header_t *) bin, fpout);
411    } 
412    else {
413        printf("[ERROR] Wrong file format\n");
414        exit(1);
415    }
416    return 0;
417} // end main()
418
419
420
421// Local Variables:
422// tab-width: 4
423// c-basic-offset: 4
424// c-file-offsets:((innamespace . 0)(inline-open . 0))
425// indent-tabs-mode: nil
426// End:
427// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
428
Note: See TracBrowser for help on using the repository browser.