1*84d9c625SLionel Sambuc /* $NetBSD: SYS.h,v 1.15 2013/08/19 22:13:34 matt Exp $ */ 22fe8fb19SBen Gras 32fe8fb19SBen Gras /*- 42fe8fb19SBen Gras * Copyright (c) 1990 The Regents of the University of California. 52fe8fb19SBen Gras * All rights reserved. 62fe8fb19SBen Gras * 72fe8fb19SBen Gras * This code is derived from software contributed to Berkeley by 82fe8fb19SBen Gras * William Jolitz. 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 * 3. Neither the name of the University nor the names of its contributors 192fe8fb19SBen Gras * may be used to endorse or promote products derived from this software 202fe8fb19SBen Gras * without specific prior written permission. 212fe8fb19SBen Gras * 222fe8fb19SBen Gras * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 232fe8fb19SBen Gras * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 242fe8fb19SBen Gras * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 252fe8fb19SBen Gras * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 262fe8fb19SBen Gras * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 272fe8fb19SBen Gras * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 282fe8fb19SBen Gras * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 292fe8fb19SBen Gras * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 302fe8fb19SBen Gras * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 312fe8fb19SBen Gras * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 322fe8fb19SBen Gras * SUCH DAMAGE. 332fe8fb19SBen Gras * 342fe8fb19SBen Gras * from: @(#)SYS.h 5.5 (Berkeley) 5/7/91 352fe8fb19SBen Gras */ 362fe8fb19SBen Gras 37*84d9c625SLionel Sambuc #define _TEXT_SECTION .section .text.hot, "ax" 38*84d9c625SLionel Sambuc 392fe8fb19SBen Gras #include <machine/asm.h> 402fe8fb19SBen Gras #include <sys/syscall.h> 412fe8fb19SBen Gras #include <arm/swi.h> 422fe8fb19SBen Gras 43*84d9c625SLionel Sambuc #ifndef __STDC__ 44*84d9c625SLionel Sambuc #error __STDC__ not defined 452fe8fb19SBen Gras #endif 462fe8fb19SBen Gras 47*84d9c625SLionel Sambuc #if !defined(__thumb__) 48*84d9c625SLionel Sambuc #define SYSTRAP(x) svc #SWI_OS_NETBSD | SYS_ ## x 49*84d9c625SLionel Sambuc #else 50*84d9c625SLionel Sambuc .macro emitsvc x 51*84d9c625SLionel Sambuc mov ip, r0 52*84d9c625SLionel Sambuc .ifeq \x / 256 53*84d9c625SLionel Sambuc movs r0, #\x 54*84d9c625SLionel Sambuc .else 55*84d9c625SLionel Sambuc #if defined(_ARM_ARCH_7) 56*84d9c625SLionel Sambuc movw r0, #\x 57*84d9c625SLionel Sambuc #else 58*84d9c625SLionel Sambuc .ifeq (\x & 3) 59*84d9c625SLionel Sambuc movs r0, #(\x / 4) 60*84d9c625SLionel Sambuc lsls r0, r0, #3 61*84d9c625SLionel Sambuc .else 62*84d9c625SLionel Sambuc .ifeq (\x & 1) 63*84d9c625SLionel Sambuc movs r0, #(\x / 2) 64*84d9c625SLionel Sambuc lsls r0, r0, #1 65*84d9c625SLionel Sambuc .else 66*84d9c625SLionel Sambuc movs r0, #(\x / 256) 67*84d9c625SLionel Sambuc lsls r0, r0, #8 68*84d9c625SLionel Sambuc adds r0, r0, #(\x & 255) 69*84d9c625SLionel Sambuc .endif 70*84d9c625SLionel Sambuc .endif 71*84d9c625SLionel Sambuc #endif /* !_ARM_ARCH_7 */ 72*84d9c625SLionel Sambuc .endif 73*84d9c625SLionel Sambuc svc #255 74*84d9c625SLionel Sambuc .endm 75*84d9c625SLionel Sambuc #define SYSTRAP(x) emitsvc SYS_ ## x 76*84d9c625SLionel Sambuc #endif /* __thumb__ */ 77*84d9c625SLionel Sambuc 782fe8fb19SBen Gras #define CERROR _C_LABEL(__cerror) 792fe8fb19SBen Gras #define CURBRK _C_LABEL(__curbrk) 802fe8fb19SBen Gras 812fe8fb19SBen Gras #define _SYSCALL_NOERROR(x,y) \ 822fe8fb19SBen Gras ENTRY(x); \ 832fe8fb19SBen Gras SYSTRAP(y) 842fe8fb19SBen Gras 85*84d9c625SLionel Sambuc #if !defined(__thumb__) || defined(_ARM_ARCH_T2) 86*84d9c625SLionel Sambuc #define _INVOKE_CERROR() bcs CERROR 87*84d9c625SLionel Sambuc #else 88*84d9c625SLionel Sambuc #define _INVOKE_CERROR() \ 89*84d9c625SLionel Sambuc bcc 86f; push {r3,lr}; bl CERROR; pop {r3,pc}; 86: 90*84d9c625SLionel Sambuc #endif 912fe8fb19SBen Gras #define _SYSCALL(x, y) \ 922fe8fb19SBen Gras _SYSCALL_NOERROR(x,y); \ 93*84d9c625SLionel Sambuc _INVOKE_CERROR() 942fe8fb19SBen Gras 952fe8fb19SBen Gras #define SYSCALL_NOERROR(x) \ 962fe8fb19SBen Gras _SYSCALL_NOERROR(x,x) 972fe8fb19SBen Gras 982fe8fb19SBen Gras #define SYSCALL(x) \ 992fe8fb19SBen Gras _SYSCALL(x,x) 1002fe8fb19SBen Gras 1012fe8fb19SBen Gras 1022fe8fb19SBen Gras #define PSEUDO_NOERROR(x,y) \ 1032fe8fb19SBen Gras _SYSCALL_NOERROR(x,y); \ 104*84d9c625SLionel Sambuc RET; \ 105*84d9c625SLionel Sambuc END(x) 1062fe8fb19SBen Gras 1072fe8fb19SBen Gras #define PSEUDO(x,y) \ 1082fe8fb19SBen Gras _SYSCALL(x,y); \ 109*84d9c625SLionel Sambuc RET; \ 110*84d9c625SLionel Sambuc END(x) 1112fe8fb19SBen Gras 1122fe8fb19SBen Gras 1132fe8fb19SBen Gras #define RSYSCALL_NOERROR(x) \ 1142fe8fb19SBen Gras PSEUDO_NOERROR(x,x) 1152fe8fb19SBen Gras 1162fe8fb19SBen Gras #define RSYSCALL(x) \ 1172fe8fb19SBen Gras PSEUDO(x,x) 1182fe8fb19SBen Gras 1192fe8fb19SBen Gras #ifdef WEAK_ALIAS 1202fe8fb19SBen Gras #define WSYSCALL(weak,strong) \ 1212fe8fb19SBen Gras WEAK_ALIAS(weak,strong); \ 1222fe8fb19SBen Gras PSEUDO(strong,weak) 1232fe8fb19SBen Gras #else 1242fe8fb19SBen Gras #define WSYSCALL(weak,strong) \ 1252fe8fb19SBen Gras PSEUDO(weak,weak) 1262fe8fb19SBen Gras #endif 1272fe8fb19SBen Gras 128*84d9c625SLionel Sambuc .hidden CERROR 1292fe8fb19SBen Gras .globl CERROR 130