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