Index: kernel/arch/sparc64/src/trap/syscall.c
===================================================================
--- kernel/arch/sparc64/src/trap/syscall.c	(revision 3ee8a07528aa466b40a362672714a05e936d396e)
+++ 	(revision )
@@ -1,48 +1,0 @@
-/*
- * Copyright (c) 2006 Jakub Jermar
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup sparc64interrupt
- * @{
- */
-/** @file
- *
- */
-
-#include <arch/syscall.h>
-#include <arch/trap/syscall.h>
-#include <syscall/syscall.h>
-#include <panic.h>
-#include <arch/types.h>
-
-unative_t syscall(int n, istate_t *istate, unative_t a1, unative_t a2, unative_t a3, unative_t a4)
-{
-	return syscall_handler(a1, a2, a3, a4, n - TT_TRAP_INSTRUCTION(0));
-}
-
-/** @}
- */
Index: kernel/arch/sparc64/src/trap/trap_table.S
===================================================================
--- kernel/arch/sparc64/src/trap/trap_table.S	(revision 3ee8a07528aa466b40a362672714a05e936d396e)
+++ kernel/arch/sparc64/src/trap/trap_table.S	(revision 05ae7081ae1690a4609ba4c709fbc67b4ae09a57)
@@ -644,5 +644,5 @@
  *
  * Input registers:
- *	%g1		Address of function to call.
+ *	%g1		Address of function to call if this is not a syscall.
  * 	%g2	 	First argument for the function.
  *	%g6		Pre-set as kernel stack base if trap from userspace.
@@ -698,8 +698,10 @@
 	 * Copy arguments for the syscall to the new window.
 	 */
-	mov %i0, %o2
-	mov %i1, %o3
-	mov %i2, %o4
-	mov %i3, %o5
+	mov %i0, %o0
+	mov %i1, %o1
+	mov %i2, %o2
+	mov %i3, %o3
+	mov %i4, %o4
+	mov %i5, %o5
 .endif
 
@@ -741,5 +743,10 @@
 	 */
 	mov %g1, %l0
+.if NOT(\is_syscall)
 	mov %g2, %o0
+.else
+	! store the syscall number on the stack as 7th argument
+	stx %g2, [%sp + STACK_WINDOW_SAVE_AREA_SIZE + STACK_BIAS + STACK_ARG6] 
+.endif
 
 	/*
@@ -768,4 +775,5 @@
 	SAVE_GLOBALS
 	
+.if NOT(\is_syscall)
 	/*
 	 * Call the higher-level handler and pass istate as second parameter.
@@ -773,10 +781,11 @@
 	call %l0
 	add %sp, PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_TNPC, %o1
-
-.if \is_syscall
-	/*
-	 * Copy the value returned by the syscall.
-	 */
-	mov %o0, %i0
+.else
+	/*
+	 * Call the higher-level syscall handler.
+	 */
+	call syscall_handler
+	nop
+	mov %o0, %i0				! copy the value returned by the syscall
 .endif
 
