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