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