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