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