1 /* 2 * Copyright (c) 2016 Mike Larkin <mlarkin@openbsd.org> 3 * 4 * Permission to use, copy, modify, and distribute this software for any 5 * purpose with or without fee is hereby granted, provided that the above 6 * copyright notice and this permission notice appear in all copies. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 */ 16 17 /* 18 * Emulated 8250 UART 19 */ 20 #define COM1_DATA 0x3f8 21 #define COM1_IER 0x3f9 22 #define COM1_IIR 0x3fa 23 #define COM1_LCR 0x3fb 24 #define COM1_MCR 0x3fc 25 #define COM1_LSR 0x3fd 26 #define COM1_MSR 0x3fe 27 #define COM1_SCR 0x3ff 28 29 /* ns8250 UART registers */ 30 struct ns8250_regs { 31 uint8_t lcr; /* Line Control Register */ 32 uint8_t fcr; /* FIFO Control Register */ 33 uint8_t iir; /* Interrupt ID Register */ 34 uint8_t ier; /* Interrupt Enable Register */ 35 uint8_t divlo; /* Baud rate divisor low byte */ 36 uint8_t divhi; /* Baud rate divisor high byte */ 37 uint8_t msr; /* Modem Status Register */ 38 uint8_t lsr; /* Line Status Register */ 39 uint8_t mcr; /* Modem Control Register */ 40 uint8_t scr; /* Scratch Register */ 41 uint8_t data; /* Unread input data */ 42 }; 43 44 /* ns8250 UART device state */ 45 struct ns8250_dev { 46 pthread_mutex_t mutex; 47 struct ns8250_regs regs; 48 struct event event; 49 int fd; 50 int irq; 51 int rcv_pending; 52 }; 53 54 void ns8250_init(int, uint32_t); 55 uint8_t vcpu_exit_com(struct vm_run_params *); 56 uint8_t vcpu_process_com_data(union vm_exit *, uint32_t, uint32_t); 57 void vcpu_process_com_lcr(union vm_exit *); 58 void vcpu_process_com_lsr(union vm_exit *); 59 void vcpu_process_com_ier(union vm_exit *); 60 void vcpu_process_com_mcr(union vm_exit *); 61 void vcpu_process_com_iir(union vm_exit *); 62 void vcpu_process_com_msr(union vm_exit *); 63 void vcpu_process_com_scr(union vm_exit *); 64