Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 23 Jul 2015 17:53:56 GMT
From:      mihai@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r288696 - in soc2015/mihai/bhyve-on-arm-head/sys/arm: include vmm
Message-ID:  <201507231753.t6NHrube035443@socsvn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mihai
Date: Thu Jul 23 17:53:55 2015
New Revision: 288696
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=288696

Log:
  soc2015: mihai: bhyve: sys: arm: vmm: add vmm_instruction_emul

Added:
  soc2015/mihai/bhyve-on-arm-head/sys/arm/include/vmm_instruction_emul.h
  soc2015/mihai/bhyve-on-arm-head/sys/arm/vmm/vmm_instruction_emul.c

Added: soc2015/mihai/bhyve-on-arm-head/sys/arm/include/vmm_instruction_emul.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ soc2015/mihai/bhyve-on-arm-head/sys/arm/include/vmm_instruction_emul.h	Thu Jul 23 17:53:55 2015	(r288696)
@@ -0,0 +1,29 @@
+#ifndef	_VMM_INSTRUCTION_EMUL_H_
+#define	_VMM_INSTRUCTION_EMUL_H_
+
+#include <sys/mman.h>
+
+/*
+ * Callback functions to read and write memory regions.
+ */
+typedef int (*mem_region_read_t)(void *vm, int cpuid, uint64_t gpa,
+				 uint64_t *rval, int rsize, void *arg);
+
+typedef int (*mem_region_write_t)(void *vm, int cpuid, uint64_t gpa,
+				  uint64_t wval, int wsize, void *arg);
+
+/*
+ * Emulate the decoded 'vie' instruction.
+ *
+ * The callbacks 'mrr' and 'mrw' emulate reads and writes to the memory region
+ * containing 'gpa'. 'mrarg' is an opaque argument that is passed into the
+ * callback functions.
+ *
+ * 'void *vm' should be 'struct vm *' when called from kernel context and
+ * 'struct vmctx *' when called from user context.
+ * s
+ */
+int vmm_emulate_instruction(void *vm, int cpuid, uint64_t gpa, struct vie *vie,
+    mem_region_read_t mrr, mem_region_write_t mrw, void *mrarg);
+
+#endif	/* _VMM_INSTRUCTION_EMUL_H_ */

Added: soc2015/mihai/bhyve-on-arm-head/sys/arm/vmm/vmm_instruction_emul.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ soc2015/mihai/bhyve-on-arm-head/sys/arm/vmm/vmm_instruction_emul.c	Thu Jul 23 17:53:55 2015	(r288696)
@@ -0,0 +1,50 @@
+#ifdef _KERNEL
+#include <sys/param.h>
+#include <sys/pcpu.h>
+#include <sys/systm.h>
+#include <sys/proc.h>
+
+#include <vm/vm.h>
+
+#include <machine/vmm.h>
+
+#else
+#include <sys/types.h>
+#include <sys/errno.h>
+#include <sys/_iovec.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <machine/vmm.h>
+
+#include <assert.h>
+#include <vmmapi.h>
+#endif
+
+#include <machine/vmm_instruction_emul.h>
+
+int
+vmm_emulate_instruction(void *vm, int vcpuid, uint64_t gpa, struct vie *vie,
+    mem_region_read_t memread, mem_region_write_t memwrite, void *memarg)
+{
+	int error;
+	uint64_t val;
+
+	if(vie->dir) {
+		printf("%s write\n",__func__);
+		error = vm_get_register(vm, vcpuid, vie->reg, &val);
+		if (error)
+			goto out;
+
+		error = memwrite(vm, vcpuid, gpa, val, vie->access_size, memarg);
+	} else {
+		printf("%s read\n",__func__);
+
+		error = memread(vm, vcpuid, gpa, &val, vie->access_size, memarg);
+		if (error)
+			goto out;
+		error = vm_set_register(vm, vcpuid, vie->reg, val);
+	}
+out:
+	return (error);
+}



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