code:
/*	$OpenBSD: disklabel.h,v 1.8 2008/04/06 21:19:35 drahn Exp $	*/

/*
 * Copyright (c) 1994 Mark Brinicombe.
 * Copyright (c) 1994 Brini.
 * All rights reserved.
 *
 * This code is derived from software written for Brini by Mark Brinicombe
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by Brini.
 * 4. The name of the company nor the name of the author may be used to
 *    endorse or promote products derived from this software without specific
 *    prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#ifndef _SH_DISKLABEL_H_
#define _SH_DISKLABEL_H_

#define LABELSECTOR	1		/* sector containing label */
#define LABELOFFSET	0		/* offset of label in sector */
#define MAXPARTITIONS	16		/* number of partitions */

#endif /* _SH_DISKLABEL_H_ */


code:
/*	$OpenBSD: endian.h,v 1.5 2014/07/12 16:25:09 guenther Exp $	*/
/*	$NetBSD: endian.h,v 1.4 2000/03/17 00:09:25 mycroft Exp $	*/

/* Written by Manuel Bouyer. Public domain */

#ifndef _SH_ENDIAN_H_
#define	_SH_ENDIAN_H_

#ifdef  __GNUC__

#define	__swap64md	__swap64gen

#define __swap16md(x) __statement({					\
	uint16_t rval;							\
									\
	__asm volatile ("swap.b %1,%0" : "=r"(rval) : "r"(x));		\
									\
	rval;								\
})

#define __swap32md(x) __statement({					\
	uint32_t rval;							\
									\
	__asm volatile ("swap.b %1,%0; swap.w %0,%0; swap.b %0,%0"	\
			  : "=r"(rval) : "r"(x));			\
									\
	rval;								\
})

#define __HAVE_MD_SWAP

#endif /* __GNUC_ */

#ifdef __LITTLE_ENDIAN__
#define	_BYTE_ORDER _LITTLE_ENDIAN
#else
#define	_BYTE_ORDER _BIG_ENDIAN
#endif
#define	__STRICT_ALIGNMENT

#ifndef __FROM_SYS__ENDIAN
#include <sys/endian.h>
#endif

#endif /* !_SH_ENDIAN_H_ */

license: unknown


code:
/*	$OpenBSD: exec.h,v 1.3 2012/09/11 15:44:18 deraadt Exp $	*/
/*	$NetBSD: elf_machdep.h,v 1.8 2002/04/28 17:10:34 uch Exp $	*/

#define __LDPGSZ	4096

#define	ARCH_ELFSIZE		32	/* MD native binary size */
#define	ELF_TARG_CLASS		ELFCLASS32
#ifdef __LITTLE_ENDIAN__
#define	ELF_TARG_DATA		ELFDATA2LSB
#else
#define	ELF_TARG_DATA		ELFDATA2MSB
#endif
#define	ELF_TARG_MACH		EM_SH

#define	_KERN_DO_ELF
#define	_NLIST_DO_ELF

/*
 * SuperH ELF header flags.
 */
#define	EF_SH_MACH_MASK		0x1f

#define	EF_SH_UNKNOWN		0x00
#define	EF_SH_SH1		0x01
#define	EF_SH_SH2		0x02
#define	EF_SH_SH3		0x03
#define	EF_SH_DSP		0x04
#define	EF_SH_SH3_DSP		0x05
#define	EF_SH_SH3E		0x08
#define	EF_SH_SH4		0x09

#define	EF_SH_HAS_DSP(x)	((x) & EF_SH_DSP)
#define	EF_SH_HAS_FP(x)		((x) & EF_SH_SH3E)


code:
/*	$OpenBSD: fenv.h,v 1.3 2011/05/25 21:46:49 martynas Exp $	*/

/*
 * Copyright (c) 2011 Martynas Venckus <martynas@openbsd.org>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#ifndef	_SH_FENV_H_
#define	_SH_FENV_H_

/*
 * Each symbol representing a floating point exception expands to an integer
 * constant expression with values, such that bitwise-inclusive ORs of _all
 * combinations_ of the constants result in distinct values.
 *
 * We use such values that allow direct bitwise operations on FPU registers.
 */
#define	FE_INEXACT		0x04
#define	FE_UNDERFLOW		0x08
#define	FE_OVERFLOW		0x10
#define	FE_DIVBYZERO		0x20
#define	FE_INVALID		0x40

/*
 * The following symbol is simply the bitwise-inclusive OR of all floating-point
 * exception constants defined above.
 */
#define	FE_ALL_EXCEPT		(FE_INEXACT | FE_UNDERFLOW | FE_OVERFLOW | \
				 FE_DIVBYZERO | FE_INVALID)
#define	_MASK_SHIFT		5

/*
 * Each symbol representing the rounding direction, expands to an integer
 * constant expression whose value is distinct non-negative value.
 *
 * We use such values that allow direct bitwise operations on FPU registers.
 */
#define	FE_TONEAREST		0x0
#define	FE_TOWARDZERO		0x1
#define	FE_UPWARD		0x2
#define	FE_DOWNWARD		0x3

/*
 * The following symbol is simply the bitwise-inclusive OR of all floating-point
 * rounding direction constants defined above.
 */
#define	_ROUND_MASK		(FE_TONEAREST | FE_TOWARDZERO | FE_UPWARD | \
				 FE_DOWNWARD)

/*
 * fenv_t represents the entire floating-point environment.
 */
typedef	unsigned int		fenv_t;

/*
 * The following constant represents the default floating-point environment
 * (that is, the one installed at program startup) and has type pointer to
 * const-qualified fenv_t.
 *
 * It can be used as an argument to the functions within the <fenv.h> header
 * that manage the floating-point environment, namely fesetenv() and
 * feupdateenv().
 */
__BEGIN_DECLS
extern	fenv_t			__fe_dfl_env;
__END_DECLS
#define	FE_DFL_ENV		((const fenv_t *)&__fe_dfl_env)

/*
 * fexcept_t represents the floating-point status flags collectively, including
 * any status the implementation associates with the flags.
 *
 * A floating-point status flag is a system variable whose value is set (but
 * never cleared) when a floating-point exception is raised, which occurs as a
 * side effect of exceptional floating-point arithmetic to provide auxiliary
 * information.
 *
 * A floating-point control mode is a system variable whose value may be set by
 * the user to affect the subsequent behavior of floating-point arithmetic.
 */
typedef	unsigned int		fexcept_t;

#endif	/* !_SH_FENV_H_ */


code:
#ifndef _SH_FPU_H_
/*	$OpenBSD: fpu.h,v 1.1 2006/11/05 18:57:20 miod Exp $	*/
/*
 * Copyright (c) 2006, Miodrag Vallat
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#define	_SH_FPU_H_

/*
 * SH4{,a} FPU definitions
 */

/* FPSCR bits */

#define	FPSCR_RB		0x00200000	/* register bank */
#define	FPSCR_SZ		0x00100000	/* transfer size mode */
#define	FPSCR_PR		0x00080000	/* precision mode */
#define	FPSCR_DN		0x00040000	/* denormalization mode */
#define	FPSCR_CAUSE_MASK	0x0003f000	/* exception cause mask */
#define	FPSCR_CAUSE_SHIFT	12
#define	FPSCR_ENABLE_MASK	0x00000f80	/* exception enable mask */
#define	FPSCR_ENABLE_SHIFT	7
#define	FPSCR_FLAG_MASK		0x0000007c	/* exception sticky mask */
#define	FPSCR_FLAG_SHIFT	2
#define	FPSCR_ROUNDING_MASK	0x00000003	/* rounding mask */

/* FPSCR exception bits */

#define	FPEXC_E			0x20	/* FPU Error */
#define	FPEXC_V			0x10	/* invalid operation */
#define	FPEXC_Z			0x08	/* divide by zero */
#define	FPEXC_O			0x04	/* overflow */
#define	FPEXC_U			0x02	/* underflow */
#define	FPEXC_I			0x01	/* inexact */

#endif	/* _SH_FPU_H_ */


code:
/*	$OpenBSD: frame.h,v 1.2 2007/03/02 06:11:54 miod Exp $	*/
/*	$NetBSD: frame.h,v 1.14 2005/12/11 12:18:58 christos Exp $	*/

/*-
 * Copyright (c) 2002 The NetBSD Foundation, Inc. All rights reserved.
 * Copyright (c) 1990 The Regents of the University of California.
 * All rights reserved.
 *
 * This code is derived from software contributed to Berkeley by
 * William Jolitz.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *	@(#)frame.h	5.2 (Berkeley) 1/18/91
 */

/*-
 * Copyright (c) 1995 Charles M. Hannum.  All rights reserved.
 *
 * This code is derived from software contributed to Berkeley by
 * William Jolitz.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by the University of
 *	California, Berkeley and its contributors.
 * 4. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *	@(#)frame.h	5.2 (Berkeley) 1/18/91
 */

#ifndef _SH_FRAME_H_
#define	_SH_FRAME_H_

#include <sys/signal.h>

/*
 * Exception Stack Frame
 */
struct trapframe {
	/* software member */
	int	tf_expevt;
	int	tf_ubc;
	/* hardware registers */
	int	tf_spc;
	int	tf_ssr;
	int	tf_macl;
	int	tf_mach;
	int	tf_pr;
	int	tf_r13;
	int	tf_r12;
	int	tf_r11;
	int	tf_r10;
	int	tf_r9;
	int	tf_r8;
	int	tf_r7;
	int	tf_r6;
	int	tf_r5;
	int	tf_r4;
	int	tf_r3;
	int	tf_r2;
	int	tf_r1;
	int	tf_r0;
	int	tf_r15;
	int	tf_r14;
};

/*
 * Stack frame inside cpu_switch()
 */
struct switchframe {
	int	sf_r15;
	int	sf_r14;
	int	sf_r13;
	int	sf_r12;
	int	sf_r11;
	int	sf_r10;
	int	sf_r9;
	int	sf_r8;
	int	sf_pr;
	int	sf_r6_bank;
	int	sf_sr;
	int	sf_r7_bank;
	int	sf_macl;
	int	sf_mach;
};

#endif /* !_SH_FRAME_H_ */


code:
/*	$OpenBSD: ieee.h,v 1.3 2008/09/07 20:36:07 martynas Exp $	*/

/*
 * Copyright (c) 1992, 1993
 *	The Regents of the University of California.  All rights reserved.
 *
 * This software was developed by the Computer Systems Engineering group
 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
 * contributed to Berkeley.
 *
 * All advertising materials mentioning features or use of this software
 * must display the following acknowledgement:
 *	This product includes software developed by the University of
 *	California, Lawrence Berkeley Laboratory.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *	@(#)ieee.h	8.1 (Berkeley) 6/11/93
 */

