syscall_6502: generate correct varargs stubs
authorAlan Cox <alan@linux.intel.com>
Sat, 17 Jan 2015 15:33:17 +0000 (15:33 +0000)
committerAlan Cox <alan@linux.intel.com>
Sat, 17 Jan 2015 15:33:17 +0000 (15:33 +0000)
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

index d3ee6c8..c523eb6 100644 (file)
@@ -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);
 }