SYS.h revision 1.14
11.14Smatt/*	$NetBSD: SYS.h,v 1.14 2013/08/16 22:30:28 matt Exp $	*/
21.1Sbjh21
31.1Sbjh21/*-
41.1Sbjh21 * Copyright (c) 1990 The Regents of the University of California.
51.1Sbjh21 * All rights reserved.
61.1Sbjh21 *
71.1Sbjh21 * This code is derived from software contributed to Berkeley by
81.1Sbjh21 * William Jolitz.
91.1Sbjh21 *
101.1Sbjh21 * Redistribution and use in source and binary forms, with or without
111.1Sbjh21 * modification, are permitted provided that the following conditions
121.1Sbjh21 * are met:
131.1Sbjh21 * 1. Redistributions of source code must retain the above copyright
141.1Sbjh21 *    notice, this list of conditions and the following disclaimer.
151.1Sbjh21 * 2. Redistributions in binary form must reproduce the above copyright
161.1Sbjh21 *    notice, this list of conditions and the following disclaimer in the
171.1Sbjh21 *    documentation and/or other materials provided with the distribution.
181.8Sagc * 3. Neither the name of the University nor the names of its contributors
191.1Sbjh21 *    may be used to endorse or promote products derived from this software
201.1Sbjh21 *    without specific prior written permission.
211.1Sbjh21 *
221.1Sbjh21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
231.1Sbjh21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
241.1Sbjh21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
251.1Sbjh21 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
261.1Sbjh21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
271.1Sbjh21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
281.1Sbjh21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
291.1Sbjh21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
301.1Sbjh21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
311.1Sbjh21 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
321.1Sbjh21 * SUCH DAMAGE.
331.1Sbjh21 *
341.1Sbjh21 *	from: @(#)SYS.h	5.5 (Berkeley) 5/7/91
351.1Sbjh21 */
361.1Sbjh21
371.1Sbjh21#include <machine/asm.h>
381.1Sbjh21#include <sys/syscall.h>
391.4Sbjh21#include <arm/swi.h>
401.1Sbjh21
411.13Smatt#ifndef __STDC__
421.13Smatt#error __STDC__ not defined
431.13Smatt#endif
441.13Smatt
451.13Smatt#if !defined(__thumb__)
461.13Smatt#define SYSTRAP(x)	svc #SWI_OS_NETBSD | SYS_ ## x
471.13Smatt#else
481.13Smatt.macro	emitsvc	x
491.13Smatt	mov	ip, r0
501.13Smatt.ifeq	\x / 256
511.13Smatt	movs	r0, #\x
521.13Smatt.else
531.13Smatt#if defined(_ARM_ARCH_7)
541.13Smatt	movw	r0, #\x
551.6Swiz#else
561.13Smatt.ifeq (\x & 3)
571.13Smatt	movs	r0, #(\x / 4)
581.13Smatt	lsls	r0, r0, #3
591.13Smatt.else
601.13Smatt.ifeq (\x & 1)
611.13Smatt	movs	r0, #(\x / 2)
621.13Smatt	lsls	r0, r0, #1
631.13Smatt.else
641.13Smatt	movs	r0, #(\x / 256)
651.13Smatt	lsls	r0, r0, #8
661.13Smatt	adds	r0, r0, #(\x & 255)
671.13Smatt.endif
681.13Smatt.endif
691.13Smatt#endif /* !_ARM_ARCH_7 */
701.13Smatt.endif
711.13Smatt	svc	#255
721.13Smatt.endm
731.13Smatt#define SYSTRAP(x)	emitsvc SYS_ ## x
741.13Smatt#endif /* __thumb__ */
751.1Sbjh21
761.2Smatt#define	CERROR		_C_LABEL(__cerror)
771.2Smatt#define	CURBRK		_C_LABEL(__curbrk)
781.2Smatt
791.1Sbjh21#define _SYSCALL_NOERROR(x,y)						\
801.1Sbjh21	ENTRY(x);							\
811.1Sbjh21	SYSTRAP(y)
821.1Sbjh21
831.13Smatt#if  !defined(__thumb__) || defined(_ARM_ARCH_T2)
841.13Smatt#define	_INVOKE_CERROR()	bcs CERROR
851.13Smatt#else
861.13Smatt#define	_INVOKE_CERROR()	\
871.14Smatt	bcc 86f; push {r3,lr}; bl CERROR; pop {r3,pc}; 86:
881.13Smatt#endif
891.1Sbjh21#define _SYSCALL(x, y)							\
901.1Sbjh21	_SYSCALL_NOERROR(x,y);						\
911.13Smatt	_INVOKE_CERROR()
921.1Sbjh21
931.1Sbjh21#define SYSCALL_NOERROR(x)						\
941.1Sbjh21	_SYSCALL_NOERROR(x,x)
951.1Sbjh21
961.1Sbjh21#define SYSCALL(x)							\
971.1Sbjh21	_SYSCALL(x,x)
981.1Sbjh21
991.1Sbjh21
1001.1Sbjh21#define PSEUDO_NOERROR(x,y)						\
1011.1Sbjh21	_SYSCALL_NOERROR(x,y);						\
1021.13Smatt	RET;								\
1031.13Smatt	END(x)
1041.1Sbjh21
1051.1Sbjh21#define PSEUDO(x,y)							\
1061.1Sbjh21	_SYSCALL(x,y);							\
1071.13Smatt	RET;								\
1081.13Smatt	END(x)
1091.1Sbjh21
1101.1Sbjh21
1111.1Sbjh21#define RSYSCALL_NOERROR(x)						\
1121.1Sbjh21	PSEUDO_NOERROR(x,x)
1131.1Sbjh21
1141.1Sbjh21#define RSYSCALL(x)							\
1151.1Sbjh21	PSEUDO(x,x)
1161.3Sthorpej
1171.3Sthorpej#ifdef WEAK_ALIAS
1181.3Sthorpej#define	WSYSCALL(weak,strong)						\
1191.3Sthorpej	WEAK_ALIAS(weak,strong);					\
1201.3Sthorpej	PSEUDO(strong,weak)
1211.3Sthorpej#else
1221.3Sthorpej#define	WSYSCALL(weak,strong)						\
1231.3Sthorpej	PSEUDO(weak,weak)
1241.3Sthorpej#endif
1251.1Sbjh21
1261.12Smatt	.hidden	CERROR
1271.2Smatt	.globl	CERROR
128