/*
 * ieee.h defines the machine-dependent layout of the machine's IEEE
 * floating point.  It does *not* define (yet?) any of the rounding
 * mode bits, exceptions, and so forth.
 */

/*
 * Define the number of bits in each fraction and exponent.
 *
 *		     k	         k+1
 * Note that  1.0 x 2  == 0.1 x 2      and that denorms are represented
 *
 *					  (-exp_bias+1)
 * as fractions that look like 0.fffff x 2             .  This means that
 *
 *			 -126
 * the number 0.10000 x 2    , for instance, is the same as the normalized
 *
 *		-127			   -128
 * float 1.0 x 2    .  Thus, to represent 2    , we need one leading zero
 *
 *				  -129
 * in the fraction; to represent 2    , we need two, and so on.  This
 *
 *						     (-exp_bias-fracbits+1)
 * implies that the smallest denormalized number is 2
 *
 * for whichever format we are talking about: for single precision, for
 *
 *						-126		-149
 * instance, we get .00000000000000000000001 x 2    , or 1.0 x 2    , and
 *
 * -149 == -127 - 23 + 1.
 */
#define	SNG_EXPBITS	8
#define	SNG_FRACBITS	23

#define	DBL_EXPBITS	11
#define	DBL_FRACHBITS	20
#define	DBL_FRACLBITS	32
#define	DBL_FRACBITS	52

struct ieee_single {
	u_int	sng_frac:23;
	u_int	sng_exp:8;
	u_int	sng_sign:1;
};

struct ieee_double {
	u_int	dbl_fracl;
	u_int	dbl_frach:20;
	u_int	dbl_exp:11;
	u_int	dbl_sign:1;
};

/*
 * Floats whose exponent is in [1..INFNAN) (of whatever type) are
 * `normal'.  Floats whose exponent is INFNAN are either Inf or NaN.
 * Floats whose exponent is zero are either zero (iff all fraction
 * bits are zero) or subnormal values.
 *
 * A NaN is a `signalling NaN' if its QUIETNAN bit is clear in its
 * high fraction; if the bit is set, it is a `quiet NaN'.
 */
#define	SNG_EXP_INFNAN	255
#define	DBL_EXP_INFNAN	2047

#if 0
#define	SNG_QUIETNAN	(1 << 22)
#define	DBL_QUIETNAN	(1 << 19)
#endif

/*
 * Exponent biases.
 */
#define	SNG_EXP_BIAS	127
#define	DBL_EXP_BIAS	1023


code:
/*	$OpenBSD: ieeefp.h,v 1.4 2011/04/24 16:57:11 martynas Exp $	*/
/*	$NetBSD: ieeefp.h,v 1.3 2002/04/28 17:10:34 uch Exp $ */

/*
 * Written by J.T. Conklin, Apr 6, 1995
 * Public domain.
 */

#ifndef _SH_IEEEFP_H_
#define	_SH_IEEEFP_H_

typedef int fp_except;
#define	FP_X_INV	0x10	/* invalid operation exception */
#define	FP_X_DZ		0x08	/* divide-by-zero exception */
#define	FP_X_OFL	0x04	/* overflow exception */
#define	FP_X_UFL	0x02	/* underflow exception */
#define	FP_X_IMP	0x01	/* imprecise (loss of precision) */

typedef enum {
	FP_RN=0,		/* round to nearest representable number */
	FP_RZ=1,		/* round to zero (truncate) */
	/* the following two are not implemented on SH4{,A} */
	FP_RP=2,		/* round toward positive infinity */
	FP_RM=3			/* round toward negative infinity */
} fp_rnd;

#endif /* !_SH_IEEEFP_H_ */


code:
/*	$OpenBSD: intcreg.h,v 1.1.1.1 2006/10/06 21:02:55 miod Exp $	*/
/*	$NetBSD: intcreg.h,v 1.10 2005/12/11 12:18:58 christos Exp $	*/

/*-
 * Copyright (C) 1999 SAITOH Masanobu.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef _SH_INTCREG_H_
#define	_SH_INTCREG_H_
#include <sh/devreg.h>

/*
 * INTC
 */
/* SH3 SH7708*, SH7709* common */
#define	SH3_ICR0		0xfffffee0	/* 16bit */
#define	SH3_IPRA		0xfffffee2	/* 16bit */
#define	SH3_IPRB		0xfffffee4	/* 16bit */

/* SH7709, SH7709A only */
#define	SH7709_ICR1		0xa4000010	/* 16bit */
#define	SH7709_ICR2		0xa4000012	/* 16bit */
#define	SH7709_PINTER		0xa4000014	/* 16bit */
#define	SH7709_IPRC		0xa4000016	/* 16bit */
#define	SH7709_IPRD		0xa4000018	/* 16bit */
#define	SH7709_IPRE		0xa400001a	/* 16bit */
#define	SH7709_IRR0		0xa4000004	/* 8bit */
#define	SH7709_IRR1		0xa4000006	/* 8bit */
#define	SH7709_IRR2		0xa4000008	/* 8bit */

#define	IPRC_IRQ3_MASK		0xf000
#define	IPRC_IRQ2_MASK		0x0f00
#define	IPRC_IRQ1_MASK		0x00f0
#define	IPRC_IRQ0_MASK		0x000f

#define	IPRD_PINT07_MASK	0xf000
#define	IPRD_PINT8F_MASK	0x0f00
#define	IPRD_IRQ5_MASK		0x00f0
#define	IPRD_IRQ4_MASK		0x000f

#define	IPRE_DMAC_MASK		0xf000
#define	IPRE_IRDA_MASK		0x0f00
#define	IPRE_SCIF_MASK		0x00f0
#define	IPRE_ADC_MASK		0x000f

#define IRR0_PINT8F		0x80
#define IRR0_PINT07		0x40
#define IRR0_IRQ5		0x20
#define IRR0_IRQ4		0x10
#define IRR0_IRQ3		0x08
#define IRR0_IRQ2		0x04
#define IRR0_IRQ1		0x02
#define IRR0_IRQ0		0x01

/* SH4 */
#define	SH4_ICR			0xffd00000	/* 16bit */
#define	SH4_IPRA		0xffd00004	/* 16bit */
#define	SH4_IPRB		0xffd00008	/* 16bit */
#define	SH4_IPRC		0xffd0000c	/* 16bit */
#define	SH4_IPRD		0xffd00010	/* 16bit */
#define	SH4_INTPRI00		0xfe080000	/* 32bit */
#define	SH4_INTREQ00		0xfe080020	/* 32bit */
#define	SH4_INTMSK00		0xfe080040	/* 32bit */
#define	SH4_INTMSKCLR00		0xfe080060	/* 32bit */

#define	IPRC_GPIO_MASK		0xf000
#define	IPRC_DMAC_MASK		0x0f00
#define	IPRC_SCIF_MASK		0x00f0
#define	IPRC_HUDI_MASK		0x000f

#define	IPRD_IRL0_MASK		0xf000
#define	IPRD_IRL1_MASK		0x0f00
#define	IPRD_IRL2_MASK		0x00f0
#define	IPRD_IRL3_MASK		0x000f

#define	IPRA_TMU0_MASK		0xf000
#define	IPRA_TMU1_MASK		0x0f00
#define	IPRA_TMU2_MASK		0x00f0
#define	IPRA_RTC_MASK		0x000f

#define	IPRB_WDT_MASK		0xf000
#define	IPRB_REF_MASK		0x0f00
#define	IPRB_SCI_MASK		0x00f0

#define	INTPRI00_PCI0_MASK      0x0000000f
#define	INTPRI00_PCI1_MASK      0x000000f0
#define	INTPRI00_TMU3_MASK      0x00000f00
#define	INTPRI00_TMU4_MASK      0x0000f000

/* INTREQ/INTMSK/INTMSKCLR */
#define	INTREQ00_PCISERR	0x00000001
#define	INTREQ00_PCIDMA3	0x00000002
#define	INTREQ00_PCIDMA2	0x00000004
#define	INTREQ00_PCIDMA1	0x00000008
#define	INTREQ00_PCIDMA0	0x00000010
#define	INTREQ00_PCIPWON	0x00000020
#define	INTREQ00_PCIPWDWN	0x00000040
#define	INTREQ00_PCIERR		0x00000080
#define	INTREQ00_TUNI3		0x00000100
#define	INTREQ00_TUNI4		0x00000200

#define	INTMSK00_MASK_ALL	0x000003ff

#endif /* !_SH_INTCREG_H_ */


code:
/*	$OpenBSD: intr.h,v 1.9 2015/02/11 07:05:39 dlg Exp $	*/
/*	$NetBSD: intr.h,v 1.22 2006/01/24 23:51:42 uwe Exp $	*/

/*-
 * Copyright (c) 2002 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef _SH_INTR_H_
#define	_SH_INTR_H_

#ifdef	_KERNEL

#include <sys/device.h>
#include <sys/evcount.h>
#include <sys/mutex.h>
#include <sys/queue.h>
#include <sh/psl.h>

/* Interrupt sharing types. */
#define	IST_NONE		0	/* none */
#define	IST_PULSE		1	/* pulsed */
#define	IST_EDGE		2	/* edge-triggered */
#define	IST_LEVEL		3	/* level-triggered */

/* Interrupt priority levels */
#define	_IPL_N		15
#define	_IPL_NSOFT	4

#define	IPL_NONE	0	/* nothing */
#define	IPL_SOFT	1
#define	IPL_SOFTCLOCK	2	/* timeouts */
#define	IPL_SOFTNET	3	/* protocol stacks */
#define	IPL_SOFTSERIAL	4	/* serial */

#define	IPL_SOFTNAMES {							\
	"misc",								\
	"clock",							\
	"net",								\
	"serial",							\
}

struct intc_intrhand {
	int	(*ih_func)(void *);
	void	*ih_arg;
	int	ih_level;	/* SR.I[0:3] value */
	int	ih_evtcode;	/* INTEVT or INTEVT2(SH7709/SH7709A) */
	int	ih_idx;		/* evtcode -> intrhand mapping */
	int	ih_irq;
	struct evcount ih_count;
	const char *ih_name;
};

/* from 0x200 by 0x20 -> from 0 by 1 */
#define	EVTCODE_TO_MAP_INDEX(x)		(((x) >> 5) - 0x10)
#define	EVTCODE_TO_IH_INDEX(x)						\
	__intc_evtcode_to_ih[EVTCODE_TO_MAP_INDEX(x)]
