1 /* $OpenBSD: SYS.h,v 1.23 2016/06/16 03:21:09 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 * the Systems Programming Group of the University of Utah Computer 8 * Science Department. 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 * from: @(#)SYS.h 5.5 (Berkeley) 5/7/91 35 */ 36 37 #include <sys/syscall.h> 38 #include <machine/asm.h> 39 40 /* 41 * We define a hidden alias with the prefix "_libc_" for each global symbol 42 * that may be used internally. By referencing _libc_x instead of x, other 43 * parts of libc prevent overriding by the application and avoid unnecessary 44 * relocations. 45 */ 46 #define _HIDDEN(x) _libc_##x 47 #define _HIDDEN_ALIAS(x,y) \ 48 STRONG_ALIAS(_HIDDEN(x),y); \ 49 .hidden _HIDDEN(x) 50 #define _HIDDEN_FALIAS(x,y) \ 51 _HIDDEN_ALIAS(x,y); \ 52 .type _HIDDEN(x),@function 53 54 /* 55 * For functions implemented in ASM that aren't syscalls. 56 * END_STRONG(x) Like DEF_STRONG() in C; for standard/reserved C names 57 * END_WEAK(x) Like DEF_WEAK() in C; for non-ISO C names 58 */ 59 #define END_STRONG(x) END(x); _HIDDEN_FALIAS(x,x); END(_HIDDEN(x)) 60 #define END_WEAK(x) END_STRONG(x); .weak x 61 62 63 #define __CONCAT(p,x) p##x 64 #define __ENTRY(p,x) ENTRY(__CONCAT(p,x)) 65 #define __END(p,x) END(__CONCAT(p,x)); \ 66 _HIDDEN_ALIAS(x,__CONCAT(p,x)); \ 67 END(_HIDDEN(x)) 68 #define __SYSCALLNAME(p,x) __CONCAT(p,x) 69 #define __ALIAS(prefix,name) WEAK_ALIAS(name,__CONCAT(prefix,name)) 70 71 #ifdef __PIC__ 72 #define CERROR __cerror#plt 73 #define PIC_SAVE(reg) or reg, %r25, %r0 74 #define PIC_RESTORE(reg) or %r25, reg, %r0 75 #define PIC_SETUP \ 76 or %r11, %r0, %r1; \ 77 or.u %r25, %r0, %hi16(.Lpic#abdiff); \ 78 bsr.n .Lpic; \ 79 or %r25, %r25, %lo16(.Lpic#abdiff); \ 80 .Lpic: add %r25, %r25, %r1; \ 81 or %r1, %r0, %r11 82 #if __PIC__ > 1 83 #define PIC_LOAD(reg,sym) \ 84 or.u %r11, %r0, %hi16(__CONCAT(sym,#got_rel)); \ 85 or %r11, %r11, %lo16(__CONCAT(sym,#got_rel)); \ 86 ld reg, %r25, %r11 87 #define PIC_STORE(reg,sym) \ 88 or.u %r11, %r0, %hi16(__CONCAT(sym,#got_rel)); \ 89 or %r11, %r11, %lo16(__CONCAT(sym,#got_rel)); \ 90 st reg, %r25, %r11 91 #else /* -fpic */ 92 #define PIC_LOAD(reg,sym) \ 93 ld %r11, %r25, __CONCAT(sym,#got_rel); \ 94 ld reg, %r11, %r0 95 #define PIC_STORE(reg,sym) \ 96 ld %r11, %r25, __CONCAT(sym,#got_rel); \ 97 st reg, %r11, %r0 98 #endif 99 #else 100 #define CERROR __cerror 101 #endif 102 103 #define __DO_SYSCALL(x) \ 104 or %r13, %r0, __SYSCALLNAME(SYS_,x); \ 105 tb0 0, %r0, 450 106 107 #define __SYSCALL__NOERROR(p,x,y) \ 108 __ENTRY(p,x); \ 109 __ALIAS(p,x); \ 110 __DO_SYSCALL(y) 111 #define __SYSCALL_HIDDEN__NOERROR(p,x,y) \ 112 __ENTRY(p,x); \ 113 __DO_SYSCALL(y) 114 115 #define __SYSCALL(p,x,y) \ 116 __SYSCALL__NOERROR(p,x,y); \ 117 br CERROR 118 #define __SYSCALL_HIDDEN(p,x,y) \ 119 __SYSCALL_HIDDEN__NOERROR(p,x,y); \ 120 br CERROR 121 122 #define __PSEUDO_NOERROR(p,x,y) \ 123 __SYSCALL__NOERROR(p,x,y); \ 124 or %r0, %r0, %r0; \ 125 jmp %r1; \ 126 __END(p,x); END(x) 127 128 #define __PSEUDO(p,x,y) \ 129 __SYSCALL(p,x,y); \ 130 jmp %r1; \ 131 __END(p,x); END(x) 132 #define __PSEUDO_HIDDEN(p,x,y) \ 133 __SYSCALL_HIDDEN(p,x,y); \ 134 jmp %r1; \ 135 __END(p,x) 136 137 /* 138 * System calls entry points are really named _thread_sys_{syscall}, 139 * and weakly aliased to the name {syscall}. This allows the thread 140 * library to replace system calls at link time. 141 */ 142 #define SYSCALL(x) __SYSCALL(_thread_sys_,x,x) 143 #define RSYSCALL(x) __PSEUDO(_thread_sys_,x,x) 144 #define RSYSCALL_HIDDEN(x) __PSEUDO_HIDDEN(_thread_sys_,x,x) 145 #define PSEUDO(x,y) __PSEUDO(_thread_sys_,x,y) 146 #define PSEUDO_NOERROR(x,y) __PSEUDO_NOERROR(_thread_sys_,x,y) 147 #define SYSENTRY_HIDDEN(x) __ENTRY(_thread_sys_,x) 148 #define SYSENTRY(x) SYSENTRY_HIDDEN(x); \ 149 __ALIAS(_thread_sys_,x) 150 #define SYSCALL_END_HIDDEN(x) __END(_thread_sys_,x) 151 #define SYSCALL_END(x) SYSCALL_END_HIDDEN(x); END(x) 152 153 #define ASMSTR .asciz 154 155 .globl __cerror 156