| 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 | |
| 36 | #ifndef _MACHINE_FRAME_H_ |
| 37 | #define _MACHINE_FRAME_H_ 1 |
| 38 | |
| 39 | /* |
| 40 | * System stack frames. |
| 41 | */ |
| 42 | |
| 43 | #ifdef __i386__ |
| 44 | /* |
| 45 | * Exception/Trap Stack Frame |
| 46 | */ |
| 47 | |
| 48 | struct trapframe { |
| 49 | 	int	tf_fs; |
| 50 | 	int	tf_es; |
| 51 | 	int	tf_ds; |
| 52 | 	int	tf_edi; |
| 53 | 	int	tf_esi; |
| 54 | 	int	tf_ebp; |
| 55 | 	int	tf_isp; |
| 56 | 	int	tf_ebx; |
| 57 | 	int	tf_edx; |
| 58 | 	int	tf_ecx; |
| 59 | 	int	tf_eax; |
| 60 | 	int	tf_trapno; |
| 61 | 	/* below portion defined in 386 hardware */ |
| 62 | 	int	tf_err; |
| 63 | 	int	tf_eip; |
| 64 | 	int	tf_cs; |
| 65 | 	int	tf_eflags; |
| 66 | 	/* below only when crossing rings (user to kernel) */ |
| 67 | 	int	tf_esp; |
| 68 | 	int	tf_ss; |
| 69 | }; |
| 70 | |
| 71 | /* Superset of trap frame, for traps from virtual-8086 mode */ |
| 72 | |
| 73 | struct trapframe_vm86 { |
| 74 | 	int	tf_fs; |
| 75 | 	int	tf_es; |
| 76 | 	int	tf_ds; |
| 77 | 	int	tf_edi; |
| 78 | 	int	tf_esi; |
| 79 | 	int	tf_ebp; |
| 80 | 	int	tf_isp; |
| 81 | 	int	tf_ebx; |
| 82 | 	int	tf_edx; |
| 83 | 	int	tf_ecx; |
| 84 | 	int	tf_eax; |
| 85 | 	int	tf_trapno; |
| 86 | 	/* below portion defined in 386 hardware */ |
| 87 | 	int	tf_err; |
| 88 | 	int	tf_eip; |
| 89 | 	int	tf_cs; |
| 90 | 	int	tf_eflags; |
| 91 | 	/* below only when crossing rings (user (including vm86) to kernel) */ |
| 92 | 	int	tf_esp; |
| 93 | 	int	tf_ss; |
| 94 | 	/* below only when crossing from vm86 mode to kernel */ |
| 95 | 	int	tf_vm86_es; |
| 96 | 	int	tf_vm86_ds; |
| 97 | 	int	tf_vm86_fs; |
| 98 | 	int	tf_vm86_gs; |
| 99 | }; |
| 100 | |
| 101 | /* |
| 102 | * This alias for the MI TRAPF_USERMODE() should be used when we don't |
| 103 | * care about user mode itself, but need to know if a frame has stack |
| 104 | * registers. The difference is only logical, but on i386 the logic |
| 105 | * for using TRAPF_USERMODE() is complicated by sometimes treating vm86 |
| 106 | * bioscall mode (which is a special ring 3 user mode) as kernel mode. |
| 107 | */ |
| 108 | #define	TF_HAS_STACKREGS(tf)	TRAPF_USERMODE(tf) |
| 109 | #endif /* __i386__ */ |
| 110 | |
| 111 | #ifdef __amd64__ |
| 112 | /* |
| 113 | * Exception/Trap Stack Frame |
| 114 | * |
| 115 | * The ordering of this is specifically so that we can take first 6 |
| 116 | * the syscall arguments directly from the beginning of the frame. |
| 117 | */ |
| 118 | |
| 119 | struct trapframe { |
| 120 | 	register_t	tf_rdi; |
| 121 | 	register_t	tf_rsi; |
| 122 | 	register_t	tf_rdx; |
| 123 | 	register_t	tf_rcx; |
| 124 | 	register_t	tf_r8; |
| 125 | 	register_t	tf_r9; |
| 126 | 	register_t	tf_rax; |
| 127 | 	register_t	tf_rbx; |
| 128 | 	register_t	tf_rbp; |
| 129 | 	register_t	tf_r10; |
| 130 | 	register_t	tf_r11; |
| 131 | 	register_t	tf_r12; |
| 132 | 	register_t	tf_r13; |
| 133 | 	register_t	tf_r14; |
| 134 | 	register_t	tf_r15; |
| 135 | 	uint32_t	tf_trapno; |
| 136 | 	uint16_t	tf_fs; |
| 137 | 	uint16_t	tf_gs; |
| 138 | 	register_t	tf_addr; |
| 139 | 	uint32_t	tf_flags; |
| 140 | 	uint16_t	tf_es; |
| 141 | 	uint16_t	tf_ds; |
| 142 | 	/* below portion defined in hardware */ |
| 143 | 	register_t	tf_err; |
| 144 | 	register_t	tf_rip; |
| 145 | 	register_t	tf_cs; |
| 146 | 	register_t	tf_rflags; |
| 147 | 	/* the amd64 frame always has the stack registers */ |
| 148 | 	register_t	tf_rsp; |
| 149 | 	register_t	tf_ss; |
| 150 | }; |
| 151 | |
| 152 | #define	TF_HASSEGS	0x1 |
| 153 | #define	TF_HASBASES	0x2 |
| 154 | #define	TF_HASFPXSTATE	0x4 |
| 155 | #define	TF_RESERV0	0x8 /* no tlsbase in the trapframe */ |
| 156 | #endif /* __amd64__ */ |
| 157 | |
| 158 | #endif /* _MACHINE_FRAME_H_ */ |