Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/bhyve/bhyverun.c
Show First 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | |||||
#include "pci_emul.h" | #include "pci_emul.h" | ||||
#include "pci_irq.h" | #include "pci_irq.h" | ||||
#include "pci_lpc.h" | #include "pci_lpc.h" | ||||
#include "smbiostbl.h" | #include "smbiostbl.h" | ||||
#include "xmsr.h" | #include "xmsr.h" | ||||
#include "spinup_ap.h" | #include "spinup_ap.h" | ||||
#include "rtc.h" | #include "rtc.h" | ||||
#include "config.h" | |||||
#include <ucl.h> | |||||
#define GUEST_NIO_PORT 0x488 /* guest upcalls via i/o port */ | #define GUEST_NIO_PORT 0x488 /* guest upcalls via i/o port */ | ||||
#define MB (1024UL * 1024) | #define MB (1024UL * 1024) | ||||
#define GB (1024UL * MB) | #define GB (1024UL * MB) | ||||
typedef int (*vmexit_handler_t)(struct vmctx *, struct vm_exit *, int *vcpu); | typedef int (*vmexit_handler_t)(struct vmctx *, struct vm_exit *, int *vcpu); | ||||
extern int vmexit_task_switch(struct vmctx *, struct vm_exit *, int *vcpu); | extern int vmexit_task_switch(struct vmctx *, struct vm_exit *, int *vcpu); | ||||
▲ Show 20 Lines • Show All 614 Lines • ▼ Show 20 Lines | |||||
main(int argc, char *argv[]) | main(int argc, char *argv[]) | ||||
{ | { | ||||
int c, error, gdb_port, err, bvmcons; | int c, error, gdb_port, err, bvmcons; | ||||
int dump_guest_memory, max_vcpus, mptgen; | int dump_guest_memory, max_vcpus, mptgen; | ||||
int rtc_localtime; | int rtc_localtime; | ||||
struct vmctx *ctx; | struct vmctx *ctx; | ||||
uint64_t rip; | uint64_t rip; | ||||
size_t memsize; | size_t memsize; | ||||
struct config_entry cb; | |||||
char temp[STR_SIZE]; | |||||
char *multiface, *multidisk = NULL; | |||||
int slot = 0; | |||||
bvmcons = 0; | bvmcons = 0; | ||||
dump_guest_memory = 0; | dump_guest_memory = 0; | ||||
progname = basename(argv[0]); | progname = basename(argv[0]); | ||||
gdb_port = 0; | gdb_port = 0; | ||||
guest_ncpus = 1; | guest_ncpus = 1; | ||||
memsize = 256 * MB; | memsize = 256 * MB; | ||||
mptgen = 1; | mptgen = 1; | ||||
rtc_localtime = 1; | rtc_localtime = 1; | ||||
while ((c = getopt(argc, argv, "abehuwxACHIPWYp:g:c:s:m:l:U:")) != -1) { | while ((c = getopt(argc, argv, "abehuwxACHIPWYp:g:c:s:m:l:U:f:")) != -1) { | ||||
switch (c) { | switch (c) { | ||||
case 'f': | |||||
emaste: 'f' ought to be inserted in alpha order in the switch statement | |||||
cb = parse_conf(optarg); | |||||
guest_ncpus = cb.vcpus; | |||||
vm_parse_memsize(cb.memsize, &memsize); | |||||
vmname = cb.vmname; | |||||
acpi = 1; | |||||
guest_vmexit_on_hlt = 1; | |||||
guest_vmexit_on_pause = 1; | |||||
gdb_port = 0; | |||||
snprintf(temp, sizeof(temp), "%d:0,hostbridge", slot); | |||||
pci_parse_slot(temp); | |||||
slot += 1; | |||||
memset(temp, '\0', STR_SIZE); | |||||
snprintf(temp, sizeof(temp), "%d:0,lpc", slot); | |||||
pci_parse_slot(temp); | |||||
slot += 1; | |||||
while ((multiface = strsep(&cb.iface, ",")) != NULL) { | |||||
memset(temp, '\0', STR_SIZE); | |||||
snprintf(temp, sizeof(temp), "%d:0,virtio-net,%s", | |||||
slot, multiface); | |||||
pci_parse_slot(temp); | |||||
slot += 1; | |||||
} | |||||
if (cb.isofile) { | |||||
memset(temp, '\0', STR_SIZE); | |||||
snprintf(temp, sizeof(temp), "%d:0,virtio-blk,%s", | |||||
slot, cb.isofile); | |||||
pci_parse_slot(temp); | |||||
slot += 1; | |||||
} | |||||
memset(temp, '\0', STR_SIZE); | |||||
snprintf(temp, sizeof(temp), "%d:0,virtio-blk,%s", | |||||
slot, cb.bootdisk); | |||||
pci_parse_slot(temp); | |||||
slot += 1; | |||||
while ((multidisk = strsep(&cb.vdisk, ",")) != NULL) { | |||||
memset(temp, '\0', STR_SIZE); | |||||
snprintf(temp, sizeof(temp), "%d:0,virtio-blk,%s", | |||||
slot, multidisk); | |||||
pci_parse_slot(temp); | |||||
slot += 1; | |||||
} | |||||
memset(temp, '\0', STR_SIZE); | |||||
snprintf(temp, sizeof(temp), "com1,%s", cb.console); | |||||
lpc_device_parse(temp); | |||||
break; | |||||
case 'a': | case 'a': | ||||
x2apic_mode = 0; | x2apic_mode = 0; | ||||
break; | break; | ||||
case 'A': | case 'A': | ||||
acpi = 1; | acpi = 1; | ||||
break; | break; | ||||
case 'b': | case 'b': | ||||
bvmcons = 1; | bvmcons = 1; | ||||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | case 'h': | ||||
usage(0); | usage(0); | ||||
default: | default: | ||||
usage(1); | usage(1); | ||||
} | } | ||||
} | } | ||||
argc -= optind; | argc -= optind; | ||||
argv += optind; | argv += optind; | ||||
if (argc != 1) | if (!vmname) | ||||
usage(1); | |||||
vmname = argv[0]; | vmname = argv[0]; | ||||
Not Done Inline Actionsthis crashes if no vmname is included on the command line (such as running just 'bhyve') allanjude: this crashes if no vmname is included on the command line (such as running just 'bhyve') | |||||
ctx = vm_open(vmname); | ctx = vm_open(vmname); | ||||
if (ctx == NULL) { | if (ctx == NULL) { | ||||
perror("vm_open"); | perror("vm_open"); | ||||
exit(1); | exit(1); | ||||
} | } | ||||
if (guest_ncpus < 1) { | if (guest_ncpus < 1) { | ||||
fprintf(stderr, "Invalid guest vCPUs (%d)\n", guest_ncpus); | fprintf(stderr, "Invalid guest vCPUs (%d)\n", guest_ncpus); | ||||
exit(1); | exit(1); | ||||
} | } | ||||
max_vcpus = num_vcpus_allowed(ctx); | max_vcpus = num_vcpus_allowed(ctx); | ||||
if (guest_ncpus > max_vcpus) { | if (guest_ncpus > max_vcpus) { | ||||
fprintf(stderr, "%d vCPUs requested but only %d available\n", | fprintf(stderr, "%d vCPUs requested but only %d available\n", | ||||
guest_ncpus, max_vcpus); | guest_ncpus, max_vcpus); | ||||
exit(1); | exit(1); | ||||
} | } | ||||
fbsdrun_set_capabilities(ctx, BSP); | fbsdrun_set_capabilities(ctx, BSP); | ||||
if (dump_guest_memory) | if (dump_guest_memory) | ||||
vm_set_memflags(ctx, VM_MEM_F_INCORE); | vm_set_memflags(ctx, VM_MEM_F_INCORE); | ||||
err = vm_setup_memory(ctx, memsize, VM_MMAP_ALL); | err = vm_setup_memory(ctx, memsize, VM_MMAP_ALL); | ||||
if (err) { | if (err) { | ||||
emasteUnsubmitted Not Done Inline Actionsunrelated whitespace changes emaste: unrelated whitespace changes | |||||
fprintf(stderr, "Unable to setup memory (%d)\n", err); | fprintf(stderr, "Unable to setup memory (%d)\n", err); | ||||
exit(1); | exit(1); | ||||
} | } | ||||
error = init_msr(); | error = init_msr(); | ||||
if (error) { | if (error) { | ||||
fprintf(stderr, "init_msr error %d", error); | fprintf(stderr, "init_msr error %d", error); | ||||
exit(1); | exit(1); | ||||
Show All 33 Lines | main(int argc, char *argv[]) | ||||
error = smbios_build(ctx); | error = smbios_build(ctx); | ||||
assert(error == 0); | assert(error == 0); | ||||
if (acpi) { | if (acpi) { | ||||
error = acpi_build(ctx, guest_ncpus); | error = acpi_build(ctx, guest_ncpus); | ||||
assert(error == 0); | assert(error == 0); | ||||
} | } | ||||
/* | |||||
* Change the proc title to include the VM name. | |||||
*/ | |||||
setproctitle("%s", vmname); | |||||
emasteUnsubmitted Not Done Inline ActionsSeems a shame to lose this emaste: Seems a shame to lose this | |||||
/* | /* | ||||
* Add CPU 0 | * Add CPU 0 | ||||
*/ | */ | ||||
fbsdrun_addcpu(ctx, BSP, BSP, rip); | fbsdrun_addcpu(ctx, BSP, BSP, rip); | ||||
/* | /* | ||||
* Head off to the main event dispatch loop | * Head off to the main event dispatch loop | ||||
*/ | */ | ||||
mevent_dispatch(); | mevent_dispatch(); | ||||
exit(1); | exit(1); | ||||
} | } |
'f' ought to be inserted in alpha order in the switch statement