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.18 2011/03/28 11:19:12 martin 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, %g5); \ 63 set name, %g5; \ 64 ld [%g1 + %g5], %g5; \ 65 jmp %g5; \ 66 nop 67#else 68#define CALL(name) \ 69 set name, %g1; \ 70 jmp %g1; \ 71 nop 72#endif 73#define ERROR() CALL(CERROR) 74 75/* 76 * SYSCALL is used when further action must be taken before returning. 77 * Note that it adds a `nop' over what we could do, if we only knew 78 * what came at label 1.... 79 */ 80#define _SYSCALL(x,y) \ 81ENTRY(x); \ 82 mov _CAT(SYS_,y), %g1; \ 83 t ST_SYSCALL; \ 84 bcc 1f; \ 85 nop; \ 86 ERROR(); \ 871: /* next insn */ 88 89#define SYSCALL(x) \ 90 _SYSCALL(x,x) 91 92/* 93 * RSYSCALL is used when the system call should just return. Here we 94 * use the SYSCALL_G5RFLAG to put the `success' return address in %g5 95 * and avoid a branch. 96 * 97 * PSEUDO(x,y) is like RSYSCALL(y), except that the name is x. 98 */ 99#define _RSYSCALL(x,y) \ 100ENTRY(x); \ 101 mov (_CAT(SYS_,y)) | SYSCALL_G5RFLAG, %g1; \ 102 add %o7, 8, %g5; \ 103 t ST_SYSCALL; \ 104 ERROR() 105 106#define RSYSCALL(x) _RSYSCALL(x,x) 107#define PSEUDO(x,y) _RSYSCALL(x,y) 108 109/* 110 * WSYSCALL(weak,strong) is like RSYSCALL(weak), 111 * except that weak is a weak internal alias for the strong symbol. 112 */ 113#ifdef WEAK_ALIAS 114#define WSYSCALL(weak,strong) \ 115 WEAK_ALIAS(weak,strong); \ 116 PSEUDO(strong,weak) 117#else 118#define WSYSCALL(weak,strong) \ 119 RSYSCALL(weak) 120#endif 121 122/* 123 * SYSCALL_NOERROR is like SYSCALL, except it's used for syscalls that 124 * never fail. 125 * 126 * XXX - This should be optimized. 127 */ 128#define SYSCALL_NOERROR(x) \ 129ENTRY(x); \ 130 mov _CAT(SYS_,x), %g1; \ 131 t ST_SYSCALL 132 133/* 134 * RSYSCALL_NOERROR is like RSYSCALL, except it's used for syscalls 135 * that never fail. 136 * 137 * PSEUDO_NOERROR(x,y) is like RSYSCALL_NOERROR(y), except that the 138 * name is x. 139 * 140 * XXX - This should be optimized. 141 */ 142#define _RSYSCALL_NOERROR(x,y) \ 143ENTRY(x); \ 144 mov (_CAT(SYS_,y)) | SYSCALL_G5RFLAG, %g1; \ 145 add %o7, 8, %g5; \ 146 t ST_SYSCALL 147 148#define RSYSCALL_NOERROR(x) _RSYSCALL_NOERROR(x,x) 149#define PSEUDO_NOERROR(x,y) _RSYSCALL_NOERROR(x,y) 150 151 .globl CERROR 152