frame.h revision 1.35 1 1.35 thorpej /* $NetBSD: frame.h,v 1.35 2024/01/13 17:07:26 thorpej Exp $ */
2 1.8 cgd
3 1.1 cgd /*
4 1.30 rmind * Copyright (c) 1988 University of Utah.
5 1.6 mycroft * Copyright (c) 1982, 1990, 1993
6 1.6 mycroft * The Regents of the University of California. All rights reserved.
7 1.20 agc *
8 1.20 agc * This code is derived from software contributed to Berkeley by
9 1.20 agc * the Systems Programming Group of the University of Utah Computer
10 1.20 agc * Science Department.
11 1.20 agc *
12 1.20 agc * Redistribution and use in source and binary forms, with or without
13 1.20 agc * modification, are permitted provided that the following conditions
14 1.20 agc * are met:
15 1.20 agc * 1. Redistributions of source code must retain the above copyright
16 1.20 agc * notice, this list of conditions and the following disclaimer.
17 1.20 agc * 2. Redistributions in binary form must reproduce the above copyright
18 1.20 agc * notice, this list of conditions and the following disclaimer in the
19 1.20 agc * documentation and/or other materials provided with the distribution.
20 1.20 agc * 3. Neither the name of the University nor the names of its contributors
21 1.20 agc * may be used to endorse or promote products derived from this software
22 1.20 agc * without specific prior written permission.
23 1.20 agc *
24 1.20 agc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 1.20 agc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 1.20 agc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 1.20 agc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 1.20 agc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 1.20 agc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 1.20 agc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 1.20 agc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 1.20 agc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 1.20 agc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 1.20 agc * SUCH DAMAGE.
35 1.20 agc *
36 1.20 agc * from: Utah $Hdr: frame.h 1.8 92/12/20$
37 1.20 agc *
38 1.20 agc * @(#)frame.h 8.1 (Berkeley) 6/10/93
39 1.20 agc */
40 1.9 chopps
41 1.13 gwr #ifndef _M68K_FRAME_H_
42 1.13 gwr #define _M68K_FRAME_H_
43 1.13 gwr
44 1.21 cl #include <m68k/cpuframe.h>
45 1.22 cl
46 1.22 cl /* common frame size */
47 1.22 cl #define CFSIZE (sizeof(struct frame) - sizeof(union F_u))
48 1.22 cl #define NFMTSIZE 9
49 1.22 cl
50 1.22 cl #define FMT0 0x0
51 1.22 cl #define FMT1 0x1
52 1.22 cl #define FMT2 0x2
53 1.22 cl #define FMT3 0x3
54 1.22 cl #define FMT4 0x4
55 1.22 cl #define FMT7 0x7
56 1.22 cl #define FMT8 0x8
57 1.22 cl #define FMT9 0x9
58 1.22 cl #define FMTA 0xA
59 1.22 cl #define FMTB 0xB
60 1.22 cl
61 1.22 cl /* frame specific info sizes */
62 1.22 cl #define FMT0SIZE 0
63 1.22 cl #define FMT1SIZE 0
64 1.22 cl #define FMT2SIZE sizeof(struct fmt2)
65 1.22 cl #define FMT3SIZE sizeof(struct fmt3)
66 1.22 cl #define FMT4SIZE sizeof(struct fmt4)
67 1.22 cl #define FMT7SIZE sizeof(struct fmt7)
68 1.22 cl #define FMT8SIZE sizeof(struct fmt8)
69 1.22 cl #define FMT9SIZE sizeof(struct fmt9)
70 1.22 cl #define FMTASIZE sizeof(struct fmtA)
71 1.22 cl #define FMTBSIZE sizeof(struct fmtB)
72 1.22 cl
73 1.22 cl /* 68010 SSW bits */
74 1.22 cl #define SSW1_RR 0x8000
75 1.22 cl #define SSW1_IF 0x2000
76 1.22 cl #define SSW1_DF 0x1000
77 1.22 cl #define SSW1_RM 0x0800
78 1.22 cl #define SSW1_HI 0x0400
79 1.22 cl #define SSW1_BX 0x0200
80 1.22 cl #define SSW1_RW 0x0100
81 1.22 cl #define SSW1_FCMASK 0x000F
82 1.22 cl
83 1.22 cl /* 68020/68030 SSW bits */
84 1.22 cl #define SSW_RC 0x2000
85 1.22 cl #define SSW_RB 0x1000
86 1.22 cl #define SSW_DF 0x0100
87 1.22 cl #define SSW_RM 0x0080
88 1.22 cl #define SSW_RW 0x0040
89 1.22 cl #define SSW_FCMASK 0x0007
90 1.22 cl
91 1.22 cl /* 68040 SSW bits */
92 1.22 cl #define SSW4_CP 0x8000
93 1.22 cl #define SSW4_CU 0x4000
94 1.22 cl #define SSW4_CT 0x2000
95 1.22 cl #define SSW4_CM 0x1000
96 1.22 cl #define SSW4_MA 0x0800
97 1.22 cl #define SSW4_ATC 0x0400
98 1.22 cl #define SSW4_LK 0x0200
99 1.22 cl #define SSW4_RW 0x0100
100 1.22 cl #define SSW4_WBSV 0x0080 /* really in WB status, not SSW */
101 1.22 cl #define SSW4_SZMASK 0x0060
102 1.22 cl #define SSW4_SZLW 0x0000
103 1.22 cl #define SSW4_SZB 0x0020
104 1.22 cl #define SSW4_SZW 0x0040
105 1.22 cl #define SSW4_SZLN 0x0060
106 1.22 cl #define SSW4_TTMASK 0x0018
107 1.22 cl #define SSW4_TTNOR 0x0000
108 1.22 cl #define SSW4_TTM16 0x0008
109 1.22 cl #define SSW4_TMMASK 0x0007
110 1.22 cl #define SSW4_TMDCP 0x0000
111 1.22 cl #define SSW4_TMUD 0x0001
112 1.22 cl #define SSW4_TMUC 0x0002
113 1.22 cl #define SSW4_TMKD 0x0005
114 1.22 cl #define SSW4_TMKC 0x0006
115 1.22 cl
116 1.22 cl /* 060 Fault Status Long Word (FPSP) */
117 1.22 cl
118 1.22 cl #define FSLW_MA 0x08000000
119 1.22 cl #define FSLW_LK 0x02000000
120 1.22 cl #define FSLW_RW 0x01800000
121 1.22 cl
122 1.22 cl #define FSLW_RW_R 0x01000000
123 1.22 cl #define FSLW_RW_W 0x00800000
124 1.22 cl
125 1.22 cl #define FSLW_SIZE 0x00600000
126 1.22 cl /*
127 1.32 tsutsui * We better define the FSLW_SIZE values here, as the table given in the
128 1.32 tsutsui * MC68060UM/AD rev. 0/1 p. 8-23 is wrong, and was corrected in the errata
129 1.22 cl * document.
130 1.22 cl */
131 1.22 cl #define FSLW_SIZE_LONG 0x00000000
132 1.22 cl #define FSLW_SIZE_BYTE 0x00200000
133 1.22 cl #define FSLW_SIZE_WORD 0x00400000
134 1.22 cl #define FSLW_SIZE_MV16 0x00600000
135 1.22 cl
136 1.22 cl #define FLSW_TT 0x00180000
137 1.22 cl #define FSLW_TM 0x00070000
138 1.22 cl #define FSLW_TM_SV 0x00040000
139 1.22 cl
140 1.22 cl
141 1.22 cl
142 1.22 cl #define FSLW_IO 0x00008000
143 1.22 cl #define FSLW_PBE 0x00004000
144 1.22 cl #define FSLW_SBE 0x00002000
145 1.22 cl #define FSLW_PTA 0x00001000
146 1.33 tsutsui #define FSLW_PTB 0x00000800
147 1.33 tsutsui #define FSLW_IL 0x00000400
148 1.33 tsutsui #define FSLW_PF 0x00000200
149 1.33 tsutsui #define FSLW_SP 0x00000100
150 1.33 tsutsui #define FSLW_WP 0x00000080
151 1.33 tsutsui #define FSLW_TWE 0x00000040
152 1.33 tsutsui #define FSLW_RE 0x00000020
153 1.33 tsutsui #define FSLW_WE 0x00000010
154 1.33 tsutsui #define FSLW_TTR 0x00000008
155 1.33 tsutsui #define FSLW_BPE 0x00000004
156 1.33 tsutsui #define FSLW_SEE 0x00000001
157 1.22 cl
158 1.22 cl /* struct fpframe060 */
159 1.22 cl #define FPF6_FMT_NULL 0x00
160 1.22 cl #define FPF6_FMT_IDLE 0x60
161 1.22 cl #define FPF6_FMT_EXCP 0xe0
162 1.22 cl
163 1.22 cl #define FPF6_V_BSUN 0
164 1.22 cl #define FPF6_V_INEX12 1
165 1.22 cl #define FPF6_V_DZ 2
166 1.22 cl #define FPF6_V_UNFL 3
167 1.22 cl #define FPF6_V_OPERR 4
168 1.22 cl #define FPF6_V_OVFL 5
169 1.22 cl #define FPF6_V_SNAN 6
170 1.22 cl #define FPF6_V_UNSUP 7
171 1.22 cl
172 1.25 drochner #if defined(_KERNEL)
173 1.25 drochner
174 1.21 cl #include <m68k/signal.h>
175 1.1 cgd
176 1.25 drochner #if defined(COMPAT_16)
177 1.11 is /*
178 1.21 cl * Stack frame layout when delivering a signal.
179 1.11 is */
180 1.21 cl struct sigframe_sigcontext {
181 1.21 cl int sf_ra; /* handler return address */
182 1.21 cl int sf_signum; /* signal number for handler */
183 1.21 cl int sf_code; /* additional info for handler */
184 1.21 cl struct sigcontext *sf_scp; /* context pointer for handler */
185 1.21 cl struct sigcontext sf_sc; /* actual context */
186 1.21 cl struct sigstate sf_state; /* state of the hardware */
187 1.1 cgd };
188 1.21 cl #endif
189 1.1 cgd
190 1.21 cl struct sigframe_siginfo {
191 1.21 cl int sf_ra; /* return address for handler */
192 1.21 cl int sf_signum; /* "signum" argument for handler */
193 1.21 cl siginfo_t *sf_sip; /* "sip" argument for handler */
194 1.21 cl ucontext_t *sf_ucp; /* "ucp" argument for handler */
195 1.21 cl siginfo_t sf_si; /* actual saved siginfo */
196 1.21 cl ucontext_t sf_uc; /* actual saved ucontext */
197 1.11 is };
198 1.16 kleink
199 1.16 kleink /*
200 1.16 kleink * Utility function to relocate the initial frame, make room to restore an
201 1.16 kleink * exception frame and reenter the syscall.
202 1.16 kleink */
203 1.24 thorpej void reenter_syscall(struct frame *, int) __attribute__((__noreturn__));
204 1.19 thorpej
205 1.19 thorpej /*
206 1.19 thorpej * Create an FPU "idle" frame for use by cpu_setmcontext()
207 1.19 thorpej */
208 1.19 thorpej extern void m68k_make_fpu_idle_frame(void);
209 1.19 thorpej extern struct fpframe m68k_cached_fpu_idle_frame;
210 1.21 cl
211 1.24 thorpej void *getframe(struct lwp *, int, int *);
212 1.24 thorpej void buildcontext(struct lwp *, void *, void *);
213 1.21 cl #ifdef COMPAT_16
214 1.24 thorpej void sendsig_sigcontext(const ksiginfo_t *, const sigset_t *);
215 1.21 cl #endif
216 1.21 cl
217 1.31 thorpej #ifdef M68040
218 1.31 thorpej int m68040_writeback(struct frame *, int);
219 1.31 thorpej #endif
220 1.31 thorpej
221 1.27 thorpej #if defined(__mc68010__)
222 1.27 thorpej /*
223 1.29 tsutsui * Restartable atomic sequence-cased compare-and-swap for atomic_cas ops
224 1.29 tsutsui * and locking primitives. We defined this here because it manipulates a
225 1.27 thorpej * "clockframe" as prepared by interrupt handlers.
226 1.27 thorpej */
227 1.29 tsutsui extern char _atomic_cas_ras_start;
228 1.29 tsutsui extern char _atomic_cas_ras_end;
229 1.27 thorpej
230 1.29 tsutsui #define ATOMIC_CAS_CHECK(cfp) \
231 1.27 thorpej do { \
232 1.28 thorpej if (! CLKF_USERMODE(cfp) && \
233 1.29 tsutsui (CLKF_PC(cfp) < (u_long)&_atomic_cas_ras_end && \
234 1.29 tsutsui CLKF_PC(cfp) > (u_long)&_atomic_cas_ras_start)) { \
235 1.33 tsutsui (cfp)->cf_pc = (u_long)&_atomic_cas_ras_start; \
236 1.27 thorpej } \
237 1.27 thorpej } while (/*CONSTCOND*/0)
238 1.27 thorpej #else
239 1.29 tsutsui #define ATOMIC_CAS_CHECK(cfp) /* nothing */
240 1.27 thorpej #endif /* __mc68010__ */
241 1.27 thorpej
242 1.34 thorpej static inline void **
243 1.34 thorpej getvbr(void)
244 1.34 thorpej {
245 1.34 thorpej void **vbr;
246 1.34 thorpej
247 1.34 thorpej __asm volatile("movc %%vbr,%0" : "=r" (vbr));
248 1.34 thorpej
249 1.34 thorpej return vbr;
250 1.34 thorpej }
251 1.34 thorpej
252 1.34 thorpej static inline void
253 1.34 thorpej setvbr(void **vbr)
254 1.34 thorpej {
255 1.34 thorpej __asm volatile("movc %0,%%vbr" : : "r" (vbr));
256 1.34 thorpej }
257 1.34 thorpej
258 1.19 thorpej #endif /* _KERNEL */
259 1.13 gwr
260 1.13 gwr #endif /* _M68K_FRAME_H_ */
261