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