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