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