+ int sarg_ofs = 1; // stack offset to args, in DWORDs
+ int argc_repush;
+ int stack_args;
+ int i;
+
+ argc_repush = pp->argc;
+ stack_args = pp->argc_stack;
+ if (pp->is_vararg) {
+ argc_repush = ARRAY_SIZE(pp->arg); // hopefully enough?
+ stack_args = argc_repush - pp->argc_reg;
+ }
+
+ fprintf(f, "# %s\n", pp->is_stdcall ? "__stdcall" : "__cdecl");
+ fprintf(f, ".global %s\n", sym);
+ fprintf(f, "%s:\n", sym);
+
+ if (pp->argc_reg == 0 && !pp->is_stdcall) {
+ fprintf(f, "\tjmp _%s\n\n", sym);
+ return;
+ }
+
+ fprintf(f, "\tpushl %%edx\n"); // just in case..
+ sarg_ofs++;
+
+ // construct arg stack
+ for (i = argc_repush - 1; i >= 0; i--) {
+ if (pp->arg[i].reg == NULL) {
+ fprintf(f, "\tmovl %d(%%esp), %%edx\n",
+ (sarg_ofs + stack_args - 1) * 4);
+ fprintf(f, "\tpushl %%edx\n");
+ stack_args--;
+ }
+ else {
+ if (IS(pp->arg[i].reg, "edx"))
+ // must reload original edx
+ fprintf(f, "\tmovl %d(%%esp), %%edx\n",
+ (sarg_ofs - 2) * 4);