1*83762a71Sderaadt /* $OpenBSD: SYS.h,v 1.26 2023/12/10 16:45:51 deraadt Exp $*/ 2443998a4Ssmurph /*- 3443998a4Ssmurph * Copyright (c) 1990 The Regents of the University of California. 4443998a4Ssmurph * All rights reserved. 5443998a4Ssmurph * 6443998a4Ssmurph * This code is derived from software contributed to Berkeley by 7443998a4Ssmurph * the Systems Programming Group of the University of Utah Computer 8443998a4Ssmurph * Science Department. 9443998a4Ssmurph * 10443998a4Ssmurph * Redistribution and use in source and binary forms, with or without 11443998a4Ssmurph * modification, are permitted provided that the following conditions 12443998a4Ssmurph * are met: 13443998a4Ssmurph * 1. Redistributions of source code must retain the above copyright 14443998a4Ssmurph * notice, this list of conditions and the following disclaimer. 15443998a4Ssmurph * 2. Redistributions in binary form must reproduce the above copyright 16443998a4Ssmurph * notice, this list of conditions and the following disclaimer in the 17443998a4Ssmurph * documentation and/or other materials provided with the distribution. 186580fee3Smillert * 3. Neither the name of the University nor the names of its contributors 19443998a4Ssmurph * may be used to endorse or promote products derived from this software 20443998a4Ssmurph * without specific prior written permission. 21443998a4Ssmurph * 22443998a4Ssmurph * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23443998a4Ssmurph * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24443998a4Ssmurph * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25443998a4Ssmurph * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26443998a4Ssmurph * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27443998a4Ssmurph * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28443998a4Ssmurph * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29443998a4Ssmurph * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30443998a4Ssmurph * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31443998a4Ssmurph * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32443998a4Ssmurph * SUCH DAMAGE. 33443998a4Ssmurph * 34443998a4Ssmurph * from: @(#)SYS.h 5.5 (Berkeley) 5/7/91 35443998a4Ssmurph */ 36443998a4Ssmurph 37443998a4Ssmurph #include <sys/syscall.h> 38ed4704d9Sguenther #include "DEFS.h" 399b9d2a55Sguenther 409b9d2a55Sguenther 410c0d3debSmiod #define __CONCAT(p,x) p##x 420c0d3debSmiod #define __ENTRY(p,x) ENTRY(__CONCAT(p,x)) 433f373d41Sguenther #define __END(p,x) END(__CONCAT(p,x)); \ 443f373d41Sguenther _HIDDEN_ALIAS(x,__CONCAT(p,x)); \ 453f373d41Sguenther END(_HIDDEN(x)) 460c0d3debSmiod #define __SYSCALLNAME(p,x) __CONCAT(p,x) 470c0d3debSmiod #define __ALIAS(prefix,name) WEAK_ALIAS(name,__CONCAT(prefix,name)) 480c0d3debSmiod 490c0d3debSmiod #ifdef __PIC__ 500c0d3debSmiod #define PIC_SAVE(reg) or reg, %r25, %r0 510c0d3debSmiod #define PIC_RESTORE(reg) or %r25, reg, %r0 520c0d3debSmiod #define PIC_SETUP \ 530c0d3debSmiod or %r11, %r0, %r1; \ 540c0d3debSmiod or.u %r25, %r0, %hi16(.Lpic#abdiff); \ 550c0d3debSmiod bsr.n .Lpic; \ 560c0d3debSmiod or %r25, %r25, %lo16(.Lpic#abdiff); \ 570c0d3debSmiod .Lpic: add %r25, %r25, %r1; \ 580c0d3debSmiod or %r1, %r0, %r11 590c0d3debSmiod #if __PIC__ > 1 600c0d3debSmiod #define PIC_LOAD(reg,sym) \ 610c0d3debSmiod or.u %r11, %r0, %hi16(__CONCAT(sym,#got_rel)); \ 628e1a0ffeSmiod or %r11, %r11, %lo16(__CONCAT(sym,#got_rel)); \ 630c0d3debSmiod ld reg, %r25, %r11 640c0d3debSmiod #define PIC_STORE(reg,sym) \ 650c0d3debSmiod or.u %r11, %r0, %hi16(__CONCAT(sym,#got_rel)); \ 668e1a0ffeSmiod or %r11, %r11, %lo16(__CONCAT(sym,#got_rel)); \ 670c0d3debSmiod st reg, %r25, %r11 680c0d3debSmiod #else /* -fpic */ 690c0d3debSmiod #define PIC_LOAD(reg,sym) \ 7030cc0b30Smiod ld %r11, %r25, __CONCAT(sym,#got_rel); \ 7130cc0b30Smiod ld reg, %r11, %r0 720c0d3debSmiod #define PIC_STORE(reg,sym) \ 7330cc0b30Smiod ld %r11, %r25, __CONCAT(sym,#got_rel); \ 7430cc0b30Smiod st reg, %r11, %r0 750c0d3debSmiod #endif 76acd0de91Sguenther #define CERROR __cerror#plt 77acd0de91Sguenther #else /* __PIC__ */ 78ed4704d9Sguenther #define CERROR __cerror 79acd0de91Sguenther #endif /* __PIC__ */ 805fb677a1Smillert 818513555cSmiod #define __DO_SYSCALL(x) \ 820b514a07Smiod or %r13, %r0, __SYSCALLNAME(SYS_,x); \ 83*83762a71Sderaadt 97: tb0 0, %r0, 450; \ 84*83762a71Sderaadt PINSYSCALL(__SYSCALLNAME(SYS_,x), 97b) 858513555cSmiod 868513555cSmiod #define __SYSCALL__NOERROR(p,x,y) \ 878513555cSmiod __ENTRY(p,x); \ 888513555cSmiod __ALIAS(p,x); \ 898513555cSmiod __DO_SYSCALL(y) 90514a545fSguenther #define __SYSCALL_HIDDEN__NOERROR(p,x,y) \ 91514a545fSguenther __ENTRY(p,x); \ 92514a545fSguenther __DO_SYSCALL(y) 938513555cSmiod 948513555cSmiod #define __SYSCALL(p,x,y) \ 958513555cSmiod __SYSCALL__NOERROR(p,x,y); \ 960c0d3debSmiod br CERROR 97514a545fSguenther #define __SYSCALL_HIDDEN(p,x,y) \ 98514a545fSguenther __SYSCALL_HIDDEN__NOERROR(p,x,y); \ 99514a545fSguenther br CERROR 100443998a4Ssmurph 1018513555cSmiod #define __PSEUDO_NOERROR(p,x,y) \ 1028513555cSmiod __SYSCALL__NOERROR(p,x,y); \ 103311b9c6bSguenther or %r0, %r0, %r0; \ 1040c0d3debSmiod jmp %r1; \ 1053f373d41Sguenther __END(p,x); END(x) 1068513555cSmiod 10766c90ecaSmiod #define __PSEUDO(p,x,y) \ 10866c90ecaSmiod __SYSCALL(p,x,y); \ 1090c0d3debSmiod jmp %r1; \ 1103f373d41Sguenther __END(p,x); END(x) 111514a545fSguenther #define __PSEUDO_HIDDEN(p,x,y) \ 112514a545fSguenther __SYSCALL_HIDDEN(p,x,y); \ 113514a545fSguenther jmp %r1; \ 114514a545fSguenther __END(p,x) 1155fb677a1Smillert 11666c90ecaSmiod /* 1178513555cSmiod * System calls entry points are really named _thread_sys_{syscall}, 1188513555cSmiod * and weakly aliased to the name {syscall}. This allows the thread 1198513555cSmiod * library to replace system calls at link time. 12066c90ecaSmiod */ 1218513555cSmiod #define SYSCALL(x) __SYSCALL(_thread_sys_,x,x) 1228513555cSmiod #define RSYSCALL(x) __PSEUDO(_thread_sys_,x,x) 123514a545fSguenther #define RSYSCALL_HIDDEN(x) __PSEUDO_HIDDEN(_thread_sys_,x,x) 1248513555cSmiod #define PSEUDO(x,y) __PSEUDO(_thread_sys_,x,y) 1258513555cSmiod #define PSEUDO_NOERROR(x,y) __PSEUDO_NOERROR(_thread_sys_,x,y) 1265aed4d28Sguenther #define SYSENTRY_HIDDEN(x) __ENTRY(_thread_sys_,x) 1275aed4d28Sguenther #define SYSENTRY(x) SYSENTRY_HIDDEN(x); \ 1288513555cSmiod __ALIAS(_thread_sys_,x) 1295aed4d28Sguenther #define SYSCALL_END_HIDDEN(x) __END(_thread_sys_,x) 1305aed4d28Sguenther #define SYSCALL_END(x) SYSCALL_END_HIDDEN(x); END(x) 1315fb677a1Smillert 132443998a4Ssmurph #define ASMSTR .asciz 133