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 memory 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 | |
---|
17 | #include <stdlib.h> |
---|
18 | #include <fcntl.h> |
---|
19 | #include <sys/types.h> |
---|
20 | #include <sys/stat.h> |
---|
21 | #include <unistd.h> |
---|
22 | #include <stdio.h> |
---|
23 | #include <string.h> |
---|
24 | #include <assert.h> |
---|
25 | #include <libxml/xmlreader.h> |
---|
26 | #include <mapping_info.h> |
---|
27 | #include <irq_handler.h> |
---|
28 | |
---|
29 | #define MAX_CLUSTERS 1024 |
---|
30 | #define MAX_PSEGS 4096 |
---|
31 | #define MAX_VSPACES 1024 |
---|
32 | #define MAX_TASKS 4096 |
---|
33 | #define MAX_VSEGS 4096 |
---|
34 | #define MAX_PROCS 1024 |
---|
35 | #define MAX_IRQS 8192 |
---|
36 | #define MAX_PERIPHS 8192 |
---|
37 | |
---|
38 | #define XML_PARSER_DEBUG 1 |
---|
39 | |
---|
40 | /////////////////////////////////////////////////////////////////////////////////// |
---|
41 | // global variables used to store and index the data structures |
---|
42 | /////////////////////////////////////////////////////////////////////////////////// |
---|
43 | |
---|
44 | mapping_header_t * header; |
---|
45 | mapping_cluster_t * cluster[MAX_CLUSTERS]; // cluster array |
---|
46 | mapping_pseg_t * pseg[MAX_PSEGS]; // pseg array |
---|
47 | mapping_vspace_t * vspace[MAX_VSPACES]; // vspace array |
---|
48 | mapping_vseg_t * vseg[MAX_VSEGS]; // vseg array |
---|
49 | mapping_task_t * task[MAX_TASKS]; // task array |
---|
50 | mapping_proc_t * proc[MAX_PROCS]; // proc array |
---|
51 | mapping_irq_t * irq[MAX_IRQS]; // irq array |
---|
52 | mapping_periph_t * periph[MAX_PERIPHS]; // peripheral array |
---|
53 | |
---|
54 | // Index for the various arrays |
---|
55 | |
---|
56 | unsigned int cluster_index = 0; |
---|
57 | unsigned int vspace_index = 0; |
---|
58 | unsigned int global_index = 0; |
---|
59 | unsigned int pseg_index = 0; |
---|
60 | |
---|
61 | unsigned int proc_index = 0; |
---|
62 | unsigned int proc_loc_index = 0; |
---|
63 | |
---|
64 | unsigned int irq_index = 0; |
---|
65 | unsigned int irq_loc_index = 0; |
---|
66 | |
---|
67 | unsigned int periph_index = 0; |
---|
68 | unsigned int periph_loc_index = 0; |
---|
69 | |
---|
70 | unsigned int vseg_index = 0; |
---|
71 | unsigned int vseg_loc_index = 0; |
---|
72 | |
---|
73 | unsigned int task_index = 0; |
---|
74 | unsigned int task_loc_index = 0; |
---|
75 | |
---|
76 | |
---|
77 | ////////////////////////////////////////////////// |
---|
78 | unsigned int getIntValue( xmlTextReaderPtr reader, |
---|
79 | const char * attributeName, |
---|
80 | unsigned int * ok) |
---|
81 | { |
---|
82 | unsigned int value = 0; |
---|
83 | unsigned int i; |
---|
84 | char c; |
---|
85 | |
---|
86 | char * string = (char *) xmlTextReaderGetAttribute(reader, |
---|
87 | (const xmlChar *) attributeName); |
---|
88 | |
---|
89 | if (string == NULL) |
---|
90 | { |
---|
91 | // missing argument |
---|
92 | *ok = 0; |
---|
93 | return 0; |
---|
94 | } |
---|
95 | else |
---|
96 | { |
---|
97 | if ((string[0] == '0') && ((string[1] == 'x') || (string[1] == 'X'))) |
---|
98 | { |
---|
99 | // Hexa |
---|
100 | for (i = 2 ; (string[i] != 0) && (i < 10) ; i++) |
---|
101 | { |
---|
102 | c = string[i]; |
---|
103 | if ((c >= '0') && (c <= '9')) { value = (value << 4) + string[i] - 48; } |
---|
104 | else if ((c >= 'a') && (c <= 'f')) { value = (value << 4) + string[i] - 87; } |
---|
105 | else if ((c >= 'A') && (c <= 'F')) { value = (value << 4) + string[i] - 55; } |
---|
106 | else |
---|
107 | { |
---|
108 | *ok = 0; |
---|
109 | return 0; |
---|
110 | } |
---|
111 | } |
---|
112 | } |
---|
113 | else |
---|
114 | { |
---|
115 | // Decimal |
---|
116 | for (i = 0; (string[i] != 0) && (i < 9); i++) |
---|
117 | { |
---|
118 | c = string[i]; |
---|
119 | if ((c >= '0') && (c <= '9')) value = (value * 10) + string[i] - 48; |
---|
120 | else |
---|
121 | { |
---|
122 | *ok = 0; |
---|
123 | return 0; |
---|
124 | } |
---|
125 | } |
---|
126 | } |
---|
127 | *ok = 1; |
---|
128 | return value; |
---|
129 | } |
---|
130 | } // end getIntValue() |
---|
131 | |
---|
132 | //////////////////////////////////////////////// |
---|
133 | paddr_t getPaddrValue( xmlTextReaderPtr reader, |
---|
134 | const char * attributeName, |
---|
135 | unsigned int * ok) |
---|
136 | { |
---|
137 | paddr_t value = 0; |
---|
138 | unsigned int i; |
---|
139 | char c; |
---|
140 | |
---|
141 | char * string = (char *) xmlTextReaderGetAttribute(reader, |
---|
142 | (const xmlChar *) attributeName); |
---|
143 | |
---|
144 | if (string == NULL) |
---|
145 | { |
---|
146 | // missing argument |
---|
147 | *ok = 0; |
---|
148 | return 0; |
---|
149 | } |
---|
150 | else |
---|
151 | { |
---|
152 | if ((string[0] == '0') && ((string[1] == 'x') || (string[1] == 'X'))) |
---|
153 | { |
---|
154 | // Hexa |
---|
155 | for (i = 2 ; (string[i] != 0) && (i < 18) ; i++) |
---|
156 | { |
---|
157 | c = string[i]; |
---|
158 | if ((c >= '0') && (c <= '9')) { value = (value << 4) + string[i] - 48; } |
---|
159 | else if ((c >= 'a') && (c <= 'f')) { value = (value << 4) + string[i] - 87; } |
---|
160 | else if ((c >= 'A') && (c <= 'F')) { value = (value << 4) + string[i] - 55; } |
---|
161 | else |
---|
162 | { |
---|
163 | *ok = 0; |
---|
164 | return 0; |
---|
165 | } |
---|
166 | } |
---|
167 | } |
---|
168 | else |
---|
169 | { |
---|
170 | // Decimal not supported for paddr_t |
---|
171 | *ok = 0; |
---|
172 | return 0; |
---|
173 | } |
---|
174 | *ok = 1; |
---|
175 | return value; |
---|
176 | } |
---|
177 | } // end getPaddrValue() |
---|
178 | |
---|
179 | //////////////////////////////////////////////// |
---|
180 | char * getStringValue( xmlTextReaderPtr reader, |
---|
181 | const char * attributeName, |
---|
182 | unsigned int * ok ) |
---|
183 | { |
---|
184 | char * string = (char *) xmlTextReaderGetAttribute(reader, |
---|
185 | (const xmlChar *) attributeName); |
---|
186 | |
---|
187 | |
---|
188 | if (string == NULL) |
---|
189 | { |
---|
190 | // missing argument |
---|
191 | *ok = 0; |
---|
192 | return NULL; |
---|
193 | } |
---|
194 | else |
---|
195 | { |
---|
196 | //we read only string smaller than 32 byte |
---|
197 | if (strlen(string) > 32) |
---|
198 | { |
---|
199 | printf("[XML ERROR] all strings must be less than 32 bytes\n"); |
---|
200 | exit(1); |
---|
201 | } |
---|
202 | |
---|
203 | *ok = 1; |
---|
204 | return string; |
---|
205 | } |
---|
206 | } // end getStringValue() |
---|
207 | |
---|
208 | /////////////////////////////////////////////////////////////// |
---|
209 | int getClusterId( unsigned int x, unsigned int y ) |
---|
210 | { |
---|
211 | // associative search of cluster index |
---|
212 | unsigned int cluster_id; |
---|
213 | |
---|
214 | for( cluster_id = 0 ; cluster_id < (header->x_size * header->y_size) ; cluster_id++ ) |
---|
215 | { |
---|
216 | if( (cluster[cluster_id]->x == x) && (cluster[cluster_id]->y == y) ) |
---|
217 | { |
---|
218 | return cluster_id; |
---|
219 | } |
---|
220 | } |
---|
221 | return -1; |
---|
222 | } // end getClusterId() |
---|
223 | |
---|
224 | /////////////////////////////////////////////////////////////// |
---|
225 | int getPsegId(unsigned int x, unsigned int y, char * pseg_name) |
---|
226 | { |
---|
227 | int cluster_id = getClusterId( x, y ); |
---|
228 | |
---|
229 | if ( cluster_id == -1 ) return -1; |
---|
230 | |
---|
231 | // associative search for pseg index |
---|
232 | unsigned int pseg_id; |
---|
233 | unsigned int pseg_min = cluster[cluster_id]->pseg_offset; |
---|
234 | unsigned int pseg_max = pseg_min + cluster[cluster_id]->psegs; |
---|
235 | |
---|
236 | for (pseg_id = pseg_min; pseg_id < pseg_max; pseg_id++) |
---|
237 | { |
---|
238 | if (strcmp(pseg[pseg_id]->name, pseg_name) == 0) |
---|
239 | { |
---|
240 | return pseg_id; |
---|
241 | } |
---|
242 | } |
---|
243 | return -1; |
---|
244 | } // end getPsegId() |
---|
245 | |
---|
246 | /////////////////////////////////// |
---|
247 | int getVspaceId(char * vspace_name) |
---|
248 | { |
---|
249 | unsigned int vspace_id; |
---|
250 | |
---|
251 | for (vspace_id = 0; vspace_id < vspace_index; vspace_id++) |
---|
252 | { |
---|
253 | if (strcmp(vspace[vspace_id]->name, vspace_name) == 0) |
---|
254 | { |
---|
255 | return vspace_id; |
---|
256 | } |
---|
257 | } |
---|
258 | return -1; |
---|
259 | } |
---|
260 | |
---|
261 | /////////////////////////////////////////////////// |
---|
262 | int getVsegId( unsigned int vspace_id, char *name ) |
---|
263 | { |
---|
264 | unsigned int vseg_id; |
---|
265 | unsigned int vseg_min = vspace[vspace_id]->vseg_offset; |
---|
266 | unsigned int vseg_max = vseg_min + vspace[vspace_id]->vsegs; |
---|
267 | |
---|
268 | for (vseg_id = vseg_min ; vseg_id < vseg_max ; vseg_id++) |
---|
269 | { |
---|
270 | if (strcmp(vseg[vseg_id]->name, name) == 0) return vseg_id; |
---|
271 | } |
---|
272 | return -1; |
---|
273 | } |
---|
274 | |
---|
275 | |
---|
276 | ////////////////////////////////////// |
---|
277 | void taskNode(xmlTextReaderPtr reader) |
---|
278 | { |
---|
279 | unsigned int ok; |
---|
280 | unsigned int value; |
---|
281 | unsigned int x,y; |
---|
282 | char * str; |
---|
283 | |
---|
284 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
285 | |
---|
286 | if (task_index >= MAX_TASKS) |
---|
287 | { |
---|
288 | printf("[XML ERROR] The number of tasks is larger than %d\n", MAX_TASKS); |
---|
289 | exit(1); |
---|
290 | } |
---|
291 | |
---|
292 | #if XML_PARSER_DEBUG |
---|
293 | printf(" task %d\n", task_loc_index); |
---|
294 | #endif |
---|
295 | |
---|
296 | task[task_index] = (mapping_task_t *) malloc(sizeof(mapping_task_t)); |
---|
297 | |
---|
298 | ////////// get name attribute |
---|
299 | str = getStringValue(reader, "name", &ok); |
---|
300 | if (ok) |
---|
301 | { |
---|
302 | #if XML_PARSER_DEBUG |
---|
303 | printf(" name = %s\n", str); |
---|
304 | #endif |
---|
305 | strncpy( task[task_index]->name, str, 31 ); |
---|
306 | } |
---|
307 | else |
---|
308 | { |
---|
309 | printf("[XML ERROR] illegal or missing <name> attribute for task (%d,%d)\n", |
---|
310 | vspace_index, task_loc_index); |
---|
311 | exit(1); |
---|
312 | } |
---|
313 | |
---|
314 | ///////// get trdid attribute (optional) |
---|
315 | task[task_index]->trdid = getIntValue(reader, "trdid", &ok); |
---|
316 | #if XML_PARSER_DEBUG |
---|
317 | printf(" trdid = %d\n", x); |
---|
318 | #endif |
---|
319 | if ( !ok ) |
---|
320 | { |
---|
321 | task[task_index]->trdid = task_loc_index; |
---|
322 | } |
---|
323 | |
---|
324 | ///////// get x coordinate |
---|
325 | x = getIntValue(reader, "x", &ok); |
---|
326 | #if XML_PARSER_DEBUG |
---|
327 | printf(" x = %d\n", x); |
---|
328 | #endif |
---|
329 | if ( !(ok && (x < header->x_size)) ) |
---|
330 | { |
---|
331 | printf("[XML ERROR] illegal or missing < x > attribute for task (%d,%d)\n", |
---|
332 | vspace_index, task_loc_index); |
---|
333 | exit(1); |
---|
334 | } |
---|
335 | |
---|
336 | ///////// get y coordinate |
---|
337 | y = getIntValue(reader, "y", &ok); |
---|
338 | #if XML_PARSER_DEBUG |
---|
339 | printf(" y = %d\n", y); |
---|
340 | #endif |
---|
341 | if ( !(ok && (y < header->y_size)) ) |
---|
342 | { |
---|
343 | printf("[XML ERROR] illegal or missing < y > attribute for task (%d,%d)\n", |
---|
344 | vspace_index, task_loc_index); |
---|
345 | exit(1); |
---|
346 | } |
---|
347 | |
---|
348 | ///////// set clusterid attribute |
---|
349 | int index = getClusterId( x, y ); |
---|
350 | #if XML_PARSER_DEBUG |
---|
351 | printf(" clusterid = %d\n", index); |
---|
352 | #endif |
---|
353 | if( index >= 0 ) |
---|
354 | { |
---|
355 | task[task_index]->clusterid = index; |
---|
356 | } |
---|
357 | else |
---|
358 | { |
---|
359 | printf("[XML ERROR] <clusterid> not found for task (%d,%d)\n", |
---|
360 | vspace_index, task_loc_index); |
---|
361 | exit(1); |
---|
362 | } |
---|
363 | |
---|
364 | ////////// get p attribute |
---|
365 | value = getIntValue(reader, "p", &ok); |
---|
366 | if (ok) |
---|
367 | { |
---|
368 | #if XML_PARSER_DEBUG |
---|
369 | printf(" proclocid = %x\n", value); |
---|
370 | #endif |
---|
371 | if (value >= cluster[task[task_index]->clusterid]->procs) |
---|
372 | { |
---|
373 | printf("[XML ERROR] <proclocid> too large for task (%d,%d)\n", |
---|
374 | vspace_index, task_loc_index); |
---|
375 | exit(1); |
---|
376 | } |
---|
377 | task[task_index]->proclocid = value; |
---|
378 | } |
---|
379 | else |
---|
380 | { |
---|
381 | printf("[XML ERROR] illegal or missing <p> attribute for task (%d,%d)\n", |
---|
382 | vspace_index, task_loc_index); |
---|
383 | exit(1); |
---|
384 | } |
---|
385 | |
---|
386 | ////////// get stackname attribute |
---|
387 | char* stack_name = getStringValue(reader, "stackname" , &ok); |
---|
388 | if (ok) |
---|
389 | { |
---|
390 | #if XML_PARSER_DEBUG |
---|
391 | printf(" stackname = %s\n", str); |
---|
392 | #endif |
---|
393 | int index = getVsegId( vspace_index , stack_name ); |
---|
394 | if (index >= 0) |
---|
395 | { |
---|
396 | #if XML_PARSER_DEBUG |
---|
397 | printf(" stack_id = %d\n", index); |
---|
398 | #endif |
---|
399 | task[task_index]->stack_vseg_id = index; |
---|
400 | } |
---|
401 | else |
---|
402 | { |
---|
403 | printf("[XML ERROR] illegal or missing <stackname> for task (%d,%d)\n", |
---|
404 | vspace_index, task_loc_index); |
---|
405 | exit(1); |
---|
406 | } |
---|
407 | } |
---|
408 | else |
---|
409 | { |
---|
410 | printf("[XML ERROR] illegal or missing <stackname> for task (%d,%d)\n", |
---|
411 | vspace_index, task_loc_index); |
---|
412 | exit(1); |
---|
413 | } |
---|
414 | |
---|
415 | ////////// get heap attribute |
---|
416 | char* heap_name = getStringValue(reader, "heapname", &ok); |
---|
417 | if (ok) |
---|
418 | { |
---|
419 | #if XML_PARSER_DEBUG |
---|
420 | printf(" heapname = %s\n", str); |
---|
421 | #endif |
---|
422 | int index = getVsegId( vspace_index , heap_name ); |
---|
423 | if (index >= 0) |
---|
424 | { |
---|
425 | #if XML_PARSER_DEBUG |
---|
426 | printf(" heap_id = %d\n", index ); |
---|
427 | #endif |
---|
428 | task[task_index]->heap_vseg_id = index; |
---|
429 | } |
---|
430 | else |
---|
431 | { |
---|
432 | printf("[XML ERROR] illegal or missing <heapname> for task (%d,%d)\n", |
---|
433 | vspace_index, task_loc_index); |
---|
434 | exit(1); |
---|
435 | } |
---|
436 | } |
---|
437 | else |
---|
438 | { |
---|
439 | task[task_index]->heap_vseg_id = -1; |
---|
440 | } |
---|
441 | |
---|
442 | ////////// get startid attribute |
---|
443 | value = getIntValue(reader, "startid", &ok); |
---|
444 | if (ok) |
---|
445 | { |
---|
446 | #if XML_PARSER_DEBUG |
---|
447 | printf(" startid = %x\n", value); |
---|
448 | #endif |
---|
449 | task[task_index]->startid = value; |
---|
450 | } |
---|
451 | else |
---|
452 | { |
---|
453 | printf("[XML ERROR] illegal or missing <startid> attribute for task (%d,%d)\n", |
---|
454 | vspace_index, task_loc_index); |
---|
455 | exit(1); |
---|
456 | } |
---|
457 | |
---|
458 | task_index++; |
---|
459 | task_loc_index++; |
---|
460 | } // end taskNode() |
---|
461 | |
---|
462 | |
---|
463 | ////////////////////////////////////// |
---|
464 | void vsegNode(xmlTextReaderPtr reader) |
---|
465 | { |
---|
466 | unsigned int ok; |
---|
467 | unsigned int value; |
---|
468 | unsigned int x,y; |
---|
469 | char * str; |
---|
470 | |
---|
471 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
472 | |
---|
473 | if (vseg_index >= MAX_VSEGS) |
---|
474 | { |
---|
475 | printf("[XML ERROR] The number of vsegs is larger than %d\n", MAX_VSEGS); |
---|
476 | exit(1); |
---|
477 | } |
---|
478 | |
---|
479 | #if XML_PARSER_DEBUG |
---|
480 | printf(" vseg %d\n", vseg_loc_index); |
---|
481 | #endif |
---|
482 | |
---|
483 | vseg[vseg_index] = (mapping_vseg_t *) malloc(sizeof(mapping_vseg_t)); |
---|
484 | |
---|
485 | ///////// set mapped attribute |
---|
486 | vseg[vseg_index]->mapped = 0; |
---|
487 | |
---|
488 | ///////// get name attribute |
---|
489 | str = getStringValue(reader, "name", &ok); |
---|
490 | if (ok) |
---|
491 | { |
---|
492 | #if XML_PARSER_DEBUG |
---|
493 | printf(" name = %s\n", str); |
---|
494 | #endif |
---|
495 | strncpy( vseg[vseg_index]->name, str, 31); |
---|
496 | } |
---|
497 | else |
---|
498 | { |
---|
499 | printf("[XML ERROR] illegal or missing <name> attribute for vseg (%d,%d)\n", |
---|
500 | vspace_index, vseg_loc_index); |
---|
501 | exit(1); |
---|
502 | } |
---|
503 | |
---|
504 | ////////// get ident attribute (optional : 0 if missing) |
---|
505 | value = getIntValue(reader, "ident", &ok); |
---|
506 | if (ok) |
---|
507 | { |
---|
508 | #if XML_PARSER_DEBUG |
---|
509 | printf(" ident = %d\n", value); |
---|
510 | #endif |
---|
511 | vseg[vseg_index]->ident = value; |
---|
512 | } |
---|
513 | else |
---|
514 | { |
---|
515 | vseg[vseg_index]->ident = 0; |
---|
516 | } |
---|
517 | |
---|
518 | ////////// get local attribute (optional : 0 if missing) |
---|
519 | value = getIntValue(reader, "local", &ok); |
---|
520 | if (ok) |
---|
521 | { |
---|
522 | #if XML_PARSER_DEBUG |
---|
523 | printf(" local = %d\n", value); |
---|
524 | #endif |
---|
525 | vseg[vseg_index]->local = value; |
---|
526 | } |
---|
527 | else |
---|
528 | { |
---|
529 | vseg[vseg_index]->local = 0; |
---|
530 | } |
---|
531 | |
---|
532 | ////////// get big attribute (optional : 0 if missing) |
---|
533 | value = getIntValue(reader, "big", &ok); |
---|
534 | if (ok) |
---|
535 | { |
---|
536 | #if XML_PARSER_DEBUG |
---|
537 | printf(" big = %d\n", value); |
---|
538 | #endif |
---|
539 | vseg[vseg_index]->big = value; |
---|
540 | } |
---|
541 | else |
---|
542 | { |
---|
543 | vseg[vseg_index]->big = 0; |
---|
544 | } |
---|
545 | |
---|
546 | /////////// get vbase attribute |
---|
547 | value = getIntValue(reader, "vbase", &ok); |
---|
548 | if (ok) |
---|
549 | { |
---|
550 | #if XML_PARSER_DEBUG |
---|
551 | printf(" vbase = 0x%x\n", value); |
---|
552 | #endif |
---|
553 | vseg[vseg_index]->vbase = value; |
---|
554 | } |
---|
555 | else |
---|
556 | { |
---|
557 | printf("[XML ERROR] illegal or missing <vbase> attribute for vseg (%d,%d)\n", |
---|
558 | vspace_index, vseg_loc_index); |
---|
559 | exit(1); |
---|
560 | } |
---|
561 | |
---|
562 | ////////// get length attribute |
---|
563 | value = getIntValue(reader, "length", &ok); |
---|
564 | if (ok) |
---|
565 | { |
---|
566 | #if XML_PARSER_DEBUG |
---|
567 | printf(" length = %x\n", value); |
---|
568 | #endif |
---|
569 | vseg[vseg_index]->length = value; |
---|
570 | } |
---|
571 | else |
---|
572 | { |
---|
573 | printf("[XML ERROR] illegal or missing <length> attribute for vseg (%d,%d)\n", |
---|
574 | vspace_index, vseg_loc_index); |
---|
575 | exit(1); |
---|
576 | } |
---|
577 | |
---|
578 | //////// get type attribute |
---|
579 | str = getStringValue(reader, "type", &ok); |
---|
580 | |
---|
581 | #if XML_PARSER_DEBUG |
---|
582 | printf(" type = %s\n", str); |
---|
583 | #endif |
---|
584 | |
---|
585 | if (ok && (strcmp(str, "ELF") == 0)) vseg[vseg_index]->type = VSEG_TYPE_ELF; |
---|
586 | else if (ok && (strcmp(str, "PERI") == 0)) vseg[vseg_index]->type = VSEG_TYPE_PERI; |
---|
587 | else if (ok && (strcmp(str, "BLOB") == 0)) vseg[vseg_index]->type = VSEG_TYPE_BLOB; |
---|
588 | else if (ok && (strcmp(str, "PTAB") == 0)) vseg[vseg_index]->type = VSEG_TYPE_PTAB; |
---|
589 | else if (ok && (strcmp(str, "BUFFER") == 0)) vseg[vseg_index]->type = VSEG_TYPE_BUFFER; |
---|
590 | else if (ok && (strcmp(str, "SCHED") == 0)) vseg[vseg_index]->type = VSEG_TYPE_SCHED; |
---|
591 | else if (ok && (strcmp(str, "HEAP") == 0)) vseg[vseg_index]->type = VSEG_TYPE_HEAP; |
---|
592 | else |
---|
593 | { |
---|
594 | printf("[XML ERROR] illegal or missing <type> attribute for vseg (%d,%d)\n", |
---|
595 | vspace_index, vseg_loc_index); |
---|
596 | exit(1); |
---|
597 | } |
---|
598 | |
---|
599 | ////////// get x coordinate |
---|
600 | x = getIntValue(reader, "x", &ok); |
---|
601 | #if XML_PARSER_DEBUG |
---|
602 | printf(" x = %d\n", x); |
---|
603 | #endif |
---|
604 | if ( !(ok && (x < header->x_size)) ) |
---|
605 | { |
---|
606 | printf("[XML ERROR] illegal or missing < x > attribute for vseg %d\n", |
---|
607 | vseg_loc_index); |
---|
608 | exit(1); |
---|
609 | } |
---|
610 | |
---|
611 | ////////// get y coordinate |
---|
612 | y = getIntValue(reader, "y", &ok); |
---|
613 | #if XML_PARSER_DEBUG |
---|
614 | printf(" y = %d\n", y); |
---|
615 | #endif |
---|
616 | if ( !(ok && (y < header->y_size)) ) |
---|
617 | { |
---|
618 | printf("[XML ERROR] illegal or missing < y > attribute for vseg %d\n", |
---|
619 | vseg_loc_index); |
---|
620 | exit(1); |
---|
621 | } |
---|
622 | |
---|
623 | ///////// get psegname attribute |
---|
624 | str = getStringValue(reader, "psegname", &ok); |
---|
625 | #if XML_PARSER_DEBUG |
---|
626 | printf(" psegname = %s\n", str); |
---|
627 | #endif |
---|
628 | if (ok == 0) |
---|
629 | { |
---|
630 | printf("[XML ERROR] illegal or missing <psegname> for vseg %d\n", |
---|
631 | vseg_loc_index); |
---|
632 | exit(1); |
---|
633 | } |
---|
634 | |
---|
635 | /////////// set psegid field |
---|
636 | int psegid = getPsegId( x, y, str ); |
---|
637 | #if XML_PARSER_DEBUG |
---|
638 | printf(" psegid = %d\n", psegid); |
---|
639 | #endif |
---|
640 | if (psegid >= 0) |
---|
641 | { |
---|
642 | vseg[vseg_index]->psegid = psegid; |
---|
643 | } |
---|
644 | else |
---|
645 | { |
---|
646 | printf("[XML ERROR] pseg not found for vseg %d / x = %d / y = %d / psegname = %s\n", |
---|
647 | vseg_loc_index, x, y, str ); |
---|
648 | exit(1); |
---|
649 | } |
---|
650 | |
---|
651 | //////// get mode attribute |
---|
652 | str = getStringValue(reader, "mode", &ok); |
---|
653 | #if XML_PARSER_DEBUG |
---|
654 | printf(" mode = %s\n", str); |
---|
655 | #endif |
---|
656 | if (ok && (strcmp(str, "CXWU") == 0)) { vseg[vseg_index]->mode = 0xF; } |
---|
657 | else if (ok && (strcmp(str, "CXW_") == 0)) { vseg[vseg_index]->mode = 0xE; } |
---|
658 | else if (ok && (strcmp(str, "CX_U") == 0)) { vseg[vseg_index]->mode = 0xD; } |
---|
659 | else if (ok && (strcmp(str, "CX__") == 0)) { vseg[vseg_index]->mode = 0xC; } |
---|
660 | else if (ok && (strcmp(str, "C_WU") == 0)) { vseg[vseg_index]->mode = 0xB; } |
---|
661 | else if (ok && (strcmp(str, "C_W_") == 0)) { vseg[vseg_index]->mode = 0xA; } |
---|
662 | else if (ok && (strcmp(str, "C__U") == 0)) { vseg[vseg_index]->mode = 0x9; } |
---|
663 | else if (ok && (strcmp(str, "C___") == 0)) { vseg[vseg_index]->mode = 0x8; } |
---|
664 | else if (ok && (strcmp(str, "_XWU") == 0)) { vseg[vseg_index]->mode = 0x7; } |
---|
665 | else if (ok && (strcmp(str, "_XW_") == 0)) { vseg[vseg_index]->mode = 0x6; } |
---|
666 | else if (ok && (strcmp(str, "_X_U") == 0)) { vseg[vseg_index]->mode = 0x5; } |
---|
667 | else if (ok && (strcmp(str, "_X__") == 0)) { vseg[vseg_index]->mode = 0x4; } |
---|
668 | else if (ok && (strcmp(str, "__WU") == 0)) { vseg[vseg_index]->mode = 0x3; } |
---|
669 | else if (ok && (strcmp(str, "__W_") == 0)) { vseg[vseg_index]->mode = 0x2; } |
---|
670 | else if (ok && (strcmp(str, "___U") == 0)) { vseg[vseg_index]->mode = 0x1; } |
---|
671 | else if (ok && (strcmp(str, "____") == 0)) { vseg[vseg_index]->mode = 0x0; } |
---|
672 | else { |
---|
673 | printf("[XML ERROR] illegal or missing <mode> attribute for vseg (%d,%d)\n", |
---|
674 | vspace_index, vseg_loc_index); |
---|
675 | exit(1); |
---|
676 | } |
---|
677 | |
---|
678 | ////////// get binpath attribute (optional : "" if missing) |
---|
679 | str = getStringValue(reader, "binpath", &ok); |
---|
680 | if (ok) |
---|
681 | { |
---|
682 | #if XML_PARSER_DEBUG |
---|
683 | printf(" binpath = %s\n", str); |
---|
684 | #endif |
---|
685 | strncpy(vseg[vseg_index]->binpath, str, 63); |
---|
686 | } |
---|
687 | else |
---|
688 | { |
---|
689 | vseg[vseg_index]->binpath[0] = 0; |
---|
690 | } |
---|
691 | |
---|
692 | vseg_index++; |
---|
693 | vseg_loc_index++; |
---|
694 | } // end vsegNode() |
---|
695 | |
---|
696 | //////////////////////////////////////// |
---|
697 | void vspaceNode(xmlTextReaderPtr reader) |
---|
698 | { |
---|
699 | unsigned int ok; |
---|
700 | |
---|
701 | vseg_loc_index = 0; |
---|
702 | task_loc_index = 0; |
---|
703 | |
---|
704 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
705 | |
---|
706 | vspace[vspace_index] = (mapping_vspace_t *) malloc(sizeof(mapping_vspace_t)); |
---|
707 | header->vspaces = header->vspaces + 1; |
---|
708 | |
---|
709 | ////////// get name attribute |
---|
710 | char* vspace_name = getStringValue(reader, "name", &ok); |
---|
711 | if (ok) |
---|
712 | { |
---|
713 | #if XML_PARSER_DEBUG |
---|
714 | printf("\n vspace = %s\n", vspace_name ); |
---|
715 | #endif |
---|
716 | strncpy( vspace[vspace_index]->name, vspace_name , 31 ); |
---|
717 | } |
---|
718 | else |
---|
719 | { |
---|
720 | printf("[XML ERROR] illegal or missing <name> attribute for vspace %d\n", |
---|
721 | vspace_index); |
---|
722 | exit(1); |
---|
723 | } |
---|
724 | |
---|
725 | ////////// set vseg_offset and task_offset attributes |
---|
726 | vspace[vspace_index]->vseg_offset = vseg_index; |
---|
727 | vspace[vspace_index]->task_offset = task_index; |
---|
728 | |
---|
729 | ////////// initialise vsegs and tasks attributes |
---|
730 | vspace[vspace_index]->vsegs = 0; |
---|
731 | vspace[vspace_index]->tasks = 0; |
---|
732 | |
---|
733 | ////////// get startname attribute |
---|
734 | char* start_name = getStringValue(reader, "startname", &ok); |
---|
735 | if (ok == 0) |
---|
736 | { |
---|
737 | printf("[XML ERROR] illegal or missing <startname> attribute for vspace %s\n", |
---|
738 | vspace[vspace_index]->name); |
---|
739 | exit(1); |
---|
740 | } |
---|
741 | |
---|
742 | int status = xmlTextReaderRead(reader); |
---|
743 | while (status == 1) |
---|
744 | { |
---|
745 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
746 | |
---|
747 | if (strcmp(tag, "vseg") == 0) |
---|
748 | { |
---|
749 | vsegNode(reader); |
---|
750 | vspace[vspace_index]->vsegs += 1; |
---|
751 | } |
---|
752 | else if (strcmp(tag, "task") == 0) |
---|
753 | { |
---|
754 | taskNode(reader); |
---|
755 | vspace[vspace_index]->tasks += 1; |
---|
756 | } |
---|
757 | else if (strcmp(tag, "#text") == 0) { } |
---|
758 | else if (strcmp(tag, "#comment") == 0) { } |
---|
759 | else if (strcmp(tag, "vspace") == 0) |
---|
760 | { |
---|
761 | // get index of the vseg containing the start vector |
---|
762 | int index = getVsegId( vspace_index, start_name ); |
---|
763 | if (index == -1) |
---|
764 | { |
---|
765 | printf("[XML ERROR] vseg containing start vector not found in vspace %s\n", |
---|
766 | vspace[vspace_index]->name); |
---|
767 | exit(1); |
---|
768 | } |
---|
769 | else |
---|
770 | { |
---|
771 | vspace[vspace_index]->start_vseg_id = index; |
---|
772 | } |
---|
773 | |
---|
774 | #if XML_PARSER_DEBUG |
---|
775 | printf(" vsegs = %d\n", vspace[vspace_index]->vsegs ); |
---|
776 | printf(" tasks = %d\n", vspace[vspace_index]->tasks ); |
---|
777 | printf(" vseg_offset = %d\n", vspace[vspace_index]->vseg_offset ); |
---|
778 | printf(" task_offset = %d\n", vspace[vspace_index]->task_offset ); |
---|
779 | printf(" startname = %s\n", start_name); |
---|
780 | printf(" start_id = %d\n", index); |
---|
781 | printf(" end vspace %d\n\n", vspace_index); |
---|
782 | #endif |
---|
783 | vspace_index++; |
---|
784 | return; |
---|
785 | } |
---|
786 | else |
---|
787 | { |
---|
788 | printf("[XML ERROR] Unknown tag %s", tag); |
---|
789 | exit(1); |
---|
790 | } |
---|
791 | status = xmlTextReaderRead(reader); |
---|
792 | } |
---|
793 | } // end vspaceNode() |
---|
794 | |
---|
795 | ///////////////////////////////////// |
---|
796 | void irqNode(xmlTextReaderPtr reader) |
---|
797 | { |
---|
798 | unsigned int ok; |
---|
799 | unsigned int value; |
---|
800 | char * str; |
---|
801 | |
---|
802 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
803 | |
---|
804 | if (irq_index >= MAX_IRQS) |
---|
805 | { |
---|
806 | printf("[XML ERROR] The number of irqs is larger than %d\n", MAX_IRQS); |
---|
807 | } |
---|
808 | |
---|
809 | #if XML_PARSER_DEBUG |
---|
810 | printf(" irq %d\n", irq_loc_index); |
---|
811 | #endif |
---|
812 | |
---|
813 | irq[irq_index] = (mapping_irq_t *) malloc(sizeof(mapping_irq_t)); |
---|
814 | |
---|
815 | ///////// get srcid attribute |
---|
816 | value = getIntValue(reader, "srcid", &ok); |
---|
817 | if (ok) |
---|
818 | { |
---|
819 | #if XML_PARSER_DEBUG |
---|
820 | printf(" srcid = %d\n", value); |
---|
821 | #endif |
---|
822 | irq[irq_index]->srcid = value; |
---|
823 | if (value >= 32) |
---|
824 | { |
---|
825 | printf("[XML ERROR] IRQ <srcid> too large for periph %d in cluster %d\n", |
---|
826 | cluster_index, periph_loc_index); |
---|
827 | exit(1); |
---|
828 | } |
---|
829 | } |
---|
830 | else |
---|
831 | { |
---|
832 | printf("[XML ERROR] missing IRQ <srcid> for periph %d in cluster %d\n", |
---|
833 | cluster_index, periph_loc_index); |
---|
834 | exit(1); |
---|
835 | } |
---|
836 | |
---|
837 | ///////// get srctype attribute |
---|
838 | str = getStringValue(reader, "srctype", &ok); |
---|
839 | if (ok) |
---|
840 | { |
---|
841 | #if XML_PARSER_DEBUG |
---|
842 | printf(" srctype = %s\n", str); |
---|
843 | #endif |
---|
844 | if ( strcmp(str, "HWI") == 0 ) irq[irq_index]->srctype = IRQ_TYPE_HWI; |
---|
845 | else if ( strcmp(str, "WTI") == 0 ) irq[irq_index]->srctype = IRQ_TYPE_WTI; |
---|
846 | else if ( strcmp(str, "PTI") == 0 ) irq[irq_index]->srctype = IRQ_TYPE_PTI; |
---|
847 | else |
---|
848 | { |
---|
849 | printf("[XML ERROR] illegal IRQ <srctype> for periph %d in cluster %d\n", |
---|
850 | cluster_index, periph_loc_index); |
---|
851 | exit(1); |
---|
852 | } |
---|
853 | } |
---|
854 | else |
---|
855 | { |
---|
856 | printf("[XML ERROR] missing IRQ <srctype> for periph %d in cluster %d\n", |
---|
857 | cluster_index, periph_loc_index); |
---|
858 | exit(1); |
---|
859 | } |
---|
860 | |
---|
861 | ///////// get isr attribute |
---|
862 | str = getStringValue(reader, "isr", &ok); |
---|
863 | if (ok) |
---|
864 | { |
---|
865 | #if XML_PARSER_DEBUG |
---|
866 | printf(" isr = %s\n", str); |
---|
867 | #endif |
---|
868 | if (strcmp(str, "ISR_TICK" ) == 0) irq[irq_index]->isr = ISR_TICK; |
---|
869 | else if (strcmp(str, "ISR_BDV" ) == 0) irq[irq_index]->isr = ISR_BDV; |
---|
870 | else if (strcmp(str, "ISR_CMA" ) == 0) irq[irq_index]->isr = ISR_CMA; |
---|
871 | else if (strcmp(str, "ISR_TTY_RX" ) == 0) irq[irq_index]->isr = ISR_TTY_RX; |
---|
872 | else if (strcmp(str, "ISR_TTY_TX" ) == 0) irq[irq_index]->isr = ISR_TTY_TX; |
---|
873 | else if (strcmp(str, "ISR_TIMER" ) == 0) irq[irq_index]->isr = ISR_TIMER; |
---|
874 | else if (strcmp(str, "ISR_WAKUP" ) == 0) irq[irq_index]->isr = ISR_WAKUP; |
---|
875 | else if (strcmp(str, "ISR_NIC_RX" ) == 0) irq[irq_index]->isr = ISR_NIC_RX; |
---|
876 | else if (strcmp(str, "ISR_NIC_TX" ) == 0) irq[irq_index]->isr = ISR_NIC_TX; |
---|
877 | else if (strcmp(str, "ISR_MMC" ) == 0) irq[irq_index]->isr = ISR_MMC; |
---|
878 | else if (strcmp(str, "ISR_DMA" ) == 0) irq[irq_index]->isr = ISR_DMA; |
---|
879 | else if (strcmp(str, "ISR_SPI" ) == 0) irq[irq_index]->isr = ISR_SPI; |
---|
880 | else if (strcmp(str, "ISR_DEFAULT") == 0) irq[irq_index]->isr = ISR_DEFAULT; |
---|
881 | else |
---|
882 | { |
---|
883 | printf("[XML ERROR] illegal IRQ <isr> for periph %d in cluster %d\n", |
---|
884 | periph_loc_index, cluster_index ); |
---|
885 | exit(1); |
---|
886 | } |
---|
887 | } |
---|
888 | else |
---|
889 | { |
---|
890 | printf("[XML ERROR] missing IRQ <isr> for periph %d in cluster %d\n", |
---|
891 | cluster_index, periph_loc_index); |
---|
892 | exit(1); |
---|
893 | } |
---|
894 | |
---|
895 | ///////// get channel attribute (optionnal : 0 if missing) |
---|
896 | value = getIntValue(reader, "channel", &ok); |
---|
897 | if (ok) |
---|
898 | { |
---|
899 | #if XML_PARSER_DEBUG |
---|
900 | printf(" channel = %d\n", value); |
---|
901 | #endif |
---|
902 | irq[irq_index]->channel = value; |
---|
903 | } |
---|
904 | else |
---|
905 | { |
---|
906 | irq[irq_index]->channel = 0; |
---|
907 | } |
---|
908 | |
---|
909 | irq_index++; |
---|
910 | irq_loc_index++; |
---|
911 | |
---|
912 | } // end irqNode |
---|
913 | |
---|
914 | |
---|
915 | //////////////////////////////////////// |
---|
916 | void periphNode(xmlTextReaderPtr reader) |
---|
917 | { |
---|
918 | char * str; |
---|
919 | unsigned int value; |
---|
920 | unsigned int ok; |
---|
921 | |
---|
922 | irq_loc_index = 0; |
---|
923 | |
---|
924 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
925 | |
---|
926 | if (periph_index >= MAX_PERIPHS) |
---|
927 | { |
---|
928 | printf("[XML ERROR] The number of periphs is larger than %d\n", MAX_PERIPHS); |
---|
929 | exit(1); |
---|
930 | } |
---|
931 | |
---|
932 | #if XML_PARSER_DEBUG |
---|
933 | printf("\n periph %d\n", periph_index); |
---|
934 | #endif |
---|
935 | |
---|
936 | periph[periph_index] = (mapping_periph_t *) malloc(sizeof(mapping_periph_t)); |
---|
937 | |
---|
938 | ///////// get channels attribute (optionnal : 1 if missing) |
---|
939 | value = getIntValue(reader, "channels", &ok); |
---|
940 | if (ok) |
---|
941 | { |
---|
942 | #if XML_PARSER_DEBUG |
---|
943 | printf(" channels = %d\n", value); |
---|
944 | #endif |
---|
945 | periph[periph_index]->channels = value; |
---|
946 | } |
---|
947 | else |
---|
948 | { |
---|
949 | periph[periph_index]->channels = 1; |
---|
950 | } |
---|
951 | |
---|
952 | ///////// get arg0 attribute (optionnal : undefined if missing) |
---|
953 | value = getIntValue(reader, "arg0", &ok); |
---|
954 | if (ok) |
---|
955 | { |
---|
956 | #if XML_PARSER_DEBUG |
---|
957 | printf(" arg0 = %d\n", value); |
---|
958 | #endif |
---|
959 | periph[periph_index]->arg0 = value; |
---|
960 | } |
---|
961 | |
---|
962 | ///////// get arg1 attribute (optionnal : undefined if missing) |
---|
963 | value = getIntValue(reader, "arg1", &ok); |
---|
964 | if (ok) |
---|
965 | { |
---|
966 | #if XML_PARSER_DEBUG |
---|
967 | printf(" arg1 = %d\n", value); |
---|
968 | #endif |
---|
969 | periph[periph_index]->arg1 = value; |
---|
970 | } |
---|
971 | |
---|
972 | ///////// get arg2 attribute (optionnal : undefined if missing) |
---|
973 | value = getIntValue(reader, "arg2", &ok); |
---|
974 | if (ok) |
---|
975 | { |
---|
976 | #if XML_PARSER_DEBUG |
---|
977 | printf(" arg2 = %d\n", value); |
---|
978 | #endif |
---|
979 | periph[periph_index]->arg2 = value; |
---|
980 | } |
---|
981 | |
---|
982 | ///////// get arg3 attribute (optionnal : undefined if missing) |
---|
983 | value = getIntValue(reader, "arg3", &ok); |
---|
984 | if (ok) |
---|
985 | { |
---|
986 | #if XML_PARSER_DEBUG |
---|
987 | printf(" arg3 = %d\n", value); |
---|
988 | #endif |
---|
989 | periph[periph_index]->arg3 = value; |
---|
990 | } |
---|
991 | |
---|
992 | /////////// get psegname attribute |
---|
993 | str = getStringValue(reader, "psegname", &ok); |
---|
994 | if (ok == 0) |
---|
995 | { |
---|
996 | printf("[XML ERROR] illegal or missing <psegname> for coproc %d in cluster %d\n", |
---|
997 | coproc_index, cluster_index); |
---|
998 | exit(1); |
---|
999 | } |
---|
1000 | |
---|
1001 | /////////// set psegid attribute |
---|
1002 | int index = getPsegId( cluster[cluster_index]->x, cluster[cluster_index]->y, str); |
---|
1003 | if (index >= 0) |
---|
1004 | { |
---|
1005 | #if XML_PARSER_DEBUG |
---|
1006 | printf(" clusterid = %d\n", cluster_index); |
---|
1007 | printf(" psegname = %s\n", str); |
---|
1008 | printf(" psegid = %d\n", index); |
---|
1009 | #endif |
---|
1010 | periph[periph_index]->psegid = index; |
---|
1011 | } |
---|
1012 | else |
---|
1013 | { |
---|
1014 | printf("[XML ERROR] pseg not found for periph %d / clusterid = %d / psegname = %s\n", |
---|
1015 | periph_loc_index, cluster_index, str ); |
---|
1016 | exit(1); |
---|
1017 | } |
---|
1018 | |
---|
1019 | /////////// get type attribute |
---|
1020 | str = getStringValue(reader, "type", &ok); |
---|
1021 | if (ok) |
---|
1022 | { |
---|
1023 | #if XML_PARSER_DEBUG |
---|
1024 | printf(" type = %s\n", str); |
---|
1025 | #endif |
---|
1026 | if (strcmp(str, "CMA" ) == 0) periph[periph_index]->type = PERIPH_TYPE_CMA; |
---|
1027 | else if (strcmp(str, "DMA" ) == 0) periph[periph_index]->type = PERIPH_TYPE_DMA; |
---|
1028 | else if (strcmp(str, "FBF" ) == 0) periph[periph_index]->type = PERIPH_TYPE_FBF; |
---|
1029 | else if (strcmp(str, "IOB" ) == 0) periph[periph_index]->type = PERIPH_TYPE_IOB; |
---|
1030 | else if (strcmp(str, "IOC" ) == 0) periph[periph_index]->type = PERIPH_TYPE_IOC; |
---|
1031 | else if (strcmp(str, "MMC" ) == 0) periph[periph_index]->type = PERIPH_TYPE_MMC; |
---|
1032 | else if (strcmp(str, "MWR" ) == 0) periph[periph_index]->type = PERIPH_TYPE_MWR; |
---|
1033 | else if (strcmp(str, "NIC" ) == 0) periph[periph_index]->type = PERIPH_TYPE_NIC; |
---|
1034 | else if (strcmp(str, "ROM" ) == 0) periph[periph_index]->type = PERIPH_TYPE_ROM; |
---|
1035 | else if (strcmp(str, "SIM" ) == 0) periph[periph_index]->type = PERIPH_TYPE_SIM; |
---|
1036 | else if (strcmp(str, "SIM" ) == 0) periph[periph_index]->type = PERIPH_TYPE_TIM; |
---|
1037 | else if (strcmp(str, "TTY" ) == 0) periph[periph_index]->type = PERIPH_TYPE_TTY; |
---|
1038 | else if (strcmp(str, "XCU" ) == 0) periph[periph_index]->type = PERIPH_TYPE_XCU; |
---|
1039 | else if (strcmp(str, "PIC" ) == 0) periph[periph_index]->type = PERIPH_TYPE_PIC; |
---|
1040 | else if (strcmp(str, "DROM") == 0) periph[periph_index]->type = PERIPH_TYPE_DROM; |
---|
1041 | else |
---|
1042 | { |
---|
1043 | printf("[XML ERROR] illegal peripheral type: %s in cluster %d\n", |
---|
1044 | str, cluster_index); |
---|
1045 | exit(1); |
---|
1046 | } |
---|
1047 | } |
---|
1048 | |
---|
1049 | ////////// get subtype if IOC |
---|
1050 | if (periph[periph_index]->type == PERIPH_TYPE_IOC ) |
---|
1051 | { |
---|
1052 | char* subtype = getStringValue(reader, "subtype", &ok); |
---|
1053 | if (ok) |
---|
1054 | { |
---|
1055 | #if XML_PARSER_DEBUG |
---|
1056 | printf(" subtype = %s\n", str); |
---|
1057 | #endif |
---|
1058 | if (strcmp(subtype, "BDV") == 0) |
---|
1059 | periph[periph_index]->subtype = IOC_SUBTYPE_BDV; |
---|
1060 | else if (strcmp(subtype, "HBA") == 0) |
---|
1061 | periph[periph_index]->subtype = IOC_SUBTYPE_HBA; |
---|
1062 | else if (strcmp(subtype, "SPI") == 0) |
---|
1063 | periph[periph_index]->subtype = IOC_SUBTYPE_SPI; |
---|
1064 | } |
---|
1065 | else |
---|
1066 | { |
---|
1067 | printf("[XML ERROR] illegal subtype for IOC peripheral\n"); |
---|
1068 | exit(1); |
---|
1069 | } |
---|
1070 | } |
---|
1071 | else |
---|
1072 | { |
---|
1073 | periph[periph_index]->subtype = 0XFFFFFFFF; |
---|
1074 | } |
---|
1075 | |
---|
1076 | ////////// get subtype if MWR |
---|
1077 | if (periph[periph_index]->type == PERIPH_TYPE_MWR ) |
---|
1078 | { |
---|
1079 | char* subtype = getStringValue(reader, "subtype", &ok); |
---|
1080 | if (ok) |
---|
1081 | { |
---|
1082 | #if XML_PARSER_DEBUG |
---|
1083 | printf(" subtype = %s\n", str); |
---|
1084 | #endif |
---|
1085 | if (strcmp(subtype, "GCD") == 0) |
---|
1086 | periph[periph_index]->subtype = MWR_SUBTYPE_GCD; |
---|
1087 | else if (strcmp(subtype, "DCT") == 0) |
---|
1088 | periph[periph_index]->subtype = MWR_SUBTYPE_DCT; |
---|
1089 | } |
---|
1090 | else |
---|
1091 | { |
---|
1092 | printf("[XML ERROR] illegal subtype for MWR peripheral\n"); |
---|
1093 | exit(1); |
---|
1094 | } |
---|
1095 | } |
---|
1096 | else |
---|
1097 | { |
---|
1098 | periph[periph_index]->subtype = 0XFFFFFFFF; |
---|
1099 | } |
---|
1100 | |
---|
1101 | ////////////// set irq_offset attribute |
---|
1102 | periph[periph_index]->irq_offset = irq_index; |
---|
1103 | |
---|
1104 | ///////////// get IRQs |
---|
1105 | int status = xmlTextReaderRead(reader); |
---|
1106 | while (status == 1) |
---|
1107 | { |
---|
1108 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
1109 | |
---|
1110 | if (strcmp(tag, "irq") == 0) |
---|
1111 | { |
---|
1112 | if ( (periph[periph_index]->type != PERIPH_TYPE_XCU) && |
---|
1113 | (periph[periph_index]->type != PERIPH_TYPE_PIC) ) |
---|
1114 | { |
---|
1115 | printf("[XML ERROR] periph %d in cluster(%d,%d) " |
---|
1116 | " only XCU and PIC can contain IRQs", |
---|
1117 | periph_loc_index, cluster[cluster_index]->x, cluster[cluster_index]->y); |
---|
1118 | exit(1); |
---|
1119 | } |
---|
1120 | else |
---|
1121 | { |
---|
1122 | irqNode(reader); |
---|
1123 | } |
---|
1124 | } |
---|
1125 | else if (strcmp(tag, "#text") == 0) { } |
---|
1126 | else if (strcmp(tag, "#comment") == 0) { } |
---|
1127 | else if (strcmp(tag, "periph") == 0) |
---|
1128 | { |
---|
1129 | periph[periph_index]->irqs = irq_loc_index; |
---|
1130 | cluster[cluster_index]->periphs++; |
---|
1131 | periph_loc_index++; |
---|
1132 | periph_index++; |
---|
1133 | |
---|
1134 | #if XML_PARSER_DEBUG |
---|
1135 | printf(" irqs = %d\n", irq_loc_index); |
---|
1136 | printf(" irq_offset = %d\n", irq_index); |
---|
1137 | #endif |
---|
1138 | return; |
---|
1139 | } |
---|
1140 | else |
---|
1141 | { |
---|
1142 | printf("[XML ERROR] Unknown tag %s", tag); |
---|
1143 | exit(1); |
---|
1144 | } |
---|
1145 | status = xmlTextReaderRead(reader); |
---|
1146 | } |
---|
1147 | } // end periphNode |
---|
1148 | |
---|
1149 | ////////////////////////////////////// |
---|
1150 | void procNode(xmlTextReaderPtr reader) |
---|
1151 | { |
---|
1152 | unsigned int ok; |
---|
1153 | unsigned int value; |
---|
1154 | |
---|
1155 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
1156 | |
---|
1157 | if (proc_index >= MAX_PROCS) |
---|
1158 | { |
---|
1159 | printf("[XML ERROR] The number of procs is larger than %d\n", MAX_PROCS); |
---|
1160 | exit(1); |
---|
1161 | } |
---|
1162 | |
---|
1163 | #if XML_PARSER_DEBUG |
---|
1164 | printf("\n proc %d\n", proc_index); |
---|
1165 | #endif |
---|
1166 | |
---|
1167 | proc[proc_index] = (mapping_proc_t *) malloc(sizeof(mapping_proc_t)); |
---|
1168 | |
---|
1169 | /////////// get index attribute (optional) |
---|
1170 | value = getIntValue(reader, "index", &ok); |
---|
1171 | if (ok && (value != proc_loc_index)) |
---|
1172 | { |
---|
1173 | printf("[XML ERROR] wrong local proc index / expected value is %d", |
---|
1174 | proc_loc_index); |
---|
1175 | exit(1); |
---|
1176 | } |
---|
1177 | proc[proc_index]->index = proc_loc_index; |
---|
1178 | |
---|
1179 | cluster[cluster_index]->procs++; |
---|
1180 | proc_loc_index++; |
---|
1181 | proc_index++; |
---|
1182 | } // end procNode() |
---|
1183 | |
---|
1184 | |
---|
1185 | ////////////////////////////////////// |
---|
1186 | void psegNode(xmlTextReaderPtr reader) |
---|
1187 | { |
---|
1188 | unsigned int ok; |
---|
1189 | paddr_t ll_value; |
---|
1190 | char * str; |
---|
1191 | |
---|
1192 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
1193 | |
---|
1194 | if (pseg_index >= MAX_PSEGS) |
---|
1195 | { |
---|
1196 | printf("[XML ERROR] The number of psegs is larger than %d\n", MAX_PSEGS); |
---|
1197 | exit(1); |
---|
1198 | } |
---|
1199 | |
---|
1200 | #if XML_PARSER_DEBUG |
---|
1201 | printf(" pseg %d\n", pseg_index); |
---|
1202 | #endif |
---|
1203 | |
---|
1204 | pseg[pseg_index] = (mapping_pseg_t *) malloc(sizeof(mapping_pseg_t)); |
---|
1205 | |
---|
1206 | /////// get name attribute |
---|
1207 | str = getStringValue(reader, "name", &ok); |
---|
1208 | #if XML_PARSER_DEBUG |
---|
1209 | printf(" name = %s\n", str); |
---|
1210 | #endif |
---|
1211 | if (ok) |
---|
1212 | { |
---|
1213 | strncpy(pseg[pseg_index]->name, str, 31); |
---|
1214 | } |
---|
1215 | else |
---|
1216 | { |
---|
1217 | printf("[XML ERROR] illegal or missing <name> for pseg %d in cluster %d\n", |
---|
1218 | pseg_index, cluster_index); |
---|
1219 | exit(1); |
---|
1220 | } |
---|
1221 | |
---|
1222 | //////// get type attribute |
---|
1223 | str = getStringValue(reader, "type", &ok); |
---|
1224 | #if XML_PARSER_DEBUG |
---|
1225 | printf(" type = %s\n", str); |
---|
1226 | #endif |
---|
1227 | if (ok && (strcmp(str, "RAM" ) == 0)) { pseg[pseg_index]->type = PSEG_TYPE_RAM; } |
---|
1228 | else if (ok && (strcmp(str, "ROM" ) == 0)) { pseg[pseg_index]->type = PSEG_TYPE_ROM; } |
---|
1229 | else if (ok && (strcmp(str, "DROM" ) == 0)) { pseg[pseg_index]->type = PSEG_TYPE_ROM; } |
---|
1230 | else if (ok && (strcmp(str, "PERI") == 0)) { pseg[pseg_index]->type = PSEG_TYPE_PERI; } |
---|
1231 | else |
---|
1232 | { |
---|
1233 | printf("[XML ERROR] illegal or missing <type> for pseg %s in cluster %d\n", |
---|
1234 | pseg[pseg_index]->name, cluster_index); |
---|
1235 | exit(1); |
---|
1236 | } |
---|
1237 | |
---|
1238 | //////// get base attribute |
---|
1239 | ll_value = getPaddrValue(reader, "base", &ok); |
---|
1240 | #if XML_PARSER_DEBUG |
---|
1241 | printf(" base = 0x%llx\n", ll_value); |
---|
1242 | #endif |
---|
1243 | if (ok) |
---|
1244 | { |
---|
1245 | pseg[pseg_index]->base = ll_value; |
---|
1246 | } |
---|
1247 | else { |
---|
1248 | printf("[XML ERROR] illegal or missing <base> for pseg %s in cluster %d\n", |
---|
1249 | pseg[pseg_index]->name, cluster_index); |
---|
1250 | exit(1); |
---|
1251 | } |
---|
1252 | |
---|
1253 | //////// get length attribute |
---|
1254 | ll_value = getPaddrValue(reader, "length", &ok); |
---|
1255 | #if XML_PARSER_DEBUG |
---|
1256 | printf(" length = 0x%llx\n", ll_value); |
---|
1257 | #endif |
---|
1258 | if (ok) |
---|
1259 | { |
---|
1260 | pseg[pseg_index]->length = ll_value; |
---|
1261 | } |
---|
1262 | else |
---|
1263 | { |
---|
1264 | printf("[XML ERROR] illegal or missing <length> for pseg %s in cluster %d\n", |
---|
1265 | pseg[pseg_index]->name, cluster_index); |
---|
1266 | exit(1); |
---|
1267 | } |
---|
1268 | |
---|
1269 | //////// set cluster attribute |
---|
1270 | pseg[pseg_index]->clusterid = cluster_index; |
---|
1271 | |
---|
1272 | //////// set next_vseg attribute |
---|
1273 | pseg[pseg_index]->next_vseg = 0; |
---|
1274 | |
---|
1275 | pseg_index++; |
---|
1276 | cluster[cluster_index]->psegs++; |
---|
1277 | } // end psegNode() |
---|
1278 | |
---|
1279 | |
---|
1280 | ///////////////////////////////////////// |
---|
1281 | void clusterNode(xmlTextReaderPtr reader) |
---|
1282 | { |
---|
1283 | unsigned int ok; |
---|
1284 | unsigned int value; |
---|
1285 | |
---|
1286 | cluster[cluster_index] = (mapping_cluster_t *) malloc(sizeof(mapping_cluster_t)); |
---|
1287 | |
---|
1288 | //initialise variables that will be incremented by *Node() functions |
---|
1289 | cluster[cluster_index]->psegs = 0; |
---|
1290 | cluster[cluster_index]->procs = 0; |
---|
1291 | cluster[cluster_index]->coprocs = 0; |
---|
1292 | cluster[cluster_index]->periphs = 0; |
---|
1293 | |
---|
1294 | //initialise global variables |
---|
1295 | proc_loc_index = 0; |
---|
1296 | coproc_loc_index = 0; |
---|
1297 | periph_loc_index = 0; |
---|
1298 | |
---|
1299 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
1300 | |
---|
1301 | #if XML_PARSER_DEBUG |
---|
1302 | printf("\n cluster %d\n", cluster_index); |
---|
1303 | #endif |
---|
1304 | |
---|
1305 | /////////// get x coordinate |
---|
1306 | value = getIntValue(reader, "x", &ok); |
---|
1307 | #if XML_PARSER_DEBUG |
---|
1308 | printf(" x = %d\n", value); |
---|
1309 | #endif |
---|
1310 | if (ok && (value < header->x_size) ) |
---|
1311 | { |
---|
1312 | cluster[cluster_index]->x = value; |
---|
1313 | } |
---|
1314 | else |
---|
1315 | { |
---|
1316 | printf("[XML ERROR] Illegal or missing < x > attribute for cluster %d", |
---|
1317 | cluster_index); |
---|
1318 | exit(1); |
---|
1319 | } |
---|
1320 | |
---|
1321 | /////////// get y coordinate |
---|
1322 | value = getIntValue(reader, "y", &ok); |
---|
1323 | #if XML_PARSER_DEBUG |
---|
1324 | printf(" y = %d\n", value); |
---|
1325 | #endif |
---|
1326 | if (ok && (value < header->y_size) ) |
---|
1327 | { |
---|
1328 | cluster[cluster_index]->y = value; |
---|
1329 | } |
---|
1330 | else |
---|
1331 | { |
---|
1332 | printf("[XML ERROR] Illegal or missing < y > attribute for cluster %d", |
---|
1333 | cluster_index); |
---|
1334 | exit(1); |
---|
1335 | } |
---|
1336 | |
---|
1337 | ////////// set offsets |
---|
1338 | cluster[cluster_index]->pseg_offset = pseg_index; |
---|
1339 | cluster[cluster_index]->proc_offset = proc_index; |
---|
1340 | cluster[cluster_index]->coproc_offset = coproc_index; |
---|
1341 | cluster[cluster_index]->periph_offset = periph_index; |
---|
1342 | |
---|
1343 | #if XML_PARSER_DEBUG |
---|
1344 | printf(" pseg_offset = %d\n", pseg_index); |
---|
1345 | printf(" proc_offset = %d\n", proc_index); |
---|
1346 | printf(" coproc_offset = %d\n", coproc_index); |
---|
1347 | printf(" periph_offset = %d\n", coproc_index); |
---|
1348 | #endif |
---|
1349 | |
---|
1350 | ////////// get psegs, procs, coprocs and periphs |
---|
1351 | int status = xmlTextReaderRead(reader); |
---|
1352 | |
---|
1353 | while (status == 1) |
---|
1354 | { |
---|
1355 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
1356 | |
---|
1357 | if (strcmp(tag, "pseg") == 0) psegNode(reader); |
---|
1358 | else if (strcmp(tag, "proc") == 0) procNode(reader); |
---|
1359 | else if (strcmp(tag, "coproc") == 0) coprocNode(reader); |
---|
1360 | else if (strcmp(tag, "periph") == 0) periphNode(reader); |
---|
1361 | else if (strcmp(tag, "#text") == 0) { } |
---|
1362 | else if (strcmp(tag, "#comment") == 0) { } |
---|
1363 | else if (strcmp(tag, "cluster") == 0) |
---|
1364 | { |
---|
1365 | |
---|
1366 | #if XML_PARSER_DEBUG |
---|
1367 | printf(" psegs = %d\n", cluster[cluster_index]->psegs); |
---|
1368 | printf(" procs = %d\n", cluster[cluster_index]->procs); |
---|
1369 | printf(" coprocs = %d\n", cluster[cluster_index]->coprocs); |
---|
1370 | printf(" periphs = %d\n", cluster[cluster_index]->periphs); |
---|
1371 | printf(" end cluster %d\n", cluster_index); |
---|
1372 | #endif |
---|
1373 | cluster_index++; |
---|
1374 | return; |
---|
1375 | } |
---|
1376 | status = xmlTextReaderRead(reader); |
---|
1377 | } |
---|
1378 | } // end clusterNode() |
---|
1379 | |
---|
1380 | |
---|
1381 | ////////////////////////////////////////////// |
---|
1382 | void clusterSetNode(xmlTextReaderPtr reader) |
---|
1383 | { |
---|
1384 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
1385 | |
---|
1386 | #if XML_PARSER_DEBUG |
---|
1387 | printf("\n clusters set\n"); |
---|
1388 | #endif |
---|
1389 | |
---|
1390 | int status = xmlTextReaderRead(reader); |
---|
1391 | while (status == 1) |
---|
1392 | { |
---|
1393 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
1394 | |
---|
1395 | if (strcmp(tag, "cluster") == 0) { clusterNode(reader); } |
---|
1396 | else if (strcmp(tag, "#text") == 0) { } |
---|
1397 | else if (strcmp(tag, "#comment") == 0) { } |
---|
1398 | else if (strcmp(tag, "clusterset") == 0) |
---|
1399 | { |
---|
1400 | // checking number of clusters |
---|
1401 | if ( cluster_index != (header->x_size * header->y_size) ) |
---|
1402 | { |
---|
1403 | printf("[XML ERROR] Wrong number of clusters\n"); |
---|
1404 | exit(1); |
---|
1405 | } |
---|
1406 | |
---|
1407 | #if XML_PARSER_DEBUG |
---|
1408 | printf(" end cluster set\n\n"); |
---|
1409 | #endif |
---|
1410 | header->psegs = pseg_index; |
---|
1411 | header->procs = proc_index; |
---|
1412 | header->irqs = irq_index; |
---|
1413 | header->coprocs = coproc_index; |
---|
1414 | header->periphs = periph_index; |
---|
1415 | return; |
---|
1416 | } |
---|
1417 | else |
---|
1418 | { |
---|
1419 | printf("[XML ERROR] Unknown tag in clusterset node : %s",tag); |
---|
1420 | exit(1); |
---|
1421 | } |
---|
1422 | status = xmlTextReaderRead(reader); |
---|
1423 | } |
---|
1424 | } // end clusterSetNode() |
---|
1425 | |
---|
1426 | |
---|
1427 | /////////////////////////////////////////// |
---|
1428 | void globalSetNode(xmlTextReaderPtr reader) |
---|
1429 | { |
---|
1430 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
1431 | |
---|
1432 | #if XML_PARSER_DEBUG |
---|
1433 | printf(" globals set\n"); |
---|
1434 | #endif |
---|
1435 | |
---|
1436 | int status = xmlTextReaderRead(reader); |
---|
1437 | while (status == 1) |
---|
1438 | { |
---|
1439 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
1440 | |
---|
1441 | if (strcmp(tag, "vseg") == 0) |
---|
1442 | { |
---|
1443 | vsegNode( reader ); |
---|
1444 | header->globals = header->globals + 1; |
---|
1445 | } |
---|
1446 | else if (strcmp(tag, "#text") == 0) { } |
---|
1447 | else if (strcmp(tag, "#comment") == 0) { } |
---|
1448 | else if (strcmp(tag, "globalset") == 0) |
---|
1449 | { |
---|
1450 | #if XML_PARSER_DEBUG |
---|
1451 | printf(" end global set\n\n"); |
---|
1452 | #endif |
---|
1453 | vseg_loc_index = 0; |
---|
1454 | return; |
---|
1455 | } |
---|
1456 | else |
---|
1457 | { |
---|
1458 | printf("[XML ERROR] Unknown tag in globalset node : %s",tag); |
---|
1459 | exit(1); |
---|
1460 | } |
---|
1461 | status = xmlTextReaderRead(reader); |
---|
1462 | } |
---|
1463 | } // end globalSetNode() |
---|
1464 | |
---|
1465 | |
---|
1466 | /////////////////////////////////////////// |
---|
1467 | void vspaceSetNode(xmlTextReaderPtr reader) |
---|
1468 | { |
---|
1469 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { |
---|
1470 | return; |
---|
1471 | } |
---|
1472 | |
---|
1473 | #if XML_PARSER_DEBUG |
---|
1474 | printf("\n vspaces set\n"); |
---|
1475 | #endif |
---|
1476 | |
---|
1477 | int status = xmlTextReaderRead ( reader ); |
---|
1478 | while (status == 1) { |
---|
1479 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
1480 | |
---|
1481 | if (strcmp(tag, "vspace") == 0) { |
---|
1482 | vspaceNode(reader); |
---|
1483 | } |
---|
1484 | else if (strcmp(tag, "#text" ) == 0 ) { } |
---|
1485 | else if (strcmp(tag, "#comment" ) == 0 ) { } |
---|
1486 | else if (strcmp(tag, "vspaceset") == 0 ) |
---|
1487 | { |
---|
1488 | header->vsegs = vseg_index; |
---|
1489 | header->tasks = task_index; |
---|
1490 | return; |
---|
1491 | } |
---|
1492 | else |
---|
1493 | { |
---|
1494 | printf("[XML ERROR] Unknown tag in vspaceset node : %s",tag); |
---|
1495 | exit(1); |
---|
1496 | } |
---|
1497 | status = xmlTextReaderRead(reader); |
---|
1498 | } |
---|
1499 | } // end globalSetNode() |
---|
1500 | |
---|
1501 | |
---|
1502 | //////////////////////////////////////// |
---|
1503 | void headerNode(xmlTextReaderPtr reader) |
---|
1504 | { |
---|
1505 | char * name; |
---|
1506 | unsigned int value; |
---|
1507 | unsigned int ok; |
---|
1508 | |
---|
1509 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
1510 | |
---|
1511 | #if XML_PARSER_DEBUG |
---|
1512 | printf("mapping_info\n"); |
---|
1513 | #endif |
---|
1514 | |
---|
1515 | header = (mapping_header_t *) malloc(sizeof(mapping_header_t)); |
---|
1516 | |
---|
1517 | ////////// get name attribute |
---|
1518 | name = getStringValue(reader, "name", &ok); |
---|
1519 | if (ok) |
---|
1520 | { |
---|
1521 | #if XML_PARSER_DEBUG |
---|
1522 | printf(" name = %s\n", name); |
---|
1523 | #endif |
---|
1524 | strncpy( header->name, name, 31); |
---|
1525 | } |
---|
1526 | else |
---|
1527 | { |
---|
1528 | printf("[XML ERROR] illegal or missing <name> attribute in header\n"); |
---|
1529 | exit(1); |
---|
1530 | } |
---|
1531 | |
---|
1532 | /////////// get signature attribute |
---|
1533 | value = getIntValue(reader, "signature", &ok); |
---|
1534 | if ( ok && (value == IN_MAPPING_SIGNATURE) ) |
---|
1535 | { |
---|
1536 | #if XML_PARSER_DEBUG |
---|
1537 | printf(" signature = %x\n", value); |
---|
1538 | #endif |
---|
1539 | header->signature = IN_MAPPING_SIGNATURE; |
---|
1540 | } |
---|
1541 | else |
---|
1542 | { |
---|
1543 | printf("[XML ERROR] illegal or missing <signature> for mapping %s\n", |
---|
1544 | header->name ); |
---|
1545 | exit(1); |
---|
1546 | } |
---|
1547 | |
---|
1548 | /////////// get x_width attribute |
---|
1549 | value = getIntValue(reader, "x_width", &ok); |
---|
1550 | if (ok) |
---|
1551 | { |
---|
1552 | #if XML_PARSER_DEBUG |
---|
1553 | printf(" x_width = %d\n", value); |
---|
1554 | #endif |
---|
1555 | header->x_width = value; |
---|
1556 | } |
---|
1557 | |
---|
1558 | /////////// get y_width attribute |
---|
1559 | value = getIntValue(reader, "y_width", &ok); |
---|
1560 | if (ok) |
---|
1561 | { |
---|
1562 | #if XML_PARSER_DEBUG |
---|
1563 | printf(" y_width = %d\n", value); |
---|
1564 | #endif |
---|
1565 | header->y_width = value; |
---|
1566 | } |
---|
1567 | |
---|
1568 | /////////// get x_size attribute |
---|
1569 | unsigned int x_size = getIntValue(reader, "x_size", &ok); |
---|
1570 | if (ok) |
---|
1571 | { |
---|
1572 | #if XML_PARSER_DEBUG |
---|
1573 | printf(" x_size = %d\n", x_size); |
---|
1574 | #endif |
---|
1575 | header->x_size = x_size; |
---|
1576 | } |
---|
1577 | else |
---|
1578 | { |
---|
1579 | printf("[XML ERROR] illegal or missing <x_size> attribute in header\n"); |
---|
1580 | exit(1); |
---|
1581 | } |
---|
1582 | |
---|
1583 | /////////// get y_size attribute |
---|
1584 | unsigned int y_size = getIntValue(reader, "y_size", &ok); |
---|
1585 | if (ok) |
---|
1586 | { |
---|
1587 | #if XML_PARSER_DEBUG |
---|
1588 | printf(" y_size = %d\n", y_size); |
---|
1589 | #endif |
---|
1590 | header->y_size = y_size; |
---|
1591 | } |
---|
1592 | else |
---|
1593 | { |
---|
1594 | printf("[XML ERROR] illegal or missing <y_size> attribute in header\n"); |
---|
1595 | exit(1); |
---|
1596 | } |
---|
1597 | |
---|
1598 | /////////// get x_io attribute |
---|
1599 | unsigned int x_io = getIntValue(reader, "x_io", &ok); |
---|
1600 | #if XML_PARSER_DEBUG |
---|
1601 | printf(" x_io = %d\n", x_io); |
---|
1602 | #endif |
---|
1603 | if ( ok && (x_io < x_size) ) |
---|
1604 | { |
---|
1605 | header->x_io = x_io; |
---|
1606 | } |
---|
1607 | else |
---|
1608 | { |
---|
1609 | printf("[XML ERROR] illegal or missing <x_io> attribute in header\n"); |
---|
1610 | exit(1); |
---|
1611 | } |
---|
1612 | |
---|
1613 | /////////// get y_io attribute |
---|
1614 | unsigned int y_io = getIntValue(reader, "y_io", &ok); |
---|
1615 | #if XML_PARSER_DEBUG |
---|
1616 | printf(" y_io = %d\n", y_io); |
---|
1617 | #endif |
---|
1618 | if ( ok &&(y_io < y_size) ) |
---|
1619 | { |
---|
1620 | header->y_io = y_io; |
---|
1621 | } |
---|
1622 | else |
---|
1623 | { |
---|
1624 | printf("[XML ERROR] illegal or missing <y_io> attribute in header\n"); |
---|
1625 | exit(1); |
---|
1626 | } |
---|
1627 | |
---|
1628 | // check the number of cluster |
---|
1629 | if ( (x_size * y_size) >= MAX_CLUSTERS ) |
---|
1630 | { |
---|
1631 | printf("[XML ERROR] Number of clusters cannot be larger than %d\n", MAX_CLUSTERS); |
---|
1632 | exit(1); |
---|
1633 | } |
---|
1634 | |
---|
1635 | ///////// get irq_per_proc attribute |
---|
1636 | value = getIntValue(reader, "irq_per_proc", &ok); |
---|
1637 | if (ok) |
---|
1638 | { |
---|
1639 | #if XML_PARSER_DEBUG |
---|
1640 | printf(" irq_per_proc = %d\n", value); |
---|
1641 | #endif |
---|
1642 | header->irq_per_proc = value; |
---|
1643 | } |
---|
1644 | else |
---|
1645 | { |
---|
1646 | printf("[XML ERROR] illegal or missing <irq_per_proc> attribute in mapping\n"); |
---|
1647 | exit(1); |
---|
1648 | } |
---|
1649 | |
---|
1650 | ///////// get use_ram_disk attribute (default = 0) |
---|
1651 | value = getIntValue(reader, "use_ram_disk", &ok); |
---|
1652 | if (ok) |
---|
1653 | { |
---|
1654 | #if XML_PARSER_DEBUG |
---|
1655 | printf(" use_ram_disk = %d\n", value); |
---|
1656 | #endif |
---|
1657 | header->use_ram_disk = value; |
---|
1658 | } |
---|
1659 | else |
---|
1660 | { |
---|
1661 | header->use_ram_disk = 0; |
---|
1662 | } |
---|
1663 | |
---|
1664 | ///////// set other header fields |
---|
1665 | header->globals = 0; |
---|
1666 | header->vspaces = 0; |
---|
1667 | header->psegs = 0; |
---|
1668 | header->vsegs = 0; |
---|
1669 | header->tasks = 0; |
---|
1670 | header->procs = 0; |
---|
1671 | header->irqs = 0; |
---|
1672 | header->coprocs = 0; |
---|
1673 | header->periphs = 0; |
---|
1674 | |
---|
1675 | |
---|
1676 | int status = xmlTextReaderRead(reader); |
---|
1677 | while (status == 1) |
---|
1678 | { |
---|
1679 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
1680 | |
---|
1681 | if (strcmp(tag, "clusterset") == 0) { clusterSetNode(reader); } |
---|
1682 | else if (strcmp(tag, "globalset") == 0) { globalSetNode(reader); } |
---|
1683 | else if (strcmp(tag, "vspaceset") == 0) { vspaceSetNode(reader); } |
---|
1684 | else if (strcmp(tag, "#text") == 0) { } |
---|
1685 | else if (strcmp(tag, "#comment") == 0) { } |
---|
1686 | else if (strcmp(tag, "mapping_info") == 0) |
---|
1687 | { |
---|
1688 | #if XML_PARSER_DEBUG |
---|
1689 | printf("end mapping_info\n"); |
---|
1690 | #endif |
---|
1691 | return; |
---|
1692 | } |
---|
1693 | else |
---|
1694 | { |
---|
1695 | printf("[XML ERROR] Unknown tag in header node : %s\n",tag); |
---|
1696 | exit(1); |
---|
1697 | } |
---|
1698 | status = xmlTextReaderRead(reader); |
---|
1699 | } |
---|
1700 | } // end headerNode() |
---|
1701 | |
---|
1702 | |
---|
1703 | //////////////////////////////////// |
---|
1704 | void BuildTable( int fdout, |
---|
1705 | const char * type, |
---|
1706 | unsigned int nb_elem, |
---|
1707 | unsigned int elem_size, |
---|
1708 | char ** table ) |
---|
1709 | { |
---|
1710 | unsigned int i; |
---|
1711 | for (i = 0; i < nb_elem; i++) |
---|
1712 | { |
---|
1713 | if (elem_size != write(fdout, table[i], elem_size)) |
---|
1714 | { |
---|
1715 | printf("function %s: %s(%d) write error \n", __FUNCTION__, type, i); |
---|
1716 | exit(1); |
---|
1717 | } |
---|
1718 | |
---|
1719 | #if XML_PARSER_DEBUG |
---|
1720 | printf("Building binary: writing %s %d\n", type, i); |
---|
1721 | #endif |
---|
1722 | } |
---|
1723 | } |
---|
1724 | |
---|
1725 | ///////////////////////////////////// |
---|
1726 | int open_file(const char * file_path) |
---|
1727 | { |
---|
1728 | //open file |
---|
1729 | int fdout = open( file_path, (O_CREAT | O_RDWR), (S_IWUSR | S_IRUSR) ); |
---|
1730 | if (fdout < 0) |
---|
1731 | { |
---|
1732 | perror("open"); |
---|
1733 | exit(1); |
---|
1734 | } |
---|
1735 | |
---|
1736 | //reinitialise the file |
---|
1737 | if (ftruncate(fdout, 0)) |
---|
1738 | { |
---|
1739 | perror("truncate"); |
---|
1740 | exit(1); |
---|
1741 | } |
---|
1742 | |
---|
1743 | //#if XML_PARSER_DEBUG |
---|
1744 | printf("%s\n", file_path); |
---|
1745 | //#endif |
---|
1746 | |
---|
1747 | return fdout; |
---|
1748 | } |
---|
1749 | |
---|
1750 | |
---|
1751 | ///////////////////////////////////// |
---|
1752 | void buildBin(const char * file_path) |
---|
1753 | { |
---|
1754 | unsigned int length; |
---|
1755 | |
---|
1756 | int fdout = open_file(file_path); |
---|
1757 | |
---|
1758 | #if XML_PARSER_DEBUG |
---|
1759 | printf("Building map.bin for %s\n", header->name); |
---|
1760 | printf("signature = %x\n", header->signature); |
---|
1761 | printf("x_size = %d\n", header->x_size); |
---|
1762 | printf("y_size = %d\n", header->y_size); |
---|
1763 | printf("x_width = %d\n", header->x_width); |
---|
1764 | printf("y_width = %d\n", header->y_width); |
---|
1765 | printf("vspaces = %d\n", header->vspaces); |
---|
1766 | printf("psegs = %d\n", header->psegs); |
---|
1767 | printf("vsegs = %d\n", header->vsegs); |
---|
1768 | printf("tasks = %d\n", header->tasks); |
---|
1769 | printf("procs = %d\n", header->procs); |
---|
1770 | printf("irqs = %d\n", header->irqs); |
---|
1771 | printf("coprocs = %d\n", header->coprocs); |
---|
1772 | printf("periphs = %d\n", header->periphs); |
---|
1773 | #endif |
---|
1774 | |
---|
1775 | // write header to binary file |
---|
1776 | length = write(fdout, (char *) header, sizeof(mapping_header_t)); |
---|
1777 | if (length != sizeof(mapping_header_t)) |
---|
1778 | { |
---|
1779 | printf("write header error : length = %d \n", length); |
---|
1780 | exit(1); |
---|
1781 | } |
---|
1782 | |
---|
1783 | // write clusters |
---|
1784 | BuildTable(fdout, "cluster", cluster_index, sizeof(mapping_cluster_t), (char **) cluster); |
---|
1785 | // write psegs |
---|
1786 | BuildTable(fdout, "pseg", pseg_index, sizeof(mapping_pseg_t), (char **) pseg); |
---|
1787 | // write vspaces |
---|
1788 | BuildTable(fdout, "vspace", vspace_index, sizeof(mapping_vspace_t), (char **) vspace); |
---|
1789 | // write vsegs |
---|
1790 | BuildTable(fdout, "vseg", vseg_index, sizeof(mapping_vseg_t), (char **) vseg); |
---|
1791 | // write tasks array |
---|
1792 | BuildTable(fdout, "task", task_index, sizeof(mapping_task_t), (char **) task); |
---|
1793 | //building procs array |
---|
1794 | BuildTable(fdout, "proc", proc_index, sizeof(mapping_proc_t), (char **) proc); |
---|
1795 | //building irqs array |
---|
1796 | BuildTable(fdout, "irq", irq_index, sizeof(mapping_irq_t), (char **) irq); |
---|
1797 | //building coprocs array |
---|
1798 | BuildTable(fdout, "coproc", coproc_index, sizeof(mapping_coproc_t), (char **) coproc); |
---|
1799 | //building periphs array |
---|
1800 | BuildTable(fdout, "periph", periph_index, sizeof(mapping_periph_t), (char **) periph); |
---|
1801 | |
---|
1802 | close(fdout); |
---|
1803 | |
---|
1804 | } // end buildBin() |
---|
1805 | |
---|
1806 | |
---|
1807 | ////////////////////////////////////////////////////// |
---|
1808 | char * buildPath(const char * path, const char * name) |
---|
1809 | { |
---|
1810 | char * res = calloc(strlen(path) + strlen(name) + 1, 1); |
---|
1811 | strcat(res, path); |
---|
1812 | strcat(res, "/"); |
---|
1813 | strcat(res, name); |
---|
1814 | return res; |
---|
1815 | } |
---|
1816 | |
---|
1817 | |
---|
1818 | ////////////////////////////////// |
---|
1819 | int main(int argc, char * argv[]) |
---|
1820 | { |
---|
1821 | if (argc < 3) |
---|
1822 | { |
---|
1823 | printf("Usage: xml2bin <input_file_path> <output_path>\n"); |
---|
1824 | return 1; |
---|
1825 | } |
---|
1826 | |
---|
1827 | struct stat dir_st; |
---|
1828 | if (stat( argv[2], &dir_st)) |
---|
1829 | { |
---|
1830 | perror("bad path"); |
---|
1831 | exit(1); |
---|
1832 | } |
---|
1833 | |
---|
1834 | if ((dir_st.st_mode & S_IFDIR) == 0) |
---|
1835 | { |
---|
1836 | printf("path is not a dir: %s", argv[2] ); |
---|
1837 | exit(1); |
---|
1838 | } |
---|
1839 | |
---|
1840 | char * map_path = buildPath(argv[2], "map.bin"); |
---|
1841 | |
---|
1842 | LIBXML_TEST_VERSION; |
---|
1843 | |
---|
1844 | int status; |
---|
1845 | xmlTextReaderPtr reader = xmlReaderForFile(argv[1], NULL, 0); |
---|
1846 | |
---|
1847 | if (reader != NULL) |
---|
1848 | { |
---|
1849 | status = xmlTextReaderRead (reader); |
---|
1850 | while (status == 1) |
---|
1851 | { |
---|
1852 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
1853 | |
---|
1854 | if (strcmp(tag, "mapping_info") == 0) |
---|
1855 | { |
---|
1856 | headerNode(reader); |
---|
1857 | buildBin(map_path); |
---|
1858 | } |
---|
1859 | else |
---|
1860 | { |
---|
1861 | printf("[XML ERROR] Wrong file type: \"%s\"\n", argv[1]); |
---|
1862 | return 1; |
---|
1863 | } |
---|
1864 | status = xmlTextReaderRead(reader); |
---|
1865 | } |
---|
1866 | xmlFreeTextReader(reader); |
---|
1867 | |
---|
1868 | if (status != 0) |
---|
1869 | { |
---|
1870 | printf("[XML ERROR] Wrong Syntax in \"%s\" file\n", argv[1]); |
---|
1871 | return 1; |
---|
1872 | } |
---|
1873 | } |
---|
1874 | return 0; |
---|
1875 | } // end main() |
---|
1876 | |
---|
1877 | |
---|
1878 | // Local Variables: |
---|
1879 | // tab-width: 4 |
---|
1880 | // c-basic-offset: 4 |
---|
1881 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
1882 | // indent-tabs-mode: nil |
---|
1883 | // End: |
---|
1884 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
1885 | |
---|