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