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 * struct trapframe is known to and used by kernel debuggers. 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 uint16_t tf_cs; 147 uint16_t tf_fred_evinfo3; 148 uint32_t tf_fred_zero2; 149 register_t tf_rflags; 150 /* the amd64 frame always has the stack registers */ 151 register_t tf_rsp; 152 uint16_t tf_ss; 153 uint16_t tf_fred_evinfo1; 154 uint32_t tf_fred_evinfo2; 155 }; 156 157 struct trapframe_fred { 158 struct trapframe tf_idt; 159 /* two long words added by FRED */ 160 uint64_t tf_fred_evdata; 161 uint64_t tf_fred_zero1; 162 }; 163 164 #define TF_FRED_EVDATA_B0 0x0000000000000001ull /* %dr6 B0 */ 165 #define TF_FRED_EVDATA_B1 0x0000000000000002ull 166 #define TF_FRED_EVDATA_B2 0x0000000000000004ull 167 #define TF_FRED_EVDATA_B3 0x0000000000000008ull 168 #define TF_FRED_EVDATA_BLD 0x0000000000000800ull /* bus lock acq 169 detected */ 170 #define TF_FRED_EVDATA_BD 0x0000000000002000ull /* dr access detected */ 171 #define TF_FRED_EVDATA_BS 0x0000000000004000ull /* single step */ 172 #define TF_FRED_EVDATA_RTM 0x0000000000010000ull /* #db or #bp in RTM */ 173 174 #define TF_FRED_EVINFO1_STIINT 0x0001 /* hw intr blocked by STI */ 175 #define TF_FRED_EVINFO1_SYSCALL 0x0002 /* SYSCALL/SYSENTER/INTn */ 176 #define TF_FRED_EVINFO1_NMI 0x0004 /* NMI */ 177 178 #define TF_FRED_EVINFO2_VECMASK 0x000000ff /* event vector mask */ 179 #define TF_FRED_EVINFO2_TYPEMASK 0x000f0000 /* event type mask */ 180 #define TF_FRED_EVINFO2_TYPE_EXTINT 0x00000000 181 #define TF_FRED_EVINFO2_TYPE_NMI 0x00020000 182 #define TF_FRED_EVINFO2_TYPE_EXC 0x00030000 183 #define TF_FRED_EVINFO2_TYPE_INTn 0x00040000 184 #define TF_FRED_EVINFO2_TYPE_INT1 0x00050000 185 #define TF_FRED_EVINFO2_TYPE_INT3 0x00060000 186 #define TF_FRED_EVINFO2_TYPE_SYSCALL 0x00070000 187 #define TF_FRED_EVINFO2_ENCL 0x01000000 /* SGX-related */ 188 #define TF_FRED_EVINFO2_LM 0x02000000 /* in 64bit mode */ 189 #define TF_FRED_EVINFO2_NEST 0x04000000 /* during ev delivery */ 190 #define TF_FRED_EVINFO2_INSTLENMASK 0xf0000000 /* instr length mask */ 191 #define TF_FRED_EVINFO2_INSTLENSHIFT 28 /* instr length shift */ 192 193 #define TF_FRED_EVINFO2_VEC_SYSCALL 1 194 #define TF_FRED_EVINFO2_VEC_SYSENTER 2 195 196 #define TF_FRED_EVINFO3_CSLMASK 0x0003 /* event CSL mask */ 197 #define TF_FRED_EVINFO3_WFE 0x0004 /* in WAIT_FOR_ENDBRANCH */ 198 199 #define TF_HASSEGS 0x00000001 200 #define TF_HASBASES 0x00000002 201 #define TF_HASFPXSTATE 0x00000004 202 #define TF_RESERV0 0x00000008 /* no tlsbase in the trapframe */ 203 #define TF_FRED 0x00000010 204 #endif /* __amd64__ */ 205 206 #endif /* _MACHINE_FRAME_H_ */ 207