7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 #ifndef _AMD64_SYS_PRIVREGS_H
28 #define _AMD64_SYS_PRIVREGS_H
29
30 #include <sys/ccompile.h>
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35
36 /*
37 * This file describes the cpu's privileged register set, and
38 * how the machine state is saved on the stack when a trap occurs.
39 */
40
41 #if !defined(__amd64)
42 #error "non-amd64 code depends on amd64 privileged header!"
43 #endif
44
45 #ifndef _ASM
46
189 movq REGOFF_RBX(%rsp), %rbx; \
190 movq REGOFF_RBP(%rsp), %rbp; \
191 movq REGOFF_R10(%rsp), %r10; \
192 movq REGOFF_R11(%rsp), %r11; \
193 movq REGOFF_R12(%rsp), %r12; \
194 movq REGOFF_R13(%rsp), %r13; \
195 movq REGOFF_R14(%rsp), %r14; \
196 movq REGOFF_R15(%rsp), %r15
197
198 /*
199 * Push register state onto the stack. If we've
200 * interrupted userland, do a swapgs as well.
201 */
202 #define INTR_PUSH \
203 subq $REGOFF_TRAPNO, %rsp; \
204 __SAVE_REGS; \
205 cmpw $KCS_SEL, REGOFF_CS(%rsp); \
206 je 6f; \
207 movq $0, REGOFF_SAVFP(%rsp); \
208 SWAPGS; \
209 6: CLEAN_CS
210
211 #define INTR_POP \
212 leaq sys_lcall32(%rip), %r11;\
213 cmpq %r11, REGOFF_RIP(%rsp); \
214 __RESTORE_REGS; \
215 je 5f; \
216 cmpw $KCS_SEL, REGOFF_CS(%rsp);\
217 je 8f; \
218 5: SWAPGS; \
219 8: addq $REGOFF_RIP, %rsp
220
221 #define USER_POP \
222 __RESTORE_REGS; \
223 SWAPGS; \
224 addq $REGOFF_RIP, %rsp /* Adjust %rsp to prepare for iretq */
225
226 #define USER32_POP \
227 movl REGOFF_RDI(%rsp), %edi; \
228 movl REGOFF_RSI(%rsp), %esi; \
229 movl REGOFF_RDX(%rsp), %edx; \
230 movl REGOFF_RCX(%rsp), %ecx; \
231 movl REGOFF_RAX(%rsp), %eax; \
232 movl REGOFF_RBX(%rsp), %ebx; \
233 movl REGOFF_RBP(%rsp), %ebp; \
234 SWAPGS; \
235 addq $REGOFF_RIP, %rsp /* Adjust %rsp to prepare for iretq */
236
237 #define DFTRAP_PUSH \
238 subq $REGOFF_TRAPNO, %rsp; \
239 __SAVE_REGS
240
|
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 /*
28 * Copyright 2019 Joyent, Inc.
29 */
30
31 #ifndef _AMD64_SYS_PRIVREGS_H
32 #define _AMD64_SYS_PRIVREGS_H
33
34 #include <sys/ccompile.h>
35
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39
40 /*
41 * This file describes the cpu's privileged register set, and
42 * how the machine state is saved on the stack when a trap occurs.
43 */
44
45 #if !defined(__amd64)
46 #error "non-amd64 code depends on amd64 privileged header!"
47 #endif
48
49 #ifndef _ASM
50
193 movq REGOFF_RBX(%rsp), %rbx; \
194 movq REGOFF_RBP(%rsp), %rbp; \
195 movq REGOFF_R10(%rsp), %r10; \
196 movq REGOFF_R11(%rsp), %r11; \
197 movq REGOFF_R12(%rsp), %r12; \
198 movq REGOFF_R13(%rsp), %r13; \
199 movq REGOFF_R14(%rsp), %r14; \
200 movq REGOFF_R15(%rsp), %r15
201
202 /*
203 * Push register state onto the stack. If we've
204 * interrupted userland, do a swapgs as well.
205 */
206 #define INTR_PUSH \
207 subq $REGOFF_TRAPNO, %rsp; \
208 __SAVE_REGS; \
209 cmpw $KCS_SEL, REGOFF_CS(%rsp); \
210 je 6f; \
211 movq $0, REGOFF_SAVFP(%rsp); \
212 SWAPGS; \
213 6: lfence; /* swapgs mitigation */ \
214 CLEAN_CS
215
216 #define INTR_POP \
217 leaq sys_lcall32(%rip), %r11;\
218 cmpq %r11, REGOFF_RIP(%rsp); \
219 __RESTORE_REGS; \
220 je 5f; \
221 cmpw $KCS_SEL, REGOFF_CS(%rsp);\
222 je 8f; \
223 5: SWAPGS; \
224 8: lfence; /* swapgs mitigation */ \
225 addq $REGOFF_RIP, %rsp
226
227 /*
228 * No need for swapgs mitigation: it's unconditional, and we're heading
229 * back to userspace.
230 */
231 #define USER_POP \
232 __RESTORE_REGS; \
233 SWAPGS; \
234 addq $REGOFF_RIP, %rsp /* Adjust %rsp to prepare for iretq */
235
236 #define USER32_POP \
237 movl REGOFF_RDI(%rsp), %edi; \
238 movl REGOFF_RSI(%rsp), %esi; \
239 movl REGOFF_RDX(%rsp), %edx; \
240 movl REGOFF_RCX(%rsp), %ecx; \
241 movl REGOFF_RAX(%rsp), %eax; \
242 movl REGOFF_RBX(%rsp), %ebx; \
243 movl REGOFF_RBP(%rsp), %ebp; \
244 SWAPGS; \
245 addq $REGOFF_RIP, %rsp /* Adjust %rsp to prepare for iretq */
246
247 #define DFTRAP_PUSH \
248 subq $REGOFF_TRAPNO, %rsp; \
249 __SAVE_REGS
250
|