#define	EVTCODE_IH(x)	(&__intc_intrhand[EVTCODE_TO_IH_INDEX(x)])
extern int8_t __intc_evtcode_to_ih[];
extern struct intc_intrhand __intc_intrhand[];

void intc_init(void);
void *intc_intr_establish(int, int, int, int (*)(void *), void *, const char *);
void intc_intr_disestablish(void *);
void intc_intr_enable(int);
void intc_intr_disable(int);
void intc_intr(int, int, int);

void intpri_intr_priority(int evtcode, int level);

/*
 * software simulated interrupt
 */
struct sh_soft_intrhand {
	TAILQ_ENTRY(sh_soft_intrhand) sih_q;
	struct sh_soft_intr *sih_intrhead;
	void	(*sih_fn)(void *);
	void	*sih_arg;
	int	sih_pending;
};

struct sh_soft_intr {
	TAILQ_HEAD(, sh_soft_intrhand)
			softintr_q;
	unsigned long	softintr_ipl;
	struct mutex	softintr_lock;
};

void	 softintr_disestablish(void *);
void	 softintr_dispatch(int);
void	*softintr_establish(int, void (*)(void *), void *);
void	 softintr_init(void);
void	 softintr_schedule(void *);

#endif	/* _KERNEL */

#endif /* !_SH_INTR_H_ */


code:
/*	$OpenBSD: kcore.h,v 1.1 2007/03/03 21:37:27 miod Exp $	*/

/*
 * Copyright (c) 2007 Miodrag Vallat.
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice, this permission notice, and the disclaimer below
 * appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#ifndef	_SH_KCORE_H_
#define	_SH_KCORE_H_

/* this should be >= VM_PHYSSEG_MAX from <machine/vmparam.h> */
#define	NPHYS_RAM_SEGS	8

typedef struct cpu_kcore_hdr {
	paddr_t		kcore_kptp;
	unsigned int	kcore_nsegs;
	phys_ram_seg_t	kcore_segs[NPHYS_RAM_SEGS];
} cpu_kcore_hdr_t;

#endif	/* _SH_KCORE_H_ */


code:
/*	$OpenBSD: limits.h,v 1.4 2015/04/30 13:42:08 millert Exp $	*/
/*	$NetBSD: limits.h,v 1.1 1996/09/30 16:34:28 ws Exp $	*/

/*-
 * Copyright (C) 1995, 1996 Wolfgang Solfrank.
 * Copyright (C) 1995, 1996 TooLs GmbH.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by TooLs GmbH.
 * 4. The name of TooLs GmbH may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef _SH_LIMITS_H_
#define _SH_LIMITS_H_

#include <sys/cdefs.h>

#if __POSIX_VISIBLE || __XPG_VISIBLE
#define	SSIZE_MAX	LONG_MAX	/* max value for a ssize_t */
#endif

#if __BSD_VISIBLE
#define	SIZE_T_MAX	ULONG_MAX	/* max value for a size_t (historic) */

#define	UQUAD_MAX	0xffffffffffffffffULL		/* max unsigned quad */
#define	QUAD_MAX	0x7fffffffffffffffLL		/* max signed quad */
#define	QUAD_MIN	(-0x7fffffffffffffffLL-1)	/* min signed quad */
#endif	/* __BSD_VISIBLE */

#endif /* _SH_LIMITS_H_ */


code:
/*	$OpenBSD: lock.h,v 1.4 2013/05/21 20:05:30 tedu Exp $	*/
/*	$NetBSD: lock.h,v 1.10 2006/01/03 01:29:46 uwe Exp $	*/

/*-
 * Copyright (c) 2002 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Gregory McGarry.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * Machine-dependent spin lock operations.
 */

#ifndef _SH_LOCK_H_
#define	_SH_LOCK_H_

#include <sh/atomic.h>

#endif /* !_SH_LOCK_H_ */


code:
/*	$OpenBSD: locore.h,v 1.5 2010/09/06 08:00:31 jsg Exp $	*/
/*	$NetBSD: locore.h,v 1.11 2006/01/23 22:32:50 uwe Exp $	*/

/*-
 * Copyright (c) 2002 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#if defined(SH3) && defined(SH4)
#define	MOV(x, r)	mov.l .L_##x, r; mov.l @r, r
#define	REG_SYMBOL(x)	.L_##x:	.long	_C_LABEL(__sh_##x)
#define	FUNC_SYMBOL(x)	.L_##x:	.long	_C_LABEL(__sh_##x)
#elif defined(SH3)
#define	MOV(x, r)	mov.l .L_##x, r
#define	REG_SYMBOL(x)	.L_##x:	.long	SH3_##x
#define	FUNC_SYMBOL(x)	.L_##x:	.long	_C_LABEL(sh3_##x)
#elif defined(SH4)
#define	MOV(x, r)	mov.l .L_##x, r
#define	REG_SYMBOL(x)	.L_##x:	.long	SH4_##x
#define	FUNC_SYMBOL(x)	.L_##x:	.long	_C_LABEL(sh4_##x)
#endif /* SH3 && SH4 */

/*
 * BANK1 r7 contains kernel stack top address.
 * BANK1 r6 contains current frame pointer. (per process)
 */
/*
 * __EXCEPTION_ENTRY:
 *	+ setup stack pointer
 *	+ save all register to frame. (struct trapframe)
 *	+ setup kernel stack.
 *	+ change bank from 1 to 0
 *	+ set BANK0 (r4, r5, r6) = (ssr, spc, ssp)
 */
#define	__EXCEPTION_ENTRY						;\
	/* Check kernel/user mode. */					;\
	mov	#0x40,	r3						;\
	swap.b	r3,	r3						;\
	stc	ssr,	r2						;\
	swap.w	r3,	r3	/* r3 = 0x40000000 */			;\
	mov	r2,	r0	/* r2 = r0 = SSR */			;\
	and	r3,	r0						;\
	tst	r0,	r0	/* if (SSR.MD == 0) T = 1 */		;\
	mov	r14,	r1						;\
	mov	r6,	r14	/* frame pointer */			;\
	bf/s	1f		/* T==0 ...Exception from kernel mode */;\
	 mov	r15,	r0						;\
	/* Exception from user mode */					;\
	mov	r7,	r15	/* change to kernel stack */		;\
1:									;\
	/* Save registers */						;\
	mov.l	r1,	@-r14	/* tf_r14 */				;\
	mov.l	r0,	@-r14	/* tf_r15 */				;\
	stc.l	r0_bank,@-r14	/* tf_r0  */				;\
	stc.l	r1_bank,@-r14	/* tf_r1  */				;\
	stc.l	r2_bank,@-r14	/* tf_r2  */				;\
	stc.l	r3_bank,@-r14	/* tf_r3  */				;\
	stc.l	r4_bank,@-r14	/* tf_r4  */				;\
	stc.l	r5_bank,@-r14	/* tf_r5  */				;\
	stc.l	r6_bank,@-r14	/* tf_r6  */				;\
	stc.l	r7_bank,@-r14	/* tf_r7  */				;\
	mov.l	r8,	@-r14	/* tf_r8  */				;\
	mov.l	r9,	@-r14	/* tf_r9  */				;\
	mov.l	r10,	@-r14	/* tf_r10 */				;\
	mov.l	r11,	@-r14	/* tf_r11 */				;\
	mov.l	r12,	@-r14	/* tf_r12 */				;\
	mov.l	r13,	@-r14	/* tf_r13 */				;\
	sts.l	pr,	@-r14	/* tf_pr  */				;\
	sts.l	mach,	@-r14	/* tf_mach*/				;\
	sts.l	macl,	@-r14	/* tf_macl*/				;\
	mov.l	r2,	@-r14	/* tf_ssr */				;\
	stc.l	spc,	@-r14	/* tf_spc */				;\
	add	#-TF_SPC, r14	/* skip tf_ubc, tf_expevt */		;\
	mov	r14,	r6	/* store frame pointer */		;\
	/* Change register bank to 0 */					;\
	shlr	r3		/* r3 = 0x20000000 */			;\
	stc	sr,	r1	/* r1 = SR */				;\
	not	r3,	r3						;\
	and	r1,	r3						;\
	ldc	r3,	sr	/* SR.RB = 0 */				;\
	/* Set up argument. r4 = ssr, r5 = spc */			;\
	stc	r2_bank,r4						;\
	stc	spc,	r5

/*
 * __EXCEPTION_RETURN:
 *	+ block exception
 *	+ restore all register from stack.
 *	+ rte.
 */
#define	__EXCEPTION_RETURN						;\
	mov	#0x10,	r0						;\
	swap.b	r0,	r0						;\
	swap.w	r0,	r0	/* r0 = 0x10000000 */			;\
	stc	sr,	r1						;\
	or	r0,	r1						;\
	ldc	r1,	sr	/* SR.BL = 1 */				;\
	stc	r6_bank,r0						;\
	mov	r0,	r14						;\
	add	#TF_SIZE, r0						;\
	ldc	r0,	r6_bank	/* roll up frame pointer */		;\
	add	#TF_SPC, r14	/* skip tf_expevt, tf_ubc */		;\
	mov.l	@r14+,	r0	/* tf_spc */				;\
	ldc	r0,	spc						;\
	mov.l	@r14+,	r0	/* tf_ssr */				;\
	ldc	r0,	ssr						;\
	lds.l	@r14+,	macl	/* tf_macl*/				;\
	lds.l	@r14+,	mach	/* tf_mach*/				;\
	lds.l	@r14+,	pr	/* tf_pr  */				;\
	mov.l	@r14+,	r13	/* tf_r13 */				;\
	mov.l	@r14+,	r12	/* tf_r12 */				;\
	mov.l	@r14+,	r11	/* tf_r11 */				;\
	mov.l	@r14+,	r10	/* tf_r10 */				;\
	mov.l	@r14+,	r9	/* tf_r9  */				;\
	mov.l	@r14+,	r8	/* tf_r8  */				;\
	mov.l	@r14+,	r7	/* tf_r7  */				;\
	mov.l	@r14+,	r6	/* tf_r6  */				;\
	mov.l	@r14+,	r5	/* tf_r5  */				;\
	mov.l	@r14+,	r4	/* tf_r4  */				;\
	mov.l	@r14+,	r3	/* tf_r3  */				;\
	mov.l	@r14+,	r2	/* tf_r2  */				;\
	mov.l	@r14+,	r1	/* tf_r1  */				;\
	mov.l	@r14+,	r0	/* tf_r0  */				;\
	mov.l	@r14+	r15	/* tf_r15 */				;\
	mov.l	@r14+,	r14	/* tf_r14 */				;\
	rte								;\
	 nop

