1 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
2 | // File : xml_parser.c |
---|
3 | // Date : 14/04/2012 |
---|
4 | // Author : alain greiner |
---|
5 | // Copyright (c) UPMC-LIP6 |
---|
6 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
7 | // This program translate a "map.xml" source file to a binary file "map.bin" that |
---|
8 | // can be directly loaded in the boot ROM and used by the GIET-VM operating system. |
---|
9 | // |
---|
10 | // This map.xml file contains : |
---|
11 | // 1) the multi-cluster/multi-processors hardware architecture description |
---|
12 | // 2) the various multi-threaded software applications |
---|
13 | // 3) the mapping directives bor both the tasks and the virtual segments. |
---|
14 | // The corresponding C structures are defined in the "mapping_info.h" file. |
---|
15 | // |
---|
16 | // This program also generates the "hard_config.h" and the "giet_vsegs.ld" files, |
---|
17 | // required to compile the GIET-VM code. |
---|
18 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
19 | |
---|
20 | #include <stdlib.h> |
---|
21 | #include <fcntl.h> |
---|
22 | #include <sys/types.h> |
---|
23 | #include <sys/stat.h> |
---|
24 | #include <unistd.h> |
---|
25 | #include <stdio.h> |
---|
26 | #include <string.h> |
---|
27 | #include <assert.h> |
---|
28 | #include <libxml/xmlreader.h> |
---|
29 | #include <mapping_info.h> |
---|
30 | #include <irq_handler.h> |
---|
31 | |
---|
32 | #define MAX_CLUSTERS 1024 |
---|
33 | #define MAX_PSEGS 4096 |
---|
34 | #define MAX_VSPACES 1024 |
---|
35 | #define MAX_TASKS 4096 |
---|
36 | #define MAX_MWMRS 4096 |
---|
37 | #define MAX_VSEGS 4096 |
---|
38 | #define MAX_VOBJS 8192 |
---|
39 | #define MAX_PROCS 1024 |
---|
40 | #define MAX_IRQS 8192 |
---|
41 | #define MAX_COPROCS 4096 |
---|
42 | #define MAX_CP_PORTS 8192 |
---|
43 | #define MAX_PERIPHS 8192 |
---|
44 | |
---|
45 | #define XML_PARSER_DEBUG 0 |
---|
46 | |
---|
47 | /////////////////////////////////////////////////////////////////////////////////// |
---|
48 | // global variables used to store and index the data structures |
---|
49 | /////////////////////////////////////////////////////////////////////////////////// |
---|
50 | |
---|
51 | mapping_header_t * header; |
---|
52 | mapping_cluster_t * cluster[MAX_CLUSTERS]; // cluster array |
---|
53 | mapping_pseg_t * pseg[MAX_PSEGS]; // pseg array |
---|
54 | mapping_vspace_t * vspace[MAX_VSPACES]; // vspace array |
---|
55 | mapping_vseg_t * vseg[MAX_VSEGS]; // vseg array |
---|
56 | mapping_vobj_t * vobj[MAX_VOBJS]; // vobj array |
---|
57 | mapping_task_t * task[MAX_TASKS]; // task array |
---|
58 | mapping_proc_t * proc[MAX_PROCS]; // proc array |
---|
59 | mapping_irq_t * irq[MAX_IRQS]; // irq array |
---|
60 | mapping_coproc_t * coproc[MAX_COPROCS]; // coproc array |
---|
61 | mapping_cp_port_t * cp_port[MAX_CP_PORTS]; // coproc port array |
---|
62 | mapping_periph_t * periph[MAX_PERIPHS]; // peripheral array |
---|
63 | |
---|
64 | // Index for the various arrays |
---|
65 | |
---|
66 | unsigned int cluster_index = 0; |
---|
67 | unsigned int vspace_index = 0; |
---|
68 | unsigned int global_index = 0; |
---|
69 | unsigned int pseg_index = 0; |
---|
70 | |
---|
71 | unsigned int proc_index = 0; |
---|
72 | unsigned int proc_loc_index = 0; |
---|
73 | |
---|
74 | unsigned int irq_index = 0; |
---|
75 | unsigned int irq_loc_index = 0; |
---|
76 | |
---|
77 | unsigned int coproc_index = 0; |
---|
78 | unsigned int coproc_loc_index = 0; |
---|
79 | |
---|
80 | unsigned int cp_port_index = 0; |
---|
81 | unsigned int cp_port_loc_index = 0; |
---|
82 | |
---|
83 | unsigned int periph_index = 0; |
---|
84 | unsigned int periph_loc_index = 0; |
---|
85 | |
---|
86 | unsigned int vseg_index = 0; |
---|
87 | unsigned int vseg_loc_index = 0; |
---|
88 | |
---|
89 | unsigned int task_index = 0; |
---|
90 | unsigned int task_loc_index = 0; |
---|
91 | |
---|
92 | unsigned int vobj_index = 0; |
---|
93 | unsigned int vobj_loc_index = 0; |
---|
94 | unsigned int vobj_count = 0; |
---|
95 | |
---|
96 | |
---|
97 | ////////////////////////////// |
---|
98 | // for replicated peripheral |
---|
99 | ////////////////////////////// |
---|
100 | char found_timer = 0; |
---|
101 | char found_icu = 0; |
---|
102 | char found_dma = 0; |
---|
103 | char found_mmc = 0; |
---|
104 | |
---|
105 | |
---|
106 | //////////////////////////////////////////////////////////////////// |
---|
107 | // These variables are used to generate the hard_config.h file |
---|
108 | //////////////////////////////////////////////////////////////////// |
---|
109 | |
---|
110 | unsigned int cluster_y = 0; // number of clusters in a column |
---|
111 | unsigned int cluster_x = 0; // number of clusters in a row |
---|
112 | unsigned int nb_proc_max = 0; // max number of processors per cluster |
---|
113 | unsigned int nb_tasks_max = 0; // max number of tasks (for all vspaces) |
---|
114 | |
---|
115 | unsigned int tim_channels = 0; // max number of user timers per cluster |
---|
116 | unsigned int dma_channels = 0; // max number of DMA channels per cluster |
---|
117 | |
---|
118 | unsigned int tty_channels = 0; // total number of terminals in first TTY |
---|
119 | unsigned int ioc_channels = 0; // total number of channels in first IOC |
---|
120 | unsigned int nic_channels = 0; // total number of channels in first NIC |
---|
121 | unsigned int cma_channels = 0; // total number of channels in first CMA |
---|
122 | |
---|
123 | unsigned int use_iob = 0; // using IOB component |
---|
124 | unsigned int use_xicu = 0; // using XICU (not ICU) |
---|
125 | |
---|
126 | |
---|
127 | //////////////////////////////////////////////////////////////// |
---|
128 | // These variables are used to generate the giet_vseg.ld file |
---|
129 | //////////////////////////////////////////////////////////////// |
---|
130 | |
---|
131 | unsigned int periph_vbase_array[PERIPH_TYPE_MAX_VALUE] |
---|
132 | = { [0 ... (PERIPH_TYPE_MAX_VALUE - 1)] = 0xFFFFFFFF }; |
---|
133 | |
---|
134 | ////////////////////////////////////////////////////////////////////// |
---|
135 | // This arrray is useful to build a temporary list of vobj references. |
---|
136 | // The struct vobj_ref_s is formed by a vspace_name and a vobj_name. |
---|
137 | // This array is used to set the attribute vobj_id of a cp_port |
---|
138 | // once all the vspace have been parsed. |
---|
139 | ///////////////////////////////////////////////////////////////////// |
---|
140 | typedef struct vobj_ref_s |
---|
141 | { |
---|
142 | char vspace_name[32]; |
---|
143 | char vobj_name[32]; |
---|
144 | } vobj_ref_t; |
---|
145 | |
---|
146 | vobj_ref_t * cp_port_vobj_ref[MAX_CP_PORTS]; |
---|
147 | |
---|
148 | |
---|
149 | ////////////////////////////////////////////////// |
---|
150 | unsigned int getIntValue( xmlTextReaderPtr reader, |
---|
151 | const char * attributeName, |
---|
152 | unsigned int * ok) |
---|
153 | { |
---|
154 | unsigned int value = 0; |
---|
155 | unsigned int i; |
---|
156 | char c; |
---|
157 | |
---|
158 | char * string = (char *) xmlTextReaderGetAttribute(reader, |
---|
159 | (const xmlChar *) attributeName); |
---|
160 | |
---|
161 | if (string == NULL) |
---|
162 | { |
---|
163 | // missing argument |
---|
164 | *ok = 0; |
---|
165 | return 0; |
---|
166 | } |
---|
167 | else |
---|
168 | { |
---|
169 | if ((string[0] == '0') && ((string[1] == 'x') || (string[1] == 'X'))) |
---|
170 | { |
---|
171 | // Hexa |
---|
172 | for (i = 2 ; (string[i] != 0) && (i < 10) ; i++) |
---|
173 | { |
---|
174 | c = string[i]; |
---|
175 | if ((c >= '0') && (c <= '9')) { value = (value << 4) + string[i] - 48; } |
---|
176 | else if ((c >= 'a') && (c <= 'f')) { value = (value << 4) + string[i] - 87; } |
---|
177 | else if ((c >= 'A') && (c <= 'F')) { value = (value << 4) + string[i] - 55; } |
---|
178 | else |
---|
179 | { |
---|
180 | *ok = 0; |
---|
181 | return 0; |
---|
182 | } |
---|
183 | } |
---|
184 | } |
---|
185 | else |
---|
186 | { |
---|
187 | // Decimal |
---|
188 | for (i = 0; (string[i] != 0) && (i < 9); i++) |
---|
189 | { |
---|
190 | c = string[i]; |
---|
191 | if ((c >= '0') && (c <= '9')) value = (value * 10) + string[i] - 48; |
---|
192 | else |
---|
193 | { |
---|
194 | *ok = 0; |
---|
195 | return 0; |
---|
196 | } |
---|
197 | } |
---|
198 | } |
---|
199 | *ok = 1; |
---|
200 | return value; |
---|
201 | } |
---|
202 | } // end getIntValue() |
---|
203 | |
---|
204 | //////////////////////////////////////////////// |
---|
205 | paddr_t getPaddrValue( xmlTextReaderPtr reader, |
---|
206 | const char * attributeName, |
---|
207 | unsigned int * ok) |
---|
208 | { |
---|
209 | paddr_t value = 0; |
---|
210 | unsigned int i; |
---|
211 | char c; |
---|
212 | |
---|
213 | char * string = (char *) xmlTextReaderGetAttribute(reader, |
---|
214 | (const xmlChar *) attributeName); |
---|
215 | |
---|
216 | if (string == NULL) |
---|
217 | { |
---|
218 | // missing argument |
---|
219 | *ok = 0; |
---|
220 | return 0; |
---|
221 | } |
---|
222 | else |
---|
223 | { |
---|
224 | if ((string[0] == '0') && ((string[1] == 'x') || (string[1] == 'X'))) |
---|
225 | { |
---|
226 | // Hexa |
---|
227 | for (i = 2 ; (string[i] != 0) && (i < 18) ; i++) |
---|
228 | { |
---|
229 | c = string[i]; |
---|
230 | if ((c >= '0') && (c <= '9')) { value = (value << 4) + string[i] - 48; } |
---|
231 | else if ((c >= 'a') && (c <= 'f')) { value = (value << 4) + string[i] - 87; } |
---|
232 | else if ((c >= 'A') && (c <= 'F')) { value = (value << 4) + string[i] - 55; } |
---|
233 | else |
---|
234 | { |
---|
235 | *ok = 0; |
---|
236 | return 0; |
---|
237 | } |
---|
238 | } |
---|
239 | } |
---|
240 | else |
---|
241 | { |
---|
242 | // Decimal not supported for paddr_t |
---|
243 | *ok = 0; |
---|
244 | return 0; |
---|
245 | } |
---|
246 | *ok = 1; |
---|
247 | return value; |
---|
248 | } |
---|
249 | } // end getPaddrValue() |
---|
250 | |
---|
251 | //////////////////////////////////////////////// |
---|
252 | char * getStringValue( xmlTextReaderPtr reader, |
---|
253 | const char * attributeName, |
---|
254 | unsigned int * ok ) |
---|
255 | { |
---|
256 | char * string = (char *) xmlTextReaderGetAttribute(reader, |
---|
257 | (const xmlChar *) attributeName); |
---|
258 | |
---|
259 | |
---|
260 | if (string == NULL) |
---|
261 | { |
---|
262 | // missing argument |
---|
263 | *ok = 0; |
---|
264 | return NULL; |
---|
265 | } |
---|
266 | else |
---|
267 | { |
---|
268 | //we read only string smaller than 32 byte |
---|
269 | if (strlen(string) > 32) |
---|
270 | { |
---|
271 | printf("[XML ERROR] all strings must be less than 32 bytes\n"); |
---|
272 | exit(1); |
---|
273 | } |
---|
274 | |
---|
275 | *ok = 1; |
---|
276 | return string; |
---|
277 | } |
---|
278 | } // end getStringValue() |
---|
279 | |
---|
280 | /////////////////////////////////////////////////////// |
---|
281 | void set_periph_vbase_array( unsigned int vseg_index ) |
---|
282 | { |
---|
283 | unsigned int vbase = vseg[vseg_index]->vbase; // peripheral vbase address |
---|
284 | unsigned int psegid = vseg[vseg_index]->psegid; // pseg global index |
---|
285 | unsigned int type; // peripheral type |
---|
286 | unsigned int periph_id; |
---|
287 | |
---|
288 | for ( periph_id = 0 ; periph_id < header->periphs ; periph_id++) |
---|
289 | { |
---|
290 | if( periph[periph_id]->psegid == psegid ) |
---|
291 | { |
---|
292 | type = periph[periph_id]->type; |
---|
293 | if ( periph_vbase_array[type] == 0xFFFFFFFF ) |
---|
294 | periph_vbase_array[type] = vbase; |
---|
295 | } |
---|
296 | } |
---|
297 | } // end set_periph_vbase_array() |
---|
298 | |
---|
299 | //////////////////////////////////////////////////////// |
---|
300 | int getPsegId(unsigned int cluster_id, char * pseg_name) |
---|
301 | { |
---|
302 | unsigned int pseg_id; |
---|
303 | unsigned int pseg_min = cluster[cluster_id]->pseg_offset; |
---|
304 | unsigned int pseg_max = pseg_min + cluster[cluster_id]->psegs; |
---|
305 | |
---|
306 | for (pseg_id = pseg_min; pseg_id < pseg_max; pseg_id++) |
---|
307 | { |
---|
308 | if (strcmp(pseg[pseg_id]->name, pseg_name) == 0) |
---|
309 | { |
---|
310 | return pseg_id; |
---|
311 | } |
---|
312 | } |
---|
313 | return -1; |
---|
314 | } |
---|
315 | |
---|
316 | /////////////////////////////////// |
---|
317 | int getVspaceId(char * vspace_name) |
---|
318 | { |
---|
319 | unsigned int vspace_id; |
---|
320 | |
---|
321 | for (vspace_id = 0; vspace_id < vspace_index; vspace_id++) |
---|
322 | { |
---|
323 | if (strcmp(vspace[vspace_id]->name, vspace_name) == 0) |
---|
324 | { |
---|
325 | return vspace_id; |
---|
326 | } |
---|
327 | } |
---|
328 | return -1; |
---|
329 | } |
---|
330 | |
---|
331 | /////////////////////////////////////////////////////////////////////////////////// |
---|
332 | int getVobjLocId(unsigned int vspace_id, char * vobj_name, unsigned int vspace_max) |
---|
333 | { |
---|
334 | unsigned int vobj_id; |
---|
335 | unsigned int vobj_min = vspace[vspace_id]->vobj_offset; |
---|
336 | unsigned int vobj_max = vobj_min + vspace_max; |
---|
337 | |
---|
338 | for (vobj_id = vobj_min; vobj_id < vobj_max; vobj_id++) { |
---|
339 | if (strcmp(vobj[vobj_id]->name, vobj_name) == 0) { |
---|
340 | return (vobj_id - vobj_min); |
---|
341 | } |
---|
342 | } |
---|
343 | return -1; |
---|
344 | } |
---|
345 | |
---|
346 | |
---|
347 | ///////////////////////////////////////// |
---|
348 | void taskNode(xmlTextReaderPtr reader) |
---|
349 | { |
---|
350 | unsigned int ok; |
---|
351 | unsigned int value; |
---|
352 | char * str; |
---|
353 | |
---|
354 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { return; } |
---|
355 | |
---|
356 | if (task_index >= MAX_TASKS) |
---|
357 | { |
---|
358 | printf("[XML ERROR] The number of tasks is larger than %d\n", MAX_TASKS); |
---|
359 | } |
---|
360 | |
---|
361 | #if XML_PARSER_DEBUG |
---|
362 | printf(" task %d\n", task_loc_index); |
---|
363 | #endif |
---|
364 | |
---|
365 | task[task_index] = (mapping_task_t *) malloc(sizeof(mapping_task_t)); |
---|
366 | |
---|
367 | ////////// get name attribute |
---|
368 | str = getStringValue(reader, "name", &ok); |
---|
369 | if (ok) |
---|
370 | { |
---|
371 | #if XML_PARSER_DEBUG |
---|
372 | printf(" name = %s\n", str); |
---|
373 | #endif |
---|
374 | strncpy( task[task_index]->name, str, 31 ); |
---|
375 | } |
---|
376 | else |
---|
377 | { |
---|
378 | printf("[XML ERROR] illegal or missing <name> attribute for task (%d,%d)\n", |
---|
379 | vspace_index, task_loc_index); |
---|
380 | exit(1); |
---|
381 | } |
---|
382 | |
---|
383 | ///////// get clusterid attribute |
---|
384 | value = getIntValue(reader, "clusterid", &ok); |
---|
385 | if (ok) |
---|
386 | { |
---|
387 | #if XML_PARSER_DEBUG |
---|
388 | printf(" clusterid = %x\n", value); |
---|
389 | #endif |
---|
390 | if (value >= header->clusters) |
---|
391 | { |
---|
392 | printf("[XML ERROR] <clusterid> too large for task (%d,%d)\n", |
---|
393 | vspace_index, task_loc_index); |
---|
394 | exit(1); |
---|
395 | } |
---|
396 | task[task_index]->clusterid = value; |
---|
397 | } |
---|
398 | else |
---|
399 | { |
---|
400 | printf("[XML ERROR] illegal or missing <clusterid> attribute for task (%d,%d)\n", |
---|
401 | vspace_index, task_loc_index); |
---|
402 | exit(1); |
---|
403 | } |
---|
404 | |
---|
405 | ////////// get proclocid attribute |
---|
406 | value = getIntValue(reader, "proclocid", &ok); |
---|
407 | if (ok) |
---|
408 | { |
---|
409 | #if XML_PARSER_DEBUG |
---|
410 | printf(" proclocid = %x\n", value); |
---|
411 | #endif |
---|
412 | if (value >= cluster[task[task_index]->clusterid]->procs) |
---|
413 | { |
---|
414 | printf("[XML ERROR] <proclocid> too large for task (%d,%d)\n", |
---|
415 | vspace_index, task_loc_index); |
---|
416 | exit(1); |
---|
417 | } |
---|
418 | task[task_index]->proclocid = value; |
---|
419 | } |
---|
420 | else |
---|
421 | { |
---|
422 | printf("[XML ERROR] illegal or missing <locprocid> attribute for task (%d,%d)\n", |
---|
423 | vspace_index, task_loc_index); |
---|
424 | exit(1); |
---|
425 | } |
---|
426 | |
---|
427 | ////////// get stackname attribute |
---|
428 | str = getStringValue(reader, "stackname" , &ok); |
---|
429 | if (ok) |
---|
430 | { |
---|
431 | int index = getVobjLocId(vspace_index, str , vobj_loc_index); |
---|
432 | if (index >= 0) |
---|
433 | { |
---|
434 | #if XML_PARSER_DEBUG |
---|
435 | printf(" stackname = %s\n", str); |
---|
436 | printf(" stackid = %d\n", index); |
---|
437 | #endif |
---|
438 | task[task_index]->stack_vobjid = index; |
---|
439 | } |
---|
440 | else |
---|
441 | { |
---|
442 | printf("[XML ERROR] illegal or missing <stackname> for task (%d,%d)\n", |
---|
443 | vspace_index, task_loc_index); |
---|
444 | exit(1); |
---|
445 | } |
---|
446 | } |
---|
447 | else |
---|
448 | { |
---|
449 | printf("[XML ERROR] illegal or missing <stackname> for task (%d,%d)\n", |
---|
450 | vspace_index, task_loc_index); |
---|
451 | exit(1); |
---|
452 | } |
---|
453 | |
---|
454 | ////////// get heap attribute |
---|
455 | str = getStringValue(reader, "heapname", &ok); |
---|
456 | if (ok) |
---|
457 | { |
---|
458 | int index = getVobjLocId(vspace_index, str, vobj_loc_index); |
---|
459 | if (index >= 0) |
---|
460 | { |
---|
461 | #if XML_PARSER_DEBUG |
---|
462 | printf(" heapname = %s\n", str); |
---|
463 | printf(" heapid = %d\n", index); |
---|
464 | #endif |
---|
465 | task[task_index]->heap_vobjid = index; |
---|
466 | } |
---|
467 | else |
---|
468 | { |
---|
469 | printf("[XML ERROR] illegal or missing <heapname> for task (%d,%d)\n", |
---|
470 | vspace_index, task_loc_index); |
---|
471 | exit(1); |
---|
472 | } |
---|
473 | } |
---|
474 | else |
---|
475 | { |
---|
476 | task[task_index]->heap_vobjid = -1; |
---|
477 | } |
---|
478 | |
---|
479 | |
---|
480 | ////////// get startid attribute |
---|
481 | value = getIntValue(reader, "startid", &ok); |
---|
482 | if (ok) |
---|
483 | { |
---|
484 | #if XML_PARSER_DEBUG |
---|
485 | printf(" startid = %x\n", value); |
---|
486 | #endif |
---|
487 | task[task_index]->startid = value; |
---|
488 | } |
---|
489 | else |
---|
490 | { |
---|
491 | printf("[XML ERROR] illegal or missing <startid> attribute for task (%d,%d)\n", |
---|
492 | vspace_index, task_loc_index); |
---|
493 | exit(1); |
---|
494 | } |
---|
495 | |
---|
496 | /////////// get usetty attribute (optionnal : 0 if missing) |
---|
497 | value = getIntValue(reader, "usetty", &ok); |
---|
498 | #if XML_PARSER_DEBUG |
---|
499 | printf(" usetty = %x\n", value); |
---|
500 | #endif |
---|
501 | task[task_index]->use_tty = (ok)? value : 0; |
---|
502 | |
---|
503 | /////////// get usenic attribute (optionnal : 0 if missing) |
---|
504 | value = getIntValue(reader, "usenic", &ok); |
---|
505 | #if XML_PARSER_DEBUG |
---|
506 | printf(" usenic = %x\n", value); |
---|
507 | #endif |
---|
508 | task[task_index]->use_nic = (ok)? value : 0; |
---|
509 | |
---|
510 | /////////// get usetim attribute (optionnal : 0 if missing) |
---|
511 | value = getIntValue(reader, "usetim", &ok); |
---|
512 | #if XML_PARSER_DEBUG |
---|
513 | printf(" usetim = %x\n", value); |
---|
514 | #endif |
---|
515 | task[task_index]->use_tim = (ok)? value : 0; |
---|
516 | |
---|
517 | /////////// get usedma attribute (optionnal : 0 if missing) |
---|
518 | value = getIntValue(reader, "usedma", &ok); |
---|
519 | #if XML_PARSER_DEBUG |
---|
520 | printf(" usedma = %x\n", value); |
---|
521 | #endif |
---|
522 | task[task_index]->use_dma = (ok)? value : 0; |
---|
523 | |
---|
524 | /////////// get useioc attribute (optionnal : 0 if missing) |
---|
525 | value = getIntValue(reader, "useioc", &ok); |
---|
526 | #if XML_PARSER_DEBUG |
---|
527 | printf(" useioc = %x\n", value); |
---|
528 | #endif |
---|
529 | task[task_index]->use_ioc = (ok)? value : 0; |
---|
530 | |
---|
531 | /////////// get usecma attribute (optionnal : 0 if missing) |
---|
532 | value = getIntValue(reader, "usecma", &ok); |
---|
533 | #if XML_PARSER_DEBUG |
---|
534 | printf(" usecma = %x\n", value); |
---|
535 | #endif |
---|
536 | task[task_index]->use_cma = (ok)? value : 0; |
---|
537 | |
---|
538 | task_index++; |
---|
539 | task_loc_index++; |
---|
540 | } // end taskNode() |
---|
541 | |
---|
542 | |
---|
543 | ////////////////////////////////////// |
---|
544 | void vobjNode(xmlTextReaderPtr reader) |
---|
545 | { |
---|
546 | unsigned int ok; |
---|
547 | unsigned int value; |
---|
548 | char * str; |
---|
549 | |
---|
550 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { return; } |
---|
551 | |
---|
552 | if (vobj_index >= MAX_VOBJS) |
---|
553 | { |
---|
554 | printf("[XML ERROR] The number of vobjs is larger than %d\n", MAX_VOBJS); |
---|
555 | exit(1); |
---|
556 | } |
---|
557 | |
---|
558 | #if XML_PARSER_DEBUG |
---|
559 | printf(" vobj %d\n", vobj_loc_index); |
---|
560 | #endif |
---|
561 | |
---|
562 | vobj[vobj_index] = (mapping_vobj_t *) malloc(sizeof(mapping_vobj_t)); |
---|
563 | |
---|
564 | ///////// get name attribute |
---|
565 | str = getStringValue(reader, "name", &ok); |
---|
566 | if (ok) |
---|
567 | { |
---|
568 | #if XML_PARSER_DEBUG |
---|
569 | printf(" name = %s\n", str); |
---|
570 | #endif |
---|
571 | strncpy(vobj[vobj_index]->name, str, 31); |
---|
572 | } |
---|
573 | else |
---|
574 | { |
---|
575 | printf("[XML ERROR] illegal or missing <name> attribute for vobj (%d,%d)\n", |
---|
576 | vseg_index, vobj_loc_index); |
---|
577 | exit(1); |
---|
578 | } |
---|
579 | |
---|
580 | //////// get type attribute |
---|
581 | str = getStringValue(reader, "type", &ok); |
---|
582 | #if XML_PARSER_DEBUG |
---|
583 | printf(" type = %s\n", str); |
---|
584 | #endif |
---|
585 | if (ok && (strcmp(str, "ELF") == 0)) |
---|
586 | { |
---|
587 | vobj[vobj_index]->type = VOBJ_TYPE_ELF; |
---|
588 | |
---|
589 | assert( (vobj_count == 0) && "[XML ERROR] an ELF vobj must be alone in a vseg"); |
---|
590 | } |
---|
591 | else if (ok && (strcmp(str, "PERI") == 0)) |
---|
592 | { |
---|
593 | vobj[vobj_index]->type = VOBJ_TYPE_PERI; |
---|
594 | |
---|
595 | assert( (vobj_count == 0) && "[XML ERROR] a PERI vobj must be alone in a vseg"); |
---|
596 | |
---|
597 | // fill the peripheral base address array |
---|
598 | set_periph_vbase_array( vseg_index ); |
---|
599 | } |
---|
600 | else if (ok && (strcmp(str, "BLOB") == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_BLOB; } |
---|
601 | else if (ok && (strcmp(str, "PTAB") == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_PTAB; } |
---|
602 | else if (ok && (strcmp(str, "MWMR") == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_MWMR; } |
---|
603 | else if (ok && (strcmp(str, "LOCK") == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_LOCK; } |
---|
604 | else if (ok && (strcmp(str, "BUFFER") == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_BUFFER; } |
---|
605 | else if (ok && (strcmp(str, "BARRIER") == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_BARRIER; } |
---|
606 | else if (ok && (strcmp(str, "CONST") == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_CONST; } |
---|
607 | else if (ok && (strcmp(str, "MEMSPACE") == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_MEMSPACE; } |
---|
608 | else if (ok && (strcmp(str, "SCHED") == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_SCHED; } |
---|
609 | else |
---|
610 | { |
---|
611 | printf("[XML ERROR] illegal or missing <type> attribute for vobj (%d,%d)\n", |
---|
612 | vspace_index, vobj_loc_index); |
---|
613 | exit(1); |
---|
614 | } |
---|
615 | |
---|
616 | ////////// get length attribute |
---|
617 | value = getIntValue(reader, "length", &ok); |
---|
618 | if (ok) { |
---|
619 | #if XML_PARSER_DEBUG |
---|
620 | printf(" length = %d\n", value); |
---|
621 | #endif |
---|
622 | vobj[vobj_index]->length = value; |
---|
623 | } |
---|
624 | else { |
---|
625 | printf("[XML ERROR] illegal or missing <length> attribute for vobj (%d,%d)\n", |
---|
626 | vspace_index, vobj_loc_index); |
---|
627 | exit(1); |
---|
628 | } |
---|
629 | |
---|
630 | ////////// get align attribute (optional : 0 if missing) |
---|
631 | value = getIntValue(reader, "align", &ok); |
---|
632 | if (ok) { |
---|
633 | #if XML_PARSER_DEBUG |
---|
634 | printf(" align = %d\n", value); |
---|
635 | #endif |
---|
636 | vobj[vobj_index]->align = value; |
---|
637 | } |
---|
638 | else { |
---|
639 | vobj[vobj_index]->align = 0; |
---|
640 | } |
---|
641 | |
---|
642 | ////////// get binpath attribute (optional : '\0' if missing) |
---|
643 | str = getStringValue(reader, "binpath", &ok); |
---|
644 | if (ok) { |
---|
645 | #if XML_PARSER_DEBUG |
---|
646 | printf(" binpath = %s\n", str); |
---|
647 | #endif |
---|
648 | strncpy(vobj[vobj_index]->binpath, str, 63); |
---|
649 | } |
---|
650 | else { |
---|
651 | vobj[vobj_index]->binpath[0] = '\0'; |
---|
652 | } |
---|
653 | |
---|
654 | ////////// get init attribute (mandatory for mwmr and barrier) |
---|
655 | value = getIntValue(reader, "init", &ok); |
---|
656 | if (ok) |
---|
657 | { |
---|
658 | #if XML_PARSER_DEBUG |
---|
659 | printf(" init = %d\n", value); |
---|
660 | #endif |
---|
661 | vobj[vobj_index]->init = value; |
---|
662 | } |
---|
663 | else |
---|
664 | { |
---|
665 | if ((vobj[vobj_index]->type == VOBJ_TYPE_MWMR) || |
---|
666 | (vobj[vobj_index]->type == VOBJ_TYPE_BARRIER) || |
---|
667 | (vobj[vobj_index]->type == VOBJ_TYPE_CONST)) |
---|
668 | { |
---|
669 | printf("[XML ERROR] illegal or missing <value> attribute for vobj (%d,%d). \ |
---|
670 | All MWMR or BARRIER or CONST vobj must have a init value \n", |
---|
671 | vspace_index, vobj_loc_index); |
---|
672 | exit(1); |
---|
673 | } |
---|
674 | vobj[vobj_index]->init = 0; |
---|
675 | } |
---|
676 | |
---|
677 | vobj_index++; |
---|
678 | vobj_count++; |
---|
679 | vobj_loc_index++; |
---|
680 | } // end vobjNode() |
---|
681 | |
---|
682 | |
---|
683 | ////////////////////////////////////// |
---|
684 | void vsegNode(xmlTextReaderPtr reader) |
---|
685 | { |
---|
686 | unsigned int ok; |
---|
687 | unsigned int value; |
---|
688 | char * str; |
---|
689 | |
---|
690 | vobj_count = 0; |
---|
691 | |
---|
692 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { return; } |
---|
693 | |
---|
694 | if (vseg_index >= MAX_VSEGS) |
---|
695 | { |
---|
696 | printf("[XML ERROR] The number of vsegs is larger than %d\n", MAX_VSEGS); |
---|
697 | exit(1); |
---|
698 | } |
---|
699 | |
---|
700 | #if XML_PARSER_DEBUG |
---|
701 | printf(" vseg %d\n", vseg_loc_index); |
---|
702 | #endif |
---|
703 | |
---|
704 | vseg[vseg_index] = (mapping_vseg_t *) malloc(sizeof(mapping_vseg_t)); |
---|
705 | |
---|
706 | ////////// set vobj_offset attributes |
---|
707 | vseg[vseg_index]->vobj_offset = vobj_index; |
---|
708 | |
---|
709 | #if XML_PARSER_DEBUG |
---|
710 | printf(" vobj_offset = %d\n", vobj_index); |
---|
711 | #endif |
---|
712 | |
---|
713 | ///////// get name attribute |
---|
714 | str = getStringValue(reader, "name", &ok); |
---|
715 | if (ok) |
---|
716 | { |
---|
717 | #if XML_PARSER_DEBUG |
---|
718 | printf(" name = %s\n", str); |
---|
719 | #endif |
---|
720 | strncpy( vseg[vseg_index]->name, str, 31); |
---|
721 | } |
---|
722 | else |
---|
723 | { |
---|
724 | printf("[XML ERROR] illegal or missing <name> attribute for vseg (%d,%d)\n", |
---|
725 | vspace_index, vseg_loc_index); |
---|
726 | exit(1); |
---|
727 | } |
---|
728 | |
---|
729 | ////////// get ident attribute (optional : 0 if missing) |
---|
730 | value = getIntValue(reader, "ident", &ok); |
---|
731 | if (ok) |
---|
732 | { |
---|
733 | #if XML_PARSER_DEBUG |
---|
734 | printf(" ident = %d\n", value); |
---|
735 | #endif |
---|
736 | vseg[vseg_index]->ident = value; |
---|
737 | } |
---|
738 | else |
---|
739 | { |
---|
740 | vseg[vseg_index]->ident = 0; |
---|
741 | } |
---|
742 | |
---|
743 | /////////// get vbase attribute |
---|
744 | value = getIntValue(reader, "vbase", &ok); |
---|
745 | if (ok) |
---|
746 | { |
---|
747 | #if XML_PARSER_DEBUG |
---|
748 | printf(" vbase = 0x%x\n", value); |
---|
749 | #endif |
---|
750 | vseg[vseg_index]->vbase = value; |
---|
751 | } |
---|
752 | else |
---|
753 | { |
---|
754 | printf("[XML ERROR] illegal or missing <vbase> attribute for vseg (%d,%d)\n", |
---|
755 | vspace_index, vseg_loc_index); |
---|
756 | exit(1); |
---|
757 | } |
---|
758 | |
---|
759 | ////////// get clusterid and psegname attributes |
---|
760 | value = getIntValue(reader, "clusterid", &ok); |
---|
761 | if (ok == 0) |
---|
762 | { |
---|
763 | printf("[XML ERROR] illegal or missing <clusterid> for vseg %d\n", |
---|
764 | vseg_loc_index); |
---|
765 | exit(1); |
---|
766 | } |
---|
767 | str = getStringValue(reader, "psegname", &ok); |
---|
768 | if (ok == 0) |
---|
769 | { |
---|
770 | printf("[XML ERROR] illegal or missing <psegname> for vseg %d\n", |
---|
771 | vseg_loc_index); |
---|
772 | exit(1); |
---|
773 | } |
---|
774 | |
---|
775 | /////////// set psegid field |
---|
776 | int index = getPsegId(value, str); |
---|
777 | if (index >= 0) |
---|
778 | { |
---|
779 | #if XML_PARSER_DEBUG |
---|
780 | printf(" clusterid = %d\n", value); |
---|
781 | printf(" psegname = %s\n", str); |
---|
782 | printf(" psegid = %d\n", index); |
---|
783 | #endif |
---|
784 | vseg[vseg_index]->psegid = index; |
---|
785 | } |
---|
786 | else |
---|
787 | { |
---|
788 | printf("[XML ERROR] pseg not found for vseg %d / clusterid = %d / psegname = %s\n", |
---|
789 | vseg_loc_index, value, str ); |
---|
790 | exit(1); |
---|
791 | } |
---|
792 | |
---|
793 | //////// get mode attribute |
---|
794 | str = getStringValue(reader, "mode", &ok); |
---|
795 | #if XML_PARSER_DEBUG |
---|
796 | printf(" mode = %s\n", str); |
---|
797 | #endif |
---|
798 | if (ok && (strcmp(str, "CXWU") == 0)) { vseg[vseg_index]->mode = 0xF; } |
---|
799 | else if (ok && (strcmp(str, "CXW_") == 0)) { vseg[vseg_index]->mode = 0xE; } |
---|
800 | else if (ok && (strcmp(str, "CX_U") == 0)) { vseg[vseg_index]->mode = 0xD; } |
---|
801 | else if (ok && (strcmp(str, "CX__") == 0)) { vseg[vseg_index]->mode = 0xC; } |
---|
802 | else if (ok && (strcmp(str, "C_WU") == 0)) { vseg[vseg_index]->mode = 0xB; } |
---|
803 | else if (ok && (strcmp(str, "C_W_") == 0)) { vseg[vseg_index]->mode = 0xA; } |
---|
804 | else if (ok && (strcmp(str, "C__U") == 0)) { vseg[vseg_index]->mode = 0x9; } |
---|
805 | else if (ok && (strcmp(str, "C___") == 0)) { vseg[vseg_index]->mode = 0x8; } |
---|
806 | else if (ok && (strcmp(str, "_XWU") == 0)) { vseg[vseg_index]->mode = 0x7; } |
---|
807 | else if (ok && (strcmp(str, "_XW_") == 0)) { vseg[vseg_index]->mode = 0x6; } |
---|
808 | else if (ok && (strcmp(str, "_X_U") == 0)) { vseg[vseg_index]->mode = 0x5; } |
---|
809 | else if (ok && (strcmp(str, "_X__") == 0)) { vseg[vseg_index]->mode = 0x4; } |
---|
810 | else if (ok && (strcmp(str, "__WU") == 0)) { vseg[vseg_index]->mode = 0x3; } |
---|
811 | else if (ok && (strcmp(str, "__W_") == 0)) { vseg[vseg_index]->mode = 0x2; } |
---|
812 | else if (ok && (strcmp(str, "___U") == 0)) { vseg[vseg_index]->mode = 0x1; } |
---|
813 | else if (ok && (strcmp(str, "____") == 0)) { vseg[vseg_index]->mode = 0x0; } |
---|
814 | else { |
---|
815 | printf("[XML ERROR] illegal or missing <mode> attribute for vseg (%d,%d)\n", |
---|
816 | vspace_index, vseg_loc_index); |
---|
817 | exit(1); |
---|
818 | } |
---|
819 | |
---|
820 | ////////// get vobjs in vseg |
---|
821 | int status = xmlTextReaderRead(reader); |
---|
822 | while (status == 1) { |
---|
823 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
824 | |
---|
825 | if (strcmp(tag, "vobj") == 0 ) { vobjNode(reader); } |
---|
826 | else if (strcmp(tag, "#text" ) == 0 ) { } |
---|
827 | else if (strcmp(tag, "#comment") == 0 ) { } |
---|
828 | else if (strcmp(tag, "vseg") == 0 ) |
---|
829 | { |
---|
830 | vseg[vseg_index]->vobjs = vobj_count; |
---|
831 | vseg_index++; |
---|
832 | vseg_loc_index++; |
---|
833 | return; |
---|
834 | } |
---|
835 | else { |
---|
836 | printf("[XML ERROR] Unknown tag %s", tag); |
---|
837 | exit(1); |
---|
838 | } |
---|
839 | status = xmlTextReaderRead (reader); |
---|
840 | } |
---|
841 | } // end vsegNode() |
---|
842 | |
---|
843 | |
---|
844 | ////////////////////////////////////////// |
---|
845 | void vspaceNode(xmlTextReaderPtr reader) { |
---|
846 | char * str; |
---|
847 | unsigned int ok; |
---|
848 | unsigned int nb_task_vspace = 0; |
---|
849 | |
---|
850 | vobj_loc_index = 0; |
---|
851 | vseg_loc_index = 0; |
---|
852 | task_loc_index = 0; |
---|
853 | |
---|
854 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { |
---|
855 | return; |
---|
856 | } |
---|
857 | |
---|
858 | // checking source file consistency |
---|
859 | if (vspace_index >= header->vspaces) { |
---|
860 | printf("[XML ERROR] The vspace index is too large : %d\n", |
---|
861 | vspace_index); |
---|
862 | exit(1); |
---|
863 | } |
---|
864 | |
---|
865 | #if XML_PARSER_DEBUG |
---|
866 | printf("\n vspace %d\n", vspace_index); |
---|
867 | #endif |
---|
868 | |
---|
869 | vspace[vspace_index] = (mapping_vspace_t *) malloc(sizeof(mapping_vspace_t)); |
---|
870 | |
---|
871 | ////////// get name attribute |
---|
872 | str = getStringValue(reader, "name", &ok); |
---|
873 | if (ok) { |
---|
874 | #if XML_PARSER_DEBUG |
---|
875 | printf(" name = %s\n", str); |
---|
876 | #endif |
---|
877 | strncpy(vspace[vspace_index]->name, str, 31); |
---|
878 | } |
---|
879 | else { |
---|
880 | printf("[XML ERROR] illegal or missing <name> attribute for vspace %d\n", |
---|
881 | vspace_index); |
---|
882 | exit(1); |
---|
883 | } |
---|
884 | |
---|
885 | ////////// set vseg_offset and task_offset attributes |
---|
886 | vspace[vspace_index]->vseg_offset = vseg_index; |
---|
887 | vspace[vspace_index]->vobj_offset = vobj_index; |
---|
888 | vspace[vspace_index]->task_offset = task_index; |
---|
889 | |
---|
890 | #if XML_PARSER_DEBUG |
---|
891 | printf(" vseg_offset = %d\n", vseg_index); |
---|
892 | printf(" vobj_offset = %d\n", vobj_index); |
---|
893 | printf(" task_offset = %d\n", task_index); |
---|
894 | #endif |
---|
895 | |
---|
896 | ////////// get startname attribute |
---|
897 | str = getStringValue(reader, "startname", &ok); |
---|
898 | if (ok) { |
---|
899 | //used after parsing the vobjs |
---|
900 | } |
---|
901 | else { |
---|
902 | printf("[XML ERROR] illegal or missing <startname> attribute for vspace %s\n", |
---|
903 | vspace[vspace_index]->name); |
---|
904 | exit(1); |
---|
905 | } |
---|
906 | |
---|
907 | int status = xmlTextReaderRead(reader); |
---|
908 | while (status == 1) { |
---|
909 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
910 | |
---|
911 | if (strcmp(tag, "vseg") == 0) { |
---|
912 | vsegNode(reader); |
---|
913 | } |
---|
914 | else if (strcmp(tag, "task") == 0) { |
---|
915 | taskNode(reader); |
---|
916 | nb_task_vspace++; |
---|
917 | } |
---|
918 | else if (strcmp(tag, "#text") == 0) { } |
---|
919 | else if (strcmp(tag, "#comment") == 0) { } |
---|
920 | else if (strcmp(tag, "vspace") == 0) { |
---|
921 | vspace[vspace_index]->vobjs = vobj_loc_index; |
---|
922 | vspace[vspace_index]->tasks = task_loc_index ; |
---|
923 | vspace[vspace_index]->vsegs = vseg_loc_index ; |
---|
924 | |
---|
925 | // get index of the vobj containing the start vector |
---|
926 | int index = getVobjLocId(vspace_index, str , vobj_loc_index); |
---|
927 | if (index == -1) { |
---|
928 | printf("[XML ERROR] vobj containing start vector not found in vspace %s\n", |
---|
929 | vspace[vspace_index]->name); |
---|
930 | exit(-1); |
---|
931 | } |
---|
932 | else { |
---|
933 | vspace[vspace_index]->start_offset = index; |
---|
934 | #if XML_PARSER_DEBUG |
---|
935 | printf(" startname = %s\n", str); |
---|
936 | printf(" startid = %d\n", index); |
---|
937 | printf(" end vspace %d\n\n", vspace_index); |
---|
938 | #endif |
---|
939 | } |
---|
940 | |
---|
941 | // checking startid values for all tasks in vspace |
---|
942 | int task_id; |
---|
943 | int task_min = vspace[vspace_index]->task_offset; |
---|
944 | int task_max = task_min + vspace[vspace_index]->tasks; |
---|
945 | for (task_id = task_min; task_id < task_max; task_id++) { |
---|
946 | if (task[task_id]->startid >= vspace[vspace_index]->tasks) { |
---|
947 | printf("[XML ERROR] <startid> too large for task (%d,%d)\n", |
---|
948 | vspace_index, task_id ); |
---|
949 | exit(1); |
---|
950 | } |
---|
951 | } |
---|
952 | |
---|
953 | nb_tasks_max += nb_task_vspace; |
---|
954 | vspace_index++; |
---|
955 | return; |
---|
956 | } |
---|
957 | else { |
---|
958 | printf("[XML ERROR] Unknown tag %s", tag); |
---|
959 | exit(1); |
---|
960 | } |
---|
961 | status = xmlTextReaderRead(reader); |
---|
962 | } |
---|
963 | } // end vspaceNode() |
---|
964 | |
---|
965 | |
---|
966 | /////////////////////////////////////////// |
---|
967 | void cpPortNode(xmlTextReaderPtr reader) { |
---|
968 | char * str; |
---|
969 | unsigned int ok; |
---|
970 | |
---|
971 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { |
---|
972 | return; |
---|
973 | } |
---|
974 | |
---|
975 | if (cp_port_index >= MAX_CP_PORTS) { |
---|
976 | printf("[XML ERROR] The number of ports (for coprocs) is larger than %d\n", MAX_CP_PORTS); |
---|
977 | } |
---|
978 | |
---|
979 | #if XML_PARSER_DEBUG |
---|
980 | printf("\n port %d\n", cp_port_index); |
---|
981 | #endif |
---|
982 | |
---|
983 | cp_port[cp_port_index] = (mapping_cp_port_t *) malloc(sizeof(mapping_cp_port_t)); |
---|
984 | cp_port_vobj_ref[cp_port_index] = (vobj_ref_t *) malloc(sizeof(vobj_ref_t)); |
---|
985 | |
---|
986 | |
---|
987 | |
---|
988 | ///////// get direction attribute |
---|
989 | str = getStringValue(reader, "direction", &ok); |
---|
990 | if (ok) { |
---|
991 | #if XML_PARSER_DEBUG |
---|
992 | printf(" direction = %s\n", str); |
---|
993 | #endif |
---|
994 | if (strcmp(str, "TO_COPROC") == 0) { |
---|
995 | cp_port[cp_port_index]->direction = PORT_TO_COPROC; |
---|
996 | } |
---|
997 | else if (strcmp(str, "FROM_COPROC") == 0) { |
---|
998 | cp_port[cp_port_index]->direction = PORT_FROM_COPROC; |
---|
999 | } |
---|
1000 | else { |
---|
1001 | printf("[XML ERROR] illegal <direction> for cp_port %d in cluster %d\n", |
---|
1002 | cp_port_index, cluster_index); |
---|
1003 | exit(1); |
---|
1004 | } |
---|
1005 | } |
---|
1006 | else { |
---|
1007 | printf("[XML ERROR] missing <direction> for cp_port %d in cluster %d\n", |
---|
1008 | cp_port_index, cluster_index); |
---|
1009 | exit(1); |
---|
1010 | } |
---|
1011 | |
---|
1012 | /////////// get vspacename attribute |
---|
1013 | str = getStringValue(reader, "vspacename", &ok); |
---|
1014 | #if XML_PARSER_DEBUG |
---|
1015 | printf(" vspacename = %s\n", str); |
---|
1016 | #endif |
---|
1017 | if (ok) { |
---|
1018 | strncpy(cp_port_vobj_ref[cp_port_index]->vspace_name, str, 31); |
---|
1019 | } |
---|
1020 | else { |
---|
1021 | printf("[XML ERROR] missing <vspacename> for cp_port %d in cluster %d\n", |
---|
1022 | cp_port_index, cluster_index); |
---|
1023 | exit(1); |
---|
1024 | } |
---|
1025 | |
---|
1026 | /////////// get vobjname attribute |
---|
1027 | str = getStringValue(reader, "vobjname", &ok); |
---|
1028 | #if XML_PARSER_DEBUG |
---|
1029 | printf(" vobjname = %s\n", str); |
---|
1030 | #endif |
---|
1031 | if (ok) { |
---|
1032 | strncpy(cp_port_vobj_ref[cp_port_index]->vobj_name, str, 31); |
---|
1033 | } |
---|
1034 | else { |
---|
1035 | printf("[XML ERROR] missing <vobjname> for cp_port %d in cluster %d\n", |
---|
1036 | cp_port_index, cluster_index); |
---|
1037 | exit(1); |
---|
1038 | } |
---|
1039 | |
---|
1040 | cp_port_index++; |
---|
1041 | cp_port_loc_index++; |
---|
1042 | |
---|
1043 | } // end cpPortNode() |
---|
1044 | |
---|
1045 | |
---|
1046 | //////////////////////////////////////// |
---|
1047 | void periphNode(xmlTextReaderPtr reader) |
---|
1048 | { |
---|
1049 | char * str; |
---|
1050 | unsigned int value; |
---|
1051 | unsigned int ok; |
---|
1052 | |
---|
1053 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { return; } |
---|
1054 | |
---|
1055 | if (periph_index >= MAX_PERIPHS) |
---|
1056 | { |
---|
1057 | printf("[XML ERROR] The number of periphs is larger than %d\n", MAX_PERIPHS); |
---|
1058 | } |
---|
1059 | |
---|
1060 | #if XML_PARSER_DEBUG |
---|
1061 | printf("\n periph %d\n", periph_index); |
---|
1062 | #endif |
---|
1063 | |
---|
1064 | periph[periph_index] = (mapping_periph_t *) malloc(sizeof(mapping_periph_t)); |
---|
1065 | |
---|
1066 | ///////// get channels attribute (optionnal : 1 if missing) |
---|
1067 | value = getIntValue(reader, "channels", &ok); |
---|
1068 | if (ok) |
---|
1069 | { |
---|
1070 | #if XML_PARSER_DEBUG |
---|
1071 | printf(" channels = %d\n", value); |
---|
1072 | #endif |
---|
1073 | periph[periph_index]->channels = value; |
---|
1074 | } |
---|
1075 | else |
---|
1076 | { |
---|
1077 | periph[periph_index]->channels = 1; |
---|
1078 | } |
---|
1079 | |
---|
1080 | /////////// get psegname attribute |
---|
1081 | str = getStringValue(reader, "psegname", &ok); |
---|
1082 | if (ok == 0) |
---|
1083 | { |
---|
1084 | printf("[XML ERROR] illegal or missing <psegname> for coproc %d in cluster %d\n", |
---|
1085 | coproc_index, cluster_index); |
---|
1086 | exit(1); |
---|
1087 | } |
---|
1088 | |
---|
1089 | /////////// set psegid attribute |
---|
1090 | int index = getPsegId(cluster_index, str); |
---|
1091 | if (index >= 0) |
---|
1092 | { |
---|
1093 | #if XML_PARSER_DEBUG |
---|
1094 | printf(" clusterid = %d\n", cluster_index); |
---|
1095 | printf(" psegname = %s\n", str); |
---|
1096 | printf(" psegid = %d\n", index); |
---|
1097 | #endif |
---|
1098 | periph[periph_index]->psegid = index; |
---|
1099 | assert(pseg[index]->type == PSEG_TYPE_PERI && |
---|
1100 | "peripheral psegname attribute must refer to a pseg of type PERI" ); |
---|
1101 | } |
---|
1102 | else |
---|
1103 | { |
---|
1104 | printf("[XML ERROR] pseg not found for periph %d / clusterid = %d / psegname = %s\n", |
---|
1105 | periph_loc_index, cluster_index, str ); |
---|
1106 | exit(1); |
---|
1107 | } |
---|
1108 | |
---|
1109 | /////////// get type attribute |
---|
1110 | str = getStringValue(reader, "type", &ok); |
---|
1111 | if (ok) |
---|
1112 | { |
---|
1113 | #if XML_PARSER_DEBUG |
---|
1114 | printf(" type = %s\n", str); |
---|
1115 | #endif |
---|
1116 | unsigned int error = 0; |
---|
1117 | |
---|
1118 | // The TTY, IOC, NIC, FBF, CMA and IOB peripherals are not replicated in all clusters |
---|
1119 | // but can be replicated in two different clusters for fault tolerance |
---|
1120 | // In case of replication, the number of channels must be the same |
---|
1121 | if (strcmp(str, "IOC") == 0) |
---|
1122 | { |
---|
1123 | periph[periph_index]->type = PERIPH_TYPE_IOC; |
---|
1124 | if (header->ioc_cluster == 0xFFFFFFFF) |
---|
1125 | { |
---|
1126 | header->ioc_cluster = cluster_index; |
---|
1127 | ioc_channels = periph[periph_index]->channels; |
---|
1128 | } |
---|
1129 | else if (header->ioc_cluster_bis == 0xFFFFFFFF) |
---|
1130 | { |
---|
1131 | header->ioc_cluster_bis = cluster_index; |
---|
1132 | } |
---|
1133 | else |
---|
1134 | { |
---|
1135 | error = 1; |
---|
1136 | } |
---|
1137 | } |
---|
1138 | else if (strcmp(str, "TTY") == 0) |
---|
1139 | { |
---|
1140 | periph[periph_index]->type = PERIPH_TYPE_TTY; |
---|
1141 | if (header->tty_cluster == 0xFFFFFFFF) |
---|
1142 | { |
---|
1143 | header->tty_cluster = cluster_index; |
---|
1144 | tty_channels = periph[periph_index]->channels; |
---|
1145 | } |
---|
1146 | else if (header->tty_cluster_bis == 0xFFFFFFFF) |
---|
1147 | { |
---|
1148 | header->tty_cluster_bis = cluster_index; |
---|
1149 | } |
---|
1150 | else |
---|
1151 | { |
---|
1152 | error = 1; |
---|
1153 | } |
---|
1154 | } |
---|
1155 | else if (strcmp(str, "FBF") == 0) |
---|
1156 | { |
---|
1157 | periph[periph_index]->type = PERIPH_TYPE_FBF; |
---|
1158 | if (header->fbf_cluster == 0xFFFFFFFF) |
---|
1159 | { |
---|
1160 | header->fbf_cluster = cluster_index; |
---|
1161 | } |
---|
1162 | else if (header->fbf_cluster_bis == 0xFFFFFFFF) |
---|
1163 | { |
---|
1164 | header->fbf_cluster_bis = cluster_index; |
---|
1165 | } |
---|
1166 | else |
---|
1167 | { |
---|
1168 | error = 1; |
---|
1169 | } |
---|
1170 | } |
---|
1171 | else if (strcmp(str, "NIC") == 0) |
---|
1172 | { |
---|
1173 | periph[periph_index]->type = PERIPH_TYPE_NIC; |
---|
1174 | if (header->nic_cluster == 0xFFFFFFFF) |
---|
1175 | { |
---|
1176 | header->nic_cluster = cluster_index; |
---|
1177 | nic_channels = periph[periph_index]->channels; |
---|
1178 | } |
---|
1179 | else if (header->nic_cluster_bis == 0xFFFFFFFF) |
---|
1180 | { |
---|
1181 | header->nic_cluster_bis = cluster_index; |
---|
1182 | } |
---|
1183 | else |
---|
1184 | { |
---|
1185 | error = 1; |
---|
1186 | } |
---|
1187 | } |
---|
1188 | else if (strcmp(str, "CMA") == 0) |
---|
1189 | { |
---|
1190 | periph[periph_index]->type = PERIPH_TYPE_CMA; |
---|
1191 | if (header->cma_cluster == 0xFFFFFFFF) |
---|
1192 | { |
---|
1193 | header->cma_cluster = cluster_index; |
---|
1194 | cma_channels = periph[periph_index]->channels; |
---|
1195 | } |
---|
1196 | else if (header->nic_cluster_bis == 0xFFFFFFFF) |
---|
1197 | { |
---|
1198 | header->cma_cluster_bis = cluster_index; |
---|
1199 | } |
---|
1200 | else |
---|
1201 | { |
---|
1202 | error = 1; |
---|
1203 | } |
---|
1204 | } |
---|
1205 | else if (strcmp(str, "IOB") == 0) |
---|
1206 | { |
---|
1207 | periph[periph_index]->type = PERIPH_TYPE_IOB; |
---|
1208 | use_iob = 1; |
---|
1209 | if (header->iob_cluster == 0xFFFFFFFF) |
---|
1210 | { |
---|
1211 | header->iob_cluster = cluster_index; |
---|
1212 | } |
---|
1213 | else if (header->iob_cluster_bis == 0xFFFFFFFF) |
---|
1214 | { |
---|
1215 | header->iob_cluster_bis = cluster_index; |
---|
1216 | } |
---|
1217 | else |
---|
1218 | { |
---|
1219 | error = 1; |
---|
1220 | } |
---|
1221 | } |
---|
1222 | // The TIM, ICU, XICU, DMA, MEMC peripherals are replicated in all clusters |
---|
1223 | // but only one component per cluster |
---|
1224 | else if (strcmp(str, "TIM") == 0 ) |
---|
1225 | { |
---|
1226 | periph[periph_index]->type = PERIPH_TYPE_TIM; |
---|
1227 | if (found_timer || use_xicu) error = 1; |
---|
1228 | found_timer = 1; |
---|
1229 | if (tim_channels < periph[periph_index]->channels) |
---|
1230 | { |
---|
1231 | tim_channels = periph[periph_index]->channels; |
---|
1232 | } |
---|
1233 | } |
---|
1234 | else if (strcmp(str, "ICU") == 0) |
---|
1235 | { |
---|
1236 | periph[periph_index]->type = PERIPH_TYPE_ICU; |
---|
1237 | if (found_icu) error = 1; |
---|
1238 | found_icu = 1; |
---|
1239 | } |
---|
1240 | else if (strcmp(str, "XICU") == 0) |
---|
1241 | { |
---|
1242 | periph[periph_index]->type = PERIPH_TYPE_ICU; |
---|
1243 | if (found_icu || found_timer) error = 1; |
---|
1244 | found_icu = 1; |
---|
1245 | if (tim_channels == 0) |
---|
1246 | { |
---|
1247 | tim_channels = 32; |
---|
1248 | } |
---|
1249 | use_xicu = 1; |
---|
1250 | } |
---|
1251 | else if (strcmp(str, "DMA") == 0) |
---|
1252 | { |
---|
1253 | periph[periph_index]->type = PERIPH_TYPE_DMA; |
---|
1254 | if (found_dma) error = 1; |
---|
1255 | found_dma = 1; |
---|
1256 | if (dma_channels < periph[periph_index]->channels) |
---|
1257 | dma_channels = periph[periph_index]->channels; |
---|
1258 | } |
---|
1259 | else if (strcmp(str, "MMC") == 0) |
---|
1260 | { |
---|
1261 | periph[periph_index]->type = PERIPH_TYPE_MMC; |
---|
1262 | if (found_mmc) error = 1; |
---|
1263 | found_mmc = 1; |
---|
1264 | if ( periph[periph_index]->channels != 1 ) error = 1; |
---|
1265 | } |
---|
1266 | else |
---|
1267 | { |
---|
1268 | printf("[XML ERROR] illegal <type> for peripheral %d in cluster %d\n", |
---|
1269 | periph_loc_index, cluster_index); |
---|
1270 | exit(1); |
---|
1271 | } |
---|
1272 | |
---|
1273 | if (error) |
---|
1274 | { |
---|
1275 | printf("[XML ERROR] illegal <type> for peripheral %d in cluster %d\n", |
---|
1276 | periph_loc_index, cluster_index); |
---|
1277 | exit(1); |
---|
1278 | } |
---|
1279 | } |
---|
1280 | else |
---|
1281 | { |
---|
1282 | printf("[XML ERROR] missing <type> for peripheral %d in cluster %d\n", |
---|
1283 | periph_loc_index, cluster_index); |
---|
1284 | exit(1); |
---|
1285 | } |
---|
1286 | |
---|
1287 | periph_index++; |
---|
1288 | periph_loc_index++; |
---|
1289 | cluster[cluster_index]->periphs++; |
---|
1290 | |
---|
1291 | } // end periphNode |
---|
1292 | |
---|
1293 | |
---|
1294 | ///////////////////////////////////////// |
---|
1295 | void coprocNode(xmlTextReaderPtr reader) { |
---|
1296 | char * str; |
---|
1297 | unsigned int ok; |
---|
1298 | |
---|
1299 | cp_port_loc_index = 0; |
---|
1300 | |
---|
1301 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { |
---|
1302 | return; |
---|
1303 | } |
---|
1304 | |
---|
1305 | if (coproc_index >= MAX_COPROCS) { |
---|
1306 | printf("[XML ERROR] The number of coprocs is larger than %d\n", MAX_COPROCS); |
---|
1307 | } |
---|
1308 | |
---|
1309 | #if XML_PARSER_DEBUG |
---|
1310 | printf("\n coproc %d\n", coproc_index); |
---|
1311 | #endif |
---|
1312 | |
---|
1313 | coproc[coproc_index] = (mapping_coproc_t *) malloc(sizeof(mapping_coproc_t)); |
---|
1314 | |
---|
1315 | /////////// get name attribute |
---|
1316 | str = getStringValue(reader, "name", &ok); |
---|
1317 | if (ok) { |
---|
1318 | #if XML_PARSER_DEBUG |
---|
1319 | printf(" name = %s\n", str); |
---|
1320 | #endif |
---|
1321 | strncpy(coproc[coproc_index]->name, str, 31); |
---|
1322 | } |
---|
1323 | else { |
---|
1324 | printf("[XML ERROR] illegal or missing <name> for coproc %d in cluster %d\n", |
---|
1325 | coproc_index, cluster_index); |
---|
1326 | exit(1); |
---|
1327 | } |
---|
1328 | |
---|
1329 | /////////// get psegname attribute |
---|
1330 | str = getStringValue(reader, "psegname", &ok); |
---|
1331 | if (ok == 0) { |
---|
1332 | printf("[XML ERROR] illegal or missing <psegname> for coproc %d in cluster %d\n", |
---|
1333 | coproc_index, cluster_index); |
---|
1334 | exit(1); |
---|
1335 | } |
---|
1336 | |
---|
1337 | /////////// set psegid attribute |
---|
1338 | int index = getPsegId(cluster_index, str); |
---|
1339 | if (index >= 0) { |
---|
1340 | #if XML_PARSER_DEBUG |
---|
1341 | printf(" clusterid = %d\n", cluster_index); |
---|
1342 | printf(" psegname = %s\n", str); |
---|
1343 | printf(" psegid = %d\n", index); |
---|
1344 | #endif |
---|
1345 | coproc[coproc_index]->psegid = index; |
---|
1346 | assert(pseg[index]->type == PSEG_TYPE_PERI && "coproc psegname attribute must refer to a pseg of type PERI" ); |
---|
1347 | } |
---|
1348 | else { |
---|
1349 | printf("[XML ERROR] pseg not found for coproc %d / clusterid = %d / psegname = %s\n", |
---|
1350 | coproc_index, cluster_index, str ); |
---|
1351 | exit(1); |
---|
1352 | } |
---|
1353 | |
---|
1354 | ////////// set port_offset |
---|
1355 | coproc[coproc_index]->port_offset = cp_port_index; |
---|
1356 | |
---|
1357 | #if XML_PARSER_DEBUG |
---|
1358 | printf(" port_offset = %d\n", cp_port_index); |
---|
1359 | #endif |
---|
1360 | |
---|
1361 | int status = xmlTextReaderRead(reader); |
---|
1362 | while (status == 1) { |
---|
1363 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
1364 | |
---|
1365 | if (strcmp(tag, "port") == 0 ) { |
---|
1366 | cpPortNode(reader); |
---|
1367 | } |
---|
1368 | else if (strcmp(tag, "#text") == 0 ) { } |
---|
1369 | else if (strcmp(tag, "#comment") == 0 ) { } |
---|
1370 | else if (strcmp(tag, "coproc") == 0 ) { |
---|
1371 | coproc[coproc_index]->ports = cp_port_loc_index; |
---|
1372 | cluster[cluster_index]->coprocs++; |
---|
1373 | coproc_loc_index++; |
---|
1374 | coproc_index++; |
---|
1375 | return; |
---|
1376 | } |
---|
1377 | else { |
---|
1378 | printf("[XML ERROR] Unknown tag %s", tag); |
---|
1379 | exit(1); |
---|
1380 | } |
---|
1381 | status = xmlTextReaderRead(reader); |
---|
1382 | } |
---|
1383 | } // end coprocNode() |
---|
1384 | |
---|
1385 | |
---|
1386 | /////////////////////////////////////// |
---|
1387 | void irqNode(xmlTextReaderPtr reader) { |
---|
1388 | unsigned int ok; |
---|
1389 | unsigned int value; |
---|
1390 | char * str; |
---|
1391 | |
---|
1392 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { |
---|
1393 | return; |
---|
1394 | } |
---|
1395 | |
---|
1396 | if (irq_index >= MAX_IRQS) { |
---|
1397 | printf("[XML ERROR] The number of irqs is larger than %d\n", MAX_IRQS); |
---|
1398 | } |
---|
1399 | |
---|
1400 | #if XML_PARSER_DEBUG |
---|
1401 | printf(" irq %d\n", irq_loc_index); |
---|
1402 | #endif |
---|
1403 | |
---|
1404 | irq[irq_index] = (mapping_irq_t *) malloc(sizeof(mapping_irq_t)); |
---|
1405 | |
---|
1406 | ///////// get type attribute |
---|
1407 | str = getStringValue(reader, "type", &ok); |
---|
1408 | if (ok) { |
---|
1409 | #if XML_PARSER_DEBUG |
---|
1410 | printf(" type = %s\n", str); |
---|
1411 | #endif |
---|
1412 | if (strcmp(str, "HARD") == 0 ) { |
---|
1413 | irq[irq_index]->type = 0; |
---|
1414 | } |
---|
1415 | else { |
---|
1416 | irq[irq_index]->type = 1; |
---|
1417 | } |
---|
1418 | } |
---|
1419 | else { |
---|
1420 | printf("[XML ERROR] missing IRQ <type> for processor %d in cluster %d\n", |
---|
1421 | cluster_index, proc_loc_index); |
---|
1422 | exit(1); |
---|
1423 | } |
---|
1424 | |
---|
1425 | ///////// get icuid attribute |
---|
1426 | value = getIntValue(reader, "icuid", &ok); |
---|
1427 | if (ok) { |
---|
1428 | #if XML_PARSER_DEBUG |
---|
1429 | printf(" icuid = %d\n", value); |
---|
1430 | #endif |
---|
1431 | irq[irq_index]->icuid = value; |
---|
1432 | if (value >= 32) { |
---|
1433 | printf("[XML ERROR] IRQ <icuid> too large for processor %d in cluster %d\n", |
---|
1434 | cluster_index, proc_loc_index); |
---|
1435 | exit(1); |
---|
1436 | } |
---|
1437 | } |
---|
1438 | else { |
---|
1439 | printf("[XML ERROR] missing IRQ <icuid> for processor %d in cluster %d\n", |
---|
1440 | cluster_index, proc_loc_index); |
---|
1441 | exit(1); |
---|
1442 | } |
---|
1443 | |
---|
1444 | ///////// get isr attribute |
---|
1445 | str = getStringValue(reader, "isr", &ok); |
---|
1446 | if (ok) { |
---|
1447 | #if XML_PARSER_DEBUG |
---|
1448 | printf(" isr = %s\n", str); |
---|
1449 | #endif |
---|
1450 | if (strcmp(str, "ISR_SWITCH" ) == 0) { irq[irq_index]->isr = ISR_SWITCH; } |
---|
1451 | else if (strcmp(str, "ISR_IOC" ) == 0) { irq[irq_index]->isr = ISR_IOC; } |
---|
1452 | else if (strcmp(str, "ISR_DMA" ) == 0) { irq[irq_index]->isr = ISR_DMA; } |
---|
1453 | else if (strcmp(str, "ISR_TTY" ) == 0) { irq[irq_index]->isr = ISR_TTY; } |
---|
1454 | else if (strcmp(str, "ISR_TIMER" ) == 0) { irq[irq_index]->isr = ISR_TIMER; } |
---|
1455 | else { |
---|
1456 | printf("[XML ERROR] illegal IRQ <isr> for processor %d in cluster %d\n", |
---|
1457 | cluster_index, proc_loc_index); |
---|
1458 | exit(1); |
---|
1459 | } |
---|
1460 | #if XML_PARSER_DEBUG |
---|
1461 | printf(" isrnum = %d\n", irq[irq_index]->isr); |
---|
1462 | #endif |
---|
1463 | } |
---|
1464 | else { |
---|
1465 | printf("[XML ERROR] missing IRQ <isr> for processor %d in cluster %d\n", |
---|
1466 | cluster_index, proc_loc_index); |
---|
1467 | exit(1); |
---|
1468 | } |
---|
1469 | |
---|
1470 | ///////// get channel attribute (optionnal : 0 if missing) |
---|
1471 | value = getIntValue(reader, "channel", &ok); |
---|
1472 | if (ok) { |
---|
1473 | #if XML_PARSER_DEBUG |
---|
1474 | printf(" channel = %d\n", value); |
---|
1475 | #endif |
---|
1476 | irq[irq_index]->channel = value; |
---|
1477 | } |
---|
1478 | else { |
---|
1479 | irq[irq_index]->channel = 0; |
---|
1480 | } |
---|
1481 | |
---|
1482 | irq_index++; |
---|
1483 | irq_loc_index++; |
---|
1484 | |
---|
1485 | } // end irqNode |
---|
1486 | |
---|
1487 | |
---|
1488 | ///////////////////////////////////////// |
---|
1489 | void procNode(xmlTextReaderPtr reader) { |
---|
1490 | unsigned int ok; |
---|
1491 | unsigned int value; |
---|
1492 | |
---|
1493 | irq_loc_index = 0; |
---|
1494 | |
---|
1495 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { |
---|
1496 | return; |
---|
1497 | } |
---|
1498 | |
---|
1499 | if (proc_index >= MAX_PROCS) { |
---|
1500 | printf("[XML ERROR] The number of procs is larger than %d\n", MAX_PROCS); |
---|
1501 | } |
---|
1502 | |
---|
1503 | #if XML_PARSER_DEBUG |
---|
1504 | printf("\n proc %d\n", proc_index); |
---|
1505 | #endif |
---|
1506 | |
---|
1507 | proc[proc_index] = (mapping_proc_t *) malloc(sizeof(mapping_proc_t)); |
---|
1508 | |
---|
1509 | |
---|
1510 | /////////// get index attribute (optional) |
---|
1511 | value = getIntValue(reader, "index", &ok); |
---|
1512 | if (ok && (value != proc_loc_index)) { |
---|
1513 | printf("[XML ERROR] wrong proc index / expected value is %d", |
---|
1514 | proc_loc_index); |
---|
1515 | exit(1); |
---|
1516 | } |
---|
1517 | |
---|
1518 | ////////// set irq_offset attribute |
---|
1519 | proc[proc_index]->irq_offset = irq_index; |
---|
1520 | |
---|
1521 | #if XML_PARSER_DEBUG |
---|
1522 | printf(" irq_offset = %d\n", irq_index); |
---|
1523 | #endif |
---|
1524 | |
---|
1525 | int status = xmlTextReaderRead(reader); |
---|
1526 | while (status == 1) { |
---|
1527 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
1528 | |
---|
1529 | if (strcmp(tag, "irq") == 0) { |
---|
1530 | irqNode(reader); |
---|
1531 | } |
---|
1532 | else if (strcmp(tag, "#text") == 0) { } |
---|
1533 | else if (strcmp(tag, "#comment") == 0) { } |
---|
1534 | else if (strcmp(tag, "proc") == 0) { |
---|
1535 | proc[proc_index]->irqs = irq_loc_index; |
---|
1536 | cluster[cluster_index]->procs++; |
---|
1537 | proc_loc_index++; |
---|
1538 | proc_index++; |
---|
1539 | return; |
---|
1540 | } |
---|
1541 | else { |
---|
1542 | printf("[XML ERROR] Unknown tag %s", tag); |
---|
1543 | exit(1); |
---|
1544 | } |
---|
1545 | status = xmlTextReaderRead(reader); |
---|
1546 | } |
---|
1547 | } // end procNode() |
---|
1548 | |
---|
1549 | |
---|
1550 | ////////////////////////////////////////// |
---|
1551 | void psegNode(xmlTextReaderPtr reader) { |
---|
1552 | unsigned int ok; |
---|
1553 | paddr_t ll_value; |
---|
1554 | char * str; |
---|
1555 | |
---|
1556 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { |
---|
1557 | return; |
---|
1558 | } |
---|
1559 | |
---|
1560 | if (pseg_index >= MAX_PSEGS) { |
---|
1561 | printf("[XML ERROR] The number of psegs is larger than %d\n", MAX_PSEGS); |
---|
1562 | exit(1); |
---|
1563 | } |
---|
1564 | |
---|
1565 | #if XML_PARSER_DEBUG |
---|
1566 | printf(" pseg %d\n", pseg_index); |
---|
1567 | #endif |
---|
1568 | |
---|
1569 | pseg[pseg_index] = (mapping_pseg_t *) malloc(sizeof(mapping_pseg_t)); |
---|
1570 | |
---|
1571 | /////// get name attribute |
---|
1572 | str = getStringValue(reader, "name", &ok); |
---|
1573 | #if XML_PARSER_DEBUG |
---|
1574 | printf(" name = %s\n", str); |
---|
1575 | #endif |
---|
1576 | if (ok) { |
---|
1577 | strncpy(pseg[pseg_index]->name, str, 31); |
---|
1578 | } |
---|
1579 | else { |
---|
1580 | printf("[XML ERROR] illegal or missing <name> for pseg %d in cluster %d\n", |
---|
1581 | pseg_index, cluster_index); |
---|
1582 | exit(1); |
---|
1583 | } |
---|
1584 | |
---|
1585 | //////// get type attribute |
---|
1586 | str = getStringValue(reader, "type", &ok); |
---|
1587 | #if XML_PARSER_DEBUG |
---|
1588 | printf(" type = %s\n", str); |
---|
1589 | #endif |
---|
1590 | if (ok && (strcmp(str, "RAM" ) == 0)) { pseg[pseg_index]->type = PSEG_TYPE_RAM; } |
---|
1591 | else if (ok && (strcmp(str, "ROM" ) == 0)) { pseg[pseg_index]->type = PSEG_TYPE_ROM; } |
---|
1592 | else if (ok && (strcmp(str, "PERI") == 0)) { pseg[pseg_index]->type = PSEG_TYPE_PERI; } |
---|
1593 | else { |
---|
1594 | printf("[XML ERROR] illegal or missing <type> for pseg %s in cluster %d\n", |
---|
1595 | pseg[pseg_index]->name, cluster_index); |
---|
1596 | exit(1); |
---|
1597 | } |
---|
1598 | |
---|
1599 | //////// get base attribute |
---|
1600 | ll_value = getPaddrValue(reader, "base", &ok); |
---|
1601 | #if XML_PARSER_DEBUG |
---|
1602 | printf(" base = 0x%llx\n", ll_value); |
---|
1603 | #endif |
---|
1604 | if (ok) { |
---|
1605 | pseg[pseg_index]->base = ll_value; |
---|
1606 | } |
---|
1607 | else { |
---|
1608 | printf("[XML ERROR] illegal or missing <base> for pseg %s in cluster %d\n", |
---|
1609 | pseg[pseg_index]->name, cluster_index); |
---|
1610 | exit(1); |
---|
1611 | } |
---|
1612 | |
---|
1613 | //////// get length attribute |
---|
1614 | ll_value = getPaddrValue(reader, "length", &ok); |
---|
1615 | #if XML_PARSER_DEBUG |
---|
1616 | printf(" length = 0x%llx\n", ll_value); |
---|
1617 | #endif |
---|
1618 | if (ok) { |
---|
1619 | pseg[pseg_index]->length = ll_value; |
---|
1620 | } |
---|
1621 | else { |
---|
1622 | printf("[XML ERROR] illegal or missing <length> for pseg %s in cluster %d\n", |
---|
1623 | pseg[pseg_index]->name, cluster_index); |
---|
1624 | exit(1); |
---|
1625 | } |
---|
1626 | |
---|
1627 | //////// set cluster attribute |
---|
1628 | pseg[pseg_index]->cluster = cluster_index; |
---|
1629 | |
---|
1630 | pseg_index++; |
---|
1631 | cluster[cluster_index]->psegs++; |
---|
1632 | } // end psegNode() |
---|
1633 | |
---|
1634 | |
---|
1635 | ///////////////////////////////////////// |
---|
1636 | void clusterNode(xmlTextReaderPtr reader) |
---|
1637 | { |
---|
1638 | unsigned int ok; |
---|
1639 | unsigned int value; |
---|
1640 | |
---|
1641 | cluster[cluster_index] = (mapping_cluster_t *) malloc(sizeof(mapping_cluster_t)); |
---|
1642 | |
---|
1643 | //initialise all variables |
---|
1644 | //they will be incremented by *Node() functions |
---|
1645 | //FIXME: calloc? |
---|
1646 | cluster[cluster_index]->psegs = 0; |
---|
1647 | cluster[cluster_index]->procs = 0; |
---|
1648 | cluster[cluster_index]->coprocs = 0; |
---|
1649 | cluster[cluster_index]->periphs = 0; |
---|
1650 | |
---|
1651 | |
---|
1652 | //initialise global variables |
---|
1653 | //TODO: delete those three |
---|
1654 | proc_loc_index = 0; |
---|
1655 | coproc_loc_index = 0; |
---|
1656 | periph_loc_index = 0; |
---|
1657 | |
---|
1658 | // for replicated periph |
---|
1659 | found_timer = 0; |
---|
1660 | found_icu = 0; |
---|
1661 | found_dma = 0; |
---|
1662 | found_mmc = 0; |
---|
1663 | |
---|
1664 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { |
---|
1665 | return; |
---|
1666 | } |
---|
1667 | |
---|
1668 | // checking source file consistency |
---|
1669 | if (cluster_index >= header->clusters) { |
---|
1670 | printf("[XML ERROR] The cluster index is too large : %d\n", cluster_index); |
---|
1671 | exit(1); |
---|
1672 | } |
---|
1673 | |
---|
1674 | #if XML_PARSER_DEBUG |
---|
1675 | printf(" cluster %d\n", cluster_index); |
---|
1676 | #endif |
---|
1677 | |
---|
1678 | |
---|
1679 | /////////// check cluster index attribute (optional) |
---|
1680 | value = getIntValue(reader, "index", &ok); |
---|
1681 | if (ok && (value != cluster_index)) { |
---|
1682 | printf("[XML ERROR] wrong cluster index / expected value is %d", |
---|
1683 | cluster_index); |
---|
1684 | exit(1); |
---|
1685 | } |
---|
1686 | |
---|
1687 | ////////// set offsets |
---|
1688 | cluster[cluster_index]->pseg_offset = pseg_index; |
---|
1689 | cluster[cluster_index]->proc_offset = proc_index; |
---|
1690 | cluster[cluster_index]->coproc_offset = coproc_index; |
---|
1691 | cluster[cluster_index]->periph_offset = periph_index; |
---|
1692 | |
---|
1693 | #if XML_PARSER_DEBUG |
---|
1694 | printf(" pseg_offset = %d\n", pseg_index); |
---|
1695 | printf(" proc_offset = %d\n", proc_index); |
---|
1696 | printf(" coproc_offset = %d\n", coproc_index); |
---|
1697 | printf(" periph_offset = %d\n", coproc_index); |
---|
1698 | #endif |
---|
1699 | |
---|
1700 | ////////// get psegs, procs, coprocs and periphs |
---|
1701 | int status = xmlTextReaderRead(reader); |
---|
1702 | |
---|
1703 | while (status == 1) |
---|
1704 | { |
---|
1705 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
1706 | |
---|
1707 | if (strcmp(tag, "pseg") == 0) psegNode(reader); |
---|
1708 | else if (strcmp(tag, "proc") == 0) procNode(reader); |
---|
1709 | else if (strcmp(tag, "coproc") == 0) coprocNode(reader); |
---|
1710 | else if (strcmp(tag, "periph") == 0) periphNode(reader); |
---|
1711 | else if (strcmp(tag, "#text") == 0) { } |
---|
1712 | else if (strcmp(tag, "#comment") == 0) { } |
---|
1713 | else if (strcmp(tag, "cluster") == 0) |
---|
1714 | { |
---|
1715 | |
---|
1716 | ////////////////// peripherals checks ///////////////////////// |
---|
1717 | if ((found_timer && use_xicu) || (!found_timer && !use_xicu)) |
---|
1718 | { |
---|
1719 | printf("[XML ERROR] illegal or missing timer peripheral in cluster %d\n", cluster_index); |
---|
1720 | exit(1); |
---|
1721 | } |
---|
1722 | |
---|
1723 | if (!found_icu) |
---|
1724 | { |
---|
1725 | printf("[XML ERROR] illegal or missing icu peripheral in cluster %d\n", cluster_index); |
---|
1726 | exit(1); |
---|
1727 | } |
---|
1728 | |
---|
1729 | if (!found_dma) |
---|
1730 | { |
---|
1731 | printf("[XML ERROR] illegal or missing dma peripheral in cluster %d\n", cluster_index); |
---|
1732 | exit(1); |
---|
1733 | } |
---|
1734 | |
---|
1735 | |
---|
1736 | if (nb_proc_max < cluster[cluster_index]->procs) |
---|
1737 | { |
---|
1738 | nb_proc_max = cluster[cluster_index]->procs; |
---|
1739 | } |
---|
1740 | |
---|
1741 | #if XML_PARSER_DEBUG |
---|
1742 | printf(" psegs = %d\n", cluster[cluster_index]->psegs); |
---|
1743 | printf(" procs = %d\n", cluster[cluster_index]->procs); |
---|
1744 | printf(" coprocs = %d\n", cluster[cluster_index]->coprocs); |
---|
1745 | printf(" periphs = %d\n", cluster[cluster_index]->periphs); |
---|
1746 | printf(" end cluster %d\n", cluster_index); |
---|
1747 | #endif |
---|
1748 | cluster_index++; |
---|
1749 | return; |
---|
1750 | } |
---|
1751 | status = xmlTextReaderRead(reader); |
---|
1752 | } |
---|
1753 | } // end clusterNode() |
---|
1754 | |
---|
1755 | |
---|
1756 | ////////////////////////////////////////////// |
---|
1757 | void clusterSetNode(xmlTextReaderPtr reader) |
---|
1758 | { |
---|
1759 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { return; } |
---|
1760 | |
---|
1761 | #if XML_PARSER_DEBUG |
---|
1762 | printf("\n clusters set\n"); |
---|
1763 | #endif |
---|
1764 | |
---|
1765 | int status = xmlTextReaderRead(reader); |
---|
1766 | while (status == 1) |
---|
1767 | { |
---|
1768 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
1769 | |
---|
1770 | if (strcmp(tag, "cluster") == 0) { clusterNode(reader); } |
---|
1771 | else if (strcmp(tag, "#text") == 0) { } |
---|
1772 | else if (strcmp(tag, "#comment") == 0) { } |
---|
1773 | else if (strcmp(tag, "clusterset") == 0) |
---|
1774 | { |
---|
1775 | // checking source file consistency |
---|
1776 | if (cluster_index != header->clusters) |
---|
1777 | { |
---|
1778 | printf("[XML ERROR] Wrong number of clusters\n"); |
---|
1779 | exit(1); |
---|
1780 | } |
---|
1781 | |
---|
1782 | // At least one TTY terminal for system boot |
---|
1783 | if (header->tty_cluster == 0xFFFFFFFF) |
---|
1784 | { |
---|
1785 | printf("[XML ERROR] illegal or missing tty peripheral"); |
---|
1786 | exit(1); |
---|
1787 | } |
---|
1788 | |
---|
1789 | #if XML_PARSER_DEBUG |
---|
1790 | printf(" end cluster set\n\n"); |
---|
1791 | #endif |
---|
1792 | header->psegs = pseg_index; |
---|
1793 | header->procs = proc_index; |
---|
1794 | header->irqs = irq_index; |
---|
1795 | header->coprocs = coproc_index; |
---|
1796 | header->cp_ports = cp_port_index; |
---|
1797 | header->periphs = periph_index; |
---|
1798 | return; |
---|
1799 | } |
---|
1800 | else { |
---|
1801 | printf("[XML ERROR] Unknown tag in clusterset node : %s",tag); |
---|
1802 | exit(1); |
---|
1803 | } |
---|
1804 | status = xmlTextReaderRead(reader); |
---|
1805 | } |
---|
1806 | } // end clusterSetNode() |
---|
1807 | |
---|
1808 | |
---|
1809 | ///////////////////////////////////////////// |
---|
1810 | void globalSetNode(xmlTextReaderPtr reader) { |
---|
1811 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { |
---|
1812 | return; |
---|
1813 | } |
---|
1814 | |
---|
1815 | #if XML_PARSER_DEBUG |
---|
1816 | printf(" globals set\n"); |
---|
1817 | #endif |
---|
1818 | |
---|
1819 | int status = xmlTextReaderRead(reader); |
---|
1820 | while (status == 1) |
---|
1821 | { |
---|
1822 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
1823 | |
---|
1824 | if (strcmp(tag, "vseg") == 0) { vsegNode(reader); } |
---|
1825 | else if (strcmp(tag, "#text") == 0) { } |
---|
1826 | else if (strcmp(tag, "#comment") == 0) { } |
---|
1827 | else if (strcmp(tag, "globalset") == 0) { |
---|
1828 | #if XML_PARSER_DEBUG |
---|
1829 | printf(" end global set\n\n"); |
---|
1830 | #endif |
---|
1831 | header->globals = vseg_index; |
---|
1832 | vseg_loc_index = 0; |
---|
1833 | return; |
---|
1834 | } |
---|
1835 | else { |
---|
1836 | printf("[XML ERROR] Unknown tag in globalset node : %s",tag); |
---|
1837 | exit(1); |
---|
1838 | } |
---|
1839 | status = xmlTextReaderRead(reader); |
---|
1840 | } |
---|
1841 | } // end globalSetNode() |
---|
1842 | |
---|
1843 | |
---|
1844 | ///////////////////////////////////////////// |
---|
1845 | void vspaceSetNode(xmlTextReaderPtr reader) { |
---|
1846 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { |
---|
1847 | return; |
---|
1848 | } |
---|
1849 | |
---|
1850 | #if XML_PARSER_DEBUG |
---|
1851 | printf("\n vspaces set\n"); |
---|
1852 | #endif |
---|
1853 | |
---|
1854 | int status = xmlTextReaderRead ( reader ); |
---|
1855 | while (status == 1) { |
---|
1856 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
1857 | |
---|
1858 | if (strcmp(tag, "vspace") == 0) { |
---|
1859 | vspaceNode(reader); |
---|
1860 | } |
---|
1861 | else if (strcmp(tag, "#text" ) == 0 ) { } |
---|
1862 | else if (strcmp(tag, "#comment" ) == 0 ) { } |
---|
1863 | else if (strcmp(tag, "vspaceset") == 0 ) { |
---|
1864 | // checking source file consistency |
---|
1865 | if (vspace_index != header->vspaces) { |
---|
1866 | printf("[XML ERROR] Wrong number of vspaces\n"); |
---|
1867 | exit(1); |
---|
1868 | } |
---|
1869 | else { |
---|
1870 | header->vsegs = vseg_index; |
---|
1871 | header->vobjs = vobj_index; |
---|
1872 | header->tasks = task_index; |
---|
1873 | return; |
---|
1874 | } |
---|
1875 | } |
---|
1876 | else { |
---|
1877 | printf("[XML ERROR] Unknown tag in vspaceset node : %s",tag); |
---|
1878 | exit(1); |
---|
1879 | } |
---|
1880 | status = xmlTextReaderRead(reader); |
---|
1881 | } |
---|
1882 | } // end globalSetNode() |
---|
1883 | |
---|
1884 | |
---|
1885 | ////////////////////////////////////////// |
---|
1886 | void headerNode(xmlTextReaderPtr reader) |
---|
1887 | { |
---|
1888 | char * name; |
---|
1889 | unsigned int value; |
---|
1890 | unsigned int ok; |
---|
1891 | |
---|
1892 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { return; } |
---|
1893 | |
---|
1894 | #if XML_PARSER_DEBUG |
---|
1895 | printf("mapping_info\n"); |
---|
1896 | #endif |
---|
1897 | |
---|
1898 | header = (mapping_header_t *) malloc(sizeof(mapping_header_t)); |
---|
1899 | |
---|
1900 | ////////// get name attribute |
---|
1901 | name = getStringValue(reader, "name", &ok); |
---|
1902 | if (ok) { |
---|
1903 | #if XML_PARSER_DEBUG |
---|
1904 | printf(" name = %s\n", name); |
---|
1905 | #endif |
---|
1906 | strncpy( header->name, name, 31); |
---|
1907 | } |
---|
1908 | else { |
---|
1909 | printf("[XML ERROR] illegal or missing <name> attribute in header\n"); |
---|
1910 | exit(1); |
---|
1911 | } |
---|
1912 | |
---|
1913 | /////////// get cluster_x attribute |
---|
1914 | cluster_x = getIntValue(reader, "cluster_x", &ok); |
---|
1915 | if (ok) { |
---|
1916 | #if XML_PARSER_DEBUG |
---|
1917 | printf(" cluster_x = %d\n", cluster_x); |
---|
1918 | #endif |
---|
1919 | header->cluster_x = cluster_x; |
---|
1920 | } |
---|
1921 | else { |
---|
1922 | printf("[XML ERROR] illegal or missing <cluster_x> attribute in header\n"); |
---|
1923 | exit(1); |
---|
1924 | } |
---|
1925 | |
---|
1926 | /////////// get cluster_y attribute |
---|
1927 | cluster_y = getIntValue(reader, "cluster_y", &ok); |
---|
1928 | if (ok) { |
---|
1929 | #if XML_PARSER_DEBUG |
---|
1930 | printf(" cluster_y = %d\n", cluster_y); |
---|
1931 | #endif |
---|
1932 | header->cluster_y = cluster_y; |
---|
1933 | } |
---|
1934 | else { |
---|
1935 | printf("[XML ERROR] illegal or missing <cluster_y> attribute in header\n"); |
---|
1936 | exit(1); |
---|
1937 | } |
---|
1938 | |
---|
1939 | //check the number of cluster |
---|
1940 | value = cluster_x * cluster_y; |
---|
1941 | if (value >= MAX_CLUSTERS) { |
---|
1942 | printf("[XML ERROR] The number of clusters is larger than %d\n", MAX_CLUSTERS); |
---|
1943 | exit(1); |
---|
1944 | } |
---|
1945 | |
---|
1946 | header->clusters = value; |
---|
1947 | |
---|
1948 | #if XML_PARSER_DEBUG |
---|
1949 | printf(" clusters = %d\n", value); |
---|
1950 | #endif |
---|
1951 | |
---|
1952 | ///////// get vspaces attribute |
---|
1953 | value = getIntValue(reader, "vspaces", &ok); |
---|
1954 | if (ok) { |
---|
1955 | if (value >= MAX_VSPACES) { |
---|
1956 | printf("[XML ERROR] The number of vspaces is larger than %d\n", MAX_VSPACES); |
---|
1957 | exit(1); |
---|
1958 | } |
---|
1959 | #if XML_PARSER_DEBUG |
---|
1960 | printf(" vspaces = %d\n", value); |
---|
1961 | #endif |
---|
1962 | header->vspaces = value; |
---|
1963 | } |
---|
1964 | else { |
---|
1965 | printf("[XML ERROR] illegal or missing <vspaces> attribute in mapping\n"); |
---|
1966 | exit(1); |
---|
1967 | } |
---|
1968 | |
---|
1969 | //////// initialise non replicated peripherals cluster index |
---|
1970 | header->tty_cluster = 0xFFFFFFFF; |
---|
1971 | header->nic_cluster = 0xFFFFFFFF; |
---|
1972 | header->ioc_cluster = 0xFFFFFFFF; |
---|
1973 | header->fbf_cluster = 0xFFFFFFFF; |
---|
1974 | header->cma_cluster = 0xFFFFFFFF; |
---|
1975 | header->iob_cluster = 0xFFFFFFFF; |
---|
1976 | header->tty_cluster_bis = 0xFFFFFFFF; |
---|
1977 | header->nic_cluster_bis = 0xFFFFFFFF; |
---|
1978 | header->ioc_cluster_bis = 0xFFFFFFFF; |
---|
1979 | header->fbf_cluster_bis = 0xFFFFFFFF; |
---|
1980 | header->cma_cluster_bis = 0xFFFFFFFF; |
---|
1981 | header->iob_cluster_bis = 0xFFFFFFFF; |
---|
1982 | |
---|
1983 | ///////// set signature |
---|
1984 | header->signature = IN_MAPPING_SIGNATURE; |
---|
1985 | |
---|
1986 | int status = xmlTextReaderRead(reader); |
---|
1987 | while (status == 1) { |
---|
1988 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
1989 | |
---|
1990 | if (strcmp(tag, "clusterset") == 0) { |
---|
1991 | clusterSetNode(reader); |
---|
1992 | } |
---|
1993 | else if (strcmp(tag, "globalset") == 0) { globalSetNode(reader); } |
---|
1994 | else if (strcmp(tag, "vspaceset") == 0) { vspaceSetNode(reader); } |
---|
1995 | else if (strcmp(tag, "#text") == 0) { } |
---|
1996 | else if (strcmp(tag, "#comment") == 0) { } |
---|
1997 | else if (strcmp(tag, "mapping_info") == 0) { |
---|
1998 | #if XML_PARSER_DEBUG |
---|
1999 | printf("end mapping_info\n"); |
---|
2000 | #endif |
---|
2001 | return; |
---|
2002 | } |
---|
2003 | else { |
---|
2004 | printf("[XML ERROR] Unknown tag in header node : %s\n",tag); |
---|
2005 | exit(1); |
---|
2006 | } |
---|
2007 | status = xmlTextReaderRead(reader); |
---|
2008 | } |
---|
2009 | } // end headerNode() |
---|
2010 | |
---|
2011 | |
---|
2012 | /////////////////////////////////////// |
---|
2013 | void BuildTable(int fdout, const char * type, unsigned int nb_elem, |
---|
2014 | unsigned int elem_size, char ** table) { |
---|
2015 | unsigned int i; |
---|
2016 | // write element |
---|
2017 | for (i = 0; i < nb_elem; i++) { |
---|
2018 | if (elem_size != write(fdout, table[i], elem_size)) { |
---|
2019 | printf("function %s: %s(%d) write error \n", __FUNCTION__, type, i); |
---|
2020 | exit(1); |
---|
2021 | } |
---|
2022 | |
---|
2023 | #if XML_PARSER_DEBUG |
---|
2024 | printf("Building binary: writing %s %d\n", type, i); |
---|
2025 | #endif |
---|
2026 | } |
---|
2027 | } |
---|
2028 | |
---|
2029 | |
---|
2030 | int open_file(const char * file_path) { |
---|
2031 | |
---|
2032 | //open file |
---|
2033 | int fdout = open( file_path, (O_CREAT | O_RDWR), (S_IWUSR | S_IRUSR) ); |
---|
2034 | if (fdout < 0) { |
---|
2035 | perror("open"); |
---|
2036 | exit(1); |
---|
2037 | } |
---|
2038 | |
---|
2039 | //reinitialise the file |
---|
2040 | if (ftruncate(fdout, 0)) { |
---|
2041 | perror("truncate"); |
---|
2042 | exit(1); |
---|
2043 | } |
---|
2044 | |
---|
2045 | //#if XML_PARSER_DEBUG |
---|
2046 | printf("%s\n", file_path); |
---|
2047 | //#endif |
---|
2048 | |
---|
2049 | return fdout; |
---|
2050 | } |
---|
2051 | |
---|
2052 | |
---|
2053 | /////////////////////////// |
---|
2054 | void buildBin(const char * file_path) { |
---|
2055 | unsigned int length; |
---|
2056 | |
---|
2057 | int fdout = open_file(file_path); |
---|
2058 | |
---|
2059 | // write header to binary file |
---|
2060 | length = write(fdout, (char *) header, sizeof(mapping_header_t)); |
---|
2061 | if (length != sizeof(mapping_header_t)) { |
---|
2062 | printf("write header error : length = %d \n", length); |
---|
2063 | exit(1); |
---|
2064 | } |
---|
2065 | |
---|
2066 | // write clusters |
---|
2067 | BuildTable(fdout, "cluster", cluster_index, sizeof(mapping_cluster_t), (char **) cluster); |
---|
2068 | // write psegs |
---|
2069 | BuildTable(fdout, "pseg", pseg_index, sizeof(mapping_pseg_t), (char **) pseg); |
---|
2070 | // write vspaces |
---|
2071 | BuildTable(fdout, "vspace", vspace_index, sizeof(mapping_vspace_t), (char **) vspace); |
---|
2072 | // write vsegs |
---|
2073 | BuildTable(fdout, "vseg", vseg_index, sizeof(mapping_vseg_t), (char **) vseg); |
---|
2074 | // write vobjs |
---|
2075 | BuildTable(fdout, "vobj", vobj_index, sizeof(mapping_vobj_t), (char **) vobj); |
---|
2076 | // write tasks array |
---|
2077 | BuildTable(fdout, "task", task_index, sizeof(mapping_task_t), (char **) task); |
---|
2078 | //building procs array |
---|
2079 | BuildTable(fdout, "proc", proc_index, sizeof(mapping_proc_t), (char **) proc); |
---|
2080 | //building irqs array |
---|
2081 | BuildTable(fdout, "irq", irq_index, sizeof(mapping_irq_t), (char **) irq); |
---|
2082 | //building coprocs array |
---|
2083 | BuildTable(fdout, "coproc", coproc_index, sizeof(mapping_coproc_t), (char **) coproc); |
---|
2084 | //building cp_ports array |
---|
2085 | BuildTable(fdout, "cp_port", cp_port_index, sizeof(mapping_cp_port_t),(char **) cp_port); |
---|
2086 | //building periphs array |
---|
2087 | BuildTable(fdout, "periph", periph_index, sizeof(mapping_periph_t), (char **) periph); |
---|
2088 | |
---|
2089 | close(fdout); |
---|
2090 | |
---|
2091 | } // end buildBin() |
---|
2092 | |
---|
2093 | |
---|
2094 | /////////////////////////////////////////////////////////////////////// |
---|
2095 | // this function set the value the vobj_id fiels of all cp_ports |
---|
2096 | /////////////////////////////////////////////////////////////////////// |
---|
2097 | void prepareBuild() |
---|
2098 | { |
---|
2099 | unsigned int i; |
---|
2100 | //asign for all cp_ports the correct vspaceid and vobjid |
---|
2101 | for (i = 0; i < cp_port_index; i++) { |
---|
2102 | int vspace_id = getVspaceId(cp_port_vobj_ref[i]->vspace_name); |
---|
2103 | if (vspace_id < 0) { |
---|
2104 | printf("[XML ERROR] illegal <vspacename> for cp_port %d,\n", i); |
---|
2105 | exit(1); |
---|
2106 | } |
---|
2107 | cp_port[i]->vspaceid = vspace_id; |
---|
2108 | |
---|
2109 | int vobj_id = getVobjLocId(vspace_id, cp_port_vobj_ref[i]->vobj_name, vspace[vspace_id]->vobjs); |
---|
2110 | if (vobj_id >= 0) { |
---|
2111 | |
---|
2112 | #if XML_PARSER_DEBUG |
---|
2113 | printf("\ncp_port = %d\n", i); |
---|
2114 | printf(" vspace_name = %s\n", cp_port_vobj_ref[i]->vspace_name); |
---|
2115 | printf(" vobj_name = %s\n", cp_port_vobj_ref[i]->vobj_name); |
---|
2116 | printf(" vobj_index = %d\n", vobj_id); |
---|
2117 | #endif |
---|
2118 | cp_port[i]->mwmr_vobjid = vobj_id; |
---|
2119 | |
---|
2120 | assert((vobj[ vspace[vspace_id]->vobj_offset + vobj_id]->type == VOBJ_TYPE_MWMR) |
---|
2121 | && "coproc ports have to refer to a vobj of type MWMR"); |
---|
2122 | } |
---|
2123 | else { |
---|
2124 | printf("[XML ERROR] illegal <vobjname> for cp_port %d,\n", i); |
---|
2125 | exit(1); |
---|
2126 | } |
---|
2127 | } |
---|
2128 | } |
---|
2129 | |
---|
2130 | ////////////////////////////////////////// |
---|
2131 | void file_write(int fdout, char * towrite) |
---|
2132 | { |
---|
2133 | unsigned int size = strlen(towrite); |
---|
2134 | if (size != write(fdout, towrite, size)) |
---|
2135 | { |
---|
2136 | printf("file_write error"); |
---|
2137 | exit(1); |
---|
2138 | } |
---|
2139 | } |
---|
2140 | |
---|
2141 | ////////////////////////////////////////////////// |
---|
2142 | void def_int_write(int fdout, char * def, int num) |
---|
2143 | { |
---|
2144 | char buf[64]; |
---|
2145 | sprintf(buf, "#define\t %s %d\n", def, num); |
---|
2146 | file_write(fdout, buf); |
---|
2147 | } |
---|
2148 | |
---|
2149 | ////////////////////////////////////////////////// |
---|
2150 | void def_hex_write(int fdout, char * def, int num) |
---|
2151 | { |
---|
2152 | char buf[64]; |
---|
2153 | sprintf(buf, "#define\t %s 0x%x\n", def, num); |
---|
2154 | file_write(fdout, buf); |
---|
2155 | } |
---|
2156 | |
---|
2157 | /////////////////////////////////// |
---|
2158 | void genHd(const char * file_path) |
---|
2159 | { |
---|
2160 | int fdout = open_file(file_path); |
---|
2161 | |
---|
2162 | char * prol = "/* Generated from the mapping_info file */\n\n"; |
---|
2163 | char * ifdef = "#ifndef _HD_CONFIG_H\n#define _HD_CONFIG_H\n\n"; |
---|
2164 | char * epil = "\n#endif //_HD_CONFIG_H"; |
---|
2165 | |
---|
2166 | file_write(fdout, prol); |
---|
2167 | file_write(fdout, ifdef); |
---|
2168 | |
---|
2169 | def_int_write(fdout, "CLUSTER_X ", cluster_x); |
---|
2170 | def_int_write(fdout, "CLUSTER_Y ", cluster_y); |
---|
2171 | def_int_write(fdout, "NB_CLUSTERS ", cluster_index); |
---|
2172 | def_int_write(fdout, "NB_PROCS_MAX ", nb_proc_max); |
---|
2173 | def_int_write(fdout, "NB_TASKS_MAX ", nb_tasks_max); |
---|
2174 | |
---|
2175 | file_write(fdout, "\n"); |
---|
2176 | |
---|
2177 | def_int_write(fdout, "NB_TIM_CHANNELS ", tim_channels); |
---|
2178 | def_int_write(fdout, "NB_DMA_CHANNELS ", dma_channels); |
---|
2179 | |
---|
2180 | file_write(fdout, "\n"); |
---|
2181 | |
---|
2182 | def_int_write(fdout, "NB_TTY_CHANNELS ", tty_channels); |
---|
2183 | def_int_write(fdout, "NB_IOC_CHANNELS ", ioc_channels); |
---|
2184 | def_int_write(fdout, "NB_NIC_CHANNELS ", nic_channels); |
---|
2185 | def_int_write(fdout, "NB_CMA_CHANNELS ", cma_channels); |
---|
2186 | |
---|
2187 | file_write(fdout, "\n"); |
---|
2188 | |
---|
2189 | def_int_write(fdout, "USE_XICU ", use_xicu); |
---|
2190 | def_int_write(fdout, "USE_IOB ", use_iob); |
---|
2191 | |
---|
2192 | file_write(fdout, epil); |
---|
2193 | |
---|
2194 | close(fdout); |
---|
2195 | } |
---|
2196 | |
---|
2197 | //////////////////////////////////////////////////////// |
---|
2198 | void ld_write(int fdout, char * seg, unsigned int addr) |
---|
2199 | { |
---|
2200 | char buf[64]; |
---|
2201 | sprintf(buf, "%s = 0x%x;\n", seg, addr); |
---|
2202 | file_write(fdout, buf); |
---|
2203 | } |
---|
2204 | |
---|
2205 | ////////////////////////////////// |
---|
2206 | void genLd(const char * file_path) |
---|
2207 | { |
---|
2208 | int fdout = open_file(file_path); |
---|
2209 | unsigned int count = 0; |
---|
2210 | unsigned int vseg_id; |
---|
2211 | |
---|
2212 | char * prol = "/* Generated from the mapping_info file */\n\n"; |
---|
2213 | file_write(fdout, prol); |
---|
2214 | |
---|
2215 | // boot and kernel segments |
---|
2216 | for (vseg_id = 0 ; vseg_id < header->vsegs ; vseg_id++) |
---|
2217 | { |
---|
2218 | if ( strcmp(vseg[vseg_id]->name, "seg_boot_code") == 0 ) |
---|
2219 | { |
---|
2220 | ld_write(fdout, "seg_boot_code_base ", vseg[vseg_id]->vbase); |
---|
2221 | count++; |
---|
2222 | } |
---|
2223 | else if ( strcmp(vseg[vseg_id]->name, "seg_boot_data") == 0 ) |
---|
2224 | { |
---|
2225 | ld_write(fdout, "seg_boot_data_base ", vseg[vseg_id]->vbase); |
---|
2226 | count++; |
---|
2227 | } |
---|
2228 | else if ( strcmp(vseg[vseg_id]->name, "seg_boot_stack") == 0 ) |
---|
2229 | { |
---|
2230 | ld_write(fdout, "seg_boot_stack_base ", vseg[vseg_id]->vbase); |
---|
2231 | count++; |
---|
2232 | } |
---|
2233 | else if ( strcmp(vseg[vseg_id]->name, "seg_boot_mapping") == 0 ) |
---|
2234 | { |
---|
2235 | ld_write(fdout, "seg_mapping_base ", vseg[vseg_id]->vbase); |
---|
2236 | count++; |
---|
2237 | } |
---|
2238 | else if ( strcmp(vseg[vseg_id]->name, "seg_kernel_code") == 0 ) |
---|
2239 | { |
---|
2240 | ld_write(fdout, "seg_kernel_code_base ", vseg[vseg_id]->vbase); |
---|
2241 | count++; |
---|
2242 | } |
---|
2243 | else if ( strcmp(vseg[vseg_id]->name, "seg_kernel_data") == 0 ) |
---|
2244 | { |
---|
2245 | ld_write(fdout, "seg_kernel_data_base ", vseg[vseg_id]->vbase); |
---|
2246 | count++; |
---|
2247 | } |
---|
2248 | else if ( strcmp(vseg[vseg_id]->name, "seg_kernel_uncdata") == 0 ) |
---|
2249 | { |
---|
2250 | ld_write(fdout, "seg_kernel_uncdata_base ", vseg[vseg_id]->vbase); |
---|
2251 | count++; |
---|
2252 | } |
---|
2253 | else if ( strcmp(vseg[vseg_id]->name, "seg_kernel_init") == 0 ) |
---|
2254 | { |
---|
2255 | ld_write(fdout, "seg_kernel_init_base ", vseg[vseg_id]->vbase); |
---|
2256 | count++; |
---|
2257 | } |
---|
2258 | } |
---|
2259 | if ( count != 8 ) |
---|
2260 | { |
---|
2261 | printf ("[XML ERROR] Missing Boot or Kernel vseg : only %d\n", count); |
---|
2262 | printf ("Mandatory segments are :\n"); |
---|
2263 | printf (" - seg_boot_code\n"); |
---|
2264 | printf (" - seg_boot_data\n"); |
---|
2265 | printf (" - seg_boot_stack\n"); |
---|
2266 | printf (" - seg_boot_mapping\n"); |
---|
2267 | printf (" - seg_kernel_code\n"); |
---|
2268 | printf (" - seg_kernel_data\n"); |
---|
2269 | printf (" - seg_kernel_uncdata\n"); |
---|
2270 | printf (" - seg_kernel_init\n"); |
---|
2271 | } |
---|
2272 | |
---|
2273 | file_write(fdout, "\n"); |
---|
2274 | |
---|
2275 | // non replicated peripherals |
---|
2276 | ld_write(fdout, "seg_cma_base ", periph_vbase_array[PERIPH_TYPE_CMA]); |
---|
2277 | ld_write(fdout, "seg_ioc_base ", periph_vbase_array[PERIPH_TYPE_IOC]); |
---|
2278 | ld_write(fdout, "seg_tty_base ", periph_vbase_array[PERIPH_TYPE_TTY]); |
---|
2279 | ld_write(fdout, "seg_fbf_base ", periph_vbase_array[PERIPH_TYPE_FBF]); |
---|
2280 | ld_write(fdout, "seg_nic_base ", periph_vbase_array[PERIPH_TYPE_NIC]); |
---|
2281 | ld_write(fdout, "seg_iob_base ", periph_vbase_array[PERIPH_TYPE_IOB]); |
---|
2282 | ld_write(fdout, "seg_gcd_base ", periph_vbase_array[PERIPH_TYPE_GCD]); |
---|
2283 | |
---|
2284 | file_write(fdout, "\n"); |
---|
2285 | |
---|
2286 | // replicated peripherals |
---|
2287 | ld_write(fdout, "seg_icu_base ", periph_vbase_array[PERIPH_TYPE_ICU]); |
---|
2288 | ld_write(fdout, "seg_tim_base ", periph_vbase_array[PERIPH_TYPE_TIM]); |
---|
2289 | ld_write(fdout, "seg_dma_base ", periph_vbase_array[PERIPH_TYPE_DMA]); |
---|
2290 | ld_write(fdout, "seg_mmc_base ", periph_vbase_array[PERIPH_TYPE_MMC]); |
---|
2291 | |
---|
2292 | close(fdout); |
---|
2293 | } |
---|
2294 | |
---|
2295 | ////////////////////////////////////////////////////// |
---|
2296 | char * buildPath(const char * path, const char * name) |
---|
2297 | { |
---|
2298 | char * res = calloc(strlen(path) + strlen(name) + 1, 1); |
---|
2299 | strcat(res, path); |
---|
2300 | strcat(res, "/"); |
---|
2301 | strcat(res, name); |
---|
2302 | return res; |
---|
2303 | } |
---|
2304 | |
---|
2305 | |
---|
2306 | ////////////////////////////////// |
---|
2307 | int main(int argc, char * argv[]) |
---|
2308 | { |
---|
2309 | if (argc < 3) { |
---|
2310 | printf("Usage: xml2bin <input_file_path> <output_path>\n"); |
---|
2311 | return 1; |
---|
2312 | } |
---|
2313 | |
---|
2314 | struct stat dir_st; |
---|
2315 | if (stat( argv[2], &dir_st)) { |
---|
2316 | perror("bad path"); |
---|
2317 | exit(1); |
---|
2318 | } |
---|
2319 | |
---|
2320 | if ((dir_st.st_mode & S_IFDIR) == 0) { |
---|
2321 | printf("path is not a dir: %s", argv[2] ); |
---|
2322 | exit(1); |
---|
2323 | } |
---|
2324 | |
---|
2325 | |
---|
2326 | char * map_path = buildPath(argv[2], "map.bin"); |
---|
2327 | char * ld_path = buildPath(argv[2], "giet_vsegs.ld"); |
---|
2328 | char * hd_path = buildPath(argv[2], "hard_config.h"); |
---|
2329 | |
---|
2330 | LIBXML_TEST_VERSION; |
---|
2331 | |
---|
2332 | int status; |
---|
2333 | xmlTextReaderPtr reader = xmlReaderForFile(argv[1], NULL, 0); |
---|
2334 | |
---|
2335 | if (reader != NULL) { |
---|
2336 | status = xmlTextReaderRead (reader); |
---|
2337 | while (status == 1) { |
---|
2338 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
2339 | |
---|
2340 | if (strcmp(tag, "mapping_info") == 0) { |
---|
2341 | headerNode(reader); |
---|
2342 | prepareBuild(); |
---|
2343 | buildBin(map_path); |
---|
2344 | genHd(hd_path); |
---|
2345 | genLd(ld_path); |
---|
2346 | } |
---|
2347 | else { |
---|
2348 | printf("[XML ERROR] Wrong file type: \"%s\"\n", argv[1]); |
---|
2349 | return 1; |
---|
2350 | } |
---|
2351 | status = xmlTextReaderRead(reader); |
---|
2352 | } |
---|
2353 | xmlFreeTextReader(reader); |
---|
2354 | |
---|
2355 | if (status != 0) { |
---|
2356 | printf("[XML ERROR] Wrong Syntax in \"%s\" file\n", argv[1]); |
---|
2357 | return 1; |
---|
2358 | } |
---|
2359 | } |
---|
2360 | return 0; |
---|
2361 | } // end main() |
---|
2362 | |
---|
2363 | |
---|
2364 | // Local Variables: |
---|
2365 | // tab-width: 4 |
---|
2366 | // c-basic-offset: 4 |
---|
2367 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
2368 | // indent-tabs-mode: nil |
---|
2369 | // End: |
---|
2370 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
2371 | |
---|