On Wed, May 22, 2019 at 08:05:50PM -0500, Katherine Rohl wrote: > Hi, > > Adjusted NS8250 behavior in vmd(8) so it gets detected as an 8250 and not a > 16450 by OpenBSD’s boot process. Also generalized some of the COM1-specific > I/O address definitions to support adding COM2 (and COM3, and COM4…) in the > future. > > Tested by logging into my VM with the virtual serial console and reinstalling > 6.5, everything was fine. The boot process detected an NS8250. >
Thanks for the vmd diff. Please test with various Linux guests also. I added the scratch reg to make this like an 8250A, IIRC, to support Linux guests. And you'll need to test with a few, Alpine, Ubuntu, Centos, etc, as they all had different behaviour. If those all work then we can get this in. -ml > Index: ns8250.c > =================================================================== > RCS file: /cvs/src/usr.sbin/vmd/ns8250.c,v > retrieving revision 1.20 > diff -u -p -u -r1.20 ns8250.c > --- ns8250.c 11 Mar 2019 17:08:52 -0000 1.20 > +++ ns8250.c 23 May 2019 00:52:15 -0000 > @@ -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, uint3 > } > 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; > Index: ns8250.h > =================================================================== > RCS file: /cvs/src/usr.sbin/vmd/ns8250.h,v > retrieving revision 1.7 > diff -u -p -u -r1.7 ns8250.h > --- ns8250.h 11 Mar 2019 17:08:52 -0000 1.7 > +++ ns8250.h 23 May 2019 00:52:15 -0000 > @@ -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; >