xref: /illumos-gate/usr/src/lib/libc/sparc/sys/syscall.S (revision 5d9d9091f564c198a760790b0bfa72c44e17912b)
1*5d9d9091SRichard Lowe/*
2*5d9d9091SRichard Lowe * CDDL HEADER START
3*5d9d9091SRichard Lowe *
4*5d9d9091SRichard Lowe * The contents of this file are subject to the terms of the
5*5d9d9091SRichard Lowe * Common Development and Distribution License (the "License").
6*5d9d9091SRichard Lowe * You may not use this file except in compliance with the License.
7*5d9d9091SRichard Lowe *
8*5d9d9091SRichard Lowe * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*5d9d9091SRichard Lowe * or http://www.opensolaris.org/os/licensing.
10*5d9d9091SRichard Lowe * See the License for the specific language governing permissions
11*5d9d9091SRichard Lowe * and limitations under the License.
12*5d9d9091SRichard Lowe *
13*5d9d9091SRichard Lowe * When distributing Covered Code, include this CDDL HEADER in each
14*5d9d9091SRichard Lowe * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*5d9d9091SRichard Lowe * If applicable, add the following below this CDDL HEADER, with the
16*5d9d9091SRichard Lowe * fields enclosed by brackets "[]" replaced with your own identifying
17*5d9d9091SRichard Lowe * information: Portions Copyright [yyyy] [name of copyright owner]
18*5d9d9091SRichard Lowe *
19*5d9d9091SRichard Lowe * CDDL HEADER END
20*5d9d9091SRichard Lowe */
21*5d9d9091SRichard Lowe
22*5d9d9091SRichard Lowe/*
23*5d9d9091SRichard Lowe * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24*5d9d9091SRichard Lowe * Use is subject to license terms.
25*5d9d9091SRichard Lowe */
26*5d9d9091SRichard Lowe
27*5d9d9091SRichard Lowe/*	Copyright (c) 1988 AT&T	*/
28*5d9d9091SRichard Lowe/*	  All Rights Reserved	*/
29*5d9d9091SRichard Lowe
30*5d9d9091SRichard Lowe/*
31*5d9d9091SRichard Lowe * C library -- long syscall(int sysnum, ...);
32*5d9d9091SRichard Lowe * C library -- long __systemcall(sysret_t *, int sysnum, ...);
33*5d9d9091SRichard Lowe *
34*5d9d9091SRichard Lowe * Interpret a given system call
35*5d9d9091SRichard Lowe *
36*5d9d9091SRichard Lowe * This version handles up to 8 'long' arguments to a system call.
37*5d9d9091SRichard Lowe *
38*5d9d9091SRichard Lowe * Even though indirect system call support exists in the SPARC
39*5d9d9091SRichard Lowe * 32-bit kernel, we want to eliminate it in a future release,
40*5d9d9091SRichard Lowe * so the real trap for the desired system call is issued right here.
41*5d9d9091SRichard Lowe *
42*5d9d9091SRichard Lowe * Even though %g5 can be used as a scratch register for sparcv9, we don't
43*5d9d9091SRichard Lowe * use it here because this code is shared between sparcv8 and sparcv9.
44*5d9d9091SRichard Lowe */
45*5d9d9091SRichard Lowe
46*5d9d9091SRichard Lowe	.file	"syscall.s"
47*5d9d9091SRichard Lowe
48*5d9d9091SRichard Lowe#include "SYS.h"
49*5d9d9091SRichard Lowe
50*5d9d9091SRichard Lowe	ANSI_PRAGMA_WEAK(syscall,function)
51*5d9d9091SRichard Lowe
52*5d9d9091SRichard Lowe	ENTRY(syscall)
53*5d9d9091SRichard Lowe	save	%sp, -SA(MINFRAME + 2*CLONGSIZE), %sp
54*5d9d9091SRichard Lowe	ldn	[%fp + STACK_BIAS + MINFRAME], %o5	! arg 5
55*5d9d9091SRichard Lowe	mov	%i3, %o2				! arg 2
56*5d9d9091SRichard Lowe	ldn	[%fp + STACK_BIAS + MINFRAME + CLONGSIZE], %g1
57*5d9d9091SRichard Lowe	mov	%i4, %o3				! arg 3
58*5d9d9091SRichard Lowe	stn	%g1, [%sp + STACK_BIAS + MINFRAME]	! arg 6
59*5d9d9091SRichard Lowe	mov	%i5, %o4				! arg 4
60*5d9d9091SRichard Lowe	ldn	[%fp + STACK_BIAS + MINFRAME + 2*CLONGSIZE], %g1
61*5d9d9091SRichard Lowe	mov	%i1, %o0				! arg 0
62*5d9d9091SRichard Lowe	stn	%g1, [%sp + STACK_BIAS + MINFRAME + CLONGSIZE] ! arg 7
63*5d9d9091SRichard Lowe	mov	%i2, %o1				! arg 1
64*5d9d9091SRichard Lowe	mov	%i0, %g1				! sysnum
65*5d9d9091SRichard Lowe	ta	SYSCALL_TRAPNUM
66*5d9d9091SRichard Lowe	bcc,a,pt %icc, 1f
67*5d9d9091SRichard Lowe	  sra	%o0, 0, %i0				! (int) cast
68*5d9d9091SRichard Lowe	restore	%o0, 0, %o0
69*5d9d9091SRichard Lowe	ba	__cerror
70*5d9d9091SRichard Lowe	  nop
71*5d9d9091SRichard Lowe1:
72*5d9d9091SRichard Lowe	ret
73*5d9d9091SRichard Lowe	  restore
74*5d9d9091SRichard Lowe	SET_SIZE(syscall)
75*5d9d9091SRichard Lowe
76*5d9d9091SRichard Lowe/*
77*5d9d9091SRichard Lowe * Same as _syscall(), but restricted to 6 syscall arguments
78*5d9d9091SRichard Lowe * so it doesn't need to incur the overhead of a register window.
79*5d9d9091SRichard Lowe * Implemented for use only within libc; symbol is not exported.
80*5d9d9091SRichard Lowe */
81*5d9d9091SRichard Lowe	ENTRY(_syscall6)
82*5d9d9091SRichard Lowe	mov	%o0, %g1			/* sysnum */
83*5d9d9091SRichard Lowe	mov	%o1, %o0			/* syscall args */
84*5d9d9091SRichard Lowe	mov	%o2, %o1
85*5d9d9091SRichard Lowe	mov	%o3, %o2
86*5d9d9091SRichard Lowe	mov	%o4, %o3
87*5d9d9091SRichard Lowe	mov	%o5, %o4
88*5d9d9091SRichard Lowe	ldn	[%sp + STACK_BIAS + MINFRAME], %o5
89*5d9d9091SRichard Lowe	ta	SYSCALL_TRAPNUM
90*5d9d9091SRichard Lowe	SYSCERROR
91*5d9d9091SRichard Lowe	retl
92*5d9d9091SRichard Lowe	  sra	%o0, 0, %o0			/* (int) cast */
93*5d9d9091SRichard Lowe	SET_SIZE(_syscall6)
94*5d9d9091SRichard Lowe
95*5d9d9091SRichard Lowe	ENTRY(__systemcall)
96*5d9d9091SRichard Lowe	save	%sp, -SA(MINFRAME + 2*CLONGSIZE), %sp
97*5d9d9091SRichard Lowe	ldn	[%fp + STACK_BIAS + MINFRAME], %o4	! arg 4
98*5d9d9091SRichard Lowe	mov	%i3, %o1				! arg 1
99*5d9d9091SRichard Lowe	ldn	[%fp + STACK_BIAS + MINFRAME + CLONGSIZE], %o5 ! arg5
100*5d9d9091SRichard Lowe	mov	%i4, %o2				! arg 2
101*5d9d9091SRichard Lowe	ldn	[%fp + STACK_BIAS + MINFRAME + 2*CLONGSIZE], %g1
102*5d9d9091SRichard Lowe	mov	%i5, %o3				! arg 3
103*5d9d9091SRichard Lowe	stn	%g1, [%sp + STACK_BIAS + MINFRAME]	! arg 6
104*5d9d9091SRichard Lowe	mov	%i2, %o0				! arg 0
105*5d9d9091SRichard Lowe	ldn	[%fp + STACK_BIAS + MINFRAME + 3*CLONGSIZE], %g1
106*5d9d9091SRichard Lowe	stn	%g1, [%sp + STACK_BIAS + MINFRAME + CLONGSIZE] ! arg7
107*5d9d9091SRichard Lowe	mov	%i1, %g1				! sysnum
108*5d9d9091SRichard Lowe	ta	SYSCALL_TRAPNUM
109*5d9d9091SRichard Lowe	bcc,pt	%icc, 1f
110*5d9d9091SRichard Lowe	  mov	-1, %g1
111*5d9d9091SRichard Lowe	stn	%g1, [%i0]	/* error */
112*5d9d9091SRichard Lowe	ba	2f
113*5d9d9091SRichard Lowe	  stn	%g1, [%i0 + CLONGSIZE]
114*5d9d9091SRichard Lowe1:
115*5d9d9091SRichard Lowe	stn	%o0, [%i0]	/* no error */
116*5d9d9091SRichard Lowe	clr	%o0
117*5d9d9091SRichard Lowe	stn	%o1, [%i0 + CLONGSIZE]
118*5d9d9091SRichard Lowe2:
119*5d9d9091SRichard Lowe	ret
120*5d9d9091SRichard Lowe	  restore %o0, 0, %o0
121*5d9d9091SRichard Lowe	SET_SIZE(__systemcall)
122*5d9d9091SRichard Lowe
123*5d9d9091SRichard Lowe/*
124*5d9d9091SRichard Lowe * Same as __systemcall(), but restricted to 6 syscall arguments
125*5d9d9091SRichard Lowe * so it doesn't need to incur the overhead of a register window.
126*5d9d9091SRichard Lowe * Implemented for use only within libc; symbol is not exported.
127*5d9d9091SRichard Lowe */
128*5d9d9091SRichard Lowe	ENTRY(__systemcall6)
129*5d9d9091SRichard Lowe	stn	%o0, [%sp + SAVE_OFFSET]	/* sysret address */
130*5d9d9091SRichard Lowe	mov	%o1, %g1			/* sysnum */
131*5d9d9091SRichard Lowe	mov	%o2, %o0			/* syscall args */
132*5d9d9091SRichard Lowe	mov	%o3, %o1
133*5d9d9091SRichard Lowe	mov	%o4, %o2
134*5d9d9091SRichard Lowe	mov	%o5, %o3
135*5d9d9091SRichard Lowe	ldn	[%sp + STACK_BIAS + MINFRAME], %o4
136*5d9d9091SRichard Lowe	ldn	[%sp + STACK_BIAS + MINFRAME + CLONGSIZE], %o5
137*5d9d9091SRichard Lowe	ta	SYSCALL_TRAPNUM
138*5d9d9091SRichard Lowe	bcs,pn	%icc, 1f
139*5d9d9091SRichard Lowe	  ldn	[%sp + SAVE_OFFSET], %g1
140*5d9d9091SRichard Lowe	stn	%o0, [%g1]	/* no error */
141*5d9d9091SRichard Lowe	stn	%o1, [%g1 + CLONGSIZE]
142*5d9d9091SRichard Lowe	retl
143*5d9d9091SRichard Lowe	  clr	%o0
144*5d9d9091SRichard Lowe1:
145*5d9d9091SRichard Lowe	mov	-1, %o1		/* error */
146*5d9d9091SRichard Lowe	stn	%o1, [%g1]
147*5d9d9091SRichard Lowe	retl
148*5d9d9091SRichard Lowe	  stn	%o1, [%g1 + CLONGSIZE]
149*5d9d9091SRichard Lowe	SET_SIZE(__systemcall6)
150