1/*	$NetBSD: frame.h,v 1.31 2019/02/18 01:12:23 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#define	V_BUSERR	0x008
 74#define	V_ADDRERR	0x00C
 75#define	V_TRAP1		0x084
 76
 77/* 68010 SSW bits */
 78#define SSW1_RR		0x8000
 79#define SSW1_IF		0x2000
 80#define SSW1_DF		0x1000
 81#define SSW1_RM		0x0800
 82#define SSW1_HI		0x0400
 83#define SSW1_BX		0x0200
 84#define SSW1_RW		0x0100
 85#define SSW1_FCMASK	0x000F
 86
 87/* 68020/68030 SSW bits */
 88#define	SSW_RC		0x2000
 89#define	SSW_RB		0x1000
 90#define	SSW_DF		0x0100
 91#define	SSW_RM		0x0080
 92#define	SSW_RW		0x0040
 93#define	SSW_FCMASK	0x0007
 94
 95/* 68040 SSW bits */
 96#define	SSW4_CP		0x8000
 97#define	SSW4_CU		0x4000
 98#define	SSW4_CT		0x2000
 99#define	SSW4_CM		0x1000
100#define	SSW4_MA		0x0800
101#define	SSW4_ATC	0x0400
102#define	SSW4_LK		0x0200
103#define	SSW4_RW		0x0100
104#define SSW4_WBSV	0x0080	/* really in WB status, not SSW */
105#define	SSW4_SZMASK	0x0060
106#define	SSW4_SZLW	0x0000
107#define	SSW4_SZB	0x0020
108#define	SSW4_SZW	0x0040
109#define	SSW4_SZLN	0x0060
110#define	SSW4_TTMASK	0x0018
111#define	SSW4_TTNOR	0x0000
112#define	SSW4_TTM16	0x0008
113#define	SSW4_TMMASK	0x0007
114#define	SSW4_TMDCP	0x0000
115#define	SSW4_TMUD	0x0001
116#define	SSW4_TMUC	0x0002
117#define	SSW4_TMKD	0x0005
118#define	SSW4_TMKC	0x0006
119
120/* 060 Fault Status Long Word (FPSP) */
121
122#define FSLW_MA		0x08000000
123#define FSLW_LK		0x02000000
124#define FSLW_RW		0x01800000
125
126#define FSLW_RW_R	0x01000000
127#define FSLW_RW_W	0x00800000
128
129#define FSLW_SIZE	0x00600000
130/*
131 * We better define the FSLW_SIZE values here, as the table given in the 
132 * MC68060UM/AD rev. 0/1 p. 8-23 is wrong, and was corrected in the errata 
133 * document.
134 */
135#define FSLW_SIZE_LONG	0x00000000
136#define FSLW_SIZE_BYTE	0x00200000
137#define FSLW_SIZE_WORD	0x00400000
138#define FSLW_SIZE_MV16	0x00600000
139
140#define FLSW_TT		0x00180000
141#define FSLW_TM		0x00070000
142#define FSLW_TM_SV	0x00040000
143
144
145
146#define FSLW_IO		0x00008000
147#define FSLW_PBE	0x00004000
148#define FSLW_SBE	0x00002000
149#define FSLW_PTA	0x00001000
150#define FSLW_PTB 	0x00000800
151#define FSLW_IL 	0x00000400
152#define FSLW_PF 	0x00000200
153#define FSLW_SP 	0x00000100
154#define FSLW_WP 	0x00000080
155#define FSLW_TWE 	0x00000040
156#define FSLW_RE 	0x00000020
157#define FSLW_WE 	0x00000010
158#define FSLW_TTR 	0x00000008
159#define FSLW_BPE 	0x00000004
160#define FSLW_SEE 	0x00000001
161
162/* struct fpframe060 */
163#define FPF6_FMT_NULL	0x00
164#define FPF6_FMT_IDLE	0x60
165#define FPF6_FMT_EXCP	0xe0
166
167#define	FPF6_V_BSUN	0
168#define	FPF6_V_INEX12	1
169#define	FPF6_V_DZ	2
170#define	FPF6_V_UNFL	3
171#define	FPF6_V_OPERR	4
172#define	FPF6_V_OVFL	5
173#define	FPF6_V_SNAN	6
174#define	FPF6_V_UNSUP	7
175
176#if defined(_KERNEL)
177
178#include <m68k/signal.h>
179
180#if defined(COMPAT_16)
181/*
182 * Stack frame layout when delivering a signal.
183 */
184struct sigframe_sigcontext {
185	int	sf_ra;			/* handler return address */
186	int	sf_signum;		/* signal number for handler */
187	int	sf_code;		/* additional info for handler */
188	struct sigcontext *sf_scp;	/* context pointer for handler */
189	struct sigcontext sf_sc;	/* actual context */
190	struct sigstate sf_state;	/* state of the hardware */
191};
192#endif
193
194struct sigframe_siginfo {
195	int		sf_ra;		/* return address for handler */
196	int		sf_signum;	/* "signum" argument for handler */
197	siginfo_t	*sf_sip;	/* "sip" argument for handler */
198	ucontext_t	*sf_ucp;	/* "ucp" argument for handler */
199	siginfo_t	sf_si;		/* actual saved siginfo */
200	ucontext_t	sf_uc;		/* actual saved ucontext */
201};
202
203/*
204 * Utility function to relocate the initial frame, make room to restore an
205 * exception frame and reenter the syscall.
206 */
207void	reenter_syscall(struct frame *, int) __attribute__((__noreturn__));
208
209/*
210 * Create an FPU "idle" frame for use by cpu_setmcontext()
211 */
212extern void m68k_make_fpu_idle_frame(void);
213extern struct fpframe m68k_cached_fpu_idle_frame;
214
215void	*getframe(struct lwp *, int, int *);
216void	buildcontext(struct lwp *, void *, void *);
217#ifdef COMPAT_16
218void	sendsig_sigcontext(const ksiginfo_t *, const sigset_t *);
219#endif
220
221#ifdef M68040
222int	m68040_writeback(struct frame *, int);
223#endif
224
225#if defined(__mc68010__)
226/*
227 * Restartable atomic sequence-cased compare-and-swap for atomic_cas ops
228 * and locking primitives.  We defined this here because it manipulates a
229 * "clockframe" as prepared by interrupt handlers.
230 */
231extern char	_atomic_cas_ras_start;
232extern char	_atomic_cas_ras_end;
233
234#define ATOMIC_CAS_CHECK(cfp)						\
235do {									\
236	if (! CLKF_USERMODE(cfp) &&					\
237	    (CLKF_PC(cfp) < (u_long)&_atomic_cas_ras_end &&		\
238	     CLKF_PC(cfp) > (u_long)&_atomic_cas_ras_start)) {		\
239	    	(cfp)->cf_pc = (u_long)&_atomic_cas_ras_start;		\
240	}								\
241} while (/*CONSTCOND*/0)
242#else
243#define	ATOMIC_CAS_CHECK(cfp)	/* nothing */
244#endif /* __mc68010__ */
245
246#endif	/* _KERNEL */
247
248#endif	/* _M68K_FRAME_H_ */