1*1c4ee7dfSMark Johnston /*- 2*1c4ee7dfSMark Johnston * SPDX-License-Identifier: BSD-2-Clause 3*1c4ee7dfSMark Johnston * 4*1c4ee7dfSMark Johnston * Copyright (c) 2011 NetApp, Inc. 5*1c4ee7dfSMark Johnston * All rights reserved. 6*1c4ee7dfSMark Johnston * 7*1c4ee7dfSMark Johnston * Redistribution and use in source and binary forms, with or without 8*1c4ee7dfSMark Johnston * modification, are permitted provided that the following conditions 9*1c4ee7dfSMark Johnston * are met: 10*1c4ee7dfSMark Johnston * 1. Redistributions of source code must retain the above copyright 11*1c4ee7dfSMark Johnston * notice, this list of conditions and the following disclaimer. 12*1c4ee7dfSMark Johnston * 2. Redistributions in binary form must reproduce the above copyright 13*1c4ee7dfSMark Johnston * notice, this list of conditions and the following disclaimer in the 14*1c4ee7dfSMark Johnston * documentation and/or other materials provided with the distribution. 15*1c4ee7dfSMark Johnston * 16*1c4ee7dfSMark Johnston * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND 17*1c4ee7dfSMark Johnston * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18*1c4ee7dfSMark Johnston * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19*1c4ee7dfSMark Johnston * ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE 20*1c4ee7dfSMark Johnston * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21*1c4ee7dfSMark Johnston * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22*1c4ee7dfSMark Johnston * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23*1c4ee7dfSMark Johnston * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24*1c4ee7dfSMark Johnston * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25*1c4ee7dfSMark Johnston * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26*1c4ee7dfSMark Johnston * SUCH DAMAGE. 27*1c4ee7dfSMark Johnston */ 28*1c4ee7dfSMark Johnston 29*1c4ee7dfSMark Johnston #include <sys/types.h> 30*1c4ee7dfSMark Johnston #include <sys/mman.h> 31*1c4ee7dfSMark Johnston 32*1c4ee7dfSMark Johnston #include <machine/cpufunc.h> 33*1c4ee7dfSMark Johnston #include <machine/specialreg.h> 34*1c4ee7dfSMark Johnston 35*1c4ee7dfSMark Johnston #include <err.h> 36*1c4ee7dfSMark Johnston #include <fcntl.h> 37*1c4ee7dfSMark Johnston #include <getopt.h> 38*1c4ee7dfSMark Johnston #include <stdbool.h> 39*1c4ee7dfSMark Johnston #include <stdio.h> 40*1c4ee7dfSMark Johnston #include <stdlib.h> 41*1c4ee7dfSMark Johnston #include <string.h> 42*1c4ee7dfSMark Johnston #include <time.h> 43*1c4ee7dfSMark Johnston #include <unistd.h> 44*1c4ee7dfSMark Johnston 45*1c4ee7dfSMark Johnston #include <vmmapi.h> 46*1c4ee7dfSMark Johnston #include "amd/vmcb.h" 47*1c4ee7dfSMark Johnston #include "intel/vmcs.h" 48*1c4ee7dfSMark Johnston 49*1c4ee7dfSMark Johnston #include "bhyvectl.h" 50*1c4ee7dfSMark Johnston 51*1c4ee7dfSMark Johnston enum { 52*1c4ee7dfSMark Johnston SET_EFER = OPT_START_MD, 53*1c4ee7dfSMark Johnston SET_CR0, 54*1c4ee7dfSMark Johnston SET_CR2, 55*1c4ee7dfSMark Johnston SET_CR3, 56*1c4ee7dfSMark Johnston SET_CR4, 57*1c4ee7dfSMark Johnston SET_DR0, 58*1c4ee7dfSMark Johnston SET_DR1, 59*1c4ee7dfSMark Johnston SET_DR2, 60*1c4ee7dfSMark Johnston SET_DR3, 61*1c4ee7dfSMark Johnston SET_DR6, 62*1c4ee7dfSMark Johnston SET_DR7, 63*1c4ee7dfSMark Johnston SET_RSP, 64*1c4ee7dfSMark Johnston SET_RIP, 65*1c4ee7dfSMark Johnston SET_RAX, 66*1c4ee7dfSMark Johnston SET_RFLAGS, 67*1c4ee7dfSMark Johnston DESC_BASE, 68*1c4ee7dfSMark Johnston DESC_LIMIT, 69*1c4ee7dfSMark Johnston DESC_ACCESS, 70*1c4ee7dfSMark Johnston SET_CS, 71*1c4ee7dfSMark Johnston SET_DS, 72*1c4ee7dfSMark Johnston SET_ES, 73*1c4ee7dfSMark Johnston SET_FS, 74*1c4ee7dfSMark Johnston SET_GS, 75*1c4ee7dfSMark Johnston SET_SS, 76*1c4ee7dfSMark Johnston SET_TR, 77*1c4ee7dfSMark Johnston SET_LDTR, 78*1c4ee7dfSMark Johnston SET_X2APIC_STATE, 79*1c4ee7dfSMark Johnston UNASSIGN_PPTDEV, 80*1c4ee7dfSMark Johnston GET_GPA_PMAP, 81*1c4ee7dfSMark Johnston ASSERT_LAPIC_LVT, 82*1c4ee7dfSMark Johnston SET_RTC_TIME, 83*1c4ee7dfSMark Johnston SET_RTC_NVRAM, 84*1c4ee7dfSMark Johnston RTC_NVRAM_OFFSET, 85*1c4ee7dfSMark Johnston }; 86*1c4ee7dfSMark Johnston 87*1c4ee7dfSMark Johnston static int get_rtc_time, set_rtc_time; 88*1c4ee7dfSMark Johnston static int get_rtc_nvram, set_rtc_nvram; 89*1c4ee7dfSMark Johnston static int rtc_nvram_offset; 90*1c4ee7dfSMark Johnston static uint8_t rtc_nvram_value; 91*1c4ee7dfSMark Johnston static time_t rtc_secs; 92*1c4ee7dfSMark Johnston static int get_gpa_pmap; 93*1c4ee7dfSMark Johnston static vm_paddr_t gpa_pmap; 94*1c4ee7dfSMark Johnston static int inject_nmi, assert_lapic_lvt = -1; 95*1c4ee7dfSMark Johnston static int get_intinfo; 96*1c4ee7dfSMark Johnston static int set_cr0, get_cr0, set_cr2, get_cr2, set_cr3, get_cr3; 97*1c4ee7dfSMark Johnston static int set_cr4, get_cr4; 98*1c4ee7dfSMark Johnston static uint64_t set_cr0_val, set_cr2_val, set_cr3_val, set_cr4_val; 99*1c4ee7dfSMark Johnston static int set_efer, get_efer; 100*1c4ee7dfSMark Johnston static uint64_t set_efer_val; 101*1c4ee7dfSMark Johnston static int set_dr0, get_dr0; 102*1c4ee7dfSMark Johnston static int set_dr1, get_dr1; 103*1c4ee7dfSMark Johnston static int set_dr2, get_dr2; 104*1c4ee7dfSMark Johnston static int set_dr3, get_dr3; 105*1c4ee7dfSMark Johnston static int set_dr6, get_dr6; 106*1c4ee7dfSMark Johnston static int set_dr7, get_dr7; 107*1c4ee7dfSMark Johnston static uint64_t set_dr0_val, set_dr1_val, set_dr2_val, set_dr3_val, set_dr6_val; 108*1c4ee7dfSMark Johnston static uint64_t set_dr7_val; 109*1c4ee7dfSMark Johnston static int set_rsp, get_rsp, set_rip, get_rip, set_rflags, get_rflags; 110*1c4ee7dfSMark Johnston static int set_rax, get_rax; 111*1c4ee7dfSMark Johnston static uint64_t set_rsp_val, set_rip_val, set_rflags_val, set_rax_val; 112*1c4ee7dfSMark Johnston static int get_rbx, get_rcx, get_rdx, get_rsi, get_rdi, get_rbp; 113*1c4ee7dfSMark Johnston static int get_r8, get_r9, get_r10, get_r11, get_r12, get_r13, get_r14, get_r15; 114*1c4ee7dfSMark Johnston static int set_desc_ds, get_desc_ds; 115*1c4ee7dfSMark Johnston static int set_desc_es, get_desc_es; 116*1c4ee7dfSMark Johnston static int set_desc_fs, get_desc_fs; 117*1c4ee7dfSMark Johnston static int set_desc_gs, get_desc_gs; 118*1c4ee7dfSMark Johnston static int set_desc_cs, get_desc_cs; 119*1c4ee7dfSMark Johnston static int set_desc_ss, get_desc_ss; 120*1c4ee7dfSMark Johnston static int set_desc_gdtr, get_desc_gdtr; 121*1c4ee7dfSMark Johnston static int set_desc_idtr, get_desc_idtr; 122*1c4ee7dfSMark Johnston static int set_desc_tr, get_desc_tr; 123*1c4ee7dfSMark Johnston static int set_desc_ldtr, get_desc_ldtr; 124*1c4ee7dfSMark Johnston static int set_cs, set_ds, set_es, set_fs, set_gs, set_ss, set_tr, set_ldtr; 125*1c4ee7dfSMark Johnston static int get_cs, get_ds, get_es, get_fs, get_gs, get_ss, get_tr, get_ldtr; 126*1c4ee7dfSMark Johnston static uint64_t set_cs_val, set_ds_val, set_es_val, set_fs_val, set_gs_val; 127*1c4ee7dfSMark Johnston static uint64_t set_ss_val, set_tr_val, set_ldtr_val; 128*1c4ee7dfSMark Johnston static int set_x2apic_state, get_x2apic_state; 129*1c4ee7dfSMark Johnston static enum x2apic_state x2apic_state; 130*1c4ee7dfSMark Johnston static int unassign_pptdev, bus, slot, func; 131*1c4ee7dfSMark Johnston 132*1c4ee7dfSMark Johnston static uint64_t desc_base; 133*1c4ee7dfSMark Johnston static uint32_t desc_limit, desc_access; 134*1c4ee7dfSMark Johnston 135*1c4ee7dfSMark Johnston /* 136*1c4ee7dfSMark Johnston * VMCB specific. 137*1c4ee7dfSMark Johnston */ 138*1c4ee7dfSMark Johnston static int get_vmcb_intercept, get_vmcb_exit_details, get_vmcb_tlb_ctrl; 139*1c4ee7dfSMark Johnston static int get_vmcb_virq, get_avic_table; 140*1c4ee7dfSMark Johnston 141*1c4ee7dfSMark Johnston /* 142*1c4ee7dfSMark Johnston * VMCS-specific fields 143*1c4ee7dfSMark Johnston */ 144*1c4ee7dfSMark Johnston static int get_pinbased_ctls, get_procbased_ctls, get_procbased_ctls2; 145*1c4ee7dfSMark Johnston static int get_eptp, get_io_bitmap, get_tsc_offset; 146*1c4ee7dfSMark Johnston static int get_vmcs_entry_interruption_info; 147*1c4ee7dfSMark Johnston static int get_vmcs_interruptibility; 148*1c4ee7dfSMark Johnston static int get_vmcs_gpa, get_vmcs_gla; 149*1c4ee7dfSMark Johnston static int get_exception_bitmap; 150*1c4ee7dfSMark Johnston static int get_cr0_mask, get_cr0_shadow; 151*1c4ee7dfSMark Johnston static int get_cr4_mask, get_cr4_shadow; 152*1c4ee7dfSMark Johnston static int get_cr3_targets; 153*1c4ee7dfSMark Johnston static int get_apic_access_addr, get_virtual_apic_addr, get_tpr_threshold; 154*1c4ee7dfSMark Johnston static int get_msr_bitmap, get_msr_bitmap_address; 155*1c4ee7dfSMark Johnston static int get_vpid_asid; 156*1c4ee7dfSMark Johnston static int get_inst_err, get_exit_ctls, get_entry_ctls; 157*1c4ee7dfSMark Johnston static int get_host_cr0, get_host_cr3, get_host_cr4; 158*1c4ee7dfSMark Johnston static int get_host_rip, get_host_rsp; 159*1c4ee7dfSMark Johnston static int get_guest_pat, get_host_pat; 160*1c4ee7dfSMark Johnston static int get_guest_sysenter, get_vmcs_link; 161*1c4ee7dfSMark Johnston static int get_exit_reason, get_vmcs_exit_qualification; 162*1c4ee7dfSMark Johnston static int get_vmcs_exit_interruption_info, get_vmcs_exit_interruption_error; 163*1c4ee7dfSMark Johnston static int get_vmcs_exit_inst_length; 164*1c4ee7dfSMark Johnston 165*1c4ee7dfSMark Johnston static bool 166*1c4ee7dfSMark Johnston cpu_vendor_intel(void) 167*1c4ee7dfSMark Johnston { 168*1c4ee7dfSMark Johnston u_int regs[4], v[3]; 169*1c4ee7dfSMark Johnston 170*1c4ee7dfSMark Johnston do_cpuid(0, regs); 171*1c4ee7dfSMark Johnston v[0] = regs[1]; 172*1c4ee7dfSMark Johnston v[1] = regs[3]; 173*1c4ee7dfSMark Johnston v[2] = regs[2]; 174*1c4ee7dfSMark Johnston 175*1c4ee7dfSMark Johnston if (memcmp(v, "GenuineIntel", sizeof(v)) == 0) 176*1c4ee7dfSMark Johnston return (true); 177*1c4ee7dfSMark Johnston if (memcmp(v, "AuthenticAMD", sizeof(v)) == 0 || 178*1c4ee7dfSMark Johnston memcmp(v, "HygonGenuine", sizeof(v)) == 0) 179*1c4ee7dfSMark Johnston return (false); 180*1c4ee7dfSMark Johnston fprintf(stderr, "Unknown cpu vendor \"%s\"\n", (const char *)v); 181*1c4ee7dfSMark Johnston exit(1); 182*1c4ee7dfSMark Johnston } 183*1c4ee7dfSMark Johnston 184*1c4ee7dfSMark Johnston void 185*1c4ee7dfSMark Johnston bhyvectl_dump_vm_run_exitcode(struct vm_exit *vmexit, int vcpu) 186*1c4ee7dfSMark Johnston { 187*1c4ee7dfSMark Johnston printf("vm exit[%d]\n", vcpu); 188*1c4ee7dfSMark Johnston printf("\trip\t\t0x%016lx\n", vmexit->rip); 189*1c4ee7dfSMark Johnston printf("\tinst_length\t%d\n", vmexit->inst_length); 190*1c4ee7dfSMark Johnston switch (vmexit->exitcode) { 191*1c4ee7dfSMark Johnston case VM_EXITCODE_INOUT: 192*1c4ee7dfSMark Johnston printf("\treason\t\tINOUT\n"); 193*1c4ee7dfSMark Johnston printf("\tdirection\t%s\n", vmexit->u.inout.in ? "IN" : "OUT"); 194*1c4ee7dfSMark Johnston printf("\tbytes\t\t%d\n", vmexit->u.inout.bytes); 195*1c4ee7dfSMark Johnston printf("\tflags\t\t%s%s\n", 196*1c4ee7dfSMark Johnston vmexit->u.inout.string ? "STRING " : "", 197*1c4ee7dfSMark Johnston vmexit->u.inout.rep ? "REP " : ""); 198*1c4ee7dfSMark Johnston printf("\tport\t\t0x%04x\n", vmexit->u.inout.port); 199*1c4ee7dfSMark Johnston printf("\teax\t\t0x%08x\n", vmexit->u.inout.eax); 200*1c4ee7dfSMark Johnston break; 201*1c4ee7dfSMark Johnston case VM_EXITCODE_VMX: 202*1c4ee7dfSMark Johnston printf("\treason\t\tVMX\n"); 203*1c4ee7dfSMark Johnston printf("\tstatus\t\t%d\n", vmexit->u.vmx.status); 204*1c4ee7dfSMark Johnston printf("\texit_reason\t0x%08x (%u)\n", 205*1c4ee7dfSMark Johnston vmexit->u.vmx.exit_reason, vmexit->u.vmx.exit_reason); 206*1c4ee7dfSMark Johnston printf("\tqualification\t0x%016lx\n", 207*1c4ee7dfSMark Johnston vmexit->u.vmx.exit_qualification); 208*1c4ee7dfSMark Johnston printf("\tinst_type\t\t%d\n", vmexit->u.vmx.inst_type); 209*1c4ee7dfSMark Johnston printf("\tinst_error\t\t%d\n", vmexit->u.vmx.inst_error); 210*1c4ee7dfSMark Johnston break; 211*1c4ee7dfSMark Johnston case VM_EXITCODE_SVM: 212*1c4ee7dfSMark Johnston printf("\treason\t\tSVM\n"); 213*1c4ee7dfSMark Johnston printf("\texit_reason\t\t%#lx\n", vmexit->u.svm.exitcode); 214*1c4ee7dfSMark Johnston printf("\texitinfo1\t\t%#lx\n", vmexit->u.svm.exitinfo1); 215*1c4ee7dfSMark Johnston printf("\texitinfo2\t\t%#lx\n", vmexit->u.svm.exitinfo2); 216*1c4ee7dfSMark Johnston break; 217*1c4ee7dfSMark Johnston default: 218*1c4ee7dfSMark Johnston printf("*** unknown vm run exitcode %d\n", vmexit->exitcode); 219*1c4ee7dfSMark Johnston break; 220*1c4ee7dfSMark Johnston } 221*1c4ee7dfSMark Johnston } 222*1c4ee7dfSMark Johnston 223*1c4ee7dfSMark Johnston static const char * 224*1c4ee7dfSMark Johnston wday_str(int idx) 225*1c4ee7dfSMark Johnston { 226*1c4ee7dfSMark Johnston static const char *weekdays[] = { 227*1c4ee7dfSMark Johnston "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" 228*1c4ee7dfSMark Johnston }; 229*1c4ee7dfSMark Johnston 230*1c4ee7dfSMark Johnston if (idx >= 0 && idx < 7) 231*1c4ee7dfSMark Johnston return (weekdays[idx]); 232*1c4ee7dfSMark Johnston else 233*1c4ee7dfSMark Johnston return ("UNK"); 234*1c4ee7dfSMark Johnston } 235*1c4ee7dfSMark Johnston 236*1c4ee7dfSMark Johnston static const char * 237*1c4ee7dfSMark Johnston mon_str(int idx) 238*1c4ee7dfSMark Johnston { 239*1c4ee7dfSMark Johnston static const char *months[] = { 240*1c4ee7dfSMark Johnston "Jan", "Feb", "Mar", "Apr", "May", "Jun", 241*1c4ee7dfSMark Johnston "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" 242*1c4ee7dfSMark Johnston }; 243*1c4ee7dfSMark Johnston 244*1c4ee7dfSMark Johnston if (idx >= 0 && idx < 12) 245*1c4ee7dfSMark Johnston return (months[idx]); 246*1c4ee7dfSMark Johnston else 247*1c4ee7dfSMark Johnston return ("UNK"); 248*1c4ee7dfSMark Johnston } 249*1c4ee7dfSMark Johnston 250*1c4ee7dfSMark Johnston static void 251*1c4ee7dfSMark Johnston print_intinfo(const char *banner, uint64_t info) 252*1c4ee7dfSMark Johnston { 253*1c4ee7dfSMark Johnston int type; 254*1c4ee7dfSMark Johnston 255*1c4ee7dfSMark Johnston printf("%s:\t", banner); 256*1c4ee7dfSMark Johnston if (info & VM_INTINFO_VALID) { 257*1c4ee7dfSMark Johnston type = info & VM_INTINFO_TYPE; 258*1c4ee7dfSMark Johnston switch (type) { 259*1c4ee7dfSMark Johnston case VM_INTINFO_HWINTR: 260*1c4ee7dfSMark Johnston printf("extint"); 261*1c4ee7dfSMark Johnston break; 262*1c4ee7dfSMark Johnston case VM_INTINFO_NMI: 263*1c4ee7dfSMark Johnston printf("nmi"); 264*1c4ee7dfSMark Johnston break; 265*1c4ee7dfSMark Johnston case VM_INTINFO_SWINTR: 266*1c4ee7dfSMark Johnston printf("swint"); 267*1c4ee7dfSMark Johnston break; 268*1c4ee7dfSMark Johnston default: 269*1c4ee7dfSMark Johnston printf("exception"); 270*1c4ee7dfSMark Johnston break; 271*1c4ee7dfSMark Johnston } 272*1c4ee7dfSMark Johnston printf(" vector %d", (int)VM_INTINFO_VECTOR(info)); 273*1c4ee7dfSMark Johnston if (info & VM_INTINFO_DEL_ERRCODE) 274*1c4ee7dfSMark Johnston printf(" errcode %#x", (u_int)(info >> 32)); 275*1c4ee7dfSMark Johnston } else { 276*1c4ee7dfSMark Johnston printf("n/a"); 277*1c4ee7dfSMark Johnston } 278*1c4ee7dfSMark Johnston printf("\n"); 279*1c4ee7dfSMark Johnston } 280*1c4ee7dfSMark Johnston 281*1c4ee7dfSMark Johnston /* AMD 6th generation and Intel compatible MSRs */ 282*1c4ee7dfSMark Johnston #define MSR_AMD6TH_START 0xC0000000 283*1c4ee7dfSMark Johnston #define MSR_AMD6TH_END 0xC0001FFF 284*1c4ee7dfSMark Johnston /* AMD 7th and 8th generation compatible MSRs */ 285*1c4ee7dfSMark Johnston #define MSR_AMD7TH_START 0xC0010000 286*1c4ee7dfSMark Johnston #define MSR_AMD7TH_END 0xC0011FFF 287*1c4ee7dfSMark Johnston 288*1c4ee7dfSMark Johnston static const char * 289*1c4ee7dfSMark Johnston msr_name(uint32_t msr) 290*1c4ee7dfSMark Johnston { 291*1c4ee7dfSMark Johnston static char buf[32]; 292*1c4ee7dfSMark Johnston 293*1c4ee7dfSMark Johnston switch (msr) { 294*1c4ee7dfSMark Johnston case MSR_TSC: 295*1c4ee7dfSMark Johnston return ("MSR_TSC"); 296*1c4ee7dfSMark Johnston case MSR_EFER: 297*1c4ee7dfSMark Johnston return ("MSR_EFER"); 298*1c4ee7dfSMark Johnston case MSR_STAR: 299*1c4ee7dfSMark Johnston return ("MSR_STAR"); 300*1c4ee7dfSMark Johnston case MSR_LSTAR: 301*1c4ee7dfSMark Johnston return ("MSR_LSTAR"); 302*1c4ee7dfSMark Johnston case MSR_CSTAR: 303*1c4ee7dfSMark Johnston return ("MSR_CSTAR"); 304*1c4ee7dfSMark Johnston case MSR_SF_MASK: 305*1c4ee7dfSMark Johnston return ("MSR_SF_MASK"); 306*1c4ee7dfSMark Johnston case MSR_FSBASE: 307*1c4ee7dfSMark Johnston return ("MSR_FSBASE"); 308*1c4ee7dfSMark Johnston case MSR_GSBASE: 309*1c4ee7dfSMark Johnston return ("MSR_GSBASE"); 310*1c4ee7dfSMark Johnston case MSR_KGSBASE: 311*1c4ee7dfSMark Johnston return ("MSR_KGSBASE"); 312*1c4ee7dfSMark Johnston case MSR_SYSENTER_CS_MSR: 313*1c4ee7dfSMark Johnston return ("MSR_SYSENTER_CS_MSR"); 314*1c4ee7dfSMark Johnston case MSR_SYSENTER_ESP_MSR: 315*1c4ee7dfSMark Johnston return ("MSR_SYSENTER_ESP_MSR"); 316*1c4ee7dfSMark Johnston case MSR_SYSENTER_EIP_MSR: 317*1c4ee7dfSMark Johnston return ("MSR_SYSENTER_EIP_MSR"); 318*1c4ee7dfSMark Johnston case MSR_PAT: 319*1c4ee7dfSMark Johnston return ("MSR_PAT"); 320*1c4ee7dfSMark Johnston } 321*1c4ee7dfSMark Johnston snprintf(buf, sizeof(buf), "MSR %#08x", msr); 322*1c4ee7dfSMark Johnston 323*1c4ee7dfSMark Johnston return (buf); 324*1c4ee7dfSMark Johnston } 325*1c4ee7dfSMark Johnston 326*1c4ee7dfSMark Johnston static inline void 327*1c4ee7dfSMark Johnston print_msr_pm(uint64_t msr, int vcpu, int readable, int writeable) 328*1c4ee7dfSMark Johnston { 329*1c4ee7dfSMark Johnston 330*1c4ee7dfSMark Johnston if (readable || writeable) { 331*1c4ee7dfSMark Johnston printf("%-20s[%d]\t\t%c%c\n", msr_name(msr), vcpu, 332*1c4ee7dfSMark Johnston readable ? 'R' : '-', writeable ? 'W' : '-'); 333*1c4ee7dfSMark Johnston } 334*1c4ee7dfSMark Johnston } 335*1c4ee7dfSMark Johnston 336*1c4ee7dfSMark Johnston /* 337*1c4ee7dfSMark Johnston * Reference APM vol2, section 15.11 MSR Intercepts. 338*1c4ee7dfSMark Johnston */ 339*1c4ee7dfSMark Johnston static void 340*1c4ee7dfSMark Johnston dump_amd_msr_pm(const char *bitmap, int vcpu) 341*1c4ee7dfSMark Johnston { 342*1c4ee7dfSMark Johnston int byte, bit, readable, writeable; 343*1c4ee7dfSMark Johnston uint32_t msr; 344*1c4ee7dfSMark Johnston 345*1c4ee7dfSMark Johnston for (msr = 0; msr < 0x2000; msr++) { 346*1c4ee7dfSMark Johnston byte = msr / 4; 347*1c4ee7dfSMark Johnston bit = (msr % 4) * 2; 348*1c4ee7dfSMark Johnston 349*1c4ee7dfSMark Johnston /* Look at MSRs in the range 0x00000000 to 0x00001FFF */ 350*1c4ee7dfSMark Johnston readable = (bitmap[byte] & (1 << bit)) ? 0 : 1; 351*1c4ee7dfSMark Johnston writeable = (bitmap[byte] & (2 << bit)) ? 0 : 1; 352*1c4ee7dfSMark Johnston print_msr_pm(msr, vcpu, readable, writeable); 353*1c4ee7dfSMark Johnston 354*1c4ee7dfSMark Johnston /* Look at MSRs in the range 0xC0000000 to 0xC0001FFF */ 355*1c4ee7dfSMark Johnston byte += 2048; 356*1c4ee7dfSMark Johnston readable = (bitmap[byte] & (1 << bit)) ? 0 : 1; 357*1c4ee7dfSMark Johnston writeable = (bitmap[byte] & (2 << bit)) ? 0 : 1; 358*1c4ee7dfSMark Johnston print_msr_pm(msr + MSR_AMD6TH_START, vcpu, readable, 359*1c4ee7dfSMark Johnston writeable); 360*1c4ee7dfSMark Johnston 361*1c4ee7dfSMark Johnston /* MSR 0xC0010000 to 0xC0011FF is only for AMD */ 362*1c4ee7dfSMark Johnston byte += 4096; 363*1c4ee7dfSMark Johnston readable = (bitmap[byte] & (1 << bit)) ? 0 : 1; 364*1c4ee7dfSMark Johnston writeable = (bitmap[byte] & (2 << bit)) ? 0 : 1; 365*1c4ee7dfSMark Johnston print_msr_pm(msr + MSR_AMD7TH_START, vcpu, readable, 366*1c4ee7dfSMark Johnston writeable); 367*1c4ee7dfSMark Johnston } 368*1c4ee7dfSMark Johnston } 369*1c4ee7dfSMark Johnston 370*1c4ee7dfSMark Johnston /* 371*1c4ee7dfSMark Johnston * Reference Intel SDM Vol3 Section 24.6.9 MSR-Bitmap Address 372*1c4ee7dfSMark Johnston */ 373*1c4ee7dfSMark Johnston static void 374*1c4ee7dfSMark Johnston dump_intel_msr_pm(const char *bitmap, int vcpu) 375*1c4ee7dfSMark Johnston { 376*1c4ee7dfSMark Johnston int byte, bit, readable, writeable; 377*1c4ee7dfSMark Johnston uint32_t msr; 378*1c4ee7dfSMark Johnston 379*1c4ee7dfSMark Johnston for (msr = 0; msr < 0x2000; msr++) { 380*1c4ee7dfSMark Johnston byte = msr / 8; 381*1c4ee7dfSMark Johnston bit = msr & 0x7; 382*1c4ee7dfSMark Johnston 383*1c4ee7dfSMark Johnston /* Look at MSRs in the range 0x00000000 to 0x00001FFF */ 384*1c4ee7dfSMark Johnston readable = (bitmap[byte] & (1 << bit)) ? 0 : 1; 385*1c4ee7dfSMark Johnston writeable = (bitmap[2048 + byte] & (1 << bit)) ? 0 : 1; 386*1c4ee7dfSMark Johnston print_msr_pm(msr, vcpu, readable, writeable); 387*1c4ee7dfSMark Johnston 388*1c4ee7dfSMark Johnston /* Look at MSRs in the range 0xC0000000 to 0xC0001FFF */ 389*1c4ee7dfSMark Johnston byte += 1024; 390*1c4ee7dfSMark Johnston readable = (bitmap[byte] & (1 << bit)) ? 0 : 1; 391*1c4ee7dfSMark Johnston writeable = (bitmap[2048 + byte] & (1 << bit)) ? 0 : 1; 392*1c4ee7dfSMark Johnston print_msr_pm(msr + MSR_AMD6TH_START, vcpu, readable, 393*1c4ee7dfSMark Johnston writeable); 394*1c4ee7dfSMark Johnston } 395*1c4ee7dfSMark Johnston } 396*1c4ee7dfSMark Johnston 397*1c4ee7dfSMark Johnston static int 398*1c4ee7dfSMark Johnston dump_msr_bitmap(int vcpu, uint64_t addr, bool cpu_intel) 399*1c4ee7dfSMark Johnston { 400*1c4ee7dfSMark Johnston char *bitmap; 401*1c4ee7dfSMark Johnston int error, fd, map_size; 402*1c4ee7dfSMark Johnston 403*1c4ee7dfSMark Johnston error = -1; 404*1c4ee7dfSMark Johnston bitmap = MAP_FAILED; 405*1c4ee7dfSMark Johnston 406*1c4ee7dfSMark Johnston fd = open("/dev/mem", O_RDONLY, 0); 407*1c4ee7dfSMark Johnston if (fd < 0) { 408*1c4ee7dfSMark Johnston perror("Couldn't open /dev/mem"); 409*1c4ee7dfSMark Johnston goto done; 410*1c4ee7dfSMark Johnston } 411*1c4ee7dfSMark Johnston 412*1c4ee7dfSMark Johnston if (cpu_intel) 413*1c4ee7dfSMark Johnston map_size = PAGE_SIZE; 414*1c4ee7dfSMark Johnston else 415*1c4ee7dfSMark Johnston map_size = 2 * PAGE_SIZE; 416*1c4ee7dfSMark Johnston 417*1c4ee7dfSMark Johnston bitmap = mmap(NULL, map_size, PROT_READ, MAP_SHARED, fd, addr); 418*1c4ee7dfSMark Johnston if (bitmap == MAP_FAILED) { 419*1c4ee7dfSMark Johnston perror("mmap failed"); 420*1c4ee7dfSMark Johnston goto done; 421*1c4ee7dfSMark Johnston } 422*1c4ee7dfSMark Johnston 423*1c4ee7dfSMark Johnston if (cpu_intel) 424*1c4ee7dfSMark Johnston dump_intel_msr_pm(bitmap, vcpu); 425*1c4ee7dfSMark Johnston else 426*1c4ee7dfSMark Johnston dump_amd_msr_pm(bitmap, vcpu); 427*1c4ee7dfSMark Johnston 428*1c4ee7dfSMark Johnston error = 0; 429*1c4ee7dfSMark Johnston done: 430*1c4ee7dfSMark Johnston if (bitmap != MAP_FAILED) 431*1c4ee7dfSMark Johnston munmap((void *)bitmap, map_size); 432*1c4ee7dfSMark Johnston if (fd >= 0) 433*1c4ee7dfSMark Johnston close(fd); 434*1c4ee7dfSMark Johnston 435*1c4ee7dfSMark Johnston return (error); 436*1c4ee7dfSMark Johnston } 437*1c4ee7dfSMark Johnston 438*1c4ee7dfSMark Johnston static int 439*1c4ee7dfSMark Johnston vm_get_vmcs_field(struct vcpu *vcpu, int field, uint64_t *ret_val) 440*1c4ee7dfSMark Johnston { 441*1c4ee7dfSMark Johnston 442*1c4ee7dfSMark Johnston return (vm_get_register(vcpu, VMCS_IDENT(field), ret_val)); 443*1c4ee7dfSMark Johnston } 444*1c4ee7dfSMark Johnston 445*1c4ee7dfSMark Johnston static int 446*1c4ee7dfSMark Johnston vm_get_vmcb_field(struct vcpu *vcpu, int off, int bytes, 447*1c4ee7dfSMark Johnston uint64_t *ret_val) 448*1c4ee7dfSMark Johnston { 449*1c4ee7dfSMark Johnston 450*1c4ee7dfSMark Johnston return (vm_get_register(vcpu, VMCB_ACCESS(off, bytes), ret_val)); 451*1c4ee7dfSMark Johnston } 452*1c4ee7dfSMark Johnston 453*1c4ee7dfSMark Johnston static int 454*1c4ee7dfSMark Johnston get_all_registers(struct vcpu *vcpu, int vcpuid, bool get_all) 455*1c4ee7dfSMark Johnston { 456*1c4ee7dfSMark Johnston uint64_t cr0, cr2, cr3, cr4, dr0, dr1, dr2, dr3, dr6, dr7; 457*1c4ee7dfSMark Johnston uint64_t rsp, rip, rflags, efer; 458*1c4ee7dfSMark Johnston uint64_t rax, rbx, rcx, rdx, rsi, rdi, rbp; 459*1c4ee7dfSMark Johnston uint64_t r8, r9, r10, r11, r12, r13, r14, r15; 460*1c4ee7dfSMark Johnston int error = 0; 461*1c4ee7dfSMark Johnston 462*1c4ee7dfSMark Johnston if (!error && (get_efer || get_all)) { 463*1c4ee7dfSMark Johnston error = vm_get_register(vcpu, VM_REG_GUEST_EFER, &efer); 464*1c4ee7dfSMark Johnston if (error == 0) 465*1c4ee7dfSMark Johnston printf("efer[%d]\t\t0x%016lx\n", vcpuid, efer); 466*1c4ee7dfSMark Johnston } 467*1c4ee7dfSMark Johnston 468*1c4ee7dfSMark Johnston if (!error && (get_cr0 || get_all)) { 469*1c4ee7dfSMark Johnston error = vm_get_register(vcpu, VM_REG_GUEST_CR0, &cr0); 470*1c4ee7dfSMark Johnston if (error == 0) 471*1c4ee7dfSMark Johnston printf("cr0[%d]\t\t0x%016lx\n", vcpuid, cr0); 472*1c4ee7dfSMark Johnston } 473*1c4ee7dfSMark Johnston 474*1c4ee7dfSMark Johnston if (!error && (get_cr2 || get_all)) { 475*1c4ee7dfSMark Johnston error = vm_get_register(vcpu, VM_REG_GUEST_CR2, &cr2); 476*1c4ee7dfSMark Johnston if (error == 0) 477*1c4ee7dfSMark Johnston printf("cr2[%d]\t\t0x%016lx\n", vcpuid, cr2); 478*1c4ee7dfSMark Johnston } 479*1c4ee7dfSMark Johnston 480*1c4ee7dfSMark Johnston if (!error && (get_cr3 || get_all)) { 481*1c4ee7dfSMark Johnston error = vm_get_register(vcpu, VM_REG_GUEST_CR3, &cr3); 482*1c4ee7dfSMark Johnston if (error == 0) 483*1c4ee7dfSMark Johnston printf("cr3[%d]\t\t0x%016lx\n", vcpuid, cr3); 484*1c4ee7dfSMark Johnston } 485*1c4ee7dfSMark Johnston 486*1c4ee7dfSMark Johnston if (!error && (get_cr4 || get_all)) { 487*1c4ee7dfSMark Johnston error = vm_get_register(vcpu, VM_REG_GUEST_CR4, &cr4); 488*1c4ee7dfSMark Johnston if (error == 0) 489*1c4ee7dfSMark Johnston printf("cr4[%d]\t\t0x%016lx\n", vcpuid, cr4); 490*1c4ee7dfSMark Johnston } 491*1c4ee7dfSMark Johnston 492*1c4ee7dfSMark Johnston if (!error && (get_dr0 || get_all)) { 493*1c4ee7dfSMark Johnston error = vm_get_register(vcpu, VM_REG_GUEST_DR0, &dr0); 494*1c4ee7dfSMark Johnston if (error == 0) 495*1c4ee7dfSMark Johnston printf("dr0[%d]\t\t0x%016lx\n", vcpuid, dr0); 496*1c4ee7dfSMark Johnston } 497*1c4ee7dfSMark Johnston 498*1c4ee7dfSMark Johnston if (!error && (get_dr1 || get_all)) { 499*1c4ee7dfSMark Johnston error = vm_get_register(vcpu, VM_REG_GUEST_DR1, &dr1); 500*1c4ee7dfSMark Johnston if (error == 0) 501*1c4ee7dfSMark Johnston printf("dr1[%d]\t\t0x%016lx\n", vcpuid, dr1); 502*1c4ee7dfSMark Johnston } 503*1c4ee7dfSMark Johnston 504*1c4ee7dfSMark Johnston if (!error && (get_dr2 || get_all)) { 505*1c4ee7dfSMark Johnston error = vm_get_register(vcpu, VM_REG_GUEST_DR2, &dr2); 506*1c4ee7dfSMark Johnston if (error == 0) 507*1c4ee7dfSMark Johnston printf("dr2[%d]\t\t0x%016lx\n", vcpuid, dr2); 508*1c4ee7dfSMark Johnston } 509*1c4ee7dfSMark Johnston 510*1c4ee7dfSMark Johnston if (!error && (get_dr3 || get_all)) { 511*1c4ee7dfSMark Johnston error = vm_get_register(vcpu, VM_REG_GUEST_DR3, &dr3); 512*1c4ee7dfSMark Johnston if (error == 0) 513*1c4ee7dfSMark Johnston printf("dr3[%d]\t\t0x%016lx\n", vcpuid, dr3); 514*1c4ee7dfSMark Johnston } 515*1c4ee7dfSMark Johnston 516*1c4ee7dfSMark Johnston if (!error && (get_dr6 || get_all)) { 517*1c4ee7dfSMark Johnston error = vm_get_register(vcpu, VM_REG_GUEST_DR6, &dr6); 518*1c4ee7dfSMark Johnston if (error == 0) 519*1c4ee7dfSMark Johnston printf("dr6[%d]\t\t0x%016lx\n", vcpuid, dr6); 520*1c4ee7dfSMark Johnston } 521*1c4ee7dfSMark Johnston 522*1c4ee7dfSMark Johnston if (!error && (get_dr7 || get_all)) { 523*1c4ee7dfSMark Johnston error = vm_get_register(vcpu, VM_REG_GUEST_DR7, &dr7); 524*1c4ee7dfSMark Johnston if (error == 0) 525*1c4ee7dfSMark Johnston printf("dr7[%d]\t\t0x%016lx\n", vcpuid, dr7); 526*1c4ee7dfSMark Johnston } 527*1c4ee7dfSMark Johnston 528*1c4ee7dfSMark Johnston if (!error && (get_rsp || get_all)) { 529*1c4ee7dfSMark Johnston error = vm_get_register(vcpu, VM_REG_GUEST_RSP, &rsp); 530*1c4ee7dfSMark Johnston if (error == 0) 531*1c4ee7dfSMark Johnston printf("rsp[%d]\t\t0x%016lx\n", vcpuid, rsp); 532*1c4ee7dfSMark Johnston } 533*1c4ee7dfSMark Johnston 534*1c4ee7dfSMark Johnston if (!error && (get_rip || get_all)) { 535*1c4ee7dfSMark Johnston error = vm_get_register(vcpu, VM_REG_GUEST_RIP, &rip); 536*1c4ee7dfSMark Johnston if (error == 0) 537*1c4ee7dfSMark Johnston printf("rip[%d]\t\t0x%016lx\n", vcpuid, rip); 538*1c4ee7dfSMark Johnston } 539*1c4ee7dfSMark Johnston 540*1c4ee7dfSMark Johnston if (!error && (get_rax || get_all)) { 541*1c4ee7dfSMark Johnston error = vm_get_register(vcpu, VM_REG_GUEST_RAX, &rax); 542*1c4ee7dfSMark Johnston if (error == 0) 543*1c4ee7dfSMark Johnston printf("rax[%d]\t\t0x%016lx\n", vcpuid, rax); 544*1c4ee7dfSMark Johnston } 545*1c4ee7dfSMark Johnston 546*1c4ee7dfSMark Johnston if (!error && (get_rbx || get_all)) { 547*1c4ee7dfSMark Johnston error = vm_get_register(vcpu, VM_REG_GUEST_RBX, &rbx); 548*1c4ee7dfSMark Johnston if (error == 0) 549*1c4ee7dfSMark Johnston printf("rbx[%d]\t\t0x%016lx\n", vcpuid, rbx); 550*1c4ee7dfSMark Johnston } 551*1c4ee7dfSMark Johnston 552*1c4ee7dfSMark Johnston if (!error && (get_rcx || get_all)) { 553*1c4ee7dfSMark Johnston error = vm_get_register(vcpu, VM_REG_GUEST_RCX, &rcx); 554*1c4ee7dfSMark Johnston if (error == 0) 555*1c4ee7dfSMark Johnston printf("rcx[%d]\t\t0x%016lx\n", vcpuid, rcx); 556*1c4ee7dfSMark Johnston } 557*1c4ee7dfSMark Johnston 558*1c4ee7dfSMark Johnston if (!error && (get_rdx || get_all)) { 559*1c4ee7dfSMark Johnston error = vm_get_register(vcpu, VM_REG_GUEST_RDX, &rdx); 560*1c4ee7dfSMark Johnston if (error == 0) 561*1c4ee7dfSMark Johnston printf("rdx[%d]\t\t0x%016lx\n", vcpuid, rdx); 562*1c4ee7dfSMark Johnston } 563*1c4ee7dfSMark Johnston 564*1c4ee7dfSMark Johnston if (!error && (get_rsi || get_all)) { 565*1c4ee7dfSMark Johnston error = vm_get_register(vcpu, VM_REG_GUEST_RSI, &rsi); 566*1c4ee7dfSMark Johnston if (error == 0) 567*1c4ee7dfSMark Johnston printf("rsi[%d]\t\t0x%016lx\n", vcpuid, rsi); 568*1c4ee7dfSMark Johnston } 569*1c4ee7dfSMark Johnston 570*1c4ee7dfSMark Johnston if (!error && (get_rdi || get_all)) { 571*1c4ee7dfSMark Johnston error = vm_get_register(vcpu, VM_REG_GUEST_RDI, &rdi); 572*1c4ee7dfSMark Johnston if (error == 0) 573*1c4ee7dfSMark Johnston printf("rdi[%d]\t\t0x%016lx\n", vcpuid, rdi); 574*1c4ee7dfSMark Johnston } 575*1c4ee7dfSMark Johnston 576*1c4ee7dfSMark Johnston if (!error && (get_rbp || get_all)) { 577*1c4ee7dfSMark Johnston error = vm_get_register(vcpu, VM_REG_GUEST_RBP, &rbp); 578*1c4ee7dfSMark Johnston if (error == 0) 579*1c4ee7dfSMark Johnston printf("rbp[%d]\t\t0x%016lx\n", vcpuid, rbp); 580*1c4ee7dfSMark Johnston } 581*1c4ee7dfSMark Johnston 582*1c4ee7dfSMark Johnston if (!error && (get_r8 || get_all)) { 583*1c4ee7dfSMark Johnston error = vm_get_register(vcpu, VM_REG_GUEST_R8, &r8); 584*1c4ee7dfSMark Johnston if (error == 0) 585*1c4ee7dfSMark Johnston printf("r8[%d]\t\t0x%016lx\n", vcpuid, r8); 586*1c4ee7dfSMark Johnston } 587*1c4ee7dfSMark Johnston 588*1c4ee7dfSMark Johnston if (!error && (get_r9 || get_all)) { 589*1c4ee7dfSMark Johnston error = vm_get_register(vcpu, VM_REG_GUEST_R9, &r9); 590*1c4ee7dfSMark Johnston if (error == 0) 591*1c4ee7dfSMark Johnston printf("r9[%d]\t\t0x%016lx\n", vcpuid, r9); 592*1c4ee7dfSMark Johnston } 593*1c4ee7dfSMark Johnston 594*1c4ee7dfSMark Johnston if (!error && (get_r10 || get_all)) { 595*1c4ee7dfSMark Johnston error = vm_get_register(vcpu, VM_REG_GUEST_R10, &r10); 596*1c4ee7dfSMark Johnston if (error == 0) 597*1c4ee7dfSMark Johnston printf("r10[%d]\t\t0x%016lx\n", vcpuid, r10); 598*1c4ee7dfSMark Johnston } 599*1c4ee7dfSMark Johnston 600*1c4ee7dfSMark Johnston if (!error && (get_r11 || get_all)) { 601*1c4ee7dfSMark Johnston error = vm_get_register(vcpu, VM_REG_GUEST_R11, &r11); 602*1c4ee7dfSMark Johnston if (error == 0) 603*1c4ee7dfSMark Johnston printf("r11[%d]\t\t0x%016lx\n", vcpuid, r11); 604*1c4ee7dfSMark Johnston } 605*1c4ee7dfSMark Johnston 606*1c4ee7dfSMark Johnston if (!error && (get_r12 || get_all)) { 607*1c4ee7dfSMark Johnston error = vm_get_register(vcpu, VM_REG_GUEST_R12, &r12); 608*1c4ee7dfSMark Johnston if (error == 0) 609*1c4ee7dfSMark Johnston printf("r12[%d]\t\t0x%016lx\n", vcpuid, r12); 610*1c4ee7dfSMark Johnston } 611*1c4ee7dfSMark Johnston 612*1c4ee7dfSMark Johnston if (!error && (get_r13 || get_all)) { 613*1c4ee7dfSMark Johnston error = vm_get_register(vcpu, VM_REG_GUEST_R13, &r13); 614*1c4ee7dfSMark Johnston if (error == 0) 615*1c4ee7dfSMark Johnston printf("r13[%d]\t\t0x%016lx\n", vcpuid, r13); 616*1c4ee7dfSMark Johnston } 617*1c4ee7dfSMark Johnston 618*1c4ee7dfSMark Johnston if (!error && (get_r14 || get_all)) { 619*1c4ee7dfSMark Johnston error = vm_get_register(vcpu, VM_REG_GUEST_R14, &r14); 620*1c4ee7dfSMark Johnston if (error == 0) 621*1c4ee7dfSMark Johnston printf("r14[%d]\t\t0x%016lx\n", vcpuid, r14); 622*1c4ee7dfSMark Johnston } 623*1c4ee7dfSMark Johnston 624*1c4ee7dfSMark Johnston if (!error && (get_r15 || get_all)) { 625*1c4ee7dfSMark Johnston error = vm_get_register(vcpu, VM_REG_GUEST_R15, &r15); 626*1c4ee7dfSMark Johnston if (error == 0) 627*1c4ee7dfSMark Johnston printf("r15[%d]\t\t0x%016lx\n", vcpuid, r15); 628*1c4ee7dfSMark Johnston } 629*1c4ee7dfSMark Johnston 630*1c4ee7dfSMark Johnston if (!error && (get_rflags || get_all)) { 631*1c4ee7dfSMark Johnston error = vm_get_register(vcpu, VM_REG_GUEST_RFLAGS, 632*1c4ee7dfSMark Johnston &rflags); 633*1c4ee7dfSMark Johnston if (error == 0) 634*1c4ee7dfSMark Johnston printf("rflags[%d]\t0x%016lx\n", vcpuid, rflags); 635*1c4ee7dfSMark Johnston } 636*1c4ee7dfSMark Johnston 637*1c4ee7dfSMark Johnston return (error); 638*1c4ee7dfSMark Johnston } 639*1c4ee7dfSMark Johnston 640*1c4ee7dfSMark Johnston static int 641*1c4ee7dfSMark Johnston get_all_segments(struct vcpu *vcpu, int vcpuid, bool get_all) 642*1c4ee7dfSMark Johnston { 643*1c4ee7dfSMark Johnston uint64_t cs, ds, es, fs, gs, ss, tr, ldtr; 644*1c4ee7dfSMark Johnston int error = 0; 645*1c4ee7dfSMark Johnston 646*1c4ee7dfSMark Johnston if (!error && (get_desc_ds || get_all)) { 647*1c4ee7dfSMark Johnston error = vm_get_desc(vcpu, VM_REG_GUEST_DS, 648*1c4ee7dfSMark Johnston &desc_base, &desc_limit, &desc_access); 649*1c4ee7dfSMark Johnston if (error == 0) { 650*1c4ee7dfSMark Johnston printf("ds desc[%d]\t0x%016lx/0x%08x/0x%08x\n", 651*1c4ee7dfSMark Johnston vcpuid, desc_base, desc_limit, desc_access); 652*1c4ee7dfSMark Johnston } 653*1c4ee7dfSMark Johnston } 654*1c4ee7dfSMark Johnston 655*1c4ee7dfSMark Johnston if (!error && (get_desc_es || get_all)) { 656*1c4ee7dfSMark Johnston error = vm_get_desc(vcpu, VM_REG_GUEST_ES, 657*1c4ee7dfSMark Johnston &desc_base, &desc_limit, &desc_access); 658*1c4ee7dfSMark Johnston if (error == 0) { 659*1c4ee7dfSMark Johnston printf("es desc[%d]\t0x%016lx/0x%08x/0x%08x\n", 660*1c4ee7dfSMark Johnston vcpuid, desc_base, desc_limit, desc_access); 661*1c4ee7dfSMark Johnston } 662*1c4ee7dfSMark Johnston } 663*1c4ee7dfSMark Johnston 664*1c4ee7dfSMark Johnston if (!error && (get_desc_fs || get_all)) { 665*1c4ee7dfSMark Johnston error = vm_get_desc(vcpu, VM_REG_GUEST_FS, 666*1c4ee7dfSMark Johnston &desc_base, &desc_limit, &desc_access); 667*1c4ee7dfSMark Johnston if (error == 0) { 668*1c4ee7dfSMark Johnston printf("fs desc[%d]\t0x%016lx/0x%08x/0x%08x\n", 669*1c4ee7dfSMark Johnston vcpuid, desc_base, desc_limit, desc_access); 670*1c4ee7dfSMark Johnston } 671*1c4ee7dfSMark Johnston } 672*1c4ee7dfSMark Johnston 673*1c4ee7dfSMark Johnston if (!error && (get_desc_gs || get_all)) { 674*1c4ee7dfSMark Johnston error = vm_get_desc(vcpu, VM_REG_GUEST_GS, 675*1c4ee7dfSMark Johnston &desc_base, &desc_limit, &desc_access); 676*1c4ee7dfSMark Johnston if (error == 0) { 677*1c4ee7dfSMark Johnston printf("gs desc[%d]\t0x%016lx/0x%08x/0x%08x\n", 678*1c4ee7dfSMark Johnston vcpuid, desc_base, desc_limit, desc_access); 679*1c4ee7dfSMark Johnston } 680*1c4ee7dfSMark Johnston } 681*1c4ee7dfSMark Johnston 682*1c4ee7dfSMark Johnston if (!error && (get_desc_ss || get_all)) { 683*1c4ee7dfSMark Johnston error = vm_get_desc(vcpu, VM_REG_GUEST_SS, 684*1c4ee7dfSMark Johnston &desc_base, &desc_limit, &desc_access); 685*1c4ee7dfSMark Johnston if (error == 0) { 686*1c4ee7dfSMark Johnston printf("ss desc[%d]\t0x%016lx/0x%08x/0x%08x\n", 687*1c4ee7dfSMark Johnston vcpuid, desc_base, desc_limit, desc_access); 688*1c4ee7dfSMark Johnston } 689*1c4ee7dfSMark Johnston } 690*1c4ee7dfSMark Johnston 691*1c4ee7dfSMark Johnston if (!error && (get_desc_cs || get_all)) { 692*1c4ee7dfSMark Johnston error = vm_get_desc(vcpu, VM_REG_GUEST_CS, 693*1c4ee7dfSMark Johnston &desc_base, &desc_limit, &desc_access); 694*1c4ee7dfSMark Johnston if (error == 0) { 695*1c4ee7dfSMark Johnston printf("cs desc[%d]\t0x%016lx/0x%08x/0x%08x\n", 696*1c4ee7dfSMark Johnston vcpuid, desc_base, desc_limit, desc_access); 697*1c4ee7dfSMark Johnston } 698*1c4ee7dfSMark Johnston } 699*1c4ee7dfSMark Johnston 700*1c4ee7dfSMark Johnston if (!error && (get_desc_tr || get_all)) { 701*1c4ee7dfSMark Johnston error = vm_get_desc(vcpu, VM_REG_GUEST_TR, 702*1c4ee7dfSMark Johnston &desc_base, &desc_limit, &desc_access); 703*1c4ee7dfSMark Johnston if (error == 0) { 704*1c4ee7dfSMark Johnston printf("tr desc[%d]\t0x%016lx/0x%08x/0x%08x\n", 705*1c4ee7dfSMark Johnston vcpuid, desc_base, desc_limit, desc_access); 706*1c4ee7dfSMark Johnston } 707*1c4ee7dfSMark Johnston } 708*1c4ee7dfSMark Johnston 709*1c4ee7dfSMark Johnston if (!error && (get_desc_ldtr || get_all)) { 710*1c4ee7dfSMark Johnston error = vm_get_desc(vcpu, VM_REG_GUEST_LDTR, 711*1c4ee7dfSMark Johnston &desc_base, &desc_limit, &desc_access); 712*1c4ee7dfSMark Johnston if (error == 0) { 713*1c4ee7dfSMark Johnston printf("ldtr desc[%d]\t0x%016lx/0x%08x/0x%08x\n", 714*1c4ee7dfSMark Johnston vcpuid, desc_base, desc_limit, desc_access); 715*1c4ee7dfSMark Johnston } 716*1c4ee7dfSMark Johnston } 717*1c4ee7dfSMark Johnston 718*1c4ee7dfSMark Johnston if (!error && (get_desc_gdtr || get_all)) { 719*1c4ee7dfSMark Johnston error = vm_get_desc(vcpu, VM_REG_GUEST_GDTR, 720*1c4ee7dfSMark Johnston &desc_base, &desc_limit, &desc_access); 721*1c4ee7dfSMark Johnston if (error == 0) { 722*1c4ee7dfSMark Johnston printf("gdtr[%d]\t\t0x%016lx/0x%08x\n", 723*1c4ee7dfSMark Johnston vcpuid, desc_base, desc_limit); 724*1c4ee7dfSMark Johnston } 725*1c4ee7dfSMark Johnston } 726*1c4ee7dfSMark Johnston 727*1c4ee7dfSMark Johnston if (!error && (get_desc_idtr || get_all)) { 728*1c4ee7dfSMark Johnston error = vm_get_desc(vcpu, VM_REG_GUEST_IDTR, 729*1c4ee7dfSMark Johnston &desc_base, &desc_limit, &desc_access); 730*1c4ee7dfSMark Johnston if (error == 0) { 731*1c4ee7dfSMark Johnston printf("idtr[%d]\t\t0x%016lx/0x%08x\n", 732*1c4ee7dfSMark Johnston vcpuid, desc_base, desc_limit); 733*1c4ee7dfSMark Johnston } 734*1c4ee7dfSMark Johnston } 735*1c4ee7dfSMark Johnston 736*1c4ee7dfSMark Johnston if (!error && (get_cs || get_all)) { 737*1c4ee7dfSMark Johnston error = vm_get_register(vcpu, VM_REG_GUEST_CS, &cs); 738*1c4ee7dfSMark Johnston if (error == 0) 739*1c4ee7dfSMark Johnston printf("cs[%d]\t\t0x%04lx\n", vcpuid, cs); 740*1c4ee7dfSMark Johnston } 741*1c4ee7dfSMark Johnston 742*1c4ee7dfSMark Johnston if (!error && (get_ds || get_all)) { 743*1c4ee7dfSMark Johnston error = vm_get_register(vcpu, VM_REG_GUEST_DS, &ds); 744*1c4ee7dfSMark Johnston if (error == 0) 745*1c4ee7dfSMark Johnston printf("ds[%d]\t\t0x%04lx\n", vcpuid, ds); 746*1c4ee7dfSMark Johnston } 747*1c4ee7dfSMark Johnston 748*1c4ee7dfSMark Johnston if (!error && (get_es || get_all)) { 749*1c4ee7dfSMark Johnston error = vm_get_register(vcpu, VM_REG_GUEST_ES, &es); 750*1c4ee7dfSMark Johnston if (error == 0) 751*1c4ee7dfSMark Johnston printf("es[%d]\t\t0x%04lx\n", vcpuid, es); 752*1c4ee7dfSMark Johnston } 753*1c4ee7dfSMark Johnston 754*1c4ee7dfSMark Johnston if (!error && (get_fs || get_all)) { 755*1c4ee7dfSMark Johnston error = vm_get_register(vcpu, VM_REG_GUEST_FS, &fs); 756*1c4ee7dfSMark Johnston if (error == 0) 757*1c4ee7dfSMark Johnston printf("fs[%d]\t\t0x%04lx\n", vcpuid, fs); 758*1c4ee7dfSMark Johnston } 759*1c4ee7dfSMark Johnston 760*1c4ee7dfSMark Johnston if (!error && (get_gs || get_all)) { 761*1c4ee7dfSMark Johnston error = vm_get_register(vcpu, VM_REG_GUEST_GS, &gs); 762*1c4ee7dfSMark Johnston if (error == 0) 763*1c4ee7dfSMark Johnston printf("gs[%d]\t\t0x%04lx\n", vcpuid, gs); 764*1c4ee7dfSMark Johnston } 765*1c4ee7dfSMark Johnston 766*1c4ee7dfSMark Johnston if (!error && (get_ss || get_all)) { 767*1c4ee7dfSMark Johnston error = vm_get_register(vcpu, VM_REG_GUEST_SS, &ss); 768*1c4ee7dfSMark Johnston if (error == 0) 769*1c4ee7dfSMark Johnston printf("ss[%d]\t\t0x%04lx\n", vcpuid, ss); 770*1c4ee7dfSMark Johnston } 771*1c4ee7dfSMark Johnston 772*1c4ee7dfSMark Johnston if (!error && (get_tr || get_all)) { 773*1c4ee7dfSMark Johnston error = vm_get_register(vcpu, VM_REG_GUEST_TR, &tr); 774*1c4ee7dfSMark Johnston if (error == 0) 775*1c4ee7dfSMark Johnston printf("tr[%d]\t\t0x%04lx\n", vcpuid, tr); 776*1c4ee7dfSMark Johnston } 777*1c4ee7dfSMark Johnston 778*1c4ee7dfSMark Johnston if (!error && (get_ldtr || get_all)) { 779*1c4ee7dfSMark Johnston error = vm_get_register(vcpu, VM_REG_GUEST_LDTR, &ldtr); 780*1c4ee7dfSMark Johnston if (error == 0) 781*1c4ee7dfSMark Johnston printf("ldtr[%d]\t\t0x%04lx\n", vcpuid, ldtr); 782*1c4ee7dfSMark Johnston } 783*1c4ee7dfSMark Johnston 784*1c4ee7dfSMark Johnston return (error); 785*1c4ee7dfSMark Johnston } 786*1c4ee7dfSMark Johnston 787*1c4ee7dfSMark Johnston static int 788*1c4ee7dfSMark Johnston get_misc_vmcs(struct vcpu *vcpu, int vcpuid, bool get_all) 789*1c4ee7dfSMark Johnston { 790*1c4ee7dfSMark Johnston uint64_t ctl, cr0, cr3, cr4, rsp, rip, pat, addr, u64; 791*1c4ee7dfSMark Johnston int error = 0; 792*1c4ee7dfSMark Johnston 793*1c4ee7dfSMark Johnston if (!error && (get_cr0_mask || get_all)) { 794*1c4ee7dfSMark Johnston uint64_t cr0mask; 795*1c4ee7dfSMark Johnston error = vm_get_vmcs_field(vcpu, VMCS_CR0_MASK, &cr0mask); 796*1c4ee7dfSMark Johnston if (error == 0) 797*1c4ee7dfSMark Johnston printf("cr0_mask[%d]\t\t0x%016lx\n", vcpuid, cr0mask); 798*1c4ee7dfSMark Johnston } 799*1c4ee7dfSMark Johnston 800*1c4ee7dfSMark Johnston if (!error && (get_cr0_shadow || get_all)) { 801*1c4ee7dfSMark Johnston uint64_t cr0shadow; 802*1c4ee7dfSMark Johnston error = vm_get_vmcs_field(vcpu, VMCS_CR0_SHADOW, 803*1c4ee7dfSMark Johnston &cr0shadow); 804*1c4ee7dfSMark Johnston if (error == 0) 805*1c4ee7dfSMark Johnston printf("cr0_shadow[%d]\t\t0x%016lx\n", vcpuid, cr0shadow); 806*1c4ee7dfSMark Johnston } 807*1c4ee7dfSMark Johnston 808*1c4ee7dfSMark Johnston if (!error && (get_cr4_mask || get_all)) { 809*1c4ee7dfSMark Johnston uint64_t cr4mask; 810*1c4ee7dfSMark Johnston error = vm_get_vmcs_field(vcpu, VMCS_CR4_MASK, &cr4mask); 811*1c4ee7dfSMark Johnston if (error == 0) 812*1c4ee7dfSMark Johnston printf("cr4_mask[%d]\t\t0x%016lx\n", vcpuid, cr4mask); 813*1c4ee7dfSMark Johnston } 814*1c4ee7dfSMark Johnston 815*1c4ee7dfSMark Johnston if (!error && (get_cr4_shadow || get_all)) { 816*1c4ee7dfSMark Johnston uint64_t cr4shadow; 817*1c4ee7dfSMark Johnston error = vm_get_vmcs_field(vcpu, VMCS_CR4_SHADOW, 818*1c4ee7dfSMark Johnston &cr4shadow); 819*1c4ee7dfSMark Johnston if (error == 0) 820*1c4ee7dfSMark Johnston printf("cr4_shadow[%d]\t\t0x%016lx\n", vcpuid, cr4shadow); 821*1c4ee7dfSMark Johnston } 822*1c4ee7dfSMark Johnston 823*1c4ee7dfSMark Johnston if (!error && (get_cr3_targets || get_all)) { 824*1c4ee7dfSMark Johnston uint64_t target_count, target_addr; 825*1c4ee7dfSMark Johnston error = vm_get_vmcs_field(vcpu, VMCS_CR3_TARGET_COUNT, 826*1c4ee7dfSMark Johnston &target_count); 827*1c4ee7dfSMark Johnston if (error == 0) { 828*1c4ee7dfSMark Johnston printf("cr3_target_count[%d]\t0x%016lx\n", 829*1c4ee7dfSMark Johnston vcpuid, target_count); 830*1c4ee7dfSMark Johnston } 831*1c4ee7dfSMark Johnston 832*1c4ee7dfSMark Johnston error = vm_get_vmcs_field(vcpu, VMCS_CR3_TARGET0, 833*1c4ee7dfSMark Johnston &target_addr); 834*1c4ee7dfSMark Johnston if (error == 0) { 835*1c4ee7dfSMark Johnston printf("cr3_target0[%d]\t\t0x%016lx\n", 836*1c4ee7dfSMark Johnston vcpuid, target_addr); 837*1c4ee7dfSMark Johnston } 838*1c4ee7dfSMark Johnston 839*1c4ee7dfSMark Johnston error = vm_get_vmcs_field(vcpu, VMCS_CR3_TARGET1, 840*1c4ee7dfSMark Johnston &target_addr); 841*1c4ee7dfSMark Johnston if (error == 0) { 842*1c4ee7dfSMark Johnston printf("cr3_target1[%d]\t\t0x%016lx\n", 843*1c4ee7dfSMark Johnston vcpuid, target_addr); 844*1c4ee7dfSMark Johnston } 845*1c4ee7dfSMark Johnston 846*1c4ee7dfSMark Johnston error = vm_get_vmcs_field(vcpu, VMCS_CR3_TARGET2, 847*1c4ee7dfSMark Johnston &target_addr); 848*1c4ee7dfSMark Johnston if (error == 0) { 849*1c4ee7dfSMark Johnston printf("cr3_target2[%d]\t\t0x%016lx\n", 850*1c4ee7dfSMark Johnston vcpuid, target_addr); 851*1c4ee7dfSMark Johnston } 852*1c4ee7dfSMark Johnston 853*1c4ee7dfSMark Johnston error = vm_get_vmcs_field(vcpu, VMCS_CR3_TARGET3, 854*1c4ee7dfSMark Johnston &target_addr); 855*1c4ee7dfSMark Johnston if (error == 0) { 856*1c4ee7dfSMark Johnston printf("cr3_target3[%d]\t\t0x%016lx\n", 857*1c4ee7dfSMark Johnston vcpuid, target_addr); 858*1c4ee7dfSMark Johnston } 859*1c4ee7dfSMark Johnston } 860*1c4ee7dfSMark Johnston 861*1c4ee7dfSMark Johnston if (!error && (get_pinbased_ctls || get_all)) { 862*1c4ee7dfSMark Johnston error = vm_get_vmcs_field(vcpu, VMCS_PIN_BASED_CTLS, &ctl); 863*1c4ee7dfSMark Johnston if (error == 0) 864*1c4ee7dfSMark Johnston printf("pinbased_ctls[%d]\t0x%016lx\n", vcpuid, ctl); 865*1c4ee7dfSMark Johnston } 866*1c4ee7dfSMark Johnston 867*1c4ee7dfSMark Johnston if (!error && (get_procbased_ctls || get_all)) { 868*1c4ee7dfSMark Johnston error = vm_get_vmcs_field(vcpu, 869*1c4ee7dfSMark Johnston VMCS_PRI_PROC_BASED_CTLS, &ctl); 870*1c4ee7dfSMark Johnston if (error == 0) 871*1c4ee7dfSMark Johnston printf("procbased_ctls[%d]\t0x%016lx\n", vcpuid, ctl); 872*1c4ee7dfSMark Johnston } 873*1c4ee7dfSMark Johnston 874*1c4ee7dfSMark Johnston if (!error && (get_procbased_ctls2 || get_all)) { 875*1c4ee7dfSMark Johnston error = vm_get_vmcs_field(vcpu, 876*1c4ee7dfSMark Johnston VMCS_SEC_PROC_BASED_CTLS, &ctl); 877*1c4ee7dfSMark Johnston if (error == 0) 878*1c4ee7dfSMark Johnston printf("procbased_ctls2[%d]\t0x%016lx\n", vcpuid, ctl); 879*1c4ee7dfSMark Johnston } 880*1c4ee7dfSMark Johnston 881*1c4ee7dfSMark Johnston if (!error && (get_vmcs_gla || get_all)) { 882*1c4ee7dfSMark Johnston error = vm_get_vmcs_field(vcpu, 883*1c4ee7dfSMark Johnston VMCS_GUEST_LINEAR_ADDRESS, &u64); 884*1c4ee7dfSMark Johnston if (error == 0) 885*1c4ee7dfSMark Johnston printf("gla[%d]\t\t0x%016lx\n", vcpuid, u64); 886*1c4ee7dfSMark Johnston } 887*1c4ee7dfSMark Johnston 888*1c4ee7dfSMark Johnston if (!error && (get_vmcs_gpa || get_all)) { 889*1c4ee7dfSMark Johnston error = vm_get_vmcs_field(vcpu, 890*1c4ee7dfSMark Johnston VMCS_GUEST_PHYSICAL_ADDRESS, &u64); 891*1c4ee7dfSMark Johnston if (error == 0) 892*1c4ee7dfSMark Johnston printf("gpa[%d]\t\t0x%016lx\n", vcpuid, u64); 893*1c4ee7dfSMark Johnston } 894*1c4ee7dfSMark Johnston 895*1c4ee7dfSMark Johnston if (!error && (get_vmcs_entry_interruption_info || 896*1c4ee7dfSMark Johnston get_all)) { 897*1c4ee7dfSMark Johnston error = vm_get_vmcs_field(vcpu, VMCS_ENTRY_INTR_INFO,&u64); 898*1c4ee7dfSMark Johnston if (error == 0) { 899*1c4ee7dfSMark Johnston printf("entry_interruption_info[%d]\t0x%016lx\n", 900*1c4ee7dfSMark Johnston vcpuid, u64); 901*1c4ee7dfSMark Johnston } 902*1c4ee7dfSMark Johnston } 903*1c4ee7dfSMark Johnston 904*1c4ee7dfSMark Johnston if (!error && (get_tpr_threshold || get_all)) { 905*1c4ee7dfSMark Johnston uint64_t threshold; 906*1c4ee7dfSMark Johnston error = vm_get_vmcs_field(vcpu, VMCS_TPR_THRESHOLD, 907*1c4ee7dfSMark Johnston &threshold); 908*1c4ee7dfSMark Johnston if (error == 0) 909*1c4ee7dfSMark Johnston printf("tpr_threshold[%d]\t0x%016lx\n", vcpuid, threshold); 910*1c4ee7dfSMark Johnston } 911*1c4ee7dfSMark Johnston 912*1c4ee7dfSMark Johnston if (!error && (get_inst_err || get_all)) { 913*1c4ee7dfSMark Johnston uint64_t insterr; 914*1c4ee7dfSMark Johnston error = vm_get_vmcs_field(vcpu, VMCS_INSTRUCTION_ERROR, 915*1c4ee7dfSMark Johnston &insterr); 916*1c4ee7dfSMark Johnston if (error == 0) { 917*1c4ee7dfSMark Johnston printf("instruction_error[%d]\t0x%016lx\n", 918*1c4ee7dfSMark Johnston vcpuid, insterr); 919*1c4ee7dfSMark Johnston } 920*1c4ee7dfSMark Johnston } 921*1c4ee7dfSMark Johnston 922*1c4ee7dfSMark Johnston if (!error && (get_exit_ctls || get_all)) { 923*1c4ee7dfSMark Johnston error = vm_get_vmcs_field(vcpu, VMCS_EXIT_CTLS, &ctl); 924*1c4ee7dfSMark Johnston if (error == 0) 925*1c4ee7dfSMark Johnston printf("exit_ctls[%d]\t\t0x%016lx\n", vcpuid, ctl); 926*1c4ee7dfSMark Johnston } 927*1c4ee7dfSMark Johnston 928*1c4ee7dfSMark Johnston if (!error && (get_entry_ctls || get_all)) { 929*1c4ee7dfSMark Johnston error = vm_get_vmcs_field(vcpu, VMCS_ENTRY_CTLS, &ctl); 930*1c4ee7dfSMark Johnston if (error == 0) 931*1c4ee7dfSMark Johnston printf("entry_ctls[%d]\t\t0x%016lx\n", vcpuid, ctl); 932*1c4ee7dfSMark Johnston } 933*1c4ee7dfSMark Johnston 934*1c4ee7dfSMark Johnston if (!error && (get_host_pat || get_all)) { 935*1c4ee7dfSMark Johnston error = vm_get_vmcs_field(vcpu, VMCS_HOST_IA32_PAT, &pat); 936*1c4ee7dfSMark Johnston if (error == 0) 937*1c4ee7dfSMark Johnston printf("host_pat[%d]\t\t0x%016lx\n", vcpuid, pat); 938*1c4ee7dfSMark Johnston } 939*1c4ee7dfSMark Johnston 940*1c4ee7dfSMark Johnston if (!error && (get_host_cr0 || get_all)) { 941*1c4ee7dfSMark Johnston error = vm_get_vmcs_field(vcpu, VMCS_HOST_CR0, &cr0); 942*1c4ee7dfSMark Johnston if (error == 0) 943*1c4ee7dfSMark Johnston printf("host_cr0[%d]\t\t0x%016lx\n", vcpuid, cr0); 944*1c4ee7dfSMark Johnston } 945*1c4ee7dfSMark Johnston 946*1c4ee7dfSMark Johnston if (!error && (get_host_cr3 || get_all)) { 947*1c4ee7dfSMark Johnston error = vm_get_vmcs_field(vcpu, VMCS_HOST_CR3, &cr3); 948*1c4ee7dfSMark Johnston if (error == 0) 949*1c4ee7dfSMark Johnston printf("host_cr3[%d]\t\t0x%016lx\n", vcpuid, cr3); 950*1c4ee7dfSMark Johnston } 951*1c4ee7dfSMark Johnston 952*1c4ee7dfSMark Johnston if (!error && (get_host_cr4 || get_all)) { 953*1c4ee7dfSMark Johnston error = vm_get_vmcs_field(vcpu, VMCS_HOST_CR4, &cr4); 954*1c4ee7dfSMark Johnston if (error == 0) 955*1c4ee7dfSMark Johnston printf("host_cr4[%d]\t\t0x%016lx\n", vcpuid, cr4); 956*1c4ee7dfSMark Johnston } 957*1c4ee7dfSMark Johnston 958*1c4ee7dfSMark Johnston if (!error && (get_host_rip || get_all)) { 959*1c4ee7dfSMark Johnston error = vm_get_vmcs_field(vcpu, VMCS_HOST_RIP, &rip); 960*1c4ee7dfSMark Johnston if (error == 0) 961*1c4ee7dfSMark Johnston printf("host_rip[%d]\t\t0x%016lx\n", vcpuid, rip); 962*1c4ee7dfSMark Johnston } 963*1c4ee7dfSMark Johnston 964*1c4ee7dfSMark Johnston if (!error && (get_host_rsp || get_all)) { 965*1c4ee7dfSMark Johnston error = vm_get_vmcs_field(vcpu, VMCS_HOST_RSP, &rsp); 966*1c4ee7dfSMark Johnston if (error == 0) 967*1c4ee7dfSMark Johnston printf("host_rsp[%d]\t\t0x%016lx\n", vcpuid, rsp); 968*1c4ee7dfSMark Johnston } 969*1c4ee7dfSMark Johnston 970*1c4ee7dfSMark Johnston if (!error && (get_vmcs_link || get_all)) { 971*1c4ee7dfSMark Johnston error = vm_get_vmcs_field(vcpu, VMCS_LINK_POINTER, &addr); 972*1c4ee7dfSMark Johnston if (error == 0) 973*1c4ee7dfSMark Johnston printf("vmcs_pointer[%d]\t0x%016lx\n", vcpuid, addr); 974*1c4ee7dfSMark Johnston } 975*1c4ee7dfSMark Johnston 976*1c4ee7dfSMark Johnston if (!error && (get_vmcs_exit_interruption_info || get_all)) { 977*1c4ee7dfSMark Johnston error = vm_get_vmcs_field(vcpu, VMCS_EXIT_INTR_INFO, &u64); 978*1c4ee7dfSMark Johnston if (error == 0) { 979*1c4ee7dfSMark Johnston printf("vmcs_exit_interruption_info[%d]\t0x%016lx\n", 980*1c4ee7dfSMark Johnston vcpuid, u64); 981*1c4ee7dfSMark Johnston } 982*1c4ee7dfSMark Johnston } 983*1c4ee7dfSMark Johnston 984*1c4ee7dfSMark Johnston if (!error && (get_vmcs_exit_interruption_error || get_all)) { 985*1c4ee7dfSMark Johnston error = vm_get_vmcs_field(vcpu, VMCS_EXIT_INTR_ERRCODE, &u64); 986*1c4ee7dfSMark Johnston if (error == 0) { 987*1c4ee7dfSMark Johnston printf("vmcs_exit_interruption_error[%d]\t0x%016lx\n", 988*1c4ee7dfSMark Johnston vcpuid, u64); 989*1c4ee7dfSMark Johnston } 990*1c4ee7dfSMark Johnston } 991*1c4ee7dfSMark Johnston 992*1c4ee7dfSMark Johnston if (!error && (get_vmcs_interruptibility || get_all)) { 993*1c4ee7dfSMark Johnston error = vm_get_vmcs_field(vcpu, 994*1c4ee7dfSMark Johnston VMCS_GUEST_INTERRUPTIBILITY, &u64); 995*1c4ee7dfSMark Johnston if (error == 0) { 996*1c4ee7dfSMark Johnston printf("vmcs_guest_interruptibility[%d]\t0x%016lx\n", 997*1c4ee7dfSMark Johnston vcpuid, u64); 998*1c4ee7dfSMark Johnston } 999*1c4ee7dfSMark Johnston } 1000*1c4ee7dfSMark Johnston 1001*1c4ee7dfSMark Johnston if (!error && (get_vmcs_exit_inst_length || get_all)) { 1002*1c4ee7dfSMark Johnston error = vm_get_vmcs_field(vcpu, 1003*1c4ee7dfSMark Johnston VMCS_EXIT_INSTRUCTION_LENGTH, &u64); 1004*1c4ee7dfSMark Johnston if (error == 0) 1005*1c4ee7dfSMark Johnston printf("vmcs_exit_inst_length[%d]\t0x%08x\n", vcpuid, 1006*1c4ee7dfSMark Johnston (uint32_t)u64); 1007*1c4ee7dfSMark Johnston } 1008*1c4ee7dfSMark Johnston 1009*1c4ee7dfSMark Johnston if (!error && (get_vmcs_exit_qualification || get_all)) { 1010*1c4ee7dfSMark Johnston error = vm_get_vmcs_field(vcpu, VMCS_EXIT_QUALIFICATION, 1011*1c4ee7dfSMark Johnston &u64); 1012*1c4ee7dfSMark Johnston if (error == 0) 1013*1c4ee7dfSMark Johnston printf("vmcs_exit_qualification[%d]\t0x%016lx\n", 1014*1c4ee7dfSMark Johnston vcpuid, u64); 1015*1c4ee7dfSMark Johnston } 1016*1c4ee7dfSMark Johnston 1017*1c4ee7dfSMark Johnston return (error); 1018*1c4ee7dfSMark Johnston } 1019*1c4ee7dfSMark Johnston 1020*1c4ee7dfSMark Johnston static int 1021*1c4ee7dfSMark Johnston get_misc_vmcb(struct vcpu *vcpu, int vcpuid, bool get_all) 1022*1c4ee7dfSMark Johnston { 1023*1c4ee7dfSMark Johnston uint64_t ctl, addr; 1024*1c4ee7dfSMark Johnston int error = 0; 1025*1c4ee7dfSMark Johnston 1026*1c4ee7dfSMark Johnston if (!error && (get_vmcb_intercept || get_all)) { 1027*1c4ee7dfSMark Johnston error = vm_get_vmcb_field(vcpu, VMCB_OFF_CR_INTERCEPT, 4, 1028*1c4ee7dfSMark Johnston &ctl); 1029*1c4ee7dfSMark Johnston if (error == 0) 1030*1c4ee7dfSMark Johnston printf("cr_intercept[%d]\t0x%08x\n", vcpuid, (int)ctl); 1031*1c4ee7dfSMark Johnston 1032*1c4ee7dfSMark Johnston error = vm_get_vmcb_field(vcpu, VMCB_OFF_DR_INTERCEPT, 4, 1033*1c4ee7dfSMark Johnston &ctl); 1034*1c4ee7dfSMark Johnston if (error == 0) 1035*1c4ee7dfSMark Johnston printf("dr_intercept[%d]\t0x%08x\n", vcpuid, (int)ctl); 1036*1c4ee7dfSMark Johnston 1037*1c4ee7dfSMark Johnston error = vm_get_vmcb_field(vcpu, VMCB_OFF_EXC_INTERCEPT, 4, 1038*1c4ee7dfSMark Johnston &ctl); 1039*1c4ee7dfSMark Johnston if (error == 0) 1040*1c4ee7dfSMark Johnston printf("exc_intercept[%d]\t0x%08x\n", vcpuid, (int)ctl); 1041*1c4ee7dfSMark Johnston 1042*1c4ee7dfSMark Johnston error = vm_get_vmcb_field(vcpu, VMCB_OFF_INST1_INTERCEPT, 1043*1c4ee7dfSMark Johnston 4, &ctl); 1044*1c4ee7dfSMark Johnston if (error == 0) 1045*1c4ee7dfSMark Johnston printf("inst1_intercept[%d]\t0x%08x\n", vcpuid, (int)ctl); 1046*1c4ee7dfSMark Johnston 1047*1c4ee7dfSMark Johnston error = vm_get_vmcb_field(vcpu, VMCB_OFF_INST2_INTERCEPT, 1048*1c4ee7dfSMark Johnston 4, &ctl); 1049*1c4ee7dfSMark Johnston if (error == 0) 1050*1c4ee7dfSMark Johnston printf("inst2_intercept[%d]\t0x%08x\n", vcpuid, (int)ctl); 1051*1c4ee7dfSMark Johnston } 1052*1c4ee7dfSMark Johnston 1053*1c4ee7dfSMark Johnston if (!error && (get_vmcb_tlb_ctrl || get_all)) { 1054*1c4ee7dfSMark Johnston error = vm_get_vmcb_field(vcpu, VMCB_OFF_TLB_CTRL, 1055*1c4ee7dfSMark Johnston 4, &ctl); 1056*1c4ee7dfSMark Johnston if (error == 0) 1057*1c4ee7dfSMark Johnston printf("TLB ctrl[%d]\t0x%016lx\n", vcpuid, ctl); 1058*1c4ee7dfSMark Johnston } 1059*1c4ee7dfSMark Johnston 1060*1c4ee7dfSMark Johnston if (!error && (get_vmcb_exit_details || get_all)) { 1061*1c4ee7dfSMark Johnston error = vm_get_vmcb_field(vcpu, VMCB_OFF_EXITINFO1, 1062*1c4ee7dfSMark Johnston 8, &ctl); 1063*1c4ee7dfSMark Johnston if (error == 0) 1064*1c4ee7dfSMark Johnston printf("exitinfo1[%d]\t0x%016lx\n", vcpuid, ctl); 1065*1c4ee7dfSMark Johnston error = vm_get_vmcb_field(vcpu, VMCB_OFF_EXITINFO2, 1066*1c4ee7dfSMark Johnston 8, &ctl); 1067*1c4ee7dfSMark Johnston if (error == 0) 1068*1c4ee7dfSMark Johnston printf("exitinfo2[%d]\t0x%016lx\n", vcpuid, ctl); 1069*1c4ee7dfSMark Johnston error = vm_get_vmcb_field(vcpu, VMCB_OFF_EXITINTINFO, 1070*1c4ee7dfSMark Johnston 8, &ctl); 1071*1c4ee7dfSMark Johnston if (error == 0) 1072*1c4ee7dfSMark Johnston printf("exitintinfo[%d]\t0x%016lx\n", vcpuid, ctl); 1073*1c4ee7dfSMark Johnston } 1074*1c4ee7dfSMark Johnston 1075*1c4ee7dfSMark Johnston if (!error && (get_vmcb_virq || get_all)) { 1076*1c4ee7dfSMark Johnston error = vm_get_vmcb_field(vcpu, VMCB_OFF_VIRQ, 1077*1c4ee7dfSMark Johnston 8, &ctl); 1078*1c4ee7dfSMark Johnston if (error == 0) 1079*1c4ee7dfSMark Johnston printf("v_irq/tpr[%d]\t0x%016lx\n", vcpuid, ctl); 1080*1c4ee7dfSMark Johnston } 1081*1c4ee7dfSMark Johnston 1082*1c4ee7dfSMark Johnston if (!error && (get_apic_access_addr || get_all)) { 1083*1c4ee7dfSMark Johnston error = vm_get_vmcb_field(vcpu, VMCB_OFF_AVIC_BAR, 8, 1084*1c4ee7dfSMark Johnston &addr); 1085*1c4ee7dfSMark Johnston if (error == 0) 1086*1c4ee7dfSMark Johnston printf("AVIC apic_bar[%d]\t0x%016lx\n", vcpuid, addr); 1087*1c4ee7dfSMark Johnston } 1088*1c4ee7dfSMark Johnston 1089*1c4ee7dfSMark Johnston if (!error && (get_virtual_apic_addr || get_all)) { 1090*1c4ee7dfSMark Johnston error = vm_get_vmcb_field(vcpu, VMCB_OFF_AVIC_PAGE, 8, 1091*1c4ee7dfSMark Johnston &addr); 1092*1c4ee7dfSMark Johnston if (error == 0) 1093*1c4ee7dfSMark Johnston printf("AVIC backing page[%d]\t0x%016lx\n", vcpuid, addr); 1094*1c4ee7dfSMark Johnston } 1095*1c4ee7dfSMark Johnston 1096*1c4ee7dfSMark Johnston if (!error && (get_avic_table || get_all)) { 1097*1c4ee7dfSMark Johnston error = vm_get_vmcb_field(vcpu, VMCB_OFF_AVIC_LT, 8, 1098*1c4ee7dfSMark Johnston &addr); 1099*1c4ee7dfSMark Johnston if (error == 0) 1100*1c4ee7dfSMark Johnston printf("AVIC logical table[%d]\t0x%016lx\n", 1101*1c4ee7dfSMark Johnston vcpuid, addr); 1102*1c4ee7dfSMark Johnston error = vm_get_vmcb_field(vcpu, VMCB_OFF_AVIC_PT, 8, 1103*1c4ee7dfSMark Johnston &addr); 1104*1c4ee7dfSMark Johnston if (error == 0) 1105*1c4ee7dfSMark Johnston printf("AVIC physical table[%d]\t0x%016lx\n", 1106*1c4ee7dfSMark Johnston vcpuid, addr); 1107*1c4ee7dfSMark Johnston } 1108*1c4ee7dfSMark Johnston 1109*1c4ee7dfSMark Johnston return (error); 1110*1c4ee7dfSMark Johnston } 1111*1c4ee7dfSMark Johnston 1112*1c4ee7dfSMark Johnston struct option * 1113*1c4ee7dfSMark Johnston bhyvectl_opts(const struct option *options, size_t count) 1114*1c4ee7dfSMark Johnston { 1115*1c4ee7dfSMark Johnston const struct option common_opts[] = { 1116*1c4ee7dfSMark Johnston { "set-efer", REQ_ARG, 0, SET_EFER }, 1117*1c4ee7dfSMark Johnston { "set-cr0", REQ_ARG, 0, SET_CR0 }, 1118*1c4ee7dfSMark Johnston { "set-cr2", REQ_ARG, 0, SET_CR2 }, 1119*1c4ee7dfSMark Johnston { "set-cr3", REQ_ARG, 0, SET_CR3 }, 1120*1c4ee7dfSMark Johnston { "set-cr4", REQ_ARG, 0, SET_CR4 }, 1121*1c4ee7dfSMark Johnston { "set-dr0", REQ_ARG, 0, SET_DR0 }, 1122*1c4ee7dfSMark Johnston { "set-dr1", REQ_ARG, 0, SET_DR1 }, 1123*1c4ee7dfSMark Johnston { "set-dr2", REQ_ARG, 0, SET_DR2 }, 1124*1c4ee7dfSMark Johnston { "set-dr3", REQ_ARG, 0, SET_DR3 }, 1125*1c4ee7dfSMark Johnston { "set-dr6", REQ_ARG, 0, SET_DR6 }, 1126*1c4ee7dfSMark Johnston { "set-dr7", REQ_ARG, 0, SET_DR7 }, 1127*1c4ee7dfSMark Johnston { "set-rsp", REQ_ARG, 0, SET_RSP }, 1128*1c4ee7dfSMark Johnston { "set-rip", REQ_ARG, 0, SET_RIP }, 1129*1c4ee7dfSMark Johnston { "set-rax", REQ_ARG, 0, SET_RAX }, 1130*1c4ee7dfSMark Johnston { "set-rflags", REQ_ARG, 0, SET_RFLAGS }, 1131*1c4ee7dfSMark Johnston { "desc-base", REQ_ARG, 0, DESC_BASE }, 1132*1c4ee7dfSMark Johnston { "desc-limit", REQ_ARG, 0, DESC_LIMIT }, 1133*1c4ee7dfSMark Johnston { "desc-access",REQ_ARG, 0, DESC_ACCESS }, 1134*1c4ee7dfSMark Johnston { "set-cs", REQ_ARG, 0, SET_CS }, 1135*1c4ee7dfSMark Johnston { "set-ds", REQ_ARG, 0, SET_DS }, 1136*1c4ee7dfSMark Johnston { "set-es", REQ_ARG, 0, SET_ES }, 1137*1c4ee7dfSMark Johnston { "set-fs", REQ_ARG, 0, SET_FS }, 1138*1c4ee7dfSMark Johnston { "set-gs", REQ_ARG, 0, SET_GS }, 1139*1c4ee7dfSMark Johnston { "set-ss", REQ_ARG, 0, SET_SS }, 1140*1c4ee7dfSMark Johnston { "set-tr", REQ_ARG, 0, SET_TR }, 1141*1c4ee7dfSMark Johnston { "set-ldtr", REQ_ARG, 0, SET_LDTR }, 1142*1c4ee7dfSMark Johnston { "set-x2apic-state",REQ_ARG, 0, SET_X2APIC_STATE }, 1143*1c4ee7dfSMark Johnston { "unassign-pptdev", REQ_ARG, 0, UNASSIGN_PPTDEV }, 1144*1c4ee7dfSMark Johnston { "get-gpa-pmap", REQ_ARG, 0, GET_GPA_PMAP }, 1145*1c4ee7dfSMark Johnston { "assert-lapic-lvt", REQ_ARG, 0, ASSERT_LAPIC_LVT }, 1146*1c4ee7dfSMark Johnston { "get-rtc-time", NO_ARG, &get_rtc_time, 1 }, 1147*1c4ee7dfSMark Johnston { "set-rtc-time", REQ_ARG, 0, SET_RTC_TIME }, 1148*1c4ee7dfSMark Johnston { "rtc-nvram-offset", REQ_ARG, 0, RTC_NVRAM_OFFSET }, 1149*1c4ee7dfSMark Johnston { "get-rtc-nvram", NO_ARG, &get_rtc_nvram, 1 }, 1150*1c4ee7dfSMark Johnston { "set-rtc-nvram", REQ_ARG, 0, SET_RTC_NVRAM }, 1151*1c4ee7dfSMark Johnston { "get-desc-ds",NO_ARG, &get_desc_ds, 1 }, 1152*1c4ee7dfSMark Johnston { "set-desc-ds",NO_ARG, &set_desc_ds, 1 }, 1153*1c4ee7dfSMark Johnston { "get-desc-es",NO_ARG, &get_desc_es, 1 }, 1154*1c4ee7dfSMark Johnston { "set-desc-es",NO_ARG, &set_desc_es, 1 }, 1155*1c4ee7dfSMark Johnston { "get-desc-ss",NO_ARG, &get_desc_ss, 1 }, 1156*1c4ee7dfSMark Johnston { "set-desc-ss",NO_ARG, &set_desc_ss, 1 }, 1157*1c4ee7dfSMark Johnston { "get-desc-cs",NO_ARG, &get_desc_cs, 1 }, 1158*1c4ee7dfSMark Johnston { "set-desc-cs",NO_ARG, &set_desc_cs, 1 }, 1159*1c4ee7dfSMark Johnston { "get-desc-fs",NO_ARG, &get_desc_fs, 1 }, 1160*1c4ee7dfSMark Johnston { "set-desc-fs",NO_ARG, &set_desc_fs, 1 }, 1161*1c4ee7dfSMark Johnston { "get-desc-gs",NO_ARG, &get_desc_gs, 1 }, 1162*1c4ee7dfSMark Johnston { "set-desc-gs",NO_ARG, &set_desc_gs, 1 }, 1163*1c4ee7dfSMark Johnston { "get-desc-tr",NO_ARG, &get_desc_tr, 1 }, 1164*1c4ee7dfSMark Johnston { "set-desc-tr",NO_ARG, &set_desc_tr, 1 }, 1165*1c4ee7dfSMark Johnston { "set-desc-ldtr", NO_ARG, &set_desc_ldtr, 1 }, 1166*1c4ee7dfSMark Johnston { "get-desc-ldtr", NO_ARG, &get_desc_ldtr, 1 }, 1167*1c4ee7dfSMark Johnston { "set-desc-gdtr", NO_ARG, &set_desc_gdtr, 1 }, 1168*1c4ee7dfSMark Johnston { "get-desc-gdtr", NO_ARG, &get_desc_gdtr, 1 }, 1169*1c4ee7dfSMark Johnston { "set-desc-idtr", NO_ARG, &set_desc_idtr, 1 }, 1170*1c4ee7dfSMark Johnston { "get-desc-idtr", NO_ARG, &get_desc_idtr, 1 }, 1171*1c4ee7dfSMark Johnston { "get-efer", NO_ARG, &get_efer, 1 }, 1172*1c4ee7dfSMark Johnston { "get-cr0", NO_ARG, &get_cr0, 1 }, 1173*1c4ee7dfSMark Johnston { "get-cr2", NO_ARG, &get_cr2, 1 }, 1174*1c4ee7dfSMark Johnston { "get-cr3", NO_ARG, &get_cr3, 1 }, 1175*1c4ee7dfSMark Johnston { "get-cr4", NO_ARG, &get_cr4, 1 }, 1176*1c4ee7dfSMark Johnston { "get-dr0", NO_ARG, &get_dr0, 1 }, 1177*1c4ee7dfSMark Johnston { "get-dr1", NO_ARG, &get_dr1, 1 }, 1178*1c4ee7dfSMark Johnston { "get-dr2", NO_ARG, &get_dr2, 1 }, 1179*1c4ee7dfSMark Johnston { "get-dr3", NO_ARG, &get_dr3, 1 }, 1180*1c4ee7dfSMark Johnston { "get-dr6", NO_ARG, &get_dr6, 1 }, 1181*1c4ee7dfSMark Johnston { "get-dr7", NO_ARG, &get_dr7, 1 }, 1182*1c4ee7dfSMark Johnston { "get-rsp", NO_ARG, &get_rsp, 1 }, 1183*1c4ee7dfSMark Johnston { "get-rip", NO_ARG, &get_rip, 1 }, 1184*1c4ee7dfSMark Johnston { "get-rax", NO_ARG, &get_rax, 1 }, 1185*1c4ee7dfSMark Johnston { "get-rbx", NO_ARG, &get_rbx, 1 }, 1186*1c4ee7dfSMark Johnston { "get-rcx", NO_ARG, &get_rcx, 1 }, 1187*1c4ee7dfSMark Johnston { "get-rdx", NO_ARG, &get_rdx, 1 }, 1188*1c4ee7dfSMark Johnston { "get-rsi", NO_ARG, &get_rsi, 1 }, 1189*1c4ee7dfSMark Johnston { "get-rdi", NO_ARG, &get_rdi, 1 }, 1190*1c4ee7dfSMark Johnston { "get-rbp", NO_ARG, &get_rbp, 1 }, 1191*1c4ee7dfSMark Johnston { "get-r8", NO_ARG, &get_r8, 1 }, 1192*1c4ee7dfSMark Johnston { "get-r9", NO_ARG, &get_r9, 1 }, 1193*1c4ee7dfSMark Johnston { "get-r10", NO_ARG, &get_r10, 1 }, 1194*1c4ee7dfSMark Johnston { "get-r11", NO_ARG, &get_r11, 1 }, 1195*1c4ee7dfSMark Johnston { "get-r12", NO_ARG, &get_r12, 1 }, 1196*1c4ee7dfSMark Johnston { "get-r13", NO_ARG, &get_r13, 1 }, 1197*1c4ee7dfSMark Johnston { "get-r14", NO_ARG, &get_r14, 1 }, 1198*1c4ee7dfSMark Johnston { "get-r15", NO_ARG, &get_r15, 1 }, 1199*1c4ee7dfSMark Johnston { "get-rflags", NO_ARG, &get_rflags, 1 }, 1200*1c4ee7dfSMark Johnston { "get-cs", NO_ARG, &get_cs, 1 }, 1201*1c4ee7dfSMark Johnston { "get-ds", NO_ARG, &get_ds, 1 }, 1202*1c4ee7dfSMark Johnston { "get-es", NO_ARG, &get_es, 1 }, 1203*1c4ee7dfSMark Johnston { "get-fs", NO_ARG, &get_fs, 1 }, 1204*1c4ee7dfSMark Johnston { "get-gs", NO_ARG, &get_gs, 1 }, 1205*1c4ee7dfSMark Johnston { "get-ss", NO_ARG, &get_ss, 1 }, 1206*1c4ee7dfSMark Johnston { "get-tr", NO_ARG, &get_tr, 1 }, 1207*1c4ee7dfSMark Johnston { "get-ldtr", NO_ARG, &get_ldtr, 1 }, 1208*1c4ee7dfSMark Johnston { "get-eptp", NO_ARG, &get_eptp, 1 }, 1209*1c4ee7dfSMark Johnston { "get-exception-bitmap", NO_ARG, &get_exception_bitmap, 1 }, 1210*1c4ee7dfSMark Johnston { "get-io-bitmap-address", NO_ARG, &get_io_bitmap, 1 }, 1211*1c4ee7dfSMark Johnston { "get-tsc-offset", NO_ARG, &get_tsc_offset, 1 }, 1212*1c4ee7dfSMark Johnston { "get-msr-bitmap", NO_ARG, &get_msr_bitmap, 1 }, 1213*1c4ee7dfSMark Johnston { "get-msr-bitmap-address", NO_ARG, &get_msr_bitmap_address, 1}, 1214*1c4ee7dfSMark Johnston { "get-guest-pat", NO_ARG, &get_guest_pat, 1 }, 1215*1c4ee7dfSMark Johnston { "get-guest-sysenter", NO_ARG, &get_guest_sysenter, 1 }, 1216*1c4ee7dfSMark Johnston { "get-exit-reason", NO_ARG, &get_exit_reason, 1 }, 1217*1c4ee7dfSMark Johnston { "get-x2apic-state", NO_ARG, &get_x2apic_state, 1 }, 1218*1c4ee7dfSMark Johnston { "inject-nmi", NO_ARG, &inject_nmi, 1 }, 1219*1c4ee7dfSMark Johnston { "get-intinfo", NO_ARG, &get_intinfo, 1 }, 1220*1c4ee7dfSMark Johnston }; 1221*1c4ee7dfSMark Johnston const struct option intel_opts[] = { 1222*1c4ee7dfSMark Johnston { "get-vmcs-pinbased-ctls", 1223*1c4ee7dfSMark Johnston NO_ARG, &get_pinbased_ctls, 1 }, 1224*1c4ee7dfSMark Johnston { "get-vmcs-procbased-ctls", 1225*1c4ee7dfSMark Johnston NO_ARG, &get_procbased_ctls, 1 }, 1226*1c4ee7dfSMark Johnston { "get-vmcs-procbased-ctls2", 1227*1c4ee7dfSMark Johnston NO_ARG, &get_procbased_ctls2, 1 }, 1228*1c4ee7dfSMark Johnston { "get-vmcs-guest-linear-address", 1229*1c4ee7dfSMark Johnston NO_ARG, &get_vmcs_gla, 1 }, 1230*1c4ee7dfSMark Johnston { "get-vmcs-guest-physical-address", 1231*1c4ee7dfSMark Johnston NO_ARG, &get_vmcs_gpa, 1 }, 1232*1c4ee7dfSMark Johnston { "get-vmcs-entry-interruption-info", 1233*1c4ee7dfSMark Johnston NO_ARG, &get_vmcs_entry_interruption_info, 1}, 1234*1c4ee7dfSMark Johnston { "get-vmcs-cr0-mask", NO_ARG, &get_cr0_mask, 1 }, 1235*1c4ee7dfSMark Johnston { "get-vmcs-cr0-shadow", NO_ARG,&get_cr0_shadow, 1 }, 1236*1c4ee7dfSMark Johnston { "get-vmcs-cr4-mask", NO_ARG, &get_cr4_mask, 1 }, 1237*1c4ee7dfSMark Johnston { "get-vmcs-cr4-shadow", NO_ARG, &get_cr4_shadow, 1 }, 1238*1c4ee7dfSMark Johnston { "get-vmcs-cr3-targets", NO_ARG, &get_cr3_targets, 1 }, 1239*1c4ee7dfSMark Johnston { "get-vmcs-tpr-threshold", 1240*1c4ee7dfSMark Johnston NO_ARG, &get_tpr_threshold, 1 }, 1241*1c4ee7dfSMark Johnston { "get-vmcs-vpid", NO_ARG, &get_vpid_asid, 1 }, 1242*1c4ee7dfSMark Johnston { "get-vmcs-exit-ctls", NO_ARG, &get_exit_ctls, 1 }, 1243*1c4ee7dfSMark Johnston { "get-vmcs-entry-ctls", 1244*1c4ee7dfSMark Johnston NO_ARG, &get_entry_ctls, 1 }, 1245*1c4ee7dfSMark Johnston { "get-vmcs-instruction-error", 1246*1c4ee7dfSMark Johnston NO_ARG, &get_inst_err, 1 }, 1247*1c4ee7dfSMark Johnston { "get-vmcs-host-pat", NO_ARG, &get_host_pat, 1 }, 1248*1c4ee7dfSMark Johnston { "get-vmcs-host-cr0", 1249*1c4ee7dfSMark Johnston NO_ARG, &get_host_cr0, 1 }, 1250*1c4ee7dfSMark Johnston { "get-vmcs-exit-qualification", 1251*1c4ee7dfSMark Johnston NO_ARG, &get_vmcs_exit_qualification, 1 }, 1252*1c4ee7dfSMark Johnston { "get-vmcs-exit-inst-length", 1253*1c4ee7dfSMark Johnston NO_ARG, &get_vmcs_exit_inst_length, 1 }, 1254*1c4ee7dfSMark Johnston { "get-vmcs-interruptibility", 1255*1c4ee7dfSMark Johnston NO_ARG, &get_vmcs_interruptibility, 1 }, 1256*1c4ee7dfSMark Johnston { "get-vmcs-exit-interruption-error", 1257*1c4ee7dfSMark Johnston NO_ARG, &get_vmcs_exit_interruption_error, 1 }, 1258*1c4ee7dfSMark Johnston { "get-vmcs-exit-interruption-info", 1259*1c4ee7dfSMark Johnston NO_ARG, &get_vmcs_exit_interruption_info, 1 }, 1260*1c4ee7dfSMark Johnston { "get-vmcs-link", NO_ARG, &get_vmcs_link, 1 }, 1261*1c4ee7dfSMark Johnston { "get-vmcs-host-cr3", 1262*1c4ee7dfSMark Johnston NO_ARG, &get_host_cr3, 1 }, 1263*1c4ee7dfSMark Johnston { "get-vmcs-host-cr4", 1264*1c4ee7dfSMark Johnston NO_ARG, &get_host_cr4, 1 }, 1265*1c4ee7dfSMark Johnston { "get-vmcs-host-rip", 1266*1c4ee7dfSMark Johnston NO_ARG, &get_host_rip, 1 }, 1267*1c4ee7dfSMark Johnston { "get-vmcs-host-rsp", 1268*1c4ee7dfSMark Johnston NO_ARG, &get_host_rsp, 1 }, 1269*1c4ee7dfSMark Johnston { "get-apic-access-address", 1270*1c4ee7dfSMark Johnston NO_ARG, &get_apic_access_addr, 1}, 1271*1c4ee7dfSMark Johnston { "get-virtual-apic-address", 1272*1c4ee7dfSMark Johnston NO_ARG, &get_virtual_apic_addr, 1} 1273*1c4ee7dfSMark Johnston }; 1274*1c4ee7dfSMark Johnston const struct option amd_opts[] = { 1275*1c4ee7dfSMark Johnston { "get-vmcb-intercepts", 1276*1c4ee7dfSMark Johnston NO_ARG, &get_vmcb_intercept, 1 }, 1277*1c4ee7dfSMark Johnston { "get-vmcb-asid", 1278*1c4ee7dfSMark Johnston NO_ARG, &get_vpid_asid, 1 }, 1279*1c4ee7dfSMark Johnston { "get-vmcb-exit-details", 1280*1c4ee7dfSMark Johnston NO_ARG, &get_vmcb_exit_details, 1 }, 1281*1c4ee7dfSMark Johnston { "get-vmcb-tlb-ctrl", 1282*1c4ee7dfSMark Johnston NO_ARG, &get_vmcb_tlb_ctrl, 1 }, 1283*1c4ee7dfSMark Johnston { "get-vmcb-virq", 1284*1c4ee7dfSMark Johnston NO_ARG, &get_vmcb_virq, 1 }, 1285*1c4ee7dfSMark Johnston { "get-avic-apic-bar", 1286*1c4ee7dfSMark Johnston NO_ARG, &get_apic_access_addr, 1 }, 1287*1c4ee7dfSMark Johnston { "get-avic-backing-page", 1288*1c4ee7dfSMark Johnston NO_ARG, &get_virtual_apic_addr, 1 }, 1289*1c4ee7dfSMark Johnston { "get-avic-table", 1290*1c4ee7dfSMark Johnston NO_ARG, &get_avic_table, 1 } 1291*1c4ee7dfSMark Johnston }; 1292*1c4ee7dfSMark Johnston const struct option null_opt = { 1293*1c4ee7dfSMark Johnston NULL, 0, NULL, 0 1294*1c4ee7dfSMark Johnston }; 1295*1c4ee7dfSMark Johnston 1296*1c4ee7dfSMark Johnston struct option *all_opts; 1297*1c4ee7dfSMark Johnston char *cp; 1298*1c4ee7dfSMark Johnston int optlen; 1299*1c4ee7dfSMark Johnston bool cpu_intel; 1300*1c4ee7dfSMark Johnston 1301*1c4ee7dfSMark Johnston cpu_intel = cpu_vendor_intel(); 1302*1c4ee7dfSMark Johnston optlen = count * sizeof(struct option) + sizeof(common_opts); 1303*1c4ee7dfSMark Johnston 1304*1c4ee7dfSMark Johnston if (cpu_intel) 1305*1c4ee7dfSMark Johnston optlen += sizeof(intel_opts); 1306*1c4ee7dfSMark Johnston else 1307*1c4ee7dfSMark Johnston optlen += sizeof(amd_opts); 1308*1c4ee7dfSMark Johnston 1309*1c4ee7dfSMark Johnston optlen += sizeof(null_opt); 1310*1c4ee7dfSMark Johnston 1311*1c4ee7dfSMark Johnston all_opts = malloc(optlen); 1312*1c4ee7dfSMark Johnston if (all_opts == NULL) 1313*1c4ee7dfSMark Johnston err(1, "malloc"); 1314*1c4ee7dfSMark Johnston 1315*1c4ee7dfSMark Johnston cp = (char *)all_opts; 1316*1c4ee7dfSMark Johnston memcpy(cp, options, count * sizeof(struct option)); 1317*1c4ee7dfSMark Johnston cp += count * sizeof(struct option); 1318*1c4ee7dfSMark Johnston memcpy(cp, common_opts, sizeof(common_opts)); 1319*1c4ee7dfSMark Johnston cp += sizeof(common_opts); 1320*1c4ee7dfSMark Johnston 1321*1c4ee7dfSMark Johnston if (cpu_intel) { 1322*1c4ee7dfSMark Johnston memcpy(cp, intel_opts, sizeof(intel_opts)); 1323*1c4ee7dfSMark Johnston cp += sizeof(intel_opts); 1324*1c4ee7dfSMark Johnston } else { 1325*1c4ee7dfSMark Johnston memcpy(cp, amd_opts, sizeof(amd_opts)); 1326*1c4ee7dfSMark Johnston cp += sizeof(amd_opts); 1327*1c4ee7dfSMark Johnston } 1328*1c4ee7dfSMark Johnston 1329*1c4ee7dfSMark Johnston memcpy(cp, &null_opt, sizeof(null_opt)); 1330*1c4ee7dfSMark Johnston cp += sizeof(null_opt); 1331*1c4ee7dfSMark Johnston 1332*1c4ee7dfSMark Johnston return (all_opts); 1333*1c4ee7dfSMark Johnston } 1334*1c4ee7dfSMark Johnston 1335*1c4ee7dfSMark Johnston void 1336*1c4ee7dfSMark Johnston bhyvectl_handle_opt(const struct option *opts, int opt) 1337*1c4ee7dfSMark Johnston { 1338*1c4ee7dfSMark Johnston switch (opt) { 1339*1c4ee7dfSMark Johnston case SET_EFER: 1340*1c4ee7dfSMark Johnston set_efer_val = strtoul(optarg, NULL, 0); 1341*1c4ee7dfSMark Johnston set_efer = 1; 1342*1c4ee7dfSMark Johnston break; 1343*1c4ee7dfSMark Johnston case SET_CR0: 1344*1c4ee7dfSMark Johnston set_cr0_val = strtoul(optarg, NULL, 0); 1345*1c4ee7dfSMark Johnston set_cr0 = 1; 1346*1c4ee7dfSMark Johnston break; 1347*1c4ee7dfSMark Johnston case SET_CR2: 1348*1c4ee7dfSMark Johnston set_cr2_val = strtoul(optarg, NULL, 0); 1349*1c4ee7dfSMark Johnston set_cr2 = 1; 1350*1c4ee7dfSMark Johnston break; 1351*1c4ee7dfSMark Johnston case SET_CR3: 1352*1c4ee7dfSMark Johnston set_cr3_val = strtoul(optarg, NULL, 0); 1353*1c4ee7dfSMark Johnston set_cr3 = 1; 1354*1c4ee7dfSMark Johnston break; 1355*1c4ee7dfSMark Johnston case SET_CR4: 1356*1c4ee7dfSMark Johnston set_cr4_val = strtoul(optarg, NULL, 0); 1357*1c4ee7dfSMark Johnston set_cr4 = 1; 1358*1c4ee7dfSMark Johnston break; 1359*1c4ee7dfSMark Johnston case SET_DR0: 1360*1c4ee7dfSMark Johnston set_dr0_val = strtoul(optarg, NULL, 0); 1361*1c4ee7dfSMark Johnston set_dr0 = 1; 1362*1c4ee7dfSMark Johnston break; 1363*1c4ee7dfSMark Johnston case SET_DR1: 1364*1c4ee7dfSMark Johnston set_dr1_val = strtoul(optarg, NULL, 0); 1365*1c4ee7dfSMark Johnston set_dr1 = 1; 1366*1c4ee7dfSMark Johnston break; 1367*1c4ee7dfSMark Johnston case SET_DR2: 1368*1c4ee7dfSMark Johnston set_dr2_val = strtoul(optarg, NULL, 0); 1369*1c4ee7dfSMark Johnston set_dr2 = 1; 1370*1c4ee7dfSMark Johnston break; 1371*1c4ee7dfSMark Johnston case SET_DR3: 1372*1c4ee7dfSMark Johnston set_dr3_val = strtoul(optarg, NULL, 0); 1373*1c4ee7dfSMark Johnston set_dr3 = 1; 1374*1c4ee7dfSMark Johnston break; 1375*1c4ee7dfSMark Johnston case SET_DR6: 1376*1c4ee7dfSMark Johnston set_dr6_val = strtoul(optarg, NULL, 0); 1377*1c4ee7dfSMark Johnston set_dr6 = 1; 1378*1c4ee7dfSMark Johnston break; 1379*1c4ee7dfSMark Johnston case SET_DR7: 1380*1c4ee7dfSMark Johnston set_dr7_val = strtoul(optarg, NULL, 0); 1381*1c4ee7dfSMark Johnston set_dr7 = 1; 1382*1c4ee7dfSMark Johnston break; 1383*1c4ee7dfSMark Johnston case SET_RSP: 1384*1c4ee7dfSMark Johnston set_rsp_val = strtoul(optarg, NULL, 0); 1385*1c4ee7dfSMark Johnston set_rsp = 1; 1386*1c4ee7dfSMark Johnston break; 1387*1c4ee7dfSMark Johnston case SET_RIP: 1388*1c4ee7dfSMark Johnston set_rip_val = strtoul(optarg, NULL, 0); 1389*1c4ee7dfSMark Johnston set_rip = 1; 1390*1c4ee7dfSMark Johnston break; 1391*1c4ee7dfSMark Johnston case SET_RAX: 1392*1c4ee7dfSMark Johnston set_rax_val = strtoul(optarg, NULL, 0); 1393*1c4ee7dfSMark Johnston set_rax = 1; 1394*1c4ee7dfSMark Johnston break; 1395*1c4ee7dfSMark Johnston case SET_RFLAGS: 1396*1c4ee7dfSMark Johnston set_rflags_val = strtoul(optarg, NULL, 0); 1397*1c4ee7dfSMark Johnston set_rflags = 1; 1398*1c4ee7dfSMark Johnston break; 1399*1c4ee7dfSMark Johnston case DESC_BASE: 1400*1c4ee7dfSMark Johnston desc_base = strtoul(optarg, NULL, 0); 1401*1c4ee7dfSMark Johnston break; 1402*1c4ee7dfSMark Johnston case DESC_LIMIT: 1403*1c4ee7dfSMark Johnston desc_limit = strtoul(optarg, NULL, 0); 1404*1c4ee7dfSMark Johnston break; 1405*1c4ee7dfSMark Johnston case DESC_ACCESS: 1406*1c4ee7dfSMark Johnston desc_access = strtoul(optarg, NULL, 0); 1407*1c4ee7dfSMark Johnston break; 1408*1c4ee7dfSMark Johnston case SET_CS: 1409*1c4ee7dfSMark Johnston set_cs_val = strtoul(optarg, NULL, 0); 1410*1c4ee7dfSMark Johnston set_cs = 1; 1411*1c4ee7dfSMark Johnston break; 1412*1c4ee7dfSMark Johnston case SET_DS: 1413*1c4ee7dfSMark Johnston set_ds_val = strtoul(optarg, NULL, 0); 1414*1c4ee7dfSMark Johnston set_ds = 1; 1415*1c4ee7dfSMark Johnston break; 1416*1c4ee7dfSMark Johnston case SET_ES: 1417*1c4ee7dfSMark Johnston set_es_val = strtoul(optarg, NULL, 0); 1418*1c4ee7dfSMark Johnston set_es = 1; 1419*1c4ee7dfSMark Johnston break; 1420*1c4ee7dfSMark Johnston case SET_FS: 1421*1c4ee7dfSMark Johnston set_fs_val = strtoul(optarg, NULL, 0); 1422*1c4ee7dfSMark Johnston set_fs = 1; 1423*1c4ee7dfSMark Johnston break; 1424*1c4ee7dfSMark Johnston case SET_GS: 1425*1c4ee7dfSMark Johnston set_gs_val = strtoul(optarg, NULL, 0); 1426*1c4ee7dfSMark Johnston set_gs = 1; 1427*1c4ee7dfSMark Johnston break; 1428*1c4ee7dfSMark Johnston case SET_SS: 1429*1c4ee7dfSMark Johnston set_ss_val = strtoul(optarg, NULL, 0); 1430*1c4ee7dfSMark Johnston set_ss = 1; 1431*1c4ee7dfSMark Johnston break; 1432*1c4ee7dfSMark Johnston case SET_TR: 1433*1c4ee7dfSMark Johnston set_tr_val = strtoul(optarg, NULL, 0); 1434*1c4ee7dfSMark Johnston set_tr = 1; 1435*1c4ee7dfSMark Johnston break; 1436*1c4ee7dfSMark Johnston case SET_LDTR: 1437*1c4ee7dfSMark Johnston set_ldtr_val = strtoul(optarg, NULL, 0); 1438*1c4ee7dfSMark Johnston set_ldtr = 1; 1439*1c4ee7dfSMark Johnston break; 1440*1c4ee7dfSMark Johnston case SET_X2APIC_STATE: 1441*1c4ee7dfSMark Johnston x2apic_state = strtol(optarg, NULL, 0); 1442*1c4ee7dfSMark Johnston set_x2apic_state = 1; 1443*1c4ee7dfSMark Johnston break; 1444*1c4ee7dfSMark Johnston case SET_RTC_TIME: 1445*1c4ee7dfSMark Johnston rtc_secs = strtoul(optarg, NULL, 0); 1446*1c4ee7dfSMark Johnston set_rtc_time = 1; 1447*1c4ee7dfSMark Johnston break; 1448*1c4ee7dfSMark Johnston case SET_RTC_NVRAM: 1449*1c4ee7dfSMark Johnston rtc_nvram_value = (uint8_t)strtoul(optarg, NULL, 0); 1450*1c4ee7dfSMark Johnston set_rtc_nvram = 1; 1451*1c4ee7dfSMark Johnston break; 1452*1c4ee7dfSMark Johnston case RTC_NVRAM_OFFSET: 1453*1c4ee7dfSMark Johnston rtc_nvram_offset = strtoul(optarg, NULL, 0); 1454*1c4ee7dfSMark Johnston break; 1455*1c4ee7dfSMark Johnston case GET_GPA_PMAP: 1456*1c4ee7dfSMark Johnston gpa_pmap = strtoul(optarg, NULL, 0); 1457*1c4ee7dfSMark Johnston get_gpa_pmap = 1; 1458*1c4ee7dfSMark Johnston break; 1459*1c4ee7dfSMark Johnston case UNASSIGN_PPTDEV: 1460*1c4ee7dfSMark Johnston unassign_pptdev = 1; 1461*1c4ee7dfSMark Johnston if (sscanf(optarg, "%d/%d/%d", &bus, &slot, &func) != 3) 1462*1c4ee7dfSMark Johnston usage(opts); 1463*1c4ee7dfSMark Johnston break; 1464*1c4ee7dfSMark Johnston case ASSERT_LAPIC_LVT: 1465*1c4ee7dfSMark Johnston assert_lapic_lvt = atoi(optarg); 1466*1c4ee7dfSMark Johnston break; 1467*1c4ee7dfSMark Johnston } 1468*1c4ee7dfSMark Johnston } 1469*1c4ee7dfSMark Johnston 1470*1c4ee7dfSMark Johnston const char * 1471*1c4ee7dfSMark Johnston bhyvectl_opt_desc(int opt) 1472*1c4ee7dfSMark Johnston { 1473*1c4ee7dfSMark Johnston switch (opt) { 1474*1c4ee7dfSMark Johnston case SET_EFER: 1475*1c4ee7dfSMark Johnston return ("EFER"); 1476*1c4ee7dfSMark Johnston case SET_CR0: 1477*1c4ee7dfSMark Johnston return ("CR0"); 1478*1c4ee7dfSMark Johnston case SET_CR2: 1479*1c4ee7dfSMark Johnston return ("CR2"); 1480*1c4ee7dfSMark Johnston case SET_CR3: 1481*1c4ee7dfSMark Johnston return ("CR3"); 1482*1c4ee7dfSMark Johnston case SET_CR4: 1483*1c4ee7dfSMark Johnston return ("CR4"); 1484*1c4ee7dfSMark Johnston case SET_DR0: 1485*1c4ee7dfSMark Johnston return ("DR0"); 1486*1c4ee7dfSMark Johnston case SET_DR1: 1487*1c4ee7dfSMark Johnston return ("DR1"); 1488*1c4ee7dfSMark Johnston case SET_DR2: 1489*1c4ee7dfSMark Johnston return ("DR2"); 1490*1c4ee7dfSMark Johnston case SET_DR3: 1491*1c4ee7dfSMark Johnston return ("DR3"); 1492*1c4ee7dfSMark Johnston case SET_DR6: 1493*1c4ee7dfSMark Johnston return ("DR6"); 1494*1c4ee7dfSMark Johnston case SET_DR7: 1495*1c4ee7dfSMark Johnston return ("DR7"); 1496*1c4ee7dfSMark Johnston case SET_RSP: 1497*1c4ee7dfSMark Johnston return ("RSP"); 1498*1c4ee7dfSMark Johnston case SET_RIP: 1499*1c4ee7dfSMark Johnston return ("RIP"); 1500*1c4ee7dfSMark Johnston case SET_RAX: 1501*1c4ee7dfSMark Johnston return ("RAX"); 1502*1c4ee7dfSMark Johnston case SET_RFLAGS: 1503*1c4ee7dfSMark Johnston return ("RFLAGS"); 1504*1c4ee7dfSMark Johnston case DESC_BASE: 1505*1c4ee7dfSMark Johnston return ("BASE"); 1506*1c4ee7dfSMark Johnston case DESC_LIMIT: 1507*1c4ee7dfSMark Johnston return ("LIMIT"); 1508*1c4ee7dfSMark Johnston case DESC_ACCESS: 1509*1c4ee7dfSMark Johnston return ("ACCESS"); 1510*1c4ee7dfSMark Johnston case SET_CS: 1511*1c4ee7dfSMark Johnston return ("CS"); 1512*1c4ee7dfSMark Johnston case SET_DS: 1513*1c4ee7dfSMark Johnston return ("DS"); 1514*1c4ee7dfSMark Johnston case SET_ES: 1515*1c4ee7dfSMark Johnston return ("ES"); 1516*1c4ee7dfSMark Johnston case SET_FS: 1517*1c4ee7dfSMark Johnston return ("FS"); 1518*1c4ee7dfSMark Johnston case SET_GS: 1519*1c4ee7dfSMark Johnston return ("GS"); 1520*1c4ee7dfSMark Johnston case SET_SS: 1521*1c4ee7dfSMark Johnston return ("SS"); 1522*1c4ee7dfSMark Johnston case SET_TR: 1523*1c4ee7dfSMark Johnston return ("TR"); 1524*1c4ee7dfSMark Johnston case SET_LDTR: 1525*1c4ee7dfSMark Johnston return ("LDTR"); 1526*1c4ee7dfSMark Johnston case SET_X2APIC_STATE: 1527*1c4ee7dfSMark Johnston return ("state"); 1528*1c4ee7dfSMark Johnston case UNASSIGN_PPTDEV: 1529*1c4ee7dfSMark Johnston return ("bus/slot.func"); 1530*1c4ee7dfSMark Johnston case GET_GPA_PMAP: 1531*1c4ee7dfSMark Johnston return ("gpa"); 1532*1c4ee7dfSMark Johnston case ASSERT_LAPIC_LVT: 1533*1c4ee7dfSMark Johnston return ("pin"); 1534*1c4ee7dfSMark Johnston case SET_RTC_TIME: 1535*1c4ee7dfSMark Johnston return ("secs"); 1536*1c4ee7dfSMark Johnston case SET_RTC_NVRAM: 1537*1c4ee7dfSMark Johnston return ("val"); 1538*1c4ee7dfSMark Johnston case RTC_NVRAM_OFFSET: 1539*1c4ee7dfSMark Johnston return ("offset"); 1540*1c4ee7dfSMark Johnston default: 1541*1c4ee7dfSMark Johnston return ("???"); 1542*1c4ee7dfSMark Johnston } 1543*1c4ee7dfSMark Johnston } 1544*1c4ee7dfSMark Johnston 1545*1c4ee7dfSMark Johnston void 1546*1c4ee7dfSMark Johnston bhyvectl_md_main(struct vmctx *ctx, struct vcpu *vcpu, int vcpuid, bool get_all) 1547*1c4ee7dfSMark Johnston { 1548*1c4ee7dfSMark Johnston struct tm tm; 1549*1c4ee7dfSMark Johnston uint64_t info[2], pteval[4], *pte; 1550*1c4ee7dfSMark Johnston uint64_t addr, bm, eptp, u64; 1551*1c4ee7dfSMark Johnston uint64_t cs, rsp, rip, pat; 1552*1c4ee7dfSMark Johnston int error, ptenum; 1553*1c4ee7dfSMark Johnston bool cpu_intel; 1554*1c4ee7dfSMark Johnston 1555*1c4ee7dfSMark Johnston cpu_intel = cpu_vendor_intel(); 1556*1c4ee7dfSMark Johnston error = 0; 1557*1c4ee7dfSMark Johnston 1558*1c4ee7dfSMark Johnston if (!error && set_efer) 1559*1c4ee7dfSMark Johnston error = vm_set_register(vcpu, VM_REG_GUEST_EFER, set_efer_val); 1560*1c4ee7dfSMark Johnston 1561*1c4ee7dfSMark Johnston if (!error && set_cr0) 1562*1c4ee7dfSMark Johnston error = vm_set_register(vcpu, VM_REG_GUEST_CR0, set_cr0_val); 1563*1c4ee7dfSMark Johnston 1564*1c4ee7dfSMark Johnston if (!error && set_cr2) 1565*1c4ee7dfSMark Johnston error = vm_set_register(vcpu, VM_REG_GUEST_CR2, set_cr2_val); 1566*1c4ee7dfSMark Johnston 1567*1c4ee7dfSMark Johnston if (!error && set_cr3) 1568*1c4ee7dfSMark Johnston error = vm_set_register(vcpu, VM_REG_GUEST_CR3, set_cr3_val); 1569*1c4ee7dfSMark Johnston 1570*1c4ee7dfSMark Johnston if (!error && set_cr4) 1571*1c4ee7dfSMark Johnston error = vm_set_register(vcpu, VM_REG_GUEST_CR4, set_cr4_val); 1572*1c4ee7dfSMark Johnston 1573*1c4ee7dfSMark Johnston if (!error && set_dr0) 1574*1c4ee7dfSMark Johnston error = vm_set_register(vcpu, VM_REG_GUEST_DR0, set_dr0_val); 1575*1c4ee7dfSMark Johnston 1576*1c4ee7dfSMark Johnston if (!error && set_dr1) 1577*1c4ee7dfSMark Johnston error = vm_set_register(vcpu, VM_REG_GUEST_DR1, set_dr1_val); 1578*1c4ee7dfSMark Johnston 1579*1c4ee7dfSMark Johnston if (!error && set_dr2) 1580*1c4ee7dfSMark Johnston error = vm_set_register(vcpu, VM_REG_GUEST_DR2, set_dr2_val); 1581*1c4ee7dfSMark Johnston 1582*1c4ee7dfSMark Johnston if (!error && set_dr3) 1583*1c4ee7dfSMark Johnston error = vm_set_register(vcpu, VM_REG_GUEST_DR3, set_dr3_val); 1584*1c4ee7dfSMark Johnston 1585*1c4ee7dfSMark Johnston if (!error && set_dr6) 1586*1c4ee7dfSMark Johnston error = vm_set_register(vcpu, VM_REG_GUEST_DR6, set_dr6_val); 1587*1c4ee7dfSMark Johnston 1588*1c4ee7dfSMark Johnston if (!error && set_dr7) 1589*1c4ee7dfSMark Johnston error = vm_set_register(vcpu, VM_REG_GUEST_DR7, set_dr7_val); 1590*1c4ee7dfSMark Johnston 1591*1c4ee7dfSMark Johnston if (!error && set_rsp) 1592*1c4ee7dfSMark Johnston error = vm_set_register(vcpu, VM_REG_GUEST_RSP, set_rsp_val); 1593*1c4ee7dfSMark Johnston 1594*1c4ee7dfSMark Johnston if (!error && set_rip) 1595*1c4ee7dfSMark Johnston error = vm_set_register(vcpu, VM_REG_GUEST_RIP, set_rip_val); 1596*1c4ee7dfSMark Johnston 1597*1c4ee7dfSMark Johnston if (!error && set_rax) 1598*1c4ee7dfSMark Johnston error = vm_set_register(vcpu, VM_REG_GUEST_RAX, set_rax_val); 1599*1c4ee7dfSMark Johnston 1600*1c4ee7dfSMark Johnston if (!error && set_rflags) 1601*1c4ee7dfSMark Johnston error = vm_set_register(vcpu, VM_REG_GUEST_RFLAGS, 1602*1c4ee7dfSMark Johnston set_rflags_val); 1603*1c4ee7dfSMark Johnston 1604*1c4ee7dfSMark Johnston if (!error && set_desc_ds) { 1605*1c4ee7dfSMark Johnston error = vm_set_desc(vcpu, VM_REG_GUEST_DS, 1606*1c4ee7dfSMark Johnston desc_base, desc_limit, desc_access); 1607*1c4ee7dfSMark Johnston } 1608*1c4ee7dfSMark Johnston 1609*1c4ee7dfSMark Johnston if (!error && set_desc_es) { 1610*1c4ee7dfSMark Johnston error = vm_set_desc(vcpu, VM_REG_GUEST_ES, 1611*1c4ee7dfSMark Johnston desc_base, desc_limit, desc_access); 1612*1c4ee7dfSMark Johnston } 1613*1c4ee7dfSMark Johnston 1614*1c4ee7dfSMark Johnston if (!error && set_desc_ss) { 1615*1c4ee7dfSMark Johnston error = vm_set_desc(vcpu, VM_REG_GUEST_SS, 1616*1c4ee7dfSMark Johnston desc_base, desc_limit, desc_access); 1617*1c4ee7dfSMark Johnston } 1618*1c4ee7dfSMark Johnston 1619*1c4ee7dfSMark Johnston if (!error && set_desc_cs) { 1620*1c4ee7dfSMark Johnston error = vm_set_desc(vcpu, VM_REG_GUEST_CS, 1621*1c4ee7dfSMark Johnston desc_base, desc_limit, desc_access); 1622*1c4ee7dfSMark Johnston } 1623*1c4ee7dfSMark Johnston 1624*1c4ee7dfSMark Johnston if (!error && set_desc_fs) { 1625*1c4ee7dfSMark Johnston error = vm_set_desc(vcpu, VM_REG_GUEST_FS, 1626*1c4ee7dfSMark Johnston desc_base, desc_limit, desc_access); 1627*1c4ee7dfSMark Johnston } 1628*1c4ee7dfSMark Johnston 1629*1c4ee7dfSMark Johnston if (!error && set_desc_gs) { 1630*1c4ee7dfSMark Johnston error = vm_set_desc(vcpu, VM_REG_GUEST_GS, 1631*1c4ee7dfSMark Johnston desc_base, desc_limit, desc_access); 1632*1c4ee7dfSMark Johnston } 1633*1c4ee7dfSMark Johnston 1634*1c4ee7dfSMark Johnston if (!error && set_desc_tr) { 1635*1c4ee7dfSMark Johnston error = vm_set_desc(vcpu, VM_REG_GUEST_TR, 1636*1c4ee7dfSMark Johnston desc_base, desc_limit, desc_access); 1637*1c4ee7dfSMark Johnston } 1638*1c4ee7dfSMark Johnston 1639*1c4ee7dfSMark Johnston if (!error && set_desc_ldtr) { 1640*1c4ee7dfSMark Johnston error = vm_set_desc(vcpu, VM_REG_GUEST_LDTR, 1641*1c4ee7dfSMark Johnston desc_base, desc_limit, desc_access); 1642*1c4ee7dfSMark Johnston } 1643*1c4ee7dfSMark Johnston 1644*1c4ee7dfSMark Johnston if (!error && set_desc_gdtr) { 1645*1c4ee7dfSMark Johnston error = vm_set_desc(vcpu, VM_REG_GUEST_GDTR, 1646*1c4ee7dfSMark Johnston desc_base, desc_limit, 0); 1647*1c4ee7dfSMark Johnston } 1648*1c4ee7dfSMark Johnston 1649*1c4ee7dfSMark Johnston if (!error && set_desc_idtr) { 1650*1c4ee7dfSMark Johnston error = vm_set_desc(vcpu, VM_REG_GUEST_IDTR, 1651*1c4ee7dfSMark Johnston desc_base, desc_limit, 0); 1652*1c4ee7dfSMark Johnston } 1653*1c4ee7dfSMark Johnston 1654*1c4ee7dfSMark Johnston if (!error && set_cs) 1655*1c4ee7dfSMark Johnston error = vm_set_register(vcpu, VM_REG_GUEST_CS, set_cs_val); 1656*1c4ee7dfSMark Johnston 1657*1c4ee7dfSMark Johnston if (!error && set_ds) 1658*1c4ee7dfSMark Johnston error = vm_set_register(vcpu, VM_REG_GUEST_DS, set_ds_val); 1659*1c4ee7dfSMark Johnston 1660*1c4ee7dfSMark Johnston if (!error && set_es) 1661*1c4ee7dfSMark Johnston error = vm_set_register(vcpu, VM_REG_GUEST_ES, set_es_val); 1662*1c4ee7dfSMark Johnston 1663*1c4ee7dfSMark Johnston if (!error && set_fs) 1664*1c4ee7dfSMark Johnston error = vm_set_register(vcpu, VM_REG_GUEST_FS, set_fs_val); 1665*1c4ee7dfSMark Johnston 1666*1c4ee7dfSMark Johnston if (!error && set_gs) 1667*1c4ee7dfSMark Johnston error = vm_set_register(vcpu, VM_REG_GUEST_GS, set_gs_val); 1668*1c4ee7dfSMark Johnston 1669*1c4ee7dfSMark Johnston if (!error && set_ss) 1670*1c4ee7dfSMark Johnston error = vm_set_register(vcpu, VM_REG_GUEST_SS, set_ss_val); 1671*1c4ee7dfSMark Johnston 1672*1c4ee7dfSMark Johnston if (!error && set_tr) 1673*1c4ee7dfSMark Johnston error = vm_set_register(vcpu, VM_REG_GUEST_TR, set_tr_val); 1674*1c4ee7dfSMark Johnston 1675*1c4ee7dfSMark Johnston if (!error && set_ldtr) 1676*1c4ee7dfSMark Johnston error = vm_set_register(vcpu, VM_REG_GUEST_LDTR, set_ldtr_val); 1677*1c4ee7dfSMark Johnston 1678*1c4ee7dfSMark Johnston if (!error && set_x2apic_state) 1679*1c4ee7dfSMark Johnston error = vm_set_x2apic_state(vcpu, x2apic_state); 1680*1c4ee7dfSMark Johnston 1681*1c4ee7dfSMark Johnston if (!error && unassign_pptdev) 1682*1c4ee7dfSMark Johnston error = vm_unassign_pptdev(ctx, bus, slot, func); 1683*1c4ee7dfSMark Johnston 1684*1c4ee7dfSMark Johnston if (!error && inject_nmi) 1685*1c4ee7dfSMark Johnston error = vm_inject_nmi(vcpu); 1686*1c4ee7dfSMark Johnston 1687*1c4ee7dfSMark Johnston if (!error && assert_lapic_lvt != -1) 1688*1c4ee7dfSMark Johnston error = vm_lapic_local_irq(vcpu, assert_lapic_lvt); 1689*1c4ee7dfSMark Johnston 1690*1c4ee7dfSMark Johnston if (!error) 1691*1c4ee7dfSMark Johnston error = get_all_registers(vcpu, vcpuid, get_all); 1692*1c4ee7dfSMark Johnston 1693*1c4ee7dfSMark Johnston if (!error) 1694*1c4ee7dfSMark Johnston error = get_all_segments(vcpu, vcpuid, get_all); 1695*1c4ee7dfSMark Johnston 1696*1c4ee7dfSMark Johnston if (!error) { 1697*1c4ee7dfSMark Johnston if (cpu_intel) 1698*1c4ee7dfSMark Johnston error = get_misc_vmcs(vcpu, vcpuid, get_all); 1699*1c4ee7dfSMark Johnston else 1700*1c4ee7dfSMark Johnston error = get_misc_vmcb(vcpu, vcpuid, get_all); 1701*1c4ee7dfSMark Johnston } 1702*1c4ee7dfSMark Johnston 1703*1c4ee7dfSMark Johnston if (!error && (get_x2apic_state || get_all)) { 1704*1c4ee7dfSMark Johnston error = vm_get_x2apic_state(vcpu, &x2apic_state); 1705*1c4ee7dfSMark Johnston if (error == 0) 1706*1c4ee7dfSMark Johnston printf("x2apic_state[%d]\t%d\n", vcpuid, x2apic_state); 1707*1c4ee7dfSMark Johnston } 1708*1c4ee7dfSMark Johnston 1709*1c4ee7dfSMark Johnston if (!error && (get_eptp || get_all)) { 1710*1c4ee7dfSMark Johnston if (cpu_intel) 1711*1c4ee7dfSMark Johnston error = vm_get_vmcs_field(vcpu, VMCS_EPTP, &eptp); 1712*1c4ee7dfSMark Johnston else 1713*1c4ee7dfSMark Johnston error = vm_get_vmcb_field(vcpu, VMCB_OFF_NPT_BASE, 8, 1714*1c4ee7dfSMark Johnston &eptp); 1715*1c4ee7dfSMark Johnston if (error == 0) 1716*1c4ee7dfSMark Johnston printf("%s[%d]\t\t0x%016lx\n", 1717*1c4ee7dfSMark Johnston cpu_intel ? "eptp" : "rvi/npt", vcpuid, eptp); 1718*1c4ee7dfSMark Johnston } 1719*1c4ee7dfSMark Johnston 1720*1c4ee7dfSMark Johnston if (!error && (get_exception_bitmap || get_all)) { 1721*1c4ee7dfSMark Johnston if (cpu_intel) 1722*1c4ee7dfSMark Johnston error = vm_get_vmcs_field(vcpu, VMCS_EXCEPTION_BITMAP, 1723*1c4ee7dfSMark Johnston &bm); 1724*1c4ee7dfSMark Johnston else 1725*1c4ee7dfSMark Johnston error = vm_get_vmcb_field(vcpu, VMCB_OFF_EXC_INTERCEPT, 1726*1c4ee7dfSMark Johnston 4, &bm); 1727*1c4ee7dfSMark Johnston if (error == 0) 1728*1c4ee7dfSMark Johnston printf("exception_bitmap[%d]\t%#lx\n", vcpuid, bm); 1729*1c4ee7dfSMark Johnston } 1730*1c4ee7dfSMark Johnston 1731*1c4ee7dfSMark Johnston if (!error && (get_io_bitmap || get_all)) { 1732*1c4ee7dfSMark Johnston if (cpu_intel) { 1733*1c4ee7dfSMark Johnston error = vm_get_vmcs_field(vcpu, VMCS_IO_BITMAP_A, &bm); 1734*1c4ee7dfSMark Johnston if (error == 0) 1735*1c4ee7dfSMark Johnston printf("io_bitmap_a[%d]\t%#lx\n", vcpuid, bm); 1736*1c4ee7dfSMark Johnston error = vm_get_vmcs_field(vcpu, VMCS_IO_BITMAP_B, &bm); 1737*1c4ee7dfSMark Johnston if (error == 0) 1738*1c4ee7dfSMark Johnston printf("io_bitmap_b[%d]\t%#lx\n", vcpuid, bm); 1739*1c4ee7dfSMark Johnston } else { 1740*1c4ee7dfSMark Johnston error = vm_get_vmcb_field(vcpu, VMCB_OFF_IO_PERM, 8, 1741*1c4ee7dfSMark Johnston &bm); 1742*1c4ee7dfSMark Johnston if (error == 0) 1743*1c4ee7dfSMark Johnston printf("io_bitmap[%d]\t%#lx\n", vcpuid, bm); 1744*1c4ee7dfSMark Johnston } 1745*1c4ee7dfSMark Johnston } 1746*1c4ee7dfSMark Johnston 1747*1c4ee7dfSMark Johnston if (!error && (get_tsc_offset || get_all)) { 1748*1c4ee7dfSMark Johnston uint64_t tscoff; 1749*1c4ee7dfSMark Johnston 1750*1c4ee7dfSMark Johnston if (cpu_intel) 1751*1c4ee7dfSMark Johnston error = vm_get_vmcs_field(vcpu, VMCS_TSC_OFFSET, 1752*1c4ee7dfSMark Johnston &tscoff); 1753*1c4ee7dfSMark Johnston else 1754*1c4ee7dfSMark Johnston error = vm_get_vmcb_field(vcpu, VMCB_OFF_TSC_OFFSET, 8, 1755*1c4ee7dfSMark Johnston &tscoff); 1756*1c4ee7dfSMark Johnston if (error == 0) 1757*1c4ee7dfSMark Johnston printf("tsc_offset[%d]\t0x%016lx\n", vcpuid, tscoff); 1758*1c4ee7dfSMark Johnston } 1759*1c4ee7dfSMark Johnston 1760*1c4ee7dfSMark Johnston if (!error && (get_msr_bitmap_address || get_all)) { 1761*1c4ee7dfSMark Johnston if (cpu_intel) 1762*1c4ee7dfSMark Johnston error = vm_get_vmcs_field(vcpu, VMCS_MSR_BITMAP, &addr); 1763*1c4ee7dfSMark Johnston else 1764*1c4ee7dfSMark Johnston error = vm_get_vmcb_field(vcpu, VMCB_OFF_MSR_PERM, 8, 1765*1c4ee7dfSMark Johnston &addr); 1766*1c4ee7dfSMark Johnston if (error == 0) 1767*1c4ee7dfSMark Johnston printf("msr_bitmap[%d]\t\t%#lx\n", vcpuid, addr); 1768*1c4ee7dfSMark Johnston } 1769*1c4ee7dfSMark Johnston 1770*1c4ee7dfSMark Johnston if (!error && (get_msr_bitmap || get_all)) { 1771*1c4ee7dfSMark Johnston if (cpu_intel) { 1772*1c4ee7dfSMark Johnston error = vm_get_vmcs_field(vcpu, VMCS_MSR_BITMAP, &addr); 1773*1c4ee7dfSMark Johnston } else { 1774*1c4ee7dfSMark Johnston error = vm_get_vmcb_field(vcpu, VMCB_OFF_MSR_PERM, 8, 1775*1c4ee7dfSMark Johnston &addr); 1776*1c4ee7dfSMark Johnston } 1777*1c4ee7dfSMark Johnston 1778*1c4ee7dfSMark Johnston if (error == 0) 1779*1c4ee7dfSMark Johnston error = dump_msr_bitmap(vcpuid, addr, cpu_intel); 1780*1c4ee7dfSMark Johnston } 1781*1c4ee7dfSMark Johnston 1782*1c4ee7dfSMark Johnston if (!error && (get_vpid_asid || get_all)) { 1783*1c4ee7dfSMark Johnston uint64_t vpid; 1784*1c4ee7dfSMark Johnston 1785*1c4ee7dfSMark Johnston if (cpu_intel) 1786*1c4ee7dfSMark Johnston error = vm_get_vmcs_field(vcpu, VMCS_VPID, &vpid); 1787*1c4ee7dfSMark Johnston else 1788*1c4ee7dfSMark Johnston error = vm_get_vmcb_field(vcpu, VMCB_OFF_ASID, 4, 1789*1c4ee7dfSMark Johnston &vpid); 1790*1c4ee7dfSMark Johnston if (error == 0) 1791*1c4ee7dfSMark Johnston printf("%s[%d]\t\t0x%04lx\n", 1792*1c4ee7dfSMark Johnston cpu_intel ? "vpid" : "asid", vcpuid, vpid); 1793*1c4ee7dfSMark Johnston } 1794*1c4ee7dfSMark Johnston 1795*1c4ee7dfSMark Johnston if (!error && (get_guest_pat || get_all)) { 1796*1c4ee7dfSMark Johnston if (cpu_intel) 1797*1c4ee7dfSMark Johnston error = vm_get_vmcs_field(vcpu, VMCS_GUEST_IA32_PAT, 1798*1c4ee7dfSMark Johnston &pat); 1799*1c4ee7dfSMark Johnston else 1800*1c4ee7dfSMark Johnston error = vm_get_vmcb_field(vcpu, VMCB_OFF_GUEST_PAT, 8, 1801*1c4ee7dfSMark Johnston &pat); 1802*1c4ee7dfSMark Johnston if (error == 0) 1803*1c4ee7dfSMark Johnston printf("guest_pat[%d]\t\t0x%016lx\n", vcpuid, pat); 1804*1c4ee7dfSMark Johnston } 1805*1c4ee7dfSMark Johnston 1806*1c4ee7dfSMark Johnston if (!error && (get_guest_sysenter || get_all)) { 1807*1c4ee7dfSMark Johnston if (cpu_intel) 1808*1c4ee7dfSMark Johnston error = vm_get_vmcs_field(vcpu, 1809*1c4ee7dfSMark Johnston VMCS_GUEST_IA32_SYSENTER_CS, &cs); 1810*1c4ee7dfSMark Johnston else 1811*1c4ee7dfSMark Johnston error = vm_get_vmcb_field(vcpu, 1812*1c4ee7dfSMark Johnston VMCB_OFF_SYSENTER_CS, 8, &cs); 1813*1c4ee7dfSMark Johnston 1814*1c4ee7dfSMark Johnston if (error == 0) 1815*1c4ee7dfSMark Johnston printf("guest_sysenter_cs[%d]\t%#lx\n", vcpuid, cs); 1816*1c4ee7dfSMark Johnston if (cpu_intel) 1817*1c4ee7dfSMark Johnston error = vm_get_vmcs_field(vcpu, 1818*1c4ee7dfSMark Johnston VMCS_GUEST_IA32_SYSENTER_ESP, &rsp); 1819*1c4ee7dfSMark Johnston else 1820*1c4ee7dfSMark Johnston error = vm_get_vmcb_field(vcpu, VMCB_OFF_SYSENTER_ESP, 1821*1c4ee7dfSMark Johnston 8, &rsp); 1822*1c4ee7dfSMark Johnston 1823*1c4ee7dfSMark Johnston if (error == 0) 1824*1c4ee7dfSMark Johnston printf("guest_sysenter_sp[%d]\t%#lx\n", vcpuid, rsp); 1825*1c4ee7dfSMark Johnston if (cpu_intel) 1826*1c4ee7dfSMark Johnston error = vm_get_vmcs_field(vcpu, 1827*1c4ee7dfSMark Johnston VMCS_GUEST_IA32_SYSENTER_EIP, &rip); 1828*1c4ee7dfSMark Johnston else 1829*1c4ee7dfSMark Johnston error = vm_get_vmcb_field(vcpu, VMCB_OFF_SYSENTER_EIP, 1830*1c4ee7dfSMark Johnston 8, &rip); 1831*1c4ee7dfSMark Johnston if (error == 0) 1832*1c4ee7dfSMark Johnston printf("guest_sysenter_ip[%d]\t%#lx\n", vcpuid, rip); 1833*1c4ee7dfSMark Johnston } 1834*1c4ee7dfSMark Johnston 1835*1c4ee7dfSMark Johnston if (!error && (get_exit_reason || get_all)) { 1836*1c4ee7dfSMark Johnston if (cpu_intel) 1837*1c4ee7dfSMark Johnston error = vm_get_vmcs_field(vcpu, VMCS_EXIT_REASON, &u64); 1838*1c4ee7dfSMark Johnston else 1839*1c4ee7dfSMark Johnston error = vm_get_vmcb_field(vcpu, VMCB_OFF_EXIT_REASON, 8, 1840*1c4ee7dfSMark Johnston &u64); 1841*1c4ee7dfSMark Johnston if (error == 0) 1842*1c4ee7dfSMark Johnston printf("exit_reason[%d]\t%#lx\n", vcpuid, u64); 1843*1c4ee7dfSMark Johnston } 1844*1c4ee7dfSMark Johnston 1845*1c4ee7dfSMark Johnston if (!error && get_gpa_pmap) { 1846*1c4ee7dfSMark Johnston error = vm_get_gpa_pmap(ctx, gpa_pmap, pteval, &ptenum); 1847*1c4ee7dfSMark Johnston if (error == 0) { 1848*1c4ee7dfSMark Johnston printf("gpa %#lx:", gpa_pmap); 1849*1c4ee7dfSMark Johnston pte = &pteval[0]; 1850*1c4ee7dfSMark Johnston while (ptenum-- > 0) 1851*1c4ee7dfSMark Johnston printf(" %#lx", *pte++); 1852*1c4ee7dfSMark Johnston printf("\n"); 1853*1c4ee7dfSMark Johnston } 1854*1c4ee7dfSMark Johnston } 1855*1c4ee7dfSMark Johnston 1856*1c4ee7dfSMark Johnston if (!error && set_rtc_nvram) 1857*1c4ee7dfSMark Johnston error = vm_rtc_write(ctx, rtc_nvram_offset, rtc_nvram_value); 1858*1c4ee7dfSMark Johnston 1859*1c4ee7dfSMark Johnston if (!error && (get_rtc_nvram || get_all)) { 1860*1c4ee7dfSMark Johnston error = vm_rtc_read(ctx, rtc_nvram_offset, &rtc_nvram_value); 1861*1c4ee7dfSMark Johnston if (error == 0) { 1862*1c4ee7dfSMark Johnston printf("rtc nvram[%03d]: 0x%02x\n", rtc_nvram_offset, 1863*1c4ee7dfSMark Johnston rtc_nvram_value); 1864*1c4ee7dfSMark Johnston } 1865*1c4ee7dfSMark Johnston } 1866*1c4ee7dfSMark Johnston 1867*1c4ee7dfSMark Johnston if (!error && set_rtc_time) 1868*1c4ee7dfSMark Johnston error = vm_rtc_settime(ctx, rtc_secs); 1869*1c4ee7dfSMark Johnston 1870*1c4ee7dfSMark Johnston if (!error && (get_rtc_time || get_all)) { 1871*1c4ee7dfSMark Johnston error = vm_rtc_gettime(ctx, &rtc_secs); 1872*1c4ee7dfSMark Johnston if (error == 0) { 1873*1c4ee7dfSMark Johnston gmtime_r(&rtc_secs, &tm); 1874*1c4ee7dfSMark Johnston printf("rtc time %#lx: %s %s %02d %02d:%02d:%02d %d\n", 1875*1c4ee7dfSMark Johnston rtc_secs, wday_str(tm.tm_wday), mon_str(tm.tm_mon), 1876*1c4ee7dfSMark Johnston tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, 1877*1c4ee7dfSMark Johnston 1900 + tm.tm_year); 1878*1c4ee7dfSMark Johnston } 1879*1c4ee7dfSMark Johnston } 1880*1c4ee7dfSMark Johnston 1881*1c4ee7dfSMark Johnston if (!error && (get_intinfo || get_all)) { 1882*1c4ee7dfSMark Johnston error = vm_get_intinfo(vcpu, &info[0], &info[1]); 1883*1c4ee7dfSMark Johnston if (!error) { 1884*1c4ee7dfSMark Johnston print_intinfo("pending", info[0]); 1885*1c4ee7dfSMark Johnston print_intinfo("current", info[1]); 1886*1c4ee7dfSMark Johnston } 1887*1c4ee7dfSMark Johnston } 1888*1c4ee7dfSMark Johnston } 1889