1 /* $OpenBSD: SYS.h,v 1.26 2023/12/10 16:45:51 deraadt 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 "DEFS.h" 39 40 41 #define __CONCAT(p,x) p##x 42 #define __ENTRY(p,x) ENTRY(__CONCAT(p,x)) 43 #define __END(p,x) END(__CONCAT(p,x)); \ 44 _HIDDEN_ALIAS(x,__CONCAT(p,x)); \ 45 END(_HIDDEN(x)) 46 #define __SYSCALLNAME(p,x) __CONCAT(p,x) 47 #define __ALIAS(prefix,name) WEAK_ALIAS(name,__CONCAT(prefix,name)) 48 49 #ifdef __PIC__ 50 #define PIC_SAVE(reg) or reg, %r25, %r0 51 #define PIC_RESTORE(reg) or %r25, reg, %r0 52 #define PIC_SETUP \ 53 or %r11, %r0, %r1; \ 54 or.u %r25, %r0, %hi16(.Lpic#abdiff); \ 55 bsr.n .Lpic; \ 56 or %r25, %r25, %lo16(.Lpic#abdiff); \ 57 .Lpic: add %r25, %r25, %r1; \ 58 or %r1, %r0, %r11 59 #if __PIC__ > 1 60 #define PIC_LOAD(reg,sym) \ 61 or.u %r11, %r0, %hi16(__CONCAT(sym,#got_rel)); \ 62 or %r11, %r11, %lo16(__CONCAT(sym,#got_rel)); \ 63 ld reg, %r25, %r11 64 #define PIC_STORE(reg,sym) \ 65 or.u %r11, %r0, %hi16(__CONCAT(sym,#got_rel)); \ 66 or %r11, %r11, %lo16(__CONCAT(sym,#got_rel)); \ 67 st reg, %r25, %r11 68 #else /* -fpic */ 69 #define PIC_LOAD(reg,sym) \ 70 ld %r11, %r25, __CONCAT(sym,#got_rel); \ 71 ld reg, %r11, %r0 72 #define PIC_STORE(reg,sym) \ 73 ld %r11, %r25, __CONCAT(sym,#got_rel); \ 74 st reg, %r11, %r0 75 #endif 76 #define CERROR __cerror#plt 77 #else /* __PIC__ */ 78 #define CERROR __cerror 79 #endif /* __PIC__ */ 80 81 #define __DO_SYSCALL(x) \ 82 or %r13, %r0, __SYSCALLNAME(SYS_,x); \ 83 97: tb0 0, %r0, 450; \ 84 PINSYSCALL(__SYSCALLNAME(SYS_,x), 97b) 85 86 #define __SYSCALL__NOERROR(p,x,y) \ 87 __ENTRY(p,x); \ 88 __ALIAS(p,x); \ 89 __DO_SYSCALL(y) 90 #define __SYSCALL_HIDDEN__NOERROR(p,x,y) \ 91 __ENTRY(p,x); \ 92 __DO_SYSCALL(y) 93 94 #define __SYSCALL(p,x,y) \ 95 __SYSCALL__NOERROR(p,x,y); \ 96 br CERROR 97 #define __SYSCALL_HIDDEN(p,x,y) \ 98 __SYSCALL_HIDDEN__NOERROR(p,x,y); \ 99 br CERROR 100 101 #define __PSEUDO_NOERROR(p,x,y) \ 102 __SYSCALL__NOERROR(p,x,y); \ 103 or %r0, %r0, %r0; \ 104 jmp %r1; \ 105 __END(p,x); END(x) 106 107 #define __PSEUDO(p,x,y) \ 108 __SYSCALL(p,x,y); \ 109 jmp %r1; \ 110 __END(p,x); END(x) 111 #define __PSEUDO_HIDDEN(p,x,y) \ 112 __SYSCALL_HIDDEN(p,x,y); \ 113 jmp %r1; \ 114 __END(p,x) 115 116 /* 117 * System calls entry points are really named _thread_sys_{syscall}, 118 * and weakly aliased to the name {syscall}. This allows the thread 119 * library to replace system calls at link time. 120 */ 121 #define SYSCALL(x) __SYSCALL(_thread_sys_,x,x) 122 #define RSYSCALL(x) __PSEUDO(_thread_sys_,x,x) 123 #define RSYSCALL_HIDDEN(x) __PSEUDO_HIDDEN(_thread_sys_,x,x) 124 #define PSEUDO(x,y) __PSEUDO(_thread_sys_,x,y) 125 #define PSEUDO_NOERROR(x,y) __PSEUDO_NOERROR(_thread_sys_,x,y) 126 #define SYSENTRY_HIDDEN(x) __ENTRY(_thread_sys_,x) 127 #define SYSENTRY(x) SYSENTRY_HIDDEN(x); \ 128 __ALIAS(_thread_sys_,x) 129 #define SYSCALL_END_HIDDEN(x) __END(_thread_sys_,x) 130 #define SYSCALL_END(x) SYSCALL_END_HIDDEN(x); END(x) 131 132 #define ASMSTR .asciz 133