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, 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 | else |
---|
1629 | { |
---|
1630 | printf("[XML ERROR] illegal peripheral type: %s in cluster %d\n", |
---|
1631 | str, cluster_index); |
---|
1632 | exit(1); |
---|
1633 | } |
---|
1634 | |
---|
1635 | if (error) |
---|
1636 | { |
---|
1637 | printf("[XML ERROR] illegal peripheral %s in cluster %d\n", |
---|
1638 | str, cluster_index); |
---|
1639 | exit(1); |
---|
1640 | } |
---|
1641 | } |
---|
1642 | else |
---|
1643 | { |
---|
1644 | printf("[XML ERROR] illegal or missing <type> for peripheral %d in cluster %d\n", |
---|
1645 | periph_loc_index, cluster_index); |
---|
1646 | exit(1); |
---|
1647 | } |
---|
1648 | |
---|
1649 | ////////////// set irq_offset attribute |
---|
1650 | periph[periph_index]->irq_offset = irq_index; |
---|
1651 | |
---|
1652 | ///////////// get IRQs |
---|
1653 | int status = xmlTextReaderRead(reader); |
---|
1654 | while (status == 1) |
---|
1655 | { |
---|
1656 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
1657 | |
---|
1658 | if (strcmp(tag, "irq") == 0) |
---|
1659 | { |
---|
1660 | if ( (periph[periph_index]->type != PERIPH_TYPE_XCU) && |
---|
1661 | (periph[periph_index]->type != PERIPH_TYPE_PIC) ) |
---|
1662 | { |
---|
1663 | printf("[XML ERROR] periph %d in cluster(%d,%d) " |
---|
1664 | " only XCU and PIC can contain IRQs", |
---|
1665 | periph_loc_index, cluster[cluster_index]->x, cluster[cluster_index]->y); |
---|
1666 | exit(1); |
---|
1667 | } |
---|
1668 | else |
---|
1669 | { |
---|
1670 | irqNode(reader); |
---|
1671 | } |
---|
1672 | } |
---|
1673 | else if (strcmp(tag, "#text") == 0) { } |
---|
1674 | else if (strcmp(tag, "#comment") == 0) { } |
---|
1675 | else if (strcmp(tag, "periph") == 0) |
---|
1676 | { |
---|
1677 | periph[periph_index]->irqs = irq_loc_index; |
---|
1678 | cluster[cluster_index]->periphs++; |
---|
1679 | periph_loc_index++; |
---|
1680 | periph_index++; |
---|
1681 | |
---|
1682 | #if XML_PARSER_DEBUG |
---|
1683 | printf(" irqs = %d\n", irq_loc_index); |
---|
1684 | printf(" irq_offset = %d\n", irq_index); |
---|
1685 | #endif |
---|
1686 | return; |
---|
1687 | } |
---|
1688 | else |
---|
1689 | { |
---|
1690 | printf("[XML ERROR] Unknown tag %s", tag); |
---|
1691 | exit(1); |
---|
1692 | } |
---|
1693 | status = xmlTextReaderRead(reader); |
---|
1694 | } |
---|
1695 | } // end periphNode |
---|
1696 | |
---|
1697 | //////////////////////////////////////// |
---|
1698 | void coprocNode(xmlTextReaderPtr reader) |
---|
1699 | { |
---|
1700 | char * str; |
---|
1701 | unsigned int ok; |
---|
1702 | |
---|
1703 | cp_port_loc_index = 0; |
---|
1704 | |
---|
1705 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
1706 | |
---|
1707 | if (coproc_index >= MAX_COPROCS) |
---|
1708 | { |
---|
1709 | printf("[XML ERROR] The number of coprocs is larger than %d\n", MAX_COPROCS); |
---|
1710 | exit(1); |
---|
1711 | } |
---|
1712 | |
---|
1713 | #if XML_PARSER_DEBUG |
---|
1714 | printf("\n coproc %d\n", coproc_index); |
---|
1715 | #endif |
---|
1716 | |
---|
1717 | coproc[coproc_index] = (mapping_coproc_t *) malloc(sizeof(mapping_coproc_t)); |
---|
1718 | |
---|
1719 | /////////// get name attribute |
---|
1720 | str = getStringValue(reader, "name", &ok); |
---|
1721 | if (ok) |
---|
1722 | { |
---|
1723 | #if XML_PARSER_DEBUG |
---|
1724 | printf(" name = %s\n", str); |
---|
1725 | #endif |
---|
1726 | strncpy(coproc[coproc_index]->name, str, 31); |
---|
1727 | } |
---|
1728 | else |
---|
1729 | { |
---|
1730 | printf("[XML ERROR] illegal or missing <name> for coproc %d in cluster %d\n", |
---|
1731 | coproc_index, cluster_index); |
---|
1732 | exit(1); |
---|
1733 | } |
---|
1734 | |
---|
1735 | /////////// get psegname attribute |
---|
1736 | str = getStringValue(reader, "psegname", &ok); |
---|
1737 | if (ok == 0) |
---|
1738 | { |
---|
1739 | printf("[XML ERROR] illegal or missing <psegname> for coproc %d in cluster %d\n", |
---|
1740 | coproc_index, cluster_index); |
---|
1741 | exit(1); |
---|
1742 | } |
---|
1743 | |
---|
1744 | /////////// set psegid attribute |
---|
1745 | int index = getPsegId( cluster[cluster_index]->x, cluster[cluster_index]->y, str); |
---|
1746 | if (index >= 0) |
---|
1747 | { |
---|
1748 | #if XML_PARSER_DEBUG |
---|
1749 | printf(" clusterid = %d\n", cluster_index); |
---|
1750 | printf(" psegname = %s\n", str); |
---|
1751 | printf(" psegid = %d\n", index); |
---|
1752 | #endif |
---|
1753 | coproc[coproc_index]->psegid = index; |
---|
1754 | assert(pseg[index]->type == PSEG_TYPE_PERI && |
---|
1755 | "coproc psegname attribute must refer to a pseg of type PERI" ); |
---|
1756 | } |
---|
1757 | else |
---|
1758 | { |
---|
1759 | printf("[XML ERROR] pseg not found for coproc %d / clusterid = %d / psegname = %s\n", |
---|
1760 | coproc_index, cluster_index, str ); |
---|
1761 | exit(1); |
---|
1762 | } |
---|
1763 | |
---|
1764 | ////////// set port_offset |
---|
1765 | coproc[coproc_index]->port_offset = cp_port_index; |
---|
1766 | |
---|
1767 | #if XML_PARSER_DEBUG |
---|
1768 | printf(" port_offset = %d\n", cp_port_index); |
---|
1769 | #endif |
---|
1770 | |
---|
1771 | int status = xmlTextReaderRead(reader); |
---|
1772 | while (status == 1) |
---|
1773 | { |
---|
1774 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
1775 | |
---|
1776 | if (strcmp(tag, "port") == 0 ) |
---|
1777 | { |
---|
1778 | cpPortNode(reader); |
---|
1779 | } |
---|
1780 | else if (strcmp(tag, "#text") == 0 ) { } |
---|
1781 | else if (strcmp(tag, "#comment") == 0 ) { } |
---|
1782 | else if (strcmp(tag, "coproc") == 0 ) |
---|
1783 | { |
---|
1784 | coproc[coproc_index]->ports = cp_port_loc_index; |
---|
1785 | cluster[cluster_index]->coprocs++; |
---|
1786 | coproc_loc_index++; |
---|
1787 | coproc_index++; |
---|
1788 | return; |
---|
1789 | } |
---|
1790 | else |
---|
1791 | { |
---|
1792 | printf("[XML ERROR] Unknown tag %s", tag); |
---|
1793 | exit(1); |
---|
1794 | } |
---|
1795 | status = xmlTextReaderRead(reader); |
---|
1796 | } |
---|
1797 | } // end coprocNode() |
---|
1798 | |
---|
1799 | |
---|
1800 | ////////////////////////////////////// |
---|
1801 | void procNode(xmlTextReaderPtr reader) |
---|
1802 | { |
---|
1803 | unsigned int ok; |
---|
1804 | unsigned int value; |
---|
1805 | |
---|
1806 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
1807 | |
---|
1808 | if (proc_index >= MAX_PROCS) |
---|
1809 | { |
---|
1810 | printf("[XML ERROR] The number of procs is larger than %d\n", MAX_PROCS); |
---|
1811 | exit(1); |
---|
1812 | } |
---|
1813 | |
---|
1814 | #if XML_PARSER_DEBUG |
---|
1815 | printf("\n proc %d\n", proc_index); |
---|
1816 | #endif |
---|
1817 | |
---|
1818 | proc[proc_index] = (mapping_proc_t *) malloc(sizeof(mapping_proc_t)); |
---|
1819 | |
---|
1820 | /////////// get index attribute (optional) |
---|
1821 | value = getIntValue(reader, "index", &ok); |
---|
1822 | if (ok && (value != proc_loc_index)) |
---|
1823 | { |
---|
1824 | printf("[XML ERROR] wrong local proc index / expected value is %d", |
---|
1825 | proc_loc_index); |
---|
1826 | exit(1); |
---|
1827 | } |
---|
1828 | proc[proc_index]->index = proc_loc_index; |
---|
1829 | |
---|
1830 | cluster[cluster_index]->procs++; |
---|
1831 | proc_loc_index++; |
---|
1832 | proc_index++; |
---|
1833 | total_procs++; |
---|
1834 | } // end procNode() |
---|
1835 | |
---|
1836 | |
---|
1837 | ////////////////////////////////////// |
---|
1838 | void psegNode(xmlTextReaderPtr reader) |
---|
1839 | { |
---|
1840 | unsigned int ok; |
---|
1841 | paddr_t ll_value; |
---|
1842 | char * str; |
---|
1843 | |
---|
1844 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
1845 | |
---|
1846 | if (pseg_index >= MAX_PSEGS) |
---|
1847 | { |
---|
1848 | printf("[XML ERROR] The number of psegs is larger than %d\n", MAX_PSEGS); |
---|
1849 | exit(1); |
---|
1850 | } |
---|
1851 | |
---|
1852 | #if XML_PARSER_DEBUG |
---|
1853 | printf(" pseg %d\n", pseg_index); |
---|
1854 | #endif |
---|
1855 | |
---|
1856 | pseg[pseg_index] = (mapping_pseg_t *) malloc(sizeof(mapping_pseg_t)); |
---|
1857 | |
---|
1858 | /////// get name attribute |
---|
1859 | str = getStringValue(reader, "name", &ok); |
---|
1860 | #if XML_PARSER_DEBUG |
---|
1861 | printf(" name = %s\n", str); |
---|
1862 | #endif |
---|
1863 | if (ok) |
---|
1864 | { |
---|
1865 | strncpy(pseg[pseg_index]->name, str, 31); |
---|
1866 | } |
---|
1867 | else |
---|
1868 | { |
---|
1869 | printf("[XML ERROR] illegal or missing <name> for pseg %d in cluster %d\n", |
---|
1870 | pseg_index, cluster_index); |
---|
1871 | exit(1); |
---|
1872 | } |
---|
1873 | |
---|
1874 | //////// get type attribute |
---|
1875 | str = getStringValue(reader, "type", &ok); |
---|
1876 | #if XML_PARSER_DEBUG |
---|
1877 | printf(" type = %s\n", str); |
---|
1878 | #endif |
---|
1879 | if (ok && (strcmp(str, "RAM" ) == 0)) { pseg[pseg_index]->type = PSEG_TYPE_RAM; } |
---|
1880 | else if (ok && (strcmp(str, "ROM" ) == 0)) { pseg[pseg_index]->type = PSEG_TYPE_ROM; } |
---|
1881 | else if (ok && (strcmp(str, "PERI") == 0)) { pseg[pseg_index]->type = PSEG_TYPE_PERI; } |
---|
1882 | else |
---|
1883 | { |
---|
1884 | printf("[XML ERROR] illegal or missing <type> for pseg %s in cluster %d\n", |
---|
1885 | pseg[pseg_index]->name, cluster_index); |
---|
1886 | exit(1); |
---|
1887 | } |
---|
1888 | |
---|
1889 | //////// get base attribute |
---|
1890 | ll_value = getPaddrValue(reader, "base", &ok); |
---|
1891 | #if XML_PARSER_DEBUG |
---|
1892 | printf(" base = 0x%llx\n", ll_value); |
---|
1893 | #endif |
---|
1894 | if (ok) |
---|
1895 | { |
---|
1896 | pseg[pseg_index]->base = ll_value; |
---|
1897 | } |
---|
1898 | else { |
---|
1899 | printf("[XML ERROR] illegal or missing <base> for pseg %s in cluster %d\n", |
---|
1900 | pseg[pseg_index]->name, cluster_index); |
---|
1901 | exit(1); |
---|
1902 | } |
---|
1903 | |
---|
1904 | //////// get length attribute |
---|
1905 | ll_value = getPaddrValue(reader, "length", &ok); |
---|
1906 | #if XML_PARSER_DEBUG |
---|
1907 | printf(" length = 0x%llx\n", ll_value); |
---|
1908 | #endif |
---|
1909 | if (ok) |
---|
1910 | { |
---|
1911 | pseg[pseg_index]->length = ll_value; |
---|
1912 | } |
---|
1913 | else |
---|
1914 | { |
---|
1915 | printf("[XML ERROR] illegal or missing <length> for pseg %s in cluster %d\n", |
---|
1916 | pseg[pseg_index]->name, cluster_index); |
---|
1917 | exit(1); |
---|
1918 | } |
---|
1919 | |
---|
1920 | //////// set cluster attribute |
---|
1921 | pseg[pseg_index]->clusterid = cluster_index; |
---|
1922 | |
---|
1923 | //////// set next_vseg attribute |
---|
1924 | pseg[pseg_index]->next_vseg = 0; |
---|
1925 | |
---|
1926 | pseg_index++; |
---|
1927 | cluster[cluster_index]->psegs++; |
---|
1928 | } // end psegNode() |
---|
1929 | |
---|
1930 | |
---|
1931 | ///////////////////////////////////////// |
---|
1932 | void clusterNode(xmlTextReaderPtr reader) |
---|
1933 | { |
---|
1934 | unsigned int ok; |
---|
1935 | unsigned int value; |
---|
1936 | |
---|
1937 | cluster[cluster_index] = (mapping_cluster_t *) malloc(sizeof(mapping_cluster_t)); |
---|
1938 | |
---|
1939 | //initialise variables that will be incremented by *Node() functions |
---|
1940 | cluster[cluster_index]->psegs = 0; |
---|
1941 | cluster[cluster_index]->procs = 0; |
---|
1942 | cluster[cluster_index]->coprocs = 0; |
---|
1943 | cluster[cluster_index]->periphs = 0; |
---|
1944 | |
---|
1945 | //initialise global variables |
---|
1946 | proc_loc_index = 0; |
---|
1947 | coproc_loc_index = 0; |
---|
1948 | periph_loc_index = 0; |
---|
1949 | |
---|
1950 | // for replicated periph |
---|
1951 | found_timer = 0; |
---|
1952 | found_icu = 0; |
---|
1953 | found_xcu = 0; |
---|
1954 | found_dma = 0; |
---|
1955 | found_mmc = 0; |
---|
1956 | |
---|
1957 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
1958 | |
---|
1959 | #if XML_PARSER_DEBUG |
---|
1960 | printf("\n cluster %d\n", cluster_index); |
---|
1961 | #endif |
---|
1962 | |
---|
1963 | /////////// get x coordinate |
---|
1964 | value = getIntValue(reader, "x", &ok); |
---|
1965 | #if XML_PARSER_DEBUG |
---|
1966 | printf(" x = %d\n", value); |
---|
1967 | #endif |
---|
1968 | if (ok && (value < header->x_size) ) |
---|
1969 | { |
---|
1970 | cluster[cluster_index]->x = value; |
---|
1971 | } |
---|
1972 | else |
---|
1973 | { |
---|
1974 | printf("[XML ERROR] Illegal or missing < x > attribute for cluster %d", |
---|
1975 | cluster_index); |
---|
1976 | exit(1); |
---|
1977 | } |
---|
1978 | |
---|
1979 | /////////// get y coordinate |
---|
1980 | value = getIntValue(reader, "y", &ok); |
---|
1981 | #if XML_PARSER_DEBUG |
---|
1982 | printf(" y = %d\n", value); |
---|
1983 | #endif |
---|
1984 | if (ok && (value < header->y_size) ) |
---|
1985 | { |
---|
1986 | cluster[cluster_index]->y = value; |
---|
1987 | } |
---|
1988 | else |
---|
1989 | { |
---|
1990 | printf("[XML ERROR] Illegal or missing < y > attribute for cluster %d", |
---|
1991 | cluster_index); |
---|
1992 | exit(1); |
---|
1993 | } |
---|
1994 | |
---|
1995 | ////////// set offsets |
---|
1996 | cluster[cluster_index]->pseg_offset = pseg_index; |
---|
1997 | cluster[cluster_index]->proc_offset = proc_index; |
---|
1998 | cluster[cluster_index]->coproc_offset = coproc_index; |
---|
1999 | cluster[cluster_index]->periph_offset = periph_index; |
---|
2000 | |
---|
2001 | #if XML_PARSER_DEBUG |
---|
2002 | printf(" pseg_offset = %d\n", pseg_index); |
---|
2003 | printf(" proc_offset = %d\n", proc_index); |
---|
2004 | printf(" coproc_offset = %d\n", coproc_index); |
---|
2005 | printf(" periph_offset = %d\n", coproc_index); |
---|
2006 | #endif |
---|
2007 | |
---|
2008 | ////////// get psegs, procs, coprocs and periphs |
---|
2009 | int status = xmlTextReaderRead(reader); |
---|
2010 | |
---|
2011 | while (status == 1) |
---|
2012 | { |
---|
2013 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
2014 | |
---|
2015 | if (strcmp(tag, "pseg") == 0) psegNode(reader); |
---|
2016 | else if (strcmp(tag, "proc") == 0) procNode(reader); |
---|
2017 | else if (strcmp(tag, "coproc") == 0) coprocNode(reader); |
---|
2018 | else if (strcmp(tag, "periph") == 0) periphNode(reader); |
---|
2019 | else if (strcmp(tag, "#text") == 0) { } |
---|
2020 | else if (strcmp(tag, "#comment") == 0) { } |
---|
2021 | else if (strcmp(tag, "cluster") == 0) |
---|
2022 | { |
---|
2023 | ///////// TIMER and ICU peripheral are mandatory when nprocs != 0 |
---|
2024 | |
---|
2025 | unsigned int procs = cluster[cluster_index]->procs; |
---|
2026 | if ( procs && !found_timer && !found_xcu) |
---|
2027 | { |
---|
2028 | printf("[XML ERROR] missing timer peripheral in cluster %d\n", cluster_index); |
---|
2029 | exit(1); |
---|
2030 | } |
---|
2031 | |
---|
2032 | if ( procs && !found_icu && !found_xcu) |
---|
2033 | { |
---|
2034 | printf("[XML ERROR] missing icu peripheral in cluster %d\n", cluster_index); |
---|
2035 | exit(1); |
---|
2036 | } |
---|
2037 | |
---|
2038 | if (nb_procs_max < procs) nb_procs_max = procs; |
---|
2039 | |
---|
2040 | #if XML_PARSER_DEBUG |
---|
2041 | printf(" psegs = %d\n", cluster[cluster_index]->psegs); |
---|
2042 | printf(" procs = %d\n", cluster[cluster_index]->procs); |
---|
2043 | printf(" coprocs = %d\n", cluster[cluster_index]->coprocs); |
---|
2044 | printf(" periphs = %d\n", cluster[cluster_index]->periphs); |
---|
2045 | printf(" end cluster %d\n", cluster_index); |
---|
2046 | #endif |
---|
2047 | cluster_index++; |
---|
2048 | return; |
---|
2049 | } |
---|
2050 | status = xmlTextReaderRead(reader); |
---|
2051 | } |
---|
2052 | } // end clusterNode() |
---|
2053 | |
---|
2054 | |
---|
2055 | ////////////////////////////////////////////// |
---|
2056 | void clusterSetNode(xmlTextReaderPtr reader) |
---|
2057 | { |
---|
2058 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
2059 | |
---|
2060 | #if XML_PARSER_DEBUG |
---|
2061 | printf("\n clusters set\n"); |
---|
2062 | #endif |
---|
2063 | |
---|
2064 | int status = xmlTextReaderRead(reader); |
---|
2065 | while (status == 1) |
---|
2066 | { |
---|
2067 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
2068 | |
---|
2069 | if (strcmp(tag, "cluster") == 0) { clusterNode(reader); } |
---|
2070 | else if (strcmp(tag, "#text") == 0) { } |
---|
2071 | else if (strcmp(tag, "#comment") == 0) { } |
---|
2072 | else if (strcmp(tag, "clusterset") == 0) |
---|
2073 | { |
---|
2074 | // checking number of clusters |
---|
2075 | if ( cluster_index != (header->x_size * header->y_size) ) |
---|
2076 | { |
---|
2077 | printf("[XML ERROR] Wrong number of clusters\n"); |
---|
2078 | exit(1); |
---|
2079 | } |
---|
2080 | |
---|
2081 | // checking TTY terminal for system boot |
---|
2082 | if ( tty_channels == 0 ) |
---|
2083 | { |
---|
2084 | printf("[XML ERROR] missing TTY peripheral\n"); |
---|
2085 | exit(1); |
---|
2086 | } |
---|
2087 | |
---|
2088 | // checking IOC sub-types |
---|
2089 | if ( (use_bdv + use_hba + use_spi) > 1 ) |
---|
2090 | { |
---|
2091 | printf("[XML ERROR] all IOC peripherals must have the same type\n"); |
---|
2092 | exit(1); |
---|
2093 | } |
---|
2094 | |
---|
2095 | #if XML_PARSER_DEBUG |
---|
2096 | printf(" end cluster set\n\n"); |
---|
2097 | #endif |
---|
2098 | header->psegs = pseg_index; |
---|
2099 | header->procs = proc_index; |
---|
2100 | header->irqs = irq_index; |
---|
2101 | header->coprocs = coproc_index; |
---|
2102 | header->cp_ports = cp_port_index; |
---|
2103 | header->periphs = periph_index; |
---|
2104 | return; |
---|
2105 | } |
---|
2106 | else |
---|
2107 | { |
---|
2108 | printf("[XML ERROR] Unknown tag in clusterset node : %s",tag); |
---|
2109 | exit(1); |
---|
2110 | } |
---|
2111 | status = xmlTextReaderRead(reader); |
---|
2112 | } |
---|
2113 | } // end clusterSetNode() |
---|
2114 | |
---|
2115 | |
---|
2116 | /////////////////////////////////////////// |
---|
2117 | void globalSetNode(xmlTextReaderPtr reader) |
---|
2118 | { |
---|
2119 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
2120 | |
---|
2121 | #if XML_PARSER_DEBUG |
---|
2122 | printf(" globals set\n"); |
---|
2123 | #endif |
---|
2124 | |
---|
2125 | int status = xmlTextReaderRead(reader); |
---|
2126 | while (status == 1) |
---|
2127 | { |
---|
2128 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
2129 | |
---|
2130 | if (strcmp(tag, "vseg") == 0) |
---|
2131 | { |
---|
2132 | vsegNode( reader ); |
---|
2133 | header->globals = header->globals + 1; |
---|
2134 | } |
---|
2135 | else if (strcmp(tag, "#text") == 0) { } |
---|
2136 | else if (strcmp(tag, "#comment") == 0) { } |
---|
2137 | else if (strcmp(tag, "globalset") == 0) |
---|
2138 | { |
---|
2139 | #if XML_PARSER_DEBUG |
---|
2140 | printf(" end global set\n\n"); |
---|
2141 | #endif |
---|
2142 | vseg_loc_index = 0; |
---|
2143 | return; |
---|
2144 | } |
---|
2145 | else |
---|
2146 | { |
---|
2147 | printf("[XML ERROR] Unknown tag in globalset node : %s",tag); |
---|
2148 | exit(1); |
---|
2149 | } |
---|
2150 | status = xmlTextReaderRead(reader); |
---|
2151 | } |
---|
2152 | } // end globalSetNode() |
---|
2153 | |
---|
2154 | |
---|
2155 | /////////////////////////////////////////// |
---|
2156 | void vspaceSetNode(xmlTextReaderPtr reader) |
---|
2157 | { |
---|
2158 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { |
---|
2159 | return; |
---|
2160 | } |
---|
2161 | |
---|
2162 | #if XML_PARSER_DEBUG |
---|
2163 | printf("\n vspaces set\n"); |
---|
2164 | #endif |
---|
2165 | |
---|
2166 | int status = xmlTextReaderRead ( reader ); |
---|
2167 | while (status == 1) { |
---|
2168 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
2169 | |
---|
2170 | if (strcmp(tag, "vspace") == 0) { |
---|
2171 | vspaceNode(reader); |
---|
2172 | } |
---|
2173 | else if (strcmp(tag, "#text" ) == 0 ) { } |
---|
2174 | else if (strcmp(tag, "#comment" ) == 0 ) { } |
---|
2175 | else if (strcmp(tag, "vspaceset") == 0 ) |
---|
2176 | { |
---|
2177 | header->vsegs = vseg_index; |
---|
2178 | header->vobjs = vobj_index; |
---|
2179 | header->tasks = task_index; |
---|
2180 | return; |
---|
2181 | } |
---|
2182 | else |
---|
2183 | { |
---|
2184 | printf("[XML ERROR] Unknown tag in vspaceset node : %s",tag); |
---|
2185 | exit(1); |
---|
2186 | } |
---|
2187 | status = xmlTextReaderRead(reader); |
---|
2188 | } |
---|
2189 | } // end globalSetNode() |
---|
2190 | |
---|
2191 | |
---|
2192 | //////////////////////////////////////// |
---|
2193 | void headerNode(xmlTextReaderPtr reader) |
---|
2194 | { |
---|
2195 | char * name; |
---|
2196 | unsigned int value; |
---|
2197 | unsigned int ok; |
---|
2198 | |
---|
2199 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) return; |
---|
2200 | |
---|
2201 | #if XML_PARSER_DEBUG |
---|
2202 | printf("mapping_info\n"); |
---|
2203 | #endif |
---|
2204 | |
---|
2205 | header = (mapping_header_t *) malloc(sizeof(mapping_header_t)); |
---|
2206 | |
---|
2207 | ////////// get name attribute |
---|
2208 | name = getStringValue(reader, "name", &ok); |
---|
2209 | if (ok) |
---|
2210 | { |
---|
2211 | #if XML_PARSER_DEBUG |
---|
2212 | printf(" name = %s\n", name); |
---|
2213 | #endif |
---|
2214 | strncpy( header->name, name, 31); |
---|
2215 | } |
---|
2216 | else |
---|
2217 | { |
---|
2218 | printf("[XML ERROR] illegal or missing <name> attribute in header\n"); |
---|
2219 | exit(1); |
---|
2220 | } |
---|
2221 | |
---|
2222 | /////////// get signature attribute |
---|
2223 | value = getIntValue(reader, "signature", &ok); |
---|
2224 | if ( ok && (value == IN_MAPPING_SIGNATURE) ) |
---|
2225 | { |
---|
2226 | #if XML_PARSER_DEBUG |
---|
2227 | printf(" signature = %x\n", value); |
---|
2228 | #endif |
---|
2229 | header->signature = IN_MAPPING_SIGNATURE; |
---|
2230 | } |
---|
2231 | else |
---|
2232 | { |
---|
2233 | printf("[XML ERROR] illegal or missing <signature> for mapping %s\n", |
---|
2234 | header->name ); |
---|
2235 | exit(1); |
---|
2236 | } |
---|
2237 | |
---|
2238 | /////////// get x_width attribute |
---|
2239 | value = getIntValue(reader, "x_width", &ok); |
---|
2240 | if (ok) |
---|
2241 | { |
---|
2242 | #if XML_PARSER_DEBUG |
---|
2243 | printf(" x_width = %d\n", value); |
---|
2244 | #endif |
---|
2245 | header->x_width = value; |
---|
2246 | } |
---|
2247 | |
---|
2248 | /////////// get y_width attribute |
---|
2249 | value = getIntValue(reader, "y_width", &ok); |
---|
2250 | if (ok) |
---|
2251 | { |
---|
2252 | #if XML_PARSER_DEBUG |
---|
2253 | printf(" y_width = %d\n", value); |
---|
2254 | #endif |
---|
2255 | header->y_width = value; |
---|
2256 | } |
---|
2257 | |
---|
2258 | /////////// get x_size attribute |
---|
2259 | unsigned int x_size = getIntValue(reader, "x_size", &ok); |
---|
2260 | if (ok) |
---|
2261 | { |
---|
2262 | #if XML_PARSER_DEBUG |
---|
2263 | printf(" x_size = %d\n", x_size); |
---|
2264 | #endif |
---|
2265 | header->x_size = x_size; |
---|
2266 | } |
---|
2267 | else |
---|
2268 | { |
---|
2269 | printf("[XML ERROR] illegal or missing <x_size> attribute in header\n"); |
---|
2270 | exit(1); |
---|
2271 | } |
---|
2272 | |
---|
2273 | /////////// get y_size attribute |
---|
2274 | unsigned int y_size = getIntValue(reader, "y_size", &ok); |
---|
2275 | if (ok) |
---|
2276 | { |
---|
2277 | #if XML_PARSER_DEBUG |
---|
2278 | printf(" y_size = %d\n", y_size); |
---|
2279 | #endif |
---|
2280 | header->y_size = y_size; |
---|
2281 | } |
---|
2282 | else |
---|
2283 | { |
---|
2284 | printf("[XML ERROR] illegal or missing <y_size> attribute in header\n"); |
---|
2285 | exit(1); |
---|
2286 | } |
---|
2287 | |
---|
2288 | /////////// get x_io attribute |
---|
2289 | unsigned int x_io = getIntValue(reader, "x_io", &ok); |
---|
2290 | #if XML_PARSER_DEBUG |
---|
2291 | printf(" x_io = %d\n", x_io); |
---|
2292 | #endif |
---|
2293 | if ( ok && (x_io < x_size) ) |
---|
2294 | { |
---|
2295 | header->x_io = x_io; |
---|
2296 | } |
---|
2297 | else |
---|
2298 | { |
---|
2299 | printf("[XML ERROR] illegal or missing <x_io> attribute in header\n"); |
---|
2300 | exit(1); |
---|
2301 | } |
---|
2302 | |
---|
2303 | /////////// get y_io attribute |
---|
2304 | unsigned int y_io = getIntValue(reader, "y_io", &ok); |
---|
2305 | #if XML_PARSER_DEBUG |
---|
2306 | printf(" y_io = %d\n", y_io); |
---|
2307 | #endif |
---|
2308 | if ( ok &&(y_io < y_size) ) |
---|
2309 | { |
---|
2310 | header->y_io = y_io; |
---|
2311 | } |
---|
2312 | else |
---|
2313 | { |
---|
2314 | printf("[XML ERROR] illegal or missing <y_io> attribute in header\n"); |
---|
2315 | exit(1); |
---|
2316 | } |
---|
2317 | |
---|
2318 | // check the number of cluster |
---|
2319 | if ( (x_size * y_size) >= MAX_CLUSTERS ) |
---|
2320 | { |
---|
2321 | printf("[XML ERROR] Number of clusters cannot be larger than %d\n", MAX_CLUSTERS); |
---|
2322 | exit(1); |
---|
2323 | } |
---|
2324 | |
---|
2325 | ///////// get irq_per_proc attribute |
---|
2326 | value = getIntValue(reader, "irq_per_proc", &ok); |
---|
2327 | if (ok) |
---|
2328 | { |
---|
2329 | #if XML_PARSER_DEBUG |
---|
2330 | printf(" irq_per_proc = %d\n", value); |
---|
2331 | #endif |
---|
2332 | header->irq_per_proc = value; |
---|
2333 | } |
---|
2334 | else |
---|
2335 | { |
---|
2336 | printf("[XML ERROR] illegal or missing <irq_per_proc> attribute in mapping\n"); |
---|
2337 | exit(1); |
---|
2338 | } |
---|
2339 | |
---|
2340 | ///////// get use_ram_disk attribute (default = 0) |
---|
2341 | value = getIntValue(reader, "use_ram_disk", &ok); |
---|
2342 | if (ok) |
---|
2343 | { |
---|
2344 | #if XML_PARSER_DEBUG |
---|
2345 | printf(" use_ram_disk = %d\n", value); |
---|
2346 | #endif |
---|
2347 | header->use_ram_disk = value; |
---|
2348 | } |
---|
2349 | else |
---|
2350 | { |
---|
2351 | header->use_ram_disk = 0; |
---|
2352 | } |
---|
2353 | |
---|
2354 | ///////// set other header fields |
---|
2355 | header->globals = 0; |
---|
2356 | header->vspaces = 0; |
---|
2357 | header->psegs = 0; |
---|
2358 | header->vsegs = 0; |
---|
2359 | header->vobjs = 0; |
---|
2360 | header->tasks = 0; |
---|
2361 | header->procs = 0; |
---|
2362 | header->irqs = 0; |
---|
2363 | header->coprocs = 0; |
---|
2364 | header->cp_ports = 0; |
---|
2365 | header->periphs = 0; |
---|
2366 | |
---|
2367 | |
---|
2368 | int status = xmlTextReaderRead(reader); |
---|
2369 | while (status == 1) |
---|
2370 | { |
---|
2371 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
2372 | |
---|
2373 | if (strcmp(tag, "clusterset") == 0) { clusterSetNode(reader); } |
---|
2374 | else if (strcmp(tag, "globalset") == 0) { globalSetNode(reader); } |
---|
2375 | else if (strcmp(tag, "vspaceset") == 0) { vspaceSetNode(reader); } |
---|
2376 | else if (strcmp(tag, "#text") == 0) { } |
---|
2377 | else if (strcmp(tag, "#comment") == 0) { } |
---|
2378 | else if (strcmp(tag, "mapping_info") == 0) |
---|
2379 | { |
---|
2380 | #if XML_PARSER_DEBUG |
---|
2381 | printf("end mapping_info\n"); |
---|
2382 | #endif |
---|
2383 | return; |
---|
2384 | } |
---|
2385 | else |
---|
2386 | { |
---|
2387 | printf("[XML ERROR] Unknown tag in header node : %s\n",tag); |
---|
2388 | exit(1); |
---|
2389 | } |
---|
2390 | status = xmlTextReaderRead(reader); |
---|
2391 | } |
---|
2392 | } // end headerNode() |
---|
2393 | |
---|
2394 | |
---|
2395 | /////////////////////////////////////// |
---|
2396 | void BuildTable(int fdout, const char * type, unsigned int nb_elem, |
---|
2397 | unsigned int elem_size, char ** table) |
---|
2398 | { |
---|
2399 | unsigned int i; |
---|
2400 | // write element |
---|
2401 | for (i = 0; i < nb_elem; i++) { |
---|
2402 | if (elem_size != write(fdout, table[i], elem_size)) { |
---|
2403 | printf("function %s: %s(%d) write error \n", __FUNCTION__, type, i); |
---|
2404 | exit(1); |
---|
2405 | } |
---|
2406 | |
---|
2407 | #if XML_PARSER_DEBUG |
---|
2408 | printf("Building binary: writing %s %d\n", type, i); |
---|
2409 | #endif |
---|
2410 | } |
---|
2411 | } |
---|
2412 | |
---|
2413 | ///////////////////////////////////// |
---|
2414 | int open_file(const char * file_path) |
---|
2415 | { |
---|
2416 | //open file |
---|
2417 | int fdout = open( file_path, (O_CREAT | O_RDWR), (S_IWUSR | S_IRUSR) ); |
---|
2418 | if (fdout < 0) |
---|
2419 | { |
---|
2420 | perror("open"); |
---|
2421 | exit(1); |
---|
2422 | } |
---|
2423 | |
---|
2424 | //reinitialise the file |
---|
2425 | if (ftruncate(fdout, 0)) |
---|
2426 | { |
---|
2427 | perror("truncate"); |
---|
2428 | exit(1); |
---|
2429 | } |
---|
2430 | |
---|
2431 | //#if XML_PARSER_DEBUG |
---|
2432 | printf("%s\n", file_path); |
---|
2433 | //#endif |
---|
2434 | |
---|
2435 | return fdout; |
---|
2436 | } |
---|
2437 | |
---|
2438 | |
---|
2439 | ///////////////////////////////////// |
---|
2440 | void buildBin(const char * file_path) |
---|
2441 | { |
---|
2442 | unsigned int length; |
---|
2443 | |
---|
2444 | int fdout = open_file(file_path); |
---|
2445 | |
---|
2446 | #if XML_PARSER_DEBUG |
---|
2447 | printf("Building map.bin for %s\n", header->name); |
---|
2448 | printf("signature = %x\n", header->signature); |
---|
2449 | printf("x_size = %d\n", header->x_size); |
---|
2450 | printf("y_size = %d\n", header->y_size); |
---|
2451 | printf("x_width = %d\n", header->x_width); |
---|
2452 | printf("y_width = %d\n", header->y_width); |
---|
2453 | printf("vspaces = %d\n", header->vspaces); |
---|
2454 | printf("psegs = %d\n", header->psegs); |
---|
2455 | printf("vobjs = %d\n", header->vobjs); |
---|
2456 | printf("vsegs = %d\n", header->vsegs); |
---|
2457 | printf("tasks = %d\n", header->tasks); |
---|
2458 | printf("procs = %d\n", header->procs); |
---|
2459 | printf("irqs = %d\n", header->irqs); |
---|
2460 | printf("coprocs = %d\n", header->coprocs); |
---|
2461 | printf("periphs = %d\n", header->periphs); |
---|
2462 | #endif |
---|
2463 | |
---|
2464 | // write header to binary file |
---|
2465 | length = write(fdout, (char *) header, sizeof(mapping_header_t)); |
---|
2466 | if (length != sizeof(mapping_header_t)) |
---|
2467 | { |
---|
2468 | printf("write header error : length = %d \n", length); |
---|
2469 | exit(1); |
---|
2470 | } |
---|
2471 | |
---|
2472 | // write clusters |
---|
2473 | BuildTable(fdout, "cluster", cluster_index, sizeof(mapping_cluster_t), (char **) cluster); |
---|
2474 | // write psegs |
---|
2475 | BuildTable(fdout, "pseg", pseg_index, sizeof(mapping_pseg_t), (char **) pseg); |
---|
2476 | // write vspaces |
---|
2477 | BuildTable(fdout, "vspace", vspace_index, sizeof(mapping_vspace_t), (char **) vspace); |
---|
2478 | // write vsegs |
---|
2479 | BuildTable(fdout, "vseg", vseg_index, sizeof(mapping_vseg_t), (char **) vseg); |
---|
2480 | // write vobjs |
---|
2481 | BuildTable(fdout, "vobj", vobj_index, sizeof(mapping_vobj_t), (char **) vobj); |
---|
2482 | // write tasks array |
---|
2483 | BuildTable(fdout, "task", task_index, sizeof(mapping_task_t), (char **) task); |
---|
2484 | //building procs array |
---|
2485 | BuildTable(fdout, "proc", proc_index, sizeof(mapping_proc_t), (char **) proc); |
---|
2486 | //building irqs array |
---|
2487 | BuildTable(fdout, "irq", irq_index, sizeof(mapping_irq_t), (char **) irq); |
---|
2488 | //building coprocs array |
---|
2489 | BuildTable(fdout, "coproc", coproc_index, sizeof(mapping_coproc_t), (char **) coproc); |
---|
2490 | //building cp_ports array |
---|
2491 | BuildTable(fdout, "cp_port", cp_port_index, sizeof(mapping_cp_port_t),(char **) cp_port); |
---|
2492 | //building periphs array |
---|
2493 | BuildTable(fdout, "periph", periph_index, sizeof(mapping_periph_t), (char **) periph); |
---|
2494 | |
---|
2495 | close(fdout); |
---|
2496 | |
---|
2497 | } // end buildBin() |
---|
2498 | |
---|
2499 | |
---|
2500 | /////////////////////////////////////////////////////////////////////////////////// |
---|
2501 | // this function set the values of vspace_id and vobj_id fields for all cp_ports |
---|
2502 | /////////////////////////////////////////////////////////////////////////////////// |
---|
2503 | void prepareBuild() |
---|
2504 | { |
---|
2505 | unsigned int i; |
---|
2506 | |
---|
2507 | for (i = 0; i < cp_port_index; i++) |
---|
2508 | { |
---|
2509 | int vspace_id = getVspaceId(cp_port_vobj_ref[i]->vspace_name); |
---|
2510 | if (vspace_id < 0) |
---|
2511 | { |
---|
2512 | printf("[XML ERROR] illegal <vspacename> for cp_port %d,\n", i); |
---|
2513 | exit(1); |
---|
2514 | } |
---|
2515 | cp_port[i]->vspaceid = vspace_id; |
---|
2516 | |
---|
2517 | int vobj_id = getVobjId( vspace_id, |
---|
2518 | cp_port_vobj_ref[i]->vobj_name, |
---|
2519 | vspace[vspace_id]->vobjs ); |
---|
2520 | if (vobj_id >= 0) |
---|
2521 | { |
---|
2522 | |
---|
2523 | #if XML_PARSER_DEBUG |
---|
2524 | printf("\ncp_port = %d\n", i); |
---|
2525 | printf(" vspace_name = %s\n", cp_port_vobj_ref[i]->vspace_name); |
---|
2526 | printf(" vobj_name = %s\n", cp_port_vobj_ref[i]->vobj_name); |
---|
2527 | printf(" vobj_index = %d\n", vobj_id); |
---|
2528 | #endif |
---|
2529 | cp_port[i]->mwmr_vobj_id = vobj_id; |
---|
2530 | |
---|
2531 | assert((vobj[vspace[vspace_id]->vobj_offset + vobj_id]->type == VOBJ_TYPE_MWMR) |
---|
2532 | && "coproc ports must refer a vobj of type MWMR"); |
---|
2533 | } |
---|
2534 | else |
---|
2535 | { |
---|
2536 | printf("[XML ERROR] <vobjname> not found for cp_port %d,\n", i); |
---|
2537 | exit(1); |
---|
2538 | } |
---|
2539 | } |
---|
2540 | } |
---|
2541 | |
---|
2542 | ////////////////////////////////////////// |
---|
2543 | void file_write(int fdout, char * towrite) |
---|
2544 | { |
---|
2545 | unsigned int size = strlen(towrite); |
---|
2546 | if (size != write(fdout, towrite, size)) |
---|
2547 | { |
---|
2548 | printf("file_write error"); |
---|
2549 | exit(1); |
---|
2550 | } |
---|
2551 | } |
---|
2552 | |
---|
2553 | ////////////////////////////////////////////////// |
---|
2554 | void def_int_write(int fdout, char * def, int num) |
---|
2555 | { |
---|
2556 | char buf[64]; |
---|
2557 | sprintf(buf, "#define\t %s %d\n", def, num); |
---|
2558 | file_write(fdout, buf); |
---|
2559 | } |
---|
2560 | |
---|
2561 | ////////////////////////////////////////////////// |
---|
2562 | void def_hex_write(int fdout, char * def, int num) |
---|
2563 | { |
---|
2564 | char buf[64]; |
---|
2565 | sprintf(buf, "#define\t %s 0x%x\n", def, num); |
---|
2566 | file_write(fdout, buf); |
---|
2567 | } |
---|
2568 | |
---|
2569 | /////////////////////////////////// |
---|
2570 | void genHd(const char * file_path) |
---|
2571 | { |
---|
2572 | int fdout = open_file(file_path); |
---|
2573 | |
---|
2574 | char prol[80]; |
---|
2575 | sprintf(prol, "/* Generated from file %s.xml */\n\n",header->name); |
---|
2576 | |
---|
2577 | char * ifdef = "#ifndef _HARD_CONFIG_H\n#define _HARD_CONFIG_H\n\n"; |
---|
2578 | char * epil = "\n#endif //_HARD_CONFIG_H"; |
---|
2579 | |
---|
2580 | file_write(fdout, prol); |
---|
2581 | file_write(fdout, ifdef); |
---|
2582 | |
---|
2583 | def_int_write(fdout, "X_SIZE ", header->x_size); |
---|
2584 | def_int_write(fdout, "Y_SIZE ", header->y_size); |
---|
2585 | def_int_write(fdout, "X_WIDTH ", header->x_width); |
---|
2586 | def_int_write(fdout, "Y_WIDTH ", header->y_width); |
---|
2587 | def_int_write(fdout, "X_IO ", header->x_io); |
---|
2588 | def_int_write(fdout, "Y_IO ", header->y_io); |
---|
2589 | |
---|
2590 | file_write(fdout, "\n"); |
---|
2591 | |
---|
2592 | def_int_write(fdout, "TOTAL_PROCS ", total_procs); |
---|
2593 | def_int_write(fdout, "NB_PROCS_MAX ", nb_procs_max); |
---|
2594 | def_int_write(fdout, "NB_TASKS_MAX ", nb_tasks_max); |
---|
2595 | |
---|
2596 | file_write(fdout, "\n"); |
---|
2597 | |
---|
2598 | def_int_write(fdout, "NB_TIM_CHANNELS ", tim_channels); |
---|
2599 | def_int_write(fdout, "NB_DMA_CHANNELS ", dma_channels); |
---|
2600 | |
---|
2601 | file_write(fdout, "\n"); |
---|
2602 | |
---|
2603 | def_int_write(fdout, "NB_TTY_CHANNELS ", tty_channels); |
---|
2604 | def_int_write(fdout, "NB_IOC_CHANNELS ", ioc_channels); |
---|
2605 | def_int_write(fdout, "NB_NIC_CHANNELS ", nic_channels); |
---|
2606 | def_int_write(fdout, "NB_CMA_CHANNELS ", cma_channels); |
---|
2607 | |
---|
2608 | file_write(fdout, "\n"); |
---|
2609 | |
---|
2610 | def_int_write(fdout, "USE_XICU ", use_xcu); |
---|
2611 | def_int_write(fdout, "USE_IOB ", use_iob); |
---|
2612 | def_int_write(fdout, "USE_PIC ", use_pic); |
---|
2613 | def_int_write(fdout, "USE_FBF ", use_fbf); |
---|
2614 | |
---|
2615 | file_write(fdout, "\n"); |
---|
2616 | |
---|
2617 | def_int_write(fdout, "USE_IOC_RDK ", header->use_ram_disk); |
---|
2618 | def_int_write(fdout, "USE_IOC_HBA ", use_hba); |
---|
2619 | def_int_write(fdout, "USE_IOC_BDV ", use_bdv); |
---|
2620 | def_int_write(fdout, "USE_IOC_SPI ", use_spi); |
---|
2621 | |
---|
2622 | file_write(fdout, "\n"); |
---|
2623 | |
---|
2624 | def_int_write(fdout, "IRQ_PER_PROCESSOR ", header->irq_per_proc); |
---|
2625 | |
---|
2626 | file_write(fdout, epil); |
---|
2627 | |
---|
2628 | close(fdout); |
---|
2629 | } |
---|
2630 | |
---|
2631 | //////////////////////////////////////////////////////// |
---|
2632 | void ld_write(int fdout, char * seg, unsigned int addr) |
---|
2633 | { |
---|
2634 | char buf[64]; |
---|
2635 | sprintf(buf, "%s = 0x%x;\n", seg, addr); |
---|
2636 | file_write(fdout, buf); |
---|
2637 | } |
---|
2638 | |
---|
2639 | ////////////////////////////////// |
---|
2640 | void genLd(const char * file_path) |
---|
2641 | { |
---|
2642 | int fdout = open_file(file_path); |
---|
2643 | unsigned int count; |
---|
2644 | unsigned int vseg_id; |
---|
2645 | unsigned int base; // vseg base |
---|
2646 | unsigned int size; // vseg size |
---|
2647 | |
---|
2648 | char prol[80]; |
---|
2649 | sprintf(prol, "/* Generated from file %s.xml */\n\n",header->name); |
---|
2650 | |
---|
2651 | file_write(fdout, prol); |
---|
2652 | |
---|
2653 | // boot mandatory global vsegs |
---|
2654 | for (vseg_id = 0 , count = 0 ; vseg_id < header->vsegs ; vseg_id++) |
---|
2655 | { |
---|
2656 | if ( strcmp(vseg[vseg_id]->name, "seg_boot_code") == 0 ) |
---|
2657 | { |
---|
2658 | base = vseg[vseg_id]->vbase; |
---|
2659 | size = vobj[vseg[vseg_id]->vobj_offset]->length; |
---|
2660 | ld_write(fdout, "seg_boot_code_base ", base); |
---|
2661 | ld_write(fdout, "seg_boot_code_size ", size); |
---|
2662 | count++; |
---|
2663 | } |
---|
2664 | else if ( strcmp(vseg[vseg_id]->name, "seg_boot_data") == 0 ) |
---|
2665 | { |
---|
2666 | base = vseg[vseg_id]->vbase; |
---|
2667 | size = vobj[vseg[vseg_id]->vobj_offset]->length; |
---|
2668 | ld_write(fdout, "seg_boot_data_base ", base); |
---|
2669 | ld_write(fdout, "seg_boot_data_size ", size); |
---|
2670 | count++; |
---|
2671 | } |
---|
2672 | else if ( strcmp(vseg[vseg_id]->name, "seg_boot_stack") == 0 ) |
---|
2673 | { |
---|
2674 | base = vseg[vseg_id]->vbase; |
---|
2675 | size = vobj[vseg[vseg_id]->vobj_offset]->length; |
---|
2676 | ld_write(fdout, "seg_boot_stack_base ", base); |
---|
2677 | ld_write(fdout, "seg_boot_stack_size ", size); |
---|
2678 | count++; |
---|
2679 | } |
---|
2680 | else if ( strcmp(vseg[vseg_id]->name, "seg_boot_mapping") == 0 ) |
---|
2681 | { |
---|
2682 | base = vseg[vseg_id]->vbase; |
---|
2683 | size = vobj[vseg[vseg_id]->vobj_offset]->length; |
---|
2684 | ld_write(fdout, "seg_boot_mapping_base ", base); |
---|
2685 | ld_write(fdout, "seg_boot_mapping_size ", size); |
---|
2686 | count++; |
---|
2687 | } |
---|
2688 | } |
---|
2689 | |
---|
2690 | if ( count != 4 ) |
---|
2691 | { |
---|
2692 | printf ("[XML ERROR] Missing mandatory Boot global vseg : only %d\n", count); |
---|
2693 | printf ("Mandatory segments are :\n"); |
---|
2694 | printf (" - seg_boot_code\n"); |
---|
2695 | printf (" - seg_boot_data\n"); |
---|
2696 | printf (" - seg_boot_stack\n"); |
---|
2697 | printf (" - seg_boot_mapping\n"); |
---|
2698 | exit(0); |
---|
2699 | } |
---|
2700 | |
---|
2701 | file_write(fdout, "\n"); |
---|
2702 | |
---|
2703 | // kernel mandatory global vsegs |
---|
2704 | for (vseg_id = 0, count = 0 ; vseg_id < header->vsegs ; vseg_id++) |
---|
2705 | { |
---|
2706 | if ( strcmp(vseg[vseg_id]->name, "seg_kernel_code") == 0 ) |
---|
2707 | { |
---|
2708 | base = vseg[vseg_id]->vbase; |
---|
2709 | size = vobj[vseg[vseg_id]->vobj_offset]->length; |
---|
2710 | ld_write(fdout, "seg_kernel_code_base ", base); |
---|
2711 | ld_write(fdout, "seg_kernel_code_size ", size); |
---|
2712 | count++; |
---|
2713 | } |
---|
2714 | else if ( strcmp(vseg[vseg_id]->name, "seg_kernel_data") == 0 ) |
---|
2715 | { |
---|
2716 | base = vseg[vseg_id]->vbase; |
---|
2717 | size = vobj[vseg[vseg_id]->vobj_offset]->length; |
---|
2718 | ld_write(fdout, "seg_kernel_data_base ", base); |
---|
2719 | ld_write(fdout, "seg_kernel_data_size ", size); |
---|
2720 | count++; |
---|
2721 | } |
---|
2722 | else if ( strcmp(vseg[vseg_id]->name, "seg_kernel_uncdata") == 0 ) |
---|
2723 | { |
---|
2724 | base = vseg[vseg_id]->vbase; |
---|
2725 | size = vobj[vseg[vseg_id]->vobj_offset]->length; |
---|
2726 | ld_write(fdout, "seg_kernel_uncdata_base ", base); |
---|
2727 | ld_write(fdout, "seg_kernel_uncdata_size ", size); |
---|
2728 | count++; |
---|
2729 | } |
---|
2730 | else if ( strcmp(vseg[vseg_id]->name, "seg_kernel_init") == 0 ) |
---|
2731 | { |
---|
2732 | base = vseg[vseg_id]->vbase; |
---|
2733 | size = vobj[vseg[vseg_id]->vobj_offset]->length; |
---|
2734 | ld_write(fdout, "seg_kernel_init_base ", base); |
---|
2735 | ld_write(fdout, "seg_kernel_init_size ", size); |
---|
2736 | count++; |
---|
2737 | } |
---|
2738 | } |
---|
2739 | if ( count != 4 ) |
---|
2740 | { |
---|
2741 | printf ("[XML ERROR] Missing mandatory Kernel global vseg : only %d\n", count); |
---|
2742 | printf ("Mandatory segments are :\n"); |
---|
2743 | printf (" - seg_kernel_code\n"); |
---|
2744 | printf (" - seg_kernel_data\n"); |
---|
2745 | printf (" - seg_kernel_uncdata\n"); |
---|
2746 | printf (" - seg_kernel_init\n"); |
---|
2747 | exit(0); |
---|
2748 | } |
---|
2749 | |
---|
2750 | file_write(fdout, "\n"); |
---|
2751 | |
---|
2752 | // boot and kernel optionnal global vsegs (pseudo ROMs) |
---|
2753 | unsigned int seg_ram_disk_base = 0xFFFFFFFF; |
---|
2754 | unsigned int seg_ram_disk_size = 0; |
---|
2755 | unsigned int seg_reset_code_base = 0xFFFFFFFF; |
---|
2756 | unsigned int seg_reset_code_size = 0; |
---|
2757 | for (vseg_id = 0 ; vseg_id < header->vsegs ; vseg_id++) |
---|
2758 | { |
---|
2759 | if ( strcmp(vseg[vseg_id]->name, "seg_reset_code") == 0 ) |
---|
2760 | { |
---|
2761 | seg_reset_code_base = vseg[vseg_id]->vbase; |
---|
2762 | seg_reset_code_size = vobj[vseg[vseg_id]->vobj_offset]->length; |
---|
2763 | } |
---|
2764 | if ( strcmp(vseg[vseg_id]->name, "seg_ram_disk") == 0 ) |
---|
2765 | { |
---|
2766 | seg_ram_disk_base = vseg[vseg_id]->vbase; |
---|
2767 | seg_ram_disk_size = vobj[vseg[vseg_id]->vobj_offset]->length; |
---|
2768 | } |
---|
2769 | } |
---|
2770 | |
---|
2771 | ld_write(fdout, "seg_reset_code_base ", seg_reset_code_base); |
---|
2772 | ld_write(fdout, "seg_reset_code_size ", seg_reset_code_size); |
---|
2773 | ld_write(fdout, "seg_ram_disk_base ", seg_ram_disk_base); |
---|
2774 | ld_write(fdout, "seg_ram_disk_size ", seg_ram_disk_size); |
---|
2775 | |
---|
2776 | file_write(fdout, "\n"); |
---|
2777 | |
---|
2778 | // fill the peripherals base address array |
---|
2779 | set_periph_vbase_array(); |
---|
2780 | |
---|
2781 | // non replicated peripherals |
---|
2782 | ld_write(fdout, "seg_cma_base ", periph_vbase_array[PERIPH_TYPE_CMA]); |
---|
2783 | ld_write(fdout, "seg_fbf_base ", periph_vbase_array[PERIPH_TYPE_FBF]); |
---|
2784 | ld_write(fdout, "seg_iob_base ", periph_vbase_array[PERIPH_TYPE_IOB]); |
---|
2785 | ld_write(fdout, "seg_ioc_base ", periph_vbase_array[PERIPH_TYPE_IOC]); |
---|
2786 | ld_write(fdout, "seg_nic_base ", periph_vbase_array[PERIPH_TYPE_NIC]); |
---|
2787 | ld_write(fdout, "seg_rom_base ", periph_vbase_array[PERIPH_TYPE_ROM]); |
---|
2788 | ld_write(fdout, "seg_sim_base ", periph_vbase_array[PERIPH_TYPE_SIM]); |
---|
2789 | ld_write(fdout, "seg_tty_base ", periph_vbase_array[PERIPH_TYPE_TTY]); |
---|
2790 | ld_write(fdout, "seg_pic_base ", periph_vbase_array[PERIPH_TYPE_PIC]); |
---|
2791 | |
---|
2792 | file_write(fdout, "\n"); |
---|
2793 | |
---|
2794 | // replicated peripherals |
---|
2795 | ld_write(fdout, "seg_dma_base ", periph_vbase_array[PERIPH_TYPE_DMA]); |
---|
2796 | ld_write(fdout, "seg_mmc_base ", periph_vbase_array[PERIPH_TYPE_MMC]); |
---|
2797 | ld_write(fdout, "seg_xcu_base ", periph_vbase_array[PERIPH_TYPE_XCU]); |
---|
2798 | |
---|
2799 | file_write(fdout, "\n"); |
---|
2800 | |
---|
2801 | ld_write(fdout, "vseg_cluster_increment ", 0x00010000); |
---|
2802 | |
---|
2803 | close(fdout); |
---|
2804 | } |
---|
2805 | |
---|
2806 | ////////////////////////////////////////////////////// |
---|
2807 | char * buildPath(const char * path, const char * name) |
---|
2808 | { |
---|
2809 | char * res = calloc(strlen(path) + strlen(name) + 1, 1); |
---|
2810 | strcat(res, path); |
---|
2811 | strcat(res, "/"); |
---|
2812 | strcat(res, name); |
---|
2813 | return res; |
---|
2814 | } |
---|
2815 | |
---|
2816 | |
---|
2817 | ////////////////////////////////// |
---|
2818 | int main(int argc, char * argv[]) |
---|
2819 | { |
---|
2820 | if (argc < 3) { |
---|
2821 | printf("Usage: xml2bin <input_file_path> <output_path>\n"); |
---|
2822 | return 1; |
---|
2823 | } |
---|
2824 | |
---|
2825 | struct stat dir_st; |
---|
2826 | if (stat( argv[2], &dir_st)) { |
---|
2827 | perror("bad path"); |
---|
2828 | exit(1); |
---|
2829 | } |
---|
2830 | |
---|
2831 | if ((dir_st.st_mode & S_IFDIR) == 0) { |
---|
2832 | printf("path is not a dir: %s", argv[2] ); |
---|
2833 | exit(1); |
---|
2834 | } |
---|
2835 | |
---|
2836 | char * map_path = buildPath(argv[2], "map.bin"); |
---|
2837 | char * ld_path = buildPath(argv[2], "giet_vsegs.ld"); |
---|
2838 | char * hd_path = buildPath(argv[2], "hard_config.h"); |
---|
2839 | |
---|
2840 | LIBXML_TEST_VERSION; |
---|
2841 | |
---|
2842 | int status; |
---|
2843 | xmlTextReaderPtr reader = xmlReaderForFile(argv[1], NULL, 0); |
---|
2844 | |
---|
2845 | if (reader != NULL) |
---|
2846 | { |
---|
2847 | status = xmlTextReaderRead (reader); |
---|
2848 | while (status == 1) |
---|
2849 | { |
---|
2850 | const char * tag = (const char *) xmlTextReaderConstName(reader); |
---|
2851 | |
---|
2852 | if (strcmp(tag, "mapping_info") == 0) |
---|
2853 | { |
---|
2854 | headerNode(reader); |
---|
2855 | prepareBuild(); |
---|
2856 | buildBin(map_path); |
---|
2857 | genHd(hd_path); |
---|
2858 | genLd(ld_path); |
---|
2859 | } |
---|
2860 | else |
---|
2861 | { |
---|
2862 | printf("[XML ERROR] Wrong file type: \"%s\"\n", argv[1]); |
---|
2863 | return 1; |
---|
2864 | } |
---|
2865 | status = xmlTextReaderRead(reader); |
---|
2866 | } |
---|
2867 | xmlFreeTextReader(reader); |
---|
2868 | |
---|
2869 | if (status != 0) |
---|
2870 | { |
---|
2871 | printf("[XML ERROR] Wrong Syntax in \"%s\" file\n", argv[1]); |
---|
2872 | return 1; |
---|
2873 | } |
---|
2874 | } |
---|
2875 | return 0; |
---|
2876 | } // end main() |
---|
2877 | |
---|
2878 | |
---|
2879 | // Local Variables: |
---|
2880 | // tab-width: 4 |
---|
2881 | // c-basic-offset: 4 |
---|
2882 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
2883 | // indent-tabs-mode: nil |
---|
2884 | // End: |
---|
2885 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
2886 | |
---|