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_DEFAULT") == 0) irq[irq_index]->isr = ISR_DEFAULT; |
---|
869 | else if (strcmp(str, "ISR_TICK" ) == 0) irq[irq_index]->isr = ISR_TICK; |
---|
870 | else if (strcmp(str, "ISR_TTY_RX" ) == 0) irq[irq_index]->isr = ISR_TTY_RX; |
---|
871 | else if (strcmp(str, "ISR_TTY_TX" ) == 0) irq[irq_index]->isr = ISR_TTY_TX; |
---|
872 | else if (strcmp(str, "ISR_BDV" ) == 0) irq[irq_index]->isr = ISR_BDV; |
---|
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_CMA" ) == 0) irq[irq_index]->isr = ISR_CMA; |
---|
878 | else if (strcmp(str, "ISR_MMC" ) == 0) irq[irq_index]->isr = ISR_MMC; |
---|
879 | else if (strcmp(str, "ISR_DMA" ) == 0) irq[irq_index]->isr = ISR_DMA; |
---|
880 | else if (strcmp(str, "ISR_SDC" ) == 0) irq[irq_index]->isr = ISR_SDC; |
---|
881 | else if (strcmp(str, "ISR_MWR" ) == 0) irq[irq_index]->isr = ISR_MWR; |
---|
882 | else if (strcmp(str, "ISR_HBA" ) == 0) irq[irq_index]->isr = ISR_HBA; |
---|
883 | else |
---|
884 | { |
---|
885 | printf("[XML ERROR] illegal IRQ <isr> for periph %d in cluster %d\n", |
---|
886 | periph_loc_index, cluster_index ); |
---|
887 | exit(1); |
---|
888 | } |
---|
889 | } |
---|
890 | else |
---|
891 | { |
---|
892 | printf("[XML ERROR] missing IRQ <isr> for periph %d in cluster %d\n", |
---|
893 | cluster_index, periph_loc_index); |
---|
894 | exit(1); |
---|
895 | } |
---|
896 | |
---|
897 | ///////// get channel attribute (optionnal : 0 if missing) |
---|
898 | value = getIntValue(reader, "channel", &ok); |
---|
899 | if (ok) |
---|
900 | { |
---|
901 | #if XML_PARSER_DEBUG |
---|
902 | printf(" channel = %d\n", value); |
---|
903 | #endif |
---|
904 | irq[irq_index]->channel = value; |
---|
905 | } |
---|
906 | else |
---|
907 | { |
---|
908 | irq[irq_index]->channel = 0; |
---|
909 | } |
---|
910 | |
---|
911 | irq_index++; |
---|
912 | irq_loc_index++; |
---|
913 | |
---|
914 | } // end irqNode |
---|
915 | |
---|
916 | |
---|
917 | //////////////////////////////////////// |
---|
918 | void periphNode(xmlTextReaderPtr reader) |
---|
919 | { |
---|
920 | char * str; |
---|
921 | unsigned int value; |
---|
922 | unsigned int ok; |
---|
923 | |
---|
924 | irq_loc_index = 0; |
---|
925 | |
---|
926 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
927 | |
---|
928 | if (periph_index >= MAX_PERIPHS) |
---|
929 | { |
---|
930 | printf("[XML ERROR] The number of periphs is larger than %d\n", MAX_PERIPHS); |
---|
931 | exit(1); |
---|
932 | } |
---|
933 | |
---|
934 | #if XML_PARSER_DEBUG |
---|
935 | printf("\n periph %d\n", periph_index); |
---|
936 | #endif |
---|
937 | |
---|
938 | periph[periph_index] = (mapping_periph_t *) malloc(sizeof(mapping_periph_t)); |
---|
939 | |
---|
940 | ///////// get channels attribute (optionnal : 1 if missing) |
---|
941 | value = getIntValue(reader, "channels", &ok); |
---|
942 | if (ok) |
---|
943 | { |
---|
944 | #if XML_PARSER_DEBUG |
---|
945 | printf(" channels = %d\n", value); |
---|
946 | #endif |
---|
947 | periph[periph_index]->channels = value; |
---|
948 | } |
---|
949 | else |
---|
950 | { |
---|
951 | periph[periph_index]->channels = 1; |
---|
952 | } |
---|
953 | |
---|
954 | ///////// get arg0 attribute (optionnal : undefined if missing) |
---|
955 | value = getIntValue(reader, "arg0", &ok); |
---|
956 | if (ok) |
---|
957 | { |
---|
958 | #if XML_PARSER_DEBUG |
---|
959 | printf(" arg0 = %d\n", value); |
---|
960 | #endif |
---|
961 | periph[periph_index]->arg0 = value; |
---|
962 | } |
---|
963 | |
---|
964 | ///////// get arg1 attribute (optionnal : undefined if missing) |
---|
965 | value = getIntValue(reader, "arg1", &ok); |
---|
966 | if (ok) |
---|
967 | { |
---|
968 | #if XML_PARSER_DEBUG |
---|
969 | printf(" arg1 = %d\n", value); |
---|
970 | #endif |
---|
971 | periph[periph_index]->arg1 = value; |
---|
972 | } |
---|
973 | |
---|
974 | ///////// get arg2 attribute (optionnal : undefined if missing) |
---|
975 | value = getIntValue(reader, "arg2", &ok); |
---|
976 | if (ok) |
---|
977 | { |
---|
978 | #if XML_PARSER_DEBUG |
---|
979 | printf(" arg2 = %d\n", value); |
---|
980 | #endif |
---|
981 | periph[periph_index]->arg2 = value; |
---|
982 | } |
---|
983 | |
---|
984 | ///////// get arg3 attribute (optionnal : undefined if missing) |
---|
985 | value = getIntValue(reader, "arg3", &ok); |
---|
986 | if (ok) |
---|
987 | { |
---|
988 | #if XML_PARSER_DEBUG |
---|
989 | printf(" arg3 = %d\n", value); |
---|
990 | #endif |
---|
991 | periph[periph_index]->arg3 = value; |
---|
992 | } |
---|
993 | |
---|
994 | /////////// get psegname attribute |
---|
995 | str = getStringValue(reader, "psegname", &ok); |
---|
996 | if (ok == 0) |
---|
997 | { |
---|
998 | printf("[XML ERROR] illegal or missing <psegname> for coproc %d in cluster %d\n", |
---|
999 | coproc_index, cluster_index); |
---|
1000 | exit(1); |
---|
1001 | } |
---|
1002 | |
---|
1003 | /////////// set psegid attribute |
---|
1004 | int index = getPsegId( cluster[cluster_index]->x, cluster[cluster_index]->y, str); |
---|
1005 | if (index >= 0) |
---|
1006 | { |
---|
1007 | #if XML_PARSER_DEBUG |
---|
1008 | printf(" clusterid = %d\n", cluster_index); |
---|
1009 | printf(" psegname = %s\n", str); |
---|
1010 | printf(" psegid = %d\n", index); |
---|
1011 | #endif |
---|
1012 | periph[periph_index]->psegid = index; |
---|
1013 | } |
---|
1014 | else |
---|
1015 | { |
---|
1016 | printf("[XML ERROR] pseg not found for periph %d / clusterid = %d / psegname = %s\n", |
---|
1017 | periph_loc_index, cluster_index, str ); |
---|
1018 | exit(1); |
---|
1019 | } |
---|
1020 | |
---|
1021 | /////////// get type attribute |
---|
1022 | str = getStringValue(reader, "type", &ok); |
---|
1023 | if (ok) |
---|
1024 | { |
---|
1025 | #if XML_PARSER_DEBUG |
---|
1026 | printf(" type = %s\n", str); |
---|
1027 | #endif |
---|
1028 | if (strcmp(str, "CMA" ) == 0) periph[periph_index]->type = PERIPH_TYPE_CMA; |
---|
1029 | else if (strcmp(str, "DMA" ) == 0) periph[periph_index]->type = PERIPH_TYPE_DMA; |
---|
1030 | else if (strcmp(str, "FBF" ) == 0) periph[periph_index]->type = PERIPH_TYPE_FBF; |
---|
1031 | else if (strcmp(str, "IOB" ) == 0) periph[periph_index]->type = PERIPH_TYPE_IOB; |
---|
1032 | else if (strcmp(str, "IOC" ) == 0) periph[periph_index]->type = PERIPH_TYPE_IOC; |
---|
1033 | else if (strcmp(str, "MMC" ) == 0) periph[periph_index]->type = PERIPH_TYPE_MMC; |
---|
1034 | else if (strcmp(str, "MWR" ) == 0) periph[periph_index]->type = PERIPH_TYPE_MWR; |
---|
1035 | else if (strcmp(str, "NIC" ) == 0) periph[periph_index]->type = PERIPH_TYPE_NIC; |
---|
1036 | else if (strcmp(str, "ROM" ) == 0) periph[periph_index]->type = PERIPH_TYPE_ROM; |
---|
1037 | else if (strcmp(str, "SIM" ) == 0) periph[periph_index]->type = PERIPH_TYPE_SIM; |
---|
1038 | else if (strcmp(str, "SIM" ) == 0) periph[periph_index]->type = PERIPH_TYPE_TIM; |
---|
1039 | else if (strcmp(str, "TTY" ) == 0) periph[periph_index]->type = PERIPH_TYPE_TTY; |
---|
1040 | else if (strcmp(str, "XCU" ) == 0) periph[periph_index]->type = PERIPH_TYPE_XCU; |
---|
1041 | else if (strcmp(str, "PIC" ) == 0) periph[periph_index]->type = PERIPH_TYPE_PIC; |
---|
1042 | else if (strcmp(str, "DROM") == 0) periph[periph_index]->type = PERIPH_TYPE_DROM; |
---|
1043 | else |
---|
1044 | { |
---|
1045 | printf("[XML ERROR] illegal peripheral type: %s in cluster %d\n", |
---|
1046 | str, cluster_index); |
---|
1047 | exit(1); |
---|
1048 | } |
---|
1049 | } |
---|
1050 | |
---|
1051 | ////////// get subtype if IOC |
---|
1052 | if (periph[periph_index]->type == PERIPH_TYPE_IOC ) |
---|
1053 | { |
---|
1054 | char* subtype = getStringValue(reader, "subtype", &ok); |
---|
1055 | if (ok) |
---|
1056 | { |
---|
1057 | #if XML_PARSER_DEBUG |
---|
1058 | printf(" subtype = %s\n", str); |
---|
1059 | #endif |
---|
1060 | if (strcmp(subtype, "BDV") == 0) |
---|
1061 | periph[periph_index]->subtype = IOC_SUBTYPE_BDV; |
---|
1062 | else if (strcmp(subtype, "HBA") == 0) |
---|
1063 | periph[periph_index]->subtype = IOC_SUBTYPE_HBA; |
---|
1064 | else if (strcmp(subtype, "SDC") == 0) |
---|
1065 | periph[periph_index]->subtype = IOC_SUBTYPE_SDC; |
---|
1066 | } |
---|
1067 | else |
---|
1068 | { |
---|
1069 | printf("[XML ERROR] illegal subtype for IOC peripheral\n"); |
---|
1070 | exit(1); |
---|
1071 | } |
---|
1072 | } |
---|
1073 | else |
---|
1074 | { |
---|
1075 | periph[periph_index]->subtype = 0XFFFFFFFF; |
---|
1076 | } |
---|
1077 | |
---|
1078 | ////////// get subtype if MWR |
---|
1079 | if (periph[periph_index]->type == PERIPH_TYPE_MWR ) |
---|
1080 | { |
---|
1081 | char* subtype = getStringValue(reader, "subtype", &ok); |
---|
1082 | if (ok) |
---|
1083 | { |
---|
1084 | #if XML_PARSER_DEBUG |
---|
1085 | printf(" subtype = %s\n", str); |
---|
1086 | #endif |
---|
1087 | if (strcmp(subtype, "GCD") == 0) |
---|
1088 | periph[periph_index]->subtype = MWR_SUBTYPE_GCD; |
---|
1089 | else if (strcmp(subtype, "DCT") == 0) |
---|
1090 | periph[periph_index]->subtype = MWR_SUBTYPE_DCT; |
---|
1091 | } |
---|
1092 | else |
---|
1093 | { |
---|
1094 | printf("[XML ERROR] illegal subtype for MWR peripheral\n"); |
---|
1095 | exit(1); |
---|
1096 | } |
---|
1097 | } |
---|
1098 | else |
---|
1099 | { |
---|
1100 | periph[periph_index]->subtype = 0XFFFFFFFF; |
---|
1101 | } |
---|
1102 | |
---|
1103 | ////////////// set irq_offset attribute |
---|
1104 | periph[periph_index]->irq_offset = irq_index; |
---|
1105 | |
---|
1106 | ///////////// get IRQs |
---|
1107 | int status = xmlTextReaderRead(reader); |
---|
1108 | while (status == 1) |
---|
1109 | { |
---|
1110 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
1111 | |
---|
1112 | if (strcmp(tag, "irq") == 0) |
---|
1113 | { |
---|
1114 | if ( (periph[periph_index]->type != PERIPH_TYPE_XCU) && |
---|
1115 | (periph[periph_index]->type != PERIPH_TYPE_PIC) ) |
---|
1116 | { |
---|
1117 | printf("[XML ERROR] periph %d in cluster(%d,%d) " |
---|
1118 | " only XCU and PIC can contain IRQs", |
---|
1119 | periph_loc_index, cluster[cluster_index]->x, cluster[cluster_index]->y); |
---|
1120 | exit(1); |
---|
1121 | } |
---|
1122 | else |
---|
1123 | { |
---|
1124 | irqNode(reader); |
---|
1125 | } |
---|
1126 | } |
---|
1127 | else if (strcmp(tag, "#text") == 0) { } |
---|
1128 | else if (strcmp(tag, "#comment") == 0) { } |
---|
1129 | else if (strcmp(tag, "periph") == 0) |
---|
1130 | { |
---|
1131 | periph[periph_index]->irqs = irq_loc_index; |
---|
1132 | cluster[cluster_index]->periphs++; |
---|
1133 | periph_loc_index++; |
---|
1134 | periph_index++; |
---|
1135 | |
---|
1136 | #if XML_PARSER_DEBUG |
---|
1137 | printf(" irqs = %d\n", irq_loc_index); |
---|
1138 | printf(" irq_offset = %d\n", irq_index); |
---|
1139 | #endif |
---|
1140 | return; |
---|
1141 | } |
---|
1142 | else |
---|
1143 | { |
---|
1144 | printf("[XML ERROR] Unknown tag %s", tag); |
---|
1145 | exit(1); |
---|
1146 | } |
---|
1147 | status = xmlTextReaderRead(reader); |
---|
1148 | } |
---|
1149 | } // end periphNode |
---|
1150 | |
---|
1151 | ////////////////////////////////////// |
---|
1152 | void procNode(xmlTextReaderPtr reader) |
---|
1153 | { |
---|
1154 | unsigned int ok; |
---|
1155 | unsigned int value; |
---|
1156 | |
---|
1157 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
1158 | |
---|
1159 | if (proc_index >= MAX_PROCS) |
---|
1160 | { |
---|
1161 | printf("[XML ERROR] The number of procs is larger than %d\n", MAX_PROCS); |
---|
1162 | exit(1); |
---|
1163 | } |
---|
1164 | |
---|
1165 | #if XML_PARSER_DEBUG |
---|
1166 | printf("\n proc %d\n", proc_index); |
---|
1167 | #endif |
---|
1168 | |
---|
1169 | proc[proc_index] = (mapping_proc_t *) malloc(sizeof(mapping_proc_t)); |
---|
1170 | |
---|
1171 | /////////// get index attribute (optional) |
---|
1172 | value = getIntValue(reader, "index", &ok); |
---|
1173 | if (ok && (value != proc_loc_index)) |
---|
1174 | { |
---|
1175 | printf("[XML ERROR] wrong local proc index / expected value is %d", |
---|
1176 | proc_loc_index); |
---|
1177 | exit(1); |
---|
1178 | } |
---|
1179 | proc[proc_index]->index = proc_loc_index; |
---|
1180 | |
---|
1181 | cluster[cluster_index]->procs++; |
---|
1182 | proc_loc_index++; |
---|
1183 | proc_index++; |
---|
1184 | } // end procNode() |
---|
1185 | |
---|
1186 | |
---|
1187 | ////////////////////////////////////// |
---|
1188 | void psegNode(xmlTextReaderPtr reader) |
---|
1189 | { |
---|
1190 | unsigned int ok; |
---|
1191 | paddr_t ll_value; |
---|
1192 | char * str; |
---|
1193 | |
---|
1194 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
1195 | |
---|
1196 | if (pseg_index >= MAX_PSEGS) |
---|
1197 | { |
---|
1198 | printf("[XML ERROR] The number of psegs is larger than %d\n", MAX_PSEGS); |
---|
1199 | exit(1); |
---|
1200 | } |
---|
1201 | |
---|
1202 | #if XML_PARSER_DEBUG |
---|
1203 | printf(" pseg %d\n", pseg_index); |
---|
1204 | #endif |
---|
1205 | |
---|
1206 | pseg[pseg_index] = (mapping_pseg_t *) malloc(sizeof(mapping_pseg_t)); |
---|
1207 | |
---|
1208 | /////// get name attribute |
---|
1209 | str = getStringValue(reader, "name", &ok); |
---|
1210 | #if XML_PARSER_DEBUG |
---|
1211 | printf(" name = %s\n", str); |
---|
1212 | #endif |
---|
1213 | if (ok) |
---|
1214 | { |
---|
1215 | strncpy(pseg[pseg_index]->name, str, 31); |
---|
1216 | } |
---|
1217 | else |
---|
1218 | { |
---|
1219 | printf("[XML ERROR] illegal or missing <name> for pseg %d in cluster %d\n", |
---|
1220 | pseg_index, cluster_index); |
---|
1221 | exit(1); |
---|
1222 | } |
---|
1223 | |
---|
1224 | //////// get type attribute |
---|
1225 | str = getStringValue(reader, "type", &ok); |
---|
1226 | #if XML_PARSER_DEBUG |
---|
1227 | printf(" type = %s\n", str); |
---|
1228 | #endif |
---|
1229 | if (ok && (strcmp(str, "RAM" ) == 0)) { pseg[pseg_index]->type = PSEG_TYPE_RAM; } |
---|
1230 | else if (ok && (strcmp(str, "ROM" ) == 0)) { pseg[pseg_index]->type = PSEG_TYPE_ROM; } |
---|
1231 | else if (ok && (strcmp(str, "DROM" ) == 0)) { pseg[pseg_index]->type = PSEG_TYPE_ROM; } |
---|
1232 | else if (ok && (strcmp(str, "PERI") == 0)) { pseg[pseg_index]->type = PSEG_TYPE_PERI; } |
---|
1233 | else |
---|
1234 | { |
---|
1235 | printf("[XML ERROR] illegal or missing <type> for pseg %s in cluster %d\n", |
---|
1236 | pseg[pseg_index]->name, cluster_index); |
---|
1237 | exit(1); |
---|
1238 | } |
---|
1239 | |
---|
1240 | //////// get base attribute |
---|
1241 | ll_value = getPaddrValue(reader, "base", &ok); |
---|
1242 | #if XML_PARSER_DEBUG |
---|
1243 | printf(" base = 0x%llx\n", ll_value); |
---|
1244 | #endif |
---|
1245 | if (ok) |
---|
1246 | { |
---|
1247 | pseg[pseg_index]->base = ll_value; |
---|
1248 | } |
---|
1249 | else { |
---|
1250 | printf("[XML ERROR] illegal or missing <base> for pseg %s in cluster %d\n", |
---|
1251 | pseg[pseg_index]->name, cluster_index); |
---|
1252 | exit(1); |
---|
1253 | } |
---|
1254 | |
---|
1255 | //////// get length attribute |
---|
1256 | ll_value = getPaddrValue(reader, "length", &ok); |
---|
1257 | #if XML_PARSER_DEBUG |
---|
1258 | printf(" length = 0x%llx\n", ll_value); |
---|
1259 | #endif |
---|
1260 | if (ok) |
---|
1261 | { |
---|
1262 | pseg[pseg_index]->length = ll_value; |
---|
1263 | } |
---|
1264 | else |
---|
1265 | { |
---|
1266 | printf("[XML ERROR] illegal or missing <length> for pseg %s in cluster %d\n", |
---|
1267 | pseg[pseg_index]->name, cluster_index); |
---|
1268 | exit(1); |
---|
1269 | } |
---|
1270 | |
---|
1271 | //////// set cluster attribute |
---|
1272 | pseg[pseg_index]->clusterid = cluster_index; |
---|
1273 | |
---|
1274 | //////// set next_vseg attribute |
---|
1275 | pseg[pseg_index]->next_vseg = 0; |
---|
1276 | |
---|
1277 | pseg_index++; |
---|
1278 | cluster[cluster_index]->psegs++; |
---|
1279 | } // end psegNode() |
---|
1280 | |
---|
1281 | |
---|
1282 | ///////////////////////////////////////// |
---|
1283 | void clusterNode(xmlTextReaderPtr reader) |
---|
1284 | { |
---|
1285 | unsigned int ok; |
---|
1286 | unsigned int value; |
---|
1287 | |
---|
1288 | cluster[cluster_index] = (mapping_cluster_t *) malloc(sizeof(mapping_cluster_t)); |
---|
1289 | |
---|
1290 | //initialise variables that will be incremented by *Node() functions |
---|
1291 | cluster[cluster_index]->psegs = 0; |
---|
1292 | cluster[cluster_index]->procs = 0; |
---|
1293 | cluster[cluster_index]->coprocs = 0; |
---|
1294 | cluster[cluster_index]->periphs = 0; |
---|
1295 | |
---|
1296 | //initialise global variables |
---|
1297 | proc_loc_index = 0; |
---|
1298 | coproc_loc_index = 0; |
---|
1299 | periph_loc_index = 0; |
---|
1300 | |
---|
1301 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
1302 | |
---|
1303 | #if XML_PARSER_DEBUG |
---|
1304 | printf("\n cluster %d\n", cluster_index); |
---|
1305 | #endif |
---|
1306 | |
---|
1307 | /////////// get x coordinate |
---|
1308 | value = getIntValue(reader, "x", &ok); |
---|
1309 | #if XML_PARSER_DEBUG |
---|
1310 | printf(" x = %d\n", value); |
---|
1311 | #endif |
---|
1312 | if (ok && (value < header->x_size) ) |
---|
1313 | { |
---|
1314 | cluster[cluster_index]->x = value; |
---|
1315 | } |
---|
1316 | else |
---|
1317 | { |
---|
1318 | printf("[XML ERROR] Illegal or missing < x > attribute for cluster %d", |
---|
1319 | cluster_index); |
---|
1320 | exit(1); |
---|
1321 | } |
---|
1322 | |
---|
1323 | /////////// get y coordinate |
---|
1324 | value = getIntValue(reader, "y", &ok); |
---|
1325 | #if XML_PARSER_DEBUG |
---|
1326 | printf(" y = %d\n", value); |
---|
1327 | #endif |
---|
1328 | if (ok && (value < header->y_size) ) |
---|
1329 | { |
---|
1330 | cluster[cluster_index]->y = value; |
---|
1331 | } |
---|
1332 | else |
---|
1333 | { |
---|
1334 | printf("[XML ERROR] Illegal or missing < y > attribute for cluster %d", |
---|
1335 | cluster_index); |
---|
1336 | exit(1); |
---|
1337 | } |
---|
1338 | |
---|
1339 | ////////// set offsets |
---|
1340 | cluster[cluster_index]->pseg_offset = pseg_index; |
---|
1341 | cluster[cluster_index]->proc_offset = proc_index; |
---|
1342 | cluster[cluster_index]->coproc_offset = coproc_index; |
---|
1343 | cluster[cluster_index]->periph_offset = periph_index; |
---|
1344 | |
---|
1345 | #if XML_PARSER_DEBUG |
---|
1346 | printf(" pseg_offset = %d\n", pseg_index); |
---|
1347 | printf(" proc_offset = %d\n", proc_index); |
---|
1348 | printf(" coproc_offset = %d\n", coproc_index); |
---|
1349 | printf(" periph_offset = %d\n", coproc_index); |
---|
1350 | #endif |
---|
1351 | |
---|
1352 | ////////// get psegs, procs, coprocs and periphs |
---|
1353 | int status = xmlTextReaderRead(reader); |
---|
1354 | |
---|
1355 | while (status == 1) |
---|
1356 | { |
---|
1357 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
1358 | |
---|
1359 | if (strcmp(tag, "pseg") == 0) psegNode(reader); |
---|
1360 | else if (strcmp(tag, "proc") == 0) procNode(reader); |
---|
1361 | else if (strcmp(tag, "coproc") == 0) coprocNode(reader); |
---|
1362 | else if (strcmp(tag, "periph") == 0) periphNode(reader); |
---|
1363 | else if (strcmp(tag, "#text") == 0) { } |
---|
1364 | else if (strcmp(tag, "#comment") == 0) { } |
---|
1365 | else if (strcmp(tag, "cluster") == 0) |
---|
1366 | { |
---|
1367 | |
---|
1368 | #if XML_PARSER_DEBUG |
---|
1369 | printf(" psegs = %d\n", cluster[cluster_index]->psegs); |
---|
1370 | printf(" procs = %d\n", cluster[cluster_index]->procs); |
---|
1371 | printf(" coprocs = %d\n", cluster[cluster_index]->coprocs); |
---|
1372 | printf(" periphs = %d\n", cluster[cluster_index]->periphs); |
---|
1373 | printf(" end cluster %d\n", cluster_index); |
---|
1374 | #endif |
---|
1375 | cluster_index++; |
---|
1376 | return; |
---|
1377 | } |
---|
1378 | status = xmlTextReaderRead(reader); |
---|
1379 | } |
---|
1380 | } // end clusterNode() |
---|
1381 | |
---|
1382 | |
---|
1383 | ////////////////////////////////////////////// |
---|
1384 | void clusterSetNode(xmlTextReaderPtr reader) |
---|
1385 | { |
---|
1386 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
1387 | |
---|
1388 | #if XML_PARSER_DEBUG |
---|
1389 | printf("\n clusters set\n"); |
---|
1390 | #endif |
---|
1391 | |
---|
1392 | int status = xmlTextReaderRead(reader); |
---|
1393 | while (status == 1) |
---|
1394 | { |
---|
1395 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
1396 | |
---|
1397 | if (strcmp(tag, "cluster") == 0) { clusterNode(reader); } |
---|
1398 | else if (strcmp(tag, "#text") == 0) { } |
---|
1399 | else if (strcmp(tag, "#comment") == 0) { } |
---|
1400 | else if (strcmp(tag, "clusterset") == 0) |
---|
1401 | { |
---|
1402 | // checking number of clusters |
---|
1403 | if ( cluster_index != (header->x_size * header->y_size) ) |
---|
1404 | { |
---|
1405 | printf("[XML ERROR] Wrong number of clusters\n"); |
---|
1406 | exit(1); |
---|
1407 | } |
---|
1408 | |
---|
1409 | #if XML_PARSER_DEBUG |
---|
1410 | printf(" end cluster set\n\n"); |
---|
1411 | #endif |
---|
1412 | header->psegs = pseg_index; |
---|
1413 | header->procs = proc_index; |
---|
1414 | header->irqs = irq_index; |
---|
1415 | header->coprocs = coproc_index; |
---|
1416 | header->periphs = periph_index; |
---|
1417 | return; |
---|
1418 | } |
---|
1419 | else |
---|
1420 | { |
---|
1421 | printf("[XML ERROR] Unknown tag in clusterset node : %s",tag); |
---|
1422 | exit(1); |
---|
1423 | } |
---|
1424 | status = xmlTextReaderRead(reader); |
---|
1425 | } |
---|
1426 | } // end clusterSetNode() |
---|
1427 | |
---|
1428 | |
---|
1429 | /////////////////////////////////////////// |
---|
1430 | void globalSetNode(xmlTextReaderPtr reader) |
---|
1431 | { |
---|
1432 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
1433 | |
---|
1434 | #if XML_PARSER_DEBUG |
---|
1435 | printf(" globals set\n"); |
---|
1436 | #endif |
---|
1437 | |
---|
1438 | int status = xmlTextReaderRead(reader); |
---|
1439 | while (status == 1) |
---|
1440 | { |
---|
1441 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
1442 | |
---|
1443 | if (strcmp(tag, "vseg") == 0) |
---|
1444 | { |
---|
1445 | vsegNode( reader ); |
---|
1446 | header->globals = header->globals + 1; |
---|
1447 | } |
---|
1448 | else if (strcmp(tag, "#text") == 0) { } |
---|
1449 | else if (strcmp(tag, "#comment") == 0) { } |
---|
1450 | else if (strcmp(tag, "globalset") == 0) |
---|
1451 | { |
---|
1452 | #if XML_PARSER_DEBUG |
---|
1453 | printf(" end global set\n\n"); |
---|
1454 | #endif |
---|
1455 | vseg_loc_index = 0; |
---|
1456 | return; |
---|
1457 | } |
---|
1458 | else |
---|
1459 | { |
---|
1460 | printf("[XML ERROR] Unknown tag in globalset node : %s",tag); |
---|
1461 | exit(1); |
---|
1462 | } |
---|
1463 | status = xmlTextReaderRead(reader); |
---|
1464 | } |
---|
1465 | } // end globalSetNode() |
---|
1466 | |
---|
1467 | |
---|
1468 | /////////////////////////////////////////// |
---|
1469 | void vspaceSetNode(xmlTextReaderPtr reader) |
---|
1470 | { |
---|
1471 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { |
---|
1472 | return; |
---|
1473 | } |
---|
1474 | |
---|
1475 | #if XML_PARSER_DEBUG |
---|
1476 | printf("\n vspaces set\n"); |
---|
1477 | #endif |
---|
1478 | |
---|
1479 | int status = xmlTextReaderRead ( reader ); |
---|
1480 | while (status == 1) { |
---|
1481 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
1482 | |
---|
1483 | if (strcmp(tag, "vspace") == 0) { |
---|
1484 | vspaceNode(reader); |
---|
1485 | } |
---|
1486 | else if (strcmp(tag, "#text" ) == 0 ) { } |
---|
1487 | else if (strcmp(tag, "#comment" ) == 0 ) { } |
---|
1488 | else if (strcmp(tag, "vspaceset") == 0 ) |
---|
1489 | { |
---|
1490 | header->vsegs = vseg_index; |
---|
1491 | header->tasks = task_index; |
---|
1492 | return; |
---|
1493 | } |
---|
1494 | else |
---|
1495 | { |
---|
1496 | printf("[XML ERROR] Unknown tag in vspaceset node : %s",tag); |
---|
1497 | exit(1); |
---|
1498 | } |
---|
1499 | status = xmlTextReaderRead(reader); |
---|
1500 | } |
---|
1501 | } // end globalSetNode() |
---|
1502 | |
---|
1503 | |
---|
1504 | //////////////////////////////////////// |
---|
1505 | void headerNode(xmlTextReaderPtr reader) |
---|
1506 | { |
---|
1507 | char * name; |
---|
1508 | unsigned int value; |
---|
1509 | unsigned int ok; |
---|
1510 | |
---|
1511 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
1512 | |
---|
1513 | #if XML_PARSER_DEBUG |
---|
1514 | printf("mapping_info\n"); |
---|
1515 | #endif |
---|
1516 | |
---|
1517 | header = (mapping_header_t *) malloc(sizeof(mapping_header_t)); |
---|
1518 | |
---|
1519 | ////////// get name attribute |
---|
1520 | name = getStringValue(reader, "name", &ok); |
---|
1521 | if (ok) |
---|
1522 | { |
---|
1523 | #if XML_PARSER_DEBUG |
---|
1524 | printf(" name = %s\n", name); |
---|
1525 | #endif |
---|
1526 | strncpy( header->name, name, 31); |
---|
1527 | } |
---|
1528 | else |
---|
1529 | { |
---|
1530 | printf("[XML ERROR] illegal or missing <name> attribute in header\n"); |
---|
1531 | exit(1); |
---|
1532 | } |
---|
1533 | |
---|
1534 | /////////// get signature attribute |
---|
1535 | value = getIntValue(reader, "signature", &ok); |
---|
1536 | if ( ok && (value == IN_MAPPING_SIGNATURE) ) |
---|
1537 | { |
---|
1538 | #if XML_PARSER_DEBUG |
---|
1539 | printf(" signature = %x\n", value); |
---|
1540 | #endif |
---|
1541 | header->signature = IN_MAPPING_SIGNATURE; |
---|
1542 | } |
---|
1543 | else |
---|
1544 | { |
---|
1545 | printf("[XML ERROR] illegal or missing <signature> for mapping %s\n", |
---|
1546 | header->name ); |
---|
1547 | exit(1); |
---|
1548 | } |
---|
1549 | |
---|
1550 | /////////// get x_width attribute |
---|
1551 | value = getIntValue(reader, "x_width", &ok); |
---|
1552 | if (ok) |
---|
1553 | { |
---|
1554 | #if XML_PARSER_DEBUG |
---|
1555 | printf(" x_width = %d\n", value); |
---|
1556 | #endif |
---|
1557 | header->x_width = value; |
---|
1558 | } |
---|
1559 | |
---|
1560 | /////////// get y_width attribute |
---|
1561 | value = getIntValue(reader, "y_width", &ok); |
---|
1562 | if (ok) |
---|
1563 | { |
---|
1564 | #if XML_PARSER_DEBUG |
---|
1565 | printf(" y_width = %d\n", value); |
---|
1566 | #endif |
---|
1567 | header->y_width = value; |
---|
1568 | } |
---|
1569 | |
---|
1570 | /////////// get x_size attribute |
---|
1571 | unsigned int x_size = getIntValue(reader, "x_size", &ok); |
---|
1572 | if (ok) |
---|
1573 | { |
---|
1574 | #if XML_PARSER_DEBUG |
---|
1575 | printf(" x_size = %d\n", x_size); |
---|
1576 | #endif |
---|
1577 | header->x_size = x_size; |
---|
1578 | } |
---|
1579 | else |
---|
1580 | { |
---|
1581 | printf("[XML ERROR] illegal or missing <x_size> attribute in header\n"); |
---|
1582 | exit(1); |
---|
1583 | } |
---|
1584 | |
---|
1585 | /////////// get y_size attribute |
---|
1586 | unsigned int y_size = getIntValue(reader, "y_size", &ok); |
---|
1587 | if (ok) |
---|
1588 | { |
---|
1589 | #if XML_PARSER_DEBUG |
---|
1590 | printf(" y_size = %d\n", y_size); |
---|
1591 | #endif |
---|
1592 | header->y_size = y_size; |
---|
1593 | } |
---|
1594 | else |
---|
1595 | { |
---|
1596 | printf("[XML ERROR] illegal or missing <y_size> attribute in header\n"); |
---|
1597 | exit(1); |
---|
1598 | } |
---|
1599 | |
---|
1600 | /////////// get x_io attribute |
---|
1601 | unsigned int x_io = getIntValue(reader, "x_io", &ok); |
---|
1602 | #if XML_PARSER_DEBUG |
---|
1603 | printf(" x_io = %d\n", x_io); |
---|
1604 | #endif |
---|
1605 | if ( ok && (x_io < x_size) ) |
---|
1606 | { |
---|
1607 | header->x_io = x_io; |
---|
1608 | } |
---|
1609 | else |
---|
1610 | { |
---|
1611 | printf("[XML ERROR] illegal or missing <x_io> attribute in header\n"); |
---|
1612 | exit(1); |
---|
1613 | } |
---|
1614 | |
---|
1615 | /////////// get y_io attribute |
---|
1616 | unsigned int y_io = getIntValue(reader, "y_io", &ok); |
---|
1617 | #if XML_PARSER_DEBUG |
---|
1618 | printf(" y_io = %d\n", y_io); |
---|
1619 | #endif |
---|
1620 | if ( ok &&(y_io < y_size) ) |
---|
1621 | { |
---|
1622 | header->y_io = y_io; |
---|
1623 | } |
---|
1624 | else |
---|
1625 | { |
---|
1626 | printf("[XML ERROR] illegal or missing <y_io> attribute in header\n"); |
---|
1627 | exit(1); |
---|
1628 | } |
---|
1629 | |
---|
1630 | // check the number of cluster |
---|
1631 | if ( (x_size * y_size) >= MAX_CLUSTERS ) |
---|
1632 | { |
---|
1633 | printf("[XML ERROR] Number of clusters cannot be larger than %d\n", MAX_CLUSTERS); |
---|
1634 | exit(1); |
---|
1635 | } |
---|
1636 | |
---|
1637 | ///////// get irq_per_proc attribute |
---|
1638 | value = getIntValue(reader, "irq_per_proc", &ok); |
---|
1639 | if (ok) |
---|
1640 | { |
---|
1641 | #if XML_PARSER_DEBUG |
---|
1642 | printf(" irq_per_proc = %d\n", value); |
---|
1643 | #endif |
---|
1644 | header->irq_per_proc = value; |
---|
1645 | } |
---|
1646 | else |
---|
1647 | { |
---|
1648 | printf("[XML ERROR] illegal or missing <irq_per_proc> attribute in mapping\n"); |
---|
1649 | exit(1); |
---|
1650 | } |
---|
1651 | |
---|
1652 | ///////// get use_ram_disk attribute (default = 0) |
---|
1653 | value = getIntValue(reader, "use_ram_disk", &ok); |
---|
1654 | if (ok) |
---|
1655 | { |
---|
1656 | #if XML_PARSER_DEBUG |
---|
1657 | printf(" use_ram_disk = %d\n", value); |
---|
1658 | #endif |
---|
1659 | header->use_ram_disk = value; |
---|
1660 | } |
---|
1661 | else |
---|
1662 | { |
---|
1663 | header->use_ram_disk = 0; |
---|
1664 | } |
---|
1665 | |
---|
1666 | ///////// set other header fields |
---|
1667 | header->globals = 0; |
---|
1668 | header->vspaces = 0; |
---|
1669 | header->psegs = 0; |
---|
1670 | header->vsegs = 0; |
---|
1671 | header->tasks = 0; |
---|
1672 | header->procs = 0; |
---|
1673 | header->irqs = 0; |
---|
1674 | header->coprocs = 0; |
---|
1675 | header->periphs = 0; |
---|
1676 | |
---|
1677 | |
---|
1678 | int status = xmlTextReaderRead(reader); |
---|
1679 | while (status == 1) |
---|
1680 | { |
---|
1681 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
1682 | |
---|
1683 | if (strcmp(tag, "clusterset") == 0) { clusterSetNode(reader); } |
---|
1684 | else if (strcmp(tag, "globalset") == 0) { globalSetNode(reader); } |
---|
1685 | else if (strcmp(tag, "vspaceset") == 0) { vspaceSetNode(reader); } |
---|
1686 | else if (strcmp(tag, "#text") == 0) { } |
---|
1687 | else if (strcmp(tag, "#comment") == 0) { } |
---|
1688 | else if (strcmp(tag, "mapping_info") == 0) |
---|
1689 | { |
---|
1690 | #if XML_PARSER_DEBUG |
---|
1691 | printf("end mapping_info\n"); |
---|
1692 | #endif |
---|
1693 | return; |
---|
1694 | } |
---|
1695 | else |
---|
1696 | { |
---|
1697 | printf("[XML ERROR] Unknown tag in header node : %s\n",tag); |
---|
1698 | exit(1); |
---|
1699 | } |
---|
1700 | status = xmlTextReaderRead(reader); |
---|
1701 | } |
---|
1702 | } // end headerNode() |
---|
1703 | |
---|
1704 | |
---|
1705 | //////////////////////////////////// |
---|
1706 | void BuildTable( int fdout, |
---|
1707 | const char * type, |
---|
1708 | unsigned int nb_elem, |
---|
1709 | unsigned int elem_size, |
---|
1710 | char ** table ) |
---|
1711 | { |
---|
1712 | unsigned int i; |
---|
1713 | for (i = 0; i < nb_elem; i++) |
---|
1714 | { |
---|
1715 | if (elem_size != write(fdout, table[i], elem_size)) |
---|
1716 | { |
---|
1717 | printf("function %s: %s(%d) write error \n", __FUNCTION__, type, i); |
---|
1718 | exit(1); |
---|
1719 | } |
---|
1720 | |
---|
1721 | #if XML_PARSER_DEBUG |
---|
1722 | printf("Building binary: writing %s %d\n", type, i); |
---|
1723 | #endif |
---|
1724 | } |
---|
1725 | } |
---|
1726 | |
---|
1727 | ///////////////////////////////////// |
---|
1728 | int open_file(const char * file_path) |
---|
1729 | { |
---|
1730 | //open file |
---|
1731 | int fdout = open( file_path, (O_CREAT | O_RDWR), (S_IWUSR | S_IRUSR) ); |
---|
1732 | if (fdout < 0) |
---|
1733 | { |
---|
1734 | perror("open"); |
---|
1735 | exit(1); |
---|
1736 | } |
---|
1737 | |
---|
1738 | //reinitialise the file |
---|
1739 | if (ftruncate(fdout, 0)) |
---|
1740 | { |
---|
1741 | perror("truncate"); |
---|
1742 | exit(1); |
---|
1743 | } |
---|
1744 | |
---|
1745 | //#if XML_PARSER_DEBUG |
---|
1746 | printf("%s\n", file_path); |
---|
1747 | //#endif |
---|
1748 | |
---|
1749 | return fdout; |
---|
1750 | } |
---|
1751 | |
---|
1752 | |
---|
1753 | ///////////////////////////////////// |
---|
1754 | void buildBin(const char * file_path) |
---|
1755 | { |
---|
1756 | unsigned int length; |
---|
1757 | |
---|
1758 | int fdout = open_file(file_path); |
---|
1759 | |
---|
1760 | #if XML_PARSER_DEBUG |
---|
1761 | printf("Building map.bin for %s\n", header->name); |
---|
1762 | printf("signature = %x\n", header->signature); |
---|
1763 | printf("x_size = %d\n", header->x_size); |
---|
1764 | printf("y_size = %d\n", header->y_size); |
---|
1765 | printf("x_width = %d\n", header->x_width); |
---|
1766 | printf("y_width = %d\n", header->y_width); |
---|
1767 | printf("vspaces = %d\n", header->vspaces); |
---|
1768 | printf("psegs = %d\n", header->psegs); |
---|
1769 | printf("vsegs = %d\n", header->vsegs); |
---|
1770 | printf("tasks = %d\n", header->tasks); |
---|
1771 | printf("procs = %d\n", header->procs); |
---|
1772 | printf("irqs = %d\n", header->irqs); |
---|
1773 | printf("coprocs = %d\n", header->coprocs); |
---|
1774 | printf("periphs = %d\n", header->periphs); |
---|
1775 | #endif |
---|
1776 | |
---|
1777 | // write header to binary file |
---|
1778 | length = write(fdout, (char *) header, sizeof(mapping_header_t)); |
---|
1779 | if (length != sizeof(mapping_header_t)) |
---|
1780 | { |
---|
1781 | printf("write header error : length = %d \n", length); |
---|
1782 | exit(1); |
---|
1783 | } |
---|
1784 | |
---|
1785 | // write clusters |
---|
1786 | BuildTable(fdout, "cluster", cluster_index, sizeof(mapping_cluster_t), (char **) cluster); |
---|
1787 | // write psegs |
---|
1788 | BuildTable(fdout, "pseg", pseg_index, sizeof(mapping_pseg_t), (char **) pseg); |
---|
1789 | // write vspaces |
---|
1790 | BuildTable(fdout, "vspace", vspace_index, sizeof(mapping_vspace_t), (char **) vspace); |
---|
1791 | // write vsegs |
---|
1792 | BuildTable(fdout, "vseg", vseg_index, sizeof(mapping_vseg_t), (char **) vseg); |
---|
1793 | // write tasks array |
---|
1794 | BuildTable(fdout, "task", task_index, sizeof(mapping_task_t), (char **) task); |
---|
1795 | //building procs array |
---|
1796 | BuildTable(fdout, "proc", proc_index, sizeof(mapping_proc_t), (char **) proc); |
---|
1797 | //building irqs array |
---|
1798 | BuildTable(fdout, "irq", irq_index, sizeof(mapping_irq_t), (char **) irq); |
---|
1799 | //building coprocs array |
---|
1800 | BuildTable(fdout, "coproc", coproc_index, sizeof(mapping_coproc_t), (char **) coproc); |
---|
1801 | //building periphs array |
---|
1802 | BuildTable(fdout, "periph", periph_index, sizeof(mapping_periph_t), (char **) periph); |
---|
1803 | |
---|
1804 | close(fdout); |
---|
1805 | |
---|
1806 | } // end buildBin() |
---|
1807 | |
---|
1808 | |
---|
1809 | ////////////////////////////////////////////////////// |
---|
1810 | char * buildPath(const char * path, const char * name) |
---|
1811 | { |
---|
1812 | char * res = calloc(strlen(path) + strlen(name) + 1, 1); |
---|
1813 | strcat(res, path); |
---|
1814 | strcat(res, "/"); |
---|
1815 | strcat(res, name); |
---|
1816 | return res; |
---|
1817 | } |
---|
1818 | |
---|
1819 | |
---|
1820 | ////////////////////////////////// |
---|
1821 | int main(int argc, char * argv[]) |
---|
1822 | { |
---|
1823 | if (argc < 3) |
---|
1824 | { |
---|
1825 | printf("Usage: xml2bin <input_file_path> <output_path>\n"); |
---|
1826 | return 1; |
---|
1827 | } |
---|
1828 | |
---|
1829 | struct stat dir_st; |
---|
1830 | if (stat( argv[2], &dir_st)) |
---|
1831 | { |
---|
1832 | perror("bad path"); |
---|
1833 | exit(1); |
---|
1834 | } |
---|
1835 | |
---|
1836 | if ((dir_st.st_mode & S_IFDIR) == 0) |
---|
1837 | { |
---|
1838 | printf("path is not a dir: %s", argv[2] ); |
---|
1839 | exit(1); |
---|
1840 | } |
---|
1841 | |
---|
1842 | char * map_path = buildPath(argv[2], "map.bin"); |
---|
1843 | |
---|
1844 | LIBXML_TEST_VERSION; |
---|
1845 | |
---|
1846 | int status; |
---|
1847 | xmlTextReaderPtr reader = xmlReaderForFile(argv[1], NULL, 0); |
---|
1848 | |
---|
1849 | if (reader != NULL) |
---|
1850 | { |
---|
1851 | status = xmlTextReaderRead (reader); |
---|
1852 | while (status == 1) |
---|
1853 | { |
---|
1854 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
1855 | |
---|
1856 | if (strcmp(tag, "mapping_info") == 0) |
---|
1857 | { |
---|
1858 | headerNode(reader); |
---|
1859 | buildBin(map_path); |
---|
1860 | } |
---|
1861 | else |
---|
1862 | { |
---|
1863 | printf("[XML ERROR] Wrong file type: \"%s\"\n", argv[1]); |
---|
1864 | return 1; |
---|
1865 | } |
---|
1866 | status = xmlTextReaderRead(reader); |
---|
1867 | } |
---|
1868 | xmlFreeTextReader(reader); |
---|
1869 | |
---|
1870 | if (status != 0) |
---|
1871 | { |
---|
1872 | printf("[XML ERROR] Wrong Syntax in \"%s\" file\n", argv[1]); |
---|
1873 | return 1; |
---|
1874 | } |
---|
1875 | } |
---|
1876 | return 0; |
---|
1877 | } // end main() |
---|
1878 | |
---|
1879 | |
---|
1880 | // Local Variables: |
---|
1881 | // tab-width: 4 |
---|
1882 | // c-basic-offset: 4 |
---|
1883 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
1884 | // indent-tabs-mode: nil |
---|
1885 | // End: |
---|
1886 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
1887 | |
---|