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