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 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 #define TF_RESERV0 0x8 /* no tlsbase in the trapframe */ 157 #endif /* __amd64__ */ 158 159 #endif /* _MACHINE_FRAME_H_ */ 160