1 /* $OpenBSD: SYS.h,v 1.9 2003/06/02 20:18:32 millert Exp $ */ 2 /*- 3 * Copyright (c) 1992, 1993 4 * The Regents of the University of California. All rights reserved. 5 * 6 * This software was developed by the Computer Systems Engineering group 7 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 8 * contributed to Berkeley. 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 * @(#)SYS.h 8.1 (Berkeley) 6/4/93 35 * 36 * from: Header: SYS.h,v 1.2 92/07/03 18:57:00 torek Exp 37 * $NetBSD: SYS.h,v 1.6 2001/07/23 07:26:50 thorpej Exp $ 38 */ 39 40 #include <machine/asm.h> 41 #include <sys/syscall.h> 42 #include <machine/trap.h> 43 44 #ifdef __STDC__ 45 #define _CAT(x,y) x##y 46 #else 47 #define _CAT(x,y) x/**/y 48 #endif 49 50 #define __ENTRY(p,x) ENTRY(_CAT(p,x)) ; .weak x; x = _CAT(p,x) 51 52 /* 53 * ERROR branches to cerror. This is done with a macro so that I can 54 * change it to be position independent later, if need be. 55 */ 56 #ifdef PIC 57 #define CALL(name) \ 58 PIC_PROLOGUE(%g1,%g2); \ 59 sethi %hi(name),%g2; \ 60 or %g2,%lo(name),%g2; \ 61 ldx [%g1+%g2],%g2; \ 62 jmp %g2; \ 63 nop 64 #else 65 #define CALL(name) \ 66 sethi %hi(name),%g1; or %lo(name),%g1,%g1; \ 67 jmp %g1; nop 68 #endif 69 #define ERROR() CALL(_C_LABEL(__cerror)) 70 71 /* 72 * SYSCALL is used when further action must be taken before returning. 73 * Note that it adds a `nop' over what we could do, if we only knew what 74 * came at label 1.... 75 */ 76 #define _SYSCALL(p,x,y) \ 77 __ENTRY(p,x); mov _CAT(SYS_,y),%g1; t ST_SYSCALL; bcc 1f; nop; ERROR(); 1: 78 79 #define __SYSCALL(p,x) \ 80 _SYSCALL(p,x,x) 81 82 /* 83 * RSYSCALL is used when the system call should just return. Here 84 * we use the SYSCALL_G2RFLAG to put the `success' return address in %g2 85 * and avoid a branch. 86 */ 87 #define __RSYSCALL(p,x) \ 88 __ENTRY(p,x); mov (_CAT(SYS_,x))|SYSCALL_G2RFLAG,%g1; add %o7,8,%g2; \ 89 t ST_SYSCALL; ERROR() 90 91 /* 92 * PSEUDO(x,y) is like RSYSCALL(y) except that the name is x. 93 */ 94 #define __PSEUDO(p,x,y) \ 95 __ENTRY(p,x); mov (_CAT(SYS_,y))|SYSCALL_G2RFLAG,%g1; add %o7,8,%g2; \ 96 t ST_SYSCALL; ERROR() 97 98 /* 99 * SYSCALL_NOERROR is like SYSCALL, except it's used for syscalls 100 * that never fail. 101 * 102 * XXX - This should be optimized. 103 */ 104 #define __SYSCALL_NOERROR(p,x) \ 105 __ENTRY(p,x); mov _CAT(SYS_,x),%g1; t ST_SYSCALL 106 107 /* 108 * RSYSCALL_NOERROR is like RSYSCALL, except it's used for syscalls 109 * that never fail. 110 * 111 * XXX - This should be optimized. 112 */ 113 #define __RSYSCALL_NOERROR(p,x) \ 114 __ENTRY(p,x); mov (_CAT(SYS_,x))|SYSCALL_G2RFLAG,%g1; add %o7,8,%g2; \ 115 t ST_SYSCALL 116 117 /* 118 * PSEUDO_NOERROR(x,y) is like RSYSCALL_NOERROR(y) except that the name is x. 119 */ 120 #define __PSEUDO_NOERROR(p,x,y) \ 121 __ENTRY(p,x); mov (_CAT(SYS_,y))|SYSCALL_G2RFLAG,%g1; add %o7,8,%g2; \ 122 t ST_SYSCALL 123 124 .globl _C_LABEL(__cerror) 125 126 /* 127 * SYSENTRY is for functions that pretend to be syscalls. 128 */ 129 #define __SYSENTRY(p,x) __ENTRY(p,x) 130 131 #define SYSCALL(x) __SYSCALL(_thread_sys_,x) 132 #define RSYSCALL(x) __RSYSCALL(_thread_sys_,x) 133 #define RSYSCALL_NOERROR(x,y) __RSYSCALL_NOERROR(_thread_sys_,x,y) 134 #define PSEUDO(x,y) __PSEUDO(_thread_sys_,x,y) 135 #define PSEUDO_NOERROR(x,y) __PSEUDO_NOERROR(_thread_sys_,x,y) 136 #define SYSENTRY(x) __SYSENTRY(_thread_sys_,x) 137