X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=tools%2Fasmproc.c;h=fe6fa474fb2f600b88280aafca431ac29238d655;hb=cb6623274360357225526abaf285e5b500dbef97;hp=f52e0a6e22db38855622585732c460e31631669c;hpb=d4e3b5db16cdce0cbf0842eb6e908972df8e73cf;p=ia32rtools.git diff --git a/tools/asmproc.c b/tools/asmproc.c index f52e0a6..fe6fa47 100644 --- a/tools/asmproc.c +++ b/tools/asmproc.c @@ -9,6 +9,7 @@ struct sl_item { char *name; unsigned int callsites:1; unsigned int found:1; + unsigned int ignore_missing:1; }; static int cmp_sym(const void *p1_, const void *p2_) @@ -50,7 +51,7 @@ static int cmp_sym_sort(const void *p1_, const void *p2_) } void read_list(struct sl_item **sl_in, int *cnt, int *alloc, - FILE *f, int callsites) + FILE *f, int callsites, int ignore_missing) { struct sl_item *sl = *sl_in; int c = *cnt; @@ -64,6 +65,7 @@ void read_list(struct sl_item **sl_in, int *cnt, int *alloc, sl[c].name = strdup(word); sl[c].callsites = callsites; + sl[c].ignore_missing = ignore_missing; sl[c].found = 0; c++; @@ -101,6 +103,7 @@ int main(int argc, char *argv[]) { struct sl_item *symlist, *sym, ssym = { NULL, }; int patch_callsites = 0; + int ignore_missing = 0; FILE *fout, *fin, *f; int symlist_alloc; int symlist_cnt; @@ -112,13 +115,14 @@ int main(int argc, char *argv[]) char word5[256]; char word6[256]; char func[256]; - char *p; + char *p, *p2; int i; if (argc < 4) { - // -c - patch callsites - printf("usage:\n%s [[-c] ]*>\n", + printf("usage:\n%s [[-c][-i] ]*>\n", argv[0]); + printf(" -c - patch callsites\n" + " -i - ignore missing syms\n"); return 1; } @@ -132,14 +136,19 @@ int main(int argc, char *argv[]) patch_callsites = 1; continue; } + if (strcmp(argv[i], "-i") == 0) { + ignore_missing = 1; + continue; + } f = fopen(argv[i], "r"); my_assert_not(f, NULL); read_list(&symlist, &symlist_cnt, &symlist_alloc, - f, patch_callsites); + f, patch_callsites, ignore_missing); fclose(f); patch_callsites = 0; + ignore_missing = 0; } qsort(symlist, symlist_cnt, sizeof(symlist[0]), cmp_sym_sort); @@ -184,7 +193,7 @@ int main(int argc, char *argv[]) } } - if (IS_OR3(word, "call", "jmp", "public")) { + if (IS_OR2(word, "call", "jmp")) { ssym.name = word2; sym = bsearch(&ssym, symlist, symlist_cnt, sizeof(symlist[0]), cmp_sym); @@ -197,16 +206,25 @@ int main(int argc, char *argv[]) } } + if (IS(word, "public")) { + ssym.name = word2; + sym = bsearch(&ssym, symlist, symlist_cnt, + sizeof(symlist[0]), cmp_sym); + if (sym != NULL) { + fprintf(fout, "\t\tpublic %s%s", sym_use(sym), p); + continue; + } + } + p = sskip(p); if (*p == 0 || *p == ';') goto pass; // need at least 3 words p = next_word(word3, sizeof(word3), p); - // dd offset // push offset // jcc short - if ( (IS_OR2(word, "dd", "push") && IS(word2, "offset")) + if ( (IS(word, "push") && IS(word2, "offset")) || (word[0] == 'j' && IS(word2, "short")) ) { ssym.name = word3; sym = bsearch(&ssym, symlist, symlist_cnt, @@ -220,6 +238,13 @@ int main(int argc, char *argv[]) } } + // dd offset + if (IS(word, "dd") && IS(word2, "offset")) { + fprintf(fout, "\t\tdd"); + strcpy(word, word3); + goto offset_loop; + } + p = sskip(p); if (*p == 0 || *p == ';') goto pass; // need at least 4 words @@ -228,14 +253,9 @@ int main(int argc, char *argv[]) // dd offset if (IS(word2, "dd") && IS(word3, "offset")) { - ssym.name = word4; - sym = bsearch(&ssym, symlist, symlist_cnt, - sizeof(symlist[0]), cmp_sym); - if (sym != NULL && sym->callsites) { - fprintf(fout, "%s\tdd offset %s%s", word, - sym_use(sym), p); - continue; - } + fprintf(fout, "%s\tdd", word); + strcpy(word, word4); + goto offset_loop; } // mov , offset @@ -280,10 +300,37 @@ int main(int argc, char *argv[]) pass: fwrite(line, 1, strlen(line), fout); + continue; + +offset_loop: + while (1) { + p2 = strchr(word, ','); + if (p2) + *p2 = 0; + + ssym.name = word; + sym = bsearch(&ssym, symlist, symlist_cnt, + sizeof(symlist[0]), cmp_sym); + fprintf(fout, " offset %s%s", + (sym != NULL && sym->callsites) ? sym_use(sym) : word, + p2 ? "," : ""); + + p2 = next_word(word, sizeof(word), p); + if (word[0] == 0 || word[0] == ';') { + break; + } + if (!IS(word, "offset")) { + printf("could not handle offset array\n"); + break; + } + p = next_word(word, sizeof(word), p2); + } + fprintf(fout, "%s", p); + continue; } for (i = 0; i < symlist_cnt; i++) { - if (!symlist[i].found) + if (!symlist[i].found && !symlist[i].ignore_missing) printf("warning: sym '%s' not found\n", symlist[i].name); } @@ -292,3 +339,5 @@ pass: return 0; } + +// vim:ts=2:shiftwidth=2