From 4851846370a543194678533ee64d645504b9b326 Mon Sep 17 00:00:00 2001 From: Tormod Volden Date: Fri, 17 Apr 2015 00:00:18 +0200 Subject: [PATCH] 6809: Adjust syscall argument passing to caller convention The calling user process will put the first argument in X and the rest on the stack. Make sure this get carried over to u_argn etc correctly. Also make sure the return values from the system call is handed back to the caller through the rti. Signed-off-by: Tormod Volden --- Kernel/lowlevel-6809.s | 18 +++++++++++------- Library/libs/fuzix6809/syscall6809.s | 5 +---- Library/tools/syscall_6809.c | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Kernel/lowlevel-6809.s b/Kernel/lowlevel-6809.s index 30e9c406..6d338d7c 100644 --- a/Kernel/lowlevel-6809.s +++ b/Kernel/lowlevel-6809.s @@ -75,26 +75,26 @@ unix_syscall_entry: lda #1 sta _kernel_flag - leax 12,s ; stacked by the swi + leax 14,s ; 12 stacked by the swi + return address of caller ldy #U_DATA__U_ARGN SAM_USER - ldd ,x++ ; copy arguments + ldd 4,s ; first argument in swi stacked X SAM_KERNEL std ,y++ SAM_USER - ldd ,x++ + ldd ,x++ ; second argument from caller's stack SAM_KERNEL std ,y++ SAM_USER - ldd ,x++ + ldd ,x++ ; third SAM_KERNEL std ,y++ SAM_USER - ldd ,x++ + ldd ,x++ ; fourth SAM_KERNEL std ,y++ SAM_USER - ldd 4,s ; X register -> syscall number + ldd 1,s ; stacked D register -> syscall number SAM_KERNEL stb U_DATA__U_CALLNO ; save process stack pointer (in user page) @@ -140,10 +140,14 @@ unix_syscall_entry: not_error: ; no error to signal! return syscall return value instead of error code ldx U_DATA__U_RETVAL - ldd #0 + ldd #0 ; just for setting Z flag unix_return: ; we never make a syscall from in kernel space SAM_USER + stx 4,s ; replace stacked values before rti + std 1,s + tfr cc,a ; Z determined by D + sta ,s ; replace stacked CC to signal error rti ; diff --git a/Library/libs/fuzix6809/syscall6809.s b/Library/libs/fuzix6809/syscall6809.s index 510d5783..a8c906da 100644 --- a/Library/libs/fuzix6809/syscall6809.s +++ b/Library/libs/fuzix6809/syscall6809.s @@ -8,8 +8,5 @@ __syscall: bne error rts error: - sta _errno - ldx #0 - stx _errno+1 - leax -1,x ; Return $FFFF (-1) + std _errno ; X is -1 rts diff --git a/Library/tools/syscall_6809.c b/Library/tools/syscall_6809.c index 64a05774..f310978c 100644 --- a/Library/tools/syscall_6809.c +++ b/Library/tools/syscall_6809.c @@ -21,7 +21,7 @@ static void write_call(int n) fprintf(fp, "\t.area .text\n\n"); fprintf(fp, "\t.globl __syscall\n"); fprintf(fp, "\t.globl _%s\n\n", syscall_name[n]); - fprintf(fp, "_%s:\n\tldx #%d\n", syscall_name[n], n); + fprintf(fp, "_%s:\n\tldd #%d\n", syscall_name[n], n); fprintf(fp, "\tjmp __syscall\n"); fclose(fp); } -- 2.34.1