1 /*- 2 * Copyright (c) 1992, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This software was developed by the Computer Systems Engineering group 6 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 7 * contributed to Berkeley. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. Neither the name of the University nor the names of its contributors 18 * may be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)SYS.h 8.1 (Berkeley) 6/4/93 34 * 35 * from: Header: SYS.h,v 1.2 92/07/03 18:57:00 torek Exp 36 * $NetBSD: SYS.h,v 1.16 2005/05/20 23:56:15 uwe Exp $ 37 */ 38 39 #include <machine/asm.h> 40 #include <sys/syscall.h> 41 #include <machine/trap.h> 42 43 #ifdef __STDC__ 44 #define _CAT(x,y) x##y 45 #else 46 #define _CAT(x,y) x/**/y 47 #endif 48 49 #ifdef __ELF__ 50 #define CERROR _C_LABEL(__cerror) 51 #define CURBRK _C_LABEL(__curbrk) 52 #else 53 #define CERROR _ASM_LABEL(cerror) 54 #define CURBRK _ASM_LABEL(curbrk) 55 #endif 56 57 /* 58 * ERROR branches to cerror. 59 */ 60 #ifdef PIC 61 #define CALL(name) \ 62 PIC_PROLOGUE(%g1, %g2); \ 63 ld [%g1 + name], %g2; \ 64 jmp %g2; \ 65 nop 66 #else 67 #define CALL(name) \ 68 set name, %g1; \ 69 jmp %g1; \ 70 nop 71 #endif 72 #define ERROR() CALL(CERROR) 73 74 /* 75 * SYSCALL is used when further action must be taken before returning. 76 * Note that it adds a `nop' over what we could do, if we only knew 77 * what came at label 1.... 78 */ 79 #define _SYSCALL(x,y) \ 80 ENTRY(x); \ 81 mov _CAT(SYS_,y), %g1; \ 82 t ST_SYSCALL; \ 83 bcc 1f; \ 84 nop; \ 85 ERROR(); \ 86 1: /* next insn */ 87 88 #define SYSCALL(x) \ 89 _SYSCALL(x,x) 90 91 /* 92 * RSYSCALL is used when the system call should just return. Here we 93 * use the SYSCALL_G2RFLAG to put the `success' return address in %g2 94 * and avoid a branch. 95 * 96 * PSEUDO(x,y) is like RSYSCALL(y), except that the name is x. 97 */ 98 #define _RSYSCALL(x,y) \ 99 ENTRY(x); \ 100 mov (_CAT(SYS_,y)) | SYSCALL_G2RFLAG, %g1; \ 101 add %o7, 8, %g2; \ 102 t ST_SYSCALL; \ 103 ERROR() 104 105 #define RSYSCALL(x) _RSYSCALL(x,x) 106 #define PSEUDO(x,y) _RSYSCALL(x,y) 107 108 /* 109 * WSYSCALL(weak,strong) is like RSYSCALL(weak), 110 * except that weak is a weak internal alias for the strong symbol. 111 */ 112 #ifdef WEAK_ALIAS 113 #define WSYSCALL(weak,strong) \ 114 WEAK_ALIAS(weak,strong); \ 115 PSEUDO(strong,weak) 116 #else 117 #define WSYSCALL(weak,strong) \ 118 RSYSCALL(weak) 119 #endif 120 121 /* 122 * SYSCALL_NOERROR is like SYSCALL, except it's used for syscalls that 123 * never fail. 124 * 125 * XXX - This should be optimized. 126 */ 127 #define SYSCALL_NOERROR(x) \ 128 ENTRY(x); \ 129 mov _CAT(SYS_,x), %g1; \ 130 t ST_SYSCALL 131 132 /* 133 * RSYSCALL_NOERROR is like RSYSCALL, except it's used for syscalls 134 * that never fail. 135 * 136 * PSEUDO_NOERROR(x,y) is like RSYSCALL_NOERROR(y), except that the 137 * name is x. 138 * 139 * XXX - This should be optimized. 140 */ 141 #define _RSYSCALL_NOERROR(x,y) \ 142 ENTRY(x); \ 143 mov (_CAT(SYS_,y)) | SYSCALL_G2RFLAG, %g1; \ 144 add %o7, 8, %g2; \ 145 t ST_SYSCALL 146 147 #define RSYSCALL_NOERROR(x) _RSYSCALL_NOERROR(x,x) 148 #define PSEUDO_NOERROR(x,y) _RSYSCALL_NOERROR(x,y) 149 150 .globl CERROR 151