psl.h revision 1.1 1 1.1 deraadt /*
2 1.1 deraadt * Copyright (c) 1992, 1993
3 1.1 deraadt * The Regents of the University of California. All rights reserved.
4 1.1 deraadt *
5 1.1 deraadt * This software was developed by the Computer Systems Engineering group
6 1.1 deraadt * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
7 1.1 deraadt * contributed to Berkeley.
8 1.1 deraadt *
9 1.1 deraadt * All advertising materials mentioning features or use of this software
10 1.1 deraadt * must display the following acknowledgement:
11 1.1 deraadt * This product includes software developed by the University of
12 1.1 deraadt * California, Lawrence Berkeley Laboratory.
13 1.1 deraadt *
14 1.1 deraadt * Redistribution and use in source and binary forms, with or without
15 1.1 deraadt * modification, are permitted provided that the following conditions
16 1.1 deraadt * are met:
17 1.1 deraadt * 1. Redistributions of source code must retain the above copyright
18 1.1 deraadt * notice, this list of conditions and the following disclaimer.
19 1.1 deraadt * 2. Redistributions in binary form must reproduce the above copyright
20 1.1 deraadt * notice, this list of conditions and the following disclaimer in the
21 1.1 deraadt * documentation and/or other materials provided with the distribution.
22 1.1 deraadt * 3. All advertising materials mentioning features or use of this software
23 1.1 deraadt * must display the following acknowledgement:
24 1.1 deraadt * This product includes software developed by the University of
25 1.1 deraadt * California, Berkeley and its contributors.
26 1.1 deraadt * 4. Neither the name of the University nor the names of its contributors
27 1.1 deraadt * may be used to endorse or promote products derived from this software
28 1.1 deraadt * without specific prior written permission.
29 1.1 deraadt *
30 1.1 deraadt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
31 1.1 deraadt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32 1.1 deraadt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33 1.1 deraadt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
34 1.1 deraadt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35 1.1 deraadt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36 1.1 deraadt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37 1.1 deraadt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
38 1.1 deraadt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
39 1.1 deraadt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 1.1 deraadt * SUCH DAMAGE.
41 1.1 deraadt *
42 1.1 deraadt * @(#)psl.h 8.1 (Berkeley) 6/11/93
43 1.1 deraadt *
44 1.1 deraadt * from: Header: psl.h,v 1.12 92/11/26 02:04:42 torek Exp
45 1.1 deraadt * $Id: psl.h,v 1.1 1993/10/02 10:23:21 deraadt Exp $
46 1.1 deraadt */
47 1.1 deraadt
48 1.1 deraadt #ifndef PSR_IMPL
49 1.1 deraadt
50 1.1 deraadt /*
51 1.1 deraadt * SPARC Process Status Register (in psl.h for hysterical raisins).
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.1 deraadt #define PSR_IMPL 0xf0000000 /* implementation */
63 1.1 deraadt #define PSR_VER 0x0f000000 /* version */
64 1.1 deraadt #define PSR_ICC 0x00f00000 /* integer condition codes */
65 1.1 deraadt #define PSR_N 0x00800000 /* negative */
66 1.1 deraadt #define PSR_Z 0x00400000 /* zero */
67 1.1 deraadt #define PSR_O 0x00200000 /* overflow */
68 1.1 deraadt #define PSR_C 0x00100000 /* carry */
69 1.1 deraadt #define PSR_EC 0x00002000 /* coprocessor enable */
70 1.1 deraadt #define PSR_EF 0x00001000 /* FP enable */
71 1.1 deraadt #define PSR_PIL 0x00000f00 /* interrupt level */
72 1.1 deraadt #define PSR_S 0x00000080 /* supervisor (kernel) mode */
73 1.1 deraadt #define PSR_PS 0x00000040 /* previous supervisor mode (traps) */
74 1.1 deraadt #define PSR_ET 0x00000020 /* trap enable */
75 1.1 deraadt #define PSR_CWP 0x0000001f /* current window pointer */
76 1.1 deraadt
77 1.1 deraadt #define PSR_BITS "\20\16EC\15EF\10S\7PS\6ET"
78 1.1 deraadt
79 1.1 deraadt #define PIL_CLOCK 10
80 1.1 deraadt
81 1.1 deraadt #ifndef LOCORE
82 1.1 deraadt /*
83 1.1 deraadt * GCC pseudo-functions for manipulating PSR (primarily PIL field).
84 1.1 deraadt */
85 1.1 deraadt static __inline int getpsr() {
86 1.1 deraadt int psr;
87 1.1 deraadt
88 1.1 deraadt __asm __volatile("rd %%psr,%0" : "=r" (psr));
89 1.1 deraadt return (psr);
90 1.1 deraadt }
91 1.1 deraadt
92 1.1 deraadt static __inline void setpsr(int newpsr) {
93 1.1 deraadt __asm __volatile("wr %0,0,%%psr" : : "r" (newpsr));
94 1.1 deraadt __asm __volatile("nop");
95 1.1 deraadt __asm __volatile("nop");
96 1.1 deraadt __asm __volatile("nop");
97 1.1 deraadt }
98 1.1 deraadt
99 1.1 deraadt static __inline int spl0() {
100 1.1 deraadt int psr, oldipl;
101 1.1 deraadt
102 1.1 deraadt /*
103 1.1 deraadt * wrpsr xors two values: we choose old psr and old ipl here,
104 1.1 deraadt * which gives us the same value as the old psr but with all
105 1.1 deraadt * the old PIL bits turned off.
106 1.1 deraadt */
107 1.1 deraadt __asm __volatile("rd %%psr,%0" : "=r" (psr));
108 1.1 deraadt oldipl = psr & PSR_PIL;
109 1.1 deraadt __asm __volatile("wr %0,%1,%%psr" : : "r" (psr), "r" (oldipl));
110 1.1 deraadt
111 1.1 deraadt /*
112 1.1 deraadt * Three instructions must execute before we can depend
113 1.1 deraadt * on the bits to be changed.
114 1.1 deraadt */
115 1.1 deraadt __asm __volatile("nop; nop; nop");
116 1.1 deraadt return (oldipl);
117 1.1 deraadt }
118 1.1 deraadt
119 1.1 deraadt /*
120 1.1 deraadt * PIL 1 through 14 can use this macro.
121 1.1 deraadt * (spl0 and splhigh are special since they put all 0s or all 1s
122 1.1 deraadt * into the ipl field.)
123 1.1 deraadt */
124 1.1 deraadt #define SPL(name, newipl) \
125 1.1 deraadt static __inline int name() { \
126 1.1 deraadt int psr, oldipl; \
127 1.1 deraadt __asm __volatile("rd %%psr,%0" : "=r" (psr)); \
128 1.1 deraadt oldipl = psr & PSR_PIL; \
129 1.1 deraadt psr &= ~oldipl; \
130 1.1 deraadt __asm __volatile("wr %0,%1,%%psr" : : \
131 1.1 deraadt "r" (psr), "n" ((newipl) << 8)); \
132 1.1 deraadt __asm __volatile("nop; nop; nop"); \
133 1.1 deraadt return (oldipl); \
134 1.1 deraadt }
135 1.1 deraadt
136 1.1 deraadt SPL(splsoftint, 1)
137 1.1 deraadt #define splnet splsoftint
138 1.1 deraadt #define splsoftclock splsoftint
139 1.1 deraadt
140 1.1 deraadt /* Memory allocation (must be as high as highest network device) */
141 1.1 deraadt SPL(splimp, 5)
142 1.1 deraadt
143 1.1 deraadt /* tty input runs at software level 6 */
144 1.1 deraadt #define PIL_TTY 6
145 1.1 deraadt SPL(spltty, PIL_TTY)
146 1.1 deraadt
147 1.1 deraadt /* audio software interrupts are at software level 4 */
148 1.1 deraadt #define PIL_AUSOFT 4
149 1.1 deraadt SPL(splausoft, PIL_AUSOFT)
150 1.1 deraadt
151 1.1 deraadt SPL(splbio, 9)
152 1.1 deraadt
153 1.1 deraadt SPL(splclock, PIL_CLOCK)
154 1.1 deraadt
155 1.1 deraadt /* zs hardware interrupts are at level 12 */
156 1.1 deraadt SPL(splzs, 12)
157 1.1 deraadt
158 1.1 deraadt /* audio hardware interrupts are at level 13 */
159 1.1 deraadt SPL(splaudio, 13)
160 1.1 deraadt
161 1.1 deraadt /* second sparc timer interrupts at level 14 */
162 1.1 deraadt SPL(splstatclock, 14)
163 1.1 deraadt
164 1.1 deraadt static __inline int splhigh() {
165 1.1 deraadt int psr, oldipl;
166 1.1 deraadt
167 1.1 deraadt __asm __volatile("rd %%psr,%0" : "=r" (psr));
168 1.1 deraadt __asm __volatile("wr %0,0,%%psr" : : "r" (psr | PSR_PIL));
169 1.1 deraadt __asm __volatile("and %1,%2,%0; nop; nop" : "=r" (oldipl) : \
170 1.1 deraadt "r" (psr), "n" (PSR_PIL));
171 1.1 deraadt return (oldipl);
172 1.1 deraadt }
173 1.1 deraadt
174 1.1 deraadt /* splx does not have a return value */
175 1.1 deraadt static __inline void splx(int newipl) {
176 1.1 deraadt int psr;
177 1.1 deraadt
178 1.1 deraadt __asm __volatile("rd %%psr,%0" : "=r" (psr));
179 1.1 deraadt __asm __volatile("wr %0,%1,%%psr" : : \
180 1.1 deraadt "r" (psr & ~PSR_PIL), "rn" (newipl));
181 1.1 deraadt __asm __volatile("nop; nop; nop");
182 1.1 deraadt }
183 1.1 deraadt #endif /* LOCORE */
184 1.1 deraadt
185 1.1 deraadt #endif /* PSR_IMPL */
186