Initial import from FreeBSD RELENG_4:
[dragonfly.git] / lib / libc / alpha / SYS.h
1 /* $FreeBSD: src/lib/libc/alpha/SYS.h,v 1.11.2.2 2002/10/15 19:46:45 fjoe Exp $ */
2 /*      From: NetBSD: SYS.h,v 1.5 1997/05/02 18:15:15 kleink Exp */
3
4 /*
5  * Copyright (c) 1994, 1995 Carnegie-Mellon University.
6  * All rights reserved.
7  *
8  * Author: Chris G. Demetriou
9  * 
10  * Permission to use, copy, modify and distribute this software and
11  * its documentation is hereby granted, provided that both the copyright
12  * notice and this permission notice appear in all copies of the
13  * software, derivative works or modified versions, and any portions
14  * thereof, and that both notices appear in supporting documentation.
15  * 
16  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 
17  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 
18  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
19  * 
20  * Carnegie Mellon requests users of this software to return to
21  *
22  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
23  *  School of Computer Science
24  *  Carnegie Mellon University
25  *  Pittsburgh PA 15213-3890
26  *
27  * any improvements or extensions that they make and grant Carnegie the
28  * rights to redistribute these changes.
29  */
30
31 #include <machine/asm.h>
32 #ifdef __NETBSD_SYSCALLS
33 #include <sys/netbsd_syscall.h>
34 #else
35 #include <sys/syscall.h>
36 #endif
37
38 #define CALLSYS_ERROR(name)                                     \
39         CALLSYS_NOERROR(name);                                  \
40         br      gp, LLABEL(name,0);                             \
41 LLABEL(name,0):                                                 \
42         LDGP(gp);                                               \
43         beq     a3, LLABEL(name,1);                             \
44         jmp     zero, .cerror;                                  \
45 LLABEL(name,1):
46
47
48 #define SYSCALL(name)                                           \
49 LEAF(__CONCAT(_,name),0);               /* XXX # of args? */    \
50         WEAK_ALIAS(name, __CONCAT(_,name));                     \
51         CALLSYS_ERROR(name)
52
53 #define SYSCALL_NOERROR(name)                                   \
54 LEAF(name,0);                           /* XXX # of args? */    \
55         CALLSYS_NOERROR(name)
56
57
58 #define RSYSCALL(name)                                          \
59         SYSCALL(name);                                          \
60         RET;                                                    \
61 END(__CONCAT(_,name))
62
63 #define RSYSCALL_NOERROR(name)                                  \
64         SYSCALL_NOERROR(name);                                  \
65         RET;                                                    \
66 END(name)
67
68
69 #define PSEUDO(label,name)                                      \
70 LEAF(__CONCAT(_,label),0);              /* XXX # of args? */    \
71         WEAK_ALIAS(label, __CONCAT(_,label));                   \
72         CALLSYS_ERROR(name);                                    \
73         RET;                                                    \
74 END(__CONCAT(_,label));
75
76 #define PSEUDO_NOERROR(label,name)                              \
77 LEAF(label,0);                          /* XXX # of args? */    \
78         CALLSYS_NOERROR(name);                                  \
79         RET;                                                    \
80 END(label);
81
82 /*
83  * Design note:
84  *
85  * The macros PSYSCALL() and PRSYSCALL() are intended for use where a
86  * syscall needs to be renamed in the threaded library. When building
87  * a normal library, they default to the traditional SYSCALL() and
88  * RSYSCALL(). This avoids the need to #ifdef _THREAD_SAFE everywhere
89  * that the renamed function needs to be called.
90  */
91 #ifdef _THREAD_SAFE
92 /*
93  * For the thread_safe versions, we prepend __sys_ to the function
94  * name so that the 'C' wrapper can go around the real name.
95  */
96 #define PCALL(name)                                             \
97         CALL(___CONCAT(__sys_,name))
98
99 #define PLEAF(name, args)                                       \
100 LEAF(___CONCAT(__sys_,name),args)
101
102 #define PEND(name)                                              \
103 END(___CONCAT(__sys_,name))
104
105 #define PSYSCALL(name)                                          \
106 PLEAF(name,0);                          /* XXX # of args? */    \
107         CALLSYS_ERROR(name)
108
109 #define PRSYSCALL(name)                                         \
110 PLEAF(name,0);                          /* XXX # of args? */    \
111         CALLSYS_ERROR(name)                                     \
112         RET;                                                    \
113 PEND(name)
114
115 #define PPSEUDO(label,name)                                     \
116 PLEAF(label,0);                         /* XXX # of args? */    \
117         CALLSYS_ERROR(name);                                    \
118         RET;                                                    \
119 PEND(label)
120
121 #else
122 /*
123  * The non-threaded library defaults to traditional syscalls where
124  * the function name matches the syscall name.
125  */
126 #define PSYSCALL(x)     SYSCALL(x)
127 #define PRSYSCALL(x)    RSYSCALL(x)
128 #define PPSEUDO(x,y)    PSEUDO(x,y)
129 #define PLEAF(x,y)      LEAF(x,y)
130 #define PEND(x)         END(x)
131 #define PCALL(x)        CALL(x)
132 #endif