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