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