1*0a6a1f1dSLionel Sambuc /* $NetBSD: SYS.h,v 1.25 2014/05/23 02:17:43 uebayasi Exp $ */ 22fe8fb19SBen Gras 32fe8fb19SBen Gras /*- 42fe8fb19SBen Gras * Copyright (c) 2007 The NetBSD Foundation, Inc. 52fe8fb19SBen Gras * All rights reserved. 62fe8fb19SBen Gras * 72fe8fb19SBen Gras * This code is derived from software contributed to The NetBSD Foundation 82fe8fb19SBen Gras * by Andrew Doran. 92fe8fb19SBen Gras * 102fe8fb19SBen Gras * Redistribution and use in source and binary forms, with or without 112fe8fb19SBen Gras * modification, are permitted provided that the following conditions 122fe8fb19SBen Gras * are met: 132fe8fb19SBen Gras * 1. Redistributions of source code must retain the above copyright 142fe8fb19SBen Gras * notice, this list of conditions and the following disclaimer. 152fe8fb19SBen Gras * 2. Redistributions in binary form must reproduce the above copyright 162fe8fb19SBen Gras * notice, this list of conditions and the following disclaimer in the 172fe8fb19SBen Gras * documentation and/or other materials provided with the distribution. 182fe8fb19SBen Gras * 192fe8fb19SBen Gras * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 202fe8fb19SBen Gras * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 212fe8fb19SBen Gras * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 222fe8fb19SBen Gras * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 232fe8fb19SBen Gras * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 242fe8fb19SBen Gras * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 252fe8fb19SBen Gras * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 262fe8fb19SBen Gras * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 272fe8fb19SBen Gras * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 282fe8fb19SBen Gras * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 292fe8fb19SBen Gras * POSSIBILITY OF SUCH DAMAGE. 302fe8fb19SBen Gras */ 312fe8fb19SBen Gras 322fe8fb19SBen Gras /*- 332fe8fb19SBen Gras * Copyright (c) 1990 The Regents of the University of California. 342fe8fb19SBen Gras * All rights reserved. 352fe8fb19SBen Gras * 362fe8fb19SBen Gras * This code is derived from software contributed to Berkeley by 372fe8fb19SBen Gras * William Jolitz. 382fe8fb19SBen Gras * 392fe8fb19SBen Gras * Redistribution and use in source and binary forms, with or without 402fe8fb19SBen Gras * modification, are permitted provided that the following conditions 412fe8fb19SBen Gras * are met: 422fe8fb19SBen Gras * 1. Redistributions of source code must retain the above copyright 432fe8fb19SBen Gras * notice, this list of conditions and the following disclaimer. 442fe8fb19SBen Gras * 2. Redistributions in binary form must reproduce the above copyright 452fe8fb19SBen Gras * notice, this list of conditions and the following disclaimer in the 462fe8fb19SBen Gras * documentation and/or other materials provided with the distribution. 472fe8fb19SBen Gras * 3. Neither the name of the University nor the names of its contributors 482fe8fb19SBen Gras * may be used to endorse or promote products derived from this software 492fe8fb19SBen Gras * without specific prior written permission. 502fe8fb19SBen Gras * 512fe8fb19SBen Gras * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 522fe8fb19SBen Gras * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 532fe8fb19SBen Gras * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 542fe8fb19SBen Gras * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 552fe8fb19SBen Gras * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 562fe8fb19SBen Gras * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 572fe8fb19SBen Gras * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 582fe8fb19SBen Gras * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 592fe8fb19SBen Gras * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 602fe8fb19SBen Gras * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 612fe8fb19SBen Gras * SUCH DAMAGE. 622fe8fb19SBen Gras * 632fe8fb19SBen Gras * from: @(#)SYS.h 5.5 (Berkeley) 5/7/91 642fe8fb19SBen Gras */ 652fe8fb19SBen Gras 662fe8fb19SBen Gras #include <machine/asm.h> 672fe8fb19SBen Gras #include <sys/syscall.h> 682fe8fb19SBen Gras 692fe8fb19SBen Gras #ifdef __STDC__ 702fe8fb19SBen Gras #define _SYSNAM(x) $(SYS_ ## x) 712fe8fb19SBen Gras #else 722fe8fb19SBen Gras #define _SYSNAM(x) $(SYS_/**/x) 732fe8fb19SBen Gras #endif 742fe8fb19SBen Gras 752fe8fb19SBen Gras #define OSYSTRAP(x) \ 762fe8fb19SBen Gras movl _SYSNAM(x),%eax ;\ 772fe8fb19SBen Gras int $0x80 782fe8fb19SBen Gras 792fe8fb19SBen Gras #ifdef I686_LIBC 802fe8fb19SBen Gras #define SYSTRAP(x) \ 812fe8fb19SBen Gras pushl %ebx ;\ 822fe8fb19SBen Gras movl _SYSNAM(x),%eax ;\ 832fe8fb19SBen Gras movl $123f,%edx ;\ 842fe8fb19SBen Gras movl %esp,%ecx ;\ 852fe8fb19SBen Gras sysenter ;\ 862fe8fb19SBen Gras 123: movl %ebx,%edx ;\ 872fe8fb19SBen Gras popl %ebx 882fe8fb19SBen Gras #else /* I686_LIBC */ 892fe8fb19SBen Gras #define SYSTRAP(x) OSYSTRAP(x) 902fe8fb19SBen Gras #endif /* I686_LIBC */ 912fe8fb19SBen Gras 922fe8fb19SBen Gras #ifdef __ELF__ 932fe8fb19SBen Gras #define CERROR _C_LABEL(__cerror) 942fe8fb19SBen Gras #define CURBRK _C_LABEL(__curbrk) 952fe8fb19SBen Gras #else 962fe8fb19SBen Gras #define CERROR _ASM_LABEL(cerror) 972fe8fb19SBen Gras #define CURBRK _ASM_LABEL(curbrk) 982fe8fb19SBen Gras #endif 992fe8fb19SBen Gras 1002fe8fb19SBen Gras #define _SYSCALL_NOERROR(x,y) \ 1012fe8fb19SBen Gras ENTRY(x); \ 1022fe8fb19SBen Gras SYSTRAP(y) 1032fe8fb19SBen Gras 10484d9c625SLionel Sambuc #ifdef __PIC__ 1052fe8fb19SBen Gras #define _SYSCALL_ERR \ 1062fe8fb19SBen Gras PIC_PROLOGUE; \ 1072fe8fb19SBen Gras mov PIC_GOT(CERROR), %ecx; \ 1082fe8fb19SBen Gras PIC_EPILOGUE; \ 1092fe8fb19SBen Gras jmp *%ecx 1102fe8fb19SBen Gras #else 1112fe8fb19SBen Gras #define _SYSCALL_ERR \ 1122fe8fb19SBen Gras jmp CERROR 1132fe8fb19SBen Gras #endif 1142fe8fb19SBen Gras 1152fe8fb19SBen Gras #define _SYSCALL(x,y) \ 1162fe8fb19SBen Gras .text; _ALIGN_TEXT; \ 1172fe8fb19SBen Gras 2: _SYSCALL_ERR; \ 1182fe8fb19SBen Gras _SYSCALL_NOERROR(x,y); \ 1192fe8fb19SBen Gras jc 2b 1202fe8fb19SBen Gras 1212fe8fb19SBen Gras #define SYSCALL_NOERROR(x) \ 1222fe8fb19SBen Gras _SYSCALL_NOERROR(x,x) 1232fe8fb19SBen Gras 1242fe8fb19SBen Gras #define SYSCALL(x) \ 1252fe8fb19SBen Gras _SYSCALL(x,x) 1262fe8fb19SBen Gras 1272fe8fb19SBen Gras #define PSEUDO_NOERROR(x,y) \ 1282fe8fb19SBen Gras _SYSCALL_NOERROR(x,y); \ 129*0a6a1f1dSLionel Sambuc ret; \ 130*0a6a1f1dSLionel Sambuc END(x) 1312fe8fb19SBen Gras 1322fe8fb19SBen Gras #define PSEUDO(x,y) \ 1332fe8fb19SBen Gras _SYSCALL_NOERROR(x,y); \ 1342fe8fb19SBen Gras jc 2f; \ 1352fe8fb19SBen Gras ret; \ 136*0a6a1f1dSLionel Sambuc 2: _SYSCALL_ERR; \ 137*0a6a1f1dSLionel Sambuc END(x) 1382fe8fb19SBen Gras 1392fe8fb19SBen Gras #define RSYSCALL_NOERROR(x) \ 1402fe8fb19SBen Gras PSEUDO_NOERROR(x,x) 1412fe8fb19SBen Gras 1422fe8fb19SBen Gras #define RSYSCALL(x) \ 1432fe8fb19SBen Gras PSEUDO(x,x) 1442fe8fb19SBen Gras 1452fe8fb19SBen Gras #ifdef WEAK_ALIAS 1462fe8fb19SBen Gras #define WSYSCALL(weak,strong) \ 1472fe8fb19SBen Gras WEAK_ALIAS(weak,strong); \ 1482fe8fb19SBen Gras PSEUDO(strong,weak) 1492fe8fb19SBen Gras #else 1502fe8fb19SBen Gras #define WSYSCALL(weak,strong) \ 1512fe8fb19SBen Gras PSEUDO(weak,weak) 1522fe8fb19SBen Gras #endif 1532fe8fb19SBen Gras 1542fe8fb19SBen Gras .globl CERROR 155