1 /* $OpenBSD: SYS.h,v 1.16 2016/05/07 19:05:22 guenther Exp $ */ 2 /*- 3 * Copyright (c) 1992, 1993 4 * The Regents of the University of California. All rights reserved. 5 * 6 * This software was developed by the Computer Systems Engineering group 7 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 8 * contributed to Berkeley. 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. Neither the name of the University nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * @(#)SYS.h 8.1 (Berkeley) 6/4/93 35 * 36 * from: Header: SYS.h,v 1.2 92/07/03 18:57:00 torek Exp 37 * $NetBSD: SYS.h,v 1.6 2001/07/23 07:26:50 thorpej Exp $ 38 */ 39 40 #include <machine/asm.h> 41 #include <sys/syscall.h> 42 #include <machine/trap.h> 43 44 /* offsetof(struct tib, tib_errno) - offsetof(struct tib, __tib_tcb) */ 45 #define TCB_OFFSET_ERRNO 24 46 47 #define _CAT(x,y) x##y 48 49 #define __ENTRY(p,x) ENTRY(_CAT(p,x)) ; .weak x; x = _CAT(p,x) 50 #define __ENTRY_HIDDEN(p,x) ENTRY(_CAT(p,x)) 51 52 53 /* 54 * We define a hidden alias with the prefix "_libc_" for each global symbol 55 * that may be used internally. By referencing _libc_x instead of x, other 56 * parts of libc prevent overriding by the application and avoid unnecessary 57 * relocations. 58 */ 59 #define _HIDDEN(x) _libc_##x 60 #define _HIDDEN_ALIAS(x,y) \ 61 STRONG_ALIAS(_HIDDEN(x),y); \ 62 .hidden _HIDDEN(x) 63 #define _HIDDEN_FALIAS(x,y) \ 64 _HIDDEN_ALIAS(x,y); \ 65 .type _HIDDEN(x),@function 66 67 /* 68 * For functions implemented in ASM that aren't syscalls. 69 * END_STRONG(x) Like DEF_STRONG() in C; for standard/reserved C names 70 * END_WEAK(x) Like DEF_WEAK() in C; for non-ISO C names 71 */ 72 #define END_STRONG(x) END(x); _HIDDEN_FALIAS(x,x); END(_HIDDEN(x)) 73 #define END_WEAK(x) END_STRONG(x); .weak x 74 75 76 #define __END_HIDDEN(p,x) END(_CAT(p,x)); \ 77 _HIDDEN_FALIAS(x, _CAT(p,x)); \ 78 END(_HIDDEN(x)) 79 #define __END(p,x) __END_HIDDEN(p,x); END(x) 80 81 /* 82 * ERROR sets the thread's errno and returns 83 */ 84 #define ERROR() \ 85 st %o0, [%g7 + TCB_OFFSET_ERRNO]; \ 86 retl; \ 87 mov -1, %o0 88 89 /* 90 * SYSCALL is used when further action must be taken before returning. 91 * Note that it adds a `nop' over what we could do, if we only knew what 92 * came at label 1.... 93 */ 94 #define _SYSCALL(p,x,y) \ 95 __ENTRY(p,x); mov _CAT(SYS_,y),%g1; t ST_SYSCALL; bcc 1f; nop; ERROR(); 1: 96 #define _SYSCALL_HIDDEN(p,x,y) \ 97 __ENTRY_HIDDEN(p,x); mov _CAT(SYS_,y),%g1; t ST_SYSCALL; bcc 1f; nop; ERROR(); 1: 98 99 #define __SYSCALL(p,x) \ 100 _SYSCALL(p,x,x) 101 102 #define __SYSCALL_HIDDEN(p,x) \ 103 _SYSCALL_HIDDEN(p,x,x) 104 105 /* 106 * RSYSCALL is used when the system call should just return. Here 107 * we use the SYSCALL_G2RFLAG to put the `success' return address in %g2 108 * and avoid a branch. 109 */ 110 #define __RSYSCALL(p,x) \ 111 __ENTRY(p,x); mov (_CAT(SYS_,x))|SYSCALL_G2RFLAG,%g1; \ 112 add %o7,8,%g2; t ST_SYSCALL; ERROR(); __END(p,x) 113 #define __RSYSCALL_HIDDEN(p,x) \ 114 __ENTRY_HIDDEN(p,x); mov (_CAT(SYS_,x))|SYSCALL_G2RFLAG,%g1; \ 115 add %o7,8,%g2; t ST_SYSCALL; ERROR(); __END_HIDDEN(p,x) 116 117 /* 118 * PSEUDO(x,y) is like RSYSCALL(y) except that the name is x. 119 */ 120 #define __PSEUDO(p,x,y) \ 121 __ENTRY(p,x); mov (_CAT(SYS_,y))|SYSCALL_G2RFLAG,%g1; add %o7,8,%g2; \ 122 t ST_SYSCALL; ERROR(); __END(p,x) 123 124 /* 125 * SYSCALL_NOERROR is like SYSCALL, except it's used for syscalls 126 * that never fail. 127 * 128 * XXX - This should be optimized. 129 */ 130 #define __SYSCALL_NOERROR(p,x) \ 131 __ENTRY(p,x); mov _CAT(SYS_,x),%g1; t ST_SYSCALL 132 133 /* 134 * RSYSCALL_NOERROR is like RSYSCALL, except it's used for syscalls 135 * that never fail. 136 * 137 * XXX - This should be optimized. 138 */ 139 #define __RSYSCALL_NOERROR(p,x) \ 140 __ENTRY(p,x); mov (_CAT(SYS_,x))|SYSCALL_G2RFLAG,%g1; add %o7,8,%g2; \ 141 t ST_SYSCALL; __END(p,x) 142 143 /* 144 * PSEUDO_NOERROR(x,y) is like RSYSCALL_NOERROR(y) except that the name is x. 145 */ 146 #define __PSEUDO_NOERROR(p,x,y) \ 147 __ENTRY(p,x); mov (_CAT(SYS_,y))|SYSCALL_G2RFLAG,%g1; add %o7,8,%g2; \ 148 t ST_SYSCALL; __END(p,x) 149 150 /* 151 * SYSENTRY is for functions that pretend to be syscalls. 152 */ 153 #define SYSCALL(x) __SYSCALL(_thread_sys_,x) 154 #define RSYSCALL(x) __RSYSCALL(_thread_sys_,x) 155 #define RSYSCALL_HIDDEN(x) __RSYSCALL_HIDDEN(_thread_sys_,x) 156 #define RSYSCALL_NOERROR(x,y) __RSYSCALL_NOERROR(_thread_sys_,x,y) 157 #define PSEUDO(x,y) __PSEUDO(_thread_sys_,x,y) 158 #define PSEUDO_NOERROR(x,y) __PSEUDO_NOERROR(_thread_sys_,x,y) 159 #define SYSENTRY(x) __ENTRY(_thread_sys_,x) 160 #define SYSENTRY_HIDDEN(x) __ENTRY_HIDDEN(_thread_sys_,x) 161 #define SYSCALL_END(x) __END(_thread_sys_,x) 162 #define SYSCALL_END_HIDDEN(x) __END_HIDDEN(_thread_sys_,x) 163