Author: grehan
Date: Sun Mar 11 08:27:11 2018
New Revision: 330764
URL: https://svnweb.freebsd.org/changeset/base/330764

Log:
  Add CR2 get/set support.
  
  Reported/Tested by:  Fabian Freyer
  Reviewed by:  araujo
  Differential Revision:        https://reviews.freebsd.org/D14648
  MFC after:    3 weeks

Modified:
  head/usr.sbin/bhyvectl/bhyvectl.c

Modified: head/usr.sbin/bhyvectl/bhyvectl.c
==============================================================================
--- head/usr.sbin/bhyvectl/bhyvectl.c   Sun Mar 11 08:07:40 2018        
(r330763)
+++ head/usr.sbin/bhyvectl/bhyvectl.c   Sun Mar 11 08:27:11 2018        
(r330764)
@@ -109,6 +109,8 @@ usage(bool cpu_intel)
        "       [--desc-access=<ACCESS>]\n"
        "       [--set-cr0=<CR0>]\n"
        "       [--get-cr0]\n"
+       "       [--set-cr2=<CR2>]\n"
+       "       [--get-cr2]\n"
        "       [--set-cr3=<CR3>]\n"
        "       [--get-cr3]\n"
        "       [--set-cr4=<CR4>]\n"
@@ -254,7 +256,8 @@ static int create, destroy, get_memmap, get_memseg;
 static int get_intinfo;
 static int get_active_cpus, get_suspended_cpus;
 static uint64_t memsize;
-static int set_cr0, get_cr0, set_cr3, get_cr3, set_cr4, get_cr4;
+static int set_cr0, get_cr0, set_cr2, get_cr2, set_cr3, get_cr3;
+static int set_cr4, get_cr4;
 static int set_efer, get_efer;
 static int set_dr0, get_dr0;
 static int set_dr1, get_dr1;
@@ -551,6 +554,7 @@ enum {
        SET_MEM,
        SET_EFER,
        SET_CR0,
+       SET_CR2,
        SET_CR3,
        SET_CR4,
        SET_DR0,
@@ -662,7 +666,7 @@ cpu_vendor_intel(void)
 static int
 get_all_registers(struct vmctx *ctx, int vcpu)
 {
-       uint64_t cr0, cr3, cr4, dr0, dr1, dr2, dr3, dr6, dr7;
+       uint64_t cr0, cr2, cr3, cr4, dr0, dr1, dr2, dr3, dr6, dr7;
        uint64_t rsp, rip, rflags, efer;
        uint64_t rax, rbx, rcx, rdx, rsi, rdi, rbp;
        uint64_t r8, r9, r10, r11, r12, r13, r14, r15;
@@ -680,6 +684,12 @@ get_all_registers(struct vmctx *ctx, int vcpu)
                        printf("cr0[%d]\t\t0x%016lx\n", vcpu, cr0);
        }
 
+       if (!error && (get_cr2 || get_all)) {
+               error = vm_get_register(ctx, vcpu, VM_REG_GUEST_CR2, &cr2);
+               if (error == 0)
+                       printf("cr2[%d]\t\t0x%016lx\n", vcpu, cr2);
+       }
+
        if (!error && (get_cr3 || get_all)) {
                error = vm_get_register(ctx, vcpu, VM_REG_GUEST_CR3, &cr3);
                if (error == 0)
@@ -1322,6 +1332,7 @@ setup_options(bool cpu_intel)
                { "set-mem",    REQ_ARG,        0,      SET_MEM },
                { "set-efer",   REQ_ARG,        0,      SET_EFER },
                { "set-cr0",    REQ_ARG,        0,      SET_CR0 },
+               { "set-cr2",    REQ_ARG,        0,      SET_CR2 },
                { "set-cr3",    REQ_ARG,        0,      SET_CR3 },
                { "set-cr4",    REQ_ARG,        0,      SET_CR4 },
                { "set-dr0",    REQ_ARG,        0,      SET_DR0 },
@@ -1384,6 +1395,7 @@ setup_options(bool cpu_intel)
                { "get-memseg", NO_ARG,         &get_memseg,    1 },
                { "get-efer",   NO_ARG,         &get_efer,      1 },
                { "get-cr0",    NO_ARG,         &get_cr0,       1 },
+               { "get-cr2",    NO_ARG,         &get_cr2,       1 },
                { "get-cr3",    NO_ARG,         &get_cr3,       1 },
                { "get-cr4",    NO_ARG,         &get_cr4,       1 },
                { "get-dr0",    NO_ARG,         &get_dr0,       1 },
@@ -1668,7 +1680,7 @@ main(int argc, char *argv[])
        int error, ch, vcpu, ptenum;
        vm_paddr_t gpa_pmap;
        struct vm_exit vmexit;
-       uint64_t rax, cr0, cr3, cr4, dr0, dr1, dr2, dr3, dr6, dr7;
+       uint64_t rax, cr0, cr2, cr3, cr4, dr0, dr1, dr2, dr3, dr6, dr7;
        uint64_t rsp, rip, rflags, efer, pat;
        uint64_t eptp, bm, addr, u64, pteval[4], *pte, info[2];
        struct vmctx *ctx;
@@ -1708,6 +1720,10 @@ main(int argc, char *argv[])
                        cr0 = strtoul(optarg, NULL, 0);
                        set_cr0 = 1;
                        break;
+               case SET_CR2:
+                       cr2 = strtoul(optarg, NULL, 0);
+                       set_cr2 = 1;
+                       break;
                case SET_CR3:
                        cr3 = strtoul(optarg, NULL, 0);
                        set_cr3 = 1;
@@ -1870,6 +1886,9 @@ main(int argc, char *argv[])
 
        if (!error && set_cr0)
                error = vm_set_register(ctx, vcpu, VM_REG_GUEST_CR0, cr0);
+
+       if (!error && set_cr2)
+               error = vm_set_register(ctx, vcpu, VM_REG_GUEST_CR2, cr2);
 
        if (!error && set_cr3)
                error = vm_set_register(ctx, vcpu, VM_REG_GUEST_CR3, cr3);
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to