Home | History | Annotate | Line # | Download | only in include
psl.h revision 1.20.2.1
      1  1.20.2.1   minoura /*	$NetBSD: psl.h,v 1.20.2.1 2000/06/22 17:04:04 minoura 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.1   deraadt  * SPARC Process Status Register (in psl.h for hysterical raisins).
     51       1.1   deraadt  *
     52       1.1   deraadt  * The picture in the Sun manuals looks like this:
     53       1.1   deraadt  *	                                     1 1
     54       1.1   deraadt  *	 31   28 27   24 23   20 19       14 3 2 11    8 7 6 5 4       0
     55       1.1   deraadt  *	+-------+-------+-------+-----------+-+-+-------+-+-+-+---------+
     56       1.1   deraadt  *	|  impl |  ver  |  icc  |  reserved |E|E|  pil  |S|P|E|   CWP   |
     57       1.1   deraadt  *	|       |       |n z v c|           |C|F|       | |S|T|         |
     58       1.1   deraadt  *	+-------+-------+-------+-----------+-+-+-------+-+-+-+---------+
     59       1.1   deraadt  */
     60       1.1   deraadt 
     61       1.1   deraadt #define	PSR_IMPL	0xf0000000	/* implementation */
     62       1.1   deraadt #define	PSR_VER		0x0f000000	/* version */
     63       1.1   deraadt #define	PSR_ICC		0x00f00000	/* integer condition codes */
     64       1.1   deraadt #define	PSR_N		0x00800000	/* negative */
     65       1.1   deraadt #define	PSR_Z		0x00400000	/* zero */
     66       1.1   deraadt #define	PSR_O		0x00200000	/* overflow */
     67       1.1   deraadt #define	PSR_C		0x00100000	/* carry */
     68       1.1   deraadt #define	PSR_EC		0x00002000	/* coprocessor enable */
     69       1.1   deraadt #define	PSR_EF		0x00001000	/* FP enable */
     70       1.1   deraadt #define	PSR_PIL		0x00000f00	/* interrupt level */
     71       1.1   deraadt #define	PSR_S		0x00000080	/* supervisor (kernel) mode */
     72       1.1   deraadt #define	PSR_PS		0x00000040	/* previous supervisor mode (traps) */
     73       1.1   deraadt #define	PSR_ET		0x00000020	/* trap enable */
     74       1.1   deraadt #define	PSR_CWP		0x0000001f	/* current window pointer */
     75       1.1   deraadt 
     76       1.1   deraadt #define	PSR_BITS "\20\16EC\15EF\10S\7PS\6ET"
     77       1.1   deraadt 
     78      1.20        pk /* define audio software interrupts to be at software level 4 */
     79      1.20        pk #define	PIL_AUSOFT	4
     80      1.20        pk /* define floppy software interrupts to be at software level 4 too */
     81      1.20        pk #define PIL_FDSOFT	4
     82      1.20        pk /* network hardware interrupts at at most (XXX - is that true?) level 6 */
     83      1.20        pk #define	PIL_NET		6
     84      1.15       mrg #define	PIL_CLOCK	10
     85      1.15       mrg 
     86       1.8   mycroft #if defined(_KERNEL) && !defined(_LOCORE)
     87      1.10  christos 
     88      1.10  christos static __inline int getpsr __P((void));
     89      1.10  christos static __inline void setpsr __P((int));
     90  1.20.2.1   minoura static __inline void spl0 __P((void));
     91      1.10  christos static __inline int splhigh __P((void));
     92      1.10  christos static __inline void splx __P((int));
     93      1.12        pk static __inline int getmid __P((void));
     94      1.10  christos 
     95       1.1   deraadt /*
     96       1.1   deraadt  * GCC pseudo-functions for manipulating PSR (primarily PIL field).
     97       1.1   deraadt  */
     98      1.10  christos static __inline int getpsr()
     99      1.10  christos {
    100       1.1   deraadt 	int psr;
    101       1.1   deraadt 
    102       1.1   deraadt 	__asm __volatile("rd %%psr,%0" : "=r" (psr));
    103       1.1   deraadt 	return (psr);
    104      1.12        pk }
    105      1.12        pk 
    106      1.12        pk static __inline int getmid()
    107      1.12        pk {
    108      1.12        pk 	int mid;
    109      1.12        pk 
    110      1.12        pk 	__asm __volatile("rd %%tbr,%0" : "=r" (mid));
    111      1.12        pk 	return ((mid >> 20) & 0x3);
    112       1.1   deraadt }
    113       1.1   deraadt 
    114      1.10  christos static __inline void setpsr(newpsr)
    115      1.10  christos 	int newpsr;
    116      1.10  christos {
    117       1.1   deraadt 	__asm __volatile("wr %0,0,%%psr" : : "r" (newpsr));
    118  1.20.2.1   minoura 	__asm __volatile("nop; nop; nop");
    119       1.1   deraadt }
    120       1.1   deraadt 
    121  1.20.2.1   minoura static __inline void spl0()
    122      1.10  christos {
    123       1.1   deraadt 	int psr, oldipl;
    124       1.1   deraadt 
    125       1.1   deraadt 	/*
    126       1.1   deraadt 	 * wrpsr xors two values: we choose old psr and old ipl here,
    127       1.1   deraadt 	 * which gives us the same value as the old psr but with all
    128       1.1   deraadt 	 * the old PIL bits turned off.
    129       1.1   deraadt 	 */
    130       1.1   deraadt 	__asm __volatile("rd %%psr,%0" : "=r" (psr));
    131       1.1   deraadt 	oldipl = psr & PSR_PIL;
    132       1.1   deraadt 	__asm __volatile("wr %0,%1,%%psr" : : "r" (psr), "r" (oldipl));
    133       1.1   deraadt 
    134       1.1   deraadt 	/*
    135       1.1   deraadt 	 * Three instructions must execute before we can depend
    136       1.1   deraadt 	 * on the bits to be changed.
    137       1.1   deraadt 	 */
    138       1.1   deraadt 	__asm __volatile("nop; nop; nop");
    139       1.1   deraadt }
    140       1.1   deraadt 
    141       1.1   deraadt /*
    142       1.1   deraadt  * PIL 1 through 14 can use this macro.
    143       1.1   deraadt  * (spl0 and splhigh are special since they put all 0s or all 1s
    144       1.1   deraadt  * into the ipl field.)
    145       1.1   deraadt  */
    146  1.20.2.1   minoura #define	_SPLSET(name, newipl) \
    147  1.20.2.1   minoura static __inline void name __P((void)); \
    148  1.20.2.1   minoura static __inline void name() \
    149      1.10  christos { \
    150       1.1   deraadt 	int psr, oldipl; \
    151       1.1   deraadt 	__asm __volatile("rd %%psr,%0" : "=r" (psr)); \
    152       1.1   deraadt 	oldipl = psr & PSR_PIL; \
    153       1.1   deraadt 	psr &= ~oldipl; \
    154       1.1   deraadt 	__asm __volatile("wr %0,%1,%%psr" : : \
    155       1.1   deraadt 	    "r" (psr), "n" ((newipl) << 8)); \
    156       1.1   deraadt 	__asm __volatile("nop; nop; nop"); \
    157       1.1   deraadt }
    158  1.20.2.1   minoura 
    159  1.20.2.1   minoura /* Raise IPL and return previous value */
    160      1.13        pk #define	_SPLRAISE(name, newipl) \
    161      1.11        pk static __inline int name __P((void)); \
    162      1.11        pk static __inline int name() \
    163      1.11        pk { \
    164      1.11        pk 	int psr, oldipl; \
    165      1.11        pk 	__asm __volatile("rd %%psr,%0" : "=r" (psr)); \
    166      1.11        pk 	oldipl = psr & PSR_PIL; \
    167      1.11        pk 	if ((newipl << 8) <= oldipl) \
    168  1.20.2.1   minoura 		return (oldipl); \
    169      1.11        pk 	psr &= ~oldipl; \
    170      1.11        pk 	__asm __volatile("wr %0,%1,%%psr" : : \
    171      1.11        pk 	    "r" (psr), "n" ((newipl) << 8)); \
    172      1.11        pk 	__asm __volatile("nop; nop; nop"); \
    173      1.11        pk 	return (oldipl); \
    174      1.11        pk }
    175       1.1   deraadt 
    176  1.20.2.1   minoura _SPLSET(spllowersoftclock, 1)
    177      1.18   thorpej 
    178      1.18   thorpej _SPLRAISE(splsoftint, 1)
    179      1.18   thorpej #define	splsoftclock	splsoftint
    180       1.7   mycroft #define	splsoftnet	splsoftint
    181       1.7   mycroft 
    182      1.20        pk 
    183      1.20        pk /* audio software interrupts */
    184      1.18   thorpej _SPLRAISE(splausoft, PIL_AUSOFT)
    185       1.9        pk 
    186      1.20        pk /* floppy software interrupts */
    187      1.18   thorpej _SPLRAISE(splfdsoft, PIL_FDSOFT)
    188       1.9        pk 
    189       1.9        pk /* Block devices */
    190      1.18   thorpej _SPLRAISE(splbio, 5)
    191       1.9        pk 
    192       1.7   mycroft /* network hardware interrupts are at level 6 */
    193      1.18   thorpej _SPLRAISE(splnet, PIL_NET)
    194       1.1   deraadt 
    195       1.1   deraadt /* tty input runs at software level 6 */
    196       1.1   deraadt #define	PIL_TTY	6
    197      1.18   thorpej _SPLRAISE(spltty, PIL_TTY)
    198       1.3   deraadt 
    199       1.9        pk /*
    200       1.9        pk  * Memory allocation (must be as high as highest network, tty, or disk device)
    201       1.9        pk  */
    202      1.18   thorpej _SPLRAISE(splimp, 7)
    203      1.18   thorpej _SPLRAISE(splpmap, 7)
    204       1.1   deraadt 
    205      1.14       mrg /* clock interrupts at level 10 */
    206      1.18   thorpej _SPLRAISE(splclock, PIL_CLOCK)
    207       1.5        pk 
    208      1.19   garbled /* fd hardware, ts102, and tadpole microcontoller interrupts are at level 11 */
    209      1.18   thorpej _SPLRAISE(splfd, 11)
    210      1.19   garbled _SPLRAISE(splts102, 11)
    211       1.1   deraadt 
    212       1.1   deraadt /* zs hardware interrupts are at level 12 */
    213      1.18   thorpej _SPLRAISE(splzs, 12)
    214      1.18   thorpej _SPLRAISE(splserial, 12) /* XXX - other serial hardware might not be at lvl 12 */
    215       1.1   deraadt 
    216       1.1   deraadt /* audio hardware interrupts are at level 13 */
    217      1.18   thorpej _SPLRAISE(splaudio, 13)
    218       1.1   deraadt 
    219       1.1   deraadt /* second sparc timer interrupts at level 14 */
    220      1.18   thorpej _SPLRAISE(splstatclock, 14)
    221       1.1   deraadt 
    222      1.10  christos static __inline int splhigh()
    223      1.10  christos {
    224       1.1   deraadt 	int psr, oldipl;
    225       1.1   deraadt 
    226       1.1   deraadt 	__asm __volatile("rd %%psr,%0" : "=r" (psr));
    227       1.1   deraadt 	__asm __volatile("wr %0,0,%%psr" : : "r" (psr | PSR_PIL));
    228       1.1   deraadt 	__asm __volatile("and %1,%2,%0; nop; nop" : "=r" (oldipl) : \
    229       1.1   deraadt 	    "r" (psr), "n" (PSR_PIL));
    230       1.1   deraadt 	return (oldipl);
    231       1.1   deraadt }
    232       1.1   deraadt 
    233       1.1   deraadt /* splx does not have a return value */
    234      1.10  christos static __inline void splx(newipl)
    235      1.10  christos 	int newipl;
    236      1.10  christos {
    237       1.1   deraadt 	int psr;
    238       1.1   deraadt 
    239       1.1   deraadt 	__asm __volatile("rd %%psr,%0" : "=r" (psr));
    240       1.1   deraadt 	__asm __volatile("wr %0,%1,%%psr" : : \
    241       1.1   deraadt 	    "r" (psr & ~PSR_PIL), "rn" (newipl));
    242       1.1   deraadt 	__asm __volatile("nop; nop; nop");
    243       1.1   deraadt }
    244       1.8   mycroft #endif /* KERNEL && !_LOCORE */
    245       1.1   deraadt 
    246       1.1   deraadt #endif /* PSR_IMPL */
    247