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