10b9f5089Scgd /*- 20b9f5089Scgd * Copyright (c) 1992, 1993 30b9f5089Scgd * The Regents of the University of California. All rights reserved. 40b9f5089Scgd * 50b9f5089Scgd * This software was developed by the Computer Systems Engineering group 60b9f5089Scgd * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 70b9f5089Scgd * contributed to Berkeley. 80b9f5089Scgd * 90b9f5089Scgd * Redistribution and use in source and binary forms, with or without 100b9f5089Scgd * modification, are permitted provided that the following conditions 110b9f5089Scgd * are met: 120b9f5089Scgd * 1. Redistributions of source code must retain the above copyright 130b9f5089Scgd * notice, this list of conditions and the following disclaimer. 140b9f5089Scgd * 2. Redistributions in binary form must reproduce the above copyright 150b9f5089Scgd * notice, this list of conditions and the following disclaimer in the 160b9f5089Scgd * documentation and/or other materials provided with the distribution. 17eb7c1594Sagc * 3. Neither the name of the University nor the names of its contributors 180b9f5089Scgd * may be used to endorse or promote products derived from this software 190b9f5089Scgd * without specific prior written permission. 200b9f5089Scgd * 210b9f5089Scgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 220b9f5089Scgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 230b9f5089Scgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 240b9f5089Scgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 250b9f5089Scgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 260b9f5089Scgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 270b9f5089Scgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 280b9f5089Scgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 290b9f5089Scgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 300b9f5089Scgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 310b9f5089Scgd * SUCH DAMAGE. 320b9f5089Scgd * 330b9f5089Scgd * @(#)SYS.h 8.1 (Berkeley) 6/4/93 340b9f5089Scgd * 350b9f5089Scgd * from: Header: SYS.h,v 1.2 92/07/03 18:57:00 torek Exp 36*4d12bfcdSjoerg * $NetBSD: SYS.h,v 1.19 2013/09/12 15:36:16 joerg Exp $ 370b9f5089Scgd */ 380b9f5089Scgd 39e0bf9676Spk #include <machine/asm.h> 400b9f5089Scgd #include <sys/syscall.h> 410b9f5089Scgd #include <machine/trap.h> 420b9f5089Scgd 4392d8b1e9Swiz #ifdef __STDC__ 44939f7033Spk #define _CAT(x,y) x##y 4592d8b1e9Swiz #else 4692d8b1e9Swiz #define _CAT(x,y) x/**/y 4792d8b1e9Swiz #endif 48939f7033Spk 49dccf2a15Skleink #ifdef __ELF__ 50dccf2a15Skleink #define CERROR _C_LABEL(__cerror) 51dccf2a15Skleink #define CURBRK _C_LABEL(__curbrk) 52dccf2a15Skleink #else 53dccf2a15Skleink #define CERROR _ASM_LABEL(cerror) 54dccf2a15Skleink #define CURBRK _ASM_LABEL(curbrk) 55dccf2a15Skleink #endif 56dccf2a15Skleink 570b9f5089Scgd /* 58faedc2c4Suwe * ERROR branches to cerror. 590b9f5089Scgd */ 60*4d12bfcdSjoerg #ifdef __PIC__ 619a416d6fSchristos #define CALL(name) \ 62ecf8c9b0Smartin PIC_PROLOGUE(%g1, %g5); \ 63ecf8c9b0Smartin set name, %g5; \ 64ecf8c9b0Smartin ld [%g1 + %g5], %g5; \ 65ecf8c9b0Smartin jmp %g5; \ 66faedc2c4Suwe nop 67e0bf9676Spk #else 689a416d6fSchristos #define CALL(name) \ 69faedc2c4Suwe set name, %g1; \ 70faedc2c4Suwe jmp %g1; \ 71faedc2c4Suwe nop 72e0bf9676Spk #endif 739a416d6fSchristos #define ERROR() CALL(CERROR) 740b9f5089Scgd 750b9f5089Scgd /* 760b9f5089Scgd * SYSCALL is used when further action must be taken before returning. 77faedc2c4Suwe * Note that it adds a `nop' over what we could do, if we only knew 78faedc2c4Suwe * what came at label 1.... 790b9f5089Scgd */ 802234f31bSkleink #define _SYSCALL(x,y) \ 81faedc2c4Suwe ENTRY(x); \ 82faedc2c4Suwe mov _CAT(SYS_,y), %g1; \ 83faedc2c4Suwe t ST_SYSCALL; \ 84faedc2c4Suwe bcc 1f; \ 85faedc2c4Suwe nop; \ 86faedc2c4Suwe ERROR(); \ 87faedc2c4Suwe 1: /* next insn */ 882234f31bSkleink 890b9f5089Scgd #define SYSCALL(x) \ 902234f31bSkleink _SYSCALL(x,x) 910b9f5089Scgd 920b9f5089Scgd /* 93faedc2c4Suwe * RSYSCALL is used when the system call should just return. Here we 94ecf8c9b0Smartin * use the SYSCALL_G5RFLAG to put the `success' return address in %g5 950b9f5089Scgd * and avoid a branch. 96faedc2c4Suwe * 97faedc2c4Suwe * PSEUDO(x,y) is like RSYSCALL(y), except that the name is x. 980b9f5089Scgd */ 99faedc2c4Suwe #define _RSYSCALL(x,y) \ 100faedc2c4Suwe ENTRY(x); \ 101ecf8c9b0Smartin mov (_CAT(SYS_,y)) | SYSCALL_G5RFLAG, %g1; \ 102ecf8c9b0Smartin add %o7, 8, %g5; \ 103faedc2c4Suwe t ST_SYSCALL; \ 104faedc2c4Suwe ERROR() 105faedc2c4Suwe 106faedc2c4Suwe #define RSYSCALL(x) _RSYSCALL(x,x) 107faedc2c4Suwe #define PSEUDO(x,y) _RSYSCALL(x,y) 1080b9f5089Scgd 1090b9f5089Scgd /* 110faedc2c4Suwe * WSYSCALL(weak,strong) is like RSYSCALL(weak), 111faedc2c4Suwe * except that weak is a weak internal alias for the strong symbol. 112ac8c1c29Sthorpej */ 113ac8c1c29Sthorpej #ifdef WEAK_ALIAS 114ac8c1c29Sthorpej #define WSYSCALL(weak,strong) \ 115ac8c1c29Sthorpej WEAK_ALIAS(weak,strong); \ 116ac8c1c29Sthorpej PSEUDO(strong,weak) 117ac8c1c29Sthorpej #else 118ac8c1c29Sthorpej #define WSYSCALL(weak,strong) \ 119ac8c1c29Sthorpej RSYSCALL(weak) 120ac8c1c29Sthorpej #endif 121ac8c1c29Sthorpej 122ac8c1c29Sthorpej /* 123faedc2c4Suwe * SYSCALL_NOERROR is like SYSCALL, except it's used for syscalls that 124faedc2c4Suwe * never fail. 12541da4098Sjtc * 12641da4098Sjtc * XXX - This should be optimized. 12741da4098Sjtc */ 12841da4098Sjtc #define SYSCALL_NOERROR(x) \ 129faedc2c4Suwe ENTRY(x); \ 130faedc2c4Suwe mov _CAT(SYS_,x), %g1; \ 131faedc2c4Suwe t ST_SYSCALL 13241da4098Sjtc 13341da4098Sjtc /* 13441da4098Sjtc * RSYSCALL_NOERROR is like RSYSCALL, except it's used for syscalls 13541da4098Sjtc * that never fail. 13641da4098Sjtc * 137faedc2c4Suwe * PSEUDO_NOERROR(x,y) is like RSYSCALL_NOERROR(y), except that the 138faedc2c4Suwe * name is x. 139faedc2c4Suwe * 14041da4098Sjtc * XXX - This should be optimized. 14141da4098Sjtc */ 142faedc2c4Suwe #define _RSYSCALL_NOERROR(x,y) \ 143faedc2c4Suwe ENTRY(x); \ 144ecf8c9b0Smartin mov (_CAT(SYS_,y)) | SYSCALL_G5RFLAG, %g1; \ 145ecf8c9b0Smartin add %o7, 8, %g5; \ 1461efc8c37Spk t ST_SYSCALL 14741da4098Sjtc 148faedc2c4Suwe #define RSYSCALL_NOERROR(x) _RSYSCALL_NOERROR(x,x) 149faedc2c4Suwe #define PSEUDO_NOERROR(x,y) _RSYSCALL_NOERROR(x,y) 1502913a7a8Skleink 151dccf2a15Skleink .globl CERROR 152