clock_desc *find_clocks( struct ptf *sopc, struct ptf *cfg ) { clock_desc *clocks, *reverse; struct ptf system = { section, "SYSTEM", 0, 0, 0 }; struct ptf wizargs = { section, "WIZARD_SCRIPT_ARGUMENTS", 0, 0, 0 }; struct ptf all = { section, "CLOCKS", 0, 0, 0 }; struct ptf clock = { section, "CLOCK", 0, 0, 0 }; struct ptf freq = { item, "frequency", 0, 0, 0 }; struct ptf_item clk_spec = { 5, &system, &wizargs, &all, &clock, &freq }; struct ptf named = { item, 0, 0, 0, 0 }; struct ptf_item clk_cfg = { 2, &all, &named }; clocks = NULL; ptf_match(sopc, &clk_spec, add_clock_spec, &clocks); /* Reverse the linked list and look for configured names */ reverse = NULL; while(clocks) { clock_desc *tmp = clocks; clocks = clocks->next; tmp->next = reverse; reverse = tmp; named.value = tmp->name; ptf_match(cfg, &clk_cfg, set_clock_cfgname, tmp); if(tmp->cfgname == NULL) tmp->cfgname = ptf_defused_name(tmp->name); }; return reverse; }
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); }
void fwrite_linkcmds_file(FILE *file, struct ptf *cfg, struct ptf *cpu, device_desc *devices, memory_desc *memory) { struct ptf *p; struct ptf_item pi; memory_desc *tmd; lcmd_desc linfo; struct ptf ptlink = { section, "LINKCMDS", 0, 0, 0 }; struct ptf ptleadtext = { item, "LEADTEXT", 0, 0, 0 }; struct ptf ptepilog = { item, "EPILOG", 0, 0, 0 }; struct ptf_item malihead = { 2, &ptlink, &ptleadtext }; struct ptf_item maliepil = { 2, &ptlink, &ptepilog }; struct ptf ptsect = { section, "SECTION", 0, 0, 0 }; struct ptf ptcmds = { item, "COMMANDS", 0, 0, 0 }; struct ptf ptstabs = { item, "STABS", 0, 0, 0 }; struct ptf_item malisect = { 3, &ptlink, &ptsect, &ptcmds }; struct ptf_item malistabs = { 2, &ptlink, &ptstabs }; linfo.cfg = cfg; linfo.cpu = cpu; linfo.file = file; linfo.devices = devices; linfo.memory = memory; ptf_match(cfg, &malihead, fwrite_value, file); fprintf(file, "MEMORY\n{\n"); for(tmd = linfo.memory; tmd; tmd = tmd->next) { fprintf(file, " %s : ORIGIN = 0x%08X, LENGTH = 0x%08X\n", tmd->dev->cfgname, tmd->base, tmd->size); } fprintf(file, "}\n\nSECTIONS\n{\n"); ptf_match(cfg, &malisect, fwrite_lcmds_section, &linfo); ptf_match(cfg, &malistabs, fwrite_value, file); for(tmd = linfo.memory; tmd; tmd = tmd->next) { fprintf(file, " %s : ORIGIN = 0x%08X, LENGTH = 0x%08X\n", tmd->dev->cfgname, tmd->base, tmd->size); } fprintf(file, "}\n\n"); ptf_match(cfg, &maliepil, fwrite_value, file); }
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); }; }
bus_bridge_pair *find_bridges(struct ptf *p) { bus_bridge_pair *bridges = 0; struct ptf system = { section, "SYSTEM", 0, 0, 0 }; struct ptf module = { section, "MODULE", 0, 0, 0 }; struct ptf slave = { section, "SLAVE", 0, 0, 0 }; struct ptf syb = { section, "SYSTEM_BUILDER_INFO", 0, 0, 0 }; struct ptf to = { item, "Bridges_To", 0, 0, 0 }; struct ptf_item brdg = { 5, &system, &module, &slave, &syb, &to }; ptf_match(p, &brdg, add_bridge_dest, &bridges); return bridges; }
void add_bridge_dest(struct ptf_item *pi, void *arg) { struct ptf maby_section = { section, "MASTERED_BY", 0, 0, 0 }; struct ptf_item maby = { 1, &maby_section }; char *bridge_name = pi->item[1]->value; char *bridge_dest = pi->item[pi->level]->value; struct { char *bt; bus_bridge_pair **bridges; } binfo; binfo.bridges = arg; binfo.bt = (char*)malloc(strlen(bridge_name)+strlen(bridge_dest) + 2); strcpy(binfo.bt, bridge_name); strcat(binfo.bt, "/"); strcat(binfo.bt, bridge_dest); ptf_match(pi->item[pi->level-1]->sub, &maby, add_bridge_master, &binfo); /* binfo.bt is NOT freed here */ }