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