xref: /freebsd/sys/x86/include/frame.h (revision c43e99fd14c915adcb7173dd49c31e803ceadfe0)
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 2003 Peter Wemm.
5  * Copyright (c) 1990 The Regents of the University of California.
6  * All rights reserved.
7  *
8  * This code is derived from software contributed to Berkeley by
9  * William Jolitz.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. Neither the name of the University nor the names of its contributors
20  *    may be used to endorse or promote products derived from this software
21  *    without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  *
35  *	from: @(#)frame.h	5.2 (Berkeley) 1/18/91
36  * $FreeBSD$
37  */
38 
39 #ifndef _MACHINE_FRAME_H_
40 #define _MACHINE_FRAME_H_ 1
41 
42 /*
43  * System stack frames.
44  */
45 
46 #ifdef __i386__
47 /*
48  * Exception/Trap Stack Frame
49  */
50 
51 struct trapframe {
52 	int	tf_fs;
53 	int	tf_es;
54 	int	tf_ds;
55 	int	tf_edi;
56 	int	tf_esi;
57 	int	tf_ebp;
58 	int	tf_isp;
59 	int	tf_ebx;
60 	int	tf_edx;
61 	int	tf_ecx;
62 	int	tf_eax;
63 	int	tf_trapno;
64 	/* below portion defined in 386 hardware */
65 	int	tf_err;
66 	int	tf_eip;
67 	int	tf_cs;
68 	int	tf_eflags;
69 	/* below only when crossing rings (user to kernel) */
70 	int	tf_esp;
71 	int	tf_ss;
72 };
73 
74 /* Superset of trap frame, for traps from virtual-8086 mode */
75 
76 struct trapframe_vm86 {
77 	int	tf_fs;
78 	int	tf_es;
79 	int	tf_ds;
80 	int	tf_edi;
81 	int	tf_esi;
82 	int	tf_ebp;
83 	int	tf_isp;
84 	int	tf_ebx;
85 	int	tf_edx;
86 	int	tf_ecx;
87 	int	tf_eax;
88 	int	tf_trapno;
89 	/* below portion defined in 386 hardware */
90 	int	tf_err;
91 	int	tf_eip;
92 	int	tf_cs;
93 	int	tf_eflags;
94 	/* below only when crossing rings (user (including vm86) to kernel) */
95 	int	tf_esp;
96 	int	tf_ss;
97 	/* below only when crossing from vm86 mode to kernel */
98 	int	tf_vm86_es;
99 	int	tf_vm86_ds;
100 	int	tf_vm86_fs;
101 	int	tf_vm86_gs;
102 };
103 
104 /*
105  * This alias for the MI TRAPF_USERMODE() should be used when we don't
106  * care about user mode itself, but need to know if a frame has stack
107  * registers.  The difference is only logical, but on i386 the logic
108  * for using TRAPF_USERMODE() is complicated by sometimes treating vm86
109  * bioscall mode (which is a special ring 3 user mode) as kernel mode.
110  */
111 #define	TF_HAS_STACKREGS(tf)	TRAPF_USERMODE(tf)
112 #endif /* __i386__ */
113 
114 #ifdef __amd64__
115 /*
116  * Exception/Trap Stack Frame
117  *
118  * The ordering of this is specifically so that we can take first 6
119  * the syscall arguments directly from the beginning of the frame.
120  */
121 
122 struct trapframe {
123 	register_t	tf_rdi;
124 	register_t	tf_rsi;
125 	register_t	tf_rdx;
126 	register_t	tf_rcx;
127 	register_t	tf_r8;
128 	register_t	tf_r9;
129 	register_t	tf_rax;
130 	register_t	tf_rbx;
131 	register_t	tf_rbp;
132 	register_t	tf_r10;
133 	register_t	tf_r11;
134 	register_t	tf_r12;
135 	register_t	tf_r13;
136 	register_t	tf_r14;
137 	register_t	tf_r15;
138 	uint32_t	tf_trapno;
139 	uint16_t	tf_fs;
140 	uint16_t	tf_gs;
141 	register_t	tf_addr;
142 	uint32_t	tf_flags;
143 	uint16_t	tf_es;
144 	uint16_t	tf_ds;
145 	/* below portion defined in hardware */
146 	register_t	tf_err;
147 	register_t	tf_rip;
148 	register_t	tf_cs;
149 	register_t	tf_rflags;
150 	/* the amd64 frame always has the stack registers */
151 	register_t	tf_rsp;
152 	register_t	tf_ss;
153 };
154 
155 #define	TF_HASSEGS	0x1
156 #define	TF_HASBASES	0x2
157 #define	TF_HASFPXSTATE	0x4
158 #endif /* __amd64__ */
159 
160 #endif /* _MACHINE_FRAME_H_ */
161