1 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
2 | // File : xml_parser.c |
---|
3 | // Date : 04/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 <unistd.h> |
---|
15 | #include <stdio.h> |
---|
16 | #include <string.h> |
---|
17 | #include <libxml/xmlreader.h> |
---|
18 | #include <mapping_info.h> |
---|
19 | |
---|
20 | #define MAX_CLUSTERS 1024 |
---|
21 | #define MAX_PSEGS 4096 |
---|
22 | #define MAX_VSPACES 1024 |
---|
23 | #define MAX_TASKS 4096 |
---|
24 | #define MAX_MWMRS 4096 |
---|
25 | #define MAX_VSEGS 4096 |
---|
26 | #define MAX_VOBJS 8192 |
---|
27 | |
---|
28 | #define XML_PARSER_DEBUG 0 |
---|
29 | |
---|
30 | /////////////////////////////////////////////////////////////////////////////////// |
---|
31 | // global variables used to store and index the data structures |
---|
32 | /////////////////////////////////////////////////////////////////////////////////// |
---|
33 | |
---|
34 | mapping_header_t* header; |
---|
35 | mapping_cluster_t* cluster[MAX_CLUSTERS]; // cluster array |
---|
36 | mapping_pseg_t* pseg[MAX_PSEGS]; // pseg array |
---|
37 | mapping_vspace_t* vspace[MAX_VSPACES]; // vspace array |
---|
38 | mapping_vseg_t* vseg[MAX_VSEGS]; // vseg array |
---|
39 | mapping_vobj_t* vobj[MAX_VOBJS]; // vobj array |
---|
40 | mapping_task_t* task[MAX_TASKS]; // task array |
---|
41 | |
---|
42 | unsigned int cluster_index = 0; |
---|
43 | unsigned int vspace_index = 0; |
---|
44 | unsigned int global_index = 0; |
---|
45 | unsigned int pseg_index = 0; |
---|
46 | unsigned int vseg_index = 0; |
---|
47 | unsigned int vseg_loc_index = 0; |
---|
48 | unsigned int task_index = 0; |
---|
49 | unsigned int task_loc_index = 0; |
---|
50 | unsigned int vobj_index = 0; |
---|
51 | unsigned int vobj_loc_index = 0; |
---|
52 | unsigned int vobj_loc_vspace_index = 0; |
---|
53 | |
---|
54 | char one_elf_found = 0;//bool: wether a first vobj of type elf was found |
---|
55 | |
---|
56 | ////////////////////////////////////////////////// |
---|
57 | unsigned int getIntValue( xmlTextReaderPtr reader, |
---|
58 | const char* attributeName, |
---|
59 | unsigned int* ok ) |
---|
60 | { |
---|
61 | unsigned int value = 0; |
---|
62 | unsigned int i; |
---|
63 | char c; |
---|
64 | |
---|
65 | char* string = (char*)xmlTextReaderGetAttribute(reader, (const xmlChar*)attributeName); |
---|
66 | |
---|
67 | if ( string == NULL ) // missing argument |
---|
68 | { |
---|
69 | *ok = 0; |
---|
70 | return 0; |
---|
71 | } |
---|
72 | else |
---|
73 | { |
---|
74 | if ( (string[0] == '0') && ((string[1] == 'x') || (string[1] == 'X')) ) // Hexa |
---|
75 | { |
---|
76 | for ( i = 2 ; (string[i] != 0) && (i < 10) ; i++ ) |
---|
77 | { |
---|
78 | c = string[i]; |
---|
79 | if ((c >= '0') && (c <= '9')) value = (value<<4) + string[i] - 48; |
---|
80 | else if ((c >= 'a') && (c <= 'f')) value = (value<<4) + string[i] - 87; |
---|
81 | else if ((c >= 'A') && (c <= 'F')) value = (value<<4) + string[i] - 55; |
---|
82 | else |
---|
83 | { |
---|
84 | *ok = 0; |
---|
85 | return 0; |
---|
86 | } |
---|
87 | } |
---|
88 | } |
---|
89 | else // Decimal |
---|
90 | { |
---|
91 | for ( i = 0 ; (string[i] != 0) && (i < 9) ; i++ ) |
---|
92 | { |
---|
93 | c = string[i]; |
---|
94 | if ((c >= '0') && (c <= '9')) value = (value*10) + string[i] - 48; |
---|
95 | else |
---|
96 | { |
---|
97 | *ok = 0; |
---|
98 | return 0; |
---|
99 | } |
---|
100 | } |
---|
101 | } |
---|
102 | *ok = 1; |
---|
103 | return value; |
---|
104 | } |
---|
105 | } // end getIntValue() |
---|
106 | |
---|
107 | /////////////////////////////////////////////// |
---|
108 | char* getStringValue ( xmlTextReaderPtr reader, |
---|
109 | const char* attributeName, |
---|
110 | unsigned int* ok ) |
---|
111 | { |
---|
112 | char* string = (char*)xmlTextReaderGetAttribute(reader, (const xmlChar*)attributeName); |
---|
113 | |
---|
114 | if ( string == NULL ) // missing argument |
---|
115 | { |
---|
116 | *ok = 0; |
---|
117 | return NULL; |
---|
118 | } |
---|
119 | else |
---|
120 | { |
---|
121 | *ok = 1; |
---|
122 | return string; |
---|
123 | } |
---|
124 | } // end getStringValue() |
---|
125 | |
---|
126 | ////////////////////////// |
---|
127 | int getPsegId( char* str ) |
---|
128 | { |
---|
129 | unsigned int pseg_id; |
---|
130 | |
---|
131 | for ( pseg_id = 0 ; pseg_id < header->psegs ; pseg_id++ ) |
---|
132 | { |
---|
133 | if ( strcmp(pseg[pseg_id]->name, str) == 0 ) return pseg_id; |
---|
134 | } |
---|
135 | return -1; |
---|
136 | } |
---|
137 | |
---|
138 | ////////////////////////////////////////// |
---|
139 | int getVobjLocId( unsigned int vspace_id, |
---|
140 | char* str ) |
---|
141 | { |
---|
142 | unsigned int vobj_id; |
---|
143 | unsigned int vobj_min = vspace[vspace_id]->vobj_offset; |
---|
144 | unsigned int vobj_max = vobj_min + vobj_loc_vspace_index; |
---|
145 | |
---|
146 | for ( vobj_id = vobj_min ; vobj_id < vobj_max ; vobj_id++ ) |
---|
147 | { |
---|
148 | if ( strcmp(vobj[vobj_id]->name, str) == 0 ) |
---|
149 | { |
---|
150 | return (vobj_id - vobj_min); |
---|
151 | } |
---|
152 | } |
---|
153 | return -1; |
---|
154 | } |
---|
155 | |
---|
156 | ////////////////////////////////////////// |
---|
157 | void taskNode ( xmlTextReaderPtr reader ) |
---|
158 | { |
---|
159 | unsigned int ok; |
---|
160 | unsigned int value; |
---|
161 | char* str; |
---|
162 | |
---|
163 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
---|
164 | |
---|
165 | if ( task_index >= MAX_TASKS ) |
---|
166 | { |
---|
167 | printf("[XML ERROR] The number of tasks is larger than %d\n", MAX_TASKS); |
---|
168 | } |
---|
169 | |
---|
170 | #if XML_PARSER_DEBUG |
---|
171 | printf(" task %d\n", task_loc_index); |
---|
172 | #endif |
---|
173 | |
---|
174 | task[task_index] = (mapping_task_t*)malloc(sizeof(mapping_task_t)); |
---|
175 | |
---|
176 | ////////// get name attribute |
---|
177 | str = getStringValue(reader, "name", &ok); |
---|
178 | if ( ok ) |
---|
179 | { |
---|
180 | #if XML_PARSER_DEBUG |
---|
181 | printf(" name = %s\n", str); |
---|
182 | #endif |
---|
183 | strncpy( task[task_index]->name, str, 31 ); |
---|
184 | } |
---|
185 | else |
---|
186 | { |
---|
187 | printf("[XML ERROR] illegal or missing <name> attribute for task (%d,%d)\n", |
---|
188 | vspace_index, task_loc_index); |
---|
189 | exit(1); |
---|
190 | } |
---|
191 | |
---|
192 | ///////// get clusterid attribute |
---|
193 | value = getIntValue(reader,"clusterid", &ok); |
---|
194 | if ( ok ) |
---|
195 | { |
---|
196 | #if XML_PARSER_DEBUG |
---|
197 | printf(" clusterid = %x\n", value); |
---|
198 | #endif |
---|
199 | task[task_index]->clusterid = value; |
---|
200 | } |
---|
201 | else |
---|
202 | { |
---|
203 | printf("[XML ERROR] illegal or missing <clusterid> attribute for task (%d,%d)\n", |
---|
204 | vspace_index, task_loc_index); |
---|
205 | exit(1); |
---|
206 | } |
---|
207 | |
---|
208 | ////////// get proclocid attribute |
---|
209 | value = getIntValue(reader,"proclocid", &ok); |
---|
210 | if ( ok ) |
---|
211 | { |
---|
212 | #if XML_PARSER_DEBUG |
---|
213 | printf(" proclocid = %x\n", value); |
---|
214 | #endif |
---|
215 | task[task_index]->proclocid = value; |
---|
216 | } |
---|
217 | else |
---|
218 | { |
---|
219 | printf("[XML ERROR] illegal or missing <locprocid> attribute for task (%d,%d)\n", |
---|
220 | vspace_index, task_loc_index); |
---|
221 | exit(1); |
---|
222 | } |
---|
223 | |
---|
224 | ////////// get stackname attribute |
---|
225 | str = getStringValue(reader, "stackname" , &ok); |
---|
226 | if ( ok ) |
---|
227 | { |
---|
228 | int index = getVobjLocId( vspace_index, str ); |
---|
229 | if ( index >= 0 ) |
---|
230 | { |
---|
231 | #if XML_PARSER_DEBUG |
---|
232 | printf(" stackname = %s\n", str); |
---|
233 | printf(" vsegid = %d\n", index); |
---|
234 | #endif |
---|
235 | task[task_index]->vobjlocid = index; |
---|
236 | } |
---|
237 | else |
---|
238 | { |
---|
239 | printf("[XML ERROR] illegal or missing <psegname> for vseg %d\n", |
---|
240 | vseg_loc_index); |
---|
241 | exit(1); |
---|
242 | } |
---|
243 | } |
---|
244 | else |
---|
245 | { |
---|
246 | printf("[XML ERROR] illegal or missing <vsegname> for task (%d,%d)\n", |
---|
247 | vspace_index, task_loc_index); |
---|
248 | exit(1); |
---|
249 | } |
---|
250 | |
---|
251 | ////////// get startid attribute |
---|
252 | value = getIntValue(reader,"startid", &ok); |
---|
253 | if ( ok ) |
---|
254 | { |
---|
255 | #if XML_PARSER_DEBUG |
---|
256 | printf(" startid = %x\n", value); |
---|
257 | #endif |
---|
258 | task[task_index]->startid = value; |
---|
259 | } |
---|
260 | else |
---|
261 | { |
---|
262 | printf("[XML ERROR] illegal or missing <startid> attribute for task (%d,%d)\n", |
---|
263 | vspace_index, task_loc_index); |
---|
264 | exit(1); |
---|
265 | } |
---|
266 | |
---|
267 | /////////// get ttylocid attribute |
---|
268 | value = getIntValue(reader,"ttylocid", &ok); |
---|
269 | if ( ok ) |
---|
270 | { |
---|
271 | #if XML_PARSER_DEBUG |
---|
272 | printf(" ttylocid = %x\n", value); |
---|
273 | #endif |
---|
274 | if ( value >= vspace[vspace_index]->ttys ) |
---|
275 | { |
---|
276 | printf("[XML ERROR] The ttylocid value is too large for task (%d,%d)\n", |
---|
277 | vspace_index, task_loc_index); |
---|
278 | exit(1); |
---|
279 | } |
---|
280 | task[task_index]->ttylocid = value; |
---|
281 | } |
---|
282 | else |
---|
283 | { |
---|
284 | printf("[XML ERROR] illegal or missing <ttylocid> attribute for task (%d,%d)\n", |
---|
285 | vspace_index, task_loc_index); |
---|
286 | exit(1); |
---|
287 | } |
---|
288 | |
---|
289 | task_index++; |
---|
290 | task_loc_index++; |
---|
291 | } // end taskNode() |
---|
292 | |
---|
293 | void vobjNode ( xmlTextReaderPtr reader ) |
---|
294 | { |
---|
295 | unsigned int ok; |
---|
296 | unsigned int value; |
---|
297 | char* str; |
---|
298 | |
---|
299 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
---|
300 | |
---|
301 | if ( vobj_index >= MAX_VOBJS ) |
---|
302 | { |
---|
303 | printf("[XML ERROR] The number of vobjs is larger than %d\n", MAX_VSEGS); |
---|
304 | exit(1); |
---|
305 | } |
---|
306 | |
---|
307 | if(one_elf_found != 0) |
---|
308 | { |
---|
309 | printf("[XML ERROR] a vobj of the type ELF must be defined alone in a vseg (%d,%d)\n", |
---|
310 | vspace_index, vobj_loc_vspace_index); |
---|
311 | exit(1); |
---|
312 | |
---|
313 | } |
---|
314 | |
---|
315 | #if XML_PARSER_DEBUG |
---|
316 | printf(" vobj %d\n", vobj_loc_index); |
---|
317 | #endif |
---|
318 | |
---|
319 | vobj[vobj_index] = (mapping_vobj_t*)malloc(sizeof(mapping_vobj_t)); |
---|
320 | |
---|
321 | ///////// get name attribute |
---|
322 | str = getStringValue(reader, "name", &ok); |
---|
323 | if ( ok ) |
---|
324 | { |
---|
325 | #if XML_PARSER_DEBUG |
---|
326 | printf(" name = %s\n", str); |
---|
327 | #endif |
---|
328 | strncpy( vobj[vobj_index]->name, str, 31); |
---|
329 | } |
---|
330 | else |
---|
331 | { |
---|
332 | printf("[XML ERROR] illegal or missing <name> attribute for vobj (%d,%d)\n", |
---|
333 | vseg_index, vobj_loc_index); |
---|
334 | exit(1); |
---|
335 | } |
---|
336 | |
---|
337 | |
---|
338 | // get type attribute |
---|
339 | str = getStringValue(reader, "type", &ok); |
---|
340 | #if XML_PARSER_DEBUG |
---|
341 | printf(" type = %s\n", str); |
---|
342 | #endif |
---|
343 | if (ok && (strcmp(str, "ELF") == 0)){ |
---|
344 | vobj[vobj_index]->type = ELF; |
---|
345 | one_elf_found = 1; |
---|
346 | if(vobj_loc_index != 0) //check that this vobj is the first |
---|
347 | { |
---|
348 | printf("[XML ERROR] a vobj of the type ELF must be defined alone in a vobj (%d,%d)\n", |
---|
349 | vspace_index, vobj_loc_vspace_index); |
---|
350 | exit(1); |
---|
351 | |
---|
352 | } |
---|
353 | } |
---|
354 | else if (ok && (strcmp(str, "PTAB") == 0)) vobj[vobj_index]->type = PTAB; |
---|
355 | else if (ok && (strcmp(str, "PERI") == 0)) vobj[vobj_index]->type = PERI; |
---|
356 | else if (ok && (strcmp(str, "MWMR") == 0)) vobj[vobj_index]->type = MWMR; |
---|
357 | else if (ok && (strcmp(str, "LOCK") == 0)) vobj[vobj_index]->type = LOCK; |
---|
358 | else if (ok && (strcmp(str, "BUFFER") == 0)) vobj[vobj_index]->type = BUFFER; |
---|
359 | else if (ok && (strcmp(str, "BARRIER") == 0)) vobj[vobj_index]->type = BARRIER; |
---|
360 | else |
---|
361 | { |
---|
362 | printf("[XML ERROR] illegal or missing <type> attribute for vobj (%d,%d)\n", |
---|
363 | vspace_index, vobj_loc_vspace_index); |
---|
364 | exit(1); |
---|
365 | } |
---|
366 | |
---|
367 | |
---|
368 | ////////// get length attribute (0 if missing) |
---|
369 | value = getIntValue(reader,"length", &ok); |
---|
370 | if ( ok ) |
---|
371 | { |
---|
372 | #if XML_PARSER_DEBUG |
---|
373 | printf(" length = %d\n", value); |
---|
374 | #endif |
---|
375 | vobj[vobj_index]->length = value; |
---|
376 | } |
---|
377 | else |
---|
378 | { |
---|
379 | vobj[vobj_index]->length = 0; |
---|
380 | } |
---|
381 | |
---|
382 | ////////// get align attribute (0 if missing) |
---|
383 | value = getIntValue(reader,"align", &ok); |
---|
384 | if ( ok ) |
---|
385 | { |
---|
386 | #if XML_PARSER_DEBUG |
---|
387 | printf(" align = %d\n", value); |
---|
388 | #endif |
---|
389 | vobj[vobj_index]->align = value; |
---|
390 | } |
---|
391 | else |
---|
392 | { |
---|
393 | vobj[vobj_index]->align = 0; |
---|
394 | } |
---|
395 | |
---|
396 | ////////// get binpath attribute ('\0' if missing) |
---|
397 | str = getStringValue(reader, "binpath", &ok); |
---|
398 | if ( ok ) |
---|
399 | { |
---|
400 | #if XML_PARSER_DEBUG |
---|
401 | printf(" binpath = %s\n", str); |
---|
402 | #endif |
---|
403 | strncpy(vobj[vobj_index]->binpath, str, 63); |
---|
404 | } |
---|
405 | else |
---|
406 | { |
---|
407 | vobj[vobj_index]->binpath[0] = '\0'; |
---|
408 | } |
---|
409 | |
---|
410 | vobj_index++; |
---|
411 | vobj_loc_index++; |
---|
412 | vobj_loc_vspace_index++; |
---|
413 | } |
---|
414 | |
---|
415 | |
---|
416 | /////////////////////////////////////////////////////////////// |
---|
417 | void vsegNode ( xmlTextReaderPtr reader ) |
---|
418 | { |
---|
419 | unsigned int ok; |
---|
420 | unsigned int value; |
---|
421 | char* str; |
---|
422 | vobj_loc_index = 0; |
---|
423 | one_elf_found = 0; |
---|
424 | |
---|
425 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
---|
426 | |
---|
427 | if ( vseg_index >= MAX_VSEGS ) |
---|
428 | { |
---|
429 | printf("[XML ERROR] The number of vsegs is larger than %d\n", MAX_VSEGS); |
---|
430 | exit(1); |
---|
431 | } |
---|
432 | |
---|
433 | #if XML_PARSER_DEBUG |
---|
434 | printf(" vseg %d\n", vseg_loc_index); |
---|
435 | #endif |
---|
436 | |
---|
437 | vseg[vseg_index] = (mapping_vseg_t*)malloc(sizeof(mapping_vseg_t)); |
---|
438 | |
---|
439 | ////////// set vobj_offset attributes |
---|
440 | vseg[vseg_index]->vobj_offset = vobj_index; |
---|
441 | #if XML_PARSER_DEBUG |
---|
442 | printf("- vobj_offset = %d\n", vobj_index); |
---|
443 | #endif |
---|
444 | |
---|
445 | ///////// get name attribute |
---|
446 | str = getStringValue(reader, "name", &ok); |
---|
447 | if ( ok ) |
---|
448 | { |
---|
449 | #if XML_PARSER_DEBUG |
---|
450 | printf(" name = %s\n", str); |
---|
451 | #endif |
---|
452 | strncpy( vseg[vseg_index]->name, str, 31); |
---|
453 | } |
---|
454 | else |
---|
455 | { |
---|
456 | printf("[XML ERROR] illegal or missing <name> attribute for vseg (%d,%d)\n", |
---|
457 | vspace_index, vseg_loc_index); |
---|
458 | exit(1); |
---|
459 | } |
---|
460 | |
---|
461 | /////////// get vbase attribute |
---|
462 | value = getIntValue(reader,"vbase", &ok); |
---|
463 | if ( ok ) |
---|
464 | { |
---|
465 | #if XML_PARSER_DEBUG |
---|
466 | printf(" vbase = 0x%x\n", value); |
---|
467 | #endif |
---|
468 | vseg[vseg_index]->vbase = value; |
---|
469 | } |
---|
470 | else |
---|
471 | { |
---|
472 | printf("[XML ERROR] illegal or missing <vbase> attribute for vseg (%d,%d)\n", |
---|
473 | vspace_index, vseg_loc_index); |
---|
474 | exit(1); |
---|
475 | } |
---|
476 | |
---|
477 | |
---|
478 | ////////// get ident attribute (0 if missing) |
---|
479 | value = getIntValue(reader,"ident", &ok); |
---|
480 | if ( ok ) |
---|
481 | { |
---|
482 | #if XML_PARSER_DEBUG |
---|
483 | printf(" ident = %d\n", value); |
---|
484 | #endif |
---|
485 | vseg[vseg_index]->ident = value; |
---|
486 | } |
---|
487 | else |
---|
488 | { |
---|
489 | vseg[vseg_index]->ident = 0; |
---|
490 | } |
---|
491 | |
---|
492 | |
---|
493 | ////////// get psegname attribute |
---|
494 | str = getStringValue(reader,"psegname", &ok); |
---|
495 | if ( ok ) |
---|
496 | { |
---|
497 | int index = getPsegId( str ); |
---|
498 | if ( index >= 0 ) |
---|
499 | { |
---|
500 | #if XML_PARSER_DEBUG |
---|
501 | printf(" psegname = %s\n", str); |
---|
502 | printf(" psegid = %d\n", index); |
---|
503 | #endif |
---|
504 | vseg[vseg_index]->psegid = index; |
---|
505 | } |
---|
506 | else |
---|
507 | { |
---|
508 | printf("[XML ERROR] illegal or missing <psegname> for vseg %d\n", |
---|
509 | vseg_loc_index); |
---|
510 | exit(1); |
---|
511 | } |
---|
512 | } |
---|
513 | else |
---|
514 | { |
---|
515 | printf("[XML ERROR] illegal or missing <psegname> for vseg %d\n", |
---|
516 | vseg_loc_index); |
---|
517 | exit(1); |
---|
518 | } |
---|
519 | |
---|
520 | // get mode attribute |
---|
521 | str = getStringValue(reader,"mode", &ok); |
---|
522 | #if XML_PARSER_DEBUG |
---|
523 | printf(" mode = %s\n", str); |
---|
524 | #endif |
---|
525 | if (ok && (strcmp(str, "CXWU") == 0)) vseg[vseg_index]->mode = 0xF; |
---|
526 | else if (ok && (strcmp(str, "CXW_") == 0)) vseg[vseg_index]->mode = 0xE; |
---|
527 | else if (ok && (strcmp(str, "CX_U") == 0)) vseg[vseg_index]->mode = 0xD; |
---|
528 | else if (ok && (strcmp(str, "CX__") == 0)) vseg[vseg_index]->mode = 0xC; |
---|
529 | else if (ok && (strcmp(str, "C_WU") == 0)) vseg[vseg_index]->mode = 0xB; |
---|
530 | else if (ok && (strcmp(str, "C_W_") == 0)) vseg[vseg_index]->mode = 0xA; |
---|
531 | else if (ok && (strcmp(str, "C__U") == 0)) vseg[vseg_index]->mode = 0x9; |
---|
532 | else if (ok && (strcmp(str, "C___") == 0)) vseg[vseg_index]->mode = 0x8; |
---|
533 | else if (ok && (strcmp(str, "_XWU") == 0)) vseg[vseg_index]->mode = 0x7; |
---|
534 | else if (ok && (strcmp(str, "_XW_") == 0)) vseg[vseg_index]->mode = 0x6; |
---|
535 | else if (ok && (strcmp(str, "_X_U") == 0)) vseg[vseg_index]->mode = 0x5; |
---|
536 | else if (ok && (strcmp(str, "_X__") == 0)) vseg[vseg_index]->mode = 0x4; |
---|
537 | else if (ok && (strcmp(str, "__WU") == 0)) vseg[vseg_index]->mode = 0x3; |
---|
538 | else if (ok && (strcmp(str, "__W_") == 0)) vseg[vseg_index]->mode = 0x2; |
---|
539 | else if (ok && (strcmp(str, "___U") == 0)) vseg[vseg_index]->mode = 0x1; |
---|
540 | else if (ok && (strcmp(str, "____") == 0)) vseg[vseg_index]->mode = 0x0; |
---|
541 | else |
---|
542 | { |
---|
543 | printf("[XML ERROR] illegal or missing <mode> attribute for vseg (%d,%d)\n", |
---|
544 | vspace_index, vseg_loc_index); |
---|
545 | exit(1); |
---|
546 | } |
---|
547 | |
---|
548 | |
---|
549 | ////////// set the length attribute to 0 |
---|
550 | //the final value will be set by the VLoader |
---|
551 | vseg[vseg_index]->length = value; |
---|
552 | |
---|
553 | ////////// get vobjs |
---|
554 | int status = xmlTextReaderRead ( reader ); |
---|
555 | while ( status == 1 ) |
---|
556 | { |
---|
557 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
---|
558 | |
---|
559 | if ( strcmp(tag,"vobj") == 0 ) vobjNode(reader); |
---|
560 | else if ( strcmp(tag,"#text" ) == 0 ) { } |
---|
561 | else if ( strcmp(tag,"vseg") == 0 ) |
---|
562 | { |
---|
563 | // checking source file consistency? |
---|
564 | vseg[vseg_index]->vobjs = vobj_loc_index; |
---|
565 | vseg_index++; |
---|
566 | vseg_loc_index++; |
---|
567 | return; |
---|
568 | } |
---|
569 | else |
---|
570 | { |
---|
571 | printf("[XML ERROR] Unknown tag %s",tag); |
---|
572 | exit(1); |
---|
573 | } |
---|
574 | status = xmlTextReaderRead ( reader ); |
---|
575 | } |
---|
576 | |
---|
577 | |
---|
578 | } // end vsegNode() |
---|
579 | |
---|
580 | ////////////////////////////////////////// |
---|
581 | void vspaceNode( xmlTextReaderPtr reader ) |
---|
582 | { |
---|
583 | char* str; |
---|
584 | unsigned int ok; |
---|
585 | unsigned int value; |
---|
586 | vobj_loc_vspace_index = 0; |
---|
587 | vseg_loc_index = 0; |
---|
588 | task_loc_index = 0; |
---|
589 | |
---|
590 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
---|
591 | |
---|
592 | // checking source file consistency |
---|
593 | if ( vspace_index >= header->vspaces ) |
---|
594 | { |
---|
595 | printf("[XML ERROR] The vspace index is too large : %d\n", |
---|
596 | vspace_index); |
---|
597 | exit(1); |
---|
598 | } |
---|
599 | |
---|
600 | #if XML_PARSER_DEBUG |
---|
601 | printf(" vspace %d\n", vspace_index); |
---|
602 | #endif |
---|
603 | |
---|
604 | vspace[vspace_index] = (mapping_vspace_t*)malloc(sizeof(mapping_vspace_t)); |
---|
605 | |
---|
606 | ////////// set vseg_offsetand task_offset attributes |
---|
607 | vspace[vspace_index]->vseg_offset = vseg_index; |
---|
608 | vspace[vspace_index]->vobj_offset = vobj_index; |
---|
609 | vspace[vspace_index]->task_offset = task_index; |
---|
610 | |
---|
611 | #if XML_PARSER_DEBUG |
---|
612 | printf("- vseg_offset = %d\n", vseg_index); |
---|
613 | printf("- vobj_offset = %d\n", vobj_index); |
---|
614 | printf("- task_offset = %d\n", task_index); |
---|
615 | #endif |
---|
616 | |
---|
617 | ////////// get name attribute |
---|
618 | str = getStringValue(reader, "name", &ok); |
---|
619 | if ( ok ) |
---|
620 | { |
---|
621 | #if XML_PARSER_DEBUG |
---|
622 | printf(" name = %s\n", str); |
---|
623 | #endif |
---|
624 | strncpy(vspace[vspace_index]->name, str, 31); |
---|
625 | } |
---|
626 | else |
---|
627 | { |
---|
628 | printf("[XML ERROR] illegal or missing <name> attribute for vspace %d", |
---|
629 | vspace_index); |
---|
630 | exit(1); |
---|
631 | } |
---|
632 | |
---|
633 | ////////// get funcs_entry attribute |
---|
634 | str = getStringValue(reader, "funcs", &ok); |
---|
635 | if ( ok ) |
---|
636 | { |
---|
637 | #if XML_PARSER_DEBUG |
---|
638 | printf(" name = %s\n", str); |
---|
639 | #endif |
---|
640 | //used after parsing all the vobjs |
---|
641 | } |
---|
642 | else |
---|
643 | { |
---|
644 | printf("[XML ERROR] illegal or missing <name> attribute for vspace %d", |
---|
645 | vspace_index); |
---|
646 | exit(1); |
---|
647 | } |
---|
648 | |
---|
649 | // get ttys attribute |
---|
650 | value = getIntValue(reader,"ttys", &ok); |
---|
651 | #if XML_PARSER_DEBUG |
---|
652 | printf(" ttys = %d\n", value); |
---|
653 | #endif |
---|
654 | if ( ok ) |
---|
655 | { |
---|
656 | vspace[vspace_index]->ttys = value; |
---|
657 | } |
---|
658 | else |
---|
659 | { |
---|
660 | printf("[XML ERROR] illegal or missing <ttys> attribute for vspace %d", |
---|
661 | vspace_index); |
---|
662 | exit(1); |
---|
663 | } |
---|
664 | |
---|
665 | int status = xmlTextReaderRead ( reader ); |
---|
666 | while ( status == 1 ) |
---|
667 | { |
---|
668 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
---|
669 | |
---|
670 | if ( strcmp(tag,"vseg") == 0 ) vsegNode(reader); |
---|
671 | else if ( strcmp(tag,"task") == 0 ) taskNode(reader); |
---|
672 | else if ( strcmp(tag,"#text" ) == 0 ) { } |
---|
673 | else if ( strcmp(tag,"vspace") == 0 ) |
---|
674 | { |
---|
675 | vspace[vspace_index]->vobjs = vobj_loc_vspace_index; |
---|
676 | vspace[vspace_index]->tasks = task_loc_index ; |
---|
677 | vspace[vspace_index]->vsegs = vseg_loc_index ; |
---|
678 | int index = getVobjLocId( vspace_index, str ); |
---|
679 | if(index == -1) |
---|
680 | { |
---|
681 | printf("Error funcs entry vobj not found %s\n",str); |
---|
682 | exit(-1); |
---|
683 | } |
---|
684 | vspace[vspace_index]->funcs_offset = index; |
---|
685 | |
---|
686 | vspace_index++; |
---|
687 | return; |
---|
688 | } |
---|
689 | else |
---|
690 | { |
---|
691 | printf("[XML ERROR] Unknown tag %s",tag); |
---|
692 | exit(1); |
---|
693 | } |
---|
694 | status = xmlTextReaderRead ( reader ); |
---|
695 | } |
---|
696 | } // end vspaceNode() |
---|
697 | |
---|
698 | ////////////////////////////////////////// |
---|
699 | void psegNode ( xmlTextReaderPtr reader ) |
---|
700 | { |
---|
701 | unsigned int ok; |
---|
702 | unsigned int value; |
---|
703 | char* str; |
---|
704 | |
---|
705 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
---|
706 | |
---|
707 | if ( pseg_index >= MAX_PSEGS ) |
---|
708 | { |
---|
709 | printf("[XML ERROR] The number of psegs is larger than %d\n", MAX_PSEGS); |
---|
710 | exit(1); |
---|
711 | } |
---|
712 | |
---|
713 | #if XML_PARSER_DEBUG |
---|
714 | printf(" pseg %d\n", pseg_index); |
---|
715 | #endif |
---|
716 | |
---|
717 | pseg[pseg_index] = (mapping_pseg_t*)malloc(sizeof(mapping_pseg_t)); |
---|
718 | |
---|
719 | // get name attribute |
---|
720 | str = getStringValue( reader, "name", &ok ); |
---|
721 | #if XML_PARSER_DEBUG |
---|
722 | printf(" - name = %s\n", str); |
---|
723 | #endif |
---|
724 | if ( ok ) |
---|
725 | { |
---|
726 | strncpy(pseg[pseg_index]->name, str, 31); |
---|
727 | } |
---|
728 | else |
---|
729 | { |
---|
730 | printf("[XML ERROR] illegal or missing <name> for pseg %d\n", pseg_index); |
---|
731 | exit(1); |
---|
732 | } |
---|
733 | |
---|
734 | // get base attribute |
---|
735 | value = getIntValue( reader, "base", &ok ); |
---|
736 | #if XML_PARSER_DEBUG |
---|
737 | printf(" - base = %x\n", value); |
---|
738 | #endif |
---|
739 | if ( ok ) |
---|
740 | { |
---|
741 | pseg[pseg_index]->base = value; |
---|
742 | } |
---|
743 | else |
---|
744 | { |
---|
745 | printf("[XML ERROR] illegal or missing <base> for pseg %d\n", pseg_index); |
---|
746 | exit(1); |
---|
747 | } |
---|
748 | |
---|
749 | // get length attribute |
---|
750 | value = getIntValue( reader, "length", &ok ); |
---|
751 | #if XML_PARSER_DEBUG |
---|
752 | printf(" - length = %x\n\n", value); |
---|
753 | #endif |
---|
754 | if ( ok ) |
---|
755 | { |
---|
756 | pseg[pseg_index]->length = value; |
---|
757 | } |
---|
758 | else |
---|
759 | { |
---|
760 | printf("[XML ERROR] illegal or missing <length> for pseg %d\n", pseg_index); |
---|
761 | exit(1); |
---|
762 | } |
---|
763 | |
---|
764 | pseg[pseg_index]->next_free_page = 0; |
---|
765 | pseg_index++; |
---|
766 | } // end psegNode() |
---|
767 | |
---|
768 | ///////////////////////////////////////////// |
---|
769 | void clusterNode ( xmlTextReaderPtr reader ) |
---|
770 | { |
---|
771 | unsigned int ok; |
---|
772 | unsigned int value; |
---|
773 | |
---|
774 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
---|
775 | |
---|
776 | // checking source file consistency |
---|
777 | if ( cluster_index >= header->clusters ) |
---|
778 | { |
---|
779 | printf("[XML ERROR] The cluster index is too large : %d\n", cluster_index); |
---|
780 | exit(1); |
---|
781 | } |
---|
782 | |
---|
783 | #if XML_PARSER_DEBUG |
---|
784 | printf(" cluster %d :\n", cluster_index); |
---|
785 | #endif |
---|
786 | |
---|
787 | cluster[cluster_index] = (mapping_cluster_t*)malloc(sizeof(mapping_cluster_t)); |
---|
788 | |
---|
789 | // get procs attribute |
---|
790 | value = getIntValue(reader,"procs",&ok); |
---|
791 | #if XML_PARSER_DEBUG |
---|
792 | printf(" - procs = %d\n", value); |
---|
793 | #endif |
---|
794 | if ( ok ) |
---|
795 | { |
---|
796 | cluster[cluster_index]->procs = value; |
---|
797 | } |
---|
798 | else |
---|
799 | { |
---|
800 | printf("[XML ERROR] illegal or missing <procs> attribute for cluster %d", |
---|
801 | cluster_index); |
---|
802 | exit(1); |
---|
803 | } |
---|
804 | |
---|
805 | // get timers attribute |
---|
806 | value = getIntValue(reader,"timers",&ok); |
---|
807 | #if XML_PARSER_DEBUG |
---|
808 | printf(" - timers = %d\n", value); |
---|
809 | #endif |
---|
810 | if ( ok ) |
---|
811 | { |
---|
812 | cluster[cluster_index]->timers = value; |
---|
813 | } |
---|
814 | else |
---|
815 | { |
---|
816 | printf("[XML ERROR] illegal or missing <timers> attribute for cluster %d", |
---|
817 | cluster_index); |
---|
818 | exit(1); |
---|
819 | } |
---|
820 | |
---|
821 | // get dmas attribute |
---|
822 | value = getIntValue(reader,"dmas",&ok); |
---|
823 | #if XML_PARSER_DEBUG |
---|
824 | printf(" - dmas = %d\n\n", value); |
---|
825 | #endif |
---|
826 | if ( ok ) |
---|
827 | { |
---|
828 | cluster[cluster_index]->dmas = value; |
---|
829 | } |
---|
830 | else |
---|
831 | { |
---|
832 | printf("[XML ERROR] illegal or missing <dmas> attribute for cluster %d", |
---|
833 | cluster_index); |
---|
834 | exit(1); |
---|
835 | } |
---|
836 | |
---|
837 | cluster_index++; |
---|
838 | } // end clusterNode() |
---|
839 | |
---|
840 | ////////////////////////////////////////////// |
---|
841 | void clusterSetNode( xmlTextReaderPtr reader ) |
---|
842 | { |
---|
843 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
---|
844 | |
---|
845 | #if XML_PARSER_DEBUG |
---|
846 | printf(" clusters set\n"); |
---|
847 | #endif |
---|
848 | |
---|
849 | int status = xmlTextReaderRead ( reader ); |
---|
850 | while ( status == 1 ) |
---|
851 | { |
---|
852 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
---|
853 | |
---|
854 | if ( strcmp(tag,"cluster") == 0 ) clusterNode(reader); |
---|
855 | else if ( strcmp(tag,"#text") == 0 ) { } |
---|
856 | else if ( strcmp(tag,"clusterset") == 0 ) |
---|
857 | { |
---|
858 | // checking source file consistency |
---|
859 | if ( cluster_index != header->clusters ) |
---|
860 | { |
---|
861 | printf("[XML ERROR] Wrong number of clusters\n"); |
---|
862 | exit(1); |
---|
863 | } |
---|
864 | else |
---|
865 | { |
---|
866 | return; |
---|
867 | } |
---|
868 | } |
---|
869 | else |
---|
870 | { |
---|
871 | printf("[XML ERROR] Unknown tag in clusterset node : %s",tag); |
---|
872 | exit(1); |
---|
873 | } |
---|
874 | status = xmlTextReaderRead ( reader ); |
---|
875 | } |
---|
876 | } // end clusterSetNode() |
---|
877 | |
---|
878 | /////////////////////////////////////////// |
---|
879 | void psegSetNode( xmlTextReaderPtr reader ) |
---|
880 | { |
---|
881 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
---|
882 | |
---|
883 | #if XML_PARSER_DEBUG |
---|
884 | printf(" psegs set\n"); |
---|
885 | #endif |
---|
886 | |
---|
887 | int status = xmlTextReaderRead ( reader ); |
---|
888 | while ( status == 1 ) |
---|
889 | { |
---|
890 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
---|
891 | |
---|
892 | if ( strcmp(tag,"pseg") == 0 ) psegNode(reader); |
---|
893 | else if ( strcmp(tag,"#text") == 0 ) { } |
---|
894 | else if ( strcmp(tag,"psegset") == 0 ) |
---|
895 | { |
---|
896 | // checking source file consistency |
---|
897 | if ( pseg_index != header->psegs ) |
---|
898 | { |
---|
899 | printf("[XML ERROR] Wrong number of psegs\n"); |
---|
900 | exit(1); |
---|
901 | } |
---|
902 | else |
---|
903 | { |
---|
904 | return; |
---|
905 | } |
---|
906 | } |
---|
907 | else |
---|
908 | { |
---|
909 | printf("[XML ERROR] Unknown tag in psegset node : %s",tag); |
---|
910 | exit(1); |
---|
911 | } |
---|
912 | status = xmlTextReaderRead ( reader ); |
---|
913 | } |
---|
914 | } // end psegSetNode() |
---|
915 | |
---|
916 | ///////////////////////////////////////////// |
---|
917 | void globalSetNode( xmlTextReaderPtr reader ) |
---|
918 | { |
---|
919 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
---|
920 | |
---|
921 | #if XML_PARSER_DEBUG |
---|
922 | printf(" global vsegs set\n"); |
---|
923 | #endif |
---|
924 | |
---|
925 | int status = xmlTextReaderRead ( reader ); |
---|
926 | while ( status == 1 ) |
---|
927 | { |
---|
928 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
---|
929 | |
---|
930 | if ( strcmp(tag,"vseg") == 0 ) vsegNode(reader); |
---|
931 | else if ( strcmp(tag,"#text" ) == 0 ) { } |
---|
932 | else if ( strcmp(tag,"globalset") == 0 ) |
---|
933 | { |
---|
934 | // checking source file consistency |
---|
935 | if ( vseg_index != header->globals ) |
---|
936 | { |
---|
937 | printf("[XML ERROR] Wrong number of global vsegs\n"); |
---|
938 | exit(1); |
---|
939 | } |
---|
940 | else |
---|
941 | { |
---|
942 | vseg_loc_index = 0; |
---|
943 | return; |
---|
944 | } |
---|
945 | } |
---|
946 | else |
---|
947 | { |
---|
948 | printf("[XML ERROR] Unknown tag in globalset node : %s",tag); |
---|
949 | exit(1); |
---|
950 | } |
---|
951 | status = xmlTextReaderRead ( reader ); |
---|
952 | } |
---|
953 | } // end globalSetNode() |
---|
954 | |
---|
955 | ///////////////////////////////////////////// |
---|
956 | void vspaceSetNode( xmlTextReaderPtr reader ) |
---|
957 | { |
---|
958 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
---|
959 | |
---|
960 | #if XML_PARSER_DEBUG |
---|
961 | printf(" vspaces set\n"); |
---|
962 | #endif |
---|
963 | |
---|
964 | int status = xmlTextReaderRead ( reader ); |
---|
965 | while ( status == 1 ) |
---|
966 | { |
---|
967 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
---|
968 | |
---|
969 | if ( strcmp(tag,"vspace") == 0 ) vspaceNode(reader); |
---|
970 | else if ( strcmp(tag,"#text" ) == 0 ) { } |
---|
971 | else if ( strcmp(tag,"vspaceset") == 0 ) |
---|
972 | { |
---|
973 | // checking source file consistency |
---|
974 | if ( vspace_index != header->vspaces ) |
---|
975 | { |
---|
976 | printf("[XML ERROR] Wrong number of vspaces\n"); |
---|
977 | exit(1); |
---|
978 | } |
---|
979 | else |
---|
980 | { |
---|
981 | header->vsegs = vseg_index; |
---|
982 | header->vobjs = vobj_index; |
---|
983 | header->tasks = task_index; |
---|
984 | return; |
---|
985 | } |
---|
986 | } |
---|
987 | else |
---|
988 | { |
---|
989 | printf("[XML ERROR] Unknown tag in vspaceset node : %s",tag); |
---|
990 | exit(1); |
---|
991 | } |
---|
992 | status = xmlTextReaderRead ( reader ); |
---|
993 | } |
---|
994 | } // end globalSetNode() |
---|
995 | |
---|
996 | ////////////////////////////////////////// |
---|
997 | void headerNode(xmlTextReaderPtr reader ) |
---|
998 | { |
---|
999 | char* name; |
---|
1000 | unsigned int value; |
---|
1001 | unsigned int ok; |
---|
1002 | |
---|
1003 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
---|
1004 | |
---|
1005 | #if XML_PARSER_DEBUG |
---|
1006 | printf("mapping_info\n"); |
---|
1007 | #endif |
---|
1008 | |
---|
1009 | header = (mapping_header_t*)malloc(sizeof(mapping_header_t)); |
---|
1010 | |
---|
1011 | // get name attribute |
---|
1012 | name = getStringValue(reader, "name", &ok); |
---|
1013 | if ( ok ) |
---|
1014 | { |
---|
1015 | #if XML_PARSER_DEBUG |
---|
1016 | printf("- name = %s\n", name); |
---|
1017 | #endif |
---|
1018 | strncpy( header->name, name, 31); |
---|
1019 | } |
---|
1020 | else |
---|
1021 | { |
---|
1022 | printf("[XML ERROR] illegal or missing <name> attribute in header\n"); |
---|
1023 | exit(1); |
---|
1024 | } |
---|
1025 | |
---|
1026 | // get clusters attribute |
---|
1027 | value = getIntValue(reader, "clusters", &ok); |
---|
1028 | if ( ok ) |
---|
1029 | { |
---|
1030 | if ( value >= MAX_CLUSTERS ) |
---|
1031 | { |
---|
1032 | printf("[XML ERROR] The number of clusters is larger than %d\n", MAX_CLUSTERS); |
---|
1033 | exit(1); |
---|
1034 | } |
---|
1035 | #if XML_PARSER_DEBUG |
---|
1036 | printf("- clusters = %d\n", value); |
---|
1037 | #endif |
---|
1038 | header->clusters = value; |
---|
1039 | } |
---|
1040 | else |
---|
1041 | { |
---|
1042 | printf("[XML ERROR] illegal or missing <clusters> attribute in header\n"); |
---|
1043 | exit(1); |
---|
1044 | } |
---|
1045 | |
---|
1046 | // get psegs attribute |
---|
1047 | value = getIntValue(reader, "psegs", &ok); |
---|
1048 | if ( ok ) |
---|
1049 | { |
---|
1050 | if ( value >= MAX_PSEGS ) |
---|
1051 | { |
---|
1052 | printf("[XML ERROR] The number of psegs is larger than %d\n", MAX_PSEGS); |
---|
1053 | exit(1); |
---|
1054 | } |
---|
1055 | #if XML_PARSER_DEBUG |
---|
1056 | printf("- psegs = %d\n", value); |
---|
1057 | #endif |
---|
1058 | header->psegs = value; |
---|
1059 | } |
---|
1060 | else |
---|
1061 | { |
---|
1062 | printf("[XML ERROR] illegal or missing <psegs> attribute in header\n"); |
---|
1063 | exit(1); |
---|
1064 | } |
---|
1065 | |
---|
1066 | // get ttys attribute |
---|
1067 | value = getIntValue(reader, "ttys", &ok); |
---|
1068 | if ( ok ) |
---|
1069 | { |
---|
1070 | #if XML_PARSER_DEBUG |
---|
1071 | printf("- ttys = %d\n", value); |
---|
1072 | #endif |
---|
1073 | header->ttys = value; |
---|
1074 | } |
---|
1075 | else |
---|
1076 | { |
---|
1077 | printf("[XML ERROR] illegal or missing <ttys> attribute in header\n"); |
---|
1078 | exit(1); |
---|
1079 | } |
---|
1080 | |
---|
1081 | // get vspaces attribute |
---|
1082 | value = getIntValue(reader, "vspaces", &ok); |
---|
1083 | if ( ok ) |
---|
1084 | { |
---|
1085 | if ( value >= MAX_VSPACES ) |
---|
1086 | { |
---|
1087 | printf("[XML ERROR] The number of vspaces is larger than %d\n", MAX_VSPACES); |
---|
1088 | exit(1); |
---|
1089 | } |
---|
1090 | #if XML_PARSER_DEBUG |
---|
1091 | printf("- vspaces = %d\n", value); |
---|
1092 | #endif |
---|
1093 | header->vspaces = value; |
---|
1094 | } |
---|
1095 | else |
---|
1096 | { |
---|
1097 | printf("[XML ERROR] illegal or missing <vspaces> attribute in mapping\n"); |
---|
1098 | exit(1); |
---|
1099 | } |
---|
1100 | |
---|
1101 | // get globals attribute |
---|
1102 | value = getIntValue(reader, "globals", &ok); |
---|
1103 | if ( ok ) |
---|
1104 | { |
---|
1105 | if ( value >= MAX_VSEGS ) |
---|
1106 | { |
---|
1107 | printf("[XML ERROR] The number of globals is larger than %d\n", MAX_VSEGS); |
---|
1108 | exit(1); |
---|
1109 | } |
---|
1110 | #if XML_PARSER_DEBUG |
---|
1111 | printf("- globals = %d\n", value); |
---|
1112 | #endif |
---|
1113 | header->globals = value; |
---|
1114 | } |
---|
1115 | else |
---|
1116 | { |
---|
1117 | printf("[XML ERROR] illegal or missing <globals> attribute in mapping_info_header\n"); |
---|
1118 | exit(1); |
---|
1119 | } |
---|
1120 | |
---|
1121 | header->signature = IN_MAPPING_SIGNATURE; |
---|
1122 | |
---|
1123 | int status = xmlTextReaderRead ( reader ); |
---|
1124 | while ( status == 1 ) |
---|
1125 | { |
---|
1126 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
---|
1127 | |
---|
1128 | if ( strcmp(tag,"clusterset") == 0 ) clusterSetNode(reader); |
---|
1129 | else if ( strcmp(tag,"psegset") == 0 ) psegSetNode(reader); |
---|
1130 | else if ( strcmp(tag,"globalset") == 0 ) globalSetNode(reader); |
---|
1131 | else if ( strcmp(tag,"vspaceset") == 0 ) vspaceSetNode(reader); |
---|
1132 | else if ( strcmp(tag,"#text") == 0 ) { } |
---|
1133 | else if ( strcmp(tag,"mapping_info") == 0 ) |
---|
1134 | { |
---|
1135 | #if XML_PARSER_DEBUG |
---|
1136 | printf("end mapping_info\n"); |
---|
1137 | #endif |
---|
1138 | return; |
---|
1139 | } |
---|
1140 | else |
---|
1141 | { |
---|
1142 | printf("[XML ERROR] Unknown tag in header node : %s",tag); |
---|
1143 | exit(1); |
---|
1144 | } |
---|
1145 | status = xmlTextReaderRead ( reader ); |
---|
1146 | } |
---|
1147 | } // end headerNode() |
---|
1148 | |
---|
1149 | /////////////////////////// |
---|
1150 | void buildBin( int fdout ) |
---|
1151 | { |
---|
1152 | unsigned int cluster_id; |
---|
1153 | unsigned int pseg_id; |
---|
1154 | unsigned int vspace_id; |
---|
1155 | unsigned int vseg_id; |
---|
1156 | unsigned int vobj_id; |
---|
1157 | unsigned int task_id; |
---|
1158 | |
---|
1159 | unsigned int length; |
---|
1160 | |
---|
1161 | // write header to binary file |
---|
1162 | length = write(fdout, (char*)header, sizeof(mapping_header_t)); |
---|
1163 | |
---|
1164 | #if XML_PARSER_DEBUG |
---|
1165 | printf("\n*** write header\n"); |
---|
1166 | #endif |
---|
1167 | |
---|
1168 | if ( length != sizeof(mapping_header_t) ) |
---|
1169 | { |
---|
1170 | perror("write header"); |
---|
1171 | exit(1); |
---|
1172 | } |
---|
1173 | |
---|
1174 | // write clusters |
---|
1175 | for ( cluster_id = 0 ; cluster_id < header->clusters ; cluster_id++ ) |
---|
1176 | { |
---|
1177 | length = write(fdout, (char*)cluster[cluster_id], sizeof(mapping_cluster_t)); |
---|
1178 | |
---|
1179 | #if XML_PARSER_DEBUG |
---|
1180 | printf("\n*** write cluster %d\n", cluster_id); |
---|
1181 | #endif |
---|
1182 | |
---|
1183 | if ( length != sizeof(mapping_cluster_t) ) |
---|
1184 | { |
---|
1185 | perror("write cluster"); |
---|
1186 | exit(1); |
---|
1187 | } |
---|
1188 | } |
---|
1189 | |
---|
1190 | // write psegs |
---|
1191 | for ( pseg_id = 0 ; pseg_id < header->psegs ; pseg_id++ ) |
---|
1192 | { |
---|
1193 | length = write(fdout, (char*)pseg[pseg_id], sizeof(mapping_pseg_t)); |
---|
1194 | |
---|
1195 | #if XML_PARSER_DEBUG |
---|
1196 | printf("write pseg %d\n", pseg_id); |
---|
1197 | #endif |
---|
1198 | |
---|
1199 | if ( length != sizeof(mapping_pseg_t) ) |
---|
1200 | { |
---|
1201 | perror("write pseg"); |
---|
1202 | exit(1); |
---|
1203 | } |
---|
1204 | } |
---|
1205 | |
---|
1206 | // write vspaces |
---|
1207 | for ( vspace_id = 0 ; vspace_id < header->vspaces ; vspace_id++ ) |
---|
1208 | { |
---|
1209 | length = write(fdout, (char*)vspace[vspace_id], sizeof(mapping_vspace_t)); |
---|
1210 | |
---|
1211 | #if XML_PARSER_DEBUG |
---|
1212 | printf("write vspace %d\n", vspace_id); |
---|
1213 | printf("vspace->vobj_offset: %d\n", vspace[vspace_id]->vobj_offset); |
---|
1214 | printf("vspace->vobjs: %d\n", vspace[vspace_id]->vobjs); |
---|
1215 | printf("header->vobjs: %d\n", header->vobjs); |
---|
1216 | #endif |
---|
1217 | |
---|
1218 | if ( length != sizeof(mapping_vspace_t) ) |
---|
1219 | { |
---|
1220 | perror("write vspace"); |
---|
1221 | exit(1); |
---|
1222 | } |
---|
1223 | } |
---|
1224 | |
---|
1225 | // write vsegs |
---|
1226 | for ( vseg_id = 0 ; vseg_id < header->vsegs ; vseg_id++ ) |
---|
1227 | { |
---|
1228 | length = write(fdout, (char*)vseg[vseg_id], sizeof(mapping_vseg_t)); |
---|
1229 | |
---|
1230 | #if XML_PARSER_DEBUG |
---|
1231 | printf("write vseg %d\n", vseg_id); |
---|
1232 | #endif |
---|
1233 | |
---|
1234 | if ( length != sizeof(mapping_vseg_t) ) |
---|
1235 | { |
---|
1236 | perror("write vseg"); |
---|
1237 | exit(1); |
---|
1238 | } |
---|
1239 | } |
---|
1240 | |
---|
1241 | // write vobjs |
---|
1242 | for ( vobj_id = 0 ; vobj_id < header->vobjs ; vobj_id++ ) |
---|
1243 | { |
---|
1244 | length = write(fdout, (char*)vobj[vobj_id], sizeof(mapping_vobj_t)); |
---|
1245 | |
---|
1246 | #if XML_PARSER_DEBUG |
---|
1247 | printf("write vobj %d\n", vobj_id); |
---|
1248 | printf("write vobj name %s\n", vobj[vobj_id]->name); |
---|
1249 | printf("write vobj length %x\n", vobj[vobj_id]->length); |
---|
1250 | printf("write vobj type %d\n", vobj[vobj_id]->type); |
---|
1251 | #endif |
---|
1252 | |
---|
1253 | if ( length != sizeof(mapping_vobj_t) ) |
---|
1254 | { |
---|
1255 | perror("write vobj"); |
---|
1256 | exit(1); |
---|
1257 | } |
---|
1258 | } |
---|
1259 | |
---|
1260 | // write tasks |
---|
1261 | for ( task_id = 0 ; task_id < header->tasks ; task_id++ ) |
---|
1262 | { |
---|
1263 | length = write(fdout, (char*)task[task_id], sizeof(mapping_task_t)); |
---|
1264 | |
---|
1265 | #if XML_PARSER_DEBUG |
---|
1266 | printf("write task %d\n", task_id); |
---|
1267 | #endif |
---|
1268 | |
---|
1269 | if ( length != sizeof(mapping_task_t) ) |
---|
1270 | { |
---|
1271 | perror("write task"); |
---|
1272 | exit(1); |
---|
1273 | } |
---|
1274 | } |
---|
1275 | } // end buildBin() |
---|
1276 | |
---|
1277 | ///////////////////////////////////// |
---|
1278 | int main ( int argc, char* argv[] ) |
---|
1279 | { |
---|
1280 | if ( argc < 3 ) |
---|
1281 | { |
---|
1282 | printf("Usage: xml2bin <input_file_path> <output_file_path>\n"); |
---|
1283 | return 1; |
---|
1284 | } |
---|
1285 | |
---|
1286 | int fdout = open( argv[2], (O_CREAT | O_RDWR), S_IRWXU ); |
---|
1287 | if ( fdout < 0) |
---|
1288 | { |
---|
1289 | perror("open"); |
---|
1290 | exit(1); |
---|
1291 | } |
---|
1292 | |
---|
1293 | LIBXML_TEST_VERSION; |
---|
1294 | |
---|
1295 | int status; |
---|
1296 | xmlTextReaderPtr reader = xmlReaderForFile ( argv[1], NULL, 0 ); |
---|
1297 | |
---|
1298 | if ( reader != NULL ) |
---|
1299 | { |
---|
1300 | status = xmlTextReaderRead ( reader ); |
---|
1301 | while ( status == 1 ) |
---|
1302 | { |
---|
1303 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
---|
1304 | if ( strcmp(tag,"mapping_info") == 0 ) |
---|
1305 | { |
---|
1306 | headerNode( reader ); |
---|
1307 | buildBin( fdout ); |
---|
1308 | } |
---|
1309 | else |
---|
1310 | { |
---|
1311 | printf("[XML ERROR] Wrong file type: \"%s\"\n", argv[1]); |
---|
1312 | return 1; |
---|
1313 | } |
---|
1314 | status = xmlTextReaderRead ( reader ); |
---|
1315 | } |
---|
1316 | xmlFreeTextReader ( reader ); |
---|
1317 | |
---|
1318 | if ( status != 0 ) |
---|
1319 | { |
---|
1320 | printf("[XML ERROR] Wrong Syntax in \"%s\" file\n", argv[1]); |
---|
1321 | return 1; |
---|
1322 | } |
---|
1323 | } |
---|
1324 | return 0; |
---|
1325 | } // end main() |
---|