SYS.h revision 1.13
1/* $NetBSD: SYS.h,v 1.13 2013/08/16 22:20:49 matt Exp $ */ 2 3/*- 4 * Copyright (c) 1990 The Regents of the University of California. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * William Jolitz. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. Neither the name of the University nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * from: @(#)SYS.h 5.5 (Berkeley) 5/7/91 35 */ 36 37#include <machine/asm.h> 38#include <sys/syscall.h> 39#include <arm/swi.h> 40 41#ifndef __STDC__ 42#error __STDC__ not defined 43#endif 44 45#if !defined(__thumb__) 46#define SYSTRAP(x) svc #SWI_OS_NETBSD | SYS_ ## x 47#else 48.macro emitsvc x 49 mov ip, r0 50.ifeq \x / 256 51 movs r0, #\x 52.else 53#if defined(_ARM_ARCH_7) 54 movw r0, #\x 55#else 56.ifeq (\x & 3) 57 movs r0, #(\x / 4) 58 lsls r0, r0, #3 59.else 60.ifeq (\x & 1) 61 movs r0, #(\x / 2) 62 lsls r0, r0, #1 63.else 64 movs r0, #(\x / 256) 65 lsls r0, r0, #8 66 adds r0, r0, #(\x & 255) 67.endif 68.endif 69#endif /* !_ARM_ARCH_7 */ 70.endif 71 svc #255 72.endm 73#define SYSTRAP(x) emitsvc SYS_ ## x 74#endif /* __thumb__ */ 75 76#define CERROR _C_LABEL(__cerror) 77#define CURBRK _C_LABEL(__curbrk) 78 79#define _SYSCALL_NOERROR(x,y) \ 80 ENTRY(x); \ 81 SYSTRAP(y) 82 83#if !defined(__thumb__) || defined(_ARM_ARCH_T2) 84#define _INVOKE_CERROR() bcs CERROR 85#else 86#define _INVOKE_CERROR() \ 87 bcc 86f; push {r4,lr}; bl CERROR; pop {r4,pc}; 86: 88#endif 89#define _SYSCALL(x, y) \ 90 _SYSCALL_NOERROR(x,y); \ 91 _INVOKE_CERROR() 92 93#define SYSCALL_NOERROR(x) \ 94 _SYSCALL_NOERROR(x,x) 95 96#define SYSCALL(x) \ 97 _SYSCALL(x,x) 98 99 100#define PSEUDO_NOERROR(x,y) \ 101 _SYSCALL_NOERROR(x,y); \ 102 RET; \ 103 END(x) 104 105#define PSEUDO(x,y) \ 106 _SYSCALL(x,y); \ 107 RET; \ 108 END(x) 109 110 111#define RSYSCALL_NOERROR(x) \ 112 PSEUDO_NOERROR(x,x) 113 114#define RSYSCALL(x) \ 115 PSEUDO(x,x) 116 117#ifdef WEAK_ALIAS 118#define WSYSCALL(weak,strong) \ 119 WEAK_ALIAS(weak,strong); \ 120 PSEUDO(strong,weak) 121#else 122#define WSYSCALL(weak,strong) \ 123 PSEUDO(weak,weak) 124#endif 125 126 .hidden CERROR 127 .globl CERROR 128