X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=tools%2Fmkbridge.c;h=9b874453f326bd4d398f49bf5f99f1c6e71f5111;hb=b2f80dfd1d1cb3dac06c234d5b2118209abd668d;hp=2066f02197d6f1d58d8597e8d913922b2beeb0bf;hpb=c0050df6e9d6eb81afacb0fa2d1910293dd2165e;p=ia32rtools.git diff --git a/tools/mkbridge.c b/tools/mkbridge.c index 2066f02..9b87445 100644 --- a/tools/mkbridge.c +++ b/tools/mkbridge.c @@ -23,13 +23,38 @@ static int is_x86_reg_saved(const char *reg) return !nosave; } -static void out_toasm_x86(FILE *f, const char *sym_in, - const char *sym_out, const struct parsed_proto *pp) +// output decorated name +static const char *pp_to_name(const struct parsed_proto *pp) +{ + static char buf[256]; + char atval[16]; + + if (!pp->is_fastcall && pp->argc_reg != 0) { + // can only be handled by __cdecl C func + snprintf(buf, sizeof(buf), "_%s", pp->name); + return buf; + } + + atval[0] = 0; + if (pp->is_stdcall) { + snprintf(atval, sizeof(atval), "@%d", + pp->argc * 4); + } + snprintf(buf, sizeof(buf), "%s%s%s", + pp->is_fastcall ? "@" : "_", + pp->name, atval); + + return buf; +} + +static void out_toasm_x86(FILE *f, const char *sym_out, + const struct parsed_proto *pp) { int must_save = 0; int sarg_ofs = 1; // stack offset to args, in DWORDs int args_repushed = 0; int argc_repush; + const char *name; int i; argc_repush = pp->argc; @@ -41,8 +66,9 @@ static void out_toasm_x86(FILE *f, const char *sym_in, must_save |= is_x86_reg_saved(pp->arg[i].reg); } - fprintf(f, ".global %s%s\n", pp->is_fastcall ? "@" : "_", sym_in); - fprintf(f, "%s%s:\n", pp->is_fastcall ? "@" : "_", sym_in); + name = pp_to_name(pp); + fprintf(f, ".global %s\n", name); + fprintf(f, "%s:\n", name); if (pp->argc_reg == 0 || pp->is_fastcall) { fprintf(f, "\t# %s\n", @@ -112,6 +138,7 @@ static void out_fromasm_x86(FILE *f, const char *sym, { int sarg_ofs = 1; // stack offset to args, in DWORDs int saved_regs = 0; + int c_is_stdcall; int argc_repush; int stack_args; int ret64; @@ -134,15 +161,15 @@ static void out_fromasm_x86(FILE *f, const char *sym, fprintf(f, "\n.global %s\n", sym); fprintf(f, "%s:\n", sym); - if (pp->argc_reg == 0 || pp->is_fastcall) { - fprintf(f, "\tjmp %s%s", - pp->is_fastcall ? "@" : "_", sym); - if (pp->is_stdcall && pp->argc > 0) - fprintf(f, "@%d", pp->argc * 4); - fprintf(f, "\n\n"); + if ((pp->argc_reg == 0 || pp->is_fastcall) + && !IS(pp->name, "storm_491")) // wants edx save :( + { + fprintf(f, "\tjmp %s\n\n", pp_to_name(pp)); return; } + c_is_stdcall = (pp->argc_reg == 0 && pp->is_stdcall); + // at least sc sub_47B150 needs edx to be preserved // int64 returns use edx:eax - no edx save // we use ecx also as scratch @@ -174,10 +201,9 @@ static void out_fromasm_x86(FILE *f, const char *sym, sarg_ofs++; } - // no worries about calling conventions - always __cdecl - fprintf(f, "\n\tcall _%s\n\n", sym); + fprintf(f, "\n\tcall %s\n\n", pp_to_name(pp)); - if (sarg_ofs > saved_regs + 1) + if (!c_is_stdcall && sarg_ofs > saved_regs + 1) fprintf(f, "\tadd $%d,%%esp\n", (sarg_ofs - (saved_regs + 1)) * 4); @@ -239,7 +265,7 @@ int main(int argc, char *argv[]) if (pp == NULL) goto out; - out_toasm_x86(fout, sym, sym_noat, pp); + out_toasm_x86(fout, sym_noat, pp); } fprintf(fout, "# from asm\n\n");