Home | History | Annotate | Line # | Download | only in include
      1 /*	$NetBSD: frame.h,v 1.41 2021/12/26 16:08:20 andvar Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Charles M. Hannum.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 /*-
     33  * Copyright (c) 1990 The Regents of the University of California.
     34  * All rights reserved.
     35  *
     36  * This code is derived from software contributed to Berkeley by
     37  * William Jolitz.
     38  *
     39  * Redistribution and use in source and binary forms, with or without
     40  * modification, are permitted provided that the following conditions
     41  * are met:
     42  * 1. Redistributions of source code must retain the above copyright
     43  *    notice, this list of conditions and the following disclaimer.
     44  * 2. Redistributions in binary form must reproduce the above copyright
     45  *    notice, this list of conditions and the following disclaimer in the
     46  *    documentation and/or other materials provided with the distribution.
     47  * 3. Neither the name of the University nor the names of its contributors
     48  *    may be used to endorse or promote products derived from this software
     49  *    without specific prior written permission.
     50  *
     51  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     52  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     53  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     54  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     55  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     56  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     57  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     58  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     59  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     60  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     61  * SUCH DAMAGE.
     62  *
     63  *	@(#)frame.h	5.2 (Berkeley) 1/18/91
     64  */
     65 
     66 #ifndef _I386_FRAME_H_
     67 #define _I386_FRAME_H_
     68 
     69 #include <sys/signal.h>
     70 
     71 /*
     72  * System stack frames.
     73  */
     74 
     75 /*
     76  * Exception/Trap Stack Frame
     77  */
     78 struct trapframe {
     79 	uint16_t	tf_gs;
     80 	uint16_t	tf_gs_pad;
     81 	uint16_t	tf_fs;
     82 	uint16_t	tf_fs_pad;
     83 	uint16_t	tf_es;
     84 	uint16_t	tf_es_pad;
     85 	uint16_t	tf_ds;
     86 	uint16_t	tf_ds_pad;
     87 	int	tf_edi;
     88 	int	tf_esi;
     89 	int	tf_ebp;
     90 	int	tf_ebx;
     91 	int	tf_edx;
     92 	int	tf_ecx;
     93 	int	tf_eax;
     94 	int	tf_trapno;
     95 	/* below portion defined in 386 hardware */
     96 	int	tf_err;
     97 	int	tf_eip;
     98 	int	tf_cs;
     99 	int	tf_eflags;
    100 	/* below used when transitting rings (e.g. user to kernel) */
    101 	int	tf_esp;
    102 	int	tf_ss;
    103 };
    104 
    105 /*
    106  * Interrupt stack frame
    107  */
    108 struct intrframe {
    109 	int	if_ppl;
    110 	int	if_gs;
    111 	int	if_fs;
    112 	int	if_es;
    113 	int	if_ds;
    114 	int	if_edi;
    115 	int	if_esi;
    116 	int	if_ebp;
    117 	int	if_ebx;
    118 	int	if_edx;
    119 	int	if_ecx;
    120 	int	if_eax;
    121 	uint32_t __if_trapno;	/* for compat with trap frame - trapno */
    122 	uint32_t __if_err;	/* for compat with trap frame - err */
    123 	/* below portion defined in 386 hardware */
    124 	int	if_eip;
    125 	int	if_cs;
    126 	int	if_eflags;
    127 	/* below only when transitting rings (e.g. user to kernel) */
    128 	int	if_esp;
    129 	int	if_ss;
    130 };
    131 
    132 #ifdef XEN
    133 /*
    134  * need arch independent way to access ip and cs from intrframe
    135  */
    136 #define	_INTRFRAME_CS	if_cs
    137 #define	_INTRFRAME_IP	if_eip
    138 #endif
    139 
    140 /*
    141  * Stack frame inside cpu_switchto()
    142  */
    143 struct switchframe {
    144 	int	sf_edi;
    145 	int	sf_esi;
    146 	int	sf_ebx;
    147 	int	sf_eip;
    148 };
    149 
    150 #ifdef _KERNEL
    151 /*
    152  * Old-style signal frame
    153  */
    154 struct sigframe_sigcontext {
    155 	int	sf_ra;			/* return address for handler */
    156 	int	sf_signum;		/* "signum" argument for handler */
    157 	int	sf_code;		/* "code" argument for handler */
    158 	struct	sigcontext *sf_scp;	/* "scp" argument for handler */
    159 	struct	sigcontext sf_sc;	/* actual saved context */
    160 };
    161 #endif
    162 
    163 /*
    164  * New-style signal frame
    165  */
    166 struct sigframe_siginfo {
    167 	int		sf_ra;		/* return address for handler */
    168 	int		sf_signum;	/* "signum" argument for handler */
    169 	siginfo_t	*sf_sip;	/* "sip" argument for handler */
    170 	ucontext_t	*sf_ucp;	/* "ucp" argument for handler */
    171 	siginfo_t	sf_si;		/* actual saved siginfo */
    172 	ucontext_t	sf_uc;		/* actual saved ucontext */
    173 };
    174 
    175 #ifdef _KERNEL
    176 void *getframe(struct lwp *, int, int *);
    177 void buildcontext(struct lwp *, int, void *, void *);
    178 void sendsig_sigcontext(const ksiginfo_t *, const sigset_t *);
    179 #define lwp_trapframe(l)	((l)->l_md.md_regs)
    180 #endif
    181 
    182 #endif  /* _I386_FRAME_H_ */
    183