summaryrefslogtreecommitdiffstats
path: root/usr.sbin/vmd/loadfile_elf.c
diff options
context:
space:
mode:
authormlarkin <mlarkin@openbsd.org>2016-04-05 09:33:05 +0000
committermlarkin <mlarkin@openbsd.org>2016-04-05 09:33:05 +0000
commitfc0598878eb32875e7c5342e1216560be467b01a (patch)
tree8ee197d3ef60009baf66c2cca5d2d4a3f9a0cb4c /usr.sbin/vmd/loadfile_elf.c
parentSplit out the generic GEM code (like Linux did) and switch it over to (diff)
downloadwireguard-openbsd-fc0598878eb32875e7c5342e1216560be467b01a.tar.xz
wireguard-openbsd-fc0598878eb32875e7c5342e1216560be467b01a.zip
Support processors without unrestricted guest capability.
ok stefan
Diffstat (limited to 'usr.sbin/vmd/loadfile_elf.c')
-rw-r--r--usr.sbin/vmd/loadfile_elf.c39
1 files changed, 34 insertions, 5 deletions
diff --git a/usr.sbin/vmd/loadfile_elf.c b/usr.sbin/vmd/loadfile_elf.c
index 10a5ad80d83..8d2e68b25b0 100644
--- a/usr.sbin/vmd/loadfile_elf.c
+++ b/usr.sbin/vmd/loadfile_elf.c
@@ -1,5 +1,5 @@
/* $NetBSD: loadfile.c,v 1.10 2000/12/03 02:53:04 tsutsui Exp $ */
-/* $OpenBSD: loadfile_elf.c,v 1.12 2016/04/04 17:13:54 stefan Exp $ */
+/* $OpenBSD: loadfile_elf.c,v 1.13 2016/04/05 09:33:05 mlarkin Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -100,14 +100,11 @@
#include <machine/vmmvar.h>
#include <machine/biosvar.h>
#include <machine/segments.h>
+#include <machine/pte.h>
#include "loadfile.h"
#include "vmd.h"
-#define BOOTARGS_PAGE 0x2000
-#define GDT_PAGE 0x10000
-#define STACK_PAGE 0xF000
-
union {
Elf32_Ehdr elf32;
Elf64_Ehdr elf64;
@@ -195,6 +192,37 @@ push_gdt(void)
}
/*
+ * push_pt
+ *
+ * Create an identity-mapped page directory hierarchy mapping the first
+ * 1GB of physical memory. This is used during bootstrapping VMs on
+ * CPUs without unrestricted guest capability.
+ */
+static void
+push_pt(void)
+{
+ pt_entry_t ptes[NPTE_PG];
+ uint64_t i;
+
+ /* PML3 [0] - first 1GB */
+ memset(ptes, 0, sizeof(ptes));
+ ptes[0] = PG_V | PML3_PAGE;
+ write_mem(PML4_PAGE, ptes, PAGE_SIZE);
+
+ /* PML3 [0] - first 1GB */
+ memset(ptes, 0, sizeof(ptes));
+ ptes[0] = PG_V | PG_RW | PG_u | PML2_PAGE;
+ write_mem(PML3_PAGE, ptes, PAGE_SIZE);
+
+ /* PML2 [0..511] - first 1GB (in 2MB pages) */
+ memset(ptes, 0, sizeof(ptes));
+ for (i = 0 ; i < NPTE_PG; i++) {
+ ptes[i] = PG_V | PG_RW | PG_u | PG_PS | (NBPD_L2 * i);
+ }
+ write_mem(PML2_PAGE, ptes, PAGE_SIZE);
+}
+
+/*
* loadelf_main
*
* Loads an ELF kernel to it's defined load address in the guest VM.
@@ -234,6 +262,7 @@ loadelf_main(int fd, struct vm_create_params *vcp, struct vcpu_init_state *vis)
return (r);
push_gdt();
+ push_pt();
n = create_bios_memmap(vcp, memmap);
bootargsz = push_bootargs(memmap, n);
stacksize = push_stack(bootargsz, marks[MARK_END]);