diff options
author | Mike Larkin <mlarkin@cvs.openbsd.org> | 2019-05-28 07:36:38 +0000 |
---|---|---|
committer | Mike Larkin <mlarkin@cvs.openbsd.org> | 2019-05-28 07:36:38 +0000 |
commit | 094a1915d818a9a4578647dce9f65fcf58d87a5d (patch) | |
tree | aca9dc97a107d037e68181ef5cf95d1d8d304165 | |
parent | e24280f07a09b142cec6c35affbda616b270073a (diff) |
Make vmd(8)'s ns8250 emulation more correct
Remove the scratch register (8250s don't have this), and reorganize
some constants to be able to more easily support more than one serial
port in the future.
ok deraadt
Diff from Katherine Rohl, thanks!
-rw-r--r-- | usr.sbin/vmd/ns8250.c | 8 | ||||
-rw-r--r-- | usr.sbin/vmd/ns8250.h | 35 |
2 files changed, 31 insertions, 12 deletions
diff --git a/usr.sbin/vmd/ns8250.c b/usr.sbin/vmd/ns8250.c index f82f49166cf..163e19a49f6 100644 --- a/usr.sbin/vmd/ns8250.c +++ b/usr.sbin/vmd/ns8250.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ns8250.c,v 1.20 2019/03/11 17:08:52 anton Exp $ */ +/* $OpenBSD: ns8250.c,v 1.21 2019/05/28 07:36:37 mlarkin Exp $ */ /* * Copyright (c) 2016 Mike Larkin <mlarkin@openbsd.org> * @@ -74,6 +74,7 @@ ns8250_init(int fd, uint32_t vmid) } com1_dev.fd = fd; com1_dev.irq = 4; + com1_dev.portid = NS8250_COM1; com1_dev.rcv_pending = 0; com1_dev.vmid = vmid; com1_dev.byte_out = 0; @@ -509,10 +510,10 @@ vcpu_process_com_scr(struct vm_exit *vei) /* * vei_dir == VEI_DIR_OUT : out instruction * - * Write to SCR + * The 8250 does not have a scratch register. */ if (vei->vei.vei_dir == VEI_DIR_OUT) { - com1_dev.regs.scr = vei->vei.vei_data; + com1_dev.regs.scr = 0xFF; } else { /* * vei_dir == VEI_DIR_IN : in instruction @@ -647,6 +648,7 @@ ns8250_restore(int fd, int con_fd, uint32_t vmid) } com1_dev.fd = con_fd; com1_dev.irq = 4; + com1_dev.portid = NS8250_COM1; com1_dev.rcv_pending = 0; com1_dev.vmid = vmid; com1_dev.byte_out = 0; diff --git a/usr.sbin/vmd/ns8250.h b/usr.sbin/vmd/ns8250.h index 0e84e397db2..cc9c8f9e894 100644 --- a/usr.sbin/vmd/ns8250.h +++ b/usr.sbin/vmd/ns8250.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ns8250.h,v 1.7 2019/03/11 17:08:52 anton Exp $ */ +/* $OpenBSD: ns8250.h,v 1.8 2019/05/28 07:36:37 mlarkin Exp $ */ /* * Copyright (c) 2016 Mike Larkin <mlarkin@openbsd.org> * @@ -18,14 +18,30 @@ /* * Emulated 8250 UART */ -#define COM1_DATA 0x3f8 -#define COM1_IER 0x3f9 -#define COM1_IIR 0x3fa -#define COM1_LCR 0x3fb -#define COM1_MCR 0x3fc -#define COM1_LSR 0x3fd -#define COM1_MSR 0x3fe -#define COM1_SCR 0x3ff +#define COM1_BASE 0x3f8 +#define COM1_DATA COM1_BASE+COM_OFFSET_DATA +#define COM1_IER COM1_BASE+COM_OFFSET_IER +#define COM1_IIR COM1_BASE+COM_OFFSET_IIR +#define COM1_LCR COM1_BASE+COM_OFFSET_LCR +#define COM1_MCR COM1_BASE+COM_OFFSET_MCR +#define COM1_LSR COM1_BASE+COM_OFFSET_LSR +#define COM1_MSR COM1_BASE+COM_OFFSET_MSR +#define COM1_SCR COM1_BASE+COM_OFFSET_SCR + +#define COM_OFFSET_DATA 0 +#define COM_OFFSET_IER 1 +#define COM_OFFSET_IIR 2 +#define COM_OFFSET_LCR 3 +#define COM_OFFSET_MCR 4 +#define COM_OFFSET_LSR 5 +#define COM_OFFSET_MSR 6 +#define COM_OFFSET_SCR 7 + +/* ns8250 port identifier */ +enum ns8250_portid { + NS8250_COM1, + NS8250_COM2, +}; /* ns8250 UART registers */ struct ns8250_regs { @@ -50,6 +66,7 @@ struct ns8250_dev { struct event rate; struct event wake; struct timeval rate_tv; + enum ns8250_portid portid; int fd; int irq; int rcv_pending; |