1 /* $OpenBSD: SYS.h,v 1.11 2016/05/18 20:21:13 guenther Exp $ */ 2 /*- 3 * Copyright (c) 1990 The Regents of the University of California. 4 * All rights reserved. 5 * 6 * This code is derived from software contributed to Berkeley by 7 * William Jolitz. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. Neither the name of the University nor the names of its contributors 18 * may be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * from: @(#)SYS.h 5.5 (Berkeley) 5/7/91 34 * $NetBSD: SYS.h,v 1.9 2006/01/06 06:19:20 uwe Exp $ 35 */ 36 37 #include <machine/asm.h> 38 #include <sys/syscall.h> 39 40 41 /* 42 * We need to offset the TCB pointer (in register gbr) by this much: 43 * offsetof(struct tib, tib_errno) - offsetof(struct tib, __tib_tcb) 44 * That's negative on a variant I arch like sh, but you can't directly 45 * load negative numbers or use them as displacements. Ha! So this is the 46 * negative of the real value and we'll explicitly subtract it in the asm 47 */ 48 #define TCB_OFFSET_ERRNO_NEG 8 49 50 /* 51 * We define a hidden alias with the prefix "_libc_" for each global symbol 52 * that may be used internally. By referencing _libc_x instead of x, other 53 * parts of libc prevent overriding by the application and avoid unnecessary 54 * relocations. 55 */ 56 #define _HIDDEN(x) _libc_##x 57 #define _HIDDEN_ALIAS(x,y) \ 58 STRONG_ALIAS(_HIDDEN(x),y); \ 59 .hidden _HIDDEN(x) 60 #define _HIDDEN_FALIAS(x,y) \ 61 _HIDDEN_ALIAS(x,y); \ 62 .type _HIDDEN(x),@function 63 64 /* 65 * For functions implemented in ASM that aren't syscalls. 66 * END_STRONG(x) Like DEF_STRONG() in C; for standard/reserved C names 67 * END_WEAK(x) Like DEF_WEAK() in C; for non-ISO C names 68 */ 69 #define END_STRONG(x) SET_ENTRY_SIZE(x); \ 70 _HIDDEN_FALIAS(x,x); \ 71 SET_ENTRY_SIZE(_HIDDEN(x)) 72 #define END_WEAK(x) END_STRONG(x); .weak x 73 74 75 #define SYSENTRY(x) \ 76 WEAK_ALIAS(x,_thread_sys_ ## x); \ 77 ENTRY(_thread_sys_ ## x) 78 #define SYSENTRY_HIDDEN(x) \ 79 ENTRY(_thread_sys_ ## x) 80 81 #define __END_HIDDEN(x) \ 82 SET_ENTRY_SIZE(_thread_sys_ ## x); \ 83 _HIDDEN_FALIAS(x,_thread_sys_ ## x); \ 84 SET_ENTRY_SIZE(_HIDDEN(x)) 85 #define __END(x) \ 86 __END_HIDDEN(x); SET_ENTRY_SIZE(x) 87 88 #define SYSTRAP(x) \ 89 mov.l 903f, r0; \ 90 .word 0xc380; /* trapa #0x80; */ \ 91 bra 904f; \ 92 nop; \ 93 .align 2; \ 94 903: .long (SYS_ ## x); \ 95 904: 96 97 #define _SYSCALL_NOERROR(x,y) \ 98 SYSENTRY(x); \ 99 SYSTRAP(y) 100 #define _SYSCALL_HIDDEN_NOERROR(x,y) \ 101 SYSENTRY_HIDDEN(x); \ 102 SYSTRAP(y) 103 104 #define SET_ERRNO_AND_RETURN \ 105 stc gbr,r1; \ 106 mov #TCB_OFFSET_ERRNO_NEG,r2; \ 107 sub r2,r1; \ 108 mov.l r0,@r1; \ 109 mov #-1, r1; \ 110 rts; \ 111 mov #-1, r0 112 113 #define _SYSCALL(x,y) \ 114 .text; \ 115 911: SET_ERRNO_AND_RETURN; \ 116 _SYSCALL_NOERROR(x,y); \ 117 bf 911b 118 #define _SYSCALL_HIDDEN(x,y) \ 119 .text; \ 120 911: SET_ERRNO_AND_RETURN; \ 121 _SYSCALL_HIDDEN_NOERROR(x,y); \ 122 bf 911b 123 124 #define SYSCALL_NOERROR(x) \ 125 _SYSCALL_NOERROR(x,x) 126 127 #define SYSCALL(x) \ 128 _SYSCALL(x,x) 129 130 #define PSEUDO_NOERROR(x,y) \ 131 _SYSCALL_NOERROR(x,y); \ 132 rts; \ 133 nop; \ 134 __END(x) 135 136 #define PSEUDO(x,y) \ 137 _SYSCALL(x,y); \ 138 rts; \ 139 nop; \ 140 __END(x) 141 142 #define PSEUDO_HIDDEN(x,y) \ 143 _SYSCALL_HIDDEN(x,y); \ 144 rts; \ 145 nop; \ 146 __END_HIDDEN(x) 147 148 #define RSYSCALL_NOERROR(x) PSEUDO_NOERROR(x,x) 149 #define RSYSCALL(x) PSEUDO(x,x) 150 #define RSYSCALL_HIDDEN(x) PSEUDO_HIDDEN(x,x) 151 #define SYSCALL_END(x) __END(x) 152 #define SYSCALL_END_HIDDEN(x) __END_HIDDEN(x) 153