1*29295d1cSmillert /* $OpenBSD: SYS.h,v 1.3 2003/06/02 23:28:09 millert Exp $ */ 2469c1a52Sjason /* $NetBSD: SYS.h,v 1.2 1999/02/15 04:54:36 hubertf Exp $ */ 3469c1a52Sjason /*- 4469c1a52Sjason * Copyright (c) 1992, 1993 5469c1a52Sjason * The Regents of the University of California. All rights reserved. 6469c1a52Sjason * 7469c1a52Sjason * This software was developed by the Computer Systems Engineering group 8469c1a52Sjason * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 9469c1a52Sjason * contributed to Berkeley. 10469c1a52Sjason * 11469c1a52Sjason * Redistribution and use in source and binary forms, with or without 12469c1a52Sjason * modification, are permitted provided that the following conditions 13469c1a52Sjason * are met: 14469c1a52Sjason * 1. Redistributions of source code must retain the above copyright 15469c1a52Sjason * notice, this list of conditions and the following disclaimer. 16469c1a52Sjason * 2. Redistributions in binary form must reproduce the above copyright 17469c1a52Sjason * notice, this list of conditions and the following disclaimer in the 18469c1a52Sjason * documentation and/or other materials provided with the distribution. 19*29295d1cSmillert * 3. Neither the name of the University nor the names of its contributors 20469c1a52Sjason * may be used to endorse or promote products derived from this software 21469c1a52Sjason * without specific prior written permission. 22469c1a52Sjason * 23469c1a52Sjason * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24469c1a52Sjason * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25469c1a52Sjason * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26469c1a52Sjason * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27469c1a52Sjason * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28469c1a52Sjason * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29469c1a52Sjason * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30469c1a52Sjason * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31469c1a52Sjason * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32469c1a52Sjason * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33469c1a52Sjason * SUCH DAMAGE. 34469c1a52Sjason * 35469c1a52Sjason * @(#)SYS.h 8.1 (Berkeley) 6/4/93 36469c1a52Sjason * 37469c1a52Sjason * from: Header: SYS.h,v 1.2 92/07/03 18:57:00 torek Exp 38*29295d1cSmillert * $Id: SYS.h,v 1.3 2003/06/02 23:28:09 millert Exp $ 39469c1a52Sjason */ 40469c1a52Sjason 41469c1a52Sjason #include <machine/asm.h> 42469c1a52Sjason #include <sys/syscall.h> 43469c1a52Sjason #include <machine/trap.h> 44469c1a52Sjason 45469c1a52Sjason #ifdef __STDC__ 46469c1a52Sjason #define _CAT(x,y) x##y 47469c1a52Sjason #else 48469c1a52Sjason #define _CAT(x,y) x/**/y 49469c1a52Sjason #endif 50469c1a52Sjason 51469c1a52Sjason /* 52469c1a52Sjason * ERROR branches to cerror. This is done with a macro so that I can 53469c1a52Sjason * change it to be position independent later, if need be. 54469c1a52Sjason */ 55469c1a52Sjason #ifdef PIC 56469c1a52Sjason #define ERROR() \ 57469c1a52Sjason PIC_PROLOGUE(%g1,%g2); \ 58469c1a52Sjason ld [%g1+cerror],%g2; jmp %g2; nop 59469c1a52Sjason #else 60469c1a52Sjason #define ERROR() \ 61469c1a52Sjason sethi %hi(cerror),%g1; or %lo(cerror),%g1,%g1; jmp %g1; nop 62469c1a52Sjason #endif 63469c1a52Sjason 64469c1a52Sjason /* 65469c1a52Sjason * SYSCALL is used when further action must be taken before returning. 66469c1a52Sjason * Note that it adds a `nop' over what we could do, if we only knew what 67469c1a52Sjason * came at label 1.... 68469c1a52Sjason */ 69469c1a52Sjason #define SYSCALL(x) \ 70469c1a52Sjason ENTRY(x); mov _CAT(SYS_,x),%g1; t ST_SYSCALL; bcc 1f; nop; ERROR(); 1: 71469c1a52Sjason 72469c1a52Sjason /* 73469c1a52Sjason * RSYSCALL is used when the system call should just return. Here 74469c1a52Sjason * we use the SYSCALL_G2RFLAG to put the `success' return address in %g2 75469c1a52Sjason * and avoid a branch. 76469c1a52Sjason */ 77469c1a52Sjason #define RSYSCALL(x) \ 78469c1a52Sjason ENTRY(x); mov (_CAT(SYS_,x))|SYSCALL_G2RFLAG,%g1; add %o7,8,%g2; \ 79469c1a52Sjason t ST_SYSCALL; ERROR() 80469c1a52Sjason 81469c1a52Sjason /* 82469c1a52Sjason * PSEUDO(x,y) is like RSYSCALL(y) except that the name is x. 83469c1a52Sjason */ 84469c1a52Sjason #define PSEUDO(x,y) \ 85469c1a52Sjason ENTRY(x); mov (_CAT(SYS_,y))|SYSCALL_G2RFLAG,%g1; add %o7,8,%g2; \ 86469c1a52Sjason t ST_SYSCALL; ERROR() 87469c1a52Sjason 88469c1a52Sjason /* 89469c1a52Sjason * SYSCALL_NOERROR is like SYSCALL, except it's used for syscalls 90469c1a52Sjason * that never fail. 91469c1a52Sjason * 92469c1a52Sjason * XXX - This should be optimized. 93469c1a52Sjason */ 94469c1a52Sjason #define SYSCALL_NOERROR(x) \ 95469c1a52Sjason ENTRY(x); mov _CAT(SYS_,x),%g1; t ST_SYSCALL 96469c1a52Sjason 97469c1a52Sjason /* 98469c1a52Sjason * RSYSCALL_NOERROR is like RSYSCALL, except it's used for syscalls 99469c1a52Sjason * that never fail. 100469c1a52Sjason * 101469c1a52Sjason * XXX - This should be optimized. 102469c1a52Sjason */ 103469c1a52Sjason #define RSYSCALL_NOERROR(x) \ 104469c1a52Sjason ENTRY(x); mov (_CAT(SYS_,x))|SYSCALL_G2RFLAG,%g1; add %o7,8,%g2; \ 105469c1a52Sjason t ST_SYSCALL 106469c1a52Sjason 107469c1a52Sjason .globl cerror 108