1*bf81166fSskrll /* $NetBSD: SYS.h,v 1.16 2023/07/23 07:25:04 skrll Exp $ */ 25aefcfdcSbjh21 35aefcfdcSbjh21 /*- 45aefcfdcSbjh21 * Copyright (c) 1990 The Regents of the University of California. 55aefcfdcSbjh21 * All rights reserved. 65aefcfdcSbjh21 * 75aefcfdcSbjh21 * This code is derived from software contributed to Berkeley by 85aefcfdcSbjh21 * William Jolitz. 95aefcfdcSbjh21 * 105aefcfdcSbjh21 * Redistribution and use in source and binary forms, with or without 115aefcfdcSbjh21 * modification, are permitted provided that the following conditions 125aefcfdcSbjh21 * are met: 135aefcfdcSbjh21 * 1. Redistributions of source code must retain the above copyright 145aefcfdcSbjh21 * notice, this list of conditions and the following disclaimer. 155aefcfdcSbjh21 * 2. Redistributions in binary form must reproduce the above copyright 165aefcfdcSbjh21 * notice, this list of conditions and the following disclaimer in the 175aefcfdcSbjh21 * documentation and/or other materials provided with the distribution. 18eb7c1594Sagc * 3. Neither the name of the University nor the names of its contributors 195aefcfdcSbjh21 * may be used to endorse or promote products derived from this software 205aefcfdcSbjh21 * without specific prior written permission. 215aefcfdcSbjh21 * 225aefcfdcSbjh21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 235aefcfdcSbjh21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 245aefcfdcSbjh21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 255aefcfdcSbjh21 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 265aefcfdcSbjh21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 275aefcfdcSbjh21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 285aefcfdcSbjh21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 295aefcfdcSbjh21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 305aefcfdcSbjh21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 315aefcfdcSbjh21 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 325aefcfdcSbjh21 * SUCH DAMAGE. 335aefcfdcSbjh21 * 345aefcfdcSbjh21 * from: @(#)SYS.h 5.5 (Berkeley) 5/7/91 355aefcfdcSbjh21 */ 365aefcfdcSbjh21 37f163a9dcSmatt #define _TEXT_SECTION .section .text.hot, "ax" 38f163a9dcSmatt 395aefcfdcSbjh21 #include <machine/asm.h> 405aefcfdcSbjh21 #include <sys/syscall.h> 41294cb551Sbjh21 #include <arm/swi.h> 425aefcfdcSbjh21 439c2cd4b1Smatt #ifndef __STDC__ 449c2cd4b1Smatt #error __STDC__ not defined 4592d8b1e9Swiz #endif 465aefcfdcSbjh21 479c2cd4b1Smatt #if !defined(__thumb__) 489c2cd4b1Smatt #define SYSTRAP(x) svc #SWI_OS_NETBSD | SYS_ ## x 499c2cd4b1Smatt #else 509c2cd4b1Smatt .macro emitsvc x 519c2cd4b1Smatt mov ip, r0 529c2cd4b1Smatt .ifeq \x / 256 539c2cd4b1Smatt movs r0, #\x 549c2cd4b1Smatt .else 559c2cd4b1Smatt #if defined(_ARM_ARCH_7) 569c2cd4b1Smatt movw r0, #\x 579c2cd4b1Smatt #else 589c2cd4b1Smatt .ifeq (\x & 3) 599c2cd4b1Smatt movs r0, #(\x / 4) 609c2cd4b1Smatt lsls r0, r0, #3 619c2cd4b1Smatt .else 629c2cd4b1Smatt .ifeq (\x & 1) 639c2cd4b1Smatt movs r0, #(\x / 2) 649c2cd4b1Smatt lsls r0, r0, #1 659c2cd4b1Smatt .else 669c2cd4b1Smatt movs r0, #(\x / 256) 679c2cd4b1Smatt lsls r0, r0, #8 689c2cd4b1Smatt adds r0, r0, #(\x & 255) 699c2cd4b1Smatt .endif 709c2cd4b1Smatt .endif 719c2cd4b1Smatt #endif /* !_ARM_ARCH_7 */ 729c2cd4b1Smatt .endif 739c2cd4b1Smatt svc #255 749c2cd4b1Smatt .endm 759c2cd4b1Smatt #define SYSTRAP(x) emitsvc SYS_ ## x 769c2cd4b1Smatt #endif /* __thumb__ */ 779c2cd4b1Smatt 785feec233Smatt #define CERROR _C_LABEL(__cerror) 795feec233Smatt #define CURBRK _C_LABEL(__curbrk) 805feec233Smatt 815aefcfdcSbjh21 #define _SYSCALL_NOERROR(x,y) \ 825aefcfdcSbjh21 ENTRY(x); \ 835aefcfdcSbjh21 SYSTRAP(y) 845aefcfdcSbjh21 859c2cd4b1Smatt #if !defined(__thumb__) || defined(_ARM_ARCH_T2) 869c2cd4b1Smatt #define _INVOKE_CERROR() bcs CERROR 879c2cd4b1Smatt #else 889c2cd4b1Smatt #define _INVOKE_CERROR() \ 89a54ea9aaSmatt bcc 86f; push {r3,lr}; bl CERROR; pop {r3,pc}; 86: 909c2cd4b1Smatt #endif 915aefcfdcSbjh21 #define _SYSCALL(x, y) \ 925aefcfdcSbjh21 _SYSCALL_NOERROR(x,y); \ 939c2cd4b1Smatt _INVOKE_CERROR() 945aefcfdcSbjh21 955aefcfdcSbjh21 #define SYSCALL_NOERROR(x) \ 965aefcfdcSbjh21 _SYSCALL_NOERROR(x,x) 975aefcfdcSbjh21 985aefcfdcSbjh21 #define SYSCALL(x) \ 995aefcfdcSbjh21 _SYSCALL(x,x) 1005aefcfdcSbjh21 1015aefcfdcSbjh21 1025aefcfdcSbjh21 #define PSEUDO_NOERROR(x,y) \ 1035aefcfdcSbjh21 _SYSCALL_NOERROR(x,y); \ 1049c2cd4b1Smatt RET; \ 1059c2cd4b1Smatt END(x) 1065aefcfdcSbjh21 1075aefcfdcSbjh21 #define PSEUDO(x,y) \ 1085aefcfdcSbjh21 _SYSCALL(x,y); \ 1099c2cd4b1Smatt RET; \ 1109c2cd4b1Smatt END(x) 1115aefcfdcSbjh21 1125aefcfdcSbjh21 1135aefcfdcSbjh21 #define RSYSCALL_NOERROR(x) \ 1145aefcfdcSbjh21 PSEUDO_NOERROR(x,x) 1155aefcfdcSbjh21 1165aefcfdcSbjh21 #define RSYSCALL(x) \ 1175aefcfdcSbjh21 PSEUDO(x,x) 1185aefcfdcSbjh21 119ac8c1c29Sthorpej #ifdef WEAK_ALIAS 120ac8c1c29Sthorpej #define WSYSCALL(weak,strong) \ 121ac8c1c29Sthorpej WEAK_ALIAS(weak,strong); \ 122ac8c1c29Sthorpej PSEUDO(strong,weak) 123ac8c1c29Sthorpej #else 124ac8c1c29Sthorpej #define WSYSCALL(weak,strong) \ 125ac8c1c29Sthorpej PSEUDO(weak,weak) 126ac8c1c29Sthorpej #endif 127ac8c1c29Sthorpej 12831fc835fSmatt .hidden CERROR 1295feec233Smatt .globl CERROR 130