12fe8fb19SBen Gras /*- 22fe8fb19SBen Gras * Copyright (c) 1992, 1993 32fe8fb19SBen Gras * The Regents of the University of California. All rights reserved. 42fe8fb19SBen Gras * 52fe8fb19SBen Gras * This software was developed by the Computer Systems Engineering group 62fe8fb19SBen Gras * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 72fe8fb19SBen Gras * contributed to Berkeley. 82fe8fb19SBen Gras * 92fe8fb19SBen Gras * Redistribution and use in source and binary forms, with or without 102fe8fb19SBen Gras * modification, are permitted provided that the following conditions 112fe8fb19SBen Gras * are met: 122fe8fb19SBen Gras * 1. Redistributions of source code must retain the above copyright 132fe8fb19SBen Gras * notice, this list of conditions and the following disclaimer. 142fe8fb19SBen Gras * 2. Redistributions in binary form must reproduce the above copyright 152fe8fb19SBen Gras * notice, this list of conditions and the following disclaimer in the 162fe8fb19SBen Gras * documentation and/or other materials provided with the distribution. 172fe8fb19SBen Gras * 3. Neither the name of the University nor the names of its contributors 182fe8fb19SBen Gras * may be used to endorse or promote products derived from this software 192fe8fb19SBen Gras * without specific prior written permission. 202fe8fb19SBen Gras * 212fe8fb19SBen Gras * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 222fe8fb19SBen Gras * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 232fe8fb19SBen Gras * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 242fe8fb19SBen Gras * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 252fe8fb19SBen Gras * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 262fe8fb19SBen Gras * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 272fe8fb19SBen Gras * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 282fe8fb19SBen Gras * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 292fe8fb19SBen Gras * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 302fe8fb19SBen Gras * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 312fe8fb19SBen Gras * SUCH DAMAGE. 322fe8fb19SBen Gras * 332fe8fb19SBen Gras * @(#)SYS.h 8.1 (Berkeley) 6/4/93 342fe8fb19SBen Gras * 352fe8fb19SBen Gras * from: Header: SYS.h,v 1.2 92/07/03 18:57:00 torek Exp 36*84d9c625SLionel Sambuc * $NetBSD: SYS.h,v 1.19 2013/09/12 15:36:16 joerg Exp $ 372fe8fb19SBen Gras */ 382fe8fb19SBen Gras 392fe8fb19SBen Gras #include <machine/asm.h> 402fe8fb19SBen Gras #include <sys/syscall.h> 412fe8fb19SBen Gras #include <machine/trap.h> 422fe8fb19SBen Gras 432fe8fb19SBen Gras #ifdef __STDC__ 442fe8fb19SBen Gras #define _CAT(x,y) x##y 452fe8fb19SBen Gras #else 462fe8fb19SBen Gras #define _CAT(x,y) x/**/y 472fe8fb19SBen Gras #endif 482fe8fb19SBen Gras 492fe8fb19SBen Gras #ifdef __ELF__ 502fe8fb19SBen Gras #define CERROR _C_LABEL(__cerror) 512fe8fb19SBen Gras #define CURBRK _C_LABEL(__curbrk) 522fe8fb19SBen Gras #else 532fe8fb19SBen Gras #define CERROR _ASM_LABEL(cerror) 542fe8fb19SBen Gras #define CURBRK _ASM_LABEL(curbrk) 552fe8fb19SBen Gras #endif 562fe8fb19SBen Gras 572fe8fb19SBen Gras /* 582fe8fb19SBen Gras * ERROR branches to cerror. 592fe8fb19SBen Gras */ 60*84d9c625SLionel Sambuc #ifdef __PIC__ 612fe8fb19SBen Gras #define CALL(name) \ 62e415d488SLionel Sambuc PIC_PROLOGUE(%g1, %g5); \ 63e415d488SLionel Sambuc set name, %g5; \ 64e415d488SLionel Sambuc ld [%g1 + %g5], %g5; \ 65e415d488SLionel Sambuc jmp %g5; \ 662fe8fb19SBen Gras nop 672fe8fb19SBen Gras #else 682fe8fb19SBen Gras #define CALL(name) \ 692fe8fb19SBen Gras set name, %g1; \ 702fe8fb19SBen Gras jmp %g1; \ 712fe8fb19SBen Gras nop 722fe8fb19SBen Gras #endif 732fe8fb19SBen Gras #define ERROR() CALL(CERROR) 742fe8fb19SBen Gras 752fe8fb19SBen Gras /* 762fe8fb19SBen Gras * SYSCALL is used when further action must be taken before returning. 772fe8fb19SBen Gras * Note that it adds a `nop' over what we could do, if we only knew 782fe8fb19SBen Gras * what came at label 1.... 792fe8fb19SBen Gras */ 802fe8fb19SBen Gras #define _SYSCALL(x,y) \ 812fe8fb19SBen Gras ENTRY(x); \ 822fe8fb19SBen Gras mov _CAT(SYS_,y), %g1; \ 832fe8fb19SBen Gras t ST_SYSCALL; \ 842fe8fb19SBen Gras bcc 1f; \ 852fe8fb19SBen Gras nop; \ 862fe8fb19SBen Gras ERROR(); \ 872fe8fb19SBen Gras 1: /* next insn */ 882fe8fb19SBen Gras 892fe8fb19SBen Gras #define SYSCALL(x) \ 902fe8fb19SBen Gras _SYSCALL(x,x) 912fe8fb19SBen Gras 922fe8fb19SBen Gras /* 932fe8fb19SBen Gras * RSYSCALL is used when the system call should just return. Here we 94e415d488SLionel Sambuc * use the SYSCALL_G5RFLAG to put the `success' return address in %g5 952fe8fb19SBen Gras * and avoid a branch. 962fe8fb19SBen Gras * 972fe8fb19SBen Gras * PSEUDO(x,y) is like RSYSCALL(y), except that the name is x. 982fe8fb19SBen Gras */ 992fe8fb19SBen Gras #define _RSYSCALL(x,y) \ 1002fe8fb19SBen Gras ENTRY(x); \ 101e415d488SLionel Sambuc mov (_CAT(SYS_,y)) | SYSCALL_G5RFLAG, %g1; \ 102e415d488SLionel Sambuc add %o7, 8, %g5; \ 1032fe8fb19SBen Gras t ST_SYSCALL; \ 1042fe8fb19SBen Gras ERROR() 1052fe8fb19SBen Gras 1062fe8fb19SBen Gras #define RSYSCALL(x) _RSYSCALL(x,x) 1072fe8fb19SBen Gras #define PSEUDO(x,y) _RSYSCALL(x,y) 1082fe8fb19SBen Gras 1092fe8fb19SBen Gras /* 1102fe8fb19SBen Gras * WSYSCALL(weak,strong) is like RSYSCALL(weak), 1112fe8fb19SBen Gras * except that weak is a weak internal alias for the strong symbol. 1122fe8fb19SBen Gras */ 1132fe8fb19SBen Gras #ifdef WEAK_ALIAS 1142fe8fb19SBen Gras #define WSYSCALL(weak,strong) \ 1152fe8fb19SBen Gras WEAK_ALIAS(weak,strong); \ 1162fe8fb19SBen Gras PSEUDO(strong,weak) 1172fe8fb19SBen Gras #else 1182fe8fb19SBen Gras #define WSYSCALL(weak,strong) \ 1192fe8fb19SBen Gras RSYSCALL(weak) 1202fe8fb19SBen Gras #endif 1212fe8fb19SBen Gras 1222fe8fb19SBen Gras /* 1232fe8fb19SBen Gras * SYSCALL_NOERROR is like SYSCALL, except it's used for syscalls that 1242fe8fb19SBen Gras * never fail. 1252fe8fb19SBen Gras * 1262fe8fb19SBen Gras * XXX - This should be optimized. 1272fe8fb19SBen Gras */ 1282fe8fb19SBen Gras #define SYSCALL_NOERROR(x) \ 1292fe8fb19SBen Gras ENTRY(x); \ 1302fe8fb19SBen Gras mov _CAT(SYS_,x), %g1; \ 1312fe8fb19SBen Gras t ST_SYSCALL 1322fe8fb19SBen Gras 1332fe8fb19SBen Gras /* 1342fe8fb19SBen Gras * RSYSCALL_NOERROR is like RSYSCALL, except it's used for syscalls 1352fe8fb19SBen Gras * that never fail. 1362fe8fb19SBen Gras * 1372fe8fb19SBen Gras * PSEUDO_NOERROR(x,y) is like RSYSCALL_NOERROR(y), except that the 1382fe8fb19SBen Gras * name is x. 1392fe8fb19SBen Gras * 1402fe8fb19SBen Gras * XXX - This should be optimized. 1412fe8fb19SBen Gras */ 1422fe8fb19SBen Gras #define _RSYSCALL_NOERROR(x,y) \ 1432fe8fb19SBen Gras ENTRY(x); \ 144e415d488SLionel Sambuc mov (_CAT(SYS_,y)) | SYSCALL_G5RFLAG, %g1; \ 145e415d488SLionel Sambuc add %o7, 8, %g5; \ 1462fe8fb19SBen Gras t ST_SYSCALL 1472fe8fb19SBen Gras 1482fe8fb19SBen Gras #define RSYSCALL_NOERROR(x) _RSYSCALL_NOERROR(x,x) 1492fe8fb19SBen Gras #define PSEUDO_NOERROR(x,y) _RSYSCALL_NOERROR(x,y) 1502fe8fb19SBen Gras 1512fe8fb19SBen Gras .globl CERROR 152