/*
 * Macros to disable and enable exceptions (including interrupts).
 * This modifies SR.BL
 */
#define	__0x10	#0x10
#define	__0x78	#0x78

#define	__EXCEPTION_BLOCK(Rn, Rm)					;\
	mov	__0x10,	Rn						;\
	swap.b	Rn,	Rn						;\
	swap.w	Rn,	Rn	/* Rn = 0x10000000 */			;\
	stc	sr,	Rm						;\
	or	Rn,	Rm						;\
	ldc	Rm,	sr	/* block exceptions */

#define	__EXCEPTION_UNBLOCK(Rn, Rm)					;\
	mov	__0x10,	Rn						;\
	swap.b	Rn,	Rn						;\
	swap.w	Rn,	Rn	/* Rn = 0x10000000 */			;\
	not	Rn,	Rn						;\
	stc	sr,	Rm						;\
	and	Rn,	Rm						;\
	ldc	Rm,	sr	/* unblock exceptions */

/*
 * Macros to disable and enable interrupts.
 * This modifies SR.I[0-3]
 */
#define	__INTR_MASK(Rn, Rm)						;\
	mov	__0x78,	Rn						;\
	shll	Rn		/* Rn = 0x000000f0 */			;\
	stc	sr,	Rm						;\
	or	Rn,	Rm						;\
	ldc	Rm,	sr	/* mask all interrupt */

#define	__INTR_UNMASK(Rn, Rm)						;\
	mov	__0x78,	Rn						;\
	shll	Rn		/* Rn = 0x000000f0 */			;\
	not	Rn,	Rn						;\
	stc	sr,	Rm						;\
	and	Rn,	Rm						;\
	ldc	Rm,	sr	/* unmask all interrupt */

#ifndef _LOCORE
void sh3_switch_setup(struct proc *);
void sh4_switch_setup(struct proc *);
void sh3_switch_resume(struct proc *);
void sh4_switch_resume(struct proc *);
extern void (*__sh_switch_resume)(struct proc *);
#endif /* !_LOCORE */


code:
/*	$OpenBSD: mmu.h,v 1.2 2008/06/26 05:42:12 ray Exp $	*/
/*	$NetBSD: mmu.h,v 1.9 2006/03/04 01:55:03 uwe Exp $	*/

/*-
 * Copyright (c) 2002 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by UCHIYAMA Yasushi.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef _SH_MMU_H_
#define	_SH_MMU_H_

/*
 * Initialize routines.
 *	sh_mmu_init		Assign function vector. Don't access hardware.
 *				Call as early as possible.
 *	sh_mmu_start		Reset TLB entry, set default ASID, and start to
 *				translate addresses.
 *				Call after exception vector was installed.
 *
 * TLB access ops.
 *	sh_tlb_invalidate_addr	invalidate TLB entris for given
 *				virtual addr with ASID.
 *	sh_tlb_invalidate_asid	invalidate TLB entries for given ASID.
 *	sh_tlb_invalidate_all	invalidate all non-wired TLB entries.
 *	sh_tlb_set_asid		set ASID.
 *	sh_tlb_update		load new PTE to TLB.
 *
 */

void sh_mmu_init(void);
void sh_mmu_information(void);
void sh_tlb_set_asid(int);

#ifdef SH3
void sh3_mmu_start(void);
void sh3_tlb_invalidate_addr(int, vaddr_t);
void sh3_tlb_invalidate_asid(int);
void sh3_tlb_invalidate_all(void);
void sh3_tlb_update(int, vaddr_t, uint32_t);
#endif

#ifdef SH4
void sh4_mmu_start(void);
void sh4_tlb_invalidate_addr(int, vaddr_t);
void sh4_tlb_invalidate_asid(int);
void sh4_tlb_invalidate_all(void);
void sh4_tlb_update(int, vaddr_t, uint32_t);
#endif

#if defined(SH3) && defined(SH4)
extern uint32_t __sh_PTEH;

extern void (*__sh_mmu_start)(void);
extern void (*__sh_tlb_invalidate_addr)(int, vaddr_t);
extern void (*__sh_tlb_invalidate_asid)(int);
extern void (*__sh_tlb_invalidate_all)(void);
extern void (*__sh_tlb_update)(int, vaddr_t, uint32_t);

#define	sh_mmu_start()			(*__sh_mmu_start)()
#define	sh_tlb_invalidate_addr(a, va)	(*__sh_tlb_invalidate_addr)(a, va)
#define	sh_tlb_invalidate_asid(a)	(*__sh_tlb_invalidate_asid)(a)
#define	sh_tlb_invalidate_all()		(*__sh_tlb_invalidate_all)()
#define	sh_tlb_update(a, va, pte)	(*__sh_tlb_update)(a, va, pte)

#elif defined(SH3)

#define	sh_mmu_start()			sh3_mmu_start()
#define	sh_tlb_invalidate_addr(a, va)	sh3_tlb_invalidate_addr(a, va)
#define	sh_tlb_invalidate_asid(a)	sh3_tlb_invalidate_asid(a)
#define	sh_tlb_invalidate_all()		sh3_tlb_invalidate_all()
#define	sh_tlb_update(a, va, pte)	sh3_tlb_update(a, va, pte)

#elif defined(SH4)

#define	sh_mmu_start()			sh4_mmu_start()
#define	sh_tlb_invalidate_addr(a, va)	sh4_tlb_invalidate_addr(a, va)
#define	sh_tlb_invalidate_asid(a)	sh4_tlb_invalidate_asid(a)
#define	sh_tlb_invalidate_all()		sh4_tlb_invalidate_all()
#define	sh_tlb_update(a, va, pte)	sh4_tlb_update(a, va, pte)

#endif

#endif /* !_SH_MMU_H_ */


code:
/*	$OpenBSD: mmu_sh3.h,v 1.2 2008/06/26 05:42:12 ray Exp $	*/
/*	$NetBSD: mmu_sh3.h,v 1.6 2006/03/04 01:55:03 uwe Exp $	*/

/*-
 * Copyright (c) 2002 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by UCHIYAMA Yasushi.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef _SH_MMU_SH3_H_
#define	_SH_MMU_SH3_H_
#include <sh/devreg.h>

/* 128-entry 4-way set-associative */
#define	SH3_MMU_WAY			4
#define	SH3_MMU_ENTRY			32

#define	SH3_PTEH			0xfffffff0
#define	  SH3_PTEH_ASID_MASK		  0x000000ff
#define	  SH3_PTEH_VPN_MASK		  0xfffffc00
#define	SH3_PTEL			0xfffffff4
#define	  SH3_PTEL_HWBITS		  0x1ffff17e /* [28:12][8][6:1] */
#define	SH3_TTB				0xfffffff8
#define	SH3_TEA				0xfffffffc
#define	SH3_MMUCR			0xffffffe0
#define	  SH3_MMUCR_AT			  0x00000001
#define	  SH3_MMUCR_IX			  0x00000002
#define	  SH3_MMUCR_TF			  0x00000004
#define	  SH3_MMUCR_RC			  0x00000030
#define	  SH3_MMUCR_SV			  0x00000100

/*
 * memory-mapped TLB
 */
/* Address array */
#define	SH3_MMUAA			0xf2000000
/* address specification */
#define	  SH3_MMU_VPN_SHIFT		  12
#define	  SH3_MMU_VPN_MASK		  0x0001f000	/* [16:12] */
#define	  SH3_MMU_WAY_SHIFT		  8
#define	  SH3_MMU_WAY_MASK		  0x00000300	/* [9:8] */
/* data specification */
#define	  SH3_MMU_D_VALID		  0x00000100
#define	  SH3_MMUAA_D_VPN_MASK_1K	  0xfffe0c00	/* [31:17][11:10] */
#define	  SH3_MMUAA_D_VPN_MASK_4K	  0xfffe0000	/* [31:17] */
#define	  SH3_MMUAA_D_ASID_MASK		  0x000000ff

/* Data array */
#define	SH3_MMUDA			0xf3000000
#define	  SH3_MMUDA_D_PPN_MASK		  0xfffffc00
#define	  SH3_MMUDA_D_V			  0x00000100
#define	  SH3_MMUDA_D_PR_SHIFT		  5
#define	  SH3_MMUDA_D_PR_MASK		  0x00000060	/* [6:5] */
#define	  SH3_MMUDA_D_SZ		  0x00000010
#define	  SH3_MMUDA_D_C			  0x00000008
#define	  SH3_MMUDA_D_D			  0x00000004
#define	  SH3_MMUDA_D_SH		  0x00000002

#define	SH3_TLB_DISABLE	*(volatile uint32_t *)SH3_MMUCR = SH3_MMUCR_TF
#endif /* !_SH_MMU_SH3_H_ */


code:
/*	$OpenBSD: mmu_sh4.h,v 1.2 2008/06/26 05:42:12 ray Exp $	*/
/*	$NetBSD: mmu_sh4.h,v 1.6 2006/03/04 01:55:03 uwe Exp $	*/

/*-
 * Copyright (c) 2002 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by UCHIYAMA Yasushi.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef _SH_MMU_SH4_H_
#define	_SH_MMU_SH4_H_
#include <sh/devreg.h>

/* ITLB 4-entry full-associative UTLB 64-entry full-associative */
#define	SH4_PTEH			0xff000000
#define	  SH4_PTEH_VPN_MASK		  0xfffffc00
#define	  SH4_PTEH_ASID_MASK		  0x000000ff
#define	SH4_PTEL			0xff000004
#define	  SH4_PTEL_WT			  0x00000001
#define	  SH4_PTEL_SH			  0x00000002
#define	  SH4_PTEL_D			  0x00000004
#define	  SH4_PTEL_C			  0x00000008
#define	  SH4_PTEL_PR_SHIFT		  5
#define	  SH4_PTEL_PR_MASK		  0x00000060	/* [5:6] */
#define	  SH4_PTEL_SZ_MASK		  0x00000090	/* [4][7] */
#define	    SH4_PTEL_SZ_1K		  0x00000000
#define	    SH4_PTEL_SZ_4K		  0x00000010
#define	    SH4_PTEL_SZ_64K		  0x00000080
#define	    SH4_PTEL_SZ_1M		  0x00000090
#define	  SH4_PTEL_V			  0x00000100
#define	  SH4_PTEL_HWBITS		  0x1ffff1ff /* [28:12]PFN [8:0]attr. */

