10Sstevel@tonic-gate/*	$NetBSD: SYS.h,v 1.22 2007/11/23 07:36:05 dsl Exp $	*/
20Sstevel@tonic-gate
30Sstevel@tonic-gate/*-
40Sstevel@tonic-gate * Copyright (c) 2007 The NetBSD Foundation, Inc.
57298SMark.J.Nelson@Sun.COM * All rights reserved.
67298SMark.J.Nelson@Sun.COM *
70Sstevel@tonic-gate * This code is derived from software contributed to The NetBSD Foundation
80Sstevel@tonic-gate * by Andrew Doran.
90Sstevel@tonic-gate *
100Sstevel@tonic-gate * Redistribution and use in source and binary forms, with or without
110Sstevel@tonic-gate * modification, are permitted provided that the following conditions
120Sstevel@tonic-gate * are met:
130Sstevel@tonic-gate * 1. Redistributions of source code must retain the above copyright
140Sstevel@tonic-gate *    notice, this list of conditions and the following disclaimer.
150Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright
160Sstevel@tonic-gate *    notice, this list of conditions and the following disclaimer in the
170Sstevel@tonic-gate *    documentation and/or other materials provided with the distribution.
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
200Sstevel@tonic-gate * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2111426SRoger.Faulkner@Sun.COM * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
220Sstevel@tonic-gate * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2311426SRoger.Faulkner@Sun.COM * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
240Sstevel@tonic-gate * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
250Sstevel@tonic-gate * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
260Sstevel@tonic-gate * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
277298SMark.J.Nelson@Sun.COM * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
280Sstevel@tonic-gate * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
290Sstevel@tonic-gate * POSSIBILITY OF SUCH DAMAGE.
300Sstevel@tonic-gate */
310Sstevel@tonic-gate
320Sstevel@tonic-gate/*-
330Sstevel@tonic-gate * Copyright (c) 1990 The Regents of the University of California.
340Sstevel@tonic-gate * All rights reserved.
350Sstevel@tonic-gate *
360Sstevel@tonic-gate * This code is derived from software contributed to Berkeley by
370Sstevel@tonic-gate * William Jolitz.
380Sstevel@tonic-gate *
390Sstevel@tonic-gate * Redistribution and use in source and binary forms, with or without
400Sstevel@tonic-gate * modification, are permitted provided that the following conditions
410Sstevel@tonic-gate * are met:
420Sstevel@tonic-gate * 1. Redistributions of source code must retain the above copyright
4311426SRoger.Faulkner@Sun.COM *    notice, this list of conditions and the following disclaimer.
440Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright
450Sstevel@tonic-gate *    notice, this list of conditions and the following disclaimer in the
4611426SRoger.Faulkner@Sun.COM *    documentation and/or other materials provided with the distribution.
470Sstevel@tonic-gate * 3. Neither the name of the University nor the names of its contributors
480Sstevel@tonic-gate *    may be used to endorse or promote products derived from this software
490Sstevel@tonic-gate *    without specific prior written permission.
500Sstevel@tonic-gate *
510Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
520Sstevel@tonic-gate * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
530Sstevel@tonic-gate * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
540Sstevel@tonic-gate * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
550Sstevel@tonic-gate * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
560Sstevel@tonic-gate * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
5711426SRoger.Faulkner@Sun.COM * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
5811426SRoger.Faulkner@Sun.COM * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
5911426SRoger.Faulkner@Sun.COM * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
6011426SRoger.Faulkner@Sun.COM * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
6111426SRoger.Faulkner@Sun.COM * SUCH DAMAGE.
6211426SRoger.Faulkner@Sun.COM *
6311426SRoger.Faulkner@Sun.COM *	from: @(#)SYS.h	5.5 (Berkeley) 5/7/91
6411426SRoger.Faulkner@Sun.COM */
650Sstevel@tonic-gate
660Sstevel@tonic-gate#include <machine/asm.h>
6711426SRoger.Faulkner@Sun.COM#include <sys/syscall.h>
6811426SRoger.Faulkner@Sun.COM
690Sstevel@tonic-gate#ifdef __STDC__
700Sstevel@tonic-gate#define _SYSNAM(x)	$(SYS_ ## x)
710Sstevel@tonic-gate#else
720Sstevel@tonic-gate#define	_SYSNAM(x)	$(SYS_/**/x)
730Sstevel@tonic-gate#endif
740Sstevel@tonic-gate
750Sstevel@tonic-gate#define OSYSTRAP(x)			\
760Sstevel@tonic-gate	movl _SYSNAM(x),%eax		;\
770Sstevel@tonic-gate	int $0x80
780Sstevel@tonic-gate
790Sstevel@tonic-gate#ifdef I686_LIBC
800Sstevel@tonic-gate#define SYSTRAP(x)			\
8111426SRoger.Faulkner@Sun.COM	pushl	%ebx			;\
8211426SRoger.Faulkner@Sun.COM	movl	_SYSNAM(x),%eax		;\
8311426SRoger.Faulkner@Sun.COM	movl	$123f,%edx		;\
8411426SRoger.Faulkner@Sun.COM	movl	%esp,%ecx		;\
8511426SRoger.Faulkner@Sun.COM	sysenter			;\
8611426SRoger.Faulkner@Sun.COM123:	movl	%ebx,%edx		;\
8711426SRoger.Faulkner@Sun.COM	popl	%ebx
880Sstevel@tonic-gate#else	/* I686_LIBC */
8911426SRoger.Faulkner@Sun.COM#define SYSTRAP(x)	OSYSTRAP(x)
900Sstevel@tonic-gate#endif	/* I686_LIBC */
9111426SRoger.Faulkner@Sun.COM
920Sstevel@tonic-gate#ifdef __ELF__
930Sstevel@tonic-gate#define CERROR		_C_LABEL(__cerror)
94#define CURBRK		_C_LABEL(__curbrk)
95#else
96#define CERROR		_ASM_LABEL(cerror)
97#define CURBRK		_ASM_LABEL(curbrk)
98#endif
99
100#define _SYSCALL_NOERROR(x,y)						\
101	ENTRY(x);							\
102	SYSTRAP(y)
103
104#ifdef PIC
105#define _SYSCALL_ERR							\
106	PIC_PROLOGUE;							\
107	mov PIC_GOT(CERROR), %ecx;					\
108	PIC_EPILOGUE;							\
109	jmp *%ecx
110#else
111#define _SYSCALL_ERR							\
112	jmp CERROR
113#endif
114
115#define _SYSCALL(x,y)							\
116	.text; _ALIGN_TEXT;						\
117	2: _SYSCALL_ERR;						\
118	_SYSCALL_NOERROR(x,y);						\
119	jc 2b
120
121#define SYSCALL_NOERROR(x)						\
122	_SYSCALL_NOERROR(x,x)
123
124#define SYSCALL(x)							\
125	_SYSCALL(x,x)
126
127#define PSEUDO_NOERROR(x,y)						\
128	_SYSCALL_NOERROR(x,y);						\
129	ret
130
131#define PSEUDO(x,y)							\
132	_SYSCALL_NOERROR(x,y);						\
133	jc 2f;								\
134	ret;								\
135	2: _SYSCALL_ERR
136
137#define RSYSCALL_NOERROR(x)						\
138	PSEUDO_NOERROR(x,x)
139
140#define RSYSCALL(x)							\
141	PSEUDO(x,x)
142
143#ifdef WEAK_ALIAS
144#define	WSYSCALL(weak,strong)						\
145	WEAK_ALIAS(weak,strong);					\
146	PSEUDO(strong,weak)
147#else
148#define	WSYSCALL(weak,strong)						\
149	PSEUDO(weak,weak)
150#endif
151
152	.globl	CERROR
153