]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - lib/libc/mips/SYS.h
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / lib / libc / mips / SYS.h
1 /*      $NetBSD: SYS.h,v 1.18 2003/10/29 12:28:33 pooka Exp $ */
2 /* $FreeBSD$ */
3
4 /*-
5  * Copyright (c) 1996 Jonathan Stone
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *      This product includes software developed by Jonathan Stone for
19  *      the NetBSD Project.
20  * 4. The name of the author may not be used to endorse or promote products
21  *    derived from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34
35 /*-
36  * Copyright (c) 1991, 1993
37  *      The Regents of the University of California.  All rights reserved.
38  *
39  * This code is derived from software contributed to Berkeley by
40  * Ralph Campbell.
41  *
42  * Redistribution and use in source and binary forms, with or without
43  * modification, are permitted provided that the following conditions
44  * are met:
45  * 1. Redistributions of source code must retain the above copyright
46  *    notice, this list of conditions and the following disclaimer.
47  * 2. Redistributions in binary form must reproduce the above copyright
48  *    notice, this list of conditions and the following disclaimer in the
49  *    documentation and/or other materials provided with the distribution.
50  * 3. Neither the name of the University nor the names of its contributors
51  *    may be used to endorse or promote products derived from this software
52  *    without specific prior written permission.
53  *
54  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
55  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64  * SUCH DAMAGE.
65  *
66  *      from: @(#)SYS.h 8.1 (Berkeley) 6/4/93
67  */
68
69 #include <sys/syscall.h>
70
71 #include <machine/asm.h>
72
73 /*
74  * If compiling for shared libs, Emit sysV ABI PIC segment pseudo-ops.
75  *
76  * i)  Emit .abicalls before .LEAF entrypoint, and .cpload/.cprestore after.
77  * ii) Do interprocedure jumps indirectly via t9, with the side-effect of
78  *     preserving the callee's entry address in t9.
79  */
80 #ifdef __ABICALLS__
81         .abicalls
82 # define PIC_PROLOGUE(x,sr)     .set noreorder; .cpload sr; .set reorder
83 # define PIC_CALL(l,sr)         la sr, _C_LABEL(l); jr sr
84 #else
85 # define PIC_PROLOGUE(x,sr)
86 # define PIC_CALL(l,sr)         j  _C_LABEL(l)
87 #endif
88
89 # define SYSTRAP(x)     li v0, SYS_ ## x; syscall;
90
91 /*
92  * Do a syscall that cannot fail (sync, get{p,u,g,eu,eg)id)
93  */
94 #define RSYSCALL_NOERROR(x)                                             \
95         PSEUDO_NOERROR(x)
96
97 /*
98  * Do a normal syscall.
99  */
100 #define RSYSCALL(x)                                                     \
101         PSEUDO(x)
102
103 /*
104  * Do a renamed or pseudo syscall (e.g., _exit()), where the entrypoint
105  * and syscall name are not the same.
106  */
107 #define PSEUDO_NOERROR(x)                                               \
108 LEAF(__sys_ ## x);                                                      \
109         .weak _C_LABEL(x);                                              \
110         _C_LABEL(x) = _C_LABEL(__CONCAT(__sys_,x));                     \
111         .weak _C_LABEL(__CONCAT(_,x));                                  \
112         _C_LABEL(__CONCAT(_,x)) = _C_LABEL(__CONCAT(__sys_,x));         \
113         SYSTRAP(x);                                                     \
114         j ra;                                                           \
115         END(__sys_ ## x)
116
117 #define PSEUDO(x)                                                       \
118 LEAF(__sys_ ## x);                                                      \
119         .weak _C_LABEL(x);                                              \
120         _C_LABEL(x) = _C_LABEL(__CONCAT(__sys_,x));                     \
121         .weak _C_LABEL(__CONCAT(_,x));                                  \
122         _C_LABEL(__CONCAT(_,x)) = _C_LABEL(__CONCAT(__sys_,x));         \
123         PIC_PROLOGUE(x,t9);                                             \
124         SYSTRAP(x);                                                     \
125         bne a3,zero,err;                                                \
126         j ra;                                                           \
127 err:                                                                    \
128         PIC_CALL(__cerror,t9);                                          \
129         END(__sys_ ## x)