diff --git a/core/consport.c b/core/consport.c index ac6bd41ec..e166dcacd 100644 --- a/core/consport.c +++ b/core/consport.c @@ -43,6 +43,7 @@ #define BVM_CONSOLE_PORT 0x220 #define BVM_CONS_SIG ('b' << 8 | 'v') +static bool bvmcons_enabled = false; static struct termios tio_orig, tio_new; static void @@ -147,7 +148,23 @@ static struct inout_port consport = { }; void +enable_bvmcons(void) +{ + bvmcons_enabled = true; +} + +int init_bvmcons(void) { - register_inout(&consport); + if (bvmcons_enabled) + register_inout(&consport); + + return 0; +} + +void +deinit_bvmcons(void) +{ + if (bvmcons_enabled) + unregister_inout(&consport); } diff --git a/core/main.c b/core/main.c index 4692efd02..6e6d1570c 100644 --- a/core/main.c +++ b/core/main.c @@ -585,7 +585,7 @@ static struct option long_options[] = { int main(int argc, char *argv[]) { - int c, error, gdb_port, err, bvmcons; + int c, error, gdb_port, err; int max_vcpus, mptgen, memflags; int rtc_localtime; struct vmctx *ctx; @@ -593,7 +593,6 @@ main(int argc, char *argv[]) char *optstr; int option_idx = 0; - bvmcons = 0; progname = basename(argv[0]); gdb_port = 0; guest_ncpus = 1; @@ -617,7 +616,7 @@ main(int argc, char *argv[]) acpi = 1; break; case 'b': - bvmcons = 1; + enable_bvmcons(); break; case 'p': if (pincpu_parse(optarg) != 0) { @@ -793,6 +792,7 @@ main(int argc, char *argv[]) vrtc_init(ctx, rtc_localtime); sci_init(ctx); + init_bvmcons(); monitor_init(ctx); /* @@ -806,9 +806,6 @@ main(int argc, char *argv[]) if (gdb_port != 0) fprintf(stderr, "dbgport not supported\n"); - if (bvmcons) - init_bvmcons(); - /* * build the guest tables, MP etc. */ @@ -860,6 +857,7 @@ main(int argc, char *argv[]) pci_irq_deinit(ctx); deinit_pci(ctx); monitor_close(); + deinit_bvmcons(); vrtc_deinit(ctx); atkbdc_deinit(ctx); vm_unsetup_memory(ctx); @@ -875,6 +873,7 @@ vm_fail: deinit_pci(ctx); pci_fail: monitor_close(); + deinit_bvmcons(); vrtc_deinit(ctx); atkbdc_deinit(ctx); mevent_fail: diff --git a/include/inout.h b/include/inout.h index abf242612..cb8a8857b 100644 --- a/include/inout.h +++ b/include/inout.h @@ -75,6 +75,8 @@ int emulate_inout(struct vmctx *ctx, int *pvcpu, struct pio_request *req, int strict); int register_inout(struct inout_port *iop); int unregister_inout(struct inout_port *iop); -void init_bvmcons(void); +int init_bvmcons(void); +void deinit_bvmcons(void); +void enable_bvmcons(void); #endif /* _INOUT_H_ */