xref: /minix3/lib/libc/arch/x86_64/SYS.h (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
12fe8fb19SBen Gras /*-
22fe8fb19SBen Gras  * Copyright (c) 1990 The Regents of the University of California.
32fe8fb19SBen Gras  * All rights reserved.
42fe8fb19SBen Gras  *
52fe8fb19SBen Gras  * This code is derived from software contributed to Berkeley by
62fe8fb19SBen Gras  * William Jolitz.
72fe8fb19SBen Gras  *
82fe8fb19SBen Gras  * Redistribution and use in source and binary forms, with or without
92fe8fb19SBen Gras  * modification, are permitted provided that the following conditions
102fe8fb19SBen Gras  * are met:
112fe8fb19SBen Gras  * 1. Redistributions of source code must retain the above copyright
122fe8fb19SBen Gras  *    notice, this list of conditions and the following disclaimer.
132fe8fb19SBen Gras  * 2. Redistributions in binary form must reproduce the above copyright
142fe8fb19SBen Gras  *    notice, this list of conditions and the following disclaimer in the
152fe8fb19SBen Gras  *    documentation and/or other materials provided with the distribution.
162fe8fb19SBen Gras  * 3. Neither the name of the University nor the names of its contributors
172fe8fb19SBen Gras  *    may be used to endorse or promote products derived from this software
182fe8fb19SBen Gras  *    without specific prior written permission.
192fe8fb19SBen Gras  *
202fe8fb19SBen Gras  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
212fe8fb19SBen Gras  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
222fe8fb19SBen Gras  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
232fe8fb19SBen Gras  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
242fe8fb19SBen Gras  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
252fe8fb19SBen Gras  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
262fe8fb19SBen Gras  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
272fe8fb19SBen Gras  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
282fe8fb19SBen Gras  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
292fe8fb19SBen Gras  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
302fe8fb19SBen Gras  * SUCH DAMAGE.
312fe8fb19SBen Gras  *
322fe8fb19SBen Gras  *	from: @(#)SYS.h	5.5 (Berkeley) 5/7/91
33*0a6a1f1dSLionel Sambuc  *	$NetBSD: SYS.h,v 1.12 2014/05/22 14:38:38 uebayasi Exp $
342fe8fb19SBen Gras  */
352fe8fb19SBen Gras 
362fe8fb19SBen Gras #include <machine/asm.h>
372fe8fb19SBen Gras #include <sys/syscall.h>
382fe8fb19SBen Gras 
392fe8fb19SBen Gras #ifdef __STDC__
402fe8fb19SBen Gras #define SYSTRAP(x)	movl $(SYS_ ## x),%eax; movq %rcx, %r10; syscall
412fe8fb19SBen Gras #else
422fe8fb19SBen Gras #define SYSTRAP(x)	movl $(SYS_/**/x),%eax; movq %rcx, %r10; syscall
432fe8fb19SBen Gras #endif
442fe8fb19SBen Gras 
452fe8fb19SBen Gras #define CERROR		_C_LABEL(__cerror)
462fe8fb19SBen Gras #define CURBRK		_C_LABEL(__curbrk)
472fe8fb19SBen Gras 
482fe8fb19SBen Gras #define _SYSCALL_NOERROR(x,y)						\
492fe8fb19SBen Gras 	ENTRY(x);							\
502fe8fb19SBen Gras 	SYSTRAP(y)
512fe8fb19SBen Gras 
522fe8fb19SBen Gras #define _SYSCALL_ERR	 						\
532fe8fb19SBen Gras 	jmp CERROR
542fe8fb19SBen Gras 
552fe8fb19SBen Gras #define _SYSCALL(x,y)							\
562fe8fb19SBen Gras 	.text; _ALIGN_TEXT;						\
572fe8fb19SBen Gras 	2: _SYSCALL_ERR;						\
582fe8fb19SBen Gras 	_SYSCALL_NOERROR(x,y);						\
592fe8fb19SBen Gras 	jc 2b
602fe8fb19SBen Gras 
612fe8fb19SBen Gras #define SYSCALL_NOERROR(x)						\
622fe8fb19SBen Gras 	_SYSCALL_NOERROR(x,x)
632fe8fb19SBen Gras 
642fe8fb19SBen Gras #define SYSCALL(x)							\
652fe8fb19SBen Gras 	_SYSCALL(x,x)
662fe8fb19SBen Gras 
672fe8fb19SBen Gras #define PSEUDO_NOERROR(x,y)						\
682fe8fb19SBen Gras 	_SYSCALL_NOERROR(x,y);						\
69*0a6a1f1dSLionel Sambuc 	ret;								\
70*0a6a1f1dSLionel Sambuc 	END(x)
712fe8fb19SBen Gras 
722fe8fb19SBen Gras #define PSEUDO(x,y)							\
732fe8fb19SBen Gras 	_SYSCALL_NOERROR(x,y);						\
742fe8fb19SBen Gras 	jc 2f;								\
752fe8fb19SBen Gras 	ret;								\
76*0a6a1f1dSLionel Sambuc 	2: _SYSCALL_ERR;						\
77*0a6a1f1dSLionel Sambuc 	END(x)
782fe8fb19SBen Gras 
792fe8fb19SBen Gras #define RSYSCALL_NOERROR(x)						\
802fe8fb19SBen Gras 	PSEUDO_NOERROR(x,x)
812fe8fb19SBen Gras 
822fe8fb19SBen Gras #define RSYSCALL(x)							\
832fe8fb19SBen Gras 	PSEUDO(x,x)
842fe8fb19SBen Gras 
852fe8fb19SBen Gras #define	WSYSCALL(weak,strong)						\
862fe8fb19SBen Gras 	WEAK_ALIAS(weak,strong);					\
872fe8fb19SBen Gras 	PSEUDO(strong,weak)
882fe8fb19SBen Gras 
892fe8fb19SBen Gras 	.globl	CERROR
90