diff options
author | Mike Larkin <mlarkin@cvs.openbsd.org> | 2016-10-26 05:26:37 +0000 |
---|---|---|
committer | Mike Larkin <mlarkin@cvs.openbsd.org> | 2016-10-26 05:26:37 +0000 |
commit | 4f21a2942d88621575eca8a2abf806f5209b034f (patch) | |
tree | 6008fe8c478fb4676c6ee554e6fbdb8a2ecef136 /usr.sbin | |
parent | bfd35f95c6162a15c5969800e38e1f9f245da99f (diff) |
vmd(8)/vmctl(8) for i386. Some ugliness in #ifdef __i386__ areas will be
fixed in tree, but the changes required were pretty minimal.
Note that i386 hosts are still presently limited to running i386 guests.
ok deraadt, stefan, jca
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/vmctl/Makefile | 4 | ||||
-rw-r--r-- | usr.sbin/vmd/Makefile | 4 | ||||
-rw-r--r-- | usr.sbin/vmd/i8253.c | 4 | ||||
-rw-r--r-- | usr.sbin/vmd/loadfile_elf.c | 40 | ||||
-rw-r--r-- | usr.sbin/vmd/mc146818.c | 4 | ||||
-rw-r--r-- | usr.sbin/vmd/ns8250.c | 4 | ||||
-rw-r--r-- | usr.sbin/vmd/vmm.c | 8 |
7 files changed, 56 insertions, 12 deletions
diff --git a/usr.sbin/vmctl/Makefile b/usr.sbin/vmctl/Makefile index 2f7dc99ef8e..cf5e25aebc1 100644 --- a/usr.sbin/vmctl/Makefile +++ b/usr.sbin/vmctl/Makefile @@ -1,6 +1,6 @@ -# $OpenBSD: Makefile,v 1.2 2015/12/05 20:26:38 reyk Exp $ +# $OpenBSD: Makefile,v 1.3 2016/10/26 05:26:36 mlarkin Exp $ -.if ${MACHINE} == "amd64" +.if ${MACHINE} == "amd64" || ${MACHINE} == "i386" PROG= vmctl SRCS= vmctl.c main.c diff --git a/usr.sbin/vmd/Makefile b/usr.sbin/vmd/Makefile index 3fe88e58824..e85c5e98aa7 100644 --- a/usr.sbin/vmd/Makefile +++ b/usr.sbin/vmd/Makefile @@ -1,6 +1,6 @@ -# $OpenBSD: Makefile,v 1.9 2016/10/04 17:17:30 reyk Exp $ +# $OpenBSD: Makefile,v 1.10 2016/10/26 05:26:36 mlarkin Exp $ -.if ${MACHINE} == "amd64" +.if ${MACHINE} == "amd64" || ${MACHINE} == "i386" PROG= vmd SRCS= vmm.c loadfile_elf.c pci.c virtio.c i8259.c mc146818.c diff --git a/usr.sbin/vmd/i8253.c b/usr.sbin/vmd/i8253.c index 994a495f650..f3daf5449b9 100644 --- a/usr.sbin/vmd/i8253.c +++ b/usr.sbin/vmd/i8253.c @@ -1,4 +1,4 @@ -/* $OpenBSD: i8253.c,v 1.3 2016/10/03 06:00:17 mlarkin Exp $ */ +/* $OpenBSD: i8253.c,v 1.4 2016/10/26 05:26:36 mlarkin Exp $ */ /* * Copyright (c) 2016 Mike Larkin <mlarkin@openbsd.org> * @@ -55,7 +55,7 @@ i8253_init(uint32_t vm_id) i8253_counter[0].start = 0xFFFF; i8253_counter[0].mode = TIMER_RATEGEN; evtimer_set(&i8253_counter[0].timer, i8253_fire, - (void *)(uint64_t)vm_id); + (void *)(intptr_t)vm_id); i8253_reset(0); } diff --git a/usr.sbin/vmd/loadfile_elf.c b/usr.sbin/vmd/loadfile_elf.c index 501ffd049d2..544795ee832 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.19 2016/09/17 17:39:34 jasper Exp $ */ +/* $OpenBSD: loadfile_elf.c,v 1.20 2016/10/26 05:26:36 mlarkin Exp $ */ /*- * Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -110,8 +110,14 @@ union { Elf64_Ehdr elf64; } hdr; +#ifdef __i386__ +typedef uint32_t pt_entry_t; +static void setsegment(struct segment_descriptor *, uint32_t, + size_t, int, int, int, int); +#else static void setsegment(struct mem_segment_descriptor *, uint32_t, size_t, int, int, int, int); +#endif static int elf32_exec(int, Elf32_Ehdr *, u_long *, int); static int elf64_exec(int, Elf64_Ehdr *, u_long *, int); static size_t create_bios_memmap(struct vm_create_params *, bios_memmap_t *); @@ -144,9 +150,15 @@ extern int vm_id; * def32: default 16/32 bit size of the segment * gran: granularity of the segment (byte/page) */ +#ifdef __i386__ +static void +setsegment(struct segment_descriptor *sd, uint32_t base, size_t limit, + int type, int dpl, int def32, int gran) +#else static void setsegment(struct mem_segment_descriptor *sd, uint32_t base, size_t limit, int type, int dpl, int def32, int gran) +#endif { sd->sd_lolimit = (int)limit; sd->sd_lobase = (int)base; @@ -154,8 +166,12 @@ setsegment(struct mem_segment_descriptor *sd, uint32_t base, size_t limit, sd->sd_dpl = dpl; sd->sd_p = 1; sd->sd_hilimit = (int)limit >> 16; +#ifdef __i386__ + sd->sd_xx = 0; +#else sd->sd_avl = 0; sd->sd_long = 0; +#endif sd->sd_def32 = def32; sd->sd_gran = gran; sd->sd_hibase = (int)base >> 24; @@ -173,10 +189,19 @@ static void push_gdt(void) { uint8_t gdtpage[PAGE_SIZE]; +#ifdef __i386__ + struct segment_descriptor *sd; +#else struct mem_segment_descriptor *sd; +#endif memset(&gdtpage, 0, sizeof(gdtpage)); + +#ifdef __i386__ + sd = (struct segment_descriptor *)&gdtpage; +#else sd = (struct mem_segment_descriptor *)&gdtpage; +#endif /* * Create three segment descriptors: @@ -204,6 +229,13 @@ push_pt(void) pt_entry_t ptes[NPTE_PG]; uint64_t i; +#ifdef __i386__ + memset(ptes, 0, sizeof(ptes)); + for (i = 0 ; i < NPTE_PG; i++) { + ptes[i] = PG_V | PG_PS | (NBPD * i); + } + write_mem(PML4_PAGE, ptes, PAGE_SIZE); +#else /* PML3 [0] - first 1GB */ memset(ptes, 0, sizeof(ptes)); ptes[0] = PG_V | PML3_PAGE; @@ -220,6 +252,7 @@ push_pt(void) ptes[i] = PG_V | PG_RW | PG_u | PG_PS | (NBPD_L2 * i); } write_mem(PML2_PAGE, ptes, PAGE_SIZE); +#endif } /* @@ -267,8 +300,13 @@ loadelf_main(int fd, struct vm_create_params *vcp, struct vcpu_reg_state *vrs) bootargsz = push_bootargs(memmap, n); stacksize = push_stack(bootargsz, marks[MARK_END]); +#ifdef __i386__ + vrs->vrs_gprs[VCPU_REGS_EIP] = (uint32_t)marks[MARK_ENTRY]; + vrs->vrs_gprs[VCPU_REGS_ESP] = (uint32_t)(STACK_PAGE + PAGE_SIZE) - stacksize; +#else vrs->vrs_gprs[VCPU_REGS_RIP] = (uint64_t)marks[MARK_ENTRY]; vrs->vrs_gprs[VCPU_REGS_RSP] = (uint64_t)(STACK_PAGE + PAGE_SIZE) - stacksize; +#endif vrs->vrs_gdtr.vsi_base = GDT_PAGE; return (0); diff --git a/usr.sbin/vmd/mc146818.c b/usr.sbin/vmd/mc146818.c index 3962b531e7c..b77c1617be0 100644 --- a/usr.sbin/vmd/mc146818.c +++ b/usr.sbin/vmd/mc146818.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mc146818.c,v 1.3 2016/10/03 06:00:17 mlarkin Exp $ */ +/* $OpenBSD: mc146818.c,v 1.4 2016/10/26 05:26:36 mlarkin Exp $ */ /* * Copyright (c) 2016 Mike Larkin <mlarkin@openbsd.org> * @@ -142,7 +142,7 @@ mc146818_init(uint32_t vm_id) evtimer_set(&rtc.sec, rtc_fire1, NULL); evtimer_add(&rtc.sec, &rtc.sec_tv); - evtimer_set(&rtc.per, rtc_fireper, (void *)(uint64_t)rtc.vm_id); + evtimer_set(&rtc.per, rtc_fireper, (void *)(intptr_t)rtc.vm_id); } /* diff --git a/usr.sbin/vmd/ns8250.c b/usr.sbin/vmd/ns8250.c index 732dea10535..b80517ac2b7 100644 --- a/usr.sbin/vmd/ns8250.c +++ b/usr.sbin/vmd/ns8250.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ns8250.c,v 1.5 2016/10/03 06:00:17 mlarkin Exp $ */ +/* $OpenBSD: ns8250.c,v 1.6 2016/10/26 05:26:36 mlarkin Exp $ */ /* * Copyright (c) 2016 Mike Larkin <mlarkin@openbsd.org> * @@ -54,7 +54,7 @@ ns8250_init(int fd, uint32_t vmid) com1_dev.rcv_pending = 0; event_set(&com1_dev.event, com1_dev.fd, EV_READ | EV_PERSIST, - com_rcv_event, (void *)(uint64_t)vmid); + com_rcv_event, (void *)(intptr_t)vmid); event_add(&com1_dev.event, NULL); } diff --git a/usr.sbin/vmd/vmm.c b/usr.sbin/vmd/vmm.c index aae985dec83..c7ff4ec9bd2 100644 --- a/usr.sbin/vmd/vmm.c +++ b/usr.sbin/vmd/vmm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vmm.c,v 1.51 2016/10/12 19:10:03 reyk Exp $ */ +/* $OpenBSD: vmm.c,v 1.52 2016/10/26 05:26:36 mlarkin Exp $ */ /* * Copyright (c) 2015 Mike Larkin <mlarkin@openbsd.org> @@ -122,9 +122,15 @@ static struct privsep_proc procs[] = { * features of the CPU in use. */ static const struct vcpu_reg_state vcpu_init_flat32 = { +#ifdef __i386__ + .vrs_gprs[VCPU_REGS_EFLAGS] = 0x2, + .vrs_gprs[VCPU_REGS_EIP] = 0x0, + .vrs_gprs[VCPU_REGS_ESP] = 0x0, +#else .vrs_gprs[VCPU_REGS_RFLAGS] = 0x2, .vrs_gprs[VCPU_REGS_RIP] = 0x0, .vrs_gprs[VCPU_REGS_RSP] = 0x0, +#endif .vrs_crs[VCPU_REGS_CR0] = CR0_CD | CR0_NW | CR0_ET | CR0_PE | CR0_PG, .vrs_crs[VCPU_REGS_CR3] = PML4_PAGE, .vrs_sregs[VCPU_REGS_CS] = { 0x8, 0xFFFFFFFF, 0xC09F, 0x0}, |