| 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 an xml file containing a MAPPING_INFO data structure |
|---|
| 8 | // to a binary file that can be directly loaded in the boot ROM and used by the GIET. |
|---|
| 9 | // The C strcutures are defined in the mapping_info.h file. |
|---|
| 10 | /////////////////////////////////////////////////////////////////////////////////////// |
|---|
| 11 | |
|---|
| 12 | #include <stdlib.h> |
|---|
| 13 | #include <fcntl.h> |
|---|
| 14 | #include <sys/types.h> |
|---|
| 15 | #include <sys/stat.h> |
|---|
| 16 | #include <unistd.h> |
|---|
| 17 | #include <stdio.h> |
|---|
| 18 | #include <string.h> |
|---|
| 19 | #include <assert.h> |
|---|
| 20 | #include <libxml/xmlreader.h> |
|---|
| 21 | #include <mapping_info.h> |
|---|
| 22 | #include <irq_handler.h> |
|---|
| 23 | |
|---|
| 24 | #define MAX_CLUSTERS 1024 |
|---|
| 25 | #define MAX_PSEGS 4096 |
|---|
| 26 | #define MAX_VSPACES 1024 |
|---|
| 27 | #define MAX_TASKS 4096 |
|---|
| 28 | #define MAX_MWMRS 4096 |
|---|
| 29 | #define MAX_VSEGS 4096 |
|---|
| 30 | #define MAX_VOBJS 8192 |
|---|
| 31 | #define MAX_PROCS 1024 |
|---|
| 32 | #define MAX_IRQS 8192 |
|---|
| 33 | #define MAX_COPROCS 4096 |
|---|
| 34 | #define MAX_CP_PORTS 8192 |
|---|
| 35 | #define MAX_PERIPHS 8192 |
|---|
| 36 | |
|---|
| 37 | #define XML_PARSER_DEBUG 0 |
|---|
| 38 | |
|---|
| 39 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 40 | // global variables used to store and index the data structures |
|---|
| 41 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 42 | |
|---|
| 43 | mapping_header_t* header; |
|---|
| 44 | mapping_cluster_t* cluster[MAX_CLUSTERS]; // cluster array |
|---|
| 45 | mapping_pseg_t* pseg[MAX_PSEGS]; // pseg array |
|---|
| 46 | mapping_vspace_t* vspace[MAX_VSPACES]; // vspace array |
|---|
| 47 | mapping_vseg_t* vseg[MAX_VSEGS]; // vseg array |
|---|
| 48 | mapping_vobj_t* vobj[MAX_VOBJS]; // vobj array |
|---|
| 49 | mapping_task_t* task[MAX_TASKS]; // task array |
|---|
| 50 | mapping_proc_t* proc[MAX_PROCS]; // proc array |
|---|
| 51 | mapping_irq_t* irq[MAX_IRQS]; // irq array |
|---|
| 52 | mapping_coproc_t* coproc[MAX_COPROCS]; // coproc array |
|---|
| 53 | mapping_cp_port_t* cp_port[MAX_CP_PORTS]; // coproc port array |
|---|
| 54 | mapping_periph_t* periph[MAX_PERIPHS]; // peripheral array |
|---|
| 55 | |
|---|
| 56 | // Index for the various arrays |
|---|
| 57 | |
|---|
| 58 | unsigned int cluster_index = 0; |
|---|
| 59 | unsigned int vspace_index = 0; |
|---|
| 60 | unsigned int global_index = 0; |
|---|
| 61 | unsigned int pseg_index = 0; |
|---|
| 62 | |
|---|
| 63 | unsigned int proc_index = 0; |
|---|
| 64 | unsigned int proc_loc_index = 0; |
|---|
| 65 | |
|---|
| 66 | unsigned int irq_index = 0; |
|---|
| 67 | unsigned int irq_loc_index = 0; |
|---|
| 68 | |
|---|
| 69 | unsigned int coproc_index = 0; |
|---|
| 70 | unsigned int coproc_loc_index = 0; |
|---|
| 71 | |
|---|
| 72 | unsigned int cp_port_index = 0; |
|---|
| 73 | unsigned int cp_port_loc_index = 0; |
|---|
| 74 | |
|---|
| 75 | unsigned int periph_index = 0; |
|---|
| 76 | unsigned int periph_loc_index = 0; |
|---|
| 77 | |
|---|
| 78 | unsigned int vseg_index = 0; |
|---|
| 79 | unsigned int vseg_loc_index = 0; |
|---|
| 80 | |
|---|
| 81 | unsigned int task_index = 0; |
|---|
| 82 | unsigned int task_loc_index = 0; |
|---|
| 83 | |
|---|
| 84 | unsigned int vobj_index = 0; |
|---|
| 85 | unsigned int vobj_loc_index = 0; |
|---|
| 86 | unsigned int vobj_count = 0; |
|---|
| 87 | |
|---|
| 88 | /////////////////////////////////////////////////////////////////////// |
|---|
| 89 | // This arrray is useful to build a temporary list of vobj references. |
|---|
| 90 | // The struct vobj_ref_s is formed by a vspace_name and a vobj_name. |
|---|
| 91 | // This array is used to set the attribute vobj_id of a cp_port |
|---|
| 92 | // once all the vspace have been parsed. |
|---|
| 93 | |
|---|
| 94 | typedef struct vobj_ref_s |
|---|
| 95 | { |
|---|
| 96 | char vspace_name[32]; |
|---|
| 97 | char vobj_name[32]; |
|---|
| 98 | }vobj_ref_t; |
|---|
| 99 | |
|---|
| 100 | vobj_ref_t* cp_port_vobj_ref[MAX_CP_PORTS]; |
|---|
| 101 | |
|---|
| 102 | |
|---|
| 103 | ////////////////////////////////////////////////// |
|---|
| 104 | unsigned int getIntValue( xmlTextReaderPtr reader, |
|---|
| 105 | const char* attributeName, |
|---|
| 106 | unsigned int* ok ) |
|---|
| 107 | { |
|---|
| 108 | unsigned int value = 0; |
|---|
| 109 | unsigned int i; |
|---|
| 110 | char c; |
|---|
| 111 | |
|---|
| 112 | char* string = (char*)xmlTextReaderGetAttribute(reader, (const xmlChar*)attributeName); |
|---|
| 113 | |
|---|
| 114 | if ( string == NULL ) // missing argument |
|---|
| 115 | { |
|---|
| 116 | *ok = 0; |
|---|
| 117 | return 0; |
|---|
| 118 | } |
|---|
| 119 | else |
|---|
| 120 | { |
|---|
| 121 | if ( (string[0] == '0') && ((string[1] == 'x') || (string[1] == 'X')) ) // Hexa |
|---|
| 122 | { |
|---|
| 123 | for ( i = 2 ; (string[i] != 0) && (i < 10) ; i++ ) |
|---|
| 124 | { |
|---|
| 125 | c = string[i]; |
|---|
| 126 | if ((c >= '0') && (c <= '9')) value = (value<<4) + string[i] - 48; |
|---|
| 127 | else if ((c >= 'a') && (c <= 'f')) value = (value<<4) + string[i] - 87; |
|---|
| 128 | else if ((c >= 'A') && (c <= 'F')) value = (value<<4) + string[i] - 55; |
|---|
| 129 | else |
|---|
| 130 | { |
|---|
| 131 | *ok = 0; |
|---|
| 132 | return 0; |
|---|
| 133 | } |
|---|
| 134 | } |
|---|
| 135 | } |
|---|
| 136 | else // Decimal |
|---|
| 137 | { |
|---|
| 138 | for ( i = 0 ; (string[i] != 0) && (i < 9) ; i++ ) |
|---|
| 139 | { |
|---|
| 140 | c = string[i]; |
|---|
| 141 | if ((c >= '0') && (c <= '9')) value = (value*10) + string[i] - 48; |
|---|
| 142 | else |
|---|
| 143 | { |
|---|
| 144 | *ok = 0; |
|---|
| 145 | return 0; |
|---|
| 146 | } |
|---|
| 147 | } |
|---|
| 148 | } |
|---|
| 149 | *ok = 1; |
|---|
| 150 | return value; |
|---|
| 151 | } |
|---|
| 152 | } // end getIntValue() |
|---|
| 153 | |
|---|
| 154 | /////////////////////////////////////////////// |
|---|
| 155 | char* getStringValue ( xmlTextReaderPtr reader, |
|---|
| 156 | const char* attributeName, |
|---|
| 157 | unsigned int* ok ) |
|---|
| 158 | { |
|---|
| 159 | char* string = (char*)xmlTextReaderGetAttribute(reader, (const xmlChar*)attributeName); |
|---|
| 160 | |
|---|
| 161 | if ( string == NULL ) // missing argument |
|---|
| 162 | { |
|---|
| 163 | *ok = 0; |
|---|
| 164 | return NULL; |
|---|
| 165 | } |
|---|
| 166 | else |
|---|
| 167 | { |
|---|
| 168 | *ok = 1; |
|---|
| 169 | return string; |
|---|
| 170 | } |
|---|
| 171 | } // end getStringValue() |
|---|
| 172 | |
|---|
| 173 | /////////////////////////////////////// |
|---|
| 174 | int getPsegId( unsigned int cluster_id, |
|---|
| 175 | char* pseg_name ) |
|---|
| 176 | { |
|---|
| 177 | unsigned int pseg_id; |
|---|
| 178 | unsigned int pseg_min = cluster[cluster_id]->pseg_offset; |
|---|
| 179 | unsigned int pseg_max = pseg_min + cluster[cluster_id]->psegs; |
|---|
| 180 | |
|---|
| 181 | for ( pseg_id = pseg_min ; pseg_id < pseg_max ; pseg_id++ ) |
|---|
| 182 | { |
|---|
| 183 | if ( strcmp(pseg[pseg_id]->name, pseg_name) == 0 ) return pseg_id; |
|---|
| 184 | } |
|---|
| 185 | return -1; |
|---|
| 186 | } |
|---|
| 187 | |
|---|
| 188 | //////////////////////////////////////////// |
|---|
| 189 | int getVspaceId( char* vspace_name) |
|---|
| 190 | { |
|---|
| 191 | unsigned int vspace_id; |
|---|
| 192 | |
|---|
| 193 | for( vspace_id = 0; vspace_id < vspace_index ; vspace_id++) |
|---|
| 194 | { |
|---|
| 195 | if( !strcmp(vspace[vspace_id]->name, vspace_name)) |
|---|
| 196 | { |
|---|
| 197 | return vspace_id; |
|---|
| 198 | } |
|---|
| 199 | } |
|---|
| 200 | return -1; |
|---|
| 201 | } |
|---|
| 202 | |
|---|
| 203 | //////////////////////////////////////////// |
|---|
| 204 | int getVobjLocId( unsigned int vspace_id, |
|---|
| 205 | char* vobj_name, |
|---|
| 206 | unsigned int vspace_max) |
|---|
| 207 | { |
|---|
| 208 | unsigned int vobj_id; |
|---|
| 209 | unsigned int vobj_min = vspace[vspace_id]->vobj_offset; |
|---|
| 210 | unsigned int vobj_max = vobj_min + vspace_max; |
|---|
| 211 | |
|---|
| 212 | for ( vobj_id = vobj_min ; vobj_id < vobj_max ; vobj_id++ ) |
|---|
| 213 | { |
|---|
| 214 | if ( strcmp(vobj[vobj_id]->name, vobj_name) == 0 ) |
|---|
| 215 | { |
|---|
| 216 | return (vobj_id - vobj_min); |
|---|
| 217 | } |
|---|
| 218 | } |
|---|
| 219 | return -1; |
|---|
| 220 | } |
|---|
| 221 | |
|---|
| 222 | /////////////////////////////////////////// |
|---|
| 223 | void cpPortNode ( xmlTextReaderPtr reader ) |
|---|
| 224 | /////////////////////////////////////////// |
|---|
| 225 | { |
|---|
| 226 | char* str; |
|---|
| 227 | unsigned int ok; |
|---|
| 228 | |
|---|
| 229 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
|---|
| 230 | |
|---|
| 231 | if ( cp_port_index >= MAX_CP_PORTS ) |
|---|
| 232 | { |
|---|
| 233 | printf("[XML ERROR] The number of ports (for coprocs) is larger than %d\n", MAX_CP_PORTS); |
|---|
| 234 | } |
|---|
| 235 | |
|---|
| 236 | #if XML_PARSER_DEBUG |
|---|
| 237 | printf("\n port %d\n", cp_port_index); |
|---|
| 238 | #endif |
|---|
| 239 | |
|---|
| 240 | cp_port[cp_port_index] = (mapping_cp_port_t*)malloc(sizeof(mapping_cp_port_t)); |
|---|
| 241 | cp_port_vobj_ref[cp_port_index] = (vobj_ref_t*)malloc(sizeof(vobj_ref_t)); |
|---|
| 242 | |
|---|
| 243 | |
|---|
| 244 | |
|---|
| 245 | ///////// get direction attribute |
|---|
| 246 | str = getStringValue( reader, "direction", &ok ); |
|---|
| 247 | if ( ok ) |
|---|
| 248 | { |
|---|
| 249 | #if XML_PARSER_DEBUG |
|---|
| 250 | printf(" direction = %s\n", str); |
|---|
| 251 | #endif |
|---|
| 252 | if ( strcmp(str, "TO_COPROC") == 0 ) cp_port[cp_port_index]->direction = PORT_TO_COPROC; |
|---|
| 253 | else if ( strcmp(str, "FROM_COPROC") == 0 ) cp_port[cp_port_index]->direction = PORT_FROM_COPROC; |
|---|
| 254 | else |
|---|
| 255 | { |
|---|
| 256 | printf("[XML ERROR] illegal <direction> for cp_port %d in cluster %d\n", |
|---|
| 257 | cp_port_index, cluster_index); |
|---|
| 258 | exit(1); |
|---|
| 259 | } |
|---|
| 260 | } |
|---|
| 261 | else |
|---|
| 262 | { |
|---|
| 263 | printf("[XML ERROR] missing <direction> for cp_port %d in cluster %d\n", |
|---|
| 264 | cp_port_index, cluster_index); |
|---|
| 265 | exit(1); |
|---|
| 266 | } |
|---|
| 267 | |
|---|
| 268 | /////////// get vspacename attribute |
|---|
| 269 | str = getStringValue( reader, "vspacename", &ok ); |
|---|
| 270 | #if XML_PARSER_DEBUG |
|---|
| 271 | printf(" vspacename = %s\n", str); |
|---|
| 272 | #endif |
|---|
| 273 | if ( ok ) |
|---|
| 274 | { |
|---|
| 275 | strncpy(cp_port_vobj_ref[cp_port_index]->vspace_name, str, 31); |
|---|
| 276 | } |
|---|
| 277 | else |
|---|
| 278 | { |
|---|
| 279 | printf("[XML ERROR] missing <vspacename> for cp_port %d in cluster %d\n", |
|---|
| 280 | cp_port_index, cluster_index); |
|---|
| 281 | exit(1); |
|---|
| 282 | } |
|---|
| 283 | |
|---|
| 284 | /////////// get vobjname attribute |
|---|
| 285 | str = getStringValue( reader, "vobjname", &ok ); |
|---|
| 286 | #if XML_PARSER_DEBUG |
|---|
| 287 | printf(" vobjname = %s\n", str); |
|---|
| 288 | #endif |
|---|
| 289 | if ( ok ) |
|---|
| 290 | { |
|---|
| 291 | strncpy(cp_port_vobj_ref[cp_port_index]->vobj_name, str, 31); |
|---|
| 292 | } |
|---|
| 293 | else |
|---|
| 294 | { |
|---|
| 295 | printf("[XML ERROR] missing <vobjname> for cp_port %d in cluster %d\n", |
|---|
| 296 | cp_port_index, cluster_index); |
|---|
| 297 | exit(1); |
|---|
| 298 | } |
|---|
| 299 | |
|---|
| 300 | cp_port_index++; |
|---|
| 301 | cp_port_loc_index++; |
|---|
| 302 | |
|---|
| 303 | } // end cpPortNode() |
|---|
| 304 | |
|---|
| 305 | /////////////////////////////////////////// |
|---|
| 306 | void periphNode ( xmlTextReaderPtr reader ) |
|---|
| 307 | /////////////////////////////////////////// |
|---|
| 308 | { |
|---|
| 309 | char* str; |
|---|
| 310 | unsigned int value; |
|---|
| 311 | unsigned int ok; |
|---|
| 312 | |
|---|
| 313 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
|---|
| 314 | |
|---|
| 315 | if ( periph_index >= MAX_PERIPHS ) |
|---|
| 316 | { |
|---|
| 317 | printf("[XML ERROR] The number of periphs is larger than %d\n", MAX_PERIPHS); |
|---|
| 318 | } |
|---|
| 319 | |
|---|
| 320 | #if XML_PARSER_DEBUG |
|---|
| 321 | printf("\n periph %d\n", periph_index); |
|---|
| 322 | #endif |
|---|
| 323 | |
|---|
| 324 | periph[periph_index] = (mapping_periph_t*)malloc(sizeof(mapping_periph_t)); |
|---|
| 325 | |
|---|
| 326 | /////////// get type attribute |
|---|
| 327 | str = getStringValue( reader, "type", &ok ); |
|---|
| 328 | if ( ok ) |
|---|
| 329 | { |
|---|
| 330 | #if XML_PARSER_DEBUG |
|---|
| 331 | printf(" type = %s\n", str); |
|---|
| 332 | #endif |
|---|
| 333 | unsigned int error = 0; |
|---|
| 334 | |
|---|
| 335 | // The TTY, IOC, NIC, FBF and IOB peripherals cannot be replicated |
|---|
| 336 | if ( strcmp( str, "IOC" ) == 0 ) |
|---|
| 337 | { |
|---|
| 338 | periph[periph_index]->type = PERIPH_TYPE_IOC; |
|---|
| 339 | if ( header->ioc_clusterid == 0xFFFFFFFF) header->ioc_clusterid = cluster_index; |
|---|
| 340 | else error = 1; |
|---|
| 341 | } |
|---|
| 342 | else if ( strcmp( str, "TTY" ) == 0 ) |
|---|
| 343 | { |
|---|
| 344 | periph[periph_index]->type = PERIPH_TYPE_TTY; |
|---|
| 345 | if ( header->ioc_clusterid == 0xFFFFFFFF) header->ioc_clusterid = cluster_index; |
|---|
| 346 | else error = 1; |
|---|
| 347 | } |
|---|
| 348 | else if ( strcmp( str, "FBF" ) == 0 ) |
|---|
| 349 | { |
|---|
| 350 | periph[periph_index]->type = PERIPH_TYPE_FBF; |
|---|
| 351 | if ( header->ioc_clusterid == 0xFFFFFFFF) header->ioc_clusterid = cluster_index; |
|---|
| 352 | else error = 1; |
|---|
| 353 | } |
|---|
| 354 | else if ( strcmp( str, "NIC" ) == 0 ) |
|---|
| 355 | { |
|---|
| 356 | periph[periph_index]->type = PERIPH_TYPE_NIC; |
|---|
| 357 | if ( header->ioc_clusterid == 0xFFFFFFFF) header->ioc_clusterid = cluster_index; |
|---|
| 358 | else error = 1; |
|---|
| 359 | } |
|---|
| 360 | // The TIM, DMA and IOB peripherals can be replicated in several clusters |
|---|
| 361 | else if ( strcmp( str, "TIM" ) == 0 ) |
|---|
| 362 | { |
|---|
| 363 | periph[periph_index]->type = PERIPH_TYPE_TIM; |
|---|
| 364 | } |
|---|
| 365 | else if ( strcmp( str, "DMA" ) == 0 ) |
|---|
| 366 | { |
|---|
| 367 | periph[periph_index]->type = PERIPH_TYPE_DMA; |
|---|
| 368 | } |
|---|
| 369 | else if ( strcmp( str, "IOB" ) == 0 ) |
|---|
| 370 | { |
|---|
| 371 | periph[periph_index]->type = PERIPH_TYPE_IOB; |
|---|
| 372 | } |
|---|
| 373 | else |
|---|
| 374 | { |
|---|
| 375 | printf("[XML ERROR] illegal <type> for peripheral %d in cluster %d\n", |
|---|
| 376 | periph_loc_index, cluster_index); |
|---|
| 377 | exit(1); |
|---|
| 378 | } |
|---|
| 379 | } |
|---|
| 380 | else |
|---|
| 381 | { |
|---|
| 382 | printf("[XML ERROR] missing <type> for peripheral %d in cluster %d\n", |
|---|
| 383 | periph_loc_index, cluster_index); |
|---|
| 384 | exit(1); |
|---|
| 385 | } |
|---|
| 386 | |
|---|
| 387 | ///////// get channels attribute (optionnal : 1 if missing) |
|---|
| 388 | value = getIntValue( reader, "channels", &ok ); |
|---|
| 389 | if ( ok ) |
|---|
| 390 | { |
|---|
| 391 | #if XML_PARSER_DEBUG |
|---|
| 392 | printf(" channels = %d\n", value); |
|---|
| 393 | #endif |
|---|
| 394 | periph[periph_index]->channels = value; |
|---|
| 395 | } |
|---|
| 396 | else |
|---|
| 397 | { |
|---|
| 398 | periph[periph_index]->channels = 1; |
|---|
| 399 | } |
|---|
| 400 | |
|---|
| 401 | /////////// get psegname attribute |
|---|
| 402 | str = getStringValue(reader,"psegname", &ok); |
|---|
| 403 | if ( ok == 0 ) |
|---|
| 404 | { |
|---|
| 405 | printf("[XML ERROR] illegal or missing <psegname> for coproc %d in cluster %d\n", |
|---|
| 406 | coproc_index, cluster_index); |
|---|
| 407 | exit(1); |
|---|
| 408 | } |
|---|
| 409 | |
|---|
| 410 | /////////// set psegid attribute |
|---|
| 411 | int index = getPsegId( cluster_index, str ); |
|---|
| 412 | if ( index >= 0 ) |
|---|
| 413 | { |
|---|
| 414 | #if XML_PARSER_DEBUG |
|---|
| 415 | printf(" clusterid = %d\n", cluster_index); |
|---|
| 416 | printf(" psegname = %s\n", str); |
|---|
| 417 | printf(" psegid = %d\n", index); |
|---|
| 418 | #endif |
|---|
| 419 | periph[periph_index]->psegid = index; |
|---|
| 420 | assert(pseg[index]->type == PSEG_TYPE_PERI && |
|---|
| 421 | "peripheral psegname attribute must refer to a pseg of type PERI" ); |
|---|
| 422 | } |
|---|
| 423 | else |
|---|
| 424 | { |
|---|
| 425 | printf("[XML ERROR] pseg not found for periph %d / clusterid = %d / psegname = %s\n", |
|---|
| 426 | periph_loc_index, cluster_index, str ); |
|---|
| 427 | exit(1); |
|---|
| 428 | } |
|---|
| 429 | |
|---|
| 430 | periph_index++; |
|---|
| 431 | periph_loc_index++; |
|---|
| 432 | |
|---|
| 433 | } // end periphNode |
|---|
| 434 | |
|---|
| 435 | ///////////////////////////////////////// |
|---|
| 436 | void coprocNode ( xmlTextReaderPtr reader ) |
|---|
| 437 | ///////////////////////////////////////// |
|---|
| 438 | { |
|---|
| 439 | char* str; |
|---|
| 440 | unsigned int ok; |
|---|
| 441 | |
|---|
| 442 | cp_port_loc_index = 0; |
|---|
| 443 | |
|---|
| 444 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
|---|
| 445 | |
|---|
| 446 | if ( coproc_index >= MAX_COPROCS ) |
|---|
| 447 | { |
|---|
| 448 | printf("[XML ERROR] The number of coprocs is larger than %d\n", MAX_COPROCS); |
|---|
| 449 | } |
|---|
| 450 | |
|---|
| 451 | #if XML_PARSER_DEBUG |
|---|
| 452 | printf("\n coproc %d\n", coproc_index); |
|---|
| 453 | #endif |
|---|
| 454 | |
|---|
| 455 | coproc[coproc_index] = (mapping_coproc_t*)malloc(sizeof(mapping_coproc_t)); |
|---|
| 456 | |
|---|
| 457 | /////////// get name attribute |
|---|
| 458 | str = getStringValue( reader, "name", &ok ); |
|---|
| 459 | if ( ok ) |
|---|
| 460 | { |
|---|
| 461 | #if XML_PARSER_DEBUG |
|---|
| 462 | printf(" name = %s\n", str); |
|---|
| 463 | #endif |
|---|
| 464 | strncpy(coproc[coproc_index]->name, str, 31); |
|---|
| 465 | } |
|---|
| 466 | else |
|---|
| 467 | { |
|---|
| 468 | printf("[XML ERROR] illegal or missing <name> for coproc %d in cluster %d\n", |
|---|
| 469 | coproc_index, cluster_index); |
|---|
| 470 | exit(1); |
|---|
| 471 | } |
|---|
| 472 | |
|---|
| 473 | /////////// get psegname attribute |
|---|
| 474 | str = getStringValue(reader,"psegname", &ok); |
|---|
| 475 | if ( ok == 0 ) |
|---|
| 476 | { |
|---|
| 477 | printf("[XML ERROR] illegal or missing <psegname> for coproc %d in cluster %d\n", |
|---|
| 478 | coproc_index, cluster_index); |
|---|
| 479 | exit(1); |
|---|
| 480 | } |
|---|
| 481 | |
|---|
| 482 | /////////// set psegid attribute |
|---|
| 483 | int index = getPsegId( cluster_index, str ); |
|---|
| 484 | if ( index >= 0 ) |
|---|
| 485 | { |
|---|
| 486 | #if XML_PARSER_DEBUG |
|---|
| 487 | printf(" clusterid = %d\n", cluster_index); |
|---|
| 488 | printf(" psegname = %s\n", str); |
|---|
| 489 | printf(" psegid = %d\n", index); |
|---|
| 490 | #endif |
|---|
| 491 | coproc[coproc_index]->psegid = index; |
|---|
| 492 | assert(pseg[index]->type == PSEG_TYPE_PERI && "coproc psegname attribute must refer to a pseg of type PERI" ); |
|---|
| 493 | } |
|---|
| 494 | else |
|---|
| 495 | { |
|---|
| 496 | printf("[XML ERROR] pseg not found for coproc %d / clusterid = %d / psegname = %s\n", |
|---|
| 497 | coproc_index, cluster_index, str ); |
|---|
| 498 | exit(1); |
|---|
| 499 | } |
|---|
| 500 | |
|---|
| 501 | ////////// set port_offset |
|---|
| 502 | coproc[coproc_index]->port_offset = cp_port_index; |
|---|
| 503 | |
|---|
| 504 | #if XML_PARSER_DEBUG |
|---|
| 505 | printf(" port_offset = %d\n", cp_port_index); |
|---|
| 506 | #endif |
|---|
| 507 | |
|---|
| 508 | int status = xmlTextReaderRead(reader); |
|---|
| 509 | while ( status == 1 ) |
|---|
| 510 | { |
|---|
| 511 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
|---|
| 512 | |
|---|
| 513 | if ( strcmp(tag, "port") == 0 ) cpPortNode(reader); |
|---|
| 514 | else if ( strcmp(tag, "#text") == 0 ) { } |
|---|
| 515 | else if ( strcmp(tag, "#comment") == 0 ) { } |
|---|
| 516 | else if ( strcmp(tag, "coproc") == 0 ) |
|---|
| 517 | { |
|---|
| 518 | coproc[coproc_index]->ports = cp_port_loc_index; |
|---|
| 519 | coproc_loc_index++; |
|---|
| 520 | coproc_index++; |
|---|
| 521 | return; |
|---|
| 522 | } |
|---|
| 523 | else |
|---|
| 524 | { |
|---|
| 525 | printf("[XML ERROR] Unknown tag %s",tag); |
|---|
| 526 | exit(1); |
|---|
| 527 | } |
|---|
| 528 | status = xmlTextReaderRead ( reader ); |
|---|
| 529 | } |
|---|
| 530 | } // end coprocNode() |
|---|
| 531 | |
|---|
| 532 | /////////////////////////////////////// |
|---|
| 533 | void irqNode( xmlTextReaderPtr reader ) |
|---|
| 534 | /////////////////////////////////////// |
|---|
| 535 | { |
|---|
| 536 | unsigned int ok; |
|---|
| 537 | unsigned int value; |
|---|
| 538 | char* str; |
|---|
| 539 | |
|---|
| 540 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
|---|
| 541 | |
|---|
| 542 | if ( irq_index >= MAX_IRQS ) |
|---|
| 543 | { |
|---|
| 544 | printf("[XML ERROR] The number of irqs is larger than %d\n", MAX_IRQS); |
|---|
| 545 | } |
|---|
| 546 | |
|---|
| 547 | #if XML_PARSER_DEBUG |
|---|
| 548 | printf(" irq %d\n", irq_loc_index); |
|---|
| 549 | #endif |
|---|
| 550 | |
|---|
| 551 | irq[irq_index] = (mapping_irq_t*)malloc(sizeof(mapping_irq_t)); |
|---|
| 552 | |
|---|
| 553 | ///////// get type attribute |
|---|
| 554 | str = getStringValue(reader,"type", &ok); |
|---|
| 555 | if ( ok ) |
|---|
| 556 | { |
|---|
| 557 | #if XML_PARSER_DEBUG |
|---|
| 558 | printf(" type = %s\n", str); |
|---|
| 559 | #endif |
|---|
| 560 | if ( strcmp(str, "HARD") == 0 ) irq[irq_index]->type = 0; |
|---|
| 561 | else if ( strcmp(str, "SOFT") == 0 ) irq[irq_index]->type = 1; |
|---|
| 562 | else |
|---|
| 563 | { |
|---|
| 564 | printf("[XML ERROR] undefined IRQ <type> for processor %d in cluster %d\n", |
|---|
| 565 | cluster_index, proc_loc_index ); |
|---|
| 566 | exit(1); |
|---|
| 567 | } |
|---|
| 568 | } |
|---|
| 569 | else |
|---|
| 570 | { |
|---|
| 571 | printf("[XML ERROR] missing IRQ <type> for processor %d in cluster %d\n", |
|---|
| 572 | cluster_index, proc_loc_index ); |
|---|
| 573 | exit(1); |
|---|
| 574 | } |
|---|
| 575 | |
|---|
| 576 | ///////// get icuid attribute |
|---|
| 577 | value = getIntValue(reader, "icuid", &ok); |
|---|
| 578 | if ( ok ) |
|---|
| 579 | { |
|---|
| 580 | #if XML_PARSER_DEBUG |
|---|
| 581 | printf(" icuid = %d\n", value); |
|---|
| 582 | #endif |
|---|
| 583 | irq[irq_index]->icuid = value; |
|---|
| 584 | if ( value >= 32 ) |
|---|
| 585 | { |
|---|
| 586 | printf("[XML ERROR] IRQ <icuid> too large for processor %d in cluster %d\n", |
|---|
| 587 | cluster_index, proc_loc_index ); |
|---|
| 588 | exit(1); |
|---|
| 589 | } |
|---|
| 590 | } |
|---|
| 591 | else |
|---|
| 592 | { |
|---|
| 593 | printf("[XML ERROR] missing IRQ <icuid> for processor %d in cluster %d\n", |
|---|
| 594 | cluster_index, proc_loc_index ); |
|---|
| 595 | exit(1); |
|---|
| 596 | } |
|---|
| 597 | |
|---|
| 598 | ///////// get isr attribute |
|---|
| 599 | str = getStringValue(reader,"isr", &ok); |
|---|
| 600 | if ( ok ) |
|---|
| 601 | { |
|---|
| 602 | #if XML_PARSER_DEBUG |
|---|
| 603 | printf(" isr = %s\n", str); |
|---|
| 604 | #endif |
|---|
| 605 | if ( strcmp(str, "ISR_SWITCH" ) == 0 ) irq[irq_index]->isr = ISR_SWITCH; |
|---|
| 606 | else if ( strcmp(str, "ISR_IOC" ) == 0 ) irq[irq_index]->isr = ISR_IOC; |
|---|
| 607 | else if ( strcmp(str, "ISR_DMA" ) == 0 ) irq[irq_index]->isr = ISR_DMA; |
|---|
| 608 | else if ( strcmp(str, "ISR_TTY" ) == 0 ) irq[irq_index]->isr = ISR_TTY; |
|---|
| 609 | else if ( strcmp(str, "ISR_TIMER" ) == 0 ) irq[irq_index]->isr = ISR_TIMER; |
|---|
| 610 | else |
|---|
| 611 | { |
|---|
| 612 | printf("[XML ERROR] illegal IRQ <isr> for processor %d in cluster %d\n", |
|---|
| 613 | cluster_index, proc_loc_index ); |
|---|
| 614 | exit(1); |
|---|
| 615 | } |
|---|
| 616 | #if XML_PARSER_DEBUG |
|---|
| 617 | printf(" isrnum = %d\n", irq[irq_index]->isr); |
|---|
| 618 | #endif |
|---|
| 619 | } |
|---|
| 620 | else |
|---|
| 621 | { |
|---|
| 622 | printf("[XML ERROR] missing IRQ <isr> for processor %d in cluster %d\n", |
|---|
| 623 | cluster_index, proc_loc_index ); |
|---|
| 624 | exit(1); |
|---|
| 625 | } |
|---|
| 626 | |
|---|
| 627 | ///////// get channel attribute (optionnal : 0 if missing) |
|---|
| 628 | value = getIntValue(reader, "channel", &ok); |
|---|
| 629 | if ( ok ) |
|---|
| 630 | { |
|---|
| 631 | #if XML_PARSER_DEBUG |
|---|
| 632 | printf(" channel = %d\n", value); |
|---|
| 633 | #endif |
|---|
| 634 | irq[irq_index]->channel = value; |
|---|
| 635 | } |
|---|
| 636 | else |
|---|
| 637 | { |
|---|
| 638 | irq[irq_index]->channel = 0; |
|---|
| 639 | } |
|---|
| 640 | |
|---|
| 641 | irq_index++; |
|---|
| 642 | irq_loc_index++; |
|---|
| 643 | |
|---|
| 644 | } // end irqNode |
|---|
| 645 | |
|---|
| 646 | ///////////////////////////////////////// |
|---|
| 647 | void procNode ( xmlTextReaderPtr reader ) |
|---|
| 648 | ///////////////////////////////////////// |
|---|
| 649 | { |
|---|
| 650 | unsigned int ok; |
|---|
| 651 | unsigned int value; |
|---|
| 652 | |
|---|
| 653 | irq_loc_index = 0; |
|---|
| 654 | |
|---|
| 655 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
|---|
| 656 | |
|---|
| 657 | if ( proc_index >= MAX_PROCS ) |
|---|
| 658 | { |
|---|
| 659 | printf("[XML ERROR] The number of procs is larger than %d\n", MAX_PROCS); |
|---|
| 660 | } |
|---|
| 661 | |
|---|
| 662 | #if XML_PARSER_DEBUG |
|---|
| 663 | printf("\n proc %d\n", proc_index); |
|---|
| 664 | #endif |
|---|
| 665 | |
|---|
| 666 | proc[proc_index] = (mapping_proc_t*)malloc(sizeof(mapping_proc_t)); |
|---|
| 667 | |
|---|
| 668 | |
|---|
| 669 | /////////// get index attribute (optional) |
|---|
| 670 | value = getIntValue(reader,"index",&ok); |
|---|
| 671 | if ( ok && (value != proc_loc_index) ) |
|---|
| 672 | { |
|---|
| 673 | printf("[XML ERROR] wrong proc index / expected value is %d", |
|---|
| 674 | proc_loc_index); |
|---|
| 675 | exit(1); |
|---|
| 676 | } |
|---|
| 677 | |
|---|
| 678 | ////////// set irq_offset attribute |
|---|
| 679 | proc[proc_index]->irq_offset = irq_index; |
|---|
| 680 | |
|---|
| 681 | #if XML_PARSER_DEBUG |
|---|
| 682 | printf(" irq_offset = %d\n", irq_index); |
|---|
| 683 | #endif |
|---|
| 684 | |
|---|
| 685 | int status = xmlTextReaderRead(reader); |
|---|
| 686 | while ( status == 1 ) |
|---|
| 687 | { |
|---|
| 688 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
|---|
| 689 | |
|---|
| 690 | if ( strcmp(tag, "irq") == 0 ) irqNode(reader); |
|---|
| 691 | else if ( strcmp(tag, "#text") == 0 ) { } |
|---|
| 692 | else if ( strcmp(tag, "#comment") == 0 ) { } |
|---|
| 693 | else if ( strcmp(tag, "proc") == 0 ) |
|---|
| 694 | { |
|---|
| 695 | proc[proc_index]->irqs = irq_loc_index; |
|---|
| 696 | proc_loc_index++; |
|---|
| 697 | proc_index++; |
|---|
| 698 | return; |
|---|
| 699 | } |
|---|
| 700 | else |
|---|
| 701 | { |
|---|
| 702 | printf("[XML ERROR] Unknown tag %s",tag); |
|---|
| 703 | exit(1); |
|---|
| 704 | } |
|---|
| 705 | status = xmlTextReaderRead ( reader ); |
|---|
| 706 | } |
|---|
| 707 | } // end procNode() |
|---|
| 708 | |
|---|
| 709 | |
|---|
| 710 | ///////////////////////////////////////// |
|---|
| 711 | void taskNode ( xmlTextReaderPtr reader ) |
|---|
| 712 | ///////////////////////////////////////// |
|---|
| 713 | { |
|---|
| 714 | unsigned int ok; |
|---|
| 715 | unsigned int value; |
|---|
| 716 | char* str; |
|---|
| 717 | |
|---|
| 718 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
|---|
| 719 | |
|---|
| 720 | if ( task_index >= MAX_TASKS ) |
|---|
| 721 | { |
|---|
| 722 | printf("[XML ERROR] The number of tasks is larger than %d\n", MAX_TASKS); |
|---|
| 723 | } |
|---|
| 724 | |
|---|
| 725 | #if XML_PARSER_DEBUG |
|---|
| 726 | printf(" task %d\n", task_loc_index); |
|---|
| 727 | #endif |
|---|
| 728 | |
|---|
| 729 | task[task_index] = (mapping_task_t*)malloc(sizeof(mapping_task_t)); |
|---|
| 730 | |
|---|
| 731 | ////////// get name attribute |
|---|
| 732 | str = getStringValue(reader, "name", &ok); |
|---|
| 733 | if ( ok ) |
|---|
| 734 | { |
|---|
| 735 | #if XML_PARSER_DEBUG |
|---|
| 736 | printf(" name = %s\n", str); |
|---|
| 737 | #endif |
|---|
| 738 | strncpy( task[task_index]->name, str, 31 ); |
|---|
| 739 | } |
|---|
| 740 | else |
|---|
| 741 | { |
|---|
| 742 | printf("[XML ERROR] illegal or missing <name> attribute for task (%d,%d)\n", |
|---|
| 743 | vspace_index, task_loc_index); |
|---|
| 744 | exit(1); |
|---|
| 745 | } |
|---|
| 746 | |
|---|
| 747 | ///////// get clusterid attribute |
|---|
| 748 | value = getIntValue(reader,"clusterid", &ok); |
|---|
| 749 | if ( ok ) |
|---|
| 750 | { |
|---|
| 751 | #if XML_PARSER_DEBUG |
|---|
| 752 | printf(" clusterid = %x\n", value); |
|---|
| 753 | #endif |
|---|
| 754 | if ( value >= header->clusters ) |
|---|
| 755 | { |
|---|
| 756 | printf("[XML ERROR] <clusterid> too large for task (%d,%d)\n", |
|---|
| 757 | vspace_index, task_loc_index); |
|---|
| 758 | exit(1); |
|---|
| 759 | } |
|---|
| 760 | task[task_index]->clusterid = value; |
|---|
| 761 | } |
|---|
| 762 | else |
|---|
| 763 | { |
|---|
| 764 | printf("[XML ERROR] illegal or missing <clusterid> attribute for task (%d,%d)\n", |
|---|
| 765 | vspace_index, task_loc_index); |
|---|
| 766 | exit(1); |
|---|
| 767 | } |
|---|
| 768 | |
|---|
| 769 | ////////// get proclocid attribute |
|---|
| 770 | value = getIntValue(reader,"proclocid", &ok); |
|---|
| 771 | if ( ok ) |
|---|
| 772 | { |
|---|
| 773 | #if XML_PARSER_DEBUG |
|---|
| 774 | printf(" proclocid = %x\n", value); |
|---|
| 775 | #endif |
|---|
| 776 | if ( value >= cluster[task[task_index]->clusterid]->procs ) |
|---|
| 777 | { |
|---|
| 778 | printf("[XML ERROR] <proclocid> too large for task (%d,%d)\n", |
|---|
| 779 | vspace_index, task_loc_index); |
|---|
| 780 | exit(1); |
|---|
| 781 | } |
|---|
| 782 | task[task_index]->proclocid = value; |
|---|
| 783 | } |
|---|
| 784 | else |
|---|
| 785 | { |
|---|
| 786 | printf("[XML ERROR] illegal or missing <locprocid> attribute for task (%d,%d)\n", |
|---|
| 787 | vspace_index, task_loc_index); |
|---|
| 788 | exit(1); |
|---|
| 789 | } |
|---|
| 790 | |
|---|
| 791 | ////////// get stackname attribute |
|---|
| 792 | str = getStringValue(reader, "stackname" , &ok); |
|---|
| 793 | if ( ok ) |
|---|
| 794 | { |
|---|
| 795 | int index = getVobjLocId( vspace_index, str , vobj_loc_index); |
|---|
| 796 | if ( index >= 0 ) |
|---|
| 797 | { |
|---|
| 798 | #if XML_PARSER_DEBUG |
|---|
| 799 | printf(" stackname = %s\n", str); |
|---|
| 800 | printf(" stackid = %d\n", index); |
|---|
| 801 | #endif |
|---|
| 802 | task[task_index]->vobjlocid = index; |
|---|
| 803 | } |
|---|
| 804 | else |
|---|
| 805 | { |
|---|
| 806 | printf("[XML ERROR] illegal or missing <stackname> for task (%d,%d)\n", |
|---|
| 807 | vspace_index, task_loc_index); |
|---|
| 808 | exit(1); |
|---|
| 809 | } |
|---|
| 810 | } |
|---|
| 811 | else |
|---|
| 812 | { |
|---|
| 813 | printf("[XML ERROR] illegal or missing <stackname> for task (%d,%d)\n", |
|---|
| 814 | vspace_index, task_loc_index); |
|---|
| 815 | exit(1); |
|---|
| 816 | } |
|---|
| 817 | |
|---|
| 818 | ////////// get startid attribute |
|---|
| 819 | value = getIntValue(reader,"startid", &ok); |
|---|
| 820 | if ( ok ) |
|---|
| 821 | { |
|---|
| 822 | #if XML_PARSER_DEBUG |
|---|
| 823 | printf(" startid = %x\n", value); |
|---|
| 824 | #endif |
|---|
| 825 | task[task_index]->startid = value; |
|---|
| 826 | } |
|---|
| 827 | else |
|---|
| 828 | { |
|---|
| 829 | printf("[XML ERROR] illegal or missing <startid> attribute for task (%d,%d)\n", |
|---|
| 830 | vspace_index, task_loc_index); |
|---|
| 831 | exit(1); |
|---|
| 832 | } |
|---|
| 833 | |
|---|
| 834 | /////////// get usetty attribute (optionnal : 0 if missing) |
|---|
| 835 | value = getIntValue(reader,"usetty", &ok); |
|---|
| 836 | if ( ok ) |
|---|
| 837 | { |
|---|
| 838 | #if XML_PARSER_DEBUG |
|---|
| 839 | printf(" usetty = %x\n", value); |
|---|
| 840 | #endif |
|---|
| 841 | task[task_index]->use_tty = value; |
|---|
| 842 | } |
|---|
| 843 | else |
|---|
| 844 | { |
|---|
| 845 | task[task_index]->use_tty = 0; |
|---|
| 846 | } |
|---|
| 847 | |
|---|
| 848 | /////////// get usenic attribute (optionnal : 0 if missing) |
|---|
| 849 | value = getIntValue(reader,"usenic", &ok); |
|---|
| 850 | if ( ok ) |
|---|
| 851 | { |
|---|
| 852 | #if XML_PARSER_DEBUG |
|---|
| 853 | printf(" usenic = %x\n", value); |
|---|
| 854 | #endif |
|---|
| 855 | task[task_index]->use_nic = value; |
|---|
| 856 | } |
|---|
| 857 | else |
|---|
| 858 | { |
|---|
| 859 | task[task_index]->use_nic = 0; |
|---|
| 860 | } |
|---|
| 861 | |
|---|
| 862 | /////////// get usetimer attribute (optionnal : 0 if missing) |
|---|
| 863 | value = getIntValue(reader,"usetimer", &ok); |
|---|
| 864 | if ( ok ) |
|---|
| 865 | { |
|---|
| 866 | #if XML_PARSER_DEBUG |
|---|
| 867 | printf(" usetimer = %x\n", value); |
|---|
| 868 | #endif |
|---|
| 869 | task[task_index]->use_timer = value; |
|---|
| 870 | } |
|---|
| 871 | else |
|---|
| 872 | { |
|---|
| 873 | task[task_index]->use_timer = 0; |
|---|
| 874 | } |
|---|
| 875 | |
|---|
| 876 | /////////// get usefbdma attribute (optionnal : 0 if missing) |
|---|
| 877 | value = getIntValue(reader,"usefbdma", &ok); |
|---|
| 878 | if ( ok ) |
|---|
| 879 | { |
|---|
| 880 | #if XML_PARSER_DEBUG |
|---|
| 881 | printf(" usefbdma = %x\n", value); |
|---|
| 882 | #endif |
|---|
| 883 | task[task_index]->use_fbdma = value; |
|---|
| 884 | } |
|---|
| 885 | else |
|---|
| 886 | { |
|---|
| 887 | task[task_index]->use_fbdma = 0; |
|---|
| 888 | } |
|---|
| 889 | |
|---|
| 890 | task_index++; |
|---|
| 891 | task_loc_index++; |
|---|
| 892 | } // end taskNode() |
|---|
| 893 | |
|---|
| 894 | ////////////////////////////////////////// |
|---|
| 895 | void vobjNode ( xmlTextReaderPtr reader ) |
|---|
| 896 | ////////////////////////////////////////// |
|---|
| 897 | { |
|---|
| 898 | unsigned int ok; |
|---|
| 899 | unsigned int value; |
|---|
| 900 | char* str; |
|---|
| 901 | |
|---|
| 902 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
|---|
| 903 | |
|---|
| 904 | if ( vobj_index >= MAX_VOBJS ) |
|---|
| 905 | { |
|---|
| 906 | printf("[XML ERROR] The number of vobjs is larger than %d\n", MAX_VSEGS); |
|---|
| 907 | exit(1); |
|---|
| 908 | } |
|---|
| 909 | |
|---|
| 910 | #if XML_PARSER_DEBUG |
|---|
| 911 | printf(" vobj %d\n", vobj_loc_index); |
|---|
| 912 | #endif |
|---|
| 913 | |
|---|
| 914 | vobj[vobj_index] = (mapping_vobj_t*)malloc(sizeof(mapping_vobj_t)); |
|---|
| 915 | |
|---|
| 916 | ///////// get name attribute |
|---|
| 917 | str = getStringValue(reader, "name", &ok); |
|---|
| 918 | if ( ok ) |
|---|
| 919 | { |
|---|
| 920 | #if XML_PARSER_DEBUG |
|---|
| 921 | printf(" name = %s\n", str); |
|---|
| 922 | #endif |
|---|
| 923 | strncpy( vobj[vobj_index]->name, str, 31); |
|---|
| 924 | } |
|---|
| 925 | else |
|---|
| 926 | { |
|---|
| 927 | printf("[XML ERROR] illegal or missing <name> attribute for vobj (%d,%d)\n", |
|---|
| 928 | vseg_index, vobj_loc_index); |
|---|
| 929 | exit(1); |
|---|
| 930 | } |
|---|
| 931 | |
|---|
| 932 | //////// get type attribute |
|---|
| 933 | str = getStringValue(reader, "type", &ok); |
|---|
| 934 | #if XML_PARSER_DEBUG |
|---|
| 935 | printf(" type = %s\n", str); |
|---|
| 936 | #endif |
|---|
| 937 | if (ok && (strcmp(str, "ELF") == 0)) |
|---|
| 938 | { |
|---|
| 939 | vobj[vobj_index]->type = VOBJ_TYPE_ELF; |
|---|
| 940 | |
|---|
| 941 | //check that this vobj is the first in vseg |
|---|
| 942 | if(vobj_count != 0) |
|---|
| 943 | { |
|---|
| 944 | printf("[XML ERROR] an ELF vobj must be alone in a vseg (%d,%d)\n", |
|---|
| 945 | vspace_index, vobj_loc_index); |
|---|
| 946 | exit(1); |
|---|
| 947 | } |
|---|
| 948 | } |
|---|
| 949 | else if (ok && (strcmp(str, "BLOB") == 0)) vobj[vobj_index]->type = VOBJ_TYPE_BLOB; |
|---|
| 950 | else if (ok && (strcmp(str, "PTAB") == 0)) vobj[vobj_index]->type = VOBJ_TYPE_PTAB; |
|---|
| 951 | else if (ok && (strcmp(str, "PERI") == 0)) vobj[vobj_index]->type = VOBJ_TYPE_PERI; |
|---|
| 952 | else if (ok && (strcmp(str, "MWMR") == 0)) vobj[vobj_index]->type = VOBJ_TYPE_MWMR; |
|---|
| 953 | else if (ok && (strcmp(str, "LOCK") == 0)) vobj[vobj_index]->type = VOBJ_TYPE_LOCK; |
|---|
| 954 | else if (ok && (strcmp(str, "BUFFER") == 0)) vobj[vobj_index]->type = VOBJ_TYPE_BUFFER; |
|---|
| 955 | else if (ok && (strcmp(str, "BARRIER") == 0)) vobj[vobj_index]->type = VOBJ_TYPE_BARRIER; |
|---|
| 956 | else |
|---|
| 957 | { |
|---|
| 958 | printf("[XML ERROR] illegal or missing <type> attribute for vobj (%d,%d)\n", |
|---|
| 959 | vspace_index, vobj_loc_index); |
|---|
| 960 | exit(1); |
|---|
| 961 | } |
|---|
| 962 | |
|---|
| 963 | ////////// get length attribute |
|---|
| 964 | value = getIntValue(reader,"length", &ok); |
|---|
| 965 | if ( ok ) |
|---|
| 966 | { |
|---|
| 967 | #if XML_PARSER_DEBUG |
|---|
| 968 | printf(" length = %d\n", value); |
|---|
| 969 | #endif |
|---|
| 970 | vobj[vobj_index]->length = value; |
|---|
| 971 | } |
|---|
| 972 | else |
|---|
| 973 | { |
|---|
| 974 | printf("[XML ERROR] illegal or missing <length> attribute for vobj (%d,%d)\n", |
|---|
| 975 | vspace_index, vobj_loc_index); |
|---|
| 976 | exit(1); |
|---|
| 977 | } |
|---|
| 978 | |
|---|
| 979 | ////////// get align attribute (optional : 0 if missing) |
|---|
| 980 | value = getIntValue(reader,"align", &ok); |
|---|
| 981 | if ( ok ) |
|---|
| 982 | { |
|---|
| 983 | #if XML_PARSER_DEBUG |
|---|
| 984 | printf(" align = %d\n", value); |
|---|
| 985 | #endif |
|---|
| 986 | vobj[vobj_index]->align = value; |
|---|
| 987 | } |
|---|
| 988 | else |
|---|
| 989 | { |
|---|
| 990 | vobj[vobj_index]->align = 0; |
|---|
| 991 | } |
|---|
| 992 | |
|---|
| 993 | ////////// get binpath attribute (optional : '\0' if missing) |
|---|
| 994 | str = getStringValue(reader, "binpath", &ok); |
|---|
| 995 | if ( ok ) |
|---|
| 996 | { |
|---|
| 997 | #if XML_PARSER_DEBUG |
|---|
| 998 | printf(" binpath = %s\n", str); |
|---|
| 999 | #endif |
|---|
| 1000 | strncpy(vobj[vobj_index]->binpath, str, 63); |
|---|
| 1001 | } |
|---|
| 1002 | else |
|---|
| 1003 | { |
|---|
| 1004 | vobj[vobj_index]->binpath[0] = '\0'; |
|---|
| 1005 | } |
|---|
| 1006 | |
|---|
| 1007 | ////////// get init attribute (mandatory for mwmr and barrier) |
|---|
| 1008 | value = getIntValue(reader,"init", &ok); |
|---|
| 1009 | if ( ok ) |
|---|
| 1010 | { |
|---|
| 1011 | #if XML_PARSER_DEBUG |
|---|
| 1012 | printf(" init = %d\n", value); |
|---|
| 1013 | #endif |
|---|
| 1014 | vobj[vobj_index]->init = value; |
|---|
| 1015 | } |
|---|
| 1016 | else |
|---|
| 1017 | { |
|---|
| 1018 | if( (vobj[vobj_index]->type == VOBJ_TYPE_MWMR) || |
|---|
| 1019 | (vobj[vobj_index]->type == VOBJ_TYPE_BARRIER) ) |
|---|
| 1020 | { |
|---|
| 1021 | printf("[XML ERROR] illegal or missing <value> attribute for vobj (%d,%d). \ |
|---|
| 1022 | All MWMR or BARRIER vobj must have a init value \n", |
|---|
| 1023 | vspace_index, vobj_loc_index); |
|---|
| 1024 | exit(1); |
|---|
| 1025 | } |
|---|
| 1026 | vobj[vobj_index]->init = 0; |
|---|
| 1027 | } |
|---|
| 1028 | |
|---|
| 1029 | vobj_index++; |
|---|
| 1030 | vobj_count++; |
|---|
| 1031 | vobj_loc_index++; |
|---|
| 1032 | } // end vobjNode() |
|---|
| 1033 | |
|---|
| 1034 | ////////////////////////////////////////// |
|---|
| 1035 | void vsegNode ( xmlTextReaderPtr reader ) |
|---|
| 1036 | ////////////////////////////////////////// |
|---|
| 1037 | { |
|---|
| 1038 | unsigned int ok; |
|---|
| 1039 | unsigned int value; |
|---|
| 1040 | char* str; |
|---|
| 1041 | |
|---|
| 1042 | vobj_count = 0; |
|---|
| 1043 | |
|---|
| 1044 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
|---|
| 1045 | |
|---|
| 1046 | if ( vseg_index >= MAX_VSEGS ) |
|---|
| 1047 | { |
|---|
| 1048 | printf("[XML ERROR] The number of vsegs is larger than %d\n", MAX_VSEGS); |
|---|
| 1049 | exit(1); |
|---|
| 1050 | } |
|---|
| 1051 | |
|---|
| 1052 | #if XML_PARSER_DEBUG |
|---|
| 1053 | printf(" vseg %d\n", vseg_loc_index); |
|---|
| 1054 | #endif |
|---|
| 1055 | |
|---|
| 1056 | vseg[vseg_index] = (mapping_vseg_t*)malloc(sizeof(mapping_vseg_t)); |
|---|
| 1057 | |
|---|
| 1058 | ////////// set vobj_offset attributes |
|---|
| 1059 | vseg[vseg_index]->vobj_offset = vobj_index; |
|---|
| 1060 | #if XML_PARSER_DEBUG |
|---|
| 1061 | printf(" vobj_offset = %d\n", vobj_index); |
|---|
| 1062 | #endif |
|---|
| 1063 | |
|---|
| 1064 | ///////// get name attribute |
|---|
| 1065 | str = getStringValue(reader, "name", &ok); |
|---|
| 1066 | if ( ok ) |
|---|
| 1067 | { |
|---|
| 1068 | #if XML_PARSER_DEBUG |
|---|
| 1069 | printf(" name = %s\n", str); |
|---|
| 1070 | #endif |
|---|
| 1071 | strncpy( vseg[vseg_index]->name, str, 31); |
|---|
| 1072 | } |
|---|
| 1073 | else |
|---|
| 1074 | { |
|---|
| 1075 | printf("[XML ERROR] illegal or missing <name> attribute for vseg (%d,%d)\n", |
|---|
| 1076 | vspace_index, vseg_loc_index); |
|---|
| 1077 | exit(1); |
|---|
| 1078 | } |
|---|
| 1079 | |
|---|
| 1080 | ////////// get ident attribute (optional : 0 if missing) |
|---|
| 1081 | value = getIntValue(reader,"ident", &ok); |
|---|
| 1082 | if ( ok ) |
|---|
| 1083 | { |
|---|
| 1084 | #if XML_PARSER_DEBUG |
|---|
| 1085 | printf(" ident = %d\n", value); |
|---|
| 1086 | #endif |
|---|
| 1087 | vseg[vseg_index]->ident = value; |
|---|
| 1088 | } |
|---|
| 1089 | else |
|---|
| 1090 | { |
|---|
| 1091 | vseg[vseg_index]->ident = 0; |
|---|
| 1092 | } |
|---|
| 1093 | |
|---|
| 1094 | /////////// get vbase attribute |
|---|
| 1095 | value = getIntValue(reader,"vbase", &ok); |
|---|
| 1096 | if ( ok ) |
|---|
| 1097 | { |
|---|
| 1098 | #if XML_PARSER_DEBUG |
|---|
| 1099 | printf(" vbase = 0x%x\n", value); |
|---|
| 1100 | #endif |
|---|
| 1101 | vseg[vseg_index]->vbase = value; |
|---|
| 1102 | } |
|---|
| 1103 | else |
|---|
| 1104 | { |
|---|
| 1105 | printf("[XML ERROR] illegal or missing <vbase> attribute for vseg (%d,%d)\n", |
|---|
| 1106 | vspace_index, vseg_loc_index); |
|---|
| 1107 | exit(1); |
|---|
| 1108 | } |
|---|
| 1109 | |
|---|
| 1110 | ////////// get clusterid and psegname attributes |
|---|
| 1111 | value = getIntValue(reader,"clusterid", &ok); |
|---|
| 1112 | if ( ok == 0 ) |
|---|
| 1113 | { |
|---|
| 1114 | printf("[XML ERROR] illegal or missing <clusterid> for vseg %d\n", |
|---|
| 1115 | vseg_loc_index); |
|---|
| 1116 | exit(1); |
|---|
| 1117 | } |
|---|
| 1118 | str = getStringValue(reader,"psegname", &ok); |
|---|
| 1119 | if ( ok == 0 ) |
|---|
| 1120 | { |
|---|
| 1121 | printf("[XML ERROR] illegal or missing <psegname> for vseg %d\n", |
|---|
| 1122 | vseg_loc_index); |
|---|
| 1123 | exit(1); |
|---|
| 1124 | } |
|---|
| 1125 | |
|---|
| 1126 | /////////// set psegid field |
|---|
| 1127 | int index = getPsegId( value, str ); |
|---|
| 1128 | if ( index >= 0 ) |
|---|
| 1129 | { |
|---|
| 1130 | #if XML_PARSER_DEBUG |
|---|
| 1131 | printf(" clusterid = %d\n", value); |
|---|
| 1132 | printf(" psegname = %s\n", str); |
|---|
| 1133 | printf(" psegid = %d\n", index); |
|---|
| 1134 | #endif |
|---|
| 1135 | vseg[vseg_index]->psegid = index; |
|---|
| 1136 | } |
|---|
| 1137 | else |
|---|
| 1138 | { |
|---|
| 1139 | printf("[XML ERROR] pseg not found for vseg %d / clusterid = %d / psegname = %s\n", |
|---|
| 1140 | vseg_loc_index, value, str ); |
|---|
| 1141 | exit(1); |
|---|
| 1142 | } |
|---|
| 1143 | |
|---|
| 1144 | //////// get mode attribute |
|---|
| 1145 | str = getStringValue(reader,"mode", &ok); |
|---|
| 1146 | #if XML_PARSER_DEBUG |
|---|
| 1147 | printf(" mode = %s\n", str); |
|---|
| 1148 | #endif |
|---|
| 1149 | if (ok && (strcmp(str, "CXWU") == 0)) vseg[vseg_index]->mode = 0xF; |
|---|
| 1150 | else if (ok && (strcmp(str, "CXW_") == 0)) vseg[vseg_index]->mode = 0xE; |
|---|
| 1151 | else if (ok && (strcmp(str, "CX_U") == 0)) vseg[vseg_index]->mode = 0xD; |
|---|
| 1152 | else if (ok && (strcmp(str, "CX__") == 0)) vseg[vseg_index]->mode = 0xC; |
|---|
| 1153 | else if (ok && (strcmp(str, "C_WU") == 0)) vseg[vseg_index]->mode = 0xB; |
|---|
| 1154 | else if (ok && (strcmp(str, "C_W_") == 0)) vseg[vseg_index]->mode = 0xA; |
|---|
| 1155 | else if (ok && (strcmp(str, "C__U") == 0)) vseg[vseg_index]->mode = 0x9; |
|---|
| 1156 | else if (ok && (strcmp(str, "C___") == 0)) vseg[vseg_index]->mode = 0x8; |
|---|
| 1157 | else if (ok && (strcmp(str, "_XWU") == 0)) vseg[vseg_index]->mode = 0x7; |
|---|
| 1158 | else if (ok && (strcmp(str, "_XW_") == 0)) vseg[vseg_index]->mode = 0x6; |
|---|
| 1159 | else if (ok && (strcmp(str, "_X_U") == 0)) vseg[vseg_index]->mode = 0x5; |
|---|
| 1160 | else if (ok && (strcmp(str, "_X__") == 0)) vseg[vseg_index]->mode = 0x4; |
|---|
| 1161 | else if (ok && (strcmp(str, "__WU") == 0)) vseg[vseg_index]->mode = 0x3; |
|---|
| 1162 | else if (ok && (strcmp(str, "__W_") == 0)) vseg[vseg_index]->mode = 0x2; |
|---|
| 1163 | else if (ok && (strcmp(str, "___U") == 0)) vseg[vseg_index]->mode = 0x1; |
|---|
| 1164 | else if (ok && (strcmp(str, "____") == 0)) vseg[vseg_index]->mode = 0x0; |
|---|
| 1165 | else |
|---|
| 1166 | { |
|---|
| 1167 | printf("[XML ERROR] illegal or missing <mode> attribute for vseg (%d,%d)\n", |
|---|
| 1168 | vspace_index, vseg_loc_index); |
|---|
| 1169 | exit(1); |
|---|
| 1170 | } |
|---|
| 1171 | |
|---|
| 1172 | ////////// get vobjs in vseg |
|---|
| 1173 | int status = xmlTextReaderRead(reader); |
|---|
| 1174 | while ( status == 1 ) |
|---|
| 1175 | { |
|---|
| 1176 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
|---|
| 1177 | |
|---|
| 1178 | if ( strcmp(tag, "vobj") == 0 ) vobjNode(reader); |
|---|
| 1179 | else if ( strcmp(tag, "#text" ) == 0 ) { } |
|---|
| 1180 | else if ( strcmp(tag, "#comment") == 0 ) { } |
|---|
| 1181 | else if ( strcmp(tag, "vseg") == 0 ) |
|---|
| 1182 | { |
|---|
| 1183 | vseg[vseg_index]->vobjs = vobj_count; |
|---|
| 1184 | vseg_index++; |
|---|
| 1185 | vseg_loc_index++; |
|---|
| 1186 | return; |
|---|
| 1187 | } |
|---|
| 1188 | else |
|---|
| 1189 | { |
|---|
| 1190 | printf("[XML ERROR] Unknown tag %s",tag); |
|---|
| 1191 | exit(1); |
|---|
| 1192 | } |
|---|
| 1193 | status = xmlTextReaderRead ( reader ); |
|---|
| 1194 | } |
|---|
| 1195 | } // end vsegNode() |
|---|
| 1196 | |
|---|
| 1197 | ////////////////////////////////////////// |
|---|
| 1198 | void vspaceNode( xmlTextReaderPtr reader ) |
|---|
| 1199 | ////////////////////////////////////////// |
|---|
| 1200 | { |
|---|
| 1201 | char* str; |
|---|
| 1202 | unsigned int ok; |
|---|
| 1203 | |
|---|
| 1204 | vobj_loc_index = 0; |
|---|
| 1205 | vseg_loc_index = 0; |
|---|
| 1206 | task_loc_index = 0; |
|---|
| 1207 | |
|---|
| 1208 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
|---|
| 1209 | |
|---|
| 1210 | // checking source file consistency |
|---|
| 1211 | if ( vspace_index >= header->vspaces ) |
|---|
| 1212 | { |
|---|
| 1213 | printf("[XML ERROR] The vspace index is too large : %d\n", |
|---|
| 1214 | vspace_index); |
|---|
| 1215 | exit(1); |
|---|
| 1216 | } |
|---|
| 1217 | |
|---|
| 1218 | #if XML_PARSER_DEBUG |
|---|
| 1219 | printf("\n vspace %d\n", vspace_index); |
|---|
| 1220 | #endif |
|---|
| 1221 | |
|---|
| 1222 | vspace[vspace_index] = (mapping_vspace_t*)malloc(sizeof(mapping_vspace_t)); |
|---|
| 1223 | |
|---|
| 1224 | ////////// get name attribute |
|---|
| 1225 | str = getStringValue(reader, "name", &ok); |
|---|
| 1226 | if ( ok ) |
|---|
| 1227 | { |
|---|
| 1228 | #if XML_PARSER_DEBUG |
|---|
| 1229 | printf(" name = %s\n", str); |
|---|
| 1230 | #endif |
|---|
| 1231 | strncpy(vspace[vspace_index]->name, str, 31); |
|---|
| 1232 | } |
|---|
| 1233 | else |
|---|
| 1234 | { |
|---|
| 1235 | printf("[XML ERROR] illegal or missing <name> attribute for vspace %d\n", |
|---|
| 1236 | vspace_index); |
|---|
| 1237 | exit(1); |
|---|
| 1238 | } |
|---|
| 1239 | |
|---|
| 1240 | ////////// set vseg_offset and task_offset attributes |
|---|
| 1241 | vspace[vspace_index]->vseg_offset = vseg_index; |
|---|
| 1242 | vspace[vspace_index]->vobj_offset = vobj_index; |
|---|
| 1243 | vspace[vspace_index]->task_offset = task_index; |
|---|
| 1244 | |
|---|
| 1245 | #if XML_PARSER_DEBUG |
|---|
| 1246 | printf(" vseg_offset = %d\n", vseg_index); |
|---|
| 1247 | printf(" vobj_offset = %d\n", vobj_index); |
|---|
| 1248 | printf(" task_offset = %d\n", task_index); |
|---|
| 1249 | #endif |
|---|
| 1250 | |
|---|
| 1251 | ////////// get startname attribute |
|---|
| 1252 | str = getStringValue(reader, "startname", &ok); |
|---|
| 1253 | if ( ok ) |
|---|
| 1254 | { |
|---|
| 1255 | //used after parsing the vobjs |
|---|
| 1256 | } |
|---|
| 1257 | else |
|---|
| 1258 | { |
|---|
| 1259 | printf("[XML ERROR] illegal or missing <startname> attribute for vspace %s\n", |
|---|
| 1260 | vspace[vspace_index]->name); |
|---|
| 1261 | exit(1); |
|---|
| 1262 | } |
|---|
| 1263 | |
|---|
| 1264 | int status = xmlTextReaderRead(reader); |
|---|
| 1265 | while ( status == 1 ) |
|---|
| 1266 | { |
|---|
| 1267 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
|---|
| 1268 | |
|---|
| 1269 | if ( strcmp(tag, "vseg") == 0 ) vsegNode(reader); |
|---|
| 1270 | else if ( strcmp(tag, "task") == 0 ) taskNode(reader); |
|---|
| 1271 | else if ( strcmp(tag, "#text") == 0 ) { } |
|---|
| 1272 | else if ( strcmp(tag, "#comment") == 0 ) { } |
|---|
| 1273 | else if ( strcmp(tag, "vspace") == 0 ) |
|---|
| 1274 | { |
|---|
| 1275 | vspace[vspace_index]->vobjs = vobj_loc_index; |
|---|
| 1276 | vspace[vspace_index]->tasks = task_loc_index ; |
|---|
| 1277 | vspace[vspace_index]->vsegs = vseg_loc_index ; |
|---|
| 1278 | |
|---|
| 1279 | // get index of the vobj containing the start vector |
|---|
| 1280 | int index = getVobjLocId( vspace_index, str , vobj_loc_index ); |
|---|
| 1281 | if(index == -1) |
|---|
| 1282 | { |
|---|
| 1283 | printf("[XML ERROR] vobj containing start vector not found in vspace %s\n", |
|---|
| 1284 | vspace[vspace_index]->name); |
|---|
| 1285 | exit(-1); |
|---|
| 1286 | } |
|---|
| 1287 | else |
|---|
| 1288 | { |
|---|
| 1289 | vspace[vspace_index]->start_offset = index; |
|---|
| 1290 | #if XML_PARSER_DEBUG |
|---|
| 1291 | printf(" startname = %s\n", str); |
|---|
| 1292 | printf(" startid = %d\n", index); |
|---|
| 1293 | printf(" end vspace %d\n\n", vspace_index); |
|---|
| 1294 | #endif |
|---|
| 1295 | } |
|---|
| 1296 | |
|---|
| 1297 | // checking startid values for all tasks in vspace |
|---|
| 1298 | int task_id; |
|---|
| 1299 | int task_min = vspace[vspace_index]->task_offset; |
|---|
| 1300 | int task_max = task_min + vspace[vspace_index]->tasks; |
|---|
| 1301 | for ( task_id = task_min ; task_id < task_max ; task_id++ ) |
|---|
| 1302 | { |
|---|
| 1303 | if ( task[task_id]->startid >= vspace[vspace_index]->tasks ) |
|---|
| 1304 | { |
|---|
| 1305 | printf("[XML ERROR] <startid> too large for task (%d,%d)\n", |
|---|
| 1306 | vspace_index, task_id ); |
|---|
| 1307 | exit(1); |
|---|
| 1308 | } |
|---|
| 1309 | } |
|---|
| 1310 | |
|---|
| 1311 | vspace_index++; |
|---|
| 1312 | return; |
|---|
| 1313 | } |
|---|
| 1314 | else |
|---|
| 1315 | { |
|---|
| 1316 | printf("[XML ERROR] Unknown tag %s",tag); |
|---|
| 1317 | exit(1); |
|---|
| 1318 | } |
|---|
| 1319 | status = xmlTextReaderRead ( reader ); |
|---|
| 1320 | } |
|---|
| 1321 | } // end vspaceNode() |
|---|
| 1322 | |
|---|
| 1323 | ////////////////////////////////////////// |
|---|
| 1324 | void psegNode ( xmlTextReaderPtr reader ) |
|---|
| 1325 | ////////////////////////////////////////// |
|---|
| 1326 | { |
|---|
| 1327 | unsigned int ok; |
|---|
| 1328 | unsigned int value; |
|---|
| 1329 | char* str; |
|---|
| 1330 | |
|---|
| 1331 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
|---|
| 1332 | |
|---|
| 1333 | if ( pseg_index >= MAX_PSEGS ) |
|---|
| 1334 | { |
|---|
| 1335 | printf("[XML ERROR] The number of psegs is larger than %d\n", MAX_PSEGS); |
|---|
| 1336 | exit(1); |
|---|
| 1337 | } |
|---|
| 1338 | |
|---|
| 1339 | #if XML_PARSER_DEBUG |
|---|
| 1340 | printf(" pseg %d\n", pseg_index); |
|---|
| 1341 | #endif |
|---|
| 1342 | |
|---|
| 1343 | pseg[pseg_index] = (mapping_pseg_t*)malloc(sizeof(mapping_pseg_t)); |
|---|
| 1344 | |
|---|
| 1345 | /////// get name attribute |
|---|
| 1346 | str = getStringValue( reader, "name", &ok ); |
|---|
| 1347 | #if XML_PARSER_DEBUG |
|---|
| 1348 | printf(" name = %s\n", str); |
|---|
| 1349 | #endif |
|---|
| 1350 | if ( ok ) |
|---|
| 1351 | { |
|---|
| 1352 | strncpy(pseg[pseg_index]->name, str, 31); |
|---|
| 1353 | } |
|---|
| 1354 | else |
|---|
| 1355 | { |
|---|
| 1356 | printf("[XML ERROR] illegal or missing <name> for pseg %d in cluster %d\n", |
|---|
| 1357 | pseg_index, cluster_index); |
|---|
| 1358 | exit(1); |
|---|
| 1359 | } |
|---|
| 1360 | |
|---|
| 1361 | //////// get type attribute |
|---|
| 1362 | str = getStringValue(reader, "type", &ok); |
|---|
| 1363 | #if XML_PARSER_DEBUG |
|---|
| 1364 | printf(" type = %s\n", str); |
|---|
| 1365 | #endif |
|---|
| 1366 | if (ok && (strcmp(str, "RAM" ) == 0)) pseg[pseg_index]->type = PSEG_TYPE_RAM; |
|---|
| 1367 | else if (ok && (strcmp(str, "ROM" ) == 0)) pseg[pseg_index]->type = PSEG_TYPE_ROM; |
|---|
| 1368 | else if (ok && (strcmp(str, "PERI") == 0)) pseg[pseg_index]->type = PSEG_TYPE_PERI; |
|---|
| 1369 | else |
|---|
| 1370 | { |
|---|
| 1371 | printf("[XML ERROR] illegal or missing <type> for pseg %s in cluster %d\n", |
|---|
| 1372 | pseg[pseg_index]->name, cluster_index); |
|---|
| 1373 | exit(1); |
|---|
| 1374 | } |
|---|
| 1375 | |
|---|
| 1376 | //////// get base attribute |
|---|
| 1377 | value = getIntValue( reader, "base", &ok ); |
|---|
| 1378 | #if XML_PARSER_DEBUG |
|---|
| 1379 | printf(" base = 0x%x\n", value); |
|---|
| 1380 | #endif |
|---|
| 1381 | if ( ok ) |
|---|
| 1382 | { |
|---|
| 1383 | pseg[pseg_index]->base = value; |
|---|
| 1384 | } |
|---|
| 1385 | else |
|---|
| 1386 | { |
|---|
| 1387 | printf("[XML ERROR] illegal or missing <base> for pseg %s in cluster %d\n", |
|---|
| 1388 | pseg[pseg_index]->name, cluster_index); |
|---|
| 1389 | exit(1); |
|---|
| 1390 | } |
|---|
| 1391 | |
|---|
| 1392 | //////// get length attribute |
|---|
| 1393 | value = getIntValue( reader, "length", &ok ); |
|---|
| 1394 | #if XML_PARSER_DEBUG |
|---|
| 1395 | printf(" length = 0x%x\n", value); |
|---|
| 1396 | #endif |
|---|
| 1397 | if ( ok ) |
|---|
| 1398 | { |
|---|
| 1399 | pseg[pseg_index]->length = value; |
|---|
| 1400 | } |
|---|
| 1401 | else |
|---|
| 1402 | { |
|---|
| 1403 | printf("[XML ERROR] illegal or missing <length> for pseg %s in cluster %d\n", |
|---|
| 1404 | pseg[pseg_index]->name, cluster_index); |
|---|
| 1405 | exit(1); |
|---|
| 1406 | } |
|---|
| 1407 | |
|---|
| 1408 | //////// set cluster attribute |
|---|
| 1409 | pseg[pseg_index]->cluster = cluster_index; |
|---|
| 1410 | |
|---|
| 1411 | pseg_index++; |
|---|
| 1412 | cluster[cluster_index]->psegs++; |
|---|
| 1413 | } // end psegNode() |
|---|
| 1414 | |
|---|
| 1415 | ///////////////////////////////////////////// |
|---|
| 1416 | void clusterNode ( xmlTextReaderPtr reader ) |
|---|
| 1417 | ///////////////////////////////////////////// |
|---|
| 1418 | { |
|---|
| 1419 | unsigned int ok; |
|---|
| 1420 | unsigned int value; |
|---|
| 1421 | |
|---|
| 1422 | proc_loc_index = 0; |
|---|
| 1423 | coproc_loc_index = 0; |
|---|
| 1424 | periph_loc_index = 0; |
|---|
| 1425 | |
|---|
| 1426 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
|---|
| 1427 | |
|---|
| 1428 | // checking source file consistency |
|---|
| 1429 | if ( cluster_index >= header->clusters ) |
|---|
| 1430 | { |
|---|
| 1431 | printf("[XML ERROR] The cluster index is too large : %d\n", cluster_index); |
|---|
| 1432 | exit(1); |
|---|
| 1433 | } |
|---|
| 1434 | |
|---|
| 1435 | #if XML_PARSER_DEBUG |
|---|
| 1436 | printf(" cluster %d\n", cluster_index); |
|---|
| 1437 | #endif |
|---|
| 1438 | |
|---|
| 1439 | cluster[cluster_index] = (mapping_cluster_t*)malloc(sizeof(mapping_cluster_t)); |
|---|
| 1440 | |
|---|
| 1441 | //initialise the number of pseg |
|---|
| 1442 | //it will be incremented by PsegNode |
|---|
| 1443 | cluster[cluster_index]->psegs = 0; |
|---|
| 1444 | |
|---|
| 1445 | /////////// check cluster index attribute (optional) |
|---|
| 1446 | value = getIntValue(reader,"index",&ok); |
|---|
| 1447 | if ( ok && (value != cluster_index) ) |
|---|
| 1448 | { |
|---|
| 1449 | printf("[XML ERROR] wrong cluster index / expected value is %d", |
|---|
| 1450 | cluster_index); |
|---|
| 1451 | exit(1); |
|---|
| 1452 | } |
|---|
| 1453 | |
|---|
| 1454 | ////////// set offsets |
|---|
| 1455 | cluster[cluster_index]->pseg_offset = pseg_index; |
|---|
| 1456 | cluster[cluster_index]->proc_offset = proc_index; |
|---|
| 1457 | cluster[cluster_index]->coproc_offset = coproc_index; |
|---|
| 1458 | cluster[cluster_index]->periph_offset = periph_index; |
|---|
| 1459 | |
|---|
| 1460 | #if XML_PARSER_DEBUG |
|---|
| 1461 | printf(" pseg_offset = %d\n", pseg_index); |
|---|
| 1462 | printf(" proc_offset = %d\n", proc_index); |
|---|
| 1463 | printf(" coproc_offset = %d\n", coproc_index); |
|---|
| 1464 | printf(" periph_offset = %d\n", coproc_index); |
|---|
| 1465 | #endif |
|---|
| 1466 | |
|---|
| 1467 | ////////// get psegs, procs, coprocs and periphs |
|---|
| 1468 | int status = xmlTextReaderRead(reader); |
|---|
| 1469 | |
|---|
| 1470 | while ( status == 1 ) |
|---|
| 1471 | { |
|---|
| 1472 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
|---|
| 1473 | |
|---|
| 1474 | if ( strcmp(tag, "pseg") == 0 ) psegNode(reader); |
|---|
| 1475 | else if ( strcmp(tag, "proc") == 0 ) procNode(reader); |
|---|
| 1476 | else if ( strcmp(tag, "coproc") == 0 ) coprocNode(reader); |
|---|
| 1477 | else if ( strcmp(tag, "periph") == 0 ) periphNode(reader); |
|---|
| 1478 | else if ( strcmp(tag, "#text") == 0 ) { } |
|---|
| 1479 | else if ( strcmp(tag, "#comment") == 0 ) { } |
|---|
| 1480 | else if ( strcmp(tag, "cluster") == 0 ) |
|---|
| 1481 | { |
|---|
| 1482 | cluster[cluster_index]->procs = proc_loc_index; |
|---|
| 1483 | cluster[cluster_index]->coprocs = coproc_loc_index; |
|---|
| 1484 | cluster[cluster_index]->periphs = periph_loc_index; |
|---|
| 1485 | |
|---|
| 1486 | // cluster[cluster_index]psegs update is done in psegNode(), |
|---|
| 1487 | // because the coprocNode() call to getPsegId() need it |
|---|
| 1488 | |
|---|
| 1489 | #if XML_PARSER_DEBUG |
|---|
| 1490 | printf(" psegs = %d\n", cluster[cluster_index]->psegs); |
|---|
| 1491 | printf(" procs = %d\n", cluster[cluster_index]->procs); |
|---|
| 1492 | printf(" coprocs = %d\n", cluster[cluster_index]->coprocs); |
|---|
| 1493 | printf(" periphs = %d\n", cluster[cluster_index]->periphs); |
|---|
| 1494 | printf(" end cluster %d\n", cluster_index); |
|---|
| 1495 | #endif |
|---|
| 1496 | cluster_index++; |
|---|
| 1497 | return; |
|---|
| 1498 | } |
|---|
| 1499 | status = xmlTextReaderRead(reader); |
|---|
| 1500 | } |
|---|
| 1501 | } // end clusterNode() |
|---|
| 1502 | |
|---|
| 1503 | ////////////////////////////////////////////// |
|---|
| 1504 | void clusterSetNode( xmlTextReaderPtr reader ) |
|---|
| 1505 | ////////////////////////////////////////////// |
|---|
| 1506 | { |
|---|
| 1507 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
|---|
| 1508 | |
|---|
| 1509 | #if XML_PARSER_DEBUG |
|---|
| 1510 | printf("\n clusters set\n"); |
|---|
| 1511 | #endif |
|---|
| 1512 | |
|---|
| 1513 | int status = xmlTextReaderRead(reader); |
|---|
| 1514 | while ( status == 1 ) |
|---|
| 1515 | { |
|---|
| 1516 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
|---|
| 1517 | |
|---|
| 1518 | if ( strcmp(tag, "cluster") == 0 ) clusterNode(reader); |
|---|
| 1519 | else if ( strcmp(tag, "#text") == 0 ) { } |
|---|
| 1520 | else if ( strcmp(tag, "#comment") == 0 ) { } |
|---|
| 1521 | else if ( strcmp(tag, "clusterset") == 0 ) |
|---|
| 1522 | { |
|---|
| 1523 | // checking source file consistency |
|---|
| 1524 | if ( cluster_index != header->clusters ) |
|---|
| 1525 | { |
|---|
| 1526 | printf("[XML ERROR] Wrong number of clusters\n"); |
|---|
| 1527 | exit(1); |
|---|
| 1528 | } |
|---|
| 1529 | else |
|---|
| 1530 | { |
|---|
| 1531 | #if XML_PARSER_DEBUG |
|---|
| 1532 | printf(" end cluster set\n\n"); |
|---|
| 1533 | #endif |
|---|
| 1534 | header->psegs = pseg_index; |
|---|
| 1535 | header->procs = proc_index; |
|---|
| 1536 | header->irqs = irq_index; |
|---|
| 1537 | header->coprocs = coproc_index; |
|---|
| 1538 | header->cp_ports = cp_port_index; |
|---|
| 1539 | return; |
|---|
| 1540 | } |
|---|
| 1541 | } |
|---|
| 1542 | else |
|---|
| 1543 | { |
|---|
| 1544 | printf("[XML ERROR] Unknown tag in clusterset node : %s",tag); |
|---|
| 1545 | exit(1); |
|---|
| 1546 | } |
|---|
| 1547 | status = xmlTextReaderRead(reader); |
|---|
| 1548 | } |
|---|
| 1549 | } // end clusterSetNode() |
|---|
| 1550 | |
|---|
| 1551 | ///////////////////////////////////////////// |
|---|
| 1552 | void globalSetNode( xmlTextReaderPtr reader ) |
|---|
| 1553 | ///////////////////////////////////////////// |
|---|
| 1554 | { |
|---|
| 1555 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
|---|
| 1556 | |
|---|
| 1557 | #if XML_PARSER_DEBUG |
|---|
| 1558 | printf(" globals set\n"); |
|---|
| 1559 | #endif |
|---|
| 1560 | |
|---|
| 1561 | int status = xmlTextReaderRead(reader); |
|---|
| 1562 | while ( status == 1 ) |
|---|
| 1563 | { |
|---|
| 1564 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
|---|
| 1565 | |
|---|
| 1566 | if ( strcmp(tag, "vseg") == 0 ) vsegNode(reader); |
|---|
| 1567 | else if ( strcmp(tag, "#text" ) == 0 ) { } |
|---|
| 1568 | else if ( strcmp(tag, "#comment") == 0 ) { } |
|---|
| 1569 | else if ( strcmp(tag, "globalset") == 0 ) |
|---|
| 1570 | { |
|---|
| 1571 | #if XML_PARSER_DEBUG |
|---|
| 1572 | printf(" end global set\n\n"); |
|---|
| 1573 | #endif |
|---|
| 1574 | header->globals = vseg_index; |
|---|
| 1575 | vseg_loc_index = 0; |
|---|
| 1576 | return; |
|---|
| 1577 | } |
|---|
| 1578 | else |
|---|
| 1579 | { |
|---|
| 1580 | printf("[XML ERROR] Unknown tag in globalset node : %s",tag); |
|---|
| 1581 | exit(1); |
|---|
| 1582 | } |
|---|
| 1583 | status = xmlTextReaderRead ( reader ); |
|---|
| 1584 | } |
|---|
| 1585 | } // end globalSetNode() |
|---|
| 1586 | |
|---|
| 1587 | ///////////////////////////////////////////// |
|---|
| 1588 | void vspaceSetNode( xmlTextReaderPtr reader ) |
|---|
| 1589 | ///////////////////////////////////////////// |
|---|
| 1590 | { |
|---|
| 1591 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
|---|
| 1592 | |
|---|
| 1593 | #if XML_PARSER_DEBUG |
|---|
| 1594 | printf("\n vspaces set\n"); |
|---|
| 1595 | #endif |
|---|
| 1596 | |
|---|
| 1597 | int status = xmlTextReaderRead ( reader ); |
|---|
| 1598 | while ( status == 1 ) |
|---|
| 1599 | { |
|---|
| 1600 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
|---|
| 1601 | |
|---|
| 1602 | if ( strcmp(tag, "vspace" ) == 0 ) vspaceNode(reader); |
|---|
| 1603 | else if ( strcmp(tag, "#text" ) == 0 ) { } |
|---|
| 1604 | else if ( strcmp(tag, "#comment" ) == 0 ) { } |
|---|
| 1605 | else if ( strcmp(tag, "vspaceset") == 0 ) |
|---|
| 1606 | { |
|---|
| 1607 | // checking source file consistency |
|---|
| 1608 | if ( vspace_index != header->vspaces ) |
|---|
| 1609 | { |
|---|
| 1610 | printf("[XML ERROR] Wrong number of vspaces\n"); |
|---|
| 1611 | exit(1); |
|---|
| 1612 | } |
|---|
| 1613 | else |
|---|
| 1614 | { |
|---|
| 1615 | header->vsegs = vseg_index; |
|---|
| 1616 | header->vobjs = vobj_index; |
|---|
| 1617 | header->tasks = task_index; |
|---|
| 1618 | return; |
|---|
| 1619 | } |
|---|
| 1620 | } |
|---|
| 1621 | else |
|---|
| 1622 | { |
|---|
| 1623 | printf("[XML ERROR] Unknown tag in vspaceset node : %s",tag); |
|---|
| 1624 | exit(1); |
|---|
| 1625 | } |
|---|
| 1626 | status = xmlTextReaderRead ( reader ); |
|---|
| 1627 | } |
|---|
| 1628 | } // end globalSetNode() |
|---|
| 1629 | |
|---|
| 1630 | ////////////////////////////////////////// |
|---|
| 1631 | void headerNode(xmlTextReaderPtr reader ) |
|---|
| 1632 | ////////////////////////////////////////// |
|---|
| 1633 | { |
|---|
| 1634 | char* name; |
|---|
| 1635 | unsigned int value; |
|---|
| 1636 | unsigned int ok; |
|---|
| 1637 | |
|---|
| 1638 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
|---|
| 1639 | |
|---|
| 1640 | #if XML_PARSER_DEBUG |
|---|
| 1641 | printf("mapping_info\n"); |
|---|
| 1642 | #endif |
|---|
| 1643 | |
|---|
| 1644 | header = (mapping_header_t*)malloc(sizeof(mapping_header_t)); |
|---|
| 1645 | |
|---|
| 1646 | ////////// get name attribute |
|---|
| 1647 | name = getStringValue(reader, "name", &ok); |
|---|
| 1648 | if ( ok ) |
|---|
| 1649 | { |
|---|
| 1650 | #if XML_PARSER_DEBUG |
|---|
| 1651 | printf(" name = %s\n", name); |
|---|
| 1652 | #endif |
|---|
| 1653 | strncpy( header->name, name, 31); |
|---|
| 1654 | } |
|---|
| 1655 | else |
|---|
| 1656 | { |
|---|
| 1657 | printf("[XML ERROR] illegal or missing <name> attribute in header\n"); |
|---|
| 1658 | exit(1); |
|---|
| 1659 | } |
|---|
| 1660 | |
|---|
| 1661 | /////////// get clusters attribute |
|---|
| 1662 | value = getIntValue(reader, "clusters", &ok); |
|---|
| 1663 | if ( ok ) |
|---|
| 1664 | { |
|---|
| 1665 | if ( value >= MAX_CLUSTERS ) |
|---|
| 1666 | { |
|---|
| 1667 | printf("[XML ERROR] The number of clusters is larger than %d\n", MAX_CLUSTERS); |
|---|
| 1668 | exit(1); |
|---|
| 1669 | } |
|---|
| 1670 | #if XML_PARSER_DEBUG |
|---|
| 1671 | printf(" clusters = %d\n", value); |
|---|
| 1672 | #endif |
|---|
| 1673 | header->clusters = value; |
|---|
| 1674 | } |
|---|
| 1675 | else |
|---|
| 1676 | { |
|---|
| 1677 | printf("[XML ERROR] illegal or missing <clusters> attribute in header\n"); |
|---|
| 1678 | exit(1); |
|---|
| 1679 | } |
|---|
| 1680 | |
|---|
| 1681 | ///////// get vspaces attribute |
|---|
| 1682 | value = getIntValue(reader, "vspaces", &ok); |
|---|
| 1683 | if ( ok ) |
|---|
| 1684 | { |
|---|
| 1685 | if ( value >= MAX_VSPACES ) |
|---|
| 1686 | { |
|---|
| 1687 | printf("[XML ERROR] The number of vspaces is larger than %d\n", MAX_VSPACES); |
|---|
| 1688 | exit(1); |
|---|
| 1689 | } |
|---|
| 1690 | #if XML_PARSER_DEBUG |
|---|
| 1691 | printf(" vspaces = %d\n", value); |
|---|
| 1692 | #endif |
|---|
| 1693 | header->vspaces = value; |
|---|
| 1694 | } |
|---|
| 1695 | else |
|---|
| 1696 | { |
|---|
| 1697 | printf("[XML ERROR] illegal or missing <vspaces> attribute in mapping\n"); |
|---|
| 1698 | exit(1); |
|---|
| 1699 | } |
|---|
| 1700 | |
|---|
| 1701 | //////// initialise non replicated peripherals cluster_id |
|---|
| 1702 | header->tty_clusterid = 0xFFFFFFFF; |
|---|
| 1703 | header->nic_clusterid = 0xFFFFFFFF; |
|---|
| 1704 | header->ioc_clusterid = 0xFFFFFFFF; |
|---|
| 1705 | header->fbf_clusterid = 0xFFFFFFFF; |
|---|
| 1706 | |
|---|
| 1707 | ///////// set signature |
|---|
| 1708 | header->signature = IN_MAPPING_SIGNATURE; |
|---|
| 1709 | |
|---|
| 1710 | int status = xmlTextReaderRead(reader); |
|---|
| 1711 | while ( status == 1 ) |
|---|
| 1712 | { |
|---|
| 1713 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
|---|
| 1714 | |
|---|
| 1715 | if ( strcmp(tag, "clusterset") == 0 ) clusterSetNode(reader); |
|---|
| 1716 | else if ( strcmp(tag, "globalset") == 0 ) globalSetNode(reader); |
|---|
| 1717 | else if ( strcmp(tag, "vspaceset") == 0 ) vspaceSetNode(reader); |
|---|
| 1718 | else if ( strcmp(tag, "#text") == 0 ) { } |
|---|
| 1719 | else if ( strcmp(tag, "#comment") == 0 ) { } |
|---|
| 1720 | else if ( strcmp(tag, "mapping_info") == 0 ) |
|---|
| 1721 | { |
|---|
| 1722 | #if XML_PARSER_DEBUG |
|---|
| 1723 | printf("end mapping_info\n"); |
|---|
| 1724 | #endif |
|---|
| 1725 | return; |
|---|
| 1726 | } |
|---|
| 1727 | else |
|---|
| 1728 | { |
|---|
| 1729 | printf("[XML ERROR] Unknown tag in header node : %s\n",tag); |
|---|
| 1730 | exit(1); |
|---|
| 1731 | } |
|---|
| 1732 | status = xmlTextReaderRead(reader); |
|---|
| 1733 | } |
|---|
| 1734 | } // end headerNode() |
|---|
| 1735 | |
|---|
| 1736 | /////////////////////////////////////// |
|---|
| 1737 | void BuildTable( int fdout, |
|---|
| 1738 | const char* type, |
|---|
| 1739 | unsigned int nb_elem, |
|---|
| 1740 | unsigned int elem_size, |
|---|
| 1741 | char** table) |
|---|
| 1742 | //////////////////////////////////////// |
|---|
| 1743 | { |
|---|
| 1744 | unsigned int i; |
|---|
| 1745 | unsigned int length; |
|---|
| 1746 | // write element |
|---|
| 1747 | for ( i = 0 ; i < nb_elem ; i++ ) |
|---|
| 1748 | { |
|---|
| 1749 | length = write(fdout, table[i], elem_size); |
|---|
| 1750 | |
|---|
| 1751 | #if XML_PARSER_DEBUG |
|---|
| 1752 | printf("Building binary: writing %s %d\n", type, i); |
|---|
| 1753 | #endif |
|---|
| 1754 | |
|---|
| 1755 | if ( length != elem_size ) |
|---|
| 1756 | { |
|---|
| 1757 | printf("type: %s\n", type); |
|---|
| 1758 | perror("error writing"); |
|---|
| 1759 | exit(1); |
|---|
| 1760 | } |
|---|
| 1761 | } |
|---|
| 1762 | } |
|---|
| 1763 | |
|---|
| 1764 | /////////////////////////// |
|---|
| 1765 | void buildBin( int fdout ) |
|---|
| 1766 | /////////////////////////// |
|---|
| 1767 | { |
|---|
| 1768 | unsigned int vspace_id; |
|---|
| 1769 | unsigned int vobj_id; |
|---|
| 1770 | unsigned int length; |
|---|
| 1771 | |
|---|
| 1772 | // write header to binary file |
|---|
| 1773 | length = write(fdout, (char*)header, sizeof(mapping_header_t)); |
|---|
| 1774 | |
|---|
| 1775 | #if XML_PARSER_DEBUG |
|---|
| 1776 | printf("\n*** write header\n"); |
|---|
| 1777 | #endif |
|---|
| 1778 | |
|---|
| 1779 | if ( length != sizeof(mapping_header_t) ) |
|---|
| 1780 | { |
|---|
| 1781 | printf("write header error : length = %d \n", length); |
|---|
| 1782 | exit(1); |
|---|
| 1783 | } |
|---|
| 1784 | |
|---|
| 1785 | // write clusters |
|---|
| 1786 | BuildTable(fdout, "cluster", cluster_index, sizeof(mapping_cluster_t), (char**) cluster); |
|---|
| 1787 | |
|---|
| 1788 | // write psegs |
|---|
| 1789 | BuildTable(fdout, "pseg", pseg_index, sizeof(mapping_pseg_t), (char**) pseg); |
|---|
| 1790 | |
|---|
| 1791 | // write vspaces |
|---|
| 1792 | for ( vspace_id = 0 ; vspace_id < header->vspaces ; vspace_id++ ) |
|---|
| 1793 | { |
|---|
| 1794 | length = write(fdout, (char*)vspace[vspace_id], sizeof(mapping_vspace_t)); |
|---|
| 1795 | |
|---|
| 1796 | #if XML_PARSER_DEBUG |
|---|
| 1797 | printf("write vspace %d\n", vspace_id); |
|---|
| 1798 | printf("vspace->vobj_offset: %d\n", vspace[vspace_id]->vobj_offset); |
|---|
| 1799 | printf("vspace->vobjs: %d\n", vspace[vspace_id]->vobjs); |
|---|
| 1800 | printf("header->vobjs: %d\n", header->vobjs); |
|---|
| 1801 | #endif |
|---|
| 1802 | |
|---|
| 1803 | if ( length != sizeof(mapping_vspace_t) ) |
|---|
| 1804 | { |
|---|
| 1805 | perror("write vspace"); |
|---|
| 1806 | exit(1); |
|---|
| 1807 | } |
|---|
| 1808 | } |
|---|
| 1809 | |
|---|
| 1810 | // write vsegs |
|---|
| 1811 | BuildTable(fdout, "vseg", vseg_index, sizeof(mapping_vseg_t), (char**) vseg); |
|---|
| 1812 | |
|---|
| 1813 | // write vobjs |
|---|
| 1814 | for ( vobj_id = 0 ; vobj_id < header->vobjs ; vobj_id++ ) |
|---|
| 1815 | { |
|---|
| 1816 | length = write(fdout, (char*)vobj[vobj_id], sizeof(mapping_vobj_t)); |
|---|
| 1817 | |
|---|
| 1818 | #if XML_PARSER_DEBUG |
|---|
| 1819 | printf("write vobj %d\n", vobj_id); |
|---|
| 1820 | printf("write vobj name %s\n", vobj[vobj_id]->name); |
|---|
| 1821 | printf("write vobj length %x\n", vobj[vobj_id]->length); |
|---|
| 1822 | printf("write vobj type %d\n", vobj[vobj_id]->type); |
|---|
| 1823 | #endif |
|---|
| 1824 | |
|---|
| 1825 | if ( length != sizeof(mapping_vobj_t) ) |
|---|
| 1826 | { |
|---|
| 1827 | perror("write vobj"); |
|---|
| 1828 | exit(1); |
|---|
| 1829 | } |
|---|
| 1830 | } |
|---|
| 1831 | |
|---|
| 1832 | // write tasks array |
|---|
| 1833 | BuildTable(fdout, "task", task_index, sizeof(mapping_task_t), (char**) task); |
|---|
| 1834 | //building procs array |
|---|
| 1835 | BuildTable(fdout, "proc", proc_index, sizeof(mapping_proc_t), (char**) proc); |
|---|
| 1836 | //building irqs array |
|---|
| 1837 | BuildTable(fdout, "irq", irq_index, sizeof(mapping_irq_t), (char**)irq); |
|---|
| 1838 | //building coprocs array |
|---|
| 1839 | BuildTable(fdout, "coproc", coproc_index, sizeof(mapping_coproc_t), (char**)coproc); |
|---|
| 1840 | //building cp_ports array |
|---|
| 1841 | BuildTable(fdout, "cp_port", cp_port_index, sizeof(mapping_cp_port_t),(char**) cp_port); |
|---|
| 1842 | //building periphs array |
|---|
| 1843 | BuildTable(fdout, "periph", periph_index, sizeof(mapping_periph_t), (char**)periph); |
|---|
| 1844 | |
|---|
| 1845 | } // end buildBin() |
|---|
| 1846 | |
|---|
| 1847 | /////////////////////////////////////////////////////////////////////// |
|---|
| 1848 | // this function set the value the vobj_id fiels of all cp_ports |
|---|
| 1849 | /////////////////////////////////////////////////////////////////////// |
|---|
| 1850 | void prepareBuild() |
|---|
| 1851 | { |
|---|
| 1852 | unsigned int i; |
|---|
| 1853 | //asign for all cp_ports the correct vspaceid and vobjid |
|---|
| 1854 | for(i=0; i< cp_port_index; i++) |
|---|
| 1855 | { |
|---|
| 1856 | int vspace_id = getVspaceId( cp_port_vobj_ref[i]->vspace_name ); |
|---|
| 1857 | if ( vspace_id < 0 ) |
|---|
| 1858 | { |
|---|
| 1859 | printf("[XML ERROR] illegal <vspacename> for cp_port %d,\n", |
|---|
| 1860 | i); |
|---|
| 1861 | exit(1); |
|---|
| 1862 | } |
|---|
| 1863 | cp_port[i]->vspaceid = vspace_id; |
|---|
| 1864 | |
|---|
| 1865 | int vobj_id = getVobjLocId( vspace_id, |
|---|
| 1866 | cp_port_vobj_ref[i]->vobj_name, |
|---|
| 1867 | vspace[vspace_id]->vobjs ); |
|---|
| 1868 | if ( vobj_id >= 0 ) |
|---|
| 1869 | { |
|---|
| 1870 | |
|---|
| 1871 | #if XML_PARSER_DEBUG |
|---|
| 1872 | printf("\ncp_port = %d\n", i); |
|---|
| 1873 | printf(" vspace_name = %s\n", cp_port_vobj_ref[i]->vspace_name); |
|---|
| 1874 | printf(" vobj_name = %s\n", cp_port_vobj_ref[i]->vobj_name); |
|---|
| 1875 | printf(" vobj_index = %d\n", vobj_id); |
|---|
| 1876 | #endif |
|---|
| 1877 | cp_port[i]->vobjlocid = vobj_id; |
|---|
| 1878 | |
|---|
| 1879 | assert((vobj[ vspace[vspace_id]->vobj_offset + vobj_id]->type == VOBJ_TYPE_MWMR) |
|---|
| 1880 | && "coproc ports has to refere to a vobj of type MWMR"); |
|---|
| 1881 | } |
|---|
| 1882 | else |
|---|
| 1883 | { |
|---|
| 1884 | printf("[XML ERROR] illegal <vobjname> for cp_port %d,\n", |
|---|
| 1885 | i); |
|---|
| 1886 | exit(1); |
|---|
| 1887 | } |
|---|
| 1888 | } |
|---|
| 1889 | } |
|---|
| 1890 | |
|---|
| 1891 | ///////////////////////////////////// |
|---|
| 1892 | int main ( int argc, char* argv[] ) |
|---|
| 1893 | ///////////////////////////////////// |
|---|
| 1894 | { |
|---|
| 1895 | if ( argc < 3 ) |
|---|
| 1896 | { |
|---|
| 1897 | printf("Usage: xml2bin <input_file_path> <output_file_path>\n"); |
|---|
| 1898 | return 1; |
|---|
| 1899 | } |
|---|
| 1900 | |
|---|
| 1901 | int fdout = open( argv[2], (O_CREAT | O_RDWR), S_IRWXU ); |
|---|
| 1902 | if ( fdout < 0) |
|---|
| 1903 | { |
|---|
| 1904 | perror("open"); |
|---|
| 1905 | exit(1); |
|---|
| 1906 | } |
|---|
| 1907 | |
|---|
| 1908 | LIBXML_TEST_VERSION; |
|---|
| 1909 | |
|---|
| 1910 | int status; |
|---|
| 1911 | xmlTextReaderPtr reader = xmlReaderForFile ( argv[1], NULL, 0 ); |
|---|
| 1912 | |
|---|
| 1913 | if ( reader != NULL ) |
|---|
| 1914 | { |
|---|
| 1915 | status = xmlTextReaderRead ( reader ); |
|---|
| 1916 | while ( status == 1 ) |
|---|
| 1917 | { |
|---|
| 1918 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
|---|
| 1919 | |
|---|
| 1920 | if ( strcmp(tag,"mapping_info") == 0 ) |
|---|
| 1921 | { |
|---|
| 1922 | headerNode( reader ); |
|---|
| 1923 | prepareBuild(); |
|---|
| 1924 | buildBin( fdout ); |
|---|
| 1925 | } |
|---|
| 1926 | else |
|---|
| 1927 | { |
|---|
| 1928 | printf("[XML ERROR] Wrong file type: \"%s\"\n", argv[1]); |
|---|
| 1929 | return 1; |
|---|
| 1930 | } |
|---|
| 1931 | status = xmlTextReaderRead ( reader ); |
|---|
| 1932 | } |
|---|
| 1933 | xmlFreeTextReader ( reader ); |
|---|
| 1934 | |
|---|
| 1935 | if ( status != 0 ) |
|---|
| 1936 | { |
|---|
| 1937 | printf("[XML ERROR] Wrong Syntax in \"%s\" file\n", argv[1]); |
|---|
| 1938 | return 1; |
|---|
| 1939 | } |
|---|
| 1940 | } |
|---|
| 1941 | return 0; |
|---|
| 1942 | } // end main() |
|---|