#define	SH4_PTEA			0xff000034
#define	  SH4_PTEA_SA_MASK		  0x00000007
#define	  SH4_PTEA_SA_TC		  0x00000008
#define	SH4_TTB				0xff000008
#define	SH4_TEA				0xff00000c
#define	SH4_MMUCR			0xff000010
#define	  SH4_MMUCR_AT			  0x00000001
#define	  SH4_MMUCR_TI			  0x00000004
#define	  SH4_MMUCR_SV			  0x00000100
#define	  SH4_MMUCR_SQMD		  0x00000200
#define	  SH4_MMUCR_URC_SHIFT		  10
#define	  SH4_MMUCR_URC_MASK		  0x0000fc00	/* [10:15] */
#define	  SH4_MMUCR_URB_SHIFT		  18
#define	  SH4_MMUCR_URB_MASK		  0x00fc0000	/* [18:23] */
#define	  SH4_MMUCR_LRUI_SHIFT		  26
#define	  SH4_MMUCR_LRUT_MASK		  0xfc000000	/* [26:31] */

#define	  SH4_MMUCR_MASK	(SH4_MMUCR_LRUT_MASK | SH4_MMUCR_URB_MASK | \
    SH4_MMUCR_URC_MASK | SH4_MMUCR_SQMD | SH4_MMUCR_SV | SH4_MMUCR_AT)
/*
 * memory-mapped TLB
 *	must be access from P2-area program.
 *	branch to the other area must be maed at least 8 instruction
 *	after access.
 */
#define	SH4_ITLB_ENTRY		4
#define	SH4_UTLB_ENTRY		64

/* ITLB */
#define	SH4_ITLB_AA			0xf2000000
/* address specification (common for address and data array(0,1)) */
#define	  SH4_ITLB_E_SHIFT		  8
#define	  SH4_ITLB_E_MASK		  0x00000300	/* [9:8] */
/* data specification */
/* address-array */
#define	  SH4_ITLB_AA_ASID_MASK		  0x000000ff	/* [7:0] */
#define	  SH4_ITLB_AA_V			  0x00000100
#define	  SH4_ITLB_AA_VPN_SHIFT		  10
#define	  SH4_ITLB_AA_VPN_MASK		  0xfffffc00	/* [31:10] */
/* data-array 1 */
#define	SH4_ITLB_DA1			0xf3000000
#define	  SH4_ITLB_DA1_SH		  0x00000002
#define	  SH4_ITLB_DA1_C		  0x00000008
#define	  SH4_ITLB_DA1_SZ_MASK		  0x00000090	/* [7][4] */
#define	    SH4_ITLB_DA1_SZ_1K		  0x00000000
#define	    SH4_ITLB_DA1_SZ_4K		  0x00000010
#define	    SH4_ITLB_DA1_SZ_64K		  0x00000080
#define	    SH4_ITLB_DA1_SZ_1M		  0x00000090
#define	  SH4_ITLB_DA1_PR		  0x00000040
#define	  SH4_ITLB_DA1_V		  0x00000100
#define	  SH4_ITLB_DA1_PPN_SHIFT	  11
#define	  SH4_ITLB_DA1_PPN_MASK		  0x1ffffc00	/* [28:10] */
/* data-array 2 */
#define	SH4_ITLB_DA2			0xf3800000
#define	  SH4_ITLB_DA2_SA_MASK		  0x00000003
#define	  SH4_ITLB_DA2_TC		  0x00000004

/* UTLB */
#define	SH4_UTLB_AA			0xf6000000
/* address specification (common for address and data array(0,1)) */
#define	  SH4_UTLB_E_SHIFT		  8
#define	  SH4_UTLB_E_MASK		  0x00003f00
#define	  SH4_UTLB_A			  0x00000080
/* data specification */
/* address-array */
#define	  SH4_UTLB_AA_VPN_MASK		  0xfffffc00	/* [31:10] */
#define	  SH4_UTLB_AA_D			  0x00000200
#define	  SH4_UTLB_AA_V			  0x00000100
#define	  SH4_UTLB_AA_ASID_MASK		  0x000000ff	/* [7:0] */
/* data-array 1 */
#define	SH4_UTLB_DA1			0xf7000000
#define	  SH4_UTLB_DA1_WT		  0x00000001
#define	  SH4_UTLB_DA1_SH		  0x00000002
#define	  SH4_UTLB_DA1_D		  0x00000004
#define	  SH4_UTLB_DA1_C		  0x00000008
#define	  SH4_UTLB_DA1_SZ_MASK		  0x00000090	/* [7][4] */
#define	    SH4_UTLB_DA1_SZ_1K		  0x00000000
#define	    SH4_UTLB_DA1_SZ_4K		  0x00000010
#define	    SH4_UTLB_DA1_SZ_64K		  0x00000080
#define	    SH4_UTLB_DA1_SZ_1M		  0x00000090
#define	  SH4_UTLB_DA1_PR_SHIFT		  5
#define	  SH4_UTLB_DA1_PR_MASK		  0x00000060
#define	  SH4_UTLB_DA1_V		  0x00000100
#define	  SH4_UTLB_DA1_PPN_SHIFT	  11
#define	  SH4_UTLB_DA1_PPN_MASK		  0x1ffffc00	/* [28:10] */
/* data-array 2 */
#define	SH4_UTLB_DA2			0xf7800000
#define	  SH4_UTLB_DA2_SA_MASK		  0x00000003
#define	  SH4_UTLB_DA2_TC		  0x00000004

#define	SH4_TLB_DISABLE	*(volatile uint32_t *)SH4_MMUCR = SH4_MMUCR_TI
#endif /* !_SH_MMU_SH4_H_ */


code:
/*	$OpenBSD: mutex.h,v 1.2 2007/05/05 12:06:20 miod Exp $	*/

/*
 * Copyright (c) 2004 Artur Grabowski <art@openbsd.org>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef _SH_MUTEX_H_
#define _SH_MUTEX_H_

/*
 * Simple non-mp implementation.
 */
struct mutex {
	int mtx_lock;
	int mtx_wantipl;
	int mtx_oldipl;
};

void mtx_init(struct mutex *, int);

#define MUTEX_INITIALIZER(ipl) { 0, (ipl) << 4, 0 }

#ifdef DIAGNOSTIC
#define MUTEX_ASSERT_LOCKED(mtx) do {					\
	if ((mtx)->mtx_lock == 0)					\
		panic("mutex %p not held in %s", (mtx), __func__);	\
} while (0)

#define MUTEX_ASSERT_UNLOCKED(mtx) do {					\
	if ((mtx)->mtx_lock != 0)					\
		panic("mutex %p held in %s", (mtx), __func__);		\
} while (0)
#else
#define MUTEX_ASSERT_LOCKED(mtx) do { } while (0)
#define MUTEX_ASSERT_UNLOCKED(mtx) do { } while (0)
#endif

#define MUTEX_OLDIPL(mtx)	(mtx)->mtx_oldipl

#endif	/* _SH_MUTEX_H_ */


code:
/*	$OpenBSD: param.h,v 1.11 2013/03/26 05:04:10 deraadt Exp $	*/

/*-
 * Copyright (c) 2002 The NetBSD Foundation, Inc. All rights reserved.
 * Copyright (c) 1990 The Regents of the University of California.
 * All rights reserved.
 *
 * This code is derived from software contributed to Berkeley by
 * William Jolitz.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#ifndef	_SH_PARAM_H_
#define	_SH_PARAM_H_

#define	_MACHINE_ARCH	sh
#define	MACHINE_ARCH	"sh"

#ifndef	MID_MACHINE
#define	MID_MACHINE	MID_SH3
#endif

#if defined(_KERNEL) && !defined(_LOCORE)
#include <sh/cpu.h>
#endif

/*
 * We use 4K pages on the sh3/sh4.  Override the PAGE_* definitions
 * to be compile-time constants.
 */
#define	PAGE_SHIFT		12
#define	PAGE_SIZE		(1 << PAGE_SHIFT)
#define	PAGE_MASK		(PAGE_SIZE - 1)

#ifdef _KERNEL

#define	NBPG			PAGE_SIZE
#define	PGSHIFT			PAGE_SHIFT
#define	PGOFSET			PAGE_MASK

#endif

/*
 * u-space.
 */
#define	UPAGES		3			/* pages of u-area */
#define	USPACE		(UPAGES * PAGE_SIZE)	/* total size of u-area */
#define	USPACE_ALIGN	(0)

#if UPAGES == 1
#error "too small u-area"
#elif UPAGES == 2
#define	P1_STACK	/* kernel stack is P1-area */
#else
#undef	P1_STACK	/* kernel stack is P3-area */
#endif

#ifdef _KERNEL

#define	NMBCLUSTERS	4096			/* map size, max cluster allocation */

#ifndef MSGBUFSIZE
#define	MSGBUFSIZE	PAGE_SIZE		/* default message buffer size */
#endif

/*
 * Maximum size of the kernel malloc arena in PAGE_SIZE-sized
 * logical pages.
 */
#define	NKMEMPAGES_MAX_DEFAULT	((64 * 1024 * 1024) >> PAGE_SHIFT)

#endif /* _KERNEL */

#endif /* _SH_PARAM_H_ */


code:
/*	$OpenBSD: pcb.h,v 1.4 2015/05/05 02:13:47 guenther Exp $	*/
/*	$NetBSD: pcb.h,v 1.7 2002/05/09 12:28:08 uch Exp $	*/

/*-
 * Copyright (c) 2002 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by UCHIYAMA Yasushi.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef _SH_PCB_H_
#define	_SH_PCB_H_

#include <sh/frame.h>
#include <sh/reg.h>

struct pcb {
	struct	switchframe	pcb_sf;		/* kernel context for resume */
	caddr_t			pcb_onfault;	/* for copyin/out fault */
	struct	fpreg		pcb_fp;		/* fp context for resume */
};

extern struct pcb *curpcb;

#endif /* !_SH_PCB_H_ */


code:
/*	$OpenBSD: pmap.h,v 1.14 2015/02/15 21:34:33 miod Exp $	*/
/*	$NetBSD: pmap.h,v 1.28 2006/04/10 23:12:11 uwe Exp $	*/

/*-
 * Copyright (c) 2002 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by UCHIYAMA Yasushi.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * OpenBSD/sh pmap:
 *	pmap.pm_ptp[512] ... 512 slot of page table page
 *	page table page contains 1024 PTEs. (PAGE_SIZE / sizeof(pt_entry_t))
 *	  | PTP 11bit | PTOFSET 10bit | PAGE_MASK 12bit |
 */

#ifndef _SH_PMAP_H_
#define	_SH_PMAP_H_

#include <sh/pte.h>

#ifdef _KERNEL
#include <sys/queue.h>

#define	PMAP_STEAL_MEMORY
#define	PMAP_GROWKERNEL

