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 memory 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 parser 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 | // for replicated peripheral |
---|
99 | ////////////////////////////// |
---|
100 | char found_timer = 0; |
---|
101 | char found_icu = 0; |
---|
102 | char found_xcu = 0; |
---|
103 | char found_dma = 0; |
---|
104 | char found_mmc = 0; |
---|
105 | |
---|
106 | |
---|
107 | //////////////////////////////////////////////////////////////////// |
---|
108 | // These variables are used to generate the hard_config.h file |
---|
109 | //////////////////////////////////////////////////////////////////// |
---|
110 | |
---|
111 | unsigned int nb_proc_max = 0; // max number of processors per cluster |
---|
112 | unsigned int nb_tasks_max = 0; // max number of tasks (in all vspaces) |
---|
113 | |
---|
114 | unsigned int tim_channels = 0; // max number of user timers (per cluster) |
---|
115 | unsigned int dma_channels = 0; // max number of DMA channels (per cluster) |
---|
116 | |
---|
117 | unsigned int icu_channels = 0; // total number of channels in ICU/XICU |
---|
118 | unsigned int tty_channels = 0; // total number of terminals in TTY |
---|
119 | unsigned int hba_channels = 0; // total number of channels in HBA |
---|
120 | unsigned int nic_channels = 0; // total number of channels in NIC |
---|
121 | unsigned int cma_channels = 0; // total number of channels in CMA |
---|
122 | |
---|
123 | unsigned int use_iob = 0; // using IOB component |
---|
124 | unsigned int use_xcu = 0; // using XCU (not ICU) |
---|
125 | |
---|
126 | // These variables define the IOC peripheral subtype |
---|
127 | unsigned int use_hba = 0; // using HBA |
---|
128 | unsigned int use_bdv = 0; // using SoCLIB block device |
---|
129 | unsigned int use_spi = 0; // using SD Card-SPI |
---|
130 | |
---|
131 | //////////////////////////////////////////////////////////////// |
---|
132 | // These variables are used to generate the giet_vseg.ld file |
---|
133 | //////////////////////////////////////////////////////////////// |
---|
134 | |
---|
135 | unsigned int periph_vbase_array[PERIPH_TYPE_MAX_VALUE] |
---|
136 | = { [0 ... (PERIPH_TYPE_MAX_VALUE - 1)] = 0xFFFFFFFF }; |
---|
137 | |
---|
138 | ////////////////////////////////////////////////////////////////////// |
---|
139 | // This arrray is useful to build a temporary list of vobj references. |
---|
140 | // The struct vobj_ref_s is formed by a vspace_name and a vobj_name. |
---|
141 | // This array is used to set the attribute vobj_id of a cp_port |
---|
142 | // once all the vspace have been parsed. |
---|
143 | ///////////////////////////////////////////////////////////////////// |
---|
144 | typedef struct vobj_ref_s |
---|
145 | { |
---|
146 | char vspace_name[32]; |
---|
147 | char vobj_name[32]; |
---|
148 | } vobj_ref_t; |
---|
149 | |
---|
150 | vobj_ref_t * cp_port_vobj_ref[MAX_CP_PORTS]; |
---|
151 | |
---|
152 | |
---|
153 | ////////////////////////////////////////////////// |
---|
154 | unsigned int getIntValue( xmlTextReaderPtr reader, |
---|
155 | const char * attributeName, |
---|
156 | unsigned int * ok) |
---|
157 | { |
---|
158 | unsigned int value = 0; |
---|
159 | unsigned int i; |
---|
160 | char c; |
---|
161 | |
---|
162 | char * string = (char *) xmlTextReaderGetAttribute(reader, |
---|
163 | (const xmlChar *) attributeName); |
---|
164 | |
---|
165 | if (string == NULL) |
---|
166 | { |
---|
167 | // missing argument |
---|
168 | *ok = 0; |
---|
169 | return 0; |
---|
170 | } |
---|
171 | else |
---|
172 | { |
---|
173 | if ((string[0] == '0') && ((string[1] == 'x') || (string[1] == 'X'))) |
---|
174 | { |
---|
175 | // Hexa |
---|
176 | for (i = 2 ; (string[i] != 0) && (i < 10) ; i++) |
---|
177 | { |
---|
178 | c = string[i]; |
---|
179 | if ((c >= '0') && (c <= '9')) { value = (value << 4) + string[i] - 48; } |
---|
180 | else if ((c >= 'a') && (c <= 'f')) { value = (value << 4) + string[i] - 87; } |
---|
181 | else if ((c >= 'A') && (c <= 'F')) { value = (value << 4) + string[i] - 55; } |
---|
182 | else |
---|
183 | { |
---|
184 | *ok = 0; |
---|
185 | return 0; |
---|
186 | } |
---|
187 | } |
---|
188 | } |
---|
189 | else |
---|
190 | { |
---|
191 | // Decimal |
---|
192 | for (i = 0; (string[i] != 0) && (i < 9); i++) |
---|
193 | { |
---|
194 | c = string[i]; |
---|
195 | if ((c >= '0') && (c <= '9')) value = (value * 10) + string[i] - 48; |
---|
196 | else |
---|
197 | { |
---|
198 | *ok = 0; |
---|
199 | return 0; |
---|
200 | } |
---|
201 | } |
---|
202 | } |
---|
203 | *ok = 1; |
---|
204 | return value; |
---|
205 | } |
---|
206 | } // end getIntValue() |
---|
207 | |
---|
208 | //////////////////////////////////////////////// |
---|
209 | paddr_t getPaddrValue( xmlTextReaderPtr reader, |
---|
210 | const char * attributeName, |
---|
211 | unsigned int * ok) |
---|
212 | { |
---|
213 | paddr_t value = 0; |
---|
214 | unsigned int i; |
---|
215 | char c; |
---|
216 | |
---|
217 | char * string = (char *) xmlTextReaderGetAttribute(reader, |
---|
218 | (const xmlChar *) attributeName); |
---|
219 | |
---|
220 | if (string == NULL) |
---|
221 | { |
---|
222 | // missing argument |
---|
223 | *ok = 0; |
---|
224 | return 0; |
---|
225 | } |
---|
226 | else |
---|
227 | { |
---|
228 | if ((string[0] == '0') && ((string[1] == 'x') || (string[1] == 'X'))) |
---|
229 | { |
---|
230 | // Hexa |
---|
231 | for (i = 2 ; (string[i] != 0) && (i < 18) ; i++) |
---|
232 | { |
---|
233 | c = string[i]; |
---|
234 | if ((c >= '0') && (c <= '9')) { value = (value << 4) + string[i] - 48; } |
---|
235 | else if ((c >= 'a') && (c <= 'f')) { value = (value << 4) + string[i] - 87; } |
---|
236 | else if ((c >= 'A') && (c <= 'F')) { value = (value << 4) + string[i] - 55; } |
---|
237 | else |
---|
238 | { |
---|
239 | *ok = 0; |
---|
240 | return 0; |
---|
241 | } |
---|
242 | } |
---|
243 | } |
---|
244 | else |
---|
245 | { |
---|
246 | // Decimal not supported for paddr_t |
---|
247 | *ok = 0; |
---|
248 | return 0; |
---|
249 | } |
---|
250 | *ok = 1; |
---|
251 | return value; |
---|
252 | } |
---|
253 | } // end getPaddrValue() |
---|
254 | |
---|
255 | //////////////////////////////////////////////// |
---|
256 | char * getStringValue( xmlTextReaderPtr reader, |
---|
257 | const char * attributeName, |
---|
258 | unsigned int * ok ) |
---|
259 | { |
---|
260 | char * string = (char *) xmlTextReaderGetAttribute(reader, |
---|
261 | (const xmlChar *) attributeName); |
---|
262 | |
---|
263 | |
---|
264 | if (string == NULL) |
---|
265 | { |
---|
266 | // missing argument |
---|
267 | *ok = 0; |
---|
268 | return NULL; |
---|
269 | } |
---|
270 | else |
---|
271 | { |
---|
272 | //we read only string smaller than 32 byte |
---|
273 | if (strlen(string) > 32) |
---|
274 | { |
---|
275 | printf("[XML ERROR] all strings must be less than 32 bytes\n"); |
---|
276 | exit(1); |
---|
277 | } |
---|
278 | |
---|
279 | *ok = 1; |
---|
280 | return string; |
---|
281 | } |
---|
282 | } // end getStringValue() |
---|
283 | |
---|
284 | /////////////////////////////////////////////////////////////////////////////////// |
---|
285 | // This function set the vbase address for all peripheral types. |
---|
286 | // For replicated peripherals with the same type the virtual base address must be: |
---|
287 | // vbase = seg_type_base & 0XFF000000 + |
---|
288 | // (cluster_id * vbase_cluster_increment) & 0x00FF0000 |
---|
289 | /////////////////////////////////////////////////////////////////////////////////// |
---|
290 | void set_periph_vbase_array() |
---|
291 | { |
---|
292 | unsigned int vseg_id; // vseg global index |
---|
293 | unsigned int periph_id; // periph global index |
---|
294 | unsigned int pseg_id; // pseg global index |
---|
295 | unsigned int cluster_id; // cluster linear index |
---|
296 | unsigned int cluster_xy; // cluster topological index |
---|
297 | unsigned int type; // peripheral type |
---|
298 | |
---|
299 | unsigned int type_mask = 0xFF000000; |
---|
300 | unsigned int cluster_mask = 0x00FF0000; |
---|
301 | |
---|
302 | // We are analysing all vsegs corresponding to a peripheral |
---|
303 | |
---|
304 | // scan all vsegs |
---|
305 | for (vseg_id = 0 ; vseg_id < header->vsegs ; vseg_id++) |
---|
306 | { |
---|
307 | // keep only vseg corresponding to a periph |
---|
308 | if ( vobj[vseg[vseg_id]->vobj_offset]->type == VOBJ_TYPE_PERI ) |
---|
309 | { |
---|
310 | pseg_id = vseg[vseg_id]->psegid; |
---|
311 | |
---|
312 | // scan all periphs to retrieve peripheral type (same psegid) |
---|
313 | for ( periph_id = 0 ; periph_id < header->periphs ; periph_id++) |
---|
314 | { |
---|
315 | if( periph[periph_id]->psegid == pseg_id ) // matching !!! |
---|
316 | { |
---|
317 | type = periph[periph_id]->type; |
---|
318 | if ( periph_vbase_array[type] == 0xFFFFFFFF ) // vbase not set |
---|
319 | { |
---|
320 | periph_vbase_array[type] = vseg[vseg_id]->vbase & type_mask; |
---|
321 | } |
---|
322 | else // vbase already set |
---|
323 | { |
---|
324 | // checking mask bits |
---|
325 | if( (vseg[vseg_id]->vbase & type_mask) != |
---|
326 | (periph_vbase_array[type]) ) |
---|
327 | { |
---|
328 | printf("[XML ERROR] All peripherals with same type "); |
---|
329 | printf(" should share the same 8 MSB bits in base address\n"); |
---|
330 | printf("periph index = %d / periph type = %d / vbase = %x\n", |
---|
331 | periph_id, type, vseg[vseg_id]->vbase); |
---|
332 | exit(1); |
---|
333 | } |
---|
334 | } |
---|
335 | |
---|
336 | // checking cluster bits for all replicated peripherals |
---|
337 | if ( (type == PERIPH_TYPE_DMA) || |
---|
338 | (type == PERIPH_TYPE_MMC) || |
---|
339 | (type == PERIPH_TYPE_ICU) || |
---|
340 | (type == PERIPH_TYPE_XCU) || |
---|
341 | (type == PERIPH_TYPE_TIM) ) |
---|
342 | { |
---|
343 | cluster_id = pseg[pseg_id]->clusterid; |
---|
344 | cluster_xy = (cluster[cluster_id]->x << header->y_width) + |
---|
345 | cluster[cluster_id]->y; |
---|
346 | |
---|
347 | if( (vseg[vseg_id]->vbase & cluster_mask) != |
---|
348 | (header->increment * cluster_xy) ) |
---|
349 | { |
---|
350 | printf("[XML ERROR] All replicated peripherals "); |
---|
351 | printf("must have cluster bits = cluster_id * increment"); |
---|
352 | printf("periph index = %d / periph type = %d / vbase = %x\n", |
---|
353 | periph_id, type, vseg[vseg_id]->vbase); |
---|
354 | exit(1); |
---|
355 | } |
---|
356 | } |
---|
357 | } |
---|
358 | } |
---|
359 | } |
---|
360 | } |
---|
361 | } // end set_periph_vbase_array() |
---|
362 | |
---|
363 | /////////////////////////////////////////////////////////////// |
---|
364 | int getClusterId( unsigned int x, unsigned int y ) |
---|
365 | { |
---|
366 | // associative search of cluster index |
---|
367 | unsigned int cluster_id; |
---|
368 | |
---|
369 | for( cluster_id = 0 ; cluster_id < (header->x_size * header->y_size) ; cluster_id++ ) |
---|
370 | { |
---|
371 | if( (cluster[cluster_id]->x == x) && (cluster[cluster_id]->y == y) ) |
---|
372 | { |
---|
373 | return cluster_id; |
---|
374 | } |
---|
375 | } |
---|
376 | return -1; |
---|
377 | } // end getClusterId() |
---|
378 | |
---|
379 | /////////////////////////////////////////////////////////////// |
---|
380 | int getPsegId(unsigned int x, unsigned int y, char * pseg_name) |
---|
381 | { |
---|
382 | int cluster_id = getClusterId( x, y ); |
---|
383 | |
---|
384 | if ( cluster_id == -1 ) return -1; |
---|
385 | |
---|
386 | // associative search for pseg index |
---|
387 | unsigned int pseg_id; |
---|
388 | unsigned int pseg_min = cluster[cluster_id]->pseg_offset; |
---|
389 | unsigned int pseg_max = pseg_min + cluster[cluster_id]->psegs; |
---|
390 | |
---|
391 | for (pseg_id = pseg_min; pseg_id < pseg_max; pseg_id++) |
---|
392 | { |
---|
393 | if (strcmp(pseg[pseg_id]->name, pseg_name) == 0) |
---|
394 | { |
---|
395 | return pseg_id; |
---|
396 | } |
---|
397 | } |
---|
398 | return -1; |
---|
399 | } // end getPsegId() |
---|
400 | |
---|
401 | /////////////////////////////////// |
---|
402 | int getVspaceId(char * vspace_name) |
---|
403 | { |
---|
404 | unsigned int vspace_id; |
---|
405 | |
---|
406 | for (vspace_id = 0; vspace_id < vspace_index; vspace_id++) |
---|
407 | { |
---|
408 | if (strcmp(vspace[vspace_id]->name, vspace_name) == 0) |
---|
409 | { |
---|
410 | return vspace_id; |
---|
411 | } |
---|
412 | } |
---|
413 | return -1; |
---|
414 | } |
---|
415 | |
---|
416 | /////////////////////////////////////////////////////////////////////////////////// |
---|
417 | int getVobjLocId(unsigned int vspace_id, char * vobj_name, unsigned int vspace_max) |
---|
418 | { |
---|
419 | unsigned int vobj_id; |
---|
420 | unsigned int vobj_min = vspace[vspace_id]->vobj_offset; |
---|
421 | unsigned int vobj_max = vobj_min + vspace_max; |
---|
422 | |
---|
423 | for (vobj_id = vobj_min; vobj_id < vobj_max; vobj_id++) |
---|
424 | { |
---|
425 | if (strcmp(vobj[vobj_id]->name, vobj_name) == 0) return (vobj_id - vobj_min); |
---|
426 | } |
---|
427 | return -1; |
---|
428 | } |
---|
429 | |
---|
430 | ////////////////////////////////////// |
---|
431 | void taskNode(xmlTextReaderPtr reader) |
---|
432 | { |
---|
433 | unsigned int ok; |
---|
434 | unsigned int value; |
---|
435 | unsigned int x,y; |
---|
436 | char * str; |
---|
437 | |
---|
438 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
439 | |
---|
440 | if (task_index >= MAX_TASKS) |
---|
441 | { |
---|
442 | printf("[XML ERROR] The number of tasks is larger than %d\n", MAX_TASKS); |
---|
443 | exit(1); |
---|
444 | } |
---|
445 | |
---|
446 | #if XML_PARSER_DEBUG |
---|
447 | printf(" task %d\n", task_loc_index); |
---|
448 | #endif |
---|
449 | |
---|
450 | task[task_index] = (mapping_task_t *) malloc(sizeof(mapping_task_t)); |
---|
451 | |
---|
452 | ////////// get name attribute |
---|
453 | str = getStringValue(reader, "name", &ok); |
---|
454 | if (ok) |
---|
455 | { |
---|
456 | #if XML_PARSER_DEBUG |
---|
457 | printf(" name = %s\n", str); |
---|
458 | #endif |
---|
459 | strncpy( task[task_index]->name, str, 31 ); |
---|
460 | } |
---|
461 | else |
---|
462 | { |
---|
463 | printf("[XML ERROR] illegal or missing <name> attribute for task (%d,%d)\n", |
---|
464 | vspace_index, task_loc_index); |
---|
465 | exit(1); |
---|
466 | } |
---|
467 | |
---|
468 | ///////// get x coordinate |
---|
469 | task[task_index]->trdid = getIntValue(reader, "trdid", &ok); |
---|
470 | #if XML_PARSER_DEBUG |
---|
471 | printf(" x = %d\n", x); |
---|
472 | #endif |
---|
473 | if ( !ok ) |
---|
474 | { |
---|
475 | task[task_index]->trdid = task_loc_index; |
---|
476 | printf("[XML WARNING] missing trdid (thread index) attribute " |
---|
477 | "for task in vspace %d. Using value %d\n" |
---|
478 | , vspace_index, task_loc_index); |
---|
479 | } |
---|
480 | |
---|
481 | ///////// get x coordinate |
---|
482 | x = getIntValue(reader, "x", &ok); |
---|
483 | #if XML_PARSER_DEBUG |
---|
484 | printf(" x = %d\n", x); |
---|
485 | #endif |
---|
486 | if ( !(ok && (x < header->x_size)) ) |
---|
487 | { |
---|
488 | printf("[XML ERROR] illegal or missing < x > attribute for task (%d,%d)\n", |
---|
489 | vspace_index, task_loc_index); |
---|
490 | exit(1); |
---|
491 | } |
---|
492 | |
---|
493 | ///////// get y coordinate |
---|
494 | y = getIntValue(reader, "y", &ok); |
---|
495 | #if XML_PARSER_DEBUG |
---|
496 | printf(" y = %d\n", y); |
---|
497 | #endif |
---|
498 | if ( !(ok && (y < header->y_size)) ) |
---|
499 | { |
---|
500 | printf("[XML ERROR] illegal or missing < y > attribute for task (%d,%d)\n", |
---|
501 | vspace_index, task_loc_index); |
---|
502 | exit(1); |
---|
503 | } |
---|
504 | |
---|
505 | ///////// set clusterid attribute |
---|
506 | int index = getClusterId( x, y ); |
---|
507 | #if XML_PARSER_DEBUG |
---|
508 | printf(" clusterid = %d\n", index); |
---|
509 | #endif |
---|
510 | if( index >= 0 ) |
---|
511 | { |
---|
512 | task[task_index]->clusterid = index; |
---|
513 | } |
---|
514 | else |
---|
515 | { |
---|
516 | printf("[XML ERROR] <clusterid> not found for task (%d,%d)\n", |
---|
517 | vspace_index, task_loc_index); |
---|
518 | exit(1); |
---|
519 | } |
---|
520 | |
---|
521 | ////////// get proclocid attribute |
---|
522 | value = getIntValue(reader, "proclocid", &ok); |
---|
523 | if (ok) |
---|
524 | { |
---|
525 | #if XML_PARSER_DEBUG |
---|
526 | printf(" proclocid = %x\n", value); |
---|
527 | #endif |
---|
528 | if (value >= cluster[task[task_index]->clusterid]->procs) |
---|
529 | { |
---|
530 | printf("[XML ERROR] <proclocid> too large for task (%d,%d)\n", |
---|
531 | vspace_index, task_loc_index); |
---|
532 | exit(1); |
---|
533 | } |
---|
534 | task[task_index]->proclocid = value; |
---|
535 | } |
---|
536 | else |
---|
537 | { |
---|
538 | printf("[XML ERROR] illegal or missing <locprocid> attribute for task (%d,%d)\n", |
---|
539 | vspace_index, task_loc_index); |
---|
540 | exit(1); |
---|
541 | } |
---|
542 | |
---|
543 | ////////// get stackname attribute |
---|
544 | str = getStringValue(reader, "stackname" , &ok); |
---|
545 | if (ok) |
---|
546 | { |
---|
547 | int index = getVobjLocId(vspace_index, str , vobj_loc_index); |
---|
548 | if (index >= 0) |
---|
549 | { |
---|
550 | #if XML_PARSER_DEBUG |
---|
551 | printf(" stackname = %s\n", str); |
---|
552 | printf(" stackid = %d\n", index); |
---|
553 | #endif |
---|
554 | task[task_index]->stack_vobjid = index; |
---|
555 | } |
---|
556 | else |
---|
557 | { |
---|
558 | printf("[XML ERROR] illegal or missing <stackname> for task (%d,%d)\n", |
---|
559 | vspace_index, task_loc_index); |
---|
560 | exit(1); |
---|
561 | } |
---|
562 | } |
---|
563 | else |
---|
564 | { |
---|
565 | printf("[XML ERROR] illegal or missing <stackname> for task (%d,%d)\n", |
---|
566 | vspace_index, task_loc_index); |
---|
567 | exit(1); |
---|
568 | } |
---|
569 | |
---|
570 | ////////// get heap attribute |
---|
571 | str = getStringValue(reader, "heapname", &ok); |
---|
572 | if (ok) |
---|
573 | { |
---|
574 | int index = getVobjLocId(vspace_index, str, vobj_loc_index); |
---|
575 | if (index >= 0) |
---|
576 | { |
---|
577 | #if XML_PARSER_DEBUG |
---|
578 | printf(" heapname = %s\n", str); |
---|
579 | printf(" heapid = %d\n", index); |
---|
580 | #endif |
---|
581 | task[task_index]->heap_vobjid = index; |
---|
582 | } |
---|
583 | else |
---|
584 | { |
---|
585 | printf("[XML ERROR] illegal or missing <heapname> for task (%d,%d)\n", |
---|
586 | vspace_index, task_loc_index); |
---|
587 | exit(1); |
---|
588 | } |
---|
589 | } |
---|
590 | else |
---|
591 | { |
---|
592 | task[task_index]->heap_vobjid = -1; |
---|
593 | } |
---|
594 | |
---|
595 | ////////// get startid attribute |
---|
596 | value = getIntValue(reader, "startid", &ok); |
---|
597 | if (ok) |
---|
598 | { |
---|
599 | #if XML_PARSER_DEBUG |
---|
600 | printf(" startid = %x\n", value); |
---|
601 | #endif |
---|
602 | task[task_index]->startid = value; |
---|
603 | } |
---|
604 | else |
---|
605 | { |
---|
606 | printf("[XML ERROR] illegal or missing <startid> attribute for task (%d,%d)\n", |
---|
607 | vspace_index, task_loc_index); |
---|
608 | exit(1); |
---|
609 | } |
---|
610 | |
---|
611 | /////////// get use_tty attribute (optionnal : 0 if missing) |
---|
612 | value = getIntValue(reader, "usetty", &ok); |
---|
613 | #if XML_PARSER_DEBUG |
---|
614 | printf(" usetty = %x\n", value); |
---|
615 | #endif |
---|
616 | task[task_index]->use_tty = (ok)? value : 0; |
---|
617 | |
---|
618 | /////////// get use_nic attribute (optionnal : 0 if missing) |
---|
619 | value = getIntValue(reader, "usenic", &ok); |
---|
620 | #if XML_PARSER_DEBUG |
---|
621 | printf(" usenic = %x\n", value); |
---|
622 | #endif |
---|
623 | task[task_index]->use_nic = (ok)? value : 0; |
---|
624 | |
---|
625 | /////////// get use_tim attribute (optionnal : 0 if missing) |
---|
626 | value = getIntValue(reader, "usetim", &ok); |
---|
627 | #if XML_PARSER_DEBUG |
---|
628 | printf(" usetim = %x\n", value); |
---|
629 | #endif |
---|
630 | task[task_index]->use_tim = (ok)? value : 0; |
---|
631 | |
---|
632 | /////////// get use_hba attribute (optionnal : 0 if missing) |
---|
633 | value = getIntValue(reader, "usehba", &ok); |
---|
634 | #if XML_PARSER_DEBUG |
---|
635 | printf(" usehba = %x\n", value); |
---|
636 | #endif |
---|
637 | task[task_index]->use_hba = (ok)? value : 0; |
---|
638 | |
---|
639 | /////////// get usecma attribute (optionnal : 0 if missing) |
---|
640 | value = getIntValue(reader, "usecma", &ok); |
---|
641 | #if XML_PARSER_DEBUG |
---|
642 | printf(" usecma = %x\n", value); |
---|
643 | #endif |
---|
644 | task[task_index]->use_cma = (ok)? value : 0; |
---|
645 | |
---|
646 | task_index++; |
---|
647 | task_loc_index++; |
---|
648 | } // end taskNode() |
---|
649 | |
---|
650 | ////////////////////////////////////// |
---|
651 | void vobjNode(xmlTextReaderPtr reader) |
---|
652 | { |
---|
653 | unsigned int ok; |
---|
654 | unsigned int value; |
---|
655 | char * str; |
---|
656 | |
---|
657 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
658 | |
---|
659 | if (vobj_index >= MAX_VOBJS) |
---|
660 | { |
---|
661 | printf("[XML ERROR] The number of vobjs is larger than %d\n", MAX_VOBJS); |
---|
662 | exit(1); |
---|
663 | } |
---|
664 | |
---|
665 | #if XML_PARSER_DEBUG |
---|
666 | printf(" vobj %d\n", vobj_loc_index); |
---|
667 | #endif |
---|
668 | |
---|
669 | vobj[vobj_index] = (mapping_vobj_t *) malloc(sizeof(mapping_vobj_t)); |
---|
670 | |
---|
671 | ///////// get name attribute |
---|
672 | str = getStringValue(reader, "name", &ok); |
---|
673 | if (ok) |
---|
674 | { |
---|
675 | #if XML_PARSER_DEBUG |
---|
676 | printf(" name = %s\n", str); |
---|
677 | #endif |
---|
678 | strncpy(vobj[vobj_index]->name, str, 31); |
---|
679 | } |
---|
680 | else |
---|
681 | { |
---|
682 | printf("[XML ERROR] illegal or missing <name> attribute for vobj (%d,%d)\n", |
---|
683 | vseg_index, vobj_loc_index); |
---|
684 | exit(1); |
---|
685 | } |
---|
686 | |
---|
687 | //////// get type attribute |
---|
688 | str = getStringValue(reader, "type", &ok); |
---|
689 | #if XML_PARSER_DEBUG |
---|
690 | printf(" type = %s\n", str); |
---|
691 | #endif |
---|
692 | |
---|
693 | if (ok && (strcmp(str, "ELF") == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_ELF; } |
---|
694 | else if (ok && (strcmp(str, "PERI") == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_PERI; } |
---|
695 | else if (ok && (strcmp(str, "BLOB") == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_BLOB; } |
---|
696 | else if (ok && (strcmp(str, "PTAB") == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_PTAB; } |
---|
697 | else if (ok && (strcmp(str, "MWMR") == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_MWMR; } |
---|
698 | else if (ok && (strcmp(str, "LOCK") == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_LOCK; } |
---|
699 | else if (ok && (strcmp(str, "BUFFER") == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_BUFFER; } |
---|
700 | else if (ok && (strcmp(str, "BARRIER") == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_BARRIER; } |
---|
701 | else if (ok && (strcmp(str, "CONST") == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_CONST; } |
---|
702 | else if (ok && (strcmp(str, "MEMSPACE") == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_MEMSPACE; } |
---|
703 | else if (ok && (strcmp(str, "SCHED") == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_SCHED; } |
---|
704 | else if (ok && (strcmp(str, "BOOT") == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_BOOT; } |
---|
705 | else |
---|
706 | { |
---|
707 | printf("[XML ERROR] illegal or missing <type> attribute for vobj (%d,%d)\n", |
---|
708 | vspace_index, vobj_loc_index); |
---|
709 | exit(1); |
---|
710 | } |
---|
711 | // some more checking |
---|
712 | if ( (vobj[vobj_index]->type == VOBJ_TYPE_ELF) || |
---|
713 | (vobj[vobj_index]->type == VOBJ_TYPE_PERI) ) |
---|
714 | { |
---|
715 | assert( (vobj_count == 0) && |
---|
716 | "[XML ERROR] an ELF or PERI vobj must be alone in a vseg"); |
---|
717 | } |
---|
718 | |
---|
719 | |
---|
720 | ////////// get length attribute |
---|
721 | value = getIntValue(reader, "length", &ok); |
---|
722 | if (ok) { |
---|
723 | #if XML_PARSER_DEBUG |
---|
724 | printf(" length = %d\n", value); |
---|
725 | #endif |
---|
726 | vobj[vobj_index]->length = value; |
---|
727 | } |
---|
728 | else { |
---|
729 | printf("[XML ERROR] illegal or missing <length> attribute for vobj (%d,%d)\n", |
---|
730 | vspace_index, vobj_loc_index); |
---|
731 | exit(1); |
---|
732 | } |
---|
733 | |
---|
734 | ////////// get align attribute (optional : 0 if missing) |
---|
735 | value = getIntValue(reader, "align", &ok); |
---|
736 | if (ok) { |
---|
737 | #if XML_PARSER_DEBUG |
---|
738 | printf(" align = %d\n", value); |
---|
739 | #endif |
---|
740 | vobj[vobj_index]->align = value; |
---|
741 | } |
---|
742 | else { |
---|
743 | vobj[vobj_index]->align = 0; |
---|
744 | } |
---|
745 | |
---|
746 | ////////// get binpath attribute (optional : '\0' if missing) |
---|
747 | str = getStringValue(reader, "binpath", &ok); |
---|
748 | if (ok) { |
---|
749 | #if XML_PARSER_DEBUG |
---|
750 | printf(" binpath = %s\n", str); |
---|
751 | #endif |
---|
752 | strncpy(vobj[vobj_index]->binpath, str, 63); |
---|
753 | } |
---|
754 | else { |
---|
755 | vobj[vobj_index]->binpath[0] = '\0'; |
---|
756 | } |
---|
757 | |
---|
758 | ////////// get init attribute (mandatory for mwmr and barrier) |
---|
759 | value = getIntValue(reader, "init", &ok); |
---|
760 | if (ok) |
---|
761 | { |
---|
762 | #if XML_PARSER_DEBUG |
---|
763 | printf(" init = %d\n", value); |
---|
764 | #endif |
---|
765 | vobj[vobj_index]->init = value; |
---|
766 | } |
---|
767 | else |
---|
768 | { |
---|
769 | if ((vobj[vobj_index]->type == VOBJ_TYPE_MWMR) || |
---|
770 | (vobj[vobj_index]->type == VOBJ_TYPE_BARRIER) || |
---|
771 | (vobj[vobj_index]->type == VOBJ_TYPE_CONST)) |
---|
772 | { |
---|
773 | printf("[XML ERROR] illegal or missing <value> attribute for vobj (%d,%d). \ |
---|
774 | All MWMR or BARRIER or CONST vobj must have a init value \n", |
---|
775 | vspace_index, vobj_loc_index); |
---|
776 | exit(1); |
---|
777 | } |
---|
778 | vobj[vobj_index]->init = 0; |
---|
779 | } |
---|
780 | |
---|
781 | vobj_index++; |
---|
782 | vobj_count++; |
---|
783 | vobj_loc_index++; |
---|
784 | } // end vobjNode() |
---|
785 | |
---|
786 | ////////////////////////////////////// |
---|
787 | void vsegNode(xmlTextReaderPtr reader) |
---|
788 | { |
---|
789 | unsigned int ok; |
---|
790 | unsigned int value; |
---|
791 | unsigned int x,y; |
---|
792 | char * str; |
---|
793 | |
---|
794 | vobj_count = 0; |
---|
795 | |
---|
796 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
797 | |
---|
798 | if (vseg_index >= MAX_VSEGS) |
---|
799 | { |
---|
800 | printf("[XML ERROR] The number of vsegs is larger than %d\n", MAX_VSEGS); |
---|
801 | exit(1); |
---|
802 | } |
---|
803 | |
---|
804 | #if XML_PARSER_DEBUG |
---|
805 | printf(" vseg %d\n", vseg_loc_index); |
---|
806 | #endif |
---|
807 | |
---|
808 | vseg[vseg_index] = (mapping_vseg_t *) malloc(sizeof(mapping_vseg_t)); |
---|
809 | |
---|
810 | ////////// set vobj_offset attributes |
---|
811 | vseg[vseg_index]->vobj_offset = vobj_index; |
---|
812 | |
---|
813 | #if XML_PARSER_DEBUG |
---|
814 | printf(" vobj_offset = %d\n", vobj_index); |
---|
815 | #endif |
---|
816 | |
---|
817 | ///////// set mapped attribute |
---|
818 | vseg[vseg_index]->mapped = 0; |
---|
819 | |
---|
820 | //////// set next_vseg attribute |
---|
821 | vseg[vseg_index]->next_vseg = 0; |
---|
822 | |
---|
823 | ///////// get name attribute |
---|
824 | str = getStringValue(reader, "name", &ok); |
---|
825 | if (ok) |
---|
826 | { |
---|
827 | #if XML_PARSER_DEBUG |
---|
828 | printf(" name = %s\n", str); |
---|
829 | #endif |
---|
830 | strncpy( vseg[vseg_index]->name, str, 31); |
---|
831 | } |
---|
832 | else |
---|
833 | { |
---|
834 | printf("[XML ERROR] illegal or missing <name> attribute for vseg (%d,%d)\n", |
---|
835 | vspace_index, vseg_loc_index); |
---|
836 | exit(1); |
---|
837 | } |
---|
838 | |
---|
839 | ////////// get ident attribute (optional : 0 if missing) |
---|
840 | value = getIntValue(reader, "ident", &ok); |
---|
841 | if (ok) |
---|
842 | { |
---|
843 | #if XML_PARSER_DEBUG |
---|
844 | printf(" ident = %d\n", value); |
---|
845 | #endif |
---|
846 | vseg[vseg_index]->ident = value; |
---|
847 | } |
---|
848 | else |
---|
849 | { |
---|
850 | vseg[vseg_index]->ident = 0; |
---|
851 | } |
---|
852 | |
---|
853 | /////////// get vbase attribute |
---|
854 | value = getIntValue(reader, "vbase", &ok); |
---|
855 | if (ok) |
---|
856 | { |
---|
857 | #if XML_PARSER_DEBUG |
---|
858 | printf(" vbase = 0x%x\n", value); |
---|
859 | #endif |
---|
860 | vseg[vseg_index]->vbase = value; |
---|
861 | } |
---|
862 | else |
---|
863 | { |
---|
864 | printf("[XML ERROR] illegal or missing <vbase> attribute for vseg (%d,%d)\n", |
---|
865 | vspace_index, vseg_loc_index); |
---|
866 | exit(1); |
---|
867 | } |
---|
868 | |
---|
869 | ////////// get x coordinate |
---|
870 | x = getIntValue(reader, "x", &ok); |
---|
871 | #if XML_PARSER_DEBUG |
---|
872 | printf(" x = %d\n", x); |
---|
873 | #endif |
---|
874 | if ( !(ok && (x < header->x_size)) ) |
---|
875 | { |
---|
876 | printf("[XML ERROR] illegal or missing < x > attribute for vseg %d\n", |
---|
877 | vseg_loc_index); |
---|
878 | exit(1); |
---|
879 | } |
---|
880 | |
---|
881 | ////////// get y coordinate |
---|
882 | y = getIntValue(reader, "y", &ok); |
---|
883 | #if XML_PARSER_DEBUG |
---|
884 | printf(" y = %d\n", y); |
---|
885 | #endif |
---|
886 | if ( !(ok && (y < header->y_size)) ) |
---|
887 | { |
---|
888 | printf("[XML ERROR] illegal or missing < y > attribute for vseg %d\n", |
---|
889 | vseg_loc_index); |
---|
890 | exit(1); |
---|
891 | } |
---|
892 | |
---|
893 | ///////// get psegname attribute |
---|
894 | str = getStringValue(reader, "psegname", &ok); |
---|
895 | #if XML_PARSER_DEBUG |
---|
896 | printf(" psegname = %s\n", str); |
---|
897 | #endif |
---|
898 | if (ok == 0) |
---|
899 | { |
---|
900 | printf("[XML ERROR] illegal or missing <psegname> for vseg %d\n", |
---|
901 | vseg_loc_index); |
---|
902 | exit(1); |
---|
903 | } |
---|
904 | |
---|
905 | /////////// set psegid field |
---|
906 | int psegid = getPsegId( x, y, str ); |
---|
907 | #if XML_PARSER_DEBUG |
---|
908 | printf(" psegid = %d\n", psegid); |
---|
909 | #endif |
---|
910 | if (index >= 0) |
---|
911 | { |
---|
912 | vseg[vseg_index]->psegid = psegid; |
---|
913 | } |
---|
914 | else |
---|
915 | { |
---|
916 | printf("[XML ERROR] pseg not found for vseg %d / x = %d / y = %d / psegname = %s\n", |
---|
917 | vseg_loc_index, x, y, str ); |
---|
918 | exit(1); |
---|
919 | } |
---|
920 | |
---|
921 | //////// get mode attribute |
---|
922 | str = getStringValue(reader, "mode", &ok); |
---|
923 | #if XML_PARSER_DEBUG |
---|
924 | printf(" mode = %s\n", str); |
---|
925 | #endif |
---|
926 | if (ok && (strcmp(str, "CXWU") == 0)) { vseg[vseg_index]->mode = 0xF; } |
---|
927 | else if (ok && (strcmp(str, "CXW_") == 0)) { vseg[vseg_index]->mode = 0xE; } |
---|
928 | else if (ok && (strcmp(str, "CX_U") == 0)) { vseg[vseg_index]->mode = 0xD; } |
---|
929 | else if (ok && (strcmp(str, "CX__") == 0)) { vseg[vseg_index]->mode = 0xC; } |
---|
930 | else if (ok && (strcmp(str, "C_WU") == 0)) { vseg[vseg_index]->mode = 0xB; } |
---|
931 | else if (ok && (strcmp(str, "C_W_") == 0)) { vseg[vseg_index]->mode = 0xA; } |
---|
932 | else if (ok && (strcmp(str, "C__U") == 0)) { vseg[vseg_index]->mode = 0x9; } |
---|
933 | else if (ok && (strcmp(str, "C___") == 0)) { vseg[vseg_index]->mode = 0x8; } |
---|
934 | else if (ok && (strcmp(str, "_XWU") == 0)) { vseg[vseg_index]->mode = 0x7; } |
---|
935 | else if (ok && (strcmp(str, "_XW_") == 0)) { vseg[vseg_index]->mode = 0x6; } |
---|
936 | else if (ok && (strcmp(str, "_X_U") == 0)) { vseg[vseg_index]->mode = 0x5; } |
---|
937 | else if (ok && (strcmp(str, "_X__") == 0)) { vseg[vseg_index]->mode = 0x4; } |
---|
938 | else if (ok && (strcmp(str, "__WU") == 0)) { vseg[vseg_index]->mode = 0x3; } |
---|
939 | else if (ok && (strcmp(str, "__W_") == 0)) { vseg[vseg_index]->mode = 0x2; } |
---|
940 | else if (ok && (strcmp(str, "___U") == 0)) { vseg[vseg_index]->mode = 0x1; } |
---|
941 | else if (ok && (strcmp(str, "____") == 0)) { vseg[vseg_index]->mode = 0x0; } |
---|
942 | else { |
---|
943 | printf("[XML ERROR] illegal or missing <mode> attribute for vseg (%d,%d)\n", |
---|
944 | vspace_index, vseg_loc_index); |
---|
945 | exit(1); |
---|
946 | } |
---|
947 | |
---|
948 | ////////// get vobjs in vseg |
---|
949 | int status = xmlTextReaderRead(reader); |
---|
950 | while (status == 1) |
---|
951 | { |
---|
952 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
953 | |
---|
954 | if (strcmp(tag, "vobj") == 0 ) { vobjNode(reader); } |
---|
955 | else if (strcmp(tag, "#text" ) == 0 ) { } |
---|
956 | else if (strcmp(tag, "#comment") == 0 ) { } |
---|
957 | else if (strcmp(tag, "vseg") == 0 ) |
---|
958 | { |
---|
959 | vseg[vseg_index]->vobjs = vobj_count; |
---|
960 | vseg_index++; |
---|
961 | vseg_loc_index++; |
---|
962 | return; |
---|
963 | } |
---|
964 | else |
---|
965 | { |
---|
966 | printf("[XML ERROR] Unknown tag %s", tag); |
---|
967 | exit(1); |
---|
968 | } |
---|
969 | status = xmlTextReaderRead (reader); |
---|
970 | } |
---|
971 | } // end vsegNode() |
---|
972 | |
---|
973 | //////////////////////////////////////// |
---|
974 | void vspaceNode(xmlTextReaderPtr reader) |
---|
975 | { |
---|
976 | char * str; |
---|
977 | unsigned int ok; |
---|
978 | unsigned int nb_task_vspace = 0; |
---|
979 | |
---|
980 | vobj_loc_index = 0; |
---|
981 | vseg_loc_index = 0; |
---|
982 | task_loc_index = 0; |
---|
983 | |
---|
984 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
985 | |
---|
986 | // checking source file consistency |
---|
987 | if (vspace_index >= header->vspaces) { |
---|
988 | printf("[XML ERROR] The vspace index is too large : %d\n", |
---|
989 | vspace_index); |
---|
990 | exit(1); |
---|
991 | } |
---|
992 | |
---|
993 | #if XML_PARSER_DEBUG |
---|
994 | printf("\n vspace %d\n", vspace_index); |
---|
995 | #endif |
---|
996 | |
---|
997 | vspace[vspace_index] = (mapping_vspace_t *) malloc(sizeof(mapping_vspace_t)); |
---|
998 | |
---|
999 | ////////// get name attribute |
---|
1000 | str = getStringValue(reader, "name", &ok); |
---|
1001 | if (ok) { |
---|
1002 | #if XML_PARSER_DEBUG |
---|
1003 | printf(" name = %s\n", str); |
---|
1004 | #endif |
---|
1005 | strncpy(vspace[vspace_index]->name, str, 31); |
---|
1006 | } |
---|
1007 | else |
---|
1008 | { |
---|
1009 | printf("[XML ERROR] illegal or missing <name> attribute for vspace %d\n", |
---|
1010 | vspace_index); |
---|
1011 | exit(1); |
---|
1012 | } |
---|
1013 | |
---|
1014 | ////////// set vseg_offset and task_offset attributes |
---|
1015 | vspace[vspace_index]->vseg_offset = vseg_index; |
---|
1016 | vspace[vspace_index]->vobj_offset = vobj_index; |
---|
1017 | vspace[vspace_index]->task_offset = task_index; |
---|
1018 | |
---|
1019 | #if XML_PARSER_DEBUG |
---|
1020 | printf(" vseg_offset = %d\n", vseg_index); |
---|
1021 | printf(" vobj_offset = %d\n", vobj_index); |
---|
1022 | printf(" task_offset = %d\n", task_index); |
---|
1023 | #endif |
---|
1024 | |
---|
1025 | ////////// get startname attribute |
---|
1026 | str = getStringValue(reader, "startname", &ok); |
---|
1027 | if (ok) { |
---|
1028 | //used after parsing the vobjs |
---|
1029 | } |
---|
1030 | else |
---|
1031 | { |
---|
1032 | printf("[XML ERROR] illegal or missing <startname> attribute for vspace %s\n", |
---|
1033 | vspace[vspace_index]->name); |
---|
1034 | exit(1); |
---|
1035 | } |
---|
1036 | |
---|
1037 | int status = xmlTextReaderRead(reader); |
---|
1038 | while (status == 1) { |
---|
1039 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
1040 | |
---|
1041 | if (strcmp(tag, "vseg") == 0) |
---|
1042 | { |
---|
1043 | vsegNode(reader); |
---|
1044 | } |
---|
1045 | else if (strcmp(tag, "task") == 0) |
---|
1046 | { |
---|
1047 | taskNode(reader); |
---|
1048 | nb_task_vspace++; |
---|
1049 | } |
---|
1050 | else if (strcmp(tag, "#text") == 0) { } |
---|
1051 | else if (strcmp(tag, "#comment") == 0) { } |
---|
1052 | else if (strcmp(tag, "vspace") == 0) { |
---|
1053 | vspace[vspace_index]->vobjs = vobj_loc_index; |
---|
1054 | vspace[vspace_index]->tasks = task_loc_index ; |
---|
1055 | vspace[vspace_index]->vsegs = vseg_loc_index ; |
---|
1056 | |
---|
1057 | // get index of the vobj containing the start vector |
---|
1058 | int index = getVobjLocId(vspace_index, str , vobj_loc_index); |
---|
1059 | if (index == -1) |
---|
1060 | { |
---|
1061 | printf("[XML ERROR] vobj containing start vector not found in vspace %s\n", |
---|
1062 | vspace[vspace_index]->name); |
---|
1063 | exit(1); |
---|
1064 | } |
---|
1065 | else |
---|
1066 | { |
---|
1067 | vspace[vspace_index]->start_offset = index; |
---|
1068 | #if XML_PARSER_DEBUG |
---|
1069 | printf(" startname = %s\n", str); |
---|
1070 | printf(" startid = %d\n", index); |
---|
1071 | printf(" end vspace %d\n\n", vspace_index); |
---|
1072 | #endif |
---|
1073 | } |
---|
1074 | |
---|
1075 | // checking startid values for all tasks in vspace |
---|
1076 | int task_id; |
---|
1077 | int task_min = vspace[vspace_index]->task_offset; |
---|
1078 | int task_max = task_min + vspace[vspace_index]->tasks; |
---|
1079 | for (task_id = task_min; task_id < task_max; task_id++) { |
---|
1080 | if (task[task_id]->startid >= vspace[vspace_index]->tasks) |
---|
1081 | { |
---|
1082 | printf("[XML ERROR] <startid> too large for task (%d,%d)\n", |
---|
1083 | vspace_index, task_id ); |
---|
1084 | exit(1); |
---|
1085 | } |
---|
1086 | } |
---|
1087 | |
---|
1088 | nb_tasks_max += nb_task_vspace; |
---|
1089 | vspace_index++; |
---|
1090 | return; |
---|
1091 | } |
---|
1092 | else |
---|
1093 | { |
---|
1094 | printf("[XML ERROR] Unknown tag %s", tag); |
---|
1095 | exit(1); |
---|
1096 | } |
---|
1097 | status = xmlTextReaderRead(reader); |
---|
1098 | } |
---|
1099 | } // end vspaceNode() |
---|
1100 | |
---|
1101 | //////////////////////////////////////// |
---|
1102 | void cpPortNode(xmlTextReaderPtr reader) |
---|
1103 | { |
---|
1104 | char * str; |
---|
1105 | unsigned int ok; |
---|
1106 | |
---|
1107 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
1108 | |
---|
1109 | if (cp_port_index >= MAX_CP_PORTS) |
---|
1110 | { |
---|
1111 | printf("[XML ERROR] The number of ports (for coprocs) is larger than %d\n", |
---|
1112 | MAX_CP_PORTS); |
---|
1113 | exit(1); |
---|
1114 | } |
---|
1115 | |
---|
1116 | #if XML_PARSER_DEBUG |
---|
1117 | printf("\n port %d\n", cp_port_index); |
---|
1118 | #endif |
---|
1119 | |
---|
1120 | cp_port[cp_port_index] = (mapping_cp_port_t *) malloc(sizeof(mapping_cp_port_t)); |
---|
1121 | cp_port_vobj_ref[cp_port_index] = (vobj_ref_t *) malloc(sizeof(vobj_ref_t)); |
---|
1122 | |
---|
1123 | ///////// get direction attribute |
---|
1124 | str = getStringValue(reader, "direction", &ok); |
---|
1125 | if (ok) |
---|
1126 | { |
---|
1127 | #if XML_PARSER_DEBUG |
---|
1128 | printf(" direction = %s\n", str); |
---|
1129 | #endif |
---|
1130 | if (strcmp(str, "TO_COPROC") == 0) |
---|
1131 | { |
---|
1132 | cp_port[cp_port_index]->direction = PORT_TO_COPROC; |
---|
1133 | } |
---|
1134 | else if (strcmp(str, "FROM_COPROC") == 0) |
---|
1135 | { |
---|
1136 | cp_port[cp_port_index]->direction = PORT_FROM_COPROC; |
---|
1137 | } |
---|
1138 | else |
---|
1139 | { |
---|
1140 | printf("[XML ERROR] illegal <direction> for cp_port %d in cluster %d\n", |
---|
1141 | cp_port_index, cluster_index); |
---|
1142 | exit(1); |
---|
1143 | } |
---|
1144 | } |
---|
1145 | else |
---|
1146 | { |
---|
1147 | printf("[XML ERROR] missing <direction> for cp_port %d in cluster %d\n", |
---|
1148 | cp_port_index, cluster_index); |
---|
1149 | exit(1); |
---|
1150 | } |
---|
1151 | |
---|
1152 | /////////// get vspacename attribute |
---|
1153 | str = getStringValue(reader, "vspacename", &ok); |
---|
1154 | #if XML_PARSER_DEBUG |
---|
1155 | printf(" vspacename = %s\n", str); |
---|
1156 | #endif |
---|
1157 | if (ok) |
---|
1158 | { |
---|
1159 | strncpy(cp_port_vobj_ref[cp_port_index]->vspace_name, str, 31); |
---|
1160 | } |
---|
1161 | else |
---|
1162 | { |
---|
1163 | printf("[XML ERROR] missing <vspacename> for cp_port %d in cluster %d\n", |
---|
1164 | cp_port_index, cluster_index); |
---|
1165 | exit(1); |
---|
1166 | } |
---|
1167 | |
---|
1168 | /////////// get vobjname attribute |
---|
1169 | str = getStringValue(reader, "vobjname", &ok); |
---|
1170 | #if XML_PARSER_DEBUG |
---|
1171 | printf(" vobjname = %s\n", str); |
---|
1172 | #endif |
---|
1173 | if (ok) |
---|
1174 | { |
---|
1175 | strncpy(cp_port_vobj_ref[cp_port_index]->vobj_name, str, 31); |
---|
1176 | } |
---|
1177 | else |
---|
1178 | { |
---|
1179 | printf("[XML ERROR] missing <vobjname> for cp_port %d in cluster %d\n", |
---|
1180 | cp_port_index, cluster_index); |
---|
1181 | exit(1); |
---|
1182 | } |
---|
1183 | cp_port_index++; |
---|
1184 | cp_port_loc_index++; |
---|
1185 | } // end cpPortNode() |
---|
1186 | |
---|
1187 | //////////////////////////////////////// |
---|
1188 | void periphNode(xmlTextReaderPtr reader) |
---|
1189 | { |
---|
1190 | char * str; |
---|
1191 | unsigned int value; |
---|
1192 | unsigned int ok; |
---|
1193 | |
---|
1194 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
1195 | |
---|
1196 | if (periph_index >= MAX_PERIPHS) |
---|
1197 | { |
---|
1198 | printf("[XML ERROR] The number of periphs is larger than %d\n", MAX_PERIPHS); |
---|
1199 | exit(1); |
---|
1200 | } |
---|
1201 | |
---|
1202 | #if XML_PARSER_DEBUG |
---|
1203 | printf("\n periph %d\n", periph_index); |
---|
1204 | #endif |
---|
1205 | |
---|
1206 | periph[periph_index] = (mapping_periph_t *) malloc(sizeof(mapping_periph_t)); |
---|
1207 | |
---|
1208 | ///////// get channels attribute (optionnal : 1 if missing) |
---|
1209 | value = getIntValue(reader, "channels", &ok); |
---|
1210 | if (ok) |
---|
1211 | { |
---|
1212 | #if XML_PARSER_DEBUG |
---|
1213 | printf(" channels = %d\n", value); |
---|
1214 | #endif |
---|
1215 | periph[periph_index]->channels = value; |
---|
1216 | } |
---|
1217 | else |
---|
1218 | { |
---|
1219 | periph[periph_index]->channels = 1; |
---|
1220 | } |
---|
1221 | |
---|
1222 | /////////// get psegname attribute |
---|
1223 | str = getStringValue(reader, "psegname", &ok); |
---|
1224 | if (ok == 0) |
---|
1225 | { |
---|
1226 | printf("[XML ERROR] illegal or missing <psegname> for coproc %d in cluster %d\n", |
---|
1227 | coproc_index, cluster_index); |
---|
1228 | exit(1); |
---|
1229 | } |
---|
1230 | |
---|
1231 | /////////// set psegid attribute |
---|
1232 | int index = getPsegId( cluster[cluster_index]->x, cluster[cluster_index]->y, str); |
---|
1233 | if (index >= 0) |
---|
1234 | { |
---|
1235 | #if XML_PARSER_DEBUG |
---|
1236 | printf(" clusterid = %d\n", cluster_index); |
---|
1237 | printf(" psegname = %s\n", str); |
---|
1238 | printf(" psegid = %d\n", index); |
---|
1239 | #endif |
---|
1240 | periph[periph_index]->psegid = index; |
---|
1241 | } |
---|
1242 | else |
---|
1243 | { |
---|
1244 | printf("[XML ERROR] pseg not found for periph %d / clusterid = %d / psegname = %s\n", |
---|
1245 | periph_loc_index, cluster_index, str ); |
---|
1246 | exit(1); |
---|
1247 | } |
---|
1248 | |
---|
1249 | /////////// get type attribute |
---|
1250 | str = getStringValue(reader, "type", &ok); |
---|
1251 | if (ok) |
---|
1252 | { |
---|
1253 | #if XML_PARSER_DEBUG |
---|
1254 | printf(" type = %s\n", str); |
---|
1255 | #endif |
---|
1256 | unsigned int error = 0; |
---|
1257 | |
---|
1258 | // initialize peripheral subtype |
---|
1259 | periph[periph_index]->subtype = 0xFFFFFFFF; |
---|
1260 | |
---|
1261 | // The CMA, FBF, HBA, IOB, IOC, NIC, ROM, SIM, TTY, peripherals are not |
---|
1262 | // replicated in all clusters but can be replicated in two clusters (fault tolerance) |
---|
1263 | // In case of replication, the two copies must have same number of channels. |
---|
1264 | |
---|
1265 | //////////////////////////// |
---|
1266 | if (strcmp(str, "CMA") == 0) |
---|
1267 | { |
---|
1268 | periph[periph_index]->type = PERIPH_TYPE_CMA; |
---|
1269 | if (header->cma_cluster == 0xFFFFFFFF) |
---|
1270 | { |
---|
1271 | header->cma_cluster = cluster_index; |
---|
1272 | cma_channels = periph[periph_index]->channels; |
---|
1273 | } |
---|
1274 | else if (header->cma_cluster_bis == 0xFFFFFFFF) |
---|
1275 | { |
---|
1276 | header->cma_cluster_bis = cluster_index; |
---|
1277 | assert( (cma_channels == periph[periph_index]->channels) && |
---|
1278 | "[XML ERROR] unconsistent non replicated peripheral"); |
---|
1279 | } |
---|
1280 | else |
---|
1281 | { |
---|
1282 | error = 1; |
---|
1283 | } |
---|
1284 | } |
---|
1285 | ///////////////////////////////// |
---|
1286 | else if (strcmp(str, "FBF") == 0) |
---|
1287 | { |
---|
1288 | periph[periph_index]->type = PERIPH_TYPE_FBF; |
---|
1289 | if (header->fbf_cluster == 0xFFFFFFFF) |
---|
1290 | { |
---|
1291 | header->fbf_cluster = cluster_index; |
---|
1292 | } |
---|
1293 | else if (header->fbf_cluster_bis == 0xFFFFFFFF) |
---|
1294 | { |
---|
1295 | header->fbf_cluster_bis = cluster_index; |
---|
1296 | } |
---|
1297 | else |
---|
1298 | { |
---|
1299 | error = 1; |
---|
1300 | } |
---|
1301 | } |
---|
1302 | ///////////////////////////////// |
---|
1303 | else if (strcmp(str, "IOB") == 0) |
---|
1304 | { |
---|
1305 | periph[periph_index]->type = PERIPH_TYPE_IOB; |
---|
1306 | use_iob = 1; |
---|
1307 | if (header->iob_cluster == 0xFFFFFFFF) |
---|
1308 | { |
---|
1309 | header->iob_cluster = cluster_index; |
---|
1310 | } |
---|
1311 | else if (header->iob_cluster_bis == 0xFFFFFFFF) |
---|
1312 | { |
---|
1313 | header->iob_cluster_bis = cluster_index; |
---|
1314 | } |
---|
1315 | else |
---|
1316 | { |
---|
1317 | error = 1; |
---|
1318 | } |
---|
1319 | } |
---|
1320 | ///////////////////////////////// |
---|
1321 | else if (strcmp(str, "IOC") == 0) |
---|
1322 | { |
---|
1323 | periph[periph_index]->type = PERIPH_TYPE_IOC; |
---|
1324 | if (header->ioc_cluster == 0xFFFFFFFF) |
---|
1325 | { |
---|
1326 | header->ioc_cluster = cluster_index; |
---|
1327 | } |
---|
1328 | else if (header->ioc_cluster_bis == 0xFFFFFFFF) |
---|
1329 | { |
---|
1330 | header->ioc_cluster_bis = cluster_index; |
---|
1331 | } |
---|
1332 | else |
---|
1333 | { |
---|
1334 | printf("[XML ERROR] At most two copies for non replicated " |
---|
1335 | "peripheral\n"); |
---|
1336 | exit(1); |
---|
1337 | } |
---|
1338 | |
---|
1339 | str = getStringValue(reader, "subtype", &ok); |
---|
1340 | |
---|
1341 | if (!ok) |
---|
1342 | { |
---|
1343 | printf("[XML ERROR] IOC peripheral needs a subtype parameter: " |
---|
1344 | "BDV, HBA or SPI\n"); |
---|
1345 | exit(1); |
---|
1346 | } |
---|
1347 | |
---|
1348 | if (strcmp(str, "BDV") == 0) |
---|
1349 | { |
---|
1350 | periph[periph_index]->subtype = PERIPH_SUBTYPE_BDV; |
---|
1351 | use_bdv = 1; |
---|
1352 | } |
---|
1353 | else if (strcmp(str, "HBA") == 0) |
---|
1354 | { |
---|
1355 | periph[periph_index]->subtype = PERIPH_SUBTYPE_HBA; |
---|
1356 | |
---|
1357 | if (use_hba == 0) |
---|
1358 | { |
---|
1359 | use_hba = 1; |
---|
1360 | hba_channels = periph[periph_index]->channels; |
---|
1361 | } |
---|
1362 | else |
---|
1363 | { |
---|
1364 | assert( (hba_channels == periph[periph_index]->channels) && |
---|
1365 | "[XML ERROR] unconsistent non replicated peripheral"); |
---|
1366 | } |
---|
1367 | } |
---|
1368 | else if (strcmp(str, "SPI") == 0) |
---|
1369 | { |
---|
1370 | periph[periph_index]->subtype = PERIPH_SUBTYPE_SPI; |
---|
1371 | use_spi = 1; |
---|
1372 | } |
---|
1373 | else |
---|
1374 | { |
---|
1375 | printf("[XML ERROR] illegal subtype for IOC peripheral\n"); |
---|
1376 | exit(1); |
---|
1377 | } |
---|
1378 | } |
---|
1379 | ///////////////////////////////// |
---|
1380 | else if (strcmp(str, "NIC") == 0) |
---|
1381 | { |
---|
1382 | periph[periph_index]->type = PERIPH_TYPE_NIC; |
---|
1383 | if (header->nic_cluster == 0xFFFFFFFF) |
---|
1384 | { |
---|
1385 | header->nic_cluster = cluster_index; |
---|
1386 | nic_channels = periph[periph_index]->channels; |
---|
1387 | } |
---|
1388 | else if (header->nic_cluster_bis == 0xFFFFFFFF) |
---|
1389 | { |
---|
1390 | header->nic_cluster_bis = cluster_index; |
---|
1391 | assert( (nic_channels == periph[periph_index]->channels) && |
---|
1392 | "[XML ERROR] unconsistent non replicated peripheral"); |
---|
1393 | } |
---|
1394 | else |
---|
1395 | { |
---|
1396 | error = 1; |
---|
1397 | } |
---|
1398 | } |
---|
1399 | ///////////////////////////////// |
---|
1400 | else if (strcmp(str, "ROM") == 0) |
---|
1401 | { |
---|
1402 | periph[periph_index]->type = PERIPH_TYPE_ROM; |
---|
1403 | if (header->rom_cluster == 0xFFFFFFFF) |
---|
1404 | { |
---|
1405 | header->rom_cluster = cluster_index; |
---|
1406 | } |
---|
1407 | else if (header->rom_cluster_bis == 0xFFFFFFFF) |
---|
1408 | { |
---|
1409 | header->rom_cluster_bis = cluster_index; |
---|
1410 | } |
---|
1411 | else |
---|
1412 | { |
---|
1413 | error = 1; |
---|
1414 | } |
---|
1415 | } |
---|
1416 | ///////////////////////////////// |
---|
1417 | else if (strcmp(str, "SIM") == 0) |
---|
1418 | { |
---|
1419 | periph[periph_index]->type = PERIPH_TYPE_SIM; |
---|
1420 | if (header->sim_cluster == 0xFFFFFFFF) |
---|
1421 | { |
---|
1422 | header->sim_cluster = cluster_index; |
---|
1423 | } |
---|
1424 | else if (header->sim_cluster_bis == 0xFFFFFFFF) |
---|
1425 | { |
---|
1426 | header->sim_cluster_bis = cluster_index; |
---|
1427 | } |
---|
1428 | else |
---|
1429 | { |
---|
1430 | error = 1; |
---|
1431 | } |
---|
1432 | } |
---|
1433 | ///////////////////////////////// |
---|
1434 | else if (strcmp(str, "TTY") == 0) |
---|
1435 | { |
---|
1436 | periph[periph_index]->type = PERIPH_TYPE_TTY; |
---|
1437 | if (header->tty_cluster == 0xFFFFFFFF) |
---|
1438 | { |
---|
1439 | header->tty_cluster = cluster_index; |
---|
1440 | tty_channels = periph[periph_index]->channels; |
---|
1441 | } |
---|
1442 | else if (header->tty_cluster_bis == 0xFFFFFFFF) |
---|
1443 | { |
---|
1444 | header->tty_cluster_bis = cluster_index; |
---|
1445 | assert( (tty_channels == periph[periph_index]->channels) && |
---|
1446 | "[XML ERROR] unconsistent non replicated peripheral"); |
---|
1447 | } |
---|
1448 | else |
---|
1449 | { |
---|
1450 | error = 1; |
---|
1451 | } |
---|
1452 | } |
---|
1453 | |
---|
1454 | // The DMA, ICU, MMC, TIM, XCU peripherals can be replicated in all clusters |
---|
1455 | // but it must exist only one component of each type per cluster |
---|
1456 | |
---|
1457 | ///////////////////////////////// |
---|
1458 | else if (strcmp(str, "DMA") == 0) |
---|
1459 | { |
---|
1460 | periph[periph_index]->type = PERIPH_TYPE_DMA; |
---|
1461 | if (found_dma) error = 1; |
---|
1462 | found_dma = 1; |
---|
1463 | if (dma_channels < periph[periph_index]->channels) |
---|
1464 | dma_channels = periph[periph_index]->channels; |
---|
1465 | } |
---|
1466 | ////////////////////////////////// |
---|
1467 | else if (strcmp(str, "ICU") == 0) |
---|
1468 | { |
---|
1469 | periph[periph_index]->type = PERIPH_TYPE_ICU; |
---|
1470 | if (found_icu || use_xcu) error = 1; |
---|
1471 | found_icu = 1; |
---|
1472 | |
---|
1473 | if (icu_channels > 0) |
---|
1474 | { |
---|
1475 | assert( (periph[periph_index]->channels == icu_channels) && |
---|
1476 | "[XML ERROR] the number of interruptions per processor " |
---|
1477 | "from the ICU (icu channels) must be the same on all " |
---|
1478 | "clusters"); |
---|
1479 | } |
---|
1480 | else |
---|
1481 | { |
---|
1482 | icu_channels = periph[periph_index]->channels; |
---|
1483 | } |
---|
1484 | } |
---|
1485 | ////////////////////////////////// |
---|
1486 | else if (strcmp(str, "MMC") == 0) |
---|
1487 | { |
---|
1488 | periph[periph_index]->type = PERIPH_TYPE_MMC; |
---|
1489 | if (found_mmc) error = 1; |
---|
1490 | found_mmc = 1; |
---|
1491 | if ( periph[periph_index]->channels != 1 ) error = 1; |
---|
1492 | } |
---|
1493 | ////////////////////////////////// |
---|
1494 | else if (strcmp(str, "TIM") == 0 ) |
---|
1495 | { |
---|
1496 | periph[periph_index]->type = PERIPH_TYPE_TIM; |
---|
1497 | if (found_timer || use_xcu) error = 1; |
---|
1498 | found_timer = 1; |
---|
1499 | if (tim_channels < periph[periph_index]->channels) |
---|
1500 | { |
---|
1501 | tim_channels = periph[periph_index]->channels; |
---|
1502 | } |
---|
1503 | } |
---|
1504 | ////////////////////////////////// |
---|
1505 | else if (strcmp(str, "XCU") == 0) |
---|
1506 | { |
---|
1507 | periph[periph_index]->type = PERIPH_TYPE_XCU; |
---|
1508 | if (found_xcu || found_icu || found_timer) error = 1; |
---|
1509 | found_xcu = 1; |
---|
1510 | found_timer = 1; |
---|
1511 | tim_channels = 32; |
---|
1512 | use_xcu = 1; |
---|
1513 | |
---|
1514 | if (icu_channels > 0) |
---|
1515 | { |
---|
1516 | assert( (periph[periph_index]->channels == icu_channels) && |
---|
1517 | "[XML ERROR] the number of interruptions per processor " |
---|
1518 | "from the ICU (icu channels) must be the same on all " |
---|
1519 | "clusters"); |
---|
1520 | } |
---|
1521 | else |
---|
1522 | { |
---|
1523 | icu_channels = periph[periph_index]->channels; |
---|
1524 | } |
---|
1525 | } |
---|
1526 | else |
---|
1527 | { |
---|
1528 | printf("[XML ERROR] illegal <type>: %s for peripheral %d in cluster %d\n", |
---|
1529 | str, periph_loc_index, cluster_index); |
---|
1530 | exit(1); |
---|
1531 | } |
---|
1532 | |
---|
1533 | if (error) |
---|
1534 | { |
---|
1535 | printf("[XML ERROR] illegal <type>: %s for peripheral %d in cluster %d\n", |
---|
1536 | str, periph_loc_index, cluster_index); |
---|
1537 | exit(1); |
---|
1538 | } |
---|
1539 | } |
---|
1540 | else |
---|
1541 | { |
---|
1542 | printf("[XML ERROR] missing <type> for peripheral %d in cluster %d\n", |
---|
1543 | periph_loc_index, cluster_index); |
---|
1544 | exit(1); |
---|
1545 | } |
---|
1546 | |
---|
1547 | periph_index++; |
---|
1548 | periph_loc_index++; |
---|
1549 | cluster[cluster_index]->periphs++; |
---|
1550 | |
---|
1551 | } // end periphNode |
---|
1552 | |
---|
1553 | //////////////////////////////////////// |
---|
1554 | void coprocNode(xmlTextReaderPtr reader) |
---|
1555 | { |
---|
1556 | char * str; |
---|
1557 | unsigned int ok; |
---|
1558 | |
---|
1559 | cp_port_loc_index = 0; |
---|
1560 | |
---|
1561 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
1562 | |
---|
1563 | if (coproc_index >= MAX_COPROCS) |
---|
1564 | { |
---|
1565 | printf("[XML ERROR] The number of coprocs is larger than %d\n", MAX_COPROCS); |
---|
1566 | exit(1); |
---|
1567 | } |
---|
1568 | |
---|
1569 | #if XML_PARSER_DEBUG |
---|
1570 | printf("\n coproc %d\n", coproc_index); |
---|
1571 | #endif |
---|
1572 | |
---|
1573 | coproc[coproc_index] = (mapping_coproc_t *) malloc(sizeof(mapping_coproc_t)); |
---|
1574 | |
---|
1575 | /////////// get name attribute |
---|
1576 | str = getStringValue(reader, "name", &ok); |
---|
1577 | if (ok) |
---|
1578 | { |
---|
1579 | #if XML_PARSER_DEBUG |
---|
1580 | printf(" name = %s\n", str); |
---|
1581 | #endif |
---|
1582 | strncpy(coproc[coproc_index]->name, str, 31); |
---|
1583 | } |
---|
1584 | else |
---|
1585 | { |
---|
1586 | printf("[XML ERROR] illegal or missing <name> for coproc %d in cluster %d\n", |
---|
1587 | coproc_index, cluster_index); |
---|
1588 | exit(1); |
---|
1589 | } |
---|
1590 | |
---|
1591 | /////////// get psegname attribute |
---|
1592 | str = getStringValue(reader, "psegname", &ok); |
---|
1593 | if (ok == 0) |
---|
1594 | { |
---|
1595 | printf("[XML ERROR] illegal or missing <psegname> for coproc %d in cluster %d\n", |
---|
1596 | coproc_index, cluster_index); |
---|
1597 | exit(1); |
---|
1598 | } |
---|
1599 | |
---|
1600 | /////////// set psegid attribute |
---|
1601 | int index = getPsegId( cluster[cluster_index]->x, cluster[cluster_index]->y, str); |
---|
1602 | if (index >= 0) |
---|
1603 | { |
---|
1604 | #if XML_PARSER_DEBUG |
---|
1605 | printf(" clusterid = %d\n", cluster_index); |
---|
1606 | printf(" psegname = %s\n", str); |
---|
1607 | printf(" psegid = %d\n", index); |
---|
1608 | #endif |
---|
1609 | coproc[coproc_index]->psegid = index; |
---|
1610 | assert(pseg[index]->type == PSEG_TYPE_PERI && "coproc psegname attribute must refer to a pseg of type PERI" ); |
---|
1611 | } |
---|
1612 | else |
---|
1613 | { |
---|
1614 | printf("[XML ERROR] pseg not found for coproc %d / clusterid = %d / psegname = %s\n", |
---|
1615 | coproc_index, cluster_index, str ); |
---|
1616 | exit(1); |
---|
1617 | } |
---|
1618 | |
---|
1619 | ////////// set port_offset |
---|
1620 | coproc[coproc_index]->port_offset = cp_port_index; |
---|
1621 | |
---|
1622 | #if XML_PARSER_DEBUG |
---|
1623 | printf(" port_offset = %d\n", cp_port_index); |
---|
1624 | #endif |
---|
1625 | |
---|
1626 | int status = xmlTextReaderRead(reader); |
---|
1627 | while (status == 1) |
---|
1628 | { |
---|
1629 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
1630 | |
---|
1631 | if (strcmp(tag, "port") == 0 ) |
---|
1632 | { |
---|
1633 | cpPortNode(reader); |
---|
1634 | } |
---|
1635 | else if (strcmp(tag, "#text") == 0 ) { } |
---|
1636 | else if (strcmp(tag, "#comment") == 0 ) { } |
---|
1637 | else if (strcmp(tag, "coproc") == 0 ) |
---|
1638 | { |
---|
1639 | coproc[coproc_index]->ports = cp_port_loc_index; |
---|
1640 | cluster[cluster_index]->coprocs++; |
---|
1641 | coproc_loc_index++; |
---|
1642 | coproc_index++; |
---|
1643 | return; |
---|
1644 | } |
---|
1645 | else |
---|
1646 | { |
---|
1647 | printf("[XML ERROR] Unknown tag %s", tag); |
---|
1648 | exit(1); |
---|
1649 | } |
---|
1650 | status = xmlTextReaderRead(reader); |
---|
1651 | } |
---|
1652 | } // end coprocNode() |
---|
1653 | |
---|
1654 | |
---|
1655 | ///////////////////////////////////// |
---|
1656 | void irqNode(xmlTextReaderPtr reader) |
---|
1657 | { |
---|
1658 | unsigned int ok; |
---|
1659 | unsigned int value; |
---|
1660 | char * str; |
---|
1661 | |
---|
1662 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
1663 | |
---|
1664 | if (irq_index >= MAX_IRQS) { |
---|
1665 | printf("[XML ERROR] The number of irqs is larger than %d\n", MAX_IRQS); |
---|
1666 | } |
---|
1667 | |
---|
1668 | #if XML_PARSER_DEBUG |
---|
1669 | printf(" irq %d\n", irq_loc_index); |
---|
1670 | #endif |
---|
1671 | |
---|
1672 | irq[irq_index] = (mapping_irq_t *) malloc(sizeof(mapping_irq_t)); |
---|
1673 | |
---|
1674 | ///////// get type attribute |
---|
1675 | str = getStringValue(reader, "type", &ok); |
---|
1676 | if (ok) |
---|
1677 | { |
---|
1678 | #if XML_PARSER_DEBUG |
---|
1679 | printf(" type = %s\n", str); |
---|
1680 | #endif |
---|
1681 | if ( strcmp(str, "HARD") == 0 ) irq[irq_index]->type = IRQ_TYPE_HWI; |
---|
1682 | else if ( strcmp(str, "SOFT") == 0 ) irq[irq_index]->type = IRQ_TYPE_SWI; |
---|
1683 | else if ( strcmp(str, "TIME") == 0 ) irq[irq_index]->type = IRQ_TYPE_PTI; |
---|
1684 | else |
---|
1685 | { |
---|
1686 | printf("[XML ERROR] illegal IRQ <type> for processor %d in cluster %d\n", |
---|
1687 | cluster_index, proc_loc_index); |
---|
1688 | exit(1); |
---|
1689 | } |
---|
1690 | } |
---|
1691 | else |
---|
1692 | { |
---|
1693 | printf("[XML ERROR] missing IRQ <type> for processor %d in cluster %d\n", |
---|
1694 | cluster_index, proc_loc_index); |
---|
1695 | exit(1); |
---|
1696 | } |
---|
1697 | |
---|
1698 | ///////// get icuid attribute |
---|
1699 | value = getIntValue(reader, "icuid", &ok); |
---|
1700 | if (ok) |
---|
1701 | { |
---|
1702 | #if XML_PARSER_DEBUG |
---|
1703 | printf(" icuid = %d\n", value); |
---|
1704 | #endif |
---|
1705 | irq[irq_index]->icuid = value; |
---|
1706 | if (value >= 32) |
---|
1707 | { |
---|
1708 | printf("[XML ERROR] IRQ <icuid> too large for processor %d in cluster %d\n", |
---|
1709 | cluster_index, proc_loc_index); |
---|
1710 | exit(1); |
---|
1711 | } |
---|
1712 | } |
---|
1713 | else |
---|
1714 | { |
---|
1715 | printf("[XML ERROR] missing IRQ <icuid> for processor %d in cluster %d\n", |
---|
1716 | cluster_index, proc_loc_index); |
---|
1717 | exit(1); |
---|
1718 | } |
---|
1719 | |
---|
1720 | ///////// get isr attribute |
---|
1721 | str = getStringValue(reader, "isr", &ok); |
---|
1722 | if (ok) |
---|
1723 | { |
---|
1724 | #if XML_PARSER_DEBUG |
---|
1725 | printf(" isr = %s\n", str); |
---|
1726 | #endif |
---|
1727 | if (strcmp(str, "ISR_SWITCH" ) == 0) irq[irq_index]->isr = ISR_SWITCH; |
---|
1728 | else if (strcmp(str, "ISR_IOC" ) == 0) irq[irq_index]->isr = ISR_IOC; |
---|
1729 | else if (strcmp(str, "ISR_DMA" ) == 0) irq[irq_index]->isr = ISR_DMA; |
---|
1730 | else if (strcmp(str, "ISR_TTY" ) == 0) irq[irq_index]->isr = ISR_TTY; |
---|
1731 | else if (strcmp(str, "ISR_TIMER" ) == 0) irq[irq_index]->isr = ISR_TIMER; |
---|
1732 | else if (strcmp(str, "ISR_WAKUP" ) == 0) irq[irq_index]->isr = ISR_WAKUP; |
---|
1733 | else if (strcmp(str, "ISR_DEFAULT") == 0) irq[irq_index]->isr = ISR_DEFAULT; |
---|
1734 | else |
---|
1735 | { |
---|
1736 | printf("[XML ERROR] illegal IRQ <isr> for processor %d in cluster %d\n", |
---|
1737 | cluster_index, proc_loc_index); |
---|
1738 | exit(1); |
---|
1739 | } |
---|
1740 | #if XML_PARSER_DEBUG |
---|
1741 | printf(" isrnum = %d\n", irq[irq_index]->isr); |
---|
1742 | #endif |
---|
1743 | } |
---|
1744 | else |
---|
1745 | { |
---|
1746 | printf("[XML ERROR] missing IRQ <isr> for processor %d in cluster %d\n", |
---|
1747 | cluster_index, proc_loc_index); |
---|
1748 | exit(1); |
---|
1749 | } |
---|
1750 | |
---|
1751 | ///////// get channel attribute (optionnal : 0 if missing) |
---|
1752 | value = getIntValue(reader, "channel", &ok); |
---|
1753 | if (ok) |
---|
1754 | { |
---|
1755 | #if XML_PARSER_DEBUG |
---|
1756 | printf(" channel = %d\n", value); |
---|
1757 | #endif |
---|
1758 | irq[irq_index]->channel = value; |
---|
1759 | } |
---|
1760 | else |
---|
1761 | { |
---|
1762 | irq[irq_index]->channel = 0; |
---|
1763 | } |
---|
1764 | |
---|
1765 | irq_index++; |
---|
1766 | irq_loc_index++; |
---|
1767 | |
---|
1768 | } // end irqNode |
---|
1769 | |
---|
1770 | |
---|
1771 | ////////////////////////////////////// |
---|
1772 | void procNode(xmlTextReaderPtr reader) |
---|
1773 | { |
---|
1774 | unsigned int ok; |
---|
1775 | unsigned int value; |
---|
1776 | |
---|
1777 | irq_loc_index = 0; |
---|
1778 | |
---|
1779 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
1780 | |
---|
1781 | if (proc_index >= MAX_PROCS) |
---|
1782 | { |
---|
1783 | printf("[XML ERROR] The number of procs is larger than %d\n", MAX_PROCS); |
---|
1784 | exit(1); |
---|
1785 | } |
---|
1786 | |
---|
1787 | #if XML_PARSER_DEBUG |
---|
1788 | printf("\n proc %d\n", proc_index); |
---|
1789 | #endif |
---|
1790 | |
---|
1791 | proc[proc_index] = (mapping_proc_t *) malloc(sizeof(mapping_proc_t)); |
---|
1792 | |
---|
1793 | /////////// get index attribute (optional) |
---|
1794 | value = getIntValue(reader, "index", &ok); |
---|
1795 | if (ok && (value != proc_loc_index)) |
---|
1796 | { |
---|
1797 | printf("[XML ERROR] wrong proc index / expected value is %d", |
---|
1798 | proc_loc_index); |
---|
1799 | exit(1); |
---|
1800 | } |
---|
1801 | |
---|
1802 | ////////// set irq_offset attribute |
---|
1803 | proc[proc_index]->irq_offset = irq_index; |
---|
1804 | |
---|
1805 | #if XML_PARSER_DEBUG |
---|
1806 | printf(" irq_offset = %d\n", irq_index); |
---|
1807 | #endif |
---|
1808 | |
---|
1809 | int status = xmlTextReaderRead(reader); |
---|
1810 | while (status == 1) |
---|
1811 | { |
---|
1812 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
1813 | |
---|
1814 | if (strcmp(tag, "irq") == 0) |
---|
1815 | { |
---|
1816 | irqNode(reader); |
---|
1817 | } |
---|
1818 | else if (strcmp(tag, "#text") == 0) { } |
---|
1819 | else if (strcmp(tag, "#comment") == 0) { } |
---|
1820 | else if (strcmp(tag, "proc") == 0) |
---|
1821 | { |
---|
1822 | proc[proc_index]->irqs = irq_loc_index; |
---|
1823 | cluster[cluster_index]->procs++; |
---|
1824 | proc_loc_index++; |
---|
1825 | proc_index++; |
---|
1826 | return; |
---|
1827 | } |
---|
1828 | else |
---|
1829 | { |
---|
1830 | printf("[XML ERROR] Unknown tag %s", tag); |
---|
1831 | exit(1); |
---|
1832 | } |
---|
1833 | status = xmlTextReaderRead(reader); |
---|
1834 | } |
---|
1835 | } // end procNode() |
---|
1836 | |
---|
1837 | |
---|
1838 | ////////////////////////////////////// |
---|
1839 | void psegNode(xmlTextReaderPtr reader) |
---|
1840 | { |
---|
1841 | unsigned int ok; |
---|
1842 | paddr_t ll_value; |
---|
1843 | char * str; |
---|
1844 | |
---|
1845 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
1846 | |
---|
1847 | if (pseg_index >= MAX_PSEGS) |
---|
1848 | { |
---|
1849 | printf("[XML ERROR] The number of psegs is larger than %d\n", MAX_PSEGS); |
---|
1850 | exit(1); |
---|
1851 | } |
---|
1852 | |
---|
1853 | #if XML_PARSER_DEBUG |
---|
1854 | printf(" pseg %d\n", pseg_index); |
---|
1855 | #endif |
---|
1856 | |
---|
1857 | pseg[pseg_index] = (mapping_pseg_t *) malloc(sizeof(mapping_pseg_t)); |
---|
1858 | |
---|
1859 | /////// get name attribute |
---|
1860 | str = getStringValue(reader, "name", &ok); |
---|
1861 | #if XML_PARSER_DEBUG |
---|
1862 | printf(" name = %s\n", str); |
---|
1863 | #endif |
---|
1864 | if (ok) |
---|
1865 | { |
---|
1866 | strncpy(pseg[pseg_index]->name, str, 31); |
---|
1867 | } |
---|
1868 | else |
---|
1869 | { |
---|
1870 | printf("[XML ERROR] illegal or missing <name> for pseg %d in cluster %d\n", |
---|
1871 | pseg_index, cluster_index); |
---|
1872 | exit(1); |
---|
1873 | } |
---|
1874 | |
---|
1875 | //////// get type attribute |
---|
1876 | str = getStringValue(reader, "type", &ok); |
---|
1877 | #if XML_PARSER_DEBUG |
---|
1878 | printf(" type = %s\n", str); |
---|
1879 | #endif |
---|
1880 | if (ok && (strcmp(str, "RAM" ) == 0)) { pseg[pseg_index]->type = PSEG_TYPE_RAM; } |
---|
1881 | else if (ok && (strcmp(str, "ROM" ) == 0)) { pseg[pseg_index]->type = PSEG_TYPE_ROM; } |
---|
1882 | else if (ok && (strcmp(str, "PERI") == 0)) { pseg[pseg_index]->type = PSEG_TYPE_PERI; } |
---|
1883 | else |
---|
1884 | { |
---|
1885 | printf("[XML ERROR] illegal or missing <type> for pseg %s in cluster %d\n", |
---|
1886 | pseg[pseg_index]->name, cluster_index); |
---|
1887 | exit(1); |
---|
1888 | } |
---|
1889 | |
---|
1890 | //////// get base attribute |
---|
1891 | ll_value = getPaddrValue(reader, "base", &ok); |
---|
1892 | #if XML_PARSER_DEBUG |
---|
1893 | printf(" base = 0x%llx\n", ll_value); |
---|
1894 | #endif |
---|
1895 | if (ok) |
---|
1896 | { |
---|
1897 | pseg[pseg_index]->base = ll_value; |
---|
1898 | } |
---|
1899 | else { |
---|
1900 | printf("[XML ERROR] illegal or missing <base> for pseg %s in cluster %d\n", |
---|
1901 | pseg[pseg_index]->name, cluster_index); |
---|
1902 | exit(1); |
---|
1903 | } |
---|
1904 | |
---|
1905 | //////// get length attribute |
---|
1906 | ll_value = getPaddrValue(reader, "length", &ok); |
---|
1907 | #if XML_PARSER_DEBUG |
---|
1908 | printf(" length = 0x%llx\n", ll_value); |
---|
1909 | #endif |
---|
1910 | if (ok) |
---|
1911 | { |
---|
1912 | pseg[pseg_index]->length = ll_value; |
---|
1913 | } |
---|
1914 | else |
---|
1915 | { |
---|
1916 | printf("[XML ERROR] illegal or missing <length> for pseg %s in cluster %d\n", |
---|
1917 | pseg[pseg_index]->name, cluster_index); |
---|
1918 | exit(1); |
---|
1919 | } |
---|
1920 | |
---|
1921 | //////// set cluster attribute |
---|
1922 | pseg[pseg_index]->clusterid = cluster_index; |
---|
1923 | |
---|
1924 | //////// set next_vseg attribute |
---|
1925 | pseg[pseg_index]->next_vseg = 0; |
---|
1926 | |
---|
1927 | pseg_index++; |
---|
1928 | cluster[cluster_index]->psegs++; |
---|
1929 | } // end psegNode() |
---|
1930 | |
---|
1931 | |
---|
1932 | ///////////////////////////////////////// |
---|
1933 | void clusterNode(xmlTextReaderPtr reader) |
---|
1934 | { |
---|
1935 | unsigned int ok; |
---|
1936 | unsigned int value; |
---|
1937 | |
---|
1938 | cluster[cluster_index] = (mapping_cluster_t *) malloc(sizeof(mapping_cluster_t)); |
---|
1939 | |
---|
1940 | //initialise variables that will be incremented by *Node() functions |
---|
1941 | cluster[cluster_index]->psegs = 0; |
---|
1942 | cluster[cluster_index]->procs = 0; |
---|
1943 | cluster[cluster_index]->coprocs = 0; |
---|
1944 | cluster[cluster_index]->periphs = 0; |
---|
1945 | |
---|
1946 | //initialise global variables |
---|
1947 | proc_loc_index = 0; |
---|
1948 | coproc_loc_index = 0; |
---|
1949 | periph_loc_index = 0; |
---|
1950 | |
---|
1951 | // for replicated periph |
---|
1952 | found_timer = 0; |
---|
1953 | found_icu = 0; |
---|
1954 | found_xcu = 0; |
---|
1955 | found_dma = 0; |
---|
1956 | found_mmc = 0; |
---|
1957 | |
---|
1958 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { |
---|
1959 | return; |
---|
1960 | } |
---|
1961 | |
---|
1962 | #if XML_PARSER_DEBUG |
---|
1963 | printf("\n cluster %d\n", cluster_index); |
---|
1964 | #endif |
---|
1965 | |
---|
1966 | /////////// get x coordinate |
---|
1967 | value = getIntValue(reader, "x", &ok); |
---|
1968 | #if XML_PARSER_DEBUG |
---|
1969 | printf(" x = %d\n", value); |
---|
1970 | #endif |
---|
1971 | if (ok && (value < header->x_size) ) |
---|
1972 | { |
---|
1973 | cluster[cluster_index]->x = value; |
---|
1974 | } |
---|
1975 | else |
---|
1976 | { |
---|
1977 | printf("[XML ERROR] Illegal or missing < x > attribute for cluster %d", |
---|
1978 | cluster_index); |
---|
1979 | exit(1); |
---|
1980 | } |
---|
1981 | |
---|
1982 | /////////// get y coordinate |
---|
1983 | value = getIntValue(reader, "y", &ok); |
---|
1984 | #if XML_PARSER_DEBUG |
---|
1985 | printf(" y = %d\n", value); |
---|
1986 | #endif |
---|
1987 | if (ok && (value < header->y_size) ) |
---|
1988 | { |
---|
1989 | cluster[cluster_index]->y = value; |
---|
1990 | } |
---|
1991 | else |
---|
1992 | { |
---|
1993 | printf("[XML ERROR] Illegal or missing < y > attribute for cluster %d", |
---|
1994 | cluster_index); |
---|
1995 | exit(1); |
---|
1996 | } |
---|
1997 | |
---|
1998 | ////////// set offsets |
---|
1999 | cluster[cluster_index]->pseg_offset = pseg_index; |
---|
2000 | cluster[cluster_index]->proc_offset = proc_index; |
---|
2001 | cluster[cluster_index]->coproc_offset = coproc_index; |
---|
2002 | cluster[cluster_index]->periph_offset = periph_index; |
---|
2003 | |
---|
2004 | #if XML_PARSER_DEBUG |
---|
2005 | printf(" pseg_offset = %d\n", pseg_index); |
---|
2006 | printf(" proc_offset = %d\n", proc_index); |
---|
2007 | printf(" coproc_offset = %d\n", coproc_index); |
---|
2008 | printf(" periph_offset = %d\n", coproc_index); |
---|
2009 | #endif |
---|
2010 | |
---|
2011 | ////////// get psegs, procs, coprocs and periphs |
---|
2012 | int status = xmlTextReaderRead(reader); |
---|
2013 | |
---|
2014 | while (status == 1) |
---|
2015 | { |
---|
2016 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
2017 | |
---|
2018 | if (strcmp(tag, "pseg") == 0) psegNode(reader); |
---|
2019 | else if (strcmp(tag, "proc") == 0) procNode(reader); |
---|
2020 | else if (strcmp(tag, "coproc") == 0) coprocNode(reader); |
---|
2021 | else if (strcmp(tag, "periph") == 0) periphNode(reader); |
---|
2022 | else if (strcmp(tag, "#text") == 0) { } |
---|
2023 | else if (strcmp(tag, "#comment") == 0) { } |
---|
2024 | else if (strcmp(tag, "cluster") == 0) |
---|
2025 | { |
---|
2026 | |
---|
2027 | ///////// TIMER and ICU peripheral are mandatory ////////////// |
---|
2028 | if (!found_timer && !found_xcu) |
---|
2029 | { |
---|
2030 | printf("[XML ERROR] missing timer peripheral in cluster %d\n", cluster_index); |
---|
2031 | exit(1); |
---|
2032 | } |
---|
2033 | |
---|
2034 | if (!found_icu && !found_xcu) |
---|
2035 | { |
---|
2036 | printf("[XML ERROR] missing icu peripheral in cluster %d\n", cluster_index); |
---|
2037 | exit(1); |
---|
2038 | } |
---|
2039 | |
---|
2040 | if (nb_proc_max < cluster[cluster_index]->procs) |
---|
2041 | { |
---|
2042 | nb_proc_max = cluster[cluster_index]->procs; |
---|
2043 | } |
---|
2044 | |
---|
2045 | #if XML_PARSER_DEBUG |
---|
2046 | printf(" psegs = %d\n", cluster[cluster_index]->psegs); |
---|
2047 | printf(" procs = %d\n", cluster[cluster_index]->procs); |
---|
2048 | printf(" coprocs = %d\n", cluster[cluster_index]->coprocs); |
---|
2049 | printf(" periphs = %d\n", cluster[cluster_index]->periphs); |
---|
2050 | printf(" end cluster %d\n", cluster_index); |
---|
2051 | #endif |
---|
2052 | cluster_index++; |
---|
2053 | return; |
---|
2054 | } |
---|
2055 | status = xmlTextReaderRead(reader); |
---|
2056 | } |
---|
2057 | } // end clusterNode() |
---|
2058 | |
---|
2059 | |
---|
2060 | ////////////////////////////////////////////// |
---|
2061 | void clusterSetNode(xmlTextReaderPtr reader) |
---|
2062 | { |
---|
2063 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
2064 | |
---|
2065 | #if XML_PARSER_DEBUG |
---|
2066 | printf("\n clusters set\n"); |
---|
2067 | #endif |
---|
2068 | |
---|
2069 | int status = xmlTextReaderRead(reader); |
---|
2070 | while (status == 1) |
---|
2071 | { |
---|
2072 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
2073 | |
---|
2074 | if (strcmp(tag, "cluster") == 0) { clusterNode(reader); } |
---|
2075 | else if (strcmp(tag, "#text") == 0) { } |
---|
2076 | else if (strcmp(tag, "#comment") == 0) { } |
---|
2077 | else if (strcmp(tag, "clusterset") == 0) |
---|
2078 | { |
---|
2079 | // checking source file consistency |
---|
2080 | if ( cluster_index != (header->x_size * header->y_size) ) |
---|
2081 | { |
---|
2082 | printf("[XML ERROR] Wrong number of clusters\n"); |
---|
2083 | exit(1); |
---|
2084 | } |
---|
2085 | |
---|
2086 | // At least one TTY terminal for system boot |
---|
2087 | if (header->tty_cluster == 0xFFFFFFFF) |
---|
2088 | { |
---|
2089 | printf("[XML ERROR] illegal or missing tty peripheral"); |
---|
2090 | exit(1); |
---|
2091 | } |
---|
2092 | |
---|
2093 | // the number of ICU channels must be NB_PROCS * irq_per_proc |
---|
2094 | if (icu_channels != (header->irq_per_proc * proc_loc_index)) |
---|
2095 | { |
---|
2096 | printf("[XML ERROR] illegal ICU number of channels. " |
---|
2097 | "It must be equal to NB_PROCS * IRQ_PER_PROC\n"); |
---|
2098 | exit(1); |
---|
2099 | } |
---|
2100 | |
---|
2101 | #if XML_PARSER_DEBUG |
---|
2102 | printf(" end cluster set\n\n"); |
---|
2103 | #endif |
---|
2104 | header->psegs = pseg_index; |
---|
2105 | header->procs = proc_index; |
---|
2106 | header->irqs = irq_index; |
---|
2107 | header->coprocs = coproc_index; |
---|
2108 | header->cp_ports = cp_port_index; |
---|
2109 | header->periphs = periph_index; |
---|
2110 | return; |
---|
2111 | } |
---|
2112 | else |
---|
2113 | { |
---|
2114 | printf("[XML ERROR] Unknown tag in clusterset node : %s",tag); |
---|
2115 | exit(1); |
---|
2116 | } |
---|
2117 | status = xmlTextReaderRead(reader); |
---|
2118 | } |
---|
2119 | } // end clusterSetNode() |
---|
2120 | |
---|
2121 | |
---|
2122 | /////////////////////////////////////////// |
---|
2123 | void globalSetNode(xmlTextReaderPtr reader) |
---|
2124 | { |
---|
2125 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
2126 | |
---|
2127 | #if XML_PARSER_DEBUG |
---|
2128 | printf(" globals set\n"); |
---|
2129 | #endif |
---|
2130 | |
---|
2131 | int status = xmlTextReaderRead(reader); |
---|
2132 | while (status == 1) |
---|
2133 | { |
---|
2134 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
2135 | |
---|
2136 | if (strcmp(tag, "vseg") == 0) { vsegNode(reader); } |
---|
2137 | else if (strcmp(tag, "#text") == 0) { } |
---|
2138 | else if (strcmp(tag, "#comment") == 0) { } |
---|
2139 | else if (strcmp(tag, "globalset") == 0) |
---|
2140 | { |
---|
2141 | #if XML_PARSER_DEBUG |
---|
2142 | printf(" end global set\n\n"); |
---|
2143 | #endif |
---|
2144 | header->globals = vseg_index; |
---|
2145 | vseg_loc_index = 0; |
---|
2146 | return; |
---|
2147 | } |
---|
2148 | else |
---|
2149 | { |
---|
2150 | printf("[XML ERROR] Unknown tag in globalset node : %s",tag); |
---|
2151 | exit(1); |
---|
2152 | } |
---|
2153 | status = xmlTextReaderRead(reader); |
---|
2154 | } |
---|
2155 | } // end globalSetNode() |
---|
2156 | |
---|
2157 | |
---|
2158 | /////////////////////////////////////////// |
---|
2159 | void vspaceSetNode(xmlTextReaderPtr reader) |
---|
2160 | { |
---|
2161 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { |
---|
2162 | return; |
---|
2163 | } |
---|
2164 | |
---|
2165 | #if XML_PARSER_DEBUG |
---|
2166 | printf("\n vspaces set\n"); |
---|
2167 | #endif |
---|
2168 | |
---|
2169 | int status = xmlTextReaderRead ( reader ); |
---|
2170 | while (status == 1) { |
---|
2171 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
2172 | |
---|
2173 | if (strcmp(tag, "vspace") == 0) { |
---|
2174 | vspaceNode(reader); |
---|
2175 | } |
---|
2176 | else if (strcmp(tag, "#text" ) == 0 ) { } |
---|
2177 | else if (strcmp(tag, "#comment" ) == 0 ) { } |
---|
2178 | else if (strcmp(tag, "vspaceset") == 0 ) |
---|
2179 | { |
---|
2180 | // checking source file consistency |
---|
2181 | if (vspace_index != header->vspaces) |
---|
2182 | { |
---|
2183 | printf("[XML ERROR] Wrong number of vspaces\n"); |
---|
2184 | exit(1); |
---|
2185 | } |
---|
2186 | else |
---|
2187 | { |
---|
2188 | header->vsegs = vseg_index; |
---|
2189 | header->vobjs = vobj_index; |
---|
2190 | header->tasks = task_index; |
---|
2191 | return; |
---|
2192 | } |
---|
2193 | } |
---|
2194 | else |
---|
2195 | { |
---|
2196 | printf("[XML ERROR] Unknown tag in vspaceset node : %s",tag); |
---|
2197 | exit(1); |
---|
2198 | } |
---|
2199 | status = xmlTextReaderRead(reader); |
---|
2200 | } |
---|
2201 | } // end globalSetNode() |
---|
2202 | |
---|
2203 | |
---|
2204 | //////////////////////////////////////// |
---|
2205 | void headerNode(xmlTextReaderPtr reader) |
---|
2206 | { |
---|
2207 | char * name; |
---|
2208 | unsigned int value; |
---|
2209 | unsigned int ok; |
---|
2210 | |
---|
2211 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
2212 | |
---|
2213 | #if XML_PARSER_DEBUG |
---|
2214 | printf("mapping_info\n"); |
---|
2215 | #endif |
---|
2216 | |
---|
2217 | header = (mapping_header_t *) malloc(sizeof(mapping_header_t)); |
---|
2218 | |
---|
2219 | ////////// get name attribute |
---|
2220 | name = getStringValue(reader, "name", &ok); |
---|
2221 | if (ok) |
---|
2222 | { |
---|
2223 | #if XML_PARSER_DEBUG |
---|
2224 | printf(" name = %s\n", name); |
---|
2225 | #endif |
---|
2226 | strncpy( header->name, name, 31); |
---|
2227 | } |
---|
2228 | else |
---|
2229 | { |
---|
2230 | printf("[XML ERROR] illegal or missing <name> attribute in header\n"); |
---|
2231 | exit(1); |
---|
2232 | } |
---|
2233 | |
---|
2234 | /////////// get x_width attribute |
---|
2235 | value = getIntValue(reader, "x_width", &ok); |
---|
2236 | if (ok) |
---|
2237 | { |
---|
2238 | #if XML_PARSER_DEBUG |
---|
2239 | printf(" x_width = %d\n", value); |
---|
2240 | #endif |
---|
2241 | header->x_width = value; |
---|
2242 | } |
---|
2243 | |
---|
2244 | /////////// get y_width attribute |
---|
2245 | value = getIntValue(reader, "y_width", &ok); |
---|
2246 | if (ok) |
---|
2247 | { |
---|
2248 | #if XML_PARSER_DEBUG |
---|
2249 | printf(" y_width = %d\n", value); |
---|
2250 | #endif |
---|
2251 | header->y_width = value; |
---|
2252 | } |
---|
2253 | |
---|
2254 | /////////// get x_size attribute |
---|
2255 | unsigned int x_size = getIntValue(reader, "x_size", &ok); |
---|
2256 | if (ok) |
---|
2257 | { |
---|
2258 | #if XML_PARSER_DEBUG |
---|
2259 | printf(" x_size = %d\n", x_size); |
---|
2260 | #endif |
---|
2261 | header->x_size = x_size; |
---|
2262 | } |
---|
2263 | else |
---|
2264 | { |
---|
2265 | printf("[XML ERROR] illegal or missing <x_size> attribute in header\n"); |
---|
2266 | exit(1); |
---|
2267 | } |
---|
2268 | |
---|
2269 | /////////// get y_size attribute |
---|
2270 | unsigned int y_size = getIntValue(reader, "y_size", &ok); |
---|
2271 | if (ok) |
---|
2272 | { |
---|
2273 | #if XML_PARSER_DEBUG |
---|
2274 | printf(" y_size = %d\n", y_size); |
---|
2275 | #endif |
---|
2276 | header->y_size = y_size; |
---|
2277 | } |
---|
2278 | else |
---|
2279 | { |
---|
2280 | printf("[XML ERROR] illegal or missing <y_size> attribute in header\n"); |
---|
2281 | exit(1); |
---|
2282 | } |
---|
2283 | |
---|
2284 | //check the number of cluster |
---|
2285 | if ( (x_size * y_size) >= MAX_CLUSTERS ) |
---|
2286 | { |
---|
2287 | printf("[XML ERROR] Number of clusters cannot be larger than %d\n", MAX_CLUSTERS); |
---|
2288 | exit(1); |
---|
2289 | } |
---|
2290 | |
---|
2291 | ///////// get vspaces attribute |
---|
2292 | value = getIntValue(reader, "vspaces", &ok); |
---|
2293 | if (ok) |
---|
2294 | { |
---|
2295 | if (value >= MAX_VSPACES) |
---|
2296 | { |
---|
2297 | printf("[XML ERROR] The number of vspaces is larger than %d\n", MAX_VSPACES); |
---|
2298 | exit(1); |
---|
2299 | } |
---|
2300 | #if XML_PARSER_DEBUG |
---|
2301 | printf(" vspaces = %d\n", value); |
---|
2302 | #endif |
---|
2303 | header->vspaces = value; |
---|
2304 | } |
---|
2305 | else |
---|
2306 | { |
---|
2307 | printf("[XML ERROR] illegal or missing <vspaces> attribute in mapping\n"); |
---|
2308 | exit(1); |
---|
2309 | } |
---|
2310 | |
---|
2311 | ///////// get increment attribute |
---|
2312 | value = getIntValue(reader, "increment", &ok); |
---|
2313 | if (ok) |
---|
2314 | { |
---|
2315 | if ( (value != 0x10000) && (value != 0x8000) && |
---|
2316 | (value != 0x4000) && (value != 0x2000) ) |
---|
2317 | |
---|
2318 | { |
---|
2319 | printf("[XML ERROR] The vseg increment must be one of the following: "); |
---|
2320 | printf(" 0x00010000 / 0x00008000 / 0x00004000 / 0x00002000"); |
---|
2321 | exit(1); |
---|
2322 | } |
---|
2323 | #if XML_PARSER_DEBUG |
---|
2324 | printf(" increment = %d\n", value); |
---|
2325 | #endif |
---|
2326 | header->increment = value; |
---|
2327 | } |
---|
2328 | else |
---|
2329 | { |
---|
2330 | printf("[XML ERROR] illegal or missing <increment> attribute in mapping\n"); |
---|
2331 | exit(1); |
---|
2332 | } |
---|
2333 | |
---|
2334 | ///////// get increment attribute |
---|
2335 | value = getIntValue(reader, "irq_per_proc", &ok); |
---|
2336 | if (ok) |
---|
2337 | { |
---|
2338 | #if XML_PARSER_DEBUG |
---|
2339 | printf(" irq_per_proc = %d\n", value); |
---|
2340 | #endif |
---|
2341 | header->irq_per_proc = value; |
---|
2342 | } |
---|
2343 | else |
---|
2344 | { |
---|
2345 | printf("[XML ERROR] illegal or missing <irq_per_proc> attribute in mapping\n"); |
---|
2346 | exit(1); |
---|
2347 | } |
---|
2348 | |
---|
2349 | //////// initialise non replicated peripherals cluster index |
---|
2350 | header->cma_cluster = 0xFFFFFFFF; |
---|
2351 | header->cma_cluster_bis = 0xFFFFFFFF; |
---|
2352 | |
---|
2353 | header->fbf_cluster = 0xFFFFFFFF; |
---|
2354 | header->fbf_cluster_bis = 0xFFFFFFFF; |
---|
2355 | |
---|
2356 | header->iob_cluster = 0xFFFFFFFF; |
---|
2357 | header->iob_cluster_bis = 0xFFFFFFFF; |
---|
2358 | |
---|
2359 | header->ioc_cluster = 0xFFFFFFFF; |
---|
2360 | header->ioc_cluster_bis = 0xFFFFFFFF; |
---|
2361 | |
---|
2362 | header->nic_cluster = 0xFFFFFFFF; |
---|
2363 | header->nic_cluster_bis = 0xFFFFFFFF; |
---|
2364 | |
---|
2365 | header->rom_cluster = 0xFFFFFFFF; |
---|
2366 | header->rom_cluster_bis = 0xFFFFFFFF; |
---|
2367 | |
---|
2368 | header->sim_cluster = 0xFFFFFFFF; |
---|
2369 | header->sim_cluster_bis = 0xFFFFFFFF; |
---|
2370 | |
---|
2371 | header->tty_cluster = 0xFFFFFFFF; |
---|
2372 | header->tty_cluster_bis = 0xFFFFFFFF; |
---|
2373 | |
---|
2374 | ///////// set signature |
---|
2375 | header->signature = IN_MAPPING_SIGNATURE; |
---|
2376 | |
---|
2377 | int status = xmlTextReaderRead(reader); |
---|
2378 | while (status == 1) |
---|
2379 | { |
---|
2380 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
2381 | |
---|
2382 | if (strcmp(tag, "clusterset") == 0) |
---|
2383 | { |
---|
2384 | clusterSetNode(reader); |
---|
2385 | } |
---|
2386 | else if (strcmp(tag, "globalset") == 0) { globalSetNode(reader); } |
---|
2387 | else if (strcmp(tag, "vspaceset") == 0) { vspaceSetNode(reader); } |
---|
2388 | else if (strcmp(tag, "#text") == 0) { } |
---|
2389 | else if (strcmp(tag, "#comment") == 0) { } |
---|
2390 | else if (strcmp(tag, "mapping_info") == 0) |
---|
2391 | { |
---|
2392 | #if XML_PARSER_DEBUG |
---|
2393 | printf("end mapping_info\n"); |
---|
2394 | #endif |
---|
2395 | return; |
---|
2396 | } |
---|
2397 | else |
---|
2398 | { |
---|
2399 | printf("[XML ERROR] Unknown tag in header node : %s\n",tag); |
---|
2400 | exit(1); |
---|
2401 | } |
---|
2402 | status = xmlTextReaderRead(reader); |
---|
2403 | } |
---|
2404 | } // end headerNode() |
---|
2405 | |
---|
2406 | |
---|
2407 | /////////////////////////////////////// |
---|
2408 | void BuildTable(int fdout, const char * type, unsigned int nb_elem, |
---|
2409 | unsigned int elem_size, char ** table) |
---|
2410 | { |
---|
2411 | unsigned int i; |
---|
2412 | // write element |
---|
2413 | for (i = 0; i < nb_elem; i++) { |
---|
2414 | if (elem_size != write(fdout, table[i], elem_size)) { |
---|
2415 | printf("function %s: %s(%d) write error \n", __FUNCTION__, type, i); |
---|
2416 | exit(1); |
---|
2417 | } |
---|
2418 | |
---|
2419 | #if XML_PARSER_DEBUG |
---|
2420 | printf("Building binary: writing %s %d\n", type, i); |
---|
2421 | #endif |
---|
2422 | } |
---|
2423 | } |
---|
2424 | |
---|
2425 | ///////////////////////////////////// |
---|
2426 | int open_file(const char * file_path) |
---|
2427 | { |
---|
2428 | //open file |
---|
2429 | int fdout = open( file_path, (O_CREAT | O_RDWR), (S_IWUSR | S_IRUSR) ); |
---|
2430 | if (fdout < 0) |
---|
2431 | { |
---|
2432 | perror("open"); |
---|
2433 | exit(1); |
---|
2434 | } |
---|
2435 | |
---|
2436 | //reinitialise the file |
---|
2437 | if (ftruncate(fdout, 0)) |
---|
2438 | { |
---|
2439 | perror("truncate"); |
---|
2440 | exit(1); |
---|
2441 | } |
---|
2442 | |
---|
2443 | //#if XML_PARSER_DEBUG |
---|
2444 | printf("%s\n", file_path); |
---|
2445 | //#endif |
---|
2446 | |
---|
2447 | return fdout; |
---|
2448 | } |
---|
2449 | |
---|
2450 | |
---|
2451 | ///////////////////////////////////// |
---|
2452 | void buildBin(const char * file_path) |
---|
2453 | { |
---|
2454 | unsigned int length; |
---|
2455 | |
---|
2456 | int fdout = open_file(file_path); |
---|
2457 | |
---|
2458 | #if XML_PARSER_DEBUG |
---|
2459 | printf("Building map.bin for %s\n", header->name); |
---|
2460 | printf("signature = %x\n", header->signature); |
---|
2461 | printf("x_size = %d\n", header->x_size); |
---|
2462 | printf("y_size = %d\n", header->y_size); |
---|
2463 | printf("x_width = %d\n", header->x_width); |
---|
2464 | printf("y_width = %d\n", header->y_width); |
---|
2465 | printf("vspaces = %d\n", header->vspaces); |
---|
2466 | printf("psegs = %d\n", header->psegs); |
---|
2467 | printf("vobjs = %d\n", header->vobjs); |
---|
2468 | printf("vsegs = %d\n", header->vsegs); |
---|
2469 | printf("tasks = %d\n", header->tasks); |
---|
2470 | printf("procs = %d\n", header->procs); |
---|
2471 | printf("irqs = %d\n", header->irqs); |
---|
2472 | printf("coprocs = %d\n", header->coprocs); |
---|
2473 | printf("periphs = %d\n", header->periphs); |
---|
2474 | #endif |
---|
2475 | |
---|
2476 | // write header to binary file |
---|
2477 | length = write(fdout, (char *) header, sizeof(mapping_header_t)); |
---|
2478 | if (length != sizeof(mapping_header_t)) |
---|
2479 | { |
---|
2480 | printf("write header error : length = %d \n", length); |
---|
2481 | exit(1); |
---|
2482 | } |
---|
2483 | |
---|
2484 | // write clusters |
---|
2485 | BuildTable(fdout, "cluster", cluster_index, sizeof(mapping_cluster_t), (char **) cluster); |
---|
2486 | // write psegs |
---|
2487 | BuildTable(fdout, "pseg", pseg_index, sizeof(mapping_pseg_t), (char **) pseg); |
---|
2488 | // write vspaces |
---|
2489 | BuildTable(fdout, "vspace", vspace_index, sizeof(mapping_vspace_t), (char **) vspace); |
---|
2490 | // write vsegs |
---|
2491 | BuildTable(fdout, "vseg", vseg_index, sizeof(mapping_vseg_t), (char **) vseg); |
---|
2492 | // write vobjs |
---|
2493 | BuildTable(fdout, "vobj", vobj_index, sizeof(mapping_vobj_t), (char **) vobj); |
---|
2494 | // write tasks array |
---|
2495 | BuildTable(fdout, "task", task_index, sizeof(mapping_task_t), (char **) task); |
---|
2496 | //building procs array |
---|
2497 | BuildTable(fdout, "proc", proc_index, sizeof(mapping_proc_t), (char **) proc); |
---|
2498 | //building irqs array |
---|
2499 | BuildTable(fdout, "irq", irq_index, sizeof(mapping_irq_t), (char **) irq); |
---|
2500 | //building coprocs array |
---|
2501 | BuildTable(fdout, "coproc", coproc_index, sizeof(mapping_coproc_t), (char **) coproc); |
---|
2502 | //building cp_ports array |
---|
2503 | BuildTable(fdout, "cp_port", cp_port_index, sizeof(mapping_cp_port_t),(char **) cp_port); |
---|
2504 | //building periphs array |
---|
2505 | BuildTable(fdout, "periph", periph_index, sizeof(mapping_periph_t), (char **) periph); |
---|
2506 | |
---|
2507 | close(fdout); |
---|
2508 | |
---|
2509 | } // end buildBin() |
---|
2510 | |
---|
2511 | |
---|
2512 | /////////////////////////////////////////////////////////////////////// |
---|
2513 | // this function set the value the vobj_id fiels of all cp_ports |
---|
2514 | /////////////////////////////////////////////////////////////////////// |
---|
2515 | void prepareBuild() |
---|
2516 | { |
---|
2517 | unsigned int i; |
---|
2518 | //asign for all cp_ports the correct vspaceid and vobjid |
---|
2519 | for (i = 0; i < cp_port_index; i++) { |
---|
2520 | int vspace_id = getVspaceId(cp_port_vobj_ref[i]->vspace_name); |
---|
2521 | if (vspace_id < 0) { |
---|
2522 | printf("[XML ERROR] illegal <vspacename> for cp_port %d,\n", i); |
---|
2523 | exit(1); |
---|
2524 | } |
---|
2525 | cp_port[i]->vspaceid = vspace_id; |
---|
2526 | |
---|
2527 | int vobj_id = getVobjLocId(vspace_id, cp_port_vobj_ref[i]->vobj_name, vspace[vspace_id]->vobjs); |
---|
2528 | if (vobj_id >= 0) { |
---|
2529 | |
---|
2530 | #if XML_PARSER_DEBUG |
---|
2531 | printf("\ncp_port = %d\n", i); |
---|
2532 | printf(" vspace_name = %s\n", cp_port_vobj_ref[i]->vspace_name); |
---|
2533 | printf(" vobj_name = %s\n", cp_port_vobj_ref[i]->vobj_name); |
---|
2534 | printf(" vobj_index = %d\n", vobj_id); |
---|
2535 | #endif |
---|
2536 | cp_port[i]->mwmr_vobjid = vobj_id; |
---|
2537 | |
---|
2538 | assert((vobj[ vspace[vspace_id]->vobj_offset + vobj_id]->type == VOBJ_TYPE_MWMR) |
---|
2539 | && "coproc ports have to refer to a vobj of type MWMR"); |
---|
2540 | } |
---|
2541 | else { |
---|
2542 | printf("[XML ERROR] illegal <vobjname> for cp_port %d,\n", i); |
---|
2543 | exit(1); |
---|
2544 | } |
---|
2545 | } |
---|
2546 | } |
---|
2547 | |
---|
2548 | ////////////////////////////////////////// |
---|
2549 | void file_write(int fdout, char * towrite) |
---|
2550 | { |
---|
2551 | unsigned int size = strlen(towrite); |
---|
2552 | if (size != write(fdout, towrite, size)) |
---|
2553 | { |
---|
2554 | printf("file_write error"); |
---|
2555 | exit(1); |
---|
2556 | } |
---|
2557 | } |
---|
2558 | |
---|
2559 | ////////////////////////////////////////////////// |
---|
2560 | void def_int_write(int fdout, char * def, int num) |
---|
2561 | { |
---|
2562 | char buf[64]; |
---|
2563 | sprintf(buf, "#define\t %s %d\n", def, num); |
---|
2564 | file_write(fdout, buf); |
---|
2565 | } |
---|
2566 | |
---|
2567 | ////////////////////////////////////////////////// |
---|
2568 | void def_hex_write(int fdout, char * def, int num) |
---|
2569 | { |
---|
2570 | char buf[64]; |
---|
2571 | sprintf(buf, "#define\t %s 0x%x\n", def, num); |
---|
2572 | file_write(fdout, buf); |
---|
2573 | } |
---|
2574 | |
---|
2575 | /////////////////////////////////// |
---|
2576 | void genHd(const char * file_path) |
---|
2577 | { |
---|
2578 | int fdout = open_file(file_path); |
---|
2579 | |
---|
2580 | char prol[80]; |
---|
2581 | sprintf(prol, "/* Generated from file %s.xml */\n\n",header->name); |
---|
2582 | |
---|
2583 | char * ifdef = "#ifndef _HARD_CONFIG_H\n#define _HARD_CONFIG_H\n\n"; |
---|
2584 | char * epil = "\n#endif //_HARD_CONFIG_H"; |
---|
2585 | |
---|
2586 | file_write(fdout, prol); |
---|
2587 | file_write(fdout, ifdef); |
---|
2588 | |
---|
2589 | def_int_write(fdout, "X_SIZE ", header->x_size); |
---|
2590 | def_int_write(fdout, "Y_SIZE ", header->y_size); |
---|
2591 | def_int_write(fdout, "X_WIDTH ", header->x_width); |
---|
2592 | def_int_write(fdout, "Y_WIDTH ", header->y_width); |
---|
2593 | |
---|
2594 | file_write(fdout, "\n"); |
---|
2595 | |
---|
2596 | def_int_write(fdout, "NB_PROCS_MAX ", nb_proc_max); |
---|
2597 | def_int_write(fdout, "NB_TASKS_MAX ", nb_tasks_max); |
---|
2598 | |
---|
2599 | file_write(fdout, "\n"); |
---|
2600 | |
---|
2601 | def_int_write(fdout, "NB_TIM_CHANNELS ", tim_channels); |
---|
2602 | def_int_write(fdout, "NB_DMA_CHANNELS ", dma_channels); |
---|
2603 | |
---|
2604 | file_write(fdout, "\n"); |
---|
2605 | |
---|
2606 | def_int_write(fdout, "NB_TTY_CHANNELS ", tty_channels); |
---|
2607 | def_int_write(fdout, "NB_HBA_CHANNELS ", hba_channels); |
---|
2608 | def_int_write(fdout, "NB_NIC_CHANNELS ", nic_channels); |
---|
2609 | def_int_write(fdout, "NB_CMA_CHANNELS ", cma_channels); |
---|
2610 | |
---|
2611 | file_write(fdout, "\n"); |
---|
2612 | |
---|
2613 | def_int_write(fdout, "USE_XICU ", use_xcu); |
---|
2614 | def_int_write(fdout, "USE_IOB ", use_iob); |
---|
2615 | def_int_write(fdout, "USE_HBA ", use_hba); |
---|
2616 | def_int_write(fdout, "USE_BDV ", use_bdv); |
---|
2617 | def_int_write(fdout, "USE_SPI ", use_spi); |
---|
2618 | |
---|
2619 | file_write(fdout, "\n"); |
---|
2620 | |
---|
2621 | def_int_write(fdout, "IRQ_PER_PROCESSOR ", header->irq_per_proc); |
---|
2622 | |
---|
2623 | file_write(fdout, epil); |
---|
2624 | |
---|
2625 | close(fdout); |
---|
2626 | } |
---|
2627 | |
---|
2628 | //////////////////////////////////////////////////////// |
---|
2629 | void ld_write(int fdout, char * seg, unsigned int addr) |
---|
2630 | { |
---|
2631 | char buf[64]; |
---|
2632 | sprintf(buf, "%s = 0x%x;\n", seg, addr); |
---|
2633 | file_write(fdout, buf); |
---|
2634 | } |
---|
2635 | |
---|
2636 | ////////////////////////////////// |
---|
2637 | void genLd(const char * file_path) |
---|
2638 | { |
---|
2639 | int fdout = open_file(file_path); |
---|
2640 | unsigned int count = 0; |
---|
2641 | unsigned int vseg_id; |
---|
2642 | unsigned int base; // vseg base |
---|
2643 | unsigned int size; // vseg size |
---|
2644 | |
---|
2645 | char prol[80]; |
---|
2646 | sprintf(prol, "/* Generated from file %s.xml */\n\n",header->name); |
---|
2647 | |
---|
2648 | file_write(fdout, prol); |
---|
2649 | |
---|
2650 | // boot and kernel segments |
---|
2651 | for (vseg_id = 0 ; vseg_id < header->vsegs ; vseg_id++) |
---|
2652 | { |
---|
2653 | if ( strcmp(vseg[vseg_id]->name, "seg_boot_code") == 0 ) |
---|
2654 | { |
---|
2655 | base = vseg[vseg_id]->vbase; |
---|
2656 | size = vobj[vseg[vseg_id]->vobj_offset]->length; |
---|
2657 | ld_write(fdout, "seg_boot_code_base ", base); |
---|
2658 | ld_write(fdout, "seg_boot_code_size ", size); |
---|
2659 | count++; |
---|
2660 | } |
---|
2661 | else if ( strcmp(vseg[vseg_id]->name, "seg_boot_data") == 0 ) |
---|
2662 | { |
---|
2663 | base = vseg[vseg_id]->vbase; |
---|
2664 | size = vobj[vseg[vseg_id]->vobj_offset]->length; |
---|
2665 | ld_write(fdout, "seg_boot_data_base ", base); |
---|
2666 | ld_write(fdout, "seg_boot_data_size ", size); |
---|
2667 | count++; |
---|
2668 | } |
---|
2669 | else if ( strcmp(vseg[vseg_id]->name, "seg_boot_stack") == 0 ) |
---|
2670 | { |
---|
2671 | base = vseg[vseg_id]->vbase; |
---|
2672 | size = vobj[vseg[vseg_id]->vobj_offset]->length; |
---|
2673 | ld_write(fdout, "seg_boot_stack_base ", base); |
---|
2674 | ld_write(fdout, "seg_boot_stack_size ", size); |
---|
2675 | count++; |
---|
2676 | } |
---|
2677 | else if ( strcmp(vseg[vseg_id]->name, "seg_boot_mapping") == 0 ) |
---|
2678 | { |
---|
2679 | base = vseg[vseg_id]->vbase; |
---|
2680 | size = vobj[vseg[vseg_id]->vobj_offset]->length; |
---|
2681 | ld_write(fdout, "seg_boot_mapping_base ", base); |
---|
2682 | ld_write(fdout, "seg_boot_mapping_size ", size); |
---|
2683 | count++; |
---|
2684 | } |
---|
2685 | else if ( strcmp(vseg[vseg_id]->name, "seg_boot_buffer") == 0 ) |
---|
2686 | { |
---|
2687 | base = vseg[vseg_id]->vbase; |
---|
2688 | size = vobj[vseg[vseg_id]->vobj_offset]->length; |
---|
2689 | ld_write(fdout, "seg_boot_buffer_base ", base); |
---|
2690 | ld_write(fdout, "seg_boot_buffer_size ", size); |
---|
2691 | count++; |
---|
2692 | } |
---|
2693 | else if ( strcmp(vseg[vseg_id]->name, "seg_kernel_code") == 0 ) |
---|
2694 | { |
---|
2695 | base = vseg[vseg_id]->vbase; |
---|
2696 | size = vobj[vseg[vseg_id]->vobj_offset]->length; |
---|
2697 | ld_write(fdout, "seg_kernel_code_base ", base); |
---|
2698 | ld_write(fdout, "seg_kernel_code_size ", size); |
---|
2699 | count++; |
---|
2700 | } |
---|
2701 | else if ( strcmp(vseg[vseg_id]->name, "seg_kernel_data") == 0 ) |
---|
2702 | { |
---|
2703 | base = vseg[vseg_id]->vbase; |
---|
2704 | size = vobj[vseg[vseg_id]->vobj_offset]->length; |
---|
2705 | ld_write(fdout, "seg_kernel_data_base ", base); |
---|
2706 | ld_write(fdout, "seg_kernel_data_size ", size); |
---|
2707 | count++; |
---|
2708 | } |
---|
2709 | else if ( strcmp(vseg[vseg_id]->name, "seg_kernel_uncdata") == 0 ) |
---|
2710 | { |
---|
2711 | base = vseg[vseg_id]->vbase; |
---|
2712 | size = vobj[vseg[vseg_id]->vobj_offset]->length; |
---|
2713 | ld_write(fdout, "seg_kernel_uncdata_base ", base); |
---|
2714 | ld_write(fdout, "seg_kernel_uncdata_size ", size); |
---|
2715 | count++; |
---|
2716 | } |
---|
2717 | else if ( strcmp(vseg[vseg_id]->name, "seg_kernel_init") == 0 ) |
---|
2718 | { |
---|
2719 | base = vseg[vseg_id]->vbase; |
---|
2720 | size = vobj[vseg[vseg_id]->vobj_offset]->length; |
---|
2721 | ld_write(fdout, "seg_kernel_init_base ", base); |
---|
2722 | ld_write(fdout, "seg_kernel_init_size ", size); |
---|
2723 | count++; |
---|
2724 | } |
---|
2725 | } |
---|
2726 | if ( count != 9 ) |
---|
2727 | { |
---|
2728 | printf ("[XML ERROR] Missing Boot or Kernel vseg : only %d\n", count); |
---|
2729 | printf ("Mandatory segments are :\n"); |
---|
2730 | printf (" - seg_boot_code\n"); |
---|
2731 | printf (" - seg_boot_data\n"); |
---|
2732 | printf (" - seg_boot_stack\n"); |
---|
2733 | printf (" - seg_boot_mapping\n"); |
---|
2734 | printf (" - seg_boot_buffer\n"); |
---|
2735 | printf (" - seg_kernel_code\n"); |
---|
2736 | printf (" - seg_kernel_data\n"); |
---|
2737 | printf (" - seg_kernel_uncdata\n"); |
---|
2738 | printf (" - seg_kernel_init\n"); |
---|
2739 | } |
---|
2740 | |
---|
2741 | file_write(fdout, "\n"); |
---|
2742 | |
---|
2743 | // fill the peripherals base address array |
---|
2744 | set_periph_vbase_array(); |
---|
2745 | |
---|
2746 | // non replicated peripherals |
---|
2747 | ld_write(fdout, "seg_cma_base ", periph_vbase_array[PERIPH_TYPE_CMA]); |
---|
2748 | ld_write(fdout, "seg_fbf_base ", periph_vbase_array[PERIPH_TYPE_FBF]); |
---|
2749 | ld_write(fdout, "seg_iob_base ", periph_vbase_array[PERIPH_TYPE_IOB]); |
---|
2750 | ld_write(fdout, "seg_ioc_base ", periph_vbase_array[PERIPH_TYPE_IOC]); |
---|
2751 | ld_write(fdout, "seg_nic_base ", periph_vbase_array[PERIPH_TYPE_NIC]); |
---|
2752 | ld_write(fdout, "seg_rom_base ", periph_vbase_array[PERIPH_TYPE_ROM]); |
---|
2753 | ld_write(fdout, "seg_sim_base ", periph_vbase_array[PERIPH_TYPE_SIM]); |
---|
2754 | ld_write(fdout, "seg_tty_base ", periph_vbase_array[PERIPH_TYPE_TTY]); |
---|
2755 | |
---|
2756 | file_write(fdout, "\n"); |
---|
2757 | |
---|
2758 | // replicated peripherals |
---|
2759 | ld_write(fdout, "seg_dma_base ", periph_vbase_array[PERIPH_TYPE_DMA]); |
---|
2760 | ld_write(fdout, "seg_icu_base ", periph_vbase_array[PERIPH_TYPE_ICU]); |
---|
2761 | ld_write(fdout, "seg_mmc_base ", periph_vbase_array[PERIPH_TYPE_MMC]); |
---|
2762 | ld_write(fdout, "seg_tim_base ", periph_vbase_array[PERIPH_TYPE_TIM]); |
---|
2763 | ld_write(fdout, "seg_xcu_base ", periph_vbase_array[PERIPH_TYPE_XCU]); |
---|
2764 | |
---|
2765 | file_write(fdout, "\n"); |
---|
2766 | |
---|
2767 | ld_write(fdout, "vseg_cluster_increment ", header->increment); |
---|
2768 | |
---|
2769 | close(fdout); |
---|
2770 | } |
---|
2771 | |
---|
2772 | ////////////////////////////////////////////////////// |
---|
2773 | char * buildPath(const char * path, const char * name) |
---|
2774 | { |
---|
2775 | char * res = calloc(strlen(path) + strlen(name) + 1, 1); |
---|
2776 | strcat(res, path); |
---|
2777 | strcat(res, "/"); |
---|
2778 | strcat(res, name); |
---|
2779 | return res; |
---|
2780 | } |
---|
2781 | |
---|
2782 | |
---|
2783 | ////////////////////////////////// |
---|
2784 | int main(int argc, char * argv[]) |
---|
2785 | { |
---|
2786 | if (argc < 3) { |
---|
2787 | printf("Usage: xml2bin <input_file_path> <output_path>\n"); |
---|
2788 | return 1; |
---|
2789 | } |
---|
2790 | |
---|
2791 | struct stat dir_st; |
---|
2792 | if (stat( argv[2], &dir_st)) { |
---|
2793 | perror("bad path"); |
---|
2794 | exit(1); |
---|
2795 | } |
---|
2796 | |
---|
2797 | if ((dir_st.st_mode & S_IFDIR) == 0) { |
---|
2798 | printf("path is not a dir: %s", argv[2] ); |
---|
2799 | exit(1); |
---|
2800 | } |
---|
2801 | |
---|
2802 | char * map_path = buildPath(argv[2], "map.bin"); |
---|
2803 | char * ld_path = buildPath(argv[2], "giet_vsegs.ld"); |
---|
2804 | char * hd_path = buildPath(argv[2], "hard_config.h"); |
---|
2805 | |
---|
2806 | LIBXML_TEST_VERSION; |
---|
2807 | |
---|
2808 | int status; |
---|
2809 | xmlTextReaderPtr reader = xmlReaderForFile(argv[1], NULL, 0); |
---|
2810 | |
---|
2811 | if (reader != NULL) |
---|
2812 | { |
---|
2813 | status = xmlTextReaderRead (reader); |
---|
2814 | while (status == 1) |
---|
2815 | { |
---|
2816 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
2817 | |
---|
2818 | if (strcmp(tag, "mapping_info") == 0) |
---|
2819 | { |
---|
2820 | headerNode(reader); |
---|
2821 | prepareBuild(); |
---|
2822 | buildBin(map_path); |
---|
2823 | genHd(hd_path); |
---|
2824 | genLd(ld_path); |
---|
2825 | } |
---|
2826 | else |
---|
2827 | { |
---|
2828 | printf("[XML ERROR] Wrong file type: \"%s\"\n", argv[1]); |
---|
2829 | return 1; |
---|
2830 | } |
---|
2831 | status = xmlTextReaderRead(reader); |
---|
2832 | } |
---|
2833 | xmlFreeTextReader(reader); |
---|
2834 | |
---|
2835 | if (status != 0) |
---|
2836 | { |
---|
2837 | printf("[XML ERROR] Wrong Syntax in \"%s\" file\n", argv[1]); |
---|
2838 | return 1; |
---|
2839 | } |
---|
2840 | } |
---|
2841 | return 0; |
---|
2842 | } // end main() |
---|
2843 | |
---|
2844 | |
---|
2845 | // Local Variables: |
---|
2846 | // tab-width: 4 |
---|
2847 | // c-basic-offset: 4 |
---|
2848 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
2849 | // indent-tabs-mode: nil |
---|
2850 | // End: |
---|
2851 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
2852 | |
---|