1*84d9c625SLionel Sambuc /* $NetBSD: SYS.h,v 1.15 2013/09/12 15:36:16 joerg Exp $ */ 22fe8fb19SBen Gras 32fe8fb19SBen Gras /*- 42fe8fb19SBen Gras * Copyright (c) 1992, 1993 52fe8fb19SBen Gras * The Regents of the University of California. All rights reserved. 62fe8fb19SBen Gras * 72fe8fb19SBen Gras * This software was developed by the Computer Systems Engineering group 82fe8fb19SBen Gras * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 92fe8fb19SBen Gras * contributed to Berkeley. 102fe8fb19SBen Gras * 112fe8fb19SBen Gras * Redistribution and use in source and binary forms, with or without 122fe8fb19SBen Gras * modification, are permitted provided that the following conditions 132fe8fb19SBen Gras * are met: 142fe8fb19SBen Gras * 1. Redistributions of source code must retain the above copyright 152fe8fb19SBen Gras * notice, this list of conditions and the following disclaimer. 162fe8fb19SBen Gras * 2. Redistributions in binary form must reproduce the above copyright 172fe8fb19SBen Gras * notice, this list of conditions and the following disclaimer in the 182fe8fb19SBen Gras * documentation and/or other materials provided with the distribution. 192fe8fb19SBen Gras * 3. Neither the name of the University nor the names of its contributors 202fe8fb19SBen Gras * may be used to endorse or promote products derived from this software 212fe8fb19SBen Gras * without specific prior written permission. 222fe8fb19SBen Gras * 232fe8fb19SBen Gras * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 242fe8fb19SBen Gras * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 252fe8fb19SBen Gras * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 262fe8fb19SBen Gras * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 272fe8fb19SBen Gras * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 282fe8fb19SBen Gras * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 292fe8fb19SBen Gras * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 302fe8fb19SBen Gras * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 312fe8fb19SBen Gras * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 322fe8fb19SBen Gras * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 332fe8fb19SBen Gras * SUCH DAMAGE. 342fe8fb19SBen Gras * 352fe8fb19SBen Gras * @(#)SYS.h 8.1 (Berkeley) 6/4/93 362fe8fb19SBen Gras * 372fe8fb19SBen Gras * from: Header: SYS.h,v 1.2 92/07/03 18:57:00 torek Exp 382fe8fb19SBen Gras */ 392fe8fb19SBen Gras 402fe8fb19SBen Gras #include <machine/asm.h> 412fe8fb19SBen Gras #include <sys/syscall.h> 422fe8fb19SBen Gras #include <machine/trap.h> 432fe8fb19SBen Gras 442fe8fb19SBen Gras #ifdef __STDC__ 452fe8fb19SBen Gras #define _CAT(x,y) x##y 462fe8fb19SBen Gras #else 472fe8fb19SBen Gras #define _CAT(x,y) x/**/y 482fe8fb19SBen Gras #endif 492fe8fb19SBen Gras 502fe8fb19SBen Gras /* 512fe8fb19SBen Gras * ERROR branches to cerror. This is done with a macro so that I can 522fe8fb19SBen Gras * change it to be position independent later, if need be. 532fe8fb19SBen Gras */ 54*84d9c625SLionel Sambuc #if __PIC__ - 0 >= 2 552fe8fb19SBen Gras #define JUMP(name) \ 562fe8fb19SBen Gras PIC_PROLOGUE(%g1,%g5); \ 572fe8fb19SBen Gras sethi %hi(_C_LABEL(name)),%g5; \ 582fe8fb19SBen Gras or %g5,%lo(_C_LABEL(name)),%g5; \ 592fe8fb19SBen Gras ldx [%g1+%g5],%g5; \ 602fe8fb19SBen Gras jmp %g5; \ 612fe8fb19SBen Gras nop 62*84d9c625SLionel Sambuc #elif __PIC__ - 0 >= 1 632fe8fb19SBen Gras #define JUMP(name) \ 642fe8fb19SBen Gras PIC_PROLOGUE(%g1,%g5); \ 652fe8fb19SBen Gras ldx [%g1+_C_LABEL(name)],%g5; jmp %g5; nop 662fe8fb19SBen Gras #else 672fe8fb19SBen Gras #define JUMP(name) set _C_LABEL(name),%g1; jmp %g1; nop 682fe8fb19SBen Gras #endif 692fe8fb19SBen Gras #define ERROR() JUMP(__cerror) 702fe8fb19SBen Gras /* 712fe8fb19SBen Gras * SYSCALL is used when further action must be taken before returning. 722fe8fb19SBen Gras * Note that it adds a `nop' over what we could do, if we only knew what 732fe8fb19SBen Gras * came at label 1.... 742fe8fb19SBen Gras */ 752fe8fb19SBen Gras #define _SYSCALL(x,y) \ 762fe8fb19SBen Gras ENTRY(x); mov _CAT(SYS_,y),%g1; t ST_SYSCALL; bcc 1f; nop; ERROR(); 1: 772fe8fb19SBen Gras 782fe8fb19SBen Gras #define SYSCALL(x) \ 792fe8fb19SBen Gras _SYSCALL(x,x) 802fe8fb19SBen Gras 812fe8fb19SBen Gras /* 822fe8fb19SBen Gras * RSYSCALL is used when the system call should just return. Here 83e415d488SLionel Sambuc * we use the SYSCALL_G5RFLAG to put the `success' return address in %g5 842fe8fb19SBen Gras * and avoid a branch. 852fe8fb19SBen Gras */ 862fe8fb19SBen Gras #define RSYSCALL(x) \ 87e415d488SLionel Sambuc ENTRY(x); mov (_CAT(SYS_,x))|SYSCALL_G5RFLAG,%g1; add %o7,8,%g5; \ 882fe8fb19SBen Gras t ST_SYSCALL; ERROR() 892fe8fb19SBen Gras 902fe8fb19SBen Gras /* 912fe8fb19SBen Gras * PSEUDO(x,y) is like RSYSCALL(y) except that the name is x. 922fe8fb19SBen Gras */ 932fe8fb19SBen Gras #define PSEUDO(x,y) \ 94e415d488SLionel Sambuc ENTRY(x); mov (_CAT(SYS_,y))|SYSCALL_G5RFLAG,%g1; add %o7,8,%g5; \ 952fe8fb19SBen Gras t ST_SYSCALL; ERROR() 962fe8fb19SBen Gras 972fe8fb19SBen Gras /* 982fe8fb19SBen Gras * WSYSCALL(weak,strong) is like RSYSCALL(weak), except that weak is 992fe8fb19SBen Gras * a weak internal alias for the strong symbol. 1002fe8fb19SBen Gras */ 1012fe8fb19SBen Gras #define WSYSCALL(weak,strong) \ 1022fe8fb19SBen Gras WEAK_ALIAS(weak,strong); \ 1032fe8fb19SBen Gras PSEUDO(strong,weak) 1042fe8fb19SBen Gras 1052fe8fb19SBen Gras /* 1062fe8fb19SBen Gras * SYSCALL_NOERROR is like SYSCALL, except it's used for syscalls 1072fe8fb19SBen Gras * that never fail. 1082fe8fb19SBen Gras * 1092fe8fb19SBen Gras * XXX - This should be optimized. 1102fe8fb19SBen Gras */ 1112fe8fb19SBen Gras #define SYSCALL_NOERROR(x) \ 1122fe8fb19SBen Gras ENTRY(x); mov _CAT(SYS_,x),%g1; t ST_SYSCALL 1132fe8fb19SBen Gras 1142fe8fb19SBen Gras /* 1152fe8fb19SBen Gras * RSYSCALL_NOERROR is like RSYSCALL, except it's used for syscalls 1162fe8fb19SBen Gras * that never fail. 1172fe8fb19SBen Gras * 1182fe8fb19SBen Gras * XXX - This should be optimized. 1192fe8fb19SBen Gras */ 1202fe8fb19SBen Gras #define RSYSCALL_NOERROR(x) \ 121e415d488SLionel Sambuc ENTRY(x); mov (_CAT(SYS_,x))|SYSCALL_G5RFLAG,%g1; add %o7,8,%g5; \ 1222fe8fb19SBen Gras t ST_SYSCALL 1232fe8fb19SBen Gras 1242fe8fb19SBen Gras /* 1252fe8fb19SBen Gras * PSEUDO_NOERROR(x,y) is like RSYSCALL_NOERROR(y) except that the name is x. 1262fe8fb19SBen Gras */ 1272fe8fb19SBen Gras #define PSEUDO_NOERROR(x,y) \ 128e415d488SLionel Sambuc ENTRY(x); mov (_CAT(SYS_,y))|SYSCALL_G5RFLAG,%g1; add %o7,8,%g5; \ 1292fe8fb19SBen Gras t ST_SYSCALL 1302fe8fb19SBen Gras 1312fe8fb19SBen Gras .globl _C_LABEL(__cerror) 132