003 File Manager
Current Path:
/usr/src/usr.sbin/bhyve
usr
/
src
/
usr.sbin
/
bhyve
/
📁
..
📄
Makefile
(2.18 KB)
📄
Makefile.depend
(434 B)
📄
Makefile.depend.options
(115 B)
📄
acpi.c
(29.64 KB)
📄
acpi.h
(2.26 KB)
📄
ahci.h
(10.72 KB)
📄
atkbdc.c
(15.5 KB)
📄
atkbdc.h
(1.66 KB)
📄
audio.c
(6.84 KB)
📄
audio.h
(2.91 KB)
📄
bhyve.8
(18.81 KB)
📄
bhyvegc.c
(2.76 KB)
📄
bhyvegc.h
(1.83 KB)
📄
bhyverun.c
(33 KB)
📄
bhyverun.h
(2.06 KB)
📄
block_if.c
(21.38 KB)
📄
block_if.h
(3.37 KB)
📄
bootrom.c
(4.92 KB)
📄
bootrom.h
(1.8 KB)
📄
console.c
(3 KB)
📄
console.h
(2.18 KB)
📄
debug.h
(1.74 KB)
📄
fwctl.c
(9.7 KB)
📄
fwctl.h
(1.87 KB)
📄
gdb.c
(37.2 KB)
📄
gdb.h
(1.65 KB)
📄
hda_codec.c
(24.56 KB)
📄
hda_reg.h
(57.84 KB)
📄
hdac_reg.h
(10.96 KB)
📄
inout.c
(6.97 KB)
📄
inout.h
(2.54 KB)
📄
ioapic.c
(2.45 KB)
📄
ioapic.h
(1.65 KB)
📄
iov.c
(3.47 KB)
📄
iov.h
(1.93 KB)
📄
kernemu_dev.c
(2.95 KB)
📄
kernemu_dev.h
(1.44 KB)
📄
mem.c
(8.78 KB)
📄
mem.h
(2.31 KB)
📄
mevent.c
(9.86 KB)
📄
mevent.h
(1.95 KB)
📄
mevent_test.c
(5.36 KB)
📄
mptbl.c
(9.44 KB)
📄
mptbl.h
(1.53 KB)
📄
net_backends.c
(24.6 KB)
📄
net_backends.h
(4.19 KB)
📄
net_utils.c
(3.04 KB)
📄
net_utils.h
(1.67 KB)
📄
pci_ahci.c
(64.56 KB)
📄
pci_e82545.c
(65.54 KB)
📄
pci_emul.c
(54.54 KB)
📄
pci_emul.h
(8.47 KB)
📄
pci_fbuf.c
(10.34 KB)
📄
pci_hda.c
(30.87 KB)
📄
pci_hda.h
(2.73 KB)
📄
pci_hostbridge.c
(2.43 KB)
📄
pci_irq.c
(9.19 KB)
📄
pci_irq.h
(1.85 KB)
📄
pci_lpc.c
(11.06 KB)
📄
pci_lpc.h
(2.41 KB)
📄
pci_nvme.c
(73.14 KB)
📄
pci_passthru.c
(22.85 KB)
📄
pci_uart.c
(3.2 KB)
📄
pci_virtio_9p.c
(9.1 KB)
📄
pci_virtio_block.c
(15.89 KB)
📄
pci_virtio_console.c
(15.86 KB)
📄
pci_virtio_net.c
(20.05 KB)
📄
pci_virtio_rnd.c
(5.23 KB)
📄
pci_virtio_scsi.c
(19.95 KB)
📄
pci_xhci.c
(80.6 KB)
📄
pci_xhci.h
(13.02 KB)
📄
pctestdev.c
(6.3 KB)
📄
pctestdev.h
(1.65 KB)
📄
pm.c
(8.9 KB)
📄
post.c
(1.8 KB)
📄
ps2kbd.c
(10.24 KB)
📄
ps2kbd.h
(1.8 KB)
📄
ps2mouse.c
(9.85 KB)
📄
ps2mouse.h
(1.94 KB)
📄
rfb.c
(25.9 KB)
📄
rfb.h
(1.56 KB)
📄
rtc.c
(3.4 KB)
📄
rtc.h
(1.52 KB)
📄
smbiostbl.c
(25.33 KB)
📄
smbiostbl.h
(1.54 KB)
📄
snapshot.c
(38.16 KB)
📄
snapshot.h
(3.51 KB)
📄
sockstream.c
(2.16 KB)
📄
sockstream.h
(1.54 KB)
📄
spinup_ap.c
(3 KB)
📄
spinup_ap.h
(1.5 KB)
📄
task_switch.c
(25.78 KB)
📄
uart_emul.c
(15.75 KB)
📄
uart_emul.h
(1.99 KB)
📄
usb_emul.c
(2.3 KB)
📄
usb_emul.h
(4.56 KB)
📄
usb_mouse.c
(19.9 KB)
📄
vga.c
(33.42 KB)
📄
vga.h
(5.32 KB)
📄
virtio.c
(25.01 KB)
📄
virtio.h
(18.67 KB)
📄
vmgenc.c
(3.27 KB)
📄
vmgenc.h
(1.48 KB)
📄
xmsr.c
(5.28 KB)
📄
xmsr.h
(1.59 KB)
Editing: inout.c
/*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2011 NetApp, Inc. * All rights reserved. * * 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 NETAPP, INC ``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 NETAPP, INC 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. * * $FreeBSD$ */ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); #include <sys/param.h> #include <sys/linker_set.h> #include <sys/_iovec.h> #include <sys/mman.h> #include <x86/psl.h> #include <x86/segments.h> #include <machine/vmm.h> #include <machine/vmm_instruction_emul.h> #include <vmmapi.h> #include <stdio.h> #include <string.h> #include <assert.h> #include "bhyverun.h" #include "inout.h" SET_DECLARE(inout_port_set, struct inout_port); #define MAX_IOPORTS (1 << 16) #define VERIFY_IOPORT(port, size) \ assert((port) >= 0 && (size) > 0 && ((port) + (size)) <= MAX_IOPORTS) static struct { const char *name; int flags; inout_func_t handler; void *arg; } inout_handlers[MAX_IOPORTS]; static int default_inout(struct vmctx *ctx, int vcpu, int in, int port, int bytes, uint32_t *eax, void *arg) { if (in) { switch (bytes) { case 4: *eax = 0xffffffff; break; case 2: *eax = 0xffff; break; case 1: *eax = 0xff; break; } } return (0); } static void register_default_iohandler(int start, int size) { struct inout_port iop; VERIFY_IOPORT(start, size); bzero(&iop, sizeof(iop)); iop.name = "default"; iop.port = start; iop.size = size; iop.flags = IOPORT_F_INOUT | IOPORT_F_DEFAULT; iop.handler = default_inout; register_inout(&iop); } int emulate_inout(struct vmctx *ctx, int vcpu, struct vm_exit *vmexit, int strict) { int addrsize, bytes, flags, in, port, prot, rep; uint32_t eax, val; inout_func_t handler; void *arg; int error, fault, retval; enum vm_reg_name idxreg; uint64_t gla, index, iterations, count; struct vm_inout_str *vis; struct iovec iov[2]; bytes = vmexit->u.inout.bytes; in = vmexit->u.inout.in; port = vmexit->u.inout.port; assert(port < MAX_IOPORTS); assert(bytes == 1 || bytes == 2 || bytes == 4); handler = inout_handlers[port].handler; if (strict && handler == default_inout) return (-1); flags = inout_handlers[port].flags; arg = inout_handlers[port].arg; if (in) { if (!(flags & IOPORT_F_IN)) return (-1); } else { if (!(flags & IOPORT_F_OUT)) return (-1); } retval = 0; if (vmexit->u.inout.string) { vis = &vmexit->u.inout_str; rep = vis->inout.rep; addrsize = vis->addrsize; prot = in ? PROT_WRITE : PROT_READ; assert(addrsize == 2 || addrsize == 4 || addrsize == 8); /* Index register */ idxreg = in ? VM_REG_GUEST_RDI : VM_REG_GUEST_RSI; index = vis->index & vie_size2mask(addrsize); /* Count register */ count = vis->count & vie_size2mask(addrsize); /* Limit number of back-to-back in/out emulations to 16 */ iterations = MIN(count, 16); while (iterations > 0) { assert(retval == 0); if (vie_calculate_gla(vis->paging.cpu_mode, vis->seg_name, &vis->seg_desc, index, bytes, addrsize, prot, &gla)) { vm_inject_gp(ctx, vcpu); break; } error = vm_copy_setup(ctx, vcpu, &vis->paging, gla, bytes, prot, iov, nitems(iov), &fault); if (error) { retval = -1; /* Unrecoverable error */ break; } else if (fault) { retval = 0; /* Resume guest to handle fault */ break; } if (vie_alignment_check(vis->paging.cpl, bytes, vis->cr0, vis->rflags, gla)) { vm_inject_ac(ctx, vcpu, 0); break; } val = 0; if (!in) vm_copyin(ctx, vcpu, iov, &val, bytes); retval = handler(ctx, vcpu, in, port, bytes, &val, arg); if (retval != 0) break; if (in) vm_copyout(ctx, vcpu, &val, iov, bytes); /* Update index */ if (vis->rflags & PSL_D) index -= bytes; else index += bytes; count--; iterations--; } /* Update index register */ error = vie_update_register(ctx, vcpu, idxreg, index, addrsize); assert(error == 0); /* * Update count register only if the instruction had a repeat * prefix. */ if (rep) { error = vie_update_register(ctx, vcpu, VM_REG_GUEST_RCX, count, addrsize); assert(error == 0); } /* Restart the instruction if more iterations remain */ if (retval == 0 && count != 0) { error = vm_restart_instruction(ctx, vcpu); assert(error == 0); } } else { eax = vmexit->u.inout.eax; val = eax & vie_size2mask(bytes); retval = handler(ctx, vcpu, in, port, bytes, &val, arg); if (retval == 0 && in) { eax &= ~vie_size2mask(bytes); eax |= val & vie_size2mask(bytes); error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RAX, eax); assert(error == 0); } } return (retval); } void init_inout(void) { struct inout_port **iopp, *iop; /* * Set up the default handler for all ports */ register_default_iohandler(0, MAX_IOPORTS); /* * Overwrite with specified handlers */ SET_FOREACH(iopp, inout_port_set) { iop = *iopp; assert(iop->port < MAX_IOPORTS); inout_handlers[iop->port].name = iop->name; inout_handlers[iop->port].flags = iop->flags; inout_handlers[iop->port].handler = iop->handler; inout_handlers[iop->port].arg = NULL; } } int register_inout(struct inout_port *iop) { int i; VERIFY_IOPORT(iop->port, iop->size); /* * Verify that the new registration is not overwriting an already * allocated i/o range. */ if ((iop->flags & IOPORT_F_DEFAULT) == 0) { for (i = iop->port; i < iop->port + iop->size; i++) { if ((inout_handlers[i].flags & IOPORT_F_DEFAULT) == 0) return (-1); } } for (i = iop->port; i < iop->port + iop->size; i++) { inout_handlers[i].name = iop->name; inout_handlers[i].flags = iop->flags; inout_handlers[i].handler = iop->handler; inout_handlers[i].arg = iop->arg; } return (0); } int unregister_inout(struct inout_port *iop) { VERIFY_IOPORT(iop->port, iop->size); assert(inout_handlers[iop->port].name == iop->name); register_default_iohandler(iop->port, iop->size); return (0); }
Upload File
Create Folder