Date: Thu, 23 Jul 2015 17:56:52 GMT From: mihai@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r288699 - soc2015/mihai/bhyve-on-arm-head/usr.sbin/bhyvearm Message-ID: <201507231756.t6NHuqKj036663@socsvn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: mihai Date: Thu Jul 23 17:56:52 2015 New Revision: 288699 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=288699 Log: soc2015: mihai: bhyve: usr.sbin: bhyvearm: consport.c: added emulation for console port [bvm] using memory Added: soc2015/mihai/bhyve-on-arm-head/usr.sbin/bhyvearm/consport.c Added: soc2015/mihai/bhyve-on-arm-head/usr.sbin/bhyvearm/consport.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2015/mihai/bhyve-on-arm-head/usr.sbin/bhyvearm/consport.c Thu Jul 23 17:56:52 2015 (r288699) @@ -0,0 +1,118 @@ +#include <sys/types.h> +#include <sys/select.h> + +#include <stdio.h> +#include <stdlib.h> +#include <termios.h> +#include <unistd.h> +#include <stdbool.h> + +#include "mem.h" + +#define BVM_CONSOLE_PORT 0x220 +#define BVM_CONS_SIG ('b' << 8 | 'v') + +static struct termios tio_orig, tio_new; + +static void +ttyclose(void) +{ + tcsetattr(STDIN_FILENO, TCSANOW, &tio_orig); +} + +static void +ttyopen(void) +{ + tcgetattr(STDIN_FILENO, &tio_orig); + + cfmakeraw(&tio_new); + tcsetattr(STDIN_FILENO, TCSANOW, &tio_new); + + atexit(ttyclose); +} + +static bool +tty_char_available(void) +{ + fd_set rfds; + struct timeval tv; + + FD_ZERO(&rfds); + FD_SET(STDIN_FILENO, &rfds); + tv.tv_sec = 0; + tv.tv_usec = 0; + if (select(STDIN_FILENO + 1, &rfds, NULL, NULL, &tv) > 0) { + return (true); + } else { + return (false); + } +} + +static int +ttyread(void) +{ + char rb; + + if (tty_char_available()) { + read(STDIN_FILENO, &rb, 1); + return (rb & 0xff); + } else { + return (-1); + } +} + +static void +ttywrite(unsigned char wb) +{ + (void) write(STDOUT_FILENO, &wb, 1); +} + +static int +console_handler(struct vmctx *ctx, int vcpu, int dir, uint64_t addr, int size, uint64_t *val, void *arg1, long arg2) +{ + static int opened; + + if (size == 2 && dir == MEM_F_READ) { + *val = BVM_CONS_SIG; + return (0); + } + + /* + * Guests might probe this port to look for old ISA devices + * using single-byte reads. Return 0xff for those. + */ + if (size == 1 && dir == MEM_F_READ) { + *val = 0xff; + return (0); + } + + if (size != 4) + return (-1); + + if (!opened) { + ttyopen(); + opened = 1; + } + + if (dir == MEM_F_READ) + *val = ttyread(); + else + ttywrite(*val); + return (0); +} + +struct mem_range consport ={ + "bvmcons", + MEM_F_RW, + console_handler, + NULL, + 0, + BVM_CONSOLE_PORT, + sizeof(int) +}; + +void +init_bvmcons(void) +{ + register_mem(&consport); +}
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201507231756.t6NHuqKj036663>