]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.sbin/bhyve/bhyverun.c
Upgrade to OpenSSH 6.6p1.
[FreeBSD/FreeBSD.git] / usr.sbin / bhyve / bhyverun.c
1 /*-
2  * Copyright (c) 2011 NetApp, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  */
28
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
31
32 #include <sys/types.h>
33 #include <sys/mman.h>
34 #include <sys/time.h>
35
36 #include <machine/atomic.h>
37 #include <machine/segments.h>
38
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <string.h>
42 #include <err.h>
43 #include <libgen.h>
44 #include <unistd.h>
45 #include <assert.h>
46 #include <errno.h>
47 #include <pthread.h>
48 #include <pthread_np.h>
49 #include <sysexits.h>
50
51 #include <machine/vmm.h>
52 #include <vmmapi.h>
53
54 #include "bhyverun.h"
55 #include "acpi.h"
56 #include "inout.h"
57 #include "dbgport.h"
58 #include "ioapic.h"
59 #include "mem.h"
60 #include "mevent.h"
61 #include "mptbl.h"
62 #include "pci_emul.h"
63 #include "pci_lpc.h"
64 #include "smbiostbl.h"
65 #include "xmsr.h"
66 #include "spinup_ap.h"
67 #include "rtc.h"
68
69 #define GUEST_NIO_PORT          0x488   /* guest upcalls via i/o port */
70
71 #define VMEXIT_SWITCH           0       /* force vcpu switch in mux mode */
72 #define VMEXIT_CONTINUE         1       /* continue from next instruction */
73 #define VMEXIT_RESTART          2       /* restart current instruction */
74 #define VMEXIT_ABORT            3       /* abort the vm run loop */
75 #define VMEXIT_RESET            4       /* guest machine has reset */
76 #define VMEXIT_POWEROFF         5       /* guest machine has powered off */
77
78 #define MB              (1024UL * 1024)
79 #define GB              (1024UL * MB)
80
81 typedef int (*vmexit_handler_t)(struct vmctx *, struct vm_exit *, int *vcpu);
82
83 char *vmname;
84
85 int guest_ncpus;
86 char *guest_uuid_str;
87
88 static int pincpu = -1;
89 static int guest_vmexit_on_hlt, guest_vmexit_on_pause;
90 static int virtio_msix = 1;
91 static int x2apic_mode = 0;     /* default is xAPIC */
92
93 static int strictio;
94 static int strictmsr = 1;
95
96 static int acpi;
97
98 static char *progname;
99 static const int BSP = 0;
100
101 static cpuset_t cpumask;
102
103 static void vm_loop(struct vmctx *ctx, int vcpu, uint64_t rip);
104
105 struct vm_exit vmexit[VM_MAXCPU];
106
107 struct bhyvestats {
108         uint64_t        vmexit_bogus;
109         uint64_t        vmexit_bogus_switch;
110         uint64_t        vmexit_hlt;
111         uint64_t        vmexit_pause;
112         uint64_t        vmexit_mtrap;
113         uint64_t        vmexit_inst_emul;
114         uint64_t        cpu_switch_rotate;
115         uint64_t        cpu_switch_direct;
116         int             io_reset;
117 } stats;
118
119 struct mt_vmm_info {
120         pthread_t       mt_thr;
121         struct vmctx    *mt_ctx;
122         int             mt_vcpu;        
123 } mt_vmm_info[VM_MAXCPU];
124
125 static void
126 usage(int code)
127 {
128
129         fprintf(stderr,
130                 "Usage: %s [-aehwAHIPW] [-g <gdb port>] [-s <pci>]\n"
131                 "       %*s [-c vcpus] [-p pincpu] [-m mem] [-l <lpc>] <vm>\n"
132                 "       -a: local apic is in xAPIC mode (deprecated)\n"
133                 "       -A: create an ACPI table\n"
134                 "       -g: gdb port\n"
135                 "       -c: # cpus (default 1)\n"
136                 "       -p: pin vcpu 'n' to host cpu 'pincpu + n'\n"
137                 "       -H: vmexit from the guest on hlt\n"
138                 "       -P: vmexit from the guest on pause\n"
139                 "       -W: force virtio to use single-vector MSI\n"
140                 "       -e: exit on unhandled I/O access\n"
141                 "       -h: help\n"
142                 "       -s: <slot,driver,configinfo> PCI slot config\n"
143                 "       -l: LPC device configuration\n"
144                 "       -m: memory size in MB\n"
145                 "       -w: ignore unimplemented MSRs\n"
146                 "       -x: local apic is in x2APIC mode\n"
147                 "       -U: uuid\n",
148                 progname, (int)strlen(progname), "");
149
150         exit(code);
151 }
152
153 void *
154 paddr_guest2host(struct vmctx *ctx, uintptr_t gaddr, size_t len)
155 {
156
157         return (vm_map_gpa(ctx, gaddr, len));
158 }
159
160 int
161 fbsdrun_vmexit_on_pause(void)
162 {
163
164         return (guest_vmexit_on_pause);
165 }
166
167 int
168 fbsdrun_vmexit_on_hlt(void)
169 {
170
171         return (guest_vmexit_on_hlt);
172 }
173
174 int
175 fbsdrun_virtio_msix(void)
176 {
177
178         return (virtio_msix);
179 }
180
181 static void *
182 fbsdrun_start_thread(void *param)
183 {
184         char tname[MAXCOMLEN + 1];
185         struct mt_vmm_info *mtp;
186         int vcpu;
187
188         mtp = param;
189         vcpu = mtp->mt_vcpu;
190
191         snprintf(tname, sizeof(tname), "vcpu %d", vcpu);
192         pthread_set_name_np(mtp->mt_thr, tname);
193
194         vm_loop(mtp->mt_ctx, vcpu, vmexit[vcpu].rip);
195
196         /* not reached */
197         exit(1);
198         return (NULL);
199 }
200
201 void
202 fbsdrun_addcpu(struct vmctx *ctx, int fromcpu, int newcpu, uint64_t rip)
203 {
204         int error;
205
206         assert(fromcpu == BSP);
207
208         CPU_SET_ATOMIC(newcpu, &cpumask);
209
210         /*
211          * Set up the vmexit struct to allow execution to start
212          * at the given RIP
213          */
214         vmexit[newcpu].rip = rip;
215         vmexit[newcpu].inst_length = 0;
216
217         mt_vmm_info[newcpu].mt_ctx = ctx;
218         mt_vmm_info[newcpu].mt_vcpu = newcpu;
219
220         error = pthread_create(&mt_vmm_info[newcpu].mt_thr, NULL,
221             fbsdrun_start_thread, &mt_vmm_info[newcpu]);
222         assert(error == 0);
223 }
224
225 static int
226 fbsdrun_deletecpu(struct vmctx *ctx, int vcpu)
227 {
228
229         if (!CPU_ISSET(vcpu, &cpumask)) {
230                 fprintf(stderr, "addcpu: attempting to delete unknown cpu %d\n",
231                     vcpu);
232                 exit(1);
233         }
234
235         CPU_CLR_ATOMIC(vcpu, &cpumask);
236         return (CPU_EMPTY(&cpumask));
237 }
238
239 static int
240 vmexit_catch_reset(void)
241 {
242         stats.io_reset++;
243         return (VMEXIT_RESET);
244 }
245
246 static int
247 vmexit_catch_inout(void)
248 {
249         return (VMEXIT_ABORT);
250 }
251
252 static int
253 vmexit_handle_notify(struct vmctx *ctx, struct vm_exit *vme, int *pvcpu,
254                      uint32_t eax)
255 {
256 #if BHYVE_DEBUG
257         /*
258          * put guest-driven debug here
259          */
260 #endif
261         return (VMEXIT_CONTINUE);
262 }
263
264 static int
265 vmexit_inout(struct vmctx *ctx, struct vm_exit *vme, int *pvcpu)
266 {
267         int error;
268         int bytes, port, in, out;
269         uint32_t eax;
270         int vcpu;
271
272         vcpu = *pvcpu;
273
274         port = vme->u.inout.port;
275         bytes = vme->u.inout.bytes;
276         eax = vme->u.inout.eax;
277         in = vme->u.inout.in;
278         out = !in;
279
280         /* We don't deal with these */
281         if (vme->u.inout.string || vme->u.inout.rep)
282                 return (VMEXIT_ABORT);
283
284         /* Special case of guest reset */
285         if (out && port == 0x64 && (uint8_t)eax == 0xFE)
286                 return (vmexit_catch_reset());
287
288         /* Extra-special case of host notifications */
289         if (out && port == GUEST_NIO_PORT)
290                 return (vmexit_handle_notify(ctx, vme, pvcpu, eax));
291
292         error = emulate_inout(ctx, vcpu, in, port, bytes, &eax, strictio);
293         if (error == INOUT_OK && in)
294                 error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RAX, eax);
295
296         switch (error) {
297         case INOUT_OK:
298                 return (VMEXIT_CONTINUE);
299         case INOUT_RESET:
300                 return (VMEXIT_RESET);
301         case INOUT_POWEROFF:
302                 return (VMEXIT_POWEROFF);
303         default:
304                 fprintf(stderr, "Unhandled %s%c 0x%04x\n",
305                         in ? "in" : "out",
306                         bytes == 1 ? 'b' : (bytes == 2 ? 'w' : 'l'), port);
307                 return (vmexit_catch_inout());
308         }
309 }
310
311 static int
312 vmexit_rdmsr(struct vmctx *ctx, struct vm_exit *vme, int *pvcpu)
313 {
314         uint64_t val;
315         uint32_t eax, edx;
316         int error;
317
318         val = 0;
319         error = emulate_rdmsr(ctx, *pvcpu, vme->u.msr.code, &val);
320         if (error != 0) {
321                 fprintf(stderr, "rdmsr to register %#x on vcpu %d\n",
322                     vme->u.msr.code, *pvcpu);
323                 if (strictmsr) {
324                         error = vm_inject_exception2(ctx, *pvcpu, IDT_GP, 0);
325                         assert(error == 0);
326                         return (VMEXIT_RESTART);
327                 }
328         }
329
330         eax = val;
331         error = vm_set_register(ctx, *pvcpu, VM_REG_GUEST_RAX, eax);
332         assert(error == 0);
333
334         edx = val >> 32;
335         error = vm_set_register(ctx, *pvcpu, VM_REG_GUEST_RDX, edx);
336         assert(error == 0);
337
338         return (VMEXIT_CONTINUE);
339 }
340
341 static int
342 vmexit_wrmsr(struct vmctx *ctx, struct vm_exit *vme, int *pvcpu)
343 {
344         int error;
345
346         error = emulate_wrmsr(ctx, *pvcpu, vme->u.msr.code, vme->u.msr.wval);
347         if (error != 0) {
348                 fprintf(stderr, "wrmsr to register %#x(%#lx) on vcpu %d\n",
349                     vme->u.msr.code, vme->u.msr.wval, *pvcpu);
350                 if (strictmsr) {
351                         error = vm_inject_exception2(ctx, *pvcpu, IDT_GP, 0);
352                         assert(error == 0);
353                         return (VMEXIT_RESTART);
354                 }
355         }
356         return (VMEXIT_CONTINUE);
357 }
358
359 static int
360 vmexit_spinup_ap(struct vmctx *ctx, struct vm_exit *vme, int *pvcpu)
361 {
362         int newcpu;
363         int retval = VMEXIT_CONTINUE;
364
365         newcpu = spinup_ap(ctx, *pvcpu,
366                            vme->u.spinup_ap.vcpu, vme->u.spinup_ap.rip);
367
368         return (retval);
369 }
370
371 static int
372 vmexit_spindown_cpu(struct vmctx *ctx, struct vm_exit *vme, int *pvcpu)
373 {
374         int lastcpu;
375
376         lastcpu = fbsdrun_deletecpu(ctx, *pvcpu);
377         if (!lastcpu)
378                 pthread_exit(NULL);
379         return (vmexit_catch_reset());
380 }
381
382 static int
383 vmexit_vmx(struct vmctx *ctx, struct vm_exit *vmexit, int *pvcpu)
384 {
385
386         fprintf(stderr, "vm exit[%d]\n", *pvcpu);
387         fprintf(stderr, "\treason\t\tVMX\n");
388         fprintf(stderr, "\trip\t\t0x%016lx\n", vmexit->rip);
389         fprintf(stderr, "\tinst_length\t%d\n", vmexit->inst_length);
390         fprintf(stderr, "\tstatus\t\t%d\n", vmexit->u.vmx.status);
391         fprintf(stderr, "\texit_reason\t%u\n", vmexit->u.vmx.exit_reason);
392         fprintf(stderr, "\tqualification\t0x%016lx\n",
393             vmexit->u.vmx.exit_qualification);
394         fprintf(stderr, "\tinst_type\t\t%d\n", vmexit->u.vmx.inst_type);
395         fprintf(stderr, "\tinst_error\t\t%d\n", vmexit->u.vmx.inst_error);
396
397         return (VMEXIT_ABORT);
398 }
399
400 static int
401 vmexit_bogus(struct vmctx *ctx, struct vm_exit *vmexit, int *pvcpu)
402 {
403
404         stats.vmexit_bogus++;
405
406         return (VMEXIT_RESTART);
407 }
408
409 static int
410 vmexit_hlt(struct vmctx *ctx, struct vm_exit *vmexit, int *pvcpu)
411 {
412
413         stats.vmexit_hlt++;
414
415         /*
416          * Just continue execution with the next instruction. We use
417          * the HLT VM exit as a way to be friendly with the host
418          * scheduler.
419          */
420         return (VMEXIT_CONTINUE);
421 }
422
423 static int
424 vmexit_pause(struct vmctx *ctx, struct vm_exit *vmexit, int *pvcpu)
425 {
426
427         stats.vmexit_pause++;
428
429         return (VMEXIT_CONTINUE);
430 }
431
432 static int
433 vmexit_mtrap(struct vmctx *ctx, struct vm_exit *vmexit, int *pvcpu)
434 {
435
436         stats.vmexit_mtrap++;
437
438         return (VMEXIT_RESTART);
439 }
440
441 static int
442 vmexit_inst_emul(struct vmctx *ctx, struct vm_exit *vmexit, int *pvcpu)
443 {
444         int err;
445         stats.vmexit_inst_emul++;
446
447         err = emulate_mem(ctx, *pvcpu, vmexit->u.inst_emul.gpa,
448                           &vmexit->u.inst_emul.vie);
449
450         if (err) {
451                 if (err == EINVAL) {
452                         fprintf(stderr,
453                             "Failed to emulate instruction at 0x%lx\n", 
454                             vmexit->rip);
455                 } else if (err == ESRCH) {
456                         fprintf(stderr, "Unhandled memory access to 0x%lx\n",
457                             vmexit->u.inst_emul.gpa);
458                 }
459
460                 return (VMEXIT_ABORT);
461         }
462
463         return (VMEXIT_CONTINUE);
464 }
465
466 static vmexit_handler_t handler[VM_EXITCODE_MAX] = {
467         [VM_EXITCODE_INOUT]  = vmexit_inout,
468         [VM_EXITCODE_VMX]    = vmexit_vmx,
469         [VM_EXITCODE_BOGUS]  = vmexit_bogus,
470         [VM_EXITCODE_RDMSR]  = vmexit_rdmsr,
471         [VM_EXITCODE_WRMSR]  = vmexit_wrmsr,
472         [VM_EXITCODE_MTRAP]  = vmexit_mtrap,
473         [VM_EXITCODE_INST_EMUL] = vmexit_inst_emul,
474         [VM_EXITCODE_SPINUP_AP] = vmexit_spinup_ap,
475         [VM_EXITCODE_SPINDOWN_CPU] = vmexit_spindown_cpu,
476 };
477
478 static void
479 vm_loop(struct vmctx *ctx, int vcpu, uint64_t rip)
480 {
481         cpuset_t mask;
482         int error, rc, prevcpu;
483         enum vm_exitcode exitcode;
484
485         if (pincpu >= 0) {
486                 CPU_ZERO(&mask);
487                 CPU_SET(pincpu + vcpu, &mask);
488                 error = pthread_setaffinity_np(pthread_self(),
489                                                sizeof(mask), &mask);
490                 assert(error == 0);
491         }
492
493         while (1) {
494                 error = vm_run(ctx, vcpu, rip, &vmexit[vcpu]);
495                 if (error != 0)
496                         break;
497
498                 prevcpu = vcpu;
499
500                 exitcode = vmexit[vcpu].exitcode;
501                 if (exitcode >= VM_EXITCODE_MAX || handler[exitcode] == NULL) {
502                         fprintf(stderr, "vm_loop: unexpected exitcode 0x%x\n",
503                             exitcode);
504                         exit(1);
505                 }
506
507                 rc = (*handler[exitcode])(ctx, &vmexit[vcpu], &vcpu);
508
509                 switch (rc) {
510                 case VMEXIT_CONTINUE:
511                         rip = vmexit[vcpu].rip + vmexit[vcpu].inst_length;
512                         break;
513                 case VMEXIT_RESTART:
514                         rip = vmexit[vcpu].rip;
515                         break;
516                 case VMEXIT_RESET:
517                         exit(0);
518                 default:
519                         exit(1);
520                 }
521         }
522         fprintf(stderr, "vm_run error %d, errno %d\n", error, errno);
523 }
524
525 static int
526 num_vcpus_allowed(struct vmctx *ctx)
527 {
528         int tmp, error;
529
530         error = vm_get_capability(ctx, BSP, VM_CAP_UNRESTRICTED_GUEST, &tmp);
531
532         /*
533          * The guest is allowed to spinup more than one processor only if the
534          * UNRESTRICTED_GUEST capability is available.
535          */
536         if (error == 0)
537                 return (VM_MAXCPU);
538         else
539                 return (1);
540 }
541
542 void
543 fbsdrun_set_capabilities(struct vmctx *ctx, int cpu)
544 {
545         int err, tmp;
546
547         if (fbsdrun_vmexit_on_hlt()) {
548                 err = vm_get_capability(ctx, cpu, VM_CAP_HALT_EXIT, &tmp);
549                 if (err < 0) {
550                         fprintf(stderr, "VM exit on HLT not supported\n");
551                         exit(1);
552                 }
553                 vm_set_capability(ctx, cpu, VM_CAP_HALT_EXIT, 1);
554                 if (cpu == BSP)
555                         handler[VM_EXITCODE_HLT] = vmexit_hlt;
556         }
557
558         if (fbsdrun_vmexit_on_pause()) {
559                 /*
560                  * pause exit support required for this mode
561                  */
562                 err = vm_get_capability(ctx, cpu, VM_CAP_PAUSE_EXIT, &tmp);
563                 if (err < 0) {
564                         fprintf(stderr,
565                             "SMP mux requested, no pause support\n");
566                         exit(1);
567                 }
568                 vm_set_capability(ctx, cpu, VM_CAP_PAUSE_EXIT, 1);
569                 if (cpu == BSP)
570                         handler[VM_EXITCODE_PAUSE] = vmexit_pause;
571         }
572
573         if (x2apic_mode)
574                 err = vm_set_x2apic_state(ctx, cpu, X2APIC_ENABLED);
575         else
576                 err = vm_set_x2apic_state(ctx, cpu, X2APIC_DISABLED);
577
578         if (err) {
579                 fprintf(stderr, "Unable to set x2apic state (%d)\n", err);
580                 exit(1);
581         }
582
583         vm_set_capability(ctx, cpu, VM_CAP_ENABLE_INVPCID, 1);
584 }
585
586 int
587 main(int argc, char *argv[])
588 {
589         int c, error, gdb_port, err, bvmcons;
590         int max_vcpus;
591         struct vmctx *ctx;
592         uint64_t rip;
593         size_t memsize;
594
595         bvmcons = 0;
596         progname = basename(argv[0]);
597         gdb_port = 0;
598         guest_ncpus = 1;
599         memsize = 256 * MB;
600
601         while ((c = getopt(argc, argv, "abehwxAHIPWp:g:c:s:m:l:U:")) != -1) {
602                 switch (c) {
603                 case 'a':
604                         x2apic_mode = 0;
605                         break;
606                 case 'A':
607                         acpi = 1;
608                         break;
609                 case 'b':
610                         bvmcons = 1;
611                         break;
612                 case 'p':
613                         pincpu = atoi(optarg);
614                         break;
615                 case 'c':
616                         guest_ncpus = atoi(optarg);
617                         break;
618                 case 'g':
619                         gdb_port = atoi(optarg);
620                         break;
621                 case 'l':
622                         if (lpc_device_parse(optarg) != 0) {
623                                 errx(EX_USAGE, "invalid lpc device "
624                                     "configuration '%s'", optarg);
625                         }
626                         break;
627                 case 's':
628                         if (pci_parse_slot(optarg) != 0)
629                                 exit(1);
630                         else
631                                 break;
632                 case 'm':
633                         error = vm_parse_memsize(optarg, &memsize);
634                         if (error)
635                                 errx(EX_USAGE, "invalid memsize '%s'", optarg);
636                         break;
637                 case 'H':
638                         guest_vmexit_on_hlt = 1;
639                         break;
640                 case 'I':
641                         /*
642                          * The "-I" option was used to add an ioapic to the
643                          * virtual machine.
644                          *
645                          * An ioapic is now provided unconditionally for each
646                          * virtual machine and this option is now deprecated.
647                          */
648                         break;
649                 case 'P':
650                         guest_vmexit_on_pause = 1;
651                         break;
652                 case 'e':
653                         strictio = 1;
654                         break;
655                 case 'U':
656                         guest_uuid_str = optarg;
657                         break;
658                 case 'w':
659                         strictmsr = 0;
660                         break;
661                 case 'W':
662                         virtio_msix = 0;
663                         break;
664                 case 'x':
665                         x2apic_mode = 1;
666                         break;
667                 case 'h':
668                         usage(0);                       
669                 default:
670                         usage(1);
671                 }
672         }
673         argc -= optind;
674         argv += optind;
675
676         if (argc != 1)
677                 usage(1);
678
679         vmname = argv[0];
680
681         ctx = vm_open(vmname);
682         if (ctx == NULL) {
683                 perror("vm_open");
684                 exit(1);
685         }
686
687         max_vcpus = num_vcpus_allowed(ctx);
688         if (guest_ncpus > max_vcpus) {
689                 fprintf(stderr, "%d vCPUs requested but only %d available\n",
690                         guest_ncpus, max_vcpus);
691                 exit(1);
692         }
693
694         fbsdrun_set_capabilities(ctx, BSP);
695
696         err = vm_setup_memory(ctx, memsize, VM_MMAP_ALL);
697         if (err) {
698                 fprintf(stderr, "Unable to setup memory (%d)\n", err);
699                 exit(1);
700         }
701
702         init_mem();
703         init_inout();
704         ioapic_init(ctx);
705
706         rtc_init(ctx);
707
708         /*
709          * Exit if a device emulation finds an error in it's initilization
710          */
711         if (init_pci(ctx) != 0)
712                 exit(1);
713
714         if (gdb_port != 0)
715                 init_dbgport(gdb_port);
716
717         if (bvmcons)
718                 init_bvmcons();
719
720         error = vm_get_register(ctx, BSP, VM_REG_GUEST_RIP, &rip);
721         assert(error == 0);
722
723         /*
724          * build the guest tables, MP etc.
725          */
726         mptable_build(ctx, guest_ncpus);
727
728         error = smbios_build(ctx);
729         assert(error == 0);
730
731         if (acpi) {
732                 error = acpi_build(ctx, guest_ncpus);
733                 assert(error == 0);
734         }
735
736         /*
737          * Change the proc title to include the VM name.
738          */
739         setproctitle("%s", vmname); 
740         
741         /*
742          * Add CPU 0
743          */
744         fbsdrun_addcpu(ctx, BSP, BSP, rip);
745
746         /*
747          * Head off to the main event dispatch loop
748          */
749         mevent_dispatch();
750
751         exit(1);
752 }