From: notaz Date: Sat, 3 Oct 2015 00:00:41 +0000 (+0300) Subject: tools: better fastcall support X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=285b3a6b777658e2fa5e504cfe8a2ca4221b54af;p=ia32rtools.git tools: better fastcall support --- diff --git a/run_exp.sh b/run_exp.sh index 6b9460f..f90c7fe 100755 --- a/run_exp.sh +++ b/run_exp.sh @@ -1,20 +1,30 @@ #!/bin/sh +# export decorated symbols using undecorated ones from .asm +# $1 - .def +# $2 - .in_c outf=$3 -grep '@' $1 | awk '{print $1}' > ${outf}_explist +grep '@' $1 | grep -v '\' | awk '{print $1}' > ${outf}_explist echo ".text" > $outf echo ".align 4" >> $outf cat ${outf}_explist | while read i; do - sym=`echo $i | awk -F@ '{print $1}'` + s0=`echo $i | cut -c 1` + if [ "$s0" = "@" ]; then + sym=`echo $i | awk -F@ '{print $2}'` + pre="" + else + sym=`echo $i | awk -F@ '{print $1}'` + pre="_" + fi if grep -q "$sym" $2; then continue fi - echo ".globl _$i" >> $outf - echo "_$i:" >> $outf + echo ".globl $pre$i" >> $outf + echo "$pre$i:" >> $outf echo " jmp $sym" >> $outf echo >> $outf done diff --git a/tools/mkbridge.c b/tools/mkbridge.c index dda6269..29bdd9a 100644 --- a/tools/mkbridge.c +++ b/tools/mkbridge.c @@ -183,7 +183,21 @@ static void out_fromasm_x86(FILE *f, const char *sym, pp->is_fastcall ? "__fastcall" : (pp->is_stdcall ? "__stdcall" : "__cdecl")); if (ret64) - fprintf(f, " ret64"); + fprintf(f, " ret64"); + if (!pp->is_fastcall && pp->argc_reg != 0) + fprintf(f, " +reg"); + + if (pp->is_stdcall && !pp->is_fastcall && pp->argc_reg != 0 + && !IS_START(sym, "sub_") && !IS_START(sym, "f_")) + { + // alias for possible .def export + char sym2[256]; + + snprintf(sym2, sizeof(sym2), "_%s@%d", + sym, pp->argc * 4); + fprintf(f, "\n.global %s # for .def\n", sym2); + fprintf(f, "%s:", sym2); + } fprintf(f, "\n.global %s\n", sym); fprintf(f, "%s:\n", sym); @@ -316,7 +330,7 @@ int main(int argc, char *argv[]) my_assert_not(fout, NULL); fprintf(fout, ".text\n\n"); - fprintf(fout, "# to asm\n\n"); + fprintf(fout, "# C -> asm\n\n"); while (fgets(line, sizeof(line), fsyms_to)) { @@ -337,7 +351,7 @@ int main(int argc, char *argv[]) out_toasm_x86(fout, sym_noat, pp); } - fprintf(fout, "# from asm\n\n"); + fprintf(fout, "# asm -> C\n\n"); while (fgets(line, sizeof(line), fsyms_from)) { diff --git a/tools/mkdef_ord.c b/tools/mkdef_ord.c index 3873c3a..648e0d4 100644 --- a/tools/mkdef_ord.c +++ b/tools/mkdef_ord.c @@ -20,7 +20,7 @@ int main(int argc, char *argv[]) { const struct parsed_proto *pp; FILE *fout, *fhdr; - char basename[256]; + char basename[256] = { 0, }; char line[256]; char fmt[256]; char word[256]; @@ -34,12 +34,14 @@ int main(int argc, char *argv[]) for (arg = 1; arg < argc; arg++) { if (IS(argv[arg], "-n")) noname = 1; + else if (IS(argv[arg], "-b") && arg < argc - 1) + snprintf(basename, sizeof(basename), "%s", argv[++arg]); else break; } if (argc != arg + 2) { - printf("usage:\n%s [-n] <.h> <.def>\n", argv[0]); + printf("usage:\n%s [-n] [-b ] <.h> <.def>\n", argv[0]); return 1; } @@ -50,15 +52,17 @@ int main(int argc, char *argv[]) fout = fopen(argv[arg++], "w"); my_assert_not(fout, NULL); - p = strrchr(hdrfn, '.'); - my_assert_not(p, NULL); - p2 = strrchr(hdrfn, '/'); - if (p2++ == NULL) - p2 = hdrfn; - l = p - p2; - my_assert((unsigned int)l < 256, 1); - memcpy(basename, p2, l); - basename[l] = 0; + if (basename[0] == 0) { + p = strrchr(hdrfn, '.'); + my_assert_not(p, NULL); + p2 = strrchr(hdrfn, '/'); + if (p2++ == NULL) + p2 = hdrfn; + l = p - p2; + my_assert((unsigned int)l < 256, 1); + memcpy(basename, p2, l); + basename[l] = 0; + } snprintf(fmt, sizeof(fmt), "%s_%%d", basename); @@ -91,9 +95,11 @@ int main(int argc, char *argv[]) if (pp == NULL) return 1; - fprintf(fout, " %s", word); + fputc(' ', fout); + fputc(pp->is_fastcall ? '@' : ' ', fout); + fprintf(fout, "%s", word); if (pp->is_stdcall) - fprintf(fout, "@%-2d", pp->argc_stack * 4); + fprintf(fout, "@%-2d", pp->argc * 4); else fprintf(fout, " "); fprintf(fout, " @%d", ord);