#define	__PMAP_PTP_N	512	/* # of page table page maps 2GB. */
typedef struct pmap {
	pt_entry_t **pm_ptp;
	int pm_asid;
	int pm_refcnt;
	struct pmap_statistics	pm_stats;	/* pmap statistics */
} *pmap_t;
extern struct pmap __pmap_kernel;

void pmap_bootstrap(void);
#define	pmap_unuse_final(p)		do { /* nothing */ } while (0)
#define	pmap_remove_holes(vm)		do { /* nothing */ } while (0)
#define	pmap_kernel()			(&__pmap_kernel)
#define	pmap_deactivate(pmap)		do { /* nothing */ } while (0)
#define	pmap_update(pmap)		do { /* nothing */ } while (0)
#define	pmap_copy(dp,sp,d,l,s)		do { /* nothing */ } while (0)
#define	pmap_collect(pmap)		do { /* nothing */ } while (0)
#define	pmap_wired_count(pmap)		((pmap)->pm_stats.wired_count)
#define	pmap_resident_count(pmap)	((pmap)->pm_stats.resident_count)

/* ARGSUSED */
static __inline void
pmap_remove_all(struct pmap *pmap)
{
	/* Nothing. */
}

/*
 * pmap_prefer() helps to avoid virtual cache aliases on SH4 CPUs
 * which have the virtually-indexed cache.
 */
#ifdef SH4
#define	PMAP_PREFER(pa, va)		pmap_prefer((pa), (va))
vaddr_t	pmap_prefer(vaddr_t, vaddr_t);
vaddr_t	pmap_prefer_align(void);
vaddr_t	pmap_prefer_offset(vaddr_t);

/* pmap prefer alignment */
#define PMAP_PREFER_ALIGN()		pmap_prefer_align()
/* pmap prefer offset in alignment */
#define PMAP_PREFER_OFFSET(of)		pmap_prefer_offset(of)
#endif /* SH4 */

#define	__HAVE_PMAP_DIRECT
vaddr_t	pmap_map_direct(vm_page_t);
vm_page_t pmap_unmap_direct(vaddr_t);

/* MD pmap utils. */
pt_entry_t *__pmap_pte_lookup(pmap_t, vaddr_t);
pt_entry_t *__pmap_kpte_lookup(vaddr_t);
boolean_t __pmap_pte_load(pmap_t, vaddr_t, int);

#endif /* !_KERNEL */

#define	PVH_REFERENCED		1
#define	PVH_MODIFIED		2

#ifndef _LOCORE
struct pv_entry;
struct vm_page_md {
	SLIST_HEAD(, pv_entry) pvh_head;
	int pvh_flags;
};

#define	VM_MDPAGE_INIT(pg)						\
do {									\
	struct vm_page_md *pvh = &(pg)->mdpage;				\
	SLIST_INIT(&pvh->pvh_head);					\
	pvh->pvh_flags = 0;						\
} while (/*CONSTCOND*/0)
#endif /* _LOCORE */

#endif /* !_SH_PMAP_H_ */


code:
/*	$OpenBSD: proc.h,v 1.2 2006/11/28 18:52:23 kettenis Exp $	*/
/*	$NetBSD: proc.h,v 1.10 2005/12/11 12:18:58 christos Exp $	*/

/*
 * Copyright (c) 2002 The NetBSD Foundation, Inc. All rights reserved.
 * Copyright (c) 1991 Regents of the University of California.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *	@(#)proc.h	7.1 (Berkeley) 5/15/91
 */

#ifndef _SH_PROC_H_
#define	_SH_PROC_H_

/*
 * Machine-dependent part of the proc structure for sh.
 */

#include <machine/param.h>

/* Kernel stack PTE */
struct md_upte {
	uint32_t addr;
	uint32_t data;
};

struct mdproc {
	struct trapframe *md_regs;	/* user context */
	struct pcb *md_pcb;		/* pcb access address */
	volatile int md_astpending;	/* AST pending on return to userland */
	int md_flags;			/* machine-dependent flags */
	/* u-area PTE: *2 .. SH4 data/address data array access */
	struct md_upte md_upte[UPAGES * 2];
};

/* md_flags */
#define	MDP_USEDFPU	0x0001	/* has used the FPU */
#define	MDP_STEP	0x0002	/* single step */

#ifdef _KERNEL
#ifndef _LOCORE
extern void sh_proc0_init(void);
extern struct md_upte *curupte;	/* SH3 wired u-area hack */
#endif /* _LOCORE */
#endif /* _KERNEL */
#endif /* !_SH_PROC_H_ */


code:
/*	$OpenBSD: profile.h,v 1.2 2013/03/02 22:42:48 miod Exp $	*/
/*	$NetBSD: profile.h,v 1.5 2006/10/26 23:54:28 uwe Exp $	*/

/*-
 * Copyright (c) 2000 Tsubai Masanari.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#if defined(__ELF__)
#define	_MCOUNT_DECL static void _mcount
#else
#define	_MCOUNT_DECL static void mcount
#endif

#define	MCOUNT __asm ("				\n\
	.text					\n\
	.align	2				\n\
	.globl	__mcount			\n\
__mcount:					\n\
	mov.l	r4, @-r15			\n\
	mov.l	r5, @-r15			\n\
	mov.l	r6, @-r15			\n\
	mov.l	r7, @-r15			\n\
	mov.l	r0, @-r15			\n\
	mov.l	r14, @-r15			\n\
	sts.l	pr, @-r15			\n\
	mov	r15, r14			\n\
						\n\
	mov.l	1f, r1		! _mcount	\n\
	sts	pr, r4		! frompc	\n\
0:	bsrf	r1				\n\
	 mov	r0, r5		! selfpc	\n\
						\n\
	mov	r14, r15			\n\
	lds.l	@r15+, pr			\n\
	mov.l	@r15+, r14			\n\
	mov.l	@r15+, r0			\n\
	mov.l	@r15+, r7			\n\
	mov.l	@r15+, r6			\n\
	mov.l	@r15+, r5			\n\
	jmp	@r0		! real function	\n\
	 mov.l	@r15+, r4			\n\
						\n\
	.align	2				\n\
1:	.long	_mcount - ((0b) + 4)		\n\
						\n\
	.size	__mcount, . - __mcount		");

#ifdef _KERNEL
#define	MCOUNT_ENTER	s = splhigh()
#define	MCOUNT_EXIT	splx(s)
#endif


code:
/*	$OpenBSD: psl.h,v 1.4 2010/04/25 18:11:36 miod Exp $	*/
/*	$NetBSD: psl.h,v 1.8 2005/12/11 12:18:58 christos Exp $	*/

/*-
 * Copyright (c) 1990 The Regents of the University of California.
 * All rights reserved.
 *
 * This code is derived from software contributed to Berkeley by
 * William Jolitz.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *	@(#)psl.h	5.2 (Berkeley) 1/18/91
 */

#ifndef _SH_PSL_H_
#define	_SH_PSL_H_

/*
 * SuperH Processor Status Register.
 */
#define	PSL_TBIT	0x00000001	/* T bit */
#define	PSL_SBIT	0x00000002	/* S bit */
#define	PSL_IMASK	0x000000f0	/* Interrupt Mask bit */
#define	PSL_QBIT	0x00000100	/* Q bit */
#define	PSL_MBIT	0x00000200	/* M bit */
#define	PSL_FD		0x00008000	/* FPU Disable bit */
#define	PSL_BL		0x10000000	/* Exception Block bit */
#define	PSL_RB		0x20000000	/* Register Bank bit */
#define	PSL_MD		0x40000000	/* Processor Mode bit */

#define	PSL_MBO		0x00000000	/* must be one bits */
#define	PSL_MBZ		0x8fff7c0c	/* must be zero bits */

#define	PSL_USERSET	0
#define	PSL_USERSTATIC	(PSL_BL|PSL_RB|PSL_MD|PSL_IMASK|PSL_FD|PSL_MBO|PSL_MBZ)

#define	KERNELMODE(sr)		((sr) & PSL_MD)

#ifdef _KERNEL
#ifndef _LOCORE
/* SR.IMASK */
int _cpu_intr_raise(int);
int _cpu_intr_suspend(void);
int _cpu_intr_resume(int);
/* SR.BL */
int _cpu_exception_suspend(void);
void _cpu_exception_resume(int);
#endif /* !_LOCORE */
#endif /* _KERNEL */

#endif /* !_SH_PSL_H_ */


code:
/*	$OpenBSD: pte.h,v 1.2 2008/06/26 05:42:13 ray Exp $	*/
/*	$NetBSD: pte.h,v 1.11 2006/03/04 01:55:03 uwe Exp $	*/

/*-
 * Copyright (c) 2002 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by UCHIYAMA Yasushi.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef _SH_PTE_H_
#define	_SH_PTE_H_

/*
 * OpenBSD/sh PTE format.
 *
 * [Hardware bit]
 * SH3
 *	  PPN   V   PR  SZ C  D  SH
 *	[28:10][8][6:5][4][3][2][1]
 *
 * SH4
 *	        V  SZ  PR  SZ C  D  SH WT
 *	[28:10][8][7][6:5][4][3][2][1][0]
 *
 * [Software bit]
 *   [31]   - PMAP_WIRED bit (not hardware wired entry)
 *   [11:9] - SH4 PCMCIA Assistant bit. (space attribute bit only)
 */

/*
 * Hardware bits
 */
#define	PG_PPN			0x1ffff000	/* Physical page number mask */
#define	PG_V			0x00000100	/* Valid */
#define	PG_PR_MASK		0x00000060	/* Page protection mask */
#define	PG_PR_URW		0x00000060	/* kernel/user read/write */
#define	PG_PR_URO		0x00000040	/* kernel/user read only */
#define	PG_PR_KRW		0x00000020	/* kernel read/write */
#define	PG_PR_KRO		0x00000000	/* kernel read only */
#define	PG_4K			0x00000010	/* page size 4KB */
#define	PG_C			0x00000008	/* Cacheable */
#define	PG_D			0x00000004	/* Dirty */
#define	PG_SH			0x00000002	/* Share status */
#define	PG_WT			0x00000001	/* Write-through (SH4 only) */

#define	PG_HW_BITS		0x1ffff17e	/* [28:12][8][6:1] */

/*
 * Software bits
 */
#define	_PG_WIRED		0x80000000

