17c958a41SKonstantin Belousov /*- 27c958a41SKonstantin Belousov * Copyright (c) 1995 Bruce D. Evans. 37c958a41SKonstantin Belousov * All rights reserved. 47c958a41SKonstantin Belousov * 57c958a41SKonstantin Belousov * Redistribution and use in source and binary forms, with or without 67c958a41SKonstantin Belousov * modification, are permitted provided that the following conditions 77c958a41SKonstantin Belousov * are met: 87c958a41SKonstantin Belousov * 1. Redistributions of source code must retain the above copyright 97c958a41SKonstantin Belousov * notice, this list of conditions and the following disclaimer. 107c958a41SKonstantin Belousov * 2. Redistributions in binary form must reproduce the above copyright 117c958a41SKonstantin Belousov * notice, this list of conditions and the following disclaimer in the 127c958a41SKonstantin Belousov * documentation and/or other materials provided with the distribution. 137c958a41SKonstantin Belousov * 3. Neither the name of the author nor the names of contributors 147c958a41SKonstantin Belousov * may be used to endorse or promote products derived from this software 157c958a41SKonstantin Belousov * without specific prior written permission. 167c958a41SKonstantin Belousov * 177c958a41SKonstantin Belousov * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 187c958a41SKonstantin Belousov * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 197c958a41SKonstantin Belousov * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 207c958a41SKonstantin Belousov * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 217c958a41SKonstantin Belousov * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 227c958a41SKonstantin Belousov * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 237c958a41SKonstantin Belousov * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 247c958a41SKonstantin Belousov * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 257c958a41SKonstantin Belousov * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 267c958a41SKonstantin Belousov * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 277c958a41SKonstantin Belousov * SUCH DAMAGE. 287c958a41SKonstantin Belousov */ 297c958a41SKonstantin Belousov 307c958a41SKonstantin Belousov #ifndef _X86_X86_VAR_H_ 317c958a41SKonstantin Belousov #define _X86_X86_VAR_H_ 327c958a41SKonstantin Belousov 337c958a41SKonstantin Belousov /* 347c958a41SKonstantin Belousov * Miscellaneous machine-dependent declarations. 357c958a41SKonstantin Belousov */ 367c958a41SKonstantin Belousov 377c958a41SKonstantin Belousov extern long Maxmem; 387c958a41SKonstantin Belousov extern u_int basemem; 397c958a41SKonstantin Belousov extern u_int cpu_exthigh; 407c958a41SKonstantin Belousov extern u_int cpu_feature; 417c958a41SKonstantin Belousov extern u_int cpu_feature2; 427c958a41SKonstantin Belousov extern u_int amd_feature; 437c958a41SKonstantin Belousov extern u_int amd_feature2; 44cd8c2581SConrad Meyer extern u_int amd_rascap; 457c958a41SKonstantin Belousov extern u_int amd_pminfo; 46194446f9SConrad Meyer extern u_int amd_extended_feature_extensions; 477c958a41SKonstantin Belousov extern u_int via_feature_rng; 487c958a41SKonstantin Belousov extern u_int via_feature_xcrypt; 497c958a41SKonstantin Belousov extern u_int cpu_clflush_line_size; 507c958a41SKonstantin Belousov extern u_int cpu_stdext_feature; 517c958a41SKonstantin Belousov extern u_int cpu_stdext_feature2; 52e8c770a6SKonstantin Belousov extern u_int cpu_stdext_feature3; 53e8c770a6SKonstantin Belousov extern uint64_t cpu_ia32_arch_caps; 547c958a41SKonstantin Belousov extern u_int cpu_high; 557c958a41SKonstantin Belousov extern u_int cpu_id; 567c958a41SKonstantin Belousov extern u_int cpu_max_ext_state_size; 577c958a41SKonstantin Belousov extern u_int cpu_mxcsr_mask; 587c958a41SKonstantin Belousov extern u_int cpu_procinfo; 597c958a41SKonstantin Belousov extern u_int cpu_procinfo2; 60c6113ac5SKonstantin Belousov extern u_int cpu_procinfo3; 617c958a41SKonstantin Belousov extern char cpu_vendor[]; 62d63ea036SMark Johnston extern char cpu_model[]; 637c958a41SKonstantin Belousov extern u_int cpu_vendor_id; 647c958a41SKonstantin Belousov extern u_int cpu_mon_mwait_flags; 65fd67ff5cSAndrew Gallatin extern u_int cpu_mon_mwait_edx; 667c958a41SKonstantin Belousov extern u_int cpu_mon_min_size; 677c958a41SKonstantin Belousov extern u_int cpu_mon_max_size; 687c958a41SKonstantin Belousov extern u_int cpu_maxphyaddr; 69bb044eafSConrad Meyer extern u_int cpu_power_eax; 70bb044eafSConrad Meyer extern u_int cpu_power_ebx; 71bb044eafSConrad Meyer extern u_int cpu_power_ecx; 72bb044eafSConrad Meyer extern u_int cpu_power_edx; 73949f834aSStephen J. Kiernan extern u_int hv_base; 747c958a41SKonstantin Belousov extern u_int hv_high; 757c958a41SKonstantin Belousov extern char hv_vendor[]; 767c958a41SKonstantin Belousov extern char kstack[]; 777c958a41SKonstantin Belousov extern char sigcode[]; 787c958a41SKonstantin Belousov extern int szsigcode; 797c958a41SKonstantin Belousov extern int workaround_erratum383; 807c958a41SKonstantin Belousov extern int _udatasel; 817c958a41SKonstantin Belousov extern int _ucodesel; 827c958a41SKonstantin Belousov extern int _ucode32sel; 837c958a41SKonstantin Belousov extern int _ufssel; 847c958a41SKonstantin Belousov extern int _ugssel; 857c958a41SKonstantin Belousov extern int use_xsave; 867c958a41SKonstantin Belousov extern uint64_t xsave_mask; 87fd1f83fbSRoger Pau Monné extern u_int max_apic_id; 88eb785fabSKonstantin Belousov extern int i386_read_exec; 89bd50262fSKonstantin Belousov extern int pti; 90a324b7f7SKonstantin Belousov extern int hw_ibrs_ibpb_active; 917355a02bSKonstantin Belousov extern int hw_mds_disable; 923621ba1eSKonstantin Belousov extern int hw_ssb_active; 93e3721601SScott Long extern int x86_taa_enable; 94ea602083SKonstantin Belousov extern int cpu_flush_rsb_ctxsw; 9517edf152SKonstantin Belousov extern int x86_rngds_mitg_enable; 96ebaea1bcSOlivier Certner extern int zenbleed_enable; 97d3ba71b2SKonstantin Belousov extern int cpu_amdc1e_bug; 98a2495c36SRoger Pau Monné extern char bootmethod[16]; 997c958a41SKonstantin Belousov 1007c958a41SKonstantin Belousov struct pcb; 1017c958a41SKonstantin Belousov struct thread; 1027c958a41SKonstantin Belousov struct reg; 1037c958a41SKonstantin Belousov struct fpreg; 1047c958a41SKonstantin Belousov struct dbreg; 1057c958a41SKonstantin Belousov struct dumperinfo; 106835c2787SKonstantin Belousov struct trapframe; 1071adebe3cSMitchell Horne struct minidumpstate; 1087c958a41SKonstantin Belousov 1090df87548SKonstantin Belousov /* 1100df87548SKonstantin Belousov * The interface type of the interrupt handler entry point cannot be 1110df87548SKonstantin Belousov * expressed in C. Use simplest non-variadic function type as an 1120df87548SKonstantin Belousov * approximation. 1130df87548SKonstantin Belousov */ 1140df87548SKonstantin Belousov typedef void alias_for_inthand_t(void); 1150df87548SKonstantin Belousov 1167705dd4dSKonstantin Belousov bool acpi_get_fadt_bootflags(uint16_t *flagsp); 1177c958a41SKonstantin Belousov void *alloc_fpusave(int flags); 1183a3f1e9dSPeter Grehan u_int cpu_auxmsr(void); 1199a527560SKonstantin Belousov vm_paddr_t cpu_getmaxphyaddr(void); 1207c958a41SKonstantin Belousov bool cpu_mwait_usable(void); 1217c958a41SKonstantin Belousov void cpu_probe_amdc1e(void); 1227c958a41SKonstantin Belousov void cpu_setregs(void); 12315dc1d44SMitchell Horne int dbreg_set_watchpoint(vm_offset_t addr, vm_size_t size, int access); 124c02c04f1SMitchell Horne int dbreg_clr_watchpoint(vm_offset_t addr, vm_size_t size); 125c02c04f1SMitchell Horne void dbreg_list_watchpoints(void); 126a8b75a57SKonstantin Belousov void x86_clear_dbregs(struct pcb *pcb); 1278fbcc334SKonstantin Belousov bool disable_wp(void); 1288fbcc334SKonstantin Belousov void restore_wp(bool old_wp); 129b5669d0aSJung-uk Kim void finishidentcpu(void); 1300530a936SKonstantin Belousov void identify_cpu1(void); 1310530a936SKonstantin Belousov void identify_cpu2(void); 132050f5a84SDmitry Chagin void identify_cpu_ext_features(void); 13383813c66SKonstantin Belousov void identify_cpu_fixup_bsp(void); 13401050344SJung-uk Kim void identify_hypervisor(void); 1357c958a41SKonstantin Belousov void initializecpu(void); 1367c958a41SKonstantin Belousov void initializecpucache(void); 1370d63fc3eSAndriy Gapon bool fix_cpuid(void); 1387c958a41SKonstantin Belousov void fillw(int /*u_short*/ pat, void *base, size_t cnt); 1397c958a41SKonstantin Belousov int isa_nmi(int cd); 140319117fdSKonstantin Belousov void handle_ibrs_entry(void); 141319117fdSKonstantin Belousov void handle_ibrs_exit(void); 142a324b7f7SKonstantin Belousov void hw_ibrs_recalculate(bool all_cpus); 1437355a02bSKonstantin Belousov void hw_mds_recalculate(void); 1443621ba1eSKonstantin Belousov void hw_ssb_recalculate(bool all_cpus); 145e3721601SScott Long void x86_taa_recalculate(void); 14617edf152SKonstantin Belousov void x86_rngds_mitg_recalculate(bool all_cpus); 147ebaea1bcSOlivier Certner void zenbleed_sanitize_enable(void); 148ebaea1bcSOlivier Certner void zenbleed_check_and_apply(bool all_cpus); 149295f4b6cSKonstantin Belousov void nmi_call_kdb(u_int cpu, u_int type, struct trapframe *frame); 150295f4b6cSKonstantin Belousov void nmi_call_kdb_smp(u_int type, struct trapframe *frame); 151*459dc427SBojan Novković void nmi_register_handler(int (*handler)(struct trapframe *)); 152*459dc427SBojan Novković void nmi_remove_handler(int (*handler)(struct trapframe *)); 153*459dc427SBojan Novković void nmi_handle_intr(struct trapframe *frame); 1547c958a41SKonstantin Belousov void pagecopy(void *from, void *to); 1557c958a41SKonstantin Belousov void printcpuinfo(void); 156b3327f62SEd Maste int pti_get_default(void); 1579e2154ffSJohn Baldwin int user_dbreg_trap(register_t dr6); 1581adebe3cSMitchell Horne int cpu_minidumpsys(struct dumperinfo *, const struct minidumpstate *); 1597c958a41SKonstantin Belousov struct pcb *get_pcb_td(struct thread *td); 160de8374dfSDmitry Chagin void x86_set_fork_retval(struct thread *td); 161652ae7b1SAdam Fenn uint64_t rdtsc_ordered(void); 1627c958a41SKonstantin Belousov 163d0bc4b46SKonstantin Belousov /* 164d0bc4b46SKonstantin Belousov * MSR ops for x86_msr_op() 165d0bc4b46SKonstantin Belousov */ 166fa83f689SKonstantin Belousov #define MSR_OP_ANDNOT 0x00000001 167fa83f689SKonstantin Belousov #define MSR_OP_OR 0x00000002 168fa83f689SKonstantin Belousov #define MSR_OP_WRITE 0x00000003 169d0bc4b46SKonstantin Belousov #define MSR_OP_READ 0x00000004 170d0bc4b46SKonstantin Belousov 171d0bc4b46SKonstantin Belousov /* 172d0bc4b46SKonstantin Belousov * Where and which execution mode 173d0bc4b46SKonstantin Belousov */ 174fa83f689SKonstantin Belousov #define MSR_OP_LOCAL 0x10000000 175d0bc4b46SKonstantin Belousov #define MSR_OP_SCHED_ALL 0x20000000 176d0bc4b46SKonstantin Belousov #define MSR_OP_SCHED_ONE 0x30000000 177d0bc4b46SKonstantin Belousov #define MSR_OP_RENDEZVOUS_ALL 0x40000000 178d0bc4b46SKonstantin Belousov #define MSR_OP_RENDEZVOUS_ONE 0x50000000 179d0bc4b46SKonstantin Belousov #define MSR_OP_CPUID(id) ((id) << 8) 180d0bc4b46SKonstantin Belousov 181d0bc4b46SKonstantin Belousov void x86_msr_op(u_int msr, u_int op, uint64_t arg1, uint64_t *res); 182fa83f689SKonstantin Belousov 183fd25c622SKonstantin Belousov #if defined(__i386__) && defined(INVARIANTS) 184fd25c622SKonstantin Belousov void trap_check_kstack(void); 185fd25c622SKonstantin Belousov #else 186fd25c622SKonstantin Belousov #define trap_check_kstack() 187fd25c622SKonstantin Belousov #endif 188fd25c622SKonstantin Belousov 1897c958a41SKonstantin Belousov #endif 190