1*83762a71Sderaadt /* $OpenBSD: SYS.h,v 1.28 2023/12/10 16:45:51 deraadt Exp $ */ 2a4afd6daSrahnds /*- 3a4afd6daSrahnds * Copyright (c) 1994 4a4afd6daSrahnds * Andrew Cagney. All rights reserved. 5a4afd6daSrahnds * 6a4afd6daSrahnds * This code is derived from software contributed to Berkeley by 7a4afd6daSrahnds * Ralph Campbell. 8a4afd6daSrahnds * 9a4afd6daSrahnds * Redistribution and use in source and binary forms, with or without 10a4afd6daSrahnds * modification, are permitted provided that the following conditions 11a4afd6daSrahnds * are met: 12a4afd6daSrahnds * 1. Redistributions of source code must retain the above copyright 13a4afd6daSrahnds * notice, this list of conditions and the following disclaimer. 14a4afd6daSrahnds * 2. Redistributions in binary form must reproduce the above copyright 15a4afd6daSrahnds * notice, this list of conditions and the following disclaimer in the 16a4afd6daSrahnds * documentation and/or other materials provided with the distribution. 17a4afd6daSrahnds * 3. All advertising materials mentioning features or use of this software 18a4afd6daSrahnds * must display the following acknowledgement: 19a4afd6daSrahnds * This product includes software developed by the University of 20a4afd6daSrahnds * California, Berkeley and its contributors. 21a4afd6daSrahnds * 4. Neither the name of the University nor the names of its contributors 22a4afd6daSrahnds * may be used to endorse or promote products derived from this software 23a4afd6daSrahnds * without specific prior written permission. 24a4afd6daSrahnds * 25a4afd6daSrahnds * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 26a4afd6daSrahnds * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27a4afd6daSrahnds * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28a4afd6daSrahnds * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 29a4afd6daSrahnds * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30a4afd6daSrahnds * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31a4afd6daSrahnds * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32a4afd6daSrahnds * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33a4afd6daSrahnds * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34a4afd6daSrahnds * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35a4afd6daSrahnds * SUCH DAMAGE. 36a4afd6daSrahnds * 37a4afd6daSrahnds * from: @(#)SYS.h 8.1 (Berkeley) 6/4/93 38a4afd6daSrahnds */ 39a4afd6daSrahnds 40a4afd6daSrahnds #include <sys/syscall.h> 41a4afd6daSrahnds 42a4afd6daSrahnds /* r0 will be a non zero errno if there was an error, while r3/r4 will 43a4afd6daSrahnds contain the return value */ 44a4afd6daSrahnds 450be5e928Sguenther #include "DEFS.h" 46a4afd6daSrahnds 475e1df623Sguenther 485e1df623Sguenther /* offsetof(struct tib, tib_errno) - offsetof(struct tib, __tib_tcb) */ 495e1df623Sguenther #define TCB_OFFSET_ERRNO (-8) 505e1df623Sguenther /* from <powerpc/tcb.h>: TCB address == %r2 - TCB_OFFSET */ 515e1df623Sguenther #define TCB_OFFSET 0x7000 525e1df623Sguenther 535e1df623Sguenther /* offset of errno from %r2 */ 545e1df623Sguenther #define R2_OFFSET_ERRNO (-TCB_OFFSET + TCB_OFFSET_ERRNO) 555e1df623Sguenther 56d2c5a474Sgkoehler #define SYSENTRY(x) WEAK_ALIAS(x, _thread_sys_ ## x); \ 57d2c5a474Sgkoehler ENTRY(_thread_sys_ ## x) 58d2c5a474Sgkoehler #define SYSENTRY_HIDDEN(x) ENTRY(_thread_sys_ ## x) 59d2c5a474Sgkoehler #define __END_HIDDEN(x) END(_thread_sys_ ## x); \ 60d2c5a474Sgkoehler _HIDDEN_FALIAS(x, _thread_sys_ ## x); \ 61aa797096Sguenther END(_HIDDEN(x)) 62d2c5a474Sgkoehler #define __END(x) __END_HIDDEN(x); END(x) 63aa797096Sguenther 64d2c5a474Sgkoehler #define PSEUDO_NOERROR(x,y) SYSENTRY(x) \ 6515572fcfSgkoehler RETGUARD_SETUP(x, %r11, %r12); \ 66d2c5a474Sgkoehler li %r0, SYS_ ## y ; \ 67*83762a71Sderaadt 97: sc; \ 68*83762a71Sderaadt PINSYSCALL(SYS_ ## y, 97b); \ 6915572fcfSgkoehler RETGUARD_CHECK(x, %r11, %r12); \ 70d2c5a474Sgkoehler blr; \ 71d2c5a474Sgkoehler __END(x) 72ba8732b6Smillert 73d2c5a474Sgkoehler #define PSEUDO_HIDDEN(x,y) SYSENTRY_HIDDEN(x) \ 7415572fcfSgkoehler RETGUARD_SETUP(x, %r11, %r12); \ 75d2c5a474Sgkoehler li %r0, SYS_ ## y; \ 76*83762a71Sderaadt 97: sc; \ 77*83762a71Sderaadt PINSYSCALL(SYS_ ## y, 97b); \ 78d2c5a474Sgkoehler cmpwi %r0, 0; \ 79d2c5a474Sgkoehler beq+ .L_ret; \ 80d2c5a474Sgkoehler stw %r0, R2_OFFSET_ERRNO(2); \ 81d2c5a474Sgkoehler li %r3, -1; \ 824c4efc0aSguenther li %r4, -1; /* for lseek */ \ 83d2c5a474Sgkoehler .L_ret: \ 8415572fcfSgkoehler RETGUARD_CHECK(x, %r11, %r12); \ 85d2c5a474Sgkoehler blr; \ 86d2c5a474Sgkoehler __END_HIDDEN(x) 87d2c5a474Sgkoehler 88d2c5a474Sgkoehler #define PSEUDO(x,y) WEAK_ALIAS(x, _thread_sys_ ## x); \ 89aa797096Sguenther PSEUDO_HIDDEN(x,y); \ 90b21062f5Sguenther END(x) 912eeeda66Srahnds 922eeeda66Srahnds #define RSYSCALL(x) PSEUDO(x,x) 93514a545fSguenther #define RSYSCALL_HIDDEN(x) PSEUDO_HIDDEN(x,x) 94d2c5a474Sgkoehler #define SYSCALL_END_HIDDEN(x) __END_HIDDEN(x) 95d2c5a474Sgkoehler #define SYSCALL_END(x) __END(x) 96aa797096Sguenther 97