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