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

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

This is a major release, including a deep restructuration of code.
The main evolutions are

  • use of the Tsar preloader to load the GIET boot-loader from disk
  • introduction of a FAT32 file system library,
  • use of this fat32 library by the boot-loader to load the map.bin data structure, and the various .elf files
  • reorganisation of drivers (one file per peripheral).
  • introduction of drivers for new peripherals: vci_chbuf_dma and vci_multi_ahci.
  • introduction of a new physical memory allocator in the boot code.

This release has been tested on the tsar_generic_iob architecture,
for the two following mappings: 4c_1p_iob_four.xml and 4c_1p_iob_sort.xml

  • Property svn:executable set to *
File size: 16.4 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->clusters);
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->clusters +
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->clusters +
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->clusters +
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->clusters +
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->clusters +
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->clusters +
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->clusters +
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->clusters +
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->clusters +
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\" ", header->signature);
232    fprintf(fpout, " name = \"%s\" ", header->name);
233    fprintf(fpout, " cluster_x = \"%d\" ", header->cluster_x);
234    fprintf(fpout, " cluster_y = \"%d\" ", header->cluster_y);
235    fprintf(fpout, " vspaces = \"%d\" >\n\n", header->vspaces);
236
237    ///////////////////// clusters ///////////////////////////////////////////////
238
239    fprintf( fpout, "    <clusterset>\n");
240    for (cluster_id = 0; cluster_id < header->clusters; cluster_id++) 
241    {
242        fprintf(fpout, "        <cluster index  = \"%d\" >\n", cluster_id);
243        for (pseg_id = cluster[cluster_id].pseg_offset;
244             pseg_id < cluster[cluster_id].pseg_offset + cluster[cluster_id].psegs;
245             pseg_id++) 
246        {
247            fprintf(fpout, "            <pseg name = \"%s\" ", pseg[pseg_id].name);
248            fprintf(fpout, " type = \"%s\" ", pseg_type[pseg[pseg_id].type]);
249            fprintf(fpout, " base = \"0x%llx\" ", pseg[pseg_id].base);
250            fprintf(fpout, " length = \"0x%llx\" />\n",   pseg[pseg_id].length);
251        }
252
253        ///////////////////// processors /////////////////////////////////////////////
254
255        unsigned int proc_index = 0;
256        for (proc_id = cluster[cluster_id].proc_offset;
257             proc_id < cluster[cluster_id].proc_offset + cluster[cluster_id].procs;
258             proc_id++) 
259        {
260            fprintf(fpout, "            <proc index = \"%d\" >\n", proc_index);
261            for (irq_id = proc[proc_id].irq_offset; 
262                 irq_id < proc[proc_id].irq_offset + proc[proc_id].irqs;
263                 irq_id++) 
264            {
265                fprintf(fpout, "                <irq type = \"%s\" ", irq_type[irq[irq_id].type]);
266                fprintf(fpout, " icuid = \"0x%x\" ", irq[irq_id].icuid);
267                fprintf(fpout, " isr = \"%s\" ", isr_type[irq[irq_id].isr]);
268                fprintf(fpout, " channel = \"0x%x\" />\n", irq[irq_id].channel);
269            }
270            fprintf(fpout, "            </proc>\n" );
271        }
272
273
274        ///////////////////// coprocessors ///////////////////////////////////////////
275
276        for (coproc_id = cluster[cluster_id].coproc_offset;
277             coproc_id < cluster[cluster_id].coproc_offset + cluster[cluster_id].coprocs;
278             coproc_id++) 
279        {
280            fprintf(fpout, "            <coproc name = \"%s\" ", coproc[coproc_id].name);
281            fprintf(fpout, " psegname = \"%s\" >\n", pseg[coproc[coproc_id].psegid].name);
282            for (port_id = coproc[coproc_id].port_offset;
283                 port_id < coproc[coproc_id].port_offset + coproc[coproc_id].ports;
284                 port_id++) 
285            {
286                unsigned int vobj_id = cp_port[port_id].mwmr_vobjid + vspace[cp_port[port_id].vspaceid].vobj_offset; 
287                fprintf(fpout, "             <port direction = \"%s\" ",  port_direction[cp_port[port_id].direction]);
288                fprintf(fpout, " vspacename = \"%s\" ", vspace[cp_port[port_id].vspaceid].name);
289                fprintf(fpout, " vobjname = \"%s\" />\n",  vobj[vobj_id].name);
290            }
291            fprintf(fpout, "            </coproc>\n" );
292        }
293
294        ///////////////////// periphs  ///////////////////////////////////////////////
295
296        for (periph_id = cluster[cluster_id].periph_offset;
297             periph_id < cluster[cluster_id].periph_offset + cluster[cluster_id].periphs;
298             periph_id++) 
299        {
300            fprintf(fpout, "            <periph type = \"%s\" ", periph_type[periph[periph_id].type]);
301            fprintf(fpout, " psegname = \"%s\" ", pseg[periph[periph_id].psegid].name);
302            fprintf(fpout, " channels = \"%d\" />\n",  periph[periph_id].channels);
303        }
304        fprintf(fpout, "        </cluster>\n" );
305    }
306    fprintf(fpout, "    </clusterset>\n\n" );
307
308    /////////////////// globals /////////////////////////////////////////////////
309
310    fprintf(fpout, "    <globalset>\n" );
311    for (vseg_id = 0; vseg_id < header->globals; vseg_id++) 
312    {
313        unsigned int pseg_id = vseg[vseg_id].psegid; 
314
315        fprintf(fpout, "        <vseg name = \"%s\" ", vseg[vseg_id].name);
316        fprintf(fpout, "vbase = \"0x%x\" ", vseg[vseg_id].vbase);
317        fprintf(fpout, "mode  = \"%s\" ", mode_str[vseg[vseg_id].mode]);
318        fprintf(fpout, "clusterid = \"%d\" ", pseg[pseg_id].cluster);
319        fprintf(fpout, "psegname = \"%s\" ", pseg[pseg_id].name);
320        fprintf(fpout, "ident = \"%d\" >\n", vseg[vseg_id].ident);
321        for (vobj_id = vseg[vseg_id].vobj_offset;
322             vobj_id < (vseg[vseg_id].vobj_offset + vseg[vseg_id].vobjs); 
323             vobj_id++) 
324        {
325            fprintf(fpout, "            <vobj name = \"%s\" ", vobj[vobj_id].name);
326            fprintf(fpout, "type = \"%s\" ", vobj_type[vobj[vobj_id].type]);
327            fprintf(fpout, "length = \"0x%x\" ", vobj[vobj_id].length);
328            fprintf(fpout, "align = \"%d\" ", vobj[vobj_id].align);
329            fprintf(fpout, "init = \"%d\" ", vobj[vobj_id].init);
330            fprintf(fpout, "binpath = \"%s\" />\n", vobj[vobj_id].binpath);
331        }
332        fprintf(fpout, "        </vseg>\n");
333    }
334    fprintf(fpout, "    </globalset>\n" );
335
336    //////////////////// vspaces ////////////////////////////////////////////////
337
338    fprintf( fpout, "\n    <vspaceset>\n\n" );
339    for (vspace_id = 0; vspace_id < header->vspaces; vspace_id++) 
340    {
341        unsigned int func_id = vspace[vspace_id].vobj_offset + vspace[vspace_id].start_offset; 
342        fprintf(fpout, "        <vspace name = \"%s\" ", vspace[vspace_id].name); 
343        fprintf(fpout, " startname = \"%s\" >\n", vobj[func_id].name); 
344
345        for (vseg_id = vspace[vspace_id].vseg_offset;
346             vseg_id < (vspace[vspace_id].vseg_offset + vspace[vspace_id].vsegs);
347             vseg_id++) 
348        {
349            unsigned int pseg_id = vseg[vseg_id].psegid; 
350
351            fprintf(fpout, "            <vseg name = \"%s\" ", vseg[vseg_id].name);
352            fprintf(fpout, "vbase = \"0x%x\" ", vseg[vseg_id].vbase);
353            fprintf(fpout, "mode  = \"%s\" ", mode_str[vseg[vseg_id].mode]);
354            fprintf(fpout, "clusterid = \"%d\" ", pseg[pseg_id].cluster);
355            fprintf(fpout, "psegname = \"%s\" ", pseg[pseg_id].name);
356            fprintf(fpout, "ident = \"%d\" >\n", vseg[vseg_id].ident);
357
358            for (vobj_id = vseg[vseg_id].vobj_offset;
359                 vobj_id < (vseg[vseg_id].vobj_offset + vseg[vseg_id].vobjs);
360                 vobj_id++) 
361            {
362                fprintf(fpout, "             <vobj name = \"%s\" ", vobj[vobj_id].name);
363                fprintf(fpout, "type = \"%s\" ", vobj_type[vobj[vobj_id].type]);
364                fprintf(fpout, "length = \"0x%x\" ", vobj[vobj_id].length);
365                fprintf(fpout, "align = \"%d\" ", vobj[vobj_id].align);
366                fprintf(fpout, "init = \"%d\" ", vobj[vobj_id].init);
367                fprintf(fpout, "binpath = \"%s\" />\n", vobj[vobj_id].binpath);
368            }
369            fprintf(fpout, "            </vseg>\n\n");
370        }
371        for (task_id = vspace[vspace_id].task_offset;
372             task_id < (vspace[vspace_id].task_offset + vspace[vspace_id].tasks);
373             task_id++) 
374        {
375            unsigned int stack_vobj_id = task[task_id].stack_vobjid + vspace[vspace_id].vobj_offset; 
376            unsigned int heap_vobj_id = task[task_id].heap_vobjid + vspace[vspace_id].vobj_offset; 
377
378            fprintf(fpout, "            <task name = \"%s\" ", task[task_id].name);
379            fprintf(fpout, "clusterid = \"%d\" ", task[task_id].clusterid);
380            fprintf(fpout, "proclocid = \"%d\" ", task[task_id].proclocid);
381            fprintf(fpout, "stackname = \"%s\" ", vobj[stack_vobj_id].name);
382            if (heap_vobj_id != -1) 
383            {
384                fprintf(fpout, "heapname = \"%s\" ", vobj[heap_vobj_id].name);
385            }
386            fprintf(fpout, "startid = \"%d\" ", task[task_id].startid);
387            fprintf(fpout, "usetty = \"%d\" ", task[task_id].use_tty);
388            fprintf(fpout, "usenic = \"%d\" ", task[task_id].use_nic);
389            fprintf(fpout, "usecma = \"%d\" ", task[task_id].use_cma);
390            fprintf(fpout, "usetim = \"%d\" ", task[task_id].use_tim);
391            fprintf(fpout, "usehba = \"%d\" />\n", task[task_id].use_hba);
392        }
393        fprintf(fpout, "        </vspace>\n\n");
394    }
395    fprintf(fpout, "    </vspaceset>\n");
396    fprintf(fpout, "</mapping_info>\n");
397} // end buildXml()
398
399
400/////////////////////////////////////
401int main(int argc, char * argv[]) {
402    if (argc < 2) {
403        printf("Usage: bin2xml <input_file_path> <output_file_path>\n");
404        return 1;
405    }
406
407    unsigned int bin[0x10000]; // 64 K int = 256 Kbytes
408
409    int fdin = open(argv[1], O_RDONLY);
410    if (fdin < 0) {
411        perror("open");
412        exit(1);
413    }
414
415    FILE * fpout = fopen( argv[2], "w");
416    if (fpout == NULL) {
417        perror("open");
418        exit(1);
419    }
420
421    unsigned int length = read(fdin, bin, 0x40000);
422
423    if (length <= 0) {
424        perror("read");
425        exit(1);
426    }
427
428    if (bin[0] == IN_MAPPING_SIGNATURE) {
429        buildXml((mapping_header_t *) bin, fpout);
430    } 
431    else {
432        printf("[ERROR] Wrong file format\n");
433        exit(1);
434    }
435    return 0;
436} // end main()
437
438
439
440// Local Variables:
441// tab-width: 4
442// c-basic-offset: 4
443// c-file-offsets:((innamespace . 0)(inline-open . 0))
444// indent-tabs-mode: nil
445// End:
446// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
447
Note: See TracBrowser for help on using the repository browser.