/* SH4 PCMCIA MMU support bits */
/* PTEA SA (Space Attribute bit) */
#define	_PG_PCMCIA		0x00000e00	/* [11:9] */
#define	_PG_PCMCIA_SHIFT	9
#define	_PG_PCMCIA_NONE		0x00000000	/* Non PCMCIA space */
#define	_PG_PCMCIA_IO		0x00000200	/* IOIS16 signal */
#define	_PG_PCMCIA_IO8		0x00000400	/* 8 bit I/O  */
#define	_PG_PCMCIA_IO16		0x00000600	/* 16 bit I/O  */
#define	_PG_PCMCIA_MEM8		0x00000800	/* 8 bit common memory */
#define	_PG_PCMCIA_MEM16	0x00000a00	/* 16 bit common memory */
#define	_PG_PCMCIA_ATTR8	0x00000c00	/* 8 bit attribute */
#define	_PG_PCMCIA_ATTR16	0x00000e00	/* 16 bit attribute */

#ifndef _LOCORE
typedef uint32_t pt_entry_t;
#endif /* _LOCORE */
#endif /* !_SH_PTE_H_ */


code:
/*	$OpenBSD: ptrace.h,v 1.3 2007/03/02 06:11:54 miod Exp $	*/
/*	$NetBSD: ptrace.h,v 1.3 2002/02/28 01:58:53 uch Exp $	*/

/*
 * Copyright (c) 1993 Christopher G. Demetriou
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *      This product includes software developed by Christopher G. Demetriou.
 * 4. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * SuperH ptrace definitions
 */

#define	PT_STEP		(PT_FIRSTMACH + 0)
#define	PT_GETREGS	(PT_FIRSTMACH + 1)
#define	PT_SETREGS	(PT_FIRSTMACH + 2)
#define	PT_GETFPREGS	(PT_FIRSTMACH + 3)
#define	PT_SETFPREGS	(PT_FIRSTMACH + 4)


code:
/*	$OpenBSD: reg.h,v 1.2 2007/03/02 06:11:54 miod Exp $	*/
/*	$NetBSD: reg.h,v 1.5 2005/12/11 12:18:58 christos Exp $	*/

/*-
 * Copyright (c) 1990 The Regents of the University of California.
 * All rights reserved.
 *
 * This code is derived from software contributed to Berkeley by
 * William Jolitz.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *	@(#)reg.h	5.5 (Berkeley) 1/18/91
 */

#ifndef _SH_REG_H_
#define	_SH_REG_H_

/*
 * Location of the users' stored
 * registers within appropriate frame of 'trap' and 'syscall', relative to
 * base of stack frame.
 *
 * XXX
 * The #defines aren't used in the kernel, but some user-level code still
 * expects them.
 */

/* When referenced during a trap/exception, registers are at these offsets */

#define	tSPC	(0)
#define	tSSR	(1)
#define	tPR	(2)
#define	tR14	(3)
#define	tR13	(4)
#define	tR12	(5)
#define	tR11	(6)
#define	tR10	(7)
#define	tR9	(8)

#define	tR8	(11)
#define	tR7	(12)
#define	tR6	(13)
#define	tR5	(14)
#define	tR4	(15)
#define	tR3	(16)
#define	tR2	(17)
#define	tR1	(18)
#define	tR0	(19)

/*
 * Registers accessible to ptrace(2) syscall for debugger
 * The machine-dependent code for PT_{SET,GET}REGS needs to
 * use whichever order, defined above, is correct, so that it
 * is all invisible to the user.
 */
struct reg {
	int r_spc;
	int r_ssr;
	int r_pr;
	int r_mach;
	int r_macl;
	int r_r15;
	int r_r14;
	int r_r13;
	int r_r12;
	int r_r11;
	int r_r10;
	int r_r9;
	int r_r8;
	int r_r7;
	int r_r6;
	int r_r5;
	int r_r4;
	int r_r3;
	int r_r2;
	int r_r1;
	int r_r0;
};

struct fpreg {
	int	fpr_fr0;
	int	fpr_fr1;
	int	fpr_fr2;
	int	fpr_fr3;
	int	fpr_fr4;
	int	fpr_fr5;
	int	fpr_fr6;
	int	fpr_fr7;
	int	fpr_fr8;
	int	fpr_fr9;
	int	fpr_fr10;
	int	fpr_fr11;
	int	fpr_fr12;
	int	fpr_fr13;
	int	fpr_fr14;
	int	fpr_fr15;
	int	fpr_xf0;
	int	fpr_xf1;
	int	fpr_xf2;
	int	fpr_xf3;
	int	fpr_xf4;
	int	fpr_xf5;
	int	fpr_xf6;
	int	fpr_xf7;
	int	fpr_xf8;
	int	fpr_xf9;
	int	fpr_xf10;
	int	fpr_xf11;
	int	fpr_xf12;
	int	fpr_xf13;
	int	fpr_xf14;
	int	fpr_xf15;
	int	fpr_fpul;
	int	fpr_fpscr;
};

#endif /* !_SH_REG_H_ */


code:
/*	$OpenBSD: reloc.h,v 1.1 2006/11/10 02:39:47 drahn Exp $	*/
/* Processor specific relocation types */

#define	R_SH_NONE				0
#define	R_SH_DIR32				1
#define	R_SH_REL32				2
#define	R_SH_DIR8WPN				3
#define	R_SH_IND12W				4
#define	R_SH_DIR8WPL				5
#define	R_SH_DIR8WPZ				6
#define	R_SH_DIR8BP				7
#define	R_SH_DIR8W				8
#define	R_SH_DIR8L				9

/* GNU extensions */
#define	R_SH_LOOP_START				10
#define	R_SH_LOOP_END				11
#define	R_SH_GNU_VTINHERIT			22
#define	R_SH_GNU_VTENTRY			23
#define	R_SH_SWITCH8				24
#define	R_SH_SWITCH16				25
#define	R_SH_SWITCH32				26
#define	R_SH_USES				27
#define	R_SH_COUNT				28
#define	R_SH_ALIGN				29
#define	R_SH_CODE				30
#define	R_SH_DATA				31
#define	R_SH_LABEL				32

#define	R_SH_DIR16				33
#define	R_SH_DIR8				34
#define	R_SH_DIR8UL				35
#define	R_SH_DIR8UW				36
#define	R_SH_DIR8U				37
#define	R_SH_DIR8SW				38
#define	R_SH_DIR8S				39
#define	R_SH_DIR4UL				40
#define	R_SH_DIR4UW				41
#define	R_SH_DIR4U				42
#define	R_SH_PSHA				43
#define	R_SH_PSHL				44
#define	R_SH_DIR5U				45
#define	R_SH_DIR6U				46
#define	R_SH_DIR6S				47
#define	R_SH_DIR10S				48
#define	R_SH_DIR10SW				49
#define	R_SH_DIR10SL				50
#define	R_SH_DIR10SQ				51
#define	R_SH_DIR16S				53

/* GNU extensions */
#define	R_SH_TLS_GD_32				144
#define	R_SH_TLS_LD_32				145
#define	R_SH_TLS_LDO_32				146
#define	R_SH_TLS_IE_32				147
#define	R_SH_TLS_LE_32				148
#define	R_SH_TLS_DTPMOD32			149
#define	R_SH_TLS_DTPOFF32			150
#define	R_SH_TLS_TPOFF32			151
#define	R_SH_GOT32				160
#define	R_SH_PLT32				161
#define	R_SH_COPY				162
#define	R_SH_GLOB_DAT				163
#define	R_SH_JMP_SLOT				164
#define	R_SH_RELATIVE				165
#define	R_SH_GOTOFF				166
#define	R_SH_GOTPC				167
#define	R_SH_GOTPLT32				168
#define	R_SH_GOT_LOW16				169
#define	R_SH_GOT_MEDLOW16			170
#define	R_SH_GOT_MEDHI16			171
#define	R_SH_GOT_HI16				172
#define	R_SH_GOTPLT_LOW16			173
#define	R_SH_GOTPLT_MEDLOW16			174
#define	R_SH_GOTPLT_MEDHI16			175
#define	R_SH_GOTPLT_HI16			176
#define	R_SH_PLT_LOW16				177
#define	R_SH_PLT_MEDLOW16			178
#define	R_SH_PLT_MEDHI16			179
#define	R_SH_PLT_HI16				180
#define	R_SH_GOTOFF_LOW16			181
#define	R_SH_GOTOFF_MEDLOW16			182
#define	R_SH_GOTOFF_MEDHI16			183
#define	R_SH_GOTOFF_HI16			184
#define	R_SH_GOTPC_LOW16			185
#define	R_SH_GOTPC_MEDLOW16			186
#define	R_SH_GOTPC_MEDHI16			187
#define	R_SH_GOTPC_HI16				188
#define	R_SH_GOT10BY4				189
#define	R_SH_GOTPLT10BY4			190
#define	R_SH_GOT10BY8				191
#define	R_SH_GOTPLT10BY8			192
#define	R_SH_COPY64				193
#define	R_SH_GLOB_DAT64				194
#define	R_SH_JMP_SLOT64				195
#define	R_SH_RELATIVE64				196
#define	R_SH_SHMEDIA_CODE			242
#define	R_SH_PT_16				243
#define	R_SH_IMMS16				244
#define	R_SH_IMMU16				245
#define	R_SH_IMM_LOW16				246
#define	R_SH_IMM_LOW16_PCREL			247
#define	R_SH_IMM_MEDLOW16			248
#define	R_SH_IMM_MEDLOW16_PCREL			249
#define	R_SH_IMM_MEDHI16			250
#define	R_SH_IMM_MEDHI16_PCREL			251
#define	R_SH_IMM_HI16				252
#define	R_SH_IMM_HI16_PCREL			253
#define	R_SH_64					254
#define	R_SH_64_PCREL				255


code:
/*	$OpenBSD: rtcreg.h,v 1.1.1.1 2006/10/06 21:02:55 miod Exp $	*/
/*	$NetBSD: rtcreg.h,v 1.10 2006/09/03 12:38:34 uwe Exp $	*/

/*-
 * Copyright (C) 1999 SAITOH Masanobu.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef _SH_RTCREG_H_
#define	_SH_RTCREG_H_
#include <sh/devreg.h>

/*
 * RTC
 */
#define	SH3_R64CNT			0xfffffec0
#define	SH3_RSECCNT			0xfffffec2
#define	SH3_RMINCNT			0xfffffec4
#define	SH3_RHRCNT			0xfffffec6
#define	SH3_RWKCNT			0xfffffec8
#define	SH3_RDAYCNT			0xfffffeca
#define	SH3_RMONCNT			0xfffffecc
#define	SH3_RYRCNT			0xfffffece
#define	SH3_RSECAR			0xfffffed0
#define	SH3_RMINAR			0xfffffed2
#define	SH3_RHRAR			0xfffffed4
#define	SH3_RWKAR			0xfffffed6
#define	SH3_RDAYAR			0xfffffed8
#define	SH3_RMONAR			0xfffffeda
#define	SH3_RCR1			0xfffffedc
#define	SH3_RCR2			0xfffffede

