[158] | 1 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
| 2 | // File : xml_parser.c |
---|
[181] | 3 | // Date : 14/04/2012 |
---|
[158] | 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> |
---|
[162] | 14 | #include <sys/types.h> |
---|
| 15 | #include <sys/stat.h> |
---|
[158] | 16 | #include <unistd.h> |
---|
| 17 | #include <stdio.h> |
---|
| 18 | #include <string.h> |
---|
[181] | 19 | #include <assert.h> |
---|
[158] | 20 | #include <libxml/xmlreader.h> |
---|
| 21 | #include <mapping_info.h> |
---|
[189] | 22 | #include <irq_handler.h> |
---|
[158] | 23 | |
---|
[160] | 24 | #define MAX_CLUSTERS 1024 |
---|
[158] | 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 |
---|
[160] | 30 | #define MAX_VOBJS 8192 |
---|
[181] | 31 | #define MAX_PROCS 1024 |
---|
| 32 | #define MAX_IRQS 8192 |
---|
| 33 | #define MAX_COPROCS 4096 |
---|
| 34 | #define MAX_CP_PORTS 8192 |
---|
[189] | 35 | #define MAX_PERIPHS 8192 |
---|
[158] | 36 | |
---|
[183] | 37 | #define XML_PARSER_DEBUG 0 |
---|
[158] | 38 | |
---|
| 39 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 40 | // global variables used to store and index the data structures |
---|
| 41 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 42 | |
---|
[181] | 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 |
---|
[189] | 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 |
---|
[158] | 55 | |
---|
[189] | 56 | // Index for the various arrays |
---|
[181] | 57 | |
---|
[158] | 58 | unsigned int cluster_index = 0; |
---|
| 59 | unsigned int vspace_index = 0; |
---|
| 60 | unsigned int global_index = 0; |
---|
[181] | 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 | |
---|
[189] | 75 | unsigned int periph_index = 0; |
---|
| 76 | unsigned int periph_loc_index = 0; |
---|
[181] | 77 | |
---|
[158] | 78 | unsigned int vseg_index = 0; |
---|
| 79 | unsigned int vseg_loc_index = 0; |
---|
[189] | 80 | |
---|
[158] | 81 | unsigned int task_index = 0; |
---|
| 82 | unsigned int task_loc_index = 0; |
---|
[189] | 83 | |
---|
[160] | 84 | unsigned int vobj_index = 0; |
---|
| 85 | unsigned int vobj_loc_index = 0; |
---|
[165] | 86 | unsigned int vobj_count = 0; |
---|
| 87 | |
---|
[189] | 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 | |
---|
[158] | 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 | |
---|
[181] | 173 | /////////////////////////////////////// |
---|
| 174 | int getPsegId( unsigned int cluster_id, |
---|
| 175 | char* pseg_name ) |
---|
[158] | 176 | { |
---|
| 177 | unsigned int pseg_id; |
---|
[181] | 178 | unsigned int pseg_min = cluster[cluster_id]->pseg_offset; |
---|
| 179 | unsigned int pseg_max = pseg_min + cluster[cluster_id]->psegs; |
---|
[158] | 180 | |
---|
[181] | 181 | for ( pseg_id = pseg_min ; pseg_id < pseg_max ; pseg_id++ ) |
---|
[158] | 182 | { |
---|
[181] | 183 | if ( strcmp(pseg[pseg_id]->name, pseg_name) == 0 ) return pseg_id; |
---|
[158] | 184 | } |
---|
| 185 | return -1; |
---|
| 186 | } |
---|
| 187 | |
---|
[181] | 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 | //////////////////////////////////////////// |
---|
[160] | 204 | int getVobjLocId( unsigned int vspace_id, |
---|
[181] | 205 | char* vobj_name, |
---|
| 206 | unsigned int vspace_max) |
---|
[158] | 207 | { |
---|
[160] | 208 | unsigned int vobj_id; |
---|
| 209 | unsigned int vobj_min = vspace[vspace_id]->vobj_offset; |
---|
[181] | 210 | unsigned int vobj_max = vobj_min + vspace_max; |
---|
[158] | 211 | |
---|
[160] | 212 | for ( vobj_id = vobj_min ; vobj_id < vobj_max ; vobj_id++ ) |
---|
[158] | 213 | { |
---|
[181] | 214 | if ( strcmp(vobj[vobj_id]->name, vobj_name) == 0 ) |
---|
[160] | 215 | { |
---|
| 216 | return (vobj_id - vobj_min); |
---|
| 217 | } |
---|
[158] | 218 | } |
---|
| 219 | return -1; |
---|
| 220 | } |
---|
| 221 | |
---|
[181] | 222 | /////////////////////////////////////////// |
---|
| 223 | void cpPortNode ( xmlTextReaderPtr reader ) |
---|
| 224 | /////////////////////////////////////////// |
---|
[158] | 225 | { |
---|
[181] | 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 | |
---|
[189] | 240 | cp_port[cp_port_index] = (mapping_cp_port_t*)malloc(sizeof(mapping_cp_port_t)); |
---|
[181] | 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") ) cp_port[cp_port_index]->direction = PORT_TO_COPROC; |
---|
| 253 | else if ( strcmp(str, "FROM_COPROC") ) cp_port[cp_port_index]->direction = PORT_FROM_COPROC; |
---|
| 254 | else |
---|
| 255 | { |
---|
[189] | 256 | printf("[XML ERROR] illegal <direction> for cp_port %d in cluster %d\n", |
---|
[181] | 257 | cp_port_index, cluster_index); |
---|
| 258 | exit(1); |
---|
| 259 | } |
---|
| 260 | } |
---|
| 261 | else |
---|
| 262 | { |
---|
[189] | 263 | printf("[XML ERROR] missing <direction> for cp_port %d in cluster %d\n", |
---|
[181] | 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 | { |
---|
[189] | 279 | printf("[XML ERROR] missing <vspacename> for cp_port %d in cluster %d\n", |
---|
[181] | 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 | { |
---|
[189] | 295 | printf("[XML ERROR] missing <vobjname> for cp_port %d in cluster %d\n", |
---|
[181] | 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 | |
---|
[189] | 305 | /////////////////////////////////////////// |
---|
| 306 | void periphNode ( xmlTextReaderPtr reader ) |
---|
| 307 | /////////////////////////////////////////// |
---|
[181] | 308 | { |
---|
| 309 | char* str; |
---|
| 310 | unsigned int value; |
---|
[189] | 311 | unsigned int ok; |
---|
[181] | 312 | |
---|
| 313 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
---|
| 314 | |
---|
[189] | 315 | if ( periph_index >= MAX_PERIPHS ) |
---|
[181] | 316 | { |
---|
[189] | 317 | printf("[XML ERROR] The number of periphs is larger than %d\n", MAX_PERIPHS); |
---|
[181] | 318 | } |
---|
| 319 | |
---|
| 320 | #if XML_PARSER_DEBUG |
---|
[189] | 321 | printf("\n periph %d\n", periph_index); |
---|
[181] | 322 | #endif |
---|
| 323 | |
---|
[189] | 324 | periph[periph_index] = (mapping_periph_t*)malloc(sizeof(mapping_periph_t)); |
---|
[181] | 325 | |
---|
[189] | 326 | /////////// get type attribute |
---|
| 327 | str = getStringValue( reader, "type", &ok ); |
---|
[181] | 328 | if ( ok ) |
---|
| 329 | { |
---|
| 330 | #if XML_PARSER_DEBUG |
---|
[189] | 331 | printf(" type = %s\n", str); |
---|
[181] | 332 | #endif |
---|
[189] | 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 | } |
---|
[181] | 373 | else |
---|
| 374 | { |
---|
[189] | 375 | printf("[XML ERROR] illegal <type> for peripheral %d in cluster %d\n", |
---|
| 376 | periph_loc_index, cluster_index); |
---|
[181] | 377 | exit(1); |
---|
| 378 | } |
---|
[189] | 379 | } |
---|
[181] | 380 | else |
---|
| 381 | { |
---|
[189] | 382 | printf("[XML ERROR] missing <type> for peripheral %d in cluster %d\n", |
---|
| 383 | periph_loc_index, cluster_index); |
---|
[181] | 384 | exit(1); |
---|
| 385 | } |
---|
| 386 | |
---|
[189] | 387 | ///////// get channels attribute (optionnal : 1 if missing) |
---|
| 388 | value = getIntValue( reader, "channels", &ok ); |
---|
[181] | 389 | if ( ok ) |
---|
| 390 | { |
---|
| 391 | #if XML_PARSER_DEBUG |
---|
[189] | 392 | printf(" channels = %d\n", value); |
---|
[181] | 393 | #endif |
---|
[189] | 394 | periph[periph_index]->channels = value; |
---|
[181] | 395 | } |
---|
| 396 | else |
---|
| 397 | { |
---|
[189] | 398 | periph[periph_index]->channels = 1; |
---|
[181] | 399 | } |
---|
| 400 | |
---|
[189] | 401 | /////////// get psegname attribute |
---|
| 402 | str = getStringValue(reader,"psegname", &ok); |
---|
| 403 | if ( ok == 0 ) |
---|
[181] | 404 | { |
---|
[189] | 405 | printf("[XML ERROR] illegal or missing <psegname> for coproc %d in cluster %d\n", |
---|
| 406 | coproc_index, cluster_index); |
---|
[181] | 407 | exit(1); |
---|
| 408 | } |
---|
| 409 | |
---|
[189] | 410 | /////////// set psegid attribute |
---|
| 411 | int index = getPsegId( cluster_index, str ); |
---|
| 412 | if ( index >= 0 ) |
---|
[181] | 413 | { |
---|
| 414 | #if XML_PARSER_DEBUG |
---|
[189] | 415 | printf(" clusterid = %d\n", cluster_index); |
---|
| 416 | printf(" psegname = %s\n", str); |
---|
| 417 | printf(" psegid = %d\n", index); |
---|
[181] | 418 | #endif |
---|
[189] | 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" ); |
---|
[181] | 422 | } |
---|
[189] | 423 | else |
---|
[181] | 424 | { |
---|
[189] | 425 | printf("[XML ERROR] pseg not found for periph %d / clusterid = %d / psegname = %s\n", |
---|
| 426 | periph_loc_index, cluster_index, str ); |
---|
[181] | 427 | exit(1); |
---|
[189] | 428 | } |
---|
[181] | 429 | |
---|
[189] | 430 | periph_index++; |
---|
| 431 | periph_loc_index++; |
---|
[181] | 432 | |
---|
[189] | 433 | } // end periphNode |
---|
[181] | 434 | |
---|
| 435 | ///////////////////////////////////////// |
---|
| 436 | void coprocNode ( xmlTextReaderPtr reader ) |
---|
| 437 | ///////////////////////////////////////// |
---|
| 438 | { |
---|
| 439 | char* str; |
---|
[158] | 440 | unsigned int ok; |
---|
[181] | 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 | |
---|
[189] | 501 | ////////// set port_offset |
---|
[181] | 502 | coproc[coproc_index]->port_offset = cp_port_index; |
---|
| 503 | |
---|
| 504 | #if XML_PARSER_DEBUG |
---|
[189] | 505 | printf(" port_offset = %d\n", cp_port_index); |
---|
[181] | 506 | #endif |
---|
| 507 | |
---|
| 508 | int status = xmlTextReaderRead(reader); |
---|
| 509 | while ( status == 1 ) |
---|
| 510 | { |
---|
| 511 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
---|
| 512 | |
---|
[189] | 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 ) |
---|
[181] | 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; |
---|
[158] | 537 | unsigned int value; |
---|
| 538 | char* str; |
---|
| 539 | |
---|
| 540 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
---|
| 541 | |
---|
[181] | 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 |
---|
[189] | 560 | if ( strcmp(str, "HARD") == 0 ) irq[irq_index]->type = 0; |
---|
| 561 | else if ( strcmp(str, "SOFT") == 0 ) irq[irq_index]->type = 1; |
---|
[181] | 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 | |
---|
[189] | 576 | ///////// get icuid attribute |
---|
[181] | 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 |
---|
[189] | 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; |
---|
[181] | 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 | } |
---|
[189] | 616 | #if XML_PARSER_DEBUG |
---|
| 617 | printf(" isrnum = %d\n", irq[irq_index]->isr); |
---|
| 618 | #endif |
---|
[181] | 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_index) ) |
---|
| 672 | { |
---|
| 673 | printf("[XML ERROR] wrong proc index / expected value is %d", |
---|
| 674 | proc_index); |
---|
| 675 | exit(1); |
---|
| 676 | } |
---|
| 677 | |
---|
| 678 | ////////// set irq_offset attribute |
---|
| 679 | proc[proc_index]->irq_offset = irq_index; |
---|
[189] | 680 | |
---|
[181] | 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 | |
---|
[189] | 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 ) |
---|
[181] | 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 | |
---|
[158] | 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 |
---|
[165] | 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 | } |
---|
[158] | 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 |
---|
[165] | 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 | } |
---|
[158] | 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 | { |
---|
[181] | 795 | int index = getVobjLocId( vspace_index, str , vobj_loc_index); |
---|
[158] | 796 | if ( index >= 0 ) |
---|
| 797 | { |
---|
| 798 | #if XML_PARSER_DEBUG |
---|
| 799 | printf(" stackname = %s\n", str); |
---|
[165] | 800 | printf(" stackid = %d\n", index); |
---|
[158] | 801 | #endif |
---|
[160] | 802 | task[task_index]->vobjlocid = index; |
---|
[158] | 803 | } |
---|
| 804 | else |
---|
| 805 | { |
---|
[165] | 806 | printf("[XML ERROR] illegal or missing <stackname> for task (%d,%d)\n", |
---|
| 807 | vspace_index, task_loc_index); |
---|
[158] | 808 | exit(1); |
---|
| 809 | } |
---|
| 810 | } |
---|
| 811 | else |
---|
| 812 | { |
---|
[165] | 813 | printf("[XML ERROR] illegal or missing <stackname> for task (%d,%d)\n", |
---|
[158] | 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 | |
---|
[189] | 834 | /////////// get usetty attribute (optionnal : 0 if missing) |
---|
[165] | 835 | value = getIntValue(reader,"usetty", &ok); |
---|
[158] | 836 | if ( ok ) |
---|
| 837 | { |
---|
| 838 | #if XML_PARSER_DEBUG |
---|
[165] | 839 | printf(" usetty = %x\n", value); |
---|
[158] | 840 | #endif |
---|
[165] | 841 | task[task_index]->use_tty = value; |
---|
[158] | 842 | } |
---|
| 843 | else |
---|
| 844 | { |
---|
[165] | 845 | task[task_index]->use_tty = 0; |
---|
| 846 | } |
---|
| 847 | |
---|
[189] | 848 | /////////// get usenic attribute (optionnal : 0 if missing) |
---|
| 849 | value = getIntValue(reader,"usenic", &ok); |
---|
[165] | 850 | if ( ok ) |
---|
| 851 | { |
---|
| 852 | #if XML_PARSER_DEBUG |
---|
[189] | 853 | printf(" usenic = %x\n", value); |
---|
[165] | 854 | #endif |
---|
[189] | 855 | task[task_index]->use_nic = value; |
---|
[165] | 856 | } |
---|
| 857 | else |
---|
| 858 | { |
---|
[189] | 859 | task[task_index]->use_nic = 0; |
---|
[158] | 860 | } |
---|
| 861 | |
---|
[189] | 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 | |
---|
[158] | 890 | task_index++; |
---|
| 891 | task_loc_index++; |
---|
| 892 | } // end taskNode() |
---|
| 893 | |
---|
[165] | 894 | ////////////////////////////////////////// |
---|
[160] | 895 | void vobjNode ( xmlTextReaderPtr reader ) |
---|
[189] | 896 | ////////////////////////////////////////// |
---|
[160] | 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 |
---|
[165] | 911 | printf(" vobj %d\n", vobj_loc_index); |
---|
[160] | 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 |
---|
[165] | 921 | printf(" name = %s\n", str); |
---|
[160] | 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 | |
---|
[165] | 932 | //////// get type attribute |
---|
[182] | 933 | str = getStringValue(reader, "type", &ok); |
---|
[160] | 934 | #if XML_PARSER_DEBUG |
---|
[182] | 935 | printf(" type = %s\n", str); |
---|
[160] | 936 | #endif |
---|
[182] | 937 | if (ok && (strcmp(str, "ELF") == 0)) |
---|
[165] | 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) |
---|
[160] | 943 | { |
---|
[165] | 944 | printf("[XML ERROR] an ELF vobj must be alone in a vseg (%d,%d)\n", |
---|
| 945 | vspace_index, vobj_loc_index); |
---|
[160] | 946 | exit(1); |
---|
| 947 | } |
---|
| 948 | } |
---|
[181] | 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; |
---|
[160] | 956 | else |
---|
| 957 | { |
---|
| 958 | printf("[XML ERROR] illegal or missing <type> attribute for vobj (%d,%d)\n", |
---|
[165] | 959 | vspace_index, vobj_loc_index); |
---|
[160] | 960 | exit(1); |
---|
| 961 | } |
---|
| 962 | |
---|
[165] | 963 | ////////// get length attribute |
---|
[160] | 964 | value = getIntValue(reader,"length", &ok); |
---|
| 965 | if ( ok ) |
---|
| 966 | { |
---|
| 967 | #if XML_PARSER_DEBUG |
---|
[165] | 968 | printf(" length = %d\n", value); |
---|
[160] | 969 | #endif |
---|
| 970 | vobj[vobj_index]->length = value; |
---|
| 971 | } |
---|
| 972 | else |
---|
| 973 | { |
---|
[165] | 974 | printf("[XML ERROR] illegal or missing <length> attribute for vobj (%d,%d)\n", |
---|
| 975 | vspace_index, vobj_loc_index); |
---|
| 976 | exit(1); |
---|
[160] | 977 | } |
---|
| 978 | |
---|
[165] | 979 | ////////// get align attribute (optional : 0 if missing) |
---|
[160] | 980 | value = getIntValue(reader,"align", &ok); |
---|
| 981 | if ( ok ) |
---|
| 982 | { |
---|
| 983 | #if XML_PARSER_DEBUG |
---|
[165] | 984 | printf(" align = %d\n", value); |
---|
[160] | 985 | #endif |
---|
| 986 | vobj[vobj_index]->align = value; |
---|
| 987 | } |
---|
| 988 | else |
---|
| 989 | { |
---|
| 990 | vobj[vobj_index]->align = 0; |
---|
| 991 | } |
---|
| 992 | |
---|
[165] | 993 | ////////// get binpath attribute (optional : '\0' if missing) |
---|
[160] | 994 | str = getStringValue(reader, "binpath", &ok); |
---|
| 995 | if ( ok ) |
---|
| 996 | { |
---|
| 997 | #if XML_PARSER_DEBUG |
---|
[165] | 998 | printf(" binpath = %s\n", str); |
---|
[160] | 999 | #endif |
---|
| 1000 | strncpy(vobj[vobj_index]->binpath, str, 63); |
---|
| 1001 | } |
---|
| 1002 | else |
---|
| 1003 | { |
---|
| 1004 | vobj[vobj_index]->binpath[0] = '\0'; |
---|
| 1005 | } |
---|
| 1006 | |
---|
[175] | 1007 | ////////// get init attribute (mandatory for mwmr and barrier) |
---|
[165] | 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 | { |
---|
[189] | 1018 | if( (vobj[vobj_index]->type == VOBJ_TYPE_MWMR) || |
---|
| 1019 | (vobj[vobj_index]->type == VOBJ_TYPE_BARRIER) ) |
---|
[175] | 1020 | { |
---|
[181] | 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); |
---|
[175] | 1024 | exit(1); |
---|
| 1025 | } |
---|
[181] | 1026 | vobj[vobj_index]->init = 0; |
---|
[165] | 1027 | } |
---|
| 1028 | |
---|
[160] | 1029 | vobj_index++; |
---|
[165] | 1030 | vobj_count++; |
---|
[160] | 1031 | vobj_loc_index++; |
---|
[165] | 1032 | } // end vobjNode() |
---|
[160] | 1033 | |
---|
[165] | 1034 | ////////////////////////////////////////// |
---|
[158] | 1035 | void vsegNode ( xmlTextReaderPtr reader ) |
---|
[189] | 1036 | ////////////////////////////////////////// |
---|
[158] | 1037 | { |
---|
| 1038 | unsigned int ok; |
---|
| 1039 | unsigned int value; |
---|
| 1040 | char* str; |
---|
| 1041 | |
---|
[165] | 1042 | vobj_count = 0; |
---|
| 1043 | |
---|
[158] | 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)); |
---|
[160] | 1057 | |
---|
| 1058 | ////////// set vobj_offset attributes |
---|
| 1059 | vseg[vseg_index]->vobj_offset = vobj_index; |
---|
| 1060 | #if XML_PARSER_DEBUG |
---|
[165] | 1061 | printf(" vobj_offset = %d\n", vobj_index); |
---|
[160] | 1062 | #endif |
---|
[158] | 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 vbase attribute |
---|
| 1081 | value = getIntValue(reader,"vbase", &ok); |
---|
| 1082 | if ( ok ) |
---|
| 1083 | { |
---|
| 1084 | #if XML_PARSER_DEBUG |
---|
| 1085 | printf(" vbase = 0x%x\n", value); |
---|
| 1086 | #endif |
---|
| 1087 | vseg[vseg_index]->vbase = value; |
---|
| 1088 | } |
---|
| 1089 | else |
---|
| 1090 | { |
---|
| 1091 | printf("[XML ERROR] illegal or missing <vbase> attribute for vseg (%d,%d)\n", |
---|
| 1092 | vspace_index, vseg_loc_index); |
---|
| 1093 | exit(1); |
---|
| 1094 | } |
---|
| 1095 | |
---|
[181] | 1096 | ////////// get clusterid and psegname attributes |
---|
| 1097 | value = getIntValue(reader,"clusterid", &ok); |
---|
| 1098 | if ( ok == 0 ) |
---|
| 1099 | { |
---|
| 1100 | printf("[XML ERROR] illegal or missing <clusterid> for vseg %d\n", |
---|
| 1101 | vseg_loc_index); |
---|
| 1102 | exit(1); |
---|
| 1103 | } |
---|
| 1104 | str = getStringValue(reader,"psegname", &ok); |
---|
| 1105 | if ( ok == 0 ) |
---|
| 1106 | { |
---|
| 1107 | printf("[XML ERROR] illegal or missing <psegname> for vseg %d\n", |
---|
| 1108 | vseg_loc_index); |
---|
| 1109 | exit(1); |
---|
| 1110 | } |
---|
| 1111 | |
---|
| 1112 | /////////// set psegid field |
---|
| 1113 | int index = getPsegId( value, str ); |
---|
| 1114 | if ( index >= 0 ) |
---|
| 1115 | { |
---|
| 1116 | #if XML_PARSER_DEBUG |
---|
| 1117 | printf(" clusterid = %d\n", value); |
---|
| 1118 | printf(" psegname = %s\n", str); |
---|
| 1119 | printf(" psegid = %d\n", index); |
---|
| 1120 | #endif |
---|
| 1121 | vseg[vseg_index]->psegid = index; |
---|
| 1122 | } |
---|
| 1123 | else |
---|
| 1124 | { |
---|
| 1125 | printf("[XML ERROR] pseg not found for vseg %d / clusterid = %d / psegname = %s\n", |
---|
| 1126 | vseg_loc_index, value, str ); |
---|
| 1127 | exit(1); |
---|
| 1128 | } |
---|
| 1129 | |
---|
[165] | 1130 | ////////// get ident attribute (optional : 0 if missing) |
---|
[158] | 1131 | value = getIntValue(reader,"ident", &ok); |
---|
| 1132 | if ( ok ) |
---|
| 1133 | { |
---|
| 1134 | #if XML_PARSER_DEBUG |
---|
| 1135 | printf(" ident = %d\n", value); |
---|
| 1136 | #endif |
---|
| 1137 | vseg[vseg_index]->ident = value; |
---|
| 1138 | } |
---|
| 1139 | else |
---|
| 1140 | { |
---|
| 1141 | vseg[vseg_index]->ident = 0; |
---|
| 1142 | } |
---|
| 1143 | |
---|
[165] | 1144 | //////// get mode attribute |
---|
[158] | 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 | |
---|
[181] | 1172 | ////////// get vobjs in vseg |
---|
| 1173 | int status = xmlTextReaderRead(reader); |
---|
[160] | 1174 | while ( status == 1 ) |
---|
| 1175 | { |
---|
| 1176 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
---|
| 1177 | |
---|
[189] | 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 ) |
---|
[160] | 1182 | { |
---|
[165] | 1183 | vseg[vseg_index]->vobjs = vobj_count; |
---|
[160] | 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 | } |
---|
[158] | 1195 | } // end vsegNode() |
---|
| 1196 | |
---|
| 1197 | ////////////////////////////////////////// |
---|
| 1198 | void vspaceNode( xmlTextReaderPtr reader ) |
---|
[189] | 1199 | ////////////////////////////////////////// |
---|
[158] | 1200 | { |
---|
| 1201 | char* str; |
---|
| 1202 | unsigned int ok; |
---|
[165] | 1203 | |
---|
| 1204 | vobj_loc_index = 0; |
---|
[160] | 1205 | vseg_loc_index = 0; |
---|
| 1206 | task_loc_index = 0; |
---|
[158] | 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 |
---|
[165] | 1219 | printf("\n vspace %d\n", vspace_index); |
---|
[158] | 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 |
---|
[165] | 1229 | printf(" name = %s\n", str); |
---|
[158] | 1230 | #endif |
---|
| 1231 | strncpy(vspace[vspace_index]->name, str, 31); |
---|
| 1232 | } |
---|
| 1233 | else |
---|
| 1234 | { |
---|
[165] | 1235 | printf("[XML ERROR] illegal or missing <name> attribute for vspace %d\n", |
---|
[158] | 1236 | vspace_index); |
---|
| 1237 | exit(1); |
---|
| 1238 | } |
---|
| 1239 | |
---|
[165] | 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 | |
---|
[158] | 1245 | #if XML_PARSER_DEBUG |
---|
[165] | 1246 | printf(" vseg_offset = %d\n", vseg_index); |
---|
| 1247 | printf(" vobj_offset = %d\n", vobj_index); |
---|
| 1248 | printf(" task_offset = %d\n", task_index); |
---|
[158] | 1249 | #endif |
---|
| 1250 | |
---|
[165] | 1251 | ////////// get startname attribute |
---|
| 1252 | str = getStringValue(reader, "startname", &ok); |
---|
[158] | 1253 | if ( ok ) |
---|
| 1254 | { |
---|
[165] | 1255 | //used after parsing the vobjs |
---|
[158] | 1256 | } |
---|
| 1257 | else |
---|
| 1258 | { |
---|
[165] | 1259 | printf("[XML ERROR] illegal or missing <startname> attribute for vspace %d\n", |
---|
| 1260 | vspace_index); |
---|
[158] | 1261 | exit(1); |
---|
| 1262 | } |
---|
| 1263 | |
---|
[181] | 1264 | int status = xmlTextReaderRead(reader); |
---|
[158] | 1265 | while ( status == 1 ) |
---|
| 1266 | { |
---|
| 1267 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
---|
| 1268 | |
---|
[189] | 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 ) |
---|
[158] | 1274 | { |
---|
[181] | 1275 | vspace[vspace_index]->vobjs = vobj_loc_index; |
---|
[160] | 1276 | vspace[vspace_index]->tasks = task_loc_index ; |
---|
| 1277 | vspace[vspace_index]->vsegs = vseg_loc_index ; |
---|
[165] | 1278 | |
---|
| 1279 | // get index of the vobj containing the start vector |
---|
[181] | 1280 | int index = getVobjLocId( vspace_index, str , vobj_loc_index ); |
---|
[160] | 1281 | if(index == -1) |
---|
[158] | 1282 | { |
---|
[165] | 1283 | printf("[XML ERROR] vobj containing the start vector not found %s\n",str); |
---|
[160] | 1284 | exit(-1); |
---|
[158] | 1285 | } |
---|
[165] | 1286 | else |
---|
| 1287 | { |
---|
| 1288 | vspace[vspace_index]->start_offset = index; |
---|
| 1289 | #if XML_PARSER_DEBUG |
---|
[181] | 1290 | printf(" startname = %s\n", str); |
---|
| 1291 | printf(" startid = %d\n", index); |
---|
| 1292 | printf(" end vspace %d\n\n", vspace_index); |
---|
[165] | 1293 | #endif |
---|
| 1294 | } |
---|
[160] | 1295 | |
---|
[165] | 1296 | // checking startid values for all tasks in vspace |
---|
| 1297 | int task_id; |
---|
| 1298 | int task_min = vspace[vspace_index]->task_offset; |
---|
| 1299 | int task_max = task_min + vspace[vspace_index]->tasks; |
---|
| 1300 | for ( task_id = task_min ; task_id < task_max ; task_id++ ) |
---|
| 1301 | { |
---|
| 1302 | if ( task[task_id]->startid >= vspace[vspace_index]->tasks ) |
---|
| 1303 | { |
---|
| 1304 | printf("[XML ERROR] <startid> too large for task (%d,%d)\n", |
---|
| 1305 | vspace_index, task_id ); |
---|
| 1306 | exit(1); |
---|
| 1307 | } |
---|
| 1308 | } |
---|
| 1309 | |
---|
[160] | 1310 | vspace_index++; |
---|
| 1311 | return; |
---|
[158] | 1312 | } |
---|
| 1313 | else |
---|
| 1314 | { |
---|
| 1315 | printf("[XML ERROR] Unknown tag %s",tag); |
---|
| 1316 | exit(1); |
---|
| 1317 | } |
---|
| 1318 | status = xmlTextReaderRead ( reader ); |
---|
| 1319 | } |
---|
| 1320 | } // end vspaceNode() |
---|
| 1321 | |
---|
| 1322 | ////////////////////////////////////////// |
---|
| 1323 | void psegNode ( xmlTextReaderPtr reader ) |
---|
[189] | 1324 | ////////////////////////////////////////// |
---|
[158] | 1325 | { |
---|
| 1326 | unsigned int ok; |
---|
| 1327 | unsigned int value; |
---|
| 1328 | char* str; |
---|
| 1329 | |
---|
| 1330 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
---|
| 1331 | |
---|
| 1332 | if ( pseg_index >= MAX_PSEGS ) |
---|
| 1333 | { |
---|
| 1334 | printf("[XML ERROR] The number of psegs is larger than %d\n", MAX_PSEGS); |
---|
| 1335 | exit(1); |
---|
| 1336 | } |
---|
| 1337 | |
---|
| 1338 | #if XML_PARSER_DEBUG |
---|
| 1339 | printf(" pseg %d\n", pseg_index); |
---|
| 1340 | #endif |
---|
| 1341 | |
---|
| 1342 | pseg[pseg_index] = (mapping_pseg_t*)malloc(sizeof(mapping_pseg_t)); |
---|
| 1343 | |
---|
[181] | 1344 | /////// get name attribute |
---|
[158] | 1345 | str = getStringValue( reader, "name", &ok ); |
---|
| 1346 | #if XML_PARSER_DEBUG |
---|
[181] | 1347 | printf(" name = %s\n", str); |
---|
[158] | 1348 | #endif |
---|
| 1349 | if ( ok ) |
---|
| 1350 | { |
---|
| 1351 | strncpy(pseg[pseg_index]->name, str, 31); |
---|
| 1352 | } |
---|
| 1353 | else |
---|
| 1354 | { |
---|
[181] | 1355 | printf("[XML ERROR] illegal or missing <name> for pseg %d in cluster %d\n", |
---|
| 1356 | pseg_index, cluster_index); |
---|
[158] | 1357 | exit(1); |
---|
| 1358 | } |
---|
| 1359 | |
---|
[181] | 1360 | //////// get type attribute |
---|
| 1361 | str = getStringValue(reader, "type", &ok); |
---|
| 1362 | #if XML_PARSER_DEBUG |
---|
| 1363 | printf(" type = %s\n", str); |
---|
| 1364 | #endif |
---|
| 1365 | if (ok && (strcmp(str, "RAM" ) == 0)) pseg[pseg_index]->type = PSEG_TYPE_RAM; |
---|
| 1366 | else if (ok && (strcmp(str, "ROM" ) == 0)) pseg[pseg_index]->type = PSEG_TYPE_ROM; |
---|
| 1367 | else if (ok && (strcmp(str, "PERI") == 0)) pseg[pseg_index]->type = PSEG_TYPE_PERI; |
---|
| 1368 | else |
---|
| 1369 | { |
---|
| 1370 | printf("[XML ERROR] illegal or missing <type> for pseg %s in cluster %d\n", |
---|
| 1371 | pseg[pseg_index]->name, cluster_index); |
---|
| 1372 | exit(1); |
---|
| 1373 | } |
---|
| 1374 | |
---|
| 1375 | //////// get base attribute |
---|
[158] | 1376 | value = getIntValue( reader, "base", &ok ); |
---|
| 1377 | #if XML_PARSER_DEBUG |
---|
[181] | 1378 | printf(" base = 0x%x\n", value); |
---|
[158] | 1379 | #endif |
---|
| 1380 | if ( ok ) |
---|
| 1381 | { |
---|
| 1382 | pseg[pseg_index]->base = value; |
---|
| 1383 | } |
---|
| 1384 | else |
---|
| 1385 | { |
---|
[181] | 1386 | printf("[XML ERROR] illegal or missing <base> for pseg %s in cluster %d\n", |
---|
| 1387 | pseg[pseg_index]->name, cluster_index); |
---|
[158] | 1388 | exit(1); |
---|
| 1389 | } |
---|
| 1390 | |
---|
[181] | 1391 | //////// get length attribute |
---|
[158] | 1392 | value = getIntValue( reader, "length", &ok ); |
---|
| 1393 | #if XML_PARSER_DEBUG |
---|
[181] | 1394 | printf(" length = 0x%x\n", value); |
---|
[158] | 1395 | #endif |
---|
| 1396 | if ( ok ) |
---|
| 1397 | { |
---|
| 1398 | pseg[pseg_index]->length = value; |
---|
| 1399 | } |
---|
| 1400 | else |
---|
| 1401 | { |
---|
[181] | 1402 | printf("[XML ERROR] illegal or missing <length> for pseg %s in cluster %d\n", |
---|
| 1403 | pseg[pseg_index]->name, cluster_index); |
---|
[158] | 1404 | exit(1); |
---|
| 1405 | } |
---|
| 1406 | |
---|
[181] | 1407 | //////// set cluster attribute |
---|
| 1408 | pseg[pseg_index]->cluster = cluster_index; |
---|
| 1409 | |
---|
[158] | 1410 | pseg_index++; |
---|
[181] | 1411 | cluster[cluster_index]->psegs++; |
---|
[158] | 1412 | } // end psegNode() |
---|
| 1413 | |
---|
| 1414 | ///////////////////////////////////////////// |
---|
| 1415 | void clusterNode ( xmlTextReaderPtr reader ) |
---|
[189] | 1416 | ///////////////////////////////////////////// |
---|
[158] | 1417 | { |
---|
| 1418 | unsigned int ok; |
---|
| 1419 | unsigned int value; |
---|
| 1420 | |
---|
[181] | 1421 | proc_loc_index = 0; |
---|
| 1422 | coproc_loc_index = 0; |
---|
[189] | 1423 | periph_loc_index = 0; |
---|
[181] | 1424 | |
---|
[158] | 1425 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
---|
| 1426 | |
---|
| 1427 | // checking source file consistency |
---|
| 1428 | if ( cluster_index >= header->clusters ) |
---|
| 1429 | { |
---|
| 1430 | printf("[XML ERROR] The cluster index is too large : %d\n", cluster_index); |
---|
| 1431 | exit(1); |
---|
| 1432 | } |
---|
| 1433 | |
---|
| 1434 | #if XML_PARSER_DEBUG |
---|
[181] | 1435 | printf(" cluster %d\n", cluster_index); |
---|
[158] | 1436 | #endif |
---|
| 1437 | |
---|
| 1438 | cluster[cluster_index] = (mapping_cluster_t*)malloc(sizeof(mapping_cluster_t)); |
---|
| 1439 | |
---|
[189] | 1440 | /////////// check cluster index attribute (optional) |
---|
[165] | 1441 | value = getIntValue(reader,"index",&ok); |
---|
| 1442 | if ( ok && (value != cluster_index) ) |
---|
[158] | 1443 | { |
---|
[165] | 1444 | printf("[XML ERROR] wrong cluster index / expected value is %d", |
---|
[158] | 1445 | cluster_index); |
---|
[165] | 1446 | exit(1); |
---|
[158] | 1447 | } |
---|
| 1448 | |
---|
[189] | 1449 | ////////// set offsets |
---|
| 1450 | cluster[cluster_index]->pseg_offset = pseg_index; |
---|
| 1451 | cluster[cluster_index]->proc_offset = proc_index; |
---|
| 1452 | cluster[cluster_index]->coproc_offset = coproc_index; |
---|
| 1453 | cluster[cluster_index]->periph_offset = periph_index; |
---|
[181] | 1454 | |
---|
[158] | 1455 | #if XML_PARSER_DEBUG |
---|
[189] | 1456 | printf(" pseg_offset = %d\n", pseg_index); |
---|
| 1457 | printf(" proc_offset = %d\n", proc_index); |
---|
[181] | 1458 | printf(" coproc_offset = %d\n", coproc_index); |
---|
[189] | 1459 | printf(" periph_offset = %d\n", coproc_index); |
---|
[158] | 1460 | #endif |
---|
[181] | 1461 | |
---|
[189] | 1462 | ////////// get psegs, procs, coprocs and periphs |
---|
[181] | 1463 | int status = xmlTextReaderRead(reader); |
---|
| 1464 | |
---|
| 1465 | while ( status == 1 ) |
---|
[158] | 1466 | { |
---|
[181] | 1467 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
---|
| 1468 | |
---|
[189] | 1469 | if ( strcmp(tag, "pseg") == 0 ) psegNode(reader); |
---|
| 1470 | else if ( strcmp(tag, "proc") == 0 ) procNode(reader); |
---|
| 1471 | else if ( strcmp(tag, "coproc") == 0 ) coprocNode(reader); |
---|
| 1472 | else if ( strcmp(tag, "periph") == 0 ) periphNode(reader); |
---|
| 1473 | else if ( strcmp(tag, "#text") == 0 ) { } |
---|
| 1474 | else if ( strcmp(tag, "#comment") == 0 ) { } |
---|
| 1475 | else if ( strcmp(tag, "cluster") == 0 ) |
---|
[181] | 1476 | { |
---|
[189] | 1477 | cluster[cluster_index]->procs = proc_loc_index; |
---|
| 1478 | cluster[cluster_index]->coprocs = coproc_loc_index; |
---|
| 1479 | cluster[cluster_index]->periphs = periph_loc_index; |
---|
| 1480 | |
---|
| 1481 | // cluster[cluster_index]psegs update is done in psegNode(), |
---|
| 1482 | // because the coprocNode() call to getPsegId() need it |
---|
| 1483 | |
---|
[181] | 1484 | #if XML_PARSER_DEBUG |
---|
[189] | 1485 | printf(" psegs = %d\n", cluster[cluster_index]->psegs); |
---|
| 1486 | printf(" procs = %d\n", cluster[cluster_index]->procs); |
---|
| 1487 | printf(" coprocs = %d\n", cluster[cluster_index]->coprocs); |
---|
| 1488 | printf(" periphs = %d\n", cluster[cluster_index]->periphs); |
---|
[181] | 1489 | printf(" end cluster %d\n", cluster_index); |
---|
| 1490 | #endif |
---|
| 1491 | cluster_index++; |
---|
| 1492 | return; |
---|
| 1493 | } |
---|
| 1494 | status = xmlTextReaderRead(reader); |
---|
[158] | 1495 | } |
---|
| 1496 | } // end clusterNode() |
---|
| 1497 | |
---|
| 1498 | ////////////////////////////////////////////// |
---|
| 1499 | void clusterSetNode( xmlTextReaderPtr reader ) |
---|
[189] | 1500 | ////////////////////////////////////////////// |
---|
[158] | 1501 | { |
---|
| 1502 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
---|
| 1503 | |
---|
| 1504 | #if XML_PARSER_DEBUG |
---|
[165] | 1505 | printf("\n clusters set\n"); |
---|
[158] | 1506 | #endif |
---|
| 1507 | |
---|
[181] | 1508 | int status = xmlTextReaderRead(reader); |
---|
[158] | 1509 | while ( status == 1 ) |
---|
| 1510 | { |
---|
| 1511 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
---|
| 1512 | |
---|
[189] | 1513 | if ( strcmp(tag, "cluster") == 0 ) clusterNode(reader); |
---|
| 1514 | else if ( strcmp(tag, "#text") == 0 ) { } |
---|
| 1515 | else if ( strcmp(tag, "#comment") == 0 ) { } |
---|
| 1516 | else if ( strcmp(tag, "clusterset") == 0 ) |
---|
[158] | 1517 | { |
---|
| 1518 | // checking source file consistency |
---|
| 1519 | if ( cluster_index != header->clusters ) |
---|
| 1520 | { |
---|
| 1521 | printf("[XML ERROR] Wrong number of clusters\n"); |
---|
| 1522 | exit(1); |
---|
| 1523 | } |
---|
| 1524 | else |
---|
| 1525 | { |
---|
[181] | 1526 | #if XML_PARSER_DEBUG |
---|
| 1527 | printf(" end cluster set\n\n"); |
---|
| 1528 | #endif |
---|
[189] | 1529 | header->psegs = pseg_index; |
---|
| 1530 | header->procs = proc_index; |
---|
| 1531 | header->irqs = irq_index; |
---|
| 1532 | header->coprocs = coproc_index; |
---|
[181] | 1533 | header->cp_ports = cp_port_index; |
---|
[158] | 1534 | return; |
---|
| 1535 | } |
---|
| 1536 | } |
---|
| 1537 | else |
---|
| 1538 | { |
---|
| 1539 | printf("[XML ERROR] Unknown tag in clusterset node : %s",tag); |
---|
| 1540 | exit(1); |
---|
| 1541 | } |
---|
[181] | 1542 | status = xmlTextReaderRead(reader); |
---|
[158] | 1543 | } |
---|
| 1544 | } // end clusterSetNode() |
---|
| 1545 | |
---|
| 1546 | ///////////////////////////////////////////// |
---|
| 1547 | void globalSetNode( xmlTextReaderPtr reader ) |
---|
[189] | 1548 | ///////////////////////////////////////////// |
---|
[158] | 1549 | { |
---|
| 1550 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
---|
| 1551 | |
---|
| 1552 | #if XML_PARSER_DEBUG |
---|
[165] | 1553 | printf(" globals set\n"); |
---|
[158] | 1554 | #endif |
---|
| 1555 | |
---|
[181] | 1556 | int status = xmlTextReaderRead(reader); |
---|
[158] | 1557 | while ( status == 1 ) |
---|
| 1558 | { |
---|
| 1559 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
---|
| 1560 | |
---|
[189] | 1561 | if ( strcmp(tag, "vseg") == 0 ) vsegNode(reader); |
---|
| 1562 | else if ( strcmp(tag, "#text" ) == 0 ) { } |
---|
| 1563 | else if ( strcmp(tag, "#comment") == 0 ) { } |
---|
| 1564 | else if ( strcmp(tag, "globalset") == 0 ) |
---|
[158] | 1565 | { |
---|
| 1566 | // checking source file consistency |
---|
| 1567 | if ( vseg_index != header->globals ) |
---|
| 1568 | { |
---|
| 1569 | printf("[XML ERROR] Wrong number of global vsegs\n"); |
---|
| 1570 | exit(1); |
---|
| 1571 | } |
---|
| 1572 | else |
---|
| 1573 | { |
---|
[181] | 1574 | #if XML_PARSER_DEBUG |
---|
| 1575 | printf(" end global set\n\n"); |
---|
| 1576 | #endif |
---|
[158] | 1577 | vseg_loc_index = 0; |
---|
| 1578 | return; |
---|
| 1579 | } |
---|
| 1580 | } |
---|
| 1581 | else |
---|
| 1582 | { |
---|
| 1583 | printf("[XML ERROR] Unknown tag in globalset node : %s",tag); |
---|
| 1584 | exit(1); |
---|
| 1585 | } |
---|
| 1586 | status = xmlTextReaderRead ( reader ); |
---|
| 1587 | } |
---|
| 1588 | } // end globalSetNode() |
---|
| 1589 | |
---|
| 1590 | ///////////////////////////////////////////// |
---|
| 1591 | void vspaceSetNode( xmlTextReaderPtr reader ) |
---|
[189] | 1592 | ///////////////////////////////////////////// |
---|
[158] | 1593 | { |
---|
| 1594 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
---|
| 1595 | |
---|
| 1596 | #if XML_PARSER_DEBUG |
---|
[165] | 1597 | printf("\n vspaces set\n"); |
---|
[158] | 1598 | #endif |
---|
| 1599 | |
---|
| 1600 | int status = xmlTextReaderRead ( reader ); |
---|
| 1601 | while ( status == 1 ) |
---|
| 1602 | { |
---|
| 1603 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
---|
| 1604 | |
---|
[189] | 1605 | if ( strcmp(tag, "vspace" ) == 0 ) vspaceNode(reader); |
---|
| 1606 | else if ( strcmp(tag, "#text" ) == 0 ) { } |
---|
| 1607 | else if ( strcmp(tag, "#comment" ) == 0 ) { } |
---|
| 1608 | else if ( strcmp(tag, "vspaceset") == 0 ) |
---|
[158] | 1609 | { |
---|
| 1610 | // checking source file consistency |
---|
| 1611 | if ( vspace_index != header->vspaces ) |
---|
| 1612 | { |
---|
| 1613 | printf("[XML ERROR] Wrong number of vspaces\n"); |
---|
| 1614 | exit(1); |
---|
| 1615 | } |
---|
| 1616 | else |
---|
| 1617 | { |
---|
| 1618 | header->vsegs = vseg_index; |
---|
[160] | 1619 | header->vobjs = vobj_index; |
---|
[158] | 1620 | header->tasks = task_index; |
---|
| 1621 | return; |
---|
| 1622 | } |
---|
| 1623 | } |
---|
| 1624 | else |
---|
| 1625 | { |
---|
| 1626 | printf("[XML ERROR] Unknown tag in vspaceset node : %s",tag); |
---|
| 1627 | exit(1); |
---|
| 1628 | } |
---|
| 1629 | status = xmlTextReaderRead ( reader ); |
---|
| 1630 | } |
---|
| 1631 | } // end globalSetNode() |
---|
| 1632 | |
---|
| 1633 | ////////////////////////////////////////// |
---|
| 1634 | void headerNode(xmlTextReaderPtr reader ) |
---|
[189] | 1635 | ////////////////////////////////////////// |
---|
[158] | 1636 | { |
---|
| 1637 | char* name; |
---|
| 1638 | unsigned int value; |
---|
| 1639 | unsigned int ok; |
---|
| 1640 | |
---|
| 1641 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
---|
| 1642 | |
---|
| 1643 | #if XML_PARSER_DEBUG |
---|
| 1644 | printf("mapping_info\n"); |
---|
| 1645 | #endif |
---|
| 1646 | |
---|
| 1647 | header = (mapping_header_t*)malloc(sizeof(mapping_header_t)); |
---|
| 1648 | |
---|
[165] | 1649 | ////////// get name attribute |
---|
[158] | 1650 | name = getStringValue(reader, "name", &ok); |
---|
| 1651 | if ( ok ) |
---|
| 1652 | { |
---|
| 1653 | #if XML_PARSER_DEBUG |
---|
[165] | 1654 | printf(" name = %s\n", name); |
---|
[158] | 1655 | #endif |
---|
| 1656 | strncpy( header->name, name, 31); |
---|
| 1657 | } |
---|
| 1658 | else |
---|
| 1659 | { |
---|
| 1660 | printf("[XML ERROR] illegal or missing <name> attribute in header\n"); |
---|
| 1661 | exit(1); |
---|
| 1662 | } |
---|
| 1663 | |
---|
[165] | 1664 | /////////// get clusters attribute |
---|
[158] | 1665 | value = getIntValue(reader, "clusters", &ok); |
---|
| 1666 | if ( ok ) |
---|
| 1667 | { |
---|
| 1668 | if ( value >= MAX_CLUSTERS ) |
---|
| 1669 | { |
---|
| 1670 | printf("[XML ERROR] The number of clusters is larger than %d\n", MAX_CLUSTERS); |
---|
| 1671 | exit(1); |
---|
| 1672 | } |
---|
| 1673 | #if XML_PARSER_DEBUG |
---|
[165] | 1674 | printf(" clusters = %d\n", value); |
---|
[158] | 1675 | #endif |
---|
| 1676 | header->clusters = value; |
---|
| 1677 | } |
---|
| 1678 | else |
---|
| 1679 | { |
---|
| 1680 | printf("[XML ERROR] illegal or missing <clusters> attribute in header\n"); |
---|
| 1681 | exit(1); |
---|
| 1682 | } |
---|
| 1683 | |
---|
[165] | 1684 | ///////// get vspaces attribute |
---|
[158] | 1685 | value = getIntValue(reader, "vspaces", &ok); |
---|
| 1686 | if ( ok ) |
---|
| 1687 | { |
---|
| 1688 | if ( value >= MAX_VSPACES ) |
---|
| 1689 | { |
---|
| 1690 | printf("[XML ERROR] The number of vspaces is larger than %d\n", MAX_VSPACES); |
---|
| 1691 | exit(1); |
---|
| 1692 | } |
---|
| 1693 | #if XML_PARSER_DEBUG |
---|
[165] | 1694 | printf(" vspaces = %d\n", value); |
---|
[158] | 1695 | #endif |
---|
| 1696 | header->vspaces = value; |
---|
| 1697 | } |
---|
| 1698 | else |
---|
| 1699 | { |
---|
| 1700 | printf("[XML ERROR] illegal or missing <vspaces> attribute in mapping\n"); |
---|
| 1701 | exit(1); |
---|
| 1702 | } |
---|
| 1703 | |
---|
[165] | 1704 | ////////// get globals attribute |
---|
[158] | 1705 | value = getIntValue(reader, "globals", &ok); |
---|
| 1706 | if ( ok ) |
---|
| 1707 | { |
---|
| 1708 | if ( value >= MAX_VSEGS ) |
---|
| 1709 | { |
---|
| 1710 | printf("[XML ERROR] The number of globals is larger than %d\n", MAX_VSEGS); |
---|
| 1711 | exit(1); |
---|
| 1712 | } |
---|
| 1713 | #if XML_PARSER_DEBUG |
---|
[165] | 1714 | printf(" globals = %d\n", value); |
---|
[158] | 1715 | #endif |
---|
| 1716 | header->globals = value; |
---|
| 1717 | } |
---|
| 1718 | else |
---|
| 1719 | { |
---|
| 1720 | printf("[XML ERROR] illegal or missing <globals> attribute in mapping_info_header\n"); |
---|
| 1721 | exit(1); |
---|
| 1722 | } |
---|
| 1723 | |
---|
[189] | 1724 | //////// initialise non replicated peripherals cluster_id |
---|
| 1725 | header->tty_clusterid = 0xFFFFFFFF; |
---|
| 1726 | header->nic_clusterid = 0xFFFFFFFF; |
---|
| 1727 | header->ioc_clusterid = 0xFFFFFFFF; |
---|
| 1728 | header->fbf_clusterid = 0xFFFFFFFF; |
---|
| 1729 | |
---|
| 1730 | ///////// set signature |
---|
[158] | 1731 | header->signature = IN_MAPPING_SIGNATURE; |
---|
| 1732 | |
---|
[181] | 1733 | int status = xmlTextReaderRead(reader); |
---|
[158] | 1734 | while ( status == 1 ) |
---|
| 1735 | { |
---|
| 1736 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
---|
| 1737 | |
---|
[189] | 1738 | if ( strcmp(tag, "clusterset") == 0 ) clusterSetNode(reader); |
---|
| 1739 | else if ( strcmp(tag, "globalset") == 0 ) globalSetNode(reader); |
---|
| 1740 | else if ( strcmp(tag, "vspaceset") == 0 ) vspaceSetNode(reader); |
---|
| 1741 | else if ( strcmp(tag, "#text") == 0 ) { } |
---|
| 1742 | else if ( strcmp(tag, "#comment") == 0 ) { } |
---|
| 1743 | else if ( strcmp(tag, "mapping_info") == 0 ) |
---|
[158] | 1744 | { |
---|
| 1745 | #if XML_PARSER_DEBUG |
---|
| 1746 | printf("end mapping_info\n"); |
---|
| 1747 | #endif |
---|
| 1748 | return; |
---|
| 1749 | } |
---|
| 1750 | else |
---|
| 1751 | { |
---|
[174] | 1752 | printf("[XML ERROR] Unknown tag in header node : %s\n",tag); |
---|
[158] | 1753 | exit(1); |
---|
| 1754 | } |
---|
[181] | 1755 | status = xmlTextReaderRead(reader); |
---|
[158] | 1756 | } |
---|
| 1757 | } // end headerNode() |
---|
[181] | 1758 | |
---|
[189] | 1759 | /////////////////////////////////////// |
---|
[181] | 1760 | void BuildTable( int fdout, |
---|
| 1761 | const char* type, |
---|
| 1762 | unsigned int nb_elem, |
---|
| 1763 | unsigned int elem_size, |
---|
| 1764 | char** table) |
---|
[189] | 1765 | //////////////////////////////////////// |
---|
[181] | 1766 | { |
---|
| 1767 | unsigned int i; |
---|
| 1768 | unsigned int length; |
---|
| 1769 | // write element |
---|
| 1770 | for ( i = 0 ; i < nb_elem ; i++ ) |
---|
| 1771 | { |
---|
| 1772 | length = write(fdout, table[i], elem_size); |
---|
| 1773 | |
---|
| 1774 | #if XML_PARSER_DEBUG |
---|
| 1775 | printf("Building binary: writing %s %d\n", type, i); |
---|
| 1776 | #endif |
---|
[158] | 1777 | |
---|
[181] | 1778 | if ( length != elem_size ) |
---|
| 1779 | { |
---|
| 1780 | printf("type: %s\n", type); |
---|
| 1781 | perror("error writing"); |
---|
| 1782 | exit(1); |
---|
| 1783 | } |
---|
| 1784 | } |
---|
| 1785 | } |
---|
| 1786 | |
---|
[158] | 1787 | /////////////////////////// |
---|
| 1788 | void buildBin( int fdout ) |
---|
[189] | 1789 | /////////////////////////// |
---|
[158] | 1790 | { |
---|
| 1791 | unsigned int vspace_id; |
---|
[160] | 1792 | unsigned int vobj_id; |
---|
[158] | 1793 | unsigned int length; |
---|
| 1794 | |
---|
| 1795 | // write header to binary file |
---|
| 1796 | length = write(fdout, (char*)header, sizeof(mapping_header_t)); |
---|
| 1797 | |
---|
| 1798 | #if XML_PARSER_DEBUG |
---|
| 1799 | printf("\n*** write header\n"); |
---|
| 1800 | #endif |
---|
| 1801 | |
---|
| 1802 | if ( length != sizeof(mapping_header_t) ) |
---|
| 1803 | { |
---|
[181] | 1804 | printf("write header error : length = %d \n", length); |
---|
[158] | 1805 | exit(1); |
---|
| 1806 | } |
---|
| 1807 | |
---|
| 1808 | // write clusters |
---|
[181] | 1809 | BuildTable(fdout, "cluster", cluster_index, sizeof(mapping_cluster_t), (char**) cluster); |
---|
[158] | 1810 | |
---|
| 1811 | // write psegs |
---|
[181] | 1812 | BuildTable(fdout, "pseg", pseg_index, sizeof(mapping_pseg_t), (char**) pseg); |
---|
[158] | 1813 | |
---|
| 1814 | // write vspaces |
---|
| 1815 | for ( vspace_id = 0 ; vspace_id < header->vspaces ; vspace_id++ ) |
---|
| 1816 | { |
---|
| 1817 | length = write(fdout, (char*)vspace[vspace_id], sizeof(mapping_vspace_t)); |
---|
| 1818 | |
---|
| 1819 | #if XML_PARSER_DEBUG |
---|
| 1820 | printf("write vspace %d\n", vspace_id); |
---|
[160] | 1821 | printf("vspace->vobj_offset: %d\n", vspace[vspace_id]->vobj_offset); |
---|
| 1822 | printf("vspace->vobjs: %d\n", vspace[vspace_id]->vobjs); |
---|
| 1823 | printf("header->vobjs: %d\n", header->vobjs); |
---|
[158] | 1824 | #endif |
---|
| 1825 | |
---|
| 1826 | if ( length != sizeof(mapping_vspace_t) ) |
---|
| 1827 | { |
---|
| 1828 | perror("write vspace"); |
---|
| 1829 | exit(1); |
---|
| 1830 | } |
---|
| 1831 | } |
---|
| 1832 | |
---|
| 1833 | // write vsegs |
---|
[181] | 1834 | BuildTable(fdout, "vseg", vseg_index, sizeof(mapping_vseg_t), (char**) vseg); |
---|
[158] | 1835 | |
---|
[160] | 1836 | // write vobjs |
---|
| 1837 | for ( vobj_id = 0 ; vobj_id < header->vobjs ; vobj_id++ ) |
---|
| 1838 | { |
---|
| 1839 | length = write(fdout, (char*)vobj[vobj_id], sizeof(mapping_vobj_t)); |
---|
| 1840 | |
---|
| 1841 | #if XML_PARSER_DEBUG |
---|
| 1842 | printf("write vobj %d\n", vobj_id); |
---|
| 1843 | printf("write vobj name %s\n", vobj[vobj_id]->name); |
---|
| 1844 | printf("write vobj length %x\n", vobj[vobj_id]->length); |
---|
| 1845 | printf("write vobj type %d\n", vobj[vobj_id]->type); |
---|
| 1846 | #endif |
---|
[158] | 1847 | |
---|
[160] | 1848 | if ( length != sizeof(mapping_vobj_t) ) |
---|
| 1849 | { |
---|
| 1850 | perror("write vobj"); |
---|
| 1851 | exit(1); |
---|
| 1852 | } |
---|
| 1853 | } |
---|
| 1854 | |
---|
[189] | 1855 | // write tasks array |
---|
[181] | 1856 | BuildTable(fdout, "task", task_index, sizeof(mapping_task_t), (char**) task); |
---|
[189] | 1857 | //building procs array |
---|
[181] | 1858 | BuildTable(fdout, "proc", proc_index, sizeof(mapping_proc_t), (char**) proc); |
---|
[189] | 1859 | //building irqs array |
---|
[181] | 1860 | BuildTable(fdout, "irq", irq_index, sizeof(mapping_irq_t), (char**)irq); |
---|
[189] | 1861 | //building coprocs array |
---|
[181] | 1862 | BuildTable(fdout, "coproc", coproc_index, sizeof(mapping_coproc_t), (char**)coproc); |
---|
[189] | 1863 | //building cp_ports array |
---|
| 1864 | BuildTable(fdout, "cp_port", cp_port_index, sizeof(mapping_cp_port_t),(char**) cp_port); |
---|
| 1865 | //building periphs array |
---|
| 1866 | BuildTable(fdout, "periph", periph_index, sizeof(mapping_periph_t), (char**)periph); |
---|
[181] | 1867 | |
---|
| 1868 | } // end buildBin() |
---|
| 1869 | |
---|
[189] | 1870 | /////////////////////////////////////////////////////////////////////// |
---|
| 1871 | // this function set the value the vobj_id fiels of all cp_ports |
---|
| 1872 | /////////////////////////////////////////////////////////////////////// |
---|
[181] | 1873 | void prepareBuild() |
---|
| 1874 | { |
---|
| 1875 | unsigned int i; |
---|
| 1876 | for(i=0; i< cp_port_index; i++) |
---|
[158] | 1877 | { |
---|
[181] | 1878 | int vspace_id = getVspaceId( cp_port_vobj_ref[i]->vspace_name ); |
---|
| 1879 | if ( vspace_id < 0 ) |
---|
| 1880 | { |
---|
[189] | 1881 | printf("[XML ERROR] illegal <vspacename> for cp_port %d,\n", |
---|
[181] | 1882 | i); |
---|
| 1883 | exit(1); |
---|
| 1884 | } |
---|
| 1885 | cp_port[i]->vspaceid = vspace_id; |
---|
| 1886 | |
---|
[189] | 1887 | int vobj_id = getVobjLocId( vspace_id, |
---|
| 1888 | cp_port_vobj_ref[i]->vobj_name, |
---|
| 1889 | vspace[vspace_id]->vobjs ); |
---|
[181] | 1890 | if ( vobj_id >= 0 ) |
---|
| 1891 | { |
---|
[189] | 1892 | |
---|
[158] | 1893 | #if XML_PARSER_DEBUG |
---|
[189] | 1894 | printf("\ncp_port = %d\n", i); |
---|
[181] | 1895 | printf(" vspace_name = %s\n", cp_port_vobj_ref[i]->vspace_name); |
---|
| 1896 | printf(" vobj_name = %s\n", cp_port_vobj_ref[i]->vobj_name); |
---|
| 1897 | printf(" vobj_index = %d\n", vobj_id); |
---|
[158] | 1898 | #endif |
---|
[181] | 1899 | cp_port[i]->vobjlocid = vobj_id; |
---|
[189] | 1900 | |
---|
| 1901 | assert((vobj[ vspace[vspace_id]->vobj_offset + vobj_id]->type == VOBJ_TYPE_MWMR) |
---|
| 1902 | && "coproc ports has to refere to a vobj of type MWMR"); |
---|
[181] | 1903 | } |
---|
| 1904 | else |
---|
[158] | 1905 | { |
---|
[189] | 1906 | printf("[XML ERROR] illegal <vobjname> for cp_port %d,\n", |
---|
[181] | 1907 | i); |
---|
[158] | 1908 | exit(1); |
---|
| 1909 | } |
---|
| 1910 | } |
---|
[181] | 1911 | } |
---|
[158] | 1912 | |
---|
| 1913 | ///////////////////////////////////// |
---|
| 1914 | int main ( int argc, char* argv[] ) |
---|
[189] | 1915 | ///////////////////////////////////// |
---|
[158] | 1916 | { |
---|
| 1917 | if ( argc < 3 ) |
---|
| 1918 | { |
---|
| 1919 | printf("Usage: xml2bin <input_file_path> <output_file_path>\n"); |
---|
| 1920 | return 1; |
---|
| 1921 | } |
---|
| 1922 | |
---|
| 1923 | int fdout = open( argv[2], (O_CREAT | O_RDWR), S_IRWXU ); |
---|
| 1924 | if ( fdout < 0) |
---|
| 1925 | { |
---|
| 1926 | perror("open"); |
---|
| 1927 | exit(1); |
---|
| 1928 | } |
---|
| 1929 | |
---|
| 1930 | LIBXML_TEST_VERSION; |
---|
| 1931 | |
---|
[181] | 1932 | int status; |
---|
[158] | 1933 | xmlTextReaderPtr reader = xmlReaderForFile ( argv[1], NULL, 0 ); |
---|
| 1934 | |
---|
| 1935 | if ( reader != NULL ) |
---|
| 1936 | { |
---|
| 1937 | status = xmlTextReaderRead ( reader ); |
---|
| 1938 | while ( status == 1 ) |
---|
| 1939 | { |
---|
| 1940 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
---|
[181] | 1941 | |
---|
[158] | 1942 | if ( strcmp(tag,"mapping_info") == 0 ) |
---|
| 1943 | { |
---|
| 1944 | headerNode( reader ); |
---|
[181] | 1945 | prepareBuild(); |
---|
[158] | 1946 | buildBin( fdout ); |
---|
| 1947 | } |
---|
| 1948 | else |
---|
| 1949 | { |
---|
| 1950 | printf("[XML ERROR] Wrong file type: \"%s\"\n", argv[1]); |
---|
| 1951 | return 1; |
---|
| 1952 | } |
---|
| 1953 | status = xmlTextReaderRead ( reader ); |
---|
| 1954 | } |
---|
| 1955 | xmlFreeTextReader ( reader ); |
---|
| 1956 | |
---|
| 1957 | if ( status != 0 ) |
---|
| 1958 | { |
---|
| 1959 | printf("[XML ERROR] Wrong Syntax in \"%s\" file\n", argv[1]); |
---|
| 1960 | return 1; |
---|
| 1961 | } |
---|
| 1962 | } |
---|
| 1963 | return 0; |
---|
| 1964 | } // end main() |
---|