Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 15 Apr 2018 20:29:38 +0000 (UTC)
From:      Peter Grehan <grehan@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r332517 - stable/11/usr.sbin/bhyvectl
Message-ID:  <201804152029.w3FKTcwt095298@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: grehan
Date: Sun Apr 15 20:29:37 2018
New Revision: 332517
URL: https://svnweb.freebsd.org/changeset/base/332517

Log:
  MFC r330764
    Add CR2 get/set support.

Modified:
  stable/11/usr.sbin/bhyvectl/bhyvectl.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/usr.sbin/bhyvectl/bhyvectl.c
==============================================================================
--- stable/11/usr.sbin/bhyvectl/bhyvectl.c	Sun Apr 15 20:20:08 2018	(r332516)
+++ stable/11/usr.sbin/bhyvectl/bhyvectl.c	Sun Apr 15 20:29:37 2018	(r332517)
@@ -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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201804152029.w3FKTcwt095298>