Home | History | Annotate | Line # | Download | only in include
psl.h revision 1.29.8.3
      1  1.29.8.3  thorpej /*	$NetBSD: psl.h,v 1.29.8.3 2003/01/03 16:55:24 thorpej Exp $ */
      2  1.29.8.2  thorpej 
      3  1.29.8.2  thorpej /*
      4  1.29.8.2  thorpej  * Copyright (c) 1992, 1993
      5  1.29.8.2  thorpej  *	The Regents of the University of California.  All rights reserved.
      6  1.29.8.2  thorpej  *
      7  1.29.8.2  thorpej  * This software was developed by the Computer Systems Engineering group
      8  1.29.8.2  thorpej  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
      9  1.29.8.2  thorpej  * contributed to Berkeley.
     10  1.29.8.2  thorpej  *
     11  1.29.8.2  thorpej  * All advertising materials mentioning features or use of this software
     12  1.29.8.2  thorpej  * must display the following acknowledgement:
     13  1.29.8.2  thorpej  *	This product includes software developed by the University of
     14  1.29.8.2  thorpej  *	California, Lawrence Berkeley Laboratory.
     15  1.29.8.2  thorpej  *
     16  1.29.8.2  thorpej  * Redistribution and use in source and binary forms, with or without
     17  1.29.8.2  thorpej  * modification, are permitted provided that the following conditions
     18  1.29.8.2  thorpej  * are met:
     19  1.29.8.2  thorpej  * 1. Redistributions of source code must retain the above copyright
     20  1.29.8.2  thorpej  *    notice, this list of conditions and the following disclaimer.
     21  1.29.8.2  thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     22  1.29.8.2  thorpej  *    notice, this list of conditions and the following disclaimer in the
     23  1.29.8.2  thorpej  *    documentation and/or other materials provided with the distribution.
     24  1.29.8.2  thorpej  * 3. All advertising materials mentioning features or use of this software
     25  1.29.8.2  thorpej  *    must display the following acknowledgement:
     26  1.29.8.2  thorpej  *	This product includes software developed by the University of
     27  1.29.8.2  thorpej  *	California, Berkeley and its contributors.
     28  1.29.8.2  thorpej  * 4. Neither the name of the University nor the names of its contributors
     29  1.29.8.2  thorpej  *    may be used to endorse or promote products derived from this software
     30  1.29.8.2  thorpej  *    without specific prior written permission.
     31  1.29.8.2  thorpej  *
     32  1.29.8.2  thorpej  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     33  1.29.8.2  thorpej  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     34  1.29.8.2  thorpej  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     35  1.29.8.2  thorpej  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     36  1.29.8.2  thorpej  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     37  1.29.8.2  thorpej  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     38  1.29.8.2  thorpej  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     39  1.29.8.2  thorpej  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     40  1.29.8.2  thorpej  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     41  1.29.8.2  thorpej  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     42  1.29.8.2  thorpej  * SUCH DAMAGE.
     43  1.29.8.2  thorpej  *
     44  1.29.8.2  thorpej  *	@(#)psl.h	8.1 (Berkeley) 6/11/93
     45  1.29.8.2  thorpej  */
     46  1.29.8.2  thorpej 
     47  1.29.8.2  thorpej #ifndef PSR_IMPL
     48  1.29.8.2  thorpej 
     49  1.29.8.2  thorpej /*
     50  1.29.8.2  thorpej  * SPARC Process Status Register (in psl.h for hysterical raisins).  This
     51  1.29.8.2  thorpej  * doesn't exist on the V9.
     52  1.29.8.2  thorpej  *
     53  1.29.8.2  thorpej  * The picture in the Sun manuals looks like this:
     54  1.29.8.2  thorpej  *	                                     1 1
     55  1.29.8.2  thorpej  *	 31   28 27   24 23   20 19       14 3 2 11    8 7 6 5 4       0
     56  1.29.8.2  thorpej  *	+-------+-------+-------+-----------+-+-+-------+-+-+-+---------+
     57  1.29.8.2  thorpej  *	|  impl |  ver  |  icc  |  reserved |E|E|  pil  |S|P|E|   CWP   |
     58  1.29.8.2  thorpej  *	|       |       |n z v c|           |C|F|       | |S|T|         |
     59  1.29.8.2  thorpej  *	+-------+-------+-------+-----------+-+-+-------+-+-+-+---------+
     60  1.29.8.2  thorpej  */
     61  1.29.8.2  thorpej 
     62  1.29.8.2  thorpej #define PSR_IMPL	0xf0000000	/* implementation */
     63  1.29.8.2  thorpej #define PSR_VER		0x0f000000	/* version */
     64  1.29.8.2  thorpej #define PSR_ICC		0x00f00000	/* integer condition codes */
     65  1.29.8.2  thorpej #define PSR_N		0x00800000	/* negative */
     66  1.29.8.2  thorpej #define PSR_Z		0x00400000	/* zero */
     67  1.29.8.2  thorpej #define PSR_O		0x00200000	/* overflow */
     68  1.29.8.2  thorpej #define PSR_C		0x00100000	/* carry */
     69  1.29.8.2  thorpej #define PSR_EC		0x00002000	/* coprocessor enable */
     70  1.29.8.2  thorpej #define PSR_EF		0x00001000	/* FP enable */
     71  1.29.8.2  thorpej #define PSR_PIL		0x00000f00	/* interrupt level */
     72  1.29.8.2  thorpej #define PSR_S		0x00000080	/* supervisor (kernel) mode */
     73  1.29.8.2  thorpej #define PSR_PS		0x00000040	/* previous supervisor mode (traps) */
     74  1.29.8.2  thorpej #define PSR_ET		0x00000020	/* trap enable */
     75  1.29.8.2  thorpej #define PSR_CWP		0x0000001f	/* current window pointer */
     76  1.29.8.2  thorpej 
     77  1.29.8.2  thorpej #define PSR_BITS "\20\16EC\15EF\10S\7PS\6ET"
     78  1.29.8.2  thorpej 
     79  1.29.8.2  thorpej /* Interesting spl()s */
     80  1.29.8.2  thorpej #define PIL_FDSOFT	IPL_SOFTFDC	/* compat */
     81  1.29.8.2  thorpej #define PIL_AUSOFT	IPL_SOFTAUDIO	/* compat */
     82  1.29.8.2  thorpej #define PIL_TTY		6		/* compat */
     83  1.29.8.2  thorpej #define PIL_CLOCK	10
     84  1.29.8.2  thorpej #define PIL_FD		11
     85  1.29.8.2  thorpej #define PIL_SER		13
     86  1.29.8.2  thorpej #define	PIL_AUD		13
     87  1.29.8.2  thorpej #define PIL_HIGH	15
     88  1.29.8.2  thorpej #define PIL_LOCK	PIL_HIGH
     89  1.29.8.2  thorpej 
     90  1.29.8.2  thorpej /*
     91  1.29.8.2  thorpej  * SPARC V9 CCR register
     92  1.29.8.2  thorpej  */
     93  1.29.8.2  thorpej 
     94  1.29.8.2  thorpej #define ICC_C	0x01L
     95  1.29.8.2  thorpej #define ICC_V	0x02L
     96  1.29.8.2  thorpej #define ICC_Z	0x04L
     97  1.29.8.2  thorpej #define ICC_N	0x08L
     98  1.29.8.2  thorpej #define XCC_SHIFT	4
     99  1.29.8.2  thorpej #define XCC_C	(ICC_C<<XCC_SHIFT)
    100  1.29.8.2  thorpej #define XCC_V	(ICC_V<<XCC_SHIFT)
    101  1.29.8.2  thorpej #define XCC_Z	(ICC_Z<<XCC_SHIFT)
    102  1.29.8.2  thorpej #define XCC_N	(ICC_N<<XCC_SHIFT)
    103  1.29.8.2  thorpej 
    104  1.29.8.2  thorpej 
    105  1.29.8.2  thorpej /*
    106  1.29.8.2  thorpej  * SPARC V9 PSTATE register (what replaces the PSR in V9)
    107  1.29.8.2  thorpej  *
    108  1.29.8.2  thorpej  * Here's the layout:
    109  1.29.8.2  thorpej  *
    110  1.29.8.2  thorpej  *    11   10    9     8   7  6   5     4     3     2     1   0
    111  1.29.8.2  thorpej  *  +------------------------------------------------------------+
    112  1.29.8.2  thorpej  *  | IG | MG | CLE | TLE | MM | RED | PEF | AM | PRIV | IE | AG |
    113  1.29.8.2  thorpej  *  +------------------------------------------------------------+
    114  1.29.8.2  thorpej  */
    115  1.29.8.2  thorpej 
    116  1.29.8.2  thorpej #define PSTATE_IG	0x800	/* enable spitfire interrupt globals */
    117  1.29.8.2  thorpej #define PSTATE_MG	0x400	/* enable spitfire MMU globals */
    118  1.29.8.2  thorpej #define PSTATE_CLE	0x200	/* current little endian */
    119  1.29.8.2  thorpej #define PSTATE_TLE	0x100	/* traps little endian */
    120  1.29.8.2  thorpej #define PSTATE_MM	0x0c0	/* memory model */
    121  1.29.8.2  thorpej #define PSTATE_MM_TSO	0x000	/* total store order */
    122  1.29.8.2  thorpej #define PSTATE_MM_PSO	0x040	/* partial store order */
    123  1.29.8.2  thorpej #define PSTATE_MM_RMO	0x080	/* Relaxed memory order */
    124  1.29.8.2  thorpej #define PSTATE_RED	0x020	/* RED state */
    125  1.29.8.2  thorpej #define PSTATE_PEF	0x010	/* enable floating point */
    126  1.29.8.2  thorpej #define PSTATE_AM	0x008	/* 32-bit address masking */
    127  1.29.8.2  thorpej #define PSTATE_PRIV	0x004	/* privileged mode */
    128  1.29.8.2  thorpej #define PSTATE_IE	0x002	/* interrupt enable */
    129  1.29.8.2  thorpej #define PSTATE_AG	0x001	/* enable alternate globals */
    130  1.29.8.2  thorpej 
    131  1.29.8.2  thorpej #define PSTATE_BITS "\20\14IG\13MG\12CLE\11TLE\10\7MM\6RED\5PEF\4AM\3PRIV\2IE\1AG"
    132  1.29.8.2  thorpej 
    133  1.29.8.2  thorpej 
    134  1.29.8.2  thorpej /*
    135  1.29.8.2  thorpej  * 32-bit code requires TSO or at best PSO since that's what's supported on
    136  1.29.8.2  thorpej  * SPARC V8 and earlier machines.
    137  1.29.8.2  thorpej  *
    138  1.29.8.2  thorpej  * 64-bit code sets the memory model in the ELF header.
    139  1.29.8.2  thorpej  *
    140  1.29.8.2  thorpej  * We're running kernel code in TSO for the moment so we don't need to worry
    141  1.29.8.2  thorpej  * about possible memory barrier bugs.
    142  1.29.8.2  thorpej  */
    143  1.29.8.2  thorpej 
    144  1.29.8.2  thorpej #ifdef __arch64__
    145  1.29.8.2  thorpej #define PSTATE_PROM	(PSTATE_MM_TSO|PSTATE_PRIV)
    146  1.29.8.2  thorpej #define PSTATE_NUCLEUS	(PSTATE_MM_TSO|PSTATE_PRIV|PSTATE_AG)
    147  1.29.8.2  thorpej #define PSTATE_KERN	(PSTATE_MM_TSO|PSTATE_PRIV)
    148  1.29.8.2  thorpej #define PSTATE_INTR	(PSTATE_KERN|PSTATE_IE)
    149  1.29.8.2  thorpej #define PSTATE_USER32	(PSTATE_MM_TSO|PSTATE_AM|PSTATE_IE)
    150  1.29.8.2  thorpej #define PSTATE_USER	(PSTATE_MM_RMO|PSTATE_IE)
    151  1.29.8.2  thorpej #else
    152  1.29.8.2  thorpej #define PSTATE_PROM	(PSTATE_MM_TSO|PSTATE_PRIV)
    153  1.29.8.2  thorpej #define PSTATE_NUCLEUS	(PSTATE_MM_TSO|PSTATE_AM|PSTATE_PRIV|PSTATE_AG)
    154  1.29.8.2  thorpej #define PSTATE_KERN	(PSTATE_MM_TSO|PSTATE_AM|PSTATE_PRIV)
    155  1.29.8.2  thorpej #define PSTATE_INTR	(PSTATE_KERN|PSTATE_IE)
    156  1.29.8.2  thorpej #define PSTATE_USER32	(PSTATE_MM_TSO|PSTATE_AM|PSTATE_IE)
    157  1.29.8.2  thorpej #define PSTATE_USER	(PSTATE_MM_TSO|PSTATE_AM|PSTATE_IE)
    158  1.29.8.2  thorpej #endif
    159  1.29.8.2  thorpej 
    160  1.29.8.2  thorpej /*
    161  1.29.8.2  thorpej  * SPARC V9 TSTATE register
    162  1.29.8.2  thorpej  *
    163  1.29.8.2  thorpej  *   39 32 31 24 23 18  17   8	7 5 4   0
    164  1.29.8.2  thorpej  *  +-----+-----+-----+--------+---+-----+
    165  1.29.8.2  thorpej  *  | CCR | ASI |  -  | PSTATE | - | CWP |
    166  1.29.8.2  thorpej  *  +-----+-----+-----+--------+---+-----+
    167  1.29.8.2  thorpej  * */
    168  1.29.8.2  thorpej 
    169  1.29.8.2  thorpej #define TSTATE_CWP		0x01f
    170  1.29.8.2  thorpej #define TSTATE_PSTATE		0x6ff00
    171  1.29.8.2  thorpej #define TSTATE_PSTATE_SHIFT	8
    172  1.29.8.2  thorpej #define TSTATE_ASI		0xff000000LL
    173  1.29.8.2  thorpej #define TSTATE_ASI_SHIFT	24
    174  1.29.8.2  thorpej #define TSTATE_CCR		0xff00000000LL
    175  1.29.8.2  thorpej #define TSTATE_CCR_SHIFT	32
    176  1.29.8.2  thorpej 
    177  1.29.8.2  thorpej #define PSRCC_TO_TSTATE(x)	(((int64_t)(x)&PSR_ICC)<<(TSTATE_CCR_SHIFT-19))
    178  1.29.8.2  thorpej #define TSTATECCR_TO_PSR(x)	(((x)&TSTATE_CCR)>>(TSTATE_CCR_SHIFT-19))
    179  1.29.8.2  thorpej 
    180  1.29.8.2  thorpej /*
    181  1.29.8.2  thorpej  * These are here to simplify life.
    182  1.29.8.2  thorpej  */
    183  1.29.8.2  thorpej #define TSTATE_IG	(PSTATE_IG<<TSTATE_PSTATE_SHIFT)
    184  1.29.8.2  thorpej #define TSTATE_MG	(PSTATE_MG<<TSTATE_PSTATE_SHIFT)
    185  1.29.8.2  thorpej #define TSTATE_CLE	(PSTATE_CLE<<TSTATE_PSTATE_SHIFT)
    186  1.29.8.2  thorpej #define TSTATE_TLE	(PSTATE_TLE<<TSTATE_PSTATE_SHIFT)
    187  1.29.8.2  thorpej #define TSTATE_MM	(PSTATE_MM<<TSTATE_PSTATE_SHIFT)
    188  1.29.8.2  thorpej #define TSTATE_MM_TSO	(PSTATE_MM_TSO<<TSTATE_PSTATE_SHIFT)
    189  1.29.8.2  thorpej #define TSTATE_MM_PSO	(PSTATE_MM_PSO<<TSTATE_PSTATE_SHIFT)
    190  1.29.8.2  thorpej #define TSTATE_MM_RMO	(PSTATE_MM_RMO<<TSTATE_PSTATE_SHIFT)
    191  1.29.8.2  thorpej #define TSTATE_RED	(PSTATE_RED<<TSTATE_PSTATE_SHIFT)
    192  1.29.8.2  thorpej #define TSTATE_PEF	(PSTATE_PEF<<TSTATE_PSTATE_SHIFT)
    193  1.29.8.2  thorpej #define TSTATE_AM	(PSTATE_AM<<TSTATE_PSTATE_SHIFT)
    194  1.29.8.2  thorpej #define TSTATE_PRIV	(PSTATE_PRIV<<TSTATE_PSTATE_SHIFT)
    195  1.29.8.2  thorpej #define TSTATE_IE	(PSTATE_IE<<TSTATE_PSTATE_SHIFT)
    196  1.29.8.2  thorpej #define TSTATE_AG	(PSTATE_AG<<TSTATE_PSTATE_SHIFT)
    197  1.29.8.2  thorpej 
    198  1.29.8.2  thorpej #define TSTATE_BITS "\20\14IG\13MG\12CLE\11TLE\10\7MM\6RED\5PEF\4AM\3PRIV\2IE\1AG"
    199  1.29.8.2  thorpej 
    200  1.29.8.2  thorpej #define TSTATE_KERN	((TSTATE_KERN)<<TSTATE_PSTATE_SHIFT)
    201  1.29.8.2  thorpej #define TSTATE_USER	((TSTATE_USER)<<TSTATE_PSTATE_SHIFT)
    202  1.29.8.2  thorpej /*
    203  1.29.8.2  thorpej  * SPARC V9 VER version register.
    204  1.29.8.2  thorpej  *
    205  1.29.8.2  thorpej  *  63   48 47  32 31  24 23 16 15    8 7 5 4      0
    206  1.29.8.2  thorpej  * +-------+------+------+-----+-------+---+--------+
    207  1.29.8.2  thorpej  * | manuf | impl | mask |  -  | maxtl | - | maxwin |
    208  1.29.8.2  thorpej  * +-------+------+------+-----+-------+---+--------+
    209  1.29.8.2  thorpej  *
    210  1.29.8.2  thorpej  */
    211  1.29.8.2  thorpej 
    212  1.29.8.2  thorpej #define VER_MANUF	0xffff000000000000LL
    213  1.29.8.2  thorpej #define VER_MANUF_SHIFT	48
    214  1.29.8.2  thorpej #define VER_IMPL	0x0000ffff00000000LL
    215  1.29.8.2  thorpej #define VER_IMPL_SHIFT	32
    216  1.29.8.2  thorpej #define VER_MASK	0x00000000ff000000LL
    217  1.29.8.2  thorpej #define VER_MASK_SHIFT	24
    218  1.29.8.2  thorpej #define VER_MAXTL	0x000000000000ff00LL
    219  1.29.8.2  thorpej #define VER_MAXTL_SHIFT	8
    220  1.29.8.2  thorpej #define VER_MAXWIN	0x000000000000001fLL
    221  1.29.8.2  thorpej 
    222  1.29.8.2  thorpej /*
    223  1.29.8.2  thorpej  * Here are a few things to help us transition between user and kernel mode:
    224  1.29.8.2  thorpej  */
    225  1.29.8.2  thorpej 
    226  1.29.8.2  thorpej /* Memory models */
    227  1.29.8.2  thorpej #define KERN_MM		PSTATE_MM_TSO
    228  1.29.8.2  thorpej #define USER_MM		PSTATE_MM_RMO
    229  1.29.8.2  thorpej 
    230  1.29.8.2  thorpej /*
    231  1.29.8.2  thorpej  * Register window handlers.  These point to generic routines that check the
    232  1.29.8.2  thorpej  * stack pointer and then vector to the real handler.  We could optimize this
    233  1.29.8.2  thorpej  * if we could guarantee only 32-bit or 64-bit stacks.
    234  1.29.8.2  thorpej  */
    235  1.29.8.2  thorpej #define WSTATE_KERN	026
    236  1.29.8.2  thorpej #define WSTATE_USER	022
    237  1.29.8.2  thorpej 
    238  1.29.8.2  thorpej #define CWP		0x01f
    239  1.29.8.2  thorpej 
    240  1.29.8.2  thorpej /* 64-byte alignment -- this seems the best place to put this. */
    241  1.29.8.2  thorpej #define BLOCK_SIZE	64
    242  1.29.8.2  thorpej #define BLOCK_ALIGN	0x3f
    243  1.29.8.2  thorpej 
    244  1.29.8.2  thorpej #if defined(_KERNEL) && !defined(_LOCORE)
    245  1.29.8.2  thorpej 
    246  1.29.8.2  thorpej static __inline int getpsr __P((void));
    247  1.29.8.2  thorpej static __inline void setpsr __P((int));
    248  1.29.8.2  thorpej static __inline void spl0 __P((void));
    249  1.29.8.2  thorpej static __inline int splhigh __P((void));
    250  1.29.8.2  thorpej static __inline void splx __P((int));
    251  1.29.8.2  thorpej static __inline int getmid __P((void));
    252  1.29.8.2  thorpej 
    253  1.29.8.2  thorpej /*
    254  1.29.8.2  thorpej  * GCC pseudo-functions for manipulating PSR (primarily PIL field).
    255  1.29.8.2  thorpej  */
    256  1.29.8.2  thorpej static __inline int getpsr()
    257  1.29.8.2  thorpej {
    258  1.29.8.2  thorpej 	int psr;
    259  1.29.8.2  thorpej 
    260  1.29.8.2  thorpej 	__asm __volatile("rd %%psr,%0" : "=r" (psr));
    261  1.29.8.2  thorpej 	return (psr);
    262  1.29.8.2  thorpej }
    263  1.29.8.2  thorpej 
    264  1.29.8.2  thorpej static __inline int getmid()
    265  1.29.8.2  thorpej {
    266  1.29.8.2  thorpej 	int mid;
    267  1.29.8.2  thorpej 
    268  1.29.8.2  thorpej 	__asm __volatile("rd %%tbr,%0" : "=r" (mid));
    269  1.29.8.2  thorpej 	return ((mid >> 20) & 0x3);
    270  1.29.8.2  thorpej }
    271  1.29.8.2  thorpej 
    272  1.29.8.2  thorpej static __inline void setpsr(newpsr)
    273  1.29.8.2  thorpej 	int newpsr;
    274  1.29.8.2  thorpej {
    275  1.29.8.2  thorpej 	__asm __volatile("wr %0,0,%%psr" : : "r" (newpsr));
    276  1.29.8.2  thorpej 	__asm __volatile("nop; nop; nop");
    277  1.29.8.2  thorpej }
    278  1.29.8.2  thorpej 
    279  1.29.8.2  thorpej static __inline void spl0()
    280  1.29.8.2  thorpej {
    281  1.29.8.2  thorpej 	int psr, oldipl;
    282  1.29.8.2  thorpej 
    283  1.29.8.2  thorpej 	/*
    284  1.29.8.2  thorpej 	 * wrpsr xors two values: we choose old psr and old ipl here,
    285  1.29.8.2  thorpej 	 * which gives us the same value as the old psr but with all
    286  1.29.8.2  thorpej 	 * the old PIL bits turned off.
    287  1.29.8.2  thorpej 	 */
    288  1.29.8.2  thorpej 	__asm __volatile("rd %%psr,%0" : "=r" (psr));
    289  1.29.8.2  thorpej 	oldipl = psr & PSR_PIL;
    290  1.29.8.2  thorpej 	__asm __volatile("wr %0,%1,%%psr" : : "r" (psr), "r" (oldipl));
    291  1.29.8.2  thorpej 
    292  1.29.8.2  thorpej 	/*
    293  1.29.8.2  thorpej 	 * Three instructions must execute before we can depend
    294  1.29.8.2  thorpej 	 * on the bits to be changed.
    295  1.29.8.2  thorpej 	 */
    296  1.29.8.2  thorpej 	__asm __volatile("nop; nop; nop");
    297  1.29.8.2  thorpej }
    298  1.29.8.2  thorpej 
    299  1.29.8.2  thorpej /*
    300  1.29.8.2  thorpej  * PIL 1 through 14 can use this macro.
    301  1.29.8.2  thorpej  * (spl0 and splhigh are special since they put all 0s or all 1s
    302  1.29.8.2  thorpej  * into the ipl field.)
    303  1.29.8.2  thorpej  */
    304  1.29.8.2  thorpej #define	_SPLSET(name, newipl) \
    305  1.29.8.2  thorpej static __inline void name __P((void)); \
    306  1.29.8.2  thorpej static __inline void name() \
    307  1.29.8.2  thorpej { \
    308  1.29.8.2  thorpej 	int psr, oldipl; \
    309  1.29.8.2  thorpej 	__asm __volatile("rd %%psr,%0" : "=r" (psr)); \
    310  1.29.8.2  thorpej 	oldipl = psr & PSR_PIL; \
    311  1.29.8.2  thorpej 	psr &= ~oldipl; \
    312  1.29.8.2  thorpej 	__asm __volatile("wr %0,%1,%%psr" : : \
    313  1.29.8.2  thorpej 	    "r" (psr), "n" ((newipl) << 8)); \
    314  1.29.8.2  thorpej 	__asm __volatile("nop; nop; nop"); \
    315  1.29.8.2  thorpej }
    316  1.29.8.2  thorpej 
    317  1.29.8.2  thorpej /* Raise IPL and return previous value */
    318  1.29.8.2  thorpej #define	_SPLRAISE(name, newipl) \
    319  1.29.8.2  thorpej static __inline int name __P((void)); \
    320  1.29.8.2  thorpej static __inline int name() \
    321  1.29.8.2  thorpej { \
    322  1.29.8.2  thorpej 	int psr, oldipl; \
    323  1.29.8.2  thorpej 	__asm __volatile("rd %%psr,%0" : "=r" (psr)); \
    324  1.29.8.2  thorpej 	oldipl = psr & PSR_PIL; \
    325  1.29.8.2  thorpej 	if ((newipl << 8) <= oldipl) \
    326  1.29.8.2  thorpej 		return (oldipl); \
    327  1.29.8.2  thorpej 	psr &= ~oldipl; \
    328  1.29.8.2  thorpej 	__asm __volatile("wr %0,%1,%%psr" : : \
    329  1.29.8.2  thorpej 	    "r" (psr), "n" ((newipl) << 8)); \
    330  1.29.8.2  thorpej 	__asm __volatile("nop; nop; nop"); \
    331  1.29.8.2  thorpej 	return (oldipl); \
    332  1.29.8.2  thorpej }
    333  1.29.8.2  thorpej 
    334  1.29.8.2  thorpej _SPLSET(spllowersoftclock, 1)
    335  1.29.8.2  thorpej 
    336  1.29.8.2  thorpej _SPLRAISE(splsoftint, 1)
    337  1.29.8.2  thorpej #define	splsoftclock	splsoftint
    338  1.29.8.2  thorpej #define	splsoftnet	splsoftint
    339  1.29.8.2  thorpej 
    340  1.29.8.2  thorpej 
    341  1.29.8.2  thorpej /* audio software interrupts */
    342  1.29.8.2  thorpej _SPLRAISE(splausoft, IPL_SOFTAUDIO)
    343  1.29.8.2  thorpej 
    344  1.29.8.2  thorpej /* floppy software interrupts */
    345  1.29.8.2  thorpej _SPLRAISE(splfdsoft, IPL_SOFTFDC)
    346  1.29.8.2  thorpej 
    347  1.29.8.2  thorpej /* Block devices */
    348  1.29.8.2  thorpej _SPLRAISE(splbio, IPL_BIO)
    349  1.29.8.2  thorpej 
    350  1.29.8.2  thorpej /* tty input runs at software level 6 */
    351  1.29.8.2  thorpej _SPLRAISE(spltty, IPL_TTY)
    352  1.29.8.2  thorpej 
    353  1.29.8.2  thorpej /* network hardware interrupts are at level 7 */
    354  1.29.8.2  thorpej _SPLRAISE(splnet, IPL_NET)
    355  1.29.8.2  thorpej 
    356  1.29.8.2  thorpej /*
    357  1.29.8.2  thorpej  * Memory allocation (must be as high as highest network, tty, or disk device)
    358  1.29.8.2  thorpej  */
    359  1.29.8.2  thorpej _SPLRAISE(splvm, IPL_IMP)
    360  1.29.8.2  thorpej 
    361  1.29.8.2  thorpej /* clock interrupts at level 10 */
    362  1.29.8.2  thorpej _SPLRAISE(splclock, IPL_CLOCK)
    363  1.29.8.2  thorpej 
    364  1.29.8.3  thorpej _SPLRAISE(splsched, IPL_SCHED)
    365  1.29.8.3  thorpej 
    366  1.29.8.2  thorpej /* fd hardware, ts102, and tadpole microcontoller interrupts are at level 11 */
    367  1.29.8.2  thorpej _SPLRAISE(splfd, 11)
    368  1.29.8.2  thorpej _SPLRAISE(splts102, 11)
    369  1.29.8.2  thorpej 
    370  1.29.8.2  thorpej /*
    371  1.29.8.2  thorpej  * zs hardware interrupts are at level 12
    372  1.29.8.2  thorpej  * su (com) hardware interrupts are at level 13
    373  1.29.8.2  thorpej  * IPL_SERIAL must protect them all.
    374  1.29.8.2  thorpej  */
    375  1.29.8.2  thorpej _SPLRAISE(splzs, 12)
    376  1.29.8.2  thorpej 
    377  1.29.8.2  thorpej _SPLRAISE(splserial, IPL_SERIAL)
    378  1.29.8.2  thorpej 
    379  1.29.8.2  thorpej /* audio hardware interrupts are at level 13 */
    380  1.29.8.2  thorpej _SPLRAISE(splaudio, IPL_AUDIO)
    381  1.29.8.2  thorpej 
    382  1.29.8.2  thorpej /* second sparc timer interrupts at level 14 */
    383  1.29.8.2  thorpej _SPLRAISE(splstatclock, IPL_STATCLOCK)
    384  1.29.8.2  thorpej 
    385  1.29.8.2  thorpej static __inline int splhigh()
    386  1.29.8.2  thorpej {
    387  1.29.8.2  thorpej 	int psr, oldipl;
    388  1.29.8.2  thorpej 
    389  1.29.8.2  thorpej 	__asm __volatile("rd %%psr,%0" : "=r" (psr));
    390  1.29.8.2  thorpej 	__asm __volatile("wr %0,0,%%psr" : : "r" (psr | PSR_PIL));
    391  1.29.8.2  thorpej 	__asm __volatile("and %1,%2,%0; nop; nop" : "=r" (oldipl) : \
    392  1.29.8.2  thorpej 	    "r" (psr), "n" (PSR_PIL));
    393  1.29.8.2  thorpej 	return (oldipl);
    394  1.29.8.2  thorpej }
    395  1.29.8.2  thorpej 
    396  1.29.8.2  thorpej #define	spllock()	splhigh()
    397  1.29.8.2  thorpej 
    398  1.29.8.2  thorpej /* splx does not have a return value */
    399  1.29.8.2  thorpej static __inline void splx(newipl)
    400  1.29.8.2  thorpej 	int newipl;
    401  1.29.8.2  thorpej {
    402  1.29.8.2  thorpej 	int psr;
    403  1.29.8.2  thorpej 
    404  1.29.8.2  thorpej 	__asm __volatile("rd %%psr,%0" : "=r" (psr));
    405  1.29.8.2  thorpej 	__asm __volatile("wr %0,%1,%%psr" : : \
    406  1.29.8.2  thorpej 	    "r" (psr & ~PSR_PIL), "rn" (newipl));
    407  1.29.8.2  thorpej 	__asm __volatile("nop; nop; nop");
    408  1.29.8.2  thorpej }
    409  1.29.8.2  thorpej #endif /* KERNEL && !_LOCORE */
    410  1.29.8.2  thorpej 
    411  1.29.8.2  thorpej #endif /* PSR_IMPL */
    412