1 /* $OpenBSD: SYS.h,v 1.11 2014/06/04 20:13:49 matthew 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 #define _CAT(x,y) x##y 45 46 #define __ENTRY(p,x) ENTRY(_CAT(p,x)) ; .weak x; x = _CAT(p,x) 47 48 /* 49 * ERROR branches to cerror. This is done with a macro so that I can 50 * change it to be position independent later, if need be. 51 */ 52 #ifdef __PIC__ 53 #define CALL(name) \ 54 PIC_PROLOGUE(%g1,%g2); \ 55 sethi %hi(name),%g2; \ 56 or %g2,%lo(name),%g2; \ 57 ldx [%g1+%g2],%g2; \ 58 jmp %g2; \ 59 nop 60 #else 61 #define CALL(name) \ 62 sethi %hi(name),%g1; or %lo(name),%g1,%g1; \ 63 jmp %g1; nop 64 #endif 65 #define ERROR() CALL(_C_LABEL(__cerror)) 66 67 /* 68 * SYSCALL is used when further action must be taken before returning. 69 * Note that it adds a `nop' over what we could do, if we only knew what 70 * came at label 1.... 71 */ 72 #define _SYSCALL(p,x,y) \ 73 __ENTRY(p,x); mov _CAT(SYS_,y),%g1; t ST_SYSCALL; bcc 1f; nop; ERROR(); 1: 74 75 #define __SYSCALL(p,x) \ 76 _SYSCALL(p,x,x) 77 78 /* 79 * RSYSCALL is used when the system call should just return. Here 80 * we use the SYSCALL_G2RFLAG to put the `success' return address in %g2 81 * and avoid a branch. 82 */ 83 #define __RSYSCALL(p,x) \ 84 __ENTRY(p,x); mov (_CAT(SYS_,x))|SYSCALL_G2RFLAG,%g1; add %o7,8,%g2; \ 85 t ST_SYSCALL; ERROR() 86 87 /* 88 * PSEUDO(x,y) is like RSYSCALL(y) except that the name is x. 89 */ 90 #define __PSEUDO(p,x,y) \ 91 __ENTRY(p,x); mov (_CAT(SYS_,y))|SYSCALL_G2RFLAG,%g1; add %o7,8,%g2; \ 92 t ST_SYSCALL; ERROR() 93 94 /* 95 * SYSCALL_NOERROR is like SYSCALL, except it's used for syscalls 96 * that never fail. 97 * 98 * XXX - This should be optimized. 99 */ 100 #define __SYSCALL_NOERROR(p,x) \ 101 __ENTRY(p,x); mov _CAT(SYS_,x),%g1; t ST_SYSCALL 102 103 /* 104 * RSYSCALL_NOERROR is like RSYSCALL, except it's used for syscalls 105 * that never fail. 106 * 107 * XXX - This should be optimized. 108 */ 109 #define __RSYSCALL_NOERROR(p,x) \ 110 __ENTRY(p,x); mov (_CAT(SYS_,x))|SYSCALL_G2RFLAG,%g1; add %o7,8,%g2; \ 111 t ST_SYSCALL 112 113 /* 114 * PSEUDO_NOERROR(x,y) is like RSYSCALL_NOERROR(y) except that the name is x. 115 */ 116 #define __PSEUDO_NOERROR(p,x,y) \ 117 __ENTRY(p,x); mov (_CAT(SYS_,y))|SYSCALL_G2RFLAG,%g1; add %o7,8,%g2; \ 118 t ST_SYSCALL 119 120 .globl _C_LABEL(__cerror) 121 122 /* 123 * SYSENTRY is for functions that pretend to be syscalls. 124 */ 125 #define __SYSENTRY(p,x) __ENTRY(p,x) 126 127 #define SYSCALL(x) __SYSCALL(_thread_sys_,x) 128 #define RSYSCALL(x) __RSYSCALL(_thread_sys_,x) 129 #define RSYSCALL_NOERROR(x,y) __RSYSCALL_NOERROR(_thread_sys_,x,y) 130 #define PSEUDO(x,y) __PSEUDO(_thread_sys_,x,y) 131 #define PSEUDO_NOERROR(x,y) __PSEUDO_NOERROR(_thread_sys_,x,y) 132 #define SYSENTRY(x) __SYSENTRY(_thread_sys_,x) 133