xref: /freebsd/sys/x86/include/frame.h (revision 29363fb446372cb3f10bc98664e9767c53fbb457)
131a53cd0SKonstantin Belousov /*-
2*51369649SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
3*51369649SPedro F. Giffuni  *
431a53cd0SKonstantin Belousov  * Copyright (c) 2003 Peter Wemm.
531a53cd0SKonstantin Belousov  * Copyright (c) 1990 The Regents of the University of California.
631a53cd0SKonstantin Belousov  * All rights reserved.
731a53cd0SKonstantin Belousov  *
831a53cd0SKonstantin Belousov  * This code is derived from software contributed to Berkeley by
931a53cd0SKonstantin Belousov  * William Jolitz.
1031a53cd0SKonstantin Belousov  *
1131a53cd0SKonstantin Belousov  * Redistribution and use in source and binary forms, with or without
1231a53cd0SKonstantin Belousov  * modification, are permitted provided that the following conditions
1331a53cd0SKonstantin Belousov  * are met:
1431a53cd0SKonstantin Belousov  * 1. Redistributions of source code must retain the above copyright
1531a53cd0SKonstantin Belousov  *    notice, this list of conditions and the following disclaimer.
1631a53cd0SKonstantin Belousov  * 2. Redistributions in binary form must reproduce the above copyright
1731a53cd0SKonstantin Belousov  *    notice, this list of conditions and the following disclaimer in the
1831a53cd0SKonstantin Belousov  *    documentation and/or other materials provided with the distribution.
19fbbd9655SWarner Losh  * 3. Neither the name of the University nor the names of its contributors
2031a53cd0SKonstantin Belousov  *    may be used to endorse or promote products derived from this software
2131a53cd0SKonstantin Belousov  *    without specific prior written permission.
2231a53cd0SKonstantin Belousov  *
2331a53cd0SKonstantin Belousov  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2431a53cd0SKonstantin Belousov  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2531a53cd0SKonstantin Belousov  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2631a53cd0SKonstantin Belousov  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2731a53cd0SKonstantin Belousov  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2831a53cd0SKonstantin Belousov  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2931a53cd0SKonstantin Belousov  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3031a53cd0SKonstantin Belousov  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3131a53cd0SKonstantin Belousov  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3231a53cd0SKonstantin Belousov  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3331a53cd0SKonstantin Belousov  * SUCH DAMAGE.
3431a53cd0SKonstantin Belousov  */
3531a53cd0SKonstantin Belousov 
3631a53cd0SKonstantin Belousov #ifndef _MACHINE_FRAME_H_
3731a53cd0SKonstantin Belousov #define _MACHINE_FRAME_H_ 1
3831a53cd0SKonstantin Belousov 
3931a53cd0SKonstantin Belousov /*
4031a53cd0SKonstantin Belousov  * System stack frames.
4131a53cd0SKonstantin Belousov  */
4231a53cd0SKonstantin Belousov 
4331a53cd0SKonstantin Belousov #ifdef __i386__
4431a53cd0SKonstantin Belousov /*
4531a53cd0SKonstantin Belousov  * Exception/Trap Stack Frame
4631a53cd0SKonstantin Belousov  */
4731a53cd0SKonstantin Belousov 
4831a53cd0SKonstantin Belousov struct trapframe {
4931a53cd0SKonstantin Belousov 	int	tf_fs;
5031a53cd0SKonstantin Belousov 	int	tf_es;
5131a53cd0SKonstantin Belousov 	int	tf_ds;
5231a53cd0SKonstantin Belousov 	int	tf_edi;
5331a53cd0SKonstantin Belousov 	int	tf_esi;
5431a53cd0SKonstantin Belousov 	int	tf_ebp;
5531a53cd0SKonstantin Belousov 	int	tf_isp;
5631a53cd0SKonstantin Belousov 	int	tf_ebx;
5731a53cd0SKonstantin Belousov 	int	tf_edx;
5831a53cd0SKonstantin Belousov 	int	tf_ecx;
5931a53cd0SKonstantin Belousov 	int	tf_eax;
6031a53cd0SKonstantin Belousov 	int	tf_trapno;
6131a53cd0SKonstantin Belousov 	/* below portion defined in 386 hardware */
6231a53cd0SKonstantin Belousov 	int	tf_err;
6331a53cd0SKonstantin Belousov 	int	tf_eip;
6431a53cd0SKonstantin Belousov 	int	tf_cs;
6531a53cd0SKonstantin Belousov 	int	tf_eflags;
66701ac880SBruce Evans 	/* below only when crossing rings (user to kernel) */
6731a53cd0SKonstantin Belousov 	int	tf_esp;
6831a53cd0SKonstantin Belousov 	int	tf_ss;
6931a53cd0SKonstantin Belousov };
7031a53cd0SKonstantin Belousov 
7131a53cd0SKonstantin Belousov /* Superset of trap frame, for traps from virtual-8086 mode */
7231a53cd0SKonstantin Belousov 
7331a53cd0SKonstantin Belousov struct trapframe_vm86 {
7431a53cd0SKonstantin Belousov 	int	tf_fs;
7531a53cd0SKonstantin Belousov 	int	tf_es;
7631a53cd0SKonstantin Belousov 	int	tf_ds;
7731a53cd0SKonstantin Belousov 	int	tf_edi;
7831a53cd0SKonstantin Belousov 	int	tf_esi;
7931a53cd0SKonstantin Belousov 	int	tf_ebp;
8031a53cd0SKonstantin Belousov 	int	tf_isp;
8131a53cd0SKonstantin Belousov 	int	tf_ebx;
8231a53cd0SKonstantin Belousov 	int	tf_edx;
8331a53cd0SKonstantin Belousov 	int	tf_ecx;
8431a53cd0SKonstantin Belousov 	int	tf_eax;
8531a53cd0SKonstantin Belousov 	int	tf_trapno;
8631a53cd0SKonstantin Belousov 	/* below portion defined in 386 hardware */
8731a53cd0SKonstantin Belousov 	int	tf_err;
8831a53cd0SKonstantin Belousov 	int	tf_eip;
8931a53cd0SKonstantin Belousov 	int	tf_cs;
9031a53cd0SKonstantin Belousov 	int	tf_eflags;
91701ac880SBruce Evans 	/* below only when crossing rings (user (including vm86) to kernel) */
9231a53cd0SKonstantin Belousov 	int	tf_esp;
9331a53cd0SKonstantin Belousov 	int	tf_ss;
94701ac880SBruce Evans 	/* below only when crossing from vm86 mode to kernel */
9531a53cd0SKonstantin Belousov 	int	tf_vm86_es;
9631a53cd0SKonstantin Belousov 	int	tf_vm86_ds;
9731a53cd0SKonstantin Belousov 	int	tf_vm86_fs;
9831a53cd0SKonstantin Belousov 	int	tf_vm86_gs;
9931a53cd0SKonstantin Belousov };
1005904b5a6SBruce Evans 
1015904b5a6SBruce Evans /*
1025904b5a6SBruce Evans  * This alias for the MI TRAPF_USERMODE() should be used when we don't
1035904b5a6SBruce Evans  * care about user mode itself, but need to know if a frame has stack
1045904b5a6SBruce Evans  * registers.  The difference is only logical, but on i386 the logic
1055904b5a6SBruce Evans  * for using TRAPF_USERMODE() is complicated by sometimes treating vm86
1065904b5a6SBruce Evans  * bioscall mode (which is a special ring 3 user mode) as kernel mode.
1075904b5a6SBruce Evans  */
1085904b5a6SBruce Evans #define	TF_HAS_STACKREGS(tf)	TRAPF_USERMODE(tf)
10931a53cd0SKonstantin Belousov #endif /* __i386__ */
11031a53cd0SKonstantin Belousov 
11131a53cd0SKonstantin Belousov #ifdef __amd64__
11231a53cd0SKonstantin Belousov /*
11331a53cd0SKonstantin Belousov  * Exception/Trap Stack Frame
11431a53cd0SKonstantin Belousov  *
11531a53cd0SKonstantin Belousov  * The ordering of this is specifically so that we can take first 6
11631a53cd0SKonstantin Belousov  * the syscall arguments directly from the beginning of the frame.
11731a53cd0SKonstantin Belousov  */
11831a53cd0SKonstantin Belousov 
11931a53cd0SKonstantin Belousov struct trapframe {
12031a53cd0SKonstantin Belousov 	register_t	tf_rdi;
12131a53cd0SKonstantin Belousov 	register_t	tf_rsi;
12231a53cd0SKonstantin Belousov 	register_t	tf_rdx;
12331a53cd0SKonstantin Belousov 	register_t	tf_rcx;
12431a53cd0SKonstantin Belousov 	register_t	tf_r8;
12531a53cd0SKonstantin Belousov 	register_t	tf_r9;
12631a53cd0SKonstantin Belousov 	register_t	tf_rax;
12731a53cd0SKonstantin Belousov 	register_t	tf_rbx;
12831a53cd0SKonstantin Belousov 	register_t	tf_rbp;
12931a53cd0SKonstantin Belousov 	register_t	tf_r10;
13031a53cd0SKonstantin Belousov 	register_t	tf_r11;
13131a53cd0SKonstantin Belousov 	register_t	tf_r12;
13231a53cd0SKonstantin Belousov 	register_t	tf_r13;
13331a53cd0SKonstantin Belousov 	register_t	tf_r14;
13431a53cd0SKonstantin Belousov 	register_t	tf_r15;
13531a53cd0SKonstantin Belousov 	uint32_t	tf_trapno;
13631a53cd0SKonstantin Belousov 	uint16_t	tf_fs;
13731a53cd0SKonstantin Belousov 	uint16_t	tf_gs;
13831a53cd0SKonstantin Belousov 	register_t	tf_addr;
13931a53cd0SKonstantin Belousov 	uint32_t	tf_flags;
14031a53cd0SKonstantin Belousov 	uint16_t	tf_es;
14131a53cd0SKonstantin Belousov 	uint16_t	tf_ds;
14231a53cd0SKonstantin Belousov 	/* below portion defined in hardware */
14331a53cd0SKonstantin Belousov 	register_t	tf_err;
14431a53cd0SKonstantin Belousov 	register_t	tf_rip;
14531a53cd0SKonstantin Belousov 	register_t	tf_cs;
14631a53cd0SKonstantin Belousov 	register_t	tf_rflags;
1475904b5a6SBruce Evans 	/* the amd64 frame always has the stack registers */
14831a53cd0SKonstantin Belousov 	register_t	tf_rsp;
14931a53cd0SKonstantin Belousov 	register_t	tf_ss;
15031a53cd0SKonstantin Belousov };
15131a53cd0SKonstantin Belousov 
15231a53cd0SKonstantin Belousov #define	TF_HASSEGS	0x1
15331a53cd0SKonstantin Belousov #define	TF_HASBASES	0x2
15431a53cd0SKonstantin Belousov #define	TF_HASFPXSTATE	0x4
15531a53cd0SKonstantin Belousov #endif /* __amd64__ */
15631a53cd0SKonstantin Belousov 
15731a53cd0SKonstantin Belousov #endif /* _MACHINE_FRAME_H_ */
158