1 /*- 2 * SPDX-License-Identifier: BSD-3-Clause 3 * 4 * Copyright (c) 1982, 1990 The Regents of the University of California. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * William Jolitz. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. Neither the name of the University nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * from: @(#)genassym.c 5.11 (Berkeley) 5/10/91 35 */ 36 37 #include <sys/cdefs.h> 38 __FBSDID("$FreeBSD$"); 39 40 #include "opt_hwpmc_hooks.h" 41 #include "opt_kstack_pages.h" 42 43 #include <sys/param.h> 44 #include <sys/systm.h> 45 #include <sys/assym.h> 46 #include <sys/bio.h> 47 #include <sys/buf.h> 48 #include <sys/proc.h> 49 #ifdef HWPMC_HOOKS 50 #include <sys/pmckern.h> 51 #endif 52 #include <sys/errno.h> 53 #include <sys/mount.h> 54 #include <sys/mutex.h> 55 #include <sys/socket.h> 56 #include <sys/resourcevar.h> 57 #include <sys/ucontext.h> 58 #include <machine/tss.h> 59 #include <sys/vmmeter.h> 60 #include <vm/vm.h> 61 #include <vm/vm_param.h> 62 #include <vm/pmap.h> 63 #include <vm/vm_map.h> 64 #include <sys/proc.h> 65 #include <x86/apicreg.h> 66 #include <machine/cpu.h> 67 #include <machine/pcb.h> 68 #include <machine/sigframe.h> 69 #include <machine/proc.h> 70 #include <machine/segments.h> 71 #include <machine/efi.h> 72 73 ASSYM(P_VMSPACE, offsetof(struct proc, p_vmspace)); 74 ASSYM(VM_PMAP, offsetof(struct vmspace, vm_pmap)); 75 ASSYM(PM_ACTIVE, offsetof(struct pmap, pm_active)); 76 77 ASSYM(P_MD, offsetof(struct proc, p_md)); 78 ASSYM(MD_LDT, offsetof(struct mdproc, md_ldt)); 79 ASSYM(MD_LDT_SD, offsetof(struct mdproc, md_ldt_sd)); 80 81 ASSYM(MD_EFIRT_TMP, offsetof(struct mdthread, md_efirt_tmp)); 82 83 ASSYM(TD_LOCK, offsetof(struct thread, td_lock)); 84 ASSYM(TD_FLAGS, offsetof(struct thread, td_flags)); 85 ASSYM(TD_AST, offsetof(struct thread, td_ast)); 86 ASSYM(TD_PCB, offsetof(struct thread, td_pcb)); 87 ASSYM(TD_PFLAGS, offsetof(struct thread, td_pflags)); 88 ASSYM(TD_PROC, offsetof(struct thread, td_proc)); 89 ASSYM(TD_FRAME, offsetof(struct thread, td_frame)); 90 ASSYM(TD_MD, offsetof(struct thread, td_md)); 91 ASSYM(TD_MD_PCB, offsetof(struct thread, td_md.md_pcb)); 92 ASSYM(TD_MD_STACK_BASE, offsetof(struct thread, td_md.md_stack_base)); 93 94 ASSYM(TDP_CALLCHAIN, TDP_CALLCHAIN); 95 ASSYM(TDP_KTHREAD, TDP_KTHREAD); 96 97 ASSYM(PAGE_SIZE, PAGE_SIZE); 98 ASSYM(NPTEPG, NPTEPG); 99 ASSYM(NPDEPG, NPDEPG); 100 ASSYM(addr_P4Tmap, addr_P4Tmap); 101 ASSYM(addr_P4Dmap, addr_P4Dmap); 102 ASSYM(addr_P5Tmap, addr_P5Tmap); 103 ASSYM(addr_P5Dmap, addr_P5Dmap); 104 ASSYM(PDESIZE, sizeof(pd_entry_t)); 105 ASSYM(PTESIZE, sizeof(pt_entry_t)); 106 ASSYM(PAGE_SHIFT, PAGE_SHIFT); 107 ASSYM(PAGE_MASK, PAGE_MASK); 108 ASSYM(PDRSHIFT, PDRSHIFT); 109 ASSYM(PDPSHIFT, PDPSHIFT); 110 ASSYM(PML4SHIFT, PML4SHIFT); 111 ASSYM(val_KPDPI, KPDPI); 112 ASSYM(val_KPML4I, KPML4I); 113 ASSYM(val_PML4PML4I, PML4PML4I); 114 ASSYM(VM_MAXUSER_ADDRESS, VM_MAXUSER_ADDRESS); 115 ASSYM(KERNBASE, KERNBASE); 116 ASSYM(KERNLOAD, KERNLOAD); 117 ASSYM(DMAP_MIN_ADDRESS, DMAP_MIN_ADDRESS); 118 ASSYM(DMAP_MAX_ADDRESS, DMAP_MAX_ADDRESS); 119 120 ASSYM(PCB_R15, offsetof(struct pcb, pcb_r15)); 121 ASSYM(PCB_R14, offsetof(struct pcb, pcb_r14)); 122 ASSYM(PCB_R13, offsetof(struct pcb, pcb_r13)); 123 ASSYM(PCB_R12, offsetof(struct pcb, pcb_r12)); 124 ASSYM(PCB_RBP, offsetof(struct pcb, pcb_rbp)); 125 ASSYM(PCB_RSP, offsetof(struct pcb, pcb_rsp)); 126 ASSYM(PCB_RBX, offsetof(struct pcb, pcb_rbx)); 127 ASSYM(PCB_RIP, offsetof(struct pcb, pcb_rip)); 128 ASSYM(PCB_FSBASE, offsetof(struct pcb, pcb_fsbase)); 129 ASSYM(PCB_GSBASE, offsetof(struct pcb, pcb_gsbase)); 130 ASSYM(PCB_KGSBASE, offsetof(struct pcb, pcb_kgsbase)); 131 ASSYM(PCB_CR0, offsetof(struct pcb, pcb_cr0)); 132 ASSYM(PCB_CR2, offsetof(struct pcb, pcb_cr2)); 133 ASSYM(PCB_CR3, offsetof(struct pcb, pcb_cr3)); 134 ASSYM(PCB_CR4, offsetof(struct pcb, pcb_cr4)); 135 ASSYM(PCB_DR0, offsetof(struct pcb, pcb_dr0)); 136 ASSYM(PCB_DR1, offsetof(struct pcb, pcb_dr1)); 137 ASSYM(PCB_DR2, offsetof(struct pcb, pcb_dr2)); 138 ASSYM(PCB_DR3, offsetof(struct pcb, pcb_dr3)); 139 ASSYM(PCB_DR6, offsetof(struct pcb, pcb_dr6)); 140 ASSYM(PCB_DR7, offsetof(struct pcb, pcb_dr7)); 141 ASSYM(PCB_GDT, offsetof(struct pcb, pcb_gdt)); 142 ASSYM(PCB_IDT, offsetof(struct pcb, pcb_idt)); 143 ASSYM(PCB_LDT, offsetof(struct pcb, pcb_ldt)); 144 ASSYM(PCB_TR, offsetof(struct pcb, pcb_tr)); 145 ASSYM(PCB_FLAGS, offsetof(struct pcb, pcb_flags)); 146 ASSYM(PCB_ONFAULT, offsetof(struct pcb, pcb_onfault)); 147 ASSYM(PCB_SAVED_UCR3, offsetof(struct pcb, pcb_saved_ucr3)); 148 ASSYM(PCB_TSSP, offsetof(struct pcb, pcb_tssp)); 149 ASSYM(PCB_SAVEFPU, offsetof(struct pcb, pcb_save)); 150 ASSYM(PCB_EFER, offsetof(struct pcb, pcb_efer)); 151 ASSYM(PCB_STAR, offsetof(struct pcb, pcb_star)); 152 ASSYM(PCB_LSTAR, offsetof(struct pcb, pcb_lstar)); 153 ASSYM(PCB_CSTAR, offsetof(struct pcb, pcb_cstar)); 154 ASSYM(PCB_SFMASK, offsetof(struct pcb, pcb_sfmask)); 155 ASSYM(PCB_SIZE, sizeof(struct pcb)); 156 ASSYM(PCB_FULL_IRET, PCB_FULL_IRET); 157 ASSYM(PCB_DBREGS, PCB_DBREGS); 158 ASSYM(PCB_32BIT, PCB_32BIT); 159 160 ASSYM(TSS_RSP0, offsetof(struct amd64tss, tss_rsp0)); 161 162 ASSYM(TF_R15, offsetof(struct trapframe, tf_r15)); 163 ASSYM(TF_R14, offsetof(struct trapframe, tf_r14)); 164 ASSYM(TF_R13, offsetof(struct trapframe, tf_r13)); 165 ASSYM(TF_R12, offsetof(struct trapframe, tf_r12)); 166 ASSYM(TF_R11, offsetof(struct trapframe, tf_r11)); 167 ASSYM(TF_R10, offsetof(struct trapframe, tf_r10)); 168 ASSYM(TF_R9, offsetof(struct trapframe, tf_r9)); 169 ASSYM(TF_R8, offsetof(struct trapframe, tf_r8)); 170 ASSYM(TF_RDI, offsetof(struct trapframe, tf_rdi)); 171 ASSYM(TF_RSI, offsetof(struct trapframe, tf_rsi)); 172 ASSYM(TF_RBP, offsetof(struct trapframe, tf_rbp)); 173 ASSYM(TF_RBX, offsetof(struct trapframe, tf_rbx)); 174 ASSYM(TF_RDX, offsetof(struct trapframe, tf_rdx)); 175 ASSYM(TF_RCX, offsetof(struct trapframe, tf_rcx)); 176 ASSYM(TF_RAX, offsetof(struct trapframe, tf_rax)); 177 ASSYM(TF_TRAPNO, offsetof(struct trapframe, tf_trapno)); 178 ASSYM(TF_ADDR, offsetof(struct trapframe, tf_addr)); 179 ASSYM(TF_ERR, offsetof(struct trapframe, tf_err)); 180 ASSYM(TF_RIP, offsetof(struct trapframe, tf_rip)); 181 ASSYM(TF_CS, offsetof(struct trapframe, tf_cs)); 182 ASSYM(TF_RFLAGS, offsetof(struct trapframe, tf_rflags)); 183 ASSYM(TF_RSP, offsetof(struct trapframe, tf_rsp)); 184 ASSYM(TF_SS, offsetof(struct trapframe, tf_ss)); 185 ASSYM(TF_DS, offsetof(struct trapframe, tf_ds)); 186 ASSYM(TF_ES, offsetof(struct trapframe, tf_es)); 187 ASSYM(TF_FS, offsetof(struct trapframe, tf_fs)); 188 ASSYM(TF_GS, offsetof(struct trapframe, tf_gs)); 189 ASSYM(TF_FLAGS, offsetof(struct trapframe, tf_flags)); 190 ASSYM(TF_SIZE, sizeof(struct trapframe)); 191 ASSYM(TF_HASSEGS, TF_HASSEGS); 192 193 ASSYM(PTI_RDX, offsetof(struct pti_frame, pti_rdx)); 194 ASSYM(PTI_RAX, offsetof(struct pti_frame, pti_rax)); 195 ASSYM(PTI_ERR, offsetof(struct pti_frame, pti_err)); 196 ASSYM(PTI_RIP, offsetof(struct pti_frame, pti_rip)); 197 ASSYM(PTI_CS, offsetof(struct pti_frame, pti_cs)); 198 ASSYM(PTI_RFLAGS, offsetof(struct pti_frame, pti_rflags)); 199 ASSYM(PTI_RSP, offsetof(struct pti_frame, pti_rsp)); 200 ASSYM(PTI_SS, offsetof(struct pti_frame, pti_ss)); 201 ASSYM(PTI_SIZE, sizeof(struct pti_frame)); 202 203 ASSYM(SIGF_HANDLER, offsetof(struct sigframe, sf_ahu.sf_handler)); 204 ASSYM(SIGF_UC, offsetof(struct sigframe, sf_uc)); 205 ASSYM(UC_EFLAGS, offsetof(ucontext_t, uc_mcontext.mc_rflags)); 206 ASSYM(UC_RDI, offsetof(ucontext_t, uc_mcontext.mc_rdi)); 207 ASSYM(UC_RSI, offsetof(ucontext_t, uc_mcontext.mc_rsi)); 208 ASSYM(UC_RDX, offsetof(ucontext_t, uc_mcontext.mc_rdx)); 209 ASSYM(UC_RCX, offsetof(ucontext_t, uc_mcontext.mc_rcx)); 210 ASSYM(UC_R8, offsetof(ucontext_t, uc_mcontext.mc_r8)); 211 ASSYM(UC_R9, offsetof(ucontext_t, uc_mcontext.mc_r9)); 212 ASSYM(UC_RAX, offsetof(ucontext_t, uc_mcontext.mc_rax)); 213 ASSYM(UC_RBX, offsetof(ucontext_t, uc_mcontext.mc_rbx)); 214 ASSYM(UC_RBP, offsetof(ucontext_t, uc_mcontext.mc_rbp)); 215 ASSYM(UC_R10, offsetof(ucontext_t, uc_mcontext.mc_r10)); 216 ASSYM(UC_R11, offsetof(ucontext_t, uc_mcontext.mc_r11)); 217 ASSYM(UC_R12, offsetof(ucontext_t, uc_mcontext.mc_r12)); 218 ASSYM(UC_R13, offsetof(ucontext_t, uc_mcontext.mc_r13)); 219 ASSYM(UC_R14, offsetof(ucontext_t, uc_mcontext.mc_r14)); 220 ASSYM(UC_R15, offsetof(ucontext_t, uc_mcontext.mc_r15)); 221 ASSYM(UC_FS, offsetof(ucontext_t, uc_mcontext.mc_fs)); 222 ASSYM(UC_GS, offsetof(ucontext_t, uc_mcontext.mc_gs)); 223 ASSYM(UC_ES, offsetof(ucontext_t, uc_mcontext.mc_es)); 224 ASSYM(UC_DS, offsetof(ucontext_t, uc_mcontext.mc_ds)); 225 ASSYM(UC_RIP, offsetof(ucontext_t, uc_mcontext.mc_rip)); 226 ASSYM(UC_CS, offsetof(ucontext_t, uc_mcontext.mc_cs)); 227 ASSYM(UC_RFLAGS, offsetof(ucontext_t, uc_mcontext.mc_rflags)); 228 ASSYM(UC_RSP, offsetof(ucontext_t, uc_mcontext.mc_rsp)); 229 ASSYM(UC_SS, offsetof(ucontext_t, uc_mcontext.mc_ss)); 230 ASSYM(UC_FSBASE, offsetof(ucontext_t, uc_mcontext.mc_fsbase)); 231 ASSYM(UC_GSBASE, offsetof(ucontext_t, uc_mcontext.mc_gsbase)); 232 233 ASSYM(ENOENT, ENOENT); 234 ASSYM(EFAULT, EFAULT); 235 ASSYM(ENAMETOOLONG, ENAMETOOLONG); 236 ASSYM(MAXCOMLEN, MAXCOMLEN); 237 ASSYM(MAXPATHLEN, MAXPATHLEN); 238 ASSYM(PC_SIZEOF, sizeof(struct pcpu)); 239 ASSYM(PC_PRVSPACE, offsetof(struct pcpu, pc_prvspace)); 240 ASSYM(PC_CURTHREAD, offsetof(struct pcpu, pc_curthread)); 241 ASSYM(PC_FPCURTHREAD, offsetof(struct pcpu, pc_fpcurthread)); 242 ASSYM(PC_IDLETHREAD, offsetof(struct pcpu, pc_idlethread)); 243 ASSYM(PC_CURPCB, offsetof(struct pcpu, pc_curpcb)); 244 ASSYM(PC_CPUID, offsetof(struct pcpu, pc_cpuid)); 245 ASSYM(PC_SCRATCH_RSP, offsetof(struct pcpu, pc_scratch_rsp)); 246 ASSYM(PC_SCRATCH_RAX, offsetof(struct pcpu, pc_scratch_rax)); 247 ASSYM(PC_CURPMAP, offsetof(struct pcpu, pc_curpmap)); 248 ASSYM(PC_TSSP, offsetof(struct pcpu, pc_tssp)); 249 ASSYM(PC_RSP0, offsetof(struct pcpu, pc_rsp0)); 250 ASSYM(PC_FS32P, offsetof(struct pcpu, pc_fs32p)); 251 ASSYM(PC_GS32P, offsetof(struct pcpu, pc_gs32p)); 252 ASSYM(PC_LDT, offsetof(struct pcpu, pc_ldt)); 253 ASSYM(PC_COMMONTSS, offsetof(struct pcpu, pc_common_tss)); 254 ASSYM(PC_TSS, offsetof(struct pcpu, pc_tss)); 255 ASSYM(PC_KCR3, offsetof(struct pcpu, pc_kcr3)); 256 ASSYM(PC_UCR3, offsetof(struct pcpu, pc_ucr3)); 257 ASSYM(PC_UCR3_LOAD_MASK, offsetof(struct pcpu, pc_ucr3_load_mask)); 258 ASSYM(PC_SAVED_UCR3, offsetof(struct pcpu, pc_saved_ucr3)); 259 ASSYM(PC_PTI_STACK, offsetof(struct pcpu, pc_pti_stack)); 260 ASSYM(PC_PTI_STACK_SZ, PC_PTI_STACK_SZ); 261 ASSYM(PC_PTI_RSP0, offsetof(struct pcpu, pc_pti_rsp0)); 262 ASSYM(PC_IBPB_SET, offsetof(struct pcpu, pc_ibpb_set)); 263 ASSYM(PC_MDS_TMP, offsetof(struct pcpu, pc_mds_tmp)); 264 ASSYM(PC_MDS_BUF, offsetof(struct pcpu, pc_mds_buf)); 265 ASSYM(PC_MDS_BUF64, offsetof(struct pcpu, pc_mds_buf64)); 266 267 ASSYM(LA_EOI, LAPIC_EOI * LAPIC_MEM_MUL); 268 ASSYM(LA_ISR, LAPIC_ISR0 * LAPIC_MEM_MUL); 269 270 ASSYM(KCSEL, GSEL(GCODE_SEL, SEL_KPL)); 271 ASSYM(KDSEL, GSEL(GDATA_SEL, SEL_KPL)); 272 ASSYM(KUCSEL, GSEL(GUCODE_SEL, SEL_UPL)); 273 ASSYM(KUDSEL, GSEL(GUDATA_SEL, SEL_UPL)); 274 ASSYM(KUC32SEL, GSEL(GUCODE32_SEL, SEL_UPL)); 275 ASSYM(KUF32SEL, GSEL(GUFS32_SEL, SEL_UPL)); 276 ASSYM(KUG32SEL, GSEL(GUGS32_SEL, SEL_UPL)); 277 ASSYM(TSSSEL, GSEL(GPROC0_SEL, SEL_KPL)); 278 ASSYM(LDTSEL, GSEL(GUSERLDT_SEL, SEL_KPL)); 279 ASSYM(SEL_RPL_MASK, SEL_RPL_MASK); 280 281 ASSYM(__FreeBSD_version, __FreeBSD_version); 282 283 #ifdef HWPMC_HOOKS 284 ASSYM(PMC_FN_USER_CALLCHAIN, PMC_FN_USER_CALLCHAIN); 285 #endif 286 287 ASSYM(EC_EFI_STATUS, offsetof(struct efirt_callinfo, ec_efi_status)); 288 ASSYM(EC_FPTR, offsetof(struct efirt_callinfo, ec_fptr)); 289 ASSYM(EC_ARGCNT, offsetof(struct efirt_callinfo, ec_argcnt)); 290 ASSYM(EC_ARG1, offsetof(struct efirt_callinfo, ec_arg1)); 291 ASSYM(EC_ARG2, offsetof(struct efirt_callinfo, ec_arg2)); 292 ASSYM(EC_ARG3, offsetof(struct efirt_callinfo, ec_arg3)); 293 ASSYM(EC_ARG4, offsetof(struct efirt_callinfo, ec_arg4)); 294 ASSYM(EC_ARG5, offsetof(struct efirt_callinfo, ec_arg5)); 295 ASSYM(EC_RBX, offsetof(struct efirt_callinfo, ec_rbx)); 296 ASSYM(EC_RSP, offsetof(struct efirt_callinfo, ec_rsp)); 297 ASSYM(EC_RBP, offsetof(struct efirt_callinfo, ec_rbp)); 298 ASSYM(EC_R12, offsetof(struct efirt_callinfo, ec_r12)); 299 ASSYM(EC_R13, offsetof(struct efirt_callinfo, ec_r13)); 300 ASSYM(EC_R14, offsetof(struct efirt_callinfo, ec_r14)); 301 ASSYM(EC_R15, offsetof(struct efirt_callinfo, ec_r15)); 302 ASSYM(EC_RFLAGS, offsetof(struct efirt_callinfo, ec_rflags)); 303