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