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