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_index) ) |
---|
672 | { |
---|
673 | printf("[XML ERROR] wrong proc index / expected value is %d", |
---|
674 | proc_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 vbase attribute |
---|
1081 | value = getIntValue(reader,"vbase", &ok); |
---|
1082 | if ( ok ) |
---|
1083 | { |
---|
1084 | #if XML_PARSER_DEBUG |
---|
1085 | printf(" vbase = 0x%x\n", value); |
---|
1086 | #endif |
---|
1087 | vseg[vseg_index]->vbase = value; |
---|
1088 | } |
---|
1089 | else |
---|
1090 | { |
---|
1091 | printf("[XML ERROR] illegal or missing <vbase> attribute for vseg (%d,%d)\n", |
---|
1092 | vspace_index, vseg_loc_index); |
---|
1093 | exit(1); |
---|
1094 | } |
---|
1095 | |
---|
1096 | ////////// get clusterid and psegname attributes |
---|
1097 | value = getIntValue(reader,"clusterid", &ok); |
---|
1098 | if ( ok == 0 ) |
---|
1099 | { |
---|
1100 | printf("[XML ERROR] illegal or missing <clusterid> for vseg %d\n", |
---|
1101 | vseg_loc_index); |
---|
1102 | exit(1); |
---|
1103 | } |
---|
1104 | str = getStringValue(reader,"psegname", &ok); |
---|
1105 | if ( ok == 0 ) |
---|
1106 | { |
---|
1107 | printf("[XML ERROR] illegal or missing <psegname> for vseg %d\n", |
---|
1108 | vseg_loc_index); |
---|
1109 | exit(1); |
---|
1110 | } |
---|
1111 | |
---|
1112 | /////////// set psegid field |
---|
1113 | int index = getPsegId( value, str ); |
---|
1114 | if ( index >= 0 ) |
---|
1115 | { |
---|
1116 | #if XML_PARSER_DEBUG |
---|
1117 | printf(" clusterid = %d\n", value); |
---|
1118 | printf(" psegname = %s\n", str); |
---|
1119 | printf(" psegid = %d\n", index); |
---|
1120 | #endif |
---|
1121 | vseg[vseg_index]->psegid = index; |
---|
1122 | } |
---|
1123 | else |
---|
1124 | { |
---|
1125 | printf("[XML ERROR] pseg not found for vseg %d / clusterid = %d / psegname = %s\n", |
---|
1126 | vseg_loc_index, value, str ); |
---|
1127 | exit(1); |
---|
1128 | } |
---|
1129 | |
---|
1130 | ////////// get ident attribute (optional : 0 if missing) |
---|
1131 | value = getIntValue(reader,"ident", &ok); |
---|
1132 | if ( ok ) |
---|
1133 | { |
---|
1134 | #if XML_PARSER_DEBUG |
---|
1135 | printf(" ident = %d\n", value); |
---|
1136 | #endif |
---|
1137 | vseg[vseg_index]->ident = value; |
---|
1138 | } |
---|
1139 | else |
---|
1140 | { |
---|
1141 | vseg[vseg_index]->ident = 0; |
---|
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 %d\n", |
---|
1260 | vspace_index); |
---|
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 the start vector not found %s\n",str); |
---|
1284 | exit(-1); |
---|
1285 | } |
---|
1286 | else |
---|
1287 | { |
---|
1288 | vspace[vspace_index]->start_offset = index; |
---|
1289 | #if XML_PARSER_DEBUG |
---|
1290 | printf(" startname = %s\n", str); |
---|
1291 | printf(" startid = %d\n", index); |
---|
1292 | printf(" end vspace %d\n\n", vspace_index); |
---|
1293 | #endif |
---|
1294 | } |
---|
1295 | |
---|
1296 | // checking startid values for all tasks in vspace |
---|
1297 | int task_id; |
---|
1298 | int task_min = vspace[vspace_index]->task_offset; |
---|
1299 | int task_max = task_min + vspace[vspace_index]->tasks; |
---|
1300 | for ( task_id = task_min ; task_id < task_max ; task_id++ ) |
---|
1301 | { |
---|
1302 | if ( task[task_id]->startid >= vspace[vspace_index]->tasks ) |
---|
1303 | { |
---|
1304 | printf("[XML ERROR] <startid> too large for task (%d,%d)\n", |
---|
1305 | vspace_index, task_id ); |
---|
1306 | exit(1); |
---|
1307 | } |
---|
1308 | } |
---|
1309 | |
---|
1310 | vspace_index++; |
---|
1311 | return; |
---|
1312 | } |
---|
1313 | else |
---|
1314 | { |
---|
1315 | printf("[XML ERROR] Unknown tag %s",tag); |
---|
1316 | exit(1); |
---|
1317 | } |
---|
1318 | status = xmlTextReaderRead ( reader ); |
---|
1319 | } |
---|
1320 | } // end vspaceNode() |
---|
1321 | |
---|
1322 | ////////////////////////////////////////// |
---|
1323 | void psegNode ( xmlTextReaderPtr reader ) |
---|
1324 | ////////////////////////////////////////// |
---|
1325 | { |
---|
1326 | unsigned int ok; |
---|
1327 | unsigned int value; |
---|
1328 | char* str; |
---|
1329 | |
---|
1330 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
---|
1331 | |
---|
1332 | if ( pseg_index >= MAX_PSEGS ) |
---|
1333 | { |
---|
1334 | printf("[XML ERROR] The number of psegs is larger than %d\n", MAX_PSEGS); |
---|
1335 | exit(1); |
---|
1336 | } |
---|
1337 | |
---|
1338 | #if XML_PARSER_DEBUG |
---|
1339 | printf(" pseg %d\n", pseg_index); |
---|
1340 | #endif |
---|
1341 | |
---|
1342 | pseg[pseg_index] = (mapping_pseg_t*)malloc(sizeof(mapping_pseg_t)); |
---|
1343 | |
---|
1344 | /////// get name attribute |
---|
1345 | str = getStringValue( reader, "name", &ok ); |
---|
1346 | #if XML_PARSER_DEBUG |
---|
1347 | printf(" name = %s\n", str); |
---|
1348 | #endif |
---|
1349 | if ( ok ) |
---|
1350 | { |
---|
1351 | strncpy(pseg[pseg_index]->name, str, 31); |
---|
1352 | } |
---|
1353 | else |
---|
1354 | { |
---|
1355 | printf("[XML ERROR] illegal or missing <name> for pseg %d in cluster %d\n", |
---|
1356 | pseg_index, cluster_index); |
---|
1357 | exit(1); |
---|
1358 | } |
---|
1359 | |
---|
1360 | //////// get type attribute |
---|
1361 | str = getStringValue(reader, "type", &ok); |
---|
1362 | #if XML_PARSER_DEBUG |
---|
1363 | printf(" type = %s\n", str); |
---|
1364 | #endif |
---|
1365 | if (ok && (strcmp(str, "RAM" ) == 0)) pseg[pseg_index]->type = PSEG_TYPE_RAM; |
---|
1366 | else if (ok && (strcmp(str, "ROM" ) == 0)) pseg[pseg_index]->type = PSEG_TYPE_ROM; |
---|
1367 | else if (ok && (strcmp(str, "PERI") == 0)) pseg[pseg_index]->type = PSEG_TYPE_PERI; |
---|
1368 | else |
---|
1369 | { |
---|
1370 | printf("[XML ERROR] illegal or missing <type> for pseg %s in cluster %d\n", |
---|
1371 | pseg[pseg_index]->name, cluster_index); |
---|
1372 | exit(1); |
---|
1373 | } |
---|
1374 | |
---|
1375 | //////// get base attribute |
---|
1376 | value = getIntValue( reader, "base", &ok ); |
---|
1377 | #if XML_PARSER_DEBUG |
---|
1378 | printf(" base = 0x%x\n", value); |
---|
1379 | #endif |
---|
1380 | if ( ok ) |
---|
1381 | { |
---|
1382 | pseg[pseg_index]->base = value; |
---|
1383 | } |
---|
1384 | else |
---|
1385 | { |
---|
1386 | printf("[XML ERROR] illegal or missing <base> for pseg %s in cluster %d\n", |
---|
1387 | pseg[pseg_index]->name, cluster_index); |
---|
1388 | exit(1); |
---|
1389 | } |
---|
1390 | |
---|
1391 | //////// get length attribute |
---|
1392 | value = getIntValue( reader, "length", &ok ); |
---|
1393 | #if XML_PARSER_DEBUG |
---|
1394 | printf(" length = 0x%x\n", value); |
---|
1395 | #endif |
---|
1396 | if ( ok ) |
---|
1397 | { |
---|
1398 | pseg[pseg_index]->length = value; |
---|
1399 | } |
---|
1400 | else |
---|
1401 | { |
---|
1402 | printf("[XML ERROR] illegal or missing <length> for pseg %s in cluster %d\n", |
---|
1403 | pseg[pseg_index]->name, cluster_index); |
---|
1404 | exit(1); |
---|
1405 | } |
---|
1406 | |
---|
1407 | //////// set cluster attribute |
---|
1408 | pseg[pseg_index]->cluster = cluster_index; |
---|
1409 | |
---|
1410 | pseg_index++; |
---|
1411 | cluster[cluster_index]->psegs++; |
---|
1412 | } // end psegNode() |
---|
1413 | |
---|
1414 | ///////////////////////////////////////////// |
---|
1415 | void clusterNode ( xmlTextReaderPtr reader ) |
---|
1416 | ///////////////////////////////////////////// |
---|
1417 | { |
---|
1418 | unsigned int ok; |
---|
1419 | unsigned int value; |
---|
1420 | |
---|
1421 | proc_loc_index = 0; |
---|
1422 | coproc_loc_index = 0; |
---|
1423 | periph_loc_index = 0; |
---|
1424 | |
---|
1425 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
---|
1426 | |
---|
1427 | // checking source file consistency |
---|
1428 | if ( cluster_index >= header->clusters ) |
---|
1429 | { |
---|
1430 | printf("[XML ERROR] The cluster index is too large : %d\n", cluster_index); |
---|
1431 | exit(1); |
---|
1432 | } |
---|
1433 | |
---|
1434 | #if XML_PARSER_DEBUG |
---|
1435 | printf(" cluster %d\n", cluster_index); |
---|
1436 | #endif |
---|
1437 | |
---|
1438 | cluster[cluster_index] = (mapping_cluster_t*)malloc(sizeof(mapping_cluster_t)); |
---|
1439 | |
---|
1440 | /////////// check cluster index attribute (optional) |
---|
1441 | value = getIntValue(reader,"index",&ok); |
---|
1442 | if ( ok && (value != cluster_index) ) |
---|
1443 | { |
---|
1444 | printf("[XML ERROR] wrong cluster index / expected value is %d", |
---|
1445 | cluster_index); |
---|
1446 | exit(1); |
---|
1447 | } |
---|
1448 | |
---|
1449 | ////////// set offsets |
---|
1450 | cluster[cluster_index]->pseg_offset = pseg_index; |
---|
1451 | cluster[cluster_index]->proc_offset = proc_index; |
---|
1452 | cluster[cluster_index]->coproc_offset = coproc_index; |
---|
1453 | cluster[cluster_index]->periph_offset = periph_index; |
---|
1454 | |
---|
1455 | #if XML_PARSER_DEBUG |
---|
1456 | printf(" pseg_offset = %d\n", pseg_index); |
---|
1457 | printf(" proc_offset = %d\n", proc_index); |
---|
1458 | printf(" coproc_offset = %d\n", coproc_index); |
---|
1459 | printf(" periph_offset = %d\n", coproc_index); |
---|
1460 | #endif |
---|
1461 | |
---|
1462 | ////////// get psegs, procs, coprocs and periphs |
---|
1463 | int status = xmlTextReaderRead(reader); |
---|
1464 | |
---|
1465 | while ( status == 1 ) |
---|
1466 | { |
---|
1467 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
---|
1468 | |
---|
1469 | if ( strcmp(tag, "pseg") == 0 ) psegNode(reader); |
---|
1470 | else if ( strcmp(tag, "proc") == 0 ) procNode(reader); |
---|
1471 | else if ( strcmp(tag, "coproc") == 0 ) coprocNode(reader); |
---|
1472 | else if ( strcmp(tag, "periph") == 0 ) periphNode(reader); |
---|
1473 | else if ( strcmp(tag, "#text") == 0 ) { } |
---|
1474 | else if ( strcmp(tag, "#comment") == 0 ) { } |
---|
1475 | else if ( strcmp(tag, "cluster") == 0 ) |
---|
1476 | { |
---|
1477 | cluster[cluster_index]->procs = proc_loc_index; |
---|
1478 | cluster[cluster_index]->coprocs = coproc_loc_index; |
---|
1479 | cluster[cluster_index]->periphs = periph_loc_index; |
---|
1480 | |
---|
1481 | // cluster[cluster_index]psegs update is done in psegNode(), |
---|
1482 | // because the coprocNode() call to getPsegId() need it |
---|
1483 | |
---|
1484 | #if XML_PARSER_DEBUG |
---|
1485 | printf(" psegs = %d\n", cluster[cluster_index]->psegs); |
---|
1486 | printf(" procs = %d\n", cluster[cluster_index]->procs); |
---|
1487 | printf(" coprocs = %d\n", cluster[cluster_index]->coprocs); |
---|
1488 | printf(" periphs = %d\n", cluster[cluster_index]->periphs); |
---|
1489 | printf(" end cluster %d\n", cluster_index); |
---|
1490 | #endif |
---|
1491 | cluster_index++; |
---|
1492 | return; |
---|
1493 | } |
---|
1494 | status = xmlTextReaderRead(reader); |
---|
1495 | } |
---|
1496 | } // end clusterNode() |
---|
1497 | |
---|
1498 | ////////////////////////////////////////////// |
---|
1499 | void clusterSetNode( xmlTextReaderPtr reader ) |
---|
1500 | ////////////////////////////////////////////// |
---|
1501 | { |
---|
1502 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
---|
1503 | |
---|
1504 | #if XML_PARSER_DEBUG |
---|
1505 | printf("\n clusters set\n"); |
---|
1506 | #endif |
---|
1507 | |
---|
1508 | int status = xmlTextReaderRead(reader); |
---|
1509 | while ( status == 1 ) |
---|
1510 | { |
---|
1511 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
---|
1512 | |
---|
1513 | if ( strcmp(tag, "cluster") == 0 ) clusterNode(reader); |
---|
1514 | else if ( strcmp(tag, "#text") == 0 ) { } |
---|
1515 | else if ( strcmp(tag, "#comment") == 0 ) { } |
---|
1516 | else if ( strcmp(tag, "clusterset") == 0 ) |
---|
1517 | { |
---|
1518 | // checking source file consistency |
---|
1519 | if ( cluster_index != header->clusters ) |
---|
1520 | { |
---|
1521 | printf("[XML ERROR] Wrong number of clusters\n"); |
---|
1522 | exit(1); |
---|
1523 | } |
---|
1524 | else |
---|
1525 | { |
---|
1526 | #if XML_PARSER_DEBUG |
---|
1527 | printf(" end cluster set\n\n"); |
---|
1528 | #endif |
---|
1529 | header->psegs = pseg_index; |
---|
1530 | header->procs = proc_index; |
---|
1531 | header->irqs = irq_index; |
---|
1532 | header->coprocs = coproc_index; |
---|
1533 | header->cp_ports = cp_port_index; |
---|
1534 | return; |
---|
1535 | } |
---|
1536 | } |
---|
1537 | else |
---|
1538 | { |
---|
1539 | printf("[XML ERROR] Unknown tag in clusterset node : %s",tag); |
---|
1540 | exit(1); |
---|
1541 | } |
---|
1542 | status = xmlTextReaderRead(reader); |
---|
1543 | } |
---|
1544 | } // end clusterSetNode() |
---|
1545 | |
---|
1546 | ///////////////////////////////////////////// |
---|
1547 | void globalSetNode( xmlTextReaderPtr reader ) |
---|
1548 | ///////////////////////////////////////////// |
---|
1549 | { |
---|
1550 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
---|
1551 | |
---|
1552 | #if XML_PARSER_DEBUG |
---|
1553 | printf(" globals set\n"); |
---|
1554 | #endif |
---|
1555 | |
---|
1556 | int status = xmlTextReaderRead(reader); |
---|
1557 | while ( status == 1 ) |
---|
1558 | { |
---|
1559 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
---|
1560 | |
---|
1561 | if ( strcmp(tag, "vseg") == 0 ) vsegNode(reader); |
---|
1562 | else if ( strcmp(tag, "#text" ) == 0 ) { } |
---|
1563 | else if ( strcmp(tag, "#comment") == 0 ) { } |
---|
1564 | else if ( strcmp(tag, "globalset") == 0 ) |
---|
1565 | { |
---|
1566 | // checking source file consistency |
---|
1567 | if ( vseg_index != header->globals ) |
---|
1568 | { |
---|
1569 | printf("[XML ERROR] Wrong number of global vsegs\n"); |
---|
1570 | exit(1); |
---|
1571 | } |
---|
1572 | else |
---|
1573 | { |
---|
1574 | #if XML_PARSER_DEBUG |
---|
1575 | printf(" end global set\n\n"); |
---|
1576 | #endif |
---|
1577 | vseg_loc_index = 0; |
---|
1578 | return; |
---|
1579 | } |
---|
1580 | } |
---|
1581 | else |
---|
1582 | { |
---|
1583 | printf("[XML ERROR] Unknown tag in globalset node : %s",tag); |
---|
1584 | exit(1); |
---|
1585 | } |
---|
1586 | status = xmlTextReaderRead ( reader ); |
---|
1587 | } |
---|
1588 | } // end globalSetNode() |
---|
1589 | |
---|
1590 | ///////////////////////////////////////////// |
---|
1591 | void vspaceSetNode( xmlTextReaderPtr reader ) |
---|
1592 | ///////////////////////////////////////////// |
---|
1593 | { |
---|
1594 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
---|
1595 | |
---|
1596 | #if XML_PARSER_DEBUG |
---|
1597 | printf("\n vspaces set\n"); |
---|
1598 | #endif |
---|
1599 | |
---|
1600 | int status = xmlTextReaderRead ( reader ); |
---|
1601 | while ( status == 1 ) |
---|
1602 | { |
---|
1603 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
---|
1604 | |
---|
1605 | if ( strcmp(tag, "vspace" ) == 0 ) vspaceNode(reader); |
---|
1606 | else if ( strcmp(tag, "#text" ) == 0 ) { } |
---|
1607 | else if ( strcmp(tag, "#comment" ) == 0 ) { } |
---|
1608 | else if ( strcmp(tag, "vspaceset") == 0 ) |
---|
1609 | { |
---|
1610 | // checking source file consistency |
---|
1611 | if ( vspace_index != header->vspaces ) |
---|
1612 | { |
---|
1613 | printf("[XML ERROR] Wrong number of vspaces\n"); |
---|
1614 | exit(1); |
---|
1615 | } |
---|
1616 | else |
---|
1617 | { |
---|
1618 | header->vsegs = vseg_index; |
---|
1619 | header->vobjs = vobj_index; |
---|
1620 | header->tasks = task_index; |
---|
1621 | return; |
---|
1622 | } |
---|
1623 | } |
---|
1624 | else |
---|
1625 | { |
---|
1626 | printf("[XML ERROR] Unknown tag in vspaceset node : %s",tag); |
---|
1627 | exit(1); |
---|
1628 | } |
---|
1629 | status = xmlTextReaderRead ( reader ); |
---|
1630 | } |
---|
1631 | } // end globalSetNode() |
---|
1632 | |
---|
1633 | ////////////////////////////////////////// |
---|
1634 | void headerNode(xmlTextReaderPtr reader ) |
---|
1635 | ////////////////////////////////////////// |
---|
1636 | { |
---|
1637 | char* name; |
---|
1638 | unsigned int value; |
---|
1639 | unsigned int ok; |
---|
1640 | |
---|
1641 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
---|
1642 | |
---|
1643 | #if XML_PARSER_DEBUG |
---|
1644 | printf("mapping_info\n"); |
---|
1645 | #endif |
---|
1646 | |
---|
1647 | header = (mapping_header_t*)malloc(sizeof(mapping_header_t)); |
---|
1648 | |
---|
1649 | ////////// get name attribute |
---|
1650 | name = getStringValue(reader, "name", &ok); |
---|
1651 | if ( ok ) |
---|
1652 | { |
---|
1653 | #if XML_PARSER_DEBUG |
---|
1654 | printf(" name = %s\n", name); |
---|
1655 | #endif |
---|
1656 | strncpy( header->name, name, 31); |
---|
1657 | } |
---|
1658 | else |
---|
1659 | { |
---|
1660 | printf("[XML ERROR] illegal or missing <name> attribute in header\n"); |
---|
1661 | exit(1); |
---|
1662 | } |
---|
1663 | |
---|
1664 | /////////// get clusters attribute |
---|
1665 | value = getIntValue(reader, "clusters", &ok); |
---|
1666 | if ( ok ) |
---|
1667 | { |
---|
1668 | if ( value >= MAX_CLUSTERS ) |
---|
1669 | { |
---|
1670 | printf("[XML ERROR] The number of clusters is larger than %d\n", MAX_CLUSTERS); |
---|
1671 | exit(1); |
---|
1672 | } |
---|
1673 | #if XML_PARSER_DEBUG |
---|
1674 | printf(" clusters = %d\n", value); |
---|
1675 | #endif |
---|
1676 | header->clusters = value; |
---|
1677 | } |
---|
1678 | else |
---|
1679 | { |
---|
1680 | printf("[XML ERROR] illegal or missing <clusters> attribute in header\n"); |
---|
1681 | exit(1); |
---|
1682 | } |
---|
1683 | |
---|
1684 | ///////// get vspaces attribute |
---|
1685 | value = getIntValue(reader, "vspaces", &ok); |
---|
1686 | if ( ok ) |
---|
1687 | { |
---|
1688 | if ( value >= MAX_VSPACES ) |
---|
1689 | { |
---|
1690 | printf("[XML ERROR] The number of vspaces is larger than %d\n", MAX_VSPACES); |
---|
1691 | exit(1); |
---|
1692 | } |
---|
1693 | #if XML_PARSER_DEBUG |
---|
1694 | printf(" vspaces = %d\n", value); |
---|
1695 | #endif |
---|
1696 | header->vspaces = value; |
---|
1697 | } |
---|
1698 | else |
---|
1699 | { |
---|
1700 | printf("[XML ERROR] illegal or missing <vspaces> attribute in mapping\n"); |
---|
1701 | exit(1); |
---|
1702 | } |
---|
1703 | |
---|
1704 | ////////// get globals attribute |
---|
1705 | value = getIntValue(reader, "globals", &ok); |
---|
1706 | if ( ok ) |
---|
1707 | { |
---|
1708 | if ( value >= MAX_VSEGS ) |
---|
1709 | { |
---|
1710 | printf("[XML ERROR] The number of globals is larger than %d\n", MAX_VSEGS); |
---|
1711 | exit(1); |
---|
1712 | } |
---|
1713 | #if XML_PARSER_DEBUG |
---|
1714 | printf(" globals = %d\n", value); |
---|
1715 | #endif |
---|
1716 | header->globals = value; |
---|
1717 | } |
---|
1718 | else |
---|
1719 | { |
---|
1720 | printf("[XML ERROR] illegal or missing <globals> attribute in mapping_info_header\n"); |
---|
1721 | exit(1); |
---|
1722 | } |
---|
1723 | |
---|
1724 | //////// initialise non replicated peripherals cluster_id |
---|
1725 | header->tty_clusterid = 0xFFFFFFFF; |
---|
1726 | header->nic_clusterid = 0xFFFFFFFF; |
---|
1727 | header->ioc_clusterid = 0xFFFFFFFF; |
---|
1728 | header->fbf_clusterid = 0xFFFFFFFF; |
---|
1729 | |
---|
1730 | ///////// set signature |
---|
1731 | header->signature = IN_MAPPING_SIGNATURE; |
---|
1732 | |
---|
1733 | int status = xmlTextReaderRead(reader); |
---|
1734 | while ( status == 1 ) |
---|
1735 | { |
---|
1736 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
---|
1737 | |
---|
1738 | if ( strcmp(tag, "clusterset") == 0 ) clusterSetNode(reader); |
---|
1739 | else if ( strcmp(tag, "globalset") == 0 ) globalSetNode(reader); |
---|
1740 | else if ( strcmp(tag, "vspaceset") == 0 ) vspaceSetNode(reader); |
---|
1741 | else if ( strcmp(tag, "#text") == 0 ) { } |
---|
1742 | else if ( strcmp(tag, "#comment") == 0 ) { } |
---|
1743 | else if ( strcmp(tag, "mapping_info") == 0 ) |
---|
1744 | { |
---|
1745 | #if XML_PARSER_DEBUG |
---|
1746 | printf("end mapping_info\n"); |
---|
1747 | #endif |
---|
1748 | return; |
---|
1749 | } |
---|
1750 | else |
---|
1751 | { |
---|
1752 | printf("[XML ERROR] Unknown tag in header node : %s\n",tag); |
---|
1753 | exit(1); |
---|
1754 | } |
---|
1755 | status = xmlTextReaderRead(reader); |
---|
1756 | } |
---|
1757 | } // end headerNode() |
---|
1758 | |
---|
1759 | /////////////////////////////////////// |
---|
1760 | void BuildTable( int fdout, |
---|
1761 | const char* type, |
---|
1762 | unsigned int nb_elem, |
---|
1763 | unsigned int elem_size, |
---|
1764 | char** table) |
---|
1765 | //////////////////////////////////////// |
---|
1766 | { |
---|
1767 | unsigned int i; |
---|
1768 | unsigned int length; |
---|
1769 | // write element |
---|
1770 | for ( i = 0 ; i < nb_elem ; i++ ) |
---|
1771 | { |
---|
1772 | length = write(fdout, table[i], elem_size); |
---|
1773 | |
---|
1774 | #if XML_PARSER_DEBUG |
---|
1775 | printf("Building binary: writing %s %d\n", type, i); |
---|
1776 | #endif |
---|
1777 | |
---|
1778 | if ( length != elem_size ) |
---|
1779 | { |
---|
1780 | printf("type: %s\n", type); |
---|
1781 | perror("error writing"); |
---|
1782 | exit(1); |
---|
1783 | } |
---|
1784 | } |
---|
1785 | } |
---|
1786 | |
---|
1787 | /////////////////////////// |
---|
1788 | void buildBin( int fdout ) |
---|
1789 | /////////////////////////// |
---|
1790 | { |
---|
1791 | unsigned int vspace_id; |
---|
1792 | unsigned int vobj_id; |
---|
1793 | unsigned int length; |
---|
1794 | |
---|
1795 | // write header to binary file |
---|
1796 | length = write(fdout, (char*)header, sizeof(mapping_header_t)); |
---|
1797 | |
---|
1798 | #if XML_PARSER_DEBUG |
---|
1799 | printf("\n*** write header\n"); |
---|
1800 | #endif |
---|
1801 | |
---|
1802 | if ( length != sizeof(mapping_header_t) ) |
---|
1803 | { |
---|
1804 | printf("write header error : length = %d \n", length); |
---|
1805 | exit(1); |
---|
1806 | } |
---|
1807 | |
---|
1808 | // write clusters |
---|
1809 | BuildTable(fdout, "cluster", cluster_index, sizeof(mapping_cluster_t), (char**) cluster); |
---|
1810 | |
---|
1811 | // write psegs |
---|
1812 | BuildTable(fdout, "pseg", pseg_index, sizeof(mapping_pseg_t), (char**) pseg); |
---|
1813 | |
---|
1814 | // write vspaces |
---|
1815 | for ( vspace_id = 0 ; vspace_id < header->vspaces ; vspace_id++ ) |
---|
1816 | { |
---|
1817 | length = write(fdout, (char*)vspace[vspace_id], sizeof(mapping_vspace_t)); |
---|
1818 | |
---|
1819 | #if XML_PARSER_DEBUG |
---|
1820 | printf("write vspace %d\n", vspace_id); |
---|
1821 | printf("vspace->vobj_offset: %d\n", vspace[vspace_id]->vobj_offset); |
---|
1822 | printf("vspace->vobjs: %d\n", vspace[vspace_id]->vobjs); |
---|
1823 | printf("header->vobjs: %d\n", header->vobjs); |
---|
1824 | #endif |
---|
1825 | |
---|
1826 | if ( length != sizeof(mapping_vspace_t) ) |
---|
1827 | { |
---|
1828 | perror("write vspace"); |
---|
1829 | exit(1); |
---|
1830 | } |
---|
1831 | } |
---|
1832 | |
---|
1833 | // write vsegs |
---|
1834 | BuildTable(fdout, "vseg", vseg_index, sizeof(mapping_vseg_t), (char**) vseg); |
---|
1835 | |
---|
1836 | // write vobjs |
---|
1837 | for ( vobj_id = 0 ; vobj_id < header->vobjs ; vobj_id++ ) |
---|
1838 | { |
---|
1839 | length = write(fdout, (char*)vobj[vobj_id], sizeof(mapping_vobj_t)); |
---|
1840 | |
---|
1841 | #if XML_PARSER_DEBUG |
---|
1842 | printf("write vobj %d\n", vobj_id); |
---|
1843 | printf("write vobj name %s\n", vobj[vobj_id]->name); |
---|
1844 | printf("write vobj length %x\n", vobj[vobj_id]->length); |
---|
1845 | printf("write vobj type %d\n", vobj[vobj_id]->type); |
---|
1846 | #endif |
---|
1847 | |
---|
1848 | if ( length != sizeof(mapping_vobj_t) ) |
---|
1849 | { |
---|
1850 | perror("write vobj"); |
---|
1851 | exit(1); |
---|
1852 | } |
---|
1853 | } |
---|
1854 | |
---|
1855 | // write tasks array |
---|
1856 | BuildTable(fdout, "task", task_index, sizeof(mapping_task_t), (char**) task); |
---|
1857 | //building procs array |
---|
1858 | BuildTable(fdout, "proc", proc_index, sizeof(mapping_proc_t), (char**) proc); |
---|
1859 | //building irqs array |
---|
1860 | BuildTable(fdout, "irq", irq_index, sizeof(mapping_irq_t), (char**)irq); |
---|
1861 | //building coprocs array |
---|
1862 | BuildTable(fdout, "coproc", coproc_index, sizeof(mapping_coproc_t), (char**)coproc); |
---|
1863 | //building cp_ports array |
---|
1864 | BuildTable(fdout, "cp_port", cp_port_index, sizeof(mapping_cp_port_t),(char**) cp_port); |
---|
1865 | //building periphs array |
---|
1866 | BuildTable(fdout, "periph", periph_index, sizeof(mapping_periph_t), (char**)periph); |
---|
1867 | |
---|
1868 | } // end buildBin() |
---|
1869 | |
---|
1870 | /////////////////////////////////////////////////////////////////////// |
---|
1871 | // this function set the value the vobj_id fiels of all cp_ports |
---|
1872 | /////////////////////////////////////////////////////////////////////// |
---|
1873 | void prepareBuild() |
---|
1874 | { |
---|
1875 | unsigned int i; |
---|
1876 | //asign for all cp_ports the correct vspaceid and vobjid |
---|
1877 | for(i=0; i< cp_port_index; i++) |
---|
1878 | { |
---|
1879 | int vspace_id = getVspaceId( cp_port_vobj_ref[i]->vspace_name ); |
---|
1880 | if ( vspace_id < 0 ) |
---|
1881 | { |
---|
1882 | printf("[XML ERROR] illegal <vspacename> for cp_port %d,\n", |
---|
1883 | i); |
---|
1884 | exit(1); |
---|
1885 | } |
---|
1886 | cp_port[i]->vspaceid = vspace_id; |
---|
1887 | |
---|
1888 | int vobj_id = getVobjLocId( vspace_id, |
---|
1889 | cp_port_vobj_ref[i]->vobj_name, |
---|
1890 | vspace[vspace_id]->vobjs ); |
---|
1891 | if ( vobj_id >= 0 ) |
---|
1892 | { |
---|
1893 | |
---|
1894 | #if XML_PARSER_DEBUG |
---|
1895 | printf("\ncp_port = %d\n", i); |
---|
1896 | printf(" vspace_name = %s\n", cp_port_vobj_ref[i]->vspace_name); |
---|
1897 | printf(" vobj_name = %s\n", cp_port_vobj_ref[i]->vobj_name); |
---|
1898 | printf(" vobj_index = %d\n", vobj_id); |
---|
1899 | #endif |
---|
1900 | cp_port[i]->vobjlocid = vobj_id; |
---|
1901 | |
---|
1902 | assert((vobj[ vspace[vspace_id]->vobj_offset + vobj_id]->type == VOBJ_TYPE_MWMR) |
---|
1903 | && "coproc ports has to refere to a vobj of type MWMR"); |
---|
1904 | } |
---|
1905 | else |
---|
1906 | { |
---|
1907 | printf("[XML ERROR] illegal <vobjname> for cp_port %d,\n", |
---|
1908 | i); |
---|
1909 | exit(1); |
---|
1910 | } |
---|
1911 | } |
---|
1912 | } |
---|
1913 | |
---|
1914 | ///////////////////////////////////// |
---|
1915 | int main ( int argc, char* argv[] ) |
---|
1916 | ///////////////////////////////////// |
---|
1917 | { |
---|
1918 | if ( argc < 3 ) |
---|
1919 | { |
---|
1920 | printf("Usage: xml2bin <input_file_path> <output_file_path>\n"); |
---|
1921 | return 1; |
---|
1922 | } |
---|
1923 | |
---|
1924 | int fdout = open( argv[2], (O_CREAT | O_RDWR), S_IRWXU ); |
---|
1925 | if ( fdout < 0) |
---|
1926 | { |
---|
1927 | perror("open"); |
---|
1928 | exit(1); |
---|
1929 | } |
---|
1930 | |
---|
1931 | LIBXML_TEST_VERSION; |
---|
1932 | |
---|
1933 | int status; |
---|
1934 | xmlTextReaderPtr reader = xmlReaderForFile ( argv[1], NULL, 0 ); |
---|
1935 | |
---|
1936 | if ( reader != NULL ) |
---|
1937 | { |
---|
1938 | status = xmlTextReaderRead ( reader ); |
---|
1939 | while ( status == 1 ) |
---|
1940 | { |
---|
1941 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
---|
1942 | |
---|
1943 | if ( strcmp(tag,"mapping_info") == 0 ) |
---|
1944 | { |
---|
1945 | headerNode( reader ); |
---|
1946 | prepareBuild(); |
---|
1947 | buildBin( fdout ); |
---|
1948 | } |
---|
1949 | else |
---|
1950 | { |
---|
1951 | printf("[XML ERROR] Wrong file type: \"%s\"\n", argv[1]); |
---|
1952 | return 1; |
---|
1953 | } |
---|
1954 | status = xmlTextReaderRead ( reader ); |
---|
1955 | } |
---|
1956 | xmlFreeTextReader ( reader ); |
---|
1957 | |
---|
1958 | if ( status != 0 ) |
---|
1959 | { |
---|
1960 | printf("[XML ERROR] Wrong Syntax in \"%s\" file\n", argv[1]); |
---|
1961 | return 1; |
---|
1962 | } |
---|
1963 | } |
---|
1964 | return 0; |
---|
1965 | } // end main() |
---|