From d656a5c6f100c2c497880820554036878eb4e54d Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Sat, 17 Jan 2015 15:33:17 +0000 Subject: [PATCH] syscall_6502: generate correct varargs stubs Syscalls are now working. Init gets as far as the login prompt then switches back to the parent and traps into the monitor --- Library/tools/syscall_6502.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Library/tools/syscall_6502.c b/Library/tools/syscall_6502.c index d3ee6c87..c523eb61 100644 --- a/Library/tools/syscall_6502.c +++ b/Library/tools/syscall_6502.c @@ -22,10 +22,16 @@ static void write_call(int n) fprintf(fp, "\t.import __syscall\n\n", syscall_name[n]); fprintf(fp, "\t.import pushax\n\n"); fprintf(fp, ".proc _%s\n", syscall_name[n]); - if (syscall_args[n]) - fprintf(fp, "\tjsr pushax\n"); + if (syscall_args[n] == VARARGS) { + /* We are not entered as fastcall, in addition y holds the argument + count for us already. All the work is already done */ + } else { + /* This is basically "fastcall to cdecl and set y" */ + if (syscall_args[n]) + fprintf(fp, "\tjsr pushax\n"); + fprintf(fp, "\tldy #%d\n", 2 * syscall_args[n]); + } fprintf(fp, "\tldx #%d\n", n); - fprintf(fp, "\tldy #%d\n", 2 * syscall_args[n]); fprintf(fp, "\tjmp __syscall\n\n.endproc\n"); fclose(fp); } -- 2.34.1