Page MenuHomeFreeBSD

D61737.1795166064.diff
No OneTemporary

Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None

D61737.1795166064.diff

diff --git a/sys/riscv/vmm/riscv.h b/sys/riscv/vmm/riscv.h
--- a/sys/riscv/vmm/riscv.h
+++ b/sys/riscv/vmm/riscv.h
@@ -92,6 +92,9 @@
struct hyp *hyp;
struct vcpu *vcpu;
bool has_exception;
+ uint64_t exception_scause;
+ uint64_t exception_stval;
+ uint64_t exception_sepc;
int cpu_id;
int ipi_pending;
int interrupts_pending;
diff --git a/sys/riscv/vmm/vmm_riscv.c b/sys/riscv/vmm/vmm_riscv.c
--- a/sys/riscv/vmm/vmm_riscv.c
+++ b/sys/riscv/vmm/vmm_riscv.c
@@ -693,9 +693,8 @@
if (hypctx->has_exception) {
hypctx->has_exception = false;
- /*
- * TODO: implement exception injection.
- */
+ riscv_inject_exception(hypctx, hypctx->exception_scause,
+ hypctx->exception_stval, hypctx->exception_sepc);
}
val = intr_disable();
@@ -967,9 +966,12 @@
panic("%s: %s%d is running", __func__, vm_name(hypctx->hyp->vm),
vcpu_vcpuid(hypctx->vcpu));
- /* TODO: implement me. */
+ hypctx->exception_scause = scause;
+ hypctx->exception_stval = 0;
+ hypctx->exception_sepc = hypctx->guest_regs.hyp_sepc;
+ hypctx->has_exception = true;
- return (ENOSYS);
+ return (0);
}
int
diff --git a/usr.sbin/bhyve/riscv/Makefile.inc b/usr.sbin/bhyve/riscv/Makefile.inc
--- a/usr.sbin/bhyve/riscv/Makefile.inc
+++ b/usr.sbin/bhyve/riscv/Makefile.inc
@@ -1,6 +1,6 @@
SRCS+= \
fdt.c \
- mem_md.c
+ mem_riscv.c
.PATH: ${BHYVE_SYSDIR}/sys/riscv/vmm
SRCS+= vmm_instruction_emul.c
diff --git a/usr.sbin/bhyve/riscv/mem_riscv.c b/usr.sbin/bhyve/riscv/mem_riscv.c
new file mode 100644
--- /dev/null
+++ b/usr.sbin/bhyve/riscv/mem_riscv.c
@@ -0,0 +1,49 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2026 Doongar Singh <doonbsd@gmail.com>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+#define _WANT_KERNEL_ERRNO 1
+#include <sys/errno.h>
+#include <sys/tree.h>
+
+#include <machine/riscvreg.h>
+#include <machine/vmm.h>
+#include <machine/vmm_instruction_emul.h>
+
+#include <vmmapi.h>
+
+#include "mem.h"
+
+int
+mmio_handle_non_backed_mem(struct vcpu *vcpu, uint64_t paddr __unused,
+ struct mem_range **mr_paramp __unused)
+{
+ int err;
+
+ err = vm_inject_exception(vcpu, SCAUSE_LOAD_ACCESS_FAULT);
+ return (err != 0 ? err : EJUSTRETURN);
+}

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 20, 9:14 AM (19 h, 46 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41862990
Default Alt Text
D61737.1795166064.diff (3 KB)

Event Timeline