#define	SH4_R64CNT			0xffc80000
#define	SH4_RSECCNT			0xffc80004
#define	SH4_RMINCNT			0xffc80008
#define	SH4_RHRCNT			0xffc8000c
#define	SH4_RWKCNT			0xffc80010
#define	SH4_RDAYCNT			0xffc80014
#define	SH4_RMONCNT			0xffc80018
#define	SH4_RYRCNT			0xffc8001c	/* 16 bit */
#define	SH4_RSECAR			0xffc80020
#define	SH4_RMINAR			0xffc80024
#define	SH4_RHRAR			0xffc80028
#define	SH4_RWKAR			0xffc8002c
#define	SH4_RDAYAR			0xffc80030
#define	SH4_RMONAR			0xffc80034
#define	SH4_RCR1			0xffc80038
#define	SH4_RCR2			0xffc8003c

#define	  SH_RCR1_CF			  0x80 /* carry flag */
#define	  SH_RCR1_CIE			  0x10 /* carry interrupt enable */
#define	  SH_RCR1_AIE			  0x08 /* alarm interrupt enable */
#define	  SH_RCR1_AF			  0x01 /* alarm flag */

#define	  SH_RCR2_PEF			  0x80 /* periodic interrupt flag */
#define	  SH_RCR2_PES2			  0x40 /* periodic interrupt freq */
#define	  SH_RCR2_PES1			  0x20 /* -//- */
#define	  SH_RCR2_PES0			  0x10 /* -//- */
#define	  SH_RCR2_ENABLE		  0x08
#define	  SH_RCR2_ADJ			  0x04 /* second adjustment */
#define	  SH_RCR2_RESET			  0x02
#define	  SH_RCR2_START			  0x01

#ifndef _LOCORE
#if defined(SH3) && defined(SH4)
extern uint32_t __sh_R64CNT;
extern uint32_t __sh_RSECCNT;
extern uint32_t __sh_RMINCNT;
extern uint32_t __sh_RHRCNT;
extern uint32_t __sh_RWKCNT;
extern uint32_t __sh_RDAYCNT;
extern uint32_t __sh_RMONCNT;
extern uint32_t __sh_RYRCNT;
extern uint32_t __sh_RSECAR;
extern uint32_t __sh_RMINAR;
extern uint32_t __sh_RHRAR;
extern uint32_t __sh_RWKAR;
extern uint32_t __sh_RDAYAR;
extern uint32_t __sh_RMONAR;
extern uint32_t __sh_RCR1;
extern uint32_t __sh_RCR2;
#endif /* SH3 && SH4 */
#endif /* !_LOCORE */

#endif /* !_SH_RTCREG_H_ */


code:
/*	$OpenBSD: setjmp.h,v 1.2 2007/03/02 06:11:54 miod Exp $	*/
/*	$NetBSD: setjmp.h,v 1.3 2006/01/05 00:50:23 uwe Exp $	*/

/*
 * machine/setjmp.h: machine dependent setjmp-related information.
 */

#define	_JBLEN 23		/* size, in longs, of a jmp_buf */


code:
/*	$OpenBSD: sh_opcode.h,v 1.1.1.1 2006/10/06 21:02:55 miod Exp $	*/
/*	$NetBSD: sh_opcode.h,v 1.3 2002/04/28 17:10:36 uch Exp $ */

typedef union {
	unsigned word;

#if _BYTE_ORDER == BIG_ENDIAN
	struct {
		unsigned op: 16;
	} oType;

	struct {
		unsigned op1: 4;
		unsigned n: 4;
		unsigned op2: 8;
	} nType;

	struct {
		unsigned op1: 4;
		unsigned m: 4;
		unsigned op2: 8;
	} mType;

	struct {
		unsigned op1: 4;
		unsigned n: 4;
		unsigned m: 4;
		unsigned op2: 4;
	} nmType;

	struct {
		unsigned op: 8;
		unsigned m: 4;
		unsigned d: 4;
	} mdType;

	struct {
		unsigned op: 8;
		unsigned n: 4;
		unsigned d: 4;
	} nd4Type;

	struct {
		unsigned op: 4;
		unsigned n: 4;
		unsigned m: 4;
		unsigned d: 4;
	} nmdType;

	struct {
		unsigned op: 8;
		unsigned d: 8;
	} dType;

	struct {
		unsigned op: 4;
		unsigned d: 12;
	} d12Type;

	struct {
		unsigned op: 4;
		unsigned n: 4;
		unsigned d: 8;
	} nd8Type;

	struct {
		unsigned op: 8;
		unsigned i: 8;
	} iType;

	struct {
		unsigned op: 4;
		unsigned n: 4;
		unsigned i: 8;
	} niType;
#endif
#if _BYTE_ORDER == LITTLE_ENDIAN
struct {
		unsigned op: 16;
	} oType;

	struct {
		unsigned op2: 8;
		unsigned n: 4;
		unsigned op1: 4;
	} nType;

	struct {
		unsigned op2: 8;
		unsigned m: 4;
		unsigned op1: 4;
	} mType;

	struct {
		unsigned op2: 4;
		unsigned m: 4;
		unsigned n: 4;
		unsigned op1: 4;
	} nmType;

	struct {
		unsigned d: 4;
		unsigned m: 4;
		unsigned op: 8;
	} mdType;

	struct {
		unsigned d: 4;
		unsigned n: 4;
		unsigned op: 8;
	} nd4Type;

	struct {
		unsigned d: 4;
		unsigned m: 4;
		unsigned n: 4;
		unsigned op: 4;
	} nmdType;

	struct {
		unsigned d: 8;
		unsigned op: 8;
	} dType;

	struct {
		unsigned d: 12;
		unsigned op: 4;
	} d12Type;

	struct {
		unsigned d: 8;
		unsigned n: 4;
		unsigned op: 4;
	} nd8Type;

	struct {
		unsigned i: 8;
		unsigned op: 8;
	} iType;

	struct {
		unsigned i: 8;
		unsigned n: 4;
		unsigned op: 4;
	} niType;
#endif
} InstFmt;

#define	OP_BF	0x8b
#define	OP_BFS	0x8f
#define	OP_BT	0x89
#define	OP_BTS	0x8d
#define	OP_BRA	0xa
#define	OP_BSR	0xb
#define	OP1_BRAF	0x0
#define	OP2_BRAF	0x23
#define	OP1_BSRF	0x0
#define	OP2_BSRF	0x03
#define	OP1_JMP	0x4
#define	OP2_JMP	0x2b
#define	OP1_JSR	0x4
#define	OP2_JSR	0x0b
#define	OP_RTS	0xffff


code:
/*	$OpenBSD: signal.h,v 1.6 2012/12/02 07:03:31 guenther Exp $	*/
/*	$NetBSD: signal.h,v 1.12 2005/12/11 12:18:58 christos Exp $	*/

/*
 * Copyright (c) 1982, 1986, 1989, 1991 Regents of the University of California.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *	@(#)signal.h	7.16 (Berkeley) 3/17/91
 */

#ifndef _SH_SIGNAL_H_
#define	_SH_SIGNAL_H_

#include <sys/cdefs.h>

typedef int sig_atomic_t;

#if __BSD_VISIBLE || __XPG_VISIBLE >= 420

/*
 * Information pushed on stack when a signal is delivered.
 * This is used by the kernel to restore state following
 * execution of the signal handler.  It is also made available
 * to the handler to allow it to restore state properly if
 * a non-standard exit is performed.
 */
struct sigcontext {
	int	sc_reg[21];
	int	sc_fpreg[34];

	int	__sc_unused;

	int	sc_expevt;	/* XXX should be above */
	int	sc_err;

	unsigned int sc_mask;	/* signal mask to restore */
};

#endif	/* __BSD_VISIBLE || __XPG_VISIBLE >= 420 */
#endif	/* !_SH_SIGNAL_H_ */


code:
/*	$OpenBSD: spinlock.h,v 1.5 2013/06/04 04:27:57 miod Exp $	*/
/*	$NetBSD: lock.h,v 1.10 2006/01/03 01:29:46 uwe Exp $	*/

/*-
 * Copyright (c) 2002 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Gregory McGarry.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * Machine-dependent spin lock operations.
 */

#ifndef _SH_SPINLOCK_H_
#define	_SH_SPINLOCK_H_

typedef unsigned char _atomic_lock_t;

#ifndef _KERNEL
int _atomic_lock(volatile _atomic_lock_t *);
#endif

#define	_ATOMIC_LOCK_LOCKED	0x80
#define	_ATOMIC_LOCK_UNLOCKED	0x00

#endif /* !_SH_SPINLOCK_H_ */


code:
/*	$OpenBSD: stdarg.h,v 1.3 2011/03/02 18:31:58 matthew Exp $	*/
/*	$NetBSD: stdarg.h,v 1.9 2006/05/21 22:39:04 uwe Exp $	*/

/*
 * Copyright (c) 1991, 1993
 *	The Regents of the University of California.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *	from: @(#)stdarg.h	8.1 (Berkeley) 6/10/93
 */

#ifndef _SH_STDARG_H_
#define	_SH_STDARG_H_

#include <sys/cdefs.h>
#include <machine/_types.h>

typedef __va_list	va_list;

#ifdef __lint__
#define __builtin_next_arg(t)		((t) ? 0 : 0)
#define	__builtin_stdarg_start(a, l)	((a) = ((l) ? 0 : 0))
#define	__builtin_va_arg(a, t)		((t)((a) ? 0 : 0))
#define	__builtin_va_end		/* nothing */
#define	__builtin_va_copy(d, s)		((d) = (s))
#endif

#define	va_start(ap, last)	__builtin_stdarg_start((ap), (last))
#define	va_arg(ap, type)	__builtin_va_arg((ap), type)
#define	va_end(ap)		__builtin_va_end((ap))
#define	__va_copy(dest, src)	__builtin_va_copy((dest), (src))

#endif /* !_SH_STDARG_H_ */


code:
/*	$OpenBSD: tcb.h,v 1.1 2011/10/27 04:01:17 guenther Exp $	*/

/*
 * Copyright (c) 2011 Philip Guenther <guenther@openbsd.org>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#ifndef _MACHINE_TCB_H_
#define _MACHINE_TCB_H_

#ifdef _KERNEL

#error "not yet"

#else /* _KERNEL */

/* ELF TLS ABI calls for small TCB, with static TLS data after it */
#define TLS_VARIANT	1

#endif /* _KERNEL */

#endif /* _MACHINE_TCB_H_ */