void fwrite_lcmds_section(struct ptf_item *pi, void *arg) { lcmd_desc *li = (lcmd_desc *)arg; struct ptf *p; struct ptf_item lpi; char *location = NULL; char *section_name = pi->item[1]->value; if(section_name == 0) { fprintf(stderr, "Found a LINKER/SECTION without name, ignoring it.\n"); return; }; p = ptf_find(pi->item[1]->sub, &lpi, item, "LOCATION", 0); if(p) { location = p->value; } else { if(strcmp(section_name, "entry") == 0) { p = ptf_find(li->cpu, &lpi, item, "reset_slave", 0); } else if(strcmp(section_name, "exceptions") == 0) { p = ptf_find(li->cpu, &lpi, item, "exc_slave", 0); }; if(p) location = p->value; /* TODO: This doesn't work yet, parse full slave address, translate into our naming */ } if(location == 0) { fprintf(stderr, "No LOCATION configured for section '%s'!\n", pi->item[1]->value); return; }; fprintf(li->file, " .%s :\n {\n", pi->item[1]->value); fprintf(li->file, pi->item[2]->value); fprintf(li->file, " } > %s\n\n", location); }
void fwrite_header_file( FILE *file, struct ptf *cfg, device_desc *devices, clock_desc *clocks) { struct ptf *p; struct ptf_item pi; struct ptf aclass = { section, "CLASS", 0, 0, 0 }; struct ptf_item matchaclass = { 1, &aclass }; struct ptf bspsect = { section, "BSPHEADER", 0, 0, 0 }; struct ptf leadtext = { item, "LEADTEXT", 0, 0, 0 }; struct ptf_item matchleadtext = { 2, &bspsect, &leadtext }; struct ptf epilog = { item, "EPILOG", 0, 0, 0 }; struct ptf_item matchepilog = { 2, &bspsect, &epilog }; out_desc dinfo; dinfo.file = file; dinfo.clocks = clocks; dinfo.devices = devices; ptf_match(cfg, &matchleadtext, fwrite_value, file); if(clocks) { clock_desc *cs; for(cs = clocks; cs; cs = cs->next) { fprintf(file, "#define %s_FREQ %luu\n", cs->cfgname, cs->freq); }; }; if(devices) { for(dinfo.dev = devices; dinfo.dev; dinfo.dev=dinfo.dev->next) { /* fprintf(file, "\n#define SOPC_HAS_%s 1\n", dinfo.dev->cfgname); */ p = ptf_find(dinfo.dev->ptf, &pi, item, "class", 0); if(p) { aclass.value = p->value; ptf_match(cfg, &matchaclass, fwrite_device_header, &dinfo); }; }; }; ptf_match(cfg, &matchepilog, fwrite_value, file); }
int is_not_connected(struct ptf_item *pi) { if(pi->item[0] == NULL) return 0; if(pi->item[0]->name == NULL) return 0; if(strcmp(pi->item[0]->name, "SLAVE") == 0) { struct ptf *t; struct ptf_item ti; t = ptf_find(pi->item[0]->sub, &ti, item, "N2G_Selected", "1"); if(t == NULL) return 1; }; return 0; }
void fwrite_device_header(struct ptf_item *pi, void *arg) { struct ptf *f; struct ptf_item fi; out_desc *dinfo = arg; /* This is called for every matching CLASS section in the configuration. The following loop iterates through all items in the CLASS section regardless of their nesting level */ f = ptf_find(pi->item[pi->level]->sub, &fi, item, 0, 0); while(f != NULL) { dinfo->orig_value = f->value; if(f->name && strncmp(f->name, "N2G_DEFINE_", 11)==0) { dinfo->def_name = f->name + 11; if(fi.level >= 2) { fi.level--; /* match only the enclosing section */ ptf_match(dinfo->dev->ptf->sub, &fi, fwrite_devhead_def, dinfo); fi.level++; } else { fwrite_devhead_def( 0, dinfo ); }; } else { f->value = 0; /* Match ANY value */ ptf_match(dinfo->dev->ptf->sub, &fi, fwrite_devhead_line, dinfo); f->value = dinfo->orig_value; }; f = ptf_next(&fi, item, 0, 0); }; }
memory_desc *find_memory(device_desc *devices) { struct ptf *p; struct ptf_item pi; memory_desc *tmd; memory_desc *memory = NULL; /********************************************************/ /* Check which of the devices are memory, sort by size */ if(devices) { struct ptf *p, *s; struct ptf_item pi; device_desc *dd; for(dd = devices; dd; dd=dd->next) { p = ptf_find(dd->ptf->sub, &pi, item, "Is_Memory_Device", "1"); if(p != NULL && pi.level>0) { s = pi.item[pi.level-1]; p = ptf_find(s, &pi, item, "Base_Address", 0); }; if(p != NULL) { tmd = (memory_desc*)malloc(sizeof(memory_desc)); if(tmd != NULL) { tmd->base = strtoul(p->value, 0, 0); p = ptf_find(s, &pi, item, "Address_Span", 0); if(p != 0) { tmd->size = strtoul(p->value, 0, 0); } else { tmd->size = 0; p = ptf_find(s, &pi, item, "Address_Width", 0); if(p) tmd->size = 1 << strtoul(p->value, 0, 0); p = ptf_find(s, &pi, item, "Data_Width", 0); if(p) tmd->size *= (strtoul(p->value, 0, 0) >> 3); }; if(tmd->size == 0) { free(tmd); } else { tmd->dev = dd; if(memory == NULL) { tmd->next = NULL; memory = tmd; } else { if(tmd->size > memory->size) { tmd->next = memory; memory = tmd; } else { memory_desc *uplink = memory; while(uplink->next != NULL && uplink->next->size > tmd->size) uplink=uplink->next; tmd->next = uplink->next; uplink->next = tmd; }; }; }; }; }; };