Home | History | Annotate | Line # | Download | only in sparc
SYS.h revision 1.15
      1   1.1       cgd /*-
      2   1.1       cgd  * Copyright (c) 1992, 1993
      3   1.1       cgd  *	The Regents of the University of California.  All rights reserved.
      4   1.1       cgd  *
      5   1.1       cgd  * This software was developed by the Computer Systems Engineering group
      6   1.1       cgd  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
      7   1.1       cgd  * contributed to Berkeley.
      8   1.1       cgd  *
      9   1.1       cgd  * Redistribution and use in source and binary forms, with or without
     10   1.1       cgd  * modification, are permitted provided that the following conditions
     11   1.1       cgd  * are met:
     12   1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     13   1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     14   1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     15   1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     16   1.1       cgd  *    documentation and/or other materials provided with the distribution.
     17  1.15       agc  * 3. Neither the name of the University nor the names of its contributors
     18   1.1       cgd  *    may be used to endorse or promote products derived from this software
     19   1.1       cgd  *    without specific prior written permission.
     20   1.1       cgd  *
     21   1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     22   1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23   1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24   1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     25   1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26   1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     27   1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     28   1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     29   1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30   1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31   1.1       cgd  * SUCH DAMAGE.
     32   1.1       cgd  *
     33   1.1       cgd  *	@(#)SYS.h	8.1 (Berkeley) 6/4/93
     34   1.1       cgd  *
     35   1.1       cgd  *	from: Header: SYS.h,v 1.2 92/07/03 18:57:00 torek Exp
     36  1.15       agc  *	$NetBSD: SYS.h,v 1.15 2003/08/07 16:42:23 agc Exp $
     37   1.1       cgd  */
     38   1.1       cgd 
     39   1.3        pk #include <machine/asm.h>
     40   1.1       cgd #include <sys/syscall.h>
     41   1.1       cgd #include <machine/trap.h>
     42   1.1       cgd 
     43  1.14       wiz #ifdef __STDC__
     44   1.2        pk #define _CAT(x,y) x##y
     45  1.14       wiz #else
     46  1.14       wiz #define _CAT(x,y) x/**/y
     47  1.14       wiz #endif
     48   1.2        pk 
     49   1.9    kleink #ifdef __ELF__
     50   1.9    kleink #define CERROR		_C_LABEL(__cerror)
     51   1.9    kleink #define CURBRK		_C_LABEL(__curbrk)
     52   1.9    kleink #else
     53   1.9    kleink #define CERROR		_ASM_LABEL(cerror)
     54   1.9    kleink #define CURBRK		_ASM_LABEL(curbrk)
     55   1.9    kleink #endif
     56   1.9    kleink 
     57   1.1       cgd /*
     58   1.1       cgd  * ERROR branches to cerror.  This is done with a macro so that I can
     59   1.1       cgd  * change it to be position independent later, if need be.
     60   1.1       cgd  */
     61   1.3        pk #ifdef PIC
     62  1.11  christos #define CALL(name) \
     63   1.3        pk 	PIC_PROLOGUE(%g1,%g2); \
     64  1.11  christos 	ld [%g1+name],%g2; jmp %g2; nop
     65   1.3        pk #else
     66  1.11  christos #define	CALL(name) \
     67  1.11  christos 	sethi %hi(name),%g1; or %lo(name),%g1,%g1; jmp %g1; nop
     68   1.3        pk #endif
     69  1.11  christos #define	ERROR() CALL(CERROR)
     70   1.1       cgd 
     71   1.1       cgd /*
     72   1.1       cgd  * SYSCALL is used when further action must be taken before returning.
     73   1.1       cgd  * Note that it adds a `nop' over what we could do, if we only knew what
     74   1.1       cgd  * came at label 1....
     75   1.1       cgd  */
     76  1.10    kleink #define	_SYSCALL(x,y) \
     77  1.10    kleink 	ENTRY(x); mov _CAT(SYS_,y),%g1; t ST_SYSCALL; bcc 1f; nop; ERROR(); 1:
     78  1.10    kleink 
     79   1.1       cgd #define	SYSCALL(x) \
     80  1.10    kleink 	_SYSCALL(x,x)
     81   1.1       cgd 
     82   1.1       cgd /*
     83   1.1       cgd  * RSYSCALL is used when the system call should just return.  Here
     84   1.1       cgd  * we use the SYSCALL_G2RFLAG to put the `success' return address in %g2
     85   1.1       cgd  * and avoid a branch.
     86   1.1       cgd  */
     87   1.1       cgd #define	RSYSCALL(x) \
     88   1.2        pk 	ENTRY(x); mov (_CAT(SYS_,x))|SYSCALL_G2RFLAG,%g1; add %o7,8,%g2; \
     89   1.1       cgd 	t ST_SYSCALL; ERROR()
     90   1.1       cgd 
     91   1.1       cgd /*
     92   1.1       cgd  * PSEUDO(x,y) is like RSYSCALL(y) except that the name is x.
     93   1.1       cgd  */
     94   1.1       cgd #define	PSEUDO(x,y) \
     95   1.2        pk 	ENTRY(x); mov (_CAT(SYS_,y))|SYSCALL_G2RFLAG,%g1; add %o7,8,%g2; \
     96   1.1       cgd 	t ST_SYSCALL; ERROR()
     97  1.12   thorpej 
     98  1.12   thorpej /*
     99  1.12   thorpej  * WSYSCALL(weak,strong) is like RSYSCALL(weak), except that weak is
    100  1.12   thorpej  * a weak internal alias for the strong symbol.
    101  1.12   thorpej  */
    102  1.12   thorpej #ifdef WEAK_ALIAS
    103  1.12   thorpej #define	WSYSCALL(weak,strong) \
    104  1.12   thorpej 	WEAK_ALIAS(weak,strong); \
    105  1.12   thorpej 	PSEUDO(strong,weak)
    106  1.12   thorpej #else
    107  1.12   thorpej #define	WSYSCALL(weak,strong) \
    108  1.12   thorpej 	RSYSCALL(weak)
    109  1.12   thorpej #endif
    110   1.4       jtc 
    111   1.4       jtc /*
    112   1.4       jtc  * SYSCALL_NOERROR is like SYSCALL, except it's used for syscalls
    113   1.4       jtc  * that never fail.
    114   1.4       jtc  *
    115   1.4       jtc  * XXX - This should be optimized.
    116   1.4       jtc  */
    117   1.4       jtc #define SYSCALL_NOERROR(x) \
    118   1.6        pk 	ENTRY(x); mov _CAT(SYS_,x),%g1; t ST_SYSCALL
    119   1.4       jtc 
    120   1.4       jtc /*
    121   1.4       jtc  * RSYSCALL_NOERROR is like RSYSCALL, except it's used for syscalls
    122   1.4       jtc  * that never fail.
    123   1.4       jtc  *
    124   1.4       jtc  * XXX - This should be optimized.
    125   1.4       jtc  */
    126   1.4       jtc #define RSYSCALL_NOERROR(x) \
    127   1.6        pk 	ENTRY(x); mov (_CAT(SYS_,x))|SYSCALL_G2RFLAG,%g1; add %o7,8,%g2; \
    128   1.7    kleink 	t ST_SYSCALL
    129   1.7    kleink 
    130   1.7    kleink /*
    131   1.7    kleink  * PSEUDO_NOERROR(x,y) is like RSYSCALL_NOERROR(y) except that the name is x.
    132   1.7    kleink  */
    133   1.8    kleink #define PSEUDO_NOERROR(x,y) \
    134   1.7    kleink 	ENTRY(x); mov (_CAT(SYS_,y))|SYSCALL_G2RFLAG,%g1; add %o7,8,%g2; \
    135   1.6        pk 	t ST_SYSCALL
    136   1.1       cgd 
    137   1.9    kleink 	.globl	CERROR
    138